SECU_RegisterDynamicOids();
main (int argc, char **argv){    int		 retval;    char	*program_name;    PRFileDesc	*in_file;    FILE	*out_file;	/* not PRFileDesc until SECU accepts it */    int		 crequest, dresponse;    int		 prequest, presponse;    int		 ccert, vcert;    const char	*db_dir, *date_str, *cert_usage_str, *name;    const char	*responder_name, *responder_url, *signer_name;    PRBool	 add_acceptable_responses, add_service_locator;    SECItem	*data = NULL;    PLOptState	*optstate;    SECStatus	 rv;    CERTCertDBHandle *handle = NULL;    SECCertUsage cert_usage;    int64	 verify_time;    retval = -1;		/* what we return/exit with on error */    program_name = PL_strrchr(argv[0], '/');    program_name = program_name ? (program_name + 1) : argv[0];    in_file = PR_STDIN;    out_file = stdout;    crequest = 0;    dresponse = 0;    prequest = 0;    presponse = 0;    ccert = 0;    vcert = 0;    db_dir = NULL;    date_str = NULL;    cert_usage_str = NULL;    name = NULL;    responder_name = NULL;    responder_url = NULL;    signer_name = NULL;    add_acceptable_responses = PR_FALSE;    add_service_locator = PR_FALSE;    optstate = PL_CreateOptState (argc, argv, "AHLPR:S:V:d:l:pr:s:t:u:w:");    if (optstate == NULL) {	SECU_PrintError (program_name, "PL_CreateOptState failed");	return retval;    }    while (PL_GetNextOpt (optstate) == PL_OPT_OK) {	switch (optstate->option) {	  case '?':	    short_usage (program_name);	    return retval;	  case 'A':	    add_acceptable_responses = PR_TRUE;	    break;	  case 'H':	    long_usage (program_name);	    return retval;	  case 'L':	    add_service_locator = PR_TRUE;	    break;	  case 'P':	    presponse = 1;	    break;	  case 'R':	    dresponse = 1;	    name = optstate->value;	    break;	  case 'S':	    ccert = 1;	    name = optstate->value;	    break;	  case 'V':	    vcert = 1;	    name = optstate->value;	    break;	  case 'd':	    db_dir = optstate->value;	    break;	  case 'l':	    responder_url = optstate->value;	    break;	  case 'p':	    prequest = 1;	    break;	  case 'r':	    crequest = 1;	    name = optstate->value;	    break;	  case 's':	    signer_name = optstate->value;	    break;	  case 't':	    responder_name = optstate->value;	    break;	  case 'u':	    cert_usage_str = optstate->value;	    break;	  case 'w':	    date_str = optstate->value;	    break;	}    }    if ((crequest + dresponse + prequest + presponse + ccert + vcert) != 1) {	PR_fprintf (PR_STDERR, "%s: must specify exactly one command\n\n",		    program_name);	short_usage (program_name);	return retval;    }    if (vcert) {	if (cert_usage_str == NULL) {	    PR_fprintf (PR_STDERR, "%s: verification requires cert usage\n\n",			program_name);	    short_usage (program_name);	    return retval;	}	rv = cert_usage_from_char (cert_usage_str, &cert_usage);	if (rv != SECSuccess) {	    PR_fprintf (PR_STDERR, "%s: invalid cert usage (\"%s\")\n\n",			program_name, cert_usage_str);	    long_usage (program_name);	    return retval;	}    }    if (ccert + vcert) {	if (responder_url != NULL || responder_name != NULL) {	    /*	     * To do a full status check, both the URL and the cert name	     * of the responder must be specified if either one is.	     */	    if (responder_url == NULL || responder_name == NULL) {		if (responder_url == NULL)		    PR_fprintf (PR_STDERR,				"%s: must also specify responder location\n\n",				program_name);		else		    PR_fprintf (PR_STDERR,				"%s: must also specify responder name\n\n",				program_name);		short_usage (program_name);		return retval;	    }	}	if (date_str != NULL) {	    rv = DER_AsciiToTime (&verify_time, (char *) date_str);	    if (rv != SECSuccess) {		SECU_PrintError (program_name, "error converting time string");		PR_fprintf (PR_STDERR, "\n");		long_usage (program_name);		return retval;	    }	} else {	    verify_time = PR_Now();	}    }    retval = -2;		/* errors change from usage to runtime */    /*     * Initialize the NSPR and Security libraries.     */    PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);    db_dir = SECU_ConfigDirectory (db_dir);    rv = NSS_Init (db_dir);    if (rv != SECSuccess) {	SECU_PrintError (program_name, "NSS_Init failed");	goto prdone;    }    if (prequest + presponse) {	data = read_file_into_item (in_file, siBuffer);	if (data == NULL) {	    SECU_PrintError (program_name, "problem reading input");	    goto nssdone;	}    }    if (crequest + dresponse + presponse + ccert + vcert) {	handle = CERT_GetDefaultCertDB();	if (handle == NULL) {	    SECU_PrintError (program_name, "problem getting certdb handle");	    goto nssdone;	}	/*	 * It would be fine to do the enable for all of these commands,	 * but this way we check that everything but an overall verify	 * can be done without it.  That is, that the individual pieces	 * work on their own.	 */	if (vcert) {	    rv = CERT_EnableOCSPChecking (handle);	    if (rv != SECSuccess) {		SECU_PrintError (program_name, "error enabling OCSP checking");		goto nssdone;	    }	}	if ((ccert + vcert) && (responder_name != NULL)) {	    rv = CERT_SetOCSPDefaultResponder (handle, responder_url,					       responder_name);	    if (rv != SECSuccess) {		SECU_PrintError (program_name,				 "error setting default responder");		goto nssdone;	    }	    rv = CERT_EnableOCSPDefaultResponder (handle);	    if (rv != SECSuccess) {		SECU_PrintError (program_name,				 "error enabling default responder");		goto nssdone;	    }	}    }#define NOTYET(opt)							\	{								\	    PR_fprintf (PR_STDERR, "%s not yet working\n", opt);	\	    exit (-1);							\	}    if (crequest) {	if (signer_name != NULL) {	    NOTYET("-s");	}	rv = create_request (out_file, handle, name, add_service_locator,			     add_acceptable_responses);    } else if (dresponse) {	if (signer_name != NULL) {	    NOTYET("-s");	}	rv = dump_response (out_file, handle, name, responder_url);    } else if (prequest) {	rv = print_request (out_file, data);    } else if (presponse) {	rv = print_response (out_file, data, handle);    } else if (ccert) {	if (signer_name != NULL) {	    NOTYET("-s");	}	rv = get_cert_status (out_file, handle, name, verify_time);    } else if (vcert) {	if (signer_name != NULL) {	    NOTYET("-s");	}	rv = verify_cert (out_file, handle, name, cert_usage, verify_time);    }    if (rv != SECSuccess)	SECU_PrintError (program_name, "error performing requested operation");    else	retval = 0;nssdone:    if (data != NULL) {	SECITEM_FreeItem (data, PR_TRUE);    }    if (handle != NULL) {	(void) CERT_DisableOCSPChecking (handle);    }    if (NSS_Shutdown () != SECSuccess) {	exit(1);    }prdone:    PR_Cleanup ();    return retval;}