[uClibc-cvs] uClibc/libc/pwd_grp fgetpwent.c,1.8,1.9 fgetspent.c,1.4,1.5 getpwnam.c,1.9,1.10 getpwuid.c,1.8,1.9 getspnam.c,1.4,1.5 getspuid.c,1.4,1.5 pwent.c,1.10,1.11 sgetspent.c,1.4,1.5 spent.c,1.4,1.5

Erik Andersen andersen at uclibc.org
Fri Jun 27 10:43:48 UTC 2003


Update of /var/cvs/uClibc/libc/pwd_grp
In directory winder:/tmp/cvs-serv26132

Modified Files:
	fgetpwent.c fgetspent.c getpwnam.c getpwuid.c getspnam.c 
	getspuid.c pwent.c sgetspent.c spent.c 
Log Message:
Yet more cleanup for the reentrant pwd/grp functions so they
should now actually be doing the right thing


Index: fgetpwent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/fgetpwent.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- fgetpwent.c	27 Jun 2003 10:19:28 -0000	1.8
+++ fgetpwent.c	27 Jun 2003 10:43:43 -0000	1.9
@@ -34,12 +34,16 @@
 #endif
 
 int fgetpwent_r (FILE *file, struct passwd *password,
-	char *buff, size_t buflen, struct passwd **crap)
+	char *buff, size_t buflen, struct passwd **result)
 {
+    int res;
     if (file == NULL) {
 	return EINTR;
     }
-    return(__getpwent_r(password, buff, buflen, fileno(file)));
+    *result = NULL;
+    res = __getpwent_r(password, buff, buflen, fileno(file));
+    *result = password;
+    return res;
 }
 
 struct passwd *fgetpwent(FILE * file)
@@ -47,9 +51,10 @@
     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), NULL)) == 0) {
+    if ((ret=fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &pwd;
     }

Index: fgetspent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/fgetspent.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- fgetspent.c	27 Jun 2003 10:19:28 -0000	1.4
+++ fgetspent.c	27 Jun 2003 10:43:43 -0000	1.5
@@ -33,12 +33,16 @@
 #endif
 
 int fgetspent_r (FILE *file, struct spwd *spwd,
-	char *buff, size_t buflen, struct spwd **crap)
+	char *buff, size_t buflen, struct spwd **result)
 {
+    int res;
     if (file == NULL) {
 	return EINTR;
     }
-    return(__getspent_r(spwd, buff, buflen, fileno(file)));
+    *result = NULL;
+    res = __getspent_r(spwd, buff, buflen, fileno(file));
+    *result = spwd;
+    return res;
 }
 
 struct spwd *fgetspent(FILE * file)
@@ -46,9 +50,10 @@
     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), NULL)) == 0) {
+    if ((ret=fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &spwd;
     }

Index: getpwnam.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getpwnam.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- getpwnam.c	27 Jun 2003 10:19:28 -0000	1.9
+++ getpwnam.c	27 Jun 2003 10:43:43 -0000	1.10
@@ -42,6 +42,8 @@
     int ret;
     int passwd_fd;
 
+    *result = NULL;
+
     if (name == NULL) {
 	return EINVAL;
     }
@@ -54,6 +56,7 @@
 	if (!strcmp(password->pw_name, name)) {
 	    *result=password;
 	    close(passwd_fd);
+	    *result = password;
 	    return 0;
 	}
     }
@@ -66,7 +69,8 @@
 {
     int ret;
     static char line_buff[PWD_BUFFER_SIZE];
-    static struct passwd pwd, *result;
+    static struct passwd pwd;
+    struct passwd *result;
 
     LOCK;
     if ((ret=getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), &result)) == 0) {

Index: getpwuid.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getpwuid.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- getpwuid.c	27 Jun 2003 10:19:28 -0000	1.8
+++ getpwuid.c	27 Jun 2003 10:43:43 -0000	1.9
@@ -37,16 +37,18 @@
 #endif      
 
 int getpwuid_r (uid_t uid, struct passwd *password,
-	char *buff, size_t buflen, struct passwd **crap)
+	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;
 	}
 
@@ -60,9 +62,10 @@
     /* file descriptor for the password file currently open */
     static char line_buff[PWD_BUFFER_SIZE];
     static struct passwd pwd;
+    struct passwd *result;
 
     LOCK;
-    if ((ret=getpwuid_r(uid, &pwd, line_buff,  sizeof(line_buff), NULL)) == 0) {
+    if ((ret=getpwuid_r(uid, &pwd, line_buff,  sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &pwd;
     }

Index: getspnam.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getspnam.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- getspnam.c	27 Jun 2003 10:19:28 -0000	1.4
+++ getspnam.c	27 Jun 2003 10:43:43 -0000	1.5
@@ -35,7 +35,7 @@
 #endif      
 
 int getspnam_r (const char *name, struct spwd *spwd,
-	char *buff, size_t buflen, struct spwd **crap)
+	char *buff, size_t buflen, struct spwd **result)
 {
     int spwd_fd;
 
@@ -46,9 +46,11 @@
     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;
 	}
 
@@ -61,9 +63,10 @@
     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), NULL)) == 0) {
+    if ((ret=getspnam_r(name, &spwd, line_buff,  sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &spwd;
     }

Index: getspuid.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/getspuid.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- getspuid.c	27 Jun 2003 10:19:28 -0000	1.4
+++ getspuid.c	27 Jun 2003 10:43:43 -0000	1.5
@@ -41,11 +41,14 @@
     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;
 
-    return getspnam_r(password.pw_name, spwd, buff, buflen, result);
+    ret = getspnam_r(password.pw_name, spwd, buff, buflen, result);
+    *result = spwd;
+    return ret;
 }
 
 struct spwd *getspuid(uid_t uid)
@@ -53,9 +56,10 @@
     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), NULL)) == 0) {
+    if ((ret=getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &spwd;
     }

Index: pwent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/pwent.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- pwent.c	27 Jun 2003 10:19:29 -0000	1.10
+++ pwent.c	27 Jun 2003 10:43:43 -0000	1.11
@@ -65,12 +65,14 @@
 }
 
 int getpwent_r (struct passwd *password, char *buff, 
-	size_t buflen, struct passwd **crap)
+	size_t buflen, struct passwd **result)
 {
     int ret;
     LOCK;
+    *result = NULL;
     if (pw_fd != -1 && (ret=__getpwent_r(password, buff, buflen, pw_fd)) == 0) {
 	UNLOCK;
+	*result = password;
 	return 0;
     }
     UNLOCK;
@@ -83,8 +85,9 @@
     int ret;
     static char line_buff[PWD_BUFFER_SIZE];
     static struct passwd pwd;
+    struct passwd *result;
 
-    if ((ret=getpwent_r(&pwd, line_buff, sizeof(line_buff), NULL)) == 0) {
+    if ((ret=getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) == 0) {
 	return &pwd;
     }
     __set_errno(ret);

Index: sgetspent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/sgetspent.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sgetspent.c	27 Jun 2003 10:19:29 -0000	1.4
+++ sgetspent.c	27 Jun 2003 10:43:43 -0000	1.5
@@ -33,9 +33,13 @@
 #endif      
 
 int sgetspent_r (const char *string, struct spwd *spwd,
-	char *buff, size_t buflen, struct spwd **crap)
+	char *buff, size_t buflen, struct spwd **result)
 {
-    return(__sgetspent_r(string, spwd, buff, buflen));
+    int ret;
+    *result = NULL;
+    ret = __sgetspent_r(string, spwd, buff, buflen);
+    *result = spwd;
+    return ret;
 }
 
 struct spwd *sgetspent(const char *string)
@@ -43,9 +47,10 @@
     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), NULL)) == 0) {
+    if ((ret = sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &spwd;
     }

Index: spent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/spent.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- spent.c	27 Jun 2003 10:19:29 -0000	1.4
+++ spent.c	27 Jun 2003 10:43:43 -0000	1.5
@@ -62,12 +62,14 @@
 }
 
 int getspent_r (struct spwd *spwd, char *buff, 
-	size_t buflen, struct spwd **crap)
+	size_t buflen, struct spwd **result)
 {
     int ret;
     LOCK;
+    *result = NULL;
     if (spwd_fd != -1 && (ret=__getspent_r(spwd, buff, buflen, spwd_fd)) == 0) {
 	UNLOCK;
+	*result = spwd;
 	return 0;
     }
     UNLOCK;
@@ -79,9 +81,10 @@
     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), NULL)) == 0) {
+    if ((ret=getspent_r(&spwd, line_buff, sizeof(line_buff), &result)) == 0) {
 	UNLOCK;
 	return &spwd;
     }



More information about the uClibc-cvs mailing list