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

📄 cimauthcommand.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            {                //l10n                //outPrintWriter << REMOVE_AUTH_FAILURE << endl <<                    //e.getMessage() << endl;                outPrintWriter << localizeMessage(MSG_PATH,                    REMOVE_AUTH_FAILURE_KEY,                    REMOVE_AUTH_FAILURE)                    << endl << e.getMessage() << endl;                return ( RC_ERROR );            }            break;        case OPERATION_TYPE_LIST:            try            {                _ListAuthorization( outPrintWriter, errPrintWriter );            }            catch (CIMException& e)            {                CIMStatusCode code = e.getCode();                if (code == CIM_ERR_FAILED)                {                    //l10n                    //outPrintWriter << LIST_AUTH_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,                        LIST_AUTH_FAILURE_KEY,                        LIST_AUTH_FAILURE)                        << endl;                    errPrintWriter << e.getMessage() << endl;                }                else if (code == CIM_ERR_NOT_SUPPORTED)                {                    //l10n                    //outPrintWriter << LIST_AUTH_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,                        LIST_AUTH_FAILURE_KEY,                        LIST_AUTH_FAILURE)                        << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_ALREADY_EXISTS)                {                    //l10n                    //outPrintWriter << LIST_AUTH_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,                        LIST_AUTH_FAILURE_KEY,                        LIST_AUTH_FAILURE)                        << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_INVALID_CLASS)                {                    //l10n                    //outPrintWriter << LIST_AUTH_FAILURE << endl;                    //outPrintWriter << AUTH_SCHEMA_NOT_LOADED << endl;                    outPrintWriter << localizeMessage(MSG_PATH,                        LIST_AUTH_FAILURE_KEY,                        LIST_AUTH_FAILURE)                        << 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 << LIST_AUTH_FAILURE << endl <<                //e.getMessage() << endl;                outPrintWriter << localizeMessage(MSG_PATH,                    LIST_AUTH_FAILURE_KEY,                    LIST_AUTH_FAILURE)                    << endl << e.getMessage() << endl;                return ( RC_ERROR );            }            break;        default:            //            // Should never get here            //            break;    }    return (RC_SUCCESS);}/**    Add the user to the CIM Server.*/void CIMAuthCommand::_AddAuthorization    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    CIMProperty prop;    CIMInstance newInstance( PEGASUS_CLASSNAME_AUTHORIZATION );    newInstance.addProperty (        CIMProperty( PROPERTY_NAME_USERNAME, _userName ) );    newInstance.addProperty (        CIMProperty( PROPERTY_NAME_NAMESPACE , _namespace ) );    newInstance.addProperty (        CIMProperty( PROPERTY_NAME_AUTHORIZATION, _authorizations ) );    _client->createInstance(        PEGASUS_NAMESPACENAME_AUTHORIZATION,        newInstance);    //l10n    //outPrintWriter << ADD_AUTH_SUCCESS << endl;    outPrintWriter << localizeMessage(MSG_PATH,        ADD_AUTH_SUCCESS_KEY,        ADD_AUTH_SUCCESS)        << endl;}//// Modify the password for a user//void CIMAuthCommand::_ModifyAuthorization    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    Array<CIMKeyBinding>      kbArray;    CIMKeyBinding             kb;    //    // Build the input params    //    kb.setName(PROPERTY_NAME_USERNAME);    kb.setValue(_userName);    kb.setType(CIMKeyBinding::STRING);    kbArray.append(kb);    kb.setName(PROPERTY_NAME_NAMESPACE);    kb.setValue(_namespace);    kb.setType(CIMKeyBinding::STRING);    kbArray.append(kb);    CIMObjectPath reference(        _hostName, PEGASUS_NAMESPACENAME_AUTHORIZATION,        PEGASUS_CLASSNAME_AUTHORIZATION, kbArray);    CIMInstance modifiedInst( PEGASUS_CLASSNAME_AUTHORIZATION );    modifiedInst.addProperty(        CIMProperty( PROPERTY_NAME_USERNAME, _userName ) );    modifiedInst.addProperty(        CIMProperty( PROPERTY_NAME_NAMESPACE , _namespace ) );    modifiedInst.addProperty(        CIMProperty( PROPERTY_NAME_AUTHORIZATION, _authorizations ) );    CIMInstance namedInstance (modifiedInst);    namedInstance.setPath (reference);    _client->modifyInstance(        PEGASUS_NAMESPACENAME_AUTHORIZATION,        namedInstance);    //l10n    //outPrintWriter << MODIFY_AUTH_SUCCESS << endl;    outPrintWriter << localizeMessage(MSG_PATH,        MODIFY_AUTH_SUCCESS_KEY,        MODIFY_AUTH_SUCCESS)        << endl;}//// Remove a user//void CIMAuthCommand::_RemoveAuthorization    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    Array<CIMKeyBinding> kbArray;    CIMKeyBinding        kb;    //    // If namespace is specified    //    if ( _namespaceSet )    {        //        // Build the input params        //        kb.setName(PROPERTY_NAME_USERNAME);        kb.setValue(_userName);        kb.setType(CIMKeyBinding::STRING);        kbArray.append(kb);        kb.setName(PROPERTY_NAME_NAMESPACE);        kb.setValue(_namespace);        kb.setType(CIMKeyBinding::STRING);        kbArray.append(kb);        CIMObjectPath reference(            _hostName, PEGASUS_NAMESPACENAME_AUTHORIZATION,            PEGASUS_CLASSNAME_AUTHORIZATION, kbArray);        _client->deleteInstance(            PEGASUS_NAMESPACENAME_AUTHORIZATION,            reference);    }    else    {        //        // ATTN: If namespace is not specified, do enumerate instance        // names to get all the namespaces and call delete instance for        // each of the namespaces.        //        Array<CIMObjectPath> instanceNames =            _client->enumerateInstanceNames(                PEGASUS_NAMESPACENAME_AUTHORIZATION,                PEGASUS_CLASSNAME_AUTHORIZATION);        //        //        //        for (Uint32 i = 0; i < instanceNames.size(); i++)        {            String user;            kbArray = instanceNames[i].getKeyBindings();            for (Uint32 j = 0; j < kbArray.size(); j++)            {                if (kbArray[j].getName().equal (PROPERTY_NAME_USERNAME))                {                    user = kbArray[j].getValue();                }            }            if ( String::equal(user, _userName) )            {                _client->deleteInstance(                    PEGASUS_NAMESPACENAME_AUTHORIZATION, instanceNames[i]);            }        }    }    //l10n    //outPrintWriter << REMOVE_AUTH_SUCCESS << endl;    outPrintWriter << localizeMessage(MSG_PATH,        REMOVE_AUTH_SUCCESS_KEY,        REMOVE_AUTH_SUCCESS)        << endl;}/**    get a list of all user names from the CIM Server. */void CIMAuthCommand::_ListAuthorization    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    Array<CIMInstance> authNamedInstances;    //    // get all the instances of class PG_Authorization    //    authNamedInstances =        _client->enumerateInstances(            PEGASUS_NAMESPACENAME_AUTHORIZATION,            PEGASUS_CLASSNAME_AUTHORIZATION);    //    // display all the user names, namespaces, and authorizations    //    for (Uint32 i = 0; i < authNamedInstances.size(); i++)    {        CIMInstance& authInstance =            authNamedInstances[i];        //        // get user name        //        Uint32 pos = authInstance.findProperty(PROPERTY_NAME_USERNAME);        CIMProperty prop = (CIMProperty)authInstance.getProperty(pos);        String name = prop.getValue().toString();        //        // get namespace name        //        pos = authInstance.findProperty(PROPERTY_NAME_NAMESPACE);        prop = (CIMProperty)authInstance.getProperty(pos);        String ns = prop.getValue().toString();        //        // get authorizations        //        pos = authInstance.findProperty(PROPERTY_NAME_AUTHORIZATION);        prop = (CIMProperty)authInstance.getProperty(pos);        String auth = prop.getValue().toString();        outPrintWriter << name << ", " << ns << ", \"" ;        outPrintWriter << auth << "\"" << endl;    }}PEGASUS_NAMESPACE_END//// exclude main from the Pegasus Namespace//PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;////////////////////////////////////////////////////////////////////////////////**    Parses the command line, and execute the command.    @param   args  the string array containing the command line arguments*////////////////////////////////////////////////////////////////////////////////int main (int argc, char* argv []){    AutoPtr<CIMAuthCommand> command;    Uint32               retCode;    MessageLoader::_useProcessLocale = true;  //l10n set messageloading to process locale    MessageLoader::setPegasusMsgHomeRelative(argv[0]);#ifdef PEGASUS_OS_OS400    if(FALSE == ycmCheckCmdAuthorities())    {        return 1;    }#else    //    // Check if root is issuing the command    //    if ( !System::isPrivilegedUser(System::getEffectiveUserName()) )    {        //l10n        //cerr << NOT_PRIVILEGED_USER << endl;        MessageLoaderParms parms(NOT_PRIVILEGED_USER_KEY,                                 NOT_PRIVILEGED_USER);        parms.msg_src_path = MSG_PATH;        cerr << MessageLoader::getMessage(parms) << endl;        return 1;    }#endif    command.reset(new CIMAuthCommand ());    try    {        command->setCommand (argc, argv);    }    catch (CommandFormatException& cfe)    {        String msg(cfe.getMessage());        cerr << COMMAND_NAME << ": " << msg <<  endl;        if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)        {            MessageLoaderParms parms(ERR_OPTION_NOT_SUPPORTED_KEY,ERR_OPTION_NOT_SUPPORTED);            parms.msg_src_path = MSG_PATH;            cerr << COMMAND_NAME <<                ": " << MessageLoader::getMessage(parms) << endl;        }        else        {            MessageLoaderParms parms(ERR_USAGE_KEY,ERR_USAGE);            parms.msg_src_path = MSG_PATH;            cerr << COMMAND_NAME <<                ": " << MessageLoader::getMessage(parms) << endl;        }        exit (Command::RC_ERROR);    }    retCode = command->execute (cout, cerr);    exit (retCode);    return 0;}

⌨️ 快捷键说明

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