rugged 0.28.4.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (391) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/rugged/extconf.rb +3 -1
  4. data/ext/rugged/rugged.c +35 -31
  5. data/ext/rugged/rugged.h +13 -0
  6. data/ext/rugged/rugged_blob.c +11 -9
  7. data/ext/rugged/rugged_commit.c +17 -15
  8. data/ext/rugged/rugged_config.c +1 -1
  9. data/ext/rugged/rugged_diff.c +4 -26
  10. data/ext/rugged/rugged_index.c +4 -2
  11. data/ext/rugged/rugged_note.c +5 -3
  12. data/ext/rugged/rugged_object.c +57 -10
  13. data/ext/rugged/rugged_rebase.c +3 -1
  14. data/ext/rugged/rugged_remote.c +32 -8
  15. data/ext/rugged/rugged_repo.c +232 -17
  16. data/ext/rugged/rugged_tag.c +8 -6
  17. data/ext/rugged/rugged_tree.c +18 -16
  18. data/lib/rugged/commit.rb +1 -2
  19. data/lib/rugged/repository.rb +5 -6
  20. data/lib/rugged/submodule_collection.rb +4 -4
  21. data/lib/rugged/version.rb +1 -1
  22. data/vendor/libgit2/AUTHORS +1 -0
  23. data/vendor/libgit2/CMakeLists.txt +39 -19
  24. data/vendor/libgit2/COPYING +28 -0
  25. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -1
  26. data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +2 -2
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +1 -1
  28. data/vendor/libgit2/cmake/Modules/FindGSSFramework.cmake +28 -0
  29. data/vendor/libgit2/cmake/Modules/FindPCRE.cmake +38 -0
  30. data/vendor/libgit2/cmake/Modules/FindPCRE2.cmake +37 -0
  31. data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +2 -2
  32. data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +6 -0
  33. data/vendor/libgit2/cmake/Modules/PkgBuildConfig.cmake +77 -0
  34. data/vendor/libgit2/cmake/Modules/SanitizeBool.cmake +20 -0
  35. data/vendor/libgit2/cmake/Modules/SelectGSSAPI.cmake +56 -0
  36. data/vendor/libgit2/cmake/Modules/SelectHTTPSBackend.cmake +127 -0
  37. data/vendor/libgit2/cmake/Modules/SelectHashes.cmake +69 -0
  38. data/vendor/libgit2/deps/http-parser/http_parser.c +11 -6
  39. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +23 -0
  40. data/vendor/libgit2/deps/ntlmclient/compat.h +55 -0
  41. data/vendor/libgit2/deps/ntlmclient/crypt.h +64 -0
  42. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +120 -0
  43. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +18 -0
  44. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +145 -0
  45. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +18 -0
  46. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +130 -0
  47. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +21 -0
  48. data/vendor/libgit2/deps/ntlmclient/ntlm.c +1422 -0
  49. data/vendor/libgit2/deps/ntlmclient/ntlm.h +174 -0
  50. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +320 -0
  51. data/vendor/libgit2/deps/ntlmclient/unicode.h +36 -0
  52. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +445 -0
  53. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +201 -0
  54. data/vendor/libgit2/deps/ntlmclient/utf8.h +1257 -0
  55. data/vendor/libgit2/deps/ntlmclient/util.c +21 -0
  56. data/vendor/libgit2/deps/ntlmclient/util.h +14 -0
  57. data/vendor/libgit2/deps/pcre/CMakeLists.txt +140 -0
  58. data/vendor/libgit2/deps/pcre/COPYING +5 -0
  59. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +22 -0
  60. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +17 -0
  61. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +58 -0
  62. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +29 -0
  63. data/vendor/libgit2/deps/pcre/config.h.in +57 -0
  64. data/vendor/libgit2/deps/pcre/pcre.h +641 -0
  65. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +319 -0
  66. data/vendor/libgit2/deps/pcre/pcre_chartables.c +198 -0
  67. data/vendor/libgit2/deps/pcre/pcre_compile.c +9800 -0
  68. data/vendor/libgit2/deps/pcre/pcre_config.c +190 -0
  69. data/vendor/libgit2/deps/pcre/pcre_dfa_exec.c +3676 -0
  70. data/vendor/libgit2/deps/pcre/pcre_exec.c +7173 -0
  71. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +245 -0
  72. data/vendor/libgit2/deps/pcre/pcre_get.c +669 -0
  73. data/vendor/libgit2/deps/pcre/pcre_globals.c +86 -0
  74. data/vendor/libgit2/deps/pcre/pcre_internal.h +2787 -0
  75. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +11913 -0
  76. data/vendor/libgit2/deps/pcre/pcre_maketables.c +156 -0
  77. data/vendor/libgit2/deps/pcre/pcre_newline.c +210 -0
  78. data/vendor/libgit2/deps/pcre/pcre_ord2utf8.c +94 -0
  79. data/vendor/libgit2/deps/pcre/pcre_printint.c +834 -0
  80. data/vendor/libgit2/deps/pcre/pcre_refcount.c +92 -0
  81. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +211 -0
  82. data/vendor/libgit2/deps/pcre/pcre_study.c +1686 -0
  83. data/vendor/libgit2/deps/pcre/pcre_tables.c +727 -0
  84. data/vendor/libgit2/deps/pcre/pcre_ucd.c +3644 -0
  85. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +301 -0
  86. data/vendor/libgit2/deps/pcre/pcre_version.c +98 -0
  87. data/vendor/libgit2/deps/pcre/pcre_xclass.c +268 -0
  88. data/vendor/libgit2/deps/pcre/pcreposix.c +421 -0
  89. data/vendor/libgit2/deps/pcre/pcreposix.h +117 -0
  90. data/vendor/libgit2/deps/pcre/ucp.h +224 -0
  91. data/vendor/libgit2/deps/zlib/adler32.c +0 -7
  92. data/vendor/libgit2/deps/zlib/crc32.c +0 -7
  93. data/vendor/libgit2/include/git2.h +2 -0
  94. data/vendor/libgit2/include/git2/apply.h +22 -2
  95. data/vendor/libgit2/include/git2/attr.h +23 -13
  96. data/vendor/libgit2/include/git2/blame.h +2 -2
  97. data/vendor/libgit2/include/git2/blob.h +44 -12
  98. data/vendor/libgit2/include/git2/branch.h +74 -57
  99. data/vendor/libgit2/include/git2/buffer.h +20 -14
  100. data/vendor/libgit2/include/git2/cert.h +135 -0
  101. data/vendor/libgit2/include/git2/checkout.h +46 -14
  102. data/vendor/libgit2/include/git2/cherrypick.h +3 -3
  103. data/vendor/libgit2/include/git2/clone.h +2 -2
  104. data/vendor/libgit2/include/git2/commit.h +23 -1
  105. data/vendor/libgit2/include/git2/common.h +15 -6
  106. data/vendor/libgit2/include/git2/config.h +12 -12
  107. data/vendor/libgit2/include/git2/cred_helpers.h +4 -42
  108. data/vendor/libgit2/include/git2/credential.h +314 -0
  109. data/vendor/libgit2/include/git2/credential_helpers.h +52 -0
  110. data/vendor/libgit2/include/git2/deprecated.h +321 -3
  111. data/vendor/libgit2/include/git2/describe.h +4 -4
  112. data/vendor/libgit2/include/git2/diff.h +16 -14
  113. data/vendor/libgit2/include/git2/errors.h +4 -2
  114. data/vendor/libgit2/include/git2/filter.h +8 -0
  115. data/vendor/libgit2/include/git2/index.h +2 -1
  116. data/vendor/libgit2/include/git2/indexer.h +48 -4
  117. data/vendor/libgit2/include/git2/merge.h +6 -10
  118. data/vendor/libgit2/include/git2/net.h +0 -5
  119. data/vendor/libgit2/include/git2/object.h +2 -14
  120. data/vendor/libgit2/include/git2/odb.h +3 -2
  121. data/vendor/libgit2/include/git2/odb_backend.h +5 -4
  122. data/vendor/libgit2/include/git2/oid.h +11 -6
  123. data/vendor/libgit2/include/git2/pack.h +12 -1
  124. data/vendor/libgit2/include/git2/proxy.h +6 -4
  125. data/vendor/libgit2/include/git2/rebase.h +46 -2
  126. data/vendor/libgit2/include/git2/refs.h +19 -0
  127. data/vendor/libgit2/include/git2/remote.h +40 -15
  128. data/vendor/libgit2/include/git2/repository.h +29 -6
  129. data/vendor/libgit2/include/git2/revert.h +1 -1
  130. data/vendor/libgit2/include/git2/revwalk.h +7 -3
  131. data/vendor/libgit2/include/git2/stash.h +4 -4
  132. data/vendor/libgit2/include/git2/status.h +25 -16
  133. data/vendor/libgit2/include/git2/submodule.h +20 -3
  134. data/vendor/libgit2/include/git2/sys/alloc.h +9 -9
  135. data/vendor/libgit2/include/git2/sys/cred.h +15 -0
  136. data/vendor/libgit2/include/git2/sys/credential.h +90 -0
  137. data/vendor/libgit2/include/git2/sys/index.h +4 -2
  138. data/vendor/libgit2/include/git2/sys/mempack.h +2 -1
  139. data/vendor/libgit2/include/git2/sys/merge.h +1 -1
  140. data/vendor/libgit2/include/git2/sys/odb_backend.h +48 -4
  141. data/vendor/libgit2/include/git2/sys/refdb_backend.h +164 -21
  142. data/vendor/libgit2/include/git2/sys/repository.h +17 -6
  143. data/vendor/libgit2/include/git2/sys/transport.h +4 -4
  144. data/vendor/libgit2/include/git2/tag.h +11 -2
  145. data/vendor/libgit2/include/git2/trace.h +2 -2
  146. data/vendor/libgit2/include/git2/transport.h +11 -340
  147. data/vendor/libgit2/include/git2/tree.h +5 -3
  148. data/vendor/libgit2/include/git2/types.h +4 -89
  149. data/vendor/libgit2/include/git2/version.h +5 -5
  150. data/vendor/libgit2/include/git2/worktree.h +5 -5
  151. data/vendor/libgit2/src/CMakeLists.txt +99 -236
  152. data/vendor/libgit2/src/alloc.c +2 -14
  153. data/vendor/libgit2/src/{stdalloc.c → allocators/stdalloc.c} +3 -4
  154. data/vendor/libgit2/src/{stdalloc.h → allocators/stdalloc.h} +4 -4
  155. data/vendor/libgit2/src/allocators/win32_crtdbg.c +118 -0
  156. data/vendor/libgit2/src/{transports/cred.h → allocators/win32_crtdbg.h} +5 -4
  157. data/vendor/libgit2/src/apply.c +60 -30
  158. data/vendor/libgit2/src/attr.c +70 -64
  159. data/vendor/libgit2/src/attr_file.c +189 -96
  160. data/vendor/libgit2/src/attr_file.h +9 -9
  161. data/vendor/libgit2/src/attrcache.c +48 -48
  162. data/vendor/libgit2/src/attrcache.h +2 -1
  163. data/vendor/libgit2/src/blame.c +17 -5
  164. data/vendor/libgit2/src/blame.h +1 -1
  165. data/vendor/libgit2/src/blame_git.c +21 -7
  166. data/vendor/libgit2/src/blob.c +81 -17
  167. data/vendor/libgit2/src/blob.h +2 -2
  168. data/vendor/libgit2/src/branch.c +60 -32
  169. data/vendor/libgit2/src/buffer.c +19 -7
  170. data/vendor/libgit2/src/buffer.h +1 -0
  171. data/vendor/libgit2/src/cache.c +33 -36
  172. data/vendor/libgit2/src/cache.h +1 -1
  173. data/vendor/libgit2/src/cc-compat.h +5 -0
  174. data/vendor/libgit2/src/checkout.c +26 -16
  175. data/vendor/libgit2/src/cherrypick.c +9 -3
  176. data/vendor/libgit2/src/clone.c +29 -7
  177. data/vendor/libgit2/src/clone.h +4 -0
  178. data/vendor/libgit2/src/commit.c +70 -22
  179. data/vendor/libgit2/src/commit.h +6 -0
  180. data/vendor/libgit2/src/commit_list.c +28 -76
  181. data/vendor/libgit2/src/commit_list.h +2 -2
  182. data/vendor/libgit2/src/common.h +3 -75
  183. data/vendor/libgit2/src/config.c +31 -40
  184. data/vendor/libgit2/src/config.h +7 -6
  185. data/vendor/libgit2/src/config_backend.h +12 -0
  186. data/vendor/libgit2/src/config_cache.c +39 -39
  187. data/vendor/libgit2/src/config_entries.c +69 -99
  188. data/vendor/libgit2/src/config_entries.h +1 -0
  189. data/vendor/libgit2/src/config_file.c +346 -380
  190. data/vendor/libgit2/src/config_mem.c +12 -16
  191. data/vendor/libgit2/src/config_parse.c +49 -29
  192. data/vendor/libgit2/src/config_parse.h +13 -12
  193. data/vendor/libgit2/src/config_snapshot.c +206 -0
  194. data/vendor/libgit2/src/crlf.c +14 -14
  195. data/vendor/libgit2/src/describe.c +21 -20
  196. data/vendor/libgit2/src/diff.c +43 -58
  197. data/vendor/libgit2/src/diff.h +4 -3
  198. data/vendor/libgit2/src/diff_driver.c +37 -38
  199. data/vendor/libgit2/src/diff_file.c +12 -10
  200. data/vendor/libgit2/src/diff_file.h +2 -2
  201. data/vendor/libgit2/src/diff_generate.c +148 -98
  202. data/vendor/libgit2/src/diff_generate.h +2 -2
  203. data/vendor/libgit2/src/diff_parse.c +1 -1
  204. data/vendor/libgit2/src/diff_print.c +25 -13
  205. data/vendor/libgit2/src/diff_stats.c +1 -1
  206. data/vendor/libgit2/src/diff_tform.c +11 -11
  207. data/vendor/libgit2/src/errors.c +21 -25
  208. data/vendor/libgit2/src/errors.h +81 -0
  209. data/vendor/libgit2/src/features.h.in +9 -2
  210. data/vendor/libgit2/src/fetch.c +7 -2
  211. data/vendor/libgit2/src/fetchhead.c +36 -4
  212. data/vendor/libgit2/src/filebuf.c +6 -10
  213. data/vendor/libgit2/src/filebuf.h +2 -2
  214. data/vendor/libgit2/src/filter.c +16 -8
  215. data/vendor/libgit2/src/{fileops.c → futils.c} +21 -17
  216. data/vendor/libgit2/src/{fileops.h → futils.h} +5 -5
  217. data/vendor/libgit2/src/global.c +12 -40
  218. data/vendor/libgit2/src/global.h +0 -2
  219. data/vendor/libgit2/src/hash.c +61 -0
  220. data/vendor/libgit2/src/hash.h +19 -21
  221. data/vendor/libgit2/src/hash/sha1.h +38 -0
  222. data/vendor/libgit2/src/hash/{hash_collisiondetect.h → sha1/collisiondetect.c} +14 -17
  223. data/vendor/libgit2/src/{sha1_lookup.h → hash/sha1/collisiondetect.h} +8 -8
  224. data/vendor/libgit2/src/hash/{hash_common_crypto.h → sha1/common_crypto.c} +15 -19
  225. data/vendor/libgit2/src/hash/sha1/common_crypto.h +19 -0
  226. data/vendor/libgit2/src/hash/{hash_generic.c → sha1/generic.c} +22 -10
  227. data/vendor/libgit2/src/hash/{hash_generic.h → sha1/generic.h} +4 -14
  228. data/vendor/libgit2/src/hash/{hash_mbedtls.c → sha1/mbedtls.c} +15 -7
  229. data/vendor/libgit2/src/hash/{hash_mbedtls.h → sha1/mbedtls.h} +6 -11
  230. data/vendor/libgit2/src/hash/{hash_openssl.h → sha1/openssl.c} +14 -18
  231. data/vendor/libgit2/src/hash/sha1/openssl.h +19 -0
  232. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.c +14 -3
  233. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.h +0 -0
  234. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.c +0 -0
  235. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.h +0 -0
  236. data/vendor/libgit2/src/hash/{hash_win32.c → sha1/win32.c} +34 -24
  237. data/vendor/libgit2/src/hash/{hash_win32.h → sha1/win32.h} +6 -19
  238. data/vendor/libgit2/src/hashsig.c +1 -1
  239. data/vendor/libgit2/src/idxmap.c +91 -65
  240. data/vendor/libgit2/src/idxmap.h +151 -15
  241. data/vendor/libgit2/src/ignore.c +32 -38
  242. data/vendor/libgit2/src/index.c +105 -83
  243. data/vendor/libgit2/src/index.h +1 -1
  244. data/vendor/libgit2/src/indexer.c +71 -72
  245. data/vendor/libgit2/src/integer.h +39 -4
  246. data/vendor/libgit2/src/iterator.c +40 -35
  247. data/vendor/libgit2/src/iterator.h +8 -8
  248. data/vendor/libgit2/src/map.h +1 -1
  249. data/vendor/libgit2/src/merge.c +78 -51
  250. data/vendor/libgit2/src/merge.h +2 -2
  251. data/vendor/libgit2/src/merge_driver.c +5 -5
  252. data/vendor/libgit2/src/merge_file.c +1 -1
  253. data/vendor/libgit2/src/mwindow.c +18 -23
  254. data/vendor/libgit2/src/mwindow.h +4 -4
  255. data/vendor/libgit2/src/net.c +411 -0
  256. data/vendor/libgit2/src/net.h +57 -0
  257. data/vendor/libgit2/src/netops.c +6 -193
  258. data/vendor/libgit2/src/netops.h +1 -34
  259. data/vendor/libgit2/src/notes.c +8 -5
  260. data/vendor/libgit2/src/object.c +3 -3
  261. data/vendor/libgit2/src/object.h +2 -0
  262. data/vendor/libgit2/src/odb.c +41 -23
  263. data/vendor/libgit2/src/odb.h +3 -2
  264. data/vendor/libgit2/src/odb_loose.c +17 -10
  265. data/vendor/libgit2/src/odb_mempack.c +13 -24
  266. data/vendor/libgit2/src/odb_pack.c +4 -5
  267. data/vendor/libgit2/src/offmap.c +43 -55
  268. data/vendor/libgit2/src/offmap.h +102 -24
  269. data/vendor/libgit2/src/oid.c +19 -8
  270. data/vendor/libgit2/src/oidmap.c +39 -57
  271. data/vendor/libgit2/src/oidmap.h +99 -19
  272. data/vendor/libgit2/src/pack-objects.c +28 -33
  273. data/vendor/libgit2/src/pack-objects.h +1 -1
  274. data/vendor/libgit2/src/pack.c +117 -129
  275. data/vendor/libgit2/src/pack.h +15 -18
  276. data/vendor/libgit2/src/parse.c +10 -0
  277. data/vendor/libgit2/src/parse.h +3 -3
  278. data/vendor/libgit2/src/patch.c +1 -1
  279. data/vendor/libgit2/src/patch_generate.c +2 -2
  280. data/vendor/libgit2/src/patch_parse.c +130 -33
  281. data/vendor/libgit2/src/path.c +43 -6
  282. data/vendor/libgit2/src/path.h +2 -0
  283. data/vendor/libgit2/src/pathspec.c +14 -14
  284. data/vendor/libgit2/src/pool.c +26 -22
  285. data/vendor/libgit2/src/pool.h +7 -7
  286. data/vendor/libgit2/src/posix.c +7 -7
  287. data/vendor/libgit2/src/posix.h +12 -1
  288. data/vendor/libgit2/src/proxy.c +7 -2
  289. data/vendor/libgit2/src/push.c +13 -7
  290. data/vendor/libgit2/src/reader.c +2 -2
  291. data/vendor/libgit2/src/rebase.c +87 -28
  292. data/vendor/libgit2/src/refdb.c +12 -0
  293. data/vendor/libgit2/src/refdb_fs.c +219 -167
  294. data/vendor/libgit2/src/reflog.c +11 -13
  295. data/vendor/libgit2/src/refs.c +39 -23
  296. data/vendor/libgit2/src/refs.h +8 -1
  297. data/vendor/libgit2/src/refspec.c +9 -16
  298. data/vendor/libgit2/src/regexp.c +221 -0
  299. data/vendor/libgit2/src/regexp.h +97 -0
  300. data/vendor/libgit2/src/remote.c +57 -55
  301. data/vendor/libgit2/src/remote.h +2 -2
  302. data/vendor/libgit2/src/repository.c +187 -154
  303. data/vendor/libgit2/src/repository.h +49 -40
  304. data/vendor/libgit2/src/revert.c +8 -3
  305. data/vendor/libgit2/src/revparse.c +18 -19
  306. data/vendor/libgit2/src/revwalk.c +72 -34
  307. data/vendor/libgit2/src/revwalk.h +20 -0
  308. data/vendor/libgit2/src/settings.c +13 -1
  309. data/vendor/libgit2/src/sortedcache.c +12 -26
  310. data/vendor/libgit2/src/sortedcache.h +1 -1
  311. data/vendor/libgit2/src/stash.c +47 -67
  312. data/vendor/libgit2/src/status.c +17 -11
  313. data/vendor/libgit2/src/streams/openssl.c +54 -2
  314. data/vendor/libgit2/src/streams/socket.c +2 -2
  315. data/vendor/libgit2/src/strmap.c +37 -84
  316. data/vendor/libgit2/src/strmap.h +105 -33
  317. data/vendor/libgit2/src/submodule.c +151 -126
  318. data/vendor/libgit2/src/submodule.h +1 -1
  319. data/vendor/libgit2/src/sysdir.c +11 -1
  320. data/vendor/libgit2/src/tag.c +10 -2
  321. data/vendor/libgit2/src/trace.c +1 -1
  322. data/vendor/libgit2/src/trace.h +3 -3
  323. data/vendor/libgit2/src/trailer.c +46 -32
  324. data/vendor/libgit2/src/transaction.c +10 -9
  325. data/vendor/libgit2/src/transports/auth.c +16 -15
  326. data/vendor/libgit2/src/transports/auth.h +18 -11
  327. data/vendor/libgit2/src/transports/auth_negotiate.c +64 -33
  328. data/vendor/libgit2/src/transports/auth_negotiate.h +2 -2
  329. data/vendor/libgit2/src/transports/auth_ntlm.c +223 -0
  330. data/vendor/libgit2/src/transports/auth_ntlm.h +38 -0
  331. data/vendor/libgit2/src/transports/credential.c +476 -0
  332. data/vendor/libgit2/src/transports/{cred_helpers.c → credential_helpers.c} +21 -8
  333. data/vendor/libgit2/src/transports/git.c +11 -16
  334. data/vendor/libgit2/src/transports/http.c +488 -1248
  335. data/vendor/libgit2/src/transports/http.h +4 -1
  336. data/vendor/libgit2/src/transports/httpclient.c +1549 -0
  337. data/vendor/libgit2/src/transports/httpclient.h +190 -0
  338. data/vendor/libgit2/src/transports/local.c +10 -10
  339. data/vendor/libgit2/src/transports/smart.c +19 -19
  340. data/vendor/libgit2/src/transports/smart.h +3 -3
  341. data/vendor/libgit2/src/transports/smart_pkt.c +1 -1
  342. data/vendor/libgit2/src/transports/smart_protocol.c +40 -64
  343. data/vendor/libgit2/src/transports/ssh.c +77 -59
  344. data/vendor/libgit2/src/transports/winhttp.c +272 -242
  345. data/vendor/libgit2/src/tree-cache.c +14 -7
  346. data/vendor/libgit2/src/tree.c +16 -26
  347. data/vendor/libgit2/src/unix/map.c +1 -1
  348. data/vendor/libgit2/src/unix/posix.h +2 -12
  349. data/vendor/libgit2/src/userdiff.h +3 -1
  350. data/vendor/libgit2/src/util.c +51 -53
  351. data/vendor/libgit2/src/util.h +16 -21
  352. data/vendor/libgit2/src/wildmatch.c +320 -0
  353. data/vendor/libgit2/src/wildmatch.h +23 -0
  354. data/vendor/libgit2/src/win32/map.c +3 -5
  355. data/vendor/libgit2/src/win32/path_w32.c +40 -3
  356. data/vendor/libgit2/src/win32/path_w32.h +15 -29
  357. data/vendor/libgit2/src/win32/posix.h +1 -4
  358. data/vendor/libgit2/src/win32/posix_w32.c +47 -5
  359. data/vendor/libgit2/src/win32/precompiled.h +0 -2
  360. data/vendor/libgit2/src/win32/thread.c +5 -10
  361. data/vendor/libgit2/src/win32/w32_buffer.c +7 -3
  362. data/vendor/libgit2/src/win32/w32_common.h +39 -0
  363. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -93
  364. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -2
  365. data/vendor/libgit2/src/win32/w32_stack.c +4 -9
  366. data/vendor/libgit2/src/win32/w32_stack.h +3 -3
  367. data/vendor/libgit2/src/win32/w32_util.c +31 -0
  368. data/vendor/libgit2/src/win32/w32_util.h +6 -32
  369. data/vendor/libgit2/src/worktree.c +79 -49
  370. data/vendor/libgit2/src/xdiff/xdiffi.c +1 -1
  371. data/vendor/libgit2/src/xdiff/xmerge.c +12 -0
  372. data/vendor/libgit2/src/xdiff/xpatience.c +3 -0
  373. data/vendor/libgit2/src/zstream.c +5 -0
  374. data/vendor/libgit2/src/zstream.h +1 -0
  375. metadata +108 -41
  376. data/vendor/libgit2/deps/regex/CMakeLists.txt +0 -2
  377. data/vendor/libgit2/deps/regex/COPYING +0 -502
  378. data/vendor/libgit2/deps/regex/config.h +0 -7
  379. data/vendor/libgit2/deps/regex/regcomp.c +0 -3857
  380. data/vendor/libgit2/deps/regex/regex.c +0 -92
  381. data/vendor/libgit2/deps/regex/regex.h +0 -582
  382. data/vendor/libgit2/deps/regex/regex_internal.c +0 -1744
  383. data/vendor/libgit2/deps/regex/regex_internal.h +0 -819
  384. data/vendor/libgit2/deps/regex/regexec.c +0 -4369
  385. data/vendor/libgit2/include/git2/inttypes.h +0 -309
  386. data/vendor/libgit2/include/git2/sys/time.h +0 -31
  387. data/vendor/libgit2/libgit2.pc.in +0 -13
  388. data/vendor/libgit2/src/fnmatch.c +0 -248
  389. data/vendor/libgit2/src/fnmatch.h +0 -48
  390. data/vendor/libgit2/src/sha1_lookup.c +0 -35
  391. 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>
