optstate = PL_CreateOptState(argc, argv, "2:3M:RTc:d:p:mn:hi:f:rt:vw:x");
optstate = PL_CreateOptState(argc, argv, "2:3DM:RTc:d:p:mn:hi:f:rt:vw:x");
main(int argc, char **argv){    char *               progName    = NULL;    char *               nickName    = NULL;    char *               fNickName   = NULL;    const char *         fileName    = NULL;    char *               cipherString= NULL;    const char *         dir         = ".";    char *               passwd      = NULL;    const char *         pidFile     = NULL;    char *               tmp;    char *               envString;    PRFileDesc *         listen_sock;    CERTCertificate *    cert   [kt_kea_size] = { NULL };    SECKEYPrivateKey *   privKey[kt_kea_size] = { NULL };    int                  optionsFound = 0;    int                  maxProcs     = 1;    unsigned short       port        = 0;    SECStatus            rv;    PRStatus             prStatus;    PRBool               useExportPolicy = PR_FALSE;    PLOptState		*optstate;    PLOptStatus          status;    tmp = strrchr(argv[0], '/');    tmp = tmp ? tmp + 1 : argv[0];    progName = strrchr(tmp, '\\');    progName = progName ? progName + 1 : tmp;    PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);    optstate = PL_CreateOptState(argc, argv, "2:3M:RTc:d:p:mn:hi:f:rt:vw:x");    while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) {	++optionsFound;	switch(optstate->option) {	case '2': fileName = optstate->value; break;	case '3': disableSSL3 = PR_TRUE; break;	case 'M': maxProcs = PORT_Atoi(optstate->value); break;	case 'R': disableRollBack = PR_TRUE; break;	case 'T': disableTLS = PR_TRUE; break;	case 'c': cipherString = strdup(optstate->value); break;	case 'd': dir = optstate->value; break;	case 'f': fNickName = strdup(optstate->value); break;	case 'h': Usage(progName); exit(0); break;	case 'm': useModelSocket = PR_TRUE; break;	case 'n': nickName = strdup(optstate->value); break;	case 'i': pidFile = optstate->value; break;	case 'p': port = PORT_Atoi(optstate->value); break;	case 'r': ++requestCert; break;	case 't':	    maxThreads = PORT_Atoi(optstate->value);	    if ( maxThreads > MAX_THREADS ) maxThreads = MAX_THREADS;	    if ( maxThreads < MIN_THREADS ) maxThreads = MIN_THREADS;	    break;	case 'v': verbose++; break;	case 'w': passwd = strdup(optstate->value); break;	case 'x': useExportPolicy = PR_TRUE; break;	default:	case '?':	    fprintf(stderr, "Unrecognized or bad option specified.\n");	    fprintf(stderr, "Run '%s -h' for usage information.\n", progName);	    exit(4);	    break;	}    }    PL_DestroyOptState(optstate);    if (status == PL_OPT_BAD) {	fprintf(stderr, "Unrecognized or bad option specified.\n");	fprintf(stderr, "Run '%s -h' for usage information.\n", progName);	exit(5);    }    if (!optionsFound) {	Usage(progName);	exit(51);    }     if ((nickName == NULL) && (fNickName == NULL)) {	fprintf(stderr, "Required arg '-n' (rsa nickname) not supplied.\n");	fprintf(stderr, "Run '%s -h' for usage information.\n", progName);        exit(6);    }    if (port == 0) {	fprintf(stderr, "Required argument 'port' must be non-zero value\n");	exit(7);    }    if (pidFile) {	FILE *tmpfile=fopen(pidFile,"w+");	if (tmpfile) {	    fprintf(tmpfile,"%d",getpid());	    fclose(tmpfile);	}    }    envString = getenv(envVarName);    if (envString) {	/* we're one of the children in a multi-process server. */	listen_sock = PR_GetInheritedFD(inheritableSockName);	if (!listen_sock)	    errExit("PR_GetInheritedFD");	prStatus = PR_SetFDInheritable(listen_sock, PR_FALSE);	if (prStatus != PR_SUCCESS)	    errExit("PR_SetFDInheritable");	rv = SSL_InheritMPServerSIDCache(envString);	if (rv != SECSuccess)	    errExit("SSL_InheritMPServerSIDCache");    } else if (maxProcs > 1) {	/* we're going to be the parent in a multi-process server.  */	listen_sock = getBoundListenSocket(port);	rv = SSL_ConfigMPServerSIDCache(32 * 1024, 0, 0, NULL);	if (rv != SECSuccess)	    errExit("SSL_ConfigMPServerSIDCache");	beAGoodParent(argc, argv, maxProcs, listen_sock);	exit(99); /* should never get here */    } else {	/* we're an ordinary single process server. */	listen_sock = getBoundListenSocket(port);	prStatus = PR_SetFDInheritable(listen_sock, PR_FALSE);	if (prStatus != PR_SUCCESS)	    errExit("PR_SetFDInheritable");	rv = SSL_ConfigServerSessionIDCache(32 * 1024, 0, 0, NULL);	if (rv != SECSuccess)	    errExit("SSL_ConfigServerSessionIDCache");    }    lm = PR_NewLogModule("TestCase");    /* allocate the array of thread slots */    threads = PR_Calloc(maxThreads, sizeof(perThread));    if ( NULL == threads )  {        fprintf(stderr, "Oh Drat! Can't allocate the perThread array\n");        goto mainExit;    }    if (fileName)    	readBigFile(fileName);    /* set our password function */    PK11_SetPasswordFunc( passwd ? ownPasswd : SECU_GetModulePassword);    /* Call the libsec initialization routines */    rv = NSS_Init(dir);    if (rv != SECSuccess) {    	fputs("NSS_Init failed.\n", stderr);		exit(8);    }    /* set the policy bits true for all the cipher suites. */    if (useExportPolicy)	NSS_SetExportPolicy();    else	NSS_SetDomesticPolicy();    /* all the SSL2 and SSL3 cipher suites are enabled by default. */    if (cipherString) {    	int ndx;	/* disable all the ciphers, then enable the ones we want. */	disableAllSSLCiphers();	while (0 != (ndx = *cipherString++)) {	    const int *cptr;	    int  cipher;	    if (! isalpha(ndx)) {		fprintf(stderr, 			"Non-alphabetic char in cipher string (-c arg).\n");		exit(9);	    }	    cptr = islower(ndx) ? ssl3CipherSuites : ssl2CipherSuites;	    for (ndx &= 0x1f; (cipher = *cptr++) != 0 && --ndx > 0; ) 		/* do nothing */;	    if (cipher) {		SECStatus status;		status = SSL_CipherPrefSetDefault(cipher, SSL_ALLOWED);		if (status != SECSuccess) 		    SECU_PrintError(progName, "SSL_CipherPrefSet()");	    }	}    }    if (nickName) {	cert[kt_rsa] = PK11_FindCertFromNickname(nickName, passwd);	if (cert[kt_rsa] == NULL) {	    fprintf(stderr, "selfserv: Can't find certificate %s\n", nickName);	    exit(10);	}	privKey[kt_rsa] = PK11_FindKeyByAnyCert(cert[kt_rsa], passwd);	if (privKey[kt_rsa] == NULL) {	    fprintf(stderr, "selfserv: Can't find Private Key for cert %s\n", nickName);	    exit(11);	}    }    if (fNickName) {	cert[kt_fortezza] = PK11_FindCertFromNickname(fNickName, NULL);	if (cert[kt_fortezza] == NULL) {	    fprintf(stderr, "selfserv: Can't find certificate %s\n", fNickName);	    exit(12);	}	privKey[kt_fortezza] = PK11_FindKeyByAnyCert(cert[kt_fortezza], NULL);    }    server_main(listen_sock, requestCert, privKey, cert);mainExit:    NSS_Shutdown();    PR_Cleanup();    return 0;}