]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - crypto/openssh/regress/cfginclude.sh
Upgrade OpenSSH to 7.3p1.
[FreeBSD/stable/10.git] / crypto / openssh / regress / cfginclude.sh
1 #       $OpenBSD: cfginclude.sh,v 1.2 2016/05/03 15:30:46 dtucker Exp $
2 #       Placed in the Public Domain.
3
4 tid="config include"
5
6 # to appease StrictModes
7 umask 022
8
9 cat > $OBJ/ssh_config.i << _EOF
10 Match host a
11         Hostname aa
12
13 Match host b
14         Hostname bb
15         Include $OBJ/ssh_config.i.*
16
17 Match host c
18         Include $OBJ/ssh_config.i.*
19         Hostname cc
20
21 Match host m
22         Include $OBJ/ssh_config.i.*
23
24 Host d
25         Hostname dd
26
27 Host e
28         Hostname ee
29         Include $OBJ/ssh_config.i.*
30
31 Host f
32         Include $OBJ/ssh_config.i.*
33         Hostname ff
34
35 Host n
36         Include $OBJ/ssh_config.i.*
37 _EOF
38
39 cat > $OBJ/ssh_config.i.0 << _EOF
40 Match host xxxxxx
41 _EOF
42
43 cat > $OBJ/ssh_config.i.1 << _EOF
44 Match host a
45         Hostname aaa
46
47 Match host b
48         Hostname bbb
49
50 Match host c
51         Hostname ccc
52
53 Host d
54         Hostname ddd
55
56 Host e
57         Hostname eee
58
59 Host f
60         Hostname fff
61 _EOF
62
63 cat > $OBJ/ssh_config.i.2 << _EOF
64 Match host a
65         Hostname aaaa
66
67 Match host b
68         Hostname bbbb
69
70 Match host c
71         Hostname cccc
72
73 Host d
74         Hostname dddd
75
76 Host e
77         Hostname eeee
78
79 Host f
80         Hostname ffff
81
82 Match all
83         Hostname xxxx
84 _EOF
85
86 trial() {
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
97 trial a aa
98 trial b bb
99 trial c ccc
100 trial d dd
101 trial e ee
102 trial f fff
103 trial m xxxx
104 trial n xxxx
105 trial x x
106
107 # Prepare an included config with an error.
108
109 cat > $OBJ/ssh_config.i.3 << _EOF
110 Hostname 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
120 rm -f $OBJ/ssh_config.i.*
121
122 # Ensure that a missing include is not fatal.
123 cat > $OBJ/ssh_config.i << _EOF
124 Include $OBJ/ssh_config.i.*
125 Hostname aa
126 _EOF
127
128 trial a aa
129
130 # Ensure that Match/Host in an included config does not affect parent.
131 cat > $OBJ/ssh_config.i.x << _EOF
132 Match host x
133 _EOF
134
135 trial a aa
136
137 cat > $OBJ/ssh_config.i.x << _EOF
138 Host x
139 _EOF
140
141 trial a aa
142
143 # cleanup
144 rm -f $OBJ/ssh_config.i $OBJ/ssh_config.i.* $OBJ/ssh_config.out
145 #       $OpenBSD: cfginclude.sh,v 1.2 2016/05/03 15:30:46 dtucker Exp $
146 #       Placed in the Public Domain.
147
148 tid="config include"
149
150 cat > $OBJ/ssh_config.i << _EOF
151 Match host a
152         Hostname aa
153
154 Match host b
155         Hostname bb
156         Include $OBJ/ssh_config.i.*
157
158 Match host c
159         Include $OBJ/ssh_config.i.*
160         Hostname cc
161
162 Match host m
163         Include $OBJ/ssh_config.i.*
164
165 Host d
166         Hostname dd
167
168 Host e
169         Hostname ee
170         Include $OBJ/ssh_config.i.*
171
172 Host f
173         Include $OBJ/ssh_config.i.*
174         Hostname ff
175
176 Host n
177         Include $OBJ/ssh_config.i.*
178 _EOF
179
180 cat > $OBJ/ssh_config.i.0 << _EOF
181 Match host xxxxxx
182 _EOF
183
184 cat > $OBJ/ssh_config.i.1 << _EOF
185 Match host a
186         Hostname aaa
187
188 Match host b
189         Hostname bbb
190
191 Match host c
192         Hostname ccc
193
194 Host d
195         Hostname ddd
196
197 Host e
198         Hostname eee
199
200 Host f
201         Hostname fff
202 _EOF
203
204 cat > $OBJ/ssh_config.i.2 << _EOF
205 Match host a
206         Hostname aaaa
207
208 Match host b
209         Hostname bbbb
210
211 Match host c
212         Hostname cccc
213
214 Host d
215         Hostname dddd
216
217 Host e
218         Hostname eeee
219
220 Host f
221         Hostname ffff
222
223 Match all
224         Hostname xxxx
225 _EOF
226
227 trial() {
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
238 trial a aa
239 trial b bb
240 trial c ccc
241 trial d dd
242 trial e ee
243 trial f fff
244 trial m xxxx
245 trial n xxxx
246 trial x x
247
248 # Prepare an included config with an error.
249
250 cat > $OBJ/ssh_config.i.3 << _EOF
251 Hostname 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
261 rm -f $OBJ/ssh_config.i.*
262
263 # Ensure that a missing include is not fatal.
264 cat > $OBJ/ssh_config.i << _EOF
265 Include $OBJ/ssh_config.i.*
266 Hostname aa
267 _EOF
268
269 trial a aa
270
271 # Ensure that Match/Host in an included config does not affect parent.
272 cat > $OBJ/ssh_config.i.x << _EOF
273 Match host x
274 _EOF
275
276 trial a aa
277
278 cat > $OBJ/ssh_config.i.x << _EOF
279 Host x
280 _EOF
281
282 trial a aa
283
284 # Ensure that recursive includes are bounded.
285 cat > $OBJ/ssh_config.i << _EOF
286 Include $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
293 rm -f $OBJ/ssh_config.i $OBJ/ssh_config.i.* $OBJ/ssh_config.out