⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimauthcommand.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    //    // 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 _RemoveAuthorization        (        PEGASUS_STD(ostream)& outPrintWriter,        PEGASUS_STD(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 _ListAuthorization    (        PEGASUS_STD(ostream)& outPrintWriter,        PEGASUS_STD(ostream)& errPrintWriter    );    //    // The CIM Client reference    //    AutoPtr<CIMClient>    _client;    //    // The host name.    //    String        _hostName;    //    // The name of the user.    //    String        _userName;    //    // The namespace.    //    String        _namespace;    //    // The authorization capability.    //    String        _authorizations;    //    // The type of operation specified on the command line.    //    Uint32        _operationType;    //    // Flags for command options    //    Boolean       _userNameSet;    Boolean       _namespaceSet;    Boolean       _readFlagSet;    Boolean       _writeFlagSet;    //String for usage information    String usage;};/**    Constructs a CIMAuthCommand and initializes instance variables.*/CIMAuthCommand::CIMAuthCommand (){    /**        Initialize the instance variables.    */    _operationType       = OPERATION_TYPE_UNINITIALIZED;    _userName            = String::EMPTY;    _namespace           = String::EMPTY;    _authorizations      = String::EMPTY;    _hostName            = String::EMPTY;    _namespaceSet        = false;    _userNameSet         = false;    _readFlagSet         = false;    _writeFlagSet        = false;    /**        Build the usage string for the config command.    */    usage.reserveCapacity(200);    //l10n    //localize usage keyword:    //MessageLoaderParms parms("Clients.CLI.USAGE_STRING","usage: ");    //String USAGE_L = MessageLoader::getMessage(parms);    //usage.append(USAGE_L);    usage.append(USAGE);    usage.append(COMMAND_NAME);    usage.append(" -").append(OPTION_ADD);    usage.append(" -").append(OPTION_USER_NAME).append(" username");    usage.append(" -").append(OPTION_NAMESPACE).append(" namespace");    usage.append(" [ -").append(OPTION_READ).append(" ]");    usage.append(" [ -").append(OPTION_WRITE).append(" ] \n");    usage.append("               -").append(OPTION_MODIFY);    usage.append(" -").append(OPTION_USER_NAME).append(" username");    usage.append(" -").append(OPTION_NAMESPACE).append(" namespace");    usage.append(" [ -").append(OPTION_READ).append(" ]");    usage.append(" [ -").append(OPTION_WRITE).append(" ] \n");    usage.append("               -").append(OPTION_REMOVE);    usage.append(" -").append(OPTION_USER_NAME).append(" username");    usage.append(" [ -").append(OPTION_NAMESPACE).append(" namespace ]\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 authorizations for a user on a namespace\n");    usage.append("    -h, --help - Display this help message\n");    usage.append("    -l         - Display the authorizations of all the authorized users\n");    usage.append("    -m         - Modify authorizations for a user on a namespace\n");    usage.append("    -n         - Use the specified namespace\n");    usage.append("    -r         - Remove authorizations for a user on a namespace\n");    usage.append("    -R         - Specify a READ authorization (Default)\n");    usage.append("    -u         - Perform operations for the specified user name\n");    usage.append("    --version  - Display CIM Server version number\n");    usage.append("    -W         - Specify a WRITE authorization\n");    usage.append("\nUsage note: The cimauth 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.    @exception CommandFormatException*/void CIMAuthCommand::setCommand (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_NAMESPACE);    optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append(OPTION_MODIFY);    optString.append(OPTION_USER_NAME);    optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append(OPTION_NAMESPACE);    optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append(OPTION_REMOVE);    optString.append(OPTION_USER_NAME);    optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append(OPTION_NAMESPACE);    optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append(OPTION_LIST);    optString.append(OPTION_READ);    optString.append(OPTION_WRITE);    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 cimauth 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_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                        //                        throw DuplicateOptionException(OPTION_REMOVE);                    }                    _operationType = OPERATION_TYPE_REMOVE;                    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_NAMESPACE:                {                    if (options.isSet (OPTION_NAMESPACE) > 1)                    {                        //                        // More than one password option was found                        //                        throw DuplicateOptionException(OPTION_NAMESPACE);                    }                    _namespace = options [i].Value ();                    _namespaceSet = true;                    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;                }                case OPTION_READ:                {                    if (options.isSet (OPTION_READ) > 1)                    {                        //                        // More than one read option was found                        //                        throw DuplicateOptionException(OPTION_READ);                    }                    _authorizations.append("r");                    _readFlagSet = true;                    break;                }                case OPTION_WRITE:                {                    if (options.isSet (OPTION_WRITE) > 1)                    {                        //                        // More than one write option was found                        //                        throw DuplicateOptionException(OPTION_WRITE);                    }                    _authorizations.append("w");                    _writeFlagSet = true;                    break;                }                //PEP#167 - 2 new cases added below for HELP and VERSION                case OPTION_HELP:                {                    if (_operationType != OPERATION_TYPE_UNINITIALIZED)                    {                        //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -