e354a5
From 4f62a21d0ed19ff29bba704167179b862140d011 Mon Sep 17 00:00:00 2001
e354a5
From: Florian Weimer <fweimer@redhat.com>
e354a5
Date: Thu, 16 Jul 2020 17:28:28 +0200
e354a5
Subject: [PATCH 07/11] grp: Implement fgetgrent_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
 grp/fgetgrent_r.c | 54 ++++++------------------------------------------------
e354a5
 1 file changed, 6 insertions(+), 48 deletions(-)
e354a5
e354a5
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
e354a5
index 03daf4f..b598584 100644
e354a5
--- a/grp/fgetgrent_r.c
e354a5
+++ b/grp/fgetgrent_r.c
e354a5
@@ -20,10 +20,6 @@
e354a5
 #include <grp.h>
e354a5
 #include <stdio.h>
e354a5
 
e354a5
-#include <libio/iolibio.h>
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
@@ -59,49 +55,11 @@ int
e354a5
 __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
e354a5
 	       struct group **result)
e354a5
 {
e354a5
-  char *p;
e354a5
-  int parse_result;
e354a5
-
e354a5
-  flockfile (stream);
e354a5
-  do
e354a5
-    {
e354a5
-      buffer[buflen - 1] = '\xff';
e354a5
-      p = fgets_unlocked (buffer, buflen, stream);
e354a5
-      if (__builtin_expect (p == NULL, 0) && feof_unlocked (stream))
e354a5
-	{
e354a5
-	  funlockfile (stream);
e354a5
-	  *result = NULL;
e354a5
-	  __set_errno (ENOENT);
e354a5
-	  return errno;
e354a5
-	}
e354a5
-      if (__builtin_expect (p == NULL, 0) || 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_result = parse_line (p, resbuf,
e354a5
-					      (void *) buffer, buflen,
e354a5
-					      &errno)));
e354a5
-
e354a5
-  funlockfile (stream);
e354a5
-
e354a5
-  if (__builtin_expect (parse_result, 0) == -1)
e354a5
-    {
e354a5
-      /* The parser ran out of space.  */
e354a5
-      *result = NULL;
e354a5
-      return errno;
e354a5
-    }
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 (__fgetgrent_r, fgetgrent_r)
e354a5
-- 
e354a5
1.8.3.1
e354a5