@@ -48,6 +49,16 @@
48
49
  # define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800
49
50
  #endif
50
51
 
52
+ #ifndef HTTP_STATUS_PERMANENT_REDIRECT
53
+ # define HTTP_STATUS_PERMANENT_REDIRECT 308
54
+ #endif
55
+
56
+ #ifndef DWORD_MAX
57
+ # define DWORD_MAX 0xffffffff
58
+ #endif
59
+
60
+ bool git_http__expect_continue = false;
61
+
51
62
  static const char *prefix_https = "https://";
52
63
  static const char *upload_pack_service = "upload-pack";
53
64
  static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";
@@ -100,24 +111,44 @@ typedef struct {
100
111
  chunked : 1;
101
112
  } winhttp_stream;
102
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
+
103
121
  typedef struct {
104
122
  git_smart_subtransport parent;
105
123
  transport_smart *owner;
106
- gitno_connection_data connection_data;
107
- gitno_connection_data proxy_connection_data;
108
- git_cred *cred;
109
- git_cred *url_cred;
110
- git_cred *proxy_cred;
111
- int auth_mechanisms;
124
+
125
+ winhttp_server server;
126
+ winhttp_server proxy;
127
+
112
128
  HINTERNET session;
113
129
  HINTERNET connection;
114
130
  } winhttp_subtransport;
