rugged 0.28.5 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (379) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +3 -1
  3. data/ext/rugged/rugged.c +35 -31
  4. data/ext/rugged/rugged.h +13 -0
  5. data/ext/rugged/rugged_blob.c +11 -9
  6. data/ext/rugged/rugged_commit.c +17 -15
  7. data/ext/rugged/rugged_diff.c +4 -26
  8. data/ext/rugged/rugged_index.c +4 -2
  9. data/ext/rugged/rugged_note.c +5 -3
  10. data/ext/rugged/rugged_object.c +57 -10
  11. data/ext/rugged/rugged_rebase.c +3 -1
  12. data/ext/rugged/rugged_remote.c +0 -6
  13. data/ext/rugged/rugged_repo.c +222 -17
  14. data/ext/rugged/rugged_tag.c +8 -6
  15. data/ext/rugged/rugged_tree.c +18 -16
  16. data/lib/rugged/version.rb +1 -1
  17. data/vendor/libgit2/CMakeLists.txt +38 -19
  18. data/vendor/libgit2/COPYING +28 -0
  19. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -1
  20. data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +2 -2
  21. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +1 -1
  22. data/vendor/libgit2/cmake/Modules/FindGSSFramework.cmake +28 -0
  23. data/vendor/libgit2/cmake/Modules/FindPCRE.cmake +38 -0
  24. data/vendor/libgit2/cmake/Modules/FindPCRE2.cmake +37 -0
  25. data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +2 -2
  26. data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +6 -0
  27. data/vendor/libgit2/cmake/Modules/PkgBuildConfig.cmake +110 -0
  28. data/vendor/libgit2/cmake/Modules/SelectGSSAPI.cmake +53 -0
  29. data/vendor/libgit2/cmake/Modules/SelectHTTPSBackend.cmake +124 -0
  30. data/vendor/libgit2/cmake/Modules/SelectHashes.cmake +66 -0
  31. data/vendor/libgit2/deps/http-parser/http_parser.c +11 -6
  32. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +21 -0
  33. data/vendor/libgit2/deps/ntlmclient/compat.h +33 -0
  34. data/vendor/libgit2/deps/ntlmclient/crypt.h +64 -0
  35. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +120 -0
  36. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +18 -0
  37. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +145 -0
  38. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +18 -0
  39. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +130 -0
  40. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +21 -0
  41. data/vendor/libgit2/deps/ntlmclient/ntlm.c +1422 -0
  42. data/vendor/libgit2/deps/ntlmclient/ntlm.h +174 -0
  43. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +320 -0
  44. data/vendor/libgit2/deps/ntlmclient/unicode.h +36 -0
  45. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +445 -0
  46. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +201 -0
  47. data/vendor/libgit2/deps/ntlmclient/utf8.h +1257 -0
  48. data/vendor/libgit2/deps/ntlmclient/util.c +21 -0
  49. data/vendor/libgit2/deps/ntlmclient/util.h +14 -0
  50. data/vendor/libgit2/deps/pcre/CMakeLists.txt +140 -0
  51. data/vendor/libgit2/deps/pcre/COPYING +5 -0
  52. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +22 -0
  53. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +17 -0
  54. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +58 -0
  55. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +29 -0
  56. data/vendor/libgit2/deps/pcre/config.h.in +57 -0
  57. data/vendor/libgit2/deps/pcre/pcre.h +641 -0
  58. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +319 -0
  59. data/vendor/libgit2/deps/pcre/pcre_chartables.c +198 -0
  60. data/vendor/libgit2/deps/pcre/pcre_compile.c +9800 -0
  61. data/vendor/libgit2/deps/pcre/pcre_config.c +190 -0
  62. data/vendor/libgit2/deps/pcre/pcre_dfa_exec.c +3676 -0
  63. data/vendor/libgit2/deps/pcre/pcre_exec.c +7173 -0
  64. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +245 -0
  65. data/vendor/libgit2/deps/pcre/pcre_get.c +669 -0
  66. data/vendor/libgit2/deps/pcre/pcre_globals.c +86 -0
  67. data/vendor/libgit2/deps/pcre/pcre_internal.h +2787 -0
  68. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +11913 -0
  69. data/vendor/libgit2/deps/pcre/pcre_maketables.c +156 -0
  70. data/vendor/libgit2/deps/pcre/pcre_newline.c +210 -0
  71. data/vendor/libgit2/deps/pcre/pcre_ord2utf8.c +94 -0
  72. data/vendor/libgit2/deps/pcre/pcre_printint.c +834 -0
  73. data/vendor/libgit2/deps/pcre/pcre_refcount.c +92 -0
  74. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +211 -0
  75. data/vendor/libgit2/deps/pcre/pcre_study.c +1686 -0
  76. data/vendor/libgit2/deps/pcre/pcre_tables.c +727 -0
  77. data/vendor/libgit2/deps/pcre/pcre_ucd.c +3644 -0
  78. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +301 -0
  79. data/vendor/libgit2/deps/pcre/pcre_version.c +98 -0
  80. data/vendor/libgit2/deps/pcre/pcre_xclass.c +268 -0
  81. data/vendor/libgit2/deps/pcre/pcreposix.c +421 -0
  82. data/vendor/libgit2/deps/pcre/pcreposix.h +117 -0
  83. data/vendor/libgit2/deps/pcre/ucp.h +224 -0
  84. data/vendor/libgit2/deps/zlib/adler32.c +0 -7
  85. data/vendor/libgit2/deps/zlib/crc32.c +0 -7
  86. data/vendor/libgit2/include/git2.h +2 -0
  87. data/vendor/libgit2/include/git2/apply.h +22 -2
  88. data/vendor/libgit2/include/git2/attr.h +23 -13
  89. data/vendor/libgit2/include/git2/blame.h +2 -2
  90. data/vendor/libgit2/include/git2/blob.h +44 -12
  91. data/vendor/libgit2/include/git2/branch.h +74 -57
  92. data/vendor/libgit2/include/git2/buffer.h +20 -14
  93. data/vendor/libgit2/include/git2/cert.h +135 -0
  94. data/vendor/libgit2/include/git2/checkout.h +46 -14
  95. data/vendor/libgit2/include/git2/cherrypick.h +3 -3
  96. data/vendor/libgit2/include/git2/clone.h +2 -2
  97. data/vendor/libgit2/include/git2/commit.h +23 -1
  98. data/vendor/libgit2/include/git2/common.h +15 -6
  99. data/vendor/libgit2/include/git2/config.h +12 -12
  100. data/vendor/libgit2/include/git2/cred_helpers.h +4 -42
  101. data/vendor/libgit2/include/git2/credential.h +314 -0
  102. data/vendor/libgit2/include/git2/credential_helpers.h +52 -0
  103. data/vendor/libgit2/include/git2/deprecated.h +314 -3
  104. data/vendor/libgit2/include/git2/describe.h +4 -4
  105. data/vendor/libgit2/include/git2/diff.h +16 -14
  106. data/vendor/libgit2/include/git2/errors.h +4 -2
  107. data/vendor/libgit2/include/git2/filter.h +8 -0
  108. data/vendor/libgit2/include/git2/index.h +2 -1
  109. data/vendor/libgit2/include/git2/indexer.h +48 -4
  110. data/vendor/libgit2/include/git2/merge.h +6 -10
  111. data/vendor/libgit2/include/git2/net.h +0 -5
  112. data/vendor/libgit2/include/git2/object.h +2 -14
  113. data/vendor/libgit2/include/git2/odb.h +3 -2
  114. data/vendor/libgit2/include/git2/odb_backend.h +5 -4
  115. data/vendor/libgit2/include/git2/oid.h +11 -6
  116. data/vendor/libgit2/include/git2/pack.h +12 -1
  117. data/vendor/libgit2/include/git2/proxy.h +6 -4
  118. data/vendor/libgit2/include/git2/rebase.h +46 -2
  119. data/vendor/libgit2/include/git2/refs.h +19 -0
  120. data/vendor/libgit2/include/git2/remote.h +40 -15
  121. data/vendor/libgit2/include/git2/repository.h +24 -2
  122. data/vendor/libgit2/include/git2/revert.h +1 -1
  123. data/vendor/libgit2/include/git2/revwalk.h +7 -3
  124. data/vendor/libgit2/include/git2/stash.h +4 -4
  125. data/vendor/libgit2/include/git2/status.h +25 -16
  126. data/vendor/libgit2/include/git2/submodule.h +20 -3
  127. data/vendor/libgit2/include/git2/sys/alloc.h +9 -9
  128. data/vendor/libgit2/include/git2/sys/cred.h +15 -0
  129. data/vendor/libgit2/include/git2/sys/credential.h +90 -0
  130. data/vendor/libgit2/include/git2/sys/index.h +4 -2
  131. data/vendor/libgit2/include/git2/sys/mempack.h +2 -1
  132. data/vendor/libgit2/include/git2/sys/merge.h +1 -1
  133. data/vendor/libgit2/include/git2/sys/odb_backend.h +48 -4
  134. data/vendor/libgit2/include/git2/sys/refdb_backend.h +57 -21
  135. data/vendor/libgit2/include/git2/sys/repository.h +17 -6
  136. data/vendor/libgit2/include/git2/sys/transport.h +4 -4
  137. data/vendor/libgit2/include/git2/tag.h +11 -2
  138. data/vendor/libgit2/include/git2/trace.h +2 -2
  139. data/vendor/libgit2/include/git2/transport.h +11 -340
  140. data/vendor/libgit2/include/git2/tree.h +5 -3
  141. data/vendor/libgit2/include/git2/types.h +4 -89
  142. data/vendor/libgit2/include/git2/version.h +4 -4
  143. data/vendor/libgit2/include/git2/worktree.h +5 -5
  144. data/vendor/libgit2/src/CMakeLists.txt +89 -224
  145. data/vendor/libgit2/src/alloc.c +2 -14
  146. data/vendor/libgit2/src/{stdalloc.c → allocators/stdalloc.c} +3 -4
  147. data/vendor/libgit2/src/{stdalloc.h → allocators/stdalloc.h} +4 -4
  148. data/vendor/libgit2/src/allocators/win32_crtdbg.c +118 -0
  149. data/vendor/libgit2/src/{transports/cred.h → allocators/win32_crtdbg.h} +5 -4
  150. data/vendor/libgit2/src/apply.c +31 -15
  151. data/vendor/libgit2/src/attr.c +70 -64
  152. data/vendor/libgit2/src/attr_file.c +189 -96
  153. data/vendor/libgit2/src/attr_file.h +9 -9
  154. data/vendor/libgit2/src/attrcache.c +47 -47
  155. data/vendor/libgit2/src/attrcache.h +2 -1
  156. data/vendor/libgit2/src/blame.c +17 -5
  157. data/vendor/libgit2/src/blame.h +1 -1
  158. data/vendor/libgit2/src/blame_git.c +21 -7
  159. data/vendor/libgit2/src/blob.c +81 -17
  160. data/vendor/libgit2/src/blob.h +2 -2
  161. data/vendor/libgit2/src/branch.c +60 -32
  162. data/vendor/libgit2/src/buffer.c +5 -0
  163. data/vendor/libgit2/src/buffer.h +1 -0
  164. data/vendor/libgit2/src/cache.c +26 -33
  165. data/vendor/libgit2/src/cache.h +1 -1
  166. data/vendor/libgit2/src/cc-compat.h +5 -0
  167. data/vendor/libgit2/src/checkout.c +26 -16
  168. data/vendor/libgit2/src/cherrypick.c +7 -1
  169. data/vendor/libgit2/src/clone.c +29 -7
  170. data/vendor/libgit2/src/clone.h +4 -0
  171. data/vendor/libgit2/src/commit.c +70 -22
  172. data/vendor/libgit2/src/commit.h +6 -0
  173. data/vendor/libgit2/src/commit_list.c +28 -76
  174. data/vendor/libgit2/src/commit_list.h +2 -2
  175. data/vendor/libgit2/src/common.h +3 -75
  176. data/vendor/libgit2/src/config.c +31 -40
  177. data/vendor/libgit2/src/config.h +7 -6
  178. data/vendor/libgit2/src/config_backend.h +12 -0
  179. data/vendor/libgit2/src/config_cache.c +39 -39
  180. data/vendor/libgit2/src/config_entries.c +69 -99
  181. data/vendor/libgit2/src/config_entries.h +1 -0
  182. data/vendor/libgit2/src/config_file.c +337 -380
  183. data/vendor/libgit2/src/config_mem.c +12 -16
  184. data/vendor/libgit2/src/config_parse.c +49 -29
  185. data/vendor/libgit2/src/config_parse.h +13 -12
  186. data/vendor/libgit2/src/config_snapshot.c +206 -0
  187. data/vendor/libgit2/src/crlf.c +14 -14
  188. data/vendor/libgit2/src/describe.c +21 -20
  189. data/vendor/libgit2/src/diff.c +43 -66
  190. data/vendor/libgit2/src/diff.h +4 -3
  191. data/vendor/libgit2/src/diff_driver.c +37 -38
  192. data/vendor/libgit2/src/diff_file.c +12 -10
  193. data/vendor/libgit2/src/diff_file.h +2 -2
  194. data/vendor/libgit2/src/diff_generate.c +26 -26
  195. data/vendor/libgit2/src/diff_generate.h +2 -2
  196. data/vendor/libgit2/src/diff_parse.c +1 -1
  197. data/vendor/libgit2/src/diff_print.c +25 -13
  198. data/vendor/libgit2/src/diff_stats.c +1 -1
  199. data/vendor/libgit2/src/diff_tform.c +11 -11
  200. data/vendor/libgit2/src/errors.c +21 -25
  201. data/vendor/libgit2/src/errors.h +81 -0
  202. data/vendor/libgit2/src/features.h.in +9 -2
  203. data/vendor/libgit2/src/fetch.c +7 -2
  204. data/vendor/libgit2/src/fetchhead.c +9 -9
  205. data/vendor/libgit2/src/filebuf.c +1 -1
  206. data/vendor/libgit2/src/filebuf.h +1 -1
  207. data/vendor/libgit2/src/filter.c +16 -8
  208. data/vendor/libgit2/src/{fileops.c → futils.c} +20 -17
  209. data/vendor/libgit2/src/{fileops.h → futils.h} +5 -5
  210. data/vendor/libgit2/src/hash.c +61 -0
  211. data/vendor/libgit2/src/hash.h +19 -21
  212. data/vendor/libgit2/src/hash/sha1.h +38 -0
  213. data/vendor/libgit2/src/hash/{hash_collisiondetect.h → sha1/collisiondetect.c} +14 -17
  214. data/vendor/libgit2/src/hash/sha1/collisiondetect.h +19 -0
  215. data/vendor/libgit2/src/hash/{hash_common_crypto.h → sha1/common_crypto.c} +15 -19
  216. data/vendor/libgit2/src/hash/sha1/common_crypto.h +19 -0
  217. data/vendor/libgit2/src/hash/{hash_generic.c → sha1/generic.c} +22 -10
  218. data/vendor/libgit2/src/hash/{hash_generic.h → sha1/generic.h} +4 -14
  219. data/vendor/libgit2/src/hash/{hash_mbedtls.c → sha1/mbedtls.c} +15 -7
  220. data/vendor/libgit2/src/hash/{hash_mbedtls.h → sha1/mbedtls.h} +6 -11
  221. data/vendor/libgit2/src/hash/{hash_openssl.h → sha1/openssl.c} +14 -18
  222. data/vendor/libgit2/src/hash/sha1/openssl.h +19 -0
  223. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.c +14 -3
  224. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.h +0 -0
  225. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.c +0 -0
  226. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.h +0 -0
  227. data/vendor/libgit2/src/hash/{hash_win32.c → sha1/win32.c} +34 -24
  228. data/vendor/libgit2/src/hash/{hash_win32.h → sha1/win32.h} +6 -19
  229. data/vendor/libgit2/src/hashsig.c +1 -1
  230. data/vendor/libgit2/src/idxmap.c +91 -65
  231. data/vendor/libgit2/src/idxmap.h +151 -15
  232. data/vendor/libgit2/src/ignore.c +26 -35
  233. data/vendor/libgit2/src/index.c +103 -81
  234. data/vendor/libgit2/src/index.h +1 -1
  235. data/vendor/libgit2/src/indexer.c +69 -70
  236. data/vendor/libgit2/src/integer.h +11 -4
  237. data/vendor/libgit2/src/iterator.c +32 -28
  238. data/vendor/libgit2/src/iterator.h +8 -8
  239. data/vendor/libgit2/src/map.h +1 -1
  240. data/vendor/libgit2/src/merge.c +55 -41
  241. data/vendor/libgit2/src/merge.h +2 -2
  242. data/vendor/libgit2/src/merge_driver.c +5 -5
  243. data/vendor/libgit2/src/merge_file.c +1 -1
  244. data/vendor/libgit2/src/mwindow.c +18 -23
  245. data/vendor/libgit2/src/mwindow.h +4 -4
  246. data/vendor/libgit2/src/net.c +411 -0
  247. data/vendor/libgit2/src/net.h +57 -0
  248. data/vendor/libgit2/src/netops.c +6 -222
  249. data/vendor/libgit2/src/netops.h +1 -37
  250. data/vendor/libgit2/src/notes.c +2 -2
  251. data/vendor/libgit2/src/object.c +3 -3
  252. data/vendor/libgit2/src/object.h +2 -0
  253. data/vendor/libgit2/src/odb.c +41 -23
  254. data/vendor/libgit2/src/odb.h +3 -2
  255. data/vendor/libgit2/src/odb_loose.c +17 -10
  256. data/vendor/libgit2/src/odb_mempack.c +13 -24
  257. data/vendor/libgit2/src/odb_pack.c +4 -4
  258. data/vendor/libgit2/src/offmap.c +43 -55
  259. data/vendor/libgit2/src/offmap.h +102 -24
  260. data/vendor/libgit2/src/oid.c +19 -8
  261. data/vendor/libgit2/src/oidmap.c +39 -57
  262. data/vendor/libgit2/src/oidmap.h +99 -19
  263. data/vendor/libgit2/src/pack-objects.c +25 -32
  264. data/vendor/libgit2/src/pack-objects.h +1 -1
  265. data/vendor/libgit2/src/pack.c +97 -129
  266. data/vendor/libgit2/src/pack.h +15 -18
  267. data/vendor/libgit2/src/parse.c +10 -0
  268. data/vendor/libgit2/src/parse.h +3 -3
  269. data/vendor/libgit2/src/patch.c +1 -1
  270. data/vendor/libgit2/src/patch_generate.c +1 -1
  271. data/vendor/libgit2/src/patch_parse.c +30 -9
  272. data/vendor/libgit2/src/path.c +43 -6
  273. data/vendor/libgit2/src/path.h +2 -0
  274. data/vendor/libgit2/src/pathspec.c +14 -14
  275. data/vendor/libgit2/src/pool.c +26 -22
  276. data/vendor/libgit2/src/pool.h +7 -7
  277. data/vendor/libgit2/src/posix.c +7 -7
  278. data/vendor/libgit2/src/posix.h +12 -1
  279. data/vendor/libgit2/src/proxy.c +7 -2
  280. data/vendor/libgit2/src/push.c +10 -5
  281. data/vendor/libgit2/src/reader.c +2 -2
  282. data/vendor/libgit2/src/rebase.c +87 -28
  283. data/vendor/libgit2/src/refdb.c +12 -0
  284. data/vendor/libgit2/src/refdb_fs.c +215 -169
  285. data/vendor/libgit2/src/reflog.c +11 -13
  286. data/vendor/libgit2/src/refs.c +34 -23
  287. data/vendor/libgit2/src/refs.h +8 -1
  288. data/vendor/libgit2/src/refspec.c +9 -16
  289. data/vendor/libgit2/src/regexp.c +221 -0
  290. data/vendor/libgit2/src/regexp.h +97 -0
  291. data/vendor/libgit2/src/remote.c +57 -55
  292. data/vendor/libgit2/src/remote.h +2 -2
  293. data/vendor/libgit2/src/repository.c +120 -103
  294. data/vendor/libgit2/src/repository.h +49 -40
  295. data/vendor/libgit2/src/revert.c +6 -1
  296. data/vendor/libgit2/src/revparse.c +18 -19
  297. data/vendor/libgit2/src/revwalk.c +71 -33
  298. data/vendor/libgit2/src/revwalk.h +20 -0
  299. data/vendor/libgit2/src/settings.c +13 -1
  300. data/vendor/libgit2/src/sortedcache.c +12 -26
  301. data/vendor/libgit2/src/sortedcache.h +1 -1
  302. data/vendor/libgit2/src/stash.c +45 -65
  303. data/vendor/libgit2/src/status.c +17 -11
  304. data/vendor/libgit2/src/streams/openssl.c +53 -1
  305. data/vendor/libgit2/src/streams/socket.c +2 -2
  306. data/vendor/libgit2/src/strmap.c +37 -84
  307. data/vendor/libgit2/src/strmap.h +105 -33
  308. data/vendor/libgit2/src/submodule.c +151 -126
  309. data/vendor/libgit2/src/submodule.h +1 -1
  310. data/vendor/libgit2/src/tag.c +10 -2
  311. data/vendor/libgit2/src/trace.c +1 -1
  312. data/vendor/libgit2/src/trace.h +3 -3
  313. data/vendor/libgit2/src/trailer.c +46 -32
  314. data/vendor/libgit2/src/transaction.c +3 -8
  315. data/vendor/libgit2/src/transports/auth.c +16 -15
  316. data/vendor/libgit2/src/transports/auth.h +18 -11
  317. data/vendor/libgit2/src/transports/auth_negotiate.c +64 -33
  318. data/vendor/libgit2/src/transports/auth_negotiate.h +2 -2
  319. data/vendor/libgit2/src/transports/auth_ntlm.c +223 -0
  320. data/vendor/libgit2/src/transports/auth_ntlm.h +38 -0
  321. data/vendor/libgit2/src/transports/credential.c +476 -0
  322. data/vendor/libgit2/src/transports/{cred_helpers.c → credential_helpers.c} +21 -8
  323. data/vendor/libgit2/src/transports/git.c +11 -16
  324. data/vendor/libgit2/src/transports/http.c +488 -1248
  325. data/vendor/libgit2/src/transports/http.h +4 -1
  326. data/vendor/libgit2/src/transports/httpclient.c +1526 -0
  327. data/vendor/libgit2/src/transports/httpclient.h +190 -0
  328. data/vendor/libgit2/src/transports/local.c +10 -10
  329. data/vendor/libgit2/src/transports/smart.c +19 -19
  330. data/vendor/libgit2/src/transports/smart.h +3 -3
  331. data/vendor/libgit2/src/transports/smart_protocol.c +40 -64
  332. data/vendor/libgit2/src/transports/ssh.c +77 -59
  333. data/vendor/libgit2/src/transports/winhttp.c +266 -241
  334. data/vendor/libgit2/src/tree-cache.c +14 -7
  335. data/vendor/libgit2/src/tree.c +16 -26
  336. data/vendor/libgit2/src/unix/map.c +1 -1
  337. data/vendor/libgit2/src/unix/posix.h +2 -12
  338. data/vendor/libgit2/src/userdiff.h +3 -1
  339. data/vendor/libgit2/src/util.c +51 -53
  340. data/vendor/libgit2/src/util.h +16 -21
  341. data/vendor/libgit2/src/wildmatch.c +320 -0
  342. data/vendor/libgit2/src/wildmatch.h +23 -0
  343. data/vendor/libgit2/src/win32/map.c +3 -5
  344. data/vendor/libgit2/src/win32/path_w32.c +12 -2
  345. data/vendor/libgit2/src/win32/path_w32.h +0 -29
  346. data/vendor/libgit2/src/win32/posix.h +1 -4
  347. data/vendor/libgit2/src/win32/posix_w32.c +48 -5
  348. data/vendor/libgit2/src/win32/precompiled.h +0 -2
  349. data/vendor/libgit2/src/win32/thread.c +5 -5
  350. data/vendor/libgit2/src/win32/w32_buffer.c +7 -3
  351. data/vendor/libgit2/src/win32/w32_common.h +39 -0
  352. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -93
  353. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -2
  354. data/vendor/libgit2/src/win32/w32_stack.c +4 -9
  355. data/vendor/libgit2/src/win32/w32_stack.h +3 -3
  356. data/vendor/libgit2/src/win32/w32_util.c +31 -0
  357. data/vendor/libgit2/src/win32/w32_util.h +6 -32
  358. data/vendor/libgit2/src/worktree.c +36 -22
  359. data/vendor/libgit2/src/xdiff/xdiffi.c +1 -1
  360. data/vendor/libgit2/src/xdiff/xmerge.c +12 -0
  361. data/vendor/libgit2/src/xdiff/xpatience.c +3 -0
  362. data/vendor/libgit2/src/zstream.c +5 -0
  363. data/vendor/libgit2/src/zstream.h +1 -0
  364. metadata +108 -38
  365. data/vendor/libgit2/deps/regex/CMakeLists.txt +0 -2
  366. data/vendor/libgit2/deps/regex/COPYING +0 -502
  367. data/vendor/libgit2/deps/regex/config.h +0 -7
  368. data/vendor/libgit2/deps/regex/regcomp.c +0 -3857
  369. data/vendor/libgit2/deps/regex/regex.c +0 -92
  370. data/vendor/libgit2/deps/regex/regex.h +0 -582
  371. data/vendor/libgit2/deps/regex/regex_internal.c +0 -1744
  372. data/vendor/libgit2/deps/regex/regex_internal.h +0 -819
  373. data/vendor/libgit2/deps/regex/regexec.c +0 -4369
  374. data/vendor/libgit2/include/git2/inttypes.h +0 -309
  375. data/vendor/libgit2/include/git2/sys/time.h +0 -31
  376. data/vendor/libgit2/libgit2.pc.in +0 -13
  377. data/vendor/libgit2/src/fnmatch.c +0 -248
  378. data/vendor/libgit2/src/fnmatch.h +0 -48
  379. data/vendor/libgit2/src/transports/cred.c +0 -390
