Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/lastlogin If the passwd entry is not found for a la...



details:   https://anonhg.NetBSD.org/src/rev/208cfe1e3113
branches:  trunk
changeset: 971845:208cfe1e3113
user:      kim <kim%NetBSD.org@localhost>
date:      Wed May 06 13:47:39 2020 +0000

description:
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.

diffstat:

 usr.sbin/lastlogin/lastlogin.c |  24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diffs (61 lines):

diff -r 779d864f71ab -r 208cfe1e3113 usr.sbin/lastlogin/lastlogin.c
--- a/usr.sbin/lastlogin/lastlogin.c    Wed May 06 13:43:48 2020 +0000
+++ b/usr.sbin/lastlogin/lastlogin.c    Wed May 06 13:47:39 2020 +0000
@@ -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 <sys/cdefs.h>
 #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 <sys/types.h>
@@ -268,7 +268,10 @@
 {
        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 @@
                        (void)memcpy(&uid, 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 = &p;
                        }
                        (void)memcpy(&l, data.data, sizeof(l));
                        process_entryx(passwd, &l);
@@ -391,11 +397,11 @@
        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 *)&l->ll_ss);
+       else
+               (void)strlcpy(o.o_host, l->ll_host, sizeof(l->ll_host));
        o.o_tv = l->ll_tv;
        o.next = NULL;
 



Home | Main Index | Thread Index | Old Index