|
|
e354a5 |
From 00bc6830e3fe3f10495917afe0835ddd19133c6a Mon Sep 17 00:00:00 2001
|
|
|
e354a5 |
From: Florian Weimer <fweimer@redhat.com>
|
|
|
e354a5 |
Date: Thu, 16 Jul 2020 17:34:43 +0200
|
|
|
e354a5 |
Subject: [PATCH 10/11] shadow: Implement fgetspent_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 |
gshadow/tst-fgetsgent_r.c | 1 +
|
|
|
e354a5 |
shadow/fgetspent_r.c | 43 ++++++-------------------------------------
|
|
|
e354a5 |
2 files changed, 7 insertions(+), 37 deletions(-)
|
|
|
e354a5 |
|
|
|
e354a5 |
diff -rup a/gshadow/tst-fgetsgent_r.c b/gshadow/tst-fgetsgent_r.c
|
|
|
e354a5 |
--- a/gshadow/tst-fgetsgent_r.c 2020-09-14 18:00:57.174146151 -0400
|
|
|
e354a5 |
+++ b/gshadow/tst-fgetsgent_r.c 2020-09-14 19:12:57.867548005 -0400
|
|
|
e354a5 |
@@ -168,6 +168,7 @@ run_test (const char *path, size_t buffe
|
|
|
e354a5 |
free (result_storage);
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
+ xfclose (fp);
|
|
|
e354a5 |
return resized;
|
|
|
e354a5 |
}
|
|
|
e354a5 |
|
|
|
e354a5 |
diff -rup a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
|
|
|
e354a5 |
--- a/shadow/fgetspent_r.c 2018-08-01 01:10:47.000000000 -0400
|
|
|
e354a5 |
+++ b/shadow/fgetspent_r.c 2020-09-14 19:17:15.623285970 -0400
|
|
|
e354a5 |
@@ -20,9 +20,6 @@
|
|
|
e354a5 |
#include <shadow.h>
|
|
|
e354a5 |
#include <stdio.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 |
@@ -39,39 +36,11 @@ int
|
|
|
e354a5 |
__fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
|
|
|
e354a5 |
struct spwd **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 (buffer, (void *) resbuf, NULL, 0, &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 (__fgetspent_r, fgetspent_r)
|