+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.
$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
<?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
</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>
</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>
/* 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);
/*
* usage - print command line syntax and exit
*/
-static void usage (void)
+static void usage (int status)
{
fputs (_("Usage: chage [options] [LOGIN]\n"
"\n"
" -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)
fprintf (stderr,
_("%s: invalid date '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
break;
case 'E':
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;
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
break;
case 'l':
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
break;
case 'M':
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
break;
case 'W':
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
*/
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);
}
}
/* 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);
/*
* 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"
" crypt algorithms\n")
#endif
);
- exit (E_USAGE);
+ exit (status);
}
/*
eflg = true;
break;
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 'm':
md5flg = true;
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
break;
#endif
default:
- usage ();
+ usage (E_USAGE);
break;
}
}
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-s", "-c");
- usage ();
+ usage (E_USAGE);
}
#endif
fprintf (stderr,
_("%s: the -c, -e, and -m flags are exclusive\n"),
Prog);
- usage ();
+ usage (E_USAGE);
}
if (cflg) {
fprintf (stderr,
_("%s: unsupported crypt method: %s\n"),
Prog, crypt_method);
- usage ();
+ usage (E_USAGE);
}
}
}
/* 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);
/*
* 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"
"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);
}
/*
long_options, &option_index)) != -1) {
switch (c) {
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
#ifndef USE_PAM
case 'c':
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;
}
}
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-s", "-c");
- usage ();
+ usage (E_USAGE);
}
#endif
fprintf (stderr,
_("%s: the -c, -e, and -m flags are exclusive\n"),
Prog);
- usage ();
+ usage (E_USAGE);
}
if (cflg) {
fprintf (stderr,
_("%s: unsupported crypt method: %s\n"),
Prog, crypt_method);
- usage ();
+ usage (E_USAGE);
}
}
#endif /* USE_PAM */
/* local function prototypes */
static void fail_exit (int code);
-static void usage (void);
+static void usage (int status);
static void new_fields (void);
static bool shell_is_listed (const char *);
static bool is_restricted_shell (const char *);
/*
* usage - print command line syntax and exit
*/
-static void usage (void)
+static void usage (int status)
{
fputs (_("Usage: chsh [options] [LOGIN]\n"
"\n"
"Options:\n"
" -h, --help display this help message and exit\n"
" -s, --shell SHELL new login shell for the user account\n"
- "\n"), stderr);
- exit (E_USAGE);
+ "\n"), status ? stderr : stdout);
+ exit (status);
}
/*
&option_index)) != -1) {
switch (c) {
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 's':
sflg = true;
STRFCPY (loginsh, optarg);
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
* be the user's name.
*/
if (argc > (optind + 1)) {
- usage ();
+ usage (E_USAGE);
}
}
/*@-exitarg@*/
#include "exitcodes.h"
+/* local function prototypes */
+static void usage (int status);
+static void print_one (/*@null@*/const struct passwd *pw, bool force);
+static void set_locktime (long locktime);
+static bool set_locktime_one (uid_t uid, long locktime);
+static void setmax (int max);
+static bool setmax_one (uid_t uid, int max);
+static void print (void);
+static bool reset_one (uid_t uid);
+static void reset (void);
+
/*
* Global variables
*/
#define NOW (time((time_t *) 0))
-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"),
"faillog");
- (void) fputs (_(" -a, --all display faillog records for all users\n"), stderr);
- (void) fputs (_(" -h, --help display this help message and exit\n"), stderr);
- (void) fputs (_(" -l, --lock-time SEC after failed login lock account for SEC seconds\n"), stderr);
- (void) fputs (_(" -m, --maximum MAX set maximum failed login counters to MAX\n"), stderr);
- (void) fputs (_(" -r, --reset reset the counters of login failures\n"), stderr);
- (void) fputs (_(" -t, --time DAYS display faillog records more recent than DAYS\n"), stderr);
+ (void) fputs (_(" -a, --all display faillog records for all users\n"), usageout);
+ (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
+ (void) fputs (_(" -l, --lock-time SEC after failed login lock account for SEC seconds\n"), usageout);
+ (void) fputs (_(" -m, --maximum MAX set maximum failed login counters to MAX\n"), usageout);
+ (void) fputs (_(" -r, --reset reset the counters of login failures\n"), usageout);
+ (void) fputs (_(" -t, --time DAYS display faillog records more recent than DAYS\n"), usageout);
(void) fputs (_(" -u, --user LOGIN/RANGE display faillog record or maintains failure\n"
" counters and limits (if used with -r, -m,\n"
- " or -l) only for the specified LOGIN(s)\n"), stderr);
- (void) fputs ("\n", stderr);
- exit (E_USAGE);
+ " or -l) only for the specified LOGIN(s)\n"), usageout);
+ (void) fputs ("\n", usageout);
+ exit (status);
}
static void print_one (/*@null@*/const struct passwd *pw, bool force)
aflg = true;
break;
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 'l':
if (getlong (optarg, &fail_locktime) == 0) {
break;
}
default:
- usage ();
+ usage (E_USAGE);
}
}
}
if (aflg && uflg) {
- usage ();
+ usage (E_USAGE);
}
if (tflg && (lflg || mflg || rflg)) {
- usage ();
+ usage (E_USAGE);
}
/* Open the faillog database */
#endif
/* local function prototypes */
-static void usage (void);
+static void usage (int status);
static RETSIGTYPE catch_signals (int killed);
static bool is_valid_user_list (const char *users);
static void process_flags (int argc, char **argv);
/*
* usage - display usage message
*/
-static void usage (void)
+static void usage (int status)
{
- fprintf (stderr,
+ fprintf (status ? stderr : stdout,
_("Usage: %s [option] GROUP\n"
"\n"
"Options:\n"
" -a, --add USER add USER to GROUP\n"
" -d, --delete USER remove USER from GROUP\n"
+ " -h, --help display this help message and exit\n"
" -r, --remove-password remove the GROUP's password\n"
" -R, --restrict restrict access to GROUP to its members\n"
" -M, --members USER,... set the list of members of GROUP\n"
_("The options cannot be combined.\n")
#endif
);
- exit (E_USAGE);
+ exit (status);
}
/*
static struct option long_options[] = {
{"add", required_argument, NULL, 'a'},
{"delete", required_argument, NULL, 'd'},
+ {"help", no_argument, NULL, 'h'},
{"remove-password", no_argument, NULL, 'r'},
{"restrict", no_argument, NULL, 'R'},
{"administrators", required_argument, NULL, 'A'},
{NULL, 0, NULL, '\0'}
};
- while ((flag = getopt_long (argc, argv, "a:A:d:gM:rR", long_options, &option_index)) != -1) {
+ while ((flag = getopt_long (argc, argv, "a:A:d:ghM:rR", long_options, &option_index)) != -1) {
switch (flag) {
case 'a': /* add a user */
aflg = true;
break;
case 'g': /* no-op from normal password */
break;
+ case 'h':
+ usage (E_SUCCESS);
case 'M': /* set the list of members */
members = optarg;
if (!is_valid_user_list (members)) {
Rflg = true;
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
exclusive++;
}
if (exclusive > 1) {
- usage ();
+ usage (E_USAGE);
}
/*
* Make sure one (and only one) group was provided
*/
if ((argc != (opt_index+1)) || (NULL == group)) {
- usage ();
+ usage (E_USAGE);
}
}
#endif
/* local function prototypes */
-static void usage (void);
+static void usage (int status);
static void new_grent (struct group *grent);
#ifdef SHADOWGRP
/*
* 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] GROUP\n"
"\n"
"Options:\n"),
Prog);
(void) fputs (_(" -f, --force exit successfully if the group already exists,\n"
- " and cancel -g if the GID is already used\n"), stderr);
- (void) fputs (_(" -g, --gid GID use GID for the new group\n"), stderr);
- (void) fputs (_(" -h, --help display this help message and exit\n"), stderr);
- (void) fputs (_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), stderr);
+ " and cancel -g if the GID is already used\n"), usageout);
+ (void) fputs (_(" -g, --gid GID use GID for the new group\n"), usageout);
+ (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
+ (void) fputs (_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), usageout);
(void) fputs (_(" -o, --non-unique allow to create groups with duplicate\n"
- " (non-unique) GID\n"), stderr);
- (void) fputs (_(" -p, --password PASSWORD use this encrypted password for the new group\n"), stderr);
- (void) fputs (_(" -r, --system create a system account\n"), stderr);
- (void) fputs ("\n", stderr);
- exit (E_USAGE);
+ " (non-unique) GID\n"), usageout);
+ (void) fputs (_(" -p, --password PASSWORD use this encrypted password for the new group\n"), usageout);
+ (void) fputs (_(" -r, --system create a system account\n"), usageout);
+ (void) fputs ("\n", usageout);
+ exit (status);
}
/*
}
break;
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 'K':
/*
rflg = true;
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
* Check the flags consistency
*/
if (optind != argc - 1) {
- usage ();
+ usage (E_USAGE);
}
group_name = argv[optind];
{
/* -o does not make sense without -g */
if (oflg && !gflg) {
- usage ();
+ usage (E_USAGE);
}
check_new_name ();
const struct group *grp);
static void purge_members (const struct group *grp);
static void display_members (const char *const *members);
-static void usage (void);
+static void usage (int status);
static void process_flags (int argc, char **argv);
static void check_perms (void);
static void fail_exit (int code);
}
}
-static void usage (void)
+static void usage (int status)
{
(void) fputs (_("Usage: groupmems [options] [action]\n"
"\n"
"Actions:\n"
" -a, --add username add username to the members of the group\n"
" -d, --delete username remove username from the members of the group\n"
+ " -h, --help display this help message and exit\n"
" -p, --purge purge all members from the group\n"
" -l, --list list the members of the group\n"
- "\n"), stderr);
- fail_exit (EXIT_USAGE);
+ "\n"), status ? stderr : stdout);
+ fail_exit (status);
}
/*
{"add", required_argument, NULL, 'a'},
{"delete", required_argument, NULL, 'd'},
{"group", required_argument, NULL, 'g'},
+ {"help", no_argument, NULL, 'h'},
{"list", no_argument, NULL, 'l'},
{"purge", no_argument, NULL, 'p'},
{NULL, 0, NULL, '\0'}
};
- while ((arg = getopt_long (argc, argv, "a:d:g:lp", long_options,
+ while ((arg = getopt_long (argc, argv, "a:d:g:hlp", long_options,
&option_index)) != EOF) {
switch (arg) {
case 'a':
case 'g':
thisgroup = xstrdup (optarg);
break;
+ case 'h':
+ usage (EXIT_SUCCESS);
case 'l':
list = true;
++exclusive;
++exclusive;
break;
default:
- usage ();
+ usage (EXIT_USAGE);
}
}
if ((exclusive > 1) || (optind < argc)) {
- usage ();
+ usage (EXIT_USAGE);
}
/* local, no need for xgetpwnam */
pflg = false; /* new encrypted password */
/* local function prototypes */
-static void usage (void);
+static void usage (int status);
static void new_grent (struct group *);
#ifdef SHADOWGRP
* 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] GROUP\n"
"\n"
"Options:\n"),
Prog);
- (void) fputs (_(" -g, --gid GID change the group ID to GID\n"), stderr);
- (void) fputs (_(" -h, --help display this help message and exit\n"), stderr);
- (void) fputs (_(" -n, --new-name NEW_GROUP change the name to NEW_GROUP\n"), stderr);
- (void) fputs (_(" -o, --non-unique allow to use a duplicate (non-unique) GID\n"), stderr);
+ (void) fputs (_(" -g, --gid GID change the group ID to GID\n"), usageout);
+ (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
+ (void) fputs (_(" -n, --new-name NEW_GROUP change the name to NEW_GROUP\n"), usageout);
+ (void) fputs (_(" -o, --non-unique allow to use a duplicate (non-unique) GID\n"), usageout);
(void) fputs (_(" -p, --password PASSWORD change the password to this (encrypted)\n"
- " PASSWORD\n"), stderr);
- (void) fputs ("\n", stderr);
- exit (E_USAGE);
+ " PASSWORD\n"), usageout);
+ (void) fputs ("\n", usageout);
+ exit (status);
}
/*
exit (E_BAD_ARG);
}
break;
+ case 'h':
+ usage (E_SUCCESS);
case 'n':
nflg = true;
group_newname = optarg;
pflg = true;
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
if (oflg && !gflg) {
- usage ();
+ usage (E_USAGE);
}
if (optind != (argc - 1)) {
- usage ();
+ usage (E_USAGE);
}
group_name = argv[argc - 1];
#define NOW (time ((time_t *) 0))
-static void usage (void)
+static void usage (int status)
{
fputs (_("Usage: lastlog [options]\n"
"\n"
" -h, --help display this help message and exit\n"
" -t, --time DAYS print only lastlog records more recent than DAYS\n"
" -u, --user LOGIN print lastlog record of the specified LOGIN\n"
- "\n"), stderr);
- exit (EXIT_FAILURE);
+ "\n"), status ? stderr : stdout);
+ exit (status);
}
static void print_one (/*@null@*/const struct passwd *pw)
NULL)) != -1) {
switch (c) {
case 'h':
- usage ();
+ usage (EXIT_SUCCESS);
break;
case 't':
{
break;
}
default:
- usage ();
+ usage (EXIT_FAILURE);
break;
}
}
fprintf (stderr,
_("lastlog: unexpected argument: %s\n"),
argv[optind]);
- usage();
+ usage (EXIT_FAILURE);
}
}
static bool spw_locked = false;
/* local function prototypes */
-static void usage (void);
+static void usage (int status);
static void fail_exit (int);
static int add_group (const char *, const char *, gid_t *, gid_t);
static int get_user_id (const char *, uid_t *);
/*
* 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"
#endif /* USE_SHA_CRYPT */
);
#endif /* !USE_PAM */
- (void) fputs (_(" -h, --help display this help message and exit\n"), stderr);
- (void) fputs (_(" -r, --system create system accounts\n"), stderr);
+ (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
+ (void) fputs (_(" -r, --system create system accounts\n"), usageout);
#ifndef USE_PAM
#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 (EXIT_FAILURE);
+ exit (status);
}
/*
long_options, &option_index)) != -1) {
switch (c) {
case 'h':
- usage ();
+ usage (EXIT_SUCCESS);
break;
case 'r':
rflg = true;
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (EXIT_FAILURE);
}
break;
#endif /* USE_SHA_CRYPT */
#endif /* !USE_PAM */
default:
- usage ();
+ usage (EXIT_FAILURE);
break;
}
}
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-s", "-c");
- usage ();
+ usage (EXIT_FAILURE);
}
#endif /* USE_SHA_CRYPT */
fprintf (stderr,
_("%s: unsupported crypt method: %s\n"),
Prog, crypt_method);
- usage ();
+ usage (EXIT_FAILURE);
}
}
#endif /* !USE_PAM */
" -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"
" -x, --maxdays MAX_DAYS set maximum number of days before password\n"
" change to MAX_DAYS\n"
- "\n"), stderr);
+ "\n"), status ? stderr : stdout);
exit (status);
}
{NULL, 0, NULL, '\0'}
};
- while ((c = getopt_long (argc, argv, "adei:kln:qr:Suw:x:",
+ while ((c = getopt_long (argc, argv, "adehi:kln:qr:Suw:x:",
long_options, &option_index)) != -1) {
switch (c) {
case 'a':
xflg = true;
anyflag = true;
break;
+ case 'h':
+ usage (E_SUCCESS);
default:
usage (E_BAD_ARG);
}
/*
* usage - print command line syntax and exit
*/
-static void usage (void)
+static void usage (int status)
{
fputs (_("Usage: su [options] [LOGIN]\n"
"\n"
" --preserve-environment do not reset environment variables, and\n"
" keep the same shell\n"
" -s, --shell SHELL use SHELL instead of the default in passwd\n"
- "\n"), stderr);
- exit (E_USAGE);
+ "\n"), status ? stderr : stdout);
+ exit (status);
}
/*
command = optarg;
break;
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 'l':
fakelogin = true;
shellstr = optarg;
break;
default:
- usage (); /* NOT REACHED */
+ usage (E_USAGE); /* NOT REACHED */
}
}
static void show_defaults (void);
static int set_defaults (void);
static int get_groups (char *);
-static void usage (void);
+static void usage (int status);
static void new_pwent (struct passwd *);
#ifdef WITH_SELINUX
static void selinux_update_mapping (void);
/*
* 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] LOGIN\n"
"\n"
"Options:\n"),
Prog);
(void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n"
- " new account\n"), stderr);
- (void) fputs (_(" -c, --comment COMMENT GECOS field of the new account\n"), stderr);
- (void) fputs (_(" -d, --home-dir HOME_DIR home directory of the new account\n"), stderr);
- (void) fputs (_(" -D, --defaults print or change default useradd configuration\n"), stderr);
- (void) fputs (_(" -e, --expiredate EXPIRE_DATE expiration date of the new account\n"), stderr);
- (void) fputs (_(" -f, --inactive INACTIVE password inactivity period of the new account\n"), stderr);
+ " new account\n"), usageout);
+ (void) fputs (_(" -c, --comment COMMENT GECOS field of the new account\n"), usageout);
+ (void) fputs (_(" -d, --home-dir HOME_DIR home directory of the new account\n"), usageout);
+ (void) fputs (_(" -D, --defaults print or change default useradd configuration\n"), usageout);
+ (void) fputs (_(" -e, --expiredate EXPIRE_DATE expiration date of the new account\n"), usageout);
+ (void) fputs (_(" -f, --inactive INACTIVE password inactivity period of the new account\n"), usageout);
(void) fputs (_(" -g, --gid GROUP name or ID of the primary group of the new\n"
- " account\n"), stderr);
+ " account\n"), usageout);
(void) fputs (_(" -G, --groups GROUPS list of supplementary groups of the new\n"
- " account\n"), stderr);
- (void) fputs (_(" -h, --help display this help message and exit\n"), stderr);
- (void) fputs (_(" -k, --skel SKEL_DIR use this alternative skeleton directory\n"), stderr);
- (void) fputs (_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), stderr);
+ " account\n"), usageout);
+ (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
+ (void) fputs (_(" -k, --skel SKEL_DIR use this alternative skeleton directory\n"), usageout);
+ (void) fputs (_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), usageout);
(void) fputs (_(" -l, --no-log-init do not add the user to the lastlog and\n"
- " faillog databases\n"), stderr);
- (void) fputs (_(" -m, --create-home create the user's home directory\n"), stderr);
- (void) fputs (_(" -M, --no-create-home do not create the user's home directory\n"), stderr);
+ " faillog databases\n"), usageout);
+ (void) fputs (_(" -m, --create-home create the user's home directory\n"), usageout);
+ (void) fputs (_(" -M, --no-create-home do not create the user's home directory\n"), usageout);
(void) fputs (_(" -N, --no-user-group do not create a group with the same name as\n"
- " the user\n"), stderr);
+ " the user\n"), usageout);
(void) fputs (_(" -o, --non-unique allow to create users with duplicate\n"
- " (non-unique) UID\n"), stderr);
- (void) fputs (_(" -p, --password PASSWORD encrypted password of the new account\n"), stderr);
- (void) fputs (_(" -r, --system create a system account\n"), stderr);
- (void) fputs (_(" -s, --shell SHELL login shell of the new account\n"), stderr);
- (void) fputs (_(" -u, --uid UID user ID of the new account\n"), stderr);
- (void) fputs (_(" -U, --user-group create a group with the same name as the user\n"), stderr);
+ " (non-unique) UID\n"), usageout);
+ (void) fputs (_(" -p, --password PASSWORD encrypted password of the new account\n"), usageout);
+ (void) fputs (_(" -r, --system create a system account\n"), usageout);
+ (void) fputs (_(" -s, --shell SHELL login shell of the new account\n"), usageout);
+ (void) fputs (_(" -u, --uid UID user ID of the new account\n"), usageout);
+ (void) fputs (_(" -U, --user-group create a group with the same name as the user\n"), usageout);
#ifdef WITH_SELINUX
- (void) fputs (_(" -Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping\n"), stderr);
+ (void) fputs (_(" -Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping\n"), usageout);
#endif
- (void) fputs ("\n", stderr);
- exit (E_USAGE);
+ (void) fputs ("\n", usageout);
+ exit (status);
}
/*
};
while ((c = getopt_long (argc, argv,
#ifdef WITH_SELINUX
- "b:c:d:De:f:g:G:k:K:lmMNop:rs:u:UZ:",
+ "b:c:d:De:f:g:G:hk:K:lmMNop:rs:u:UZ:",
#else
- "b:c:d:De:f:g:G:k:K:lmMNop:rs:u:U",
+ "b:c:d:De:f:g:G:hk:K:lmMNop:rs:u:U",
#endif
long_options, NULL)) != -1) {
switch (c) {
break;
case 'D':
if (anyflag) {
- usage ();
+ usage (E_USAGE);
}
Dflg = true;
break;
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
/*
* -f -1 is allowed
Gflg = true;
break;
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 'k':
def_template = optarg;
break;
#endif
default:
- usage ();
+ usage (E_USAGE);
}
anyflag = true;
}
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-o", "-u");
- usage ();
+ usage (E_USAGE);
}
if (kflg && !mflg) {
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-k", "-m");
- usage ();
+ usage (E_USAGE);
}
if (Uflg && gflg) {
fprintf (stderr,
_("%s: options %s and %s conflict\n"),
Prog, "-U", "-g");
- usage ();
+ usage (E_USAGE);
}
if (Uflg && Nflg) {
fprintf (stderr,
_("%s: options %s and %s conflict\n"),
Prog, "-U", "-N");
- usage ();
+ usage (E_USAGE);
}
if (mflg && Mflg) {
fprintf (stderr,
_("%s: options %s and %s conflict\n"),
Prog, "-m", "-M");
- usage ();
+ usage (E_USAGE);
}
/*
*/
if (Dflg) {
if (optind != argc) {
- usage ();
+ usage (E_USAGE);
}
if (uflg || oflg || Gflg || dflg || cflg || mflg) {
- usage ();
+ usage (E_USAGE);
}
} else {
if (optind != argc - 1) {
- usage ();
+ usage (E_USAGE);
}
user_name = argv[optind];
static bool spw_locked = false;
/* local function prototypes */
-static void usage (void);
+static void usage (int status);
static void update_groups (void);
static void close_files (void);
static void fail_exit (int);
/*
* usage - display usage message and exit
*/
-static void usage (void)
+static void usage (int status)
{
fputs (_("Usage: userdel [options] LOGIN\n"
"\n"
" even if not owned by user\n"
" -h, --help display this help message and exit\n"
" -r, --remove remove home directory and mail spool\n"
- "\n"), stderr);
- exit (E_USAGE);
+ "\n"), status ? stderr : stdout);
+ exit (status);
}
/*
case 'f': /* force remove even if not owned by user */
fflg = true;
break;
+ case 'h':
+ usage (E_SUCCESS);
case 'r': /* remove home dir and mailbox */
rflg = true;
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
}
if ((optind + 1) != argc) {
- usage ();
+ usage (E_USAGE);
}
OPENLOG ("userdel");
static void date_to_str (char *buf, size_t maxsize,
long int date, const char *negativ);
static int get_groups (char *);
-static void usage (void);
+static void usage (int status);
static void new_pwent (struct passwd *);
#ifdef WITH_SELINUX
static void selinux_update_mapping (void);
/*
* usage - display usage message and exit
*/
-static void usage (void)
+static void usage (int status)
{
- fprintf (stderr,
+ fprintf (status ? stderr : stdout,
_("Usage: usermod [options] LOGIN\n"
"\n"
"Options:\n"
""
#endif
);
- exit (E_USAGE);
+ exit (status);
}
/*
bool anyflag = false;
if ((1 == argc) || ('-' == argv[argc - 1][0])) {
- usage ();
+ usage (E_USAGE);
}
{
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
- usage ();
+ usage (E_USAGE);
}
fflg = true;
break;
}
Gflg = true;
break;
+ case 'h':
+ usage (E_SUCCESS);
case 'l':
if (!is_valid_user_name (optarg)) {
fprintf (stderr,
break;
#endif
default:
- usage ();
+ usage (E_USAGE);
}
anyflag = true;
}
}
if (optind != argc - 1) {
- usage ();
+ usage (E_USAGE);
}
if (aflg && (!Gflg)) {
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-a", "-G");
- usage ();
+ usage (E_USAGE);
exit (E_USAGE);
}
fprintf (stderr,
_("%s: the -L, -p, and -U flags are exclusive\n"),
Prog);
- usage ();
+ usage (E_USAGE);
exit (E_USAGE);
}
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-o", "-u");
- usage ();
+ usage (E_USAGE);
exit (E_USAGE);
}
fprintf (stderr,
_("%s: %s flag is only allowed with the %s flag\n"),
Prog, "-m", "-d");
- usage ();
+ usage (E_USAGE);
exit (E_USAGE);
}
/*
vipw, vigr edit the password or group file
with -s will edit shadow or gshadow file
-
+
Copyright (c) 1997 , Guy Maor <maor@ece.utexas.edu>
Copyright (c) 1999 - 2000, Marek Michałkiewicz
Copyright (c) 2002 - 2006, Tomasz Kłoczko
#include <errno.h>
#include <getopt.h>
-#ifdef WITH_SELINUX
-#include <selinux/selinux.h>
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
#endif
#include <signal.h>
#include <stdio.h>
static bool quiet = false;
/* local function prototypes */
-static void usage (void);
+static void usage (int status);
static int create_backup_file (FILE *, const char *, struct stat *);
static void vipwexit (const char *msg, int syserr, int ret);
static void vipwedit (const char *, int (*)(void), int (*)(void));
/*
* usage - display usage message and exit
*/
-static void usage (void)
+static void usage (int status)
{
- (void)
+ (void)
fputs (_("Usage: vipw [options]\n"
"\n"
"Options:\n"
" -p, --passwd edit passwd database\n"
" -q, --quiet quiet mode\n"
" -s, --shadow edit shadow or gshadow database\n"
- "\n"), stderr);
- exit (E_USAGE);
+ "\n"), status ? stderr : stdout);
+ exit (status);
}
/*
if (st1.st_mtime == st2.st_mtime) {
vipwexit (0, 0, 0);
}
-#ifdef WITH_SELINUX
- /* unset the fscreatecon */
+#ifdef WITH_SELINUX
+ /* unset the fscreatecon */
if (is_selinux_enabled ()) {
if (setfscreatecon (NULL)) {
vipwexit (_("setfscreatecon () failed"), errno, 1);
do_vipw = false;
break;
case 'h':
- usage ();
+ usage (E_SUCCESS);
break;
case 'p':
do_vipw = true;
editshadow = true;
break;
default:
- usage ();
+ usage (E_USAGE);
}
}
}