bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-inetutils] [PATCH] ftpd


From: oli
Subject: Re: [bug-inetutils] [PATCH] ftpd
Date: Mon, 12 Oct 2009 21:25:33 +1100

Hi,

Patch contains modifications as suggested.

diff --git a/ChangeLog b/ChangeLog
index 325f5ef..4df07a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+
+2009-10-10  Oliver Naylor <address@hidden>
+       
+       * ftpd/ftpd.c (argp_options, parse_opt): New option: --port, specify
+       port for ftpd to listen on.
+       (MIN_PORT): New Define.
+       (MAX_PORT): New Define.
+       * ftpd/server_mode.c (server_mode): Removed variable port.
+       Added new argument port.
+       * doc/inetutils.texi (ftpd invocation): Updated.
+               
 2009-10-06  Rakesh Pandit  <address@hidden>

        * ping/ping_common.h (ping_data): New member `ping_start_time'.
diff --git a/NEWS b/NEWS
index 30beda0..6b755c7 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,10 @@ Please send inetutils bug reports to <address@hidden>.
 Unreleased
 Version 1.7:

+* ftpd
+
+New option --port=PORT, listen for connections on port PORT
+
 * ping

 New option --timeout=N, stop sending packets after N seconds.
diff --git a/doc/.gitignore b/doc/.gitignore
index a5ee19f..24c6478 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -1,6 +1,6 @@
-inetutils.info*
 Makefile
 Makefile.in
 fdl-1.3.texi
+inetutils.info*
 stamp-vti
 version.texi
diff --git a/doc/inetutils.texi b/doc/inetutils.texi
index aba0c28..0ebef97 100644
--- a/doc/inetutils.texi
+++ b/doc/inetutils.texi
@@ -2582,6 +2582,12 @@ is 15 minutes).
 @opindex -u
 @opindex --umask
 Set default umask(base 8).
+
address@hidden -P @var{port}
address@hidden address@hidden
address@hidden -p
address@hidden --port
+Set the TCP port on which ftpd will listen when running in daemon mode.
 @end table

 The file @file{/etc/nologin} can be used to disable ftp access.  If
diff --git a/ftpd/extern.h b/ftpd/extern.h
index ce1ac8c..f116524 100644
--- a/ftpd/extern.h
+++ b/ftpd/extern.h
@@ -112,7 +112,7 @@ extern char tmpline[];
 extern off_t restart_point;

 /* Exported from server_mode.c.  */
-extern int server_mode (const char *pidfile, struct sockaddr_in *phis_addr);
+extern int server_mode (const char *pidfile, int port, struct
sockaddr_in *phis_addr);

 /* Credential for the request.  */
 struct credentials
diff --git a/ftpd/ftpd.c b/ftpd/ftpd.c
index 8a951cf..04c0e9c 100644
--- a/ftpd/ftpd.c
+++ b/ftpd/ftpd.c
@@ -1,4 +1,5 @@
-/* - Ftp Server
+
+ /* - Ftp Server
  * Copyright (c) 1985, 1988, 1990, 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -166,6 +167,15 @@ static off_t file_size;
 static off_t byte_count;
 static sig_atomic_t transflag; /* Flag where in a middle of transfer.  */
 static const char *pid_file = PATH_FTPDPID;
+
+/* Listen for connections on port (--port);
+   -1 means use default tcp/ftp port */
+static int port = -1;
+
+/* TCP port range */
+#define PORT_MIN 0
+#define PORT_MAX 65535
+
 #if !defined(CMASK) || CMASK == 0
 # undef CMASK
 # define CMASK 027
@@ -294,6 +304,9 @@ static struct argp_option options[] = {
   { "  default", 0, NULL, OPTION_DOC|OPTION_NO_TRANS,
     "passwd authentication",
     GRID+3 },
+  { "port", 'P', "PORT", 0,
+    "listen for connections on port PORT",
+    GRID+1 },
 #ifdef WITH_PAM
   { "  pam", 0, NULL, OPTION_DOC|OPTION_NO_TRANS,
     "using pam 'ftp' module",
@@ -335,7 +348,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
        cred.auth_type = AUTH_TYPE_PAM;
 #endif
 #ifdef WITH_KERBEROS
-      else if (strcasecmp (arg, "kerberos") == 0)
+     else if (strcasecmp (arg, "kerberos") == 0)
        cred.auth_type = AUTH_TYPE_KERBEROS;
 #endif
 #ifdef WITH_KERBEROS5
@@ -397,6 +410,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
          defumask = val;
        break;
       }
+
+    case 'P': /* Set port */
+      {
+        port = strtol (arg, &arg, 0);
+        if (port < PORT_MIN || port > PORT_MAX)
+          argp_error (state, "bad port %d", port);
+        break;
+      }

     default:
       return ARGP_ERR_UNKNOWN;
@@ -450,7 +471,7 @@ main (int argc, char *argv[], char **envp)
      fd = accept(). tcpd is check if compile with the support  */
   if (daemon_mode)
     {
-      if (server_mode (pid_file, &his_addr) < 0)
+      if (server_mode (pid_file, port, &his_addr) < 0)
        exit (1);
     }
   else
diff --git a/ftpd/server_mode.c b/ftpd/server_mode.c
index bc122dc..0a3e5b9 100644
--- a/ftpd/server_mode.c
+++ b/ftpd/server_mode.c
@@ -75,11 +75,10 @@ reapchild (int signo ARG_UNUSED)
 }

 int
-server_mode (const char *pidfile, struct sockaddr_in *phis_addr)
+server_mode (const char *pidfile, int port, struct sockaddr_in *phis_addr)
 {
   int ctl_sock, fd;
-  struct servent *sv;
-  int port;
+  struct servent *sv = NULL;
   static struct sockaddr_in server_addr;       /* Our address.  */

   /* Become a daemon.  */
@@ -90,9 +89,19 @@ server_mode (const char *pidfile, struct
sockaddr_in *phis_addr)
     }
   signal (SIGCHLD, reapchild);

-  /* Get port for ftp/tcp.  */
-  sv = getservbyname ("ftp", "tcp");
-  port = (sv == NULL) ? DEFPORT : ntohs (sv->s_port);
+
+  memset (&server_addr, 0, sizeof server_addr);
+  server_addr.sin_family = AF_INET;
+
+  /* If a port was not specified on the command line use the default
+     ftp/tcp port. */
+  if (port == -1)
+    {
+      sv = getservbyname ("ftp", "tcp");
+      port = (sv == NULL) ? DEFPORT : ntohs (sv->s_port);
+    }
+
+  server_addr.sin_port = htons (port);

   /* Open socket, bind and start listen.  */
   ctl_sock = socket (AF_INET, SOCK_STREAM, 0);
@@ -110,10 +119,6 @@ server_mode (const char *pidfile, struct
sockaddr_in *phis_addr)
       syslog (LOG_ERR, "control setsockopt: %m");
   }

-  memset (&server_addr, 0, sizeof server_addr);
-  server_addr.sin_family = AF_INET;
-  server_addr.sin_port = htons (port);
-
   if (bind (ctl_sock, (struct sockaddr *) &server_addr, sizeof server_addr))
     {
       syslog (LOG_ERR, "control bind: %m");
diff --git a/lib/.gitignore b/lib/.gitignore
index f9d57b1..2e7dfdd 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -23,9 +23,9 @@ basename.c
 btowc.c
 canonicalize-lgpl.c
 canonicalize.h
+charset.alias
 chdir-long.c
 chdir-long.h
-charset.alias
 chown.c
 close-hook.c
 close-hook.h
@@ -56,6 +56,7 @@ fcntl-safer.h
 fcntl.h
 fcntl.in.h
 fd-safer.c
+fdopendir.c
 filemode.c
 filemode.h
 float+.h
@@ -66,6 +67,7 @@ fnmatch.h
 fnmatch.in.h
 fnmatch_loop.c
 fopen-safer.c
+fopen.c
 fseeko.c
 fstatat.c
 getcwd.c
@@ -111,6 +113,7 @@ memchr.valgrind
 mempcpy.c
 memrchr.c
 minmax.h
+mkdir.c
 mkdirat.c
 obstack.c
 obstack.h
@@ -151,6 +154,7 @@ regex.h
 regex_internal.c
 regex_internal.h
 regexec.c
+rmdir.c
 same-inode.h
 save-cwd.c
 save-cwd.h
@@ -161,6 +165,7 @@ sleep.c
 snprintf.c
 sockets.c
 sockets.h
+stat.c
 stdarg.h
 stdarg.in.h
 stdbool.h
@@ -210,6 +215,8 @@ unistd--.h
 unistd-safer.h
 unistd.h
 unistd.in.h
+unlink.c
+unlinkat.c
 unlocked-io.h
 vasnprintf.c
 vasnprintf.h


On Sat, Oct 10, 2009 at 11:56 PM, Alfred M. Szmidt <address@hidden> wrote:
> Please reply to the list.
>
>   Thank you for your feedback. I should point out that it is Richard
>   Stallman's vision that I believe in not Eric Raymond's. I will be more
>   careful in the future with the terminology that I use :-)
>
> It is more useful to believe in freedom than in someones vision, since
> a persons vision can change, but freedom does not.
>
>   I have made most of the changes that you suggested and will supply
>   a new patch shortly.
>
> Thank you!
>
>   The reason that I passed in port as a separate argument to server_mode
>   is because phis->sin_port is used for the data port. The command port
>   is set via server_addr.sin_port.
>
> I do not follow...  I wasn't referring to sin_port, but to the usage
> of "port = port_no;" in server_mode, which is redundant.
>
>   Do we want to allow a user to specify 0 as a port number? I realise
>   this will cause the port to be generated dynamically. Not sure
>   about other FTP servers but I do not think the Solaris in.ftpd
>   allows you to use 0.
>
> Could you check?  I have no preference if we accept 0 or not, but it
> is a valid port number.
>



-- 
oli

"During times of universal deceit, telling the truth becomes a
revolutionary act."
- George Orwell




reply via email to

[Prev in Thread] Current Thread [Next in Thread]