📄 cimtrustcommand.cpp
字号:
} if ( _operationType == _OPERATION_TYPE_ADD ) { // // For -a option, the next required option is -f, // make sure it is set. // if ( !_certFileSet ) { // // A required option is missing // MissingOptionException e (_OPTION_CERTFILE); throw e; } if ( !_typeSet ) { // // A required option is missing // MissingOptionException e (_OPTION_TYPE); throw e; } if (!(_type == _ARG_TYPE_AUTHORITY || _type == _ARG_TYPE_AUTHORITY_END_ENTITY || _type == _ARG_TYPE_SELF_SIGNED_IDENTITY )) { InvalidOptionArgumentException e (_type, _OPTION_TYPE); throw e; } if ((_type == _ARG_TYPE_AUTHORITY_END_ENTITY || _type == _ARG_TYPE_SELF_SIGNED_IDENTITY) && !_certUserSet) { // // A required option is missing // MissingOptionException e (_OPTION_CERTUSER); throw e; } } if ( _operationType == _OPERATION_TYPE_REMOVE || _operationType == _OPERATION_TYPE_LIST ) { if ( _operationType == _OPERATION_TYPE_REMOVE ) { if (_certFileSet) { UnexpectedOptionException e (_OPTION_CERTFILE); throw e; } if (_certUserSet) { UnexpectedOptionException e (_OPTION_CERTUSER); throw e; } // // For -r option, the required option is -i, // make sure it is set. // if ( !_issuerSet ) { // // A required option is missing // MissingOptionException e (_OPTION_ISSUER); throw e; } else if ( !_serialNumberSet && !_subjectSet ) { // // A required option is missing // CommandFormatException e ( localizeMessage ( MSG_PATH, REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING ) ); throw e; } } else if ( _operationType == _OPERATION_TYPE_LIST ) { // // For -l option, there is no required option. // // // Serial number specified without issuer name // if ( (_serialNumberSet || _subjectSet) && !_issuerSet ) { MissingOptionException e (_OPTION_ISSUER); throw e; } } }}/** Executes the command and writes the results to the PrintWriters. @param outPrintWriter the ostream to which output should be written @param errPrintWriter the ostream to which error output should be written @return 0 if the command is successful 1 if an error occurs in executing the command */Uint32 CIMTrustCommand::execute ( ostream& outPrintWriter, ostream& errPrintWriter){ if ( _operationType == _OPERATION_TYPE_UNINITIALIZED ) { // // The command was not initialized // return 1; } // // Check if a specified certificate user is valid // if (_certUserSet) { if (!System::isSystemUser(_certUser.getCString())) { outPrintWriter << localizeMessage(MSG_PATH, INVALID_SYSTEM_USER_KEY, INVALID_SYSTEM_USER) << endl; return ( RC_INVALID_SYSTEM_USER ); } } // // Options HELP and VERSION // CIMServer need not be running for these options to work // else if (_operationType == _OPERATION_TYPE_HELP) { errPrintWriter << _usage << endl; return (RC_SUCCESS); } else if(_operationType == _OPERATION_TYPE_VERSION) { errPrintWriter << "Version " << PEGASUS_PRODUCT_VERSION << endl; return (RC_SUCCESS); } CIMClient client; client.setTimeout( _timeout ); client.setRequestDefaultLanguages(); //l10n try { _connectToServer( client, outPrintWriter); } catch(CannotConnectException& cce) { outPrintWriter << localizeMessage( MSG_PATH, CANNOT_CONNECT_CIMSERVER_NOT_RUNNING_KEY, CANNOT_CONNECT_CIMSERVER_NOT_RUNNING) << endl; return ( RC_CONNECTION_FAILED ); } catch(Exception& e) { //l10n outPrintWriter << e.getMessage() << endl; return (RC_ERROR); } // // Perform the requested operation // switch ( _operationType ) { case _OPERATION_TYPE_ADD: try { _addCertificate( client, outPrintWriter ); } catch (ConnectionTimeoutException& cte) { outPrintWriter << localizeMessage(MSG_PATH, CONNECTION_TIMEOUT_KEY, CONNECTION_TIMEOUT); return ( RC_CONNECTION_TIMEOUT ); } catch (CIMException& e) { CIMStatusCode code = e.getCode(); if (code == CIM_ERR_FAILED || code == CIM_ERR_NOT_SUPPORTED) { outPrintWriter << localizeMessage(MSG_PATH, ADD_CERT_FAILURE_KEY, ADD_CERT_FAILURE) << endl; errPrintWriter << e.getMessage() << endl; } else if (code == CIM_ERR_ALREADY_EXISTS) { outPrintWriter << localizeMessage(MSG_PATH, ADD_CERT_FAILURE_KEY, ADD_CERT_FAILURE) << endl; outPrintWriter << localizeMessage(MSG_PATH, CERT_ALREADY_EXISTS_KEY, CERT_ALREADY_EXISTS) << endl; errPrintWriter << e.getMessage() << endl; return ( RC_CERTIFICATE_ALREADY_EXISTS ); } else if (code == CIM_ERR_INVALID_CLASS) { outPrintWriter << localizeMessage(MSG_PATH, ADD_CERT_FAILURE_KEY, ADD_CERT_FAILURE) << endl; outPrintWriter << localizeMessage(MSG_PATH, CERT_SCHEMA_NOT_LOADED_KEY, CERT_SCHEMA_NOT_LOADED) << endl; } else { errPrintWriter << e.getMessage() << endl; } return ( RC_ERROR ); } catch (Exception& e) { outPrintWriter << localizeMessage(MSG_PATH, ADD_CERT_FAILURE_KEY, ADD_CERT_FAILURE) << endl << e.getMessage() << endl; return ( RC_ERROR ); } break; case _OPERATION_TYPE_REMOVE: try { _removeCertificate ( client, outPrintWriter ); } catch (ConnectionTimeoutException& cte) { outPrintWriter << localizeMessage(MSG_PATH, CONNECTION_TIMEOUT_KEY, CONNECTION_TIMEOUT); return ( RC_CONNECTION_TIMEOUT ); } catch (CIMException& e) { CIMStatusCode code = e.getCode(); if (code == CIM_ERR_FAILED || code == CIM_ERR_NOT_SUPPORTED) { outPrintWriter << localizeMessage(MSG_PATH, REMOVE_CERT_FAILURE_KEY, REMOVE_CERT_FAILURE) << endl; errPrintWriter << e.getMessage() << endl; } else if (code == CIM_ERR_NOT_FOUND) { outPrintWriter << localizeMessage(MSG_PATH, REMOVE_CERT_FAILURE_KEY, REMOVE_CERT_FAILURE) << endl; outPrintWriter << localizeMessage(MSG_PATH, CERT_NOT_FOUND_KEY, CERT_NOT_FOUND) << endl; errPrintWriter << e.getMessage() << endl; return ( RC_CERTIFICATE_DOES_NOT_EXIST ); } else if (code == CIM_ERR_INVALID_CLASS) { outPrintWriter << localizeMessage(MSG_PATH, REMOVE_CERT_FAILURE_KEY, REMOVE_CERT_FAILURE) << endl; outPrintWriter << localizeMessage(MSG_PATH, CERT_SCHEMA_NOT_LOADED_KEY, CERT_SCHEMA_NOT_LOADED) << endl; } else { errPrintWriter << e.getMessage() << endl; } return ( RC_ERROR ); } catch (Exception& e) { outPrintWriter << localizeMessage(MSG_PATH, REMOVE_CERT_FAILURE_KEY, REMOVE_CERT_FAILURE) << endl << e.getMessage() << endl; return ( RC_ERROR ); } break; case _OPERATION_TYPE_LIST: try { _listCertificates ( client, outPrintWriter ); } catch (ConnectionTimeoutException& cte) { outPrintWriter << localizeMessage(MSG_PATH, CONNECTION_TIMEOUT_KEY, CONNECTION_TIMEOUT); return ( RC_CONNECTION_TIMEOUT ); } catch (CIMException& e) { CIMStatusCode code = e.getCode(); if (code == CIM_ERR_NOT_FOUND) { return ( RC_CERTIFICATE_DOES_NOT_EXIST ); } if (code == CIM_ERR_FAILED || code == CIM_ERR_NOT_SUPPORTED) { outPrintWriter << localizeMessage(MSG_PATH, LIST_CERT_FAILURE_KEY, LIST_CERT_FAILURE) << endl; errPrintWriter << e.getMessage() << endl; } else if (code == CIM_ERR_INVALID_CLASS) { outPrintWriter << localizeMessage(MSG_PATH, LIST_CERT_FAILURE_KEY, LIST_CERT_FAILURE) << endl; outPrintWriter << localizeMessage(MSG_PATH, CERT_SCHEMA_NOT_LOADED_KEY, CERT_SCHEMA_NOT_LOADED) << endl; } else { errPrintWriter << e.getMessage() << endl; } return ( RC_ERROR ); } catch (Exception& e) { outPrintWriter << localizeMessage(MSG_PATH, LIST_CERT_FAILURE_KEY, LIST_CERT_FAILURE) << endl << e.getMessage() << endl; return ( RC_ERROR ); } break; default: // // This path should not be hit // break; } return (RC_SUCCESS);}PEGASUS_NAMESPACE_END// exclude main from the Pegasus NamespacePEGASUS_USING_PEGASUS;PEGASUS_USING_STD;////////////////////////////////////////////////////////////////////////////** Parses the command line, and executes the command. @param argc the number of command line arguments @param argv the string vector of command line arguments @return 0 if the command is successful 1 if an error occurs in executing the command *////////////////////////////////////////////////////////////////////////////int main (int argc, char* argv []){ //l10n set message loading to process locale MessageLoader::_useProcessLocale = true; CIMTrustCommand command = CIMTrustCommand(); int retCode; try { command.setCommand (argc, argv); } catch (CommandFormatException& cfe) { cerr << CIMTrustCommand::COMMAND_NAME << ": " << cfe.getMessage () << endl; cerr << "Use '--help' to obtain command syntax." << endl; exit (Command::RC_ERROR); } retCode = command.execute (cout, cerr); exit (retCode); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -