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 #include #include -#include +#include #include #include #include @@ -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. */