On Sat, 2008-08-23 at 05:01 -0400, Alfred M. Szmidt wrote: 
> Tool name: ftpd
> 
>    ftpd/ftpd.c:
> 
>          * Removed getopt () interface
>          * Added argp_* interface
>          * Removed usage ()
> 
> 
> Note that we use GNU ChangLog entries, please check the GNU Coding
> Standards, and the ChangeLog file in inetutils.


        * ftpd/ftpd.c: Include <argp.h>.  Remove include for <getopt.h>.
        (ARGP_PROGRAM_DATA): Call macro.
        (argp, args_doc, doc, argp_options): New variables.
        (parse_opt): New function.
        (usage): Function removed.
        (short_options, long_options): Variables removed.
        (main): Added new variable INDEX. Use argp to parse program
options.

> 
>    +const char AUTH_ARG_DESC[] = "Use AUTH for authentication, it can be:\n"
>    +"\tdefault (passwd authentication)\n"
>    +#ifdef WITH_PAM
>    +"\tpam (using pam 'ftp' module)\n"
>    +#endif
>    +#ifdef WITH_KERBEROS
>    +"\tkerberos\n"
>    +#endif
>    +#ifdef WITH_KERBEROS5
>    +"\tkderberos5\n"
>    +#endif
>    +#ifdef WITH_OPIE
>    +"\topie"
>    +#endif
>    +;
> 
> I find this immensly ugly.  For one, AUTH_ARG_DESC is not a macro, so
> it should not be upper-case.  Secondly, I am guessing that --help will
> look completely messed up.  Something simpler would be more useful,
> just a comma seperated list of the options available.  Or simply not
> listing them at all, they should be documented in the manual.

Agreed. this is an ugly hack. But since I wasn't sure enough to move
them to the manual, I put them that way. BTW, --help looks OK, even
with those '\t'. Anyways, As you mentioned, I think the best place for them, is
the manual. Strangely, the current man page tells an awkward story for
'-a' which doesn't make any sense, at least for what it is
supposed to do.

I've added some more description about it ('-a') in the man page
which describes the argument itself and all the values it can possess.
However, 3 of 5 options are not implemented in the current code.
'Kerberos', 'Kerberos5' and 'Opie' do nothing but falling back to
'passwd' authentication. I also included them in the manual.


Attached:
 * Updated ftpd patch
 * man page patch


PS, Is there any plan too add kerberos support to ftpd ? I mean do you
think it will worth the effort ?


Regards,
Index: ftpd/ftpd.c
===================================================================
RCS file: /sources/inetutils/inetutils/ftpd/ftpd.c,v
retrieving revision 1.63
diff -u -p -r1.63 ftpd.c
--- ftpd/ftpd.c	21 May 2008 04:48:57 -0000	1.63
+++ ftpd/ftpd.c	23 Aug 2008 21:37:57 -0000
@@ -77,7 +77,7 @@ char *alloca ();
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <getopt.h>
+#include <argp.h>
 #include <limits.h>
 #include <netdb.h>
 #include <setjmp.h>
@@ -254,78 +254,116 @@ static void myoob (int);
 static int receive_data (FILE *, FILE *);
 static void send_data (FILE *, FILE *, off_t);
 static void sigquit (int);
-static void usage (int);
 