@@ -14,11 +14,14 @@
14
14
  #include "global.h"
15
15
  #include "git2.h"
16
16
  #include "buffer.h"
17
+ #include "net.h"
17
18
  #include "netops.h"
18
19
  #include "smart.h"
19
- #include "cred.h"
20
20
  #include "streams/socket.h"
21
21
 
22
+ #include "git2/credential.h"
23
+ #include "git2/sys/credential.h"
24
+
22
25
  #ifdef GIT_SSH
23
26
 
24
27
  #define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport)
@@ -42,7 +45,7 @@ typedef struct {
42
45
  git_smart_subtransport parent;
43
46
  transport_smart *owner;
44
47
  ssh_stream *current_stream;
45
- git_cred *cred;
48
+ git_credential *cred;
46
49
  char *cmd_uploadpack;
47
50
  char *cmd_receivepack;
48
51
  } ssh_subtransport;
@@ -132,7 +135,7 @@ static int ssh_stream_read(
132
135
  size_t *bytes_read)
133
136
  {
134
137
  int rc;
135
- ssh_stream *s = (ssh_stream *)stream;
138
+ ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
136
139
 
137
140
  *bytes_read = 0;
138
141
 
@@ -170,7 +173,7 @@ static int ssh_stream_write(
170
173
  const char *buffer,
171
174
  size_t len)
172
175
  {
173
- ssh_stream *s = (ssh_stream *)stream;
176
+ ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
174
177
  size_t off = 0;
175
178
  ssize_t ret = 0;
176
179
 
@@ -196,7 +199,7 @@ static int ssh_stream_write(
196
199
 
197
200
  static void ssh_stream_free(git_smart_subtransport_stream *stream)
198
201
  {
199
- ssh_stream *s = (ssh_stream *)stream;
202
+ ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
200
203
  ssh_subtransport *t;
201
204
 
202
205
  if (!stream)
@@ -258,8 +261,7 @@ static int ssh_stream_alloc(
258
261
  }
259
262
 
260
263
  static int git_ssh_extract_url_parts(
261
- char **host,
262
- char **username,
264
+ git_net_url *urldata,
263
265
  const char *url)
264
266
  {
265
267
  char *colon, *at;
@@ -271,11 +273,11 @@ static int git_ssh_extract_url_parts(
271
273
  at = strchr(url, '@');
272
274
  if (at) {
273
275
  start = at + 1;
274
- *username = git__substrdup(url, at - url);
275
- GIT_ERROR_CHECK_ALLOC(*username);
276
+ urldata->username = git__substrdup(url, at - url);
277
+ GIT_ERROR_CHECK_ALLOC(urldata->username);
276
278
  } else {
277
279
  start = url;
278
- *username = NULL;
280
+ urldata->username = NULL;
279
281
  }
280
282
 
281
283
  if (colon == NULL || (colon < start)) {
@@ -283,13 +285,13 @@ static int git_ssh_extract_url_parts(
283
285
  return -1;
284
286
  }
285
287
 
286
- *host = git__substrdup(start, colon - start);
287
- GIT_ERROR_CHECK_ALLOC(*host);
288
+ urldata->host = git__substrdup(start, colon - start);
289
+ GIT_ERROR_CHECK_ALLOC(urldata->host);
288
290
 
289
291
  return 0;
290
292
  }
291
293
 
292
- static int ssh_agent_auth(LIBSSH2_SESSION *session, git_cred_ssh_key *c) {
294
+ static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) {
293
295
  int rc = LIBSSH2_ERROR_NONE;
294
296
 
295
297
  struct libssh2_agent_publickey *curr, *prev = NULL;
@@ -344,21 +346,21 @@ shutdown:
344
346
  }
345
347
 
346
348
  static int _git_ssh_authenticate_session(
347
- LIBSSH2_SESSION* session,
348
- git_cred* cred)
349
+ LIBSSH2_SESSION *session,
350
+ git_credential *cred)
349
351
  {
350
352
  int rc;
351
353
 
352
354
  do {
353
355
  git_error_clear();
354
356
  switch (cred->credtype) {
355
- case GIT_CREDTYPE_USERPASS_PLAINTEXT: {
356
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
357
+ case GIT_CREDENTIAL_USERPASS_PLAINTEXT: {
358
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
357
359
  rc = libssh2_userauth_password(session, c->username, c->password);
358
360
  break;
359
361
  }
360
- case GIT_CREDTYPE_SSH_KEY: {
361
- git_cred_ssh_key *c = (git_cred_ssh_key *)cred;
362
+ case GIT_CREDENTIAL_SSH_KEY: {
363
+ git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
362
364
 
363
365
  if (c->privatekey)
364
366
  rc = libssh2_userauth_publickey_fromfile(
@@ -369,17 +371,17 @@ static int _git_ssh_authenticate_session(
369
371
 
370
372
  break;
371
373
  }
372
- case GIT_CREDTYPE_SSH_CUSTOM: {
373
- git_cred_ssh_custom *c = (git_cred_ssh_custom *)cred;
374
+ case GIT_CREDENTIAL_SSH_CUSTOM: {
375
+ git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred;
374
376
 
375
377
  rc = libssh2_userauth_publickey(
376
378
  session, c->username, (const unsigned char *)c->publickey,
377
379
  c->publickey_len, c->sign_callback, &c->payload);
378
380
  break;
379
381
  }
380
- case GIT_CREDTYPE_SSH_INTERACTIVE: {
382
+ case GIT_CREDENTIAL_SSH_INTERACTIVE: {
381
383
  void **abstract = libssh2_session_abstract(session);
382
- git_cred_ssh_interactive *c = (git_cred_ssh_interactive *)cred;
384
+ git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred;
383
385
 
384
386
  /* ideally, we should be able to set this by calling
385
387
  * libssh2_session_init_ex() instead of libssh2_session_init().
@@ -399,8 +401,8 @@ static int _git_ssh_authenticate_session(
399
401
  break;
400
402
  }
401
403
  #ifdef GIT_SSH_MEMORY_CREDENTIALS
402
- case GIT_CREDTYPE_SSH_MEMORY: {
403
- git_cred_ssh_key *c = (git_cred_ssh_key *)cred;
404
+ case GIT_CREDENTIAL_SSH_MEMORY: {
405
+ git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
404
406
 
405
407
  assert(c->username);
406
408
  assert(c->privatekey);
@@ -436,10 +438,10 @@ static int _git_ssh_authenticate_session(
436
438
  return 0;
437
439
  }
438
440
 
439
- static int request_creds(git_cred **out, ssh_subtransport *t, const char *user, int auth_methods)
441
+ static int request_creds(git_credential **out, ssh_subtransport *t, const char *user, int auth_methods)
440
442
  {
441
443
  int error, no_callback = 0;
442
- git_cred *cred = NULL;
444
+ git_credential *cred = NULL;
443
445
 
444
446
  if (!t->owner->cred_acquire_cb) {
445
447
  no_callback = 1;
@@ -479,7 +481,7 @@ static int _git_ssh_session_create(
479
481
  {
480
482
  int rc = 0;
481
483
  LIBSSH2_SESSION* s;
482
- git_socket_stream *socket = (git_socket_stream *) io;
484
+ git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
483
485
 
484
486
  assert(session);
485
487
 
@@ -506,18 +508,19 @@ static int _git_ssh_session_create(
506
508
  return 0;
507
509
  }
508
510
 
511
+ #define SSH_DEFAULT_PORT "22"
512
+
509
513
  static int _git_ssh_setup_conn(
510
514
  ssh_subtransport *t,
511
515
  const char *url,
512
516
  const char *cmd,
513
517
  git_smart_subtransport_stream **stream)
514
518
  {
515
- char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
516
- const char *default_port="22";
519
+ git_net_url urldata = GIT_NET_URL_INIT;
517
520
  int auth_methods, error = 0;
518
521
  size_t i;
519
522
  ssh_stream *s;
520
- git_cred *cred = NULL;
523
+ git_credential *cred = NULL;
521
524
  LIBSSH2_SESSION* session=NULL;
522
525
  LIBSSH2_CHANNEL* channel=NULL;
523
526
 
@@ -535,19 +538,22 @@ static int _git_ssh_setup_conn(
535
538
  const char *p = ssh_prefixes[i];
536
539
 
537
540
  if (!git__prefixcmp(url, p)) {
538
- if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0)
541
+ if ((error = git_net_url_parse(&urldata, url)) < 0)
539
542
  goto done;
540
543
 
541
544
  goto post_extract;
542
545
  }
543
546
  }
544
- if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0)
547
+ if ((error = git_ssh_extract_url_parts(&urldata, url)) < 0)
545
548
  goto done;
546
- port = git__strdup(default_port);
547
- GIT_ERROR_CHECK_ALLOC(port);
549
+
550
+ if (urldata.port == NULL)
551
+ urldata.port = git__strdup(SSH_DEFAULT_PORT);
552
+
553
+ GIT_ERROR_CHECK_ALLOC(urldata.port);
548
554
 
549
555
  post_extract:
550
- if ((error = git_socket_stream_new(&s->io, host, port)) < 0 ||
556
+ if ((error = git_socket_stream_new(&s->io, urldata.host, urldata.port)) < 0 ||
551
557
  (error = git_stream_connect(s->io)) < 0)
552
558
  goto done;
553
559
 
@@ -560,6 +566,14 @@ post_extract:
560
566
 
561
567
  cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
562
568
 
569
+ #ifdef LIBSSH2_HOSTKEY_HASH_SHA256
570
+ key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256);
571
+ if (key != NULL) {
572
+ cert.type |= GIT_CERT_SSH_SHA256;
573
+ memcpy(&cert.hash_sha256, key, 32);
574
+ }
575
+ #endif
576
+
563
577
  key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
564
578
  if (key != NULL) {
565
579
  cert.type |= GIT_CERT_SSH_SHA1;
@@ -583,7 +597,7 @@ post_extract:
583
597
 
584
598
  cert_ptr = &cert;
585
599
 
586
- error = t->owner->certificate_check_cb((git_cert *) cert_ptr, 0, host, t->owner->message_cb_payload);
600
+ error = t->owner->certificate_check_cb((git_cert *) cert_ptr, 0, urldata.host, t->owner->message_cb_payload);
587
601
 
588
602
  if (error < 0 && error != GIT_PASSTHROUGH) {
589
603
  if (!git_error_last())
@@ -594,21 +608,21 @@ post_extract:
594
608
  }
595
609
 
596
610
  /* we need the username to ask for auth methods */
597
- if (!user) {
598
- if ((error = request_creds(&cred, t, NULL, GIT_CREDTYPE_USERNAME)) < 0)
611
+ if (!urldata.username) {
612
+ if ((error = request_creds(&cred, t, NULL, GIT_CREDENTIAL_USERNAME)) < 0)
599
613
  goto done;
600
614
 
601
- user = git__strdup(((git_cred_username *) cred)->username);
615
+ urldata.username = git__strdup(((git_credential_username *) cred)->username);
602
616
  cred->free(cred);
603
617
  cred = NULL;
604
- if (!user)
618
+ if (!urldata.username)
605
619
  goto done;
606
- } else if (user && pass) {
607
- if ((error = git_cred_userpass_plaintext_new(&cred, user, pass)) < 0)
620
+ } else if (urldata.username && urldata.password) {
621
+ if ((error = git_credential_userpass_plaintext_new(&cred, urldata.username, urldata.password)) < 0)
608
622
  goto done;
609
623
  }
610
624
 
611
- if ((error = list_auth_methods(&auth_methods, session, user)) < 0)
625
+ if ((error = list_auth_methods(&auth_methods, session, urldata.username)) < 0)
612
626
  goto done;
613
627
 
614
628
  error = GIT_EAUTH;
@@ -622,16 +636,24 @@ post_extract:
622
636
  cred = NULL;
623
637
  }
624
638
 
625
- if ((error = request_creds(&cred, t, user, auth_methods)) < 0)
639
+ if ((error = request_creds(&cred, t, urldata.username, auth_methods)) < 0)
626
640
  goto done;
627
641
 
628
- if (strcmp(user, git_cred__username(cred))) {
642
+ if (strcmp(urldata.username, git_credential_get_username(cred))) {
629
643
  git_error_set(GIT_ERROR_SSH, "username does not match previous request");
630
644
  error = -1;
631
645
  goto done;
632
646
  }
633
647
 
634
648
  error = _git_ssh_authenticate_session(session, cred);
649
+
650
+ if (error == GIT_EAUTH) {
651
+ /* refresh auth methods */
652
+ if ((error = list_auth_methods(&auth_methods, session, urldata.username)) < 0)
653
+ goto done;
654
+ else
655
+ error = GIT_EAUTH;
656
+ }
635
657
  }
636
658
 
637
659
  if (error < 0)
@@ -662,11 +684,7 @@ done:
662
684
  if (cred)
663
685
  cred->free(cred);
664
686
 
665
- git__free(host);
666
- git__free(port);
667
- git__free(path);
668
- git__free(user);
669
- git__free(pass);
687
+ git_net_url_dispose(&urldata);
670
688
 
671
689
  return error;
672
690
  }
@@ -730,7 +748,7 @@ static int _ssh_action(
730
748
  const char *url,
731
749
  git_smart_service_t action)
732
750
  {
733
- ssh_subtransport *t = (ssh_subtransport *) subtransport;
751
+ ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
734
752
 
735
753
  switch (action) {
736
754
  case GIT_SERVICE_UPLOADPACK_LS:
@@ -752,7 +770,7 @@ static int _ssh_action(
752
770
 
753
771
  static int _ssh_close(git_smart_subtransport *subtransport)
754
772
  {
755
- ssh_subtransport *t = (ssh_subtransport *) subtransport;
773
+ ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
756
774
 
757
775
  assert(!t->current_stream);
758
776
 
@@ -763,7 +781,7 @@ static int _ssh_close(git_smart_subtransport *subtransport)
763
781
 
764
782
  static void _ssh_free(git_smart_subtransport *subtransport)
765
783
  {
766
- ssh_subtransport *t = (ssh_subtransport *) subtransport;
784
+ ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
767
785
 
768
786
  assert(!t->current_stream);
769
787
 
@@ -796,23 +814,23 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
796
814
  ptr++;
797
815
 
798
816
  if (!git__prefixcmp(ptr, SSH_AUTH_PUBLICKEY)) {
799
- *out |= GIT_CREDTYPE_SSH_KEY;
800
- *out |= GIT_CREDTYPE_SSH_CUSTOM;
817
+ *out |= GIT_CREDENTIAL_SSH_KEY;
818
+ *out |= GIT_CREDENTIAL_SSH_CUSTOM;
801
819
  #ifdef GIT_SSH_MEMORY_CREDENTIALS
802
- *out |= GIT_CREDTYPE_SSH_MEMORY;
820
+ *out |= GIT_CREDENTIAL_SSH_MEMORY;
803
821
  #endif
804
822
  ptr += strlen(SSH_AUTH_PUBLICKEY);
805
823
  continue;
806
824
  }
807
825
 
808
826
  if (!git__prefixcmp(ptr, SSH_AUTH_PASSWORD)) {
809
- *out |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
827
+ *out |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
810
828
  ptr += strlen(SSH_AUTH_PASSWORD);
811
829
  continue;
812
830
  }
813
831
 
814
832
  if (!git__prefixcmp(ptr, SSH_AUTH_KEYBOARD_INTERACTIVE)) {
815
- *out |= GIT_CREDTYPE_SSH_INTERACTIVE;
833
+ *out |= GIT_CREDENTIAL_SSH_INTERACTIVE;
816
834
  ptr += strlen(SSH_AUTH_KEYBOARD_INTERACTIVE);
817
835
  continue;
818
836
  }
@@ -19,6 +19,7 @@
19
19
  #include "repository.h"
20
20
  #include "global.h"
21
21
  #include "http.h"
22
+ #include "git2/sys/credential.h"
22
23
 
23
24
  #include <wincrypt.h>
24
25
  #include <winhttp.h>
@@ -52,6 +53,12 @@
52
53
  # define HTTP_STATUS_PERMANENT_REDIRECT 308
53
54
  #endif
54
55
 
56
+ #ifndef DWORD_MAX
57
+ # define DWORD_MAX 0xffffffff
58
+ #endif
59
+
60
+ bool git_http__expect_continue = false;
61
+
55
62
  static const char *prefix_https = "https://";
56
63
  static const char *upload_pack_service = "upload-pack";
57
64
  static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";
@@ -104,24 +111,44 @@ typedef struct {
104
111
  chunked : 1;
105
112
  } winhttp_stream;
106
113
 
114
+ typedef struct {
115
+ git_net_url url;
116
+ git_credential *cred;
117
+ int auth_mechanisms;
118
+ bool url_cred_presented;
119
+ } winhttp_server;
120
+
107
121
  typedef struct {
108
122
  git_smart_subtransport parent;
109
123
  transport_smart *owner;
110
- gitno_connection_data connection_data;
111
- gitno_connection_data proxy_connection_data;
112
- git_cred *cred;
113
- git_cred *url_cred;
114
- git_cred *proxy_cred;
115
- int auth_mechanisms;
124
+
125
+ winhttp_server server;
126
+ winhttp_server proxy;
127
+
116
128
  HINTERNET session;
117
129
  HINTERNET connection;
118
130
  } winhttp_subtransport;
119
131
 
120
- static int _apply_userpass_credential(HINTERNET request, DWORD target, DWORD scheme, git_cred *cred)
132
+ static int apply_userpass_credentials(HINTERNET request, DWORD target, int mechanisms, git_credential *cred)
121
133
  {
122
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
123
- wchar_t *user, *pass;
134
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
135
+ wchar_t *user = NULL, *pass = NULL;
124
136
  int user_len = 0, pass_len = 0, error = 0;
137
+ DWORD native_scheme;
138
+
139
+ if (mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) {
140
+ native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
141
+ } else if (mechanisms & GIT_WINHTTP_AUTH_NTLM) {
142
+ native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
143
+ } else if (mechanisms & GIT_WINHTTP_AUTH_DIGEST) {
144
+ native_scheme = WINHTTP_AUTH_SCHEME_DIGEST;
145
+ } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) {
146
+ native_scheme = WINHTTP_AUTH_SCHEME_BASIC;
147
+ } else {
148
+ git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme");
149
+ error = -1;
150
+ goto done;
151
+ }
125
152
 
126
153
  if ((error = user_len = git__utf8_to_16_alloc(&user, c->username)) < 0)
127
154
  goto done;
@@ -129,7 +156,7 @@ static int _apply_userpass_credential(HINTERNET request, DWORD target, DWORD sch
129
156
  if ((error = pass_len = git__utf8_to_16_alloc(&pass, c->password)) < 0)
130
157
  goto done;
131
158
 
132
- if (!WinHttpSetCredentials(request, target, scheme, user, pass, NULL)) {
159
+ if (!WinHttpSetCredentials(request, target, native_scheme, user, pass, NULL)) {
133
160
  git_error_set(GIT_ERROR_OS, "failed to set credentials");
134
161
  error = -1;
135
162
  }
@@ -147,81 +174,62 @@ done:
147
174
  return error;
148
175
  }
149
176
 
150
- static int apply_userpass_credential_proxy(HINTERNET request, git_cred *cred, int mechanisms)
177
+ static int apply_default_credentials(HINTERNET request, DWORD target, int mechanisms)
151
178
  {
152
- if (GIT_WINHTTP_AUTH_DIGEST & mechanisms) {
153
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_PROXY,
154
- WINHTTP_AUTH_SCHEME_DIGEST, cred);
155
- }
156
-
157
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_PROXY,
158
- WINHTTP_AUTH_SCHEME_BASIC, cred);
159
- }
160
-
161
- static int apply_userpass_credential(HINTERNET request, int mechanisms, git_cred *cred)
162
- {
163
- DWORD native_scheme;
179
+ DWORD autologon_level = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW;
180
+ DWORD native_scheme = 0;
164
181
 
165
- if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) ||
166
- (mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE)) {
182
+ if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0) {
183
+ native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
184
+ } else if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0) {
167
185
  native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
168
- } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) {
169
- native_scheme = WINHTTP_AUTH_SCHEME_BASIC;
170
186
  } else {
171
- git_error_set(GIT_ERROR_NET, "invalid authentication scheme");
187
+ git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme");
172
188
  return -1;
173
189
  }
174
190
 
175
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_SERVER,
176
- native_scheme, cred);
177
- }
178
-
179
- static int apply_default_credentials(HINTERNET request, int mechanisms)
180
- {
181
- /* Either the caller explicitly requested that default credentials be passed,
182
- * or our fallback credential callback was invoked and checked that the target
183
- * URI was in the appropriate Internet Explorer security zone. By setting this
184
- * flag, we guarantee that the credentials are delivered by WinHTTP. The default
185
- * is "medium" which applies to the intranet and sounds like it would correspond
186
- * to Internet Explorer security zones, but in fact does not. */
187
- DWORD data = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW;
188
- DWORD native_scheme = 0;
189
-
190
- if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0)
191
- native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
192
-
193
- if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0)
194
- native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
195
-
196
- if (!native_scheme) {
197
- git_error_set(GIT_ERROR_NET, "invalid authentication scheme");
191
+ /*
192
+ * Autologon policy must be "low" to use default creds.
193
+ * This is safe as the user has explicitly requested it.
194
+ */
195
+ if (!WinHttpSetOption(request, WINHTTP_OPTION_AUTOLOGON_POLICY, &autologon_level, sizeof(DWORD))) {
196
+ git_error_set(GIT_ERROR_OS, "could not configure logon policy");
198
197
  return -1;
199
198
  }
200
199
 
201
- if (!WinHttpSetOption(request, WINHTTP_OPTION_AUTOLOGON_POLICY, &data, sizeof(DWORD)))
202
- return -1;
203
-
204
- if (!WinHttpSetCredentials(request, WINHTTP_AUTH_TARGET_SERVER, native_scheme, NULL, NULL, NULL))
200
+ if (!WinHttpSetCredentials(request, target, native_scheme, NULL, NULL, NULL)) {
201
+ git_error_set(GIT_ERROR_OS, "could not configure credentials");
205
202
  return -1;
203
+ }
206
204
 
207
205
  return 0;
208
206
  }
209
207
 
210
- static int fallback_cred_acquire_cb(
211
- git_cred **cred,
212
- const char *url,
213
- const char *username_from_url,
208
+ static int acquire_url_cred(
209
+ git_credential **cred,
214
210
  unsigned int allowed_types,
215
- void *payload)
211
+ const char *username,
212
+ const char *password)
216
213
  {
217
- int error = 1;
214
+ if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT)
215
+ return git_credential_userpass_plaintext_new(cred, username, password);
216
+
217
+ if ((allowed_types & GIT_CREDENTIAL_DEFAULT) && *username == '\0' && *password == '\0')
218
+ return git_credential_default_new(cred);
218
219
 
219
- GIT_UNUSED(username_from_url);
220
- GIT_UNUSED(payload);
220
+ return 1;
221
+ }
222
+
223
+ static int acquire_fallback_cred(
224
+ git_credential **cred,
225
+ const char *url,
226
+ unsigned int allowed_types)
227
+ {
228
+ int error = 1;
221
229
 
222
230
  /* If the target URI supports integrated Windows authentication
223
231
  * as an authentication mechanism */
224
- if (GIT_CREDTYPE_DEFAULT & allowed_types) {
232
+ if (GIT_CREDENTIAL_DEFAULT & allowed_types) {
225
233
  wchar_t *wide_url;
226
234
  HRESULT hCoInitResult;
227
235
 
@@ -245,21 +253,21 @@ static int fallback_cred_acquire_cb(
245
253
  (URLZONE_LOCAL_MACHINE == dwZone ||
246
254
  URLZONE_INTRANET == dwZone ||
247
255
  URLZONE_TRUSTED == dwZone)) {
248
- git_cred *existing = *cred;
256
+ git_credential *existing = *cred;
249
257
 
250
258
  if (existing)
251
259
  existing->free(existing);
252
260
 
253
261
  /* Then use default Windows credentials to authenticate this request */
254
- error = git_cred_default_new(cred);
262
+ error = git_credential_default_new(cred);
255
263
  }
256
264
 
257
265
  pISM->lpVtbl->Release(pISM);
258
266
  }
259
267
 
260
- if (SUCCEEDED(hCoInitResult))
261
- /* Only unitialize if the call to CoInitializeEx was successful. */
262
- CoUninitialize();
268
+ /* Only unitialize if the call to CoInitializeEx was successful. */
269
+ if (SUCCEEDED(hCoInitResult))
270
+ CoUninitialize();
263
271
  }
264
272
 
265
273
  git__free(wide_url);
@@ -279,12 +287,12 @@ static int certificate_check(winhttp_stream *s, int valid)
279
287
  /* If there is no override, we should fail if WinHTTP doesn't think it's fine */
280
288
  if (t->owner->certificate_check_cb == NULL && !valid) {
281
289
  if (!git_error_last())
282
- git_error_set(GIT_ERROR_NET, "unknown certificate check failure");
290
+ git_error_set(GIT_ERROR_HTTP, "unknown certificate check failure");
283
291
 
284
292
  return GIT_ECERTIFICATE;
285
293
  }
286
294
 
287
- if (t->owner->certificate_check_cb == NULL || !t->connection_data.use_ssl)
295
+ if (t->owner->certificate_check_cb == NULL || git__strcmp(t->server.url.scheme, "https") != 0)
288
296
  return 0;
289
297
 
290
298
  if (!WinHttpQueryOption(s->request, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert_ctx, &cert_ctx_size)) {
@@ -296,14 +304,14 @@ static int certificate_check(winhttp_stream *s, int valid)
296
304
  cert.parent.cert_type = GIT_CERT_X509;
297
305
  cert.data = cert_ctx->pbCertEncoded;
298
306
  cert.len = cert_ctx->cbCertEncoded;
299
- error = t->owner->certificate_check_cb((git_cert *) &cert, valid, t->connection_data.host, t->owner->message_cb_payload);
307
+ error = t->owner->certificate_check_cb((git_cert *) &cert, valid, t->server.url.host, t->owner->message_cb_payload);
300
308
  CertFreeCertificateContext(cert_ctx);
301
309
 
302
310
  if (error == GIT_PASSTHROUGH)
303
311
  error = valid ? 0 : GIT_ECERTIFICATE;
304
312
 
305
313
  if (error < 0 && !git_error_last())
306
- git_error_set(GIT_ERROR_NET, "user cancelled certificate check");
314
+ git_error_set(GIT_ERROR_HTTP, "user cancelled certificate check");
307
315
 
308
316
  return error;
309
317
  }
@@ -333,8 +341,25 @@ static void winhttp_stream_close(winhttp_stream *s)
333
341
  s->sent_request = 0;
334
342
  }
335
343
 
336
- #define SCHEME_HTTP "http://"
337
- #define SCHEME_HTTPS "https://"
344
+ static int apply_credentials(
345
+ HINTERNET request,
346
+ git_net_url *url,
347
+ int target,
348
+ git_credential *creds,
349
+ int mechanisms)
350
+ {
351
+ int error = 0;
352
+
353
+ GIT_UNUSED(url);
354
+
355
+ /* If we have creds, just apply them */
356
+ if (creds && creds->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT)
357
+ error = apply_userpass_credentials(request, target, mechanisms, creds);
358
+ else if (creds && creds->credtype == GIT_CREDENTIAL_DEFAULT)
359
+ error = apply_default_credentials(request, target, mechanisms);
360
+
361
+ return error;
362
+ }
338
363
 
339
364
  static int winhttp_stream_connect(winhttp_stream *s)
340
365
  {
@@ -348,11 +373,17 @@ static int winhttp_stream_connect(winhttp_stream *s)
348
373
  unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
349
374
  int default_timeout = TIMEOUT_INFINITE;
350
375
  int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
376
+ DWORD autologon_policy = WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH;
377
+
378
+ const char *service_url = s->service_url;
351
379
  size_t i;
352
380
  const git_proxy_options *proxy_opts;
353
381
 
382
+ /* If path already ends in /, remove the leading slash from service_url */
383
+ if ((git__suffixcmp(t->server.url.path, "/") == 0) && (git__prefixcmp(service_url, "/") == 0))
384
+ service_url++;
354
385
  /* Prepare URL */
355
- git_buf_printf(&buf, "%s%s", t->connection_data.path, s->service_url);
386
+ git_buf_printf(&buf, "%s%s", t->server.url.path, service_url);
356
387
 
357
388
  if (git_buf_oom(&buf))
358
389
  return -1;
@@ -371,13 +402,17 @@ static int winhttp_stream_connect(winhttp_stream *s)
371
402
  NULL,
372
403
  WINHTTP_NO_REFERER,
373
404
  types,
374
- t->connection_data.use_ssl ? WINHTTP_FLAG_SECURE : 0);
405
+ git__strcmp(t->server.url.scheme, "https") == 0 ? WINHTTP_FLAG_SECURE : 0);
375
406
 
376
407
  if (!s->request) {
377
408
  git_error_set(GIT_ERROR_OS, "failed to open request");
378
409
  goto on_error;
379
410
  }
380
411
 
412
+ /* Never attempt default credentials; we'll provide them explicitly. */
413
+ if (!WinHttpSetOption(s->request, WINHTTP_OPTION_AUTOLOGON_POLICY, &autologon_policy, sizeof(DWORD)))
414
+ return -1;
415
+
381
416
  if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
382
417
  git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP");
383
418
  goto on_error;
@@ -386,7 +421,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
386
421
  proxy_opts = &t->owner->proxy;
387
422
  if (proxy_opts->type == GIT_PROXY_AUTO) {
388
423
  /* Set proxy if necessary */
389
- if (git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &proxy_url) < 0)
424
+ if (git_remote__get_http_proxy(t->owner->owner, (strcmp(t->server.url.scheme, "https") == 0), &proxy_url) < 0)
390
425
  goto on_error;
391
426
  }
392
427
  else if (proxy_opts->type == GIT_PROXY_SPECIFIED) {
@@ -399,38 +434,24 @@ static int winhttp_stream_connect(winhttp_stream *s)
399
434
  WINHTTP_PROXY_INFO proxy_info;
400
435
  wchar_t *proxy_wide;
401
436
 
402
- if (!git__prefixcmp(proxy_url, SCHEME_HTTP)) {
403
- t->proxy_connection_data.use_ssl = false;
404
- } else if (!git__prefixcmp(proxy_url, SCHEME_HTTPS)) {
405
- t->proxy_connection_data.use_ssl = true;
406
- } else {
407
- git_error_set(GIT_ERROR_NET, "invalid URL: '%s'", proxy_url);
408
- return -1;
409
- }
437
+ git_net_url_dispose(&t->proxy.url);
410
438
 
411
- gitno_connection_data_free_ptrs(&t->proxy_connection_data);
412
-
413
- if ((error = gitno_extract_url_parts(&t->proxy_connection_data.host, &t->proxy_connection_data.port, NULL,
414
- &t->proxy_connection_data.user, &t->proxy_connection_data.pass, proxy_url, NULL)) < 0)
439
+ if ((error = git_net_url_parse(&t->proxy.url, proxy_url)) < 0)
415
440
  goto on_error;
416
441
 
417
- if (t->proxy_connection_data.user && t->proxy_connection_data.pass) {
418
- if (t->proxy_cred) {
419
- t->proxy_cred->free(t->proxy_cred);
420
- }
421
-
422
- if ((error = git_cred_userpass_plaintext_new(&t->proxy_cred, t->proxy_connection_data.user, t->proxy_connection_data.pass)) < 0)
423
- goto on_error;
442
+ if (strcmp(t->proxy.url.scheme, "http") != 0 && strcmp(t->proxy.url.scheme, "https") != 0) {
443
+ git_error_set(GIT_ERROR_HTTP, "invalid URL: '%s'", proxy_url);
444
+ error = -1;
445
+ goto on_error;
424
446
  }
425
447
 
426
- if (t->proxy_connection_data.use_ssl)
427
- git_buf_PUTS(&processed_url, SCHEME_HTTPS);
428
- else
429
- git_buf_PUTS(&processed_url, SCHEME_HTTP);
448
+ git_buf_puts(&processed_url, t->proxy.url.scheme);
449
+ git_buf_PUTS(&processed_url, "://");
450
+
451
+ git_buf_puts(&processed_url, t->proxy.url.host);
430
452
 
431
- git_buf_puts(&processed_url, t->proxy_connection_data.host);
432
- if (t->proxy_connection_data.port)
433
- git_buf_printf(&processed_url, ":%s", t->proxy_connection_data.port);
453
+ if (!git_net_url_is_default_port(&t->proxy.url))
454
+ git_buf_printf(&processed_url, ":%s", t->proxy.url.port);
434
455
 
435
456
  if (git_buf_oom(&processed_url)) {
436
457
  error = -1;
@@ -458,13 +479,8 @@ static int winhttp_stream_connect(winhttp_stream *s)
458
479
 
459
480
  git__free(proxy_wide);
460
481
 
461
- if (t->proxy_cred) {
462
- if (t->proxy_cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT) {
463
- if ((error = apply_userpass_credential_proxy(s->request, t->proxy_cred, t->auth_mechanisms)) < 0)
464
- goto on_error;
465
- }
466
- }
467
-
482
+ if ((error = apply_credentials(s->request, &t->proxy.url, WINHTTP_AUTH_TARGET_PROXY, t->proxy.cred, t->proxy.auth_mechanisms)) < 0)
483
+ goto on_error;
468
484
  }
469
485
 
470
486
  /* Disable WinHTTP redirects so we can handle them manually. Why, you ask?
@@ -475,6 +491,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
475
491
  &disable_redirects,
476
492
  sizeof(disable_redirects))) {
477
493
  git_error_set(GIT_ERROR_OS, "failed to disable redirects");
494
+ error = -1;
478
495
  goto on_error;
479
496
  }
480
497
 
@@ -547,32 +564,15 @@ static int winhttp_stream_connect(winhttp_stream *s)
547
564
  }
548
565
 
549
566
  /* If requested, disable certificate validation */
550
- if (t->connection_data.use_ssl) {
567
+ if (strcmp(t->server.url.scheme, "https") == 0) {
551
568
  int flags;
552
569
 
553
570
  if (t->owner->parent.read_flags(&t->owner->parent, &flags) < 0)
554
571
  goto on_error;
555
572
  }
556
573
 
557
- /* If we have a credential on the subtransport, apply it to the request */
558
- if (t->cred &&
559
- t->cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT &&
560
- apply_userpass_credential(s->request, t->auth_mechanisms, t->cred) < 0)
574
+ if ((error = apply_credentials(s->request, &t->server.url, WINHTTP_AUTH_TARGET_SERVER, t->server.cred, t->server.auth_mechanisms)) < 0)
561
575
  goto on_error;
562
- else if (t->cred &&
563
- t->cred->credtype == GIT_CREDTYPE_DEFAULT &&
564
- apply_default_credentials(s->request, t->auth_mechanisms) < 0)
565
- goto on_error;
566
-
567
- /* If no other credentials have been applied and the URL has username and
568
- * password, use those */
569
- if (!t->cred && t->connection_data.user && t->connection_data.pass) {
570
- if (!t->url_cred &&
571
- git_cred_userpass_plaintext_new(&t->url_cred, t->connection_data.user, t->connection_data.pass) < 0)
572
- goto on_error;
573
- if (apply_userpass_credential(s->request, GIT_WINHTTP_AUTH_BASIC, t->url_cred) < 0)
574
- goto on_error;
575
- }
576
576
 
577
577
  /* We've done everything up to calling WinHttpSendRequest. */
578
578
 
@@ -588,9 +588,9 @@ on_error:
588
588
  }
589
589
 
590
590
  static int parse_unauthorized_response(
591
- HINTERNET request,
592
591
  int *allowed_types,
593
- int *allowed_mechanisms)
592
+ int *allowed_mechanisms,
593
+ HINTERNET request)
594
594
  {
595
595
  DWORD supported, first, target;
596
596
 
@@ -606,23 +606,23 @@ static int parse_unauthorized_response(
606
606
  }
607
607
 
608
608
  if (WINHTTP_AUTH_SCHEME_NTLM & supported) {
609
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
610
- *allowed_types |= GIT_CREDTYPE_DEFAULT;
609
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
610
+ *allowed_types |= GIT_CREDENTIAL_DEFAULT;
611
611
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_NTLM;
612
612
  }
613
613
 
614
614
  if (WINHTTP_AUTH_SCHEME_NEGOTIATE & supported) {
615
- *allowed_types |= GIT_CREDTYPE_DEFAULT;
615
+ *allowed_types |= GIT_CREDENTIAL_DEFAULT;
616
616
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_NEGOTIATE;
617
617
  }
618
618
 
619
619
  if (WINHTTP_AUTH_SCHEME_BASIC & supported) {
620
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
620
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
621
621
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_BASIC;
622
622
  }
623
623
 
624
624
  if (WINHTTP_AUTH_SCHEME_DIGEST & supported) {
625
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
625
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
626
626
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_DIGEST;
627
627
  }
628
628
 
@@ -703,27 +703,31 @@ static void CALLBACK winhttp_status(
703
703
  {
704
704
  DWORD status;
705
705
 
706
+ GIT_UNUSED(connection);
707
+ GIT_UNUSED(ctx);
708
+ GIT_UNUSED(info_len);
709
+
706
710
  if (code != WINHTTP_CALLBACK_STATUS_SECURE_FAILURE)
707
711
  return;
708
712
 
709
713
  status = *((DWORD *)info);
710
714
 
711
715
  if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID))
712
- git_error_set(GIT_ERROR_NET, "SSL certificate issued for different common name");
716
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate issued for different common name");
713
717
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID))
714
- git_error_set(GIT_ERROR_NET, "SSL certificate has expired");
718
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate has expired");
715
719
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA))
716
- git_error_set(GIT_ERROR_NET, "SSL certificate signed by unknown CA");
720
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate signed by unknown CA");
717
721
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT))
718
- git_error_set(GIT_ERROR_NET, "SSL certificate is invalid");
722
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate is invalid");
719
723
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED))
720
- git_error_set(GIT_ERROR_NET, "certificate revocation check failed");
724
+ git_error_set(GIT_ERROR_HTTP, "certificate revocation check failed");
721
725
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED))
722
- git_error_set(GIT_ERROR_NET, "SSL certificate was revoked");
726
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate was revoked");
723
727
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR))
724
- git_error_set(GIT_ERROR_NET, "security libraries could not be loaded");
728
+ git_error_set(GIT_ERROR_HTTP, "security libraries could not be loaded");
725
729
  else
