[svn-upgrade] Integrating new upstream version, shadow (4.0.1)
This commit is contained in:
144
src/lastlog.c
144
src/lastlog.c
@ -17,7 +17,7 @@
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -30,14 +30,12 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID(PKG_VER "$Id: lastlog.c,v 1.9 2000/11/29 12:50:09 kloczek Exp $")
|
||||
|
||||
RCSID (PKG_VER "$Id: lastlog.c,v 1.11 2002/01/05 15:41:43 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#if HAVE_LASTLOG_H
|
||||
@ -45,17 +43,15 @@ RCSID(PKG_VER "$Id: lastlog.c,v 1.9 2000/11/29 12:50:09 kloczek Exp $")
|
||||
#else
|
||||
#include "lastlog_.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Needed for MkLinux DR1/2/2.1 - J.
|
||||
*/
|
||||
#ifndef LASTLOG_FILE
|
||||
#define LASTLOG_FILE "/var/log/lastlog"
|
||||
#endif
|
||||
|
||||
static FILE *lastlogfile; /* lastlog file stream */
|
||||
static off_t user; /* one single user, specified on command line */
|
||||
static int days; /* number of days to consider for print command */
|
||||
static off_t user; /* one single user, specified on command line */
|
||||
static int days; /* number of days to consider for print command */
|
||||
static time_t seconds; /* that number of days in seconds */
|
||||
|
||||
static int uflg = 0; /* set if user is a valid user id */
|
||||
@ -64,79 +60,78 @@ static struct lastlog lastlog; /* scratch structure to play with ... */
|
||||
static struct stat statbuf; /* fstat buffer for file size */
|
||||
static struct passwd *pwent;
|
||||
|
||||
#include <getopt.h>
|
||||
static struct option const longopts[] =
|
||||
{
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"time", required_argument, 0, 't'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
#include <getopt.h>
|
||||
static struct option const longopts[] = {
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"time", required_argument, 0, 't'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
#define NOW (time ((time_t *) 0))
|
||||
|
||||
/* local function prototypes */
|
||||
static void print(void);
|
||||
static void print_one(const struct passwd *);
|
||||
static void print (void);
|
||||
static void print_one (const struct passwd *);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
if ((lastlogfile = fopen (LASTLOG_FILE,"r")) == (FILE *) 0) {
|
||||
if ((lastlogfile = fopen (LASTLOG_FILE, "r")) == (FILE *) 0) {
|
||||
perror (LASTLOG_FILE);
|
||||
exit (1);
|
||||
}
|
||||
while ((c = getopt_long (argc, argv, "u:t:h", longopts, NULL)) != -1) {
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "u:t:h", longopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'u':
|
||||
pwent = getpwnam (optarg);
|
||||
if (!pwent) {
|
||||
fprintf(stderr,
|
||||
_("Unknown User: %s\n"),
|
||||
optarg);
|
||||
exit (1);
|
||||
}
|
||||
uflg++;
|
||||
user = pwent->pw_uid;
|
||||
break;
|
||||
case 't':
|
||||
days = atoi (optarg);
|
||||
seconds = days * DAY;
|
||||
tflg++;
|
||||
break;
|
||||
case 'h':
|
||||
fprintf(stdout, _("Usage: %s [<-u|--login> login-name] [<-t|--time> days] [<-h|--help>]\n"),
|
||||
argv[0]);
|
||||
exit(0);
|
||||
default:
|
||||
fprintf(stdout, _("Usage: %s [<-u|--login> login-name] [<-t|--time> days] [<-h|--help>]\n"),
|
||||
argv[0]);
|
||||
exit(1);
|
||||
case 'u':
|
||||
pwent = getpwnam (optarg);
|
||||
if (!pwent) {
|
||||
fprintf (stderr,
|
||||
_("Unknown User: %s\n"), optarg);
|
||||
exit (1);
|
||||
}
|
||||
uflg++;
|
||||
user = pwent->pw_uid;
|
||||
break;
|
||||
case 't':
|
||||
days = atoi (optarg);
|
||||
seconds = days * DAY;
|
||||
tflg++;
|
||||
break;
|
||||
case 'h':
|
||||
fprintf (stdout,
|
||||
_
|
||||
("Usage: %s [<-u|--login> login-name] [<-t|--time> days] [<-h|--help>]\n"),
|
||||
argv[0]);
|
||||
exit (0);
|
||||
default:
|
||||
fprintf (stdout,
|
||||
_
|
||||
("Usage: %s [<-u|--login> login-name] [<-t|--time> days] [<-h|--help>]\n"),
|
||||
argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
print ();
|
||||
fclose (lastlogfile);
|
||||
exit (0);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
/*NOTREACHED*/}
|
||||
|
||||
static void
|
||||
print(void)
|
||||
static void print (void)
|
||||
{
|
||||
off_t offset;
|
||||
off_t offset;
|
||||
|
||||
if (uflg) {
|
||||
offset = (unsigned long) user * sizeof lastlog;
|
||||
offset = (unsigned long) user *sizeof lastlog;
|
||||
|
||||
if (fstat (fileno (lastlogfile), &statbuf)) {
|
||||
perror(LASTLOG_FILE);
|
||||
perror (LASTLOG_FILE);
|
||||
return;
|
||||
}
|
||||
if (offset >= statbuf.st_size)
|
||||
@ -144,7 +139,7 @@ print(void)
|
||||
|
||||
fseek (lastlogfile, offset, SEEK_SET);
|
||||
if (fread ((char *) &lastlog, sizeof lastlog, 1,
|
||||
lastlogfile) == 1)
|
||||
lastlogfile) == 1)
|
||||
print_one (pwent);
|
||||
else
|
||||
perror (LASTLOG_FILE);
|
||||
@ -152,10 +147,11 @@ print(void)
|
||||
setpwent ();
|
||||
while ((pwent = getpwent ())) {
|
||||
user = pwent->pw_uid;
|
||||
offset = (unsigned long) user * sizeof lastlog;
|
||||
offset = (unsigned long) user *sizeof lastlog;
|
||||
|
||||
fseek (lastlogfile, offset, SEEK_SET);
|
||||
if (fread ((char *) &lastlog, sizeof lastlog, 1,
|
||||
lastlogfile) != 1)
|
||||
lastlogfile) != 1)
|
||||
continue;
|
||||
|
||||
if (tflg && NOW - lastlog.ll_time > seconds)
|
||||
@ -166,44 +162,44 @@ print(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_one(const struct passwd *pw)
|
||||
static void print_one (const struct passwd *pw)
|
||||
{
|
||||
static int once;
|
||||
char *cp;
|
||||
struct tm *tm;
|
||||
static int once;
|
||||
char *cp;
|
||||
struct tm *tm;
|
||||
|
||||
#ifdef HAVE_STRFTIME
|
||||
char ptime[80];
|
||||
#endif
|
||||
|
||||
if (! pw)
|
||||
if (!pw)
|
||||
return;
|
||||
|
||||
if (! once) {
|
||||
if (!once) {
|
||||
#ifdef HAVE_LL_HOST
|
||||
printf(_("Username Port From Latest\n"));
|
||||
printf (_
|
||||
("Username Port From Latest\n"));
|
||||
#else
|
||||
printf(_("Username Port Latest\n"));
|
||||
printf (_("Username Port Latest\n"));
|
||||
#endif
|
||||
once++;
|
||||
}
|
||||
tm = localtime (&lastlog.ll_time);
|
||||
#ifdef HAVE_STRFTIME
|
||||
strftime(ptime, sizeof(ptime), "%a %b %e %H:%M:%S %z %Y", tm);
|
||||
strftime (ptime, sizeof (ptime), "%a %b %e %H:%M:%S %z %Y", tm);
|
||||
cp = ptime;
|
||||
#else
|
||||
cp = asctime (tm);
|
||||
cp[24] = '\0';
|
||||
#endif
|
||||
|
||||
if(lastlog.ll_time == (time_t) 0)
|
||||
if (lastlog.ll_time == (time_t) 0)
|
||||
cp = _("**Never logged in**\0");
|
||||
|
||||
#ifdef HAVE_LL_HOST
|
||||
printf ("%-16s %-8.8s %-16.16s %s\n", pw->pw_name,
|
||||
lastlog.ll_line, lastlog.ll_host, cp);
|
||||
#else
|
||||
printf ("%-16s\t%-8.8s %s\n", pw->pw_name,
|
||||
lastlog.ll_line, cp);
|
||||
printf ("%-16s\t%-8.8s %s\n", pw->pw_name, lastlog.ll_line, cp);
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user