CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: wiz Date: Thu May 7 12:52:40 UTC 2020 Modified Files: src/usr.sbin/lastlogin: lastlogin.c Log Message: Sync usage with man page. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/lastlogin/lastlogin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.c diff -u src/usr.sbin/lastlogin/lastlogin.c:1.19 src/usr.sbin/lastlogin/lastlogin.c:1.20 --- src/usr.sbin/lastlogin/lastlogin.c:1.19 Wed May 6 19:45:39 2020 +++ src/usr.sbin/lastlogin/lastlogin.c Thu May 7 12:52:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lastlogin.c,v 1.19 2020/05/06 19:45:39 kim Exp $ */ +/* $NetBSD: lastlogin.c,v 1.20 2020/05/07 12:52:40 wiz Exp $ */ /* * Copyright (c) 1996 John M. Vinopal * All rights reserved. @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: lastlogin.c,v 1.19 2020/05/06 19:45:39 kim Exp $"); +__RCSID("$NetBSD: lastlogin.c,v 1.20 2020/05/07 12:52:40 wiz Exp $"); #endif #include @@ -531,8 +531,8 @@ output_record(struct output *o) static void usage(void) { - (void)fprintf(stderr, "Usage: %s [-nrt] [-f ] " - "[-H ] [-L ] [-N ] [user ...]\n", + (void)fprintf(stderr, "Usage: %s [-Fnrt] [-f filename] " + "[-H hostsize] [-L linesize] [-N namesize] [user ...]\n", getprogname()); exit(1); }
CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: wiz Date: Thu May 7 12:52:26 UTC 2020 Modified Files: src/usr.sbin/lastlogin: lastlogin.8 Log Message: New sentence, new line. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/lastlogin/lastlogin.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.8 diff -u src/usr.sbin/lastlogin/lastlogin.8:1.13 src/usr.sbin/lastlogin/lastlogin.8:1.14 --- src/usr.sbin/lastlogin/lastlogin.8:1.13 Wed May 6 11:58:33 2020 +++ src/usr.sbin/lastlogin/lastlogin.8 Thu May 7 12:52:26 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: lastlogin.8,v 1.13 2020/05/06 11:58:33 kim Exp $ +.\" $NetBSD: lastlogin.8,v 1.14 2020/05/07 12:52:26 wiz Exp $ .\" .\" Copyright (c) 1996 John M. Vinopal .\" All rights reserved. @@ -48,15 +48,16 @@ .Nm will list the last login session of specified .Ar users , -or for all users by default. Each line of output contains -the user name, the tty from which the session was conducted, any -hostname, and the start time for the session. +or for all users by default. +Each line of output contains the user name, the tty from which the +session was conducted, any hostname, and the start time for the +session. .Pp If multiple .Ar users are given, the session information for each user is printed in -the order given on the command line. Otherwise, information -for all users is printed, sorted by uid. +the order given on the command line. +Otherwise, information for all users is printed, sorted by uid. .Pp .Nm differs from
CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: kim Date: Wed May 6 19:45:39 UTC 2020 Modified Files: src/usr.sbin/lastlogin: lastlogin.c Log Message: Output records in original order Append to the list of output records instead of pushing on it, so we don't reverse the order of records (when not sorting). To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/lastlogin/lastlogin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.c diff -u src/usr.sbin/lastlogin/lastlogin.c:1.18 src/usr.sbin/lastlogin/lastlogin.c:1.19 --- src/usr.sbin/lastlogin/lastlogin.c:1.18 Wed May 6 19:31:32 2020 +++ src/usr.sbin/lastlogin/lastlogin.c Wed May 6 19:45:39 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lastlogin.c,v 1.18 2020/05/06 19:31:32 kim Exp $ */ +/* $NetBSD: lastlogin.c,v 1.19 2020/05/06 19:45:39 kim Exp $ */ /* * Copyright (c) 1996 John M. Vinopal * All rights reserved. @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: lastlogin.c,v 1.18 2020/05/06 19:31:32 kim Exp $"); +__RCSID("$NetBSD: lastlogin.c,v 1.19 2020/05/06 19:45:39 kim Exp $"); #endif #include @@ -95,6 +95,7 @@ struct output { #define DOSORT(x) ((x) & (SORT_TIME)) static int sortlog = SORT_NONE; static struct output *outstack = NULL; +static struct output *outstack_p = NULL; static int fixed = 0; #define FIXED_NAMELEN UT_NAMESIZE @@ -121,7 +122,7 @@ static void dolastlog(const char *, int static void process_entryx(struct passwd *, struct lastlogx *); static void dolastlogx(const char *, int, char *[]); #endif -static void push_record(struct output *); +static void append_record(struct output *); static void sizecolumns(struct output *); static void output_stack(struct output *); static void sort_and_output_stack(struct output *); @@ -289,7 +290,7 @@ process_entry(struct passwd *p, struct l * onto a stack. Otherwise, we can just output it. */ if (SIZECOLUMNS || DOSORT(sortlog)) - push_record(); + append_record(); else output_record(); } @@ -417,14 +418,14 @@ process_entryx(struct passwd *p, struct * onto a stack. Otherwise, we can just output it. */ if (SIZECOLUMNS || DOSORT(sortlog)) - push_record(); + append_record(); else output_record(); } #endif static void -push_record(struct output *o) +append_record(struct output *o) { struct output *out; @@ -434,12 +435,10 @@ push_record(struct output *o) (void)memcpy(out, o, sizeof(*out)); out->next = NULL; - if (outstack) { - out->next = outstack; - outstack = out; - } else { - outstack = out; - } + if (outstack_p) + outstack_p = outstack_p->next = out; + else + outstack = outstack_p = out; } static void
CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: kim Date: Wed May 6 19:31:32 UTC 2020 Modified Files: src/usr.sbin/lastlogin: lastlogin.c Log Message: Use memcpy for copying out lastlog and lastlogx text Lastlog and lastlogx text fields are not NUL-terminated when original data is truncated. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/lastlogin/lastlogin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.c diff -u src/usr.sbin/lastlogin/lastlogin.c:1.17 src/usr.sbin/lastlogin/lastlogin.c:1.18 --- src/usr.sbin/lastlogin/lastlogin.c:1.17 Wed May 6 13:47:39 2020 +++ src/usr.sbin/lastlogin/lastlogin.c Wed May 6 19:31:32 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lastlogin.c,v 1.17 2020/05/06 13:47:39 kim Exp $ */ +/* $NetBSD: lastlogin.c,v 1.18 2020/05/06 19:31:32 kim Exp $ */ /* * Copyright (c) 1996 John M. Vinopal * All rights reserved. @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: lastlogin.c,v 1.17 2020/05/06 13:47:39 kim Exp $"); +__RCSID("$NetBSD: lastlogin.c,v 1.18 2020/05/06 19:31:32 kim Exp $"); #endif #include @@ -77,6 +77,10 @@ __RCSID("$NetBSD: lastlogin.c,v 1.17 202 # define UTX_HOSTSIZE 256 #endif +/* + * Fields in the structure below are 1 byte longer than the maximum possible + * for NUL-termination. + */ struct output { struct timeval o_tv; char o_name[UTX_USERSIZE+1]; @@ -268,12 +272,13 @@ process_entry(struct passwd *p, struct l { struct output o; + memset(, 0, sizeof(o)); if (numeric > 1) (void)snprintf(o.o_name, sizeof(o.o_name), "%d", p->pw_uid); else (void)strlcpy(o.o_name, p->pw_name, sizeof(o.o_name)); - (void)strlcpy(o.o_line, l->ll_line, sizeof(l->ll_line)); - (void)strlcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); + (void)memcpy(o.o_line, l->ll_line, sizeof(l->ll_line)); + (void)memcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); o.o_tv.tv_sec = l->ll_time; o.o_tv.tv_usec = 0; o.next = NULL; @@ -392,16 +397,17 @@ process_entryx(struct passwd *p, struct { struct output o; + memset(, 0, sizeof(o)); if (numeric > 1) (void)snprintf(o.o_name, sizeof(o.o_name), "%d", p->pw_uid); else (void)strlcpy(o.o_name, p->pw_name, sizeof(o.o_name)); - (void)strlcpy(o.o_line, l->ll_line, sizeof(l->ll_line)); + (void)memcpy(o.o_line, l->ll_line, sizeof(l->ll_line)); if (numeric) (void)sockaddr_snprintf(o.o_host, sizeof(o.o_host), "%a", (struct sockaddr *)>ll_ss); else - (void)strlcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); + (void)memcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); o.o_tv = l->ll_tv; o.next = NULL;
CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: kim Date: Wed May 6 13:47:40 UTC 2020 Modified Files: src/usr.sbin/lastlogin: lastlogin.c Log Message: If the passwd entry is not found for a lastlogx entry, cons up a fake struct passwd where pw_name is the numeric uid in parentheses. This was already implemented for lastlog entries in revision 1.13. If -n is specified more than once, also print the user numerically (ie, uid instead of username) for lastlog entries. This was already implemented for lastlogx entries in revision 1.13. Reorder the lastlogx host name numeric condition so it better matches the user name numeric condition. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/lastlogin/lastlogin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.c diff -u src/usr.sbin/lastlogin/lastlogin.c:1.16 src/usr.sbin/lastlogin/lastlogin.c:1.17 --- src/usr.sbin/lastlogin/lastlogin.c:1.16 Wed May 6 11:58:33 2020 +++ src/usr.sbin/lastlogin/lastlogin.c Wed May 6 13:47:39 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lastlogin.c,v 1.16 2020/05/06 11:58:33 kim Exp $ */ +/* $NetBSD: lastlogin.c,v 1.17 2020/05/06 13:47:39 kim Exp $ */ /* * Copyright (c) 1996 John M. Vinopal * All rights reserved. @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: lastlogin.c,v 1.16 2020/05/06 11:58:33 kim Exp $"); +__RCSID("$NetBSD: lastlogin.c,v 1.17 2020/05/06 13:47:39 kim Exp $"); #endif #include @@ -268,7 +268,10 @@ process_entry(struct passwd *p, struct l { struct output o; - (void)strlcpy(o.o_name, p->pw_name, sizeof(o.o_name)); + if (numeric > 1) + (void)snprintf(o.o_name, sizeof(o.o_name), "%d", p->pw_uid); + else + (void)strlcpy(o.o_name, p->pw_name, sizeof(o.o_name)); (void)strlcpy(o.o_line, l->ll_line, sizeof(l->ll_line)); (void)strlcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); o.o_tv.tv_sec = l->ll_time; @@ -358,9 +361,12 @@ dolastlogx(const char *logfile, int argc (void)memcpy(, key.data, sizeof(uid)); if ((passwd = getpwuid(uid)) == NULL) { -warnx("Cannot find user for uid %lu", -(unsigned long)uid); -continue; +static struct passwd p; +static char n[32]; +snprintf(n, sizeof(n), "(%d)", i); +p.pw_uid = i; +p.pw_name = n; +passwd = } (void)memcpy(, data.data, sizeof(l)); process_entryx(passwd, ); @@ -391,11 +397,11 @@ process_entryx(struct passwd *p, struct else (void)strlcpy(o.o_name, p->pw_name, sizeof(o.o_name)); (void)strlcpy(o.o_line, l->ll_line, sizeof(l->ll_line)); - if (!numeric) - (void)strlcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); - else + if (numeric) (void)sockaddr_snprintf(o.o_host, sizeof(o.o_host), "%a", (struct sockaddr *)>ll_ss); + else + (void)strlcpy(o.o_host, l->ll_host, sizeof(l->ll_host)); o.o_tv = l->ll_tv; o.next = NULL;
CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: kim Date: Wed May 6 11:58:33 UTC 2020 Modified Files: src/usr.sbin/lastlogin: lastlogin.8 lastlogin.c Log Message: Size output columns dynamically by default to fit contents. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/lastlogin/lastlogin.8 cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/lastlogin/lastlogin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.8 diff -u src/usr.sbin/lastlogin/lastlogin.8:1.12 src/usr.sbin/lastlogin/lastlogin.8:1.13 --- src/usr.sbin/lastlogin/lastlogin.8:1.12 Wed Apr 8 14:20:38 2009 +++ src/usr.sbin/lastlogin/lastlogin.8 Wed May 6 11:58:33 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: lastlogin.8,v 1.12 2009/04/08 14:20:38 joerg Exp $ +.\" $NetBSD: lastlogin.8,v 1.13 2020/05/06 11:58:33 kim Exp $ .\" .\" Copyright (c) 1996 John M. Vinopal .\" All rights reserved. @@ -30,7 +30,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 4, 2005 +.Dd May 6, 2020 .Dt LASTLOGIN 8 .Os .Sh NAME @@ -38,7 +38,7 @@ .Nd indicate last login time of users .Sh SYNOPSIS .Nm -.Op Fl nrt +.Op Fl Fnrt .Op Fl f Ar filename .Op Fl H Ar hostsize .Op Fl L Ar linesize @@ -66,6 +66,8 @@ The last login database is never turned .Pp The following options are available: .Bl -tag -width indent +.It Fl F +Use fixed widths for all output fields. .It Fl f Ar filename Process input from .Ar filename . Index: src/usr.sbin/lastlogin/lastlogin.c diff -u src/usr.sbin/lastlogin/lastlogin.c:1.15 src/usr.sbin/lastlogin/lastlogin.c:1.16 --- src/usr.sbin/lastlogin/lastlogin.c:1.15 Wed Aug 31 13:31:29 2011 +++ src/usr.sbin/lastlogin/lastlogin.c Wed May 6 11:58:33 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lastlogin.c,v 1.15 2011/08/31 13:31:29 joerg Exp $ */ +/* $NetBSD: lastlogin.c,v 1.16 2020/05/06 11:58:33 kim Exp $ */ /* * Copyright (c) 1996 John M. Vinopal * All rights reserved. @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: lastlogin.c,v 1.15 2011/08/31 13:31:29 joerg Exp $"); +__RCSID("$NetBSD: lastlogin.c,v 1.16 2020/05/06 11:58:33 kim Exp $"); #endif #include @@ -57,12 +57,31 @@ __RCSID("$NetBSD: lastlogin.c,v 1.15 201 #include #include +#ifndef UT_NAMESIZE +# define UT_NAMESIZE 8 +#endif +#ifndef UT_LINESIZE +# define UT_LINESIZE 8 +#endif +#ifndef UT_HOSTSIZE +# define UT_HOSTSIZE 16 +#endif + +#ifndef UTX_USERSIZE +# define UTX_USERSIZE 64 +#endif +#ifndef UTX_LINESIZE +# define UTX_LINESIZE 64 +#endif +#ifndef UTX_HOSTSIZE +# define UTX_HOSTSIZE 256 +#endif + struct output { struct timeval o_tv; - struct sockaddr_storage o_ss; - char o_name[64]; - char o_line[64]; - char o_host[256]; + char o_name[UTX_USERSIZE+1]; + char o_line[UTX_LINESIZE+1]; + char o_host[UTX_HOSTSIZE+1]; struct output *next; }; @@ -73,24 +92,35 @@ struct output { static int sortlog = SORT_NONE; static struct output *outstack = NULL; +static int fixed = 0; +#define FIXED_NAMELEN UT_NAMESIZE +#define FIXED_LINELEN UT_LINESIZE +/* + * This makes the "fixed" output fit in 79 columns. + * Using UT_HOSTSIZE (16) seems too conservative. + */ +#define FIXED_HOSTLEN 32 + static int numeric = 0; -static size_t namelen = UT_NAMESIZE; -static size_t linelen = UT_LINESIZE; -static size_t hostlen = UT_HOSTSIZE; +static size_t namelen = 0; +static size_t linelen = 0; +static size_t hostlen = 0; +#define SIZECOLUMNS (!(namelen && linelen && hostlen)) -static int comparelog(const void *, const void *); -static void output(struct output *); +static int comparelog(const void *, const void *); +static void output_record(struct output *); #ifdef SUPPORT_UTMP -static void process_entry(struct passwd *, struct lastlog *); -static void dolastlog(const char *, int, char *[]); +static void process_entry(struct passwd *, struct lastlog *); +static void dolastlog(const char *, int, char *[]); #endif #ifdef SUPPORT_UTMPX -static void process_entryx(struct passwd *, struct lastlogx *); -static void dolastlogx(const char *, int, char *[]); +static void process_entryx(struct passwd *, struct lastlogx *); +static void dolastlogx(const char *, int, char *[]); #endif -static void push(struct output *); -static const char *gethost(struct output *); -static void sortoutput(struct output *); +static void push_record(struct output *); +static void sizecolumns(struct output *); +static void output_stack(struct output *); +static void sort_and_output_stack(struct output *); __dead static void usage(void); int @@ -107,7 +137,7 @@ main(int argc, char *argv[]) int ch; size_t len; - while ((ch = getopt(argc, argv, "f:H:L:nN:rt")) != -1) { + while ((ch = getopt(argc, argv, "f:FH:L:nN:rt")) != -1) { switch (ch) { case 'H': hostlen = atoi(optarg); @@ -115,6 +145,9 @@ main(int argc, char *argv[]) case 'f': logfile = optarg;
CVS commit: src/usr.sbin/lastlogin
Module Name:src Committed By: joerg Date: Wed Aug 31 13:31:29 UTC 2011 Modified Files: src/usr.sbin/lastlogin: lastlogin.c Log Message: __dead + ANSIfy To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/lastlogin/lastlogin.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.sbin/lastlogin/lastlogin.c diff -u src/usr.sbin/lastlogin/lastlogin.c:1.14 src/usr.sbin/lastlogin/lastlogin.c:1.15 --- src/usr.sbin/lastlogin/lastlogin.c:1.14 Thu Apr 16 05:59:56 2009 +++ src/usr.sbin/lastlogin/lastlogin.c Wed Aug 31 13:31:29 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: lastlogin.c,v 1.14 2009/04/16 05:59:56 lukem Exp $ */ +/* $NetBSD: lastlogin.c,v 1.15 2011/08/31 13:31:29 joerg Exp $ */ /* * Copyright (c) 1996 John M. Vinopal * All rights reserved. @@ -33,7 +33,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: lastlogin.c,v 1.14 2009/04/16 05:59:56 lukem Exp $); +__RCSID($NetBSD: lastlogin.c,v 1.15 2011/08/31 13:31:29 joerg Exp $); #endif #include sys/types.h @@ -78,7 +78,6 @@ static size_t linelen = UT_LINESIZE; static size_t hostlen = UT_HOSTSIZE; - int main(int, char **); static int comparelog(const void *, const void *); static void output(struct output *); #ifdef SUPPORT_UTMP @@ -92,12 +91,10 @@ static void push(struct output *); static const char *gethost(struct output *); static void sortoutput(struct output *); -static void usage(void); +__dead static void usage(void); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { const char *logfile = #if defined(SUPPORT_UTMPX)