VirtualBox

Changeset 86973 in vbox


Ignore:
Timestamp:
Nov 25, 2020 9:18:33 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141515
Message:

IPRT/FTP: Resolved some @ŧodos. bugref:9646

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/ftp.h

    r85121 r86973  
    5454
    5555/** Maximum length (in characters) a command can have (without parameters). */
    56 #define RTFTPSERVER_MAX_CMD_LEN                 64
     56#define RTFTPSERVER_MAX_CMD_LEN                 8
    5757
    5858/**
  • trunk/src/VBox/Runtime/r3/ftp-server.cpp

    r85676 r86973  
    326326
    327327/** Function pointer declaration for a specific FTP server command handler. */
    328 typedef DECLCALLBACKTYPE(int, FNRTFTPSERVERCMD,(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs));
     328typedef DECLCALLBACKTYPE(int, FNRTFTPSERVERCMD,(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs));
    329329/** Pointer to a FNRTFTPSERVERCMD(). */
    330330typedef FNRTFTPSERVERCMD *PFNRTFTPSERVERCMD;
     
    337337static int  rtFtpServerDataConnClose(PRTFTPSERVERDATACONN pDataConn);
    338338static void rtFtpServerDataConnReset(PRTFTPSERVERDATACONN pDataConn);
    339 static int  rtFtpServerDataConnStart(PRTFTPSERVERDATACONN pDataConn, PFNRTTHREAD pfnThread, uint8_t cArgs, const char * const *apcszArgs);
     339static int  rtFtpServerDataConnStart(PRTFTPSERVERDATACONN pDataConn, PFNRTTHREAD pfnThread, uint8_t cArgs, const char * const *apszArgs);
    340340static int  rtFtpServerDataConnStop(PRTFTPSERVERDATACONN pDataConn);
    341341static void rtFtpServerDataConnDestroy(PRTFTPSERVERDATACONN pDataConn);
     
    375375    /** Command ID. */
    376376    RTFTPSERVERCMD      enmCmd;
    377     /** Command represented as ASCII string.
    378      * @todo r=bird: It's a waste to use 64 byte here when all supported commands
    379      *       are 3 or 4 chars + terminator.  For (64-bit) alignment reasons,  */
     377    /** Command represented as ASCII string. */
    380378    char                szCmd[RTFTPSERVER_MAX_CMD_LEN];
    381379    /** Whether the commands needs a logged in (valid) user. */
     
    466464 * @param   pClient             Client to reply to.
    467465 * @param   enmReply            Reply code to send.
    468  * @param   pcszFormat          Format string of message to send with the reply code.
     466 * @param   pszFormat           Format string of message to send with the reply code.
    469467 */
    470468static int rtFtpServerSendReplyRcEx(PRTFTPSERVERCLIENT pClient, RTFTPSERVER_REPLY enmReply,
    471                                     const char *pcszFormat, ...)
     469                                    const char *pszFormat, ...)
    472470{
    473471    char *pszMsg = NULL;
    474472
    475473    va_list args;
    476     va_start(args, pcszFormat);
     474    va_start(args, pszFormat);
    477475    char *pszFmt = NULL;
    478     const int cch = RTStrAPrintfV(&pszFmt, pcszFormat, args);
     476    const int cch = RTStrAPrintfV(&pszFmt, pszFormat, args);
    479477    va_end(args);
    480478    AssertReturn(cch > 0, VERR_NO_MEMORY);
     
    512510 * @returns VBox status code.
    513511 * @param   pClient             Client to reply to.
    514  * @param   pcszFormat          Format to reply.
     512 * @param   pszFormat           Format to reply.
    515513 * @param   ...                 Format arguments.
    516514 */
    517 static int rtFtpServerSendReplyStr(PRTFTPSERVERCLIENT pClient, const char *pcszFormat, ...)
     515static int rtFtpServerSendReplyStr(PRTFTPSERVERCLIENT pClient, const char *pszFormat, ...)
    518516{
    519517    va_list args;
    520     va_start(args, pcszFormat);
     518    va_start(args, pszFormat);
    521519    char *psz = NULL;
    522     const int cch = RTStrAPrintfV(&psz, pcszFormat, args);
     520    const int cch = RTStrAPrintfV(&psz, pszFormat, args);
    523521    va_end(args);
    524522    AssertReturn(cch > 0, VERR_NO_MEMORY);
     
    540538 *
    541539 * @returns \c true if path is valid, or \c false if not.
    542  * @param   pcszPath            Path to check.
     540 * @param   pszPath             Path to check.
    543541 * @param   fIsAbsolute         Whether the path to check is an absolute path or not.
    544542 */
    545 static bool rtFtpServerPathIsValid(const char *pcszPath, bool fIsAbsolute)
    546 {
    547     if (!pcszPath)
     543static bool rtFtpServerPathIsValid(const char *pszPath, bool fIsAbsolute)
     544{
     545    if (!pszPath)
    548546        return false;
    549547
    550     bool fIsValid =    strlen(pcszPath)
    551                     && RTStrIsValidEncoding(pcszPath)
    552                     && RTStrStr(pcszPath, "..") == NULL;     /** @todo Very crude for now -- improve this. */
     548    bool fIsValid =    strlen(pszPath)
     549                    && RTStrIsValidEncoding(pszPath)
     550                    && RTStrStr(pszPath, "..") == NULL;     /** @todo Very crude for now -- improve this. */
    553551    if (   fIsValid
    554552        && fIsAbsolute)
    555553    {
    556554        RTFSOBJINFO objInfo;
    557         int rc2 = RTPathQueryInfo(pcszPath, &objInfo, RTFSOBJATTRADD_NOTHING);
     555        int rc2 = RTPathQueryInfo(pszPath, &objInfo, RTFSOBJATTRADD_NOTHING);
    558556        if (RT_SUCCESS(rc2))
    559557        {
     
    567565    }
    568566
    569     LogFlowFunc(("pcszPath=%s -> %RTbool\n", pcszPath, fIsValid));
     567    LogFlowFunc(("pszPath=%s -> %RTbool\n", pszPath, fIsValid));
    570568    return fIsValid;
    571569}
     
    576574 * @returns VBox status code.
    577575 * @param   pState              Client state to set current working directory for.
    578  * @param   pcszPath            Working directory to set.
    579  */
    580 static int rtFtpSetCWD(PRTFTPSERVERCLIENTSTATE pState, const char *pcszPath)
     576 * @param   pszPath             Working directory to set.
     577 */
     578static int rtFtpSetCWD(PRTFTPSERVERCLIENTSTATE pState, const char *pszPath)
    581579{
    582580    RTStrFree(pState->pszCWD);
    583581
    584     if (!rtFtpServerPathIsValid(pcszPath, false /* fIsAbsolute */))
     582    if (!rtFtpServerPathIsValid(pszPath, false /* fIsAbsolute */))
    585583        return VERR_INVALID_PARAMETER;
    586584
    587     pState->pszCWD = RTStrDup(pcszPath);
     585    pState->pszCWD = RTStrDup(pszPath);
    588586
    589587    LogFlowFunc(("Current CWD is now '%s'\n", pState->pszCWD));
     
    599597 * @returns VBox status code, or VERR_NOT_FOUND if user has not been found.
    600598 * @param   pClient             Client to look up user for.
    601  * @param   pcszUser            User name to look up.
    602  */
    603 static int rtFtpServerLookupUser(PRTFTPSERVERCLIENT pClient, const char *pcszUser)
    604 {
    605     RTFTPSERVER_HANDLE_CALLBACK_VA_RET(pfnOnUserConnect, pcszUser);
     599 * @param   pszUser             User name to look up.
     600 */
     601static int rtFtpServerLookupUser(PRTFTPSERVERCLIENT pClient, const char *pszUser)
     602{
     603    RTFTPSERVER_HANDLE_CALLBACK_VA_RET(pfnOnUserConnect, pszUser);
    606604}
    607605
     
    611609 * @returns VBox status code, or VERR_ACCESS_DENIED if authentication failed.
    612610 * @param   pClient             Client to authenticate.
    613  * @param   pcszUser            User name to authenticate with.
    614  * @param   pcszPassword        Password to authenticate with.
    615  */
    616 static int rtFtpServerAuthenticate(PRTFTPSERVERCLIENT pClient, const char *pcszUser, const char *pcszPassword)
    617 {
    618     RTFTPSERVER_HANDLE_CALLBACK_VA_RET(pfnOnUserAuthenticate, pcszUser, pcszPassword);
     611 * @param   pszUser             User name to authenticate with.
     612 * @param   pszPassword         Password to authenticate with.
     613 */
     614static int rtFtpServerAuthenticate(PRTFTPSERVERCLIENT pClient, const char *pszUser, const char *pszPassword)
     615{
     616    RTFTPSERVER_HANDLE_CALLBACK_VA_RET(pfnOnUserAuthenticate, pszUser, pszPassword);
    619617}
    620618
     
    713711 *
    714712 * @returns VBox status code.
    715  * @param   pcszStr             String to parse.
     713 * @param   pszStr              String to parse.
    716714 * @param   pAddr               Where to store the IPv4 address on success.
    717715 * @param   puPort              Where to store the port number on success.
    718716 */
    719 static int rtFtpParseHostAndPort(const char *pcszStr, PRTNETADDRIPV4 pAddr, uint16_t *puPort)
    720 {
    721     AssertPtrReturn(pcszStr, VERR_INVALID_POINTER);
     717static int rtFtpParseHostAndPort(const char *pszStr, PRTNETADDRIPV4 pAddr, uint16_t *puPort)
     718{
     719    AssertPtrReturn(pszStr, VERR_INVALID_POINTER);
    722720    AssertPtrReturn(pAddr, VERR_INVALID_POINTER);
    723721    AssertPtrReturn(puPort, VERR_INVALID_POINTER);
     
    728726    /* Parse IP (v4). */
    729727    /** @todo I don't think IPv6 ever will be a thing here, or will it? */
    730     rc = RTStrToUInt8Ex(pcszStr, &pszNext, 10, &pAddr->au8[0]);
     728    rc = RTStrToUInt8Ex(pszStr, &pszNext, 10, &pAddr->au8[0]);
    731729    if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
    732730        return VERR_INVALID_PARAMETER;
     
    774772 * @returns Duplicated argument vector or NULL if failed or no arguments given. Needs to be free'd with rtFtpCmdArgsFree().
    775773 * @param   cArgs               Number of arguments in argument vector.
    776  * @param   apcszArgs           Pointer to argument vector to duplicate.
    777  */
    778 static char** rtFtpCmdArgsDup(uint8_t cArgs, const char * const *apcszArgs)
     774 * @param   apszArgs            Pointer to argument vector to duplicate.
     775 */
     776static char** rtFtpCmdArgsDup(uint8_t cArgs, const char * const *apszArgs)
    779777{
    780778    if (!cArgs)
    781779        return NULL;
    782780
    783     char **apcszArgsDup = (char **)RTMemAlloc(cArgs * sizeof(char *));
    784     if (!apcszArgsDup)
     781    char **apszArgsDup = (char **)RTMemAlloc(cArgs * sizeof(char *));
     782    if (!apszArgsDup)
    785783    {
    786784        AssertFailed();
     
    793791    for (i = 0; i < cArgs; i++)
    794792    {
    795         apcszArgsDup[i] = RTStrDup(apcszArgs[i]);
    796         if (!apcszArgsDup[i])
     793        apszArgsDup[i] = RTStrDup(apszArgs[i]);
     794        if (!apszArgsDup[i])
    797795            rc2 = VERR_NO_MEMORY;
    798796    }
     
    801799    {
    802800        while (i--)
    803             RTStrFree(apcszArgsDup[i]);
    804 
    805         RTMemFree(apcszArgsDup);
     801            RTStrFree(apszArgsDup[i]);
     802
     803        RTMemFree(apszArgsDup);
    806804        return NULL;
    807805    }
    808806
    809     return apcszArgsDup;
     807    return apszArgsDup;
    810808}
    811809
     
    814812 *
    815813 * @param   cArgs               Number of arguments in argument vector.
    816  * @param   papcszArgs          Pointer to argument vector to free.
    817  */
    818 static void rtFtpCmdArgsFree(uint8_t cArgs, char **papcszArgs)
     814 * @param   papszArgs           Pointer to argument vector to free.
     815 */
     816static void rtFtpCmdArgsFree(uint8_t cArgs, char **papszArgs)
    819817{
    820818    while (cArgs--)
    821         RTStrFree(papcszArgs[cArgs]);
    822 
    823     RTMemFree(papcszArgs);
     819        RTStrFree(papszArgs[cArgs]);
     820
     821    RTMemFree(papszArgs);
    824822}
    825823
     
    1001999 * @returns VBox status code.
    10021000 * @param   pDataConn           Data connection to write to.
    1003  * @param   pcszFormat          Format string to send. No (terminal) termination added.
    1004  */
    1005 static int rtFtpServerDataConnPrintf(PRTFTPSERVERDATACONN pDataConn, const char *pcszFormat, ...)
     1001 * @param   pszFormat           Format string to send. No (terminal) termination added.
     1002 */
     1003static int rtFtpServerDataConnPrintf(PRTFTPSERVERDATACONN pDataConn, const char *pszFormat, ...)
    10061004{
    10071005    va_list args;
    1008     va_start(args, pcszFormat);
     1006    va_start(args, pszFormat);
    10091007    char *pszFmt = NULL;
    1010     const int cch = RTStrAPrintfV(&pszFmt, pcszFormat, args);
     1008    const int cch = RTStrAPrintfV(&pszFmt, pszFormat, args);
    10111009    va_end(args);
    10121010    AssertReturn(cch > 0, VERR_NO_MEMORY);
     
    10571055
    10581056    AssertPtr(pDataConn->papszArgs);
    1059     const char *pcszFile = pDataConn->papszArgs[0];
    1060     AssertPtr(pcszFile);
     1057    const char *pszFile = pDataConn->papszArgs[0];
     1058    AssertPtr(pszFile);
    10611059
    10621060    void *pvHandle = NULL; /* Opaque handle known to the actual implementation. */
    10631061
    1064     RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileOpen, pcszFile,
     1062    RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileOpen, pszFile,
    10651063                                   RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &pvHandle);
    10661064    if (RT_SUCCESS(rc))
     
    11421140 * @param   pfnThread           Thread function for the data connection to use.
    11431141 * @param   cArgs               Number of arguments.
    1144  * @param   apcszArgs           Array of arguments.
     1142 * @param   apszArgs            Array of arguments.
    11451143 */
    11461144static int rtFtpServerDataConnStart(PRTFTPSERVERDATACONN pDataConn, PFNRTTHREAD pfnThread,
    1147                                     uint8_t cArgs, const char * const *apcszArgs)
     1145                                    uint8_t cArgs, const char * const *apszArgs)
    11481146{
    11491147    AssertPtrReturn(pDataConn, VERR_INVALID_POINTER);
     
    11581156    if (cArgs)
    11591157    {
    1160         pDataConn->papszArgs = rtFtpCmdArgsDup(cArgs, apcszArgs);
     1158        pDataConn->papszArgs = rtFtpCmdArgsDup(cArgs, apszArgs);
    11611159        if (!pDataConn->papszArgs)
    11621160            rc = VERR_NO_MEMORY;
     
    12791277*********************************************************************************************************************************/
    12801278
    1281 static DECLCALLBACK(int) rtFtpServerHandleABOR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1282 {
    1283     RT_NOREF(cArgs, apcszArgs);
     1279static DECLCALLBACK(int) rtFtpServerHandleABOR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1280{
     1281    RT_NOREF(cArgs, apszArgs);
    12841282
    12851283    int rc = rtFtpServerDataConnClose(pClient->pDataConn);
     
    12951293}
    12961294
    1297 static DECLCALLBACK(int) rtFtpServerHandleCDUP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1298 {
    1299     RT_NOREF(cArgs, apcszArgs);
     1295static DECLCALLBACK(int) rtFtpServerHandleCDUP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1296{
     1297    RT_NOREF(cArgs, apszArgs);
    13001298
    13011299    int rc;
     
    13311329}
    13321330
    1333 static DECLCALLBACK(int) rtFtpServerHandleCWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     1331static DECLCALLBACK(int) rtFtpServerHandleCWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    13341332{
    13351333    if (cArgs != 1)
     
    13381336    int rc;
    13391337
    1340     const char *pcszPath = apcszArgs[0];
    1341 
    1342     if (!rtFtpServerPathIsValid(pcszPath, false /* fIsAbsolute */))
     1338    const char *pszPath = apszArgs[0];
     1339
     1340    if (!rtFtpServerPathIsValid(pszPath, false /* fIsAbsolute */))
    13431341        return VERR_INVALID_PARAMETER;
    13441342
    1345     RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnPathSetCurrent, pcszPath);
     1343    RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnPathSetCurrent, pszPath);
    13461344
    13471345    if (RT_SUCCESS(rc))
    1348         rc = rtFtpSetCWD(&pClient->State, pcszPath);
     1346        rc = rtFtpSetCWD(&pClient->State, pszPath);
    13491347
    13501348    return rtFtpServerSendReplyRc(pClient,
     
    13531351}
    13541352
    1355 static DECLCALLBACK(int) rtFtpServerHandleFEAT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1356 {
    1357     RT_NOREF(cArgs, apcszArgs);
     1353static DECLCALLBACK(int) rtFtpServerHandleFEAT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1354{
     1355    RT_NOREF(cArgs, apszArgs);
    13581356
    13591357    int rc = rtFtpServerSendReplyStr(pClient, "211-BEGIN Features:");
     
    18711869}
    18721870
    1873 static DECLCALLBACK(int) rtFtpServerHandleLIST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     1871static DECLCALLBACK(int) rtFtpServerHandleLIST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    18741872{
    18751873    /* If no argument is given, use the server's CWD as the path. */
    1876     const char *pcszPath = cArgs ? apcszArgs[0] : pClient->State.pszCWD;
    1877     AssertPtr(pcszPath);
     1874    const char *pszPath = cArgs ? apszArgs[0] : pClient->State.pszCWD;
     1875    AssertPtr(pszPath);
    18781876
    18791877    int rc = VINF_SUCCESS;
    18801878
    1881     if (!rtFtpServerPathIsValid(pcszPath, false /* fIsAbsolute */))
     1879    if (!rtFtpServerPathIsValid(pszPath, false /* fIsAbsolute */))
    18821880    {
    18831881        int rc2 = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_CONN_REQ_FILE_ACTION_NOT_TAKEN);
     
    18861884    else
    18871885    {
    1888         RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileStat, pcszPath, NULL /* PRTFSOBJINFO */);
     1886        RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileStat, pszPath, NULL /* PRTFSOBJINFO */);
    18891887
    18901888        if (RT_SUCCESS(rc))
     
    18941892                rc = rtFtpServerDataConnCreate(pClient, &pClient->pDataConn);
    18951893                if (RT_SUCCESS(rc))
    1896                     rc = rtFtpServerDataConnStart(pClient->pDataConn, rtFtpServerDataConnListThread, cArgs, apcszArgs);
     1894                    rc = rtFtpServerDataConnStart(pClient->pDataConn, rtFtpServerDataConnListThread, cArgs, apszArgs);
    18971895
    18981896                int rc2 = rtFtpServerSendReplyRc(  pClient, RT_SUCCESS(rc)
     
    19171915}
    19181916
    1919 static DECLCALLBACK(int) rtFtpServerHandleMODE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1920 {
    1921     RT_NOREF(pClient, cArgs, apcszArgs);
     1917static DECLCALLBACK(int) rtFtpServerHandleMODE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1918{
     1919    RT_NOREF(pClient, cArgs, apszArgs);
    19221920
    19231921    /** @todo Anything to do here? */
     
    19251923}
    19261924
    1927 static DECLCALLBACK(int) rtFtpServerHandleNOOP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1928 {
    1929     RT_NOREF(cArgs, apcszArgs);
     1925static DECLCALLBACK(int) rtFtpServerHandleNOOP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1926{
     1927    RT_NOREF(cArgs, apszArgs);
    19301928
    19311929    /* Save timestamp of last command sent. */
     
    19351933}
    19361934
    1937 static DECLCALLBACK(int) rtFtpServerHandlePASS(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     1935static DECLCALLBACK(int) rtFtpServerHandlePASS(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    19381936{
    19391937    if (cArgs != 1)
    19401938        return rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_INVALID_PARAMETERS);
    19411939
    1942     const char *pcszPassword = apcszArgs[0];
    1943     AssertPtrReturn(pcszPassword, VERR_INVALID_PARAMETER);
    1944 
    1945     int rc = rtFtpServerAuthenticate(pClient, pClient->State.pszUser, pcszPassword);
     1940    const char *pszPassword = apszArgs[0];
     1941    AssertPtrReturn(pszPassword, VERR_INVALID_PARAMETER);
     1942
     1943    int rc = rtFtpServerAuthenticate(pClient, pClient->State.pszUser, pszPassword);
    19461944    if (RT_SUCCESS(rc))
    19471945    {
     
    19601958}
    19611959
    1962 static DECLCALLBACK(int) rtFtpServerHandlePORT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     1960static DECLCALLBACK(int) rtFtpServerHandlePORT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    19631961{
    19641962    if (cArgs != 1)
     
    19671965    RTFTPSERVER_REPLY rcClient;
    19681966
    1969     int rc = rtFtpParseHostAndPort(apcszArgs[0], &pClient->DataConnAddr, &pClient->uDataConnPort);
     1967    int rc = rtFtpParseHostAndPort(apszArgs[0], &pClient->DataConnAddr, &pClient->uDataConnPort);
    19701968    if (RT_SUCCESS(rc))
    19711969        rcClient = RTFTPSERVER_REPLY_OKAY;
     
    19801978}
    19811979
    1982 static DECLCALLBACK(int) rtFtpServerHandlePWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1983 {
    1984     RT_NOREF(cArgs, apcszArgs);
     1980static DECLCALLBACK(int) rtFtpServerHandlePWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1981{
     1982    RT_NOREF(cArgs, apszArgs);
    19851983
    19861984    int rc;
     
    19961994}
    19971995
    1998 static DECLCALLBACK(int) rtFtpServerHandleOPTS(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    1999 {
    2000     RT_NOREF(cArgs, apcszArgs);
     1996static DECLCALLBACK(int) rtFtpServerHandleOPTS(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     1997{
     1998    RT_NOREF(cArgs, apszArgs);
    20011999
    20022000    int rc = VINF_SUCCESS;
     
    20092007}
    20102008
    2011 static DECLCALLBACK(int) rtFtpServerHandleQUIT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    2012 {
    2013     RT_NOREF(cArgs, apcszArgs);
     2009static DECLCALLBACK(int) rtFtpServerHandleQUIT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     2010{
     2011    RT_NOREF(cArgs, apszArgs);
    20142012
    20152013    int rc = VINF_SUCCESS;
     
    20322030}
    20332031
    2034 static DECLCALLBACK(int) rtFtpServerHandleRETR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     2032static DECLCALLBACK(int) rtFtpServerHandleRETR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    20352033{
    20362034    if (cArgs != 1) /* File name needs to be present. */
     
    20392037    int rc;
    20402038
    2041     const char *pcszPath = apcszArgs[0];
    2042 
    2043     RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileStat, pcszPath, NULL /* PRTFSOBJINFO */);
     2039    const char *pszPath = apszArgs[0];
     2040
     2041    RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileStat, pszPath, NULL /* PRTFSOBJINFO */);
    20442042
    20452043    if (RT_SUCCESS(rc))
     
    20512049                rc = rtFtpServerDataConnCreate(pClient, &pClient->pDataConn);
    20522050                if (RT_SUCCESS(rc))
    2053                     rc = rtFtpServerDataConnStart(pClient->pDataConn, rtFtpServerDataConnFileWriteThread, cArgs, apcszArgs);
     2051                    rc = rtFtpServerDataConnStart(pClient->pDataConn, rtFtpServerDataConnFileWriteThread, cArgs, apszArgs);
    20542052
    20552053                int rc2 = rtFtpServerSendReplyRc(  pClient, RT_SUCCESS(rc)
     
    20802078}
    20812079
    2082 static DECLCALLBACK(int) rtFtpServerHandleSIZE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     2080static DECLCALLBACK(int) rtFtpServerHandleSIZE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    20832081{
    20842082    if (cArgs != 1)
     
    20872085    int rc;
    20882086
    2089     const char *pcszPath = apcszArgs[0];
     2087    const char *pszPath = apszArgs[0];
    20902088    uint64_t uSize = 0;
    20912089
    2092     RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileGetSize, pcszPath, &uSize);
     2090    RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileGetSize, pszPath, &uSize);
    20932091
    20942092    if (RT_SUCCESS(rc))
     
    21052103}
    21062104
    2107 static DECLCALLBACK(int) rtFtpServerHandleSTAT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     2105static DECLCALLBACK(int) rtFtpServerHandleSTAT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    21082106{
    21092107    if (cArgs != 1)
     
    21152113    RT_ZERO(objInfo);
    21162114
    2117     const char *pcszPath = apcszArgs[0];
    2118 
    2119     RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileStat, pcszPath, &objInfo);
     2115    const char *pszPath = apszArgs[0];
     2116
     2117    RTFTPSERVER_HANDLE_CALLBACK_VA(pfnOnFileStat, pszPath, &objInfo);
    21202118
    21212119    if (RT_SUCCESS(rc))
     
    21262124        {
    21272125            char szFsPathInfo[RTPATH_MAX + 16];
    2128             const ssize_t cchPathInfo = RTStrPrintf2(szFsPathInfo, sizeof(szFsPathInfo), " %2zu %s\n", strlen(pcszPath), pcszPath);
     2126            const ssize_t cchPathInfo = RTStrPrintf2(szFsPathInfo, sizeof(szFsPathInfo), " %2zu %s\n", strlen(pszPath), pszPath);
    21292127            if (cchPathInfo > 0)
    21302128            {
     
    21472145}
    21482146
    2149 static DECLCALLBACK(int) rtFtpServerHandleSTRU(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     2147static DECLCALLBACK(int) rtFtpServerHandleSTRU(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    21502148{
    21512149    if (cArgs != 1)
    21522150        return VERR_INVALID_PARAMETER;
    21532151
    2154     const char *pcszType = apcszArgs[0];
     2152    const char *pszType = apszArgs[0];
    21552153
    21562154    int rc;
    21572155
    2158     if (!RTStrICmp(pcszType, "F"))
     2156    if (!RTStrICmp(pszType, "F"))
    21592157    {
    21602158        pClient->State.enmStructType = RTFTPSERVER_STRUCT_TYPE_FILE;
     
    21682166}
    21692167
    2170 static DECLCALLBACK(int) rtFtpServerHandleSYST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
    2171 {
    2172     RT_NOREF(cArgs, apcszArgs);
     2168static DECLCALLBACK(int) rtFtpServerHandleSYST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
     2169{
     2170    RT_NOREF(cArgs, apszArgs);
    21732171
    21742172    char szOSInfo[64];
     
    21802178}
    21812179
    2182 static DECLCALLBACK(int) rtFtpServerHandleTYPE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     2180static DECLCALLBACK(int) rtFtpServerHandleTYPE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    21832181{
    21842182    if (cArgs != 1)
    21852183        return VERR_INVALID_PARAMETER;
    21862184
    2187     const char *pcszType = apcszArgs[0];
     2185    const char *pszType = apszArgs[0];
    21882186
    21892187    int rc = VINF_SUCCESS;
    21902188
    2191     if (!RTStrICmp(pcszType, "A"))
     2189    if (!RTStrICmp(pszType, "A"))
    21922190    {
    21932191        pClient->State.enmDataType = RTFTPSERVER_DATA_TYPE_ASCII;
    21942192    }
    2195     else if (!RTStrICmp(pcszType, "I")) /* Image (binary). */
     2193    else if (!RTStrICmp(pszType, "I")) /* Image (binary). */
    21962194    {
    21972195        pClient->State.enmDataType = RTFTPSERVER_DATA_TYPE_IMAGE;
     
    22062204}
    22072205
    2208 static DECLCALLBACK(int) rtFtpServerHandleUSER(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)
     2206static DECLCALLBACK(int) rtFtpServerHandleUSER(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apszArgs)
    22092207{
    22102208    if (cArgs != 1)
    22112209        return VERR_INVALID_PARAMETER;
    22122210
    2213     const char *pcszUser = apcszArgs[0];
    2214     AssertPtrReturn(pcszUser, VERR_INVALID_PARAMETER);
     2211    const char *pszUser = apszArgs[0];
     2212    AssertPtrReturn(pszUser, VERR_INVALID_PARAMETER);
    22152213
    22162214    rtFtpServerClientStateReset(&pClient->State);
    22172215
    2218     int rc = rtFtpServerLookupUser(pClient, pcszUser);
     2216    int rc = rtFtpServerLookupUser(pClient, pszUser);
    22192217    if (RT_SUCCESS(rc))
    22202218    {
    2221         pClient->State.pszUser = RTStrDup(pcszUser);
     2219        pClient->State.pszUser = RTStrDup(pszUser);
    22222220        AssertPtrReturn(pClient->State.pszUser, VERR_NO_MEMORY);
    22232221
     
    22452243 *
    22462244 * @returns VBox status code.
    2247  * @param   pcszCmdParms        Pointer to command arguments, if any. Can be NULL if no arguments are given.
     2245 * @param   pszCmdParms         Pointer to command arguments, if any. Can be NULL if no arguments are given.
    22482246 * @param   pcArgs              Returns the number of parsed arguments, separated by a space (hex 0x20).
    2249  * @param   ppapcszArgs         Returns the string array of parsed arguments. Needs to be free'd with rtFtpServerCmdArgsFree().
    2250  */
    2251 static int rtFtpServerCmdArgsParse(const char *pcszCmdParms, uint8_t *pcArgs, char ***ppapcszArgs)
     2247 * @param   ppapszArgs          Returns the string array of parsed arguments. Needs to be free'd with rtFtpServerCmdArgsFree().
     2248 */
     2249static int rtFtpServerCmdArgsParse(const char *pszCmdParms, uint8_t *pcArgs, char ***ppapszArgs)
    22522250{
    22532251    *pcArgs      = 0;
    2254     *ppapcszArgs = NULL;
    2255 
    2256     if (!pcszCmdParms) /* No parms given? Bail out early. */
     2252    *ppapszArgs = NULL;
     2253
     2254    if (!pszCmdParms) /* No parms given? Bail out early. */
    22572255        return VINF_SUCCESS;
    22582256
     
    22612259
    22622260    int cArgs = 0;
    2263     int rc = RTGetOptArgvFromString(ppapcszArgs, &cArgs, pcszCmdParms, RTGETOPTARGV_CNV_QUOTE_MS_CRT, " " /* Separators */);
     2261    int rc = RTGetOptArgvFromString(ppapszArgs, &cArgs, pszCmdParms, RTGETOPTARGV_CNV_QUOTE_MS_CRT, " " /* Separators */);
    22642262    if (RT_SUCCESS(rc))
    22652263    {
     
    22782276 * Frees a formerly argument string array parsed by rtFtpServerCmdArgsParse().
    22792277 *
    2280  * @param   ppapcszArgs         Argument string array to free.
    2281  */
    2282 static void rtFtpServerCmdArgsFree(char **ppapcszArgs)
    2283 {
    2284     RTGetOptArgvFree(ppapcszArgs);
     2278 * @param   ppapszArgs          Argument string array to free.
     2279 */
     2280static void rtFtpServerCmdArgsFree(char **ppapszArgs)
     2281{
     2282    RTGetOptArgvFree(ppapszArgs);
    22852283}
    22862284
     
    22902288 * @returns VBox status code.
    22912289 * @param   pClient             Client to process commands for.
    2292  * @param   pcszCmd             Command string to parse and handle.
     2290 * @param   pszCmd              Command string to parse and handle.
    22932291 * @param   cbCmd               Size (in bytes) of command string.
    22942292 */
    2295 static int rtFtpServerProcessCommands(PRTFTPSERVERCLIENT pClient, char *pcszCmd, size_t cbCmd)
    2296 {
    2297     /** @todo r=bird: pcszCmd is a misnomer, it is _clearly_ not const as you
    2298      * modify it all over the place!  Please do _not_use 'c' to mean 'const', it
    2299      * means 'count of'. */
     2293static int rtFtpServerProcessCommands(PRTFTPSERVERCLIENT pClient, char *pszCmd, size_t cbCmd)
     2294{
    23002295    /* Make sure to terminate the string in any case. */
    2301     pcszCmd[RT_MIN(RTFTPSERVER_MAX_CMD_LEN, cbCmd)] = '\0';
     2296    pszCmd[RT_MIN(RTFTPSERVER_MAX_CMD_LEN, cbCmd)] = '\0';
    23022297
    23032298    /* A tiny bit of sanitation. */
    2304     RTStrStripL(pcszCmd);
     2299    RTStrStripL(pszCmd);
    23052300
    23062301    /* First, terminate string by finding the command end marker (telnet style). */
    23072302    /** @todo Not sure if this is entirely correct and/or needs tweaking; good enough for now as it seems. */
    2308     /** @todo r=bird: Why are you using the case-insensitive version here? */
    2309     char *pszCmdEnd = RTStrIStr(pcszCmd, "\r\n");
     2303    char *pszCmdEnd = RTStrStr(pszCmd, "\r\n");
    23102304    if (pszCmdEnd)
    23112305        *pszCmdEnd = '\0';
     
    23182312    uint8_t cArgs     = 0;
    23192313    char  **papszArgs = NULL;
    2320     int rc = rtFtpServerCmdArgsParse(pcszCmd, &cArgs, &papszArgs);
     2314    int rc = rtFtpServerCmdArgsParse(pszCmd, &cArgs, &papszArgs);
    23212315    if (   RT_SUCCESS(rc)
    23222316        && cArgs) /* At least the actual command (without args) must be present. */
     
    24152409 *       (even in C++ code, see init() methods in the API).
    24162410 */
    2417 static int rtFtpServerProcessCommands(PRTFTPSERVERCLIENT pClient)
     2411static int rtFtpServerClientMain(PRTFTPSERVERCLIENT pClient)
    24182412{
    24192413    int rc;
     
    25272521        ASMAtomicIncU32(&pThis->cClients);
    25282522
    2529         rc = rtFtpServerProcessCommands(&Client);
     2523        rc = rtFtpServerClientMain(&Client);
    25302524
    25312525        ASMAtomicDecU32(&pThis->cClients);
     
    25372531}
    25382532
    2539 RTR3DECL(int) RTFtpServerCreate(PRTFTPSERVER phFTPServer, const char *pcszAddress, uint16_t uPort,
     2533RTR3DECL(int) RTFtpServerCreate(PRTFTPSERVER phFTPServer, const char *pszAddress, uint16_t uPort,
    25402534                                PRTFTPSERVERCALLBACKS pCallbacks, void *pvUser, size_t cbUser)
    25412535{
    25422536    AssertPtrReturn(phFTPServer,  VERR_INVALID_POINTER);
    2543     AssertPtrReturn(pcszAddress,  VERR_INVALID_POINTER);
     2537    AssertPtrReturn(pszAddress,  VERR_INVALID_POINTER);
    25442538    AssertReturn   (uPort,        VERR_INVALID_PARAMETER);
    25452539    AssertPtrReturn(pCallbacks,   VERR_INVALID_POINTER);
     
    25562550        pThis->cbUser    = cbUser;
    25572551
    2558         rc = RTTcpServerCreate(pcszAddress, uPort, RTTHREADTYPE_DEFAULT, "ftpsrv",
     2552        rc = RTTcpServerCreate(pszAddress, uPort, RTTHREADTYPE_DEFAULT, "ftpsrv",
    25592553                               rtFtpServerClientThread, pThis /* pvUser */, &pThis->pTCPServer);
    25602554        if (RT_SUCCESS(rc))
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