diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-11-06 20:56:04 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-11-06 20:56:04 +0000 |
commit | 95f53957e3dcce2544fd03ca3b314f2bbb6f5b2a (patch) | |
tree | 933c82cfe6e2a995a741b2bf0d87933e73fb8fbd /libc/pwd_grp | |
parent | b924d9a8af442bb0c7b2d4c98841482342f5362b (diff) |
Rewrite the pwd.h, grp.h, and shadow.h functions (except lckpwdf/ulckpwdf).
Diffstat (limited to 'libc/pwd_grp')
-rw-r--r-- | libc/pwd_grp/Makefile | 30 | ||||
-rw-r--r-- | libc/pwd_grp/__getgrent_r.c | 114 | ||||
-rw-r--r-- | libc/pwd_grp/__getpwent_r.c | 115 | ||||
-rw-r--r-- | libc/pwd_grp/__getspent_r.c | 59 | ||||
-rw-r--r-- | libc/pwd_grp/__sgetspent_r.c | 167 | ||||
-rw-r--r-- | libc/pwd_grp/config.h | 45 | ||||
-rw-r--r-- | libc/pwd_grp/fgetgrent.c | 74 | ||||
-rw-r--r-- | libc/pwd_grp/fgetpwent.c | 66 | ||||
-rw-r--r-- | libc/pwd_grp/fgetspent.c | 65 | ||||
-rw-r--r-- | libc/pwd_grp/getgrgid.c | 79 | ||||
-rw-r--r-- | libc/pwd_grp/getgrnam.c | 86 | ||||
-rw-r--r-- | libc/pwd_grp/getpw.c | 48 | ||||
-rw-r--r-- | libc/pwd_grp/getpwnam.c | 85 | ||||
-rw-r--r-- | libc/pwd_grp/getpwuid.c | 77 | ||||
-rw-r--r-- | libc/pwd_grp/getspnam.c | 79 | ||||
-rw-r--r-- | libc/pwd_grp/getspuid.c | 72 | ||||
-rw-r--r-- | libc/pwd_grp/grent.c | 107 | ||||
-rw-r--r-- | libc/pwd_grp/initgroups.c | 75 | ||||
-rw-r--r-- | libc/pwd_grp/putgrent.c | 56 | ||||
-rw-r--r-- | libc/pwd_grp/putpwent.c | 41 | ||||
-rw-r--r-- | libc/pwd_grp/putspent.c | 79 | ||||
-rw-r--r-- | libc/pwd_grp/pwd_grp.c | 1172 | ||||
-rw-r--r-- | libc/pwd_grp/pwent.c | 109 | ||||
-rw-r--r-- | libc/pwd_grp/sgetspent.c | 62 | ||||
-rw-r--r-- | libc/pwd_grp/spent.c | 97 |
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> -#incl |