* src/groupdel.c: Add process_flags().

* src/groupdel.c, man/groupdel.8.xml: Add --help option.
	* NEWS, src/groupdel.c, man/groupdel.8.xml: Add --root option. Open
	audit and syslog after the potential chroot.
	* src/groupdel.c: Check atexit failures.
This commit is contained in:
nekral-guest 2011-11-06 18:37:57 +00:00
parent 9195f6085d
commit c017dd73aa
4 changed files with 110 additions and 24 deletions

View File

@ -18,6 +18,11 @@
* NEWS, src/groupadd.c, man/groupadd.8.xml: Add --root option. Open * NEWS, src/groupadd.c, man/groupadd.8.xml: Add --root option. Open
audit and syslog after the potential chroot. audit and syslog after the potential chroot.
* src/groupmod.c: The index of long options is not used. * src/groupmod.c: The index of long options is not used.
* src/groupdel.c: Add process_flags().
* src/groupdel.c, man/groupdel.8.xml: Add --help option.
* NEWS, src/groupdel.c, man/groupdel.8.xml: Add --root option. Open
audit and syslog after the potential chroot.
* src/groupdel.c: Check atexit failures.
2011-10-22 Nicolas François <nicolas.francois@centraliens.net> 2011-10-22 Nicolas François <nicolas.francois@centraliens.net>

2
NEWS
View File

@ -33,6 +33,8 @@ shadow-4.1.4.3 -> shadow-4.1.5 UNRELEASED
specified. specified.
- groupadd - groupadd
* Add --root option. * Add --root option.
- groupdel
* Add --root option.
- groupmod - groupmod
* Fixed groupmod when configured with --enable-account-tools-setuid. * Fixed groupmod when configured with --enable-account-tools-setuid.
* When the gshadow file exists but there are no gshadow entries, an entry * When the gshadow file exists but there are no gshadow entries, an entry

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright (c) 1991 - 1993, Julianne Frances Haugh Copyright (c) 1991 - 1993, Julianne Frances Haugh
Copyright (c) 2007 - 2008, Nicolas François Copyright (c) 2007 - 2011, Nicolas François
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -50,20 +50,50 @@
<refsynopsisdiv id='synopsis'> <refsynopsisdiv id='synopsis'>
<cmdsynopsis> <cmdsynopsis>
<command>groupdel</command> <command>groupdel</command>
<arg choice='plain'> <arg choice='opt'>
<replaceable>group</replaceable> <replaceable>options</replaceable>
</arg> </arg>
<arg choice='plain'><replaceable>GROUP</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
<refsect1 id='description'> <refsect1 id='description'>
<title>DESCRIPTION</title> <title>DESCRIPTION</title>
<para> The <command>groupdel</command> command modifies the system <para> The <command>groupdel</command> command modifies the system
account files, deleting all entries that refer to <emphasis account files, deleting all entries that refer to
remap='I'>group</emphasis>. The named group must exist. <replaceable>GROUP</replaceable>. The named group must exist.
</para> </para>
</refsect1> </refsect1>
<refsect1 id='options'>
<title>OPTIONS</title>
<para>
The options which apply to the <command>groupdel</command> command
are:
</para>
<variablelist remap='IP'>
<varlistentry>
<term><option>-h</option>, <option>--help</option></term>
<listitem>
<para>Display help message and exit.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-R</option>, <option>--root</option>
<replaceable>CHROOT_DIR</replaceable>
</term>
<listitem>
<para>
Apply changes in the <replaceable>CHROOT_DIR</replaceable>
directory and use the configuration files from the
<replaceable>CHROOT_DIR</replaceable> directory.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id='caveats'> <refsect1 id='caveats'>
<title>CAVEATS</title> <title>CAVEATS</title>
<para> <para>
@ -147,7 +177,8 @@
<refsect1 id='see_also'> <refsect1 id='see_also'>
<title>SEE ALSO</title> <title>SEE ALSO</title>
<para><citerefentry> <para>
<citerefentry>
<refentrytitle>chfn</refentrytitle><manvolnum>1</manvolnum> <refentrytitle>chfn</refentrytitle><manvolnum>1</manvolnum>
</citerefentry>, </citerefentry>,
<citerefentry> <citerefentry>
@ -173,7 +204,7 @@
</citerefentry>, </citerefentry>,
<citerefentry> <citerefentry>
<refentrytitle>usermod</refentrytitle><manvolnum>8</manvolnum> <refentrytitle>usermod</refentrytitle><manvolnum>8</manvolnum>
</citerefentry> </citerefentry>.
</para> </para>
</refsect1> </refsect1>
</refentry> </refentry>

