[BusyBox-cvs] CVS busybox/libbb

CVS User bug1 bug1 at codepoet.org
Wed Sep 15 03:04:09 UTC 2004


Update of /var/cvs/busybox/libbb
In directory nail:/tmp/cvs-serv5025/libbb

Modified Files:
	Makefile.in my_getgrgid.c my_getpwuid.c 
Added Files:
	my_getug.c 
Log Message:
Tito writes,
"This patch fixes all the bugs in id previously spotted by vodz and me.
The binary size increased a bit,  but now it should work as expected."


--- /var/cvs/busybox/libbb/Makefile.in	2004/09/02 22:21:40	1.37
+++ /var/cvs/busybox/libbb/Makefile.in	2004/09/15 03:04:08	1.38
@@ -34,7 +34,7 @@
 	human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \
 	kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \
 	make_directory.c mode_string.c module_syscalls.c mtab.c mtab_file.c \
-	my_getgrgid.c my_getgrnam.c my_getpwnam.c \
+	my_getgrgid.c my_getgrnam.c my_getpwnam.c my_getug.c\
 	my_getpwuid.c obscure.c parse_mode.c parse_number.c perror_msg.c \
 	perror_msg_and_die.c print_file.c get_console.c \
 	process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c qmodule.c \
--- /var/cvs/busybox/libbb/my_getgrgid.c	2004/09/02 22:21:40	1.9
+++ /var/cvs/busybox/libbb/my_getgrgid.c	2004/09/15 03:04:08	1.10
@@ -22,48 +22,28 @@
   /* Hacked by Tito Ragusa (c) 2004 <farmatito at tiscali.it> to make it more
   * flexible :
   *
-  * if bufsize is > 0 char *group cannot be set to NULL
-  *                   on success groupname is written on static allocated buffer
-  *                   on failure gid as string is written to buffer and NULL is returned
-  * if bufsize is = 0 char *group can be set to NULL
-  *                   on success groupname is returned 
-  *                   on failure NULL is returned
-  * if bufsize is < 0 char *group can be set to NULL
-  *                   on success groupname is returned
-  *                   on failure an error message is printed and the program exits   
+  * if bufsize is > 0 char *group cannot be set to NULL.
+  *                   On success groupname is written on static allocated buffer group
+  *                   (and a pointer to it is returned).
+  *                   On failure gid as string is written to static allocated buffer 
+  *                   group and NULL is returned.
+  * if bufsize is = 0 char *group can be set to NULL.
+  *                   On success groupname is returned. 
+  *                   On failure NULL is returned.
+  * if bufsize is < 0 char *group can be set to NULL.
+  *                   On success groupname is returned.
+  *                   On failure an error message is printed and the program exits.   
   */
   
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
 #include "libbb.h"
-#include "pwd_.h"
 #include "grp_.h"
 
-
 /* gets a groupname given a gid */
 char * my_getgrgid(char *group, long gid, int bufsize)
 {
-	struct group *mygroup;
+	struct group *mygroup = getgrgid(gid);
 
-	mygroup  = getgrgid(gid);
-	if (mygroup==NULL) {
-		if(bufsize > 0) {
-			assert(group != NULL);
-			snprintf(group, bufsize, "%ld", (long)gid);
-		}
-		if( bufsize < 0 ) {
-			bb_error_msg_and_die("unknown gid %ld", (long)gid);
-		} 
-		return NULL;
-	} else {
-		if(bufsize > 0)
-		{
-			assert(group != NULL);
-			return safe_strncpy(group, mygroup->gr_name, bufsize);
-		}
-		return mygroup->gr_name;
-	}
+	return  my_getug(group, (mygroup) ? mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g');
 }
 
 
--- /var/cvs/busybox/libbb/my_getpwuid.c	2004/09/02 22:21:40	1.9
+++ /var/cvs/busybox/libbb/my_getpwuid.c	2004/09/15 03:04:08	1.10
@@ -22,49 +22,28 @@
  /* Hacked by Tito Ragusa (c) 2004 <farmatito at tiscali.it> to make it more
   * flexible :
   *
-  * if bufsize is > 0 char *user can not be set to NULL
-  *                   on success username is written on static allocated buffer
-  *                   on failure uid as string is written to buffer and NULL is returned
-  * if bufsize is = 0 char *user can be set to NULL
-  *                   on success username is returned 
-  *                   on failure NULL is returned
+  * if bufsize is > 0 char *user can not be set to NULL.
+  *                   On success username is written on static allocated buffer name 
+  *                   (and a pointer to it is returned).
+  *                   On failure uid as string is written to static allocated buffer name
+  *                   and NULL is returned.
+  * if bufsize is = 0 char *user can be set to NULL.
+  *                   On success username is returned. 
+  *                   On failure NULL is returned.
   * if bufsize is < 0 char *user can be set to NULL
-  *                   on success username is returned
-  *                   on failure an error message is printed and the program exits   
+  *                   On success username is returned.
+  *                   On failure an error message is printed and the program exits.   
   */
   
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
 #include "libbb.h"
 #include "pwd_.h"
-#include "grp_.h"
-
-
 
 /* gets a username given a uid */
 char * my_getpwuid(char *name, long uid, int bufsize)
 {
-	struct passwd *myuser;
+	struct passwd *myuser = getpwuid(uid);
 
-	myuser  = getpwuid(uid);
-	if (myuser==NULL) {
-		if(bufsize > 0) {
-			assert(name != NULL);
-			snprintf(name, bufsize, "%ld", (long)uid);
-		}
-		if (bufsize < 0 ) {
-			bb_error_msg_and_die("unknown uid %ld", (long)uid); 
-		}
-		return NULL;
-	} else {
-		if(bufsize > 0 )
-		{
-			assert(name != NULL);
-			return safe_strncpy(name, myuser->pw_name, bufsize);
-		}
-		return myuser->pw_name;
-	}
+	return  my_getug(name, (myuser) ? myuser->pw_name : (char *)myuser , uid, bufsize, 'u');
 }
 
 /* END CODE */



More information about the busybox-cvs mailing list