📄 cimauthcommand.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Nag Boranna, Hewlett Packard Company (nagaraja_boranna@hp.com)//// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)// Alagaraja Ramasubramanian, IBM (alags_raj@in.ibm.com) - PEP-167// Amit K Arora, IBM (amitarora@in.ibm.com) - Bug#2311,#2333,#2351// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - PEP#101, Bug#2756// David Dillard, VERITAS Software Corp.// (david.dillard@veritas.com)// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3032////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/AutoPtr.h>#include <iostream>#include <Clients/cliutils/Command.h>#include <Clients/cliutils/CommandException.h>#include <Pegasus/getoopt/getoopt.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/CIMProperty.h>#include <Pegasus/Common/CIMObjectPath.h>#include <Pegasus/Common/CIMStatusCode.h>#include <Pegasus/Common/Config.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/MessageLoader.h> //l10n#include <Pegasus/Common/PegasusVersion.h>#ifdef PEGASUS_OS_OS400#include "qycmutiltyUtility.H"#endifPEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN//l10n/** * The CLI message resource name */static const char MSG_PATH [] = "pegasus/pegasusCLI";//l10n end/** The command name.*/static const char COMMAND_NAME [] = "cimauth";/** This constant represents the name of the User name property in the schema*/static const CIMName PROPERTY_NAME_USERNAME = CIMName ("Username");/** This constant represents the name of the Namespace property in the schema*/static const CIMName PROPERTY_NAME_NAMESPACE = CIMName ("Namespace");/** This constant represents the name of the authorizations property in the schema*/static const CIMName PROPERTY_NAME_AUTHORIZATION = CIMName ("Authorization");/** The usage string for this command. This string is displayed when an error occurs in parsing or validating the command line.*/static const char USAGE [] = "Usage: ";/** This constant represents the getoopt argument designator*/static const char GETOPT_ARGUMENT_DESIGNATOR = ':';/* These constants represent the operation modes supported by the CLI. Any new operation should be added here.*//** This constant signifies that an operation option has not been recorded*/static const Uint32 OPERATION_TYPE_UNINITIALIZED = 0;/** This constant represents a add user operation*/static const Uint32 OPERATION_TYPE_ADD = 1;/** This constant represents a add user operation*/static const Uint32 OPERATION_TYPE_MODIFY = 2;/** This constant represents a remove user operation*/static const Uint32 OPERATION_TYPE_REMOVE = 3;/** This constant represents a list operation*/static const Uint32 OPERATION_TYPE_LIST = 4;/** This constant represents a help operation*/static const Uint32 OPERATION_TYPE_HELP = 5;/** This constant represents a version display operation*/static const Uint32 OPERATION_TYPE_VERSION = 6;/** The constants representing the messages.*///l10n default messages and corresponding resource keysstatic const char NOT_PRIVILEGED_USER [] = "You must have superuser privilege to run this command.";static const char NOT_PRIVILEGED_USER_KEY [] = "Clients.cimauth.CIMAuthCommand.NOT_PRIVILEGED_USER";static const char CIMOM_NOT_RUNNING [] = "CIM Server may not be running.";static const char CIMOM_NOT_RUNNING_KEY [] = "Clients.cimauth.CIMAuthCommand.CIMOM_NOT_RUNNING";static const char FILE_NOT_READABLE [] = "Unable to read the config file.";static const char FILE_NOT_READABLE_KEY [] = "Clients.cimauth.CIMAuthCommand.FILE_NOT_READABLE";static const char ADD_AUTH_FAILURE [] = "Failed to add authorizations.";static const char ADD_AUTH_FAILURE_KEY [] = "Clients.cimauth.CIMAuthCommand.ADD_AUTH_FAILURE";static const char MODIFY_AUTH_FAILURE [] = "Failed to modify authorizations.";static const char MODIFY_AUTH_FAILURE_KEY [] = "Clients.cimauth.CIMAuthCommand.MODIFY_AUTH_FAILURE";static const char REMOVE_AUTH_FAILURE [] = "Failed to remove authorizations.";static const char REMOVE_AUTH_FAILURE_KEY [] = "Clients.cimauth.CIMAuthCommand.REMOVE_AUTH_FAILURE";static const char LIST_AUTH_FAILURE [] = "Failed to list the users. ";static const char LIST_AUTH_FAILURE_KEY [] = "Clients.cimauth.CIMAuthCommand.LIST_AUTH_FAILURE";static const char ADD_AUTH_SUCCESS [] = "Authorizations added successfully.";static const char ADD_AUTH_SUCCESS_KEY [] = "Clients.cimauth.CIMAuthCommand.ADD_AUTH_SUCCESS";static const char MODIFY_AUTH_SUCCESS [] = "Authorizations modified successfully.";static const char MODIFY_AUTH_SUCCESS_KEY [] = "Clients.cimauth.CIMAuthCommand.MODIFY_AUTH_SUCCESS";static const char REMOVE_AUTH_SUCCESS [] = "Authorizations removed successfully.";static const char REMOVE_AUTH_SUCCESS_KEY [] = "Clients.cimauth.CIMAuthCommand.REMOVE_AUTH_SUCCESS";static const char NO_AUTHS_FOUND [] = "No user authorizations found for listing.";static const char NO_AUTHS_FOUND_KEY [] = "Clients.cimauth.CIMAuthCommand.NO_AUTHS_FOUND";static const char AUTH_SCHEMA_NOT_LOADED [] = "Please restore the internal repository on the CIM Server.";static const char AUTH_SCHEMA_NOT_LOADED_KEY [] = "Clients.cimauth.CIMAuthCommand.AUTH_SCHEMA_NOT_LOADED";static const char REQUIRED_ARGS_MISSING [] = "Required arguments missing.";static const char REQUIRED_ARGS_MISSING_KEY [] = "Clients.cimauth.CIMAuthCommand.REQUIRED_ARGS_MISSING";static const char AUTH_ALREADY_EXISTS [] = "Specified user authorizations already exist.";static const char AUTH_ALREADY_EXISTS_KEY [] = "Clients.cimauth.CIMAuthCommand.AUTH_ALREADY_EXISTS";static const char AUTH_NOT_FOUND [] = "Specified user authorizations were not found.";static const char AUTH_NOT_FOUND_KEY [] = "Clients.cimauth.CIMAuthCommand.AUTH_NOT_FOUND";static const char ERR_OPTION_NOT_SUPPORTED_KEY [] = "Clients.cimauth.CIMAuthCommand.ERR_OPTION_NOT_SUPPORTED";static const char ERR_OPTION_NOT_SUPPORTED [] = "Invalid option. Use '--help' to obtain command syntax.";static const char ERR_USAGE_KEY [] = "Clients.cimauth.CIMAuthCommand.ERR_USAGE";static const char ERR_USAGE [] = "Incorrect usage. Use '--help' to obtain command syntax.";//l10n end default messages and resource keys/** The constant representing the user provider class name*/static const char PG_USER_MGR_PROV_CLASS [] = "PG_UserManager";static const char LONG_HELP [] = "help";static const char LONG_VERSION [] = "version";/** The option character used to specify add user.*/static const char OPTION_ADD = 'a';/** The option character used to specify modify user.*/static const char OPTION_MODIFY = 'm';/** The option character used to specify user name.*/static const char OPTION_USER_NAME = 'u';/** The option character used to specify password.*/static const char OPTION_NAMESPACE = 'n';/** The option character used to specify read permision.*/static const char OPTION_READ = 'R';/** The option character used to specify write permision.*/static const char OPTION_WRITE = 'W';/** The option character used to specify remove user.*/static const char OPTION_REMOVE = 'r';/** The option character used to specify listing of users.*/static const char OPTION_LIST = 'l';/** The option character used to display help info.*/static const char OPTION_HELP = 'h';/** The option character used to display version info.*/static const char OPTION_VERSION = 'v';/**This is a CLI used to manage users of the CIM Server. This command supportsoperations to add, modify, list and remove users.@author Nag Boranna, Hewlett-Packard Company*/class CIMAuthCommand : public Command{public: /** Constructs a CIMAuthCommand and initializes instance variables. */ CIMAuthCommand (); /** Parses the command line, validates the options, and sets instance variables based on the option arguments. @param args The string array containing the command line arguments @param argc The int containing the arguments count @throws CommandFormatException if an error is encountered in parsing the command line */ void setCommand (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 ( PEGASUS_STD(ostream)& outPrintWriter, PEGASUS_STD(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 _AddAuthorization ( PEGASUS_STD(ostream)& outPrintWriter, PEGASUS_STD(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 _ModifyAuthorization ( PEGASUS_STD(ostream)& outPrintWriter, PEGASUS_STD(ostream)& errPrintWriter );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -