Changeset 82699 in vbox for trunk/src/VBox/Runtime/generic
- Timestamp:
- Jan 9, 2020 2:43:25 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 135618
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/generic/ftp-server.cpp
r82698 r82699 189 189 * Function prototypes for command handlers. 190 190 */ 191 static FNRTFTPSERVERCMD rtF TPServerHandleABOR;192 static FNRTFTPSERVERCMD rtF TPServerHandleCDUP;193 static FNRTFTPSERVERCMD rtF TPServerHandleCWD;194 static FNRTFTPSERVERCMD rtF TPServerHandleLIST;195 static FNRTFTPSERVERCMD rtF TPServerHandleMODE;196 static FNRTFTPSERVERCMD rtF TPServerHandleNOOP;197 static FNRTFTPSERVERCMD rtF TPServerHandlePORT;198 static FNRTFTPSERVERCMD rtF TPServerHandlePWD;199 static FNRTFTPSERVERCMD rtF TPServerHandleQUIT;200 static FNRTFTPSERVERCMD rtF TPServerHandleRETR;201 static FNRTFTPSERVERCMD rtF TPServerHandleRGET;202 static FNRTFTPSERVERCMD rtF TPServerHandleSTAT;203 static FNRTFTPSERVERCMD rtF TPServerHandleSYST;204 static FNRTFTPSERVERCMD rtF TPServerHandleTYPE;191 static FNRTFTPSERVERCMD rtFtpServerHandleABOR; 192 static FNRTFTPSERVERCMD rtFtpServerHandleCDUP; 193 static FNRTFTPSERVERCMD rtFtpServerHandleCWD; 194 static FNRTFTPSERVERCMD rtFtpServerHandleLIST; 195 static FNRTFTPSERVERCMD rtFtpServerHandleMODE; 196 static FNRTFTPSERVERCMD rtFtpServerHandleNOOP; 197 static FNRTFTPSERVERCMD rtFtpServerHandlePORT; 198 static FNRTFTPSERVERCMD rtFtpServerHandlePWD; 199 static FNRTFTPSERVERCMD rtFtpServerHandleQUIT; 200 static FNRTFTPSERVERCMD rtFtpServerHandleRETR; 201 static FNRTFTPSERVERCMD rtFtpServerHandleRGET; 202 static FNRTFTPSERVERCMD rtFtpServerHandleSTAT; 203 static FNRTFTPSERVERCMD rtFtpServerHandleSYST; 204 static FNRTFTPSERVERCMD rtFtpServerHandleTYPE; 205 205 206 206 /** … … 222 222 const RTFTPSERVER_CMD_ENTRY g_aCmdMap[] = 223 223 { 224 { RTFTPSERVER_CMD_ABOR, "ABOR", rtF TPServerHandleABOR },225 { RTFTPSERVER_CMD_CDUP, "CDUP", rtF TPServerHandleCDUP },226 { RTFTPSERVER_CMD_CWD, "CWD", rtF TPServerHandleCWD },227 { RTFTPSERVER_CMD_LIST, "LIST", rtF TPServerHandleLIST },228 { RTFTPSERVER_CMD_MODE, "MODE", rtF TPServerHandleMODE },229 { RTFTPSERVER_CMD_NOOP, "NOOP", rtF TPServerHandleNOOP },230 { RTFTPSERVER_CMD_PORT, "PORT", rtF TPServerHandlePORT },231 { RTFTPSERVER_CMD_PWD, "PWD", rtF TPServerHandlePWD },232 { RTFTPSERVER_CMD_QUIT, "QUIT", rtF TPServerHandleQUIT },233 { RTFTPSERVER_CMD_RETR, "RETR", rtF TPServerHandleRETR },234 { RTFTPSERVER_CMD_RGET, "RGET", rtF TPServerHandleRGET },235 { RTFTPSERVER_CMD_STAT, "STAT", rtF TPServerHandleSTAT },236 { RTFTPSERVER_CMD_SYST, "SYST", rtF TPServerHandleSYST },237 { RTFTPSERVER_CMD_TYPE, "TYPE", rtF TPServerHandleTYPE },224 { RTFTPSERVER_CMD_ABOR, "ABOR", rtFtpServerHandleABOR }, 225 { RTFTPSERVER_CMD_CDUP, "CDUP", rtFtpServerHandleCDUP }, 226 { RTFTPSERVER_CMD_CWD, "CWD", rtFtpServerHandleCWD }, 227 { RTFTPSERVER_CMD_LIST, "LIST", rtFtpServerHandleLIST }, 228 { RTFTPSERVER_CMD_MODE, "MODE", rtFtpServerHandleMODE }, 229 { RTFTPSERVER_CMD_NOOP, "NOOP", rtFtpServerHandleNOOP }, 230 { RTFTPSERVER_CMD_PORT, "PORT", rtFtpServerHandlePORT }, 231 { RTFTPSERVER_CMD_PWD, "PWD", rtFtpServerHandlePWD }, 232 { RTFTPSERVER_CMD_QUIT, "QUIT", rtFtpServerHandleQUIT }, 233 { RTFTPSERVER_CMD_RETR, "RETR", rtFtpServerHandleRETR }, 234 { RTFTPSERVER_CMD_RGET, "RGET", rtFtpServerHandleRGET }, 235 { RTFTPSERVER_CMD_STAT, "STAT", rtFtpServerHandleSTAT }, 236 { RTFTPSERVER_CMD_SYST, "SYST", rtFtpServerHandleSYST }, 237 { RTFTPSERVER_CMD_TYPE, "TYPE", rtFtpServerHandleTYPE }, 238 238 { RTFTPSERVER_CMD_LAST, "", NULL } 239 239 }; … … 251 251 * @param enmReply Reply code to send. 252 252 */ 253 static int rtF TPServerSendReplyRc(PRTFTPSERVERCLIENT pClient, RTFTPSERVER_REPLY enmReply)253 static int rtFtpServerSendReplyRc(PRTFTPSERVERCLIENT pClient, RTFTPSERVER_REPLY enmReply) 254 254 { 255 255 char szReply[32]; … … 266 266 * @param pcszStr String to reply. 267 267 */ 268 static int rtF TPServerSendReplyStr(PRTFTPSERVERCLIENT pClient, const char *pcszStr)268 static int rtFtpServerSendReplyStr(PRTFTPSERVERCLIENT pClient, const char *pcszStr) 269 269 { 270 270 char *pszReply; … … 287 287 * @param pcszUser User name to look up. 288 288 */ 289 static int rtF TPServerLookupUser(PRTFTPSERVERCLIENT pClient, const char *pcszUser)289 static int rtFtpServerLookupUser(PRTFTPSERVERCLIENT pClient, const char *pcszUser) 290 290 { 291 291 RTFTPSERVER_HANDLE_CALLBACK_VA_RET(pfnOnUserConnect, pcszUser); … … 302 302 * @param pcszPassword Password to authenticate with. 303 303 */ 304 static int rtF TPServerAuthenticate(PRTFTPSERVERCLIENT pClient, const char *pcszUser, const char *pcszPassword)304 static int rtFtpServerAuthenticate(PRTFTPSERVERCLIENT pClient, const char *pcszUser, const char *pcszPassword) 305 305 { 306 306 RTFTPSERVER_HANDLE_CALLBACK_VA_RET(pfnOnUserAuthenticate, pcszUser, pcszPassword); … … 314 314 *********************************************************************************************************************************/ 315 315 316 static int rtF TPServerHandleABOR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)317 { 318 RT_NOREF(pClient, cArgs, apcszArgs); 319 320 /** @todo Anything to do here? */ 321 return VINF_SUCCESS; 322 } 323 324 static int rtF TPServerHandleCDUP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)325 { 326 RT_NOREF(pClient, cArgs, apcszArgs); 327 328 /** @todo Anything to do here? */ 329 return VINF_SUCCESS; 330 } 331 332 static int rtF TPServerHandleCWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)316 static int rtFtpServerHandleABOR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 317 { 318 RT_NOREF(pClient, cArgs, apcszArgs); 319 320 /** @todo Anything to do here? */ 321 return VINF_SUCCESS; 322 } 323 324 static int rtFtpServerHandleCDUP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 325 { 326 RT_NOREF(pClient, cArgs, apcszArgs); 327 328 /** @todo Anything to do here? */ 329 return VINF_SUCCESS; 330 } 331 332 static int rtFtpServerHandleCWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 333 333 { 334 334 AssertPtrReturn(apcszArgs, VERR_INVALID_POINTER); … … 342 342 } 343 343 344 static int rtF TPServerHandleLIST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)344 static int rtFtpServerHandleLIST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 345 345 { 346 346 RT_NOREF(cArgs, apcszArgs); … … 354 354 } 355 355 356 static int rtF TPServerHandleMODE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)357 { 358 RT_NOREF(pClient, cArgs, apcszArgs); 359 360 /** @todo Anything to do here? */ 361 return VINF_SUCCESS; 362 } 363 364 static int rtF TPServerHandleNOOP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)356 static int rtFtpServerHandleMODE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 357 { 358 RT_NOREF(pClient, cArgs, apcszArgs); 359 360 /** @todo Anything to do here? */ 361 return VINF_SUCCESS; 362 } 363 364 static int rtFtpServerHandleNOOP(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 365 365 { 366 366 RT_NOREF(pClient, cArgs, apcszArgs); … … 370 370 } 371 371 372 static int rtF TPServerHandlePORT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)373 { 374 RT_NOREF(pClient, cArgs, apcszArgs); 375 376 /** @todo Anything to do here? */ 377 return VINF_SUCCESS; 378 } 379 380 static int rtF TPServerHandlePWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)372 static int rtFtpServerHandlePORT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 373 { 374 RT_NOREF(pClient, cArgs, apcszArgs); 375 376 /** @todo Anything to do here? */ 377 return VINF_SUCCESS; 378 } 379 380 static int rtFtpServerHandlePWD(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 381 381 { 382 382 RT_NOREF(cArgs, apcszArgs); … … 399 399 } 400 400 401 static int rtF TPServerHandleQUIT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)402 { 403 RT_NOREF(pClient, cArgs, apcszArgs); 404 405 /** @todo Anything to do here? */ 406 return VINF_SUCCESS; 407 } 408 409 static int rtF TPServerHandleRETR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)410 { 411 RT_NOREF(pClient, cArgs, apcszArgs); 412 413 /** @todo Anything to do here? */ 414 return VINF_SUCCESS; 415 } 416 417 static int rtF TPServerHandleRGET(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)418 { 419 RT_NOREF(pClient, cArgs, apcszArgs); 420 421 /** @todo Anything to do here? */ 422 return VINF_SUCCESS; 423 } 424 425 static int rtF TPServerHandleSTAT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)426 { 427 RT_NOREF(pClient, cArgs, apcszArgs); 428 429 /** @todo Anything to do here? */ 430 return VINF_SUCCESS; 431 } 432 433 static int rtF TPServerHandleSYST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)401 static int rtFtpServerHandleQUIT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 402 { 403 RT_NOREF(pClient, cArgs, apcszArgs); 404 405 /** @todo Anything to do here? */ 406 return VINF_SUCCESS; 407 } 408 409 static int rtFtpServerHandleRETR(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 410 { 411 RT_NOREF(pClient, cArgs, apcszArgs); 412 413 /** @todo Anything to do here? */ 414 return VINF_SUCCESS; 415 } 416 417 static int rtFtpServerHandleRGET(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 418 { 419 RT_NOREF(pClient, cArgs, apcszArgs); 420 421 /** @todo Anything to do here? */ 422 return VINF_SUCCESS; 423 } 424 425 static int rtFtpServerHandleSTAT(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 426 { 427 RT_NOREF(pClient, cArgs, apcszArgs); 428 429 /** @todo Anything to do here? */ 430 return VINF_SUCCESS; 431 } 432 433 static int rtFtpServerHandleSYST(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 434 434 { 435 435 RT_NOREF(cArgs, apcszArgs); … … 438 438 int rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szOSInfo, sizeof(szOSInfo)); 439 439 if (RT_SUCCESS(rc)) 440 rc = rtF TPServerSendReplyStr(pClient, szOSInfo);440 rc = rtFtpServerSendReplyStr(pClient, szOSInfo); 441 441 442 442 return rc; 443 443 } 444 444 445 static int rtF TPServerHandleTYPE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs)445 static int rtFtpServerHandleTYPE(PRTFTPSERVERCLIENT pClient, uint8_t cArgs, const char * const *apcszArgs) 446 446 { 447 447 RT_NOREF(pClient, cArgs, apcszArgs); … … 462 462 * @param pClient Client to handle login procedure for. 463 463 */ 464 static int rtF TPServerDoLogin(PRTFTPSERVERCLIENT pClient)464 static int rtFtpServerDoLogin(PRTFTPSERVERCLIENT pClient) 465 465 { 466 466 LogFlowFuncEnter(); 467 467 468 468 /* Send welcome message. */ 469 int rc = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_READY_FOR_NEW_USER);469 int rc = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_READY_FOR_NEW_USER); 470 470 if (RT_SUCCESS(rc)) 471 471 { … … 476 476 if (RT_SUCCESS(rc)) 477 477 { 478 rc = rtF TPServerLookupUser(pClient, szUser);478 rc = rtFtpServerLookupUser(pClient, szUser); 479 479 if (RT_SUCCESS(rc)) 480 480 { 481 rc = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_USERNAME_OKAY_NEED_PASSWORD);481 rc = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_USERNAME_OKAY_NEED_PASSWORD); 482 482 if (RT_SUCCESS(rc)) 483 483 { … … 487 487 if (RT_SUCCESS(rc)) 488 488 { 489 rc = rtF TPServerAuthenticate(pClient, szUser, szPass);489 rc = rtFtpServerAuthenticate(pClient, szUser, szPass); 490 490 if (RT_SUCCESS(rc)) 491 491 { 492 rc = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_LOGGED_IN_PROCEED);492 rc = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_LOGGED_IN_PROCEED); 493 493 } 494 494 } … … 501 501 if (RT_FAILURE(rc)) 502 502 { 503 int rc2 = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_NOT_LOGGED_IN);503 int rc2 = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_NOT_LOGGED_IN); 504 504 if (RT_SUCCESS(rc)) 505 505 rc = rc2; … … 515 515 * @param pcszCmdParms Pointer to command arguments, if any. Can be NULL if no arguments are given. 516 516 * @param pcArgs Returns the number of parsed arguments, separated by a space (hex 0x20). 517 * @param ppapcszArgs Returns the string array of parsed arguments. Needs to be free'd with rtF TPServerCmdArgsFree().518 */ 519 static int rtF TPServerCmdArgsParse(const char *pcszCmdParms, uint8_t *pcArgs, char ***ppapcszArgs)517 * @param ppapcszArgs Returns the string array of parsed arguments. Needs to be free'd with rtFtpServerCmdArgsFree(). 518 */ 519 static int rtFtpServerCmdArgsParse(const char *pcszCmdParms, uint8_t *pcArgs, char ***ppapcszArgs) 520 520 { 521 521 *pcArgs = 0; … … 544 544 545 545 /** 546 * Frees a formerly argument string array parsed by rtF TPServerCmdArgsParse().546 * Frees a formerly argument string array parsed by rtFtpServerCmdArgsParse(). 547 547 * 548 548 * @param ppapcszArgs Argument string array to free. 549 549 */ 550 static void rtF TPServerCmdArgsFree(char **ppapcszArgs)550 static void rtFtpServerCmdArgsFree(char **ppapcszArgs) 551 551 { 552 552 RTGetOptArgvFree(ppapcszArgs); … … 559 559 * @param pClient Client to process commands for. 560 560 */ 561 static int rtF TPServerProcessCommands(PRTFTPSERVERCLIENT pClient)561 static int rtFtpServerProcessCommands(PRTFTPSERVERCLIENT pClient) 562 562 { 563 563 int rc; … … 589 589 uint8_t cArgs = 0; 590 590 char **papszArgs = NULL; 591 rc = rtF TPServerCmdArgsParse(pszCmdParms, &cArgs, &papszArgs);591 rc = rtFtpServerCmdArgsParse(pszCmdParms, &cArgs, &papszArgs); 592 592 if (RT_SUCCESS(rc)) 593 593 { … … 605 605 } 606 606 607 rtF TPServerCmdArgsFree(papszArgs);607 rtFtpServerCmdArgsFree(papszArgs); 608 608 609 609 if (i == RT_ELEMENTS(g_aCmdMap)) 610 610 { 611 int rc2 = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_CMD_NOT_IMPL);611 int rc2 = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_CMD_NOT_IMPL); 612 612 if (RT_SUCCESS(rc)) 613 613 rc = rc2; … … 622 622 else 623 623 { 624 int rc2 = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_INVALID_PARAMETERS);624 int rc2 = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_INVALID_PARAMETERS); 625 625 if (RT_SUCCESS(rc)) 626 626 rc = rc2; … … 629 629 else 630 630 { 631 int rc2 = rtF TPServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_CMD_NOT_RECOGNIZED);631 int rc2 = rtFtpServerSendReplyRc(pClient, RTFTPSERVER_REPLY_ERROR_CMD_NOT_RECOGNIZED); 632 632 if (RT_SUCCESS(rc)) 633 633 rc = rc2; … … 643 643 * @param pState Client state to reset. 644 644 */ 645 static void rtF TPServerClientStateReset(PRTFTPSERVERCLIENTSTATE pState)645 static void rtFtpServerClientStateReset(PRTFTPSERVERCLIENTSTATE pState) 646 646 { 647 647 pState->tsLastCmdMs = RTTimeMilliTS(); … … 655 655 * @param pvUser User-provided arguments. Of type PRTFTPSERVERINTERNAL. 656 656 */ 657 static DECLCALLBACK(int) rtF TPServerClientThread(RTSOCKET hSocket, void *pvUser)657 static DECLCALLBACK(int) rtFtpServerClientThread(RTSOCKET hSocket, void *pvUser) 658 658 { 659 659 PRTFTPSERVERINTERNAL pThis = (PRTFTPSERVERINTERNAL)pvUser; … … 666 666 Client.hSocket = hSocket; 667 667 668 rtF TPServerClientStateReset(&Client.State);669 670 int rc = rtF TPServerDoLogin(&Client);668 rtFtpServerClientStateReset(&Client.State); 669 670 int rc = rtFtpServerDoLogin(&Client); 671 671 if (RT_SUCCESS(rc)) 672 672 { 673 673 ASMAtomicIncU32(&pThis->cClients); 674 674 675 rc = rtF TPServerProcessCommands(&Client);675 rc = rtFtpServerProcessCommands(&Client); 676 676 677 677 ASMAtomicDecU32(&pThis->cClients); … … 681 681 } 682 682 683 RTR3DECL(int) RTF TPServerCreate(PRTFTPSERVER phFTPServer, const char *pcszAddress, uint16_t uPort,683 RTR3DECL(int) RTFtpServerCreate(PRTFTPSERVER phFTPServer, const char *pcszAddress, uint16_t uPort, 684 684 PRTFTPSERVERCALLBACKS pCallbacks) 685 685 { … … 698 698 699 699 rc = RTTcpServerCreate(pcszAddress, uPort, RTTHREADTYPE_DEFAULT, "ftpsrv", 700 rtF TPServerClientThread, pThis /* pvUser */, &pThis->pTCPServer);700 rtFtpServerClientThread, pThis /* pvUser */, &pThis->pTCPServer); 701 701 } 702 702 else … … 706 706 } 707 707 708 RTR3DECL(int) RTF TPServerDestroy(RTFTPSERVER hFTPServer)708 RTR3DECL(int) RTFtpServerDestroy(RTFTPSERVER hFTPServer) 709 709 { 710 710 if (hFTPServer == NIL_RTFTPSERVER)
Note:
See TracChangeset
for help on using the changeset viewer.