Subject: Re: bug#35553: getlogin and getlogin_r fail with error ENXIO

From: Ludovic Courtès <[email-masked]>
Date: Tue, 07 May 2019 12:18:09 +0200

Hi Bruno!

Bruno Haible <[email-masked]> skribis:

> Danny Milosavljevic wrote:
>> Are you logging in using gdm?
>
> I'm using the guix-1.0 installation image
> (guix-system-vm-image-1.0.0.x86_64-linux). It shows a screen "Logging in..."
> for less than one second and then starts the user's desktop immediately.

This is the VM image (not the installation image), and it uses SLiM:

  https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/system/examples/vm-image.tmpl

Danny wrote:

> We don't refer to pam_loginuid.so anywhere, so it's understandable that
> /proc/self/loginuid is not set either.

Is it the only way to get that done?  (That something has to write some
number to /proc/self/loginuid looks very clunky to me.)

I’ve tested the patch below and confirmed that after logging in at the
tty, running Guile and calling ‘getlogin’ at the REPL now returns the
right thing.

We’d have to do that for all the relevant services (graphical log-in
managers, SSH daemons, anything else?).  Perhaps we can simply add a
keyword to ‘unix-pam-service’ to make it less verbose.

Thoughts?

Thanks for the bug report, Bruno!

Ludo’.

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 952f6f9ab2..30e50f4b9a 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -829,11 +829,18 @@ Return a service that sets up Unicode support in @var{tty} and loads
 (define (login-pam-service config)
   "Return the list of PAM service needed for CONF."
   ;; Let 'login' be known to PAM.
-  (list (unix-pam-service "login"
-                          #:allow-empty-passwords?
-                          (login-configuration-allow-empty-passwords? config)
-                          #:motd
-                          (login-configuration-motd config))))
+  (let ((base (unix-pam-service
+               "login"
+               #:allow-empty-passwords?
+               (login-configuration-allow-empty-passwords? config)
+               #:motd
+               (login-configuration-motd config))))
+    (list (pam-service
+           (inherit base)
+           (session (cons (pam-entry
+                           (control "required")
+                           (module "pam_loginuid.so"))
+                          (pam-service-session base)))))))
 
 (define login-service-type
   (service-type (name 'login)