]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
* src/groupdel.c: Add process_flags().
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 6 Nov 2011 18:37:57 +0000 (18:37 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sun, 6 Nov 2011 18:37:57 +0000 (18:37 +0000)
* 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.

ChangeLog
NEWS
man/groupdel.8.xml
src/groupdel.c

index ed40e03ad80c9885fa84568adcda681b9f2e11f8..05b737714bc0ae58828d2fdefe35877d48d847c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * NEWS, src/groupadd.c, man/groupadd.8.xml: Add --root option. Open
        audit and syslog after the potential chroot.
        * 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>
 
diff --git a/NEWS b/NEWS
index 413664d205ea23af96a36707b5597a64c9dced86..a109e7c4e10c8d49e63224d90db58b9e4e833c93 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,8 @@ shadow-4.1.4.3 -> shadow-4.1.5                                        UNRELEASED
     specified.
 - groupadd
   * Add --root option.
+- groupdel
+  * Add --root option.
 - groupmod
   * Fixed groupmod when configured with --enable-account-tools-setuid.
   * When the gshadow file exists but there are no gshadow entries, an entry
index 4cc508ef73933669253956579de209c4e6833952..557afed615a90d11b157b18e90eee4ddd7881e87 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
    Copyright (c) 1991 - 1993, Julianne Frances Haugh
-   Copyright (c) 2007 - 2008, Nicolas François
+   Copyright (c) 2007 - 2011, Nicolas François
    All rights reserved.
   
    Redistribution and use in source and binary forms, with or without
   <refsynopsisdiv id='synopsis'>
     <cmdsynopsis>
       <command>groupdel</command>
-      <arg choice='plain'>
-       <replaceable>group</replaceable>
+      <arg choice='opt'>
+        <replaceable>options</replaceable>
       </arg>
+      <arg choice='plain'><replaceable>GROUP</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
 
   <refsect1 id='description'>
     <title>DESCRIPTION</title>
     <para> The <command>groupdel</command> command modifies the system
-      account files, deleting all entries that refer to <emphasis
-      remap='I'>group</emphasis>. The named group must exist.
+      account files, deleting all entries that refer to
+      <replaceable>GROUP</replaceable>. The named group must exist.
     </para>
   </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'>
     <title>CAVEATS</title>
     <para>
 
   <refsect1 id='see_also'>
     <title>SEE ALSO</title>
-    <para><citerefentry>
+    <para>
+      <citerefentry>
        <refentrytitle>chfn</refentrytitle><manvolnum>1</manvolnum>
       </citerefentry>,
       <citerefentry>
       </citerefentry>,
       <citerefentry>
        <refentrytitle>usermod</refentrytitle><manvolnum>8</manvolnum>
-      </citerefentry>
+      </citerefentry>.
     </para>
   </refsect1>
 </refentry>
index afd28b1b657775a2dbac84617e83478fda1853a8..1a7de7097461e916cb5a6faaa109a66cde441d10 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1991 - 1994, Julianne Frances Haugh
  * Copyright (c) 1996 - 2000, Marek Michałkiewicz
  * Copyright (c) 2000 - 2006, Tomasz Kłoczko
- * Copyright (c) 2007 - 2008, Nicolas François
+ * Copyright (c) 2007 - 2011, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@
 #endif                         /* ACCT_TOOLS_SETUID */
 #include <stdio.h>
 #include <sys/types.h>
+#include <getopt.h>
 #include "defines.h"
 #include "groupio.h"
 #include "nscd.h"
@@ -75,19 +76,28 @@ static bool is_shadow_grp;
 #define E_GRP_UPDATE   10      /* can't update group file */
 
 /* local function prototypes */
-static void usage (void);
+static /*@noreturn@*/void usage (int status);
 static void grp_update (void);
 static void close_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
  */
-static void usage (void)
+static /*@noreturn@*/void usage (int status)
 {
-       fputs (_("Usage: groupdel group\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 (_("  -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);
 }
 
+/*
+ * 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
  *
@@ -313,28 +359,30 @@ int main (int argc, char **argv)
 #endif                         /* USE_PAM */
 #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.
         */
-
        Prog = Basename (argv[0]);
 
        (void) setlocale (LC_ALL, "");
        (void) bindtextdomain (PACKAGE, LOCALEDIR);
        (void) textdomain (PACKAGE);
 
-       if (argc != 2) {
-               usage ();
-       }
-
-       group_name = argv[1];
+       process_root_flag ("-R", argc, argv);
 
        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 USE_PAM