VirtualBox

Changeset 82841 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 23, 2020 10:02:26 AM (5 years ago)
Author:
vboxsync
Message:

IPRT/FTP: Implemented support for directory traversing. bugref:9646

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/tools/RTFTPServer.cpp

    r82822 r82841  
    6969typedef struct FTPSERVERDATA
    7070{
    71     char szRootDir[RTPATH_MAX];
     71    /** The absolute path of the FTP server's root directory. */
     72    char szPathRootAbs[RTPATH_MAX];
     73    /** The relative current working directory (CWD) to szRootDir. */
    7274    char szCWD[RTPATH_MAX];
    7375    RTFILE hFile;
     
    241243static DECLCALLBACK(int) onFileGetSize(PRTFTPCALLBACKDATA pData, const char *pcszPath, uint64_t *puSize)
    242244{
    243     RT_NOREF(pData);
     245    PFTPSERVERDATA pThis = (PFTPSERVERDATA)pData->pvUser;
     246    Assert(pData->cbUser == sizeof(FTPSERVERDATA));
     247
     248    char *pszStat = NULL;
     249    if (RTStrAPrintf(&pszStat, "%s/%s", pThis->szPathRootAbs, pcszPath) <= 0)
     250        return VERR_NO_MEMORY;
    244251
    245252    RTPrintf("Retrieving file size for '%s' ...\n", pcszPath);
     
    256263    }
    257264
     265    RTStrFree(pszStat);
     266
    258267    return rc;
    259268}
     
    264273    Assert(pData->cbUser == sizeof(FTPSERVERDATA));
    265274
    266     const char *pcszStat = pcszPath ? pcszPath : pThis->szCWD;
    267 
    268     RTPrintf("Stat for '%s'\n", pcszStat);
     275    char *pszStat = NULL;
     276    if (RTStrAPrintf(&pszStat, "%s/%s", pThis->szPathRootAbs, pcszPath) <= 0)
     277        return VERR_NO_MEMORY;
     278
     279    RTPrintf("Stat for '%s'\n", pszStat);
    269280
    270281    RTFILE hFile;
    271     int rc = RTFileOpen(&hFile, pcszStat,
     282    int rc = RTFileOpen(&hFile, pszStat,
    272283                        RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
    273284    if (RT_SUCCESS(rc))
     
    284295    }
    285296
     297    RTStrFree(pszStat);
     298
    286299    return rc;
    287300}
     
    327340    /* Construct absolute path. */
    328341    char *pszPathAbs = NULL;
    329     int rc = RTStrAAppend(&pszPathAbs, pThis->szRootDir);
    330     AssertRCReturn(rc, rc);
    331     rc = RTStrAAppend(&pszPathAbs, pcszPath);
    332     AssertRCReturn(rc, rc);
     342    if (RTStrAPrintf(&pszPathAbs, "%s/%s", pThis->szPathRootAbs, pcszPath) <= 0)
     343        return VERR_NO_MEMORY;
    333344
    334345    RTPrintf("Opening directory '%s'\n", pszPathAbs);
    335346
    336     rc = RTVfsChainOpenDir(pszPathAbs, 0 /*fFlags*/, &pHandle->hVfsDir, NULL /* poffError */, NULL /* pErrInfo */);
     347    int rc = RTVfsChainOpenDir(pszPathAbs, 0 /*fFlags*/, &pHandle->hVfsDir, NULL /* poffError */, NULL /* pErrInfo */);
    337348    if (RT_SUCCESS(rc))
    338349    {
     
    489500
    490501            case 'r':
    491                 RTStrCopy(g_FTPServerData.szRootDir, sizeof(g_FTPServerData.szRootDir), ValueUnion.psz);
     502                RTStrCopy(g_FTPServerData.szPathRootAbs, sizeof(g_FTPServerData.szPathRootAbs), ValueUnion.psz);
    492503                break;
    493504
     
    524535    }
    525536
    526     if (!strlen(g_FTPServerData.szRootDir))
     537    if (!strlen(g_FTPServerData.szPathRootAbs))
    527538    {
    528539        /* By default use the current directory as serving root directory. */
    529         rc = RTPathGetCurrent(g_FTPServerData.szRootDir, sizeof(g_FTPServerData.szRootDir));
     540        rc = RTPathGetCurrent(g_FTPServerData.szPathRootAbs, sizeof(g_FTPServerData.szPathRootAbs));
    530541        if (RT_FAILURE(rc))
    531542            return RTMsgErrorExit(RTEXITCODE_FAILURE, "Retrieving current directory failed: %Rrc", rc);
     
    566577        {
    567578            RTPrintf("Starting FTP server at %s:%RU16 ...\n", szAddress, uPort);
    568             RTPrintf("Root directory is '%s'\n", g_FTPServerData.szRootDir);
     579            RTPrintf("Root directory is '%s'\n", g_FTPServerData.szPathRootAbs);
    569580
    570581            RTPrintf("Running FTP server ...\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