VirtualBox

Ignore:
Timestamp:
Jan 21, 2020 5:48:19 PM (5 years ago)
Author:
vboxsync
Message:

IPRT/FTP: Remember the current working directory per client.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/ftp-server.cpp

    r82781 r82813  
    364364    " UTF8"
    365365
     366/** Maximum length in characters a FTP server path can have (excluding termination). */
     367#define RTFTPSERVER_MAX_PATH        RTPATH_MAX
     368
    366369
    367370/*********************************************************************************************************************************
     
    461464    RTStrFree(psz);
    462465
     466    return rc;
     467}
     468
     469/**
     470 * Sets the current working directory for a client.
     471 *
     472 * @returns VBox status code.
     473 * @param   pClient             Client to set current working directory for.
     474 * @param   pcszPath            Working directory to set.
     475 */
     476static int rtFtpSetCWD(PRTFTPSERVERCLIENT pClient, const char *pcszPath)
     477{
     478    RTStrFree(pClient->State.pszCWD);
     479
     480    pClient->State.pszCWD = RTStrDup(pcszPath);
     481
     482    LogFlowFunc(("Current CWD is now '%s'\n", pClient->State.pszCWD));
     483
     484    int rc = pClient->State.pszCWD ? VINF_SUCCESS : VERR_NO_MEMORY;
     485    AssertRC(rc);
    463486    return rc;
    464487}
     
    10381061
    10391062    if (RT_SUCCESS(rc))
     1063    {
     1064        const size_t cbPath   = sizeof(char) * RTFTPSERVER_MAX_PATH;
     1065        char        *pszPath  = RTStrAlloc(cbPath);
     1066        if (pszPath)
     1067        {
     1068            RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnPathGetCurrent, pszPath, cbPath);
     1069
     1070            if (RT_SUCCESS(rc))
     1071                rtFtpSetCWD(pClient, pszPath);
     1072
     1073            RTStrFree(pszPath);
     1074        }
     1075        else
     1076            rc = VERR_NO_MEMORY;
     1077
    10401078        return rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_OKAY);
     1079    }
    10411080
    10421081    return rc;
     
    10501089    int rc;
    10511090
    1052     RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnPathSetCurrent, apcszArgs[0]);
    1053 
    1054     if (RT_SUCCESS(rc))
     1091    const char *pcszPath = apcszArgs[0];
     1092
     1093    RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnPathSetCurrent, pcszPath);
     1094
     1095    if (RT_SUCCESS(rc))
     1096    {
     1097        rtFtpSetCWD(pClient, pcszPath);
     1098
    10551099        return rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_OKAY);
     1100    }
    10561101
    10571102    return rc;
     
    17111756    pState->pszUser = NULL;
    17121757
     1758    RTStrFree(pState->pszCWD);
     1759    pState->pszCWD = NULL;
     1760
    17131761    pState->cFailedLoginAttempts = 0;
    17141762    pState->tsLastCmdMs          = RTTimeMilliTS();
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