1 /* Copyright (C) 2009-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <ctype.h>
19 #include <errno.h>
20 #include <gshadow.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 /* Define a line parsing function using the common code
25 used in the nss_files module. */
26
27 #define STRUCTURE sgrp
28 #define ENTNAME sgent
29 struct sgent_data {};
30
31
32 #define TRAILING_LIST_MEMBER sg_mem
33 #define TRAILING_LIST_SEPARATOR_P(c) ((c) == ',')
34 #include <nss/nss_files/files-parse.c>
35 LINE_PARSER
36 (,
37 STRING_FIELD (result->sg_namp, ISCOLON, 0);
38 if (line[0] == '\0'
39 && (result->sg_namp[0] == '+' || result->sg_namp[0] == '-'))
40 {
41 result->sg_passwd = NULL;
42 result->sg_adm = NULL;
43 result->sg_mem = NULL;
44 }
45 else
46 {
47 STRING_FIELD (result->sg_passwd, ISCOLON, 0);
48 STRING_LIST (result->sg_adm, ':');
49 }
50 )
51
52
53 /* Read one shadow entry from the given stream. */
54 int
__sgetsgent_r(const char * string,struct sgrp * resbuf,char * buffer,size_t buflen,struct sgrp ** result)55 __sgetsgent_r (const char *string, struct sgrp *resbuf, char *buffer,
56 size_t buflen, struct sgrp **result)
57 {
58 char *sp;
59 if (string < buffer || string >= buffer + buflen)
60 {
61 buffer[buflen - 1] = '\0';
62 sp = strncpy (buffer, string, buflen);
63 if (buffer[buflen - 1] != '\0')
64 return ERANGE;
65 }
66 else
67 sp = (char *) string;
68
69 int parse_result = parse_line (sp, resbuf, (void *) buffer, buflen, &errno);
70 *result = parse_result > 0 ? resbuf : NULL;
71
72 return *result == NULL ? errno : 0;
73 }
74 weak_alias (__sgetsgent_r, sgetsgent_r)
75