* 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/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
- 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
* 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
<?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
</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>
<!--
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
<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>
/*
* 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 */
_("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"
*/
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 {
*/
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 {
}
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;
}
*/
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 {
}
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;
}
*/
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 {
}
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;
}
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[] = {
{"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':
if (getlong (optarg, &fail_locktime) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
- "faillog", optarg);
+ Prog, optarg);
exit (E_BAD_ARG);
}
lflg = true;
if (getlong (optarg, &fail_max) == 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
- "faillog", optarg);
+ Prog, optarg);
exit (E_BAD_ARG);
}
mflg = true;
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;
&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);
}
}
}
if (argc > optind) {
fprintf (stderr,
- _("faillog: unexpected argument: %s\n"),
- argv[optind]);
+ _("%s: unexpected argument: %s\n"),
+ Prog, argv[optind]);
usage (EXIT_FAILURE);
}
}
}
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);
}
* 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
#include <assert.h>
#include "defines.h"
#include "prototypes.h"
+/*@-exitarg@*/
+#include "exitcodes.h"
/*
* Needed for MkLinux DR1/2/2.1 - J.
/*
* 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;
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);
}
*/
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 {
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':
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;
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;
&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);
}
}
}
if (argc > optind) {
fprintf (stderr,
- _("lastlog: unexpected argument: %s\n"),
- argv[optind]);
+ _("%s: unexpected argument: %s\n"),
+ Prog, argv[optind]);
usage (EXIT_FAILURE);
}
}
/* 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);
}