<!--
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
<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>
</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>
#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
/*
* 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);
+ }
}
/*
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
/*
* If checking accounts, use agecheck() function.
*/
- if (strcmp (argv[1], "-c") == 0) {
-
+ if (cflg) {
/*
* Print out number of days until expiration.
*/
*/
expire (pwd, spwd);
- exit (0);
+ return E_SUCCESS;
}