Module Name:    src
Committed By:   martin
Date:           Thu May  7 18:22:58 UTC 2020

Modified Files:
        src/usr.bin/finger [netbsd-9]: finger.1 util.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.16.1 src/usr.bin/finger/finger.1
cvs rdiff -u -r1.29 -r1.29.18.1 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.19 src/usr.bin/finger/finger.1:1.19.16.1
--- src/usr.bin/finger/finger.1:1.19	Thu Dec 22 12:39:40 2016
+++ src/usr.bin/finger/finger.1	Thu May  7 18:22:58 2020
@@ -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 ,

Index: src/usr.bin/finger/util.c
diff -u src/usr.bin/finger/util.c:1.29 src/usr.bin/finger/util.c:1.29.18.1
--- src/usr.bin/finger/util.c:1.29	Wed Mar  9 16:12:14 2016
+++ src/usr.bin/finger/util.c	Thu May  7 18:22:58 2020
@@ -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/
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <utmp.h>
 
 #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) {

Reply via email to