Home | History | Annotate | Line # | Download | only in runtime
      1   1.1.1.4  christos #!/bin/sh
      2   1.1.1.6  christos 
      3       1.1  christos # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      4       1.1  christos #
      5   1.1.1.6  christos # SPDX-License-Identifier: MPL-2.0
      6   1.1.1.6  christos #
      7       1.1  christos # This Source Code Form is subject to the terms of the Mozilla Public
      8   1.1.1.6  christos # License, v. 2.0.  If a copy of the MPL was not distributed with this
      9   1.1.1.5  christos # file, you can obtain one at https://mozilla.org/MPL/2.0/.
     10       1.1  christos #
     11       1.1  christos # See the COPYRIGHT file distributed with this work for additional
     12       1.1  christos # information regarding copyright ownership.
     13       1.1  christos 
     14   1.1.1.4  christos set -e
     15       1.1  christos 
     16   1.1.1.8  christos # shellcheck source=conf.sh
     17   1.1.1.8  christos . ../conf.sh
     18   1.1.1.8  christos 
     19   1.1.1.8  christos RNDCCMD="$RNDC -c ../_common/rndc.conf -p ${CONTROLPORT} -s"
     20  1.1.1.10  christos NAMED_DEFAULT_ARGS="-m record -d 99 -g"
     21       1.1  christos 
     22   1.1.1.4  christos kill_named() {
     23   1.1.1.8  christos   pidfile="${1}"
     24   1.1.1.8  christos   if [ ! -r "${pidfile}" ]; then
     25   1.1.1.8  christos     return 1
     26   1.1.1.8  christos   fi
     27   1.1.1.8  christos 
     28   1.1.1.8  christos   pid=$(cat "${pidfile}" 2>/dev/null)
     29   1.1.1.8  christos   if [ "${pid:+set}" = "set" ]; then
     30   1.1.1.8  christos     kill -15 "${pid}" >/dev/null 2>&1
     31   1.1.1.8  christos     retries=10
     32   1.1.1.8  christos     while [ "$retries" -gt 0 ]; do
     33   1.1.1.8  christos       if ! kill -0 "${pid}" >/dev/null 2>&1; then
     34   1.1.1.8  christos         break
     35   1.1.1.8  christos       fi
     36   1.1.1.8  christos       sleep 1
     37   1.1.1.8  christos       retries=$((retries - 1))
     38   1.1.1.8  christos     done
     39   1.1.1.8  christos     # Timed-out
     40   1.1.1.8  christos     if [ "$retries" -eq 0 ]; then
     41   1.1.1.8  christos       echo_i "failed to kill named ($pidfile)"
     42   1.1.1.8  christos       return 1
     43   1.1.1.8  christos     fi
     44   1.1.1.8  christos   fi
     45   1.1.1.8  christos   rm -f "${pidfile}"
     46   1.1.1.8  christos   return 0
     47   1.1.1.4  christos }
     48   1.1.1.4  christos 
     49   1.1.1.5  christos check_named_log() {
     50   1.1.1.8  christos   grep "$@" >/dev/null 2>&1
     51   1.1.1.4  christos }
     52   1.1.1.4  christos 
     53   1.1.1.5  christos run_named() (
     54   1.1.1.8  christos   dir="$1"
     55   1.1.1.8  christos   shift
     56   1.1.1.8  christos   run="$1"
     57   1.1.1.8  christos   shift
     58   1.1.1.8  christos   if cd "$dir" >/dev/null 2>&1; then
     59   1.1.1.8  christos     "${NAMED}" "$@" ${NAMED_DEFAULT_ARGS} >>"$run" 2>&1 &
     60   1.1.1.8  christos     echo $!
     61   1.1.1.8  christos   fi
     62   1.1.1.5  christos )
     63   1.1.1.5  christos 
     64   1.1.1.5  christos check_pid() (
     65  1.1.1.11  christos   ! kill -0 "${1}" >/dev/null 2>&1
     66   1.1.1.5  christos )
     67   1.1.1.5  christos 
     68       1.1  christos status=0
     69       1.1  christos n=0
     70       1.1  christos 
     71   1.1.1.8  christos n=$((n + 1))
     72       1.1  christos echo_i "verifying that named started normally ($n)"
     73       1.1  christos ret=0
     74       1.1  christos [ -s ns2/named.pid ] || ret=1
     75   1.1.1.8  christos grep "unable to listen on any configured interface" ns2/named.run >/dev/null && ret=1
     76   1.1.1.8  christos grep "another named process" ns2/named.run >/dev/null && ret=1
     77   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
     78   1.1.1.8  christos status=$((status + ret))
     79       1.1  christos 
     80   1.1.1.8  christos n=$((n + 1))
     81       1.1  christos echo_i "checking that named refuses to reconfigure if working directory is not writable ($n)"
     82       1.1  christos ret=0
     83  1.1.1.12  christos cp ns2/named2.conf ns2/named.conf
     84   1.1.1.8  christos $RNDCCMD 10.53.0.2 reconfig >rndc.out.$n 2>&1 && ret=1
     85   1.1.1.8  christos grep "failed: permission denied" rndc.out.$n >/dev/null 2>&1 || ret=1
     86       1.1  christos sleep 1
     87   1.1.1.8  christos grep "[^-]directory './nope' is not writable" ns2/named.run >/dev/null 2>&1 || ret=1
     88   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
     89   1.1.1.8  christos status=$((status + ret))
     90       1.1  christos 
     91   1.1.1.8  christos n=$((n + 1))
     92       1.1  christos echo_i "checking that named refuses to reconfigure if managed-keys-directory is not writable ($n)"
     93       1.1  christos ret=0
     94  1.1.1.12  christos cp ns2/named3.conf ns2/named.conf
     95   1.1.1.8  christos $RNDCCMD 10.53.0.2 reconfig >rndc.out.$n 2>&1 && ret=1
     96   1.1.1.8  christos grep "failed: permission denied" rndc.out.$n >/dev/null 2>&1 || ret=1
     97       1.1  christos sleep 1
     98   1.1.1.8  christos grep "managed-keys-directory './nope' is not writable" ns2/named.run >/dev/null 2>&1 || ret=1
     99   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    100   1.1.1.8  christos status=$((status + ret))
    101       1.1  christos 
    102   1.1.1.8  christos n=$((n + 1))
    103       1.1  christos echo_i "checking that named refuses to reconfigure if new-zones-directory is not writable ($n)"
    104       1.1  christos ret=0
    105  1.1.1.12  christos cp ns2/named4.conf ns2/named.conf
    106   1.1.1.8  christos $RNDCCMD 10.53.0.2 reconfig >rndc.out.$n 2>&1 && ret=1
    107   1.1.1.8  christos grep "failed: permission denied" rndc.out.$n >/dev/null 2>&1 || ret=1
    108       1.1  christos sleep 1
    109   1.1.1.8  christos grep "new-zones-directory './nope' is not writable" ns2/named.run >/dev/null 2>&1 || ret=1
    110   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    111   1.1.1.8  christos status=$((status + ret))
    112   1.1.1.4  christos 
    113   1.1.1.8  christos n=$((n + 1))
    114   1.1.1.4  christos echo_i "checking that named recovers when configuration file is valid again ($n)"
    115   1.1.1.4  christos ret=0
    116  1.1.1.12  christos cp ns2/named1.conf ns2/named.conf
    117   1.1.1.8  christos $RNDCCMD 10.53.0.2 reconfig >rndc.out.$n 2>&1 || ret=1
    118   1.1.1.4  christos [ -s ns2/named.pid ] || ret=1
    119   1.1.1.4  christos kill_named ns2/named.pid || ret=1
    120   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    121   1.1.1.8  christos status=$((status + ret))
    122       1.1  christos 
    123   1.1.1.8  christos n=$((n + 1))
    124       1.1  christos echo_i "checking that named refuses to start if working directory is not writable ($n)"
    125       1.1  christos ret=0
    126  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named2.conf -D runtime-ns2-extra-4)
    127   1.1.1.5  christos test -n "$testpid" || ret=1
    128   1.1.1.5  christos retry_quiet 10 check_named_log "exiting (due to fatal error)" ns2/named$n.run || ret=1
    129   1.1.1.8  christos grep "[^-]directory './nope' is not writable" ns2/named$n.run >/dev/null 2>&1 || ret=1
    130   1.1.1.4  christos kill_named ns2/named.pid && ret=1
    131   1.1.1.5  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    132   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    133   1.1.1.8  christos status=$((status + ret))
    134       1.1  christos 
    135   1.1.1.8  christos n=$((n + 1))
    136       1.1  christos echo_i "checking that named refuses to start if managed-keys-directory is not writable ($n)"
    137       1.1  christos ret=0
    138  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named3.conf -D runtime-ns2-extra-5)
    139   1.1.1.5  christos test -n "$testpid" || ret=1
    140   1.1.1.5  christos retry_quiet 10 check_named_log "exiting (due to fatal error)" ns2/named$n.run || ret=1
    141   1.1.1.8  christos grep "managed-keys-directory './nope' is not writable" ns2/named$n.run >/dev/null 2>&1 || ret=1
    142   1.1.1.4  christos kill_named named.pid && ret=1
    143   1.1.1.5  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    144   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    145   1.1.1.8  christos status=$((status + ret))
    146   1.1.1.4  christos 
    147   1.1.1.8  christos n=$((n + 1))
    148   1.1.1.4  christos echo_i "checking that named refuses to start if new-zones-directory is not writable ($n)"
    149   1.1.1.4  christos ret=0
    150  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named4.conf -D runtime-ns2-extra-6)
    151   1.1.1.5  christos test -n "$testpid" || ret=1
    152   1.1.1.5  christos retry_quiet 10 check_named_log "exiting (due to fatal error)" ns2/named$n.run || ret=1
    153   1.1.1.8  christos grep "new-zones-directory './nope' is not writable" ns2/named$n.run >/dev/null 2>&1 || ret=1
    154   1.1.1.4  christos kill_named ns2/named.pid && ret=1
    155   1.1.1.5  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    156   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    157   1.1.1.8  christos status=$((status + ret))
    158   1.1.1.4  christos 
    159   1.1.1.8  christos n=$((n + 1))
    160   1.1.1.4  christos echo_i "checking that named logs control characters in octal notation ($n)"
    161   1.1.1.4  christos ret=0
    162   1.1.1.4  christos INSTANCE_NAME="runtime-ns2-extra-7-$(cat ctrl-chars)"
    163  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named5.conf -D "${INSTANCE_NAME}")
    164   1.1.1.5  christos test -n "$testpid" || ret=1
    165   1.1.1.7  christos retry_quiet 60 check_named_log "running$" ns2/named$n.run || ret=1
    166   1.1.1.8  christos grep 'running as.*\\177\\033' ns2/named$n.run >/dev/null || ret=1
    167   1.1.1.4  christos kill_named ns2/named.pid || ret=1
    168   1.1.1.5  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    169   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    170   1.1.1.8  christos status=$((status + ret))
    171   1.1.1.4  christos 
    172   1.1.1.8  christos n=$((n + 1))
    173   1.1.1.4  christos echo_i "checking that named escapes special characters in the logs ($n)"
    174   1.1.1.4  christos ret=0
    175   1.1.1.4  christos INSTANCE_NAME="runtime-ns2-extra-8-$;"
    176  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named5.conf -D "${INSTANCE_NAME}")
    177   1.1.1.5  christos test -n "$testpid" || ret=1
    178   1.1.1.7  christos retry_quiet 60 check_named_log "running$" ns2/named$n.run || ret=1
    179   1.1.1.8  christos grep 'running as.*\\$\\;' ns2/named$n.run >/dev/null || ret=1
    180   1.1.1.4  christos kill_named ns2/named.pid || ret=1
    181   1.1.1.5  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    182   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    183   1.1.1.8  christos status=$((status + ret))
    184   1.1.1.4  christos 
    185   1.1.1.8  christos n=$((n + 1))
    186   1.1.1.4  christos echo_i "checking that named logs an ellipsis when the command line is larger than 8k bytes ($n)"
    187   1.1.1.4  christos ret=0
    188   1.1.1.4  christos LONG_CMD_LINE=$(cat long-cmd-line)
    189   1.1.1.4  christos # shellcheck disable=SC2086
    190  1.1.1.12  christos testpid=$(run_named ns2 named$n.run $LONG_CMD_LINE -c "named5.conf")
    191   1.1.1.5  christos test -n "$testpid" || ret=1
    192   1.1.1.7  christos retry_quiet 60 check_named_log "running$" ns2/named$n.run || ret=1
    193   1.1.1.8  christos grep "running as.*\.\.\.$" ns2/named$n.run >/dev/null || ret=1
    194   1.1.1.4  christos kill_named ns2/named.pid || ret=1
    195   1.1.1.5  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    196   1.1.1.4  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    197   1.1.1.8  christos status=$((status + ret))
    198   1.1.1.4  christos 
    199   1.1.1.8  christos n=$((n + 1))
    200   1.1.1.9  christos echo_i "checking that named log missing IPv4 primaries in -4 mode ($n)"
    201   1.1.1.9  christos ret=0
    202   1.1.1.9  christos INSTANCE_NAME="missing-primaries-ipv4-only-mode"
    203  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named6.conf -D "${INSTANCE_NAME}" -4)
    204   1.1.1.9  christos test -n "$testpid" || ret=1
    205   1.1.1.9  christos retry_quiet 60 check_named_log "running$" ns2/named$n.run || ret=1
    206   1.1.1.9  christos grep "IPv6 disabled and no IPv4 primaries" ns2/named$n.run >/dev/null || ret=1
    207   1.1.1.9  christos kill_named ns2/named.pid || ret=1
    208   1.1.1.9  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    209   1.1.1.9  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    210   1.1.1.9  christos status=$((status + ret))
    211   1.1.1.9  christos 
    212   1.1.1.9  christos n=$((n + 1))
    213   1.1.1.9  christos echo_i "checking that named log missing IPv6 primaries in -6 mode ($n)"
    214   1.1.1.9  christos ret=0
    215   1.1.1.9  christos INSTANCE_NAME="missing-primaries-ipv4-only-mode"
    216  1.1.1.12  christos testpid=$(run_named ns2 named$n.run -c named6.conf -D "${INSTANCE_NAME}" -6)
    217   1.1.1.9  christos test -n "$testpid" || ret=1
    218   1.1.1.9  christos retry_quiet 60 check_named_log "running$" ns2/named$n.run || ret=1
    219   1.1.1.9  christos grep "IPv4 disabled and no IPv6 primaries" ns2/named$n.run >/dev/null || ret=1
    220   1.1.1.9  christos kill_named ns2/named.pid || ret=1
    221   1.1.1.9  christos test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    222   1.1.1.9  christos if [ $ret -ne 0 ]; then echo_i "failed"; fi
    223   1.1.1.9  christos status=$((status + ret))
    224   1.1.1.9  christos 
    225   1.1.1.9  christos n=$((n + 1))
    226   1.1.1.4  christos echo_i "verifying that named switches UID ($n)"
    227   1.1.1.8  christos if [ "$(id -u)" -eq 0 ]; then
    228   1.1.1.8  christos   ret=0
    229   1.1.1.8  christos   {
    230   1.1.1.4  christos     TEMP_NAMED_DIR=$(mktemp -d "$(pwd)/ns2/tmp.XXXXXXXX")
    231   1.1.1.8  christos     rc=$?
    232   1.1.1.8  christos   } || true
    233   1.1.1.8  christos   if [ "$rc" -eq 0 ]; then
    234  1.1.1.12  christos     cp ns2/named7.conf "${TEMP_NAMED_DIR}/named7.conf"
    235   1.1.1.8  christos     chown -R nobody: "${TEMP_NAMED_DIR}"
    236   1.1.1.8  christos     chmod 0700 "${TEMP_NAMED_DIR}"
    237  1.1.1.12  christos     testpid=$(run_named "${TEMP_NAMED_DIR}" "${TEMP_NAMED_DIR}/named$n.run" -u nobody -c named7.conf)
    238   1.1.1.8  christos     test -n "$testpid" || ret=1
    239   1.1.1.8  christos     retry_quiet 60 check_named_log "running$" "${TEMP_NAMED_DIR}/named$n.run" || ret=1
    240  1.1.1.12  christos     [ -s "${TEMP_NAMED_DIR}/named7.pid" ] || ret=1
    241   1.1.1.8  christos     grep "loading configuration: permission denied" "${TEMP_NAMED_DIR}/named$n.run" >/dev/null && ret=1
    242  1.1.1.12  christos     kill_named "${TEMP_NAMED_DIR}/named7.pid" || ret=1
    243   1.1.1.8  christos     test -n "$testpid" || ret=1
    244   1.1.1.8  christos     test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
    245   1.1.1.8  christos   else
    246   1.1.1.8  christos     echo_i "mktemp failed"
    247   1.1.1.8  christos     ret=1
    248   1.1.1.8  christos   fi
    249   1.1.1.8  christos   if [ $ret -ne 0 ]; then echo_i "failed"; fi
    250   1.1.1.8  christos   status=$((status + ret))
    251   1.1.1.4  christos else
    252  1.1.1.10  christos   echo_i "skipped, not running as root"
    253   1.1.1.4  christos fi
    254       1.1  christos 
    255       1.1  christos echo_i "exit status: $status"
    256       1.1  christos [ $status -eq 0 ] || exit 1
    257