726
- git_error_set(GIT_ERROR_NET, "unknown security error %lu", status);
730
+ git_error_set(GIT_ERROR_HTTP, "unknown security error %lu", status);
727
731
  }
728
732
 
729
733
  static int winhttp_connect(
@@ -745,12 +749,12 @@ static int winhttp_connect(
745
749
  t->connection = NULL;
746
750
 
747
751
  /* Prepare port */
748
- if (git__strntol32(&port, t->connection_data.port,
749
- strlen(t->connection_data.port), NULL, 10) < 0)
752
+ if (git__strntol32(&port, t->server.url.port,
753
+ strlen(t->server.url.port), NULL, 10) < 0)
750
754
  return -1;
751
755
 
752
756
  /* Prepare host */
753
- if (git__utf8_to_16_alloc(&wide_host, t->connection_data.host) < 0) {
757
+ if (git__utf8_to_16_alloc(&wide_host, t->server.url.host) < 0) {
754
758
  git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
755
759
  return -1;
756
760
  }
@@ -828,13 +832,18 @@ on_error:
828
832
  return error;
829
833
  }
830
834
 
831
- static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
835
+ static int do_send_request(winhttp_stream *s, size_t len, bool chunked)
832
836
  {
833
837
  int attempts;
834
838
  bool success;
835
839
 
840
+ if (len > DWORD_MAX) {
841
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
842
+ return -1;
843
+ }
844
+
836
845
  for (attempts = 0; attempts < 5; attempts++) {
837
- if (ignore_length) {
846
+ if (chunked) {
838
847
  success = WinHttpSendRequest(s->request,
839
848
  WINHTTP_NO_ADDITIONAL_HEADERS, 0,
840
849
  WINHTTP_NO_REQUEST_DATA, 0,
@@ -843,7 +852,7 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
843
852
  success = WinHttpSendRequest(s->request,
844
853
  WINHTTP_NO_ADDITIONAL_HEADERS, 0,
845
854
  WINHTTP_NO_REQUEST_DATA, 0,
846
- len, 0);
855
+ (DWORD)len, 0);
847
856
  }
848
857
 
849
858
  if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL)
@@ -853,13 +862,13 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
853
862
  return success ? 0 : -1;
854
863
  }
855
864
 
856
- static int send_request(winhttp_stream *s, size_t len, int ignore_length)
865
+ static int send_request(winhttp_stream *s, size_t len, bool chunked)
857
866
  {
858
867
  int request_failed = 0, cert_valid = 1, error = 0;
859
868
  DWORD ignore_flags;
860
869
 
861
870
  git_error_clear();
862
- if ((error = do_send_request(s, len, ignore_length)) < 0) {
871
+ if ((error = do_send_request(s, len, chunked)) < 0) {
863
872
  if (GetLastError() != ERROR_WINHTTP_SECURE_FAILURE) {
864
873
  git_error_set(GIT_ERROR_OS, "failed to send request");
865
874
  return -1;
@@ -888,12 +897,65 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length)
888
897
  return -1;
889
898
  }
890
899
 
891
- if ((error = do_send_request(s, len, ignore_length)) < 0)
900
+ if ((error = do_send_request(s, len, chunked)) < 0)
892
901
  git_error_set(GIT_ERROR_OS, "failed to send request with unchecked certificate");
893
902
 
894
903
  return error;
895
904
  }
896
905
 
906
+ static int acquire_credentials(
907
+ HINTERNET request,
908
+ winhttp_server *server,
909
+ const char *url_str,
910
+ git_credential_acquire_cb cred_cb,
911
+ void *cred_cb_payload)
912
+ {
913
+ int allowed_types;
914
+ int error = 1;
915
+
916
+ if (parse_unauthorized_response(&allowed_types, &server->auth_mechanisms, request) < 0)
917
+ return -1;
918
+
919
+ if (allowed_types) {
920
+ git_credential_free(server->cred);
921
+ server->cred = NULL;
922
+
923
+ /* Start with URL-specified credentials, if there were any. */
924
+ if (!server->url_cred_presented && server->url.username && server->url.password) {
925
+ error = acquire_url_cred(&server->cred, allowed_types, server->url.username, server->url.password);
926
+ server->url_cred_presented = 1;
927
+
928
+ if (error < 0)
929
+ return error;
930
+ }
931
+
932
+ /* Next use the user-defined callback, if there is one. */
933
+ if (error > 0 && cred_cb) {
934
+ error = cred_cb(&server->cred, url_str, server->url.username, allowed_types, cred_cb_payload);
935
+
936
+ /* Treat GIT_PASSTHROUGH as though git_credential_acquire_cb isn't set */
937
+ if (error == GIT_PASSTHROUGH)
938
+ error = 1;
939
+ else if (error < 0)
940
+ return error;
941
+ }
942
+
943
+ /* Finally, invoke the fallback default credential lookup. */
944
+ if (error > 0) {
945
+ error = acquire_fallback_cred(&server->cred, url_str, allowed_types);
946
+
947
+ if (error < 0)
948
+ return error;
949
+ }
950
+ }
951
+
952
+ /*
953
+ * No error occurred but we could not find appropriate credentials.
954
+ * This behaves like a pass-through.
955
+ */
956
+ return error;
957
+ }
958
+
897
959
  static int winhttp_stream_read(
898
960
  git_smart_subtransport_stream *stream,
899
961
  char *buffer,
@@ -909,7 +971,7 @@ static int winhttp_stream_read(
909
971
  replay:
910
972
  /* Enforce a reasonable cap on the number of replays */
911
973
  if (replay_count++ >= GIT_HTTP_REPLAY_MAX) {
912
- git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays");
974
+ git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays");
913
975
  return -1;
914
976
  }
915
977
 
@@ -924,7 +986,7 @@ replay:
924
986
 
925
987
  if (!s->sent_request) {
926
988
 
927
- if ((error = send_request(s, s->post_body_len, 0)) < 0)
989
+ if ((error = send_request(s, s->post_body_len, false)) < 0)
928
990
  return error;
929
991
 
930
992
  s->sent_request = 1;
@@ -960,6 +1022,7 @@ replay:
960
1022
  }
961
1023
 
962
1024
  buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1025
+ GIT_ERROR_CHECK_ALLOC(buffer);
963
1026
 
964
1027
  while (len > 0) {
965
1028
  DWORD bytes_written;
@@ -1067,7 +1130,7 @@ replay:
1067
1130
 
1068
1131
  if (!git__prefixcmp_icase(location8, prefix_https)) {
1069
1132
  /* Upgrade to secure connection; disconnect and start over */
1070
- if (gitno_connection_data_from_url(&t->connection_data, location8, s->service_url) < 0) {
1133
+ if (git_net_url_apply_redirect(&t->server.url, location8, s->service_url) < 0) {
1071
1134
  git__free(location8);
1072
1135
  return -1;
1073
1136
  }
@@ -1082,72 +1145,39 @@ replay:
1082
1145
  goto replay;
1083
1146
  }
1084
1147
 
1085
- /* Handle proxy authentication failures */
1086
- if (status_code == HTTP_STATUS_PROXY_AUTH_REQ) {
1087
- int allowed_types;
1088
-
1089
- if (parse_unauthorized_response(s->request, &allowed_types, &t->auth_mechanisms) < 0)
1090
- return -1;
1091
-
1092
- /* TODO: extract the username from the url, no payload? */
1093
- if (t->owner->proxy.credentials) {
1094
- int cred_error = 1;
1095
- cred_error = t->owner->proxy.credentials(&t->proxy_cred, t->owner->proxy.url, NULL, allowed_types, t->owner->proxy.payload);
1096
-
1097
- if (cred_error < 0)
1098
- return cred_error;
1099
- }
1100
-
1101
- winhttp_stream_close(s);
1102
- goto replay;
1103
- }
1104
-
1105
1148
  /* Handle authentication failures */
1106
- if (HTTP_STATUS_DENIED == status_code && get_verb == s->verb) {
1107
- int allowed_types;
1108
-
1109
- if (parse_unauthorized_response(s->request, &allowed_types, &t->auth_mechanisms) < 0)
1110
- return -1;
1111
-
1112
- if (allowed_types) {
1113
- int cred_error = 1;
1114
-
1115
- git_cred_free(t->cred);
1116
- t->cred = NULL;
1117
- /* Start with the user-supplied credential callback, if present */
1118
- if (t->owner->cred_acquire_cb) {
1119
- cred_error = t->owner->cred_acquire_cb(&t->cred, t->owner->url,
1120
- t->connection_data.user, allowed_types, t->owner->cred_acquire_payload);
1121
-
1122
- /* Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set */
1123
- if (cred_error == GIT_PASSTHROUGH)
1124
- cred_error = 1;
1125
- else if (cred_error < 0)
1126
- return cred_error;
1127
- }
1128
-
1129
- /* Invoke the fallback credentials acquisition callback if necessary */
1130
- if (cred_error > 0) {
1131
- cred_error = fallback_cred_acquire_cb(&t->cred, t->owner->url,
1132
- t->connection_data.user, allowed_types, NULL);
1133
-
1134
- if (cred_error < 0)
1135
- return cred_error;
1136
- }
1137
-
1138
- if (!cred_error) {
1139
- assert(t->cred);
1140
-
1141
- winhttp_stream_close(s);
1142
-
1143
- /* Successfully acquired a credential */
1144
- goto replay;
1145
- }
1149
+ if (status_code == HTTP_STATUS_DENIED) {
1150
+ int error = acquire_credentials(s->request,
1151
+ &t->server,
1152
+ t->owner->url,
1153
+ t->owner->cred_acquire_cb,
1154
+ t->owner->cred_acquire_payload);
1155
+
1156
+ if (error < 0) {
1157
+ return error;
1158
+ } else if (!error) {
1159
+ assert(t->server.cred);
1160
+ winhttp_stream_close(s);
1161
+ goto replay;
1162
+ }
1163
+ } else if (status_code == HTTP_STATUS_PROXY_AUTH_REQ) {
1164
+ int error = acquire_credentials(s->request,
1165
+ &t->proxy,
1166
+ t->owner->proxy.url,
1167
+ t->owner->proxy.credentials,
1168
+ t->owner->proxy.payload);
1169
+
1170
+ if (error < 0) {
1171
+ return error;
1172
+ } else if (!error) {
1173
+ assert(t->proxy.cred);
1174
+ winhttp_stream_close(s);
1175
+ goto replay;
1146
1176
  }
1147
1177
  }
1148
1178
 
1149
1179
  if (HTTP_STATUS_OK != status_code) {
1150
- git_error_set(GIT_ERROR_NET, "request failed with status code: %lu", status_code);
1180
+ git_error_set(GIT_ERROR_HTTP, "request failed with status code: %lu", status_code);
1151
1181
  return -1;
1152
1182
  }
1153
1183
 
@@ -1174,7 +1204,7 @@ replay:
1174
1204
  }
1175
1205
 
1176
1206
  if (wcscmp(expected_content_type, content_type)) {
1177
- git_error_set(GIT_ERROR_NET, "received unexpected content-type");
1207
+ git_error_set(GIT_ERROR_HTTP, "received unexpected content-type");
1178
1208
  return -1;
1179
1209
  }
1180
1210
 
@@ -1209,11 +1239,11 @@ static int winhttp_stream_write_single(
1209
1239
 
1210
1240
  /* This implementation of write permits only a single call. */
1211
1241
  if (s->sent_request) {
1212
- git_error_set(GIT_ERROR_NET, "subtransport configured for only one write");
1242
+ git_error_set(GIT_ERROR_HTTP, "subtransport configured for only one write");
1213
1243
  return -1;
1214
1244
  }
1215
1245
 
1216
- if ((error = send_request(s, len, 0)) < 0)
1246
+ if ((error = send_request(s, len, false)) < 0)
1217
1247
  return error;
1218
1248
 
1219
1249
  s->sent_request = 1;
@@ -1240,12 +1270,12 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch)
1240
1270
  if (RPC_S_OK != status &&
1241
1271
  RPC_S_UUID_LOCAL_ONLY != status &&
1242
1272
  RPC_S_UUID_NO_ADDRESS != status) {
1243
- git_error_set(GIT_ERROR_NET, "unable to generate name for temp file");
1273
+ git_error_set(GIT_ERROR_HTTP, "unable to generate name for temp file");
1244
1274
  return -1;
1245
1275
  }
1246
1276
 
1247
1277
  if (buffer_len_cch < UUID_LENGTH_CCH + 1) {
1248
- git_error_set(GIT_ERROR_NET, "buffer too small for name of temp file");
1278
+ git_error_set(GIT_ERROR_HTTP, "buffer too small for name of temp file");
1249
1279
  return -1;
1250
1280
  }
1251
1281
 
@@ -1352,7 +1382,7 @@ static int winhttp_stream_write_chunked(
1352
1382
  return -1;
1353
1383
  }
1354
1384
 
1355
- if ((error = send_request(s, 0, 1)) < 0)
1385
+ if ((error = send_request(s, 0, true)) < 0)
1356
1386
  return error;
1357
1387
 
1358
1388
  s->sent_request = 1;
@@ -1375,8 +1405,10 @@ static int winhttp_stream_write_chunked(
1375
1405
  /* Append as much to the buffer as we can */
1376
1406
  int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len);
1377
1407
 
1378
- if (!s->chunk_buffer)
1408
+ if (!s->chunk_buffer) {
1379
1409
  s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1410
+ GIT_ERROR_CHECK_ALLOC(s->chunk_buffer);
1411
+ }
1380
1412
 
1381
1413
  memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count);
1382
1414
  s->chunk_buffer_len += count;
@@ -1501,7 +1533,7 @@ static int winhttp_action(
1501
1533
  int ret = -1;
1502
1534
 
1503
1535
  if (!t->connection)
1504
- if ((ret = gitno_connection_data_from_url(&t->connection_data, url, NULL)) < 0 ||
1536
+ if ((ret = git_net_url_parse(&t->server.url, url)) < 0 ||
1505
1537
  (ret = winhttp_connect(t)) < 0)
1506
1538
  return ret;
1507
1539
 
@@ -1543,24 +1575,17 @@ static int winhttp_close(git_smart_subtransport *subtransport)
1543
1575
  {
1544
1576
  winhttp_subtransport *t = (winhttp_subtransport *)subtransport;
1545
1577
 
1546
- gitno_connection_data_free_ptrs(&t->connection_data);
1547
- memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1548
- gitno_connection_data_free_ptrs(&t->proxy_connection_data);
1549
- memset(&t->proxy_connection_data, 0x0, sizeof(gitno_connection_data));
1550
-
1551
- if (t->cred) {
1552
- t->cred->free(t->cred);
1553
- t->cred = NULL;
1554
- }
1578
+ git_net_url_dispose(&t->server.url);
1579
+ git_net_url_dispose(&t->proxy.url);
1555
1580
 
1556
- if (t->proxy_cred) {
1557
- t->proxy_cred->free(t->proxy_cred);
1558
- t->proxy_cred = NULL;
1581
+ if (t->server.cred) {
1582
+ t->server.cred->free(t->server.cred);
1583
+ t->server.cred = NULL;
1559
1584
  }
1560
1585
 
1561
- if (t->url_cred) {
1562
- t->url_cred->free(t->url_cred);
1563
- t->url_cred = NULL;
1586
+ if (t->proxy.cred) {
1587
+ t->proxy.cred->free(t->proxy.cred);
1588
+ t->proxy.cred = NULL;
1564
1589
  }
1565
1590
 
1566
1591
  return winhttp_close_connection(t);