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
);
359 /**********************************************************************/
363 struct group
*getgrnam(const char *name
)
365 static char buffer
[__UCLIBC_GRP_BUFFER_SIZE__
];
366 static struct group resultbuf
;
367 struct group
*result
;
369 getgrnam_r(name
, &resultbuf
, buffer
, sizeof(buffer
), &result
);
374 /**********************************************************************/
378 struct spwd
*getspnam(const char *name
)
380 static char buffer
[__UCLIBC_PWD_BUFFER_SIZE__
];
381 static struct spwd resultbuf
;
384 getspnam_r(name
, &resultbuf
, buffer
, sizeof(buffer
), &result
);
389 /**********************************************************************/
393 int getpw(uid_t uid
, char *buf
)
395 struct passwd resultbuf
;
396 struct passwd
*result
;
397 char buffer
[__UCLIBC_PWD_BUFFER_SIZE__
];
401 } else if (!getpwuid_r(uid
, &resultbuf
, buffer
, sizeof(buffer
), &result
)) {
402 if (sprintf(buf
, "%s:%s:%lu:%lu:%s:%s:%s\n",
403 resultbuf
.pw_name
, resultbuf
.pw_passwd
,
404 (unsigned long)(resultbuf
.pw_uid
),
405 (unsigned long)(resultbuf
.pw_gid
),
406 resultbuf
.pw_gecos
, resultbuf
.pw_dir
,
407 resultbuf
.pw_shell
) >= 0
417 /**********************************************************************/
420 __UCLIBC_MUTEX_STATIC(mylock
, PTHREAD_MUTEX_INITIALIZER
);
422 static FILE *pwf
/*= NULL*/;
426 __UCLIBC_MUTEX_LOCK(mylock
);
430 __UCLIBC_MUTEX_UNLOCK(mylock
);
435 __UCLIBC_MUTEX_LOCK(mylock
);
440 __UCLIBC_MUTEX_UNLOCK(mylock
);
444 int getpwent_r(struct passwd
*__restrict resultbuf
,
445 char *__restrict buffer
, size_t buflen
,
446 struct passwd
**__restrict result
)
450 __UCLIBC_MUTEX_LOCK(mylock
);
452 *result
= NULL
; /* In case of error... */
455 if (!(pwf
= fopen(_PATH_PASSWD
, "r"))) {
459 __STDIO_SET_USER_LOCKING(pwf
);
462 if (!(rv
= __pgsreader(__parsepwent
, resultbuf
,
463 buffer
, buflen
, pwf
))) {
468 __UCLIBC_MUTEX_UNLOCK(mylock
);
472 libc_hidden_def(getpwent_r
)
475 /**********************************************************************/
477 __UCLIBC_MUTEX_STATIC(mylock
, PTHREAD_MUTEX_INITIALIZER
);
479 static FILE *grf
/*= NULL*/;
483 __UCLIBC_MUTEX_LOCK(mylock
);
487 __UCLIBC_MUTEX_UNLOCK(mylock
);
492 __UCLIBC_MUTEX_LOCK(mylock
);
497 __UCLIBC_MUTEX_UNLOCK(mylock
);
500 int getgrent_r(struct group
*__restrict resultbuf
,
501 char *__restrict buffer
, size_t buflen
,
502 struct group
**__restrict result
)
506 __UCLIBC_MUTEX_LOCK(mylock
);
508 *result
= NULL
; /* In case of error... */
511 if (!(grf
= fopen(_PATH_GROUP
, "r"))) {
515 __STDIO_SET_USER_LOCKING(grf
);
518 if (!(rv
= __pgsreader(__parsegrent
, resultbuf
,
519 buffer
, buflen
, grf
))) {
524 __UCLIBC_MUTEX_UNLOCK(mylock
);
528 libc_hidden_def(getgrent_r
)
531 /**********************************************************************/
533 __UCLIBC_MUTEX_STATIC(mylock
, PTHREAD_MUTEX_INITIALIZER
);
535 static FILE *spf
/*= NULL*/;
539 __UCLIBC_MUTEX_LOCK(mylock
);
543 __UCLIBC_MUTEX_UNLOCK(mylock
);
548 __UCLIBC_MUTEX_LOCK(mylock
);
553 __UCLIBC_MUTEX_UNLOCK(mylock
);
556 int getspent_r(struct spwd
*resultbuf
, char *buffer
,
557 size_t buflen
, struct spwd
**result
)
561 __UCLIBC_MUTEX_LOCK(mylock
);
563 *result
= NULL
; /* In case of error... */
566 if (!(spf
= fopen(_PATH_SHADOW
, "r"))) {
570 __STDIO_SET_USER_LOCKING(spf
);
573 if (!(rv
= __pgsreader(__parsespent
, resultbuf
,
574 buffer
, buflen
, spf
))) {
579 __UCLIBC_MUTEX_UNLOCK(mylock
);
583 libc_hidden_def(getspent_r
)
586 /**********************************************************************/
590 struct passwd
*getpwent(void)
592 static char line_buff
[__UCLIBC_PWD_BUFFER_SIZE__
];
593 static struct passwd pwd
;
594 struct passwd
*result
;
596 getpwent_r(&pwd
, line_buff
, sizeof(line_buff
), &result
);
601 /**********************************************************************/
605 struct group
*getgrent(void)
607 static char line_buff
[__UCLIBC_GRP_BUFFER_SIZE__
];
608 static struct group gr
;
609 struct group
*result
;
611 getgrent_r(&gr
, line_buff
, sizeof(line_buff
), &result
);
616 /**********************************************************************/
620 struct spwd
*getspent(void)
622 static char line_buff
[__UCLIBC_PWD_BUFFER_SIZE__
];
623 static struct spwd spwd
;
626 getspent_r(&spwd
, line_buff
, sizeof(line_buff
), &result
);
631 /**********************************************************************/
635 struct spwd
*sgetspent(const char *string
)
637 static char line_buff
[__UCLIBC_PWD_BUFFER_SIZE__
];
638 static struct spwd spwd
;
641 sgetspent_r(string
, &spwd
, line_buff
, sizeof(line_buff
), &result
);
646 /**********************************************************************/
647 #ifdef L___getgrouplist_internal
649 gid_t attribute_hidden
*__getgrouplist_internal(const char *user
, gid_t gid
, int *ngroups
)
655 char buff
[__UCLIBC_PWD_BUFFER_SIZE__
];
657 *ngroups
= num_groups
= 1;
659 /* We alloc space for 8 gids at a time. */
660 group_list
= malloc(8 * sizeof(group_list
[0]));
665 grfile
= fopen(_PATH_GROUP
, "r");
666 /* If /etc/group doesn't exist, we still return 1-element vector */
670 __STDIO_SET_USER_LOCKING(grfile
);
672 while (!__pgsreader(__parsegrent
, &group
, buff
, sizeof(buff
), grfile
)) {
675 assert(group
.gr_mem
); /* Must have at least a NULL terminator. */
676 if (group
.gr_gid
== gid
)
678 for (m
= group
.gr_mem
; *m
; m
++) {
679 if (strcmp(*m
, user
) != 0)
681 if (!(num_groups
& 7)) {
682 gid_t
*tmp
= realloc(group_list
, (num_groups
+8) * sizeof(group_list
[0]));
687 group_list
[num_groups
++] = group
.gr_gid
;
694 *ngroups
= num_groups
;
699 /**********************************************************************/
700 #ifdef L_getgrouplist
702 #if defined __USE_BSD || defined __USE_GNU
703 int getgrouplist(const char *user
, gid_t gid
, gid_t
*groups
, int *ngroups
)
706 gid_t
*group_list
= __getgrouplist_internal(user
, gid
, ngroups
);
709 /* malloc failure - what shall we do?
710 * fail with ENOMEM? I bet users never check for that */
711 /* *ngroups = 1; - already done by __getgrouplist_internal */
718 /* *ngroups is non-zero here */
723 memcpy(groups
, group_list
, sz
* sizeof(group_list
[0]));
732 /**********************************************************************/
737 int initgroups(const char *user
, gid_t gid
)
740 int num_groups
= ((unsigned)~0) >> 1; /* INT_MAX */
741 gid_t
*group_list
= __getgrouplist_internal(user
, gid
, &num_groups
);
744 rv
= setgroups(num_groups
, group_list
);
751 /**********************************************************************/
755 int putpwent(const struct passwd
*__restrict p
, FILE *__restrict f
)
762 /* No extra thread locking is needed above what fprintf does. */
763 if (fprintf(f
, "%s:%s:%lu:%lu:%s:%s:%s\n",
764 p
->pw_name
, p
->pw_passwd
,
765 (unsigned long)(p
->pw_uid
),
766 (unsigned long)(p
->pw_gid
),
767 p
->pw_gecos
, p
->pw_dir
, p
->pw_shell
) >= 0
778 /**********************************************************************/
781 int putgrent(const struct group
*__restrict p
, FILE *__restrict f
)
783 static const char format
[] = ",%s";
787 __STDIO_AUTO_THREADLOCK_VAR
;
789 if (!p
|| !f
) { /* Sigh... glibc checks. */
792 __STDIO_AUTO_THREADLOCK(f
);
794 if (fprintf(f
, "%s:%s:%lu:",
795 p
->gr_name
, p
->gr_passwd
,
796 (unsigned long)(p
->gr_gid
)) >= 0
806 if (__fputc_unlocked('\n', f
) >= 0) {
811 if (fprintf(f
, fmt
, *m
) < 0) {
820 __STDIO_AUTO_THREADUNLOCK(f
);
827 /**********************************************************************/
830 static const unsigned char _sp_off
[] = {
831 offsetof(struct spwd
, sp_lstchg
), /* 2 - not a char ptr */
832 offsetof(struct spwd
, sp_min
), /* 3 - not a char ptr */
833 offsetof(struct spwd
, sp_max
), /* 4 - not a char ptr */
834 offsetof(struct spwd
, sp_warn
), /* 5 - not a char ptr */
835 offsetof(struct spwd
, sp_inact
), /* 6 - not a char ptr */
836 offsetof(struct spwd
, sp_expire
), /* 7 - not a char ptr */
839 int putspent(const struct spwd
*p
, FILE *stream
)
841 static const char ld_format
[] = "%ld:";
846 __STDIO_AUTO_THREADLOCK_VAR
;
848 /* Unlike putpwent and putgrent, glibc does not check the args. */
850 __STDIO_AUTO_THREADLOCK(stream
);
852 if (fprintf(stream
, "%s:%s:", p
->sp_namp
,
853 (p
->sp_pwdp
? p
->sp_pwdp
: "")) < 0
858 for (i
=0 ; i
< sizeof(_sp_off
) ; i
++) {
860 if ((x
= *(const long int *)(((const char *) p
) + _sp_off
[i
])) == -1) {
863 if (fprintf(stream
, f
, x
) < 0) {
868 if ((p
->sp_flag
!= ~0UL) && (fprintf(stream
, "%lu", p
->sp_flag
) < 0)) {
872 if (__fputc_unlocked('\n', stream
) > 0) {
877 __STDIO_AUTO_THREADUNLOCK(stream
);
883 /**********************************************************************/
884 /* Internal uClibc functions. */
885 /**********************************************************************/
886 #ifdef L___parsepwent
888 static const unsigned char pw_off
[] = {
889 offsetof(struct passwd
, pw_name
), /* 0 */
890 offsetof(struct passwd
, pw_passwd
), /* 1 */
891 offsetof(struct passwd
, pw_uid
), /* 2 - not a char ptr */
892 offsetof(struct passwd
, pw_gid
), /* 3 - not a char ptr */
893 offsetof(struct passwd
, pw_gecos
), /* 4 */
894 offsetof(struct passwd
, pw_dir
), /* 5 */
895 offsetof(struct passwd
, pw_shell
) /* 6 */
898 int attribute_hidden
__parsepwent(void *data
, char *line
)
906 p
= ((char *) ((struct passwd
*) data
)) + pw_off
[i
];
908 if ((i
& 6) ^ 2) { /* i!=2 and i!=3 */
909 *((char **) p
) = line
;
913 /* NOTE: glibc difference - glibc allows omission of
914 * ':' seperators after the gid field if all remaining
915 * entries are empty. We require all separators. */
916 if (!(line
= strchr(line
, ':'))) {
920 unsigned long t
= strtoul(line
, &endptr
, 10);
921 /* Make sure we had at least one digit, and that the
922 * failing char is the next field seperator ':'. See
923 * glibc difference note above. */
924 /* TODO: Also check for leading whitespace? */
925 if ((endptr
== line
) || (*endptr
!= ':')) {
929 if (i
& 1) { /* i == 3 -- gid */
931 } else { /* i == 2 -- uid */
944 /**********************************************************************/
945 #ifdef L___parsegrent
947 static const unsigned char gr_off
[] = {
948 offsetof(struct group
, gr_name
), /* 0 */
949 offsetof(struct group
, gr_passwd
), /* 1 */
950 offsetof(struct group
, gr_gid
) /* 2 - not a char ptr */
953 int attribute_hidden
__parsegrent(void *data
, char *line
)
961 end_of_buf
= ((struct group
*) data
)->gr_name
; /* Evil hack! */
964 p
= ((char *) ((struct group
*) data
)) + gr_off
[i
];
967 *((char **) p
) = line
;
968 if (!(line
= strchr(line
, ':'))) {
974 *((gid_t
*) p
) = strtoul(line
, &endptr
, 10);
976 /* NOTE: glibc difference - glibc allows omission of the
977 * trailing colon when there is no member list. We treat
978 * this as an error. */
980 /* Make sure we had at least one digit, and that the
981 * failing char is the next field seperator ':'. See
982 * glibc difference note above. */
983 if ((endptr
== line
) || (*endptr
!= ':')) {
987 i
= 1; /* Count terminating NULL ptr. */
990 if (p
[1]) { /* We have a member list to process. */
991 /* Overwrite the last ':' with a ',' before counting.
992 * This allows us to test for initial ',' and adds
993 * one ',' so that the ',' count equals the member
997 /* NOTE: glibc difference - glibc allows and trims leading
998 * (but not trailing) space. We treat this as an error. */
999 /* NOTE: glibc difference - glibc allows consecutive and
1000 * trailing commas, and ignores "empty string" users. We
1001 * treat this as an error. */
1004 *p
= 0; /* nul-terminate each member string. */
1005 if (!*++p
|| (*p
== ',') || isspace(*p
)) {
1012 /* Now align (p+1), rounding up. */
1013 /* Assumes sizeof(char **) is a power of 2. */
1014 members
= (char **)( (((intptr_t) p
) + sizeof(char **))
1015 & ~((intptr_t)(sizeof(char **) - 1)) );
1017 if (((char *)(members
+ i
)) > end_of_buf
) { /* No space. */
1021 ((struct group
*) data
)->gr_mem
= members
;
1024 p
= endptr
; /* Pointing to char prior to first member. */
1042 /**********************************************************************/
1043 #ifdef L___parsespent
1045 static const unsigned char sp_off
[] = {
1046 offsetof(struct spwd
, sp_namp
), /* 0 */
1047 offsetof(struct spwd
, sp_pwdp
), /* 1 */
1048 offsetof(struct spwd
, sp_lstchg
), /* 2 - not a char ptr */
1049 offsetof(struct spwd
, sp_min
), /* 3 - not a char ptr */
1050 offsetof(struct spwd
, sp_max
), /* 4 - not a char ptr */
1051 offsetof(struct spwd
, sp_warn
), /* 5 - not a char ptr */
1052 offsetof(struct spwd
, sp_inact
), /* 6 - not a char ptr */
1053 offsetof(struct spwd
, sp_expire
), /* 7 - not a char ptr */
1054 offsetof(struct spwd
, sp_flag
) /* 8 - not a char ptr */
1057 int attribute_hidden
__parsespent(void *data
, char * line
)
1065 p
= ((char *) ((struct spwd
*) data
)) + sp_off
[i
];
1067 *((char **) p
) = line
;
1068 if (!(line
= strchr(line
, ':'))) {
1073 if (i
==5) { /* Support for old format. */
1074 while (isspace(*line
)) ++line
; /* glibc eats space here. */
1076 ((struct spwd
*) data
)->sp_warn
= -1;
1077 ((struct spwd
*) data
)->sp_inact
= -1;
1078 ((struct spwd
*) data
)->sp_expire
= -1;
1079 ((struct spwd
*) data
)->sp_flag
= ~0UL;
1085 *((long *) p
) = (long) strtoul(line
, &endptr
, 10);
1087 if (endptr
== line
) {
1088 *((long *) p
) = ((i
!= 8) ? -1L : ((long)(~0UL)));
1100 if (*endptr
!= ':') {
1114 /**********************************************************************/
1115 #ifdef L___pgsreader
1117 /* Reads until if EOF, or until if finds a line which fits in the buffer
1118 * and for which the parser function succeeds.
1120 * Returns 0 on success and ENOENT for end-of-file (glibc concession).
1123 int attribute_hidden
__pgsreader(int (*__parserfunc
)(void *d
, char *line
), void *data
,
1124 char *__restrict line_buff
, size_t buflen
, FILE *f
)
1129 __STDIO_AUTO_THREADLOCK_VAR
;
1131 if (buflen
< __UCLIBC_PWD_BUFFER_SIZE__
) {
1134 __STDIO_AUTO_THREADLOCK(f
);
1138 if (!fgets_unlocked(line_buff
, buflen
, f
)) {
1139 if (feof_unlocked(f
)) {
1145 line_len
= strlen(line_buff
) - 1; /* strlen() must be > 0. */
1146 if (line_buff
[line_len
] == '\n') {
1147 line_buff
[line_len
] = 0;
1148 } else if (line_len
+ 2 == buflen
) { /* line too long */
1158 /* NOTE: glibc difference - glibc strips leading whitespace from
1159 * records. We do not allow leading whitespace. */
1161 /* Skip empty lines, comment lines, and lines with leading
1163 if (*line_buff
&& (*line_buff
!= '#') && !isspace(*line_buff
)) {
1164 if (__parserfunc
== __parsegrent
) { /* Do evil group hack. */
1165 /* The group entry parsing function needs to know where
1166 * the end of the buffer is so that it can construct the
1167 * group member ptr table. */
1168 ((struct group
*) data
)->gr_name
= line_buff
+ buflen
;
1171 if (!__parserfunc(data
, line_buff
)) {
1178 __STDIO_AUTO_THREADUNLOCK(f
);
1185 /**********************************************************************/