summaryrefslogtreecommitdiff
path: root/libc/pwd_grp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/pwd_grp')
-rw-r--r--libc/pwd_grp/Makefile.in27
-rw-r--r--libc/pwd_grp/__getgrouplist_internal.c8
-rw-r--r--libc/pwd_grp/fgetgrent.c12
-rw-r--r--libc/pwd_grp/fgetpwent.c12
-rw-r--r--libc/pwd_grp/fgetspent.c6
-rw-r--r--libc/pwd_grp/getgrent.c5
-rw-r--r--libc/pwd_grp/getgrgid.c6
-rw-r--r--libc/pwd_grp/getgrgid_r.c7
-rw-r--r--libc/pwd_grp/getgrnam.c6
-rw-r--r--libc/pwd_grp/getgrnam_r.c7
-rw-r--r--libc/pwd_grp/getgrouplist.c8
-rw-r--r--libc/pwd_grp/getpwent.c5
-rw-r--r--libc/pwd_grp/getpwnam.c7
-rw-r--r--libc/pwd_grp/getpwnam_r.c7
-rw-r--r--libc/pwd_grp/getpwuid.c6
-rw-r--r--libc/pwd_grp/getpwuid_r.c7
-rw-r--r--libc/pwd_grp/getspent.c5
-rw-r--r--libc/pwd_grp/getspnam.c6
-rw-r--r--libc/pwd_grp/getspnam_r.c7
-rw-r--r--libc/pwd_grp/lckpwdf.c99
-rw-r--r--libc/pwd_grp/pwd_grp.c422
-rw-r--r--libc/pwd_grp/pwd_grp_internal.c56
-rw-r--r--libc/pwd_grp/sgetspent.c6
23 files changed, 286 insertions, 451 deletions
diff --git a/libc/pwd_grp/Makefile.in b/libc/pwd_grp/Makefile.in
index f9c7149e7..4a2e77385 100644
--- a/libc/pwd_grp/Makefile.in
+++ b/libc/pwd_grp/Makefile.in
@@ -1,31 +1,30 @@
# Makefile for uClibc
#
-# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+# Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
#
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
+subdirs += libc/pwd_grp
+
PWDGRP_DIR := $(top_srcdir)libc/pwd_grp
PWDGRP_OUT := $(top_builddir)libc/pwd_grp
-CSRC := $(notdir $(wildcard $(PWDGRP_DIR)/*.c))
-CSRC := $(filter-out pwd_grp.c pwd_grp_internal.c,$(CSRC))
-
-ifneq ($(UCLIBC_HAS_SHADOW),y)
-SHADOW_CSRC := \
- fgetspent_r.c fgetspent.c getspent_r.c getspent.c \
+CSRC-y := $(notdir $(wildcard $(PWDGRP_DIR)/*.c))
+CSRC- := pwd_grp.c pwd_grp_internal.c # multi-source and helper
+CSRC-$(UCLIBC_HAS_SHADOW) += fgetspent_r.c fgetspent.c getspent_r.c getspent.c \
getspnam_r.c getspnam.c lckpwdf.c putspent.c \
sgetspent_r.c sgetspent.c __parsespent.c
# getspuid_r.c getspuid.c
-CSRC := $(filter-out $(SHADOW_CSRC),$(CSRC))
-endif
-PWDGRP_SRC := $(patsubst %.c,$(PWDGRP_DIR)/%.c,$(CSRC))
-PWDGRP_OBJ := $(patsubst %.c,$(PWDGRP_OUT)/%.o,$(CSRC))
+CSRC-y := $(filter-out $(CSRC-),$(CSRC-y))
+
+PWDGRP_SRC := $(patsubst %.c,$(PWDGRP_DIR)/%.c,$(CSRC-y))
+PWDGRP_OBJ := $(patsubst %.c,$(PWDGRP_OUT)/%.o,$(CSRC-y))
libc-y += $(PWDGRP_OBJ)
-objclean-y += pwdgrp_objclean
+objclean-y += CLEAN_libc/pwd_grp
-pwdgrp_objclean:
- $(RM) $(PWDGRP_OUT)/*.{o,os}
+CLEAN_libc/pwd_grp:
+ $(do_rm) $(addprefix $(PWDGRP_OUT)/*., o os)
diff --git a/libc/pwd_grp/__getgrouplist_internal.c b/libc/pwd_grp/__getgrouplist_internal.c
new file mode 100644
index 000000000..c2edc99cf
--- /dev/null
+++ b/libc/pwd_grp/__getgrouplist_internal.c
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define L___getgrouplist_internal
+#include "pwd_grp.c"
diff --git a/libc/pwd_grp/fgetgrent.c b/libc/pwd_grp/fgetgrent.c
index 695aee119..6a45799bc 100644
--- a/libc/pwd_grp/fgetgrent.c
+++ b/libc/pwd_grp/fgetgrent.c
@@ -4,5 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetgrent
+#include <features.h>
+
+#ifdef __USE_SVID
+
+#define GETXXKEY_FUNC fgetgrent
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
+
+#endif
diff --git a/libc/pwd_grp/fgetpwent.c b/libc/pwd_grp/fgetpwent.c
index ddcc7ffb7..6f65cf672 100644
--- a/libc/pwd_grp/fgetpwent.c
+++ b/libc/pwd_grp/fgetpwent.c
@@ -4,5 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetpwent
+#include <features.h>
+
+#ifdef __USE_SVID
+
+#define GETXXKEY_FUNC fgetpwent
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
+
+#endif
diff --git a/libc/pwd_grp/fgetspent.c b/libc/pwd_grp/fgetspent.c
index b7c1ef24f..77ca0b895 100644
--- a/libc/pwd_grp/fgetspent.c
+++ b/libc/pwd_grp/fgetspent.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetspent
+#define GETXXKEY_FUNC fgetspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrent.c b/libc/pwd_grp/getgrent.c
index 808e4e817..5b03b31a0 100644
--- a/libc/pwd_grp/getgrent.c
+++ b/libc/pwd_grp/getgrent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrent
+#define GETXXKEY_FUNC getgrent
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c
index 96ce9039d..298845270 100644
--- a/libc/pwd_grp/getgrgid.c
+++ b/libc/pwd_grp/getgrgid.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrgid
+#define GETXXKEY_FUNC getgrgid
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS gid_t git
+#define GETXXKEY_ADD_VARIABLES git
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrgid_r.c b/libc/pwd_grp/getgrgid_r.c
index a962f4cec..b0f0c9aa6 100644
--- a/libc/pwd_grp/getgrgid_r.c
+++ b/libc/pwd_grp/getgrgid_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrgid_r
+#define GETXXKEY_R_FUNC getgrgid_r
+#define GETXXKEY_R_PARSER __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
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c
index 3b47d9a9f..f6ce45953 100644
--- a/libc/pwd_grp/getgrnam.c
+++ b/libc/pwd_grp/getgrnam.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrnam
+#define GETXXKEY_FUNC getgrnam
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrnam_r.c b/libc/pwd_grp/getgrnam_r.c
index 592a66c47..35121e70e 100644
--- a/libc/pwd_grp/getgrnam_r.c
+++ b/libc/pwd_grp/getgrnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrnam_r
+#define GETXXKEY_R_FUNC getgrnam_r
+#define GETXXKEY_R_PARSER __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
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrouplist.c b/libc/pwd_grp/getgrouplist.c
new file mode 100644
index 000000000..a4eba7dbb
--- /dev/null
+++ b/libc/pwd_grp/getgrouplist.c
@@ -0,0 +1,8 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#define L_getgrouplist
+#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwent.c b/libc/pwd_grp/getpwent.c
index a617bc8b2..7ddc8ee8a 100644
--- a/libc/pwd_grp/getpwent.c
+++ b/libc/pwd_grp/getpwent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwent
+#define GETXXKEY_FUNC getpwent
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c
index d00640b54..e3e8c027d 100644
--- a/libc/pwd_grp/getpwnam.c
+++ b/libc/pwd_grp/getpwnam.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwnam
+#define GETXXKEY_FUNC getpwnam
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
+#define GETXXKEY_FUNC_HIDDEN
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwnam_r.c b/libc/pwd_grp/getpwnam_r.c
index a4440e756..bc5e3d5cf 100644
--- a/libc/pwd_grp/getpwnam_r.c
+++ b/libc/pwd_grp/getpwnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwnam_r
+#define GETXXKEY_R_FUNC getpwnam_r
+#define GETXXKEY_R_PARSER __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
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c
index 16ac50f72..1ad26888b 100644
--- a/libc/pwd_grp/getpwuid.c
+++ b/libc/pwd_grp/getpwuid.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwuid
+#define GETXXKEY_FUNC getpwuid
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS uid_t uid
+#define GETXXKEY_ADD_VARIABLES uid
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwuid_r.c b/libc/pwd_grp/getpwuid_r.c
index 21d39ed7f..0a5aa962a 100644
--- a/libc/pwd_grp/getpwuid_r.c
+++ b/libc/pwd_grp/getpwuid_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwuid_r
+#define GETXXKEY_R_FUNC getpwuid_r
+#define GETXXKEY_R_PARSER __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
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspent.c b/libc/pwd_grp/getspent.c
index 5699b67d6..4feb9f988 100644
--- a/libc/pwd_grp/getspent.c
+++ b/libc/pwd_grp/getspent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspent
+#define GETXXKEY_FUNC getspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspnam.c b/libc/pwd_grp/getspnam.c
index 19e40c737..a0a01ec63 100644
--- a/libc/pwd_grp/getspnam.c
+++ b/libc/pwd_grp/getspnam.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspnam
+#define GETXXKEY_FUNC getspnam
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspnam_r.c b/libc/pwd_grp/getspnam_r.c
index 053b697ea..ea23848fe 100644
--- a/libc/pwd_grp/getspnam_r.c
+++ b/libc/pwd_grp/getspnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspnam_r
+#define GETXXKEY_R_FUNC getspnam_r
+#define GETXXKEY_R_PARSER __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
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/lckpwdf.c b/libc/pwd_grp/lckpwdf.c
index 0b0fb471b..9b2aebcce 100644
--- a/libc/pwd_grp/lckpwdf.c
+++ b/libc/pwd_grp/lckpwdf.c
@@ -15,9 +15,8 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <features.h>
#include <fcntl.h>
@@ -28,22 +27,9 @@
#include <paths.h>
#include <shadow.h>
-/* Experimentally off - libc_hidden_proto(memset) */
-libc_hidden_proto(open)
-libc_hidden_proto(fcntl)
-libc_hidden_proto(close)
-libc_hidden_proto(sigfillset)
-libc_hidden_proto(sigaction)
-libc_hidden_proto(sigprocmask)
-libc_hidden_proto(sigaddset)
-libc_hidden_proto(sigemptyset)
-libc_hidden_proto(alarm)
-
-/* How long to wait for getting the lock before returning with an
- error. */
+/* How long to wait for getting the lock before returning with an error. */
#define TIMEOUT 15 /* sec */
-
/* File descriptor for lock file. */
static int lock_fd = -1;
@@ -51,7 +37,6 @@ static int lock_fd = -1;
#include <bits/uClibc_mutex.h>
__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
-
/* Prototypes for local functions. */
static void noop_handler (int __sig);
@@ -59,7 +44,6 @@ static void noop_handler (int __sig);
int
lckpwdf (void)
{
- int flags;
sigset_t saved_set; /* Saved set of caught signals. */
struct sigaction saved_act; /* Saved signal action. */
sigset_t new_set; /* New set of caught signals. */
@@ -75,90 +59,65 @@ lckpwdf (void)
/* Prevent problems caused by multiple threads. */
__UCLIBC_MUTEX_LOCK(mylock);
- lock_fd = open (_PATH_PASSWD, O_WRONLY);
+ lock_fd = open (_PATH_PASSWD, O_WRONLY | O_CLOEXEC);
if (lock_fd == -1) {
- /* Cannot create lock file. */
- goto DONE;
+ goto DONE;
}
-
+#ifndef __ASSUME_O_CLOEXEC
/* Make sure file gets correctly closed when process finished. */
- flags = fcntl (lock_fd, F_GETFD, 0);
- if (flags == -1) {
- /* Cannot get file flags. */
- close(lock_fd);
- lock_fd = -1;
- goto DONE;
- }
- flags |= FD_CLOEXEC; /* Close on exit. */
- if (fcntl (lock_fd, F_SETFD, flags) < 0) {
- /* Cannot set new flags. */
- close(lock_fd);
- lock_fd = -1;
- goto DONE;
- }
+ fcntl (lock_fd, F_SETFD, FD_CLOEXEC);
+#endif
/* Now we have to get exclusive write access. Since multiple
process could try this we won't stop when it first fails.
Instead we set a timeout for the system call. Once the timer
expires it is likely that there are some problems which cannot be
- resolved by waiting.
+ resolved by waiting. (sa_flags have no SA_RESTART. Thus SIGALRM
+ will EINTR fcntl(F_SETLKW)
It is important that we don't change the signal state. We must
restore the old signal behaviour. */
- memset (&new_act, '\0', sizeof (struct sigaction));
+ memset (&new_act, '\0', sizeof (new_act));
new_act.sa_handler = noop_handler;
- sigfillset (&new_act.sa_mask);
- new_act.sa_flags = 0ul;
+ __sigfillset (&new_act.sa_mask);
- /* Install new action handler for alarm and save old. */
- if (sigaction (SIGALRM, &new_act, &saved_act) < 0) {
- /* Cannot install signal handler. */
- close(lock_fd);
- lock_fd = -1;
- goto DONE;
- }
+ /* Install new action handler for alarm and save old.
+ * This never fails in Linux. */
+ sigaction (SIGALRM, &new_act, &saved_act);
/* Now make sure the alarm signal is not blocked. */
- sigemptyset (&new_set);
- sigaddset (&new_set, SIGALRM);
- if (sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0) {
- sigaction (SIGALRM, &saved_act, NULL);
- close(lock_fd);
- lock_fd = -1;
- goto DONE;
- }
+ __sigemptyset (&new_set);
+ __sigaddset (&new_set, SIGALRM);
+ sigprocmask (SIG_UNBLOCK, &new_set, &saved_set);
/* Start timer. If we cannot get the lock in the specified time we
get a signal. */
alarm (TIMEOUT);
/* Try to get the lock. */
- memset (&fl, '\0', sizeof (struct flock));
- fl.l_type = F_WRLCK;
- fl.l_whence = SEEK_SET;
+ memset (&fl, '\0', sizeof (fl));
+ if (F_WRLCK)
+ fl.l_type = F_WRLCK;
+ if (SEEK_SET)
+ fl.l_whence = SEEK_SET;
result = fcntl (lock_fd, F_SETLKW, &fl);
/* Clear alarm. */
alarm (0);
- /* Restore old set of handled signals. We don't need to know
- about the current one.*/
sigprocmask (SIG_SETMASK, &saved_set, NULL);
-
- /* Restore old action handler for alarm. We don't need to know
- about the current one. */
sigaction (SIGALRM, &saved_act, NULL);
if (result < 0) {
close(lock_fd);
lock_fd = -1;
- goto DONE;
+ goto DONE;
}
rv = 0;
DONE:
__UCLIBC_MUTEX_UNLOCK(mylock);
- return 0;
+ return rv;
}
@@ -173,7 +132,7 @@ ulckpwdf (void)
else
{
/* Prevent problems caused by multiple threads. */
- __UCLIBC_MUTEX_LOCK(mylock);
+ __UCLIBC_MUTEX_LOCK(mylock);
result = close (lock_fd);
@@ -181,7 +140,7 @@ ulckpwdf (void)
lock_fd = -1;
/* Clear mutex. */
- __UCLIBC_MUTEX_UNLOCK(mylock);
+ __UCLIBC_MUTEX_UNLOCK(mylock);
}
return result;
@@ -189,7 +148,7 @@ ulckpwdf (void)
static void
-noop_handler (int sig)
-{
+noop_handler (int sig attribute_unused) {
+
/* We simply return which makes the `fcntl' call return with an error. */
}
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
index 217ed39a7..acdb08d39 100644
--- a/libc/pwd_grp/pwd_grp.c
+++ b/libc/pwd_grp/pwd_grp.c
@@ -32,28 +32,10 @@
#include <grp.h>
#include <paths.h>
#ifdef __UCLIBC_HAS_SHADOW__
-#include <shadow.h>
+# include <shadow.h>
#endif
#include <bits/uClibc_mutex.h>
-/* Experimentally off - libc_hidden_proto(strchr) */
-/* Experimentally off - libc_hidden_proto(strcmp) */
-/* Experimentally off - libc_hidden_proto(strcpy) */
-/* Experimentally off - libc_hidden_proto(strlen) */
-libc_hidden_proto(strtoul)
-libc_hidden_proto(rewind)
-libc_hidden_proto(fgets_unlocked)
-libc_hidden_proto(__fputc_unlocked)
-libc_hidden_proto(sprintf)
-libc_hidden_proto(fopen)
-libc_hidden_proto(fclose)
-libc_hidden_proto(fprintf)
-#ifdef __UCLIBC_HAS_XLOCALE__
-libc_hidden_proto(__ctype_b_loc)
-#elif defined __UCLIBC_HAS_CTYPE_TABLES__
-libc_hidden_proto(__ctype_b)
-#endif
-
/**********************************************************************/
/* Prototypes for internal functions. */
@@ -64,6 +46,8 @@ extern int __parsespent(void *sp, char *line) attribute_hidden;
extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
char *__restrict line_buff, size_t buflen, FILE *f) attribute_hidden;
+extern gid_t* __getgrouplist_internal(const char *user, gid_t gid, int *ngroups) attribute_hidden;
+
/**********************************************************************/
/* For the various fget??ent_r funcs, return
*
@@ -82,7 +66,6 @@ extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
#ifdef L_fgetpwent_r
#ifdef __USE_SVID
-libc_hidden_proto(fgetpwent_r)
int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
struct passwd **__restrict result)
@@ -105,7 +88,6 @@ libc_hidden_def(fgetpwent_r)
#ifdef L_fgetgrent_r
#ifdef __USE_SVID
-libc_hidden_proto(fgetgrent_r)
int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
struct group **__restrict result)
@@ -127,7 +109,6 @@ libc_hidden_def(fgetgrent_r)
/**********************************************************************/
#ifdef L_fgetspent_r
-libc_hidden_proto(fgetspent_r)
int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
struct spwd **__restrict result)
@@ -146,65 +127,8 @@ libc_hidden_def(fgetspent_r)
#endif
/**********************************************************************/
-/* For the various fget??ent funcs, return NULL on failure and a
- * pointer to the appropriate struct (statically allocated) on success.
- */
-/**********************************************************************/
-#ifdef L_fgetpwent
-
-#ifdef __USE_SVID
-libc_hidden_proto(fgetpwent_r)
-
-struct passwd *fgetpwent(FILE *stream)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_fgetgrent
-
-#ifdef __USE_SVID
-libc_hidden_proto(fgetgrent_r)
-
-struct group *fgetgrent(FILE *stream)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_fgetspent
-
-libc_hidden_proto(fgetspent_r)
-
-struct spwd *fgetspent(FILE *stream)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- fgetspent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_sgetspent_r
-libc_hidden_proto(sgetspent_r)
int sgetspent_r(const char *string, struct spwd *result_buf,
char *buffer, size_t buflen, struct spwd **result)
{
@@ -236,102 +160,12 @@ libc_hidden_def(sgetspent_r)
#endif
/**********************************************************************/
-
-#ifdef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is already defined!
-#endif
-
-#ifdef L_getpwnam_r
-#define GETXXKEY_R_FUNC getpwnam_r
-#define GETXXKEY_R_PARSER __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
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getgrnam_r
-#define GETXXKEY_R_FUNC getgrnam_r
-#define GETXXKEY_R_PARSER __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
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getspnam_r
-#define GETXXKEY_R_FUNC getspnam_r
-#define GETXXKEY_R_PARSER __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
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getpwuid_r
-#define GETXXKEY_R_FUNC getpwuid_r
-#define GETXXKEY_R_PARSER __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
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getgrgid_r
-#define GETXXKEY_R_FUNC getgrgid_r
-#define GETXXKEY_R_PARSER __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
-#include "pwd_grp_internal.c"
-#endif
-
-/**********************************************************************/
-#ifdef L_getpwuid
-
-libc_hidden_proto(getpwuid_r)
-
-struct passwd *getpwuid(uid_t uid)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrgid
-
-libc_hidden_proto(getgrgid_r)
-
-struct group *getgrgid(gid_t gid)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- getgrgid_r(gid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getspuid_r
/* This function is non-standard and is currently not built. It seems
* to have been created as a reentrant version of the non-standard
* functions getspuid. Why getspuid was added, I do not know. */
-libc_hidden_proto(getpwuid_r)
-libc_hidden_proto(getspnam_r)
int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
@@ -352,76 +186,8 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
#endif
/**********************************************************************/
-#ifdef L_getspuid
-
-/* This function is non-standard and is currently not built.
- * Why it was added, I do not know. */
-
-libc_hidden_proto(getspuid_r)
-
-struct spwd *getspuid(uid_t uid)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getpwnam
-
-libc_hidden_proto(getpwnam_r)
-
-struct passwd *getpwnam(const char *name)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrnam
-
-libc_hidden_proto(getgrnam_r)
-
-struct group *getgrnam(const char *name)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getspnam
-
-libc_hidden_proto(getspnam_r)
-
-struct spwd *getspnam(const char *name)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getpw
-libc_hidden_proto(getpwuid_r)
int getpw(uid_t uid, char *buf)
{
@@ -474,7 +240,6 @@ void endpwent(void)
}
-libc_hidden_proto(getpwent_r)
int getpwent_r(struct passwd *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
struct passwd **__restrict result)
@@ -531,7 +296,6 @@ void endgrent(void)
__UCLIBC_MUTEX_UNLOCK(mylock);
}
-libc_hidden_proto(getgrent_r)
int getgrent_r(struct group *__restrict resultbuf,
char *__restrict buffer, size_t buflen,
struct group **__restrict result)
@@ -588,7 +352,6 @@ void endspent(void)
__UCLIBC_MUTEX_UNLOCK(mylock);
}
-libc_hidden_proto(getspent_r)
int getspent_r(struct spwd *resultbuf, char *buffer,
size_t buflen, struct spwd **result)
{
@@ -620,67 +383,98 @@ libc_hidden_def(getspent_r)
#endif
/**********************************************************************/
-#ifdef L_getpwent
-
-libc_hidden_proto(getpwent_r)
-
-struct passwd *getpwent(void)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd pwd;
- struct passwd *result;
-
- getpwent_r(&pwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
-#endif
+/* For the various fget??ent funcs, return NULL on failure and a
+ * pointer to the appropriate struct (statically allocated) on success.
+ */
/**********************************************************************/
-#ifdef L_getgrent
+#if defined(GETXXKEY_FUNC) || defined(GETXXKEY_R_FUNC)
+#include "pwd_grp_internal.c"
+#endif
-libc_hidden_proto(getgrent_r)
+/**********************************************************************/
+#ifdef L___getgrouplist_internal
-struct group *getgrent(void)
+gid_t attribute_hidden *__getgrouplist_internal(const char *user, gid_t gid, int *ngroups)
{
- static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group gr;
- struct group *result;
-
- getgrent_r(&gr, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getspent
+ FILE *grfile;
+ gid_t *group_list;
+ int num_groups;
+ struct group group;
+ char buff[__UCLIBC_PWD_BUFFER_SIZE__];
-libc_hidden_proto(getspent_r)
+ *ngroups = num_groups = 1;
-struct spwd *getspent(void)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd spwd;
- struct spwd *result;
+ /* We alloc space for 8 gids at a time. */
+ group_list = malloc(8 * sizeof(group_list[0]));
+ if (!group_list)
+ return NULL;
+
+ group_list[0] = gid;
+ grfile = fopen(_PATH_GROUP, "r");
+ /* If /etc/group doesn't exist, we still return 1-element vector */
+ if (!grfile)
+ return group_list;
+
+ __STDIO_SET_USER_LOCKING(grfile);
+
+ while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grfile)) {
+ char **m;
+
+ assert(group.gr_mem); /* Must have at least a NULL terminator. */
+ if (group.gr_gid == gid)
+ continue;
+ for (m = group.gr_mem; *m; m++) {
+ if (strcmp(*m, user) != 0)
+ continue;
+ if (!(num_groups & 7)) {
+ gid_t *tmp = realloc(group_list, (num_groups+8) * sizeof(group_list[0]));
+ if (!tmp)
+ goto DO_CLOSE;
+ group_list = tmp;
+ }
+ group_list[num_groups++] = group.gr_gid;
+ break;
+ }
+ }
- getspent_r(&spwd, line_buff, sizeof(line_buff), &result);
- return result;
+ DO_CLOSE:
+ fclose(grfile);
+ *ngroups = num_groups;
+ return group_list;
}
#endif
/**********************************************************************/
-#ifdef L_sgetspent
-
-libc_hidden_proto(sgetspent_r)
+#ifdef L_getgrouplist
-struct spwd *sgetspent(const char *string)
+#if defined __USE_BSD || defined __USE_GNU
+int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd spwd;
- struct spwd *result;
+ int sz = *ngroups;
+ gid_t *group_list = __getgrouplist_internal(user, gid, ngroups);
- sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
- return result;
+ if (!group_list) {
+ /* malloc failure - what shall we do?
+ * fail with ENOMEM? I bet users never check for that */
+ /* *ngroups = 1; - already done by __getgrouplist_internal */
+ if (sz) {
+ groups[0] = gid;
+ return 1;
+ }
+ return -1;
+ }
+ /* *ngroups is non-zero here */
+
+ if (sz > *ngroups)
+ sz = *ngroups;
+ if (sz)
+ memcpy(groups, group_list, sz * sizeof(group_list[0]));
+ free(group_list);
+ if (sz < *ngroups)
+ return -1;
+ return sz;
}
+#endif
#endif
/**********************************************************************/
@@ -688,58 +482,14 @@ struct spwd *sgetspent(const char *string)
#ifdef __USE_BSD
-libc_hidden_proto(setgroups)
-
int initgroups(const char *user, gid_t gid)
{
- FILE *grfile;
- gid_t *group_list;
- int num_groups, rv;
- char **m;
- struct group group;
- char buff[__UCLIBC_PWD_BUFFER_SIZE__];
-
- rv = -1;
-
- /* We alloc space for 8 gids at a time. */
- if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL)
- && ((grfile = fopen(_PATH_GROUP, "r")) != NULL)
- ) {
-
- __STDIO_SET_USER_LOCKING(grfile);
-
- *group_list = gid;
- num_groups = 1;
-
- 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++) {
- if (!strcmp(*m, user)) {
- if (!(num_groups & 7)) {
- gid_t *tmp = (gid_t *)
- realloc(group_list,
- (num_groups+8) * sizeof(gid_t *));
- if (!tmp) {
- rv = -1;
- goto DO_CLOSE;
- }
- group_list = tmp;
- }
- group_list[num_groups++] = group.gr_gid;
- break;
- }
- }
- }
- }
-
- rv = setgroups(num_groups, group_list);
- DO_CLOSE:
- fclose(grfile);
- }
-
- /* group_list will be NULL if initial malloc failed, which may trigger
- * warnings from various malloc debuggers. */
+ int rv;
+ int num_groups = ((unsigned)~0) >> 1; /* INT_MAX */
+ gid_t *group_list = __getgrouplist_internal(user, gid, &num_groups);
+ if (!group_list)
+ return -1;
+ rv = setgroups(num_groups, group_list);
free(group_list);
return rv;
}
diff --git a/libc/pwd_grp/pwd_grp_internal.c b/libc/pwd_grp/pwd_grp_internal.c
index c89747890..f82c298d5 100644
--- a/libc/pwd_grp/pwd_grp_internal.c
+++ b/libc/pwd_grp/pwd_grp_internal.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <stddef.h>
#include <errno.h>
+#include <malloc.h>
#include <assert.h>
#include <ctype.h>
#include <pwd.h>
@@ -34,23 +35,12 @@
#ifdef __UCLIBC_HAS_SHADOW__
#include <shadow.h>
#endif
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-#endif
-
-/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
/**********************************************************************/
/* Prototypes for internal functions. */
-#ifndef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is not defined!
+#if !defined(GETXXKEY_R_FUNC) && !defined(GETXXKEY_FUNC)
+#error GETXXKEY_R_FUNC/GETXXKEY_FUNC are not defined!
#endif
/**********************************************************************/
#ifdef GETXXKEY_R_FUNC
@@ -92,9 +82,47 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
}
libc_hidden_def(GETXXKEY_R_FUNC)
+#endif /* GETXXKEY_R_FUNC */
+
+/**********************************************************************/
+#ifdef GETXXKEY_FUNC
+
+#define REENTRANT_NAME APPEND_R(GETXXKEY_FUNC)
+#define APPEND_R(name) APPEND_R1(name)
+#define APPEND_R1(name) name##_r
+
+GETXXKEY_ENTTYPE *GETXXKEY_FUNC(GETXXKEY_ADD_PARAMS)
+{
+ static char *buffer = NULL;
+ static GETXXKEY_ENTTYPE resultbuf;
+ GETXXKEY_ENTTYPE *result;
+
+ if (buffer == NULL)
+ buffer = (char *)__uc_malloc(GETXXKEY_BUFLEN);
+
+# ifdef GETXXKEY_ADD_VARIABLES
+ REENTRANT_NAME(GETXXKEY_ADD_VARIABLES, &resultbuf, buffer, GETXXKEY_BUFLEN, &result);
+# else
+ REENTRANT_NAME(&resultbuf, buffer, GETXXKEY_BUFLEN, &result);
+# endif
+ return result;
+}
+#ifdef GETXXKEY_FUNC_HIDDEN
+libc_hidden_def(GETXXKEY_FUNC)
#endif
+
+#undef REENTRANT_NAME
+#undef APPEND_R
+#undef APPEND_R1
+#endif /* GETXXKEY_FUNC */
+
/**********************************************************************/
-#undef GETXXKEY_R_FUNC_HIDDEN
+#undef GETXXKEY_FUNC
+#undef GETXXKEY_ENTTYPE
+#undef GETXXKEY_BUFLEN
+#undef GETXXKEY_FUNC_HIDDEN
+#undef GETXXKEY_ADD_PARAMS
+#undef GETXXKEY_ADD_VARIABLES
#undef GETXXKEY_R_FUNC
#undef GETXXKEY_R_PARSER
#undef GETXXKEY_R_ENTTYPE
diff --git a/libc/pwd_grp/sgetspent.c b/libc/pwd_grp/sgetspent.c
index 877a2478a..990c0b6a4 100644
--- a/libc/pwd_grp/sgetspent.c
+++ b/libc/pwd_grp/sgetspent.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_sgetspent
+#define GETXXKEY_FUNC sgetspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS const char *string
+#define GETXXKEY_ADD_VARIABLES string
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"