diff options
Diffstat (limited to 'libpwdgrp/pwd_grp_internal.c')
-rw-r--r-- | libpwdgrp/pwd_grp_internal.c | 87 |
1 files changed, 18 insertions, 69 deletions
diff --git a/libpwdgrp/pwd_grp_internal.c b/libpwdgrp/pwd_grp_internal.c index 39c11f677..866ed3699 100644 --- a/libpwdgrp/pwd_grp_internal.c +++ b/libpwdgrp/pwd_grp_internal.c | |||
@@ -18,96 +18,45 @@ | |||
18 | * | 18 | * |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <features.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <stdint.h> | ||
25 | #include <string.h> | ||
26 | #include <stddef.h> | ||
27 | #include <errno.h> | ||
28 | #include <assert.h> | ||
29 | #include <ctype.h> | ||
30 | |||
31 | #include "pwd_.h" | ||
32 | #include "grp_.h" | ||
33 | #include "shadow_.h" | ||
34 | #include "libbb.h" | ||
35 | |||
36 | #ifndef _PATH_SHADOW | ||
37 | #define _PATH_SHADOW "/etc/shadow" | ||
38 | #endif | ||
39 | #ifndef _PATH_PASSWD | ||
40 | #define _PATH_PASSWD "/etc/passwd" | ||
41 | #endif | ||
42 | #ifndef _PATH_GROUP | ||
43 | #define _PATH_GROUP "/etc/group" | ||
44 | #endif | ||
45 | |||
46 | /**********************************************************************/ | ||
47 | /* Sizes for statically allocated buffers. */ | ||
48 | |||
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 | ||
53 | |||
54 | /**********************************************************************/ | ||
55 | /* Prototypes for internal functions. */ | ||
56 | |||
57 | extern int __parsepwent(void *pw, char *line); | ||
58 | extern int __parsegrent(void *gr, char *line); | ||
59 | extern int __parsespent(void *sp, char *line); | ||
60 | |||
61 | extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | ||
62 | char *__restrict line_buff, size_t buflen, FILE *f); | ||
63 | |||
64 | |||
65 | #ifndef GETXXKEY_R_FUNC | 21 | #ifndef GETXXKEY_R_FUNC |
66 | #error GETXXKEY_R_FUNC is not defined! | 22 | #error GETXXKEY_R_FUNC is not defined! |
67 | #endif | 23 | #endif |
68 | /**********************************************************************/ | ||
69 | #ifdef GETXXKEY_R_FUNC | ||
70 | 24 | ||
71 | int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key, | 25 | int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key, |
72 | GETXXKEY_R_ENTTYPE *__restrict resultbuf, | 26 | GETXXKEY_R_ENTTYPE *__restrict resultbuf, |
73 | char *__restrict buffer, size_t buflen, | 27 | char *__restrict buffer, size_t buflen, |
74 | GETXXKEY_R_ENTTYPE **__restrict result) | 28 | GETXXKEY_R_ENTTYPE **__restrict result) |
75 | { | 29 | { |
76 | FILE *stream; | 30 | FILE *stream; |
77 | int rv; | 31 | int rv; |
78 | 32 | ||
79 | *result = NULL; | 33 | *result = NULL; |
80 | 34 | ||
81 | if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) { | 35 | stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"); |
82 | rv = errno; | 36 | if (!stream) |
83 | } else { | 37 | return errno; |
84 | do { | 38 | while (1) { |
85 | if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, | 39 | rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream); |
86 | buffer, buflen, stream)) | 40 | if (!rv) { |
87 | ) { | 41 | if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ |
88 | if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ | 42 | *result = resultbuf; |
89 | *result = resultbuf; | ||
90 | break; | ||
91 | } | ||
92 | } else { | ||
93 | if (rv == ENOENT) { /* end-of-file encountered. */ | ||
94 | rv = 0; | ||
95 | } | ||
96 | break; | 43 | break; |
97 | } | 44 | } |
98 | } while (1); | 45 | } else { |
99 | fclose(stream); | 46 | if (rv == ENOENT) { /* end-of-file encountered. */ |
47 | rv = 0; | ||
48 | } | ||
49 | break; | ||
50 | } | ||
100 | } | 51 | } |
52 | fclose(stream); | ||
101 | 53 | ||
102 | return rv; | 54 | return rv; |
103 | } | 55 | } |
104 | 56 | ||
105 | #endif | ||
106 | /**********************************************************************/ | ||
107 | #undef GETXXKEY_R_FUNC | 57 | #undef GETXXKEY_R_FUNC |
108 | #undef GETXXKEY_R_PARSER | 58 | #undef GETXXKEY_R_PARSER |
109 | #undef GETXXKEY_R_ENTTYPE | 59 | #undef GETXXKEY_R_ENTTYPE |
110 | #undef GETXXKEY_R_TEST | 60 | #undef GETXXKEY_R_TEST |
111 | #undef DO_GETXXKEY_R_KEYTYPE | 61 | #undef DO_GETXXKEY_R_KEYTYPE |
112 | #undef DO_GETXXKEY_R_PATHNAME | 62 | #undef DO_GETXXKEY_R_PATHNAME |
113 | |||