VirtualBox

Changeset 42444 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 30, 2012 11:56:33 AM (13 years ago)
Author:
vboxsync
Message:

Frontends/VBoxManage: add options to specify passwords through a file

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r42125 r42444  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    247247
    248248#ifndef VBOX_ONLY_DOCS
    249 static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFile)
     249RTEXITCODE readPasswordFile(const char *pszFilename, com::Utf8Str *pPasswd)
    250250{
    251251    size_t cbFile;
     
    253253    int vrc = VINF_SUCCESS;
    254254    RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
    255     bool fStdIn = !strcmp(pszFile, "stdin");
     255    bool fStdIn = !strcmp(pszFilename, "stdin");
    256256    PRTSTREAM pStrm;
    257257    if (!fStdIn)
    258         vrc = RTStrmOpen(pszFile, "r", &pStrm);
     258        vrc = RTStrmOpen(pszFilename, "r", &pStrm);
    259259    else
    260260        pStrm = g_pStdIn;
     
    265265        {
    266266            if (cbFile >= sizeof(szPasswd)-1)
    267                 rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Provided password too long");
     267                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Provided password in file '%s' is too long", pszFilename);
    268268            else
    269269            {
     
    272272                    ;
    273273                szPasswd[i] = '\0';
    274                 int rc;
    275                 CHECK_ERROR(virtualBox, SetSettingsSecret(com::Bstr(szPasswd).raw()));
    276                 if (FAILED(rc))
    277                     rcExit = RTEXITCODE_FAILURE;
    278             }
    279         }
     274                *pPasswd = szPasswd;
     275            }
     276        }
     277        else
     278            rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot read password from file '%s': %Rrc", pszFilename, vrc);
    280279        if (!fStdIn)
    281280            RTStrmClose(pStrm);
    282281    }
    283282    else
    284         rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot open password file '%s' (%Rrc)", pszFile);
     283        rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot open password file '%s' (%Rrc)", pszFilename, vrc);
     284
     285    return rcExit;
     286}
     287
     288static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFilename)
     289{
     290    com::Utf8Str passwd;
     291    RTEXITCODE rcExit = readPasswordFile(pszFilename, &passwd);
     292    if (rcExit == RTEXITCODE_SUCCESS)
     293    {
     294        int rc;
     295        CHECK_ERROR(virtualBox, SetSettingsSecret(com::Bstr(passwd).raw()));
     296        if (FAILED(rc))
     297            rcExit = RTEXITCODE_FAILURE;
     298    }
    285299
    286300    return rcExit;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r42442 r42444  
    162162
    163163#ifndef VBOX_ONLY_DOCS
     164RTEXITCODE readPasswordFile(const char *pszFilename, com::Utf8Str *pPasswd);
     165
    164166int handleInternalCommands(HandlerArg *a);
    165167#endif /* !VBOX_ONLY_DOCS */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageControlVM.cpp

    r42261 r42444  
    953953        {
    954954            bool fAllowLocalLogon = true;
    955             if (a->argc == 7)
    956             {
    957                 if (   strcmp(a->argv[5], "--allowlocallogon")
    958                     && strcmp(a->argv[5], "-allowlocallogon"))
     955            if (   a->argc == 7
     956                || (   a->argc == 8
     957                    && (   !strcmp(a->argv[3], "-p")
     958                        || !strcmp(a->argv[3], "--passwordfile"))))
     959            {
     960                if (   strcmp(a->argv[5 + (a->argc - 7)], "--allowlocallogon")
     961                    && strcmp(a->argv[5 + (a->argc - 7)], "-allowlocallogon"))
    959962                {
    960963                    errorArgument("Invalid parameter '%s'", a->argv[5]);
     
    962965                    break;
    963966                }
    964                 if (!strcmp(a->argv[6], "no"))
     967                if (!strcmp(a->argv[6 + (a->argc - 7)], "no"))
    965968                    fAllowLocalLogon = false;
    966969            }
    967             else if (a->argc != 5)
     970            else if (   a->argc != 5
     971                     && (   a->argc != 6
     972                         || (   strcmp(a->argv[3], "-p")
     973                             && strcmp(a->argv[3], "--passwordfile"))))
    968974            {
    969975                errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
    970976                rc = E_FAIL;
    971977                break;
     978            }
     979            Utf8Str passwd, domain;
     980            if (a->argc == 5 || a->argc == 7)
     981            {
     982                passwd = a->argv[3];
     983                domain = a->argv[4];
     984            }
     985            else
     986            {
     987                RTEXITCODE rcExit = readPasswordFile(a->argv[4], &passwd);
     988                if (rcExit != RTEXITCODE_SUCCESS)
     989                {
     990                    rc = E_FAIL;
     991                    break;
     992                }
     993                domain = a->argv[5];
    972994            }
    973995
     
    975997            CHECK_ERROR_BREAK(console, COMGETTER(Guest)(guest.asOutParam()));
    976998            CHECK_ERROR_BREAK(guest, SetCredentials(Bstr(a->argv[2]).raw(),
    977                                                     Bstr(a->argv[3]).raw(),
    978                                                     Bstr(a->argv[4]).raw(),
     999                                                    Bstr(passwd).raw(),
     1000                                                    Bstr(domain).raw(),
    9791001                                                    fAllowLocalLogon));
    9801002        }
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r40687 r42444  
    55
    66/*
    7  * Copyright (C) 2010-2011 Oracle Corporation
     7 * Copyright (C) 2010-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    183183    GETOPTDEF_EXEC_DOS2UNIX,
    184184    GETOPTDEF_EXEC_UNIX2DOS,
     185    GETOPTDEF_EXEC_PASSWORD,
    185186    GETOPTDEF_EXEC_WAITFOREXIT,
    186187    GETOPTDEF_EXEC_WAITFORSTDOUT,
     
    188189};
    189190
    190 enum GETOPTDEF_COPYFROM
    191 {
    192     GETOPTDEF_COPYFROM_DRYRUN = 1000,
    193     GETOPTDEF_COPYFROM_FOLLOW,
    194     GETOPTDEF_COPYFROM_PASSWORD,
    195     GETOPTDEF_COPYFROM_TARGETDIR,
    196     GETOPTDEF_COPYFROM_USERNAME
     191enum GETOPTDEF_COPY
     192{
     193    GETOPTDEF_COPY_DRYRUN = 1000,
     194    GETOPTDEF_COPY_FOLLOW,
     195    GETOPTDEF_COPY_PASSWORD,
     196    GETOPTDEF_COPY_TARGETDIR
    197197};
    198198
    199 enum GETOPTDEF_COPYTO
    200 {
    201     GETOPTDEF_COPYTO_DRYRUN = 1000,
    202     GETOPTDEF_COPYTO_FOLLOW,
    203     GETOPTDEF_COPYTO_PASSWORD,
    204     GETOPTDEF_COPYTO_TARGETDIR,
    205     GETOPTDEF_COPYTO_USERNAME
     199enum GETOPTDEF_MKDIR
     200{
     201    GETOPTDEF_MKDIR_PASSWORD = 1000
    206202};
    207203
    208 enum GETOPTDEF_MKDIR
    209 {
    210     GETOPTDEF_MKDIR_PASSWORD = 1000,
    211     GETOPTDEF_MKDIR_USERNAME
    212 };
    213 
    214204enum GETOPTDEF_STAT
    215205{
    216     GETOPTDEF_STAT_PASSWORD = 1000,
    217     GETOPTDEF_STAT_USERNAME
     206    GETOPTDEF_STAT_PASSWORD = 1000
    218207};
    219208
     
    234223                 "VBoxManage guestcontrol     <vmname>|<uuid>\n"
    235224                 "                            exec[ute]\n"
    236                  "                            --image <path to program>\n"
    237                  "                            --username <name> --password <password>\n"
    238                  "                            [--dos2unix]\n"
     225                 "                            --image <path to program> --username <name>\n"
     226                 "                            --passwordfile <file> | --password <password>\n"
    239227                 "                            [--environment \"<NAME>=<VALUE> [<NAME>=<VALUE>]\"]\n"
    240                  "                            [--timeout <msec>] [--unix2dos] [--verbose]\n"
     228                 "                            [--verbose] [--timeout <msec>]\n"
    241229                 "                            [--wait-exit] [--wait-stdout] [--wait-stderr]\n"
     230                 "                            [--dos2unix] [--unix2dos]\n"
    242231                 "                            [-- [<argument1>] ... [<argumentN>]]\n"
    243232                 /** @todo Add a "--" parameter (has to be last parameter) to directly execute
     
    245234                 "\n"
    246235                 "                            copyfrom\n"
    247                  "                            <source on guest> <destination on host>\n"
    248                  "                            --username <name> --password <password>\n"
     236                 "                            <guest source> <host dest> --username <name>\n"
     237                 "                            --passwordfile <file> | --password <password>\n"
    249238                 "                            [--dryrun] [--follow] [--recursive] [--verbose]\n"
    250239                 "\n"
    251240                 "                            copyto|cp\n"
    252                  "                            <source on host> <destination on guest>\n"
    253                  "                            --username <name> --password <password>\n"
     241                 "                            <host source> <guest dest> --username <name>\n"
     242                 "                            --passwordfile <file> | --password <password>\n"
    254243                 "                            [--dryrun] [--follow] [--recursive] [--verbose]\n"
    255244                 "\n"
    256245                 "                            createdir[ectory]|mkdir|md\n"
    257                  "                            <director[y|ies] to create on guest>\n"
    258                  "                            --username <name> --password <password>\n"
     246                 "                            <guest directory>... --username <name>\n"
     247                 "                            --passwordfile <file> | --password <password>\n"
    259248                 "                            [--parents] [--mode <mode>] [--verbose]\n"
    260249                 "\n"
    261250                 "                            stat\n"
    262                  "                            <file element(s) to check on guest>\n"
    263                  "                            --username <name> --password <password>\n"
     251                 "                            <file>... --username <name>\n"
     252                 "                            --passwordfile <file> | --password <password>\n"
    264253                 "                            [--verbose]\n"
    265254                 "\n"
     
    597586}
    598587
    599 /* <Missing docuemntation> */
     588/* <Missing documentation> */
    600589static int handleCtrlExecProgram(ComPtr<IGuest> pGuest, HandlerArg *pArg)
    601590{
     
    616605        { "--image",                        'i',                                      RTGETOPT_REQ_STRING  },
    617606        { "--no-profile",                   GETOPTDEF_EXEC_NO_PROFILE,                RTGETOPT_REQ_NOTHING },
    618         { "--password",                     'p',                                      RTGETOPT_REQ_STRING  },
     607        { "--passwordfile",                 'p',                                      RTGETOPT_REQ_STRING  },
     608        { "--password",                     GETOPTDEF_EXEC_PASSWORD,                  RTGETOPT_REQ_STRING  },
    619609        { "--timeout",                      't',                                      RTGETOPT_REQ_UINT32  },
    620610        { "--unix2dos",                     GETOPTDEF_EXEC_UNIX2DOS,                  RTGETOPT_REQ_NOTHING },
     
    685675            /** @todo Add a hidden flag. */
    686676
    687             case 'p': /* Password */
     677            case GETOPTDEF_EXEC_PASSWORD: /* Password */
    688678                Utf8Password = ValueUnion.psz;
    689679                break;
     680
     681            case 'p': /* Password file */
     682            {
     683                RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &Utf8Password);
     684                if (rcExit != RTEXITCODE_SUCCESS)
     685                    return rcExit;
     686                break;
     687            }
    690688
    691689            case 't': /* Timeout */
     
    761759
    762760    /* Execute the process. */
    763     int rcProc = RTEXITCODE_FAILURE;
     761    int rcExit = RTEXITCODE_FAILURE;
    764762    ComPtr<IProgress> progress;
    765763    ULONG uPID = 0;
     
    872870            if (fVerbose)
    873871                RTPrintf("Process execution canceled!\n");
    874             rcProc = EXITCODEEXEC_CANCELED;
     872            rcExit = EXITCODEEXEC_CANCELED;
    875873        }
    876874        else if (   fCompleted
     
    890888                    if (fVerbose)
    891889                        RTPrintf("Exit code=%u (Status=%u [%s], Flags=%u)\n", uRetExitCode, retStatus, ctrlExecProcessStatusToText(retStatus), uRetFlags);
    892                     rcProc = ctrlExecProcessStatusToExitCode(retStatus, uRetExitCode);
     890                    rcExit = ctrlExecProcessStatusToExitCode(retStatus, uRetExitCode);
    893891                }
    894892                else
    895893                {
    896894                    ctrlPrintError(pGuest, COM_IIDOF(IGuest));
    897                     rcProc = RTEXITCODE_FAILURE;
     895                    rcExit = RTEXITCODE_FAILURE;
    898896                }
    899897            }
     
    903901            if (fVerbose)
    904902                RTPrintf("Process execution aborted!\n");
    905             rcProc = EXITCODEEXEC_TERM_ABEND;
     903            rcExit = EXITCODEEXEC_TERM_ABEND;
    906904        }
    907905    }
     
    909907    if (RT_FAILURE(vrc) || FAILED(rc))
    910908        return RTEXITCODE_FAILURE;
    911     return rcProc;
     909    return rcExit;
    912910}
    913911
     
    17991797}
    18001798
    1801 static int handleCtrlCopyTo(ComPtr<IGuest> guest, HandlerArg *pArg,
    1802                             bool fHostToGuest)
     1799static int handleCtrlCopy(ComPtr<IGuest> guest, HandlerArg *pArg,
     1800                          bool fHostToGuest)
    18031801{
    18041802    AssertPtrReturn(pArg, VERR_INVALID_PARAMETER);
     
    18201818    static const RTGETOPTDEF s_aOptions[] =
    18211819    {
    1822         { "--dryrun",              GETOPTDEF_COPYTO_DRYRUN,         RTGETOPT_REQ_NOTHING },
    1823         { "--follow",              GETOPTDEF_COPYTO_FOLLOW,         RTGETOPT_REQ_NOTHING },
    1824         { "--password",            GETOPTDEF_COPYTO_PASSWORD,       RTGETOPT_REQ_STRING  },
     1820        { "--dryrun",              GETOPTDEF_COPY_DRYRUN,           RTGETOPT_REQ_NOTHING },
     1821        { "--follow",              GETOPTDEF_COPY_FOLLOW,           RTGETOPT_REQ_NOTHING },
     1822        { "--passwordfile",        'p',                             RTGETOPT_REQ_STRING  },
     1823        { "--password",            GETOPTDEF_COPY_PASSWORD,         RTGETOPT_REQ_STRING  },
    18251824        { "--recursive",           'R',                             RTGETOPT_REQ_NOTHING },
    1826         { "--target-directory",    GETOPTDEF_COPYTO_TARGETDIR,      RTGETOPT_REQ_STRING  },
    1827         { "--username",            GETOPTDEF_COPYTO_USERNAME,       RTGETOPT_REQ_STRING  },
     1825        { "--target-directory",    GETOPTDEF_COPY_TARGETDIR,        RTGETOPT_REQ_STRING  },
     1826        { "--username",            'u',                             RTGETOPT_REQ_STRING  },
    18281827        { "--verbose",             'v',                             RTGETOPT_REQ_NOTHING }
    18291828    };
     
    18521851        switch (ch)
    18531852        {
    1854             case GETOPTDEF_COPYTO_DRYRUN:
     1853            case GETOPTDEF_COPY_DRYRUN:
    18551854                fDryRun = true;
    18561855                break;
    18571856
    1858             case GETOPTDEF_COPYTO_FOLLOW:
     1857            case GETOPTDEF_COPY_FOLLOW:
    18591858                fFlags |= CopyFileFlag_FollowLinks;
    18601859                break;
    18611860
    1862             case GETOPTDEF_COPYTO_PASSWORD:
     1861            case GETOPTDEF_COPY_PASSWORD: /* Password */
    18631862                Utf8Password = ValueUnion.psz;
    18641863                break;
     1864
     1865            case 'p': /* Password file */
     1866            {
     1867                RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &Utf8Password);
     1868                if (rcExit != RTEXITCODE_SUCCESS)
     1869                    return rcExit;
     1870                break;
     1871            }
    18651872
    18661873            case 'R': /* Recursive processing */
     
    18681875                break;
    18691876
    1870             case GETOPTDEF_COPYTO_TARGETDIR:
     1877            case GETOPTDEF_COPY_TARGETDIR:
    18711878                Utf8Dest = ValueUnion.psz;
    18721879                break;
    18731880
    1874             case GETOPTDEF_COPYTO_USERNAME:
     1881            case 'u': /* User name */
    18751882                Utf8UserName = ValueUnion.psz;
    18761883                break;
     
    20812088        { "--mode",                'm',                             RTGETOPT_REQ_UINT32  },
    20822089        { "--parents",             'P',                             RTGETOPT_REQ_NOTHING },
     2090        { "--passwordfile",        'p',                             RTGETOPT_REQ_STRING  },
    20832091        { "--password",            GETOPTDEF_MKDIR_PASSWORD,        RTGETOPT_REQ_STRING  },
    2084         { "--username",            GETOPTDEF_MKDIR_USERNAME,        RTGETOPT_REQ_STRING  },
     2092        { "--username",            'u',                             RTGETOPT_REQ_STRING  },
    20852093        { "--verbose",             'v',                             RTGETOPT_REQ_NOTHING }
    20862094    };
     
    21002108    DESTDIRMAP mapDirs;
    21012109
    2102     RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
    2103     while (   (ch = RTGetOpt(&GetState, &ValueUnion))
    2104            && rcExit == RTEXITCODE_SUCCESS)
     2110    while ((ch = RTGetOpt(&GetState, &ValueUnion)))
    21052111    {
    21062112        /* For options that require an argument, ValueUnion has received the value. */
     
    21192125                break;
    21202126
    2121             case GETOPTDEF_MKDIR_USERNAME: /* User name */
     2127            case 'p': /* Password file */
     2128            {
     2129                RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &Utf8Password);
     2130                if (rcExit != RTEXITCODE_SUCCESS)
     2131                    return rcExit;
     2132                break;
     2133            }
     2134
     2135            case 'u': /* User name */
    21222136                Utf8UserName = ValueUnion.psz;
    21232137                break;
     
    21342148
    21352149            default:
    2136                 rcExit = RTGetOptPrintError(ch, &ValueUnion);
    2137                 break;
     2150                return RTGetOptPrintError(ch, &ValueUnion);
    21382151        }
    21392152    }
    21402153
    21412154    uint32_t cDirs = mapDirs.size();
    2142     if (rcExit == RTEXITCODE_SUCCESS && !cDirs)
    2143         rcExit = errorSyntax(USAGE_GUESTCONTROL, "No directory to create specified!");
    2144 
    2145     if (rcExit == RTEXITCODE_SUCCESS && Utf8UserName.isEmpty())
    2146         rcExit = errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
    2147 
    2148     if (rcExit == RTEXITCODE_SUCCESS)
    2149     {
    2150         /*
    2151          * Create the directories.
    2152          */
    2153         HRESULT hrc = S_OK;
    2154         if (fVerbose && cDirs)
    2155             RTPrintf("Creating %u directories ...\n", cDirs);
    2156 
    2157         DESTDIRMAPITER it = mapDirs.begin();
    2158         while (it != mapDirs.end())
    2159         {
    2160             if (fVerbose)
    2161                 RTPrintf("Creating directory \"%s\" ...\n", it->first.c_str());
    2162 
    2163             hrc = guest->DirectoryCreate(Bstr(it->first).raw(),
    2164                                          Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(),
    2165                                          fDirMode, fFlags);
    2166             if (FAILED(hrc))
    2167             {
    2168                 ctrlPrintError(guest, COM_IIDOF(IGuest)); /* Return code ignored, save original rc. */
    2169                 break;
    2170             }
    2171 
    2172             it++;
    2173         }
    2174 
     2155    if (!cDirs)
     2156        return errorSyntax(USAGE_GUESTCONTROL, "No directory to create specified!");
     2157
     2158    if (Utf8UserName.isEmpty())
     2159        return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
     2160
     2161    /*
     2162     * Create the directories.
     2163     */
     2164    HRESULT hrc = S_OK;
     2165    if (fVerbose && cDirs)
     2166        RTPrintf("Creating %u directories ...\n", cDirs);
     2167
     2168    DESTDIRMAPITER it = mapDirs.begin();
     2169    while (it != mapDirs.end())
     2170    {
     2171        if (fVerbose)
     2172            RTPrintf("Creating directory \"%s\" ...\n", it->first.c_str());
     2173
     2174        hrc = guest->DirectoryCreate(Bstr(it->first).raw(),
     2175                                     Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(),
     2176                                     fDirMode, fFlags);
    21752177        if (FAILED(hrc))
    2176             rcExit = RTEXITCODE_FAILURE;
    2177     }
    2178 
    2179     return rcExit;
     2178        {
     2179            ctrlPrintError(guest, COM_IIDOF(IGuest)); /* Return code ignored, save original rc. */
     2180            break;
     2181        }
     2182
     2183        it++;
     2184    }
     2185
     2186    return FAILED(hrc) ? RTEXITCODE_FAILURE : RTEXITCODE_SUCCESS;
    21802187}
    21812188
     
    21892196        { "--file-system",         'f',                             RTGETOPT_REQ_NOTHING },
    21902197        { "--format",              'c',                             RTGETOPT_REQ_STRING },
     2198        { "--passwordfile",        'p',                             RTGETOPT_REQ_STRING  },
    21912199        { "--password",            GETOPTDEF_STAT_PASSWORD,         RTGETOPT_REQ_STRING  },
    21922200        { "--terse",               't',                             RTGETOPT_REQ_NOTHING },
    2193         { "--username",            GETOPTDEF_STAT_USERNAME,         RTGETOPT_REQ_STRING  },
     2201        { "--username",            'u',                             RTGETOPT_REQ_STRING  },
    21942202        { "--verbose",             'v',                             RTGETOPT_REQ_NOTHING }
    21952203    };
     
    22072215    DESTDIRMAP mapObjs;
    22082216
    2209     RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
    2210     while (   (ch = RTGetOpt(&GetState, &ValueUnion))
    2211            && rcExit == RTEXITCODE_SUCCESS)
     2217    while ((ch = RTGetOpt(&GetState, &ValueUnion)))
    22122218    {
    22132219        /* For options that require an argument, ValueUnion has received the value. */
     
    22182224                break;
    22192225
    2220             case GETOPTDEF_STAT_USERNAME: /* User name */
     2226            case 'p': /* Password file */
     2227            {
     2228                RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &Utf8Password);
     2229                if (rcExit != RTEXITCODE_SUCCESS)
     2230                    return rcExit;
     2231                break;
     2232            }
     2233
     2234            case 'u': /* User name */
    22212235                Utf8UserName = ValueUnion.psz;
    22222236                break;
     
    22422256            default:
    22432257                return RTGetOptPrintError(ch, &ValueUnion);
    2244                 break; /* Never reached. */
    22452258        }
    22462259    }
    22472260
    22482261    uint32_t cObjs = mapObjs.size();
    2249     if (rcExit == RTEXITCODE_SUCCESS && !cObjs)
    2250         rcExit = errorSyntax(USAGE_GUESTCONTROL, "No element(s) to check specified!");
    2251 
    2252     if (rcExit == RTEXITCODE_SUCCESS && Utf8UserName.isEmpty())
    2253         rcExit = errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
    2254 
    2255     if (rcExit == RTEXITCODE_SUCCESS)
    2256     {
    2257         /*
    2258          * Create the directories.
    2259          */
    2260         HRESULT hrc = S_OK;
    2261 
    2262         DESTDIRMAPITER it = mapObjs.begin();
    2263         while (it != mapObjs.end())
    2264         {
    2265             if (fVerbose)
    2266                 RTPrintf("Checking for element \"%s\" ...\n", it->first.c_str());
    2267 
    2268             BOOL fExists;
    2269             hrc = guest->FileExists(Bstr(it->first).raw(),
    2270                                     Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(),
    2271                                     &fExists);
    2272             if (FAILED(hrc))
    2273             {
    2274                 ctrlPrintError(guest, COM_IIDOF(IGuest)); /* Return code ignored, save original rc. */
    2275                 break;
    2276             }
    2277             else
    2278             {
    2279                 /** @todo: Output vbox_stat's stdout output to get more information about
    2280                  *         what happened. */
    2281 
    2282                 /* If there's at least one element which does not exist on the guest,
    2283                  * drop out with exitcode 1. */
    2284                 if (!fExists)
    2285                 {
    2286                     if (fVerbose)
    2287                         RTPrintf("Cannot stat for element \"%s\": No such file or directory\n",
    2288                                  it->first.c_str());
    2289                     rcExit = RTEXITCODE_FAILURE;
    2290                 }
    2291             }
    2292 
    2293             it++;
    2294         }
    2295 
     2262    if (!cObjs)
     2263        return errorSyntax(USAGE_GUESTCONTROL, "No element(s) to check specified!");
     2264
     2265    if (Utf8UserName.isEmpty())
     2266        return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
     2267
     2268    /*
     2269     * Create the directories.
     2270     */
     2271    HRESULT hrc = S_OK;
     2272    RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
     2273    DESTDIRMAPITER it = mapObjs.begin();
     2274    while (it != mapObjs.end())
     2275    {
     2276        if (fVerbose)
     2277            RTPrintf("Checking for element \"%s\" ...\n", it->first.c_str());
     2278
     2279        BOOL fExists;
     2280        hrc = guest->FileExists(Bstr(it->first).raw(),
     2281                                Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(),
     2282                                &fExists);
    22962283        if (FAILED(hrc))
     2284        {
     2285            ctrlPrintError(guest, COM_IIDOF(IGuest)); /* Return code ignored, save original rc. */
    22972286            rcExit = RTEXITCODE_FAILURE;
     2287        }
     2288        else
     2289        {
     2290            /** @todo: Output vbox_stat's stdout output to get more information about
     2291             *         what happened. */
     2292
     2293            /* If there's at least one element which does not exist on the guest,
     2294             * drop out with exitcode 1. */
     2295            if (!fExists)
     2296            {
     2297                if (fVerbose)
     2298                    RTPrintf("Cannot stat for element \"%s\": No such file or directory\n",
     2299                             it->first.c_str());
     2300                rcExit = RTEXITCODE_FAILURE;
     2301            }
     2302        }
     2303
     2304        it++;
    22982305    }
    22992306
     
    24432450            rcExit = handleCtrlExecProgram(guest, &arg);
    24442451        else if (!strcmp(pArg->argv[1], "copyfrom"))
    2445             rcExit = handleCtrlCopyTo(guest, &arg, false /* Guest to host */);
     2452            rcExit = handleCtrlCopy(guest, &arg, false /* Guest to host */);
    24462453        else if (   !strcmp(pArg->argv[1], "copyto")
    24472454                 || !strcmp(pArg->argv[1], "cp"))
    2448             rcExit = handleCtrlCopyTo(guest, &arg, true /* Host to guest */);
     2455            rcExit = handleCtrlCopy(guest, &arg, true /* Host to guest */);
    24492456        else if (   !strcmp(pArg->argv[1], "createdirectory")
    24502457                 || !strcmp(pArg->argv[1], "createdir")
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r42395 r42444  
    439439                     "                                              [<xorigin> <yorigin>]]] |\n"
    440440                     "                            screenshotpng <file> [display] |\n"
    441                      "                            setcredentials <username> <password> <domain>\n"
     441                     "                            setcredentials <username>\n"
     442                     "                                           --passwordfile <file> | <password>\n"
     443                     "                                           <domain>\n"
    442444                     "                                           [--allowlocallogon <yes|no>] |\n"
    443445                     "                            teleport --host <name> --port <port>\n"
Note: See TracChangeset for help on using the changeset viewer.

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