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

📄 cimcrlcommand.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      case 10 :          sprintf(monthString, "Oct");          break;      case 11 :          sprintf(monthString, "Nov");          break;      case 12 :          sprintf(monthString, "Dec");          break;      default:          PEGASUS_ASSERT(false);      return (cimDateTimeStr);   }   char dateTimeStr[80];   sprintf(dateTimeStr, "%s %d, %d  %d:%02d:%02d (%03d%02d)",           monthString, day, year, hour, minute, second,           timezone/60, timezone%60);   String retVal = String(dateTimeStr);   return (retVal);}/**    Read CRL content.    @param  crlFilePath     the CRL file path    @return  Buffer containing the CRL content    @exception  Exception    if an error is encountered                             in reading the CRL file */Buffer CIMCRLCommand::_readCRLContent(const String &certFilePath){    Buffer content;    //    //  Check that cert file exists    //    if (!FileSystem::exists (certFilePath))    {        NoSuchFile e (certFilePath);        throw e;    }    //    //  Load file context to memory    //    FileSystem::loadFileToMemory (content, certFilePath);    content.append ('\0');    return content;}/**   Add a CRL to the CRL store   @param  client           the handle to CIMClient object   @param  outPrintWriter   the ostream to which output should be written */void CIMCRLCommand::_addCRL(    CIMClient&   client,    ostream&     outPrintWriter){    Buffer              content;    Array<CIMKeyBinding>   kbArray;    CIMKeyBinding          kb;    Array<CIMParamValue>   inParams;    Array<CIMParamValue>   outParams;    content = _readCRLContent(_crlFile);    String contentStr = String(content.getData());    //    // Build the input params    //    inParams.append ( CIMParamValue ( CRL_CONTENTS,                                      CIMValue (contentStr)));    CIMObjectPath reference(        String::EMPTY, PEGASUS_NAMESPACENAME_CERTIFICATE,        PEGASUS_CLASSNAME_CRL, kbArray);    //    // Call the invokeMethod with the input parameters    //    client.invokeMethod (                   PEGASUS_NAMESPACENAME_CERTIFICATE,                   reference,                   ADD_CRL_METHOD,                   inParams,                   outParams );    outPrintWriter << localizeMessage(MSG_PATH, ADD_CRL_SUCCESS_KEY,        ADD_CRL_SUCCESS) << endl;}/**   Remove an existing CRL from the CRL store   @param  client           the handle to CIMClient object   @param  outPrintWriter   the ostream to which output should be written*/void CIMCRLCommand::_removeCRL (    CIMClient&   client,    ostream&     outPrintWriter){    Array<CIMKeyBinding> kbArray;    CIMKeyBinding        kb;    //    // Build the input params    //    kb.setName(PROPERTY_NAME_ISSUERNAME);    kb.setValue(_issuer);    kb.setType(CIMKeyBinding::STRING);    kbArray.append(kb);    CIMObjectPath reference(        String::EMPTY, PEGASUS_NAMESPACENAME_CERTIFICATE,        PEGASUS_CLASSNAME_CRL, kbArray);    client.deleteInstance(        PEGASUS_NAMESPACENAME_CERTIFICATE,        reference);    outPrintWriter << localizeMessage(MSG_PATH, REMOVE_CRL_SUCCESS_KEY,        REMOVE_CRL_SUCCESS) << endl;}/**   List CRL's in the CRL store   @param  client           the handle to CIMClient object   @param  outPrintWriter   the ostream to which output should be written */void CIMCRLCommand::_listCRL (    CIMClient&   client,    ostream&     outPrintWriter){    Array<CIMInstance> crlNamedInstances;    Boolean	       issuerFound = false;    //    // get all the instances of class PG_SSLCertificateRevocationList    //    crlNamedInstances =        client.enumerateInstances(            PEGASUS_NAMESPACENAME_CERTIFICATE,            PEGASUS_CLASSNAME_CRL);    //    // copy the CRL content    //    Uint32 numberInstances = crlNamedInstances.size();    for (Uint32 i = 0; i < numberInstances; i++)    {        CIMInstance& crlInstance = crlNamedInstances[i];        String issuer;        CIMDateTime lastUpdate;        CIMDateTime nextUpdate;        //        // Check if issuer name is specified        //        Uint32 pos = crlInstance.findProperty(PROPERTY_NAME_ISSUERNAME);        CIMConstProperty prop = crlInstance.getProperty(pos);        prop.getValue().get(issuer);        if ( _issuerSet && !String::equal(_issuer, issuer) )        {            continue;        }        else        {            issuerFound = true;        }        //        // Get the remaining properties and display them.        //        pos = crlInstance.findProperty(PROPERTY_NAME_LASTUPDATE);        prop = crlInstance.getProperty(pos);        prop.getValue().get(lastUpdate);        String lastUpdateStr = _formatCIMDateTime(lastUpdate.toString());        pos = crlInstance.findProperty(PROPERTY_NAME_NEXTUPDATE);        prop = crlInstance.getProperty(pos);        prop.getValue().get(nextUpdate);        String nextUpdateStr = _formatCIMDateTime(nextUpdate.toString());        //        // Display the CRL issuer name and update dates        //        outPrintWriter << "Issuer:  " << issuer << endl;        outPrintWriter << "Last update: " << lastUpdateStr << endl;        outPrintWriter << "Next update: " << nextUpdateStr << endl;        Array<String> revokedSerialNumbers;        Array<CIMDateTime> revocationDates;        pos = crlInstance.findProperty(PROPERTY_NAME_REVOKED_SERIAL_NUMBERS);        prop = crlInstance.getProperty(pos);        prop.getValue().get(revokedSerialNumbers);        pos = crlInstance.findProperty(PROPERTY_NAME_REVOCATION_DATES);        prop = crlInstance.getProperty(pos);        prop.getValue().get(revocationDates);        outPrintWriter << "Revoked Certificates:" << endl;        for (Uint32 i = 0; i < revokedSerialNumbers.size(); i++)        {            String revocationDateStr =                _formatCIMDateTime(revocationDates[i].toString());            //            // Display the revoked serial numbers and the revocation dates            //            outPrintWriter <<                "    Serial Number: " << revokedSerialNumbers[i] << endl;            outPrintWriter <<                "        Revocation Date: " << revocationDateStr << endl;            outPrintWriter << endl;        }        outPrintWriter <<            "---------------------------------------------"<< endl;    }    if ( _issuerSet && !issuerFound)    {         CIMException ce( CIM_ERR_NOT_FOUND );         throw ce;    }}/**    Parses the command line, validates the options, and sets instance    variables based on the option arguments.    @param   argc  the number of command line arguments    @param   argv  the string vector of command line arguments    @exception  CommandFormatException  if an error is encountered in parsing                                        the command line */void CIMCRLCommand::setCommand (Uint32 argc, char* argv []){    Uint32         i               = 0;    Uint32         c               = 0;    String         timeoutStr;    String         serialNumberStr;    String         optString;    getoopt        getOpts;    //    //  Construct optString    //    optString.append (_OPTION_ADD);    optString.append (getoopt::NOARG);    optString.append (_OPTION_CRLFILE);    optString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append (_OPTION_REMOVE);    optString.append (getoopt::NOARG);    optString.append (_OPTION_ISSUERNAME);    optString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    optString.append (_OPTION_LIST);    optString.append (getoopt::NOARG);    optString.append (_OPTION_ISSUERNAME);    optString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    //    //  Initialize and parse getOpts    //    getOpts = getoopt ();    getOpts.addFlagspec (optString);    //    // Add long flag options for 'help' and 'version'    //    getOpts.addLongFlagspec (LONG_HELP, getoopt::NOARG);    getOpts.addLongFlagspec (LONG_VERSION, getoopt::NOARG);    getOpts.parse (argc, argv);    if (getOpts.hasErrors ())    {        CommandFormatException e (getOpts.getErrorStrings () [0]);        throw e;    }    _operationType = _OPERATION_TYPE_UNINITIALIZED;    //    //  Get options and arguments from the command line    //    for (i =  getOpts.first (); i <  getOpts.last (); i++)    {        if (getOpts [i].getType () == Optarg::LONGFLAG)        {            if (getOpts [i].getopt () == LONG_HELP)            {                if (_operationType != _OPERATION_TYPE_UNINITIALIZED)                {                    String param = String (LONG_HELP);                    //                    // More than one operation option was found                    //                    UnexpectedOptionException e (param);                    throw e;                }               _operationType = _OPERATION_TYPE_HELP;            }            else if (getOpts [i].getopt () == LONG_VERSION)            {                if (_operationType != _OPERATION_TYPE_UNINITIALIZED)                {                    String param = String (LONG_VERSION);                    //                    // More than one operation option was found                    //                    UnexpectedOptionException e (param);                    throw e;                }               _operationType = _OPERATION_TYPE_VERSION;            }        }        else if (getOpts [i].getType () == Optarg::REGULAR)        {            //            //  The cimcrl command has no non-option argument options            //            UnexpectedArgumentException e (getOpts [i].Value ());            throw e;        }        else /* getOpts [i].getType () == FLAG */        {            c = getOpts [i].getopt () [0];            switch (c)            {                case _OPTION_ADD:                {                    if (_operationType != _OPERATION_TYPE_UNINITIALIZED)                    {                        //                        // More than one operation option was found                        //                        UnexpectedOptionException e (_OPTION_ADD);                        throw e;                    }                    if (getOpts.isSet (_OPTION_ADD) > 1)                    {                        //                        // More than one add option was found                        //                        DuplicateOptionException e (_OPTION_ADD);

⌨️ 快捷键说明

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