svn commit: trunk/busybox: coreutils include libbb loginutils miscu etc...

vda at busybox.net vda at busybox.net
Wed Dec 3 19:05:55 UTC 2008


Author: vda
Date: 2008-12-03 11:05:55 -0800 (Wed, 03 Dec 2008)
New Revision: 24249

Log:
libbb: introduce and use xgetpwnam. ~ -150 bytes.



Modified:
   trunk/busybox/coreutils/id.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/bb_pwd.c
   trunk/busybox/loginutils/addgroup.c
   trunk/busybox/loginutils/passwd.c
   trunk/busybox/loginutils/su.c
   trunk/busybox/miscutils/crontab.c
   trunk/busybox/networking/tftp.c


Changeset:
Modified: trunk/busybox/coreutils/id.c
===================================================================
--- trunk/busybox/coreutils/id.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/coreutils/id.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -124,9 +124,7 @@
 
 	username = argv[optind];
 	if (username) {
-		struct passwd *p = getpwnam(username);
-		if (!p)
-			bb_error_msg_and_die("unknown user %s", username);
+		struct passwd *p = xgetpwnam(username);
 		euid = ruid = p->pw_uid;
 		egid = rgid = p->pw_gid;
 	} else {

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/include/libbb.h	2008-12-03 19:05:55 UTC (rev 24249)
@@ -702,6 +702,7 @@
 void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
 /* chown-like handling of "user[:[group]" */
 void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC;
+struct passwd* xgetpwnam(const char *name) FAST_FUNC;
 struct passwd* xgetpwuid(uid_t uid) FAST_FUNC;
 struct group* xgetgrgid(gid_t gid) FAST_FUNC;
 char* xuid2uname(uid_t uid) FAST_FUNC;

Modified: trunk/busybox/libbb/bb_pwd.c
===================================================================
--- trunk/busybox/libbb/bb_pwd.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/libbb/bb_pwd.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -15,8 +15,16 @@
  * pointers to static data (getpwuid)
  */
 
-/* TODO: add xgetpwnam, this construct is used a lot */
+struct passwd* FAST_FUNC xgetpwnam(const char *name)
+{
+	struct passwd *pw = getpwnam(name);
+	if (!pw)
+		bb_error_msg_and_die("unknown user %s", name);
+	return pw;
+}
 
+/* xgetgrnam too? */
+
 struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
 {
 	struct passwd *pw = getpwuid(uid);
@@ -73,10 +81,7 @@
 {
 	struct passwd *myuser;
 
-	myuser = getpwnam(name);
-	if (myuser == NULL)
-		bb_error_msg_and_die("unknown user %s", name);
-
+	myuser = xgetpwnam(name);
 	return myuser->pw_uid;
 }
 

Modified: trunk/busybox/loginutils/addgroup.c
===================================================================
--- trunk/busybox/loginutils/addgroup.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/loginutils/addgroup.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -159,6 +159,7 @@
 		/* check if group and user exist */
 		xuname2uid(argv[0]); /* unknown user: exit */
 		xgroup2gid(argv[1]); /* unknown group: exit */
+// race here!
 		/* check if user is already in this group */
 		gr = getgrnam(argv[1]);
 		for (; *(gr->gr_mem) != NULL; (gr->gr_mem)++) {

Modified: trunk/busybox/loginutils/passwd.c
===================================================================
--- trunk/busybox/loginutils/passwd.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/loginutils/passwd.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -118,9 +118,7 @@
 	myname = xstrdup(xuid2uname(myuid));
 	name = argv[0] ? argv[0] : myname;
 
-	pw = getpwnam(name);
-	if (!pw)
-		bb_error_msg_and_die("unknown user %s", name);
+	pw = xgetpwnam(name);
 	if (myuid && pw->pw_uid != myuid) {
 		/* LOGMODE_BOTH */
 		bb_error_msg_and_die("%s can't change password for %s", myname, name);

Modified: trunk/busybox/loginutils/su.c
===================================================================
--- trunk/busybox/loginutils/su.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/loginutils/su.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -48,9 +48,7 @@
 		openlog(applet_name, 0, LOG_AUTH);
 	}
 
-	pw = getpwnam(opt_username);
-	if (!pw)
-		bb_error_msg_and_die("unknown id: %s", opt_username);
+	pw = xgetpwnam(opt_username);
 
 	/* Make sure pw->pw_shell is non-NULL.  It may be NULL when NEW_USER
 	   is a username that is retrieved via NIS (YP), but that doesn't have

Modified: trunk/busybox/miscutils/crontab.c
===================================================================
--- trunk/busybox/miscutils/crontab.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/miscutils/crontab.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -126,9 +126,7 @@
 	}
 
 	if (opt_ler & OPT_u) {
-		pas = getpwnam(user_name);
-		if (!pas)
-			bb_error_msg_and_die("user %s is not known", user_name);
+		pas = xgetpwnam(user_name);
 	} else {
 		pas = xgetpwuid(getuid());
 	}

Modified: trunk/busybox/networking/tftp.c
===================================================================
--- trunk/busybox/networking/tftp.c	2008-12-03 18:49:44 UTC (rev 24248)
+++ trunk/busybox/networking/tftp.c	2008-12-03 19:05:55 UTC (rev 24249)
@@ -223,9 +223,7 @@
 		}
 
 		if (user_opt) {
-			struct passwd *pw = getpwnam(user_opt);
-			if (!pw)
-				bb_error_msg_and_die("unknown user %s", user_opt);
+			struct passwd *pw = xgetpwnam(user_opt);
 			change_identity(pw); /* initgroups, setgid, setuid */
 		}
 	}




More information about the busybox-cvs mailing list