summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/pwd_grp/Makefile30
-rw-r--r--libc/pwd_grp/__getgrent_r.c114
-rw-r--r--libc/pwd_grp/__getpwent_r.c115
-rw-r--r--libc/pwd_grp/__getspent_r.c59
-rw-r--r--libc/pwd_grp/__sgetspent_r.c167
-rw-r--r--libc/pwd_grp/config.h45
-rw-r--r--libc/pwd_grp/fgetgrent.c74
-rw-r--r--libc/pwd_grp/fgetpwent.c66
-rw-r--r--libc/pwd_grp/fgetspent.c65
-rw-r--r--libc/pwd_grp/getgrgid.c79
-rw-r--r--libc/pwd_grp/getgrnam.c86
-rw-r--r--libc/pwd_grp/getpw.c48
-rw-r--r--libc/pwd_grp/getpwnam.c85
-rw-r--r--libc/pwd_grp/getpwuid.c77
-rw-r--r--libc/pwd_grp/getspnam.c79
-rw-r--r--libc/pwd_grp/getspuid.c72
-rw-r--r--libc/pwd_grp/grent.c107
-rw-r--r--libc/pwd_grp/initgroups.c75
-rw-r--r--libc/pwd_grp/putgrent.c56
-rw-r--r--libc/pwd_grp/putpwent.c41
-rw-r--r--libc/pwd_grp/putspent.c79
-rw-r--r--libc/pwd_grp/pwd_grp.c1172
-rw-r--r--libc/pwd_grp/pwent.c109
-rw-r--r--libc/pwd_grp/sgetspent.c62
-rw-r--r--libc/pwd_grp/spent.c97
25 files changed, 1194 insertions, 1865 deletions
diff --git a/libc/pwd_grp/Makefile b/libc/pwd_grp/Makefile
index 288b84a9c..18acebf17 100644
--- a/libc/pwd_grp/Makefile
+++ b/libc/pwd_grp/Makefile
@@ -24,17 +24,27 @@
TOPDIR=../../
include $(TOPDIR)Rules.mak
-CSRC= pwent.c getpwnam.c getpwuid.c putpwent.c getpw.c fgetpwent.c \
- __getgrent_r.c grent.c getgrnam.c getgrgid.c fgetgrent.c \
- initgroups.c __getpwent_r.c putgrent.c
+MSRC=pwd_grp.c
+MOBJ= fgetpwent_r.o fgetgrent_r.o fgetpwent.o fgetgrent.o \
+ getpwnam_r.o getgrnam_r.o getpwuid_r.o getgrgid_r.o \
+ getpwuid.o getgrgid.o getpwnam.o getgrnam.o getpw.o \
+ getpwent_r.o getgrent_r.o getpwent.o getgrent.o \
+ initgroups.o putpwent.o putgrent.o \
+ __parsepwent.o __parsegrent.o __pgsreader.o
ifeq ($(HAS_SHADOW),y)
-CSRC+= lckpwdf.c spent.c getspnam.c getspuid.c putspent.c sgetspent.c \
- fgetspent.c __getspent_r.c __sgetspent_r.c
+MOBJ+= fgetspent_r.o fgetspent.o sgetspent_r.o getspnam_r.o \
+ getspnam.o getspent_r.o getspent.o sgetspent.o \
+ putspent.o __parsespent.o # getspuid_r.o getspuid.o
endif
-COBJS=$(patsubst %.c,%.o, $(CSRC))
-OBJS=$(COBJS)
+CSRC=
+ifeq ($(HAS_SHADOW),y)
+CSRC+= lckpwdf.c
+endif
+
+COBJ=$(patsubst %.c,%.o, $(CSRC))
+OBJS=$(MOBJ) $(COBJ)
all: $(OBJS) $(LIBC)
@@ -43,7 +53,11 @@ $(LIBC): ar-target
ar-target: $(OBJS)
$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
-$(COBJS): %.o : %.c
+$(MOBJ): $(MSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
+$(COBJ): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
$(STRIPTOOL) -x -R .note -R .comment $*.o
diff --git a/libc/pwd_grp/__getgrent_r.c b/libc/pwd_grp/__getgrent_r.c
deleted file mode 100644
index 69559bdb1..000000000
--- a/libc/pwd_grp/__getgrent_r.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * __getgrent.c - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "config.h"
-
-
-/*
- * This is the core group-file read function. It behaves exactly like
- * getgrent() except that it is passed a file descriptor. getgrent()
- * is just a wrapper for this function.
- */
-int __getgrent_r (struct group *__restrict group,
- char *__restrict line_buff, size_t buflen, int grp_fd)
-{
- char *endptr, *field_begin, **members;
- int i, line_len, member_num = 0;
-
-
- if (buflen<GRP_BUFFER_SIZE) {
- return ERANGE;
- }
-
- /* We use the restart label to handle malformatted lines */
-restart:
- /* Read the group line into the buffer for processing */
- if ((line_len = read(grp_fd, line_buff, buflen)) <= 0) {
- return EIO;
- }
- field_begin = strchr(line_buff, '\n');
- if (field_begin != NULL)
- lseek(grp_fd, (long) (1 + field_begin - (line_buff + line_len)), SEEK_CUR);
- else {
- /* The line is too long - skip it. :-\ */
- do {
- if ((line_len = read(grp_fd, line_buff, buflen)) <= 0) {
- return EIO;
- }
- } while (!(field_begin = strchr(line_buff, '\n')));
- lseek(grp_fd, (long) (field_begin - line_buff) - line_len + 1, SEEK_CUR);
- goto restart;
- }
- if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' || *line_buff == '\t')
- goto restart;
- *field_begin = '\0';
-
- /* We've read the line; now parse it. */
- field_begin = line_buff;
- for (i = 0; i < 3; i++) {
- switch (i) {
- case 0:
- group->gr_name = field_begin;
- break;
- case 1:
- group->gr_passwd = field_begin;
- break;
- case 2:
- group->gr_gid = (__gid_t) strtoul(field_begin, &endptr, 10);
- if (*endptr != ':')
- goto restart;
- break;
- }
- if (i < 3) {
- field_begin = strchr(field_begin, ':');
- if (field_begin == NULL)
- break;
- *field_begin++ = '\0';
- }
- }
-
- members = (char **) malloc(sizeof(char *));
- if (members==NULL) {
- return ENOMEM;
- }
- while(field_begin && strlen(field_begin)) {
- members[member_num++] = field_begin;
- members = (char **) realloc(members, (member_num + 1) * sizeof(char *));
- if (members==NULL) {
- return ENOMEM;
- }
- endptr = strchr(field_begin, ',');
- if (endptr == NULL) {
- /* Final entry */
- break;
- }
- *field_begin++ = '\0';
- }
- members[member_num] = NULL;
- group->gr_mem = members;
- return 0;
-}
diff --git a/libc/pwd_grp/__getpwent_r.c b/libc/pwd_grp/__getpwent_r.c
deleted file mode 100644
index 6e6de4038..000000000
--- a/libc/pwd_grp/__getpwent_r.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * __getpwent_r.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- * March 7, 2001 -- Reworked to be reentrant by Erik Andersen
- * Oct 9, 2003 -- Reworked again by Erik Andersen to be fully reentrant
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "config.h"
-
-
-/* This isn't as flash as my previous version -- it doesn't dynamically
- scale down the gecos on too-long lines, but it also makes fewer syscalls,
- so it's probably nicer. Write me if you want the old version. Maybe I
- should include it as a build-time option... ?
- -Nat <ndf@linux.mit.edu> */
-
-int __getpwent_r(struct passwd * passwd, char * line_buff, size_t buflen, int pwd_fd)
-{
- char *endptr, *field_begin;
- char *gid_ptr=NULL;
- char *uid_ptr=NULL;
- int i, line_len;
-
- if (buflen<PWD_BUFFER_SIZE) {
- return ERANGE;
- }
-
- /* We use the restart label to handle malformatted lines */
-restart:
- /* Read the passwd line into the buffer for processing */
- if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0) {
- return EIO;
- }
- field_begin = strchr(line_buff, '\n');
- if (field_begin != NULL)
- lseek(pwd_fd, (long) (1 + field_begin - (line_buff + line_len)), SEEK_CUR);
- else {
- /* The line is too long - skip it. :-\ */
- do {
- if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0) {
- return EIO;
- }
- } while (!(field_begin = strchr(line_buff, '\n')));
- lseek(pwd_fd, (long) (field_begin - line_buff) - line_len + 1, SEEK_CUR);
- goto restart;
- }
- if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' || *line_buff == '\t')
- goto restart;
- *field_begin = '\0';
-
- /* We've read the line; now parse it. */
- field_begin = line_buff;
- for (i = 0; i < 7; i++) {
- switch (i) {
- case 0:
- passwd->pw_name = field_begin;
- break;
- case 1:
- passwd->pw_passwd = field_begin;
- break;
- case 2:
- uid_ptr = field_begin;
- break;
- case 3:
- gid_ptr = field_begin;
- break;
- case 4:
- passwd->pw_gecos = field_begin;
- break;
- case 5:
- passwd->pw_dir = field_begin;
- break;
- case 6:
- passwd->pw_shell = field_begin;
- break;
- }
- if (i < 6) {
- field_begin = strchr(field_begin, ':');
- if (field_begin == NULL)
- goto restart;
- *field_begin++ = '\0';
- }
- }
- passwd->pw_gid = (gid_t) strtoul(gid_ptr, &endptr, 10);
- if (*endptr != '\0')
- goto restart;
-
- passwd->pw_uid = (uid_t) strtoul(uid_ptr, &endptr, 10);
- if (*endptr != '\0')
- goto restart;
-
- return 0;
-}
diff --git a/libc/pwd_grp/__getspent_r.c b/libc/pwd_grp/__getspent_r.c
deleted file mode 100644
index 8ac7d40ea..000000000
--- a/libc/pwd_grp/__getspent_r.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* __getspent_r.c - Based on __getpwent_r.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "config.h"
-
-
-int __getspent_r(struct spwd * spwd, char * line_buff, size_t buflen, int spwd_fd)
-{
- char *endptr;
- int line_len;
-
- if (buflen<PWD_BUFFER_SIZE)
- return ERANGE;
-
- /* We use the restart label to handle malformatted lines */
-restart:
- /* Read the shadow line into the buffer using a minimum of syscalls. */
- if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0)
- return EIO;
- endptr = strchr(line_buff, '\n');
- if (endptr != NULL)
- lseek(spwd_fd, (long) (1 + endptr - (line_buff + line_len)), SEEK_CUR);
- else {
- /* The line is too long - skip it. :-\ */
- do {
- if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0)
- return EIO;
- } while (!(endptr = strchr(line_buff, '\n')));
- lseek(spwd_fd, (long) (endptr - line_buff) - line_len + 1, SEEK_CUR);
- goto restart;
- }
-
- if (__sgetspent_r(line_buff, spwd, line_buff, buflen) != 0)
- goto restart;
-
- return 0;
-}
diff --git a/libc/pwd_grp/__sgetspent_r.c b/libc/pwd_grp/__sgetspent_r.c
deleted file mode 100644
index fbd40fc62..000000000
--- a/libc/pwd_grp/__sgetspent_r.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * __sgetspent_r.c - Based on __getpwent_r.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "config.h"
-
-
-int __sgetspent_r(const char * string, struct spwd * spwd, char * line_buff, size_t buflen)
-{
- char *field_begin;
- char *endptr;
- char *lstchg_ptr=NULL;
- char *min_ptr=NULL;
- char *max_ptr=NULL;
- char *warn_ptr=NULL;
- char *inact_ptr=NULL;
- char *expire_ptr=NULL;
- char *flag_ptr=NULL;
- int i;
-
- if (buflen<PWD_BUFFER_SIZE)
- return ERANGE;
-
- if (string != line_buff) {
- if (strlen(string) >= buflen)
- return ERANGE;
- strcpy(line_buff, string);
- }
-
- if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' ||
- *line_buff == '\t')
- return EINVAL;
-
- field_begin = strchr(line_buff, '\n');
- if (field_begin != NULL)
- *field_begin = '\0';
-
- /* We've read the line; now parse it. */
- field_begin = line_buff;
- for (i = 0; i < 9; i++) {
- switch (i) {
- case 0:
- spwd->sp_namp = field_begin;
- break;
- case 1:
- spwd->sp_pwdp = field_begin;
- break;
- case 2:
- lstchg_ptr = field_begin;
- break;
- case 3:
- min_ptr = field_begin;
- break;
- case 4:
- max_ptr = field_begin;
- break;
- case 5:
- warn_ptr = field_begin;
- break;
- case 6:
- inact_ptr = field_begin;
- break;
- case 7:
- expire_ptr = field_begin;
- break;
- case 8:
- flag_ptr = field_begin;
- break;
- }
- if (i < 8) {
- field_begin = strchr(field_begin, ':');
- if (field_begin == NULL) {
- if (i==4 || i==7)
- break;
- return EINVAL;
- }
- *field_begin++ = '\0';
- }
- }
-
- if (*lstchg_ptr == '\0') {
- spwd->sp_lstchg = -1;
- } else {
- spwd->sp_lstchg = (gid_t) strtoul(lstchg_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
-
- if (*min_ptr == '\0') {
- spwd->sp_min = -1;
- } else {
- spwd->sp_min = (gid_t) strtoul(min_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
-
- if (*max_ptr == '\0') {
- spwd->sp_max = -1;
- } else {
- spwd->sp_max = (gid_t) strtoul(max_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
-
- if (warn_ptr == NULL) {
- /* Support for old format */
- spwd->sp_warn = -1;
- spwd->sp_inact = -1;
- spwd->sp_expire = -1;
- spwd->sp_flag = 0;
- }
- else {
- if (*warn_ptr == '\0') {
- spwd->sp_warn = -1;
- } else {
- spwd->sp_warn = (gid_t) strtoul(warn_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
-
- if (*inact_ptr == '\0') {
- spwd->sp_inact = -1;
- } else {
- spwd->sp_inact = (gid_t) strtoul(inact_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
-
- if (*expire_ptr == '\0') {
- spwd->sp_expire = -1;
- } else {
- spwd->sp_expire = (gid_t) strtoul(expire_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
-
- if (flag_ptr==NULL || *flag_ptr=='\0') {
- spwd->sp_flag = ~0ul;
- } else {
- spwd->sp_flag = (gid_t) strtoul(flag_ptr, &endptr, 10);
- if (*endptr != '\0')
- return EINVAL;
- }
- }
-
- return 0;
-}
diff --git a/libc/pwd_grp/config.h b/libc/pwd_grp/config.h
deleted file mode 100644
index fb678876b..000000000
--- a/libc/pwd_grp/config.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * config.h - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- *
- * 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.
- *
- */
-
-
-#ifndef _CONFIG_GRP_H
-#define _CONFIG_GRP_H
-
-#include <features.h>
-#include <pwd.h>
-#include <grp.h>
-#include <shadow.h>
-
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-
-/* These are used internally to uClibc */
-extern int __getgrent_r (struct group *__restrict group,
- char *__restrict line_buff, size_t buflen, int grp_fd);
-extern int __getpwent_r(struct passwd * passwd, char * line_buff,
- size_t buflen, int pwd_fd);
-extern int __getspent_r(struct spwd * spwd, char * line_buff,
- size_t buflen, int spwd_fd);
-extern int __sgetspent_r(const char * string, struct spwd * spwd,
- char * line_buff, size_t buflen);
-
-
-#endif /* !_CONFIG_GRP_H */
diff --git a/libc/pwd_grp/fgetgrent.c b/libc/pwd_grp/fgetgrent.c
deleted file mode 100644
index d1a6514bd..000000000
--- a/libc/pwd_grp/fgetgrent.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * fgetgrent.c - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-
-int fgetgrent_r (FILE *__restrict file, struct group *__restrict grp,
- char *__restrict buff, size_t buflen,
- struct group **__restrict result)
-{
- int ret;
- if (file == NULL) {
- return EINTR;
- }
- *result = NULL;
- flockfile(file);
- ret = __getgrent_r(grp, buff, buflen, fileno(file));
- funlockfile(file);
- if (ret == 0) {
- *result = grp;
- return 0;
- }
- __set_errno(ret);
- return ret;
-}
-
-struct group *fgetgrent(FILE * file)
-{
- int ret;
- struct group *result;
- static struct group grp;
- static char line_buff[PWD_BUFFER_SIZE];
-
- LOCK;
- ret=fgetgrent_r(file, &grp, line_buff, sizeof(line_buff), &result);
- if (ret == 0) {
- UNLOCK;
- return result;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
diff --git a/libc/pwd_grp/fgetpwent.c b/libc/pwd_grp/fgetpwent.c
deleted file mode 100644
index 14ac73698..000000000
--- a/libc/pwd_grp/fgetpwent.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * fgetpwent.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <errno.h>
-#include <stdio.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int fgetpwent_r (FILE *file, struct passwd *password,
- char *buff, size_t buflen, struct passwd **result)
-{
- int res;
- if (file == NULL) {
- return EINTR;
- }
- *result = NULL;
- res = __getpwent_r(password, buff, buflen, fileno(file));
- *result = password;
- return res;
-}
-
-struct passwd *fgetpwent(FILE * file)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct passwd pwd;
- struct passwd *result;
-
- LOCK;
- if ((ret=fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &pwd;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
diff --git a/libc/pwd_grp/fgetspent.c b/libc/pwd_grp/fgetspent.c
deleted file mode 100644
index 497db40cc..000000000
--- a/libc/pwd_grp/fgetspent.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * fgetspent.c - Based on fgetpwent.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <errno.h>
-#include <stdio.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int fgetspent_r (FILE *file, struct spwd *spwd,
- char *buff, size_t buflen, struct spwd **result)
-{
- int res;
- if (file == NULL) {
- return EINTR;
- }
- *result = NULL;
- res = __getspent_r(spwd, buff, buflen, fileno(file));
- *result = spwd;
- return res;
-}
-
-struct spwd *fgetspent(FILE * file)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct spwd spwd;
- struct spwd *result;
-
- LOCK;
- if ((ret=fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &spwd;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c
deleted file mode 100644
index b8f2a29f5..000000000
--- a/libc/pwd_grp/getgrgid.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getgrgid.c - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <errno.h>
-#include "config.h"
-
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-
-/* Search for an entry with a matching group ID. */
-int getgrgid_r (gid_t gid, struct group *group, char *buffer,
- size_t buflen, struct group **result)
-{
- int grp_fd;
- if ((grp_fd = open(_PATH_GROUP, O_RDONLY)) < 0)
- return errno;
-
- *result = NULL;
- while (__getgrent_r(group, buffer, buflen, grp_fd) == 0) {
- if (group->gr_gid == gid) {
- close(grp_fd);
- *result = group;
- return 0;
- }
- }
-
- close(grp_fd);
- return EINVAL;
-}
-
-struct group *getgrgid(const gid_t gid)
-{
- int ret;
- struct group *result;
- static struct group grp;
- static char line_buff[GRP_BUFFER_SIZE];
-
- LOCK;
- if ((ret=getgrgid_r(gid, &grp, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &grp;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
-
diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c
deleted file mode 100644
index 27d714407..000000000
--- a/libc/pwd_grp/getgrnam.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getgrnam.c - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int getgrnam_r (const char *name, struct group *group,
- char *buff, size_t buflen, struct group **result)
-{
- int ret;
- int group_fd;
-
- *result = NULL;
-
- if (name == NULL) {
- return EINVAL;
- }
-
- if ((group_fd = open(_PATH_GROUP, O_RDONLY)) < 0) {
- return ENOENT;
- }
-
- while ((ret=__getgrent_r(group, buff, buflen, group_fd)) == 0) {
- if (!strcmp(group->gr_name, name)) {
- close(group_fd);
- *result = group;
- return 0;
- }
- }
-
- close(group_fd);
- return ret;
-}
-
-struct group *getgrnam(const char *name)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct group grp;
- struct group *result;
-
- LOCK;
- if ((ret=getgrnam_r(name, &grp, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &grp;
- }
- __set_errno(ret);
- UNLOCK;
- return NULL;
-}
-
-
diff --git a/libc/pwd_grp/getpw.c b/libc/pwd_grp/getpw.c
deleted file mode 100644
index 6665b6090..000000000
--- a/libc/pwd_grp/getpw.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getpw.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <stdio.h>
-#include "config.h"
-
-int getpw(uid_t uid, char *buf)
-{
- struct passwd *passwd;
-
- if (buf == NULL) {
- __set_errno(EINVAL);
- return -1;
- }
- if ((passwd = getpwuid(uid)) == NULL)
- return -1;
-
- if (sprintf
- (buf, "%s:%s:%u:%u:%s:%s:%s", passwd->pw_name, passwd->pw_passwd,
- passwd->pw_gid, passwd->pw_uid, passwd->pw_gecos, passwd->pw_dir,
- passwd->pw_shell) < 0) {
- __set_errno(ENOBUFS);
- return -1;
- }
-
- return 0;
-}
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c
deleted file mode 100644
index b9a55f114..000000000
--- a/libc/pwd_grp/getpwnam.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getpwnam.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int getpwnam_r (const char *name, struct passwd *password,
- char *buff, size_t buflen, struct passwd **result)
-{
- int ret;
- int passwd_fd;
-
- *result = NULL;
-
- if (name == NULL) {
- return EINVAL;
- }
-
- if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) {
- return ENOENT;
- }
-
- while ((ret=__getpwent_r(password, buff, buflen, passwd_fd)) == 0) {
- if (!strcmp(password->pw_name, name)) {
- close(passwd_fd);
- *result = password;
- return 0;
- }
- }
-
- close(passwd_fd);
- return ret;
-}
-
-struct passwd *getpwnam(const char *name)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct passwd pwd;
- struct passwd *result;
-
- LOCK;
- if ((ret=getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &pwd;
- }
- __set_errno(ret);
- UNLOCK;
- return NULL;
-}
-
diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c
deleted file mode 100644
index 5ec890647..000000000
--- a/libc/pwd_grp/getpwuid.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getpwuid.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <errno.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int getpwuid_r (uid_t uid, struct passwd *password,
- char *buff, size_t buflen, struct passwd **result)
-{
- int passwd_fd;
- if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
- return errno;
-
- *result = NULL;
- while (__getpwent_r(password, buff, buflen, passwd_fd) == 0) {
- if (password->pw_uid == uid) {
- close(passwd_fd);
- *result = password;
- return 0;
- }
- }
-
- close(passwd_fd);
- return EINVAL;
-}
-
-struct passwd *getpwuid(uid_t uid)
-{
- int ret;
- struct passwd *result;
- static struct passwd pwd;
- static char line_buff[PWD_BUFFER_SIZE];
-
- LOCK;
- if ((ret=getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &pwd;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
-
diff --git a/libc/pwd_grp/getspnam.c b/libc/pwd_grp/getspnam.c
deleted file mode 100644
index 2b1d4c95c..000000000
--- a/libc/pwd_grp/getspnam.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getspnam.c - Based on getpwnam.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int getspnam_r (const char *name, struct spwd *spwd,
- char *buff, size_t buflen, struct spwd **result)
-{
- int spwd_fd;
-
- if (name == NULL) {
- return EINVAL;
- }
-
- if ((spwd_fd = open(_PATH_SHADOW, O_RDONLY)) < 0)
- return errno;
-
- *result = NULL;
- while (__getspent_r(spwd, buff, buflen, spwd_fd) == 0)
- if (!strcmp(spwd->sp_namp, name)) {
- close(spwd_fd);
- *result = spwd;
- return 0;
- }
-
- close(spwd_fd);
- return EINVAL;
-}
-
-struct spwd *getspnam(const char *name)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct spwd spwd;
- struct spwd *result;
-
- LOCK;
- if ((ret=getspnam_r(name, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &spwd;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
-
diff --git a/libc/pwd_grp/getspuid.c b/libc/pwd_grp/getspuid.c
deleted file mode 100644
index c97d186bd..000000000
--- a/libc/pwd_grp/getspuid.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * getspuid.c - Based on getpwuid.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int getspuid_r (uid_t uid, struct spwd *spwd,
- char *buff, size_t buflen, struct spwd **result)
-{
- int ret;
- char pwd_buff[PWD_BUFFER_SIZE];
- struct passwd password;
-
- *result = NULL;
- ret = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), NULL);
- if (ret != 0)
- return ret;
-
- ret = getspnam_r(password.pw_name, spwd, buff, buflen, result);
- *result = spwd;
- return ret;
-}
-
-struct spwd *getspuid(uid_t uid)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct spwd spwd;
- struct spwd *result;
-
- LOCK;
- if ((ret=getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &spwd;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
-
diff --git a/libc/pwd_grp/grent.c b/libc/pwd_grp/grent.c
deleted file mode 100644
index b2d6f8c6a..000000000
--- a/libc/pwd_grp/grent.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * grent.c - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-/*
- * setgrent(), endgrent(), and getgrent() are mutually-dependent functions,
- * so they are all included in the same object file, and thus all linked
- * in together.
- */
-
-#define _GNU_SOURCE
-#include <features.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <errno.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-/* file descriptor for the group file currently open */
-static int grp_fd = -9;
-
-void setgrent(void)
-{
- LOCK;
- if (grp_fd > -1)
- close(grp_fd);
- grp_fd = open(_PATH_GROUP, O_RDONLY);
- UNLOCK;
-}
-
-void endgrent(void)
-{
- LOCK;
- if (grp_fd > -1)
- close(grp_fd);
- grp_fd = -9;
- UNLOCK;
-}
-
-int getgrent_r (struct group *grp, char *buff,
- size_t buflen, struct group **result)
-{
- int ret=EINVAL;
- *result = NULL;
-
- LOCK;
- /* Open /etc/group if it has never been opened */
- if (grp_fd == -9) {
- setgrent();
- }
- if (grp_fd == -1) {
- UNLOCK;
- return -1;
- }
- ret=__getgrent_r(grp, buff, buflen, grp_fd);
- if (ret == 0) {
- UNLOCK;
- *result = grp;
- return 0;
- }
- UNLOCK;
- __set_errno(ret);
- return ret;
-}
-
-struct group *getgrent(void)
-{
- int ret;
- struct group *result;
- static struct group grp;
- static char line_buff[PWD_BUFFER_SIZE];
-
- ret = getgrent_r(&grp, line_buff, sizeof(line_buff), &result);
- if (ret == 0) {
- return &grp;
- }
- __set_errno(ret);
- return NULL;
-}
diff --git a/libc/pwd_grp/initgroups.c b/libc/pwd_grp/initgroups.c
deleted file mode 100644
index bc537069c..000000000
--- a/libc/pwd_grp/initgroups.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * initgroups.c - This file is part of the libc-8086/grp package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int initgroups(__const char *user, gid_t gid)
-{
- gid_t *group_list = NULL;
- register char **tmp_mem;
- int num_groups;
- int grp_fd;
- static struct group group;
- static char line_buff[PWD_BUFFER_SIZE];
-
- if ((grp_fd = open(_PATH_GROUP, O_RDONLY)) < 0)
- return errno;
-
- num_groups = 0;
- group_list = (gid_t *) realloc(group_list, 1);
- group_list[num_groups] = gid;
- LOCK;
- while (__getgrent_r(&group, line_buff, sizeof(line_buff), grp_fd) == 0)
- {
- if (group.gr_gid != gid)
- {
- tmp_mem = group.gr_mem;
- while (*tmp_mem != NULL) {
- if (!strcmp(*tmp_mem, user)) {
- num_groups++;
- group_list = (gid_t *) realloc(group_list, num_groups * sizeof(gid_t *));
- group_list[num_groups-1] = group.gr_gid;
- }
- tmp_mem++;
- }
- }
- }
- close(grp_fd);
- UNLOCK;
- return setgroups(num_groups, group_list);
-}
diff --git a/libc/pwd_grp/putgrent.c b/libc/pwd_grp/putgrent.c
deleted file mode 100644
index d4838dbee..000000000
--- a/libc/pwd_grp/putgrent.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * putgrent.c
- * Copyright (C) 2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include "config.h"
-
-
-/* Write the given entry onto the given stream. */
-int putgrent(const struct group *__restrict grp,
- FILE *__restrict f)
-{
- if (grp == NULL || f == NULL) {
- __set_errno(EINVAL);
- return -1;
- }
- if (fprintf(f, "%s:%s:%u:", grp->gr_name,
- grp->gr_passwd, grp->gr_gid) < 0)
- {
- return -1;
- }
- if (grp->gr_mem) {
- int i;
- char **gr_mem = grp->gr_mem;
- while(*gr_mem) {
- if (fprintf(f, (i++)? ",%s" : "%s", *gr_mem) < 0) {
- return -1;
- }
- gr_mem++;
- }
- }
-
- if (fputc('\n', f) < 0) {
- return -1;
- }
- return 0;
-}
-
diff --git a/libc/pwd_grp/putpwent.c b/libc/pwd_grp/putpwent.c
deleted file mode 100644
index bbc8ec3a8..000000000
--- a/libc/pwd_grp/putpwent.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * putpwent.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include "config.h"
-
-int putpwent(const struct passwd *passwd, FILE * f)
-{
- if (passwd == NULL || f == NULL) {
- __set_errno(EINVAL);
- return -1;
- }
- if (fprintf
- (f, "%s:%s:%u:%u:%s:%s:%s\n", passwd->pw_name, passwd->pw_passwd,
- passwd->pw_uid, passwd->pw_gid, passwd->pw_gecos, passwd->pw_dir,
- passwd->pw_shell) < 0)
- return -1;
-
- return 0;
-}
-
diff --git a/libc/pwd_grp/putspent.c b/libc/pwd_grp/putspent.c
deleted file mode 100644
index 401401705..000000000
--- a/libc/pwd_grp/putspent.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* Copyright (C) 1991, 1992, 1996, 1997, 1998 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C 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.
-
- The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <stdio.h>
-#include "config.h"
-
-#define _S(x) x ? x : ""
-
-
-/* Write an entry to the given stream.
- This must know the format of the password file. */
-int putspent (const struct spwd *p, FILE *stream)
-{
- int errors = 0;
-
- if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
- ++errors;
-
- if ((p->sp_lstchg != (long int) -1
- && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
- || (p->sp_lstchg == (long int) -1
- && putc (':', stream) == EOF))
- ++errors;
-
- if ((p->sp_min != (long int) -1
- && fprintf (stream, "%ld:", p->sp_min) < 0)
- || (p->sp_min == (long int) -1
- && putc (':', stream) == EOF))
- ++errors;
-
- if ((p->sp_max != (long int) -1
- && fprintf (stream, "%ld:", p->sp_max) < 0)
- || (p->sp_max == (long int) -1
- && putc (':', stream) == EOF))
- ++errors;
-
- if ((p->sp_warn != (long int) -1
- && fprintf (stream, "%ld:", p->sp_warn) < 0)
- || (p->sp_warn == (long int) -1
- && putc (':', stream) == EOF))
- ++errors;
-
- if ((p->sp_inact != (long int) -1
- && fprintf (stream, "%ld:", p->sp_inact) < 0)
- || (p->sp_inact == (long int) -1
- && putc (':', stream) == EOF))
- ++errors;
-
- if ((p->sp_expire != (long int) -1
- && fprintf (stream, "%ld:", p->sp_expire) < 0)
- || (p->sp_expire == (long int) -1
- && putc (':', stream) == EOF))
- ++errors;
-
- if (p->sp_flag != ~0ul
- && fprintf (stream, "%ld", p->sp_flag) < 0)
- ++errors;
-
- if (putc ('\n', stream) == EOF)
- ++errors;
-
- return errors ? -1 : 0;
-}
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
new file mode 100644
index 000000000..da8893eb9
--- /dev/null
+++ b/libc/pwd_grp/pwd_grp.c
@@ -0,0 +1,1172 @@
+/* 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.
+ */
+
+/* Nov 6, 2003 Initial version.
+ *
+ * NOTE: This implementation is quite strict about requiring all
+ * field seperators. It also does not allow leading whitespace
+ * except when processing the numeric fields. glibc is more
+ * lenient. See the various glibc difference comments below.
+ *
+ * TODO:
+ * Move to dynamic allocation of (currently staticly allocated)
+ * buffers; especially for the group-related functions since
+ * large group member lists will cause error returns.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <features.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stddef.h>
+#include <errno.h>
+#include <assert.h>
+#include <ctype.h>
+#include <pwd.h>
+#include <grp.h>
+#include <shadow.h>
+#ifdef __UCLIBC_HAS_THREADS__
+#include <pthread.h>
+#endif
+
+/**********************************************************************/
+/* Sizes for staticly allocated buffers. */
+
+#define PWD_BUFFER_SIZE 256
+#define GRP_BUFFER_SIZE 256
+
+/**********************************************************************/
+/* Prototypes for internal functions. */
+
+extern int __parsepwent(void *pw, char *line);
+extern int __parsegrent(void *gr, char *line);
+extern int __parsespent(void *sp, char *line);
+
+extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
+ char *__restrict line_buff, size_t buflen, FILE *f);
+
+/**********************************************************************/
+/* For the various fget??ent_r funcs, return
+ *
+ * 0: success
+ * ENOENT: end-of-file encountered
+ * ERANGE: buflen too small
+ * other error values possible. See __pgsreader.
+ *
+ * Also, *result == resultbuf on success and NULL on failure.
+ *
+ * NOTE: glibc difference - For the ENOENT case, glibc also sets errno.
+ * We do not, as it really isn't an error if we reach the end-of-file.
+ * Doing so is analogous to having fgetc() set errno on EOF.
+ */
+/**********************************************************************/
+#ifdef L_fgetpwent_r
+
+int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
+ char *__restrict buffer, size_t buflen,
+ struct passwd **__restrict result)
+{
+ int rv;
+
+ *result = NULL;
+
+ if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) {
+ *result = resultbuf;
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_fgetgrent_r
+
+int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
+ char *__restrict buffer, size_t buflen,
+ struct group **__restrict result)
+{
+ int rv;
+
+ *result = NULL;
+
+ if (!(rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream))) {
+ *result = resultbuf;
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_fgetspent_r
+
+int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
+ char *__restrict buffer, size_t buflen,
+ struct spwd **__restrict result)
+{
+ int rv;
+
+ *result = NULL;
+
+ if (!(rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream))) {
+ *result = resultbuf;
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+/* For the various fget??ent funcs, return NULL on failure and a
+ * pointer to the appropriate struct (staticly allocated) on success.
+ */
+/**********************************************************************/
+#ifdef L_fgetpwent
+
+struct passwd *fgetpwent(FILE *stream)
+{
+ static char buffer[PWD_BUFFER_SIZE];
+ static struct passwd resultbuf;
+ struct passwd *result;
+
+ fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_fgetgrent
+
+struct group *fgetgrent(FILE *stream)
+{
+ static char buffer[GRP_BUFFER_SIZE];
+ static struct group resultbuf;
+ struct group *result;
+
+ fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_fgetspent
+
+struct spwd *fgetspent(FILE *stream)
+{
+ static char buffer[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
+
+int sgetspent_r(const char *string, struct spwd *result_buf,
+ char *buffer, size_t buflen, struct spwd **result)
+{
+ int rv = ERANGE;
+
+ *result = NULL;
+
+ if (buflen < PWD_BUFFER_SIZE) {
+ DO_ERANGE:
+ __set_errno(rv);
+ goto DONE;
+ }
+
+ if (string != buffer) {
+ if (strlen(string) >= buflen) {
+ goto DO_ERANGE;
+ }
+ strcpy(buffer, string);
+ }
+
+ if (!(rv = __parsespent(result_buf, buffer))) {
+ *result = result_buf;
+ }
+
+ DONE:
+ return rv;
+}
+
+#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
+#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
+#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
+#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
+#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
+#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)
+{
+ static char buffer[PWD_BUFFER_SIZE];
+ static struct passwd resultbuf;
+ struct passwd *result;
+
+ getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getgrgid
+
+struct group *getgrgid(gid_t gid)
+{
+ static char buffer[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. */
+
+int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
+ char *__restrict buffer, size_t buflen,
+ struct spwd **__restrict result)
+{
+ int rv;
+ struct passwd *pp;
+ struct passwd password;
+ char pwd_buff[PWD_BUFFER_SIZE];
+
+ *result = NULL;
+ if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) {
+ rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result);
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getspuid
+
+/* This function is non-standard and is currently not built.
+ * Why it was added, I do not know. */
+
+struct spwd *getspuid(uid_t uid)
+{
+ static char buffer[PWD_BUFFER_SIZE];
+ static struct spwd resultbuf;
+ struct spwd *result;
+
+ getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getpwnam
+
+struct passwd *getpwnam(const char *name)
+{
+ static char buffer[PWD_BUFFER_SIZE];
+ static struct passwd resultbuf;
+ struct passwd *result;
+
+ getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getgrnam
+
+struct group *getgrnam(const char *name)
+{
+ static char buffer[GRP_BUFFER_SIZE];
+ static struct group resultbuf;
+ struct group *result;
+
+ getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getspnam
+
+struct spwd *getspnam(const char *name)
+{
+ static char buffer[PWD_BUFFER_SIZE];
+ static struct spwd resultbuf;
+ struct spwd *result;
+
+ getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getpw
+
+int getpw(uid_t uid, char *buf)
+{
+ struct passwd resultbuf;
+ struct passwd *result;
+ char buffer[PWD_BUFFER_SIZE];
+
+ if (!buf) {
+ __set_errno(EINVAL);
+ } else if (!getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result)) {
+ if (sprintf(buf, "%s:%s:%lu:%lu:%s:%s:%s\n",
+ resultbuf.pw_name, resultbuf.pw_passwd,
+ (unsigned long)(resultbuf.pw_uid),
+ (unsigned long)(resultbuf.pw_gid),
+ resultbuf.pw_gecos, resultbuf.pw_dir,
+ resultbuf.pw_shell) >= 0
+ ) {
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getpwent_r
+
+#ifdef __UCLIBC_HAS_THREADS__
+static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+# define LOCK pthread_mutex_lock(&mylock)
+# define UNLOCK pthread_mutex_unlock(&mylock);
+#else
+# define LOCK ((void) 0)
+# define UNLOCK ((void) 0)
+#endif
+
+static FILE *pwf /*= NULL*/;
+
+void setpwent(void)
+{
+ LOCK;
+ if (pwf) {
+ rewind(pwf);
+ }
+ UNLOCK;
+}
+
+void endpwent(void)
+{
+ LOCK;
+ if (pwf) {
+ fclose(pwf);
+ pwf = NULL;
+ }
+ UNLOCK;
+}
+
+
+int getpwent_r(struct passwd *__restrict resultbuf,
+ char *__restrict buffer, size_t buflen,
+ struct passwd **__restrict result)
+{
+ int rv;
+
+ LOCK;
+
+ *result = NULL; /* In case of error... */
+
+ if (!pwf) {
+ if (!(pwf = fopen(_PATH_PASSWD, "r"))) {
+ rv = errno;
+ goto ERR;
+ }
+ __STDIO_SET_USER_LOCKING(pwf);
+ }
+
+ if (!(rv = __pgsreader(__parsepwent, resultbuf,
+ buffer, buflen, pwf))) {
+ *result = resultbuf;
+ }
+
+ ERR:
+ UNLOCK;
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getgrent_r
+
+#ifdef __UCLIBC_HAS_THREADS__
+static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+# 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)
+{
+ LOCK;
+ if (grf) {
+ rewind(grf);
+ }
+ UNLOCK;
+}
+
+void endgrent(void)
+{
+ LOCK;
+ if (grf) {
+ fclose(grf);
+ grf = NULL;
+ }
+ UNLOCK;
+}
+
+int getgrent_r(struct group *__restrict resultbuf,
+ char *__restrict buffer, size_t buflen,
+ struct group **__restrict result)
+{
+ int rv;
+
+ LOCK;
+
+ *result = NULL; /* In case of error... */
+
+ if (!grf) {
+ if (!(grf = fopen(_PATH_GROUP, "r"))) {
+ rv = errno;
+ goto ERR;
+ }
+ __STDIO_SET_USER_LOCKING(grf);
+ }
+
+ if (!(rv = __pgsreader(__parsegrent, resultbuf,
+ buffer, buflen, grf))) {
+ *result = resultbuf;
+ }
+
+ ERR:
+ UNLOCK;
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getspent_r
+
+#ifdef __UCLIBC_HAS_THREADS__
+static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+# 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)
+{
+ LOCK;
+ if (spf) {
+ rewind(spf);
+ }
+ UNLOCK;
+}
+
+void endspent(void)
+{
+ LOCK;
+ if (spf) {
+ fclose(spf);
+ spf = NULL;
+ }
+ UNLOCK;
+}
+
+int getspent_r(struct spwd *resultbuf, char *buffer,
+ size_t buflen, struct spwd **result)
+{
+ int rv;
+
+ LOCK;
+
+ *result = NULL; /* In case of error... */
+
+ if (!spf) {
+ if (!(spf = fopen(_PATH_SHADOW, "r"))) {
+ rv = errno;
+ goto ERR;
+ }
+ __STDIO_SET_USER_LOCKING(spf);
+ }
+
+ if (!(rv = __pgsreader(__parsespent, resultbuf,
+ buffer, buflen, spf))) {
+ *result = resultbuf;
+ }
+
+ ERR:
+ UNLOCK;
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getpwent
+
+struct passwd *getpwent(void)
+{
+ static char line_buff[PWD_BUFFER_SIZE];
+ static struct passwd pwd;
+ struct passwd *result;
+
+ getpwent_r(&pwd, line_buff, sizeof(line_buff), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_getgrent
+
+struct group *getgrent(void)
+{
+ static char line_buff[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
+
+struct spwd *getspent(void)
+{
+ static char line_buff[PWD_BUFFER_SIZE];
+ static struct spwd spwd;
+ struct spwd *result;
+
+ getspent_r(&spwd, line_buff, sizeof(line_buff), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_sgetspent
+
+struct spwd *sgetspent(const char *string)
+{
+ static char line_buff[PWD_BUFFER_SIZE];
+ static struct spwd spwd;
+ struct spwd *result;
+
+ sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
+ return result;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_initgroups
+
+int initgroups(const char *user, gid_t gid)
+{
+ FILE *grf;
+ gid_t *group_list;
+ int num_groups, rv;
+ char **m;
+ struct group group;
+ char buff[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)
+ && ((grf = fopen(_PATH_GROUP, "r")) != NULL)
+ ) {
+
+ __STDIO_SET_USER_LOCKING(grf);
+
+ *group_list = gid;
+ num_groups = 1;
+
+ while (!__pgsreader(__parsegrent, &group, buff, sizeof(buff), grf)) {
+ 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(grf);
+ }
+
+ /* group_list will be NULL if initial malloc failed, which may trigger
+ * warnings from various malloc debuggers. */
+ free(group_list);
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_putpwent
+
+int putpwent(const struct passwd *__restrict p, FILE *__restrict f)
+{
+ int rv = -1;
+
+ if (!p || !f) {
+ __set_errno(EINVAL);
+ } else {
+ /* No extra thread locking is needed above what fprintf does. */
+ if (fprintf(f, "%s:%s:%lu:%lu:%s:%s:%s\n",
+ p->pw_name, p->pw_passwd,
+ (unsigned long)(p->pw_uid),
+ (unsigned long)(p->pw_gid),
+ p->pw_gecos, p->pw_dir, p->pw_shell) >= 0
+ ) {
+ rv = 0;
+ }
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_putgrent
+
+int putgrent(const struct group *__restrict p, FILE *__restrict f)
+{
+ static const char format[] = ",%s";
+ char **m;
+ const char *fmt;
+ int rv = -1;
+
+ if (!p || !f) { /* Sigh... glibc checks. */
+ __set_errno(EINVAL);
+ } else {
+ __STDIO_THREADLOCK(f);
+
+ if (fprintf(f, "%s:%s:%lu:",
+ p->gr_name, p->gr_passwd,
+ (unsigned long)(p->gr_gid)) >= 0
+ ) {
+
+ fmt = format + 1;
+
+ assert(p->gr_mem);
+ m = p->gr_mem;
+
+ do {
+ if (!*m) {
+ if (fputc_unlocked('\n', f) >= 0) {
+ rv = 0;
+ }
+ break;
+ }
+ if (fprintf(f, fmt, *m) < 0) {
+ break;
+ }
+ fmt = format;
+ } while (1);
+
+ }
+
+ __STDIO_THREADUNLOCK(f);
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_putspent
+
+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 */
+ offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
+ offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
+ offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
+};
+
+int putspent(const struct spwd *p, FILE *stream)
+{
+ static const char ld_format[] = "%ld:";
+ const char *f;
+ long int x;
+ int i;
+ int rv = -1;
+
+ /* Unlike putpwent and putgrent, glibc does not check the args. */
+
+ __STDIO_THREADLOCK(stream);
+
+ if (fprintf(stream, "%s:%s:", p->sp_namp,
+ (p->sp_pwdp ? p->sp_pwdp : "")) < 0
+ ) {
+ goto DO_UNLOCK;
+ }
+
+ for (i=0 ; i < sizeof(sp_off) ; i++) {
+ f = ld_format;
+ if ((x = *(const long int *)(((const char *) p) + sp_off[i])) == -1) {
+ f += 3;
+ }
+ if (fprintf(stream, f, x) < 0) {
+ goto DO_UNLOCK;
+ }
+ }
+
+ if ((p->sp_flag != ~0UL) && (fprintf(stream, "%lu", p->sp_flag) < 0)) {
+ goto DO_UNLOCK;
+ }
+
+ if (fputc_unlocked('\n', stream) > 0) {
+ rv = 0;
+ }
+
+ DO_UNLOCK:
+ __STDIO_THREADUNLOCK(stream);
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
+/* Internal uClibc functions. */
+/**********************************************************************/
+#ifdef L___parsepwent
+
+static const unsigned char pw_off[] = {
+ offsetof(struct passwd, pw_name), /* 0 */
+ offsetof(struct passwd, pw_passwd), /* 1 */
+ offsetof(struct passwd, pw_uid), /* 2 - not a char ptr */
+ offsetof(struct passwd, pw_gid), /* 3 - not a char ptr */
+ offsetof(struct passwd, pw_gecos), /* 4 */
+ offsetof(struct passwd, pw_dir), /* 5 */
+ offsetof(struct passwd, pw_shell) /* 6 */
+};
+
+int __parsepwent(void *data, char *line)
+{
+ char *endptr;
+ char *p;
+ int i;
+
+ i = 0;
+ do {
+ p = ((char *) ((struct passwd *) data)) + pw_off[i];
+
+ if ((i & 6) ^ 2) { /* i!=2 and i!=3 */
+ *((char **) p) = line;
+ if (i==6) {
+ return 0;
+ }
+ /* NOTE: glibc difference - glibc allows omission of
+ * ':' seperators after the gid field if all remaining
+ * entries are empty. We require all separators. */
+ if (!(line = strchr(line, ':'))) {
+ break;
+ }
+ } else {
+ unsigned long t = strtoul(line, &endptr, 10);
+ /* Make sure we had at least one digit, and that the
+ * failing char is the next field seperator ':'. See
+ * glibc difference note above. */
+ /* TODO: Also check for leading whitespace? */
+ if ((endptr == line) || (*endptr != ':')) {
+ break;
+ }
+ line = endptr;
+ if (i & 1) { /* i == 3 -- gid */
+ *((gid_t *) p) = t;
+ } else { /* i == 2 -- uid */
+ *((uid_t *) p) = t;
+ }
+ }
+
+ *line++ = 0;
+ ++i;
+ } while (1);
+
+ return -1;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L___parsegrent
+
+static const unsigned char gr_off[] = {
+ offsetof(struct group, gr_name), /* 0 */
+ offsetof(struct group, gr_passwd), /* 1 */
+ offsetof(struct group, gr_gid) /* 2 - not a char ptr */
+};
+
+int __parsegrent(void *data, char *line)
+{
+ char *endptr;
+ char *p;
+ int i;
+ char **members;
+ char *end_of_buf;
+
+ end_of_buf = ((struct group *) data)->gr_name; /* Evil hack! */
+ i = 0;
+ do {
+ p = ((char *) ((struct group *) data)) + gr_off[i];
+
+ if (i < 2) {
+ *((char **) p) = line;
+ if (!(line = strchr(line, ':'))) {
+ break;
+ }
+ *line++ = 0;
+ ++i;
+ } else {
+ *((gid_t *) p) = strtoul(line, &endptr, 10);
+
+ /* NOTE: glibc difference - glibc allows omission of the
+ * trailing colon when there is no member list. We treat
+ * this as an error. */
+ if (*endptr != ':') {
+ break;
+ }
+
+ i = 1; /* Count terminating NULL ptr. */
+ p = endptr;
+
+ if (p[1]) { /* We have a member list to process. */
+ /* Overwrite the last ':' with a ',' before counting.
+ * This allows us to test for initial ',' and adds
+ * one ',' so that the ',' count equals the member
+ * count. */
+ *p = ',';
+ do {
+ /* NOTE: glibc difference - glibc allows and trims leading
+ * (but not trailing) space. We treat this as an error. */
+ /* NOTE: glibc difference - glibc allows consecutive and
+ * trailing commas, and ignores "empty string" users. We
+ * treat this as an error. */
+ if (*p == ',') {
+ ++i;
+ *p = 0; /* nul-terminate each member string. */
+ if (!*++p || (*p == ',') || isspace(*p)) {
+ goto ERR;
+ }
+ }
+ } while (*++p);
+ }
+
+ /* Now align (p+1), rounding up. */
+ /* Assumes sizeof(char **) is a power of 2. */
+ members = (char **)( (((intptr_t) p) + sizeof(char **))
+ & ~((intptr_t)(sizeof(char **) - 1)) );
+
+ if (((char *)(members + i)) > end_of_buf) { /* No space. */
+ break;
+ }
+
+ ((struct group *) data)->gr_mem = members;
+
+ if (--i) {
+ p = endptr; /* Pointing to char prior to first member. */
+ do {
+ *members++ = ++p;
+ if (!--i) break;
+ while (*++p) {}
+ } while (1);
+ }
+ *members = NULL;
+
+ return 0;
+ }
+ } while (1);
+
+ ERR:
+ return -1;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L___parsespent
+
+static const unsigned char sp_off[] = {
+ offsetof(struct spwd, sp_namp), /* 0 */
+ offsetof(struct spwd, sp_pwdp), /* 1 */
+ 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 */
+ offsetof(struct spwd, sp_warn), /* 5 - not a char ptr */
+ offsetof(struct spwd, sp_inact), /* 6 - not a char ptr */
+ offsetof(struct spwd, sp_expire), /* 7 - not a char ptr */
+ offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
+};
+
+int __parsespent(void *data, char * line)
+{
+ char *endptr;
+ char *p;
+ int i;
+
+ i = 0;
+ do {
+ p = ((char *) ((struct spwd *) data)) + sp_off[i];
+ if (i < 2) {
+ *((char **) p) = line;
+ if (!(line = strchr(line, ':'))) {
+ break;
+ }
+ } else {
+#if 0
+ if (i==5) { /* Support for old format. */
+ while (isspace(*line)) ++line; /* glibc eats space here. */
+ if (!*line) {
+ ((struct spwd *) data)->sp_warn = -1;
+ ((struct spwd *) data)->sp_inact = -1;
+ ((struct spwd *) data)->sp_expire = -1;
+ ((struct spwd *) data)->sp_flag = ~0UL;
+ return 0;
+ }
+ }
+#endif
+
+ *((long *) p) = (long) strtoul(line, &endptr, 10);
+
+ if (endptr == line) {
+ *((long *) p) = ((i != 8) ? -1L : ((long)(~0UL)));
+ }
+
+ line = endptr;
+
+ if (i == 8) {
+ if (!*endptr) {
+ return 0;
+ }
+ break;
+ }
+
+ if (*endptr != ':') {
+ break;
+ }
+
+ }
+
+ *line++ = 0;
+ ++i;
+ } while (1);
+
+ return EINVAL;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L___pgsreader
+
+/* Reads until if EOF, or until if finds a line which fits in the buffer
+ * and for which the parser function succeeds.
+ *
+ * Returns 0 on success and ENOENT for end-of-file (glibc concession).
+ * On error, it both sets errno to ERANGE and returns ERANGE.
+ * (seems to be glibc behavior.)
+ */
+
+int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
+ char *__restrict line_buff, size_t buflen, FILE *f)
+{
+ int line_len;
+ int skip;
+ int rv = ERANGE;
+
+ if (buflen < PWD_BUFFER_SIZE) {
+ __set_errno(rv);
+ } else {
+ __STDIO_THREADLOCK(f);
+
+ skip = 0;
+ do {
+ if (!fgets_unlocked(line_buff, buflen, f)) {
+ if (feof_unlocked(f)) {
+ rv = ENOENT;
+ }
+ break;
+ }
+
+ line_len = strlen(line_buff) - 1; /* strlen() must be > 0. */
+ if (line_buff[line_len] == '\n') {
+ line_buff[line_len] = 0;
+ } else if (line_len + 2 == buflen) { /* line too long */
+ ++skip;
+ continue;
+ }
+
+ if (skip) {
+ --skip;
+ continue;
+ }
+
+ /* NOTE: glibc difference - glibc strips leading whitespace from
+ * records. We do not allow leading whitespace. */
+
+ /* 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. */
+ /* 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. */
+ ((struct group *) data)->gr_name = line_buff + buflen;
+ }
+
+ if (!__parserfunc(data, line_buff)) {
+ rv = 0;
+ break;
+ }
+ }
+ } while (1);
+
+ __STDIO_THREADUNLOCK(f);
+ }
+
+ return rv;
+}
+
+#endif
+/**********************************************************************/
diff --git a/libc/pwd_grp/pwent.c b/libc/pwd_grp/pwent.c
deleted file mode 100644
index 557bffd65..000000000
--- a/libc/pwd_grp/pwent.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * pwent.c - This file is part of the libc-8086/pwd package for ELKS,
- * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-/*
- * setpwent(), endpwent(), and getpwent() are included in the same object
- * file, since one cannot be used without the other two, so it makes sense to
- * link them all in together.
- */
-
-#define _GNU_SOURCE
-#include <features.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-/* file descriptor for the password file currently open */
-static int pw_fd = -9;
-
-void setpwent(void)
-{
- LOCK;
- if (pw_fd > -1)
- close(pw_fd);
- pw_fd = open(_PATH_PASSWD, O_RDONLY);
- UNLOCK;
-}
-
-void endpwent(void)
-{
- LOCK;
- if (pw_fd > -1)
- close(pw_fd);
- pw_fd = -9;
- UNLOCK;
-}
-
-int getpwent_r (struct passwd *password, char *buff,
- size_t buflen, struct passwd **result)
-{
- int ret=EINVAL;
- *result = NULL;
-
- LOCK;
- /* Open /etc/passwd if not yet opened */
- if (pw_fd == -9) {
- setpwent();
- }
- if (pw_fd == -1) {
- UNLOCK;
- return -1;
- }
- ret=__getpwent_r(password, buff, buflen, pw_fd);
- if (ret == 0) {
- UNLOCK;
- *result = password;
- return 0;
- }
- UNLOCK;
- __set_errno(ret);
- return ret;
-}
-
-struct passwd *getpwent(void)
-{
- int ret;
- struct passwd *result;
- static struct passwd pwd;
- static char line_buff[PWD_BUFFER_SIZE];
-
- ret = getpwent_r(&pwd, line_buff, sizeof(line_buff), &result);
- if (ret == 0) {
- return &pwd;
- }
- __set_errno(ret);
- return NULL;
-}
-
diff --git a/libc/pwd_grp/sgetspent.c b/libc/pwd_grp/sgetspent.c
deleted file mode 100644
index 1c6bafbc2..000000000
--- a/libc/pwd_grp/sgetspent.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * sgetspent.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <errno.h>
-#include <stdio.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-int sgetspent_r (const char *string, struct spwd *spwd,
- char *buff, size_t buflen, struct spwd **result)
-{
- int ret;
- *result = NULL;
- ret = __sgetspent_r(string, spwd, buff, buflen);
- *result = spwd;
- return ret;
-}
-
-struct spwd *sgetspent(const char *string)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct spwd spwd;
- struct spwd *result;
-
- LOCK;
- if ((ret = sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &spwd;
- }
- __set_errno(ret);
- UNLOCK;
- return NULL;
-}
diff --git a/libc/pwd_grp/spent.c b/libc/pwd_grp/spent.c
deleted file mode 100644
index 126e8dec6..000000000
--- a/libc/pwd_grp/spent.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * spent.c - Based on pwent.c
- * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org>
- *
- * 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.
- *
- */
-
-#include <features.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include "config.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK pthread_mutex_lock(&mylock)
-# define UNLOCK pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-/*
- * setspent(), endspent(), and getspent() are included in the same object
- * file, since one cannot be used without the other two, so it makes sense to
- * link them all in together.
- */
-
-/* file descriptor for the password file currently open */
-static int spwd_fd = -1;
-
-void setspent(void)
-{
- LOCK;
- if (spwd_fd != -1)
- close(spwd_fd);
- spwd_fd = open(_PATH_SHADOW, O_RDONLY);
- UNLOCK;
-}
-
-void endspent(void)
-{
- LOCK;
- if (spwd_fd != -1)
- close(spwd_fd);
- spwd_fd = -1;
- UNLOCK;
-}
-
-int getspent_r (struct spwd *spwd, char *buff,
- size_t buflen, struct spwd **result)
-{
- int ret=EINVAL;
- LOCK;
- *result = NULL;
- if (spwd_fd != -1 && (ret=__getspent_r(spwd, buff, buflen, spwd_fd)) == 0) {
- UNLOCK;
- *result = spwd;
- return 0;
- }
- UNLOCK;
- return ret;
-}
-
-struct spwd *getspent(void)
-{
- int ret;
- static char line_buff[PWD_BUFFER_SIZE];
- static struct spwd spwd;
- struct spwd *result;
-
- LOCK;
- if ((ret=getspent_r(&spwd, line_buff, sizeof(line_buff), &result)) == 0) {
- UNLOCK;
- return &spwd;
- }
- UNLOCK;
- __set_errno(ret);
- return NULL;
-}
-