rugged 1.7.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/AUTHORS +1 -0
  4. data/vendor/libgit2/CMakeLists.txt +23 -10
  5. data/vendor/libgit2/COPYING +195 -1
  6. data/vendor/libgit2/cmake/{FindIconv.cmake → FindIntlIconv.cmake} +6 -0
  7. data/vendor/libgit2/cmake/FindLLHTTP.cmake +39 -0
  8. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +1 -1
  9. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +23 -8
  10. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +17 -8
  11. data/vendor/libgit2/cmake/SelectHashes.cmake +28 -11
  12. data/vendor/libgit2/cmake/SelectRegex.cmake +6 -1
  13. data/vendor/libgit2/cmake/SelectSSH.cmake +22 -17
  14. data/vendor/libgit2/cmake/SelectZlib.cmake +4 -0
  15. data/vendor/libgit2/deps/llhttp/CMakeLists.txt +8 -0
  16. data/vendor/libgit2/deps/llhttp/LICENSE-MIT +22 -0
  17. data/vendor/libgit2/deps/llhttp/api.c +510 -0
  18. data/vendor/libgit2/deps/llhttp/http.c +170 -0
  19. data/vendor/libgit2/deps/llhttp/llhttp.c +10168 -0
  20. data/vendor/libgit2/deps/llhttp/llhttp.h +897 -0
  21. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +1 -1
  22. data/vendor/libgit2/deps/ntlmclient/crypt_builtin_md4.c +311 -0
  23. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +2 -1
  24. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +0 -20
  25. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +4 -4
  26. data/vendor/libgit2/deps/ntlmclient/ntlm.c +21 -21
  27. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +5 -4
  28. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +2 -1
  29. data/vendor/libgit2/deps/ntlmclient/utf8.h +1176 -721
  30. data/vendor/libgit2/deps/ntlmclient/util.h +11 -0
  31. data/vendor/libgit2/deps/pcre/CMakeLists.txt +1 -0
  32. data/vendor/libgit2/deps/xdiff/xmerge.c +2 -2
  33. data/vendor/libgit2/deps/zlib/CMakeLists.txt +6 -1
  34. data/vendor/libgit2/deps/zlib/LICENSE +22 -0
  35. data/vendor/libgit2/deps/zlib/adler32.c +5 -27
  36. data/vendor/libgit2/deps/zlib/crc32.c +94 -167
  37. data/vendor/libgit2/deps/zlib/deflate.c +358 -435
  38. data/vendor/libgit2/deps/zlib/deflate.h +41 -10
  39. data/vendor/libgit2/deps/zlib/gzguts.h +13 -18
  40. data/vendor/libgit2/deps/zlib/infback.c +17 -30
  41. data/vendor/libgit2/deps/zlib/inffast.c +1 -4
  42. data/vendor/libgit2/deps/zlib/inffast.h +1 -1
  43. data/vendor/libgit2/deps/zlib/inflate.c +36 -102
  44. data/vendor/libgit2/deps/zlib/inftrees.c +6 -11
  45. data/vendor/libgit2/deps/zlib/inftrees.h +6 -6
  46. data/vendor/libgit2/deps/zlib/trees.c +287 -352
  47. data/vendor/libgit2/deps/zlib/zconf.h +23 -14
  48. data/vendor/libgit2/deps/zlib/zlib.h +202 -202
  49. data/vendor/libgit2/deps/zlib/zutil.c +18 -44
  50. data/vendor/libgit2/deps/zlib/zutil.h +13 -33
  51. data/vendor/libgit2/include/git2/annotated_commit.h +12 -5
  52. data/vendor/libgit2/include/git2/apply.h +27 -6
  53. data/vendor/libgit2/include/git2/attr.h +17 -4
  54. data/vendor/libgit2/include/git2/blame.h +133 -28
  55. data/vendor/libgit2/include/git2/blob.h +71 -28
  56. data/vendor/libgit2/include/git2/branch.h +22 -15
  57. data/vendor/libgit2/include/git2/buffer.h +6 -4
  58. data/vendor/libgit2/include/git2/cert.h +2 -1
  59. data/vendor/libgit2/include/git2/checkout.h +83 -32
  60. data/vendor/libgit2/include/git2/cherrypick.h +10 -3
  61. data/vendor/libgit2/include/git2/clone.h +25 -9
  62. data/vendor/libgit2/include/git2/commit.h +132 -3
  63. data/vendor/libgit2/include/git2/common.h +120 -63
  64. data/vendor/libgit2/include/git2/config.h +93 -23
  65. data/vendor/libgit2/include/git2/credential.h +30 -2
  66. data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
  67. data/vendor/libgit2/include/git2/deprecated.h +133 -3
  68. data/vendor/libgit2/include/git2/describe.h +13 -1
  69. data/vendor/libgit2/include/git2/diff.h +38 -8
  70. data/vendor/libgit2/include/git2/email.h +9 -29
  71. data/vendor/libgit2/include/git2/errors.h +46 -73
  72. data/vendor/libgit2/include/git2/filter.h +14 -7
  73. data/vendor/libgit2/include/git2/global.h +8 -1
  74. data/vendor/libgit2/include/git2/graph.h +3 -2
  75. data/vendor/libgit2/include/git2/ignore.h +10 -0
  76. data/vendor/libgit2/include/git2/index.h +99 -14
  77. data/vendor/libgit2/include/git2/indexer.h +21 -4
  78. data/vendor/libgit2/include/git2/mailmap.h +7 -1
  79. data/vendor/libgit2/include/git2/merge.h +46 -1
  80. data/vendor/libgit2/include/git2/message.h +2 -2
  81. data/vendor/libgit2/include/git2/net.h +3 -1
  82. data/vendor/libgit2/include/git2/notes.h +9 -6
  83. data/vendor/libgit2/include/git2/object.h +9 -8
  84. data/vendor/libgit2/include/git2/odb.h +91 -49
  85. data/vendor/libgit2/include/git2/odb_backend.h +80 -52
  86. data/vendor/libgit2/include/git2/oid.h +23 -24
  87. data/vendor/libgit2/include/git2/oidarray.h +7 -1
  88. data/vendor/libgit2/include/git2/pack.h +13 -1
  89. data/vendor/libgit2/include/git2/patch.h +2 -3
  90. data/vendor/libgit2/include/git2/pathspec.h +9 -0
  91. data/vendor/libgit2/include/git2/proxy.h +10 -0
  92. data/vendor/libgit2/include/git2/rebase.h +9 -6
  93. data/vendor/libgit2/include/git2/refdb.h +2 -2
  94. data/vendor/libgit2/include/git2/reflog.h +3 -2
  95. data/vendor/libgit2/include/git2/refs.h +9 -6
  96. data/vendor/libgit2/include/git2/refspec.h +14 -4
  97. data/vendor/libgit2/include/git2/remote.h +94 -18
  98. data/vendor/libgit2/include/git2/repository.h +57 -21
  99. data/vendor/libgit2/include/git2/reset.h +16 -3
  100. data/vendor/libgit2/include/git2/revert.h +9 -4
  101. data/vendor/libgit2/include/git2/revparse.h +3 -3
  102. data/vendor/libgit2/include/git2/revwalk.h +3 -2
  103. data/vendor/libgit2/include/git2/signature.h +46 -1
  104. data/vendor/libgit2/include/git2/stash.h +17 -3
  105. data/vendor/libgit2/include/git2/status.h +10 -6
  106. data/vendor/libgit2/include/git2/stdint.h +87 -85
  107. data/vendor/libgit2/include/git2/strarray.h +2 -3
  108. data/vendor/libgit2/include/git2/submodule.h +20 -9
  109. data/vendor/libgit2/include/git2/sys/alloc.h +12 -0
  110. data/vendor/libgit2/include/git2/sys/commit.h +77 -3
  111. data/vendor/libgit2/include/git2/sys/commit_graph.h +103 -62
  112. data/vendor/libgit2/include/git2/sys/config.h +80 -4
  113. data/vendor/libgit2/include/git2/sys/credential.h +4 -3
  114. data/vendor/libgit2/include/git2/sys/diff.h +21 -1
  115. data/vendor/libgit2/include/git2/sys/email.h +7 -0
  116. data/vendor/libgit2/include/git2/sys/errors.h +76 -0
  117. data/vendor/libgit2/include/git2/sys/filter.h +66 -3
  118. data/vendor/libgit2/include/git2/sys/hashsig.h +11 -0
  119. data/vendor/libgit2/include/git2/sys/index.h +3 -2
  120. data/vendor/libgit2/include/git2/sys/mempack.h +32 -2
  121. data/vendor/libgit2/include/git2/sys/merge.h +55 -7
  122. data/vendor/libgit2/include/git2/sys/midx.h +43 -4
  123. data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -3
  124. data/vendor/libgit2/include/git2/sys/openssl.h +8 -1
  125. data/vendor/libgit2/include/git2/sys/path.h +12 -1
  126. data/vendor/libgit2/include/git2/sys/refdb_backend.h +40 -36
  127. data/vendor/libgit2/include/git2/sys/refs.h +3 -2
  128. data/vendor/libgit2/include/git2/sys/remote.h +8 -1
  129. data/vendor/libgit2/include/git2/sys/repository.h +63 -3
  130. data/vendor/libgit2/include/git2/sys/stream.h +11 -2
  131. data/vendor/libgit2/include/git2/sys/transport.h +24 -3
  132. data/vendor/libgit2/include/git2/tag.h +3 -1
  133. data/vendor/libgit2/include/git2/trace.h +9 -3
  134. data/vendor/libgit2/include/git2/transaction.h +3 -2
  135. data/vendor/libgit2/include/git2/transport.h +11 -3
  136. data/vendor/libgit2/include/git2/tree.h +16 -5
  137. data/vendor/libgit2/include/git2/types.h +19 -3
  138. data/vendor/libgit2/include/git2/version.h +44 -8
  139. data/vendor/libgit2/include/git2/worktree.h +16 -6
  140. data/vendor/libgit2/src/CMakeLists.txt +6 -4
  141. data/vendor/libgit2/src/cli/CMakeLists.txt +2 -2
  142. data/vendor/libgit2/src/cli/cmd.c +1 -1
  143. data/vendor/libgit2/src/cli/cmd.h +4 -0
  144. data/vendor/libgit2/src/cli/cmd_blame.c +287 -0
  145. data/vendor/libgit2/src/cli/cmd_cat_file.c +6 -8
  146. data/vendor/libgit2/src/cli/cmd_clone.c +5 -7
  147. data/vendor/libgit2/src/cli/cmd_config.c +241 -0
  148. data/vendor/libgit2/src/cli/cmd_hash_object.c +6 -8
  149. data/vendor/libgit2/src/cli/cmd_help.c +6 -7
  150. data/vendor/libgit2/src/cli/cmd_index_pack.c +114 -0
  151. data/vendor/libgit2/src/cli/cmd_init.c +102 -0
  152. data/vendor/libgit2/src/cli/common.c +168 -0
  153. data/vendor/libgit2/src/cli/common.h +63 -0
  154. data/vendor/libgit2/src/cli/error.h +1 -1
  155. data/vendor/libgit2/src/cli/main.c +52 -24
  156. data/vendor/libgit2/src/cli/opt.c +29 -3
  157. data/vendor/libgit2/src/cli/opt.h +21 -3
  158. data/vendor/libgit2/src/cli/opt_usage.c +102 -33
  159. data/vendor/libgit2/src/cli/opt_usage.h +6 -1
  160. data/vendor/libgit2/src/cli/progress.c +51 -2
  161. data/vendor/libgit2/src/cli/progress.h +12 -0
  162. data/vendor/libgit2/src/cli/unix/sighandler.c +2 -1
  163. data/vendor/libgit2/src/cli/win32/precompiled.h +1 -1
  164. data/vendor/libgit2/src/cli/win32/sighandler.c +1 -1
  165. data/vendor/libgit2/src/libgit2/CMakeLists.txt +26 -8
  166. data/vendor/libgit2/src/libgit2/apply.c +10 -13
  167. data/vendor/libgit2/src/libgit2/attr.c +30 -13
  168. data/vendor/libgit2/src/libgit2/attr_file.c +7 -2
  169. data/vendor/libgit2/src/libgit2/attr_file.h +2 -0
  170. data/vendor/libgit2/src/libgit2/attrcache.c +69 -33
  171. data/vendor/libgit2/src/libgit2/attrcache.h +5 -9
  172. data/vendor/libgit2/src/libgit2/blame.c +130 -44
  173. data/vendor/libgit2/src/libgit2/blame.h +1 -0
  174. data/vendor/libgit2/src/libgit2/cache.c +22 -17
  175. data/vendor/libgit2/src/libgit2/cache.h +7 -9
  176. data/vendor/libgit2/src/libgit2/checkout.c +34 -24
  177. data/vendor/libgit2/src/libgit2/checkout.h +0 -2
  178. data/vendor/libgit2/src/libgit2/cherrypick.c +1 -2
  179. data/vendor/libgit2/src/libgit2/clone.c +186 -166
  180. data/vendor/libgit2/src/libgit2/clone.h +4 -1
  181. data/vendor/libgit2/src/libgit2/commit.c +92 -0
  182. data/vendor/libgit2/src/libgit2/commit_graph.c +67 -56
  183. data/vendor/libgit2/src/libgit2/commit_graph.h +1 -2
  184. data/vendor/libgit2/src/libgit2/config.c +389 -298
  185. data/vendor/libgit2/src/libgit2/config.cmake.in +3 -0
  186. data/vendor/libgit2/src/libgit2/config.h +9 -4
  187. data/vendor/libgit2/src/libgit2/config_backend.h +8 -10
  188. data/vendor/libgit2/src/libgit2/config_cache.c +4 -5
  189. data/vendor/libgit2/src/libgit2/config_file.c +99 -88
  190. data/vendor/libgit2/src/libgit2/config_list.c +285 -0
  191. data/vendor/libgit2/src/libgit2/config_list.h +32 -0
  192. data/vendor/libgit2/src/libgit2/config_mem.c +194 -40
  193. data/vendor/libgit2/src/libgit2/config_parse.c +10 -9
  194. data/vendor/libgit2/src/libgit2/config_snapshot.c +24 -31
  195. data/vendor/libgit2/src/libgit2/describe.c +24 -24
  196. data/vendor/libgit2/src/libgit2/diff.c +1 -1
  197. data/vendor/libgit2/src/libgit2/diff_driver.c +12 -19
  198. data/vendor/libgit2/src/libgit2/diff_driver.h +2 -2
  199. data/vendor/libgit2/src/libgit2/diff_generate.c +3 -3
  200. data/vendor/libgit2/src/libgit2/diff_parse.c +2 -2
  201. data/vendor/libgit2/src/libgit2/diff_print.c +65 -9
  202. data/vendor/libgit2/src/libgit2/diff_tform.c +36 -8
  203. data/vendor/libgit2/src/libgit2/email.c +1 -0
  204. data/vendor/libgit2/src/libgit2/fetch.c +5 -3
  205. data/vendor/libgit2/src/libgit2/filter.c +5 -5
  206. data/vendor/libgit2/src/libgit2/git2.rc +3 -3
  207. data/vendor/libgit2/src/libgit2/grafts.c +18 -20
  208. data/vendor/libgit2/src/libgit2/grafts.h +0 -1
  209. data/vendor/libgit2/src/libgit2/graph.c +1 -1
  210. data/vendor/libgit2/src/libgit2/hashmap_oid.h +30 -0
  211. data/vendor/libgit2/src/libgit2/ignore.c +9 -5
  212. data/vendor/libgit2/src/libgit2/index.c +68 -90
  213. data/vendor/libgit2/src/libgit2/index.h +2 -2
  214. data/vendor/libgit2/src/libgit2/index_map.c +95 -0
  215. data/vendor/libgit2/src/libgit2/index_map.h +28 -0
  216. data/vendor/libgit2/src/libgit2/indexer.c +34 -38
  217. data/vendor/libgit2/src/libgit2/iterator.c +14 -8
  218. data/vendor/libgit2/src/libgit2/libgit2.c +153 -368
  219. data/vendor/libgit2/src/libgit2/mailmap.c +1 -1
  220. data/vendor/libgit2/src/libgit2/merge.c +42 -37
  221. data/vendor/libgit2/src/libgit2/merge_driver.c +2 -2
  222. data/vendor/libgit2/src/libgit2/midx.c +28 -15
  223. data/vendor/libgit2/src/libgit2/mwindow.c +38 -45
  224. data/vendor/libgit2/src/libgit2/mwindow.h +4 -0
  225. data/vendor/libgit2/src/libgit2/object.c +6 -5
  226. data/vendor/libgit2/src/libgit2/odb.c +5 -4
  227. data/vendor/libgit2/src/libgit2/odb_mempack.c +49 -17
  228. data/vendor/libgit2/src/libgit2/odb_pack.c +13 -5
  229. data/vendor/libgit2/src/libgit2/oid.c +32 -5
  230. data/vendor/libgit2/src/libgit2/oid.h +11 -0
  231. data/vendor/libgit2/src/libgit2/pack-objects.c +58 -31
  232. data/vendor/libgit2/src/libgit2/pack-objects.h +12 -4
  233. data/vendor/libgit2/src/libgit2/pack.c +30 -24
  234. data/vendor/libgit2/src/libgit2/pack.h +15 -10
  235. data/vendor/libgit2/src/libgit2/patch_parse.c +2 -2
  236. data/vendor/libgit2/src/libgit2/path.c +1 -1
  237. data/vendor/libgit2/src/libgit2/pathspec.c +1 -1
  238. data/vendor/libgit2/src/libgit2/push.c +79 -28
  239. data/vendor/libgit2/src/libgit2/push.h +1 -0
  240. data/vendor/libgit2/src/libgit2/refdb_fs.c +128 -61
  241. data/vendor/libgit2/src/libgit2/reflog.c +1 -2
  242. data/vendor/libgit2/src/libgit2/reflog.h +2 -0
  243. data/vendor/libgit2/src/libgit2/refs.c +26 -7
  244. data/vendor/libgit2/src/libgit2/refs.h +6 -1
  245. data/vendor/libgit2/src/libgit2/refspec.c +28 -1
  246. data/vendor/libgit2/src/libgit2/refspec.h +8 -0
  247. data/vendor/libgit2/src/libgit2/remote.c +121 -61
  248. data/vendor/libgit2/src/libgit2/repository.c +231 -51
  249. data/vendor/libgit2/src/libgit2/repository.h +10 -6
  250. data/vendor/libgit2/src/libgit2/revert.c +1 -2
  251. data/vendor/libgit2/src/libgit2/revparse.c +2 -2
  252. data/vendor/libgit2/src/libgit2/revwalk.c +13 -10
  253. data/vendor/libgit2/src/libgit2/revwalk.h +3 -3
  254. data/vendor/libgit2/src/libgit2/settings.c +468 -0
  255. data/vendor/libgit2/src/libgit2/settings.h +6 -2
  256. data/vendor/libgit2/src/libgit2/signature.c +132 -15
  257. data/vendor/libgit2/src/libgit2/signature.h +0 -1
  258. data/vendor/libgit2/src/libgit2/status.c +1 -1
  259. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +54 -60
  260. data/vendor/libgit2/src/libgit2/streams/openssl.c +32 -7
  261. data/vendor/libgit2/src/libgit2/streams/openssl.h +2 -0
  262. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +4 -0
  263. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.h +3 -0
  264. data/vendor/libgit2/src/libgit2/streams/stransport.c +39 -7
  265. data/vendor/libgit2/src/libgit2/submodule.c +106 -63
  266. data/vendor/libgit2/src/libgit2/submodule.h +6 -7
  267. data/vendor/libgit2/src/libgit2/tag.c +1 -1
  268. data/vendor/libgit2/src/libgit2/trailer.c +6 -6
  269. data/vendor/libgit2/src/libgit2/transaction.c +26 -20
  270. data/vendor/libgit2/src/libgit2/transaction.h +4 -1
  271. data/vendor/libgit2/src/libgit2/transport.c +4 -1
  272. data/vendor/libgit2/src/libgit2/transports/credential.c +1 -1
  273. data/vendor/libgit2/src/libgit2/transports/http.c +1 -2
  274. data/vendor/libgit2/src/libgit2/transports/http.h +0 -10
  275. data/vendor/libgit2/src/libgit2/transports/httpclient.c +112 -72
  276. data/vendor/libgit2/src/libgit2/transports/httpparser.c +128 -0
  277. data/vendor/libgit2/src/libgit2/transports/httpparser.h +99 -0
  278. data/vendor/libgit2/src/libgit2/transports/local.c +8 -7
  279. data/vendor/libgit2/src/libgit2/transports/smart.c +20 -8
  280. data/vendor/libgit2/src/libgit2/transports/smart.h +4 -2
  281. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +2 -2
  282. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +55 -10
  283. data/vendor/libgit2/src/libgit2/transports/ssh.c +41 -1103
  284. data/vendor/libgit2/src/libgit2/transports/ssh_exec.c +347 -0
  285. data/vendor/libgit2/src/libgit2/transports/ssh_exec.h +26 -0
  286. data/vendor/libgit2/src/libgit2/transports/ssh_libssh2.c +1126 -0
  287. data/vendor/libgit2/src/libgit2/transports/ssh_libssh2.h +28 -0
  288. data/vendor/libgit2/src/libgit2/transports/winhttp.c +35 -7
  289. data/vendor/libgit2/src/libgit2/tree.c +34 -26
  290. data/vendor/libgit2/src/libgit2/tree.h +3 -2
  291. data/vendor/libgit2/src/libgit2/worktree.c +14 -17
  292. data/vendor/libgit2/src/util/CMakeLists.txt +4 -6
  293. data/vendor/libgit2/src/util/alloc.c +4 -1
  294. data/vendor/libgit2/src/util/allocators/debugalloc.c +73 -0
  295. data/vendor/libgit2/src/{cli/cli.h → util/allocators/debugalloc.h} +6 -9
  296. data/vendor/libgit2/src/util/allocators/stdalloc.c +0 -10
  297. data/vendor/libgit2/src/util/array.h +18 -17
  298. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  299. data/vendor/libgit2/src/util/ctype_compat.h +70 -0
  300. data/vendor/libgit2/src/util/date.c +22 -14
  301. data/vendor/libgit2/src/util/date.h +12 -0
  302. data/vendor/libgit2/src/util/errors.c +401 -0
  303. data/vendor/libgit2/src/{libgit2 → util}/errors.h +21 -17
  304. data/vendor/libgit2/src/util/fs_path.c +15 -4
  305. data/vendor/libgit2/src/util/fs_path.h +23 -0
  306. data/vendor/libgit2/src/util/futils.c +6 -5
  307. data/vendor/libgit2/src/util/futils.h +13 -4
  308. data/vendor/libgit2/src/util/git2_features.h.in +12 -1
  309. data/vendor/libgit2/src/util/git2_util.h +6 -0
  310. data/vendor/libgit2/src/util/hash/openssl.c +152 -0
  311. data/vendor/libgit2/src/util/hash/openssl.h +17 -1
  312. data/vendor/libgit2/src/util/hash/sha.h +4 -1
  313. data/vendor/libgit2/src/util/hashmap.h +424 -0
  314. data/vendor/libgit2/src/util/hashmap_str.h +43 -0
  315. data/vendor/libgit2/src/util/integer.h +3 -1
  316. data/vendor/libgit2/src/util/net.c +13 -7
  317. data/vendor/libgit2/src/util/net.h +2 -0
  318. data/vendor/libgit2/src/util/pool.c +1 -1
  319. data/vendor/libgit2/src/util/pool.h +5 -0
  320. data/vendor/libgit2/src/util/pqueue.h +1 -1
  321. data/vendor/libgit2/src/util/process.h +222 -0
  322. data/vendor/libgit2/src/util/rand.c +1 -7
  323. data/vendor/libgit2/src/util/regexp.c +1 -1
  324. data/vendor/libgit2/src/util/sortedcache.c +14 -13
  325. data/vendor/libgit2/src/util/sortedcache.h +3 -3
  326. data/vendor/libgit2/src/util/str.c +2 -2
  327. data/vendor/libgit2/src/util/strlist.c +108 -0
  328. data/vendor/libgit2/src/util/strlist.h +36 -0
  329. data/vendor/libgit2/src/util/unix/posix.h +0 -2
  330. data/vendor/libgit2/src/util/unix/process.c +629 -0
  331. data/vendor/libgit2/src/util/unix/realpath.c +23 -5
  332. data/vendor/libgit2/src/util/util.c +2 -2
  333. data/vendor/libgit2/src/util/util.h +4 -38
  334. data/vendor/libgit2/src/util/vector.c +3 -3
  335. data/vendor/libgit2/src/util/vector.h +2 -2
  336. data/vendor/libgit2/src/util/win32/posix_w32.c +29 -6
  337. data/vendor/libgit2/src/util/win32/process.c +506 -0
  338. metadata +45 -28
  339. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -6
  340. data/vendor/libgit2/deps/http-parser/COPYING +0 -23
  341. data/vendor/libgit2/deps/http-parser/http_parser.c +0 -2182
  342. data/vendor/libgit2/deps/http-parser/http_parser.h +0 -305
  343. data/vendor/libgit2/deps/zlib/COPYING +0 -27
  344. data/vendor/libgit2/include/git2/sys/reflog.h +0 -21
  345. data/vendor/libgit2/src/libgit2/config_entries.c +0 -237
  346. data/vendor/libgit2/src/libgit2/config_entries.h +0 -24
  347. data/vendor/libgit2/src/libgit2/errors.c +0 -293
  348. data/vendor/libgit2/src/libgit2/idxmap.c +0 -157
  349. data/vendor/libgit2/src/libgit2/idxmap.h +0 -177
  350. data/vendor/libgit2/src/libgit2/libgit2.h +0 -15
  351. data/vendor/libgit2/src/libgit2/offmap.c +0 -101
  352. data/vendor/libgit2/src/libgit2/offmap.h +0 -133
  353. data/vendor/libgit2/src/libgit2/oidmap.c +0 -107
  354. data/vendor/libgit2/src/libgit2/oidmap.h +0 -128
  355. data/vendor/libgit2/src/libgit2/threadstate.c +0 -97
  356. data/vendor/libgit2/src/libgit2/threadstate.h +0 -22
  357. data/vendor/libgit2/src/libgit2/transports/ssh.h +0 -14
  358. data/vendor/libgit2/src/util/khash.h +0 -615
  359. data/vendor/libgit2/src/util/strmap.c +0 -100
  360. data/vendor/libgit2/src/util/strmap.h +0 -131
  361. /data/vendor/libgit2/cmake/{FindHTTPParser.cmake → FindHTTP_Parser.cmake} +0 -0
