[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] Argpfying rlogind
From: |
Debarshi Ray |
Subject: |
[bug-inetutils] Argpfying rlogind |
Date: |
Tue, 17 Jun 2008 10:07:00 +0530 |
Here (http://rishi.fedorapeople.org/gnu/rlogind-argp.diff and below)
is an initial patch to argpfy rlogind. Since it looks like -D does
actually do anything, and Alfred did not like the idea of debug levels
I have removed the option for the moment. In fact Linux NetKit's
implemention also does not provide the -D option,
diff -urNp inetutils/rlogind/rlogind.c inetutils-build/rlogind/rlogind.c
--- inetutils/rlogind/rlogind.c 2008-06-03 23:52:39.000000000 +0530
+++ inetutils-build/rlogind/rlogind.c 2008-06-17 01:22:04.000000000 +0530
@@ -60,13 +60,13 @@
#include <pwd.h>
#include <syslog.h>
+#include <argp.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
-#include <getopt.h>
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
@@ -154,27 +154,10 @@ struct auth_data
};
#endif
-static const char *short_options = "aD::d::hk::L:lnp:orxV";
-static struct option long_options[] = {
- {"allow-root", no_argument, 0, 'o'},
- {"verify-hostname", no_argument, 0, 'a'},
- {"daemon", optional_argument, 0, 'd'},
- {"no-rhosts", no_argument, 0, 'l'},
- {"no-keepalive", no_argument, 0, 'n'},
- {"local-domain", required_argument, 0, 'L'},
- {"kerberos", optional_argument, 0, 'k'},
- {"encrypt", no_argument, 0, 'x'},
- {"debug", optional_argument, 0, 'D'},
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'V'},
- {"port", required_argument, 0, 'p'},
- {"reverse-required", no_argument, 0, 'r'},
- {0, 0, 0, 0}
-};
-
int allow_root = 0;
int verify_hostname = 0;
int keepalive = 1;
+int port = 0;
#if defined(KERBEROS) || defined(SHISHI)
int kerberos = 0;
@@ -184,8 +167,8 @@ int encrypt_io = 0;
# endif /* ENCRYPTION */
#endif /* KERBEROS */
int reverse_required = 0;
-int debug_level = 0;
+int maxchildren = DEFMAXCHILDREN;
int numchildren;
int netf;
char line[1024]; /* FIXME */
@@ -262,96 +245,121 @@ rlogind_sigchld (int sig)
# define ENC_WRITE(c, fd, buf, size, ap) c = write (fd, buf, size)
#endif
-char *program_name;
+int mode = MODE_INETD;
-int
-main (int argc, char *argv[])
+ARGP_PROGRAM_DATA ("rlogind", "2008", "FIXME unknown");
+
+const char args_doc[] = "";
+const char doc[] = "Remote login server.";
+
+static struct argp_option argp_options[] = {
+#define GRP 0
+ {"allow-root", 'o', NULL, 0, "Allow uid == 0 to login, disable by
default", GRP+1},
+ {"daemon", 'd', "NUM", OPTION_ARG_OPTIONAL, "Daemon mode with NUM
children", GRP+1},
+ {"local-domain", 'L', "NAME", 0, "Set local domain name", GRP+1},
+ {"no-keepalive", 'n', NULL, 0, "Do not set SO_KEEPALIVE", GRP+1},
+ {"no-rhosts", 'l', NULL, 0, "Ignore .rhosts file", GRP+1},
+ {"port", 'p', "PORT", 0, "Listen on port PORT, (valid only in
daemon mode)", GRP+1},
+ {"reverse-required", 'r', NULL, 0, "Require reverse resolving of a
remote host IP", GRP+1},
+ {"verify-hostname", 'a', NULL, 0, "Ask hostname for verification", GRP+1},
+#if defined(KERBEROS) || defined(SHISHI)
+#ifdef ENCRYPTION
+ {"encrypt", 'x', NULL, 0, "Use DES encryption", GRP+1},
+#endif
+ {"kerberos", 'k', "VERSION", OPTION_ARG_OPTIONAL, "Use kerberos
IV/V authentication", GRP+1},
+#endif
+#undef GRP
+ {NULL}
+};
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
{
- int port = 0;
- int maxchildren = DEFMAXCHILDREN;
- int mode = MODE_INETD;
- int c;
-
- program_name = argv[0];
- while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
- != EOF)
- {
- switch (c)
- {
- case 'a':
- verify_hostname = 1;
- break;
-
- case 'D':
- if (optarg)
- debug_level = strtoul (optarg, NULL, 10);
- break;
-
- case 'd':
- mode = MODE_DAEMON;
- if (optarg)
- maxchildren = strtoul (optarg, NULL, 10);
- if (maxchildren == 0)
- maxchildren = DEFMAXCHILDREN;
- break;
-
- case 'l':
- __check_rhosts_file = 0; /* FIXME: extern var? */
- break;
-
- case 'L':
- local_domain_name = optarg;
- break;
-
- case 'n':
- keepalive = 0;
- break;
+ char *endptr;
+
+ switch (key)
+ {
+ case 'o':
+ allow_root = 1;
+ break;
+
+ case 'd':
+ mode = MODE_DAEMON;
+ if (arg)
+ {
+ maxchildren = strtoul (arg, &endptr, 10);
+ if (*endptr)
+ argp_error (state, "invalid value (`%s' near `%s')", arg, endptr);
+ if (maxchildren == 0)
+ maxchildren = DEFMAXCHILDREN;
+ }
+ break;
+
+ case 'L':
+ local_domain_name = arg;
+ break;
+
+ case 'n':
+ keepalive = 0;
+ break;
+
+ case 'l':
+ __check_rhosts_file = 0;
+ break;
+
+ case 'p':
+ port = strtoul (arg, &endptr, 10);
+ if (*endptr)
+ argp_error (state, "invalid value (`%s' near `%s')", arg, endptr);
+ break;
+
+ case 'r':
+ reverse_required = 1;
+ break;
+
+ case 'a':
+ verify_hostname = 1;
+ break;
#if defined(KERBEROS) || defined(SHISHI)
- case 'k':
- if (optarg)
- {
- if (*optarg == '4')
- kerberos = AUTH_KERBEROS_4;
- else if (*optarg == '5')
- kerberos = AUTH_KERBEROS_5;
- }
- else
- kerberos = AUTH_KERBEROS_DEFAULT;
- break;
+#ifdef ENCRYPTION
+ case 'x':
+ encrypt_io = 1;
+ break;
+#endif
-# ifdef ENCRYPTION
- case 'x':
- encrypt_io = 1;
- break;
-# endif /* ENCRYPTION */
-#endif /* KERBEROS */
+ case 'k':
+ if (arg)
+ {
+ if (*arg == '4')
+ kerberos = AUTH_KERBEROS_4;
+ else if (*arg == '5')
+ kerberos = AUTH_KERBEROS_5;
+ }
+ else
+ kerberos = AUTH_KERBEROS_DEFAULT;
+ break;
+#endif
- case 'o':
- allow_root = 1;
- break;
-
- case 'p':
- port = strtoul (optarg, NULL, 10);
- break;
-
- case 'r':
- reverse_required = 1;
- break;
-
- case 'V':
- printf ("rlogind (%s %s)\n", PACKAGE_NAME, PACKAGE_VERSION);
- exit (0);
-
- case 'h':
- default:
- usage ();
- exit (0);
- }
+ default:
+ return ARGP_ERR_UNKNOWN;
}
+ return 0;
+}
+
+static struct argp argp = {argp_options, parse_opt, args_doc, doc};
+
+int
+main (int argc, char *argv[])
+{
+ int index;
+
+ /* Parse command line */
+ argp_parse (&argp, argc, argv, 0, &index, NULL);
+
openlog ("rlogind", LOG_PID | LOG_CONS, LOG_AUTH);
- argc -= optind;
+ argc -= index;
if (argc > 0)
{
syslog (LOG_ERR, "%d extra arguments", argc);
@@ -1518,31 +1526,3 @@ fatal (int f, const char *msg, int syser
write (f, buf, bp + len - buf);
exit (1);
}
-
-static const char usage_str[] =
- "usage: rlogind [options]\n"
- "\n"
- "Options are:\n"
- " -a, --verify-hostname Ask hostname for verification\n"
- " -d, --daemon Daemon mode\n"
- " -l, --no-rhosts Ignore .rhosts file\n"
- " -L, --local-domain=NAME Set local domain name\n"
- " -n, --no-keepalive Do not set SO_KEEPALIVE\n"
-#if defined(KERBEROS) || defined(SHISHI)
- " -k, --kerberos Use kerberos IV/V authentication\n"
-# ifdef ENCRYPTION
- " -x, --encrypt Use DES encryption\n"
-# endif /* ENCRYPTION */
-#endif /* KERBEROS */
- " -D, --debug[=LEVEL] Set debug level\n"
- " -h, --help Display usage instructions\n"
- " -V, --version Display program version\n"
- " -o, --allow-root Allow uid == 0 to login, disable by default\n"
- " -p, --port PORT Listen on given port (valid only in
daemon mode)\n"
- " -r, --reverse-required Require reverse resolving of a remote host IP\n";
-
-void
-usage ()
-{
- printf ("%s\n" "Send bug reports to %s\n", usage_str, PACKAGE_BUGREPORT);
-}
This just manages to compile, and I have not tested it much. Moreover
I am not very familiar with how the rlogind daemon is supposed to
work. So please shout if something is wrong.
Happy hacking,
Debarshi
- [bug-inetutils] Argpfying rlogind,
Debarshi Ray <=