VirtualBox

Ignore:
Timestamp:
Aug 7, 2012 4:18:47 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
79866
Message:

Frontends/VBoxManage: completed conversion to new API, still disabled as it anticipates an API change

File:
1 edited

Legend:

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

    r42551 r42668  
    7373typedef struct COPYCONTEXT
    7474{
    75     IGuest *pGuest;
     75    COPYCONTEXT() : fVerbose(false), fDryRun(false), fHostToGuest(false)
     76    {
     77    }
     78
     79#ifndef VBOX_WITH_GUEST_CONTROL2
     80    ComPtr<IGuest> pGuest;
     81#else
     82    ComPtr<IGuestSession> pGuestSession;
     83#endif
    7684    bool fVerbose;
    7785    bool fDryRun;
    7886    bool fHostToGuest;
    79     char *pszUsername;
    80     char *pszPassword;
     87#ifndef VBOX_WITH_GUEST_CONTROL2
     88    Utf8Str strUsername;
     89    Utf8Str strPassword;
     90#endif
    8191} COPYCONTEXT, *PCOPYCONTEXT;
    8292
     
    334344static int ctrlExecProcessStatusToExitCode(ExecuteProcessStatus_T enmStatus, ULONG uExitCode)
    335345{
    336     int rc = EXITCODEEXEC_SUCCESS;
     346    int vrc = EXITCODEEXEC_SUCCESS;
    337347    switch (enmStatus)
    338348    {
    339349        case ExecuteProcessStatus_Started:
    340             rc = EXITCODEEXEC_SUCCESS;
     350            vrc = EXITCODEEXEC_SUCCESS;
    341351            break;
    342352        case ExecuteProcessStatus_TerminatedNormally:
    343             rc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
     353            vrc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
    344354            break;
    345355        case ExecuteProcessStatus_TerminatedSignal:
    346             rc = EXITCODEEXEC_TERM_SIGNAL;
     356            vrc = EXITCODEEXEC_TERM_SIGNAL;
    347357            break;
    348358        case ExecuteProcessStatus_TerminatedAbnormally:
    349             rc = EXITCODEEXEC_TERM_ABEND;
     359            vrc = EXITCODEEXEC_TERM_ABEND;
    350360            break;
    351361        case ExecuteProcessStatus_TimedOutKilled:
    352             rc = EXITCODEEXEC_TIMEOUT;
     362            vrc = EXITCODEEXEC_TIMEOUT;
    353363            break;
    354364        case ExecuteProcessStatus_TimedOutAbnormally:
    355             rc = EXITCODEEXEC_TIMEOUT;
     365            vrc = EXITCODEEXEC_TIMEOUT;
    356366            break;
    357367        case ExecuteProcessStatus_Down:
    358368            /* Service/OS is stopping, process was killed, so
    359369             * not exactly an error of the started process ... */
    360             rc = EXITCODEEXEC_DOWN;
     370            vrc = EXITCODEEXEC_DOWN;
    361371            break;
    362372        case ExecuteProcessStatus_Error:
    363             rc = EXITCODEEXEC_FAILED;
     373            vrc = EXITCODEEXEC_FAILED;
    364374            break;
    365375        default:
     
    367377            break;
    368378    }
    369     return rc;
     379    return vrc;
    370380}
    371381#else
     
    408418static int ctrlExecProcessStatusToExitCode(ProcessStatus_T enmStatus, ULONG uExitCode)
    409419{
    410     int rc = EXITCODEEXEC_SUCCESS;
     420    int vrc = EXITCODEEXEC_SUCCESS;
    411421    switch (enmStatus)
    412422    {
    413423        case ProcessStatus_Starting:
    414             rc = EXITCODEEXEC_SUCCESS;
     424            vrc = EXITCODEEXEC_SUCCESS;
    415425            break;
    416426        case ProcessStatus_Started:
    417             rc = EXITCODEEXEC_SUCCESS;
     427            vrc = EXITCODEEXEC_SUCCESS;
    418428            break;
    419429        case ProcessStatus_Paused:
    420             rc = EXITCODEEXEC_SUCCESS;
     430            vrc = EXITCODEEXEC_SUCCESS;
    421431            break;
    422432        case ProcessStatus_Terminating:
    423             rc = EXITCODEEXEC_SUCCESS;
     433            vrc = EXITCODEEXEC_SUCCESS;
    424434            break;
    425435        case ProcessStatus_TerminatedNormally:
    426             rc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
     436            vrc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
    427437            break;
    428438        case ProcessStatus_TerminatedSignal:
    429             rc = EXITCODEEXEC_TERM_SIGNAL;
     439            vrc = EXITCODEEXEC_TERM_SIGNAL;
    430440            break;
    431441        case ProcessStatus_TerminatedAbnormally:
    432             rc = EXITCODEEXEC_TERM_ABEND;
     442            vrc = EXITCODEEXEC_TERM_ABEND;
    433443            break;
    434444        case ProcessStatus_TimedOutKilled:
    435             rc = EXITCODEEXEC_TIMEOUT;
     445            vrc = EXITCODEEXEC_TIMEOUT;
    436446            break;
    437447        case ProcessStatus_TimedOutAbnormally:
    438             rc = EXITCODEEXEC_TIMEOUT;
     448            vrc = EXITCODEEXEC_TIMEOUT;
    439449            break;
    440450        case ProcessStatus_Down:
    441451            /* Service/OS is stopping, process was killed, so
    442452             * not exactly an error of the started process ... */
    443             rc = EXITCODEEXEC_DOWN;
     453            vrc = EXITCODEEXEC_DOWN;
    444454            break;
    445455        case ProcessStatus_Error:
    446             rc = EXITCODEEXEC_FAILED;
     456            vrc = EXITCODEEXEC_FAILED;
    447457            break;
    448458        default:
     
    450460            break;
    451461    }
    452     return rc;
     462    return vrc;
    453463}
    454464#endif
     
    718728     * Parse arguments.
    719729     */
    720     if (pArg->argc < 2) /* At least the command we want to execute in the guest should be present :-). */
    721         return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters");
    722 
    723730    static const RTGETOPTDEF s_aOptions[] =
    724731    {
     
    755762    com::SafeArray<IN_BSTR> args;
    756763    com::SafeArray<IN_BSTR> env;
    757     Utf8Str                 strUserName;
     764    Utf8Str                 strUsername;
    758765    Utf8Str                 strPassword;
    759766    Utf8Str                 strDomain;
     
    814821
    815822            case 'u': /* User name */
    816                 strUserName = ValueUnion.psz;
     823                strUsername = ValueUnion.psz;
    817824                break;
    818825
     
    892899        return errorSyntax(USAGE_GUESTCONTROL, "No command to execute specified!");
    893900
    894     if (strUserName.isEmpty())
     901    if (strUsername.isEmpty())
    895902        return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
    896903
     
    924931                               ComSafeArrayAsInParam(args),
    925932                               ComSafeArrayAsInParam(env),
    926                                Bstr(strUserName).raw(),
     933                               Bstr(strUsername).raw(),
    927934                               Bstr(strPassword).raw(),
    928935                               cMsTimeout,
     
    10671074#else
    10681075    ComPtr<IGuestSession> pGuestSession;
    1069     rc = pGuest->CreateSession(Bstr(strUserName).raw(),
     1076    rc = pGuest->CreateSession(Bstr(strUsername).raw(),
    10701077                               Bstr(strPassword).raw(),
    10711078                               Bstr(strDomain).raw(),
     
    12101217 * @param   fHostToGuest            Flag indicating if we want to copy from host to guest
    12111218 *                                  or vice versa.
    1212  * @param   pszUsername             Username of account to use on the guest side.
    1213  * @param   pszPassword             Password of account to use.
     1219 * @param   strUsername             Username of account to use on the guest side.
     1220 * @param   strPassword             Password of account to use.
     1221 * @param   strDomain               Domain of account to use.
     1222 * @param   strSessionName          Session name (only for identification purposes).
    12141223 * @param   ppContext               Pointer which receives the allocated copy context.
    12151224 */
    12161225static int ctrlCopyContextCreate(IGuest *pGuest, bool fVerbose, bool fDryRun,
    1217                                  bool fHostToGuest,
    1218                                  const char *pszUsername, const char *pszPassword,
     1226                                 bool fHostToGuest, const Utf8Str &strUsername,
     1227                                 const Utf8Str &strPassword, const Utf8Str &strDomain,
     1228                                 const Utf8Str &strSessionName,
    12191229                                 PCOPYCONTEXT *ppContext)
    12201230{
    12211231    AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
    1222     AssertPtrReturn(pszUsername, VERR_INVALID_POINTER);
    1223     AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
    1224 
    1225     PCOPYCONTEXT pContext = (PCOPYCONTEXT)RTMemAlloc(sizeof(COPYCONTEXT));
    1226     AssertPtrReturn(pContext, VERR_NO_MEMORY);
     1232
     1233    PCOPYCONTEXT pContext = new COPYCONTEXT();
     1234    AssertPtrReturn(pContext, VERR_NO_MEMORY); /**< @todo r=klaus cannot happen with new */
     1235#ifndef VBOX_WITH_GUEST_CONTROL2
     1236    NOREF(strDomain);
     1237    NOREF(strSessionName);
    12271238    pContext->pGuest = pGuest;
     1239
     1240    pContext->strUsername = strUsername;
     1241    pContext->strPassword = strPassword;
     1242#else
     1243    ComPtr<IGuestSession> pGuestSession;
     1244    HRESULT rc = pGuest->CreateSession(Bstr(strUsername).raw(),
     1245                                       Bstr(strPassword).raw(),
     1246                                       Bstr(strDomain).raw(),
     1247                                       Bstr(strSessionName).raw(),
     1248                                       pGuestSession.asOutParam());
     1249    if (FAILED(rc))
     1250        return ctrlPrintError(pGuest, COM_IIDOF(IGuest));
     1251
     1252#endif
     1253
    12281254    pContext->fVerbose = fVerbose;
    12291255    pContext->fDryRun = fDryRun;
    12301256    pContext->fHostToGuest = fHostToGuest;
    12311257
    1232     pContext->pszUsername = RTStrDup(pszUsername);
    1233     if (!pContext->pszUsername)
    1234     {
    1235         RTMemFree(pContext);
    1236         return VERR_NO_MEMORY;
    1237     }
    1238 
    1239     pContext->pszPassword = RTStrDup(pszPassword);
    1240     if (!pContext->pszPassword)
    1241     {
    1242         RTStrFree(pContext->pszUsername);
    1243         RTMemFree(pContext);
    1244         return VERR_NO_MEMORY;
    1245     }
    1246 
    12471258    *ppContext = pContext;
    12481259
     
    12591270    if (pContext)
    12601271    {
    1261         RTStrFree(pContext->pszUsername);
    1262         RTStrFree(pContext->pszPassword);
    1263         RTMemFree(pContext);
    1264     }
    1265 }
    1266 
    1267 /**
    1268  * Translates a source path to a destintation path (can be both sides,
     1272#ifndef VBOX_WITH_GUEST_CONTROL2
     1273#else
     1274        if (pContext->pGuestSession)
     1275            pContext->pGuestSession->Close();
     1276#endif
     1277        delete pContext;
     1278    }
     1279}
     1280
     1281/**
     1282 * Translates a source path to a destination path (can be both sides,
    12691283 * either host or guest). The source root is needed to determine the start
    12701284 * of the relative source path which also needs to present in the destination
     
    13021316    AssertPtrReturn(pszDestPath, VERR_NO_MEMORY);
    13031317
    1304     int rc;
     1318    int vrc;
    13051319    if (!RTPathFilename(pszDestPath))
    13061320    {
    1307         rc = RTPathJoin(szTranslated, sizeof(szTranslated),
    1308                         pszDestPath, &pszSource[srcOff]);
     1321        vrc = RTPathJoin(szTranslated, sizeof(szTranslated),
     1322                         pszDestPath, &pszSource[srcOff]);
    13091323    }
    13101324    else
     
    13141328        {
    13151329            RTPathStripFilename(pszDestPath);
    1316             rc = RTPathJoin(szTranslated, sizeof(szTranslated),
     1330            vrc = RTPathJoin(szTranslated, sizeof(szTranslated),
    13171331                            pszDestPath, pszDestFileName);
    13181332            RTStrFree(pszDestFileName);
    13191333        }
    13201334        else
    1321             rc = VERR_NO_MEMORY;
     1335            vrc = VERR_NO_MEMORY;
    13221336    }
    13231337    RTStrFree(pszDestPath);
    13241338
    1325     if (RT_SUCCESS(rc))
     1339    if (RT_SUCCESS(vrc))
    13261340    {
    13271341        *ppszTranslated = RTStrDup(szTranslated);
     
    13311345#endif
    13321346    }
    1333     return rc;
     1347    return vrc;
    13341348}
    13351349
     
    14321446    if (pContext->fHostToGuest) /* We want to create directories on the guest. */
    14331447    {
     1448#ifndef VBOX_WITH_GUEST_CONTROL2
    14341449        HRESULT rc = pContext->pGuest->DirectoryCreate(Bstr(pszDir).raw(),
    1435                                                        Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
     1450                                                       Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
    14361451                                                       0700, DirectoryCreateFlag_Parents);
    14371452        if (FAILED(rc))
    14381453            vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     1454#else
     1455        ComPtr<IGuestDirectory> pDirectory;
     1456        SafeArray<DirectoryCreateFlag_T> dirCreateFlags;
     1457        dirCreateFlags.push_back(DirectoryCreateFlag_Parents);
     1458        HRESULT rc = pContext->pGuestSession->DirectoryCreate(Bstr(pszDir).raw(),
     1459                                                              0700, ComSafeArrayAsInParam(dirCreateFlags), pDirectory.asOutParam());
     1460        if (FAILED(rc))
     1461            vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
     1462        if (!pDirectory.isNull())
     1463            pDirectory->Close();
     1464#endif
    14391465    }
    14401466    else /* ... or on the host. */
     
    14651491    AssertPtrReturn(fExists, false);
    14661492
    1467     int rc = VINF_SUCCESS;
     1493    int vrc = VINF_SUCCESS;
    14681494    if (bGuest)
    14691495    {
    14701496        BOOL fDirExists = FALSE;
     1497#ifndef VBOX_WITH_GUEST_CONTROL2
    14711498        /** @todo Replace with DirectoryExists as soon as API is in place. */
    1472         HRESULT hr = pContext->pGuest->FileExists(Bstr(pszDir).raw(),
    1473                                                   Bstr(pContext->pszUsername).raw(),
    1474                                                   Bstr(pContext->pszPassword).raw(), &fDirExists);
    1475         if (FAILED(hr))
    1476             rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     1499        HRESULT rc = pContext->pGuest->FileExists(Bstr(pszDir).raw(),
     1500                                                  Bstr(pContext->strUsername).raw(),
     1501                                                  Bstr(pContext->strPassword).raw(), &fDirExists);
     1502        if (FAILED(rc))
     1503            vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
    14771504        else
    14781505            *fExists = fDirExists ? true : false;
     1506#else
     1507        HRESULT rc = pContext->pGuestSession->DirectoryExists(Bstr(pszDir).raw(), &fDirExists);
     1508        if (FAILED(rc))
     1509            vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
     1510        else
     1511            *fExists = fDirExists ? true : false;
     1512#endif
    14791513    }
    14801514    else
    14811515        *fExists = RTDirExists(pszDir);
    1482     return rc;
     1516    return vrc;
    14831517}
    14841518
     
    15351569    AssertPtrReturn(fExists, false);
    15361570
    1537     int rc = VINF_SUCCESS;
     1571    int vrc = VINF_SUCCESS;
    15381572    if (bOnGuest)
    15391573    {
    15401574        BOOL fFileExists = FALSE;
    1541         HRESULT hr = pContext->pGuest->FileExists(Bstr(pszFile).raw(),
    1542                                                   Bstr(pContext->pszUsername).raw(),
    1543                                                   Bstr(pContext->pszPassword).raw(), &fFileExists);
    1544         if (FAILED(hr))
    1545             rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     1575#ifndef VBOX_WITH_GUEST_CONTROL2
     1576        HRESULT rc = pContext->pGuest->FileExists(Bstr(pszFile).raw(),
     1577                                                  Bstr(pContext->strUsername).raw(),
     1578                                                  Bstr(pContext->strPassword).raw(), &fFileExists);
     1579        if (FAILED(rc))
     1580            vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
    15461581        else
    15471582            *fExists = fFileExists ? true : false;
     1583#else
     1584        HRESULT rc = pContext->pGuestSession->FileExists(Bstr(pszFile).raw(), &fFileExists);
     1585        if (FAILED(rc))
     1586            vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
     1587        else
     1588            *fExists = fFileExists ? true : false;
     1589#endif
    15481590    }
    15491591    else
    15501592        *fExists = RTFileExists(pszFile);
    1551     return rc;
     1593    return vrc;
    15521594}
    15531595
     
    16161658    if (pContext->fHostToGuest)
    16171659    {
     1660#ifndef VBOX_WITH_GUEST_CONTROL2
    16181661        rc = pContext->pGuest->CopyToGuest(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
    1619                                            Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
     1662                                           Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
    16201663                                           fFlags, pProgress.asOutParam());
     1664#else
     1665        Assert(!fFlags);
     1666        SafeArray<CopyFileFlag_T> copyFlags;
     1667        rc = pContext->pGuestSession->CopyTo(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
     1668                                             ComSafeArrayAsInParam(copyFlags),
     1669
     1670                                             pProgress.asOutParam());
     1671#endif
    16211672    }
    16221673    else
    16231674    {
     1675#ifndef VBOX_WITH_GUEST_CONTROL2
    16241676        rc = pContext->pGuest->CopyFromGuest(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
    1625                                              Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
     1677                                             Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
    16261678                                             fFlags, pProgress.asOutParam());
     1679#else
     1680        Assert(!fFlags);
     1681        SafeArray<CopyFileFlag_T> copyFlags;
     1682        rc = pContext->pGuestSession->CopyFrom(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
     1683                                               ComSafeArrayAsInParam(copyFlags),
     1684                                               pProgress.asOutParam());
     1685#endif
    16271686    }
    16281687
    16291688    if (FAILED(rc))
     1689    {
     1690#ifndef VBOX_WITH_GUEST_CONTROL2
    16301691        vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     1692#else
     1693        vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
     1694#endif
     1695    }
    16311696    else
    16321697    {
     
    16701735     */
    16711736    char szCurDir[RTPATH_MAX];
    1672     int rc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
    1673     if (RT_SUCCESS(rc) && pszSubDir)
    1674         rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
     1737    int vrc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
     1738    if (RT_SUCCESS(vrc) && pszSubDir)
     1739        vrc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
    16751740
    16761741    if (pContext->fVerbose)
     
    16861751     */
    16871752    PRTDIR pDir = NULL;
    1688     if (RT_SUCCESS(rc))
    1689     {
    1690         rc = RTDirOpen(&pDir, szCurDir);
    1691         if (RT_FAILURE(rc))
     1753    if (RT_SUCCESS(vrc))
     1754    {
     1755        vrc = RTDirOpen(&pDir, szCurDir);
     1756        if (RT_FAILURE(vrc))
    16921757            pDir = NULL;
    16931758    }
    1694     if (RT_SUCCESS(rc))
     1759    if (RT_SUCCESS(vrc))
    16951760    {
    16961761        /*
    16971762         * Enumerate the directory tree.
    16981763         */
    1699         while (RT_SUCCESS(rc))
     1764        while (RT_SUCCESS(vrc))
    17001765        {
    17011766            RTDIRENTRY DirEntry;
    1702             rc = RTDirRead(pDir, &DirEntry, NULL);
    1703             if (RT_FAILURE(rc))
    1704             {
    1705                 if (rc == VERR_NO_MORE_FILES)
    1706                     rc = VINF_SUCCESS;
     1767            vrc = RTDirRead(pDir, &DirEntry, NULL);
     1768            if (RT_FAILURE(vrc))
     1769            {
     1770                if (vrc == VERR_NO_MORE_FILES)
     1771                    vrc = VINF_SUCCESS;
    17071772                break;
    17081773            }
     
    17321797                        if (pszNewSub)
    17331798                        {
    1734                             rc = ctrlCopyDirToGuest(pContext,
    1735                                                     pszSource, pszFilter,
    1736                                                     pszDest, fFlags, pszNewSub);
     1799                            vrc = ctrlCopyDirToGuest(pContext,
     1800                                                     pszSource, pszFilter,
     1801                                                     pszDest, fFlags, pszNewSub);
    17371802                            RTStrFree(pszNewSub);
    17381803                        }
    17391804                        else
    1740                             rc = VERR_NO_MEMORY;
     1805                            vrc = VERR_NO_MEMORY;
    17411806                    }
    17421807                    break;
     
    17661831                    {
    17671832                        char *pszDestDir;
    1768                         rc = ctrlCopyTranslatePath(pszSource, szCurDir,
    1769                                                    pszDest, &pszDestDir);
    1770                         if (RT_SUCCESS(rc))
     1833                        vrc = ctrlCopyTranslatePath(pszSource, szCurDir,
     1834                                                    pszDest, &pszDestDir);
     1835                        if (RT_SUCCESS(vrc))
    17711836                        {
    1772                             rc = ctrlCopyDirCreate(pContext, pszDestDir);
     1837                            vrc = ctrlCopyDirCreate(pContext, pszDestDir);
    17731838                            RTStrFree(pszDestDir);
    17741839
     
    17771842                    }
    17781843
    1779                     if (RT_SUCCESS(rc))
     1844                    if (RT_SUCCESS(vrc))
    17801845                    {
    17811846                        char *pszFileSource = RTPathJoinA(szCurDir, DirEntry.szName);
     
    17831848                        {
    17841849                            char *pszFileDest;
    1785                             rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
     1850                            vrc = ctrlCopyTranslatePath(pszSource, pszFileSource,
    17861851                                                       pszDest, &pszFileDest);
    1787                             if (RT_SUCCESS(rc))
     1852                            if (RT_SUCCESS(vrc))
    17881853                            {
    1789                                 rc = ctrlCopyFileToDest(pContext, pszFileSource,
     1854                                vrc = ctrlCopyFileToDest(pContext, pszFileSource,
    17901855                                                        pszFileDest, 0 /* Flags */);
    17911856                                RTStrFree(pszFileDest);
     
    18001865                    break;
    18011866            }
    1802             if (RT_FAILURE(rc))
     1867            if (RT_FAILURE(vrc))
    18031868                break;
    18041869        }
     
    18061871        RTDirClose(pDir);
    18071872    }
    1808     return rc;
     1873    return vrc;
    18091874}
    18101875
     
    18361901     */
    18371902    char szCurDir[RTPATH_MAX];
    1838     int rc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
    1839     if (RT_SUCCESS(rc) && pszSubDir)
    1840         rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
    1841 
    1842     if (RT_FAILURE(rc))
    1843         return rc;
     1903    int vrc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
     1904    if (RT_SUCCESS(vrc) && pszSubDir)
     1905        vrc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
     1906
     1907    if (RT_FAILURE(vrc))
     1908        return vrc;
    18441909
    18451910    if (pContext->fVerbose)
     
    18501915    bool fDirCreated = false;
    18511916
     1917#ifndef VBOX_WITH_GUEST_CONTROL2
    18521918    ULONG uDirHandle;
    1853     HRESULT hr = pContext->pGuest->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),
     1919    HRESULT rc = pContext->pGuest->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),
    18541920                                                 DirectoryOpenFlag_None /* No flags supported yet. */,
    1855                                                  Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
     1921                                                 Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
    18561922                                                 &uDirHandle);
    1857     if (FAILED(hr))
    1858         rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
    1859     else
    1860     {
    1861         ComPtr <IGuestDirEntry> dirEntry;
    1862         while (SUCCEEDED(hr = pContext->pGuest->DirectoryRead(uDirHandle, dirEntry.asOutParam())))
    1863         {
    1864             GuestDirEntryType_T enmType;
    1865             dirEntry->COMGETTER(Type)(&enmType);
    1866 
    1867             Bstr strName;
    1868             dirEntry->COMGETTER(Name)(strName.asOutParam());
    1869 
    1870             switch (enmType)
    1871             {
    1872                 case GuestDirEntryType_Directory:
     1923    if (FAILED(rc))
     1924        return ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     1925    ComPtr<IGuestDirEntry> dirEntry;
     1926#else
     1927    ComPtr<IGuestDirectory> pDirectory;
     1928    HRESULT rc = pContext->pGuestSession->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),
     1929                                                 Bstr().raw() /* No flags supported yet. */,
     1930                                                 pDirectory.asOutParam());
     1931    if (FAILED(rc))
     1932        return ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
     1933    ComPtr<IFsObjInfo> dirEntry;
     1934#endif
     1935    while (true)
     1936    {
     1937#ifndef VBOX_WITH_GUEST_CONTROL2
     1938        rc = pContext->pGuest->DirectoryRead(uDirHandle, dirEntry.asOutParam());
     1939#else
     1940        rc = pDirectory->Read(dirEntry.asOutParam());
     1941#endif
     1942        if (FAILED(rc))
     1943            break;
     1944
     1945#ifndef VBOX_WITH_GUEST_CONTROL2
     1946        GuestDirEntryType_T enmType;
     1947#else
     1948        FsObjType_T enmType;
     1949#endif
     1950        dirEntry->COMGETTER(Type)(&enmType);
     1951
     1952        Bstr strName;
     1953        dirEntry->COMGETTER(Name)(strName.asOutParam());
     1954
     1955        switch (enmType)
     1956        {
     1957#ifndef VBOX_WITH_GUEST_CONTROL2
     1958            case GuestDirEntryType_Directory:
     1959#else
     1960            case FsObjType_Directory:
     1961#endif
     1962            {
     1963                Assert(!strName.isEmpty());
     1964
     1965                /* Skip "." and ".." entries. */
     1966                if (   !strName.compare(Bstr("."))
     1967                    || !strName.compare(Bstr("..")))
     1968                    break;
     1969
     1970                if (pContext->fVerbose)
    18731971                {
    1874                     Assert(!strName.isEmpty());
    1875 
    1876                     /* Skip "." and ".." entries. */
    1877                     if (   !strName.compare(Bstr("."))
    1878                         || !strName.compare(Bstr("..")))
    1879                         break;
    1880 
    1881                     if (pContext->fVerbose)
     1972                    Utf8Str strDir(strName);
     1973                    RTPrintf("Directory: %s\n", strDir.c_str());
     1974                }
     1975
     1976                if (fFlags & CopyFileFlag_Recursive)
     1977                {
     1978                    Utf8Str strDir(strName);
     1979                    char *pszNewSub = NULL;
     1980                    if (pszSubDir)
     1981                        pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str());
     1982                    else
    18821983                    {
    1883                         Utf8Str strDir(strName);
    1884                         RTPrintf("Directory: %s\n", strDir.c_str());
     1984                        pszNewSub = RTStrDup(strDir.c_str());
     1985                        RTPathStripTrailingSlash(pszNewSub);
    18851986                    }
    1886 
    1887                     if (fFlags & CopyFileFlag_Recursive)
     1987                    if (pszNewSub)
    18881988                    {
    1889                         Utf8Str strDir(strName);
    1890                         char *pszNewSub = NULL;
    1891                         if (pszSubDir)
    1892                             pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str());
    1893                         else
    1894                         {
    1895                             pszNewSub = RTStrDup(strDir.c_str());
    1896                             RTPathStripTrailingSlash(pszNewSub);
    1897                         }
    1898                         if (pszNewSub)
    1899                         {
    1900                             rc = ctrlCopyDirToHost(pContext,
    1901                                                    pszSource, pszFilter,
    1902                                                    pszDest, fFlags, pszNewSub);
    1903                             RTStrFree(pszNewSub);
    1904                         }
    1905                         else
    1906                             rc = VERR_NO_MEMORY;
    1907                     }
    1908                     break;
    1909                 }
    1910 
    1911                 case GuestDirEntryType_Symlink:
    1912                     if (   (fFlags & CopyFileFlag_Recursive)
    1913                         && (fFlags & CopyFileFlag_FollowLinks))
    1914                     {
    1915                         /* Fall through to next case is intentional. */
     1989                        vrc = ctrlCopyDirToHost(pContext,
     1990                                                pszSource, pszFilter,
     1991                                                pszDest, fFlags, pszNewSub);
     1992                        RTStrFree(pszNewSub);
    19161993                    }
    19171994                    else
    1918                         break;
    1919 
    1920                 case GuestDirEntryType_File:
     1995                        vrc = VERR_NO_MEMORY;
     1996                }
     1997                break;
     1998            }
     1999
     2000#ifndef VBOX_WITH_GUEST_CONTROL2
     2001            case GuestDirEntryType_Symlink:
     2002#else
     2003            case FsObjType_Symlink:
     2004#endif
     2005                if (   (fFlags & CopyFileFlag_Recursive)
     2006                    && (fFlags & CopyFileFlag_FollowLinks))
    19212007                {
    1922                     Assert(!strName.isEmpty());
    1923 
    1924                     Utf8Str strFile(strName);
    1925                     if (   pszFilter
    1926                         && !RTStrSimplePatternMatch(pszFilter, strFile.c_str()))
     2008                    /* Fall through to next case is intentional. */
     2009                }
     2010                else
     2011                    break;
     2012
     2013#ifndef VBOX_WITH_GUEST_CONTROL2
     2014            case GuestDirEntryType_File:
     2015#else
     2016            case FsObjType_File:
     2017#endif
     2018            {
     2019                Assert(!strName.isEmpty());
     2020
     2021                Utf8Str strFile(strName);
     2022                if (   pszFilter
     2023                    && !RTStrSimplePatternMatch(pszFilter, strFile.c_str()))
     2024                {
     2025                    break; /* Filter does not match. */
     2026                }
     2027
     2028                if (pContext->fVerbose)
     2029                    RTPrintf("File: %s\n", strFile.c_str());
     2030
     2031                if (!fDirCreated)
     2032                {
     2033                    char *pszDestDir;
     2034                    vrc = ctrlCopyTranslatePath(pszSource, szCurDir,
     2035                                                pszDest, &pszDestDir);
     2036                    if (RT_SUCCESS(vrc))
    19272037                    {
    1928                         break; /* Filter does not match. */
     2038                        vrc = ctrlCopyDirCreate(pContext, pszDestDir);
     2039                        RTStrFree(pszDestDir);
     2040
     2041                        fDirCreated = true;
    19292042                    }
    1930 
    1931                     if (pContext->fVerbose)
    1932                         RTPrintf("File: %s\n", strFile.c_str());
    1933 
    1934                     if (!fDirCreated)
     2043                }
     2044
     2045                if (RT_SUCCESS(vrc))
     2046                {
     2047                    char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
     2048                    if (pszFileSource)
    19352049                    {
    1936                         char *pszDestDir;
    1937                         rc = ctrlCopyTranslatePath(pszSource, szCurDir,
    1938                                                    pszDest, &pszDestDir);
    1939                         if (RT_SUCCESS(rc))
     2050                        char *pszFileDest;
     2051                        vrc = ctrlCopyTranslatePath(pszSource, pszFileSource,
     2052                                                   pszDest, &pszFileDest);
     2053                        if (RT_SUCCESS(vrc))
    19402054                        {
    1941                             rc = ctrlCopyDirCreate(pContext, pszDestDir);
    1942                             RTStrFree(pszDestDir);
    1943 
    1944                             fDirCreated = true;
     2055                            vrc = ctrlCopyFileToDest(pContext, pszFileSource,
     2056                                                    pszFileDest, 0 /* Flags */);
     2057                            RTStrFree(pszFileDest);
    19452058                        }
     2059                        RTStrFree(pszFileSource);
    19462060                    }
    1947 
    1948                     if (RT_SUCCESS(rc))
    1949                     {
    1950                         char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
    1951                         if (pszFileSource)
    1952                         {
    1953                             char *pszFileDest;
    1954                             rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
    1955                                                        pszDest, &pszFileDest);
    1956                             if (RT_SUCCESS(rc))
    1957                             {
    1958                                 rc = ctrlCopyFileToDest(pContext, pszFileSource,
    1959                                                         pszFileDest, 0 /* Flags */);
    1960                                 RTStrFree(pszFileDest);
    1961                             }
    1962                             RTStrFree(pszFileSource);
    1963                         }
    1964                         else
    1965                             rc = VERR_NO_MEMORY;
    1966                     }
    1967                     break;
     2061                    else
     2062                        vrc = VERR_NO_MEMORY;
    19682063                }
    1969 
    1970                 default:
    1971                     RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n",
    1972                              enmType);
    1973                     break;
    1974             }
    1975 
    1976             if (RT_FAILURE(rc))
    1977                 break;
    1978         }
    1979 
    1980         if (RT_UNLIKELY(FAILED(hr)))
    1981         {
    1982             switch (hr)
    1983             {
    1984                 case E_ABORT: /* No more directory entries left to process. */
    1985                     break;
    1986 
    1987                 case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to
    1988                                            to missing rights. */
    1989                 {
    1990                     RTPrintf("Warning: Cannot access \"%s\", skipping ...\n",
    1991                              szCurDir);
    1992                     break;
    1993                 }
    1994 
    1995                 default:
    1996                     rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
    1997                     break;
    1998             }
    1999         }
    2000 
    2001         HRESULT hr2 = pContext->pGuest->DirectoryClose(uDirHandle);
    2002         if (FAILED(hr2))
    2003         {
    2004             int rc2 = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
    2005             if (RT_SUCCESS(rc))
    2006                 rc = rc2;
    2007         }
    2008         else if (SUCCEEDED(hr))
    2009             hr = hr2;
    2010     }
    2011 
    2012     return rc;
     2064                break;
     2065            }
     2066
     2067            default:
     2068                RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n",
     2069                         enmType);
     2070                break;
     2071        }
     2072
     2073        if (RT_FAILURE(vrc))
     2074            break;
     2075    }
     2076
     2077    if (RT_UNLIKELY(FAILED(rc)))
     2078    {
     2079        switch (rc)
     2080        {
     2081            case E_ABORT: /* No more directory entries left to process. */
     2082                break;
     2083
     2084            case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to
     2085                                       to missing rights. */
     2086            {
     2087                RTPrintf("Warning: Cannot access \"%s\", skipping ...\n",
     2088                         szCurDir);
     2089                break;
     2090            }
     2091
     2092            default:
     2093#ifndef VBOX_WITH_GUEST_CONTROL2
     2094                vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     2095#else
     2096                vrc = ctrlPrintError(pDirectory, COM_IIDOF(IGuestDirectory));
     2097#endif
     2098                break;
     2099        }
     2100    }
     2101
     2102#ifndef VBOX_WITH_GUEST_CONTROL2
     2103    HRESULT rc2 = pContext->pGuest->DirectoryClose(uDirHandle);
     2104#else
     2105    HRESULT rc2 = pDirectory->Close();
     2106#endif
     2107    if (FAILED(rc2))
     2108    {
     2109#ifndef VBOX_WITH_GUEST_CONTROL2
     2110        int vrc2 = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     2111#else
     2112        int vrc2 = ctrlPrintError(pDirectory, COM_IIDOF(IGuestDirectory));
     2113#endif
     2114        if (RT_SUCCESS(vrc))
     2115            vrc = vrc2;
     2116    }
     2117    else if (SUCCEEDED(rc))
     2118        rc = rc2;
     2119
     2120    return vrc;
    20132121}
    20142122
     
    21272235    Utf8Str strSource;
    21282236    Utf8Str strDest;
    2129     Utf8Str strUserName;
     2237    Utf8Str strUsername;
    21302238    Utf8Str strPassword;
    21312239    Utf8Str strDomain;
     
    21522260
    21532261            case 'u': /* User name */
    2154                 strUserName = ValueUnion.psz;
     2262                strUsername = ValueUnion.psz;
    21552263                break;
    21562264
     
    22142322                           "No destination specified!");
    22152323
    2216     if (strUserName.isEmpty())
     2324    if (strUsername.isEmpty())
    22172325        return errorSyntax(USAGE_GUESTCONTROL,
    22182326                           "No user name specified!");
     
    22352343    PCOPYCONTEXT pContext;
    22362344    vrc = ctrlCopyContextCreate(guest, fVerbose, fDryRun, fHostToGuest,
    2237                                 strUserName.c_str(), strPassword.c_str(),
    2238                                 &pContext);
     2345                                strUsername.c_str(), strPassword.c_str(),
     2346                                strDomain.c_str(), "guest copy", &pContext);
    22392347    if (RT_FAILURE(vrc))
    22402348    {
     
    23972505                 s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    23982506
    2399     Utf8Str strUserName;
     2507    Utf8Str strUsername;
    24002508    Utf8Str strPassword;
    24012509    Utf8Str strDomain;
     
    24202528
    24212529            case 'u': /* User name */
    2422                 strUserName = ValueUnion.psz;
     2530                strUsername = ValueUnion.psz;
    24232531                break;
    24242532
     
    24582566        return errorSyntax(USAGE_GUESTCONTROL, "No directory to create specified!");
    24592567
    2460     if (strUserName.isEmpty())
     2568    if (strUsername.isEmpty())
    24612569        return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
    24622570
     
    24752583
    24762584        hrc = guest->DirectoryCreate(Bstr(it->first).raw(),
    2477                                      Bstr(strUserName).raw(), Bstr(strPassword).raw(),
     2585                                     Bstr(strUsername).raw(), Bstr(strPassword).raw(),
    24782586                                     fDirMode, fFlags);
    24792587        if (FAILED(hrc))
     
    25122620                 s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    25132621
    2514     Utf8Str strUserName;
     2622    Utf8Str strUsername;
    25152623    Utf8Str strPassword;
    25162624    Utf8Str strDomain;
     
    25252633        {
    25262634            case 'u': /* User name */
    2527                 strUserName = ValueUnion.psz;
     2635                strUsername = ValueUnion.psz;
    25282636                break;
    25292637
     
    25712679        return errorSyntax(USAGE_GUESTCONTROL, "No element(s) to check specified!");
    25722680
    2573     if (strUserName.isEmpty())
     2681    if (strUsername.isEmpty())
    25742682        return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
    25752683
     
    25872695        BOOL fExists;
    25882696        hrc = guest->FileExists(Bstr(it->first).raw(),
    2589                                 Bstr(strUserName).raw(), Bstr(strPassword).raw(),
     2697                                Bstr(strUsername).raw(), Bstr(strPassword).raw(),
    25902698                                &fExists);
    25912699        if (FAILED(hrc))
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