xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/logfileconfig/tests.sh (revision 3f351f34c6d827cf017cdcff3543f6ec0c88b420)
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
14SYSTEMTESTTOP=..
15. $SYSTEMTESTTOP/conf.sh
16THISDIR=`pwd`
17CONFDIR="ns1"
18
19# Test given condition.  If true, test again after a second.  Used for testing
20# filesystem-dependent conditions in order to prevent false negatives caused by
21# directory contents not being synchronized immediately after rename() returns.
22test_with_retry() {
23	if test "$@"; then
24		sleep 1
25		if test "$@"; then
26			return 0
27		fi
28	fi
29	return 1
30}
31
32status=0
33n=0
34
35echo_i "testing log file validity (named -g + only plain files allowed)"
36
37# First run with a known good config.
38n=$((n+1))
39echo_i "testing log file validity (only plain files allowed) ($n)"
40ret=0
41cat /dev/null > ns1/named_log
42copy_setports ns1/named.plainconf.in ns1/named.conf
43nextpart ns1/named.run > /dev/null
44rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
45wait_for_log 5 "reloading configuration succeeded" ns1/named.run || ret=1
46if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
47status=$((status+ret))
48
49# Now try directory, expect failure
50n=$((n+1))
51echo_i "testing directory as log file ($n)"
52ret=0
53nextpart ns1/named.run > /dev/null
54copy_setports ns1/named.dirconf.in ns1/named.conf
55rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
56wait_for_log 5 "reloading configuration failed: invalid file" ns1/named.run || ret=1
57if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
58status=$((status+ret))
59
60# Now try pipe file, expect failure
61n=$((n+1))
62echo_i "testing pipe file as log file ($n)"
63ret=0
64nextpart ns1/named.run > /dev/null
65rm -f ns1/named_pipe
66if mkfifo ns1/named_pipe >/dev/null 2>&1; then
67    copy_setports ns1/named.pipeconf.in ns1/named.conf
68    rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
69    wait_for_log 5 "reloading configuration failed: invalid file" ns1/named.run || ret=1
70    if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
71    status=$((status+ret))
72else
73    echo_i "skipping pipe test (unable to create pipe)"
74fi
75
76# Now try symlink file to plain file, expect success
77n=$((n+1))
78echo_i "testing symlink to plain file as log file ($n)"
79ret=0
80rm -f ns1/named_log ns1/named_sym
81touch ns1/named_log
82if ln -s $(pwd)/ns1/named_log $(pwd)/ns1/named_sym >/dev/null 2>&1; then
83    nextpart ns1/named.run > /dev/null
84    copy_setports ns1/named.symconf.in ns1/named.conf
85    rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
86    wait_for_log 5 "reloading configuration succeeded" ns1/named.run || ret=1
87    if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
88    status=$((status+ret))
89else
90	echo_i "skipping symlink test (unable to create symlink)"
91fi
92
93echo_i "repeat previous tests without named -g"
94copy_setports ns1/named.plain.in ns1/named.conf
95$PERL ../stop.pl --use-rndc --port ${CONTROLPORT} logfileconfig ns1
96cp named1.args ns1/named.args
97start_server --noclean --restart --port ${PORT} ns1
98
99n=$((n+1))
100echo_i "testing log file validity (only plain files allowed) ($n)"
101ret=0
102cat /dev/null > ns1/named_log
103copy_setports ns1/named.plainconf.in ns1/named.conf
104nextpart ns1/named.run > /dev/null
105rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
106wait_for_log 5 "reloading configuration succeeded" ns1/named.run || ret=1
107if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
108status=$((status+ret))
109
110# Now try directory, expect failure
111n=$((n+1))
112echo_i "testing directory as log file ($n)"
113ret=0
114nextpart ns1/named.run > /dev/null
115copy_setports ns1/named.dirconf.in ns1/named.conf
116rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
117wait_for_log 5 "reloading configuration failed: invalid file" ns1/named.run || ret=1
118if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
119status=$((status+ret))
120
121# Now try pipe file, expect failure
122n=$((n+1))
123echo_i "testing pipe file as log file ($n)"
124ret=0
125nextpart ns1/named.run > /dev/null
126rm -f ns1/named_pipe
127if mkfifo ns1/named_pipe >/dev/null 2>&1; then
128    copy_setports ns1/named.pipeconf.in ns1/named.conf
129    rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
130    wait_for_log 5 "reloading configuration failed: invalid file" ns1/named.run || ret=1
131    if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
132    status=$((status+ret))
133else
134    echo_i "skipping pipe test (unable to create pipe)"
135fi
136
137# Now try symlink file to plain file, expect success
138n=$((n+1))
139echo_i "testing symlink to plain file as log file ($n)"
140ret=0
141rm -f ns1/named_log ns1/named_sym
142touch ns1/named_log
143if ln -s $(pwd)/ns1/named_log $(pwd)/ns1/named_sym >/dev/null 2>&1; then
144    nextpart ns1/named.run > /dev/null
145    copy_setports ns1/named.symconf.in ns1/named.conf
146    rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
147    wait_for_log 5 "reloading configuration succeeded" ns1/named.run || ret=1
148    if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
149    status=$((status+ret))
150else
151	echo_i "skipping symlink test (unable to create symlink)"
152fi
153
154echo_i "testing logging functionality"
155n=$((n+1))
156ret=0
157echo_i "testing iso8601 timestamp ($n)"
158copy_setports ns1/named.iso8601.in ns1/named.conf
159rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
160grep '^....-..-..T..:..:..\.... ' ns1/named_iso8601 > /dev/null || ret=1
161if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
162status=$((status+ret))
163
164n=$((n+1))
165echo_i "testing iso8601-utc timestamp ($n)"
166ret=0
167copy_setports ns1/named.iso8601-utc.in ns1/named.conf
168rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
169grep '^....-..-..T..:..:..\....Z' ns1/named_iso8601_utc > /dev/null || ret=1
170if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
171status=$((status+ret))
172
173n=$((n+1))
174echo_i "testing explicit versions ($n)"
175ret=0
176copy_setports ns1/named.versconf.in ns1/named.conf
177# a seconds since epoch version number
178touch ns1/named_vers.1480039317
179rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
180$DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n
181grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
182# we are configured to retain five logfiles (a current file
183# and 4 backups). so files with version number 5 or higher
184# should be removed.
185test_with_retry -f ns1/named_vers.1480039317 && ret=1
186test_with_retry -f ns1/named_vers.5 && ret=1
187test_with_retry -f ns1/named_vers.4 || ret=1
188if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
189status=$((status+ret))
190
191n=$((n+1))
192echo_i "testing timestamped versions ($n)"
193ret=0
194copy_setports ns1/named.tsconf.in ns1/named.conf
195# a seconds since epoch version number
196touch ns1/named_ts.1480039317
197# a timestamp version number
198touch ns1/named_ts.20150101120000120
199rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
200_found2() (
201        $DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n
202        grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
203
204        # we are configured to keep three versions, so the oldest
205        # timestamped versions should be gone, and there should
206        # be two or three backup ones.
207        [ -f ns1/named_ts.1480039317 ] && return 1
208        [ -f ns1/named_ts.20150101120000120 ] && return 1
209        set -- ns1/named_ts.*
210        [ "$#" -eq 2 -o "$#" -eq 3 ] || return 1
211)
212retry_quiet 5 _found2 || ret=1
213if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
214status=$((status+ret))
215
216n=$((n+1))
217echo_i "testing unlimited versions ($n)"
218ret=0
219copy_setports ns1/named.unlimited.in ns1/named.conf
220# a seconds since epoch version number
221touch ns1/named_unlimited.1480039317
222rndc_reconfig ns1 10.53.0.1 > rndc.out.test$n
223$DIG version.bind txt ch @10.53.0.1 -p ${PORT} > dig.out.test$n
224grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
225test_with_retry -f ns1/named_unlimited.1480039317 || ret=1
226test_with_retry -f ns1/named_unlimited.4 || ret=1
227if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
228status=$((status+ret))
229
230n=$((n+1))
231echo_i "testing default logfile using named -L file ($n)"
232ret=0
233$PERL ../stop.pl logfileconfig ns1
234cp named2.args ns1/named.args
235test -f ns1/named.pid && ret=1
236rm -f ns1/named_deflog
237copy_setports ns1/named.plainconf.in ns1/named.conf
238start_server --noclean --restart --port ${PORT} ns1
239[ -f "ns1/named_deflog" ] || ret=1
240if [ "$ret" -ne 0 ]; then echo_i "failed"; fi
241status=$((status+ret))
242
243echo_i "exit status: $status"
244[ $status -eq 0 ] || exit 1
245