lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] logname fails


From: Vadim Zeitlin
Subject: Re: [lmi] logname fails
Date: Mon, 24 Feb 2020 20:38:12 +0100

On Mon, 24 Feb 2020 18:35:23 +0000 Greg Chicares <address@hidden> wrote:

GC> If I
GC>   sudo [... whatever]
GC>   schroot [...whatever]
GC> then 'logname' returns my unprivileged login name on my debian machine,
GC> but not on a corporate redhat server. See this branch:
GC>   http://git.savannah.nongnu.org/cgit/lmi.git/log/?h=odd/rh_server
GC> 
GC> The only purpose of this email is preemptively to answer the question:
GC> "can't you get that information with pstree though?".

 I hadn't thought about this question, but I did think about 2 other ones.
First one was related to the comment in the commit above: could we solve
the problem by defining some LMI_USERNAME environment variable which could
be inherited by sudo if its "-E" option were used, and would, hopefully, be
propagated inside chroot too? This wouldn't be dependent on user home
location.

 Second is more directly related to your question above: it looks like it
would be much simpler to get this information from /proc/self/loginuid than
from pstree output. AFAICS this file is the real source of logname
information anyhow, as logname(1) is just a thin wrapper for getlogin(3),
see 
https://github.com/coreutils/coreutils/blob/2ed7c2867974ccf7abc61c34ad7bf9565489c18e/src/logname.c
and getlogin() itself gets the user ID from this file, see
https://github.com/bminor/glibc/blob/5f72f9800b250410cad3abfeeb09469ef12b2438/sysdeps/unix/sysv/linux/getlogin_r.c

GC> So I am still 'greg' after all. But that doesn't work on the server,
GC> presumably because it uses LDAP or something

 Whatever the server uses, it's still misconfigured if it can't map the
user ID to the user name. I don't know if it helps you whatsoever in
practice and suspect that it doesn't, but I wanted to mention this just in
case it could be helpful to complain to the system administrator about it.

 OTOH a quick web search also found this question which might be relevant:

https://stackoverflow.com/questions/18570177/getpwuid-returns-null-for-ldap-user

It dates from 2013 and your problem is definitely not due to lack of 32 bit
libraries, but I wonder if /lib64/libnss_sss.so might be missing on your
system?

GC> So it seems that, with effort, I can get my numeric user ID, but I can't
GC> get my alphanumeric user name.

 I guess you could use some horrible hack with "ls -n /home" and selecting
the line using correct UID, but it's rather painful to even think about
this...

 Good luck,
VZ

Attachment: pgppoNYz_7SGN.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]