* NEWS, src/faillog.c, man/faillog.8.xml: Add --root option.

* NEWS, src/lastlog.c, man/lastlog.8.xml: Likewise.
	* src/faillog.c: Add Prog variable, and prefix error messages with
	Prog rather than "faillog".
	* src/lastlog.c: Likewise.
	* src/lastlog.c: Split usage in smaller messages.
This commit is contained in:
nekral-guest 2011-11-06 18:39:03 +00:00
parent 0857837e64
commit a2d23700e4
6 changed files with 118 additions and 49 deletions

View File

@ -1,3 +1,12 @@
2011-10-30 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, src/faillog.c, man/faillog.8.xml: Add --root option.
* NEWS, src/lastlog.c, man/lastlog.8.xml: Likewise.
* src/faillog.c: Add Prog variable, and prefix error messages with
Prog rather than "faillog".
* src/lastlog.c: Likewise.
* src/lastlog.c: Split usage in smaller messages.
2011-10-30 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, src/chage.c, man/chage.1.xml: Add --root option. Open

3
NEWS
View File

@ -37,6 +37,7 @@ shadow-4.1.4.3 -> shadow-4.1.5 UNRELEASED
- faillog
* The -l, -m, -r, -t options only act on the existing users, unless -a is
specified.
* Add --root option.
- gpasswd
* Add --root option.
- groupadd
@ -58,6 +59,8 @@ shadow-4.1.4.3 -> shadow-4.1.5 UNRELEASED
* Add --root option.
- grpunconv
* Add --root option.
- lastlog
* Add --root option.
- login
* Fixed limits support (non PAM enabled versions only)
* Added support for infinite limits and group based limits (non PAM

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 1989 - 1994, Julianne Frances Haugh
Copyright (c) 2007 - 2010, Nicolas François
Copyright (c) 2007 - 2011, Nicolas François
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -159,6 +159,19 @@
</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>
<varlistentry>
<term><option>-t</option>, <option>--time</option>
<replaceable>DAYS</replaceable>

View File

@ -2,7 +2,7 @@
<!--
Copyright (c) 1992 , Julianne Frances Haugh
Copyright (c) 1992 , Phillip Street
Copyright (c) 2007 - 2009, Nicolas François
Copyright (c) 2007 - 2011, Nicolas François
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -92,6 +92,19 @@
<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>
<varlistentry>
<term>
<option>-t</option>, <option>--time</option>

View File

@ -61,6 +61,7 @@ static void reset (void);
/*
* Global variables
*/
const char *Prog; /* Program name */
static FILE *fail; /* failure file stream */
static time_t seconds; /* that number of days in seconds */
static unsigned long umin; /* if uflg and has_umin, only display users with uid >= umin */
@ -87,12 +88,13 @@ static /*@noreturn@*/void usage (int status)
_("Usage: %s [options]\n"
"\n"
"Options:\n"),
"faillog");
Prog);
(void) fputs (_(" -a, --all display faillog records for all users\n"), usageout);
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
(void) fputs (_(" -l, --lock-secs SEC after failed login lock account for SEC seconds\n"), usageout);
(void) fputs (_(" -m, --maximum MAX set maximum failed login counters to MAX\n"), usageout);
(void) fputs (_(" -r, --reset reset the counters of login failures\n"), usageout);
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
(void) fputs (_(" -t, --time DAYS display faillog records more recent than DAYS\n"), usageout);
(void) fputs (_(" -u, --user LOGIN/RANGE display faillog record or maintains failure\n"
" counters and limits (if used with -r, -m,\n"
@ -129,8 +131,8 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force)
*/
if (fread ((char *) &fl, sizeof (fl), 1, fail) != 1) {
fprintf (stderr,
_("faillog: Failed to get the entry for UID %lu\n"),
(unsigned long int)pw->pw_uid);
_("%s: Failed to get the entry for UID %lu\n"),
Prog, (unsigned long int)pw->pw_uid);
return;
}
} else {
@ -229,8 +231,8 @@ static bool reset_one (uid_t uid)
*/
if (fread ((char *) &fl, sizeof (fl), 1, fail) != 1) {
fprintf (stderr,
_("faillog: Failed to get the entry for UID %lu\n"),
(unsigned long int)uid);
_("%s: Failed to get the entry for UID %lu\n"),
Prog, (unsigned long int)uid);
return true;
}
} else {
@ -259,8 +261,8 @@ static bool reset_one (uid_t uid)
}
fprintf (stderr,
_("faillog: Failed to reset fail count for UID %lu\n"),
(unsigned long int)uid);
_("%s: Failed to reset fail count for UID %lu\n"),
Prog, (unsigned long int)uid);
return true;
}
@ -343,8 +345,8 @@ static bool setmax_one (uid_t uid, int max)
*/
if (fread ((char *) &fl, sizeof (fl), 1, fail) != 1) {
fprintf (stderr,
_("faillog: Failed to get the entry for UID %lu\n"),
(unsigned long int)uid);
_("%s: Failed to get the entry for UID %lu\n"),
Prog, (unsigned long int)uid);
return true;
}
} else {
@ -374,8 +376,8 @@ static bool setmax_one (uid_t uid, int max)
}
fprintf (stderr,
_("faillog: Failed to set max for UID %lu\n"),
(unsigned long int)uid);
_("%s: Failed to set max for UID %lu\n"),
Prog, (unsigned long int)uid);
return true;
}
@ -460,8 +462,8 @@ static bool set_locktime_one (uid_t uid, long locktime)
*/
if (fread ((char *) &fl, sizeof (fl), 1, fail) != 1) {
fprintf (stderr,
_("faillog: Failed to get the entry for UID %lu\n"),
(unsigned long int)uid);
_("%s: Failed to get the entry for UID %lu\n"),
Prog, (unsigned long int)uid);
return true;
}
} else {
@ -491,8 +493,8 @@ static bool set_locktime_one (uid_t uid, long locktime)
}
fprintf (stderr,
_("faillog: Failed to set locktime for UID %lu\n"),
(unsigned long int)uid);
_("%s: Failed to set locktime for UID %lu\n"),
Prog, (unsigned long int)uid);
return true;
}
@ -562,10 +564,18 @@ int main (int argc, char **argv)
long fail_max;
long days;
/*
* Get the program name. The program name is used as a prefix to
* most error messages.
*/
Prog = Basename (argv[0]);
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
process_root_flag ("-R", argc, argv);
{
int c;
static struct option long_options[] = {
@ -574,11 +584,12 @@ int main (int argc, char **argv)
{"lock-secs", required_argument, NULL, 'l'},
{"maximum", required_argument, NULL, 'm'},
{"reset", no_argument, NULL, 'r'},
{"root", required_argument, NULL, 'R'},
{"time", required_argument, NULL, 't'},
{"user", required_argument, NULL, 'u'},
{NULL, 0, NULL, '\0'}
};
while ((c = getopt_long (argc, argv, "ahl:m:rt:u:",
while ((c = getopt_long (argc, argv, "ahl:m:rR:t:u:",
long_options, NULL)) != -1) {
switch (c) {
case 'a':
@ -591,7 +602,7 @@ int main (int argc, char **argv)
if (getlong (optarg, &fail_locktime) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
"faillog", optarg);
Prog, optarg);
exit (E_BAD_ARG);
}
lflg = true;
@ -600,7 +611,7 @@ int main (int argc, char **argv)
if (getlong (optarg, &fail_max) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
"faillog", optarg);
Prog, optarg);
exit (E_BAD_ARG);
}
mflg = true;
@ -608,11 +619,13 @@ int main (int argc, char **argv)
case 'r':
rflg = true;
break;
case 'R': /* no-op, handled in process_root_flag () */
break;
case 't':
if (getlong (optarg, &days) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
"faillog", optarg);
Prog, optarg);
exit (E_BAD_ARG);
}
seconds = (time_t) days * DAY;
@ -642,8 +655,8 @@ int main (int argc, char **argv)
&umin, &has_umin,
&umax, &has_umax) == 0) {
fprintf (stderr,
_("faillog: Unknown user or range: %s\n"),
optarg);
_("%s: Unknown user or range: %s\n"),
Prog, optarg);
exit (E_BAD_ARG);
}
}
@ -656,8 +669,8 @@ int main (int argc, char **argv)
}
if (argc > optind) {
fprintf (stderr,
_("faillog: unexpected argument: %s\n"),
argv[optind]);
_("%s: unexpected argument: %s\n"),
Prog, argv[optind]);
usage (EXIT_FAILURE);
}
}
@ -674,16 +687,16 @@ int main (int argc, char **argv)
}
if (NULL == fail) {
fprintf (stderr,
_("faillog: Cannot open %s: %s\n"),
FAILLOG_FILE, strerror (errno));
_("%s: Cannot open %s: %s\n"),
Prog, FAILLOG_FILE, strerror (errno));
exit (E_NOPERM);
}
/* Get the size of the faillog */
if (fstat (fileno (fail), &statbuf) != 0) {
fprintf (stderr,
_("faillog: Cannot get the size of %s: %s\n"),
FAILLOG_FILE, strerror (errno));
_("%s: Cannot get the size of %s: %s\n"),
Prog, FAILLOG_FILE, strerror (errno));
exit (E_NOPERM);
}