115
131
 
116
- 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)
117
133
  {
118
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
119
- wchar_t *user, *pass;
134
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
135
+ wchar_t *user = NULL, *pass = NULL;
120
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
+ }
121
152
 
122
153
  if ((error = user_len = git__utf8_to_16_alloc(&user, c->username)) < 0)
123
154
  goto done;
@@ -125,7 +156,7 @@ static int _apply_userpass_credential(HINTERNET request, DWORD target, DWORD sch
125
156
  if ((error = pass_len = git__utf8_to_16_alloc(&pass, c->password)) < 0)
126
157
  goto done;
127
158
 
128
- if (!WinHttpSetCredentials(request, target, scheme, user, pass, NULL)) {
159
+ if (!WinHttpSetCredentials(request, target, native_scheme, user, pass, NULL)) {
129
160
  git_error_set(GIT_ERROR_OS, "failed to set credentials");
130
161
  error = -1;
131
162
  }
@@ -143,81 +174,62 @@ done:
143
174
  return error;
144
175
  }
145
176
 
146
- 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)
147
178
  {
148
- if (GIT_WINHTTP_AUTH_DIGEST & mechanisms) {
149
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_PROXY,
150
- WINHTTP_AUTH_SCHEME_DIGEST, cred);
151
- }
152
-
153
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_PROXY,
154
- WINHTTP_AUTH_SCHEME_BASIC, cred);
155
- }
156
-
157
- static int apply_userpass_credential(HINTERNET request, int mechanisms, git_cred *cred)
158
- {
159
- DWORD native_scheme;
179
+ DWORD autologon_level = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW;
180
+ DWORD native_scheme = 0;
160
181
 
161
- if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) ||
162
- (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) {
163
185
  native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
164
- } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) {
165
- native_scheme = WINHTTP_AUTH_SCHEME_BASIC;
166
186
  } else {
167
- git_error_set(GIT_ERROR_NET, "invalid authentication scheme");
187
+ git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme");
168
188
  return -1;
169
189
  }
