[Pkg-shadow-commits] r3555 - in upstream/trunk: . man src

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Sun Nov 6 18:39:30 UTC 2011


Author: nekral-guest
Date: 2011-11-06 18:39:30 +0000 (Sun, 06 Nov 2011)
New Revision: 3555

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/man/expiry.1.xml
   upstream/trunk/src/expiry.c
Log:
	* src/expiry.c, man/expiry.1.xml: Add support for long options.
	* src/expiry.c, man/expiry.1.xml: Add -h/--help option

Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2011-11-06 18:39:24 UTC (rev 3554)
+++ upstream/trunk/ChangeLog	2011-11-06 18:39:30 UTC (rev 3555)
@@ -1,5 +1,10 @@
 2011-10-30  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/expiry.c, man/expiry.1.xml: Add support for long options.
+	* src/expiry.c, man/expiry.1.xml: Add -h/--help option
+
+2011-10-30  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/chfn.c, man/chfn.1.xml: Add support for long options.
 	* src/chfn.c, man/chfn.1.xml: Add -u/--help option
 	* NEWS, src/chfn.c, man/chfn.1.xml: Add --root option.

Modified: upstream/trunk/man/expiry.1.xml
===================================================================
--- upstream/trunk/man/expiry.1.xml	2011-11-06 18:39:24 UTC (rev 3554)
+++ upstream/trunk/man/expiry.1.xml	2011-11-06 18:39:30 UTC (rev 3555)
@@ -2,7 +2,7 @@
 <!--
    Copyright (c) 1990 - 1994, Julianne Frances Haugh
    Copyright (c) 1999       , Ben Collins
-   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
@@ -53,8 +53,9 @@
   <refsynopsisdiv id='synopsis'>
     <cmdsynopsis>
       <command>expiry</command>
-      <arg choice='opt'>-c </arg>
-      <arg choice='opt'>-f </arg>
+      <arg choice='plain'>
+	<replaceable>option</replaceable>
+      </arg>
     </cmdsynopsis>
   </refsynopsisdiv>
 
@@ -67,6 +68,36 @@
     </para>
   </refsect1>
 
+  <refsect1 id='options'>
+    <title>OPTIONS</title>
+    <para>
+      The options which apply to the <command>expiry</command> command are:
+    </para>
+    <variablelist remap='IP'>
+      <varlistentry>
+	<term><option>-c</option>, <option>--check</option></term>
+	<listitem>
+	  <para>Check the password expiration of the current user.</para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><option>-f</option>, <option>--force</option></term>
+	<listitem>
+	  <para>
+	    Force a password change if the current user has an expired
+	    password.
+	  </para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
+	<term><option>-h</option>, <option>--help</option></term>
+	<listitem>
+	  <para>Display help message and exit.</para>
+	</listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
   <refsect1 id='files'>
     <title>FILES</title>
     <variablelist>

Modified: upstream/trunk/src/expiry.c
===================================================================
--- upstream/trunk/src/expiry.c	2011-11-06 18:39:24 UTC (rev 3554)
+++ upstream/trunk/src/expiry.c	2011-11-06 18:39:30 UTC (rev 3555)
@@ -38,15 +38,20 @@
 #include <signal.h>
 #include <stdio.h>
 #include <sys/types.h>
+#include <getopt.h>
 #include "defines.h"
 #include "prototypes.h"
+/*@-exitarg@*/
+#include "exitcodes.h"
 
 /* Global variables */
 const char *Prog;
+static bool cflg = false;
 
 /* local function prototypes */
 static RETSIGTYPE catch_signals (int);
-static void usage (void);
+static /*@noreturn@*/void usage (int status);
+static void process_flags (int argc, char **argv);
 
 /*
  * catch_signals - signal catcher
@@ -59,12 +64,74 @@
 /*
  * usage - print syntax message and exit
  */
-static void usage (void)
+static /*@noreturn@*/void usage (int status)
 {
-	fputs (_("Usage: expiry {-f|-c}\n"), stderr);
-	exit (10);
+	FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
+	(void) fprintf (usageout,
+	                _("Usage: %s [options]\n"
+	                  "\n"
+	                  "Options:\n"),
+	                Prog);
+	(void) fputs (_("  -c, --check                   check the user's password expiration\n"), usageout);
+	(void) fputs (_("  -f, --force                   force password change if the user's password\n"
+	                "                                is expired\n"), usageout);
+	(void) fputs (_("  -h, --help                    display this help message and exit\n"), usageout);
+	(void) fputs ("\n", usageout);
+	exit (status);
 }
 
+/*
+ * process_flags - parse the command line options
+ *
+ *	It will not return if an error is encountered.
+ */
+static void process_flags (int argc, char **argv)
+{
+	bool fflg = false;
+	int c;
+	static struct option long_options[] = {
+		{"check", no_argument, NULL, 'c'},
+		{"force", no_argument, NULL, 'f'},
+		{"help",  no_argument, NULL, 'h'},
+		{NULL, 0, NULL, '\0'}
+	};
+
+	while ((c = getopt_long (argc, argv, "cfh",
+	                         long_options, NULL)) != -1) {
+		switch (c) {
+		case 'c':
+			cflg = true;
+			break;
+		case 'f':
+			fflg = true;
+			break;
+		case 'h':
+			usage (E_SUCCESS);
+			/*@notreached@*/break;
+		default:
+			usage (E_USAGE);
+		}
+	}
+
+	if (! (cflg || fflg)) {
+		usage (E_USAGE);
+	}
+
+	if (cflg && fflg) {
+		fprintf (stderr,
+		         _("%s: options %s and %s conflict\n"),
+		         Prog, "-c", "-f");
+		usage (E_USAGE);
+	}
+
+	if (argc != optind) {
+		fprintf (stderr,
+		         _("%s: unexpected argument: %s\n"),
+		         Prog, argv[optind]);
+		usage (E_USAGE);
+	}
+}
+
 /* 
  * expiry - check and enforce password expiration policy
  *
@@ -100,11 +167,7 @@
 
 	OPENLOG ("expiry");
 
-	if (   (argc != 2)
-	    || (   (strcmp (argv[1], "-f") != 0)
-	        && (strcmp (argv[1], "-c") != 0))) {
-		usage ();
-	}
+	process_flags (argc, argv);
 
 	/*
 	 * Get user entries for /etc/passwd and /etc/shadow
@@ -122,8 +185,7 @@
 	/*
 	 * If checking accounts, use agecheck() function.
 	 */
-	if (strcmp (argv[1], "-c") == 0) {
-
+	if (cflg) {
 		/*
 		 * Print out number of days until expiration.
 		 */
@@ -143,6 +205,6 @@
 	 */
 	expire (pwd, spwd);
 
-	exit (0);
+	return E_SUCCESS;
 }
 




More information about the Pkg-shadow-commits mailing list