[PATCH 2/6] ftpd: Remove FTPD_SessionInfo_t::pass member

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Oct 5 13:43:43 UTC 2018


There is no need to keep the password throughout the session.

Update #3530.
---
 cpukit/ftpd/ftpd.c                  | 10 +---------
 testsuites/libtests/ftp01/ftp01.scn | 32 ++++++++++++++++++++++++++++----
 testsuites/libtests/ftp01/init.c    | 25 ++++++++++++++++++++++---
 3 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/cpukit/ftpd/ftpd.c b/cpukit/ftpd/ftpd.c
index ccb2a93410..fb67335c0c 100644
--- a/cpukit/ftpd/ftpd.c
+++ b/cpukit/ftpd/ftpd.c
@@ -265,7 +265,6 @@ typedef struct
   int                 xfer_mode;   /* Transfer mode (ASCII/binary) */
   rtems_id            tid;         /* Task id */
   char                *user;       /* user name (0 if not supplied) */
-  char                *pass;       /* password (0 if not supplied) */
   bool                auth;        /* true if user/pass was valid, false if not or not supplied */
 } FTPD_SessionInfo_t;
 
@@ -1739,8 +1738,6 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
   {
     sscanf(args, "%254s", fname);
     free(info->user);
-    free(info->pass);
-    info->pass = NULL;
     info->user = strdup(fname);
     if (ftpd_config->login &&
       !ftpd_config->login(info->user, NULL)) {
@@ -1753,14 +1750,11 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
   }
   else if (!strcmp("PASS", cmd))
   {
-    sscanf(args, "%254s", fname);
-    free(info->pass);
-    info->pass = strdup(fname);
     if (!info->user) {
       send_reply(info, 332, "Need account to log in");
     } else {
       if (ftpd_config->login &&
-        !ftpd_config->login(info->user, info->pass)) {
+        !ftpd_config->login(info->user, args)) {
         info->auth = false;
         send_reply(info, 530, "Not logged in.");
       } else {
@@ -1951,7 +1945,6 @@ session(rtems_task_argument arg)
     close_data_socket(info);
     close_stream(info);
     free(info->user);
-    free(info->pass);
     task_pool_release(info);
   }
 }
@@ -2038,7 +2031,6 @@ ftpd_daemon(rtems_task_argument args RTEMS_UNUSED)
               htons(ntohs(info->ctrl_addr.sin_port) - 1);
             info->idle = ftpd_timeout;
             info->user = NULL;
-            info->pass = NULL;
             if (ftpd_config->login)
               info->auth = false;
             else
diff --git a/testsuites/libtests/ftp01/ftp01.scn b/testsuites/libtests/ftp01/ftp01.scn
index a27da4b698..c960064450 100644
--- a/testsuites/libtests/ftp01/ftp01.scn
+++ b/testsuites/libtests/ftp01/ftp01.scn
@@ -1,10 +1,17 @@
-*** TEST FTP 1 ***
+*** BEGIN OF TEST FTP 1 ***
+*** TEST VERSION: 5.0.0.b38887ad22e2e28c15b4e248dac72f6eaff8cb13
+*** TEST STATE: EXPECTED-PASS
+*** TEST BUILD: RTEMS_NETWORKING
+*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 9670d7541e0621915e521fe76e7bb33de8cee661, Newlib d13c84eb07e35984bf7a974cd786a6cdac29e6b9)
 syslog: ftpd: FTP daemon started (2 sessions max)
 220 RTEMS FTP server (Version 1.1-JWJ) ready.
+login check (1): user "anonymous"
 USER anonymous
 230 User logged in.
 TYPE I
 200 Type set to I.
+SIZE a.txt
+550 Could not get file size.
 PASV
 227 Entering passive mode (127,0,0,1,4,1).
 STOR a.txt
@@ -13,6 +20,7 @@ STOR a.txt
 QUIT
 221 Goodbye.
 220 RTEMS FTP server (Version 1.1-JWJ) ready.
+login check (1): user "anonymous"
 USER anonymous
 230 User logged in.
 TYPE I
@@ -24,10 +32,16 @@ PASV
 RETR a.txt
 150 Opening BINARY mode data connection.
 220 RTEMS FTP server (Version 1.1-JWJ) ready.
-USER anonymous
+login check (1): user "user"
+USER user
+331 User name okay, need password.
+login check (2): user "user", pass "pass"
+PASS pass
 230 User logged in.
 TYPE I
 200 Type set to I.
+SIZE b.txt
+550 Could not get file size.
 PASV
 227 Entering passive mode (127,0,0,1,4,7).
 STOR b.txt
@@ -39,7 +53,11 @@ QUIT
 QUIT
 221 Goodbye.
 220 RTEMS FTP server (Version 1.1-JWJ) ready.
-USER anonymous
+login check (1): user "user"
+USER user
+331 User name okay, need password.
+login check (2): user "user", pass "pass"
+PASS pass
 230 User logged in.
 TYPE I
 200 Type set to I.
@@ -53,6 +71,7 @@ RETR b.txt
 QUIT
 221 Goodbye.
 220 RTEMS FTP server (Version 1.1-JWJ) ready.
+login check (1): user "anonymous"
 USER anonymous
 230 User logged in.
 TYPE I
@@ -62,7 +81,11 @@ SIZE a.txt
 QUIT
 221 Goodbye.
 220 RTEMS FTP server (Version 1.1-JWJ) ready.
-USER anonymous
+login check (1): user "user"
+USER user
+331 User name okay, need password.
+login check (2): user "user", pass "pass"
+PASS pass
 230 User logged in.
 TYPE I
 200 Type set to I.
@@ -70,4 +93,5 @@ SIZE b.txt
 213 1102
 QUIT
 221 Goodbye.
+
 *** END OF TEST FTP 1 ***
diff --git a/testsuites/libtests/ftp01/init.c b/testsuites/libtests/ftp01/init.c
index 55699a2e16..acbbcbe4ad 100644
--- a/testsuites/libtests/ftp01/init.c
+++ b/testsuites/libtests/ftp01/init.c
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2011, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
- *  Obere Lagerstr. 30
+ *  Dornierstr. 4
  *  82178 Puchheim
  *  Germany
  *  <rtems at embedded-brains.de>
@@ -38,6 +38,24 @@ struct rtems_bsdnet_config rtems_bsdnet_config;
 
 #define FTP_WORKER_TASK_EXTRA_STACK (FTP_WORKER_TASK_COUNT * FTPD_STACKSIZE)
 
+static bool login_check(const char *user, const char *pass)
+{
+  rtems_test_assert(
+    strcmp(user, "anonymous") == 0 || strcmp(user, "user") == 0
+  );
+
+  if (pass != NULL) {
+    rtems_test_assert(
+      strcmp(pass, "anonymous") == 0 || strcmp(pass, "pass") == 0
+    );
+    printf("login check (2): user \"%s\", pass \"%s\"\n", user, pass);
+    return true;
+  } else {
+    printf("login check (1): user \"%s\"\n", user);
+    return strcmp(user, "anonymous") == 0;
+  }
+}
+
 struct rtems_ftpd_configuration rtems_ftpd_configuration = {
   .priority = 90,
   .max_hook_filesize = 0,
@@ -46,6 +64,7 @@ struct rtems_ftpd_configuration rtems_ftpd_configuration = {
   .root = NULL,
   .tasks_count = FTP_WORKER_TASK_COUNT,
   .idle = 0,
+  .login = login_check,
   .access = 0
 };
 
@@ -199,7 +218,7 @@ static void test(void)
 {
   int rv = 0;
   const char file_a [] = "/FTP/127.0.0.1/a.txt";
-  const char file_b [] = "/FTP/127.0.0.1/b.txt";
+  const char file_b [] = "/FTP/user:pass at 127.0.0.1/b.txt";
 
   rv = rtems_bsdnet_initialize_network();
   rtems_test_assert(rv == 0);
-- 
2.16.4




More information about the devel mailing list