Question on /etc/nsswitch.conf

Yury Norov ynorov@caviumnetworks.com
Wed Sep 27 21:50:00 GMT 2017


Hi all,

Recently Linaro issued the toolchain for arm64/ilp32 [1], and
running LTP compiled with it, I found multiple regressions. I
tracked them down to function family getpw*(). The problem is
that they return NULL, and don't set any errno.

#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <unistd.h>

int main(void)
{
        struct passwd *pwent;
        uid_t uid = getuid();
        printf("uid  == %d, errno = %d\n", uid,
                        errno);

        pwent = getpwuid(uid);
        printf("pwent  == %p, errno == %d\n", pwent, errno);

        return 0;
}

Steve Ellcey noticed that it's related to the "passwd: compat"
record in /etc/nsswitch.conf. On my testing system (Ubuntu 14.04) I replaced the
file with one coming in glibc sources (passwd is "db_files" there), and it fixed
the problem.

By this email I'd like to report the issue to community and ask some
questions:
 - I think it shuld be a bug if function returns NULL instead the pointer
   to the structure, and doesn't set errno. The POSIX [2] is not
   specific here: "If getpwuid() returns a null pointer and errno is
   set to non-zero, an error occurred". But if getpwuid() returns null,
   it is an error from user point of view (LTP treats is like this for
   example). But Glibc doesn't set errno, and POSIX doesn't restrict it
   explicitly.
 - system may host many toolchains, but there's a single nsswitch.conf
   for them all. It raises the problem of compatibility of settings,
   like this one. Fortunately, in this case I can modify the
   nsswitch.conf to make it suitable for both lp64 and ilp32 toolchains,
   but it may become a problem in general case... The most straightforward
   solution is to introduce a system variable that allows to alternate the 
   file path, but discussion on resolv.conf [3] shows that there may be
   other considerations. So I don't have the answer what to do.
 - On the other hand, it might be considered as local problem of
   Debian distro. In that case, I would like to ask if there's any way
   to update nsswitch.conf while installing the new library? People
   soon will start use the toolchain, and will have the problem. I
   think that now GLIBC is not informative in this case and doesn't help
   to track the issue down, even if the issue is not in GLIBC itself,
   but in configuration files. Can we change it? I think that simple
   warning would be lot helpful.

Yury

[1] http://snapshots.linaro.org/components/toolchain/binaries/7.1-2017.08-rc1/aarch64-linux-gnu_ilp32/
[2] http://pubs.opengroup.org/onlinepubs/9699919799/
[3] https://sourceware.org/ml/libc-alpha/2017-08/msg00742.html



More information about the Libc-alpha mailing list