changeset 5501:5b2272a0f3c3 draft

privsep: Only log chrooting from the launcher process And the sandbox tech as well. Rework stop_interface so we can reuse an option for marking a process as the launcher.
author Roy Marples <roy@marples.name>
date Wed, 07 Oct 2020 14:37:35 +0100
parents d15a1aae6583
children 7100066d2c7e
files src/dhcpcd.c src/if-options.h src/privsep.c
diffstat 3 files changed, 9 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcpcd.c	Wed Oct 07 14:23:23 2020 +0100
+++ b/src/dhcpcd.c	Wed Oct 07 14:37:35 2020 +0100
@@ -409,7 +409,7 @@
 }
 
 static void
-stop_interface(struct interface *ifp)
+stop_interface(struct interface *ifp, const char *reason)
 {
 	struct dhcpcd_ctx *ctx;
 
@@ -418,10 +418,7 @@
 	ifp->options->options |= DHCPCD_STOPPING;
 
 	dhcpcd_drop(ifp, 1);
-	if (ifp->options->options & DHCPCD_DEPARTED)
-		script_runreason(ifp, "DEPARTED");
-	else
-		script_runreason(ifp, "STOPPED");
+	script_runreason(ifp, reason == NULL ? "STOPPED" : reason);
 
 	/* Delete all timeouts for the interfaces */
 	eloop_q_timeout_delete(ctx->eloop, ELOOP_QUEUE_ALL, NULL, ifp);
@@ -1025,8 +1022,7 @@
 		}
 		if (ifp->active) {
 			logdebugx("%s: interface departed", ifp->name);
-			ifp->options->options |= DHCPCD_DEPARTED;
-			stop_interface(ifp);
+			stop_interface(ifp, "DEPARTED");
 		}
 		TAILQ_REMOVE(ctx->ifaces, ifp, next);
 		if_free(ifp);
@@ -1339,7 +1335,7 @@
 		if (ifp->options->options & DHCPCD_RELEASE)
 			ifp->options->options &= ~DHCPCD_PERSISTENT;
 		ifp->options->options |= DHCPCD_EXITING;
-		stop_interface(ifp);
+		stop_interface(ifp, NULL);
 	}
 }
 
@@ -1591,7 +1587,7 @@
 			ifp->options->options |= opts;
 			if (opts & DHCPCD_RELEASE)
 				ifp->options->options &= ~DHCPCD_PERSISTENT;
-			stop_interface(ifp);
+			stop_interface(ifp, NULL);
 		}
 		return 0;
 	}
@@ -2293,7 +2289,7 @@
 		break;
 	default:
 		setproctitle("[launcher]");
-		ctx.options |= DHCPCD_FORKED;
+		ctx.options |= DHCPCD_FORKED | DHCPCD_LAUNCHER;
 		ctx.fork_fd = fork_fd[0];
 		close(fork_fd[1]);
 #ifdef PRIVSEP_RIGHTS
--- a/src/if-options.h	Wed Oct 07 14:23:23 2020 +0100
+++ b/src/if-options.h	Wed Oct 07 14:37:35 2020 +0100
@@ -99,7 +99,7 @@
 #define DHCPCD_NOALIAS			(1ULL << 39)
 #define DHCPCD_IA_FORCED		(1ULL << 40)
 #define DHCPCD_STOPPING			(1ULL << 41)
-#define DHCPCD_DEPARTED			(1ULL << 42)
+#define DHCPCD_LAUNCHER			(1ULL << 42)
 #define DHCPCD_HOSTNAME_SHORT		(1ULL << 43)
 #define DHCPCD_EXITING			(1ULL << 44)
 #define DHCPCD_WAITIP4			(1ULL << 45)
--- a/src/privsep.c	Wed Oct 07 14:23:23 2020 +0100
+++ b/src/privsep.c	Wed Oct 07 14:37:35 2020 +0100
@@ -116,7 +116,7 @@
 {
 	struct passwd *pw = ctx->ps_user;
 
-	if (!(ctx->options & DHCPCD_FORKED))
+	if (ctx->options & DHCPCD_LAUNCHER)
 		logdebugx("chrooting as %s to %s", pw->pw_name, pw->pw_dir);
 	if (chroot(pw->pw_dir) == -1 &&
 	    (errno != EPERM || ctx->options & DHCPCD_FORKED))
@@ -566,7 +566,7 @@
 		}
 		logerr("%s: %s", __func__, sandbox);
 		return -1;
-	} else if (!forked)
+	} else if (ctx->options & DHCPCD_LAUNCHER)
 		logdebugx("sandbox: %s", sandbox);
 	return 0;
 }