summaryrefslogtreecommitdiffstats
path: root/libc/pwd_grp
diff options
context:
space:
mode:
author"Steven J. Hill" <sjhill@realitydiluted.com>2005-10-30 01:14:23 +0000
committer"Steven J. Hill" <sjhill@realitydiluted.com>2005-10-30 01:14:23 +0000
commit6e46869a9c0c9f5e31378247e5835cd0b3301c96 (patch)
treedad4ede474ab46f074fd8381965d160f6a2ac92c /libc/pwd_grp
parentca798b3b1e0937336dc382b6f3fe7453a219fd2f (diff)
downloaduClibc-alpine-6e46869a9c0c9f5e31378247e5835cd0b3301c96.tar.bz2
uClibc-alpine-6e46869a9c0c9f5e31378247e5835cd0b3301c96.tar.xz
Merge from trunk.
Diffstat (limited to 'libc/pwd_grp')
-rw-r--r--libc/pwd_grp/pwd_grp.c104
1 files changed, 22 insertions, 82 deletions
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
index e56b545d6..0225c6c7e 100644
--- a/libc/pwd_grp/pwd_grp.c
+++ b/libc/pwd_grp/pwd_grp.c
@@ -1,18 +1,7 @@
-/* Copyright (C) 2003 Manuel Novoa III
+/*
+ * Copyright (C) 2003 Manuel Novoa III
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details.
*/
/* Nov 6, 2003 Initial version.
@@ -229,6 +218,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
#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
+#include "pwd_grp_internal.c"
#endif
#ifdef L_getgrnam_r
@@ -238,6 +228,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
#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
+#include "pwd_grp_internal.c"
#endif
#ifdef L_getspnam_r
@@ -247,6 +238,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
#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
+#include "pwd_grp_internal.c"
#endif
#ifdef L_getpwuid_r
@@ -256,6 +248,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
#define DO_GETXXKEY_R_KEYTYPE uid_t
#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
+#include "pwd_grp_internal.c"
#endif
#ifdef L_getgrgid_r
@@ -265,48 +258,10 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
#define DO_GETXXKEY_R_KEYTYPE gid_t
#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
+#include "pwd_grp_internal.c"
#endif
/**********************************************************************/
-#ifdef GETXXKEY_R_FUNC
-
-int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
- GETXXKEY_R_ENTTYPE *__restrict resultbuf,
- char *__restrict buffer, size_t buflen,
- GETXXKEY_R_ENTTYPE **__restrict result)
-{
- FILE *stream;
- int rv;
-
- *result = NULL;
-
- if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) {
- rv = errno;
- } else {
- __STDIO_SET_USER_LOCKING(stream);
- do {
- if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf,
- buffer, buflen, stream))
- ) {
- if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
- *result = resultbuf;
- break;
- }
- } else {
- if (rv == ENOENT) { /* end-of-file encountered. */
- rv = 0;
- }
- break;
- }
- } while (1);
- fclose(stream);
- }
-
- return rv;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getpwuid
struct passwd *getpwuid(uid_t uid)
@@ -446,16 +401,19 @@ int getpw(uid_t uid, char *buf)
#endif
/**********************************************************************/
-#ifdef L_getpwent_r
+#if defined(L_getpwent_r) || defined(L_getgrent_r) || defined(L_getspent_r)
#ifdef __UCLIBC_HAS_THREADS__
static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
# define LOCK __pthread_mutex_lock(&mylock)
# define UNLOCK __pthread_mutex_unlock(&mylock);
-#else
+#else
# define LOCK ((void) 0)
# define UNLOCK ((void) 0)
-#endif
+#endif
+#endif
+
+#ifdef L_getpwent_r
static FILE *pwf /*= NULL*/;
@@ -512,15 +470,6 @@ int getpwent_r(struct passwd *__restrict resultbuf,
/**********************************************************************/
#ifdef L_getgrent_r
-#ifdef __UCLIBC_HAS_THREADS__
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK __pthread_mutex_lock(&mylock)
-# define UNLOCK __pthread_mutex_unlock(&mylock);
-#else
-# define LOCK ((void) 0)
-# define UNLOCK ((void) 0)
-#endif
-
static FILE *grf /*= NULL*/;
void setgrent(void)
@@ -575,15 +524,6 @@ int getgrent_r(struct group *__restrict resultbuf,
/**********************************************************************/
#ifdef L_getspent_r
-#ifdef __UCLIBC_HAS_THREADS__
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK __pthread_mutex_lock(&mylock)
-# define UNLOCK __pthread_mutex_unlock(&mylock);
-#else
-# define LOCK ((void) 0)
-# define UNLOCK ((void) 0)
-#endif
-
static FILE *spf /*= NULL*/;
void setspent(void)
@@ -695,7 +635,7 @@ struct spwd *sgetspent(const char *string)
int initgroups(const char *user, gid_t gid)
{
- FILE *grf;
+ FILE *grfile;
gid_t *group_list;
int num_groups, rv;
char **m;
@@ -706,15 +646,15 @@ int initgroups(const char *user, gid_t gid)
/* We alloc space for 8 gids at a time. */
if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL)
- && ((grf = fopen(_PATH_GROUP, "r")) != NULL)
+ && ((grfile = fopen(_PATH_GROUP, "r")) != NULL)
) {
- __STDIO_SET_USER_LOCKING(grf);
+ __STDIO_SET_USER_LOCKING(grfile);
*group_list = gid;
num_groups = 1;
- while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grf)) {
+ while (!__pgsreader(__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++) {
@@ -738,7 +678,7 @@ int initgroups(const char *user, gid_t gid)
rv = setgroups(num_groups, group_list);
DO_CLOSE:
- fclose(grf);
+ fclose(grfile);
}
/* group_list will be NULL if initial malloc failed, which may trigger
@@ -825,7 +765,7 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
/**********************************************************************/
#ifdef L_putspent
-static const unsigned char sp_off[] = {
+static const unsigned char _sp_off[] = {
offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
offsetof(struct spwd, sp_max), /* 4 - not a char ptr */
@@ -853,9 +793,9 @@ int putspent(const struct spwd *p, FILE *stream)
goto DO_UNLOCK;
}
- for (i=0 ; i < sizeof(sp_off) ; i++) {
+ for (i=0 ; i < sizeof(_sp_off) ; i++) {
f = ld_format;
- if ((x = *(const long int *)(((const char *) p) + sp_off[i])) == -1) {
+ if ((x = *(const long int *)(((const char *) p) + _sp_off[i])) == -1) {
f += 3;
}
if (fprintf(stream, f, x) < 0) {