📄 cimusercommand.cpp
字号:
*/ void setCommand ( ostream& outPrintWriter, ostream& errPrintWriter, Uint32 argc, char* argv[]); /** Executes the command and writes the results to the output streams. @param ostream The stream to which command output is written. @param ostream The stream to which command errors are written. @return 0 if the command is successful 1 if an error occurs in executing the command */ Uint32 execute ( ostream& outPrintWriter, ostream& errPrintWriter);private: // // Add a new user to the CIM Server // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception Exception if failed to add user // void _AddUser ( ostream& outPrintWriter, ostream& errPrintWriter ); // // Modify an existing user's password. // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception Exception if failed to modify password // void _ModifyUser ( ostream& outPrintWriter, ostream& errPrintWriter ); // // Remove an existing user from the CIM Server // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // // @exception Exception if failed to remove user // void _RemoveUser ( ostream& outPrintWriter, ostream& errPrintWriter ); // // List all users. // // @param ostream The stream to which command output is written. // @param ostream The stream to which command errors are written. // void _ListUsers ( ostream& outPrintWriter, ostream& errPrintWriter ); // // The CIM Client reference // AutoPtr<CIMClient> _client; //PEP101 // // The host name. // String _hostName; // // The name of the user. // String _userName; // // The password of the user. // String _password; // // The new password of the user. // String _newpassword; // // The type of operation specified on the command line. // Uint32 _operationType; // // Flags for command options // Boolean _userNameSet; Boolean _passwordSet; Boolean _newpasswordSet; String usage;};/** Constructs a CIMUserCommand and initializes instance variables.*/CIMUserCommand::CIMUserCommand (){ /** Initialize the instance variables. */ _operationType = OPERATION_TYPE_UNINITIALIZED; _userName = String::EMPTY; _password = String::EMPTY; _newpassword = String::EMPTY; _hostName = String::EMPTY; _passwordSet = false; _newpasswordSet = false; _userNameSet = false; /** Build the usage string for the config command. */ usage.reserveCapacity(200); usage.append(USAGE); usage.append(COMMAND_NAME); usage.append(" -").append(OPTION_ADD); usage.append(" -").append(OPTION_USER_NAME).append(" username"); usage.append(" [ -").append(OPTION_PASSWORD).append(" password") .append(" ] \n"); usage.append(" -").append(OPTION_MODIFY); usage.append(" -").append(OPTION_USER_NAME).append(" username"); usage.append(" [ -").append(OPTION_PASSWORD).append(" old password") .append(" ]"); usage.append(" [ -").append(OPTION_NEW_PASSWORD).append(" new password") .append(" ] \n"); usage.append(" -").append(OPTION_REMOVE); usage.append(" -").append(OPTION_USER_NAME).append(" username \n"); usage.append(" -").append(OPTION_LIST).append(" \n"); usage.append(" -").append(OPTION_HELP).append(" \n"); usage.append(" --").append(LONG_HELP).append(" \n"); usage.append(" --").append(LONG_VERSION).append(" \n"); usage.append("Options : \n"); usage.append(" -a - Add a new CIM user\n"); usage.append(" -h, --help - Display this help message\n"); usage.append(" -l - List the names of CIM users\n"); usage.append(" -m - Modify a CIM user's password\n"); usage.append(" -n - Supply a new password for the specified user name\n"); usage.append(" -r - Remove the specified CIM user\n"); usage.append(" -u - Specify a CIM user name\n"); usage.append(" --version - Display CIM Server version number\n"); usage.append(" -w - Supply a password for the specified user name\n"); usage.append("\nUsage note: The cimuser command requires that the CIM Server is running.\n"); setUsage (usage);}/** Parses the command line, validates the options, and sets instance variables based on the option arguments.*/void CIMUserCommand::setCommand ( ostream& outPrintWriter, ostream& errPrintWriter, Uint32 argc, char* argv[]){ Uint32 i = 0; Uint32 c = 0; String badOptionString = String (); String optString = String (); // // Construct optString // optString.append(OPTION_ADD); optString.append(OPTION_USER_NAME); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_PASSWORD); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_MODIFY); optString.append(OPTION_USER_NAME); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_PASSWORD); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_NEW_PASSWORD); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_REMOVE); optString.append(OPTION_USER_NAME); optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR); optString.append(OPTION_LIST); optString.append(OPTION_HELP); // // Initialize and parse options // getoopt options (""); options.addFlagspec(optString); //PEP#167 - adding long flag for options : 'help' and 'version' options.addLongFlagspec(LONG_HELP,getoopt::NOARG); options.addLongFlagspec(LONG_VERSION,getoopt::NOARG); options.parse (argc, argv); if (options.hasErrors ()) { throw CommandFormatException(options.getErrorStrings()[0]); } _operationType = OPERATION_TYPE_UNINITIALIZED; // // Get options and arguments from the command line // for (i = options.first (); i < options.last (); i++) { if (options[i].getType () == Optarg::LONGFLAG) { if (options[i].getopt () == LONG_HELP) { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { String param = String (LONG_HELP); // // More than one operation option was found // throw UnexpectedOptionException(param); } _operationType = OPERATION_TYPE_HELP; } else if (options[i].getopt () == LONG_VERSION) { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { String param = String (LONG_VERSION); // // More than one operation option was found // throw UnexpectedOptionException(param); } _operationType = OPERATION_TYPE_VERSION; } } else if (options [i].getType () == Optarg::REGULAR) { // // The cimuser command has no non-option argument options // throw UnexpectedArgumentException(options[i].Value()); } else /* if (options [i].getType () == Optarg::FLAG) */ { c = options [i].getopt () [0]; switch (c) { case OPTION_ADD: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_ADD); } if (options.isSet (OPTION_ADD) > 1) { // // More than one add user option was found // throw DuplicateOptionException(OPTION_ADD); } _operationType = OPERATION_TYPE_ADD; break; } case OPTION_MODIFY: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_MODIFY); } if (options.isSet (OPTION_MODIFY) > 1) { // // More than one modify user option was found // throw DuplicateOptionException(OPTION_MODIFY); } _operationType = OPERATION_TYPE_MODIFY; break; } case OPTION_USER_NAME: { if (options.isSet (OPTION_USER_NAME) > 1) { // // More than one username option was found // throw DuplicateOptionException(OPTION_USER_NAME); } _userName = options [i].Value (); _userNameSet = true; break; } case OPTION_PASSWORD: { if (options.isSet (OPTION_PASSWORD) > 1) { // // More than one password option was found // throw DuplicateOptionException(OPTION_PASSWORD); } String password = options [i].Value (); _password = password.subString(0,8); _passwordSet = true; break; } case OPTION_NEW_PASSWORD: { if (options.isSet (OPTION_NEW_PASSWORD) > 1) { // // More than one new password option was found // throw DuplicateOptionException(OPTION_NEW_PASSWORD); } String newpassword = options [i].Value (); _newpassword = newpassword.subString(0,8); _newpasswordSet = true; break; } case OPTION_REMOVE: { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { // // More than one operation option was found // throw UnexpectedOptionException(OPTION_REMOVE); } if (options.isSet (OPTION_REMOVE) > 1) { // // More than one remove user option was found //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -