svn commit: trunk/busybox: coreutils include libbb libpwdgrp loginu etc...

aldot at busybox.net aldot at busybox.net
Mon Jul 21 07:41:35 PDT 2008


Author: aldot
Date: 2008-07-21 07:41:33 -0700 (Mon, 21 Jul 2008)
New Revision: 22904

Log:
- first pass to unify/cleanup uid handling (-236b)
  This needs further love, alot of love.. Tito?


Modified:
   trunk/busybox/coreutils/install.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/bb_pwd.c
   trunk/busybox/libpwdgrp/uidgid_get.c
   trunk/busybox/loginutils/passwd.c
   trunk/busybox/loginutils/vlock.c
   trunk/busybox/miscutils/crontab.c
   trunk/busybox/networking/httpd.c
   trunk/busybox/networking/libiproute/libnetlink.c
   trunk/busybox/networking/tcpudp.c
   trunk/busybox/networking/tftp.c
   trunk/busybox/procps/renice.c
   trunk/busybox/runit/chpst.c


Changeset:
Modified: trunk/busybox/coreutils/install.c
===================================================================
--- trunk/busybox/coreutils/install.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/coreutils/install.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -170,7 +170,7 @@
 
 		/* Set the file mode */
 		if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
-			bb_perror_msg("cannot change permissions of %s", dest);
+			bb_perror_msg("can't change %s of %s", "permissions", dest);
 			ret = EXIT_FAILURE;
 		}
 #if ENABLE_SELINUX
@@ -181,7 +181,7 @@
 		if ((flags & (OPT_OWNER|OPT_GROUP))
 		 && lchown(dest, uid, gid) == -1
 		) {
-			bb_perror_msg("cannot change ownership of %s", dest);
+			bb_perror_msg("can't change %s of %s", "ownership", dest);
 			ret = EXIT_FAILURE;
 		}
 		if (flags & OPT_STRIP) {

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/include/libbb.h	2008-07-21 14:41:33 UTC (rev 22904)
@@ -691,6 +691,8 @@
 };
 /* always sets uid and gid */
 int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC;
+/* always sets uid and gid, allows numeric; exits on failure */
+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;
 /* bb_getpwuid, bb_getgrgid:

Modified: trunk/busybox/libbb/bb_pwd.c
===================================================================
--- trunk/busybox/libbb/bb_pwd.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/libbb/bb_pwd.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -82,7 +82,7 @@
 
 	myuser = getpwnam(name);
 	if (myuser == NULL)
-		bb_error_msg_and_die("unknown user name: %s", name);
+		bb_error_msg_and_die("unknown user %s", name);
 
 	return myuser->pw_uid;
 }

Modified: trunk/busybox/libpwdgrp/uidgid_get.c
===================================================================
--- trunk/busybox/libpwdgrp/uidgid_get.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/libpwdgrp/uidgid_get.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -76,6 +76,11 @@
 	}
 	return 1;
 }
+void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug)
+{
+    if (!get_uidgid(u, ug, 1))
+	bb_error_msg_and_die("unknown user/group %s", ug);
+}
 
 /* chown-like:
  * "user" sets uid only,
@@ -106,8 +111,7 @@
 	} else {
 		if (!group[1]) /* "user:" */
 			*group = '\0';
-		if (!get_uidgid(u, user_group, 1))
-			bb_error_msg_and_die("unknown user/group %s", user_group);
+		xget_uidgid(u, user_group);
 	}
 }
 

Modified: trunk/busybox/loginutils/passwd.c
===================================================================
--- trunk/busybox/loginutils/passwd.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/loginutils/passwd.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -27,7 +27,7 @@
 			goto err_ret;
 		encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */
 		if (strcmp(encrypted, pw->pw_passwd) != 0) {
-			syslog(LOG_WARNING, "incorrect password for '%s'",
+			syslog(LOG_WARNING, "incorrect password for %s",
 				pw->pw_name);
 			bb_do_delay(FAIL_DELAY);
 			puts("Incorrect password");
@@ -119,7 +119,8 @@
 	name = argv[0] ? argv[0] : myname;
 
 	pw = getpwnam(name);
-	if (!pw) bb_error_msg_and_die("unknown user %s", name);
+	if (!pw)
+		bb_error_msg_and_die("unknown user %s", 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/vlock.c
===================================================================
--- trunk/busybox/loginutils/vlock.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/loginutils/vlock.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -40,7 +40,7 @@
 	struct vt_mode ovtm;
 	uid_t uid;
 	struct passwd *pw;
-
+/* XXX: xgetpwuid */
 	uid = getuid();
 	pw = getpwuid(uid);
 	if (pw == NULL)

Modified: trunk/busybox/miscutils/crontab.c
===================================================================
--- trunk/busybox/miscutils/crontab.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/miscutils/crontab.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -129,11 +129,11 @@
 		if (!pas)
 			bb_error_msg_and_die("user %s is not known", user_name);
 	} else {
+/* XXX: xgetpwuid */
 		uid_t my_uid = getuid();
 		pas = getpwuid(my_uid);
 		if (!pas)
-			bb_perror_msg_and_die("no user record for UID %u",
-					(unsigned)my_uid);
+			bb_perror_msg_and_die("unknown uid %d", (int)my_uid);
 	}
 
 #define user_name DONT_USE_ME_BEYOND_THIS_POINT

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/networking/httpd.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -2351,9 +2351,7 @@
 #endif
 #if ENABLE_FEATURE_HTTPD_SETUID
 	if (opt & OPT_SETUID) {
-		if (!get_uidgid(&ugid, s_ugid, 1))
-			bb_error_msg_and_die("unknown user[:group] "
-						"name '%s'", s_ugid);
+		xget_uidgid(&ugid, s_ugid);
 	}
 #endif
 

Modified: trunk/busybox/networking/libiproute/libnetlink.c
===================================================================
--- trunk/busybox/networking/libiproute/libnetlink.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/networking/libiproute/libnetlink.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -37,7 +37,7 @@
 	xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local));
 	addr_len = sizeof(rth->local);
 	if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0)