170
190
 
171
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_SERVER,
172
- native_scheme, cred);
173
- }
174
-
175
- static int apply_default_credentials(HINTERNET request, int mechanisms)
176
- {
177
- /* Either the caller explicitly requested that default credentials be passed,
178
- * or our fallback credential callback was invoked and checked that the target
179
- * URI was in the appropriate Internet Explorer security zone. By setting this
180
- * flag, we guarantee that the credentials are delivered by WinHTTP. The default
181
- * is "medium" which applies to the intranet and sounds like it would correspond
182
- * to Internet Explorer security zones, but in fact does not. */
183
- DWORD data = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW;
184
- DWORD native_scheme = 0;
185
-
186
- if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0)
187
- native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
188
-
189
- if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0)
190
- native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
191
-
192
- if (!native_scheme) {
193
- 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");
194
197
  return -1;
195
198
  }
196
199
 
197
- if (!WinHttpSetOption(request, WINHTTP_OPTION_AUTOLOGON_POLICY, &data, sizeof(DWORD)))
198
- return -1;
199
-
200
- 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");
201
202
  return -1;
203
+ }
202
204
 
203
205
  return 0;
204
206
  }
205
207
 
206
- static int fallback_cred_acquire_cb(
207
- git_cred **cred,
208
- const char *url,
209
- const char *username_from_url,
208
+ static int acquire_url_cred(
209
+ git_credential **cred,
210
210
  unsigned int allowed_types,
211
- void *payload)
211
+ const char *username,
212
+ const char *password)
212
213
  {
213
- int error = 1;
214
+ if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT)
215
+ return git_credential_userpass_plaintext_new(cred, username, password);
214
216
 
