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