1 #!/bin/sh 2 3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4 # 5 # SPDX-License-Identifier: MPL-2.0 6 # 7 # This Source Code Form is subject to the terms of the Mozilla Public 8 # License, v. 2.0. If a copy of the MPL was not distributed with this 9 # file, you can obtain one at https://mozilla.org/MPL/2.0/. 10 # 11 # See the COPYRIGHT file distributed with this work for additional 12 # information regarding copyright ownership. 13 14 set -e 15 16 . ../conf.sh 17 18 DIGOPTS="-p ${PORT}" 19 RNDCCMD="$RNDC -c ../_common/rndc.conf -p ${CONTROLPORT} -s" 20 21 status=0 22 23 # 24 echo_i "checking that we detect a NS which refers to a CNAME" 25 if $CHECKZONE . cname.db >cname.out 2>&1; then 26 echo_i "failed (status)" 27 status=$((status + 1)) 28 else 29 if grep "is a CNAME" cname.out >/dev/null; then 30 : 31 else 32 echo_i "failed (message)" 33 status=$((status + 1)) 34 fi 35 fi 36 37 # 38 echo_i "checking that we detect a NS which is below a DNAME" 39 if $CHECKZONE . dname.db >dname.out 2>&1; then 40 echo_i "failed (status)" 41 status=$((status + 1)) 42 else 43 if grep "is below a DNAME" dname.out >/dev/null; then 44 : 45 else 46 echo_i "failed (message)" 47 status=$((status + 1)) 48 fi 49 fi 50 51 # 52 echo_i "checking that we detect a NS which has no address records (A/AAAA)" 53 if $CHECKZONE . noaddress.db >noaddress.out; then 54 echo_i "failed (status)" 55 status=$((status + 1)) 56 else 57 if grep "has no address records" noaddress.out >/dev/null; then 58 : 59 else 60 echo_i "failed (message)" 61 status=$((status + 1)) 62 fi 63 fi 64 65 # 66 echo_i "checking that we detect a NS which has no records" 67 if $CHECKZONE . nxdomain.db >nxdomain.out; then 68 echo_i "failed (status)" 69 status=$((status + 1)) 70 else 71 if grep "has no address records" noaddress.out >/dev/null; then 72 : 73 else 74 echo_i "failed (message)" 75 status=$((status + 1)) 76 fi 77 fi 78 79 # 80 echo_i "checking that we detect a NS which looks like a A record (fail)" 81 if $CHECKZONE -n fail . a.db >a.out 2>&1; then 82 echo_i "failed (status)" 83 status=$((status + 1)) 84 else 85 if grep "appears to be an address" a.out >/dev/null; then 86 : 87 else 88 echo_i "failed (message)" 89 status=$((status + 1)) 90 fi 91 fi 92 93 # 94 echo_i "checking that we detect a NS which looks like a A record (warn=default)" 95 if $CHECKZONE . a.db >a.out 2>&1; then 96 if grep "appears to be an address" a.out >/dev/null; then 97 : 98 else 99 echo_i "failed (message)" 100 status=$((status + 1)) 101 fi 102 else 103 echo_i "failed (status)" 104 status=$((status + 1)) 105 fi 106 107 # 108 echo_i "checking that we detect a NS which looks like a A record (ignore)" 109 if $CHECKZONE -n ignore . a.db >a.out 2>&1; then 110 if grep "appears to be an address" a.out >/dev/null; then 111 echo_i "failed (message)" 112 status=$((status + 1)) 113 else 114 : 115 fi 116 else 117 echo_i "failed (status)" 118 status=$((status + 1)) 119 fi 120 121 # 122 echo_i "checking that we detect a NS which looks like a AAAA record (fail)" 123 if $CHECKZONE -n fail . aaaa.db >aaaa.out 2>&1; then 124 echo_i "failed (status)" 125 status=$((status + 1)) 126 else 127 if grep "appears to be an address" aaaa.out >/dev/null; then 128 : 129 else 130 echo_i "failed (message)" 131 status=$((status + 1)) 132 fi 133 fi 134 135 # 136 echo_i "checking that we detect a NS which looks like a AAAA record (warn=default)" 137 if $CHECKZONE . aaaa.db >aaaa.out 2>&1; then 138 if grep "appears to be an address" aaaa.out >/dev/null; then 139 : 140 else 141 echo_i "failed (message)" 142 status=$((status + 1)) 143 fi 144 else 145 echo_i "failed (status)" 146 status=$((status + 1)) 147 fi 148 149 # 150 echo_i "checking that we detect a NS which looks like a AAAA record (ignore)" 151 if $CHECKZONE -n ignore . aaaa.db >aaaa.out 2>&1; then 152 if grep "appears to be an address" aaaa.out >/dev/null; then 153 echo_i "failed (message)" 154 status=$((status + 1)) 155 else 156 : 157 fi 158 else 159 echo_i "failed (status)" 160 status=$((status + 1)) 161 fi 162 163 # 164 echo_i "checking 'rdnc zonestatus' output" 165 ret=0 166 for i in 0 1 2 3 4 5 6 7 8 9; do 167 $RNDCCMD 10.53.0.1 zonestatus primary.example >rndc.out.pri 2>&1 168 grep "zone not loaded" rndc.out.pri >/dev/null || break 169 sleep 1 170 done 171 checkfor() { 172 grep "$1" $2 >/dev/null || { 173 ret=1 174 echo_i "missing string '$1' from '$2'" 175 } 176 } 177 checkfor "name: primary.example" rndc.out.pri 178 checkfor "type: primary" rndc.out.pri 179 checkfor "files: primary.db, primary.db.signed" rndc.out.pri 180 checkfor "serial: " rndc.out.pri 181 checkfor "nodes: " rndc.out.pri 182 checkfor "last loaded: " rndc.out.pri 183 checkfor "secure: yes" rndc.out.pri 184 checkfor "inline signing: no" rndc.out.pri 185 checkfor "key maintenance: automatic" rndc.out.pri 186 checkfor "next key event: " rndc.out.pri 187 checkfor "next resign node: " rndc.out.pri 188 checkfor "next resign time: " rndc.out.pri 189 checkfor "dynamic: yes" rndc.out.pri 190 checkfor "frozen: no" rndc.out.pri 191 for i in 0 1 2 3 4 5 6 7 8 9; do 192 $RNDCCMD 10.53.0.2 zonestatus primary.example >rndc.out.sec 2>&1 193 grep "zone not loaded" rndc.out.sec >/dev/null || break 194 sleep 1 195 done 196 checkfor "name: primary.example" rndc.out.sec 197 checkfor "type: secondary" rndc.out.sec 198 checkfor "files: sec.db" rndc.out.sec 199 checkfor "serial: " rndc.out.sec 200 checkfor "nodes: " rndc.out.sec 201 checkfor "next refresh: " rndc.out.sec 202 checkfor "expires: " rndc.out.sec 203 checkfor "secure: yes" rndc.out.sec 204 for i in 0 1 2 3 4 5 6 7 8 9; do 205 $RNDCCMD 10.53.0.1 zonestatus reload.example >rndc.out.prereload 2>&1 206 grep "zone not loaded" rndc.out.prereload >/dev/null || break 207 sleep 1 208 done 209 checkfor "files: reload.db, soa.db$" rndc.out.prereload 210 echo "@ 0 SOA . . 2 0 0 0 0" >ns1/soa.db 211 $RNDCCMD 10.53.0.1 reload reload.example | sed 's/^/ns1 /' | cat_i 212 for i in 0 1 2 3 4 5 6 7 8 9; do 213 $DIG $DIGOPTS reload.example SOA @10.53.0.1 >dig.out 214 grep " 2 0 0 0 0" dig.out >/dev/null && break 215 sleep 1 216 done 217 $RNDCCMD 10.53.0.1 zonestatus reload.example >rndc.out.postreload 2>&1 218 checkfor "files: reload.db, soa.db$" rndc.out.postreload 219 sleep 1 220 echo "@ 0 SOA . . 3 0 0 0 0" >ns1/reload.db 221 echo "@ 0 NS ." >>ns1/reload.db 222 rndc_reload ns1 10.53.0.1 reload.example 223 for i in 0 1 2 3 4 5 6 7 8 9; do 224 $DIG $DIGOPTS reload.example SOA @10.53.0.1 >dig.out 225 grep " 3 0 0 0 0" dig.out >/dev/null && break 226 sleep 1 227 done 228 $RNDCCMD 10.53.0.1 zonestatus reload.example >rndc.out.removeinclude 2>&1 229 checkfor "files: reload.db$" rndc.out.removeinclude 230 231 if [ $ret != 0 ]; then echo_i "failed"; fi 232 status=$((status + ret)) 233 234 echo_i "checking 'rdnc zonestatus' with duplicated zone name" 235 ret=0 236 $RNDCCMD 10.53.0.1 zonestatus duplicate.example >rndc.out.duplicate 2>&1 && ret=1 237 checkfor "zone 'duplicate.example' was found in multiple views" rndc.out.duplicate 238 $RNDCCMD 10.53.0.1 zonestatus duplicate.example in primary >rndc.out.duplicate 2>&1 || ret=1 239 checkfor "name: duplicate.example" rndc.out.duplicate 240 $RNDCCMD 10.53.0.1 zonestatus nosuchzone.example >rndc.out.duplicate 2>&1 && ret=1 241 checkfor "no matching zone 'nosuchzone.example' in any view" rndc.out.duplicate 242 if [ $ret != 0 ]; then echo_i "failed"; fi 243 status=$((status + ret)) 244 245 echo_i "checking 'rdnc zonestatus' with big serial value" 246 ret=0 247 $RNDCCMD 10.53.0.1 zonestatus bigserial.example >rndc.out.bigserial 2>&1 248 checkfor "serial: 3003113544" rndc.out.bigserial 249 if [ $ret != 0 ]; then echo_i "failed"; fi 250 status=$((status + ret)) 251 252 echo_i "exit status: $status" 253 [ $status -eq 0 ] || exit 1 254