#ident "$Id$"
-#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <getopt.h>
/*
* exit status values
*/
+/*@-exitarg@*/
#define E_SUCCESS 0 /* success */
#define E_USAGE 2 /* invalid command syntax */
#define E_BAD_ARG 3 /* invalid argument to option */
/*
* Global variables
*/
-char *Prog;
+const char *Prog;
static /*@null@*/char *group_name;
static gid_t group_id;
#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)
{
- fputs (_("Usage: groupadd [options] GROUP\n"
- "\n"
- "Options:\n"
- " -f, --force force exit with success status if the\n"
- " specified group already exists\n"
- " -g, --gid GID use GID for the new group\n"
- " -h, --help display this help message and exit\n"
- " -K, --key KEY=VALUE overrides /etc/login.defs defaults\n"
- " -o, --non-unique allow create group with duplicate\n"
- " (non-unique) GID\n"
- " -p, --password PASSWORD use encrypted password for the new group\n"
- " -r, --system create a system account\n"
- "\n"), stderr);
- exit (E_USAGE);
+ FILE *usageout = (E_SUCCESS != 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"), 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"), 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);
}
/*
*/
add_cleanup (cleanup_report_add_group, group_name);
- /* An now open the databases */
+ /* And now open the databases */
if (gr_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ()));
}
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 ();