Пример #1
0
/* main program logic:  spawn crud to see what happens */
int                 main
    (
    int             argc,
    char * *        argv,
    char * *        env
    )
    {
    char            mode;
    int             cnt;

    mode = toupper( argv[ 1 ][ 0 ]);
    cnt = atoi( argv[ 2 ]);
    if ( mode == 'T')
        {
        do_threads( cnt);
        }  // threads?
    else if ( mode == 'F')
        {
        do_forks( cnt);
        }  // forks?
    else if ( mode == 'S')
        {
        do_sequence( cnt);
        }  // sequential processing?
    else
        {
        die( "Arg 1 must be T (thread), F (fork), or S (sequential)");
        }
    return 0;
    }
Пример #2
0
int main(int ac, char *av[])
{
	int ret = 0;

	strcpy(applnamebuf,av[0]);
#ifdef _WIN32
	{
		char *q;
		
		if((q=strrchr(applnamebuf, '.')))
			if(!equal(q+1,"exe"))
				strcat(applnamebuf,".exe");
	}
#endif
	applname = applnamebuf;

	if(ac > 1 && isdigit(av[1][0])) {
		maxcount = atoik(av[1]);
		ac--;
		av++;
		if(maxcount == 0)
			maxcount = 1;
	}
	ret = do_threads();
	return ret;
}
Пример #3
0
int main(int argc, char *argv[])
{
    char *CApath = NULL, *CAfile = NULL;
    int badop = 0;
    int ret = 1;
    int client_auth = 0;
    int server_auth = 0;
    SSL_CTX *s_ctx = NULL;
    SSL_CTX *c_ctx = NULL;
    char *scert = TEST_SERVER_CERT;
    char *ccert = TEST_CLIENT_CERT;
    SSL_METHOD *ssl_method = SSLv23_method();

    RAND_seed(rnd_seed, sizeof rnd_seed);

    if (bio_err == NULL)
        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
    if (bio_stdout == NULL)
        bio_stdout = BIO_new_fp(stdout, BIO_NOCLOSE);
    argc--;
    argv++;

    while (argc >= 1) {
        if (sgx_strcmp(*argv, "-server_auth") == 0)
            server_auth = 1;
        else if (sgx_strcmp(*argv, "-client_auth") == 0)
            client_auth = 1;
        else if (sgx_strcmp(*argv, "-reconnect") == 0)
            reconnect = 1;
        else if (sgx_strcmp(*argv, "-stats") == 0)
            cache_stats = 1;
        else if (sgx_strcmp(*argv, "-ssl3") == 0)
            ssl_method = SSLv3_method();
        else if (sgx_strcmp(*argv, "-ssl2") == 0)
            ssl_method = SSLv2_method();
        else if (sgx_strcmp(*argv, "-CApath") == 0) {
            if (--argc < 1)
                goto bad;
            CApath = *(++argv);
        } else if (sgx_strcmp(*argv, "-CAfile") == 0) {
            if (--argc < 1)
                goto bad;
            CAfile = *(++argv);
        } else if (sgx_strcmp(*argv, "-cert") == 0) {
            if (--argc < 1)
                goto bad;
            scert = *(++argv);
        } else if (sgx_strcmp(*argv, "-ccert") == 0) {
            if (--argc < 1)
                goto bad;
            ccert = *(++argv);
        } else if (sgx_strcmp(*argv, "-threads") == 0) {
            if (--argc < 1)
                goto bad;
            thread_number = atoi(*(++argv));
            if (thread_number == 0)
                thread_number = 1;
            if (thread_number > MAX_THREAD_NUMBER)
                thread_number = MAX_THREAD_NUMBER;
        } else if (sgx_strcmp(*argv, "-loops") == 0) {
            if (--argc < 1)
                goto bad;
            number_of_loops = atoi(*(++argv));
            if (number_of_loops == 0)
                number_of_loops = 1;
        } else {
            fprintf(stderr, "unknown option %s\n", *argv);
            badop = 1;
            break;
        }
        argc--;
        argv++;
    }
    if (badop) {
 bad:
        sv_usage();
        goto end;
    }

    if (cipher == NULL && OPENSSL_issetugid() == 0)
        cipher = getenv("SSL_CIPHER");

    SSL_load_error_strings();
    OpenSSL_add_ssl_algorithms();

    c_ctx = SSL_CTX_new(ssl_method);
    s_ctx = SSL_CTX_new(ssl_method);
    if ((c_ctx == NULL) || (s_ctx == NULL)) {
        ERR_print_errors(bio_err);
        goto end;
    }

    SSL_CTX_set_session_cache_mode(s_ctx,
                                   SSL_SESS_CACHE_NO_AUTO_CLEAR |
                                   SSL_SESS_CACHE_SERVER);
    SSL_CTX_set_session_cache_mode(c_ctx,
                                   SSL_SESS_CACHE_NO_AUTO_CLEAR |
                                   SSL_SESS_CACHE_SERVER);

    if (!SSL_CTX_use_certificate_file(s_ctx, scert, SSL_FILETYPE_PEM)) {
        ERR_print_errors(bio_err);
    } else
        if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx, scert, SSL_FILETYPE_PEM)) {
        ERR_print_errors(bio_err);
        goto end;
    }

    if (client_auth) {
        SSL_CTX_use_certificate_file(c_ctx, ccert, SSL_FILETYPE_PEM);
        SSL_CTX_use_RSAPrivateKey_file(c_ctx, ccert, SSL_FILETYPE_PEM);
    }

    if ((!SSL_CTX_load_verify_locations(s_ctx, CAfile, CApath)) ||
        (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
        (!SSL_CTX_load_verify_locations(c_ctx, CAfile, CApath)) ||
        (!SSL_CTX_set_default_verify_paths(c_ctx))) {
        fprintf(stderr, "SSL_load_verify_locations\n");
        ERR_print_errors(bio_err);
        goto end;
    }

    if (client_auth) {
        fprintf(stderr, "client authentication\n");
        SSL_CTX_set_verify(s_ctx,
                           SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
                           verify_callback);
    }
    if (server_auth) {
        fprintf(stderr, "server authentication\n");
        SSL_CTX_set_verify(c_ctx, SSL_VERIFY_PEER, verify_callback);
    }

    thread_setup();
    do_threads(s_ctx, c_ctx);
    thread_cleanup();
 end:

    if (c_ctx != NULL) {
        fprintf(stderr, "Client SSL_CTX stats then free it\n");
        print_stats(stderr, c_ctx);
        SSL_CTX_free(c_ctx);
    }
    if (s_ctx != NULL) {
        fprintf(stderr, "Server SSL_CTX stats then free it\n");
        print_stats(stderr, s_ctx);
        if (cache_stats) {
            fprintf(stderr, "-----\n");
            lh_stats(SSL_CTX_sessions(s_ctx), stderr);
            fprintf(stderr, "-----\n");
    /*-     lh_node_stats(SSL_CTX_sessions(s_ctx),stderr);
            fprintf(stderr,"-----\n"); */
            lh_node_usage_stats(SSL_CTX_sessions(s_ctx), stderr);
            fprintf(stderr, "-----\n");
        }
        SSL_CTX_free(s_ctx);
        fprintf(stderr, "done free\n");
    }
    exit(ret);
    return (0);
}
Пример #4
0
/*============================================================================
 *
 * main() BEGINS HERE
 *
 *===========================================================================*/