215
- GIT_UNUSED(username_from_url);
216
- GIT_UNUSED(payload);
217
+ if ((allowed_types & GIT_CREDENTIAL_DEFAULT) && *username == '\0' && *password == '\0')
218
+ return git_credential_default_new(cred);
219
+
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;
217
229
 
218
230
  /* If the target URI supports integrated Windows authentication
219
231
  * as an authentication mechanism */
220
- if (GIT_CREDTYPE_DEFAULT & allowed_types) {
232
+ if (GIT_CREDENTIAL_DEFAULT & allowed_types) {
221
233
  wchar_t *wide_url;
222
234
  HRESULT hCoInitResult;
223
235
 
@@ -241,21 +253,21 @@ static int fallback_cred_acquire_cb(
241
253
  (URLZONE_LOCAL_MACHINE == dwZone ||
242
254
  URLZONE_INTRANET == dwZone ||
243
255
  URLZONE_TRUSTED == dwZone)) {
244
- git_cred *existing = *cred;
256
+ git_credential *existing = *cred;
245
257
 
246
258
  if (existing)
247
259
  existing->free(existing);
248
260
 
249
261
  /* Then use default Windows credentials to authenticate this request */
250
- error = git_cred_default_new(cred);
262
+ error = git_credential_default_new(cred);
251
263
  }
252
264
 
253
265
  pISM->lpVtbl->Release(pISM);
254
266
  }
255
267
 
256
- if (SUCCEEDED(hCoInitResult))
257
- /* Only unitialize if the call to CoInitializeEx was successful. */
258
- CoUninitialize();
268
+ /* Only unitialize if the call to CoInitializeEx was successful. */
269
+ if (SUCCEEDED(hCoInitResult))
270
+ CoUninitialize();
259
271
  }
260
272
 
261
273
  git__free(wide_url);
@@ -275,12 +287,12 @@ static int certificate_check(winhttp_stream *s, int valid)
275
287
  /* If there is no override, we should fail if WinHTTP doesn't think it's fine */
276
288
  if (t->owner->certificate_check_cb == NULL && !valid) {
277
289
  if (!git_error_last())
278
- git_error_set(GIT_ERROR_NET, "unknown certificate check failure");
290
+ git_error_set(GIT_ERROR_HTTP, "unknown certificate check failure");
279
291
 
280
292
  return GIT_ECERTIFICATE;
281
293
  }
282
294
 
283
- 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)
284
296
  return 0;
285
297
 
286
298
  if (!WinHttpQueryOption(s->request, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert_ctx, &cert_ctx_size)) {
@@ -292,14 +304,14 @@ static int certificate_check(winhttp_stream *s, int valid)
292
304
  cert.parent.cert_type = GIT_CERT_X509;
293
305
  cert.data = cert_ctx->pbCertEncoded;
294
306
  cert.len = cert_ctx->cbCertEncoded;
295
- 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);
296
308
  CertFreeCertificateContext(cert_ctx);
297
309
 
298
310
  if (error == GIT_PASSTHROUGH)
299
311
  error = valid ? 0 : GIT_ECERTIFICATE;
