Two more pontential places where user_from_uid(3) makes sense.
These were in my large diff but got lost chopping it up into smaller
pieces.

 - todd

Index: usr.bin/write/write.c
===================================================================
RCS file: /cvs/src/usr.bin/write/write.c,v
retrieving revision 1.33
diff -u -p -u -r1.33 write.c
--- usr.bin/write/write.c       5 Feb 2016 19:00:39 -0000       1.33
+++ usr.bin/write/write.c       13 Sep 2018 15:39:12 -0000
@@ -224,20 +224,16 @@ term_chk(char *tty, int *msgsokP, time_t
 void
 do_write(char *tty, char *mytty, uid_t myuid)
 {
-       char *login, *nows;
-       struct passwd *pwd;
+       const char *login;
+       char *nows;
        time_t now;
        char path[PATH_MAX], host[HOST_NAME_MAX+1], line[512];
        gid_t gid;
        int fd;
 
        /* Determine our login name before the we reopen() stdout */
-       if ((login = getlogin()) == NULL) {
-               if ((pwd = getpwuid(myuid)))
-                       login = pwd->pw_name;
-               else
-                       login = "???";
-       }
+       if ((login = getlogin()) == NULL)
+               login = user_from_uid(myuid, 0);
 
        (void)snprintf(path, sizeof(path), "%s%s", _PATH_DEV, tty);
        fd = open(path, O_WRONLY, 0666);
Index: usr.sbin/quot/quot.c
===================================================================
RCS file: /cvs/src/usr.sbin/quot/quot.c,v
retrieving revision 1.31
diff -u -p -u -r1.31 quot.c
--- usr.sbin/quot/quot.c        26 Jul 2018 13:37:40 -0000      1.31
+++ usr.sbin/quot/quot.c        13 Sep 2018 15:39:12 -0000
@@ -227,8 +227,8 @@ static struct user *
 user(uid_t uid)
 {
        int i;
-       struct passwd *pwd;
        struct user *usr;
+       const char *name;
 
        while (1) {
                for (usr = users + (uid&(nusers - 1)), i = nusers;
@@ -237,10 +237,10 @@ user(uid_t uid)
                        if (!usr->name) {
                                usr->uid = uid;
 
-                               if (!(pwd = getpwuid(uid)))
+                               if ((name = user_from_uid(uid, 1)) == NULL)
                                        asprintf(&usr->name, "#%u", uid);
                                else
-                                       usr->name = strdup(pwd->pw_name);
+                                       usr->name = strdup(name);
                                if (!usr->name)
                                        err(1, "allocate users");
                                return usr;
@@ -368,6 +368,8 @@ douser(int fd, struct fs *super, char *n
        struct user *usr, *usrs;
        union dinode *dp;
        int n;
+
+       setpassent(1);
 
        maxino = super->fs_ncg * super->fs_ipg - 1;
        for (inode = 0; inode < maxino; inode++) {

Reply via email to