]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: check parent PID too when looking for utmp entry
authorEvgeny Grin (Karlson2k) <k2k@drgrin.dev>
Thu, 10 Jul 2025 16:12:29 +0000 (18:12 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Sun, 13 Jul 2025 19:25:08 +0000 (21:25 +0200)
'login' binary may fork itself before this check, so the entry may
contain parent PID instead of current process PID

lib/utmp.c

index ff886354ac052cbcd89c2f3fb8beae6255ffe8e5..44f0301f49287dff4688691b38aa1d353c97a119 100644 (file)
@@ -157,7 +157,8 @@ get_current_utmp(void)
 
        /* First, try to find a valid utmp entry for this process.  */
        while ((ut = getutxent()) != NULL) {
-               if (   (ut->ut_pid == getpid ())
+               if (   (   (ut->ut_pid == getpid ())
+                       || (ut->ut_pid == getppid ()))
                    && ('\0' != ut->ut_id[0])
                    && (   (LOGIN_PROCESS == ut->ut_type)
                        || (USER_PROCESS  == ut->ut_type))