diff options
author | Michael Rothwell <mrothwell@google.com> | 2016-09-30 06:09:04 -0700 |
---|---|---|
committer | Michael Rothwell <mrothwell@google.com> | 2016-09-30 06:09:04 -0700 |
commit | ad9d6e1dbecb0dabe522d6efc793a4bc2bee2140 (patch) | |
tree | a3e94f01f45746294fe23d43d351ae9f166b05f0 | |
parent | 74b27c48cba48d5fad9cf500e1965ac64692c091 (diff) | |
download | glibc-ad9d6e1dbecb0dabe522d6efc793a4bc2bee2140.zip glibc-ad9d6e1dbecb0dabe522d6efc793a4bc2bee2140.tar.gz glibc-ad9d6e1dbecb0dabe522d6efc793a4bc2bee2140.tar.bz2 |
Augment borg-pwd to also search through passwd.borg.base, if it exists.
-rw-r--r-- | nss/nss_borg/borg-pwd.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/nss/nss_borg/borg-pwd.c b/nss/nss_borg/borg-pwd.c index 61b2944..97a9a93 100644 --- a/nss/nss_borg/borg-pwd.c +++ b/nss/nss_borg/borg-pwd.c @@ -1,9 +1,6 @@ -// Copyright 2004 Google Inc. -// Author: Paul Menage - -// An NSS module that extends local user account lookup to the file /etc/passwd.borg -// (Despite the suggestive name, passwd.borg is just a second file in the standard -// passwd format, separated for various reasons. -sts 2015) +// An NSS module that extends local user account lookup to the files +// /etc/passwd.borg and /etc/passwd.borg.base +// passwd.borg.base is a subset of passwd.borg that is used as a fallback. #include <stdio.h> #include <pwd.h> @@ -18,6 +15,7 @@ __libc_lock_define_initialized (static, lock) #define NSSBORG_UNLOCK __libc_lock_unlock (lock); static FILE *f; +static FILE *fb; #define DEBUG(fmt, ...) @@ -29,7 +27,10 @@ static enum nss_status _nss_borg_setpwent_locked(void) { DEBUG("Opening passwd.borg\n"); f = fopen("/etc/passwd.borg", "r"); - if (f) { + DEBUG("Opening passwd.borg.base\n"); + fb = fopen("/etc/passwd.borg.base", "r"); + + if (f||fb) { return NSS_STATUS_SUCCESS; } else { return NSS_STATUS_UNAVAIL; @@ -58,6 +59,11 @@ static enum nss_status _nss_borg_endpwent_locked(void) { fclose(f); f = NULL; } + DEBUG("Closing passwd.borg.base\n"); + if (fb) { + fclose(fb); + fb = NULL; + } return NSS_STATUS_SUCCESS; } @@ -81,8 +87,13 @@ static enum nss_status _nss_borg_getpwent_r_locked(struct passwd *result, enum nss_status ret; - if (fgetpwent_r(f, result, buffer, buflen, &result) == 0) { - DEBUG("Returning user %d:%s\n", result->pw_uid, result->pw_name); + if (f != NULL + && fgetpwent_r(f, result, buffer, buflen, &result) == 0) { + DEBUG("Returning borg user %d:%s\n", result->pw_uid, result->pw_name); + ret = NSS_STATUS_SUCCESS; + } else if (fb != NULL + && getpwent_r(fb, result, buffer, buflen, &result) == 0) { + DEBUG("Returning base user %d:%s\n", result->pw_uid, result->pw_name); ret = NSS_STATUS_SUCCESS; } else { *errnop = errno; |