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

📄 osinfo.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//%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: Mike Brasher (mbrasher@bmc.com)//         Carol Ann Krug Graves, Hewlett-Packard Company//         (carolann_graves@hp.com)//// Modified By://          Warren Otsuka (warren_otsuka@hp.com)//          Sushma Fernandes, Hewlett-Packard Company//              (sushma_fernandes@hp.com)//          Mike Day (mdday@us.ibm.com)//          Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)//          Bapu Patil, Hewlett-Packard Company ( bapu_patil@hp.com )//          Warren Otsuka, Hewlett-Packard Company (warren_otsuka@hp.com)//          Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)//          Susan Campbell, Hewlett-Packard Company (scampbell@hp.com)//          Alagaraja Ramasubramanian, IBM (alags_raj@in.ibm.com) - PEP-167//          Amit K Arora, IBM (amitarora@in.ibm.com) - Bug#2333,#2351//          Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2756//          David Dillard, VERITAS Software Corp.//              (david.dillard@veritas.com)//          Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3032////%/////////////////////////////////////////////////////////////////////////////#include <iostream>#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/SSLContext.h>#include <Pegasus/getoopt/getoopt.h>#include <Clients/cliutils/CommandException.h>#include "OSInfo.h"// To build a version of osinfo that does not// support remote connections the// DISABLE_SUPPORT_FOR_REMOTE_CONNECTIONS// flag can be enabled.//#define DISABLE_SUPPORT_FOR_REMOTE_CONNECTIONS//#define DEBUGPEGASUS_NAMESPACE_BEGIN#define NAMESPACE CIMNamespaceName ("root/cimv2")#define CLASSNAME CIMName ("PG_OperatingSystem")/**    The command name. */const char   OSInfoCommand::COMMAND_NAME []      = "osinfo";/**    Label for the usage string for this command. */const char   OSInfoCommand::_USAGE []            = "Usage: ";/**    The option character used to specify the hostname. */const char   OSInfoCommand::_OPTION_HOSTNAME     = 'h';/**    The option character used to specify the port number. */const char   OSInfoCommand::_OPTION_PORTNUMBER   = 'p';/**    The option character used to specify SSL usage. */const char   OSInfoCommand::_OPTION_SSL          = 's';/**    The option character used to specify the timeout value. */const char   OSInfoCommand::_OPTION_TIMEOUT      = 't';/**    The option character used to specify the username. */const char   OSInfoCommand::_OPTION_USERNAME     = 'u';/**    The option character used to specify the password. */const char   OSInfoCommand::_OPTION_PASSWORD     = 'w';/**    The option character used to specify the password. */const char   OSInfoCommand::_OPTION_RAW_DATETIME_FORMAT     = 'c';/**    The minimum valid portnumber. */const Uint32 OSInfoCommand::_MIN_PORTNUMBER      = 0;/**    The maximum valid portnumber. */const Uint32 OSInfoCommand::_MAX_PORTNUMBER      = 65535;//l10n/** * The CLI message resource name */static const char MSG_PATH [] = "pegasus/pegasusCLI";static const char PASSWORD_PROMPT [] =                     "Please enter your password: ";static const char PASSWORD_BLANK [] =                     "Password cannot be blank. Please re-enter your password.";static const char LONG_HELP [] = "help";static const char LONG_VERSION [] = "version";static const char REQUIRED_ARGS_MISSING [] =                        "Required arguments missing.";static const char REQUIRED_ARGS_MISSING_KEY [] = "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";static const char ERR_OPTION_NOT_SUPPORTED [] =    "Invalid option. Use '--help' to obtain command syntax.";static const char ERR_OPTION_NOT_SUPPORTED_KEY [] = "Clients.cimuser.CIMUserCommand..ERR_OPTION_NOT_SUPPORTED";static const char ERR_USAGE [] =    "Incorrect usage. Use '--help' to obtain command syntax.";static const char ERR_USAGE_KEY [] = "Clients.cimuser.CIMUserCommand..ERR_USAGE";/**    This constant signifies that an operation option has not been recorded*/static const Uint32 OPERATION_TYPE_UNINITIALIZED  = 0;/**    This constant represents a help operation*/static const Uint32 OPERATION_TYPE_HELP           = 1;/**    This constant represents a version display operation*/static const Uint32 OPERATION_TYPE_VERSION        = 2;static const Uint32 MAX_PW_RETRIES = 3;static Boolean verifyCertificate(SSLCertificateInfo &certInfo){#ifdef DEBUG    cout << certInfo.getSubjectName() << endl;#endif    //    // If server certificate was found in trust store and validated, then    // return 'true' to accept the certificate, otherwise return 'false'.    //    if (certInfo.getResponseCode() == 1)    {        return true;    }    else    {        return false;    }}/**    Constructs a OSInfoCommand and initializes instance variables. */OSInfoCommand::OSInfoCommand (){    _hostName            = String ();    _hostNameSet         = false;    _portNumber          = WBEM_DEFAULT_HTTP_PORT;    _portNumberSet       = false;    char buffer[32];    sprintf(buffer, "%lu", (unsigned long) _portNumber);    _portNumberStr       = buffer;    _timeout             = DEFAULT_TIMEOUT_MILLISECONDS;    _userName            = String ();    _userNameSet         = false;    _password            = String ();    _passwordSet         = false;    _useSSL              = false;    _useRawDateTimeFormat   = false;    usage = String (_USAGE);    usage.append (COMMAND_NAME);    usage.append (" [ -");#ifndef DISABLE_SUPPORT_FOR_REMOTE_CONNECTIONS    usage.append (_OPTION_SSL);    usage.append (" ] [ -");    usage.append (_OPTION_HOSTNAME);    usage.append (" hostname ] [ -");    usage.append (_OPTION_PORTNUMBER);    usage.append (" portnumber ] [ -");    usage.append (_OPTION_USERNAME);    usage.append (" username ]\n              [ -");    usage.append (_OPTION_PASSWORD);    usage.append (" password ] [ -");    usage.append (_OPTION_TIMEOUT);    usage.append (" timeout ] [ -");#endif    usage.append (_OPTION_RAW_DATETIME_FORMAT);    usage.append (" ]");    usage.append (" [ --");    usage.append (LONG_HELP);    usage.append(" ] [ --").append(LONG_VERSION).append(" ] \n");    usage.append("Options : \n");    usage.append("    -c         - Use CIM format for date and time\n");    usage.append("    -h         - Connect to CIM Server on specified hostname\n");    usage.append("    --help     - Display this help message\n");    usage.append("    -p         - Connect to CIM Server on specified portnumber\n");    usage.append("    -s         - Use SSL protocol between 'osinfo' client and the CIM Server\n");    usage.append("    -t         - Specify response timeout value in milliseconds\n");    usage.append("    -u         - Connect to CIM Server using the specified username\n");    usage.append("    --version  - Display CIM Server version number\n");    usage.append("    -w         - Connect to CIM Server using the specified password\n");    usage.append("\nUsage note: The osinfo command requires that the CIM Server is running.\n");    setUsage (usage);}String OSInfoCommand::_promptForPassword( ostream& outPrintWriter ){  //  // Password is not set, prompt for non-blank password  //  String pw = String::EMPTY;  Uint32 retries = 1;  do    {      pw = System::getPassword( PASSWORD_PROMPT );      if ( pw == String::EMPTY || pw == "" )        {          if( retries < MAX_PW_RETRIES )            {              retries++;            }          else            {              break;            }          outPrintWriter << PASSWORD_BLANK << endl;          pw = String::EMPTY;          continue;        }    }  while ( pw == String::EMPTY );  return( pw );}/**    Connects to cimserver.    @param   outPrintWriter     the ostream to which error output should be                                written    @exception       Exception  if an error is encountered in creating                               the connection */ void OSInfoCommand::_connectToServer( CIMClient& client,                                       ostream& outPrintWriter ){    String                 host                  = String ();    Uint32                 portNumber            = 0;    Boolean                connectToLocal        = false;    //    //  Construct host address    //    if ((!_hostNameSet) && (!_portNumberSet) && (!_userNameSet) && (!_passwordSet))      {        connectToLocal = true;      }    else    {        if (!_hostNameSet)        {           _hostName = System::getHostName();        }        if( !_portNumberSet )        {           if( _useSSL )           {               _portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME,                                          WBEM_DEFAULT_HTTPS_PORT );           }           else           {               _portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME,                                          WBEM_DEFAULT_HTTP_PORT );           }           char buffer[32];           sprintf( buffer, "%lu", (unsigned long) _portNumber );           _portNumberStr = buffer;        }    }    host = _hostName;    portNumber = _portNumber;    if( connectToLocal )    {        client.connectLocal();    }    else    {        if (!_userNameSet)        {           _userName = System::getEffectiveUserName();        }        if (!_passwordSet)        {            _password = _promptForPassword( outPrintWriter );        }        if( _useSSL )        {           //           // Get environment variables:           //           const char* pegasusHome = getenv("PEGASUS_HOME");           String certpath = FileSystem::getAbsolutePath(              pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);           String randFile = String::EMPTY;

⌨️ 快捷键说明

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