View File

@ -2,7 +2,7 @@
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
* Copyright (c) 2000 - 2006, Tomasz Kłoczko
* Copyright (c) 2007 - 2009, Nicolas François
* Copyright (c) 2007 - 2011, Nicolas François
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -44,6 +44,8 @@
#include <assert.h>
#include "defines.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
/*
* Needed for MkLinux DR1/2/2.1 - J.
@ -55,6 +57,7 @@
/*
* Global variables
*/
const char *Prog; /* Program name */
static FILE *lastlogfile; /* lastlog file stream */
static unsigned long umin; /* if uflg and has_umin, only display users with uid >= umin */
static bool has_umin = false;
@ -73,14 +76,18 @@ static bool bflg = false; /* print excludes most recent days */
static /*@noreturn@*/void usage (int status)
{
fputs (_("Usage: lastlog [options]\n"
"\n"
"Options:\n"
" -b, --before DAYS print only lastlog records older than DAYS\n"
" -h, --help display this help message and exit\n"
" -t, --time DAYS print only lastlog records more recent than DAYS\n"
" -u, --user LOGIN print lastlog record of the specified LOGIN\n"
"\n"), (EXIT_SUCCESS != status) ? stderr : stdout);
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
(void) fprintf (usageout,
_("Usage: %s [options]\n"
"\n"
"Options:\n"),
Prog);
(void) fputs (_(" -b, --before DAYS print only lastlog records older than DAYS\n"), usageout);
(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 (_(" -t, --time DAYS print only lastlog records more recent than DAYS\n"), usageout);
(void) fputs (_(" -u, --user LOGIN print lastlog record of the specified LOGIN\n"), usageout);
(void) fputs ("\n", usageout);
exit (status);
}
@ -113,8 +120,8 @@ static void print_one (/*@null@*/const struct passwd *pw)
*/
if (fread ((char *) &ll, sizeof (ll), 1, lastlogfile) != 1) {
fprintf (stderr,
_("lastlog: Failed to get the entry for UID %lu\n"),
(unsigned long int)pw->pw_uid);
_("%s: Failed to get the entry for UID %lu\n"),
Prog, (unsigned long int)pw->pw_uid);
exit (EXIT_FAILURE);
}
} else {
@ -189,21 +196,30 @@ static void print (void)
int main (int argc, char **argv)
{
/*
* Get the program name. The program name is used as a prefix to
* most error messages.
*/
Prog = Basename (argv[0]);
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
process_root_flag ("-R", argc, argv);
{
int c;
static struct option const longopts[] = {
{"help", no_argument, NULL, 'h'},
{"time", required_argument, NULL, 't'},
{"before", required_argument, NULL, 'b'},
{"root", required_argument, NULL, 'R'},
{"user", required_argument, NULL, 'u'},
{NULL, 0, NULL, '\0'}
};
while ((c = getopt_long (argc, argv, "ht:b:u:", longopts,
while ((c = getopt_long (argc, argv, "ht:b:R:u:", longopts,
NULL)) != -1) {
switch (c) {
case 'h':
@ -215,7 +231,7 @@ int main (int argc, char **argv)
if (getulong (optarg, &days) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
"lastlog", optarg);
Prog, optarg);
exit (EXIT_FAILURE);
}
seconds = (time_t) days * DAY;
@ -228,13 +244,15 @@ int main (int argc, char **argv)
if (getulong (optarg, &inverse_days) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
"lastlog", optarg);
Prog, optarg);
exit (EXIT_FAILURE);
}
inverse_seconds = (time_t) inverse_days * DAY;
bflg = true;
break;
}
case 'R': /* no-op, handled in process_root_flag () */
break;
case 'u':
{
const struct passwd *pwent;
@ -258,8 +276,8 @@ int main (int argc, char **argv)
&umin, &has_umin,
&umax, &has_umax) == 0) {
fprintf (stderr,
_("lastlog: Unknown user or range: %s\n"),
optarg);
_("%s: Unknown user or range: %s\n"),
Prog, optarg);
exit (EXIT_FAILURE);
}
}
@ -272,8 +290,8 @@ int main (int argc, char **argv)
}
if (argc > optind) {
fprintf (stderr,
_("lastlog: unexpected argument: %s\n"),
argv[optind]);
_("%s: unexpected argument: %s\n"),
Prog, argv[optind]);
usage (EXIT_FAILURE);
}
}
@ -287,8 +305,8 @@ int main (int argc, char **argv)
/* Get the lastlog size */
if (fstat (fileno (lastlogfile), &statbuf) != 0) {
fprintf (stderr,
_("lastlog: Cannot get the size of %s: %s\n"),
LASTLOG_FILE, strerror (errno));
_("%s: Cannot get the size of %s: %s\n"),
Prog, LASTLOG_FILE, strerror (errno));
exit (EXIT_FAILURE);
}