📄 cimusercommand.cpp
字号:
throw DuplicateOptionException(OPTION_REMOVE); } _operationType = OPERATION_TYPE_REMOVE; break; } case OPTION_LIST: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_LIST); } if (options.isSet (OPTION_LIST) > 1) { // // More than one list option was found // throw DuplicateOptionException(OPTION_LIST); } _operationType = OPERATION_TYPE_LIST; break; } //PEP#167 - 2 new cases added below for HELP and VERSION case OPTION_HELP: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_HELP); } if (options.isSet (OPTION_HELP) > 1) { // // More than one list option was found // throw DuplicateOptionException(OPTION_HELP); } _operationType = OPERATION_TYPE_HELP; break; } case OPTION_VERSION: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_VERSION); } if (options.isSet (OPTION_VERSION) > 1) { // // More than one list option was found // throw DuplicateOptionException(OPTION_VERSION); } _operationType = OPERATION_TYPE_VERSION; break; } default: { // // Should never get here // break; } } } } // // Some more validations // if (_operationType == OPERATION_TYPE_UNINITIALIZED) { // // No operation type was specified // Show the usage // //l10n //CommandFormatException e (REQUIRED_ARGS_MISSING); throw CommandFormatException(localizeMessage( MSG_PATH, REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING)); } if (_operationType == OPERATION_TYPE_LIST && (_userNameSet || _passwordSet || _newpasswordSet)) { //l10n MessageLoaderParms parms("Clients.cimuser.CIMUserCommand.UNEXPECTED_OPTION", "Unexpected Option."); //CommandFormatException e("Unexpected Option."); throw CommandFormatException(parms); } if (_operationType == OPERATION_TYPE_ADD) { if (_newpasswordSet) { // // An invalid option was encountered // throw UnexpectedOptionException(OPTION_NEW_PASSWORD); } if (!_userNameSet) { // // An invalid option was encountered // throw MissingOptionException(OPTION_USER_NAME); } if (!_passwordSet) { // // Password is not set, prompt for the password // String pw = String::EMPTY; do { pw = System::getPassword(PASSWORD_PROMPT); if (pw == String::EMPTY || pw == "") { //l10n //errPrintWriter << PASSWORD_BLANK << endl; errPrintWriter << localizeMessage(MSG_PATH,PASSWORD_BLANK_KEY,PASSWORD_BLANK) << endl; pw = String::EMPTY; continue; } if (pw != System::getPassword(RE_ENTER_PROMPT)) { //l10n //errPrintWriter << PASSWORD_DOES_NOT_MATCH << endl; errPrintWriter << localizeMessage(MSG_PATH,PASSWORD_DOES_NOT_MATCH_KEY,PASSWORD_DOES_NOT_MATCH_KEY) << endl; pw = String::EMPTY; } } while (pw == String::EMPTY); _password = pw ; } } if (_operationType == OPERATION_TYPE_MODIFY) { if (!_userNameSet) { // // An invalid option was encountered // throw MissingOptionException(OPTION_USER_NAME); } if (_passwordSet && _newpasswordSet) { if (_newpassword == _password) { //l10n //cerr << PASSWORD_SAME_ERROR << endl; cerr << localizeMessage(MSG_PATH,PASSWORD_SAME_ERROR_KEY,PASSWORD_SAME_ERROR) << endl; exit (1); } } if (!_passwordSet) { // // Password is not set, prompt for the old password once // String pw = String::EMPTY; do { pw = System::getPassword(OLD_PASSWORD_PROMPT); if (pw == String::EMPTY || pw == "") { //l10n //errPrintWriter << PASSWORD_BLANK << endl; errPrintWriter << localizeMessage(MSG_PATH,PASSWORD_BLANK_KEY,PASSWORD_BLANK) << endl; pw = String::EMPTY; continue; } } while (pw == String::EMPTY); _password = pw ; } if (!_newpasswordSet) { // // Password is not set, prompt for the new password twice // String newPw = String::EMPTY; do { newPw = System::getPassword(NEW_PASSWORD_PROMPT); if (newPw == String::EMPTY || newPw == "") { //l10n //errPrintWriter << PASSWORD_BLANK << endl; errPrintWriter << localizeMessage(MSG_PATH,PASSWORD_BLANK_KEY,PASSWORD_BLANK) << endl; newPw = String::EMPTY; continue; } if (newPw != System::getPassword(RE_ENTER_PROMPT)) { //l10n //errPrintWriter << PASSWORD_DOES_NOT_MATCH << endl; errPrintWriter << localizeMessage(MSG_PATH,PASSWORD_DOES_NOT_MATCH_KEY,PASSWORD_DOES_NOT_MATCH) << endl; newPw = String::EMPTY; } } while (newPw == String::EMPTY); _newpassword = newPw ; if (_newpassword == _password) { //l10n //cerr << PASSWORD_SAME_ERROR << endl; cerr << localizeMessage(MSG_PATH,PASSWORD_SAME_ERROR_KEY, PASSWORD_SAME_ERROR) << endl; exit (-1); } } } if (_operationType == OPERATION_TYPE_REMOVE) { if (!_userNameSet) { // // An invalid option was encountered // throw MissingOptionException(OPTION_USER_NAME); } if (_passwordSet) { // // An invalid option was encountered // throw UnexpectedOptionException(OPTION_PASSWORD); } if (_newpasswordSet) { // // An invalid option was encountered // throw UnexpectedOptionException(OPTION_NEW_PASSWORD); } }}/** Executes the command and writes the results to the PrintWriters.*/Uint32 CIMUserCommand::execute ( ostream& outPrintWriter, ostream& errPrintWriter){ if (_operationType == OPERATION_TYPE_UNINITIALIZED) { // // The command was not initialized // return 1; } //PEP#167 - Added Options HELP and VERSION //PEP#167 - CIMServer need not be running for these to work else if (_operationType == OPERATION_TYPE_HELP) { cerr << usage << endl; return (RC_SUCCESS); } else if(_operationType == OPERATION_TYPE_VERSION) { cerr << "Version " << PEGASUS_PRODUCT_VERSION << endl; return (RC_SUCCESS); } // // Get local host name // _hostName.assign(System::getHostName()); try { // Construct the CIMClient and set to request server messages // in the default language of this client process. _client.reset(new CIMClient); _client->setRequestDefaultLanguages(); //l10n } catch (Exception & e) { errPrintWriter << e.getMessage() << endl; return (RC_ERROR); } try { // // Open connection with CIMSever // _client->connectLocal(); } catch(const Exception&) { //l10n //outPrintWriter << CIMOM_NOT_RUNNING << endl; outPrintWriter << localizeMessage(MSG_PATH,CIMOM_NOT_RUNNING_KEY,CIMOM_NOT_RUNNING) << endl; return 1; } // // Perform the requested operation // switch (_operationType) { case OPERATION_TYPE_ADD: try { _AddUser(outPrintWriter, errPrintWriter); } catch (CIMException& e) { CIMStatusCode code = e.getCode(); if (code == CIM_ERR_FAILED) { //l10n //outPrintWriter << ADD_USER_FAILURE << endl; outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl; errPrintWriter << e.getMessage() << endl; } else if (code == CIM_ERR_NOT_SUPPORTED) { //l10n //outPrintWriter << ADD_USER_FAILURE << endl; outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl; errPrintWriter << e.getMessage() << endl; } else if (code == CIM_ERR_ALREADY_EXISTS) { //l10n //outPrintWriter << ADD_USER_FAILURE << endl; outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl; //outPrintWriter << USER_ALREADY_EXISTS << endl; outPrintWriter << localizeMessage(MSG_PATH,USER_ALREADY_EXISTS_KEY,USER_ALREADY_EXISTS) << endl; errPrintWriter << e.getMessage() << endl; } else if (code == CIM_ERR_INVALID_CLASS) { //l10n //outPrintWriter << ADD_USER_FAILURE << endl; outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl; //outPrintWriter << AUTH_SCHEMA_NOT_LOADED << endl; outPrintWriter << localizeMessage(MSG_PATH,AUTH_SCHEMA_NOT_LOADED_KEY,AUTH_SCHEMA_NOT_LOADED) << endl; } else { errPrintWriter << e.getMessage() << endl; } return (RC_ERROR); } catch (Exception& e) { //l10n //outPrintWriter << ADD_USER_FAILURE << endl << //e.getMessage() << endl; outPrintWriter << localizeMessage(MSG_PATH,ADD_USER_FAILURE_KEY,ADD_USER_FAILURE) << endl << e.getMessage() << endl; return (RC_ERROR); } break; case OPERATION_TYPE_MODIFY: try { _ModifyUser(outPrintWriter, errPrintWriter); } catch (CIMException& e) { CIMStatusCode code = e.getCode(); if (code == CIM_ERR_FAILED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -