From efcd81d373eb2a624ba0c0f39d809c29690b760f Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 7 May 2020 18:22:58 +0000 Subject: [PATCH] Pull up following revision(s) (requested by kim in ticket #894): usr.bin/finger/finger.1: revision 1.22 usr.bin/finger/util.c: revision 1.30 Add lastlogx support --- usr.bin/finger/finger.1 | 22 ++++++++++++++++++---- usr.bin/finger/util.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/usr.bin/finger/finger.1 b/usr.bin/finger/finger.1 index 6eed57ee56f5..cdf65fab1ea1 100644 --- a/usr.bin/finger/finger.1 +++ b/usr.bin/finger/finger.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: finger.1,v 1.19 2016/12/22 12:39:40 abhinav Exp $ +.\" $NetBSD: finger.1,v 1.19.16.1 2020/05/07 18:22:58 martin 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 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 , diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c index ef30800f57bd..a7329aa60cd3 100644 --- a/usr.bin/finger/util.c +++ b/usr.bin/finger/util.c @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.29 2016/03/09 16:12:14 chs Exp $ */ +/* $NetBSD: util.c,v 1.29.18.1 2020/05/07 18:22:58 martin 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.29.18.1 2020/05/07 18:22:58 martin Exp $"); #endif #endif /* not lint */ @@ -90,7 +90,6 @@ __RCSID("$NetBSD: util.c,v 1.29 2016/03/09 16:12:14 chs Exp $"); #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(&ll, 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 = &pn->uid; + key.size = sizeof(pn->uid); + if ((*lldb->get)(lldb, &key, &data, 0) == 0 && + data.size == sizeof(ll)) + (void)memcpy(&ll, 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) {