wall: use xgetlogin.

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 "<someone>" when pw look up fails.

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
This commit is contained in:
Érico Nogueira 2021-07-27 23:51:34 -03:00 committed by Karel Zak
parent bca77acb03
commit 5cc21d91fc
1 changed files with 3 additions and 4 deletions

View File

@ -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 = "<someone>";
warn(_("cannot get passwd uid"));
}
where = ttyname(STDOUT_FILENO);