2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2011, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <lastlog.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <pwd.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <time.h>
|
2009-03-14 03:50:20 +05:30
|
|
|
#include <assert.h>
|
2020-05-25 02:52:34 +05:30
|
|
|
#ifdef HAVE_LL_HOST
|
|
|
|
#include <net/if.h>
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "defines.h"
|
2007-10-07 17:17:01 +05:30
|
|
|
#include "prototypes.h"
|
2018-11-28 19:27:16 +05:30
|
|
|
#include "getdef.h"
|
2011-11-07 00:09:03 +05:30
|
|
|
/*@-exitarg@*/
|
|
|
|
#include "exitcodes.h"
|
2021-11-29 05:07:53 +05:30
|
|
|
#include "shadowlog.h"
|
2008-06-10 00:45:27 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Needed for MkLinux DR1/2/2.1 - J.
|
|
|
|
*/
|
|
|
|
#ifndef LASTLOG_FILE
|
|
|
|
#define LASTLOG_FILE "/var/log/lastlog"
|
|
|
|
#endif
|
2008-06-10 00:45:27 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2011-11-07 00:09:03 +05:30
|
|
|
const char *Prog; /* Program name */
|
2007-10-07 17:14:02 +05:30
|
|
|
static FILE *lastlogfile; /* lastlog file stream */
|
2009-03-14 03:50:20 +05:30
|
|
|
static unsigned long umin; /* if uflg and has_umin, only display users with uid >= umin */
|
2008-06-15 02:36:53 +05:30
|
|
|
static bool has_umin = false;
|
2009-03-14 03:50:20 +05:30
|
|
|
static unsigned long umax; /* if uflg and has_umax, only display users with uid <= umax */
|
2008-06-15 02:36:53 +05:30
|
|
|
static bool has_umax = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
static time_t seconds; /* that number of days in seconds */
|
2007-10-07 17:17:01 +05:30
|
|
|
static time_t inverse_seconds; /* that number of days in seconds */
|
2009-03-14 03:50:20 +05:30
|
|
|
static struct stat statbuf; /* fstat buffer for file size */
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-10 00:45:27 +05:30
|
|
|
static bool uflg = false; /* print only an user of range of users */
|
|
|
|
static bool tflg = false; /* print is restricted to most recent days */
|
|
|
|
static bool bflg = false; /* print excludes most recent days */
|
2016-03-03 20:07:01 +05:30
|
|
|
static bool Cflg = false; /* clear record for user */
|
|
|
|
static bool Sflg = false; /* set record for user */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#define NOW (time ((time_t *) 0))
|
|
|
|
|
2011-07-23 13:40:27 +05:30
|
|
|
static /*@noreturn@*/void usage (int status)
|
2007-10-07 17:15:58 +05:30
|
|
|
{
|
2011-11-07 00:09:03 +05:30
|
|
|
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);
|
2016-03-03 20:07:01 +05:30
|
|
|
(void) fputs (_(" -C, --clear clear lastlog record of an user (usable only with -u)\n"), usageout);
|
2011-11-07 00:09:03 +05:30
|
|
|
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
|
|
|
|
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
2016-03-03 20:07:01 +05:30
|
|
|
(void) fputs (_(" -S, --set set lastlog record to current time (usable only with -u)\n"), usageout);
|
2011-11-07 00:09:03 +05:30
|
|
|
(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);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
exit (status);
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 16:51:01 +05:30
|
|
|
static void print_one (/*@null@*/const struct passwd *pw)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-06-10 00:45:27 +05:30
|
|
|
static bool once = false;
|
2007-10-07 17:15:58 +05:30
|
|
|
char *cp;
|
|
|
|
struct tm *tm;
|
|
|
|
time_t ll_time;
|
2009-03-14 03:50:20 +05:30
|
|
|
off_t offset;
|
|
|
|
struct lastlog ll;
|
2007-10-07 17:15:58 +05:30
|
|
|
char ptime[80];
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2020-05-25 02:52:34 +05:30
|
|
|
#ifdef HAVE_LL_HOST
|
|
|
|
int maxIPv6Addrlen;
|
|
|
|
#endif
|
|
|
|
|
2008-06-10 00:45:27 +05:30
|
|
|
if (NULL == pw) {
|
2007-10-07 17:15:58 +05:30
|
|
|
return;
|
2008-06-10 00:45:27 +05:30
|
|
|
}
|
2007-10-07 17:15:58 +05:30
|
|
|
|
2009-03-14 03:50:20 +05:30
|
|
|
|
2011-06-03 01:56:30 +05:30
|
|
|
offset = (off_t) pw->pw_uid * sizeof (ll);
|
|
|
|
if (offset + sizeof (ll) <= statbuf.st_size) {
|
2009-03-14 03:50:20 +05:30
|
|
|
/* fseeko errors are not really relevant for us. */
|
2009-04-25 04:35:29 +05:30
|
|
|
int err = fseeko (lastlogfile, offset, SEEK_SET);
|
|
|
|
assert (0 == err);
|
2009-03-14 03:50:20 +05:30
|
|
|
/* lastlog is a sparse file. Even if no entries were
|
|
|
|
* entered for this user, which should be able to get the
|
|
|
|
* empty entry in this case.
|
|
|
|
*/
|
|
|
|
if (fread ((char *) &ll, sizeof (ll), 1, lastlogfile) != 1) {
|
|
|
|
fprintf (stderr,
|
2011-11-07 00:09:03 +05:30
|
|
|
_("%s: Failed to get the entry for UID %lu\n"),
|
|
|
|
Prog, (unsigned long int)pw->pw_uid);
|
2009-04-23 16:51:01 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2009-03-14 03:50:20 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Outsize of the lastlog file.
|
|
|
|
* Behave as if there were a missing entry (same behavior
|
|
|
|
* as if we were reading an non existing entry in the
|
|
|
|
* sparse lastlog file).
|
|
|
|
*/
|
|
|
|
memzero (&ll, sizeof (ll));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Filter out entries that do not match with the -t or -b options */
|
|
|
|
if (tflg && ((NOW - ll.ll_time) > seconds)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bflg && ((NOW - ll.ll_time) < inverse_seconds)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print the header only once */
|
2007-10-07 17:15:58 +05:30
|
|
|
if (!once) {
|
|
|
|
#ifdef HAVE_LL_HOST
|
2020-05-25 02:52:34 +05:30
|
|
|
/*
|
|
|
|
* ll_host is in minimized form, thus the maximum IPv6 address possible is
|
|
|
|
* 8*4+7 = 39 characters.
|
|
|
|
* RFC 4291 2.5.6 states that for LL-addresses fe80+only the interface ID is set,
|
|
|
|
* thus having a maximum size of 25+1+IFNAMSIZ.
|
|
|
|
* POSIX says IFNAMSIZ should be 16 characters long including the null byte, thus
|
|
|
|
* 25+1+IFNAMSIZ >= 42 > 39
|
|
|
|
*/
|
|
|
|
/* Link-Local address + % + Interfacename */
|
|
|
|
maxIPv6Addrlen = 25+1+IFNAMSIZ;
|
|
|
|
printf (_("Username Port From%*sLatest\n"), maxIPv6Addrlen-3, " ");
|
2007-10-07 17:15:58 +05:30
|
|
|
#else
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("Username Port Latest"));
|
2007-10-07 17:15:58 +05:30
|
|
|
#endif
|
2008-06-10 00:45:27 +05:30
|
|
|
once = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2009-03-14 03:50:20 +05:30
|
|
|
|
|
|
|
ll_time = ll.ll_time;
|
2007-10-07 17:15:58 +05:30
|
|
|
tm = localtime (&ll_time);
|
|
|
|
strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm);
|
|
|
|
cp = ptime;
|
|
|
|
|
2009-03-14 03:50:20 +05:30
|
|
|
if (ll.ll_time == (time_t) 0) {
|
2007-10-07 17:15:58 +05:30
|
|
|
cp = _("**Never logged in**\0");
|
2008-06-10 00:45:27 +05:30
|
|
|
}
|
2007-10-07 17:15:58 +05:30
|
|
|
|
|
|
|
#ifdef HAVE_LL_HOST
|
2020-05-25 02:52:34 +05:30
|
|
|
printf ("%-16s %-8.8s %*s%s\n",
|
|
|
|
pw->pw_name, ll.ll_line, -maxIPv6Addrlen, ll.ll_host, cp);
|
2007-10-07 17:15:58 +05:30
|
|
|
#else
|
2009-03-14 03:50:20 +05:30
|
|
|
printf ("%-16s\t%-8.8s %s\n",
|
|
|
|
pw->pw_name, ll.ll_line, cp);
|
2007-10-07 17:15:58 +05:30
|
|
|
#endif
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void print (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2009-04-23 16:51:01 +05:30
|
|
|
const struct passwd *pwent;
|
2018-11-28 19:27:16 +05:30
|
|
|
unsigned long lastlog_uid_max;
|
|
|
|
|
|
|
|
lastlog_uid_max = getdef_ulong ("LASTLOG_UID_MAX", 0xFFFFFFFFUL);
|
|
|
|
if ( (has_umin && umin > lastlog_uid_max)
|
|
|
|
|| (has_umax && umax > lastlog_uid_max)) {
|
|
|
|
fprintf (stderr, _("%s: Selected uid(s) are higher than LASTLOG_UID_MAX (%lu),\n"
|
|
|
|
"\tthe output might be incorrect.\n"), Prog, lastlog_uid_max);
|
|
|
|
}
|
|
|
|
|
2009-03-14 03:50:20 +05:30
|
|
|
if (uflg && has_umin && has_umax && (umin == umax)) {
|
|
|
|
print_one (getpwuid ((uid_t)umin));
|
|
|
|
} else {
|
|
|
|
setpwent ();
|
|
|
|
while ( (pwent = getpwent ()) != NULL ) {
|
|
|
|
if ( uflg
|
|
|
|
&& ( (has_umin && (pwent->pw_uid < (uid_t)umin))
|
|
|
|
|| (has_umax && (pwent->pw_uid > (uid_t)umax)))) {
|
|
|
|
continue;
|
2018-11-28 19:27:16 +05:30
|
|
|
} else if ( !uflg && pwent->pw_uid > (uid_t) lastlog_uid_max) {
|
|
|
|
continue;
|
2009-03-14 03:50:20 +05:30
|
|
|
}
|
|
|
|
print_one (pwent);
|
2008-06-10 00:45:27 +05:30
|
|
|
}
|
2009-03-14 03:50:20 +05:30
|
|
|
endpwent ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-03 20:07:01 +05:30
|
|
|
static void update_one (/*@null@*/const struct passwd *pw)
|
|
|
|
{
|
|
|
|
off_t offset;
|
|
|
|
struct lastlog ll;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (NULL == pw) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = (off_t) pw->pw_uid * sizeof (ll);
|
|
|
|
/* fseeko errors are not really relevant for us. */
|
|
|
|
err = fseeko (lastlogfile, offset, SEEK_SET);
|
|
|
|
assert (0 == err);
|
|
|
|
|
|
|
|
memzero (&ll, sizeof (ll));
|
|
|
|
|
|
|
|
if (Sflg) {
|
|
|
|
ll.ll_time = NOW;
|
|
|
|
#ifdef HAVE_LL_HOST
|
|
|
|
strcpy (ll.ll_host, "localhost");
|
|
|
|
#endif
|
|
|
|
strcpy (ll.ll_line, "lastlog");
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_ACCT_UNLOCK, Prog,
|
|
|
|
"clearing-lastlog",
|
|
|
|
pw->pw_name, (unsigned int) pw->pw_uid, SHADOW_AUDIT_SUCCESS);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
else {
|
|
|
|
audit_logger (AUDIT_ACCT_UNLOCK, Prog,
|
|
|
|
"refreshing-lastlog",
|
|
|
|
pw->pw_name, (unsigned int) pw->pw_uid, SHADOW_AUDIT_SUCCESS);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fwrite (&ll, sizeof(ll), 1, lastlogfile) != 1) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Failed to update the entry for UID %lu\n"),
|
|
|
|
Prog, (unsigned long int)pw->pw_uid);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update (void)
|
|
|
|
{
|
|
|
|
const struct passwd *pwent;
|
2018-11-28 19:27:16 +05:30
|
|
|
unsigned long lastlog_uid_max;
|
2016-03-03 20:07:01 +05:30
|
|
|
|
|
|
|
if (!uflg) /* safety measure */
|
|
|
|
return;
|
|
|
|
|
2018-11-28 19:27:16 +05:30
|
|
|
lastlog_uid_max = getdef_ulong ("LASTLOG_UID_MAX", 0xFFFFFFFFUL);
|
|
|
|
if ( (has_umin && umin > lastlog_uid_max)
|
|
|
|
|| (has_umax && umax > lastlog_uid_max)) {
|
|
|
|
fprintf (stderr, _("%s: Selected uid(s) are higher than LASTLOG_UID_MAX (%lu),\n"
|
|
|
|
"\tthey will not be updated.\n"), Prog, lastlog_uid_max);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-03 20:07:01 +05:30
|
|
|
if (has_umin && has_umax && (umin == umax)) {
|
|
|
|
update_one (getpwuid ((uid_t)umin));
|
|
|
|
} else {
|
|
|
|
setpwent ();
|
|
|
|
while ( (pwent = getpwent ()) != NULL ) {
|
|
|
|
if ((has_umin && (pwent->pw_uid < (uid_t)umin))
|
|
|
|
|| (has_umax && (pwent->pw_uid > (uid_t)umax))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
update_one (pwent);
|
|
|
|
}
|
|
|
|
endpwent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fflush (lastlogfile) != 0 || fsync (fileno (lastlogfile)) != 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Failed to update the lastlog file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:15:58 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2011-11-07 00:09:03 +05:30
|
|
|
/*
|
|
|
|
* Get the program name. The program name is used as a prefix to
|
|
|
|
* most error messages.
|
|
|
|
*/
|
|
|
|
Prog = Basename (argv[0]);
|
2021-11-29 05:07:53 +05:30
|
|
|
log_set_progname(Prog);
|
|
|
|
log_set_logfd(stderr);
|
2011-11-07 00:09:03 +05:30
|
|
|
|
2008-06-10 00:45:27 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-11-07 00:09:03 +05:30
|
|
|
process_root_flag ("-R", argc, argv);
|
|
|
|
|
2016-03-03 20:07:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_help_open ();
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:15:58 +05:30
|
|
|
{
|
|
|
|
int c;
|
|
|
|
static struct option const longopts[] = {
|
2007-10-07 17:17:01 +05:30
|
|
|
{"before", required_argument, NULL, 'b'},
|
2016-03-03 20:07:01 +05:30
|
|
|
{"clear", no_argument, NULL, 'C'},
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"root", required_argument, NULL, 'R'},
|
2016-03-03 20:07:01 +05:30
|
|
|
{"set", no_argument, NULL, 'S'},
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
{"time", required_argument, NULL, 't'},
|
|
|
|
{"user", required_argument, NULL, 'u'},
|
2007-10-07 17:15:58 +05:30
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
|
|
|
|
2016-03-03 20:07:01 +05:30
|
|
|
while ((c = getopt_long (argc, argv, "b:ChR:St:u:", longopts,
|
2009-03-14 03:50:20 +05:30
|
|
|
NULL)) != -1) {
|
2007-10-07 17:15:58 +05:30
|
|
|
switch (c) {
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
case 'b':
|
2009-04-29 00:55:15 +05:30
|
|
|
{
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
unsigned long inverse_days;
|
|
|
|
if (getulong (optarg, &inverse_days) == 0) {
|
2009-04-29 00:55:15 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid numeric argument '%s'\n"),
|
2011-11-07 00:09:03 +05:30
|
|
|
Prog, optarg);
|
2009-04-29 00:55:15 +05:30
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
inverse_seconds = (time_t) inverse_days * DAY;
|
|
|
|
bflg = true;
|
2007-10-07 17:15:58 +05:30
|
|
|
break;
|
2009-04-29 00:55:15 +05:30
|
|
|
}
|
2016-03-03 20:07:01 +05:30
|
|
|
case 'C':
|
|
|
|
{
|
|
|
|
Cflg = true;
|
|
|
|
break;
|
|
|
|
}
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
case 'h':
|
|
|
|
usage (EXIT_SUCCESS);
|
|
|
|
/*@notreached@*/break;
|
|
|
|
case 'R': /* no-op, handled in process_root_flag () */
|
|
|
|
break;
|
2016-03-03 20:07:01 +05:30
|
|
|
case 'S':
|
|
|
|
{
|
|
|
|
Sflg = true;
|
|
|
|
break;
|
|
|
|
}
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
case 't':
|
2009-04-29 00:55:15 +05:30
|
|
|
{
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
unsigned long days;
|
|
|
|
if (getulong (optarg, &days) == 0) {
|
2009-04-29 00:55:15 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid numeric argument '%s'\n"),
|
2011-11-07 00:09:03 +05:30
|
|
|
Prog, optarg);
|
2009-04-29 00:55:15 +05:30
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
seconds = (time_t) days * DAY;
|
|
|
|
tflg = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
2009-04-29 00:55:15 +05:30
|
|
|
}
|
2007-10-07 17:15:58 +05:30
|
|
|
case 'u':
|
2009-04-23 16:51:01 +05:30
|
|
|
{
|
|
|
|
const struct passwd *pwent;
|
2007-12-27 03:24:04 +05:30
|
|
|
/*
|
|
|
|
* The user can be:
|
|
|
|
* - a login name
|
|
|
|
* - numerical
|
|
|
|
* - a numerical login ID
|
|
|
|
* - a range (-x, x-, x-y)
|
|
|
|
*/
|
2008-06-10 00:45:27 +05:30
|
|
|
uflg = true;
|
2009-03-14 03:50:20 +05:30
|
|
|
/* local, no need for xgetpwnam */
|
|
|
|
pwent = getpwnam (optarg);
|
2007-12-27 03:24:04 +05:30
|
|
|
if (NULL != pwent) {
|
2008-06-15 02:36:53 +05:30
|
|
|
umin = (unsigned long) pwent->pw_uid;
|
|
|
|
has_umin = true;
|
2007-12-27 03:24:04 +05:30
|
|
|
umax = umin;
|
2008-06-15 02:36:53 +05:30
|
|
|
has_umax = true;
|
2007-12-27 03:24:04 +05:30
|
|
|
} else {
|
2008-06-15 02:36:53 +05:30
|
|
|
if (getrange (optarg,
|
|
|
|
&umin, &has_umin,
|
|
|
|
&umax, &has_umax) == 0) {
|
2007-12-27 03:24:04 +05:30
|
|
|
fprintf (stderr,
|
2011-11-07 00:09:03 +05:30
|
|
|
_("%s: Unknown user or range: %s\n"),
|
|
|
|
Prog, optarg);
|
2009-04-23 16:51:01 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-12-27 03:24:04 +05:30
|
|
|
}
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
|
|
|
break;
|
2009-04-23 16:51:01 +05:30
|
|
|
}
|
2007-10-07 17:15:58 +05:30
|
|
|
default:
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (EXIT_FAILURE);
|
2011-07-23 13:40:27 +05:30
|
|
|
/*@notreached@*/break;
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
if (argc > optind) {
|
|
|
|
fprintf (stderr,
|
2011-11-07 00:09:03 +05:30
|
|
|
_("%s: unexpected argument: %s\n"),
|
|
|
|
Prog, argv[optind]);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (EXIT_FAILURE);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
2016-03-03 20:07:01 +05:30
|
|
|
if (Cflg && Sflg) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Option -C cannot be used together with option -S\n"),
|
|
|
|
Prog);
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if ((Cflg || Sflg) && !uflg) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Options -C and -S require option -u to specify the user\n"),
|
|
|
|
Prog);
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2016-03-03 20:07:01 +05:30
|
|
|
lastlogfile = fopen (LASTLOG_FILE, (Cflg || Sflg)?"r+":"r");
|
2009-04-23 16:51:01 +05:30
|
|
|
if (NULL == lastlogfile) {
|
2007-10-07 17:15:58 +05:30
|
|
|
perror (LASTLOG_FILE);
|
2009-04-23 16:51:01 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 19:34:48 +05:30
|
|
|
/* Get the lastlog size */
|
2009-03-14 03:50:20 +05:30
|
|
|
if (fstat (fileno (lastlogfile), &statbuf) != 0) {
|
|
|
|
fprintf (stderr,
|
2011-11-07 00:09:03 +05:30
|
|
|
_("%s: Cannot get the size of %s: %s\n"),
|
|
|
|
Prog, LASTLOG_FILE, strerror (errno));
|
2009-04-23 16:51:01 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2009-03-14 03:50:20 +05:30
|
|
|
}
|
|
|
|
|
2016-03-03 20:07:01 +05:30
|
|
|
if (Cflg || Sflg)
|
|
|
|
update ();
|
|
|
|
else
|
|
|
|
print ();
|
2009-04-20 19:34:48 +05:30
|
|
|
|
2009-04-23 16:51:01 +05:30
|
|
|
(void) fclose (lastlogfile);
|
* src/newgrp.c, src/chfn.c, src/groupmems.c, src/usermod.c,
src/userdel.c, src/chpasswd.c, src/grpck.c, src/gpasswd.c,
src/groupdel.c, src/chgpasswd.c, src/vipw.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/faillog.c,
src/sulogin.c, src/chsh.c, src/pwconv.c: Added splint annotations.
* src/userdel.c, src/pwconv.c, src/lastlog.c, src/grpck.c,
src/vipw.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/login.c,
src/sulogin.c, src/usermod.c: Use return instead of exit at the
end of main().
* src/gpasswd.c, src/passwd.c, src/faillog.c: Use the exitcodes.h
exit codes.
* src/chpasswd.c: Added missing ||.
* src/nologin.c: Do not include exitcodes.h.
* src/nologin.c: Added brackets.
* src/nologin.c: Avoid assignments in comparisons.
2009-05-01 03:09:38 +05:30
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 00:45:27 +05:30
|
|
|
|