300
312
 
301
313
  if (error < 0 && !git_error_last())
302
- git_error_set(GIT_ERROR_NET, "user cancelled certificate check");
314
+ git_error_set(GIT_ERROR_HTTP, "user cancelled certificate check");
303
315
 
304
316
  return error;
305
317
  }
@@ -329,8 +341,25 @@ static void winhttp_stream_close(winhttp_stream *s)
329
341
  s->sent_request = 0;
330
342
  }
331
343
 
332
- #define SCHEME_HTTP "http://"
333
- #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
+ }
334
363
 
335
364
  static int winhttp_stream_connect(winhttp_stream *s)
336
365
  {
@@ -344,11 +373,17 @@ static int winhttp_stream_connect(winhttp_stream *s)
344
373
  unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
345
374
  int default_timeout = TIMEOUT_INFINITE;
346
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;
347
379
  size_t i;
348
380
  const git_proxy_options *proxy_opts;
349
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++;
350
385
  /* Prepare URL */
351
- 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);
352
387
 
353
388
  if (git_buf_oom(&buf))
354
389
  return -1;
@@ -367,13 +402,17 @@ static int winhttp_stream_connect(winhttp_stream *s)
367
402
  NULL,
368
403
  WINHTTP_NO_REFERER,
369
404
  types,
370
- t->connection_data.use_ssl ? WINHTTP_FLAG_SECURE : 0);
405
+ git__strcmp(t->server.url.scheme, "https") == 0 ? WINHTTP_FLAG_SECURE : 0);
371
406
 
372
407
  if (!s->request) {
373
408
  git_error_set(GIT_ERROR_OS, "failed to open request");
374
409
  goto on_error;
375
410
  }
376
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
+
377
416
  if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
378
417
  git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP");
379
418
  goto on_error;
@@ -382,7 +421,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
382
421
  proxy_opts = &t->owner->proxy;
383
422
  if (proxy_opts->type == GIT_PROXY_AUTO) {
384
423
  /* Set proxy if necessary */
385
- 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)
386
425
  goto on_error;
387
426
  }
388
427
  else if (proxy_opts->type == GIT_PROXY_SPECIFIED) {
@@ -395,38 +434,24 @@ static int winhttp_stream_connect(winhttp_stream *s)
395
434
  WINHTTP_PROXY_INFO proxy_info;
396
435
  wchar_t *proxy_wide;
397
436
 
398
- if (!git__prefixcmp(proxy_url, SCHEME_HTTP)) {
399
- t->proxy_connection_data.use_ssl = false;
400
- } else if (!git__prefixcmp(proxy_url, SCHEME_HTTPS)) {
401
- t->proxy_connection_data.use_ssl = true;
402
- } else {
403
- git_error_set(GIT_ERROR_NET, "invalid URL: '%s'", proxy_url);
404
- return -1;
405
- }
406
-
407
- gitno_connection_data_free_ptrs(&t->proxy_connection_data);
437
+ git_net_url_dispose(&t->proxy.url);
408
438
 
409
- if ((error = gitno_extract_url_parts(&t->proxy_connection_data.host, &t->proxy_connection_data.port, NULL,
410
- &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)
411
440
  goto on_error;
412
441
 
413
- if (t->proxy_connection_data.user && t->proxy_connection_data.pass) {
414
- if (t->proxy_cred) {
415
- t->proxy_cred->free(t->proxy_cred);
416
- }
417
-
418
- if ((error = git_cred_userpass_plaintext_new(&t->proxy_cred, t->proxy_connection_data.user, t->proxy_connection_data.pass)) < 0)
419
- 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;
420
446
  }
421
447
 
422
- if (t->proxy_connection_data.use_ssl)
423
- git_buf_PUTS(&processed_url, SCHEME_HTTPS);
424
- else
425
- 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);
426
452
 
427
- git_buf_puts(&processed_url, t->proxy_connection_data.host);
428
- if (t->proxy_connection_data.port)
429
- 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);
430
455
 
431
456
  if (git_buf_oom(&processed_url)) {
432
457
  error = -1;
@@ -454,13 +479,8 @@ static int winhttp_stream_connect(winhttp_stream *s)
454
479
 
455
480
  git__free(proxy_wide);
456
481
 
457
- if (t->proxy_cred) {
458
- if (t->proxy_cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT) {
459
- if ((error = apply_userpass_credential_proxy(s->request, t->proxy_cred, t->auth_mechanisms)) < 0)
460
- goto on_error;
461
- }
462
- }
463
-
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;
464
484
  }
465
485
 
466
486
  /* Disable WinHTTP redirects so we can handle them manually. Why, you ask?
@@ -471,6 +491,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
471
491
  &disable_redirects,
472
492
  sizeof(disable_redirects))) {
473
493
  git_error_set(GIT_ERROR_OS, "failed to disable redirects");
494
+ error = -1;
474
495
  goto on_error;
475
496
  }
476
497
 
@@ -543,33 +564,16 @@ static int winhttp_stream_connect(winhttp_stream *s)
543
564
  }
544
565
 
545
566
  /* If requested, disable certificate validation */
546
- if (t->connection_data.use_ssl) {
567
+ if (strcmp(t->server.url.scheme, "https") == 0) {
547
568
  int flags;
548
569
 
549
570
  if (t->owner->parent.read_flags(&t->owner->parent, &flags) < 0)
550
571
  goto on_error;
551
572
  }
552
573
 
553
- /* If we have a credential on the subtransport, apply it to the request */
554
- if (t->cred &&
555
- t->cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT &&
556
- apply_userpass_credential(s->request, t->auth_mechanisms, t->cred) < 0)
557
- goto on_error;
558
- else if (t->cred &&
559
- t->cred->credtype == GIT_CREDTYPE_DEFAULT &&
560
- apply_default_credentials(s->request, t->auth_mechanisms) < 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
576
 
563
- /* If no other credentials have been applied and the URL has username and
564
- * password, use those */
565
- if (!t->cred && t->connection_data.user && t->connection_data.pass) {
566
- if (!t->url_cred &&
567
- git_cred_userpass_plaintext_new(&t->url_cred, t->connection_data.user, t->connection_data.pass) < 0)
568
- goto on_error;
569
- if (apply_userpass_credential(s->request, GIT_WINHTTP_AUTH_BASIC, t->url_cred) < 0)
570
- goto on_error;
571
- }
572
-
573
577
  /* We've done everything up to calling WinHttpSendRequest. */
574
578
 
575
579
  error = 0;
@@ -584,9 +588,9 @@ on_error:
584
588
  }
585
589
 
586
590
  static int parse_unauthorized_response(
587
- HINTERNET request,
588
591
  int *allowed_types,
589
- int *allowed_mechanisms)
592
+ int *allowed_mechanisms,
593
+ HINTERNET request)
590
594
  {
591
595
  DWORD supported, first, target;
592
596
 
@@ -602,23 +606,23 @@ static int parse_unauthorized_response(
602
606
  }
603
607
 
604
608
  if (WINHTTP_AUTH_SCHEME_NTLM & supported) {
605
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
606
- *allowed_types |= GIT_CREDTYPE_DEFAULT;
609
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
610
+ *allowed_types |= GIT_CREDENTIAL_DEFAULT;
607
611
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_NTLM;
608
612
  }
609
613
 
610
614
  if (WINHTTP_AUTH_SCHEME_NEGOTIATE & supported) {
611
- *allowed_types |= GIT_CREDTYPE_DEFAULT;
615
+ *allowed_types |= GIT_CREDENTIAL_DEFAULT;
612
616
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_NEGOTIATE;
613
617
  }
614
618
 
615
619
  if (WINHTTP_AUTH_SCHEME_BASIC & supported) {
616
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
620
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
617
621
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_BASIC;
618
622
  }
619
623
 
620
624
  if (WINHTTP_AUTH_SCHEME_DIGEST & supported) {
621
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
625
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
622
626
  *allowed_mechanisms |= GIT_WINHTTP_AUTH_DIGEST;
623
627
  }
624
628
 
@@ -699,27 +703,31 @@ static void CALLBACK winhttp_status(
699
703
  {
700
704
  DWORD status;
701
705
 
706
+ GIT_UNUSED(connection);
707
+ GIT_UNUSED(ctx);
708
+ GIT_UNUSED(info_len);
709
+
702
710
  if (code != WINHTTP_CALLBACK_STATUS_SECURE_FAILURE)
703
711
  return;
704
712
 
705
713
  status = *((DWORD *)info);
706
714
 
707
715
  if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID))
708
- 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");
709
717
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID))
710
- git_error_set(GIT_ERROR_NET, "SSL certificate has expired");
718
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate has expired");
711
719
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA))
712
- 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");
713
721
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT))
714
- git_error_set(GIT_ERROR_NET, "SSL certificate is invalid");
722
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate is invalid");
715
723
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED))
716
- git_error_set(GIT_ERROR_NET, "certificate revocation check failed");
724
+ git_error_set(GIT_ERROR_HTTP, "certificate revocation check failed");
717
725
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED))
718
- git_error_set(GIT_ERROR_NET, "SSL certificate was revoked");
726
+ git_error_set(GIT_ERROR_HTTP, "SSL certificate was revoked");
719
727
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR))
720
- 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");
721
729
  else
