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

📄 cimusercommand.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                {                    //l10n                    //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;                    errPrintWriter << e.getMessage() << endl;                }                else if (code == CIM_ERR_NOT_SUPPORTED)                {                    //l10n                    //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_NOT_FOUND)                {                    //l10n                    //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) << endl;                    //outPrintWriter << USER_NOT_FOUND          << endl;                    outPrintWriter << localizeMessage(MSG_PATH,USER_NOT_FOUND_KEY,USER_NOT_FOUND) << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_INVALID_CLASS)                {                    //l10n                    //outPrintWriter << CHANGE_PASSWORD_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_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 << CHANGE_PASSWORD_FAILURE << endl <<                    //e.getMessage() << endl;                outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_FAILURE_KEY,CHANGE_PASSWORD_FAILURE) <<                    endl << e.getMessage() << endl;                return (RC_ERROR);            }            break;        case OPERATION_TYPE_REMOVE:            try            {                _RemoveUser(outPrintWriter, errPrintWriter);            }            catch (CIMException& e)            {                CIMStatusCode code = e.getCode();                if (code == CIM_ERR_FAILED)                {                    //l10n                    //outPrintWriter << REMOVE_USER_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;                    errPrintWriter << e.getMessage() << endl;                }                else if (code == CIM_ERR_NOT_SUPPORTED)                {                    //l10n                    //outPrintWriter << REMOVE_USER_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_NOT_FOUND)                {                    //l10n                    //outPrintWriter << REMOVE_USER_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) << endl;                    //outPrintWriter << USER_NOT_FOUND          << endl;                    outPrintWriter << localizeMessage(MSG_PATH,USER_NOT_FOUND_KEY,USER_NOT_FOUND) << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_INVALID_CLASS)                {                    //l10n                    //outPrintWriter << REMOVE_USER_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_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 << REMOVE_USER_FAILURE << endl <<                    //e.getMessage() << endl;                outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_FAILURE_KEY,REMOVE_USER_FAILURE) <<                endl << e.getMessage() << endl;                return (RC_ERROR);            }            break;        case OPERATION_TYPE_LIST:            try            {                _ListUsers(outPrintWriter, errPrintWriter);            }            catch (CIMException& e)            {                CIMStatusCode code = e.getCode();                if (code == CIM_ERR_FAILED)                {                    //l10n                    //outPrintWriter << LIST_USERS_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;                    errPrintWriter << e.getMessage() << endl;                }                else if (code == CIM_ERR_NOT_SUPPORTED)                {                    //l10n                    //outPrintWriter << LIST_USERS_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_ALREADY_EXISTS)                {                    //l10n                    //outPrintWriter << LIST_USERS_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_FAILURE) << endl;                    errPrintWriter << e.getMessage()  << endl;                }                else if (code == CIM_ERR_INVALID_CLASS)                {                    //l10n                    //outPrintWriter << LIST_USERS_FAILURE << endl;                    outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_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 << LIST_USERS_FAILURE << endl <<                    //e.getMessage() << endl;                outPrintWriter << localizeMessage(MSG_PATH,LIST_USERS_FAILURE_KEY,LIST_USERS_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 CIMUserCommand::_AddUser    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    CIMProperty prop;    CIMInstance newInstance(PEGASUS_CLASSNAME_USER);    newInstance.addProperty(        CIMProperty(PROPERTY_NAME_USER_NAME, _userName));    newInstance.addProperty(        CIMProperty(PROPERTY_NAME_PASSWORD , _password));    _client->createInstance(PEGASUS_NAMESPACENAME_USER, newInstance);    //l10n    //outPrintWriter << ADD_USER_SUCCESS << endl;    outPrintWriter <<        localizeMessage(MSG_PATH,ADD_USER_SUCCESS_KEY,ADD_USER_SUCCESS) << endl;}//// Modify the password for a user//void CIMUserCommand::_ModifyUser    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    Array<CIMKeyBinding>      kbArray;    CIMKeyBinding             kb;    Array<CIMParamValue>   inParams;    Array<CIMParamValue>   outParams;    //    // Build the input params    //    inParams.append(CIMParamValue(OLD_PASS_PARAM,        CIMValue(_password)));    inParams.append(CIMParamValue(NEW_PASS_PARAM,        CIMValue(_newpassword)));    kb.setName(CIMName ("Username"));    kb.setValue(_userName);    kb.setType(CIMKeyBinding::STRING);    kbArray.append(kb);    CIMObjectPath reference(        _hostName, PEGASUS_NAMESPACENAME_USER,        PEGASUS_CLASSNAME_USER, kbArray);    //    // Call the invokeMethod with the input parameters    //    //    // Not checking for return code as all error conditions will    // throw exceptions and will be handled by the catch block. If new    // return codes are added in future, they need to be handled here.    //    CIMValue retValue = _client->invokeMethod(        PEGASUS_NAMESPACENAME_USER,        reference,        MODIFY_METHOD,        inParams,        outParams);    //l10n    //outPrintWriter << CHANGE_PASSWORD_SUCCESS << endl;    outPrintWriter << localizeMessage(MSG_PATH,CHANGE_PASSWORD_SUCCESS_KEY,CHANGE_PASSWORD_SUCCESS) << endl;}//// Remove a user//void CIMUserCommand::_RemoveUser    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    Array<CIMKeyBinding> kbArray;    CIMKeyBinding kb;    kb.setName(PROPERTY_NAME_USER_NAME);    kb.setValue(_userName);    kb.setType(CIMKeyBinding::STRING);    kbArray.append(kb);    CIMObjectPath reference(        _hostName, PEGASUS_NAMESPACENAME_USER,        PEGASUS_CLASSNAME_USER, kbArray);    _client->deleteInstance(PEGASUS_NAMESPACENAME_USER, reference);    //l10n    //outPrintWriter << REMOVE_USER_SUCCESS << endl;    outPrintWriter << localizeMessage(MSG_PATH,REMOVE_USER_SUCCESS_KEY,REMOVE_USER_SUCCESS) << endl;}/**    get a list of all user names from the CIM Server. */void CIMUserCommand::_ListUsers    (    ostream& outPrintWriter,    ostream& errPrintWriter    ){    //    // get all the instances of class PG_User    //    Array<CIMObjectPath> instanceNames =        _client->enumerateInstanceNames(            PEGASUS_NAMESPACENAME_USER,            PEGASUS_CLASSNAME_USER);    if (instanceNames.size() == 0)    {         //l10n         //outPrintWriter << NO_USERS_FOUND << endl;         outPrintWriter <<             localizeMessage(MSG_PATH,NO_USERS_FOUND_KEY,NO_USERS_FOUND) <<             endl;    }    else    {        //        // List all the users.        //        for (Uint32 i = 0; i < instanceNames.size(); i++)        {            Array<CIMKeyBinding> kbArray = instanceNames[i].getKeyBindings();            if (kbArray.size() > 0)            {                outPrintWriter << kbArray[0].getValue() << 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<CIMUserCommand>  command;    Uint32               retCode;    MessageLoader::_useProcessLocale = true; //l10n set message loading to process locale    MessageLoader::setPegasusMsgHomeRelative(argv[0]);    //    // Check if root is issuing the command    //    if (!System::isPrivilegedUser(System::getEffectiveUserName()))    {        MessageLoaderParms parms(NOT_PRIVILEGED_USER_KEY, NOT_PRIVILEGED_USER);        parms.msg_src_path = MSG_PATH;        cerr << MessageLoader::getMessage(parms) << endl;        return 1;    }    command.reset(new CIMUserCommand ());    try    {        command->setCommand ( cout, cerr, 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;         }        return 1;    }    retCode = command->execute (cout, cerr);    return (retCode);}

⌨️ 快捷键说明

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