View File

@ -2,7 +2,7 @@
* Copyright (c) 1991 - 1994, Julianne Frances Haugh * Copyright (c) 1991 - 1994, Julianne Frances Haugh
* Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 1996 - 2000, Marek Michałkiewicz
* Copyright (c) 2000 - 2006, Tomasz Kłoczko * Copyright (c) 2000 - 2006, Tomasz Kłoczko
* Copyright (c) 2007 - 2008, Nicolas François * Copyright (c) 2007 - 2011, Nicolas François
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,6 +45,7 @@
#endif /* ACCT_TOOLS_SETUID */ #endif /* ACCT_TOOLS_SETUID */
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <getopt.h>
#include "defines.h" #include "defines.h"
#include "groupio.h" #include "groupio.h"
#include "nscd.h" #include "nscd.h"
@ -75,19 +76,28 @@ static bool is_shadow_grp;
#define E_GRP_UPDATE 10 /* can't update group file */ #define E_GRP_UPDATE 10 /* can't update group file */
/* local function prototypes */ /* local function prototypes */
static void usage (void); static /*@noreturn@*/void usage (int status);
static void grp_update (void); static void grp_update (void);
static void close_files (void); static void close_files (void);
static void open_files (void); static void open_files (void);
static void group_busy (gid_t); static void group_busy (gid_t gid);
static void process_flags (int argc, char **argv);
/* /*
* usage - display usage message and exit * usage - display usage message and exit
*/ */
static void usage (void) static /*@noreturn@*/void usage (int status)
{ {
fputs (_("Usage: groupdel group\n"), stderr); FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
exit (E_USAGE); (void) fprintf (usageout,
_("Usage: %s [options] GROUP\n"
"\n"
"Options:\n"),
Prog);
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
(void) fputs ("\n", usageout);
exit (status);
} }
/* /*
@ -294,6 +304,42 @@ static void group_busy (gid_t gid)
exit (E_GROUP_BUSY); exit (E_GROUP_BUSY);
} }
/*
* process_flags - parse the command line options
*
* It will not return if an error is encountered.
*/
static void process_flags (int argc, char **argv)
{
/*
* Parse the command line options.
*/
int c;
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"root", required_argument, NULL, 'R'},
{NULL, 0, NULL, '\0'}
};
while ((c = getopt_long (argc, argv, "hR:",
long_options, NULL)) != -1) {
switch (c) {
case 'h':
usage (E_SUCCESS);
/*@notreached@*/break;
case 'R': /* no-op, handled in process_root_flag () */
break;
default:
usage (E_USAGE);
}
}
if (optind != argc - 1) {
usage (E_USAGE);
}
group_name = argv[optind];
}
/* /*
* main - groupdel command * main - groupdel command
* *
@ -313,28 +359,30 @@ int main (int argc, char **argv)
#endif /* USE_PAM */ #endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */ #endif /* ACCT_TOOLS_SETUID */
#ifdef WITH_AUDIT
audit_help_open ();
#endif
atexit (do_cleanups);
/* /*
* Get my name so that I can use it to report errors. * Get my name so that I can use it to report errors.
*/ */
Prog = Basename (argv[0]); Prog = Basename (argv[0]);
(void) setlocale (LC_ALL, ""); (void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR); (void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE); (void) textdomain (PACKAGE);
if (argc != 2) { process_root_flag ("-R", argc, argv);
usage ();
}
group_name = argv[1];
OPENLOG ("groupdel"); OPENLOG ("groupdel");
#ifdef WITH_AUDIT
audit_help_open ();
#endif
if (atexit (do_cleanups) != 0) {
fprintf (stderr,
_("%s: Cannot setup cleanup service.\n"),
Prog);
exit (1);
}
process_flags (argc, argv);
#ifdef ACCT_TOOLS_SETUID #ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM #ifdef USE_PAM