|
|
446cf2 |
From 00bc6830e3fe3f10495917afe0835ddd19133c6a Mon Sep 17 00:00:00 2001
|
|
|
446cf2 |
From: Florian Weimer <fweimer@redhat.com>
|
|
|
446cf2 |
Date: Thu, 16 Jul 2020 17:34:43 +0200
|
|
|
446cf2 |
Subject: [PATCH 10/11] shadow: Implement fgetspent_r using __nss_fgetent_r
|
|
|
446cf2 |
|
|
|
446cf2 |
Tested-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
446cf2 |
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
446cf2 |
---
|
|
|
446cf2 |
gshadow/tst-fgetsgent_r.c | 1 +
|
|
|
446cf2 |
shadow/fgetspent_r.c | 43 ++++++-------------------------------------
|
|
|
446cf2 |
2 files changed, 7 insertions(+), 37 deletions(-)
|
|
|
446cf2 |
|
|
|
446cf2 |
diff -rup a/gshadow/tst-fgetsgent_r.c b/gshadow/tst-fgetsgent_r.c
|
|
|
446cf2 |
--- a/gshadow/tst-fgetsgent_r.c 2020-09-14 18:00:57.174146151 -0400
|
|
|
446cf2 |
+++ b/gshadow/tst-fgetsgent_r.c 2020-09-14 19:12:57.867548005 -0400
|
|
|
446cf2 |
@@ -168,6 +168,7 @@ run_test (const char *path, size_t buffe
|
|
|
446cf2 |
free (result_storage);
|
|
|
446cf2 |
}
|
|
|
446cf2 |
|
|
|
446cf2 |
+ xfclose (fp);
|
|
|
446cf2 |
return resized;
|
|
|
446cf2 |
}
|
|
|
446cf2 |
|
|
|
446cf2 |
diff -rup a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
|
|
|
446cf2 |
--- a/shadow/fgetspent_r.c 2018-08-01 01:10:47.000000000 -0400
|
|
|
446cf2 |
+++ b/shadow/fgetspent_r.c 2020-09-14 19:17:15.623285970 -0400
|
|
|
446cf2 |
@@ -20,9 +20,6 @@
|
|
|
446cf2 |
#include <shadow.h>
|
|
|
446cf2 |
#include <stdio.h>
|
|
|
446cf2 |
|
|
|
446cf2 |
-#define flockfile(s) _IO_flockfile (s)
|
|
|
446cf2 |
-#define funlockfile(s) _IO_funlockfile (s)
|
|
|
446cf2 |
-
|
|
|
446cf2 |
/* Define a line parsing function using the common code
|
|
|
446cf2 |
used in the nss_files module. */
|
|
|
446cf2 |
|
|
|
446cf2 |
@@ -39,39 +36,11 @@ int
|
|
|
446cf2 |
__fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
|
|
|
446cf2 |
struct spwd **result)
|
|
|
446cf2 |
{
|
|
|
446cf2 |
- char *p;
|
|
|
446cf2 |
-
|
|
|
446cf2 |
- flockfile (stream);
|
|
|
446cf2 |
- do
|
|
|
446cf2 |
- {
|
|
|
446cf2 |
- buffer[buflen - 1] = '\xff';
|
|
|
446cf2 |
- p = fgets_unlocked (buffer, buflen, stream);
|
|
|
446cf2 |
- if (p == NULL && feof_unlocked (stream))
|
|
|
446cf2 |
- {
|
|
|
446cf2 |
- funlockfile (stream);
|
|
|
446cf2 |
- *result = NULL;
|
|
|
446cf2 |
- __set_errno (ENOENT);
|
|
|
446cf2 |
- return errno;
|
|
|
446cf2 |
- }
|
|
|
446cf2 |
- if (p == NULL || buffer[buflen - 1] != '\xff')
|
|
|
446cf2 |
- {
|
|
|
446cf2 |
- funlockfile (stream);
|
|
|
446cf2 |
- *result = NULL;
|
|
|
446cf2 |
- __set_errno (ERANGE);
|
|
|
446cf2 |
- return errno;
|
|
|
446cf2 |
- }
|
|
|
446cf2 |
-
|
|
|
446cf2 |
- /* Skip leading blanks. */
|
|
|
446cf2 |
- while (isspace (*p))
|
|
|
446cf2 |
- ++p;
|
|
|
446cf2 |
- } while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
|
|
|
446cf2 |
- /* Parse the line. If it is invalid, loop to
|
|
|
446cf2 |
- get the next line of the file to parse. */
|
|
|
446cf2 |
- ! parse_line (buffer, (void *) resbuf, NULL, 0, &errno));
|
|
|
446cf2 |
-
|
|
|
446cf2 |
- funlockfile (stream);
|
|
|
446cf2 |
-
|
|
|
446cf2 |
- *result = resbuf;
|
|
|
446cf2 |
- return 0;
|
|
|
446cf2 |
+ int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
|
|
|
446cf2 |
+ if (ret == 0)
|
|
|
446cf2 |
+ *result = resbuf;
|
|
|
446cf2 |
+ else
|
|
|
446cf2 |
+ *result = NULL;
|
|
|
446cf2 |
+ return ret;
|
|
|
446cf2 |
}
|
|
|
446cf2 |
weak_alias (__fgetspent_r, fgetspent_r)
|