VirtualBox

Changeset 40130 in vbox for trunk/src/VBox/Main/webservice


Ignore:
Timestamp:
Feb 14, 2012 3:17:35 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
76274
Message:

Main/webservice+doc/manual: Add SSL support to the webservice, and also add an optional parameter which ensures the authentication setting is correct. Update manual and SDK reference.

Location:
trunk/src/VBox/Main/webservice
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/Makefile.kmk

    r39876 r40130  
    77
    88#
    9 # Copyright (C) 2006-2011 Oracle Corporation
     9# Copyright (C) 2006-2012 Oracle Corporation
    1010#
    1111# This file is part of VirtualBox Open Source Edition (OSE), as
     
    212212        $(VBOXWEB_OUT_DIR) \
    213213        $(PATH_SUB_CURRENT)
     214 ifdef VBOX_WITH_WEBSERVICES_SSL
     215  vboxsoap_DEFS += WITH_OPENSSL
     216  vboxsoap_SDKS += VBOX_OPENSSL2
     217 endif
    214218 ifdef VBOX_WITHOUT_SPLIT_SOAPC
    215219  vboxsoap_SOURCES = \
     
    287291 vboxwebsrv_LIBS += \
    288292        $(PATH_STAGE_LIB)/vboxsoap$(VBOX_SUFF_LIB) \
    289         $(VBOX_GSOAP_CXX_LIBS)
     293        $(VBOX_GSOAP_CXX_LIBS) \
     294        $(LIB_RUNTIME)
    290295 vboxwebsrv_LIBS.solaris += socket nsl
     296 ifdef VBOX_WITH_WEBSERVICES_SSL
     297  vboxwebsrv_DEFS += WITH_OPENSSL
     298  vboxwebsrv_SDKS += VBOX_OPENSSL2
     299 endif
    291300 vboxwebsrv_SOURCES = \
    292301        vboxweb.cpp \
     
    430439 webtest_LIBS += \
    431440        $(PATH_STAGE_LIB)/vboxsoap$(VBOX_SUFF_LIB) \
    432         $(VBOX_GSOAP_CXX_LIBS)
     441        $(VBOX_GSOAP_CXX_LIBS) \
     442        $(LIB_RUNTIME)
    433443 webtest_LIBS.solaris += nsl
     444 ifdef VBOX_WITH_WEBSERVICES_SSL
     445  webtest_DEFS += WITH_OPENSSL
     446  webtest_SDKS += VBOX_OPENSSL2
     447 endif
    434448 webtest_SOURCES = \
    435449        webtest.cpp \
  • trunk/src/VBox/Main/webservice/vboxweb.cpp

    r38802 r40130  
    66 *      server, to which clients can connect.
    77 *
    8  * Copyright (C) 2006-2011 Oracle Corporation
     8 * Copyright (C) 2006-2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include <VBox/com/com.h>
    2424#include <VBox/com/array.h>
     25#include <VBox/com/string.h>
    2526#include <VBox/com/ErrorInfo.h>
    2627#include <VBox/com/errorprint.h>
     
    4243#include <iprt/rand.h>
    4344#include <iprt/semaphore.h>
     45#include <iprt/critsect.h>
    4446#include <iprt/string.h>
    4547#include <iprt/thread.h>
     
    4850#include <iprt/system.h>
    4951#include <iprt/base64.h>
     52#include <iprt/stream.h>
    5053
    5154// workaround for compile problems on gcc 4.1
     
    7578
    7679RT_C_DECLS_END
     80
     81static void WebLogSoapError(struct soap *soap);
    7782
    7883/****************************************************************************
     
    117122unsigned int            g_uBindToPort = 18083;          // port
    118123unsigned int            g_uBacklog = 100;               // backlog = max queue size for requests
     124
     125#ifdef WITH_OPENSSL
     126bool                    g_fSSL = false;                 // if SSL is enabled
     127const char              *g_pcszKeyFile = NULL;          // server key file
     128const char              *g_pcszPassword = NULL;         // password for server key
     129const char              *g_pcszCACert = NULL;           // file with trusted CA certificates
     130const char              *g_pcszCAPath = NULL;           // directory with trusted CA certificates
     131const char              *g_pcszDHFile = NULL;           // DH file name or DH key length in bits, NULL=use RSA
     132const char              *g_pcszRandFile = NULL;         // file with random data seed
     133const char              *g_pcszSID = "vboxwebsrv";      // server ID for SSL session cache
     134#endif /* WITH_OPENSSL */
     135
    119136unsigned int            g_cMaxWorkerThreads = 100;      // max. no. of worker threads
    120137unsigned int            g_cMaxKeepAlive = 100;          // maximum number of soap requests in one connection
     138
     139const char              *g_pcszAuthentication = NULL;   // web service authentication
    121140
    122141uint32_t                g_cHistory = 10;                // enable log rotation, 10 files
     
    180199        { "--host",             'H', RTGETOPT_REQ_STRING },
    181200        { "--port",             'p', RTGETOPT_REQ_UINT32 },
     201#ifdef WITH_OPENSSL
     202        { "--ssl",              's', RTGETOPT_REQ_NOTHING },
     203        { "--keyfile",          'K', RTGETOPT_REQ_STRING },
     204        { "--passwordfile",     'a', RTGETOPT_REQ_STRING },
     205        { "--cacert",           'c', RTGETOPT_REQ_STRING },
     206        { "--capath",           'C', RTGETOPT_REQ_STRING },
     207        { "--dhfile",           'D', RTGETOPT_REQ_STRING },
     208        { "--randfile",         'r', RTGETOPT_REQ_STRING },
     209#endif /* WITH_OPENSSL */
    182210        { "--timeout",          't', RTGETOPT_REQ_UINT32 },
    183211        { "--check-interval",   'i', RTGETOPT_REQ_UINT32 },
    184212        { "--threads",          'T', RTGETOPT_REQ_UINT32 },
    185213        { "--keepalive",        'k', RTGETOPT_REQ_UINT32 },
     214        { "--authentication",   'A', RTGETOPT_REQ_STRING },
    186215        { "--verbose",          'v', RTGETOPT_REQ_NOTHING },
    187216        { "--pidfile",          'P', RTGETOPT_REQ_STRING },
     
    226255                break;
    227256
     257#ifdef WITH_OPENSSL
     258            case 's':
     259                pcszDescr = "Enable SSL/TLS encryption.";
     260                break;
     261
     262            case 'K':
     263                pcszDescr = "Server key and certificate file, PEM format (\"\").";
     264                break;
     265
     266            case 'a':
     267                pcszDescr = "File name for password to server key (\"\").";
     268                break;
     269
     270            case 'c':
     271                pcszDescr = "CA certificate file, PEM format (\"\").";
     272                break;
     273
     274            case 'C':
     275                pcszDescr = "CA certificate path (\"\").";
     276                break;
     277
     278            case 'D':
     279                pcszDescr = "DH file name or DH key length in bits (\"\").";
     280                break;
     281
     282            case 'r':
     283                pcszDescr = "File containing seed for random number generator (\"\").";
     284                break;
     285#endif /* WITH_OPENSSL */
     286
    228287            case 't':
    229288                pcszDescr = "Session timeout in seconds; 0 = disable timeouts (" DEFAULT_TIMEOUT_SECS_STRING ").";
     
    236295            case 'k':
    237296                pcszDescr = "Maximum number of requests before a socket will be closed (100).";
     297                break;
     298
     299            case 'A':
     300                pcszDescr = "Authentication method for the webservice (\"\").";
    238301                break;
    239302
     
    516579        m_soap->recv_timeout = 60;
    517580        // process the request; this goes into the COM code in methodmaps.cpp
    518         soap_serve(m_soap);
     581        do {
     582#ifdef WITH_OPENSSL
     583            if (g_fSSL && soap_ssl_accept(m_soap))
     584            {
     585                WebLogSoapError(m_soap);
     586                break;
     587            }
     588#endif /* WITH_OPENSSL */
     589            soap_serve(m_soap);
     590        } while (0);
    519591
    520592        soap_destroy(m_soap); // clean up class instances
     
    632704 * @param soap
    633705 */
     706/*static*/
    634707void WebLogSoapError(struct soap *soap)
    635708{
     
    715788}
    716789
     790#ifdef WITH_OPENSSL
    717791/****************************************************************************
    718792 *
     793 * OpenSSL convenience functions for multithread support
     794 *
     795 ****************************************************************************/
     796
     797static RTCRITSECT *g_pSSLMutexes = NULL;
     798
     799struct CRYPTO_dynlock_value
     800{
     801    RTCRITSECT mutex;
     802};
     803
     804static unsigned long CRYPTO_id_function()
     805{
     806    return RTThreadNativeSelf();
     807}
     808
     809static void CRYPTO_locking_function(int mode, int n, const char * /*file*/, int /*line*/)
     810{
     811    if (mode & CRYPTO_LOCK)
     812        RTCritSectEnter(&g_pSSLMutexes[n]);
     813    else
     814        RTCritSectLeave(&g_pSSLMutexes[n]);
     815}
     816
     817static struct CRYPTO_dynlock_value *CRYPTO_dyn_create_function(const char * /*file*/, int /*line*/)
     818{
     819    struct CRYPTO_dynlock_value *value = (struct CRYPTO_dynlock_value *)RTMemAlloc(sizeof(struct CRYPTO_dynlock_value));
     820    if (value)
     821        RTCritSectInit(&value->mutex);
     822
     823    return value;
     824}
     825
     826static void CRYPTO_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *value, const char * /*file*/, int /*line*/)
     827{
     828    if (mode & CRYPTO_LOCK)
     829        RTCritSectEnter(&value->mutex);
     830    else
     831        RTCritSectLeave(&value->mutex);
     832}
     833
     834static void CRYPTO_dyn_destroy_function(struct CRYPTO_dynlock_value *value, const char * /*file*/, int /*line*/)
     835{
     836    if (value)
     837    {
     838        RTCritSectDelete(&value->mutex);
     839        free(value);
     840    }
     841}
     842
     843static int CRYPTO_thread_setup()
     844{
     845    int num_locks = CRYPTO_num_locks();
     846    g_pSSLMutexes = (RTCRITSECT *)RTMemAlloc(num_locks * sizeof(RTCRITSECT));
     847    if (!g_pSSLMutexes)
     848        return SOAP_EOM;
     849
     850    for (int i = 0; i < num_locks; i++)
     851    {
     852        int rc = RTCritSectInit(&g_pSSLMutexes[i]);
     853        if (RT_FAILURE(rc))
     854        {
     855            for ( ; i >= 0; i--)
     856                RTCritSectDelete(&g_pSSLMutexes[i]);
     857            RTMemFree(g_pSSLMutexes);
     858            g_pSSLMutexes = NULL;
     859            return SOAP_EOM;
     860        }
     861    }
     862
     863    CRYPTO_set_id_callback(CRYPTO_id_function);
     864    CRYPTO_set_locking_callback(CRYPTO_locking_function);
     865    CRYPTO_set_dynlock_create_callback(CRYPTO_dyn_create_function);
     866    CRYPTO_set_dynlock_lock_callback(CRYPTO_dyn_lock_function);
     867    CRYPTO_set_dynlock_destroy_callback(CRYPTO_dyn_destroy_function);
     868
     869    return SOAP_OK;
     870}
     871
     872static void CRYPTO_thread_cleanup()
     873{
     874    if (!g_pSSLMutexes)
     875        return;
     876
     877    CRYPTO_set_id_callback(NULL);
     878    CRYPTO_set_locking_callback(NULL);
     879    CRYPTO_set_dynlock_create_callback(NULL);
     880    CRYPTO_set_dynlock_lock_callback(NULL);
     881    CRYPTO_set_dynlock_destroy_callback(NULL);
     882
     883    int num_locks = CRYPTO_num_locks();
     884    for (int i = 0; i < num_locks; i++)
     885        RTCritSectDelete(&g_pSSLMutexes[i]);
     886
     887    RTMemFree(g_pSSLMutexes);
     888    g_pSSLMutexes = NULL;
     889}
     890#endif /* WITH_OPENSSL */
     891
     892/****************************************************************************
     893 *
    719894 * SOAP queue pumper thread
    720895 *
     
    723898void doQueuesLoop()
    724899{
     900#ifdef WITH_OPENSSL
     901    if (g_fSSL && CRYPTO_thread_setup())
     902    {
     903        WebLog("Failed to set up OpenSSL thread mutex!");
     904        exit(RTEXITCODE_FAILURE);
     905    }
     906#endif /* WITH_OPENSSL */
     907
    725908    // set up gSOAP
    726909    struct soap soap;
    727910    soap_init(&soap);
     911
     912#ifdef WITH_OPENSSL
     913    if (g_fSSL && soap_ssl_server_context(&soap, SOAP_SSL_DEFAULT, g_pcszKeyFile,
     914                                         g_pcszPassword, g_pcszCACert, g_pcszCAPath,
     915                                         g_pcszDHFile, g_pcszRandFile, g_pcszSID))
     916    {
     917        WebLogSoapError(&soap);
     918        exit(RTEXITCODE_FAILURE);
     919    }
     920#endif /* WITH_OPENSSL */
    728921
    729922    soap.bind_flags |= SO_REUSEADDR;
     
    739932    else
    740933    {
    741         WebLog("Socket connection successful: host = %s, port = %u, master socket = %d\n",
     934        WebLog("Socket connection successful: host = %s, port = %u, %smaster socket = %d\n",
    742935               (g_pcszBindToHost) ? g_pcszBindToHost : "default (localhost)",
    743936               g_uBindToPort,
     937#ifdef WITH_OPENSSL
     938               g_fSSL ? "SSL, " : "",
     939#else /* !WITH_OPENSSL */
     940               "",
     941#endif /*!WITH_OPENSSL */
    744942               m);
    745943
     
    766964    }
    767965    soap_done(&soap); // close master socket and detach environment
     966
     967#ifdef WITH_OPENSSL
     968    if (g_fSSL)
     969        CRYPTO_thread_cleanup();
     970#endif /* WITH_OPENSSL */
    768971}
    769972
     
    8401043                break;
    8411044
     1045#ifdef WITH_OPENSSL
     1046            case 's':
     1047                g_fSSL = true;
     1048                break;
     1049
     1050            case 'K':
     1051                g_pcszKeyFile = ValueUnion.psz;
     1052                break;
     1053
     1054            case 'a':
     1055                if (ValueUnion.psz[0] == '\0')
     1056                    g_pcszPassword = NULL;
     1057                else
     1058                {
     1059                    PRTSTREAM StrmIn;
     1060                    if (!strcmp(ValueUnion.psz, "-"))
     1061                        StrmIn = g_pStdIn;
     1062                    else
     1063                    {
     1064                        int vrc = RTStrmOpen(ValueUnion.psz, "r", &StrmIn);
     1065                        if (RT_FAILURE(vrc))
     1066                            return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open password file (%s, %Rrc)", ValueUnion.psz, vrc);
     1067                    }
     1068                    char szPasswd[512];
     1069                    int vrc = RTStrmGetLine(StrmIn, szPasswd, sizeof(szPasswd));
     1070                    if (RT_FAILURE(vrc))
     1071                        return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to read password (%s, %Rrc)", ValueUnion.psz, vrc);
     1072                    g_pcszPassword = RTStrDup(szPasswd);
     1073                    memset(szPasswd, '\0', sizeof(szPasswd));
     1074                    if (StrmIn != g_pStdIn)
     1075                        RTStrmClose(StrmIn);
     1076                }
     1077                break;
     1078
     1079            case 'c':
     1080                g_pcszCACert = ValueUnion.psz;
     1081                break;
     1082
     1083            case 'C':
     1084                g_pcszCAPath = ValueUnion.psz;
     1085                break;
     1086
     1087            case 'D':
     1088                g_pcszDHFile = ValueUnion.psz;
     1089                break;
     1090
     1091            case 'r':
     1092                g_pcszRandFile = ValueUnion.psz;
     1093                break;
     1094#endif /* WITH_OPENSSL */
     1095
    8421096            case 't':
    8431097                g_iWatchdogTimeoutSecs = ValueUnion.u32;
     
    8741128            case 'k':
    8751129                g_cMaxKeepAlive = ValueUnion.u32;
     1130                break;
     1131
     1132            case 'A':
     1133                g_pcszAuthentication = ValueUnion.psz;
    8761134                break;
    8771135
     
    9641222#endif
    9651223
     1224    // initialize SOAP SSL support if enabled
     1225#ifdef WITH_OPENSSL
     1226    if (g_fSSL)
     1227        soap_ssl_init();
     1228#endif /* WITH_OPENSSL */
     1229
    9661230    // initialize COM/XPCOM
    9671231    HRESULT hrc = com::Initialize();
     
    9891253        RTMsgError("Failed to get VirtualBox object (rc=%Rhrc)!", hrc);
    9901254        return RTEXITCODE_FAILURE;
     1255    }
     1256
     1257    // set the authentication method if requested
     1258    if (g_pVirtualBox && g_pcszAuthentication && g_pcszAuthentication[0])
     1259    {
     1260        ComPtr<ISystemProperties> pSystemProperties;
     1261        g_pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
     1262        if (pSystemProperties)
     1263            pSystemProperties->COMSETTER(WebServiceAuthLibrary)(com::Bstr(g_pcszAuthentication).raw());
    9911264    }
    9921265
     
    11141387                ++it;
    11151388        }
     1389
     1390        // re-set the authentication method in case it has been changed
     1391        if (g_pVirtualBox && g_pcszAuthentication && g_pcszAuthentication[0])
     1392        {
     1393            ComPtr<ISystemProperties> pSystemProperties;
     1394            g_pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
     1395            if (pSystemProperties)
     1396                pSystemProperties->COMSETTER(WebServiceAuthLibrary)(com::Bstr(g_pcszAuthentication).raw());
     1397        }
    11161398    }
    11171399
  • trunk/src/VBox/Main/webservice/webtest.cpp

    r33451 r40130  
    44 *      functionality of VBoxManage for testing purposes.
    55 *
    6  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2012 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626
    2727
     28static void usage(int exitcode)
     29{
     30    std::cout <<
     31       "webtest: VirtualBox webservice testcase.\n"
     32       "\nUsage: webtest [options] [command]...\n"
     33       "\nSupported options:\n"
     34       " -h: print this help message and exit.\n"
     35       " -c URL: specify the webservice server URL (default http://localhost:18083/).\n"
     36       "\nSupported commands:\n"
     37       " - IWebsessionManager:\n"
     38       "   - webtest logon <user> <pass>: IWebsessionManager::logon().\n"
     39       "   - webtest getsession <vboxref>: IWebsessionManager::getSessionObject().\n"
     40       "   - webtest logoff <vboxref>: IWebsessionManager::logoff().\n"
     41       " - IVirtualBox:\n"
     42       "   - webtest version <vboxref>: IVirtualBox::getVersion().\n"
     43       "   - webtest gethost <vboxref>: IVirtualBox::getHost().\n"
     44       "   - webtest getpc <vboxref>: IVirtualBox::getPerformanceCollector().\n"
     45       "   - webtest getmachines <vboxref>: IVirtualBox::getMachines().\n"
     46       "   - webtest createmachine <vboxref> <settingsPath> <name>: IVirtualBox::createMachine().\n"
     47       "   - webtest registermachine <vboxref> <machineref>: IVirtualBox::registerMachine().\n"
     48       " - IHost:\n"
     49       "   - webtest getdvddrives <hostref>: IHost::getDVDDrives.\n"
     50       " - IHostDVDDrive:\n"
     51       "   - webtest getdvdname <dvdref>: IHostDVDDrive::getname.\n"
     52       " - IMachine:\n"
     53       "   - webtest getname <machineref>: IMachine::getName().\n"
     54       "   - webtest getid <machineref>: IMachine::getId().\n"
     55       "   - webtest getostype <machineref>: IMachine::getGuestOSType().\n"
     56       "   - webtest savesettings <machineref>: IMachine::saveSettings().\n"
     57       " - IPerformanceCollector:\n"
     58       "   - webtest setupmetrics <pcref>: IPerformanceCollector::setupMetrics()\n"
     59       "   - webtest querymetricsdata <pcref>: IPerformanceCollector::QueryMetricsData()\n"
     60       " - All managed object references:\n"
     61       "   - webtest getif <ref>: report interface of object.\n"
     62       "   - webtest release <ref>: IUnknown::Release().\n";
     63    exit(exitcode);
     64}
     65
    2866/**
    2967 *
     
    3472int main(int argc, char* argv[])
    3573{
     74    bool fSSL = false;
     75    const char *pcszArgEndpoint = "http://localhost:18083/";
     76
     77    int ap;
     78    for (ap = 1; ap <= argc; ap++)
     79    {
     80        if (argv[ap][0] == '-')
     81        {
     82            if (!strcmp(argv[ap], "-h"))
     83                usage(0);
     84            else if (!strcmp(argv[ap], "-c"))
     85            {
     86                ap++;
     87                if (ap > argc)
     88                    usage(1);
     89                pcszArgEndpoint = argv[ap];
     90                fSSL = !strncmp(pcszArgEndpoint, "https://", 8);
     91            }
     92            else
     93                usage(1);
     94        }
     95        else
     96            break;
     97    }
     98
     99    if (argc < 1 + ap)
     100        usage(1);
     101
     102#ifdef WITH_OPENSSL
     103    if (fSSL)
     104        soap_ssl_init();
     105#endif /* WITH_OPENSSL */
     106
    36107    struct soap soap; // gSOAP runtime environment
    37108    soap_init(&soap); // initialize runtime environment (only once)
    38 
    39     if (argc < 2)
    40     {
    41         std::cout <<
    42                "webtest: VirtualBox webservice testcase.\n"
    43                "Usage:\n"
    44                " - IWebsessionManager:\n"
    45                "   - webtest logon <user> <pass>: IWebsessionManager::logon().\n"
    46                "   - webtest getsession <vboxref>: IWebsessionManager::getSessionObject().\n"
    47                "   - webtest logoff <vboxref>: IWebsessionManager::logoff().\n"
    48                " - IVirtualBox:\n"
    49                "   - webtest version <vboxref>: IVirtualBox::getVersion().\n"
    50                "   - webtest gethost <vboxref>: IVirtualBox::getHost().\n"
    51                "   - webtest getpc <vboxref>: IVirtualBox::getPerformanceCollector().\n"
    52                "   - webtest getmachines <vboxref>: IVirtualBox::getMachines().\n"
    53                "   - webtest createmachine <vboxref> <settingsPath> <name>: IVirtualBox::createMachine().\n"
    54                "   - webtest registermachine <vboxref> <machineref>: IVirtualBox::registerMachine().\n"
    55                " - IHost:\n"
    56                "   - webtest getdvddrives <hostref>: IHost::getDVDDrives.\n"
    57                " - IHostDVDDrive:\n"
    58                "   - webtest getdvdname <dvdref>: IHostDVDDrive::getname.\n"
    59                " - IMachine:\n"
    60                "   - webtest getname <machineref>: IMachine::getName().\n"
    61                "   - webtest getid <machineref>: IMachine::getId().\n"
    62                "   - webtest getostype <machineref>: IMachine::getGuestOSType().\n"
    63                "   - webtest savesettings <machineref>: IMachine::saveSettings().\n"
    64                " - IPerformanceCollector:\n"
    65                "   - webtest setupmetrics <pcref>: IPerformanceCollector::setupMetrics()\n"
    66                "   - webtest querymetricsdata <pcref>: IPerformanceCollector::QueryMetricsData()\n"
    67                " - All managed object references:\n"
    68                "   - webtest getif <ref>: report interface of object.\n"
    69                "   - webtest release <ref>: IUnknown::Release().\n";
     109#ifdef WITH_OPENSSL
     110    // Use SOAP_SSL_NO_AUTHENTICATION here to accept broken server configs.
     111    // In a real world setup please use at least SOAP_SSL_DEFAULT and provide
     112    // the necessary CA certificate for validating the server's certificate.
     113    if (fSSL && soap_ssl_client_context(&soap, SOAP_SSL_NO_AUTHENTICATION,
     114                                        NULL /*clientkey*/, NULL /*password*/,
     115                                        NULL /*cacert*/, NULL /*capath*/,
     116                                        NULL /*randfile*/))
     117    {
     118        soap_print_fault(&soap, stderr);
    70119        exit(1);
    71120    }
    72 
    73     const char *pcszArgEndpoint = "localhost:18083";
    74 
    75     const char *pcszMode = argv[1];
    76     int soaprc = 2;
     121#endif /* WITH_OPENSSL */
     122
     123    const char *pcszMode = argv[ap];
     124    int soaprc = SOAP_SVR_FAULT;
    77125
    78126    if (!strcmp(pcszMode, "logon"))
    79127    {
    80         if (argc < 4)
     128        if (argc < 3 + ap)
    81129            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    82130        else
    83131        {
    84132            _vbox__IWebsessionManager_USCORElogon req;
    85             req.username = argv[2];
    86             req.password = argv[3];
     133            req.username = argv[ap + 1];
     134            req.password = argv[ap + 2];
    87135            _vbox__IWebsessionManager_USCORElogonResponse resp;
    88136
     
    97145    else if (!strcmp(pcszMode, "getsession"))
    98146    {
    99         if (argc < 3)
     147        if (argc < 2 + ap)
    100148            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    101149        else
    102150        {
    103151            _vbox__IWebsessionManager_USCOREgetSessionObject req;
    104             req.refIVirtualBox = argv[2];
     152            req.refIVirtualBox = argv[ap + 1];
    105153            _vbox__IWebsessionManager_USCOREgetSessionObjectResponse resp;
    106154
     
    115163    else if (!strcmp(pcszMode, "logoff"))
    116164    {
    117         if (argc < 3)
     165        if (argc < 2 + ap)
    118166            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    119167        else
    120168        {
    121169            _vbox__IWebsessionManager_USCORElogoff req;
    122             req.refIVirtualBox = argv[2];
     170            req.refIVirtualBox = argv[ap + 1];
    123171            _vbox__IWebsessionManager_USCORElogoffResponse resp;
    124172
     
    135183    else if (!strcmp(pcszMode, "version"))
    136184    {
    137         if (argc < 3)
     185        if (argc < 2 + ap)
    138186            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    139187        else
    140188        {
    141189            _vbox__IVirtualBox_USCOREgetVersion req;
    142             req._USCOREthis = argv[2];
     190            req._USCOREthis = argv[ap + 1];
    143191            _vbox__IVirtualBox_USCOREgetVersionResponse resp;
    144192
     
    153201    else if (!strcmp(pcszMode, "gethost"))
    154202    {
    155         if (argc < 3)
     203        if (argc < 2 + ap)
    156204            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    157205        else
    158206        {
    159207            _vbox__IVirtualBox_USCOREgetHost req;
    160             req._USCOREthis = argv[2];
     208            req._USCOREthis = argv[ap + 1];
    161209            _vbox__IVirtualBox_USCOREgetHostResponse resp;
    162210
     
    173221    else if (!strcmp(pcszMode, "getpc"))
    174222    {
    175         if (argc < 3)
     223        if (argc < 2 + ap)
    176224            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    177225        else
    178226        {
    179227            _vbox__IVirtualBox_USCOREgetPerformanceCollector req;
    180             req._USCOREthis = argv[2];
     228            req._USCOREthis = argv[ap + 1];
    181229            _vbox__IVirtualBox_USCOREgetPerformanceCollectorResponse resp;
    182230
     
    193241    else if (!strcmp(pcszMode, "getmachines"))
    194242    {
    195         if (argc < 3)
     243        if (argc < 2 + ap)
    196244            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    197245        else
    198246        {
    199247            _vbox__IVirtualBox_USCOREgetMachines req;
    200             req._USCOREthis = argv[2];
     248            req._USCOREthis = argv[ap + 1];
    201249            _vbox__IVirtualBox_USCOREgetMachinesResponse resp;
    202250
     
    219267    else if (!strcmp(pcszMode, "createmachine"))
    220268    {
    221         if (argc < 5)
     269        if (argc < 4 + ap)
    222270            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    223271        else
    224272        {
    225273            _vbox__IVirtualBox_USCOREcreateMachine req;
    226             req._USCOREthis = argv[2];
    227             req.settingsFile = argv[3];
    228             req.name = argv[4];
     274            req._USCOREthis = argv[ap + 1];
     275            req.settingsFile = argv[ap + 2];
     276            req.name = argv[ap + 3];
    229277            std::cout << "createmachine: settingsFile = \"" << req.settingsFile << "\", name = \"" << req.name << "\"\n";
    230278            _vbox__IVirtualBox_USCOREcreateMachineResponse resp;
     
    240288    else if (!strcmp(pcszMode, "registermachine"))
    241289    {
    242         if (argc < 4)
     290        if (argc < 3 + ap)
    243291            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    244292        else
    245293        {
    246294            _vbox__IVirtualBox_USCOREregisterMachine req;
    247             req._USCOREthis = argv[2];
    248             req.machine = argv[3];
     295            req._USCOREthis = argv[ap + 1];
     296            req.machine = argv[ap + 2];
    249297            _vbox__IVirtualBox_USCOREregisterMachineResponse resp;
    250298            if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREregisterMachine(&soap,
     
    258306    else if (!strcmp(pcszMode, "getdvddrives"))
    259307    {
    260         if (argc < 3)
     308        if (argc < 2 + ap)
    261309            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    262310        else
    263311        {
    264312            _vbox__IHost_USCOREgetDVDDrives req;
    265             req._USCOREthis = argv[2];
     313            req._USCOREthis = argv[ap + 1];
    266314            _vbox__IHost_USCOREgetDVDDrivesResponse resp;
    267315            if (!(soaprc = soap_call___vbox__IHost_USCOREgetDVDDrives(&soap,
     
    283331    else if (!strcmp(pcszMode, "getname"))
    284332    {
    285         if (argc < 3)
     333        if (argc < 2 + ap)
    286334            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    287335        else
    288336        {
    289337            _vbox__IMachine_USCOREgetName req;
    290             req._USCOREthis = argv[2];
     338            req._USCOREthis = argv[ap + 1];
    291339            _vbox__IMachine_USCOREgetNameResponse resp;
    292340            if (!(soaprc = soap_call___vbox__IMachine_USCOREgetName(&soap,
     
    300348    else if (!strcmp(pcszMode, "getid"))
    301349    {
    302         if (argc < 3)
     350        if (argc < 2 + ap)
    303351            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    304352        else
    305353        {
    306354            _vbox__IMachine_USCOREgetId req;
    307             req._USCOREthis = argv[2];
     355            req._USCOREthis = argv[ap + 1];
    308356            _vbox__IMachine_USCOREgetIdResponse resp;
    309357            if (!(soaprc = soap_call___vbox__IMachine_USCOREgetId(&soap,
     
    317365    else if (!strcmp(pcszMode, "getostypeid"))
    318366    {
    319         if (argc < 3)
     367        if (argc < 2 + ap)
    320368            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    321369        else
    322370        {
    323371            _vbox__IMachine_USCOREgetOSTypeId req;
    324             req._USCOREthis = argv[2];
     372            req._USCOREthis = argv[ap + 1];
    325373            _vbox__IMachine_USCOREgetOSTypeIdResponse resp;
    326374            if (!(soaprc = soap_call___vbox__IMachine_USCOREgetOSTypeId(&soap,
     
    334382    else if (!strcmp(pcszMode, "savesettings"))
    335383    {
    336         if (argc < 3)
     384        if (argc < 2 + ap)
    337385            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    338386        else
    339387        {
    340388            _vbox__IMachine_USCOREsaveSettings req;
    341             req._USCOREthis = argv[2];
     389            req._USCOREthis = argv[ap + 1];
    342390            _vbox__IMachine_USCOREsaveSettingsResponse resp;
    343391            if (!(soaprc = soap_call___vbox__IMachine_USCOREsaveSettings(&soap,
     
    351399    else if (!strcmp(pcszMode, "setupmetrics"))
    352400    {
    353         if (argc < 3)
     401        if (argc < 2 + ap)
    354402            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    355403        else
    356404        {
    357405            _vbox__IPerformanceCollector_USCOREsetupMetrics req;
    358             req._USCOREthis = argv[2];
     406            req._USCOREthis = argv[ap + 1];
    359407//             req.metricNames[0] = "*";
    360408//             req.objects
     
    380428    else if (!strcmp(pcszMode, "querymetricsdata"))
    381429    {
    382         if (argc < 3)
     430        if (argc < 2 + ap)
    383431            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    384432        else
    385433        {
    386434            _vbox__IPerformanceCollector_USCOREqueryMetricsData req;
    387             req._USCOREthis = argv[2];
     435            req._USCOREthis = argv[ap + 1];
    388436//             req.metricNames[0] = "*";
    389437//             req.objects
     
    407455    else if (!strcmp(pcszMode, "release"))
    408456    {
    409         if (argc < 3)
     457        if (argc < 2 + ap)
    410458            std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
    411459        else
    412460        {
    413461            _vbox__IManagedObjectRef_USCORErelease req;
    414             req._USCOREthis = argv[2];
     462            req._USCOREthis = argv[ap + 1];
    415463            _vbox__IManagedObjectRef_USCOREreleaseResponse resp;
    416464            if (!(soaprc = soap_call___vbox__IManagedObjectRef_USCORErelease(&soap,
     
    435483                std::cout << "Bad object ID: " << soap.fault->detail->vbox__InvalidObjectFault->badObjectID << "\n";
    436484            }
    437             if (soap.fault->detail->vbox__RuntimeFault)
     485            else if (soap.fault->detail->vbox__RuntimeFault)
    438486            {
    439487                std::cout << "Result code:   0x" << std::hex << soap.fault->detail->vbox__RuntimeFault->resultCode << "\n";
     
    442490                std::cout << "Interface ID:  " << std::hex << soap.fault->detail->vbox__RuntimeFault->interfaceID << "\n";
    443491            }
     492            else
     493            {
     494                // generic fault
     495                std::cerr << "Generic fault message:\n";
     496                soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream
     497            }
    444498        }
    445499        else
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette