Skip to content

Commit

Permalink
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
Browse files Browse the repository at this point in the history
	src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
	src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
	src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
	src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
	the usage should not go to stderr nor should the utility exit with
	non-zero status. All of the shadow utils do just this
	unfortunately, so convert them over to sanity.
	* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
  • Loading branch information
nekral-guest committed Sep 4, 2009
1 parent 3d10e75 commit 91b60a9
Show file tree
Hide file tree
Showing 21 changed files with 271 additions and 205 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2009-09-05 Mike Frysinger <vapier@gentoo.org>

* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.

2009-09-05 Nicolas François <nicolas.francois@centraliens.net>

* src/useradd.c: Fixed wrong format string.
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
$Id$

shadow-4.1.4.1 -> shadow-4.1.4.2 UNRELEASED

- general
* report usage error to stderr, but report usage help to stdout (and return
zero) when explicitly requested (e.g. with --help).

shadow-4.1.4.1 -> shadow-4.1.4.2 2009-07-24

- general
Expand Down
10 changes: 9 additions & 1 deletion man/gpasswd.1.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 1996 , Rafal Maszkowski
Copyright (c) 2007 - 2008, Nicolas François
Copyright (c) 2007 - 2009, Nicolas François
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -146,6 +146,14 @@
</listitem>
</varlistentry>
</variablelist>
<variablelist remap='IP'>
<varlistentry>
<term><option>-h</option>, <option>--help</option></term>
<listitem>
<para>Display help message and exit.</para>
</listitem>
</varlistentry>
</variablelist>
<variablelist remap='IP'>
<varlistentry>
<term>
Expand Down
6 changes: 6 additions & 0 deletions man/groupmems.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option>, <option>--help</option></term>
<listitem>
<para>Display help message and exit.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-l</option>, <option>--list</option></term>
<listitem>
Expand Down
28 changes: 14 additions & 14 deletions src/chage.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static long expdate;

/* local function prototypes */
static bool isnum (const char *s);
static void usage (void);
static void usage (int status);
static void date_to_str (char *buf, size_t maxsize, time_t date);
static int new_fields (void);
static void print_date (time_t date);
Expand Down Expand Up @@ -152,7 +152,7 @@ static bool isnum (const char *s)
/*
* usage - print command line syntax and exit
*/
static void usage (void)
static void usage (int status)
{
fputs (_("Usage: chage [options] [LOGIN]\n"
"\n"
Expand All @@ -168,8 +168,8 @@ static void usage (void)
" -M, --maxdays MAX_DAYS set maximim number of days before password\n"
" change to MAX_DAYS\n"
" -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"
"\n"), stderr);
exit (E_USAGE);
"\n"), status ? stderr : stdout);
exit (status);
}

static void date_to_str (char *buf, size_t maxsize, time_t date)
Expand Down Expand Up @@ -413,7 +413,7 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
case 'E':
Expand All @@ -425,11 +425,11 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
case 'h':
usage ();
usage (E_SUCCESS);
break;
case 'I':
Iflg = true;
Expand All @@ -438,7 +438,7 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
case 'l':
Expand All @@ -451,7 +451,7 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
case 'M':
Expand All @@ -461,7 +461,7 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
case 'W':
Expand All @@ -471,11 +471,11 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
default:
usage ();
usage (E_USAGE);
}
}

Expand All @@ -495,14 +495,14 @@ static void check_flags (int argc, int opt_index)
*/

if (argc != opt_index + 1) {
usage ();
usage (E_USAGE);
}

if (lflg && (mflg || Mflg || dflg || Wflg || Iflg || Eflg)) {
fprintf (stderr,
_("%s: do not include \"l\" with other flags\n"),
Prog);
usage ();
usage (E_USAGE);
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/chgpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static bool gr_locked = false;

/* local function prototypes */
static void fail_exit (int code);
static void usage (void);
static void usage (int status);
static void process_flags (int argc, char **argv);
static void check_flags (void);
static void check_perms (void);
Expand Down Expand Up @@ -114,9 +114,10 @@ static void fail_exit (int code)
/*
* usage - display usage message and exit
*/
static void usage (void)
static void usage (int status)
{
fprintf (stderr, _("Usage: %s [options]\n"
fprintf (status ? stderr : stdout,
_("Usage: %s [options]\n"
"\n"
"Options:\n"
" -c, --crypt-method the crypt method (one of %s)\n"
Expand All @@ -135,7 +136,7 @@ static void usage (void)
" crypt algorithms\n")
#endif
);
exit (E_USAGE);
exit (status);
}

/*
Expand Down Expand Up @@ -174,7 +175,7 @@ static void process_flags (int argc, char **argv)
eflg = true;
break;
case 'h':
usage ();
usage (E_SUCCESS);
break;
case 'm':
md5flg = true;
Expand All @@ -186,12 +187,12 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
#endif
default:
usage ();
usage (E_USAGE);
break;
}
}
Expand All @@ -212,7 +213,7 @@ static void check_flags (void)
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-s", "-c");
usage ();
usage (E_USAGE);
}
#endif

Expand All @@ -221,7 +222,7 @@ static void check_flags (void)
fprintf (stderr,
_("%s: the -c, -e, and -m flags are exclusive\n"),
Prog);
usage ();
usage (E_USAGE);
}

if (cflg) {
Expand All @@ -236,7 +237,7 @@ static void check_flags (void)
fprintf (stderr,
_("%s: unsupported crypt method: %s\n"),
Prog, crypt_method);
usage ();
usage (E_USAGE);
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions src/chpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static bool spw_locked = false;

/* local function prototypes */
static void fail_exit (int code);
static void usage (void);
static void usage (int status);
static void process_flags (int argc, char **argv);
static void check_flags (void);
static void check_perms (void);
Expand Down Expand Up @@ -112,38 +112,39 @@ static void fail_exit (int code)
/*
* usage - display usage message and exit
*/
static void usage (void)
static void usage (int status)
{
(void) fprintf (stderr,
FILE *usageout = status ? stderr : stdout;
(void) fprintf (usageout,
_("Usage: %s [options]\n"
"\n"
"Options:\n"),
Prog);
#ifndef USE_PAM
(void) fprintf (stderr,
(void) fprintf (usageout,
_(" -c, --crypt-method the crypt method (one of %s)\n"),
#ifndef USE_SHA_CRYPT
"NONE DES MD5"
#else /* USE_SHA_CRYPT */
"NONE DES MD5 SHA256 SHA512"
#endif /* USE_SHA_CRYPT */
);
(void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), stderr);
(void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout);
#endif /* !USE_PAM */
(void) fputs (_(" -h, --help display this help message and exit\n"), stderr);
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
#ifndef USE_PAM
(void) fputs (_(" -m, --md5 encrypt the clear text password using\n"
" the MD5 algorithm\n"),
stderr);
usageout);
#ifdef USE_SHA_CRYPT
(void) fputs (_(" -s, --sha-rounds number of SHA rounds for the SHA*\n"
" crypt algorithms\n"),
stderr);
usageout);
#endif /* USE_SHA_CRYPT */
#endif /* !USE_PAM */
(void) fputs ("\n", stderr);
(void) fputs ("\n", usageout);

exit (E_USAGE);
exit (status);
}

/*
Expand Down Expand Up @@ -181,7 +182,7 @@ static void process_flags (int argc, char **argv)
long_options, &option_index)) != -1) {
switch (c) {
case 'h':
usage ();
usage (E_SUCCESS);
break;
#ifndef USE_PAM
case 'c':
Expand All @@ -201,13 +202,13 @@ static void process_flags (int argc, char **argv)
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
usage ();
usage (E_USAGE);
}
break;
#endif /* USE_SHA_CRYPT */
#endif /* !USE_PAM */
default:
usage ();
usage (E_USAGE);
break;
}
}
Expand All @@ -229,7 +230,7 @@ static void check_flags (void)
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-s", "-c");
usage ();
usage (E_USAGE);
}
#endif

Expand All @@ -238,7 +239,7 @@ static void check_flags (void)
fprintf (stderr,
_("%s: the -c, -e, and -m flags are exclusive\n"),
Prog);
usage ();
usage (E_USAGE);
}

if (cflg) {
Expand All @@ -253,7 +254,7 @@ static void check_flags (void)
fprintf (stderr,
_("%s: unsupported crypt method: %s\n"),
Prog, crypt_method);
usage ();
usage (E_USAGE);
}
}
#endif /* USE_PAM */
Expand Down
Loading

0 comments on commit 91b60a9

Please sign in to comment.