📄 osptnep.c
字号:
ospvStringLowercaseOut[ inputStringIndex ] = (char)(OSPM_TOLOWER( ospvStringIn[ inputStringIndex ]) ); } ospvStringLowercaseOut[ inputStringIndex ] = 0; } OSPM_DBGEXIT(( "EXIT: OSPPEnrollStringLowercase\n" )); return retVal;}/* * This function will parse the parameters that are sent on the command line. * * Input: * ospvArgc ( a count of all the parameters in ospvArgv ) * ospvArgv ( all of the input parameters to be parsed ) * enrollParams ( a structure with all of the parameters that could * possibly be collected on the command line ) * */int OSPPEnrollParseParameters ( int ospvArgc, char* ospvArgv[], OSPTENROLLPARAMS* enrollParams ){ /* The return value of this function; it's initially set to true, * and gets set to the subsequent value of each function call. */ int retVal = OSPC_ERR_NO_ERROR; /* The next argument in the parameter list, converted to lowercase * ( for the sake of comparisons. ) */ char nextArg[10000]; /* The index into the list of arguments: */ int argvIndex = 0; OSPM_DBGENTER(( "ENTER: OSPPEnrollParseParameters\n" )); if ( ( enrollParams == OSPC_OSNULL ) || ( ospvArgv == OSPC_OSNULL ) || ( ospvArgc <= 2 ) ) { retVal = OSPC_ERR_ENROLL_INVALID_ARG; OSPM_DBGERRORLOG( retVal, "The parameters passed in for parsing are invalid.\n" ); /* Tell the user how to use the program, but only if we know what * command was entered on the command line to begin with: */ if ( ( ospvArgv != OSPC_OSNULL ) && ( ospvArgv[0] != OSPC_OSNULL ) ) { OSPPEnrollUsage( ospvArgv[0], OSPC_ENROLL_HELP_MSG ); } /* Else * o use the default command for enrollment, just for the sake * of syntax: */ else { OSPPEnrollUsage( OSPC_ENROLL_DEFAULT_CMD, OSPC_ENROLL_HELP_MSG ); } } /* For ( all of the arguments in the list, as long as there are no errors ) * o get the lowercase version of the next argument * o if ( the arg could be converted to lowercase ) then * - compare it to each possible argument and check its validity. * - set the return value to an error code if anything goes wrong. */ else { for ( argvIndex = 1; ( argvIndex < ospvArgc ) && ( retVal == OSPC_ERR_NO_ERROR ); argvIndex++ ) { retVal = OSPPEnrollStringLowercase( ospvArgv[ argvIndex ], nextArg ); if ( ( retVal == OSPC_ERR_NO_ERROR ) && ( nextArg != OSPC_OSNULL ) ) { if ( argvIndex < ospvArgc - 1 ) { if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_FUNCTION_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->Function), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->Function == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_FUNCTION; OSPM_DBGERRORLOG( retVal, "Unable to copy the operation.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_USERNAME_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->Username), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->Username == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_USERNAME; OSPM_DBGERRORLOG( retVal, "Unable to copy the username.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_PASSWORD_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->Password), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->Password == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_PASSWORD; OSPM_DBGERRORLOG( retVal, "Unable to copy the password.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_DEVICEID_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->DeviceId), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->DeviceId == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_DEVICEID; OSPM_DBGERRORLOG( retVal, "Unable to copy the device id.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_CUSTOMERID_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->CustomerId), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->CustomerId == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_CUSTOMERID; OSPM_DBGERRORLOG( retVal, "Unable to copy the customer id.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_CA_URL_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->CAUrl), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->CAUrl == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_CA_URL; OSPM_DBGERRORLOG( retVal, "Unable to copy the CA's url.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_SSL_URL_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->SSLUrl), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->SSLUrl == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_SSL_URL; OSPM_DBGERRORLOG( retVal, "Unable to copy the enrollment server's url.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_CACERT_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->CACertB64 ), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->CACertB64 == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_CACERT; OSPM_DBGERRORLOG( retVal, "Unable to copy the CA's certificate.\n" ); } else { enrollParams->CACertB64Len = OSPM_STRLEN( (const char *)enrollParams->CACertB64 ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_CERTREQ_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->CertReq ), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->CertReq == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_CERTREQ; OSPM_DBGERRORLOG( retVal, "Unable to copy the cert request.\n" ); } } else if ( OSPM_STRCMP( nextArg, OSPC_ENROLL_CA_FPRINT_PARAM ) == 0 ) { retVal = OSPPCopyString( &(enrollParams->CAFprint), (unsigned char *)ospvArgv[ argvIndex + 1 ] ); if ( ( retVal != OSPC_ERR_NO_ERROR ) || ( enrollParams->CAFprint == OSPC_OSNULL ) ) { retVal = OSPC_ERR_ENROLL_PARAMS_CA_FPRINT; OSPM_DBGERRORLOG( retVal, "Unable to copy the CA cert's fingerprint.\n" ); } } } /* End of test for what to do if the argument is binary */ /* We can do all of the unary arguments separately from the * binary arguments, since the binary arguments require some * sort of parameter value. The unary arguments shouldn't be * the same as the binary arguments ( otherwise there's a naming * collision ), so this should be acceptable. */ if ( ( OSPM_STRCMP( nextArg, OSPC_ENROLL_VERBOSE_PARAM ) == 0 ) || ( OSPM_STRCMP( nextArg, OSPC_ENROLL_DEBUG_PARAM ) == 0 ) ) { enrollParams->Verbose = OSPC_TRUE; } if ( retVal != OSPC_ERR_NO_ERROR ) { OSPM_DBGERRORLOG( retVal, "An invalid enrollment parameter was parsed.\n" ); } } /* End of test for whether the next argument is non-null */ } /* End of for loop for arguments */ if ( retVal != OSPC_ERR_NO_ERROR ) { if ( ospvArgv[0] != OSPC_OSNULL ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -