From 791312e7259153e1235f14a9a9e5cc6055ce8dfc Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 8 Mar 2001 16:45:24 +0000 Subject: Reworked the password stuff to be reentrant. Group stuff is still needing to be reworked. -Erik --- libc/pwd_grp/getpwuid.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'libc/pwd_grp/getpwuid.c') diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c index 1cd0d691c..307f840e1 100644 --- a/libc/pwd_grp/getpwuid.c +++ b/libc/pwd_grp/getpwuid.c @@ -23,20 +23,36 @@ #include #include -struct passwd *getpwuid(uid_t uid) + +#define PWD_BUFFER_SIZE 256 + +/* file descriptor for the password file currently open */ +static char line_buff[PWD_BUFFER_SIZE]; +static struct passwd pwd; + +int getpwuid_r (uid_t uid, struct passwd *password, + char *buff, size_t buflen, struct passwd **crap) { int passwd_fd; - struct passwd *passwd; if ((passwd_fd = open("/etc/passwd", O_RDONLY)) < 0) - return NULL; + return -1; - while ((passwd = __getpwent(passwd_fd)) != NULL) - if (passwd->pw_uid == uid) { + while (__getpwent_r(password, buff, buflen, passwd_fd) != -1) + if (password->pw_uid == uid) { close(passwd_fd); - return passwd; + return 0; } close(passwd_fd); - return NULL; + return -1; } + +struct passwd *getpwuid(uid_t uid) +{ + if (getpwuid_r(uid, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { + return &pwd; + } + return NULL; +} + -- cgit v1.2.3