]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Verifying that named switches UID
authorMichal Nowak <mnowak@isc.org>
Wed, 27 Nov 2019 11:52:08 +0000 (11:52 +0000)
committerOndřej Surý <ondrej@isc.org>
Wed, 27 Nov 2019 11:52:08 +0000 (11:52 +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.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
util/copyrights

index 60c8f68edfd5544680b345066f38a3d07a501a9a..6d196b209edce336f7487817e2ff40bb389cb437 100644 (file)
@@ -22,6 +22,9 @@ DEFAULT_ALGORITHM=RSASHA256
 DEFAULT_ALGORITHM_NUMBER=8
 DEFAULT_BITS=1280
 
+# Provide TMPDIR variable for tests that need it.
+TMPDIR=${TMPDIR:-/tmp}
+
 # must be different from DEFAULT_ALGORITHM
 ALTERNATIVE_ALGORITHM=RSASHA1
 ALTERNATIVE_ALGORITHM_NUMBER=5
@@ -508,3 +511,4 @@ export RRCHECKER
 export SAMPLEUPDATE
 export SIGNER
 export SUBDIRS
+export TMPDIR
index e98d0f3c0380653cf58d1766470d4b02c626c4ce..896e20f5027b5668b4e90bf8b9f59a08a3de9b35 100644 (file)
@@ -18,3 +18,4 @@ rm -f rndc.out*
 [ -d ns2/nope ] && chmod 755 ns2/nope
 rm -rf ns2/nope
 rm -f ns2/dir ns2/nopedir ns2/mkd ns2/nopemkd
+rm -rf ns2/tmp.*
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 e515f2ac454adba56b4902b80b3e6ae1c4002603..5c77a9cabbccb5c784fc80f6010f804d5ecd9d3b 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
@@ -149,5 +151,33 @@ 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"
+        export SOFTHSM2_CONF="${TEMP_NAMED_DIR}/softhsm2.conf"
+        sh -x "$TOP/util/prepare-softhsm2.sh"
+        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
index 07e271d8f4c933a92c5e846b259bb9d4b32035ac..b5863d94c06037e3bf737dbccc4b919bf1b1b0c4 100644 (file)
 ./bin/tests/system/runtime/ns2/named-alt4.conf.in      CONF-C  2014,2016,2017,2018,2019
 ./bin/tests/system/runtime/ns2/named-alt5.conf.in      CONF-C  2014,2016,2017,2018,2019
 ./bin/tests/system/runtime/ns2/named-alt6.conf.in      CONF-C  2014,2016,2017,2018,2019
+./bin/tests/system/runtime/ns2/named-alt9.conf.in      CONF-C  2019
 ./bin/tests/system/runtime/ns2/named1.conf.in  CONF-C  2014,2016,2017,2018,2019
 ./bin/tests/system/runtime/setup.sh            SH      2015,2016,2017,2018,2019
 ./bin/tests/system/runtime/tests.sh            SH      2014,2015,2016,2017,2018,2019