* src/expiry.c, man/expiry.1.xml: Add support for long options.
* src/expiry.c, man/expiry.1.xml: Add -h/--help option
This commit is contained in:
parent
0530588266
commit
b9163f6348
@ -1,3 +1,8 @@
|
|||||||
|
2011-10-30 Nicolas François <nicolas.francois@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@centraliens.net>
|
2011-10-30 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/chfn.c, man/chfn.1.xml: Add support for long options.
|
* src/chfn.c, man/chfn.1.xml: Add support for long options.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright (c) 1990 - 1994, Julianne Frances Haugh
|
Copyright (c) 1990 - 1994, Julianne Frances Haugh
|
||||||
Copyright (c) 1999 , Ben Collins
|
Copyright (c) 1999 , Ben Collins
|
||||||
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
|
||||||
@ -53,8 +53,9 @@
|
|||||||
<refsynopsisdiv id='synopsis'>
|
<refsynopsisdiv id='synopsis'>
|
||||||
<cmdsynopsis>
|
<cmdsynopsis>
|
||||||
<command>expiry</command>
|
<command>expiry</command>
|
||||||
<arg choice='opt'>-c </arg>
|
<arg choice='plain'>
|
||||||
<arg choice='opt'>-f </arg>
|
<replaceable>option</replaceable>
|
||||||
|
</arg>
|
||||||
</cmdsynopsis>
|
</cmdsynopsis>
|
||||||
</refsynopsisdiv>
|
</refsynopsisdiv>
|
||||||
|
|
||||||
@ -67,6 +68,36 @@
|
|||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</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'>
|
<refsect1 id='files'>
|
||||||
<title>FILES</title>
|
<title>FILES</title>
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
86
src/expiry.c
86
src/expiry.c
@ -38,15 +38,20 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
/*@-exitarg@*/
|
||||||
|
#include "exitcodes.h"
|
||||||
|
|
||||||
/* Global variables */
|
/* Global variables */
|
||||||
const char *Prog;
|
const char *Prog;
|
||||||
|
static bool cflg = false;
|
||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
static RETSIGTYPE catch_signals (int);
|
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
|
* catch_signals - signal catcher
|
||||||
@ -59,10 +64,72 @@ static RETSIGTYPE catch_signals (unused int sig)
|
|||||||
/*
|
/*
|
||||||
* usage - print syntax message and exit
|
* usage - print syntax message and exit
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static /*@noreturn@*/void usage (int status)
|
||||||
{
|
{
|
||||||
fputs (_("Usage: expiry {-f|-c}\n"), stderr);
|
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
|
||||||
exit (10);
|
(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -100,11 +167,7 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
OPENLOG ("expiry");
|
OPENLOG ("expiry");
|
||||||
|
|
||||||
if ( (argc != 2)
|
process_flags (argc, argv);
|
||||||
|| ( (strcmp (argv[1], "-f") != 0)
|
|
||||||
&& (strcmp (argv[1], "-c") != 0))) {
|
|
||||||
usage ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get user entries for /etc/passwd and /etc/shadow
|
* Get user entries for /etc/passwd and /etc/shadow
|
||||||
@ -122,8 +185,7 @@ int main (int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* If checking accounts, use agecheck() function.
|
* If checking accounts, use agecheck() function.
|
||||||
*/
|
*/
|
||||||
if (strcmp (argv[1], "-c") == 0) {
|
if (cflg) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print out number of days until expiration.
|
* Print out number of days until expiration.
|
||||||
*/
|
*/
|
||||||
@ -143,6 +205,6 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
expire (pwd, spwd);
|
expire (pwd, spwd);
|
||||||
|
|
||||||
exit (0);
|
return E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user