722
- git_error_set(GIT_ERROR_NET, "unknown security error %lu", status);
730
+ git_error_set(GIT_ERROR_HTTP, "unknown security error %lu", status);
723
731
  }
724
732
 
725
733
  static int winhttp_connect(
@@ -741,12 +749,12 @@ static int winhttp_connect(
741
749
  t->connection = NULL;
742
750
 
743
751
  /* Prepare port */
744
- if (git__strntol32(&port, t->connection_data.port,
745
- 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)
746
754
  return -1;
747
755
 
748
756
  /* Prepare host */
749
- 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) {
750
758
  git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
751
759
  return -1;
752
760
  }
@@ -824,13 +832,18 @@ on_error:
824
832
  return error;
825
833
  }
826
834
 
827
- 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)
828
836
  {
829
837
  int attempts;
830
838
  bool success;
831
839
 
840
+ if (len > DWORD_MAX) {
841
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
842
+ return -1;
843
+ }
844
+
832
845
  for (attempts = 0; attempts < 5; attempts++) {
833
- if (ignore_length) {
846
+ if (chunked) {
834
847
  success = WinHttpSendRequest(s->request,
835
848
  WINHTTP_NO_ADDITIONAL_HEADERS, 0,
836
849
  WINHTTP_NO_REQUEST_DATA, 0,
@@ -839,7 +852,7 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
839
852
  success = WinHttpSendRequest(s->request,
840
853
  WINHTTP_NO_ADDITIONAL_HEADERS, 0,
841
854
  WINHTTP_NO_REQUEST_DATA, 0,
842
- len, 0);
855
+ (DWORD)len, 0);
843
856
  }
844
857
 
845
858
  if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL)
@@ -849,13 +862,13 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
849
862
  return success ? 0 : -1;
850
863
  }
851
864
 
852
- 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)
853
866
  {
854
867
  int request_failed = 0, cert_valid = 1, error = 0;
855
868
  DWORD ignore_flags;
856
869
 
857
870
  git_error_clear();
858
- if ((error = do_send_request(s, len, ignore_length)) < 0) {
871
+ if ((error = do_send_request(s, len, chunked)) < 0) {
859
872
  if (GetLastError() != ERROR_WINHTTP_SECURE_FAILURE) {
860
873
  git_error_set(GIT_ERROR_OS, "failed to send request");
861
874
  return -1;
@@ -884,12 +897,65 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length)
884
897
  return -1;
885
898
  }
886
899
 
887
- if ((error = do_send_request(s, len, ignore_length)) < 0)
900
+ if ((error = do_send_request(s, len, chunked)) < 0)
888
901
  git_error_set(GIT_ERROR_OS, "failed to send request with unchecked certificate");
889
902
 
890
903
  return error;
891
904
  }
892
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
+
893
959
  static int winhttp_stream_read(
894
960
  git_smart_subtransport_stream *stream,
895
961
  char *buffer,
@@ -905,7 +971,7 @@ static int winhttp_stream_read(
905
971
  replay:
906
972
  /* Enforce a reasonable cap on the number of replays */
907
973
  if (replay_count++ >= GIT_HTTP_REPLAY_MAX) {
908
- 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");
909
975
  return -1;
910
976
  }
911
977
 
@@ -920,7 +986,7 @@ replay:
920
986
 
921
987
  if (!s->sent_request) {
922
988
 
923
- if ((error = send_request(s, s->post_body_len, 0)) < 0)
989
+ if ((error = send_request(s, s->post_body_len, false)) < 0)
924
990
  return error;
925
991
 
926
992
  s->sent_request = 1;
@@ -956,6 +1022,7 @@ replay:
956
1022
  }
957
1023
 
958
1024
  buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1025
+ GIT_ERROR_CHECK_ALLOC(buffer);
959
1026
 
960
1027
  while (len > 0) {
961
1028
  DWORD bytes_written;
@@ -1014,7 +1081,8 @@ replay:
1014
1081
  HTTP_STATUS_REDIRECT == status_code ||
1015
1082
  (HTTP_STATUS_REDIRECT_METHOD == status_code &&
1016
1083
  get_verb == s->verb) ||
1017
- HTTP_STATUS_REDIRECT_KEEP_VERB == status_code)) {
1084
+ HTTP_STATUS_REDIRECT_KEEP_VERB == status_code ||
1085
+ HTTP_STATUS_PERMANENT_REDIRECT == status_code)) {
1018
1086
 
1019
1087
  /* Check for Windows 7. This workaround is only necessary on
1020
1088
  * Windows Vista and earlier. Windows 7 is version 6.1. */
@@ -1062,7 +1130,7 @@ replay:
1062
1130
 
1063
1131
  if (!git__prefixcmp_icase(location8, prefix_https)) {
1064
1132
  /* Upgrade to secure connection; disconnect and start over */
1065
- 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) {
1066
1134
  git__free(location8);
1067
1135
  return -1;
1068
1136
  }
@@ -1077,72 +1145,39 @@ replay:
1077
1145
  goto replay;
1078
1146
  }
1079
1147
 
1080
- /* Handle proxy authentication failures */
1081
- if (status_code == HTTP_STATUS_PROXY_AUTH_REQ) {
1082
- int allowed_types;
1083
-
1084
- if (parse_unauthorized_response(s->request, &allowed_types, &t->auth_mechanisms) < 0)
1085
- return -1;
1086
-
1087
- /* TODO: extract the username from the url, no payload? */
1088
- if (t->owner->proxy.credentials) {
1089
- int cred_error = 1;
1090
- cred_error = t->owner->proxy.credentials(&t->proxy_cred, t->owner->proxy.url, NULL, allowed_types, t->owner->proxy.payload);
1091
-
1092
- if (cred_error < 0)
1093
- return cred_error;
1094
- }
1095
-
1096
- winhttp_stream_close(s);
1097
- goto replay;
1098
- }
1099
-
1100
1148
  /* Handle authentication failures */
1101
- if (HTTP_STATUS_DENIED == status_code && get_verb == s->verb) {
1102
- int allowed_types;
1103
-
1104
- if (parse_unauthorized_response(s->request, &allowed_types, &t->auth_mechanisms) < 0)
1105
- return -1;
1106
-
1107
- if (allowed_types) {
1108
- int cred_error = 1;
1109
-
1110
- git_cred_free(t->cred);
1111
- t->cred = NULL;
1112
- /* Start with the user-supplied credential callback, if present */
1113
- if (t->owner->cred_acquire_cb) {
1114
- cred_error = t->owner->cred_acquire_cb(&t->cred, t->owner->url,
1115
- t->connection_data.user, allowed_types, t->owner->cred_acquire_payload);
1116
-
1117
- /* Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set */
1118
- if (cred_error == GIT_PASSTHROUGH)
1119
- cred_error = 1;
1120
- else if (cred_error < 0)
1121
- return cred_error;
1122
- }
1123
-
1124
- /* Invoke the fallback credentials acquisition callback if necessary */
1125
- if (cred_error > 0) {
1126
- cred_error = fallback_cred_acquire_cb(&t->cred, t->owner->url,
1127
- t->connection_data.user, allowed_types, NULL);
1128
-
1129
- if (cred_error < 0)
1130
- return cred_error;
1131
- }
1132
-
1133
- if (!cred_error) {
1134
- assert(t->cred);
1135
-
1136
- winhttp_stream_close(s);
1137
-
1138
- /* Successfully acquired a credential */
1139
- goto replay;
1140
- }
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;
1141
1176
  }
1142
1177
  }
1143
1178
 
1144
1179
  if (HTTP_STATUS_OK != status_code) {
1145
- 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);
1146
1181
  return -1;
1147
1182
  }