-		bb_perror_msg_and_die("cannot getsockname");
+		bb_perror_msg_and_die("getsockname");
 	if (addr_len != sizeof(rth->local))
 		bb_error_msg_and_die("wrong address length %d", addr_len);
 	if (rth->local.nl_family != AF_NETLINK)

Modified: trunk/busybox/networking/tcpudp.c
===================================================================
--- trunk/busybox/networking/tcpudp.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/networking/tcpudp.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -216,8 +216,7 @@
 	if (max_per_host > cmax)
 		max_per_host = cmax;
 	if (option_mask32 & OPT_u) {
-		if (!get_uidgid(&ugid, user, 1))
-			bb_error_msg_and_die("unknown user/group: %s", user);
+		xget_uidgid(&ugid, user);
 	}
 #ifdef SSLSVD
 	if (option_mask32 & OPT_U) ssluser = optarg;
@@ -245,9 +244,9 @@
 	if (option_mask32 & OPT_u)
 		if (!uidgid_get(&sslugid, ssluser, 1)) {
 			if (errno) {
-				bb_perror_msg_and_die("fatal: cannot get user/group: %s", ssluser);
+				bb_perror_msg_and_die("can't get user/group: %s", ssluser);
 			}
-			bb_error_msg_and_die("unknown user/group '%s'", ssluser);
+			bb_error_msg_and_die("unknown user/group %s", ssluser);
 		}
 	if (!cert) cert = "./cert.pem";
 	if (!key) key = cert;

Modified: trunk/busybox/networking/tftp.c
===================================================================
--- trunk/busybox/networking/tftp.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/networking/tftp.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -225,7 +225,7 @@
 		if (user_opt) {
 			struct passwd *pw = getpwnam(user_opt);
 			if (!pw)
-				bb_error_msg_and_die("unknown user '%s'", user_opt);
+				bb_error_msg_and_die("unknown user %s", user_opt);
 			change_identity(pw); /* initgroups, setgid, setuid */
 		}
 	}

Modified: trunk/busybox/procps/renice.c
===================================================================
--- trunk/busybox/procps/renice.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/procps/renice.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -84,7 +84,7 @@
 			struct passwd *p;
 			p = getpwnam(arg);
 			if (!p) {
-				bb_error_msg("unknown user: %s", arg);
+				bb_error_msg("unknown user %s", arg);
 				goto HAD_ERROR;
 			}
 			who = p->pw_uid;

Modified: trunk/busybox/runit/chpst.c
===================================================================
--- trunk/busybox/runit/chpst.c	2008-07-21 13:46:54 UTC (rev 22903)
+++ trunk/busybox/runit/chpst.c	2008-07-21 14:41:33 UTC (rev 22904)
@@ -81,9 +81,7 @@
 {
 	struct bb_uidgid_t ugid;
 
-	if (!get_uidgid(&ugid, user, 1)) {
-		bb_error_msg_and_die("unknown user/group: %s", user);
-	}
+	xget_uidgid(&ugid, user);
 	if (setgroups(1, &ugid.gid) == -1)
 		bb_perror_msg_and_die("setgroups");
 	xsetgid(ugid.gid);
@@ -94,9 +92,7 @@
 {
 	struct bb_uidgid_t ugid;
 
-	if (!get_uidgid(&ugid, user, 1)) {
-		bb_error_msg_and_die("unknown user/group: %s", user);
-	}
+	xget_uidgid(&ugid, user);
 	xsetenv("GID", utoa(ugid.gid));
 	xsetenv("UID", utoa(ugid.uid));
 }



More information about the busybox-cvs mailing list