From e87b432fb4950076cc450196c0c2f8e9c22df32d Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 18 Sep 2018 03:10:53 +0000 Subject: [PATCH] Use user_from_uid(3) if getlogin(2) fails, storing the uid as a string if there is no passwd entry. OK tb@ --- usr.bin/write/write.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/usr.bin/write/write.c b/usr.bin/write/write.c index 3a45efc9fee..ace3010d4b3 100644 --- a/usr.bin/write/write.c +++ b/usr.bin/write/write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: write.c,v 1.33 2016/02/05 19:00:39 martijn Exp $ */ +/* $OpenBSD: write.c,v 1.34 2018/09/18 03:10:53 millert Exp $ */ /* $NetBSD: write.c,v 1.5 1995/08/31 21:48:32 jtc Exp $ */ /* @@ -224,20 +224,16 @@ term_chk(char *tty, int *msgsokP, time_t *atimeP, int showerror) 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); -- 2.20.1