1148
1183
 
@@ -1169,7 +1204,7 @@ replay:
1169
1204
  }
1170
1205
 
1171
1206
  if (wcscmp(expected_content_type, content_type)) {
1172
- git_error_set(GIT_ERROR_NET, "received unexpected content-type");
1207
+ git_error_set(GIT_ERROR_HTTP, "received unexpected content-type");
1173
1208
  return -1;
1174
1209
  }
1175
1210
 
@@ -1204,11 +1239,11 @@ static int winhttp_stream_write_single(
1204
1239
 
1205
1240
  /* This implementation of write permits only a single call. */
1206
1241
  if (s->sent_request) {
1207
- 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");
1208
1243
  return -1;
1209
1244
  }
1210
1245
 
1211
- if ((error = send_request(s, len, 0)) < 0)
1246
+ if ((error = send_request(s, len, false)) < 0)
1212
1247
  return error;
1213
1248
 
1214
1249
  s->sent_request = 1;
@@ -1235,12 +1270,12 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch)
1235
1270
  if (RPC_S_OK != status &&
1236
1271
  RPC_S_UUID_LOCAL_ONLY != status &&
1237
1272
  RPC_S_UUID_NO_ADDRESS != status) {
1238
- 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");
1239
1274
  return -1;
1240
1275
  }
1241
1276
 
1242
1277
  if (buffer_len_cch < UUID_LENGTH_CCH + 1) {
1243
- 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");
1244
1279
  return -1;
1245
1280
  }
1246
1281
 
@@ -1347,7 +1382,7 @@ static int winhttp_stream_write_chunked(
1347
1382
  return -1;
1348
1383
  }
1349
1384
 
1350
- if ((error = send_request(s, 0, 1)) < 0)
1385
+ if ((error = send_request(s, 0, true)) < 0)
1351
1386
  return error;
1352
1387
 
1353
1388
  s->sent_request = 1;
@@ -1370,8 +1405,10 @@ static int winhttp_stream_write_chunked(
1370
1405
  /* Append as much to the buffer as we can */
1371
1406
  int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len);
1372
1407
 
1373
- if (!s->chunk_buffer)
1408
+ if (!s->chunk_buffer) {
1374
1409
  s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1410
+ GIT_ERROR_CHECK_ALLOC(s->chunk_buffer);
1411
+ }
1375
1412
 
1376
1413
  memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count);
1377
1414
  s->chunk_buffer_len += count;
@@ -1496,7 +1533,7 @@ static int winhttp_action(
1496
1533
  int ret = -1;
1497
1534
 
1498
1535
  if (!t->connection)
1499
- 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 ||
1500
1537
  (ret = winhttp_connect(t)) < 0)
1501
1538
  return ret;
1502
1539
 
@@ -1538,24 +1575,17 @@ static int winhttp_close(git_smart_subtransport *subtransport)
1538
1575
  {
1539
1576
  winhttp_subtransport *t = (winhttp_subtransport *)subtransport;
1540
1577
 
1541
- gitno_connection_data_free_ptrs(&t->connection_data);
1542
- memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1543
- gitno_connection_data_free_ptrs(&t->proxy_connection_data);
1544
- memset(&t->proxy_connection_data, 0x0, sizeof(gitno_connection_data));
1545
-
1546
- if (t->cred) {
1547
- t->cred->free(t->cred);
1548
- t->cred = NULL;
1549
- }
1578
+ git_net_url_dispose(&t->server.url);
1579
+ git_net_url_dispose(&t->proxy.url);
1550
1580
 
1551
- if (t->proxy_cred) {
1552
- t->proxy_cred->free(t->proxy_cred);
1553
- t->proxy_cred = NULL;
1581
+ if (t->server.cred) {
1582
+ t->server.cred->free(t->server.cred);
1583
+ t->server.cred = NULL;
1554
1584
  }
1555
1585
 
1556
- if (t->url_cred) {
1557
- t->url_cred->free(t->url_cred);
1558
- t->url_cred = NULL;
1586
+ if (t->proxy.cred) {
1587
+ t->proxy.cred->free(t->proxy.cred);
1588
+ t->proxy.cred = NULL;
1559
1589
  }
1560
1590
 
1561
1591
  return winhttp_close_connection(t);