@@ -5,1090 +5,67 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
 
8
- #include "ssh.h"
8
+ #include "ssh_exec.h"
9
+ #include "ssh_libssh2.h"
9
10
 
10
- #ifdef GIT_SSH
11
- #include <libssh2.h>
12
- #endif
13
-
14
- #include "runtime.h"
15
- #include "net.h"
16
- #include "smart.h"
17
- #include "streams/socket.h"
18
- #include "sysdir.h"
19
-
20
- #include "git2/credential.h"
21
- #include "git2/sys/credential.h"
22
-
23
- #ifdef GIT_SSH
24
-
25
- #define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport)
26
-
27
- static const char cmd_uploadpack[] = "git-upload-pack";
28
- static const char cmd_receivepack[] = "git-receive-pack";
29
-
30
- typedef struct {
31
- git_smart_subtransport_stream parent;
32
- git_stream *io;
33
- LIBSSH2_SESSION *session;
34
- LIBSSH2_CHANNEL *channel;
35
- const char *cmd;
36
- git_net_url url;
37
- unsigned sent_command : 1;
38
- } ssh_stream;
39
-
40
- typedef struct {
41
- git_smart_subtransport parent;
42
- transport_smart *owner;
43
- ssh_stream *current_stream;
44
- git_credential *cred;
45
- char *cmd_uploadpack;
46
- char *cmd_receivepack;
47
- } ssh_subtransport;
48
-
49
- static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *username);
50
-
51
- static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg)
52
- {
53
- char *ssherr;
54
- libssh2_session_last_error(session, &ssherr, NULL, 0);
55
-
56
- git_error_set(GIT_ERROR_SSH, "%s: %s", errmsg, ssherr);
57
- }
58
-
59
- /*
60
- * Create a git protocol request.
61
- *
62
- * For example: git-upload-pack '/libgit2/libgit2'
63
- */
64
- static int gen_proto(git_str *request, const char *cmd, git_net_url *url)
65
- {
66
- const char *repo;
67
-
68
- repo = url->path;
69
-
70
- if (repo && repo[0] == '/' && repo[1] == '~')
71
- repo++;
72
-
73
- if (!repo || !repo[0]) {
74
- git_error_set(GIT_ERROR_NET, "malformed git protocol URL");
75
- return -1;
76
- }
77
-
78
- git_str_puts(request, cmd);
79
- git_str_puts(request, " '");
80
- git_str_puts(request, repo);
81
- git_str_puts(request, "'");
82
-
83
- if (git_str_oom(request))
84
- return -1;
85
-
86
- return 0;
87
- }
88
-
89
- static int send_command(ssh_stream *s)
90
- {
91
- int error;
92
- git_str request = GIT_STR_INIT;
93
-
94
- error = gen_proto(&request, s->cmd, &s->url);
95
- if (error < 0)
96
- goto cleanup;
97
-
98
- error = libssh2_channel_exec(s->channel, request.ptr);
99
- if (error < LIBSSH2_ERROR_NONE) {
100
- ssh_error(s->session, "SSH could not execute request");
101
- goto cleanup;
102
- }
103
-
104
- s->sent_command = 1;
105
-
106
- cleanup:
107
- git_str_dispose(&request);
108
- return error;
109
- }
110
-
111
- static int ssh_stream_read(
112
- git_smart_subtransport_stream *stream,
113
- char *buffer,
114
- size_t buf_size,
115
- size_t *bytes_read)
116
- {
117
- int rc;
118
- ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
119
-
120
- *bytes_read = 0;
121
-
122
- if (!s->sent_command && send_command(s) < 0)
123
- return -1;
124
-
125
- if ((rc = libssh2_channel_read(s->channel, buffer, buf_size)) < LIBSSH2_ERROR_NONE) {
126
- ssh_error(s->session, "SSH could not read data");
127
- return -1;
128
- }
129
-
130
- /*
131
- * If we can't get anything out of stdout, it's typically a
132
- * not-found error, so read from stderr and signal EOF on
133
- * stderr.
134
- */
135
- if (rc == 0) {
136
- if ((rc = libssh2_channel_read_stderr(s->channel, buffer, buf_size)) > 0) {
137
- git_error_set(GIT_ERROR_SSH, "%*s", rc, buffer);
138
- return GIT_EEOF;
139
- } else if (rc < LIBSSH2_ERROR_NONE) {
140
- ssh_error(s->session, "SSH could not read stderr");
141
- return -1;
142
- }
143
- }
144
-
145
-
146
- *bytes_read = rc;
147
-
148
- return 0;
149
- }
150
-
151
- static int ssh_stream_write(
152
- git_smart_subtransport_stream *stream,
153
- const char *buffer,
154
- size_t len)
155
- {
156
- ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
157
- size_t off = 0;
158
- ssize_t ret = 0;
159
-
160
- if (!s->sent_command && send_command(s) < 0)
161
- return -1;
162
-
163
- do {
164
- ret = libssh2_channel_write(s->channel, buffer + off, len - off);
165
- if (ret < 0)
166
- break;
167
-
168
- off += ret;
169
-
170
- } while (off < len);
171
-
172
- if (ret < 0) {
173
- ssh_error(s->session, "SSH could not write data");
174
- return -1;
175
- }
176
-
177
- return 0;
178
- }
179
-
180
- static void ssh_stream_free(git_smart_subtransport_stream *stream)
181
- {
182
- ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
183
- ssh_subtransport *t;
184
-
185
- if (!stream)
186
- return;
187
-
188
- t = OWNING_SUBTRANSPORT(s);
189
- t->current_stream = NULL;
190
-
191
- if (s->channel) {
192
- libssh2_channel_close(s->channel);
193
- libssh2_channel_free(s->channel);
194
- s->channel = NULL;
195
- }
196
-
197
- if (s->session) {
198
- libssh2_session_disconnect(s->session, "closing transport");
199
- libssh2_session_free(s->session);
200
- s->session = NULL;
201
- }
202
-
203
- if (s->io) {
204
- git_stream_close(s->io);
205
- git_stream_free(s->io);
206
- s->io = NULL;
207
- }
208
-
209
- git_net_url_dispose(&s->url);
210
- git__free(s);
211
- }
212
-
213
- static int ssh_stream_alloc(
214
- ssh_subtransport *t,
215
- const char *cmd,
216
- git_smart_subtransport_stream **stream)
217
- {
218
- ssh_stream *s;
219
-
220
- GIT_ASSERT_ARG(stream);
221
-
222
- s = git__calloc(sizeof(ssh_stream), 1);
223
- GIT_ERROR_CHECK_ALLOC(s);
224
-
225
- s->parent.subtransport = &t->parent;
226
- s->parent.read = ssh_stream_read;
227
- s->parent.write = ssh_stream_write;
228
- s->parent.free = ssh_stream_free;
229
-
230
- s->cmd = cmd;
231
-
232
- *stream = &s->parent;
233
- return 0;
234
- }
235
-
236
- static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) {
237
- int rc = LIBSSH2_ERROR_NONE;
238
-
239
- struct libssh2_agent_publickey *curr, *prev = NULL;
240
-
241
- LIBSSH2_AGENT *agent = libssh2_agent_init(session);
242
-
243
- if (agent == NULL)
244
- return -1;
245
-
246
- rc = libssh2_agent_connect(agent);
247
-
248
- if (rc != LIBSSH2_ERROR_NONE) {
249
- rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
250
- goto shutdown;
251
- }
252
-
253
- rc = libssh2_agent_list_identities(agent);
254
-
255
- if (rc != LIBSSH2_ERROR_NONE)
256
- goto shutdown;
257
-
258
- while (1) {
259
- rc = libssh2_agent_get_identity(agent, &curr, prev);
260
-
261
- if (rc < 0)
262
- goto shutdown;
11
+ #include "transports/smart.h"
263
12
 
264
- /* rc is set to 1 whenever the ssh agent ran out of keys to check.
265
- * Set the error code to authentication failure rather than erroring
266
- * out with an untranslatable error code.
267
- */
268
- if (rc == 1) {
269
- rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
270
- goto shutdown;
271
- }
272
-
273
- rc = libssh2_agent_userauth(agent, c->username, curr);
274
-
275
- if (rc == 0)
276
- break;
277
-
278
- prev = curr;
279
- }
280
-
281
- shutdown:
282
-
283
- if (rc != LIBSSH2_ERROR_NONE)
284
- ssh_error(session, "error authenticating");
285
-
286
- libssh2_agent_disconnect(agent);
287
- libssh2_agent_free(agent);
288
-
289
- return rc;
290
- }
291
-
292
- static int _git_ssh_authenticate_session(
293
- LIBSSH2_SESSION *session,
294
- git_credential *cred)
295
- {
296
- int rc;
297
-
298
- do {
299
- git_error_clear();
300
- switch (cred->credtype) {
301
- case GIT_CREDENTIAL_USERPASS_PLAINTEXT: {
302
- git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
303
- rc = libssh2_userauth_password(session, c->username, c->password);
304
- break;
305
- }
306
- case GIT_CREDENTIAL_SSH_KEY: {
307
- git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
308
-
309
- if (c->privatekey)
310
- rc = libssh2_userauth_publickey_fromfile(
311
- session, c->username, c->publickey,
312
- c->privatekey, c->passphrase);
313
- else
314
- rc = ssh_agent_auth(session, c);
315
-
316
- break;
317
- }
318
- case GIT_CREDENTIAL_SSH_CUSTOM: {
319
- git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred;
320
-
321
- rc = libssh2_userauth_publickey(
322
- session, c->username, (const unsigned char *)c->publickey,
323
- c->publickey_len, c->sign_callback, &c->payload);
324
- break;
325
- }
326
- case GIT_CREDENTIAL_SSH_INTERACTIVE: {
327
- void **abstract = libssh2_session_abstract(session);
328
- git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred;
329
-
330
- /* ideally, we should be able to set this by calling
331
- * libssh2_session_init_ex() instead of libssh2_session_init().
332
- * libssh2's API is inconsistent here i.e. libssh2_userauth_publickey()
333
- * allows you to pass the `abstract` as part of the call, whereas
334
- * libssh2_userauth_keyboard_interactive() does not!
335
- *
336
- * The only way to set the `abstract` pointer is by calling
337
- * libssh2_session_abstract(), which will replace the existing
338
- * pointer as is done below. This is safe for now (at time of writing),
339
- * but may not be valid in future.
340
- */
341
- *abstract = c->payload;
342
-
343
- rc = libssh2_userauth_keyboard_interactive(
344
- session, c->username, c->prompt_callback);
345
- break;
346
- }
347
- #ifdef GIT_SSH_MEMORY_CREDENTIALS
348
- case GIT_CREDENTIAL_SSH_MEMORY: {
349
- git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
350
-
351
- GIT_ASSERT(c->username);
352
- GIT_ASSERT(c->privatekey);
353
-
354
- rc = libssh2_userauth_publickey_frommemory(
355
- session,
356
- c->username,
357
- strlen(c->username),
358
- c->publickey,
359
- c->publickey ? strlen(c->publickey) : 0,
360
- c->privatekey,
361
- strlen(c->privatekey),
362
- c->passphrase);
363
- break;
364
- }
365
- #endif
366
- default:
367
- rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
368
- }
369
- } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
370
-
371
- if (rc == LIBSSH2_ERROR_PASSWORD_EXPIRED ||
372
- rc == LIBSSH2_ERROR_AUTHENTICATION_FAILED ||
373
- rc == LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED)
374
- return GIT_EAUTH;
375
-
376
- if (rc != LIBSSH2_ERROR_NONE) {
377
- if (!git_error_last())
378
- ssh_error(session, "Failed to authenticate SSH session");
379
- return -1;
380
- }
381
-
382
- return 0;
383
- }
384
-
385
- static int request_creds(git_credential **out, ssh_subtransport *t, const char *user, int auth_methods)
386
- {
387
- int error, no_callback = 0;
388
- git_credential *cred = NULL;
389
-
390
- if (!t->owner->connect_opts.callbacks.credentials) {
391
- no_callback = 1;
392
- } else {
393
- error = t->owner->connect_opts.callbacks.credentials(
394
- &cred,
395
- t->owner->url,
396
- user,
397
- auth_methods,
398
- t->owner->connect_opts.callbacks.payload);
399
-
400
- if (error == GIT_PASSTHROUGH) {
401
- no_callback = 1;
402
- } else if (error < 0) {
403
- return error;
404
- } else if (!cred) {
405
- git_error_set(GIT_ERROR_SSH, "callback failed to initialize SSH credentials");
406
- return -1;
407
- }
408
- }
409
-
410
- if (no_callback) {
411
- git_error_set(GIT_ERROR_SSH, "authentication required but no callback set");
412
- return GIT_EAUTH;
413
- }
414
-
415
- if (!(cred->credtype & auth_methods)) {
416
- cred->free(cred);
417
- git_error_set(GIT_ERROR_SSH, "authentication callback returned unsupported credentials type");
418
- return GIT_EAUTH;
419
- }
420
-
421
- *out = cred;
422
-
423
- return 0;
424
- }
425
-
426
- #define SSH_DIR ".ssh"
427
- #define KNOWN_HOSTS_FILE "known_hosts"
428
-
429
- /*
430
- * Load the known_hosts file.
431
- *
432
- * Returns success but leaves the output NULL if we couldn't find the file.
433
- */
434
- static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session)
435
- {
436
- git_str path = GIT_STR_INIT, sshdir = GIT_STR_INIT;
437
- LIBSSH2_KNOWNHOSTS *known_hosts = NULL;
438
- int error;
439
-
440
- GIT_ASSERT_ARG(hosts);
441
-
442
- if ((error = git_sysdir_expand_homedir_file(&sshdir, SSH_DIR)) < 0 ||
443
- (error = git_str_joinpath(&path, git_str_cstr(&sshdir), KNOWN_HOSTS_FILE)) < 0)
444
- goto out;
445
-
446
- if ((known_hosts = libssh2_knownhost_init(session)) == NULL) {
447
- ssh_error(session, "error initializing known hosts");
448
- error = -1;
449
- goto out;
450
- }
451
-
452
- /*
453
- * Try to read the file and consider not finding it as not trusting the
454
- * host rather than an error.
455
- */
456
- error = libssh2_knownhost_readfile(known_hosts, git_str_cstr(&path), LIBSSH2_KNOWNHOST_FILE_OPENSSH);
457
- if (error == LIBSSH2_ERROR_FILE)
458
- error = 0;
459
- if (error < 0)
460
- ssh_error(session, "error reading known_hosts");
461
-
462
- out:
463
- *hosts = known_hosts;
464
-
465
- git_str_dispose(&sshdir);
466
- git_str_dispose(&path);
467
-
468
- return error;
469
- }
470
-
471
- static void add_hostkey_pref_if_avail(
472
- LIBSSH2_KNOWNHOSTS *known_hosts,
473
- const char *hostname,
474
- int port,
475
- git_str *prefs,
476
- int type,
477
- const char *type_name)
478
- {
479
- struct libssh2_knownhost *host = NULL;
480
- const char key = '\0';
481
- int mask = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW | type;
482
- int error;
483
-
484
- error = libssh2_knownhost_checkp(known_hosts, hostname, port, &key, 1, mask, &host);
485
- if (error == LIBSSH2_KNOWNHOST_CHECK_MISMATCH) {
486
- if (git_str_len(prefs) > 0) {
487
- git_str_putc(prefs, ',');
488
- }
489
- git_str_puts(prefs, type_name);
490
- }
491
- }
492
-
493
- /*
494
- * We figure out what kind of key we want to ask the remote for by trying to
495
- * look it up with a nonsense key and using that mismatch to figure out what key
496
- * we do have stored for the host.
497
- *
498
- * Populates prefs with the string to pass to libssh2_session_method_pref.
499
- */
500
- static void find_hostkey_preference(
501
- LIBSSH2_KNOWNHOSTS *known_hosts,
502
- const char *hostname,
503
- int port,
504
- git_str *prefs)
505
- {
506
- /*
507
- * The order here is important as it indicates the priority of what will
508
- * be preferred.
509
- */
510
- #ifdef LIBSSH2_KNOWNHOST_KEY_ED25519
511
- add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ED25519, "ssh-ed25519");
512
- #endif
513
- #ifdef LIBSSH2_KNOWNHOST_KEY_ECDSA_256
514
- add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_256, "ecdsa-sha2-nistp256");
515
- add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_384, "ecdsa-sha2-nistp384");
516
- add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_521, "ecdsa-sha2-nistp521");
517
- #endif
518
- add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_SSHRSA, "ssh-rsa");
519
- }
520
-
521
- static int _git_ssh_session_create(
522
- LIBSSH2_SESSION **session,
523
- LIBSSH2_KNOWNHOSTS **hosts,
524
- const char *hostname,
525
- int port,
526
- git_stream *io)
527
- {
528
- git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
529
- LIBSSH2_SESSION *s;
530
- LIBSSH2_KNOWNHOSTS *known_hosts;
531
- git_str prefs = GIT_STR_INIT;
532
- int rc = 0;
533
-
534
- GIT_ASSERT_ARG(session);
535
- GIT_ASSERT_ARG(hosts);
536
-
537
- s = libssh2_session_init();
538
- if (!s) {
539
- git_error_set(GIT_ERROR_NET, "failed to initialize SSH session");
540
- return -1;
541
- }
542
-
543
- if ((rc = load_known_hosts(&known_hosts, s)) < 0) {
544
- ssh_error(s, "error loading known_hosts");
545
- libssh2_session_free(s);
546
- return -1;
547
- }
548
-
549
- find_hostkey_preference(known_hosts, hostname, port, &prefs);
550
- if (git_str_len(&prefs) > 0) {
551
- do {
552
- rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, git_str_cstr(&prefs));
553
- } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
554
- if (rc != LIBSSH2_ERROR_NONE) {
555
- ssh_error(s, "failed to set hostkey preference");
556
- goto on_error;
557
- }
558
- }
559
- git_str_dispose(&prefs);
560
-
561
- do {
562
- rc = libssh2_session_handshake(s, socket->s);
563
- } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
564
-
565
- if (rc != LIBSSH2_ERROR_NONE) {
566
- ssh_error(s, "failed to start SSH session");
567
- goto on_error;
568
- }
569
-
570
- libssh2_session_set_blocking(s, 1);
571
-
572
- *session = s;
573
- *hosts = known_hosts;
574
-
575
- return 0;
576
-
577
- on_error:
578
- libssh2_knownhost_free(known_hosts);
579
- libssh2_session_free(s);
580
- return -1;
581
- }
582
-
583
-
584
- /*
585
- * Returns the typemask argument to pass to libssh2_knownhost_check{,p} based on
586
- * the type of key that libssh2_session_hostkey returns.
587
- */
588
- static int fingerprint_type_mask(int keytype)
589
- {
590
- int mask = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW;
591
- return mask;
592
-
593
- switch (keytype) {
594
- case LIBSSH2_HOSTKEY_TYPE_RSA:
595
- mask |= LIBSSH2_KNOWNHOST_KEY_SSHRSA;
596
- break;
597
- case LIBSSH2_HOSTKEY_TYPE_DSS:
598
- mask |= LIBSSH2_KNOWNHOST_KEY_SSHDSS;
599
- break;
600
- #ifdef LIBSSH2_HOSTKEY_TYPE_ECDSA_256
601
- case LIBSSH2_HOSTKEY_TYPE_ECDSA_256:
602
- mask |= LIBSSH2_KNOWNHOST_KEY_ECDSA_256;
603
- break;
604
- case LIBSSH2_HOSTKEY_TYPE_ECDSA_384:
605
- mask |= LIBSSH2_KNOWNHOST_KEY_ECDSA_384;
606
- break;
607
- case LIBSSH2_HOSTKEY_TYPE_ECDSA_521:
608
- mask |= LIBSSH2_KNOWNHOST_KEY_ECDSA_521;
609
- break;
610
- #endif
611
- #ifdef LIBSSH2_HOSTKEY_TYPE_ED25519
612
- case LIBSSH2_HOSTKEY_TYPE_ED25519:
613
- mask |= LIBSSH2_KNOWNHOST_KEY_ED25519;
614
- break;
615
- #endif
616
- }
617
-
618
- return mask;
619
- }
620
-
621
- /*
622
- * Check the host against the user's known_hosts file.
623
- *
624
- * Returns 1/0 for valid/''not-valid or <0 for an error
625
- */
626
- static int check_against_known_hosts(
627
- LIBSSH2_SESSION *session,
628
- LIBSSH2_KNOWNHOSTS *known_hosts,
629
- const char *hostname,
630
- int port,
631
- const char *key,
632
- size_t key_len,
633
- int key_type)
634
- {
635
- int check, typemask, ret = 0;
636
- struct libssh2_knownhost *host = NULL;
637
-
638
- if (known_hosts == NULL)
639
- return 0;
640
-
641
- typemask = fingerprint_type_mask(key_type);
642
- check = libssh2_knownhost_checkp(known_hosts, hostname, port, key, key_len, typemask, &host);
643
- if (check == LIBSSH2_KNOWNHOST_CHECK_FAILURE) {
644
- ssh_error(session, "error checking for known host");
645
- return -1;
646
- }
647
-
648
- ret = check == LIBSSH2_KNOWNHOST_CHECK_MATCH ? 1 : 0;
649
-
650
- return ret;
651
- }
652
-
653
- /*
654
- * Perform the check for the session's certificate against known hosts if
655
- * possible and then ask the user if they have a callback.
656
- *
657
- * Returns 1/0 for valid/not-valid or <0 for an error
658
- */
659
- static int check_certificate(
660
- LIBSSH2_SESSION *session,
661
- LIBSSH2_KNOWNHOSTS *known_hosts,
662
- git_transport_certificate_check_cb check_cb,
663
- void *check_cb_payload,
664
- const char *host,
665
- int port)
666
- {
667
- git_cert_hostkey cert = {{ 0 }};
668
- const char *key;
669
- size_t cert_len;
670
- int cert_type, cert_valid = 0, error = 0;
671
-
672
- if ((key = libssh2_session_hostkey(session, &cert_len, &cert_type)) == NULL) {
673
- ssh_error(session, "failed to retrieve hostkey");
674
- return -1;
675
- }
676
-
677
- if ((cert_valid = check_against_known_hosts(session, known_hosts, host, port, key, cert_len, cert_type)) < 0)
678
- return -1;
679
-
680
- cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
681
- if (key != NULL) {
682
- cert.type |= GIT_CERT_SSH_RAW;
683
- cert.hostkey = key;
684
- cert.hostkey_len = cert_len;
685
- switch (cert_type) {
686
- case LIBSSH2_HOSTKEY_TYPE_RSA:
687
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_RSA;
688
- break;
689
- case LIBSSH2_HOSTKEY_TYPE_DSS:
690
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_DSS;
691
- break;
692
-
693
- #ifdef LIBSSH2_HOSTKEY_TYPE_ECDSA_256
694
- case LIBSSH2_HOSTKEY_TYPE_ECDSA_256:
695
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256;
696
- break;
697
- case LIBSSH2_HOSTKEY_TYPE_ECDSA_384:
698
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_384;
699
- break;
700
- case LIBSSH2_KNOWNHOST_KEY_ECDSA_521:
701
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521;
702
- break;
703
- #endif
704
-
705
- #ifdef LIBSSH2_HOSTKEY_TYPE_ED25519
706
- case LIBSSH2_HOSTKEY_TYPE_ED25519:
707
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_KEY_ED25519;
708
- break;
709
- #endif
710
- default:
711
- cert.raw_type = GIT_CERT_SSH_RAW_TYPE_UNKNOWN;
712
- }
713
- }
714
-
715
- #ifdef LIBSSH2_HOSTKEY_HASH_SHA256
716
- key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256);
717
- if (key != NULL) {
718
- cert.type |= GIT_CERT_SSH_SHA256;
719
- memcpy(&cert.hash_sha256, key, 32);
720
- }
721
- #endif
722
-
723
- key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
724
- if (key != NULL) {
725
- cert.type |= GIT_CERT_SSH_SHA1;
726
- memcpy(&cert.hash_sha1, key, 20);
727
- }
728
-
729
- key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_MD5);
730
- if (key != NULL) {
731
- cert.type |= GIT_CERT_SSH_MD5;
732
- memcpy(&cert.hash_md5, key, 16);
733
- }
734
-
735
- if (cert.type == 0) {
736
- git_error_set(GIT_ERROR_SSH, "unable to get the host key");
737
- return -1;
738
- }
739
-
740
- git_error_clear();
741
- error = 0;
742
- if (!cert_valid) {
743
- git_error_set(GIT_ERROR_SSH, "invalid or unknown remote ssh hostkey");
744
- error = GIT_ECERTIFICATE;
745
- }
746
-
747
- if (check_cb != NULL) {
748
- git_cert_hostkey *cert_ptr = &cert;
749
- git_error_state previous_error = {0};
750
-
751
- git_error_state_capture(&previous_error, error);
752
- error = check_cb((git_cert *) cert_ptr, cert_valid, host, check_cb_payload);
753
- if (error == GIT_PASSTHROUGH) {
754
- error = git_error_state_restore(&previous_error);
755
- } else if (error < 0 && !git_error_last()) {
756
- git_error_set(GIT_ERROR_NET, "unknown remote host key");
757
- }
758
-
759
- git_error_state_free(&previous_error);
760
- }
761
-
762
- return error;
763
- }
764
-
765
- #define SSH_DEFAULT_PORT "22"
766
-
767
- static int _git_ssh_setup_conn(
768
- ssh_subtransport *t,
769
- const char *url,
770
- const char *cmd,
771
- git_smart_subtransport_stream **stream)
772
- {
773
- int auth_methods, error = 0, port;
774
- ssh_stream *s;
775
- git_credential *cred = NULL;
776
- LIBSSH2_SESSION *session=NULL;
777
- LIBSSH2_CHANNEL *channel=NULL;
778
- LIBSSH2_KNOWNHOSTS *known_hosts = NULL;
779
-
780
- t->current_stream = NULL;
781
-
782
- *stream = NULL;
783
- if (ssh_stream_alloc(t, cmd, stream) < 0)
784
- return -1;
785
-
786
- s = (ssh_stream *)*stream;
787
- s->session = NULL;
788
- s->channel = NULL;
789
-
790
- if ((error = git_net_url_parse_standard_or_scp(&s->url, url)) < 0 ||
791
- (error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
792
- (error = git_stream_connect(s->io)) < 0)
793
- goto done;
794
-
795
- /*
796
- * Try to parse the port as a number, if we can't then fall back to
797
- * default. It would be nice if we could get the port that was resolved
798
- * as part of the stream connection, but that's not something that's
799
- * exposed.
800
- */
801
- if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) {
802
- git_error_set(GIT_ERROR_NET, "invalid port to ssh: %s", s->url.port);
803
- error = -1;
804
- goto done;
805
- }
806
-
807
- if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0)
808
- goto done;
809
-
810
- if ((error = check_certificate(session, known_hosts, t->owner->connect_opts.callbacks.certificate_check, t->owner->connect_opts.callbacks.payload, s->url.host, port)) < 0)
811
- goto done;
812
-
813
- /* we need the username to ask for auth methods */
814
- if (!s->url.username) {
815
- if ((error = request_creds(&cred, t, NULL, GIT_CREDENTIAL_USERNAME)) < 0)
816
- goto done;
817
-
818
- s->url.username = git__strdup(((git_credential_username *) cred)->username);
819
- cred->free(cred);
820
- cred = NULL;
821
- if (!s->url.username)
822
- goto done;
823
- } else if (s->url.username && s->url.password) {
824
- if ((error = git_credential_userpass_plaintext_new(&cred, s->url.username, s->url.password)) < 0)
825
- goto done;
826
- }
827
-
828
- if ((error = list_auth_methods(&auth_methods, session, s->url.username)) < 0)
829
- goto done;
830
-
831
- error = GIT_EAUTH;
832
- /* if we already have something to try */
833
- if (cred && auth_methods & cred->credtype)
834
- error = _git_ssh_authenticate_session(session, cred);
835
-
836
- while (error == GIT_EAUTH) {
837
- if (cred) {
838
- cred->free(cred);
839
- cred = NULL;
840
- }
841
-
842
- if ((error = request_creds(&cred, t, s->url.username, auth_methods)) < 0)
843
- goto done;
844
-
845
- if (strcmp(s->url.username, git_credential_get_username(cred))) {
846
- git_error_set(GIT_ERROR_SSH, "username does not match previous request");
847
- error = -1;
848
- goto done;
849
- }
850
-
851
- error = _git_ssh_authenticate_session(session, cred);
852
-
853
- if (error == GIT_EAUTH) {
854
- /* refresh auth methods */
855
- if ((error = list_auth_methods(&auth_methods, session, s->url.username)) < 0)
856
- goto done;
857
- else
858
- error = GIT_EAUTH;
859
- }
860
- }
861
-
862
- if (error < 0)
863
- goto done;
864
-
865
- channel = libssh2_channel_open_session(session);
866
- if (!channel) {
867
- error = -1;
868
- ssh_error(session, "Failed to open SSH channel");
869
- goto done;
870
- }
871
-
872
- libssh2_channel_set_blocking(channel, 1);
873
-
874
- s->session = session;
875
- s->channel = channel;
876
-
877
- t->current_stream = s;
878
-
879
- done:
880
- if (known_hosts)
881
- libssh2_knownhost_free(known_hosts);
882
-
883
- if (error < 0) {
884
- ssh_stream_free(*stream);
885
-
886
- if (session)
887
- libssh2_session_free(session);
888
- }
889
-
890
- if (cred)
891
- cred->free(cred);
892
-
893
- return error;
894
- }
895
-
896
- static int ssh_uploadpack_ls(
897
- ssh_subtransport *t,
898
- const char *url,
899
- git_smart_subtransport_stream **stream)
900
- {
901
- const char *cmd = t->cmd_uploadpack ? t->cmd_uploadpack : cmd_uploadpack;
902
-
903
- return _git_ssh_setup_conn(t, url, cmd, stream);
904
- }
905
-
906
- static int ssh_uploadpack(
907
- ssh_subtransport *t,
908
- const char *url,
909
- git_smart_subtransport_stream **stream)
910
- {
911
- GIT_UNUSED(url);
912
-
913
- if (t->current_stream) {
914
- *stream = &t->current_stream->parent;
915
- return 0;
916
- }
917
-
918
- git_error_set(GIT_ERROR_NET, "must call UPLOADPACK_LS before UPLOADPACK");
919
- return -1;
920
- }
921
-
922
- static int ssh_receivepack_ls(
923
- ssh_subtransport *t,
924
- const char *url,
925
- git_smart_subtransport_stream **stream)
926
- {
927
- const char *cmd = t->cmd_receivepack ? t->cmd_receivepack : cmd_receivepack;
928
-
929
-
930
- return _git_ssh_setup_conn(t, url, cmd, stream);
931
- }
932
-
933
- static int ssh_receivepack(
934
- ssh_subtransport *t,
935
- const char *url,
936
- git_smart_subtransport_stream **stream)
937
- {
938
- GIT_UNUSED(url);
939
-
940
- if (t->current_stream) {
941
- *stream = &t->current_stream->parent;
942
- return 0;
943
- }
944
-
945
- git_error_set(GIT_ERROR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK");
946
- return -1;
947
- }
948
-
949
- static int _ssh_action(
950
- git_smart_subtransport_stream **stream,
951
- git_smart_subtransport *subtransport,
952
- const char *url,
953
- git_smart_service_t action)
954
- {
955
- ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
956
-
957
- switch (action) {
958
- case GIT_SERVICE_UPLOADPACK_LS:
959
- return ssh_uploadpack_ls(t, url, stream);
960
-
961
- case GIT_SERVICE_UPLOADPACK:
962
- return ssh_uploadpack(t, url, stream);
963
-
964
- case GIT_SERVICE_RECEIVEPACK_LS:
965
- return ssh_receivepack_ls(t, url, stream);
966
-
967
- case GIT_SERVICE_RECEIVEPACK:
968
- return ssh_receivepack(t, url, stream);
969
- }
13
+ int git_smart_subtransport_ssh(
14
+ git_smart_subtransport **out,
15
+ git_transport *owner,
16
+ void *param)
17
+ {
18
+ #ifdef GIT_SSH_LIBSSH2
19
+ return git_smart_subtransport_ssh_libssh2(out, owner, param);
20
+ #elif GIT_SSH_EXEC
21
+ return git_smart_subtransport_ssh_exec(out, owner, param);
22
+ #else
23
+ GIT_UNUSED(out);
24
+ GIT_UNUSED(owner);
25
+ GIT_UNUSED(param);
970
26
 
971
- *stream = NULL;
27
+ git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport; library was built without SSH support");
972
28
  return -1;
973
- }
974
-
975
- static int _ssh_close(git_smart_subtransport *subtransport)
976
- {
977
- ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
978
-
979
- GIT_ASSERT(!t->current_stream);
980
-
981
- GIT_UNUSED(t);
982
-
983
- return 0;
984
- }
985
-
986
- static void _ssh_free(git_smart_subtransport *subtransport)
987
- {
988
- ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
989
-
990
- git__free(t->cmd_uploadpack);
991
- git__free(t->cmd_receivepack);
992
- git__free(t);
993
- }
994
-
995
- #define SSH_AUTH_PUBLICKEY "publickey"
996
- #define SSH_AUTH_PASSWORD "password"
997
- #define SSH_AUTH_KEYBOARD_INTERACTIVE "keyboard-interactive"
998
-
999
- static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *username)
1000
- {
1001
- const char *list, *ptr;
1002
-
1003
- *out = 0;
1004
-
1005
- list = libssh2_userauth_list(session, username, strlen(username));
1006
-
1007
- /* either error, or the remote accepts NONE auth, which is bizarre, let's punt */
1008
- if (list == NULL && !libssh2_userauth_authenticated(session)) {
1009
- ssh_error(session, "remote rejected authentication");
1010
- return GIT_EAUTH;
1011
- }
1012
-
1013
- ptr = list;
1014
- while (ptr) {
1015
- if (*ptr == ',')
1016
- ptr++;
1017
-
1018
- if (!git__prefixcmp(ptr, SSH_AUTH_PUBLICKEY)) {
1019
- *out |= GIT_CREDENTIAL_SSH_KEY;
1020
- *out |= GIT_CREDENTIAL_SSH_CUSTOM;
1021
- #ifdef GIT_SSH_MEMORY_CREDENTIALS
1022
- *out |= GIT_CREDENTIAL_SSH_MEMORY;
1023
29
  #endif
1024
- ptr += strlen(SSH_AUTH_PUBLICKEY);
1025
- continue;
1026
- }
1027
-
1028
- if (!git__prefixcmp(ptr, SSH_AUTH_PASSWORD)) {
1029
- *out |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
1030
- ptr += strlen(SSH_AUTH_PASSWORD);
1031
- continue;
1032
- }
1033
-
1034
- if (!git__prefixcmp(ptr, SSH_AUTH_KEYBOARD_INTERACTIVE)) {
1035
- *out |= GIT_CREDENTIAL_SSH_INTERACTIVE;
1036
- ptr += strlen(SSH_AUTH_KEYBOARD_INTERACTIVE);
1037
- continue;
1038
- }
1039
-
1040
- /* Skip it if we don't know it */
1041
- ptr = strchr(ptr, ',');
1042
- }
1043
-
1044
- return 0;
1045
30
  }
1046
- #endif
1047
31
 
1048
- int git_smart_subtransport_ssh(
1049
- git_smart_subtransport **out, git_transport *owner, void *param)
32
+ static int transport_set_paths(git_transport *t, git_strarray *paths)
1050
33
  {
1051
- #ifdef GIT_SSH
1052
- ssh_subtransport *t;
34
+ transport_smart *smart = (transport_smart *)t;
1053
35
 
1054
- GIT_ASSERT_ARG(out);
1055
-
1056
- GIT_UNUSED(param);
1057
-
1058
- t = git__calloc(sizeof(ssh_subtransport), 1);
1059
- GIT_ERROR_CHECK_ALLOC(t);
1060
-
1061
- t->owner = (transport_smart *)owner;
1062
- t->parent.action = _ssh_action;
1063
- t->parent.close = _ssh_close;
1064
- t->parent.free = _ssh_free;
1065
-
1066
- *out = (git_smart_subtransport *) t;
1067
- return 0;
36
+ #ifdef GIT_SSH_LIBSSH2
37
+ return git_smart_subtransport_ssh_libssh2_set_paths(
38
+ (git_smart_subtransport *)smart->wrapped,
39
+ paths->strings[0],
40
+ paths->strings[1]);
41
+ #elif GIT_SSH_EXEC
42
+ return git_smart_subtransport_ssh_exec_set_paths(
43
+ (git_smart_subtransport *)smart->wrapped,
44
+ paths->strings[0],
45
+ paths->strings[1]);
1068
46
  #else
1069
- GIT_UNUSED(owner);
1070
- GIT_UNUSED(param);
1071
-
1072
- GIT_ASSERT_ARG(out);
1073
- *out = NULL;
47
+ GIT_UNUSED(t);
48
+ GIT_UNUSED(smart);
49
+ GIT_UNUSED(paths);
1074
50
 
1075
- git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
51
+ GIT_ASSERT(!"cannot create SSH library; library was built without SSH support");
1076
52
  return -1;
1077
53
  #endif
1078
54
  }
1079
55
 
1080
- int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *payload)
56
+ int git_transport_ssh_with_paths(
57
+ git_transport **out,
58
+ git_remote *owner,
59
+ void *payload)
1081
60
  {
1082
- #ifdef GIT_SSH
1083
61
  git_strarray *paths = (git_strarray *) payload;
1084
62
  git_transport *transport;
1085
- transport_smart *smart;
1086
- ssh_subtransport *t;
1087
63
  int error;
64
+
1088
65
  git_smart_subtransport_definition ssh_definition = {
1089
66
  git_smart_subtransport_ssh,
1090
67
  0, /* no RPC */
1091
- NULL,
68
+ NULL
1092
69
  };
1093
70
 
1094
71
  if (paths->count != 2) {
@@ -1099,49 +76,10 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
1099
76
  if ((error = git_transport_smart(&transport, owner, &ssh_definition)) < 0)
1100
77
  return error;
1101
78
 
1102
- smart = (transport_smart *) transport;
1103
- t = (ssh_subtransport *) smart->wrapped;
1104
-
1105
- t->cmd_uploadpack = git__strdup(paths->strings[0]);
1106
- GIT_ERROR_CHECK_ALLOC(t->cmd_uploadpack);
1107
- t->cmd_receivepack = git__strdup(paths->strings[1]);
1108
- GIT_ERROR_CHECK_ALLOC(t->cmd_receivepack);
79
+ if ((error = transport_set_paths(transport, paths)) < 0)
80
+ return error;
1109
81
 
1110
82
  *out = transport;
1111
83
  return 0;
1112
- #else
1113
- GIT_UNUSED(owner);
1114
- GIT_UNUSED(payload);
1115
-
1116
- GIT_ASSERT_ARG(out);
1117
- *out = NULL;
1118
-
1119
- git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
1120
- return -1;
1121
- #endif
1122
- }
1123
-
1124
- #ifdef GIT_SSH
1125
- static void shutdown_ssh(void)
1126
- {
1127
- libssh2_exit();
1128
84
  }
1129
- #endif
1130
-
1131
- int git_transport_ssh_global_init(void)
1132
- {
1133
- #ifdef GIT_SSH
1134
- if (libssh2_init(0) < 0) {
1135
- git_error_set(GIT_ERROR_SSH, "unable to initialize libssh2");
1136
- return -1;
1137
- }
1138
-
1139
- return git_runtime_shutdown_register(shutdown_ssh);
1140
85
 
1141
- #else
1142
-
1143
- /* Nothing to initialize */
1144
- return 0;
1145
-
1146
- #endif
1147
- }