]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Verifying that named switches UID
authorMichal Nowak <mnowak@isc.org>
Wed, 20 Nov 2019 11:01:05 +0000 (11:01 +0000)
committerMichal Nowak <mnowak@isc.org>
Wed, 20 Nov 2019 11:01:05 +0000 (11:01 +0000)
This test runs only under root, which is required for the user-switch
`-u` option to work.

Closes #537.

(cherry picked from commit b00360537eae440f03ee47e9779ceeecd491dba7)

bin/tests/system/conf.sh.common
bin/tests/system/conf.sh.in
bin/tests/system/runtime/clean.sh
bin/tests/system/runtime/ns2/named-alt9.conf.in [new file with mode: 0644]
bin/tests/system/runtime/tests.sh

index e06a11e30244b347ea2c40148b11eceaa11bb5fe..41daad51c6c6ea67258a4ede6efbf5ed94e5649a 100644 (file)
@@ -526,5 +526,6 @@ export RRCHECKER
 export SAMPLEUPDATE
 export SIGNER
 export SUBDIRS
+export TMPDIR
 export TSIGKEYGEN
 export WIRETEST
index c713d965d1ae0e99932a04ad94858a12fed6e94f..a4dceb1d3c7954935a60425fc87d97368dc6a136 100644 (file)
@@ -17,6 +17,9 @@
 # Find the top of the BIND9 tree.
 TOP=@abs_top_builddir@
 
+# Provide TMPDIR variable for tests that need it.
+TMPDIR=${TMPDIR:-/tmp}
+
 # This is not the windows build.
 CYGWIN=""
 
index 1be52649b00e5562a11337363e6d733a219b36a6..4a756b3d381a5c53d82aee99b4be90413807878c 100644 (file)
@@ -17,4 +17,5 @@ rm -f *.pid
 rm -f rndc.out*
 [ -d ns2/nope ] && chmod 755 ns2/nope
 rm -rf ns2/nope
+rm -rf ns2/tmp.*
 rm -f ns*/managed-keys.bind*
diff --git a/bin/tests/system/runtime/ns2/named-alt9.conf.in b/bin/tests/system/runtime/ns2/named-alt9.conf.in
new file mode 100644 (file)
index 0000000..7a5cb24
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+options {
+       port @PORT@;
+       pid-file "named9.pid";
+       listen-on { 127.0.0.1; };
+       listen-on-v6 { none; };
+       recursion no;
+};
index 343adebc6b1bed51bb4ff03d9a5960736dc12c99..87d83f496d4d79c7faca1ae6026672266d01b63d 100644 (file)
@@ -1,3 +1,5 @@
+#!/bin/sh
+#
 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
@@ -113,5 +115,31 @@ cd ..
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
+n=`expr $n + 1`
+echo_i "verifying that named switches UID ($n)"
+if [ "`id -u`" = 0 ] && [ ! "$CYGWIN" ]; then
+    ret=0
+    TEMP_NAMED_DIR=`mktemp -d`
+    if [ -d "${TEMP_NAMED_DIR}" ]; then
+        copy_setports ns2/named-alt9.conf.in "${TEMP_NAMED_DIR}/named-alt9.conf"
+        chown -R nobody "${TEMP_NAMED_DIR}"
+        chmod 0700 "${TEMP_NAMED_DIR}"
+        ( cd "${TEMP_NAMED_DIR}" && $NAMED -u nobody -c named-alt9.conf -d 99 -g -U 4 >> named9.run 2>&1 & )
+        sleep 2
+        [ -s "${TEMP_NAMED_DIR}/named9.pid" ] || ret=1
+        grep "loading configuration: permission denied" "${TEMP_NAMED_DIR}/named9.run" > /dev/null && ret=1
+        pid=`cat "${TEMP_NAMED_DIR}/named9.pid" 2>/dev/null`
+        test "${pid:+set}" = set && $KILL -15 "${pid}" >/dev/null 2>&1
+        mv "${TEMP_NAMED_DIR}" ns2/
+    else
+        echo_i "mktemp failed"
+        ret=1
+    fi
+    if [ $ret != 0 ]; then echo_i "failed"; fi
+    status=`expr $status + $ret`
+else
+    echo_i "skipped, not running as root or running on Windows"
+fi
+
 echo_i "exit status: $status"
 [ $status -eq 0 ] || exit 1