]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wall: use xgetlogin.
authorÉrico Nogueira <erico.erc@gmail.com>
Wed, 28 Jul 2021 02:51:34 +0000 (23:51 -0300)
committerÉrico Nogueira <erico.erc@gmail.com>
Thu, 29 Jul 2021 12:58:19 +0000 (09:58 -0300)
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>
term-utils/wall.c

index fb283d3bfd96685c53f16f8182b42478ca51c9ab..c601d3e5b73582dfaa20edf04b2a61e8384a7f1f 100644 (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);