public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/google/grte/v5-2.27/master] Augment borg-pwd to also search through passwd.borg.base, if it exists.
@ 2021-08-28  0:40 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-28  0:40 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f098d7ac4c329175e9bf03d6462aa3a69b5ad5b6

commit f098d7ac4c329175e9bf03d6462aa3a69b5ad5b6
Author: Michael Rothwell <mrothwell@google.com>
Date:   Fri Sep 30 06:09:04 2016 -0700

    Augment borg-pwd to also search through passwd.borg.base, if it exists.

Diff:
---
 nss/nss_borg/borg-pwd.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/nss/nss_borg/borg-pwd.c b/nss/nss_borg/borg-pwd.c
index c4ff035984..4f6c5443e8 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-28  0:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28  0:40 [glibc/google/grte/v5-2.27/master] Augment borg-pwd to also search through passwd.borg.base, if it exists Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).