cfginclude.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. # $OpenBSD: cfginclude.sh,v 1.2 2016/05/03 15:30:46 dtucker Exp $
  2. # Placed in the Public Domain.
  3. tid="config include"
  4. # to appease StrictModes
  5. umask 022
  6. cat > $OBJ/ssh_config.i << _EOF
  7. Match host a
  8. Hostname aa
  9. Match host b
  10. Hostname bb
  11. Include $OBJ/ssh_config.i.*
  12. Match host c
  13. Include $OBJ/ssh_config.i.*
  14. Hostname cc
  15. Match host m
  16. Include $OBJ/ssh_config.i.*
  17. Host d
  18. Hostname dd
  19. Host e
  20. Hostname ee
  21. Include $OBJ/ssh_config.i.*
  22. Host f
  23. Include $OBJ/ssh_config.i.*
  24. Hostname ff
  25. Host n
  26. Include $OBJ/ssh_config.i.*
  27. _EOF
  28. cat > $OBJ/ssh_config.i.0 << _EOF
  29. Match host xxxxxx
  30. _EOF
  31. cat > $OBJ/ssh_config.i.1 << _EOF
  32. Match host a
  33. Hostname aaa
  34. Match host b
  35. Hostname bbb
  36. Match host c
  37. Hostname ccc
  38. Host d
  39. Hostname ddd
  40. Host e
  41. Hostname eee
  42. Host f
  43. Hostname fff
  44. _EOF
  45. cat > $OBJ/ssh_config.i.2 << _EOF
  46. Match host a
  47. Hostname aaaa
  48. Match host b
  49. Hostname bbbb
  50. Match host c
  51. Hostname cccc
  52. Host d
  53. Hostname dddd
  54. Host e
  55. Hostname eeee
  56. Host f
  57. Hostname ffff
  58. Match all
  59. Hostname xxxx
  60. _EOF
  61. trial()
  62. {
  63. _host="$1"
  64. _exp="$2"
  65. ${REAL_SSH} -F $OBJ/ssh_config.i -G "$_host" > $OBJ/ssh_config.out ||
  66. fatal "ssh config parse failed"
  67. _got=$(grep -i '^hostname ' $OBJ/ssh_config.out | awk '{print $2}')
  68. if test "x$_exp" != "x$_got"; then
  69. fail "host $_host include fail: expected $_exp got $_got"
  70. fi
  71. }
  72. trial a aa
  73. trial b bb
  74. trial c ccc
  75. trial d dd
  76. trial e ee
  77. trial f fff
  78. trial m xxxx
  79. trial n xxxx
  80. trial x x
  81. # Prepare an included config with an error.
  82. cat > $OBJ/ssh_config.i.3 << _EOF
  83. Hostname xxxx
  84. Junk
  85. _EOF
  86. ${REAL_SSH} -F $OBJ/ssh_config.i -G a 2> /dev/null &&
  87. fail "ssh include allowed invalid config"
  88. ${REAL_SSH} -F $OBJ/ssh_config.i -G x 2> /dev/null &&
  89. fail "ssh include allowed invalid config"
  90. rm -f $OBJ/ssh_config.i.*
  91. # Ensure that a missing include is not fatal.
  92. cat > $OBJ/ssh_config.i << _EOF
  93. Include $OBJ/ssh_config.i.*
  94. Hostname aa
  95. _EOF
  96. trial a aa
  97. # Ensure that Match/Host in an included config does not affect parent.
  98. cat > $OBJ/ssh_config.i.x << _EOF
  99. Match host x
  100. _EOF
  101. trial a aa
  102. cat > $OBJ/ssh_config.i.x << _EOF
  103. Host x
  104. _EOF
  105. trial a aa
  106. # cleanup
  107. rm -f $OBJ/ssh_config.i $OBJ/ssh_config.i.* $OBJ/ssh_config.out
  108. # $OpenBSD: cfginclude.sh,v 1.2 2016/05/03 15:30:46 dtucker Exp $
  109. # Placed in the Public Domain.
  110. tid="config include"
  111. cat > $OBJ/ssh_config.i << _EOF
  112. Match host a
  113. Hostname aa
  114. Match host b
  115. Hostname bb
  116. Include $OBJ/ssh_config.i.*
  117. Match host c
  118. Include $OBJ/ssh_config.i.*
  119. Hostname cc
  120. Match host m
  121. Include $OBJ/ssh_config.i.*
  122. Host d
  123. Hostname dd
  124. Host e
  125. Hostname ee
  126. Include $OBJ/ssh_config.i.*
  127. Host f
  128. Include $OBJ/ssh_config.i.*
  129. Hostname ff
  130. Host n
  131. Include $OBJ/ssh_config.i.*
  132. _EOF
  133. cat > $OBJ/ssh_config.i.0 << _EOF
  134. Match host xxxxxx
  135. _EOF
  136. cat > $OBJ/ssh_config.i.1 << _EOF
  137. Match host a
  138. Hostname aaa
  139. Match host b
  140. Hostname bbb
  141. Match host c
  142. Hostname ccc
  143. Host d
  144. Hostname ddd
  145. Host e
  146. Hostname eee
  147. Host f
  148. Hostname fff
  149. _EOF
  150. cat > $OBJ/ssh_config.i.2 << _EOF
  151. Match host a
  152. Hostname aaaa
  153. Match host b
  154. Hostname bbbb
  155. Match host c
  156. Hostname cccc
  157. Host d
  158. Hostname dddd
  159. Host e
  160. Hostname eeee
  161. Host f
  162. Hostname ffff
  163. Match all
  164. Hostname xxxx
  165. _EOF
  166. trial()
  167. {
  168. _host="$1"
  169. _exp="$2"
  170. ${REAL_SSH} -F $OBJ/ssh_config.i -G "$_host" > $OBJ/ssh_config.out ||
  171. fatal "ssh config parse failed"
  172. _got=$(grep -i '^hostname ' $OBJ/ssh_config.out | awk '{print $2}')
  173. if test "x$_exp" != "x$_got"; then
  174. fail "host $_host include fail: expected $_exp got $_got"
  175. fi
  176. }
  177. trial a aa
  178. trial b bb
  179. trial c ccc
  180. trial d dd
  181. trial e ee
  182. trial f fff
  183. trial m xxxx
  184. trial n xxxx
  185. trial x x
  186. # Prepare an included config with an error.
  187. cat > $OBJ/ssh_config.i.3 << _EOF
  188. Hostname xxxx
  189. Junk
  190. _EOF
  191. ${REAL_SSH} -F $OBJ/ssh_config.i -G a 2> /dev/null &&
  192. fail "ssh include allowed invalid config"
  193. ${REAL_SSH} -F $OBJ/ssh_config.i -G x 2> /dev/null &&
  194. fail "ssh include allowed invalid config"
  195. rm -f $OBJ/ssh_config.i.*
  196. # Ensure that a missing include is not fatal.
  197. cat > $OBJ/ssh_config.i << _EOF
  198. Include $OBJ/ssh_config.i.*
  199. Hostname aa
  200. _EOF
  201. trial a aa
  202. # Ensure that Match/Host in an included config does not affect parent.
  203. cat > $OBJ/ssh_config.i.x << _EOF
  204. Match host x
  205. _EOF
  206. trial a aa
  207. cat > $OBJ/ssh_config.i.x << _EOF
  208. Host x
  209. _EOF
  210. trial a aa
  211. # Ensure that recursive includes are bounded.
  212. cat > $OBJ/ssh_config.i << _EOF
  213. Include $OBJ/ssh_config.i
  214. _EOF
  215. ${REAL_SSH} -F $OBJ/ssh_config.i -G a 2> /dev/null &&
  216. fail "ssh include allowed infinite recursion?" # or hang...
  217. # cleanup
  218. rm -f $OBJ/ssh_config.i $OBJ/ssh_config.i.* $OBJ/ssh_config.out