Tool name: rshd
rshd/rshd.c:
* Changed 'optarg' to 'arg'. (Fixes empty realm bug)
* Removed macro for getopt's short options (old)
* Removed help () and usage ()
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 22 Aug 2008 16:03:59 -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,103 @@ 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},
+ /* 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},
+#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
+#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;
+
+#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 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 +1247,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