Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/finger Add lastlogx support



details:   https://anonhg.NetBSD.org/src/rev/c2a1ff4ee245
branches:  trunk
changeset: 932423:c2a1ff4ee245
user:      kim <kim%NetBSD.org@localhost>
date:      Thu May 07 13:40:20 2020 +0000

description:
Add lastlogx support

diffstat:

 usr.bin/finger/finger.1 |  22 ++++++++++++++++++----
 usr.bin/finger/util.c   |  33 +++++++++++++++++++++++++++++----
 2 files changed, 47 insertions(+), 8 deletions(-)

diffs (120 lines):

diff -r 571425a31e35 -r c2a1ff4ee245 usr.bin/finger/finger.1
--- a/usr.bin/finger/finger.1   Thu May 07 12:58:09 2020 +0000
+++ b/usr.bin/finger/finger.1   Thu May 07 13:40:20 2020 +0000
@@ -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 @@
 .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 -r 571425a31e35 -r c2a1ff4ee245 usr.bin/finger/util.c
--- a/usr.bin/finger/util.c     Thu May 07 12:58:09 2020 +0000
+++ b/usr.bin/finger/util.c     Thu May 07 13:40:20 2020 +0000
@@ -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 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <utmp.h>
 
 #include "utmpentry.h"
 
@@ -160,15 +159,40 @@
 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 @@
                        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) {



Home | Main Index | Thread Index | Old Index