From c2769647244b766cdfe574a70bd7d90f9b45b053 Mon Sep 17 00:00:00 2001
From: Mike Hibler <hibler@cs.utah.edu>
Date: Mon, 18 May 2020 14:21:15 -0600
Subject: [PATCH] Forgot the basic setuid necessities.

---
 wbstore/createwbstore.in  | 27 +++++++++++++++++----------
 wbstore/destroywbstore.in | 10 ++++++++--
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/wbstore/createwbstore.in b/wbstore/createwbstore.in
index 8f671ec8e0..f01de20386 100644
--- a/wbstore/createwbstore.in
+++ b/wbstore/createwbstore.in
@@ -486,7 +486,10 @@ sub distribconfigs()
 
 	    my $host =
 		($domain eq "emulab.net" ? "users" : "boss") . ".$domain";
+	    my $SAVEUID = $UID;
+	    $UID = 0;
 	    $rv = system("scp $SSH_ARGS $tarball $host:$TARGETDIR/");
+	    $UID = $SAVEUID;
 	    if ($rv) {
 		$rv >>= 8;
 		if ($rv == 255) {
@@ -499,17 +502,21 @@ sub distribconfigs()
 		next;
 	    }
 
-	    if ($install &&
-		($rv = system("ssh $SSH_ARGS $host $installbin -f $instance"))) {
-		$rv >>= 8;
-		if ($rv == 255) {
-		    print STDERR "$instance: could not connect to $host, ".
-			"trying again later.\n";
-		} else {
-		    print STDERR "$instance: install of tarball on $host failed ".
-			"(stat=$rv), trying again later.\n";
+	    if ($install) {
+		$UID = 0;
+		$rv = system("ssh $SSH_ARGS $host $installbin -f $instance");
+		$UID = $SAVEUID;
+		if ($rv) {
+		    $rv >>= 8;
+		    if ($rv == 255) {
+			print STDERR "$instance: could not connect to $host, ".
+			    "trying again later.\n";
+		    } else {
+			print STDERR "$instance: install of tarball on $host failed ".
+			    "(stat=$rv), trying again later.\n";
+		    }
+		    next;
 		}
-		next;
 	    }
 
 	    print STDERR "$instance: $domain done.\n"
diff --git a/wbstore/destroywbstore.in b/wbstore/destroywbstore.in
index e04d3471ca..66c4e40c22 100644
--- a/wbstore/destroywbstore.in
+++ b/wbstore/destroywbstore.in
@@ -172,7 +172,9 @@ if (-e "$pidfile") {
 	print STDERR "$exptuuid: killing background installer ($bgpid)\n"
 	    if ($debug);
 	chomp($bgpid);
-	kill('TERM', $bgpid);
+	if ($bgpid =~ /^(\d+)$/) {
+	    kill('TERM', $1);
+	}
     }
     unlink($pidfile);
 }
@@ -214,7 +216,11 @@ foreach my $h ($SERVER, @fqdns) {
 	if ($debug);
 
     my $target = "$CONFDIR/$uuid/$domain/status";
-    if (system("ssh $SSH_ARGS $h 'echo $state > $target'")) {
+    my $SAVEUID = $UID;
+    $UID = 0;
+    my $rv = system("ssh $SSH_ARGS $h 'echo $state > $target'");
+    $UID = $SAVEUID;
+    if ($rv) {
 	my $stat = ($? >> 8);
 	print STDERR "$uuid: WARNING: setting state=$state at $h failed ($stat)\n";
     } else {
-- 
GitLab