1 /* vi: set sw=4 ts=4: */
2 /* Copyright (C) 2003 Manuel Novoa III
4 * Licensed under GPL v2, or later. See file LICENSE in this tarball.
7 /* Nov 6, 2003 Initial version.
9 * NOTE: This implementation is quite strict about requiring all
10 * field seperators. It also does not allow leading whitespace
11 * except when processing the numeric fields. glibc is more
12 * lenient. See the various glibc difference comments below.
15 * Move to dynamic allocation of (currently statically allocated)
16 * buffers; especially for the group-related functions since
17 * large group member lists will cause error returns.
37 #define _PATH_SHADOW "/etc/shadow"
40 #define _PATH_PASSWD "/etc/passwd"
43 #define _PATH_GROUP "/etc/group"
46 /**********************************************************************/
47 /* Sizes for statically allocated buffers. */
49 /* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
50 * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
51 #define PWD_BUFFER_SIZE 256
52 #define GRP_BUFFER_SIZE 256
54 /**********************************************************************/
55 /* Prototypes for internal functions. */
57 extern int __parsepwent(void *pw, char *line);
58 extern int __parsegrent(void *gr, char *line);
59 extern int __parsespent(void *sp, char *line);
61 extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
62 char *__restrict line_buff, size_t buflen, FILE *f);
65 #ifndef GETXXKEY_R_FUNC
66 #error GETXXKEY_R_FUNC is not defined!
68 /**********************************************************************/
69 #ifdef GETXXKEY_R_FUNC
71 int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
72 GETXXKEY_R_ENTTYPE *__restrict resultbuf,
73 char *__restrict buffer, size_t buflen,
74 GETXXKEY_R_ENTTYPE **__restrict result)
81 if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) {
85 if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf,
86 buffer, buflen, stream))
88 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
93 if (rv == ENOENT) { /* end-of-file encountered. */
106 /**********************************************************************/
107 #undef GETXXKEY_R_FUNC
108 #undef GETXXKEY_R_PARSER
109 #undef GETXXKEY_R_ENTTYPE
110 #undef GETXXKEY_R_TEST
111 #undef DO_GETXXKEY_R_KEYTYPE
112 #undef DO_GETXXKEY_R_PATHNAME