[PATCH] start-stop-daemon cannot set gid

Thaddeus Ternes tternes at gmail.com
Mon Feb 26 05:51:23 PST 2007


On 2006/7/16, I posted a patch that added chuid support to
start-stop-daemon.  See this thread for the original patch:

http://busybox.net/lists/busybox/2006-July/023212.html

I'm including a modification of that patch to add chgid support as
well.  The syntax is a bit different the previous proposed patch on
this thread, but it may be of interest to some.

I have to note that I haven't tried this against recent builds of
Busybox.  The project I'm working on is locked at 1.2.2.1 right now,
so I patch against that.  This patch will likely not work against
current SVN, but could obviously be coaxed to fit in with a little
love.

Hopefully it's of use to somebody still using older builds.

-Thaddeus

diff -Naur busybox-1.2.2.1.clean/debianutils/start_stop_daemon.c
busybox-1.2.2.1/debianutils/start_stop_daemon.c
--- busybox-1.2.2.1.clean/debianutils/start_stop_daemon.c	2006-06-30
17:42:04.000000000 -0500
+++ busybox-1.2.2.1/debianutils/start_stop_daemon.c	2007-02-06
11:10:38.000000000 -0600
@@ -22,8 +22,11 @@

 static int signal_nr = 15;
 static int user_id = -1;
+static int group_id = -1;
 static int quiet;
 static char *userspec = NULL;
+static char *chuid = NULL;
+static char *chgid = NULL;
 static char *cmdname = NULL;
 static char *execname = NULL;
 static char *pidfile = NULL;
@@ -211,6 +214,8 @@
 	{ "name",			1,		NULL,		'n' },
 	{ "signal",			1,		NULL,		's' },
 	{ "user",			1,		NULL,		'u' },
+	{ "chuid", 			1,		NULL,		'c' },
+	{ "chgid", 			1,		NULL,		'g' },
 	{ "exec",			1,		NULL,		'x' },
 	{ "pidfile",		1,		NULL,		'p' },
 #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
@@ -249,9 +254,9 @@
 	opt = bb_getopt_ulflags(argc, argv, "KSbqm"
 //		USE_FEATURE_START_STOP_DAEMON_FANCY("ovR:")
 		USE_FEATURE_START_STOP_DAEMON_FANCY("ov")
-		"a:n:s:u:x:p:"
+		"a:n:s:u:c:g:x:p:"
 //		USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg)
-		,&startas, &cmdname, &signame, &userspec, &execname, &pidfile);
+		,&startas, &cmdname, &signame, &userspec, &chuid, &chgid,
&execname, &pidfile);

 	quiet = (opt & SSD_OPT_QUIET)
 			USE_FEATURE_START_STOP_DAEMON_FANCY(&& !(opt & SSD_OPT_VERBOSE));
@@ -301,6 +306,17 @@
 		fprintf(pidf, "%d\n", pidt);
 		fclose(pidf);
 	}
+	if(chgid) {
+		if(sscanf(chgid, "%d", &group_id) != 1)
+			group_id = bb_xgetgrnam(chgid);
+		setgid(group_id);
+	}
+	if(chuid) {
+		if(sscanf(chuid, "%d", &user_id) != 1)
+			user_id = bb_xgetpwnam(chuid);
+		setuid(user_id);
+	}
+
 	execv(startas, argv);
 	bb_perror_msg_and_die ("unable to start %s", startas);
 }
diff -Naur busybox-1.2.2.1.clean/include/usage.h busybox-1.2.2.1/include/usage.h
--- busybox-1.2.2.1.clean/include/usage.h	2006-06-30 17:42:10.000000000 -0500
+++ busybox-1.2.2.1/include/usage.h	2007-02-06 11:10:45.000000000 -0600
@@ -2693,7 +2693,9 @@
 	"\n\t-o|--oknodo\t\t\texit status 0 if nothing done" \
 	"\n\t-v|--verbose\t\t\tbe verbose" \
 ) \
-	"\n\t-s|--signal <signal>\t\tsignal to send (default TERM)"
+	"\n\t-s|--signal <signal>\t\tsignal to send (default TERM)" \
+	"\n\t-g|--chgid <group>|<gid>\tstart process with this group" \
+	"\n\t-c|--chuid <username>|<uid>\tstart process with this name"

 #ifdef CONFIG_FEATURE_STAT_FORMAT
 #  define USAGE_STAT_FORMAT(a) a


On 2/25/07, Denis Vlasenko <vda.linux at googlemail.com> wrote:
> On Sunday 25 February 2007 16:17, Natanael Copa wrote:
> > The attatched patch adds support for group with the --chuid.
> >
> >   start-stop-daemon --chuid user:group
> >
> > Patch is against 1.4.1.
>
> Thanks. I see that we do something similar in chown.
> I want to make this code common.
>
> Please try attached patch which does that.
>
> > btw... the usage message is wrong:
> >
> >   -U|--chuid <username>|<uid>     Start process with this name
> >
> > its -c and not -U for --chuid short opt.
>
> Corrected, along with description.
> --
> vda
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://busybox.net/cgi-bin/mailman/listinfo/busybox
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: busybox_start-stop-daemon_chuid_chgid.patch
Type: application/octet-stream
Size: 2474 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20070226/b0f91bc4/attachment.obj 


More information about the busybox mailing list