xref: /freebsd/crypto/openssh/regress/cfginclude.sh (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1#	$OpenBSD: cfginclude.sh,v 1.3 2021/06/08 06:52:43 djm Exp $
2#	Placed in the Public Domain.
3
4tid="config include"
5
6# to appease StrictModes
7umask 022
8
9cat > $OBJ/ssh_config.i << _EOF
10Match host a
11	Hostname aa
12
13Match host b # comment
14	Hostname bb
15	Include $OBJ/ssh_config.i.*
16
17Match host c
18	Include $OBJ/ssh_config.i.*
19	Hostname cc
20
21Match host m
22	Include $OBJ/ssh_config.i.* # comment
23
24Host d
25	Hostname dd # comment
26
27Host e
28	Hostname ee
29	Include $OBJ/ssh_config.i.*
30
31Host f
32	Include $OBJ/ssh_config.i.*
33	Hostname ff
34
35Host n
36	Include $OBJ/ssh_config.i.*
37_EOF
38
39cat > $OBJ/ssh_config.i.0 << _EOF
40Match host xxxxxx
41_EOF
42
43cat > $OBJ/ssh_config.i.1 << _EOF
44Match host a
45	Hostname aaa
46
47Match host b
48	Hostname bbb
49
50Match host c # comment
51	Hostname ccc
52
53Host d # comment
54	Hostname ddd
55
56Host e
57	Hostname eee
58
59Host f
60	Hostname fff # comment
61_EOF
62
63cat > $OBJ/ssh_config.i.2 << _EOF
64Match host a
65	Hostname aaaa
66
67Match host b
68	Hostname bbbb
69
70Match host c
71	Hostname cccc
72
73Host d
74	Hostname dddd
75
76Host e
77	Hostname eeee
78
79Host f
80	Hostname ffff
81
82Match all
83	Hostname xxxx
84_EOF
85
86trial() {
87	_host="$1"
88	_exp="$2"
89	${REAL_SSH} -F $OBJ/ssh_config.i -G "$_host" > $OBJ/ssh_config.out ||
90		fatal "ssh config parse failed"
91	_got=`grep -i '^hostname ' $OBJ/ssh_config.out | awk '{print $2}'`
92	if test "x$_exp" != "x$_got" ; then
93		fail "host $_host include fail: expected $_exp got $_got"
94	fi
95}
96
97trial a aa
98trial b bb
99trial c ccc
100trial d dd
101trial e ee
102trial f fff
103trial m xxxx
104trial n xxxx
105trial x x
106
107# Prepare an included config with an error.
108
109cat > $OBJ/ssh_config.i.3 << _EOF
110Hostname xxxx
111	Junk
112_EOF
113
114${REAL_SSH} -F $OBJ/ssh_config.i -G a 2>/dev/null && \
115	fail "ssh include allowed invalid config"
116
117${REAL_SSH} -F $OBJ/ssh_config.i -G x 2>/dev/null && \
118	fail "ssh include allowed invalid config"
119
120rm -f $OBJ/ssh_config.i.*
121
122# Ensure that a missing include is not fatal.
123cat > $OBJ/ssh_config.i << _EOF
124Include $OBJ/ssh_config.i.*
125Hostname aa
126_EOF
127
128trial a aa
129
130# Ensure that Match/Host in an included config does not affect parent.
131cat > $OBJ/ssh_config.i.x << _EOF
132Match host x
133_EOF
134
135trial a aa
136
137cat > $OBJ/ssh_config.i.x << _EOF
138Host x
139_EOF
140
141trial a aa
142
143# cleanup
144rm -f $OBJ/ssh_config.i $OBJ/ssh_config.i.* $OBJ/ssh_config.out
145#	$OpenBSD: cfginclude.sh,v 1.3 2021/06/08 06:52:43 djm Exp $
146#	Placed in the Public Domain.
147
148tid="config include"
149
150cat > $OBJ/ssh_config.i << _EOF
151Match host a
152	Hostname aa
153
154Match host b
155	Hostname bb
156	Include $OBJ/ssh_config.i.*
157
158Match host c
159	Include $OBJ/ssh_config.i.*
160	Hostname cc
161
162Match host m
163	Include $OBJ/ssh_config.i.*
164
165Host d
166	Hostname dd
167
168Host e
169	Hostname ee
170	Include $OBJ/ssh_config.i.*
171
172Host f
173	Include $OBJ/ssh_config.i.*
174	Hostname ff
175
176Host n
177	Include $OBJ/ssh_config.i.*
178_EOF
179
180cat > $OBJ/ssh_config.i.0 << _EOF
181Match host xxxxxx
182_EOF
183
184cat > $OBJ/ssh_config.i.1 << _EOF
185Match host a
186	Hostname aaa
187
188Match host b # comment
189	Hostname bbb
190
191Match host c
192	Hostname ccc # comment
193
194Host d
195	Hostname ddd
196
197Host e
198	Hostname eee
199
200Host f
201	Hostname fff
202_EOF
203
204cat > $OBJ/ssh_config.i.2 << _EOF
205Match host a
206	Hostname aaaa
207
208Match host b
209	Hostname bbbb
210
211Match host c
212	Hostname cccc
213
214Host d
215	Hostname dddd
216
217Host e
218	Hostname eeee
219
220Host f
221	Hostname ffff
222
223Match all # comment
224	Hostname xxxx # comment
225_EOF
226
227trial() {
228	_host="$1"
229	_exp="$2"
230	${REAL_SSH} -F $OBJ/ssh_config.i -G "$_host" > $OBJ/ssh_config.out ||
231		fatal "ssh config parse failed"
232	_got=`grep -i '^hostname ' $OBJ/ssh_config.out | awk '{print $2}'`
233	if test "x$_exp" != "x$_got" ; then
234		fail "host $_host include fail: expected $_exp got $_got"
235	fi
236}
237
238trial a aa
239trial b bb
240trial c ccc
241trial d dd
242trial e ee
243trial f fff
244trial m xxxx
245trial n xxxx
246trial x x
247
248# Prepare an included config with an error.
249
250cat > $OBJ/ssh_config.i.3 << _EOF
251Hostname xxxx
252	Junk
253_EOF
254
255${REAL_SSH} -F $OBJ/ssh_config.i -G a 2>/dev/null && \
256	fail "ssh include allowed invalid config"
257
258${REAL_SSH} -F $OBJ/ssh_config.i -G x 2>/dev/null && \
259	fail "ssh include allowed invalid config"
260
261rm -f $OBJ/ssh_config.i.*
262
263# Ensure that a missing include is not fatal.
264cat > $OBJ/ssh_config.i << _EOF
265Include $OBJ/ssh_config.i.*
266Hostname aa
267_EOF
268
269trial a aa
270
271# Ensure that Match/Host in an included config does not affect parent.
272cat > $OBJ/ssh_config.i.x << _EOF
273Match host x
274_EOF
275
276trial a aa
277
278cat > $OBJ/ssh_config.i.x << _EOF
279Host x
280_EOF
281
282trial a aa
283
284# Ensure that recursive includes are bounded.
285cat > $OBJ/ssh_config.i << _EOF
286Include $OBJ/ssh_config.i
287_EOF
288
289${REAL_SSH} -F $OBJ/ssh_config.i -G a 2>/dev/null && \
290	fail "ssh include allowed infinite recursion?" # or hang...
291
292# cleanup
293rm -f $OBJ/ssh_config.i $OBJ/ssh_config.i.* $OBJ/ssh_config.out
294