[git commit] adduser: prefer to call addgroup --gid, not non-std addgroup -g

Denys Vlasenko vda.linux at googlemail.com
Sat May 21 17:57:58 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=569e930768922812ce5169a3058b65fff9196308
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 loginutils/adduser.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index a05b721..0e06ab2 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -67,6 +67,7 @@ static void passwd_study(struct passwd *p)
 		}
 		if (p->pw_uid == max) {
 			bb_error_msg_and_die("no %cids left", 'u');
+			/* this format string is reused in adduser and addgroup */
 		}
 		p->pw_uid++;
 	}
@@ -92,9 +93,16 @@ static void addgroup_wrapper(struct passwd *p, const char *group_name)
 		argv[3] = (char*)group_name;
 		argv[4] = NULL;
 	} else {
-		/* Add user to his own group with the first free gid found in passwd_study */
-//TODO: to be compatible with external addgroup programs we should use --gid instead...
+		/* Add user to his own group with the first free gid
+		 * found in passwd_study.
+		 * We try to use --gid, not -g, because "standard" addgroup
+		 * has no such short option, it has only long --gid.
+		 */
+#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS
+		argv[1] = (char*)"--gid";
+#else
 		argv[1] = (char*)"-g";
+#endif
 		argv[2] = utoa(p->pw_gid);
 		argv[3] = (char*)"--";
 		argv[4] = p->pw_name;
@@ -230,9 +238,11 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
 		if (mkdir_err == 0) {
 			/* New home. Copy /etc/skel to it */
 			const char *args[] = {
-				"chown", "-R",
+				"chown",
+				"-R",
 				xasprintf("%u:%u", (int)pw.pw_uid, (int)pw.pw_gid),
-				pw.pw_dir, NULL
+				pw.pw_dir,
+				NULL
 			};
 			/* Be silent on any errors (like: no /etc/skel) */
 			logmode = LOGMODE_NONE;
-- 
1.7.3.4



More information about the busybox-cvs mailing list