From 5cc21d91fc8c67b1e727e8ba0cb81d0846c2e17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Tue, 27 Jul 2021 23:51:34 -0300 Subject: [PATCH] wall: use xgetlogin. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getlogin(3) shouldn't be used for identification here. This also removes the bug where a missing entry for getuid() in passwd database wouldn't print a warning, because whom would be set to "???". For consistency, switch to "" when pw look up fails. Signed-off-by: Érico Nogueira --- term-utils/wall.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/term-utils/wall.c b/term-utils/wall.c index fb283d3bf..c601d3e5b 100644 --- a/term-utils/wall.c +++ b/term-utils/wall.c @@ -72,6 +72,7 @@ #include "fileutils.h" #include "closestream.h" #include "timeutils.h" +#include "pwdutils.h" #define TERM_WIDTH 79 #define WRITE_TIME_OUT 300 /* in seconds */ @@ -352,13 +353,11 @@ static char *makemsg(char *fname, char **mvec, int mvecsz, if (print_banner == TRUE) { char *hostname = xgethostname(); char *whom, *where, date[CTIME_BUFSIZ]; - struct passwd *pw; time_t now; - if (!(whom = getlogin()) || !*whom) - whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; + whom = xgetlogin(); if (!whom) { - whom = "someone"; + whom = ""; warn(_("cannot get passwd uid")); } where = ttyname(STDOUT_FILENO);