summaryrefslogtreecommitdiff
path: root/libpwdgrp
diff options
context:
space:
mode:
authorDenis Vlasenko2006-12-30 21:11:57 +0000
committerDenis Vlasenko2006-12-30 21:11:57 +0000
commitcb04ff5c68c1363837d8cd9f2170bdf64625b872 (patch)
treeadde9e8d46920ae48f3768e6b7fa76bdd123f618 /libpwdgrp
parent80602a98bcc3100279e09e1291d47a0adb6addb1 (diff)
downloadbusybox-cb04ff5c68c1363837d8cd9f2170bdf64625b872.zip
busybox-cb04ff5c68c1363837d8cd9f2170bdf64625b872.tar.gz
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 fcf6eaf..7aed265 100644
--- a/libpwdgrp/pwd_grp.c
+++ b/libpwdgrp/pwd_grp.c
@@ -43,13 +43,13 @@
/**********************************************************************/
/* Prototypes for internal functions. */
-static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data,
+static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
char *__restrict line_buff, size_t buflen, FILE *f);
-static int __parsepwent(void *pw, char *line);
-static int __parsegrent(void *gr, char *line);
+static int bb__parsepwent(void *pw, char *line);
+static int bb__parsegrent(void *gr, char *line);
#if ENABLE_USE_BB_SHADOW
-static int __parsespent(void *sp, char *line);
+static int bb__parsespent(void *sp, char *line);
#endif
/**********************************************************************/
@@ -58,7 +58,7 @@ static int __parsespent(void *sp, char *line);
* 0: success
* ENOENT: end-of-file encountered
* ERANGE: buflen too small
- * other error values possible. See __pgsreader.
+ * other error values possible. See bb__pgsreader.
*
* Also, *result == resultbuf on success and NULL on failure.
*
@@ -76,7 +76,7 @@ int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
*result = NULL;
- rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream);
+ rv = bb__pgsreader(bb__parsepwent, resultbuf, buffer, buflen, stream);
if (!rv) {
*result = resultbuf;
}
@@ -92,7 +92,7 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
*result = NULL;
- rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream);
+ rv = bb__pgsreader(bb__parsegrent, resultbuf, buffer, buflen, stream);
if (!rv) {
*result = resultbuf;
}
@@ -109,7 +109,7 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
*result = NULL;
- rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream);
+ rv = bb__pgsreader(bb__parsespent, resultbuf, buffer, buflen, stream);
if (!rv) {
*result = resultbuf;
}
@@ -175,7 +175,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
strcpy(buffer, string);
}
- rv = __parsespent(result_buf, buffer);
+ rv = bb__parsespent(result_buf, buffer);
if (!rv) {
*result = result_buf;
}
@@ -187,50 +187,46 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
/**********************************************************************/
-#ifdef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is already defined!
-#endif
-
-#define GETXXKEY_R_FUNC getpwnam_R
-#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_FUNC getpwnam_r
+#define GETXXKEY_R_PARSER bb__parsepwent
#define GETXXKEY_R_ENTTYPE struct passwd
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
+#define GETXXKEY_R_KEYTYPE const char *__restrict
+#define GETXXKEY_R_PATHNAME _PATH_PASSWD
#include "pwd_grp_internal.c"
-#define GETXXKEY_R_FUNC getgrnam_R
-#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_FUNC getgrnam_r
+#define GETXXKEY_R_PARSER bb__parsegrent
#define GETXXKEY_R_ENTTYPE struct group
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
+#define GETXXKEY_R_KEYTYPE const char *__restrict
+#define GETXXKEY_R_PATHNAME _PATH_GROUP
#include "pwd_grp_internal.c"
#if ENABLE_USE_BB_SHADOW
-#define GETXXKEY_R_FUNC getspnam_R
-#define GETXXKEY_R_PARSER __parsespent
+#define GETXXKEY_R_FUNC getspnam_r
+#define GETXXKEY_R_PARSER bb__parsespent
#define GETXXKEY_R_ENTTYPE struct spwd
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
+#define GETXXKEY_R_KEYTYPE const char *__restrict
+#define GETXXKEY_R_PATHNAME _PATH_SHADOW
#include "pwd_grp_internal.c"
#endif
-#define GETXXKEY_R_FUNC getpwuid_R
-#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_FUNC getpwuid_r
+#define GETXXKEY_R_PARSER bb__parsepwent
#define GETXXKEY_R_ENTTYPE struct passwd
#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
-#define DO_GETXXKEY_R_KEYTYPE uid_t
-#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
+#define GETXXKEY_R_KEYTYPE uid_t
+#define GETXXKEY_R_PATHNAME _PATH_PASSWD
#include "pwd_grp_internal.c"
-#define GETXXKEY_R_FUNC getgrgid_R
-#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_FUNC getgrgid_r
+#define GETXXKEY_R_PARSER bb__parsegrent
#define GETXXKEY_R_ENTTYPE struct group
#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
-#define DO_GETXXKEY_R_KEYTYPE gid_t
-#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
+#define GETXXKEY_R_KEYTYPE gid_t
+#define GETXXKEY_R_PATHNAME _PATH_GROUP
#include "pwd_grp_internal.c"
/**********************************************************************/
@@ -347,6 +343,8 @@ int getpw(uid_t uid, char *buf)
/**********************************************************************/
+/* FIXME: we don't have such CONFIG_xx - ?! */
+
#if defined CONFIG_USE_BB_THREADSAFE_SHADOW && defined PTHREAD_MUTEX_INITIALIZER
static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
# define LOCK pthread_mutex_lock(&mylock)
@@ -394,7 +392,7 @@ int getpwent_r(struct passwd *__restrict resultbuf,
}
}
- rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, pwf);
+ rv = bb__pgsreader(bb__parsepwent, resultbuf, buffer, buflen, pwf);
if (!rv) {
*result = resultbuf;
}
@@ -441,7 +439,7 @@ int getgrent_r(struct group *__restrict resultbuf,
}
}
- rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, grf);
+ rv = bb__pgsreader(bb__parsegrent, resultbuf, buffer, buflen, grf);
if (!rv) {
*result = resultbuf;
}
@@ -488,7 +486,7 @@ int getspent_r(struct spwd *resultbuf, char *buffer,
}
}
- rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, spf);
+ rv = bb__pgsreader(bb__parsespent, resultbuf, buffer, buflen, spf);
if (!rv) {
*result = resultbuf;
}
@@ -560,7 +558,7 @@ int initgroups(const char *user, gid_t gid)
*group_list = gid;
num_groups = 1;
- while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grfile)) {
+ while (!bb__pgsreader(bb__parsegrent, &group, buff, sizeof(buff), grfile)) {
assert(group.gr_mem); /* Must have at least a NULL terminator. */
if (group.gr_gid != gid) {
for (m=group.gr_mem ; *m ; m++) {
@@ -705,7 +703,7 @@ DO_UNLOCK:
#endif
/**********************************************************************/
-/* Internal uClibc functions. */
+/* Internal uClibc functions. */
/**********************************************************************/
static const unsigned char pw_off[] = {
@@ -718,7 +716,7 @@ static const unsigned char pw_off[] = {
offsetof(struct passwd, pw_shell) /* 6 */
};
-static int __parsepwent(void *data, char *line)
+static int bb__parsepwent(void *data, char *line)
{
char *endptr;
char *p;
@@ -772,7 +770,7 @@ static const unsigned char gr_off[] = {
offsetof(struct group, gr_gid) /* 2 - not a char ptr */
};
-static int __parsegrent(void *data, char *line)
+static int bb__parsegrent(void *data, char *line)
{
char *endptr;
char *p;
@@ -862,6 +860,7 @@ static int __parsegrent(void *data, char *line)
}
/**********************************************************************/
+
#if ENABLE_USE_BB_SHADOW
static const unsigned char sp_off[] = {
offsetof(struct spwd, sp_namp), /* 0 */
@@ -875,7 +874,7 @@ static const unsigned char sp_off[] = {
offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
};
-static int __parsespent(void *data, char * line)
+static int bb__parsespent(void *data, char * line)
{
char *endptr;
char *p;
@@ -928,7 +927,7 @@ static int __parsespent(void *data, char * line)
* Returns 0 on success and ENOENT for end-of-file (glibc concession).
*/
-static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data,
+static int bb__pgsreader(int (*parserfunc)(void *d, char *line), void *data,
char *__restrict line_buff, size_t buflen, FILE *f)
{
int line_len;
@@ -966,7 +965,7 @@ static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data,
/* Skip empty lines, comment lines, and lines with leading
* whitespace. */
if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) {
- if (parserfunc == __parsegrent) { /* Do evil group hack. */
+ if (parserfunc == bb__parsegrent) { /* Do evil group hack. */
/* The group entry parsing function needs to know where
* the end of the buffer is so that it can construct the
* group member ptr table. */
diff --git a/libpwdgrp/pwd_grp_internal.c b/libpwdgrp/pwd_grp_internal.c
index 866ed36..d55edc3 100644
--- a/libpwdgrp/pwd_grp_internal.c
+++ b/libpwdgrp/pwd_grp_internal.c
@@ -22,7 +22,7 @@
#error GETXXKEY_R_FUNC is not defined!
#endif
-int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
+int GETXXKEY_R_FUNC(GETXXKEY_R_KEYTYPE key,
GETXXKEY_R_ENTTYPE *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
GETXXKEY_R_ENTTYPE **__restrict result)
@@ -32,11 +32,11 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
*result = NULL;
- stream = fopen(DO_GETXXKEY_R_PATHNAME, "r");
+ stream = fopen(GETXXKEY_R_PATHNAME, "r");
if (!stream)
return errno;
while (1) {
- rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
+ rv = bb__pgsreader(GETXXKEY_R_PARSER, resultbuf, buffer, buflen, stream);
if (!rv) {
if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
*result = resultbuf;
@@ -58,5 +58,5 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
#undef GETXXKEY_R_PARSER
#undef GETXXKEY_R_ENTTYPE
#undef GETXXKEY_R_TEST
-#undef DO_GETXXKEY_R_KEYTYPE
-#undef DO_GETXXKEY_R_PATHNAME
+#undef GETXXKEY_R_KEYTYPE
+#undef GETXXKEY_R_PATHNAME
diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c
index 32cbd21..69c228e 100644
--- a/libpwdgrp/uidgid_get.c
+++ b/libpwdgrp/uidgid_get.c
@@ -1,3 +1,30 @@
+/*
+Copyright (c) 2001-2006, Gerrit Pape
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
#include "busybox.h"
int get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)