xref: /freebsd/crypto/openssh/regress/servcfginclude.sh (revision 19261079b74319502c6ffa1249920079f0f69a72)
1*19261079SEd Maste#	Placed in the Public Domain.
2*19261079SEd Maste
3*19261079SEd Mastetid="server config include"
4*19261079SEd Maste
5*19261079SEd Mastecat > $OBJ/sshd_config.i << _EOF
6*19261079SEd MasteHostKey $OBJ/host.ssh-ed25519
7*19261079SEd MasteMatch host a
8*19261079SEd Maste	Banner /aa
9*19261079SEd Maste
10*19261079SEd MasteMatch host b
11*19261079SEd Maste	Banner /bb
12*19261079SEd Maste	Include $OBJ/sshd_config.i.* # comment
13*19261079SEd Maste
14*19261079SEd MasteMatch host c
15*19261079SEd Maste	Include $OBJ/sshd_config.i.* # comment
16*19261079SEd Maste	Banner /cc
17*19261079SEd Maste
18*19261079SEd MasteMatch host m
19*19261079SEd Maste	Include $OBJ/sshd_config.i.*
20*19261079SEd Maste
21*19261079SEd MasteMatch Host d
22*19261079SEd Maste	Banner /dd # comment
23*19261079SEd Maste
24*19261079SEd MasteMatch Host e
25*19261079SEd Maste	Banner /ee
26*19261079SEd Maste	Include $OBJ/sshd_config.i.*
27*19261079SEd Maste
28*19261079SEd MasteMatch Host f
29*19261079SEd Maste	Include $OBJ/sshd_config.i.*
30*19261079SEd Maste	Banner /ff
31*19261079SEd Maste
32*19261079SEd MasteMatch Host n
33*19261079SEd Maste	Include $OBJ/sshd_config.i.*
34*19261079SEd Maste_EOF
35*19261079SEd Maste
36*19261079SEd Mastecat > $OBJ/sshd_config.i.0 << _EOF
37*19261079SEd MasteMatch host xxxxxx
38*19261079SEd Maste_EOF
39*19261079SEd Maste
40*19261079SEd Mastecat > $OBJ/sshd_config.i.1 << _EOF
41*19261079SEd MasteMatch host a
42*19261079SEd Maste	Banner /aaa
43*19261079SEd Maste
44*19261079SEd MasteMatch host b
45*19261079SEd Maste	Banner /bbb
46*19261079SEd Maste
47*19261079SEd MasteMatch host c
48*19261079SEd Maste	Banner /ccc
49*19261079SEd Maste
50*19261079SEd MasteMatch Host d
51*19261079SEd Maste	Banner /ddd
52*19261079SEd Maste
53*19261079SEd MasteMatch Host e
54*19261079SEd Maste	Banner /eee
55*19261079SEd Maste
56*19261079SEd MasteMatch Host f
57*19261079SEd Maste	Banner /fff
58*19261079SEd Maste_EOF
59*19261079SEd Maste
60*19261079SEd Mastecat > $OBJ/sshd_config.i.2 << _EOF
61*19261079SEd MasteMatch host a
62*19261079SEd Maste	Banner /aaaa
63*19261079SEd Maste
64*19261079SEd MasteMatch host b
65*19261079SEd Maste	Banner /bbbb
66*19261079SEd Maste
67*19261079SEd MasteMatch host c # comment
68*19261079SEd Maste	Banner /cccc
69*19261079SEd Maste
70*19261079SEd MasteMatch Host d
71*19261079SEd Maste	Banner /dddd
72*19261079SEd Maste
73*19261079SEd MasteMatch Host e
74*19261079SEd Maste	Banner /eeee
75*19261079SEd Maste
76*19261079SEd MasteMatch Host f
77*19261079SEd Maste	Banner /ffff
78*19261079SEd Maste
79*19261079SEd MasteMatch all
80*19261079SEd Maste	Banner /xxxx
81*19261079SEd Maste_EOF
82*19261079SEd Maste
83*19261079SEd Mastetrial() {
84*19261079SEd Maste	_host="$1"
85*19261079SEd Maste	_exp="$2"
86*19261079SEd Maste	_desc="$3"
87*19261079SEd Maste	test -z "$_desc" && _desc="test match"
88*19261079SEd Maste	trace "$_desc host=$_host expect=$_exp"
89*19261079SEd Maste	${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i -T \
90*19261079SEd Maste	    -C "host=$_host,user=test,addr=127.0.0.1" > $OBJ/sshd_config.out ||
91*19261079SEd Maste		fatal "ssh config parse failed: $_desc host=$_host expect=$_exp"
92*19261079SEd Maste	_got=`grep -i '^banner ' $OBJ/sshd_config.out | awk '{print $2}'`
93*19261079SEd Maste	if test "x$_exp" != "x$_got" ; then
94*19261079SEd Maste		fail "$desc_ host $_host include fail: expected $_exp got $_got"
95*19261079SEd Maste	fi
96*19261079SEd Maste}
97*19261079SEd Maste
98*19261079SEd Mastetrial a /aa
99*19261079SEd Mastetrial b /bb
100*19261079SEd Mastetrial c /ccc
101*19261079SEd Mastetrial d /dd
102*19261079SEd Mastetrial e /ee
103*19261079SEd Mastetrial f /fff
104*19261079SEd Mastetrial m /xxxx
105*19261079SEd Mastetrial n /xxxx
106*19261079SEd Mastetrial x none
107*19261079SEd Maste
108*19261079SEd Maste# Prepare an included config with an error.
109*19261079SEd Maste
110*19261079SEd Mastecat > $OBJ/sshd_config.i.3 << _EOF
111*19261079SEd MasteBanner xxxx
112*19261079SEd Maste	Junk
113*19261079SEd Maste_EOF
114*19261079SEd Maste
115*19261079SEd Mastetrace "disallow invalid config host=a"
116*19261079SEd Maste${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i \
117*19261079SEd Maste    -C "host=a,user=test,addr=127.0.0.1" 2>/dev/null && \
118*19261079SEd Maste	fail "sshd include allowed invalid config"
119*19261079SEd Maste
120*19261079SEd Mastetrace "disallow invalid config host=x"
121*19261079SEd Maste${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i \
122*19261079SEd Maste    -C "host=x,user=test,addr=127.0.0.1" 2>/dev/null && \
123*19261079SEd Maste	fail "sshd include allowed invalid config"
124*19261079SEd Maste
125*19261079SEd Masterm -f $OBJ/sshd_config.i.*
126*19261079SEd Maste
127*19261079SEd Maste# Ensure that a missing include is not fatal.
128*19261079SEd Mastecat > $OBJ/sshd_config.i << _EOF
129*19261079SEd MasteHostKey $OBJ/host.ssh-ed25519
130*19261079SEd MasteInclude $OBJ/sshd_config.i.*
131*19261079SEd MasteBanner /aa
132*19261079SEd Maste_EOF
133*19261079SEd Maste
134*19261079SEd Mastetrial a /aa "missing include non-fatal"
135*19261079SEd Maste
136*19261079SEd Maste# Ensure that Match/Host in an included config does not affect parent.
137*19261079SEd Mastecat > $OBJ/sshd_config.i.x << _EOF
138*19261079SEd MasteMatch host x
139*19261079SEd Maste_EOF
140*19261079SEd Maste
141*19261079SEd Mastetrial a /aa "included file does not affect match state"
142*19261079SEd Maste
143*19261079SEd Maste# Ensure the empty include directive is not accepted
144*19261079SEd Mastecat > $OBJ/sshd_config.i.x << _EOF
145*19261079SEd MasteInclude
146*19261079SEd Maste_EOF
147*19261079SEd Maste
148*19261079SEd Mastetrace "disallow invalid with no argument"
149*19261079SEd Maste${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i.x -T \
150*19261079SEd Maste    -C "host=x,user=test,addr=127.0.0.1" 2>/dev/null && \
151*19261079SEd Maste	fail "sshd allowed Include with no argument"
152*19261079SEd Maste
153*19261079SEd Maste# Ensure the Include before any Match block works as expected (bug #3122)
154*19261079SEd Mastecat > $OBJ/sshd_config.i << _EOF
155*19261079SEd MasteBanner /xx
156*19261079SEd MasteHostKey $OBJ/host.ssh-ed25519
157*19261079SEd MasteInclude $OBJ/sshd_config.i.2
158*19261079SEd MasteMatch host a
159*19261079SEd Maste	Banner /aaaa
160*19261079SEd Maste_EOF
161*19261079SEd Mastecat > $OBJ/sshd_config.i.2 << _EOF
162*19261079SEd MasteMatch host a
163*19261079SEd Maste	Banner /aa
164*19261079SEd Maste_EOF
165*19261079SEd Maste
166*19261079SEd Mastetrace "Include before match blocks"
167*19261079SEd Mastetrial a /aa "included file before match blocks is properly evaluated"
168*19261079SEd Maste
169*19261079SEd Maste# Port in included file is correctly interpretted (bug #3169)
170*19261079SEd Mastecat > $OBJ/sshd_config.i << _EOF
171*19261079SEd MasteInclude $OBJ/sshd_config.i.2
172*19261079SEd MastePort 7722
173*19261079SEd Maste_EOF
174*19261079SEd Mastecat > $OBJ/sshd_config.i.2 << _EOF
175*19261079SEd MasteHostKey $OBJ/host.ssh-ed25519
176*19261079SEd Maste_EOF
177*19261079SEd Maste
178*19261079SEd Mastetrace "Port after included files"
179*19261079SEd Maste${SUDO} ${REAL_SSHD} -f $OBJ/sshd_config.i -T \
180*19261079SEd Maste    -C "host=x,user=test,addr=127.0.0.1" > $OBJ/sshd_config.out || \
181*19261079SEd Maste	fail "failed to parse Port after included files"
182*19261079SEd Maste_port=`grep -i '^port ' $OBJ/sshd_config.out | awk '{print $2}'`
183*19261079SEd Masteif test "x7722" != "x$_port" ; then
184*19261079SEd Maste	fail "The Port in included file was intertepretted wrongly. Expected 7722, got $_port"
185*19261079SEd Mastefi
186*19261079SEd Maste
187*19261079SEd Maste# cleanup
188*19261079SEd Masterm -f $OBJ/sshd_config.i $OBJ/sshd_config.i.* $OBJ/sshd_config.out
189