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

📄 wbemexeccommand.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: 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)//         David Eger (dteger@us.ibm.com)//         Amit K Arora (amita@in.ibm.com) for PEP-101//         Alagaraja Ramasubramanian, IBM (alags_raj@in.ibm.com) - PEP-167//         Amit K Arora (amita@in.ibm.com) for Bug#2333, #2351//         David Dillard, VERITAS Software Corp.//             (david.dillard@veritas.com)//         Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2756, #3424, Bug#3032////%/////////////////////////////////////////////////////////////////////////////// define asprintf used to implement ultostr on Linux#if defined(PEGASUS_LINUX_GENERIC_GNU)#define _GNU_SOURCE#include <features.h>#include <stdio.h>#endif#include <iostream>#include <Pegasus/Common/Signal.h>#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/XmlWriter.h>#include <Pegasus/Common/SSLContext.h>#include <Pegasus/Common/AutoPtr.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/getoopt/getoopt.h>#include <Clients/cliutils/CommandException.h>#include "HttpConstants.h"#include "XMLProcess.h"#include "WbemExecCommand.h"#include "WbemExecClient.h"PEGASUS_NAMESPACE_BEGIN/**    The command name. */const char   WbemExecCommand::COMMAND_NAME []      = "wbemexec";/**    Label for the usage string for this command. */const char   WbemExecCommand::_USAGE []            = "Usage: ";/**    The option character used to specify the hostname. */const char   WbemExecCommand::_OPTION_HOSTNAME     = 'h';/**    The option character used to specify the port number. */const char   WbemExecCommand::_OPTION_PORTNUMBER   = 'p';/**    The option character used to specify the HTTP version for the request. */const char   WbemExecCommand::_OPTION_HTTPVERSION  = 'v';/**    The option character used to specify the HTTP method for the request. */const char   WbemExecCommand::_OPTION_HTTPMETHOD   = 'm';/**    The option character used to specify SSL usage. */const char   WbemExecCommand::_OPTION_SSL          = 's';/**    The option character used to specify the timeout value. */const char   WbemExecCommand::_OPTION_TIMEOUT      = 't';/**    The option character used to specify that debug output is requested. */const char   WbemExecCommand::_OPTION_DEBUG        = 'd';/**    The option character used to specify the username. */const char   WbemExecCommand::_OPTION_USERNAME     = 'u';/**    The option character used to specify the password. */const char   WbemExecCommand::_OPTION_PASSWORD     = 'w';/**    The minimum valid portnumber. */const Uint32 WbemExecCommand::_MIN_PORTNUMBER      = 0;/**    The maximum valid portnumber. */const Uint32 WbemExecCommand::_MAX_PORTNUMBER      = 65535;/**    The debug option argument value used to specify that the HTTP    encapsulation of the original XML request be included in the output.*/const char   WbemExecCommand::_DEBUG_OPTION1       = '1';/**    The debug option argument value used to specify that the HTTP    encapsulation of the XML response be included in the output.*/const char   WbemExecCommand::_DEBUG_OPTION2       = '2';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 MSG_PATH []               = "pegasus/pegasusCLI";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.CIMConfig.CIMConfigCommand.ERR_OPTION_NOT_SUPPORTED";static const char ERR_USAGE [] =                        "Incorrect usage. Use '--help' to obtain command syntax.";static const char ERR_USAGE_KEY [] = "Clients.CIMConfig.CIMConfigCommand.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 Boolean verifyCertificate(SSLCertificateInfo &certInfo){    //    // If server certificate was found in CA 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 WbemExecCommand and initializes instance variables. */WbemExecCommand::WbemExecCommand (){    _hostName            = String ();    _hostNameSet         = false;    _portNumber          = WBEM_DEFAULT_HTTP_PORT;    _portNumberSet       = false;    char buffer[32];    sprintf(buffer, "%lu", (unsigned long) _portNumber);    _portNumberStr       = buffer;    _useHTTP11           = true;    _useMPost            = true;    _timeout             = WbemExecClient::DEFAULT_TIMEOUT_MILLISECONDS;    _debugOutput1        = false;    _debugOutput2        = false;    _userName            = String ();    _userNameSet         = false;    _password            = String ();    _passwordSet         = false;    _inputFilePath       = String ();    _inputFilePathSet    = false;    _useSSL              = false;    //    //  Note: debug option is not shown in usage string.    //  The debug option is not included in end-user documentation.    //    usage = String (_USAGE);    usage.append (COMMAND_NAME);    usage.append (" [ -");    usage.append (_OPTION_HOSTNAME);    usage.append (" hostname ] [ -");    usage.append (_OPTION_PORTNUMBER);    usage.append (" portnumber ] [ -");    usage.append (_OPTION_HTTPVERSION);    usage.append (" httpversion ]\n                [ -");    usage.append (_OPTION_HTTPMETHOD);    usage.append (" httpmethod ] [ -");    usage.append (_OPTION_TIMEOUT);    usage.append (" timeout ] [ -");    usage.append (_OPTION_USERNAME);    usage.append (" username ]\n                [ -");    usage.append (_OPTION_PASSWORD);    usage.append (" password ] [ -");    usage.append (_OPTION_SSL);    usage.append (" ] [ --");    usage.append (LONG_HELP);    usage.append (" ] [ --");    usage.append (LONG_VERSION);    usage.append (" ]\n                [ inputfilepath ]\n");    usage.append("Options : \n");    usage.append("    -h         - Connect to CIM Server on specified hostname\n");    usage.append("    --help     - Display this help message\n");    usage.append("    -m         - Use the specified HTTP method for the request\n");    usage.append("    -p         - Connect to CIM Server on specified portnumber\n");    usage.append("    -s         - Use SSL protocol between 'wbemexec' client and the CIM Server\n");    usage.append("    -t         - Specify response timeout value in milliseconds\n");    usage.append("    -u         - Authorize the operation using the specified username\n");    usage.append("    -v         - Use the specified HTTP version for the request\n");    usage.append("    --version  - Display CIM Server version number\n");    usage.append("    -w         - Authorize the operation using the specified password\n");    usage.append("\nUsage note: The wbemexec command requires that the CIM Server is running.\n");    setUsage (usage);}/**    Connects to cimserver.    @param   outPrintWriter     the ostream to which error output should be                                written    @return  the Channel created    @exception       Exception  if an error is encountered in creating                               the connection */ void WbemExecCommand::_connectToServer( WbemExecClient& client,                         ostream& outPrintWriter ){    String                 host                  = String ();    Uint32                 portNumber            = 0;    Boolean                connectToLocal        = false;    //    //  Construct host address    //    if ((!_hostNameSet) && (!_portNumberSet))      {        connectToLocal = true;      }#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET    if ((_hostNameSet) || (_portNumberSet))    {#endif      host = _hostName;      portNumber = _portNumber;#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET    }#endif    if( _useSSL )      {    if( connectToLocal )    {        client.connectLocal();    }    else    {        //        // Get environment variables:        //        const char* pegasusHome = getenv("PEGASUS_HOME");        String certpath = FileSystem::getAbsolutePath(                pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);        String randFile = String::EMPTY;#ifdef PEGASUS_SSL_RANDOMFILE        randFile = FileSystem::getAbsolutePath(                pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);#endif        AutoPtr<SSLContext> sslcontext(new SSLContext(certpath, verifyCertificate, randFile));        client.connect(host, portNumber, sslcontext,  _userName, _password );    }      }    else      {    if( connectToLocal )      {        client.connectLocal();      }    else      {        client.connect(host, portNumber, _userName, _password );      }      }}/**    Prints the response to the specified output stream. */void WbemExecCommand::_printContent(    ostream& oStream,    Buffer& responseMessage,    Uint32 contentOffset){    //    //  Get HTTP header    //    const char* message = responseMessage.getData ();    if (contentOffset < responseMessage.size())      {        //        //  Print XML response to the ostream        //        ((Buffer&) responseMessage).append ('\0');        const char* content = responseMessage.getData () + contentOffset;        XmlWriter::indentedPrint (oStream, content, 0);      }}/**    Process HTTP response message from cimserver    @param   httpResponse        Buffer reply from cimserver    @param   ostream             the ostream to which output should be written    @param   estream             the ostream to which errors should be written    @return  true  = wait for data from challenge response

⌨️ 快捷键说明

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