-static const char *short_options = "Aa:Ddlp:qt:T:u:";
-static struct option long_options[] = {
-  {"anonymous-only", no_argument, 0, 'A'},
-  {"auth", required_argument, 0, 'a'},
-  {"daemon", no_argument, 0, 'D'},
-  {"debug", no_argument, 0, 'd'},
-  {"help", no_argument, 0, '&'},
-  {"logging", no_argument, 0, 'l'},
-  {"pidfile", required_argument, 0, 'p'},
-  {"no-version", no_argument, 0, 'q'},
-  {"timeout", required_argument, 0, 't'},
-  {"max-timeout", required_argument, 0, 'T'},
-  {"umask", required_argument, 0, 'u'},
-  {"version", no_argument, 0, 'V'},
-  {0, 0, 0, 0}
+ARGP_PROGRAM_DATA ("ftpd", "2008", "FIXME unknown");
+
+const char args_doc[] = "";
+const char doc[] = "Internet File Transfer Protocol server.";
+
+static struct argp_option argp_options[] = {
+#define GRP 0
+  {"daemon", 'D', NULL, 0, "Start the ftpd standalone", GRP+1},
+  {"debug", 'd', NULL, 0, "Debug mode", GRP+1},
+  {"auth", 'a', "AUTH", 0, "Use AUTH for authentication", GRP+1},
+  {"anonymous-only", 'A', NULL, 0, "Server configure for anonymous "
+    "service only", GRP+1},
+  {"logging", 'l', NULL, 0, "Increase verbosity of syslog messages", GRP+1},
+  {"pidfile", 'p', "PIDFILE", 0, "Change default location of pidfile", GRP+1},
+  {"no-version", 'q', NULL, 0, "Do not display version in banner", GRP+1},
+  {"timeout", 't', "TIMEOUT", 0, "Set default idle timeout", GRP+1},
+  {"max-timeout", 'T', "TIMEOUT", 0, "Reset maximum value of timeout allowed",
+    GRP+1},
+  {"umask", 'u', "MASK", 0, "Set default umask(base 8)", GRP+1},
+#undef GRP
+  {NULL}
 };
 
-static void
-usage (int err)
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
 {
-  if (err != 0)
-    {
-      fprintf (stderr, "Usage: %s [OPTION] ...\n", program_name);
-      fprintf (stderr, "Try `%s --help' for more information.\n",
-	       program_name);
-    }
-  else
-    {
-      fprintf (stdout, "Usage: %s [OPTION] ...\n", program_name);
-      puts ("Internet File Transfer Protocol server.\n\n\
-  -A, --anonymous-only      Server configure for anonymous service only\n\
-  -D, --daemon              Start the ftpd standalone\n\
-  -d, --debug               Debug mode\n\
-  -l, --logging             Increase verbosity of syslog messages\n\
-  -p, --pidfile=[PIDFILE]   Change default location of pidfile\n\
-  -q, --no-version          Do not display version in banner\n\
-  -t, --timeout=[TIMEOUT]   Set default idle timeout\n\
-  -T, --max-timeout         Reset maximum value of timeout allowed\n\
-  -u, --umask               Set default umask(base 8)\n\
-      --help                Print this message\n\
-  -V, --version             Print version\n\
-  -a, --auth=[AUTH]         Use AUTH for authentication, it can be:\n\
-                               default     passwd authentication.");
+  switch (key)
+  {
+    case 'A':		/* Anonymous ftp only.  */
+      anon_only = 1;
+      break;
+		
+    case 'a':		/* Authentification method.  */
+      if (strcasecmp (arg, "default") == 0)
+	cred.auth_type = AUTH_TYPE_PASSWD;
 #ifdef WITH_PAM
-      puts ("\
-                               pam         using pam 'ftp' module.");
+      else if (strcasecmp (arg, "pam") == 0)
+	cred.auth_type = AUTH_TYPE_PAM;
 #endif
 #ifdef WITH_KERBEROS
-      puts ("\
-                               kerberos");
+      else if (stracasecmp (arg, "kerberos") == 0)
+	cred.auth_type = AUTH_TYPE_KERBEROS;
 #endif
 #ifdef WITH_KERBEROS5
-      puts ("\
-                               kderberos5");
+      else if (stracasecmp (arg, "kerberos5") == 0)
+	cred.auth_type = AUTH_TYPE_KERBEROS5;
 #endif
 #ifdef WITH_OPIE
-      puts ("\
-                               opie");
+      else if (stracasecmp (arg, "opie") == 0)
+	cred.auth_type = AUTH_TYPE_OPIE;
 #endif
+      break;
 
-      fprintf (stdout, "\nSubmit bug reports to %s.\n", PACKAGE_BUGREPORT);
-    }
-  exit (err);
+    case 'D':		/* Run ftpd as daemon.  */
+      daemon_mode = 1;
+      break;
+
+    case 'd':		/* Enable debug mode.  */
+      debug = 1;
+      break;
+
+    case 'l':		/* Increase logging level.  */
+      logging++;		/* > 1 == Extra logging.  */
+      break;
+
+    case 'p':		/* Override pid file */
+      pid_file = arg;
+      break;
+
+    case 'q':		/* Don't include version number in banner.  */
+      no_version = 1;
+      break;
+
+    case 't':		/* Set default timeout value.  */
+      timeout = atoi (arg);
+      if (maxtimeout < timeout)
+	maxtimeout = timeout;
+      break;
+
+    case 'T':		/* Maximum timeout allowed.  */
+      maxtimeout = atoi (arg);
+      if (timeout > maxtimeout)
+	timeout = maxtimeout;
+      break;
+
+    case 'u':		/* Set umask.  */
+      {
+	long val = 0;
+
+	val = strtol (arg, &arg, 8);
+	if (*arg != '\0' || val < 0)
+	  fprintf (stderr, "%s: bad value for -u", state->argv[0]);
+	else
+	  defumask = val;
+	break;
+      }
+
+    default:
+      return ARGP_ERR_UNKNOWN;
+  }
+
+  return 0;
 }
 
+static struct argp argp = {argp_options, parse_opt, args_doc, doc};
+
 int
 main (int argc, char *argv[], char **envp)
 {
-  int option;
-
   program_name = argv[0];
 
 #ifdef HAVE_TZSET
@@ -337,99 +375,8 @@ main (int argc, char *argv[], char **env
   initsetproctitle (argc, argv, envp);
 #endif /* HAVE_INITSETPROCTITLE */
 
-  while ((option = getopt_long (argc, argv, short_options,
-				long_options, NULL)) != EOF)
-    {
-      switch (option)
-	{
-	case 'A':		/* Anonymous ftp only.  */
-	  anon_only = 1;
-	  break;
-
-	case 'a':		/* Authentification method.  */
-	  if (strcasecmp (optarg, "default") == 0)
-	    cred.auth_type = AUTH_TYPE_PASSWD;
-#ifdef WITH_PAM
-	  else if (strcasecmp (optarg, "pam") == 0)
-	    cred.auth_type = AUTH_TYPE_PAM;
-#endif
-#ifdef WITH_KERBEROS
-	  else if (stracasecmp (optarg, "kerberos") == 0)
-	    cred.auth_type = AUTH_TYPE_KERBEROS;
-#endif
-#ifdef WITH_KERBEROS5
-	  else if (stracasecmp (optarg, "kerberos5") == 0)
-	    cred.auth_type = AUTH_TYPE_KERBEROS5;
-#endif
-#ifdef WITH_OPIE
-	  else if (stracasecmp (optarg, "opie") == 0)
-	    cred.auth_type = AUTH_TYPE_OPIE;
-#endif
-	  break;
-
-	case 'D':		/* Run ftpd as daemon.  */
-	  daemon_mode = 1;
-	  break;
-
-	case 'd':		/* Enable debug mode.  */
-	  debug = 1;
-	  break;
-
-	case 'l':		/* Increase logging level.  */
-	  logging++;		/* > 1 == Extra logging.  */
-	  break;
-
-	case 'p':		/* Override pid file */
-	  pid_file = optarg;
-	  break;
-
-	case 'q':		/* Don't include version number in banner.  */
-	  no_version = 1;
-	  break;
-
-	case 't':		/* Set default timeout value.  */
-	  timeout = atoi (optarg);
-	  if (maxtimeout < timeout)
-	    maxtimeout = timeout;
-	  break;
-
-	case 'T':		/* Maximum timeout allowed.  */
-	  maxtimeout = atoi (optarg);
-	  if (timeout > maxtimeout)
-	    timeout = maxtimeout;
-	  break;
-
-	case 'u':		/* Set umask.  */
-	  {
-	    long val = 0;
-
-	    val = strtol (optarg, &optarg, 8);
-	    if (*optarg != '\0' || val < 0)
-	      fprintf (stderr, "%s: bad value for -u", argv[0]);
-	    else
-	      defumask = val;
-	    break;
-	  }
-
-	case '&':		/* Usage.  */
-	  usage (0);
-	  /* Not reached.  */
-
-	case 'V':		/* Version.  */
-	  printf ("ftpd (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
-	  exit (0);
-
-	case '?':
-	default:
-	  usage (1);
-	  /* Not reached.  */
-	}
-    }
-
-  /* Bail out, wrong usage */
-  argc -= optind;
-  if (argc != 0)
-    usage (1);
+  /* Parse command line */
+  argp_parse (&argp, argc, argv, 0, NULL, NULL);
 
   /* LOG_NDELAY sets up the logging connection immediately,
      necessary for anonymous ftp's that chroot and can't do it later.  */
Index: ftpd/ftpd.8
===================================================================
RCS file: /sources/inetutils/inetutils/ftpd/ftpd.8,v
retrieving revision 1.4
diff -u -r1.4 ftpd.8
--- ftpd/ftpd.8	13 Jul 2000 23:19:39 -0000	1.4
+++ ftpd/ftpd.8	23 Aug 2008 21:41:43 -0000
@@ -39,7 +39,7 @@
 .Op Fl dlADq
 .Op Fl T Ar maxtimeout
 .Op Fl t Ar timeout
-.Op Fl a Ar login-name
+.Op Fl a Ar auth-type
 .Sh DESCRIPTION
 .Nm Ftpd
 is the
@@ -84,9 +84,9 @@
 .Ar timeout
 seconds (the default is 15 minutes).
 .It Fl a
-Give anonymous an other 
-.Ar login-name 
-(anonymous and ftpd will still work).
+Specifies which authentication mechanism to use for incoming connections.
+Default mode is UNIX 'passwd'. Other possible values are: kerberos, kerberos5 and Opie.
+Note that anonymous logins will still work with this option being used.
 .El
 .Pp
 The file
_______________________________________________
bug-inetutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-inetutils

Reply via email to