VirtualBox

Changeset 82735 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jan 14, 2020 12:59:53 PM (5 years ago)
Author:
vboxsync
Message:

IPRT/FTP: Made connecting w/ other clients more compatible by also supplying a (short) welcome message text. bugref:9646

File:
1 edited

Legend:

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

    r82734 r82735  
    357357    RTStrPrintf2(szReply, sizeof(szReply), "%RU32\r\n", enmReply);
    358358
     359    LogFlowFunc(("Sending reply code %RU32\n", enmReply));
     360
    359361    return RTTcpWrite(pClient->hSocket, szReply, strlen(szReply) + 1);
     362}
     363
     364/**
     365 * Replies a (three digit) reply code with a custom message back to the client.
     366 *
     367 * @returns VBox status code.
     368 * @param   pClient             Client to reply to.
     369 * @param   enmReply            Reply code to send.
     370 * @param   pcszFormat          Format string of message to send with the reply code.
     371 */
     372static int rtFtpServerSendReplyRcEx(PRTFTPSERVERCLIENT pClient, RTFTPSERVER_REPLY enmReply,
     373                                    const char *pcszFormat, ...)
     374{
     375    char *pszMsg = NULL;
     376
     377    va_list args;
     378    va_start(args, pcszFormat);
     379    char *pszFmt = NULL;
     380    const int cch = RTStrAPrintfV(&pszFmt, pcszFormat, args);
     381    va_end(args);
     382    AssertReturn(cch > 0, VERR_NO_MEMORY);
     383
     384    int rc = RTStrAPrintf(&pszMsg, "%RU32", enmReply);
     385    AssertRCReturn(rc, rc);
     386
     387    if (pszFmt)
     388    {
     389        rc = RTStrAAppend(&pszMsg, " - ");
     390        AssertRCReturn(rc, rc);
     391
     392        rc = RTStrAAppend(&pszMsg, pszFmt);
     393        AssertRCReturn(rc, rc);
     394    }
     395
     396
     397    rc = RTStrAAppend(&pszMsg, "\r\n");
     398    AssertRCReturn(rc, rc);
     399
     400    RTStrFree(pszFmt);
     401
     402    rc = RTTcpWrite(pClient->hSocket, pszMsg, strlen(pszMsg) + 1 /* Include termination */);
     403
     404    RTStrFree(pszMsg);
     405
     406    return rc;
    360407}
    361408
     
    12111258        && cArgs) /* At least the actual command (without args) must be present. */
    12121259    {
     1260        LogFlowFunc(("Handling command '%s'\n", papszArgs[0]));
     1261
    12131262        unsigned i = 0;
    12141263        for (; i < RT_ELEMENTS(g_aCmdMap); i++)
     
    12321281                rc = rc2;
    12331282
     1283            LogFlowFunc(("Command not implemented\n", papszArgs[0]));
    12341284            return rc;
    12351285        }
     
    13711421    Client.hSocket     = hSocket;
    13721422
     1423    LogFlowFunc(("New client connected\n"));
     1424
    13731425    rtFtpServerClientStateReset(&Client.State);
    13741426
    1375     /* Send welcome message. */
    1376     int rc = rtFtpServerSendReplyRc(&Client, RTFTPSERVER_REPLY_READY_FOR_NEW_USER);
     1427    /*
     1428     * Send welcome message.
     1429     * Note: Some clients (like FileZilla / Firefox) expect a message together with the reply code,
     1430     *       so make sure to include at least *something*.
     1431     */
     1432    int rc = rtFtpServerSendReplyRcEx(&Client, RTFTPSERVER_REPLY_READY_FOR_NEW_USER,
     1433                                      "Welcome!");
    13771434    if (RT_SUCCESS(rc))
    13781435    {
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