aboutsummaryrefslogtreecommitdiff
path: root/libpwdgrp
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-30 21:11:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-30 21:11:57 +0000
commitcb04ff5c68c1363837d8cd9f2170bdf64625b872 (patch)
treeadde9e8d46920ae48f3768e6b7fa76bdd123f618 /libpwdgrp
parent80602a98bcc3100279e09e1291d47a0adb6addb1 (diff)
downloadbusybox-w32-cb04ff5c68c1363837d8cd9f2170bdf64625b872.tar.gz
busybox-w32-cb04ff5c68c1363837d8cd9f2170bdf64625b872.tar.bz2
busybox-w32-cb04ff5c68c1363837d8cd9f2170bdf64625b872.zip
fixdep.c: avoit doing memcmp in most cases
uidgid_get.c: add forgotten copyright notice pwd/grp/shadow: avoid collisions with libc names
Diffstat (limited to 'libpwdgrp')
-rw-r--r--libpwdgrp/pwd_grp.c85
-rw-r--r--libpwdgrp/pwd_grp_internal.c10
-rw-r--r--libpwdgrp/uidgid_get.c27
3 files changed, 74 insertions, 48 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
46static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, 46static 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
49static int __parsepwent(void *pw, char *line); 49static int bb__parsepwent(void *pw, char *line);
50static int __parsegrent(void *gr, char *line); 50static int bb__parsegrent(void *gr, char *line);
51#if ENABLE_USE_BB_SHADOW 51#if ENABLE_USE_BB_SHADOW
52static int __parsespent(void *sp, char *line); 52static 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
351static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; 349static 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
711static const unsigned char pw_off[] = { 709static 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
721static int __parsepwent(void *data, char *line) 719static 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
775static int __parsegrent(void *data, char *line) 773static 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
866static const unsigned char sp_off[] = { 865static 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
878static int __parsespent(void *data, char * line) 877static 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
931static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, 930static 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. */
diff --git a/libpwdgrp/pwd_grp_internal.c b/libpwdgrp/pwd_grp_internal.c
index 866ed3699..d55edc349 100644
--- a/libpwdgrp/pwd_grp_internal.c
+++ b/libpwdgrp/pwd_grp_internal.c
@@ -22,7 +22,7 @@
22#error GETXXKEY_R_FUNC is not defined! 22#error GETXXKEY_R_FUNC is not defined!
23#endif 23#endif
24 24
25int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key, 25int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
26 GETXXKEY_R_ENTTYPE *__restrict resultbuf, 26 GETXXKEY_R_ENTTYPE *__restrict resultbuf,
27 char *__restrict buffer, size_t buflen, 27 char *__restrict buffer, size_t buflen,
28 GETXXKEY_R_ENTTYPE **__restrict result) 28 GETXXKEY_R_ENTTYPE **__restrict result)
@@ -32,11 +32,11 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
32 32
33 *result = NULL; 33 *result = NULL;
34 34
35 stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"); 35 stream = fopen(GETXXKEY_R_PATHNAME, "r");
36 if (!stream) 36 if (!stream)
37 return errno; 37 return errno;
38 while (1) { 38 while (1) {
39 rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream); 39 rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
40 if (!rv) { 40 if (!rv) {
41 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */ 41 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
42 *result = resultbuf; 42 *result = resultbuf;
@@ -58,5 +58,5 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
58#undef GETXXKEY_R_PARSER 58#undef GETXXKEY_R_PARSER
59#undef GETXXKEY_R_ENTTYPE 59#undef GETXXKEY_R_ENTTYPE
60#undef GETXXKEY_R_TEST 60#undef GETXXKEY_R_TEST
61#undef DO_GETXXKEY_R_KEYTYPE 61#undef GETXXKEY_R_KEYTYPE
62#undef DO_GETXXKEY_R_PATHNAME 62#undef GETXXKEY_R_PATHNAME
diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c
index 32cbd21b9..69c228e16 100644
--- a/libpwdgrp/uidgid_get.c
+++ b/libpwdgrp/uidgid_get.c
@@ -1,3 +1,30 @@
1/*
2Copyright (c) 2001-2006, Gerrit Pape
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
1#include "busybox.h" 28#include "busybox.h"
2 29
3int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) 30int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)