2 * Copyright (C) 2003 Manuel Novoa III <mjn3@uclibc.org>
3 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 /* Nov 6, 2003 Initial version.
10 * NOTE: This implementation is quite strict about requiring all
11 * field seperators. It also does not allow leading whitespace
12 * except when processing the numeric fields. glibc is more
13 * lenient. See the various glibc difference comments below.
16 * Move to dynamic allocation of (currently statically allocated)
17 * buffers; especially for the group-related functions since
18 * large group member lists will cause error returns.
34 #ifdef __UCLIBC_HAS_SHADOW__
37 #include <bits/uClibc_mutex.h>
39 /**********************************************************************/
40 /* Prototypes for internal functions. */
42 extern int __parsepwent(void *pw, char *line) attribute_hidden;
43 extern int __parsegrent(void *gr, char *line) attribute_hidden;
44 extern int __parsespent(void *sp, char *line) attribute_hidden;
46 extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
47 char *__restrict line_buff, size_t buflen, FILE *f) attribute_hidden;
49 extern gid_t* __getgrouplist_internal(const char *user, gid_t gid, int *ngroups) attribute_hidden;
51 /**********************************************************************/
52 /* For the various fget??ent_r funcs, return
55 * ENOENT: end-of-file encountered
56 * ERANGE: buflen too small
57 * other error values possible. See __pgsreader.
59 * Also, *result == resultbuf on success and NULL on failure.
61 * NOTE: glibc difference - For the ENOENT case, glibc also sets errno.
62 * We do not, as it really isn't an error if we reach the end-of-file.
63 * Doing so is analogous to having fgetc() set errno on EOF.
65 /**********************************************************************/
69 int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
70 char *__restrict buffer, size_t buflen,
71 struct passwd **__restrict result)
77 if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) {
83 libc_hidden_def(fgetpwent_r)
87 /**********************************************************************/
91 int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
92 char *__restrict buffer, size_t buflen,
93 struct group **__restrict result)
99 if (!(rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream))) {
105 libc_hidden_def(fgetgrent_r)
109 /**********************************************************************/
112 int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
113 char *__restrict buffer, size_t buflen,
114 struct spwd **__restrict result)
120 if (!(rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream))) {
126 libc_hidden_def(fgetspent_r)
129 /**********************************************************************/
130 /* For the various fget??ent funcs, return NULL on failure and a
131 * pointer to the appropriate struct (statically allocated) on success.
133 /**********************************************************************/
138 struct passwd *fgetpwent(FILE *stream)
140 static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
141 static struct passwd resultbuf;
142 struct passwd *result;
144 fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
150 /**********************************************************************/
155 struct group *fgetgrent(FILE *stream)
157 static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
158 static struct group resultbuf;
159 struct group *result;
161 fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
167 /**********************************************************************/
171 struct spwd *fgetspent(FILE *stream)
173 static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
174 static struct spwd resultbuf;
177 fgetspent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
182 /**********************************************************************/
185 int sgetspent_r(const char *string, struct spwd *result_buf,
186 char *buffer, size_t buflen, struct spwd **result)
192 if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
198 if (string != buffer) {
199 if (strlen(string) >= buflen) {
202 strcpy(buffer, string);
205 if (!(rv = __parsespent(result_buf, buffer))) {
206 *result = result_buf;
212 libc_hidden_def(sgetspent_r)
215 /**********************************************************************/
217 #ifdef GETXXKEY_R_FUNC
218 #error GETXXKEY_R_FUNC is already defined!
222 #define GETXXKEY_R_FUNC getpwnam_r
223 #define GETXXKEY_R_PARSER __parsepwent
224 #define GETXXKEY_R_ENTTYPE struct passwd
225 #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
226 #define DO_GETXXKEY_R_KEYTYPE const char *__restrict
227 #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
228 #include "pwd_grp_internal.c"
232 #define GETXXKEY_R_FUNC getgrnam_r
233 #define GETXXKEY_R_PARSER __parsegrent
234 #define GETXXKEY_R_ENTTYPE struct group
235 #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
236 #define DO_GETXXKEY_R_KEYTYPE const char *__restrict
237 #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
238 #include "pwd_grp_internal.c"
242 #define GETXXKEY_R_FUNC getspnam_r
243 #define GETXXKEY_R_PARSER __parsespent
244 #define GETXXKEY_R_ENTTYPE struct spwd
245 #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
246 #define DO_GETXXKEY_R_KEYTYPE const char *__restrict
247 #define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
248 #include "pwd_grp_internal.c"
252 #define GETXXKEY_R_FUNC getpwuid_r
253 #define GETXXKEY_R_PARSER __parsepwent
254 #define GETXXKEY_R_ENTTYPE struct passwd
255 #define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
256 #define DO_GETXXKEY_R_KEYTYPE uid_t
257 #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
258 #include "pwd_grp_internal.c"
262 #define GETXXKEY_R_FUNC getgrgid_r
263 #define GETXXKEY_R_PARSER __parsegrent
264 #define GETXXKEY_R_ENTTYPE struct group
265 #define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
266 #define DO_GETXXKEY_R_KEYTYPE gid_t
267 #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
268 #include "pwd_grp_internal.c"
271 /**********************************************************************/
275 struct passwd *getpwuid(uid_t uid)
277 static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
278 static struct passwd resultbuf;
279 struct passwd *result;
281 getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
286 /**********************************************************************/
290 struct group *getgrgid(gid_t gid)
292 static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
293 static struct group resultbuf;
294 struct group *result;
296 getgrgid_r(gid, &resultbuf, buffer, sizeof(buffer), &result);
301 /**********************************************************************/
304 /* This function is non-standard and is currently not built. It seems
305 * to have been created as a reentrant version of the non-standard
306 * functions getspuid. Why getspuid was added, I do not know. */
309 int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
310 char *__restrict buffer, size_t buflen,
311 struct spwd **__restrict result)
315 struct passwd password;
316 char pwd_buff[__UCLIBC_PWD_BUFFER_SIZE__];
319 if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) {
320 rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result);
327 /**********************************************************************/
330 /* This function is non-standard and is currently not built.
331 * Why it was added, I do not know. */
333 struct spwd *getspuid(uid_t uid)
335 static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
336 static struct spwd resultbuf;
339 getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
344 /**********************************************************************/
348 struct passwd *getpwnam(const char *name)
350 static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
351 static struct passwd resultbuf;
352 struct passwd *result;
354 getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
357 libc_hidden_def(getpwnam)
360 /**********************************************************************/
364 struct group *getgrnam(const char *name)
366 static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
367 static struct group resultbuf;
368 struct group *result;
370 getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
375 /**********************************************************************/
379 struct spwd *getspnam(const char *name)
381 static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
382 static struct spwd resultbuf;
385 getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
390 /**********************************************************************/
394 int getpw(uid_t uid, char *buf)
396 struct passwd resultbuf;
397 struct passwd *result;
398 char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
402 } else if (!getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result)) {
403 if (sprintf(buf, "%s:%s:%lu:%lu:%s:%s:%s\n",
404 resultbuf.pw_name, resultbuf.pw_passwd,
405 (unsigned long)(resultbuf.pw_uid),
406 (unsigned long)(resultbuf.pw_gid),
407 resultbuf.pw_gecos, resultbuf.pw_dir,
408 resultbuf.pw_shell) >= 0
418 /**********************************************************************/
421 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
423 static FILE *pwf /*= NULL*/;
427 __UCLIBC_MUTEX_LOCK(mylock);
431 __UCLIBC_MUTEX_UNLOCK(mylock);
436 __UCLIBC_MUTEX_LOCK(mylock);
441 __UCLIBC_MUTEX_UNLOCK(mylock);
445 int getpwent_r(struct passwd *__restrict resultbuf,
446 char *__restrict buffer, size_t buflen,
447 struct passwd **__restrict result)
451 __UCLIBC_MUTEX_LOCK(mylock);
453 *result = NULL; /* In case of error... */
456 if (!(pwf = fopen(_PATH_PASSWD, "r"))) {
460 __STDIO_SET_USER_LOCKING(pwf);
463 if (!(rv = __pgsreader(__parsepwent, resultbuf,
464 buffer, buflen, pwf))) {
469 __UCLIBC_MUTEX_UNLOCK(mylock);
473 libc_hidden_def(getpwent_r)
476 /**********************************************************************/
478 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
480 static FILE *grf /*= NULL*/;
484 __UCLIBC_MUTEX_LOCK(mylock);
488 __UCLIBC_MUTEX_UNLOCK(mylock);
493 __UCLIBC_MUTEX_LOCK(mylock);
498 __UCLIBC_MUTEX_UNLOCK(mylock);
501 int getgrent_r(struct group *__restrict resultbuf,
502 char *__restrict buffer, size_t buflen,
503 struct group **__restrict result)
507 __UCLIBC_MUTEX_LOCK(mylock);
509 *result = NULL; /* In case of error... */
512 if (!(grf = fopen(_PATH_GROUP, "r"))) {
516 __STDIO_SET_USER_LOCKING(grf);
519 if (!(rv = __pgsreader(__parsegrent, resultbuf,
520 buffer, buflen, grf))) {
525 __UCLIBC_MUTEX_UNLOCK(mylock);
529 libc_hidden_def(getgrent_r)
532 /**********************************************************************/
534 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
536 static FILE *spf /*= NULL*/;
540 __UCLIBC_MUTEX_LOCK(mylock);
544 __UCLIBC_MUTEX_UNLOCK(mylock);
549 __UCLIBC_MUTEX_LOCK(mylock);
554 __UCLIBC_MUTEX_UNLOCK(mylock);
557 int getspent_r(struct spwd *resultbuf, char *buffer,
558 size_t buflen, struct spwd **result)
562 __UCLIBC_MUTEX_LOCK(mylock);
564 *result = NULL; /* In case of error... */
567 if (!(spf = fopen(_PATH_SHADOW, "r"))) {
571 __STDIO_SET_USER_LOCKING(spf);
574 if (!(rv = __pgsreader(__parsespent, resultbuf,
575 buffer, buflen, spf))) {
580 __UCLIBC_MUTEX_UNLOCK(mylock);
584 libc_hidden_def(getspent_r)
587 /**********************************************************************/
591 struct passwd *getpwent(void)
593 static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
594 static struct passwd pwd;
595 struct passwd *result;
597 getpwent_r(&pwd, line_buff, sizeof(line_buff), &result);
602 /**********************************************************************/
606 struct group *getgrent(void)
608 static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
609 static struct group gr;
610 struct group *result;
612 getgrent_r(&gr, line_buff, sizeof(line_buff), &result);
617 /**********************************************************************/
621 struct spwd *getspent(void)
623 static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
624 static struct spwd spwd;
627 getspent_r(&spwd, line_buff, sizeof(line_buff), &result);
632 /**********************************************************************/
636 struct spwd *sgetspent(const char *string)
638 static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
639 static struct spwd spwd;
642 sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
647 /**********************************************************************/
648 #ifdef L___getgrouplist_internal
650 gid_t attribute_hidden *__getgrouplist_internal(const char *user, gid_t gid, int *ngroups)
656 char buff[__UCLIBC_PWD_BUFFER_SIZE__];
658 *ngroups = num_groups = 1;
660 /* We alloc space for 8 gids at a time. */
661 group_list = malloc(8 * sizeof(group_list[0]));
666 grfile = fopen(_PATH_GROUP, "r");
667 /* If /etc/group doesn't exist, we still return 1-element vector */
671 __STDIO_SET_USER_LOCKING(grfile);
673 while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grfile)) {
676 assert(group.gr_mem); /* Must have at least a NULL terminator. */
677 if (group.gr_gid == gid)
679 for (m = group.gr_mem; *m; m++) {
680 if (strcmp(*m, user) != 0)
682 if (!(num_groups & 7)) {
683 gid_t *tmp = realloc(group_list, (num_groups+8) * sizeof(group_list[0]));
688 group_list[num_groups++] = group.gr_gid;
695 *ngroups = num_groups;
700 /**********************************************************************/
701 #ifdef L_getgrouplist
703 #if defined __USE_BSD || defined __USE_GNU
704 int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
707 gid_t *group_list = __getgrouplist_internal(user, gid, ngroups);
710 /* malloc failure - what shall we do?
711 * fail with ENOMEM? I bet users never check for that */
712 /* *ngroups = 1; - already done by __getgrouplist_internal */
719 /* *ngroups is non-zero here */
724 memcpy(groups, group_list, sz * sizeof(group_list[0]));
733 /**********************************************************************/
738 int initgroups(const char *user, gid_t gid)
741 int num_groups = ((unsigned)~0) >> 1; /* INT_MAX */
742 gid_t *group_list = __getgrouplist_internal(user, gid, &num_groups);
745 rv = setgroups(num_groups, group_list);
752 /**********************************************************************/
756 int putpwent(const struct passwd *__restrict p, FILE *__restrict f)
763 /* No extra thread locking is needed above what fprintf does. */
764 if (fprintf(f, "%s:%s:%lu:%lu:%s:%s:%s\n",
765 p->pw_name, p->pw_passwd,
766 (unsigned long)(p->pw_uid),
767 (unsigned long)(p->pw_gid),
768 p->pw_gecos, p->pw_dir, p->pw_shell) >= 0
779 /**********************************************************************/
782 int putgrent(const struct group *__restrict p, FILE *__restrict f)
784 static const char format[] = ",%s";
788 __STDIO_AUTO_THREADLOCK_VAR;
790 if (!p || !f) { /* Sigh... glibc checks. */
793 __STDIO_AUTO_THREADLOCK(f);
795 if (fprintf(f, "%s:%s:%lu:",
796 p->gr_name, p->gr_passwd,
797 (unsigned long)(p->gr_gid)) >= 0
807 if (__fputc_unlocked('\n', f) >= 0) {
812 if (fprintf(f, fmt, *m) < 0) {
821 __STDIO_AUTO_THREADUNLOCK(f);
828 /**********************************************************************/
831 static const unsigned char _sp_off[] = {
832 offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
833 offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
834 offsetof(struct spwd, sp_max), /* 4 - not a char ptr */
835 offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
836 offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
837 offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
840 int putspent(const struct spwd *p, FILE *stream)
842 static const char ld_format[] = "%ld:";
847 __STDIO_AUTO_THREADLOCK_VAR;
849 /* Unlike putpwent and putgrent, glibc does not check the args. */
851 __STDIO_AUTO_THREADLOCK(stream);
853 if (fprintf(stream, "%s:%s:", p->sp_namp,
854 (p->sp_pwdp ? p->sp_pwdp : "")) < 0
859 for (i=0 ; i < sizeof(_sp_off) ; i++) {
861 if ((x = *(const long int *)(((const char *) p) + _sp_off[i])) == -1) {
864 if (fprintf(stream, f, x) < 0) {
869 if ((p->sp_flag != ~0UL) && (fprintf(stream, "%lu", p->sp_flag) < 0)) {
873 if (__fputc_unlocked('\n', stream) > 0) {
878 __STDIO_AUTO_THREADUNLOCK(stream);
884 /**********************************************************************/
885 /* Internal uClibc functions. */
886 /**********************************************************************/
887 #ifdef L___parsepwent
889 static const unsigned char pw_off[] = {
890 offsetof(struct passwd, pw_name), /* 0 */
891 offsetof(struct passwd, pw_passwd), /* 1 */
892 offsetof(struct passwd, pw_uid), /* 2 - not a char ptr */
893 offsetof(struct passwd, pw_gid), /* 3 - not a char ptr */
894 offsetof(struct passwd, pw_gecos), /* 4 */
895 offsetof(struct passwd, pw_dir), /* 5 */
896 offsetof(struct passwd, pw_shell) /* 6 */
899 int attribute_hidden __parsepwent(void *data, char *line)
907 p = ((char *) ((struct passwd *) data)) + pw_off[i];
909 if ((i & 6) ^ 2) { /* i!=2 and i!=3 */
910 *((char **) p) = line;
914 /* NOTE: glibc difference - glibc allows omission of
915 * ':' seperators after the gid field if all remaining
916 * entries are empty. We require all separators. */
917 if (!(line = strchr(line, ':'))) {
921 unsigned long t = strtoul(line, &endptr, 10);
922 /* Make sure we had at least one digit, and that the
923 * failing char is the next field seperator ':'. See
924 * glibc difference note above. */
925 /* TODO: Also check for leading whitespace? */
926 if ((endptr == line) || (*endptr != ':')) {
930 if (i & 1) { /* i == 3 -- gid */
932 } else { /* i == 2 -- uid */
945 /**********************************************************************/
946 #ifdef L___parsegrent
948 static const unsigned char gr_off[] = {
949 offsetof(struct group, gr_name), /* 0 */
950 offsetof(struct group, gr_passwd), /* 1 */
951 offsetof(struct group, gr_gid) /* 2 - not a char ptr */
954 int attribute_hidden __parsegrent(void *data, char *line)
962 end_of_buf = ((struct group *) data)->gr_name; /* Evil hack! */
965 p = ((char *) ((struct group *) data)) + gr_off[i];
968 *((char **) p) = line;
969 if (!(line = strchr(line, ':'))) {
975 *((gid_t *) p) = strtoul(line, &endptr, 10);
977 /* NOTE: glibc difference - glibc allows omission of the
978 * trailing colon when there is no member list. We treat
979 * this as an error. */
981 /* Make sure we had at least one digit, and that the
982 * failing char is the next field seperator ':'. See
983 * glibc difference note above. */
984 if ((endptr == line) || (*endptr != ':')) {
988 i = 1; /* Count terminating NULL ptr. */
991 if (p[1]) { /* We have a member list to process. */
992 /* Overwrite the last ':' with a ',' before counting.
993 * This allows us to test for initial ',' and adds
994 * one ',' so that the ',' count equals the member
998 /* NOTE: glibc difference - glibc allows and trims leading
999 * (but not trailing) space. We treat this as an error. */
1000 /* NOTE: glibc difference - glibc allows consecutive and
1001 * trailing commas, and ignores "empty string" users. We
1002 * treat this as an error. */
1005 *p = 0; /* nul-terminate each member string. */
1006 if (!*++p || (*p == ',') || isspace(*p)) {
1013 /* Now align (p+1), rounding up. */
1014 /* Assumes sizeof(char **) is a power of 2. */
1015 members = (char **)( (((intptr_t) p) + sizeof(char **))
1016 & ~((intptr_t)(sizeof(char **) - 1)) );
1018 if (((char *)(members + i)) > end_of_buf) { /* No space. */
1022 ((struct group *) data)->gr_mem = members;
1025 p = endptr; /* Pointing to char prior to first member. */
1043 /**********************************************************************/
1044 #ifdef L___parsespent
1046 static const unsigned char sp_off[] = {
1047 offsetof(struct spwd, sp_namp), /* 0 */
1048 offsetof(struct spwd, sp_pwdp), /* 1 */
1049 offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
1050 offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
1051 offsetof(struct spwd, sp_max), /* 4 - not a char ptr */
1052 offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
1053 offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
1054 offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
1055 offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
1058 int attribute_hidden __parsespent(void *data, char * line)
1066 p = ((char *) ((struct spwd *) data)) + sp_off[i];
1068 *((char **) p) = line;
1069 if (!(line = strchr(line, ':'))) {
1074 if (i==5) { /* Support for old format. */
1075 while (isspace(*line)) ++line; /* glibc eats space here. */
1077 ((struct spwd *) data)->sp_warn = -1;
1078 ((struct spwd *) data)->sp_inact = -1;
1079 ((struct spwd *) data)->sp_expire = -1;
1080 ((struct spwd *) data)->sp_flag = ~0UL;
1086 *((long *) p) = (long) strtoul(line, &endptr, 10);
1088 if (endptr == line) {
1089 *((long *) p) = ((i != 8) ? -1L : ((long)(~0UL)));
1101 if (*endptr != ':') {
1115 /**********************************************************************/
1116 #ifdef L___pgsreader
1118 /* Reads until if EOF, or until if finds a line which fits in the buffer
1119 * and for which the parser function succeeds.
1121 * Returns 0 on success and ENOENT for end-of-file (glibc concession).
1124 int attribute_hidden __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
1125 char *__restrict line_buff, size_t buflen, FILE *f)
1130 __STDIO_AUTO_THREADLOCK_VAR;
1132 if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
1135 __STDIO_AUTO_THREADLOCK(f);
1139 if (!fgets_unlocked(line_buff, buflen, f)) {
1140 if (feof_unlocked(f)) {
1146 line_len = strlen(line_buff) - 1; /* strlen() must be > 0. */
1147 if (line_buff[line_len] == '\n') {
1148 line_buff[line_len] = 0;
1149 } else if (line_len + 2 == buflen) { /* line too long */
1159 /* NOTE: glibc difference - glibc strips leading whitespace from
1160 * records. We do not allow leading whitespace. */
1162 /* Skip empty lines, comment lines, and lines with leading
1164 if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) {
1165 if (__parserfunc == __parsegrent) { /* Do evil group hack. */
1166 /* The group entry parsing function needs to know where
1167 * the end of the buffer is so that it can construct the
1168 * group member ptr table. */
1169 ((struct group *) data)->gr_name = line_buff + buflen;
1172 if (!__parserfunc(data, line_buff)) {
1179 __STDIO_AUTO_THREADUNLOCK(f);
1186 /**********************************************************************/