On Sat, 2008-08-23 at 05:14 -0400, Alfred M. Szmidt wrote:
> + /* FIXME: Argument name and argument description doesn't match */
> + /* XXX: Changed required_argument to no_argument, since there
> + * is not any use for it's argument value in current code. */
> + {"log-sessions", 'L', NULL, 0, "Set local domain name", GRP+1},
>
> Do we have a better name for this switch? We could mark
> --log-sessions as deprected, and use something more sensible.
I think argument name is OK. This option is supposed to log session
activity. The one to blame here is the description. I've changed the
description to something more meaningful.
>
> +#if defined(KERBEROS) || defined(SHISHI)
> + {"kerberos", 'k', NULL, 0, "Use kerberos IV authentication", GRP+1},
> + {"vacuous", 'v', NULL, OPT_HIDDEN, NULL, GRP+1},
> +# ifdef ENCRYPTION
> + {"encryption", 'x', NULL, 0, "Use DES encryption", GRP+1},
> +# endif
> +#endif
>
> Same here, warn the user that those specific switches are not
> avaiable, but don't say that they do not exist when they do...
>
Done.
* rshd/rshd.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.
(help, usage): Functions removed.
(short_options, long_options): Variables removed.
(main): Added new variable INDEX. Use argp to parse program
options.
Updated patch is attached.
Index: rshd/rshd.c
===================================================================
RCS file: /sources/inetutils/inetutils/rshd/rshd.c,v
retrieving revision 1.35
diff -u -p -r1.35 rshd.c
--- rshd/rshd.c 4 Jun 2007 17:27:02 -0000 1.35
+++ rshd/rshd.c 25 Aug 2008 08:52:52 -0000
@@ -92,7 +92,7 @@ char *alloca ();
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <getopt.h>
+#include <argp.h>
#include <grp.h>
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
@@ -110,8 +110,6 @@ void rshd_error (const char *, ...);
char *getstr (const char *);
int local_domain (const char *);
const char *topdomain (const char *);
-void usage (void);
-void help (void);
#if defined(KERBEROS) || defined(SHISHI)
# ifdef KERBEROS
@@ -132,94 +130,107 @@ int protocol;
# endif
# define VERSION_SIZE 9
# define SECURE_MESSAGE "This rsh session is using DES encryption for all transmissions.\r\n"
-# define OPTIONS "alnkvxLVh"
int doencrypt, use_kerberos, vacuous;
-#else
-# define OPTIONS "alnLVh"
#endif
-static const char *short_options = OPTIONS;
-static struct option long_options[] = {
- {"verify-hostname", no_argument, 0, 'a'},
- {"no-rhosts", no_argument, 0, 'l'},
- {"no-keepalive", no_argument, 0, 'n'},
- {"log-sessions", required_argument, 0, 'L'},
- {"kerberos", no_argument, 0, 'k'},
- {"vacuous", no_argument, 0, 'v'},
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'V'},
- {0, 0, 0, 0}
+char *program_name;
+extern int __check_rhosts_file; /* hook in rcmd(3) */
+
+ARGP_PROGRAM_DATA ("rshd", "2008", "FIXME unknown");
+
+const char args_doc[] = "";
+const char doc[] = "Remote shell server.";
+
+static struct argp_option argp_options[] = {
+#define GRP 0
+ {"verify-hostname", 'a', NULL, 0, "Ask hostname for verification", GRP+1},
+ {"no-rhosts", 'l', NULL, 0, "Ignore .rhosts file", GRP+1},
+ {"no-keepalive", 'n', NULL, 0, "Do not set SO_KEEPALIVE", GRP+1},
+ {"log-sessions", 'L', NULL, 0, "Log session activity", GRP+1},
+ {"kerberos", 'k', NULL, 0, "Use kerberos IV authentication", GRP+1},
+ {"vacuous", 'v', NULL, OPTION_HIDDEN, NULL, GRP+1},
+ {"encryption", 'x', NULL, 0, "Use DES encryption", GRP+1},
+#undef GRP
+ {NULL}
};
-char *program_name;
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case 'a':
+ check_all = 1;
+ break;
+
+ case 'l':
+ __check_rhosts_file = 0; /* don't check .rhosts file */
+ break;
+
+ case 'n':
+ keepalive = 0; /* don't enable SO_KEEPALIVE */
+ break;
+
+ case 'k':
+#if defined(KERBEROS) || defined(SHISHI)
+ use_kerberos = 1;
+#else
+ argp_error (state, "'-%c' is currently not supported on this machine.",
+ key);
+#endif
+ break;
+
+ case 'v':
+#if defined(KERBEROS) || defined(SHISHI)
+ vacuous = 1;
+#else
+ argp_error (state, "'-%c' is currently not supported on this machine.",
+ key);
+#endif
+ break;
+
+ case 'x':
+#if (defined(KERBEROS) || defined(SHISHI)) && defined(ENCRYPTION)
+ doencrypt = 1;
+#else
+ argp_error (state, "'-%c' is currently not supported on this machine.",
+ key);
+#endif
+ break;
+
+ case 'L':
+ log_success = 1;
+ break;
+
+ case ARGP_KEY_ARG:
+ argp_usage (state);
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+static struct argp argp = {argp_options, parse_opt, args_doc, doc};
/* Remote shell server. We're invoked by the rcmd(3) function. */
int
main (int argc, char *argv[])
{
- extern int __check_rhosts_file; /* hook in rcmd(3) */
struct linger linger;
int ch, on = 1, fromlen;
struct sockaddr_in from;
int sockfd;
+ int index;
program_name = argv[0];
- opterr = 0;
- while ((ch = getopt_long (argc, argv, short_options, long_options, NULL))
- != EOF)
- {
- switch (ch)
- {
- case 'a':
- check_all = 1;
- break;
-
- case 'l':
- __check_rhosts_file = 0; /* don't check .rhosts file */
- break;
-
- case 'n':
- keepalive = 0; /* don't enable SO_KEEPALIVE */
- break;
-
-#if defined(KERBEROS) || defined(SHISHI)
- case 'k':
- use_kerberos = 1;
- break;
-
- case 'v':
- vacuous = 1;
- break;
-
-# ifdef ENCRYPTION
- case 'x':
- doencrypt = 1;
- break;
-# endif
-#endif
-
- case 'L':
- log_success = 1;
- break;
-
- case 'V':
- printf ("rshd (%s %s)\n", PACKAGE_NAME, PACKAGE_VERSION);
- exit (0);
-
- case 'h':
- help ();
- exit (0);
- case '?':
- default:
- usage ();
- break;
- }
- }
+ /* Parse command line */
+ argp_parse (&argp, argc, argv, 0, &index, NULL);
openlog ("rshd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
-
- argc -= optind;
+ argc -= index;
if (argc > 0)
{
syslog (LOG_ERR, "%d extra arguments", argc);
@@ -1240,37 +1251,3 @@ topdomain (const char *h)
}
return maybe;
}
-
-void
-usage ()
-{
- syslog (LOG_ERR, "usage: rshd [-%s]", OPTIONS);
- exit (2);
-}
-
-void
-help (void)
-{
- puts ("usage: rshd [options]");
- puts ("\
- -a, --verify-hostname Ask hostname for verification");
- puts ("\
- -l, --no-rhosts Ignore .rhosts file");
- puts ("\
- -L, --log-session Set local domain name");
- puts ("\
- -n, --no-keepalive Do not set SO_KEEPALIVE");
-#if defined(KERBEROS) || defined(SHISHI)
- puts ("\
- -k, --kerberos Use kerberos IV authentication");
-# ifdef ENCRYPTION
- puts ("\
- -x, --encrypt Use DES encryption");
-# endif /* ENCRYPTION */
-#endif /* KERBEROS */
- puts ("\
- -h, --help Display usage instructions");
- puts ("\
- -V, --version Display program version");
- printf ("\nSend bug reports to %s\n", PACKAGE_BUGREPORT);
-}
_______________________________________________
bug-inetutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-inetutils