CVS commit: src/usr.bin/finger
Module Name:src Committed By: kim Date: Thu May 7 13:40:20 UTC 2020 Modified Files: src/usr.bin/finger: finger.1 util.c Log Message: Add lastlogx support To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/finger/finger.1 cvs rdiff -u -r1.29 -r1.30 src/usr.bin/finger/util.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.bin/finger/finger.1 diff -u src/usr.bin/finger/finger.1:1.21 src/usr.bin/finger/finger.1:1.22 --- src/usr.bin/finger/finger.1:1.21 Thu Jan 30 23:59:59 2020 +++ src/usr.bin/finger/finger.1 Thu May 7 13:40:20 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: finger.1,v 1.21 2020/01/30 23:59:59 sevan Exp $ +.\" $NetBSD: finger.1,v 1.22 2020/05/07 13:40:20 kim Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)finger.1 8.3 (Berkeley) 5/5/94 .\" -.Dd January 30, 2020 +.Dd May 7, 2020 .Dt FINGER 1 .Os .Sh NAME @@ -199,9 +199,23 @@ The .Fl l option is the only option that may be passed to a remote machine. .Sh FILES -.Bl -tag -width /var/log/lastlog -compact +.Bl -tag -width /var/log/lastlogx -compact +.It Pa /var/run/utmpx +The +.Nm utmpx +file. +.It Pa /var/log/lastlogx +The +.Nm lastlogx +file. +.It Pa /var/run/utmp +The +.Nm utmp +file. .It Pa /var/log/lastlog -last login data base +The +.Nm lastlog +file. .El .Sh SEE ALSO .Xr chpass 1 , Index: src/usr.bin/finger/util.c diff -u src/usr.bin/finger/util.c:1.29 src/usr.bin/finger/util.c:1.30 --- src/usr.bin/finger/util.c:1.29 Wed Mar 9 16:12:14 2016 +++ src/usr.bin/finger/util.c Thu May 7 13:40:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.29 2016/03/09 16:12:14 chs Exp $ */ +/* $NetBSD: util.c,v 1.30 2020/05/07 13:40:20 kim Exp $ */ /* * Copyright (c) 1989, 1993 @@ -72,7 +72,7 @@ #if 0 static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: util.c,v 1.29 2016/03/09 16:12:14 chs Exp $"); +__RCSID("$NetBSD: util.c,v 1.30 2020/05/07 13:40:20 kim Exp $"); #endif #endif /* not lint */ @@ -90,7 +90,6 @@ __RCSID("$NetBSD: util.c,v 1.29 2016/03/ #include #include #include -#include #include "utmpentry.h" @@ -160,15 +159,40 @@ void enter_lastlog(PERSON *pn) { WHERE *w; - static int opened, fd; + static int opened; +#ifdef SUPPORT_UTMPX +# define ll_time ll_tv.tv_sec +# define UT_LINESIZE _UTX_LINESIZE +# define UT_HOSTSIZE _UTX_HOSTSIZE + static DB *lldb = NULL; + DBT key, data; + struct lastlogx ll; +#else + static int fd; struct lastlog ll; +#endif char doit = 0; + (void)memset(, 0, sizeof(ll)); + /* some systems may not maintain lastlog, don't report errors. */ if (!opened) { +#ifdef SUPPORT_UTMPX + lldb = dbopen(_PATH_LASTLOGX, O_RDONLY|O_SHLOCK, 0, DB_HASH, NULL); +#else fd = open(_PATH_LASTLOG, O_RDONLY, 0); +#endif opened = 1; } +#ifdef SUPPORT_UTMPX + if (lldb != NULL) { + key.data = >uid; + key.size = sizeof(pn->uid); + if ((*lldb->get)(lldb, , , 0) == 0 && + data.size == sizeof(ll)) + (void)memcpy(, data.data, sizeof(ll)); + } +#else if (fd == -1 || lseek(fd, (off_t)pn->uid * sizeof(ll), SEEK_SET) != (off_t)pn->uid * (off_t)sizeof(ll) || @@ -177,6 +201,7 @@ enter_lastlog(PERSON *pn) ll.ll_line[0] = ll.ll_host[0] = '\0'; ll.ll_time = 0; } +#endif if ((w = pn->whead) == NULL) doit = 1; else if (ll.ll_time != 0) {
CVS commit: src/usr.bin/finger
Module Name:src Committed By: sevan Date: Thu Jan 30 23:59:59 UTC 2020 Modified Files: src/usr.bin/finger: finger.1 Log Message: finish with a full stop To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.bin/finger/finger.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/finger/finger.1 diff -u src/usr.bin/finger/finger.1:1.20 src/usr.bin/finger/finger.1:1.21 --- src/usr.bin/finger/finger.1:1.20 Thu Jan 30 23:50:23 2020 +++ src/usr.bin/finger/finger.1 Thu Jan 30 23:59:59 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: finger.1,v 1.20 2020/01/30 23:50:23 sevan Exp $ +.\" $NetBSD: finger.1,v 1.21 2020/01/30 23:59:59 sevan Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -212,4 +212,4 @@ last login data base The .Nm command appeared in -.Bx 2.0 +.Bx 2.0 .
CVS commit: src/usr.bin/finger
Module Name:src Committed By: sevan Date: Thu Jan 30 23:50:23 UTC 2020 Modified Files: src/usr.bin/finger: finger.1 Log Message: Drop url which is now invalid, see CSRG archive or mirrors on TUHS.org or svnweb.FreeBSD.org To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/finger/finger.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/finger/finger.1 diff -u src/usr.bin/finger/finger.1:1.19 src/usr.bin/finger/finger.1:1.20 --- src/usr.bin/finger/finger.1:1.19 Thu Dec 22 12:39:40 2016 +++ src/usr.bin/finger/finger.1 Thu Jan 30 23:50:23 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: finger.1,v 1.19 2016/12/22 12:39:40 abhinav Exp $ +.\" $NetBSD: finger.1,v 1.20 2020/01/30 23:50:23 sevan Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)finger.1 8.3 (Berkeley) 5/5/94 .\" -.Dd December 25, 2014 +.Dd January 30, 2020 .Dt FINGER 1 .Os .Sh NAME @@ -212,5 +212,4 @@ last login data base The .Nm command appeared in -.Bx 2.0 : -.Lk ftp://ftp.tuhs.org.ua/PDP-11/Distributions/ucb/2bsd.tar.gz +.Bx 2.0
CVS commit: src/usr.bin/finger
Module Name:src Committed By: abhinav Date: Thu Dec 22 12:39:40 UTC 2016 Modified Files: src/usr.bin/finger: finger.1 Log Message: Instead of saying "The finger displays information..." say "The finger utility" (not sure if it was intentionally written like that :) Also, add an xref to fingerd(8) To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/finger/finger.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/finger/finger.1 diff -u src/usr.bin/finger/finger.1:1.18 src/usr.bin/finger/finger.1:1.19 --- src/usr.bin/finger/finger.1:1.18 Fri Dec 26 12:45:57 2014 +++ src/usr.bin/finger/finger.1 Thu Dec 22 12:39:40 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: finger.1,v 1.18 2014/12/26 12:45:57 christos Exp $ +.\" $NetBSD: finger.1,v 1.19 2016/12/22 12:39:40 abhinav Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -43,7 +43,7 @@ .Sh DESCRIPTION The .Nm -displays information about the system users. +utility displays information about the system users. .Pp Options are: .Bl -tag -width flag @@ -180,8 +180,9 @@ If no arguments are specified, .Nm will print an entry for each user currently logged into the system. .Pp +The .Nm -may be used to look up users on a remote machine. +utility may be used to look up users on a remote machine. The format is to specify a .Ar user as @@ -205,7 +206,8 @@ last login data base .Sh SEE ALSO .Xr chpass 1 , .Xr w 1 , -.Xr who 1 +.Xr who 1 , +.Xr fingerd 8 .Sh HISTORY The .Nm
CVS commit: src/usr.bin/finger
Module Name:src Committed By: chs Date: Wed Mar 9 16:12:14 UTC 2016 Modified Files: src/usr.bin/finger: util.c Log Message: in find_idle_and_ttywrite(), initialize idletime and writable to 0 when stat() fails. this prevents a coredump later in stimeprint() due to gmtime() returning NULL for an uninitialized idletime. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/usr.bin/finger/util.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.bin/finger/util.c diff -u src/usr.bin/finger/util.c:1.28 src/usr.bin/finger/util.c:1.29 --- src/usr.bin/finger/util.c:1.28 Sun Apr 12 06:18:54 2009 +++ src/usr.bin/finger/util.c Wed Mar 9 16:12:14 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.28 2009/04/12 06:18:54 lukem Exp $ */ +/* $NetBSD: util.c,v 1.29 2016/03/09 16:12:14 chs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -72,7 +72,7 @@ #if 0 static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: util.c,v 1.28 2009/04/12 06:18:54 lukem Exp $"); +__RCSID("$NetBSD: util.c,v 1.29 2016/03/09 16:12:14 chs Exp $"); #endif #endif /* not lint */ @@ -358,6 +358,8 @@ find_idle_and_ttywrite(WHERE *w) (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty); if (stat(tbuf, ) < 0) { warn("%s", tbuf); + w->idletime = 0; + w->writable = 0; return; } w->idletime = now < sb.st_atime ? 0 : now - sb.st_atime;
CVS commit: src/usr.bin/finger
Module Name:src Committed By: christos Date: Sat Nov 21 15:22:17 UTC 2015 Modified Files: src/usr.bin/finger: sprint.c Log Message: fix format To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/finger/sprint.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.bin/finger/sprint.c diff -u src/usr.bin/finger/sprint.c:1.17 src/usr.bin/finger/sprint.c:1.18 --- src/usr.bin/finger/sprint.c:1.17 Tue Jan 3 20:17:54 2006 +++ src/usr.bin/finger/sprint.c Sat Nov 21 10:22:17 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: sprint.c,v 1.17 2006/01/04 01:17:54 perry Exp $ */ +/* $NetBSD: sprint.c,v 1.18 2015/11/21 15:22:17 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: sprint.c,v 1.17 2006/01/04 01:17:54 perry Exp $"); +__RCSID("$NetBSD: sprint.c,v 1.18 2015/11/21 15:22:17 christos Exp $"); #endif #endif /* not lint */ @@ -92,7 +92,7 @@ sflag_print(void) * office phone */ #define MAXREALNAME 18 - (void)printf("%-*s %-*s %s %s\n", maxname, "Login", MAXREALNAME, + (void)printf("%-*s %-*s %s %s\n", (int)maxname, "Login", MAXREALNAME, "Name", " Tty Idle Login Time ", (gflag) ? "" : (oflag) ? "Office Office Phone" : "Where");
CVS commit: src/usr.bin/finger
Module Name:src Committed By: christos Date: Fri Dec 26 12:45:57 UTC 2014 Modified Files: src/usr.bin/finger: finger.1 Log Message: And correct it. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/finger/finger.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/finger/finger.1 diff -u src/usr.bin/finger/finger.1:1.17 src/usr.bin/finger/finger.1:1.18 --- src/usr.bin/finger/finger.1:1.17 Thu Dec 25 22:49:00 2014 +++ src/usr.bin/finger/finger.1 Fri Dec 26 07:45:57 2014 @@ -1,4 +1,4 @@ -.\ $NetBSD: finger.1,v 1.17 2014/12/26 03:49:00 christos Exp $ +.\ $NetBSD: finger.1,v 1.18 2014/12/26 12:45:57 christos Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -210,5 +210,5 @@ last login data base The .Nm command appeared in -.Bx 3.0 : +.Bx 2.0 : .Lk ftp://ftp.tuhs.org.ua/PDP-11/Distributions/ucb/2bsd.tar.gz
CVS commit: src/usr.bin/finger
Module Name:src Committed By: christos Date: Fri Dec 26 03:49:00 UTC 2014 Modified Files: src/usr.bin/finger: finger.1 Log Message: Correct the provenance of finger.1 and show the link that it was part of 2BSD (from Marcin F. Michalski) To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.bin/finger/finger.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/finger/finger.1 diff -u src/usr.bin/finger/finger.1:1.16 src/usr.bin/finger/finger.1:1.17 --- src/usr.bin/finger/finger.1:1.16 Sun Jun 10 13:45:59 2012 +++ src/usr.bin/finger/finger.1 Thu Dec 25 22:49:00 2014 @@ -1,4 +1,4 @@ -.\ $NetBSD: finger.1,v 1.16 2012/06/10 17:45:59 dholland Exp $ +.\ $NetBSD: finger.1,v 1.17 2014/12/26 03:49:00 christos Exp $ .\ .\ Copyright (c) 1989, 1990, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\ .\ from: @(#)finger.1 8.3 (Berkeley) 5/5/94 .\ -.Dd June 10, 2012 +.Dd December 25, 2014 .Dt FINGER 1 .Os .Sh NAME @@ -210,4 +210,5 @@ last login data base The .Nm command appeared in -.Bx 3.0 . +.Bx 3.0 : +.Lk ftp://ftp.tuhs.org.ua/PDP-11/Distributions/ucb/2bsd.tar.gz
CVS commit: src/usr.bin/finger
Module Name:src Committed By: christos Date: Fri Jan 18 22:10:31 UTC 2013 Modified Files: src/usr.bin/finger: lprint.c Log Message: - Don't dump core or print random junk on corrupt utmp entries. - Factor out duplicated code in the process. - The actual code is now smaller and does error checking, and encoding. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/finger/lprint.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.bin/finger/lprint.c diff -u src/usr.bin/finger/lprint.c:1.22 src/usr.bin/finger/lprint.c:1.23 --- src/usr.bin/finger/lprint.c:1.22 Sun Apr 12 02:18:54 2009 +++ src/usr.bin/finger/lprint.c Fri Jan 18 17:10:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: lprint.c,v 1.22 2009/04/12 06:18:54 lukem Exp $ */ +/* $NetBSD: lprint.c,v 1.23 2013/01/18 22:10:31 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = @(#)lprint.c 8.3 (Berkeley) 4/28/95; #else -__RCSID( $NetBSD: lprint.c,v 1.22 2009/04/12 06:18:54 lukem Exp $); +__RCSID( $NetBSD: lprint.c,v 1.23 2013/01/18 22:10:31 christos Exp $); #endif #endif /* not lint */ @@ -111,16 +111,71 @@ lflag_print(void) } } +static size_t +visify(char *buf, size_t blen, const char *str) +{ + int len = strnvisx(buf, blen, str, strlen(str), VIS_WHITE|VIS_CSTYLE); + if (len == -1) { + buf[0] = '\0'; + return 0; + } + return len; +} + +static void +fmt_time(char *buf, size_t blen, time_t ti, time_t n) +{ + struct tm *tp = localtime(ti); + if (tp != NULL) { + char *t = asctime(tp); + char *tzn = TIMEZONE(tp); + if (n == (time_t)-1 || + n - ti SECSPERDAY * DAYSPERNYEAR / 2) + snprintf(buf, blen, %.16s %.4s (%s), t, t + 20, tzn); + else + snprintf(buf, blen, %.16s (%s), t, tzn); + } else + snprintf(buf, blen, [*bad time 0x%llx*], (long long)ti); +} + +/* + * idle time is tough; if have one, print a comma, + * then spaces to pad out the device name, then the + * idle time. Follow with a comma if a remote login. + */ +static int +print_idle(time_t t, int maxlen, size_t hostlen, size_t ttylen) { + + int cpr; + struct tm *delta = gmtime(t); + + if (delta == NULL) + return printf(Bad idle 0x%llx, (long long)t); + + if (delta-tm_yday == 0 delta-tm_hour == 0 delta-tm_min == 0) + return 0; + + cpr = printf(%-*s idle , (int)(maxlen - ttylen + 1), ,); + if (delta-tm_yday 0) { + cpr += printf(%d day%s , delta-tm_yday, + delta-tm_yday == 1 ? : s); + } + cpr += printf(%d:%02d, delta-tm_hour, delta-tm_min); + if (hostlen) { + putchar(','); + ++cpr; + } + return cpr; +} + static void lprint(PERSON *pn) { - struct tm *delta; WHERE *w; int cpr, len, maxlen; - struct tm *tp; int oddfield; - char *t; - const char *tzn; + char timebuf[128], ttybuf[64], hostbuf[512]; + size_t ttylen, hostlen; cpr = 0; /* @@ -148,25 +203,25 @@ lprint(PERSON *pn) if (pn-office pn-officephone strlen(pn-office) + strlen(pn-officephone) + sizeof(OFFICE_TAG) + 2 = 5 * TAB_LEN) { - (void)snprintf(tbuf, sizeof(tbuf), %s: %s, %s, + (void)snprintf(timebuf, sizeof(timebuf), %s: %s, %s, OFFICE_TAG, pn-office, prphone(pn-officephone)); - oddfield = demi_print(tbuf, oddfield); + oddfield = demi_print(timebuf, oddfield); } else { if (pn-office) { - (void)snprintf(tbuf, sizeof(tbuf), %s: %s, + (void)snprintf(timebuf, sizeof(timebuf), %s: %s, OFFICE_TAG, pn-office); - oddfield = demi_print(tbuf, oddfield); + oddfield = demi_print(timebuf, oddfield); } if (pn-officephone) { - (void)snprintf(tbuf, sizeof(tbuf), %s: %s, + (void)snprintf(timebuf, sizeof(timebuf), %s: %s, OFFICE_PHONE_TAG, prphone(pn-officephone)); - oddfield = demi_print(tbuf, oddfield); + oddfield = demi_print(timebuf, oddfield); } } if (pn-homephone) { - (void)snprintf(tbuf, sizeof(tbuf), %s: %s, Home Phone, + (void)snprintf(timebuf, sizeof(timebuf), %s: %s, Home Phone, prphone(pn-homephone)); - oddfield = demi_print(tbuf, oddfield); + oddfield = demi_print(timebuf, oddfield); } if (oddfield) putchar('\n'); @@ -183,39 +238,23 @@ no_gecos: * when last logged in */ /* find out longest device name for this user for formatting */ - for (w = pn-whead, maxlen = -1; w != NULL; w = w-next) - if ((len = strlen(w-tty)) maxlen) + for (w = pn-whead, maxlen = -1; w != NULL; w = w-next) { + visify(ttybuf, sizeof(ttybuf), w-tty); + if ((len = strlen(ttybuf)) maxlen) maxlen = len; + } /* find rest of entries for user */ for (w = pn-whead; w != NULL; w = w-next) { + ttylen = visify(ttybuf, sizeof(ttybuf), w-tty); + hostlen = visify(hostbuf, sizeof(hostbuf), w-host); switch (w-info) { case LOGGEDIN: - tp = localtime(w-loginat); - t = asctime(tp); - tzn = TIMEZONE(tp); - cpr = printf(On since %.16s (%s) on %s, - t, tzn, w-tty); - /* - * idle time is tough; if have one, print a comma, - *