int
main(int argc, char *argv[])
{
    val_context_t  *context = NULL;

    // Parse the command line for a query and resolve+validate it
    int             c;
    char           *domain_name = NULL;
    const char     *args = "c:dF:hi:I:l:m:nw:o:pr:S:st:T:v:V";
    int            class_h = ns_c_in;
    int            type_h = ns_t_a;
    int             success = 0;
    int             doprint = 0;
    int             selftest = 0;
    int             num_threads = 0;
    int             max_in_flight = 1;
    int             daemon = 0;
    //u_int32_t       flags = VAL_QUERY_AC_DETAIL|VAL_QUERY_NO_EDNS0_FALLBACK|VAL_QUERY_SKIP_CACHE;
    u_int32_t       flags = VAL_QUERY_AC_DETAIL;
    u_int32_t       nodnssec_flag = 0;
    int             retvals[] = { 0 };
    int             tcs = 0, tce = -1;
    int             wait = 0;
    char           *label_str = NULL, *nextarg = NULL;
    char           *suite = NULL, *testcase_config = NULL;
    val_log_t      *logp;
    int             rc;

    if (argc == 1)
        return 0;

    while (1) {
#ifdef HAVE_GETOPT_LONG
        int             opt_index = 0;
#ifdef HAVE_GETOPT_LONG_ONLY
        c = getopt_long_only(argc, argv, args, prog_options, &opt_index);
#else
        c = getopt_long(argc, argv, args, prog_options, &opt_index);
#endif
#else                           /* only have getopt */
        c = getopt(argc, argv, args);
#endif

        if (c == -1) {
            break;
        }

        switch (c) {
        case 'h':
            usage(argv[0]);
            return (-1);

        case 'F':
            testcase_config = optarg;
            break;

        case 'd':
            daemon = 1;
            break;

        case 's':
            selftest = 1;
            if (NULL != suite) {
                fprintf(stderr,
                        "Warning: -s runs all tests.\n"
                        "         ignoring previous suite(s).\n");
                suite = NULL; /* == all suites */
            }
            break;

        case 'S':
            if (selftest) {
                if (NULL == suite)
                    fprintf(stderr,
                            "Warning: -s runs all tests.\n"
                            "         ignoring specified suite.\n");
                else {
                    fprintf(stderr,
                            "Warning: -S may only be specified once.\n"
                            "         ignoring previous suite.\n");
                    suite = optarg;
                }
            }
            else {
                selftest = 1;
                suite = optarg;
            }
            break;

        case 'p':
            doprint = 1;
            break;

        case 'n':
            nodnssec_flag = 1;
            break;

        case 'c':
            // optarg is a global variable.  See man page for getopt_long(3).
            class_h = res_nametoclass(optarg, &success);
            if (!success) {
                fprintf(stderr, "Cannot parse class %s\n", optarg);
                usage(argv[0]);
                return -1;
            }
            break;

        case 'o':
            logp = val_log_add_optarg(optarg, 1);
            if (NULL == logp) { /* err msg already logged */
                usage(argv[0]);
                return -1;
            }
            break;


        case 'I':
#ifndef VAL_NO_ASYNC
            max_in_flight = strtol(optarg, &nextarg, 10);
#else
            fprintf(stderr, "libval was built without asynchronous support\n");
            fprintf(stderr, "ignoring -I parameter\n");
#endif /* ndef VAL_NO_ASYNC */
            break;

        case 'm':
            num_threads = atoi(optarg);
            break;

        case 'v':
            dnsval_conf_set(optarg);
            break;

        case 'i':
            root_hints_set(optarg);
            break;

        case 'r':
            resolv_conf_set(optarg);
            break;

        case 'w':
            wait = strtol(optarg, &nextarg, 10);
            break; 

        case 't':
            type_h = res_nametotype(optarg, &success);
            if (!success) {
                fprintf(stderr, "Cannot parse type %s\n", optarg);
                usage(argv[0]);
                return -1;
            }
            break;

        case 'T':
            tcs = strtol(optarg, &nextarg, 10);
            if (*nextarg == '\0')
                tce = tcs;
            else
                tce = atoi(++nextarg);
            break;

        case 'l':
            label_str = optarg;
            break;

        case 'V':
            version();
            return 0;

        default:
            fprintf(stderr, "Unknown option %s (c = %d [%c])\n",
                    argv[optind - 1], c, (char) c);
            usage(argv[0]);
            return -1;

        }                       // end switch
    }

    if (daemon) {
        endless_loop();
        return 0;
    }

#ifndef TEST_NULL_CTX_CREATION
    if (VAL_NO_ERROR !=
        (rc = val_create_context(label_str, &context))) {
        fprintf(stderr, "Cannot create context: %d\n", rc);
        return -1;
    }
#else
    context = NULL;
#endif

    /* returned level is 0 based;, > 6 means 7 or higher; e.g. -o 7:stdout */
    if (val_log_highest_debug_level() > 6)
        res_set_debug_level(val_log_highest_debug_level());

    rc = 0;

    if (nodnssec_flag) {
        val_context_setqflags(context, VAL_CTX_FLAG_SET,
                              VAL_QUERY_DONT_VALIDATE);
    }

    // optind is a global variable.  See man page for getopt_long(3)
    if (optind >= argc) {
        if (!selftest && (tcs == -1)) {
            fprintf(stderr, "Please specify domain name\n");
            usage(argv[0]);
            rc = -1;
            goto done;
        } else {

#ifndef VAL_NO_THREADS
            if (num_threads > 0) {
                struct thread_params_st 
                    threadparams = {context, tcs, tce, flags, testcase_config,
                                    suite, doprint, wait, max_in_flight};

                do_threads(num_threads, &threadparams);
                fprintf(stderr, "Parent exiting\n");
            } else {
#endif /* VAL_NO_THREADS */
                do { /* endless loop */ 
                    rc = self_test(context, tcs, tce, flags, testcase_config,
                                   suite, doprint, max_in_flight);
                    if (wait)
                        sleep(wait);
                } while (wait && !rc);
#ifndef VAL_NO_THREADS
            }
#endif /* VAL_NO_THREADS */
        }

        goto done;
    }

    domain_name = argv[optind++];

#ifndef VAL_NO_THREADS
    if (num_threads > 0) {
        struct thread_params_st 
            threadparams = {context, tcs, tce, flags, testcase_config,
                            suite, doprint, wait, max_in_flight};

        do_threads(num_threads, &threadparams);
    } else {
#endif /* VAL_NO_THREADS */
        do { /* endless loop */
            rc = one_test(context, domain_name, class_h, type_h, flags, retvals,
                     doprint);

            if (wait)
                sleep(wait);
        } while (wait);

#ifndef VAL_NO_THREADS
    }
#endif /* VAL_NO_THREADS */

done:
    if (context)
        val_free_context(context);
    val_free_validator_state();

    return rc;
}
Пример #5
0
int main(int ac, char *av[])
{
    int ret = 0;

    //strcpy(applnamebuf,av[0]);
    if(strrchr(av[0],SLASHC))
        strcpy(applnamebuf, strrchr(av[0],SLASHC)+1);
    else
        strcpy(applnamebuf, av[0]);
#ifdef _WIN32
    {
        char *q;
        
        if((q=strrchr(applnamebuf, '.')))
            if(!equal(q+1,"exe"))
                strcat(applnamebuf,".exe");
    }
#endif
    applname = applnamebuf;

    if(ac == 1) {
        USAGE();
        return 0;
    }
    while(ac > 1) {
        if(equal(av[1],"-debug") || equal(av[1],"-d")) {
            ac--;
            av++;
            showme++;
        }
        else if(equal(av[1],"-csv")) {
            ac--;
            av++;
            csv = 1;
        }
        else if(equaln(av[1], "-t",2)) {
            if(av[1][2] == 0) {
                ac--;
                av++;
                nthreads = atoik(av[1]);
            }
            else {
                nthreads = atoik(&av[1][2]);
            }
            //if(nthreads > 1000) nthreads = 1000;
            if(nthreads < 2) nthreads = 2;
            ac--;
            av++;
        }
        else if(equaln(av[1], "-c",2)) {
            if(av[1][2] == 0) {
                ac--;
                av++;
                ncrits = atoik(av[1]);
            }
            else {
                ncrits = atoik(&av[1][2]);
            }
            ac--;
            av++;
        }
        else if(isdigit(av[1][0])) {
            maxcount = atoik(av[1]);
            ac--;
            av++;
            if(maxcount == 0)
                maxcount = 1;
        }
    }
    //
    // There has to be at least 1 more critical section than threads.
    //
    if(ncrits <= nthreads)
        ncrits = nthreads + 1;

    ret = do_threads();
    return ret;
}