[PATCH] Add --chuid to start-stop-daemon

Thaddeus Ternes tternes at gmail.com
Sat Jul 15 08:51:39 UTC 2006


My apologies in advance... I'm pretty new to C development, and even
newer to Busybox hacking.  But alas, time to start trying to
contribute.

Here's a patch that provides the --chuid functionality described in
the start-stop-daemon man pages to Busybox's applet.  Either username
or uid can be specified following -c|--chuid.

Again, I'm a relatively new to C development, so (constructive)
criticism is greatly appreciated...

-Thaddeus

=======================================

diff -Naur busybox-1.2.0/debianutils/start_stop_daemon.c
busybox-1.2.0-start-stop/debianutils/start_stop_daemon.c
--- busybox-1.2.0/debianutils/start_stop_daemon.c       2006-06-30
17:42:04.000000000 -0500
+++ busybox-1.2.0-start-stop/debianutils/start_stop_daemon.c
2006-07-15 03:10:13.000000000 -0500
@@ -24,6 +24,7 @@
 static int user_id = -1;
 static int quiet;
 static char *userspec = NULL;
+static char *chuid = NULL;
 static char *cmdname = NULL;
 static char *execname = NULL;
 static char *pidfile = NULL;
@@ -211,6 +212,7 @@
        { "name",                       1,              NULL,           'n' },
        { "signal",                     1,              NULL,           's' },
        { "user",                       1,              NULL,           'u' },
+       { "chuid",                      1,              NULL,           'c' },
        { "exec",                       1,              NULL,           'x' },
        { "pidfile",            1,              NULL,           'p' },
 #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
@@ -249,9 +251,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:x:p:"
 //             USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg)
-               ,&startas, &cmdname, &signame, &userspec, &execname, &pidfile);
+               ,&startas, &cmdname, &signame, &userspec, &chuid,
&execname, &pidfile);

        quiet = (opt & SSD_OPT_QUIET)
                        USE_FEATURE_START_STOP_DAEMON_FANCY(&& !(opt &
SSD_OPT_VERBOSE));
@@ -301,6 +303,11 @@
                fprintf(pidf, "%d\n", pidt);
                fclose(pidf);
        }
+       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.0/include/usage.h
busybox-1.2.0-start-stop/include/usage.h
--- busybox-1.2.0/include/usage.h       2006-06-30 17:42:10.000000000 -0500
+++ busybox-1.2.0-start-stop/include/usage.h    2006-07-15
00:48:22.000000000 -0500
@@ -2693,7 +2693,8 @@
        "\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-U|--chuid <username>|<uid>\tstart process with this name"

 #ifdef CONFIG_FEATURE_STAT_FORMAT
 #  define USAGE_STAT_FORMAT(a) a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bb_start-stop-daemon_chuid.patch
Type: application/octet-stream
Size: 2161 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20060715/1b880547/attachment.obj 


More information about the busybox mailing list