[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#151800: dpkg: bug in start-stop-deamon with chroot and background options



Package: dpkg
Version: 1.10
Severity: normal
File: /sbin/start-stop-daemon
Tags: patch



-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux alibaba 2.4.18 #1 Thu May 23 16:58:14 CEST 2002 i686
Locale: LANG=fr_FR@euro, LC_CTYPE=fr_FR@euro

Versions of packages dpkg depends on:
ii  dselect                       1.10       a user tool to manage Debian packa
ii  libc6                         2.2.5-7    GNU C Library: Shared libraries an

-- no debconf information


Hello

I have a problem when combining --background and --chroot options of
start-stop-daemon. The program I try to start fails immediately. I
looked at the source and discovered why, the background code is done
after the chroot code, and so the openning of /dev/null for stdin,
stdout and stderr fails because the /dev/null is not in the jail. So
instead of forcing people to create de /dev/null in the jail I think it
better to reorder the code. This is what I have done in the attached
patch. I have not check that this patch works in every situation but it
woks for me and it is very light so it should not disturbe many things
except that went background option is used, more potential errors are
hidden.

-- 
Loïc

"heaven is not a place, it's a feeling"
--- start-stop-daemon.c.orig	Sun May 19 09:35:12 2002
+++ start-stop-daemon.c	Wed Jul  3 15:25:52 2002
@@ -107,6 +107,7 @@
 static char *changeuser = NULL;
 static const char *changegroup = NULL;
 static char *changeroot = NULL;
+static char *changedir = NULL;
 static const char *cmdname = NULL;
 static char *execname = NULL;
 static char *startas = NULL;
@@ -1183,20 +1184,6 @@
 	if (quietmode < 0)
 		printf("Starting %s...\n", startas);
 	*--argv = startas;
-	if (changeroot != NULL) {
-		if (chdir(changeroot) < 0)
-			fatal("Unable to chdir() to %s", changeroot);
-		if (chroot(changeroot) < 0)
-			fatal("Unable to chroot() to %s", changeroot);
-	}
-	if (changeuser != NULL) {
- 		if (setgid(runas_gid))
- 			fatal("Unable to set gid to %d", runas_gid);
-		if (initgroups(changeuser, runas_gid))
-			fatal("Unable to set initgroups() with gid %d", runas_gid);
-		if (setuid(runas_uid))
-			fatal("Unable to set uid to %s", changeuser);
-	}
 
 	if (background) { /* ok, we need to detach this process */
 		int i, fd;
@@ -1239,6 +1226,20 @@
 		fd=open("/dev/null", O_RDWR); /* stdin */
 		dup(fd); /* stdout */
 		dup(fd); /* stderr */
+	}
+	if (changeroot != NULL) {
+		if (chdir(changeroot) < 0)
+			fatal("Unable to chdir() to %s", changeroot);
+		if (chroot(changeroot) < 0)
+			fatal("Unable to chroot() to %s", changeroot);
+	}
+	if (changeuser != NULL) {
+ 		if (setgid(runas_gid))
+ 			fatal("Unable to set gid to %d", runas_gid);
+		if (initgroups(changeuser, runas_gid))
+			fatal("Unable to set initgroups() with gid %d", runas_gid);
+		if (setuid(runas_uid))
+			fatal("Unable to set uid to %s", changeuser);
 	}
 	if (nicelevel) {
 		errno=0;

Reply to: