]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pwdutils: don't use getlogin(3).
authorÉrico Nogueira <erico.erc@gmail.com>
Wed, 28 Jul 2021 02:41:30 +0000 (23:41 -0300)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Jul 2021 19:40:05 +0000 (21:40 +0200)
Per the man page, it shouldn't be used for security purposes. This is an
issue especially on musl, where getlogin is implemented as
getenv("LOGNAME"). Since xgetlogin is being used as user identity in su(1), to
set PAM_RUSER, we simply switch to always using getpwuid(getuid()).

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
lib/pwdutils.c

index d97020cb9cd6e4b5bbc0e82fb8fbdbeb4abfcae6..641a9da401150e761669a85be599a08a3e418ce4 100644 (file)
@@ -104,11 +104,6 @@ char *xgetlogin(void)
 {
        struct passwd *pw = NULL;
        uid_t ruid;
-       char *user;
-
-       user = getlogin();
-       if (user)
-               return xstrdup(user);
 
        /* GNU Hurd implementation has an extension where a process can exist in a
         * non-conforming environment, and thus be outside the realms of POSIX
@@ -117,6 +112,9 @@ char *xgetlogin(void)
         * environment.
         *
         * http://austingroupbugs.net/view.php?id=511
+        *
+        * The same implementation is useful for other systems, since getlogin(3)
+        * shouldn't be used as actual identification.
         */
        errno = 0;
        ruid = getuid();