diff options
Diffstat (limited to 'libpwdgrp/pwd_grp.c')
-rw-r--r-- | libpwdgrp/pwd_grp.c | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index fcf6eaffe..7aed265b9 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -43,13 +43,13 @@ | |||
43 | /**********************************************************************/ | 43 | /**********************************************************************/ |
44 | /* Prototypes for internal functions. */ | 44 | /* Prototypes for internal functions. */ |
45 | 45 | ||
46 | static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, | 46 | static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data, |
47 | char *__restrict line_buff, size_t buflen, FILE *f); | 47 | char *__restrict line_buff, size_t buflen, FILE *f); |
48 | 48 | ||
49 | static int __parsepwent(void *pw, char *line); | 49 | static int bb__parsepwent(void *pw, char *line); |
50 | static int __parsegrent(void *gr, char *line); | 50 | static int bb__parsegrent(void *gr, char *line); |
51 | #if ENABLE_USE_BB_SHADOW | 51 | #if ENABLE_USE_BB_SHADOW |
52 | static int __parsespent(void *sp, char *line); | 52 | static int bb__parsespent(void *sp, char *line); |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | /**********************************************************************/ | 55 | /**********************************************************************/ |
@@ -58,7 +58,7 @@ static int __parsespent(void *sp, char *line); | |||
58 | * 0: success | 58 | * 0: success |
59 | * ENOENT: end-of-file encountered | 59 | * ENOENT: end-of-file encountered |
60 | * ERANGE: buflen too small | 60 | * ERANGE: buflen too small |
61 | * other error values possible. See __pgsreader. | 61 | * other error values possible. See bb__pgsreader. |
62 | * | 62 | * |
63 | * Also, *result == resultbuf on success and NULL on failure. | 63 | * Also, *result == resultbuf on success and NULL on failure. |
64 | * | 64 | * |
@@ -76,7 +76,7 @@ int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf, | |||
76 | 76 | ||
77 | *result = NULL; | 77 | *result = NULL; |
78 | 78 | ||
79 | rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream); | 79 | rv = bb__pgsreader(bb__parsepwent, resultbuf, buffer, buflen, stream); |
80 | if (!rv) { | 80 | if (!rv) { |
81 | *result = resultbuf; | 81 | *result = resultbuf; |
82 | } | 82 | } |
@@ -92,7 +92,7 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf, | |||
92 | 92 | ||
93 | *result = NULL; | 93 | *result = NULL; |
94 | 94 | ||
95 | rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream); | 95 | rv = bb__pgsreader(bb__parsegrent, resultbuf, buffer, buflen, stream); |
96 | if (!rv) { | 96 | if (!rv) { |
97 | *result = resultbuf; | 97 | *result = resultbuf; |
98 | } | 98 | } |
@@ -109,7 +109,7 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, | |||
109 | 109 | ||
110 | *result = NULL; | 110 | *result = NULL; |
111 | 111 | ||
112 | rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream); | 112 | rv = bb__pgsreader(bb__parsespent, resultbuf, buffer, buflen, stream); |
113 | if (!rv) { | 113 | if (!rv) { |
114 | *result = resultbuf; | 114 | *result = resultbuf; |
115 | } | 115 | } |
@@ -175,7 +175,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf, | |||
175 | strcpy(buffer, string); | 175 | strcpy(buffer, string); |
176 | } | 176 | } |
177 | 177 | ||
178 | rv = __parsespent(result_buf, buffer); | 178 | rv = bb__parsespent(result_buf, buffer); |
179 | if (!rv) { | 179 | if (!rv) { |
180 | *result = result_buf; | 180 | *result = result_buf; |
181 | } | 181 | } |
@@ -187,50 +187,46 @@ int sgetspent_r(const char *string, struct spwd *result_buf, | |||
187 | 187 | ||
188 | /**********************************************************************/ | 188 | /**********************************************************************/ |
189 | 189 | ||
190 | #ifdef GETXXKEY_R_FUNC | 190 | #define GETXXKEY_R_FUNC getpwnam_r |
191 | #error GETXXKEY_R_FUNC is already defined! | 191 | #define GETXXKEY_R_PARSER bb__parsepwent |
192 | #endif | ||
193 | |||
194 | #define GETXXKEY_R_FUNC getpwnam_R | ||
195 | #define GETXXKEY_R_PARSER __parsepwent | ||
196 | #define GETXXKEY_R_ENTTYPE struct passwd | 192 | #define GETXXKEY_R_ENTTYPE struct passwd |
197 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) | 193 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) |
198 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | 194 | #define GETXXKEY_R_KEYTYPE const char *__restrict |
199 | #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD | 195 | #define GETXXKEY_R_PATHNAME _PATH_PASSWD |
200 | #include "pwd_grp_internal.c" | 196 | #include "pwd_grp_internal.c" |
201 | 197 | ||
202 | #define GETXXKEY_R_FUNC getgrnam_R | 198 | #define GETXXKEY_R_FUNC getgrnam_r |
203 | #define GETXXKEY_R_PARSER __parsegrent | 199 | #define GETXXKEY_R_PARSER bb__parsegrent |
204 | #define GETXXKEY_R_ENTTYPE struct group | 200 | #define GETXXKEY_R_ENTTYPE struct group |
205 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) | 201 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) |
206 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | 202 | #define GETXXKEY_R_KEYTYPE const char *__restrict |
207 | #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP | 203 | #define GETXXKEY_R_PATHNAME _PATH_GROUP |
208 | #include "pwd_grp_internal.c" | 204 | #include "pwd_grp_internal.c" |
209 | 205 | ||
210 | #if ENABLE_USE_BB_SHADOW | 206 | #if ENABLE_USE_BB_SHADOW |
211 | #define GETXXKEY_R_FUNC getspnam_R | 207 | #define GETXXKEY_R_FUNC getspnam_r |
212 | #define GETXXKEY_R_PARSER __parsespent | 208 | #define GETXXKEY_R_PARSER bb__parsespent |
213 | #define GETXXKEY_R_ENTTYPE struct spwd | 209 | #define GETXXKEY_R_ENTTYPE struct spwd |
214 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) | 210 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) |
215 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | 211 | #define GETXXKEY_R_KEYTYPE const char *__restrict |
216 | #define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW | 212 | #define GETXXKEY_R_PATHNAME _PATH_SHADOW |
217 | #include "pwd_grp_internal.c" | 213 | #include "pwd_grp_internal.c" |
218 | #endif | 214 | #endif |
219 | 215 | ||
220 | #define GETXXKEY_R_FUNC getpwuid_R | 216 | #define GETXXKEY_R_FUNC getpwuid_r |
221 | #define GETXXKEY_R_PARSER __parsepwent | 217 | #define GETXXKEY_R_PARSER bb__parsepwent |
222 | #define GETXXKEY_R_ENTTYPE struct passwd | 218 | #define GETXXKEY_R_ENTTYPE struct passwd |
223 | #define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) | 219 | #define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) |
224 | #define DO_GETXXKEY_R_KEYTYPE uid_t | 220 | #define GETXXKEY_R_KEYTYPE uid_t |
225 | #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD | 221 | #define GETXXKEY_R_PATHNAME _PATH_PASSWD |
226 | #include "pwd_grp_internal.c" | 222 | #include "pwd_grp_internal.c" |
227 | 223 | ||
228 | #define GETXXKEY_R_FUNC getgrgid_R | 224 | #define GETXXKEY_R_FUNC getgrgid_r |
229 | #define GETXXKEY_R_PARSER __parsegrent | 225 | #define GETXXKEY_R_PARSER bb__parsegrent |
230 | #define GETXXKEY_R_ENTTYPE struct group | 226 | #define GETXXKEY_R_ENTTYPE struct group |
231 | #define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) | 227 | #define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) |
232 | #define DO_GETXXKEY_R_KEYTYPE gid_t | 228 | #define GETXXKEY_R_KEYTYPE gid_t |
233 | #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP | 229 | #define GETXXKEY_R_PATHNAME _PATH_GROUP |
234 | #include "pwd_grp_internal.c" | 230 | #include "pwd_grp_internal.c" |
235 | 231 | ||
236 | /**********************************************************************/ | 232 | /**********************************************************************/ |
@@ -347,6 +343,8 @@ int getpw(uid_t uid, char *buf) | |||
347 | 343 | ||
348 | /**********************************************************************/ | 344 | /**********************************************************************/ |
349 | 345 | ||
346 | /* FIXME: we don't have such CONFIG_xx - ?! */ | ||
347 | |||
350 | #if defined CONFIG_USE_BB_THREADSAFE_SHADOW && defined PTHREAD_MUTEX_INITIALIZER | 348 | #if defined CONFIG_USE_BB_THREADSAFE_SHADOW && defined PTHREAD_MUTEX_INITIALIZER |
351 | static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; | 349 | static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; |
352 | # define LOCK pthread_mutex_lock(&mylock) | 350 | # define LOCK pthread_mutex_lock(&mylock) |
@@ -394,7 +392,7 @@ int getpwent_r(struct passwd *__restrict resultbuf, | |||
394 | } | 392 | } |
395 | } | 393 | } |
396 | 394 | ||
397 | rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, pwf); | 395 | rv = bb__pgsreader(bb__parsepwent, resultbuf, buffer, buflen, pwf); |
398 | if (!rv) { | 396 | if (!rv) { |
399 | *result = resultbuf; | 397 | *result = resultbuf; |
400 | } | 398 | } |
@@ -441,7 +439,7 @@ int getgrent_r(struct group *__restrict resultbuf, | |||
441 | } | 439 | } |
442 | } | 440 | } |
443 | 441 | ||
444 | rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, grf); | 442 | rv = bb__pgsreader(bb__parsegrent, resultbuf, buffer, buflen, grf); |
445 | if (!rv) { | 443 | if (!rv) { |
446 | *result = resultbuf; | 444 | *result = resultbuf; |
447 | } | 445 | } |
@@ -488,7 +486,7 @@ int getspent_r(struct spwd *resultbuf, char *buffer, | |||
488 | } | 486 | } |
489 | } | 487 | } |
490 | 488 | ||
491 | rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, spf); | 489 | rv = bb__pgsreader(bb__parsespent, resultbuf, buffer, buflen, spf); |
492 | if (!rv) { | 490 | if (!rv) { |
493 | *result = resultbuf; | 491 | *result = resultbuf; |
494 | } | 492 | } |
@@ -560,7 +558,7 @@ int initgroups(const char *user, gid_t gid) | |||
560 | *group_list = gid; | 558 | *group_list = gid; |
561 | num_groups = 1; | 559 | num_groups = 1; |
562 | 560 | ||
563 | while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grfile)) { | 561 | while (!bb__pgsreader(bb__parsegrent, &group, buff, sizeof(buff), grfile)) { |
564 | assert(group.gr_mem); /* Must have at least a NULL terminator. */ | 562 | assert(group.gr_mem); /* Must have at least a NULL terminator. */ |
565 | if (group.gr_gid != gid) { | 563 | if (group.gr_gid != gid) { |
566 | for (m=group.gr_mem ; *m ; m++) { | 564 | for (m=group.gr_mem ; *m ; m++) { |
@@ -705,7 +703,7 @@ DO_UNLOCK: | |||
705 | #endif | 703 | #endif |
706 | 704 | ||
707 | /**********************************************************************/ | 705 | /**********************************************************************/ |
708 | /* Internal uClibc functions. */ | 706 | /* Internal uClibc functions. */ |
709 | /**********************************************************************/ | 707 | /**********************************************************************/ |
710 | 708 | ||
711 | static const unsigned char pw_off[] = { | 709 | static const unsigned char pw_off[] = { |
@@ -718,7 +716,7 @@ static const unsigned char pw_off[] = { | |||
718 | offsetof(struct passwd, pw_shell) /* 6 */ | 716 | offsetof(struct passwd, pw_shell) /* 6 */ |
719 | }; | 717 | }; |
720 | 718 | ||
721 | static int __parsepwent(void *data, char *line) | 719 | static int bb__parsepwent(void *data, char *line) |
722 | { | 720 | { |
723 | char *endptr; | 721 | char *endptr; |
724 | char *p; | 722 | char *p; |
@@ -772,7 +770,7 @@ static const unsigned char gr_off[] = { | |||
772 | offsetof(struct group, gr_gid) /* 2 - not a char ptr */ | 770 | offsetof(struct group, gr_gid) /* 2 - not a char ptr */ |
773 | }; | 771 | }; |
774 | 772 | ||
775 | static int __parsegrent(void *data, char *line) | 773 | static int bb__parsegrent(void *data, char *line) |
776 | { | 774 | { |
777 | char *endptr; | 775 | char *endptr; |
778 | char *p; | 776 | char *p; |
@@ -862,6 +860,7 @@ static int __parsegrent(void *data, char *line) | |||
862 | } | 860 | } |
863 | 861 | ||
864 | /**********************************************************************/ | 862 | /**********************************************************************/ |
863 | |||
865 | #if ENABLE_USE_BB_SHADOW | 864 | #if ENABLE_USE_BB_SHADOW |
866 | static const unsigned char sp_off[] = { | 865 | static const unsigned char sp_off[] = { |
867 | offsetof(struct spwd, sp_namp), /* 0 */ | 866 | offsetof(struct spwd, sp_namp), /* 0 */ |
@@ -875,7 +874,7 @@ static const unsigned char sp_off[] = { | |||
875 | offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */ | 874 | offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */ |
876 | }; | 875 | }; |
877 | 876 | ||
878 | static int __parsespent(void *data, char * line) | 877 | static int bb__parsespent(void *data, char * line) |
879 | { | 878 | { |
880 | char *endptr; | 879 | char *endptr; |
881 | char *p; | 880 | char *p; |
@@ -928,7 +927,7 @@ static int __parsespent(void *data, char * line) | |||
928 | * Returns 0 on success and ENOENT for end-of-file (glibc concession). | 927 | * Returns 0 on success and ENOENT for end-of-file (glibc concession). |
929 | */ | 928 | */ |
930 | 929 | ||
931 | static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, | 930 | static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data, |
932 | char *__restrict line_buff, size_t buflen, FILE *f) | 931 | char *__restrict line_buff, size_t buflen, FILE *f) |
933 | { | 932 | { |
934 | int line_len; | 933 | int line_len; |
@@ -966,7 +965,7 @@ static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, | |||
966 | /* Skip empty lines, comment lines, and lines with leading | 965 | /* Skip empty lines, comment lines, and lines with leading |
967 | * whitespace. */ | 966 | * whitespace. */ |
968 | if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) { | 967 | if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) { |
969 | if (parserfunc == __parsegrent) { /* Do evil group hack. */ | 968 | if (parserfunc == bb__parsegrent) { /* Do evil group hack. */ |
970 | /* The group entry parsing function needs to know where | 969 | /* The group entry parsing function needs to know where |
971 | * the end of the buffer is so that it can construct the | 970 | * the end of the buffer is so that it can construct the |
972 | * group member ptr table. */ | 971 | * group member ptr table. */ |