e354a5
From ee1c062be09da006e82ab34c1c9b5c82dd2af92c Mon Sep 17 00:00:00 2001
e354a5
From: Florian Weimer <fweimer@redhat.com>
e354a5
Date: Thu, 16 Jul 2020 17:34:19 +0200
e354a5
Subject: [PATCH 09/11] pwd: Implement fgetpwent_r using __nss_fgetent_r
e354a5
e354a5
Tested-by: Carlos O'Donell <carlos@redhat.com>
e354a5
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
e354a5
---
e354a5
 pwd/fgetpwent_r.c | 43 ++++++-------------------------------------
e354a5
 1 file changed, 6 insertions(+), 37 deletions(-)
e354a5
e354a5
diff -rup a/pwd/fgetpwent_r.c b/pwd/fgetpwent_r.c
e354a5
--- a/pwd/fgetpwent_r.c	2018-08-01 01:10:47.000000000 -0400
e354a5
+++ b/pwd/fgetpwent_r.c	2020-09-14 19:03:41.277514743 -0400
e354a5
@@ -20,9 +20,6 @@
e354a5
 #include <stdio.h>
e354a5
 #include <pwd.h>
e354a5
 
e354a5
-#define flockfile(s) _IO_flockfile (s)
e354a5
-#define funlockfile(s) _IO_funlockfile (s)
e354a5
-
e354a5
 /* Define a line parsing function using the common code
e354a5
    used in the nss_files module.  */
e354a5
 
e354a5
@@ -72,39 +69,11 @@ int
e354a5
 __fgetpwent_r (FILE *stream, struct passwd *resbuf, char *buffer,
e354a5
 	       size_t buflen, struct passwd **result)
e354a5
 {
e354a5
-  char *p;
e354a5
-
e354a5
-  flockfile (stream);
e354a5
-  do
e354a5
-    {
e354a5
-      buffer[buflen - 1] = '\xff';
e354a5
-      p = fgets_unlocked (buffer, buflen, stream);
e354a5
-      if (p == NULL && feof_unlocked (stream))
e354a5
-	{
e354a5
-	  funlockfile (stream);
e354a5
-	  *result = NULL;
e354a5
-	  __set_errno (ENOENT);
e354a5
-	  return errno;
e354a5
-	}
e354a5
-      if (p == NULL || buffer[buflen - 1] != '\xff')
e354a5
-	{
e354a5
-	  funlockfile (stream);
e354a5
-	  *result = NULL;
e354a5
-	  __set_errno (ERANGE);
e354a5
-	  return errno;
e354a5
-	}
e354a5
-
e354a5
-      /* Skip leading blanks.  */
e354a5
-      while (isspace (*p))
e354a5
-	++p;
e354a5
-    } while (*p == '\0' || *p == '#' ||	/* Ignore empty and comment lines.  */
e354a5
-	     /* Parse the line.  If it is invalid, loop to
e354a5
-		get the next line of the file to parse.  */
e354a5
-	     ! parse_line (p, resbuf, (void *) buffer, buflen, &errno));
e354a5
-
e354a5
-  funlockfile (stream);
e354a5
-
e354a5
-  *result = resbuf;
e354a5
-  return 0;
e354a5
+  int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
e354a5
+  if (ret == 0)
e354a5
+    *result = resbuf;
e354a5
+  else
e354a5
+    *result = NULL;
e354a5
+  return ret;
e354a5
 }
e354a5
 weak_alias (__fgetpwent_r, fgetpwent_r)