rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "git2.h"
9
+ #include "buffer.h"
10
+ #include "auth.h"
11
+
12
+ static int basic_next_token(
13
+ git_buf *out, git_http_auth_context *ctx, git_cred *c)
14
+ {
15
+ git_cred_userpass_plaintext *cred;
16
+ git_buf raw = GIT_BUF_INIT;
17
+ int error = -1;
18
+
19
+ GIT_UNUSED(ctx);
20
+
21
+ if (c->credtype != GIT_CREDTYPE_USERPASS_PLAINTEXT) {
22
+ giterr_set(GITERR_INVALID, "invalid credential type for basic auth");
23
+ goto on_error;
24
+ }
25
+
26
+ cred = (git_cred_userpass_plaintext *)c;
27
+
28
+ git_buf_printf(&raw, "%s:%s", cred->username, cred->password);
29
+
30
+ if (git_buf_oom(&raw) ||
31
+ git_buf_puts(out, "Authorization: Basic ") < 0 ||
32
+ git_buf_encode_base64(out, git_buf_cstr(&raw), raw.size) < 0 ||
33
+ git_buf_puts(out, "\r\n") < 0)
34
+ goto on_error;
35
+
36
+ error = 0;
37
+
38
+ on_error:
39
+ if (raw.size)
40
+ git__memzero(raw.ptr, raw.size);
41
+
42
+ git_buf_free(&raw);
43
+ return error;
44
+ }
45
+
46
+ static git_http_auth_context basic_context = {
47
+ GIT_AUTHTYPE_BASIC,
48
+ GIT_CREDTYPE_USERPASS_PLAINTEXT,
49
+ NULL,
50
+ basic_next_token,
51
+ NULL
52
+ };
53
+
54
+ int git_http_auth_basic(
55
+ git_http_auth_context **out, const gitno_connection_data *connection_data)
56
+ {
57
+ GIT_UNUSED(connection_data);
58
+
59
+ *out = &basic_context;
60
+ return 0;
61
+ }
62
+
63
+ int git_http_auth_dummy(
64
+ git_http_auth_context **out, const gitno_connection_data *connection_data)
65
+ {
66
+ GIT_UNUSED(connection_data);
67
+
68
+ *out = NULL;
69
+ return 0;
70
+ }
71
+
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_http_auth_h__
9
+ #define INCLUDE_http_auth_h__
10
+
11
+ #include "git2.h"
12
+ #include "netops.h"
13
+
14
+ typedef enum {
15
+ GIT_AUTHTYPE_BASIC = 1,
16
+ GIT_AUTHTYPE_NEGOTIATE = 2,
17
+ } git_http_authtype_t;
18
+
19
+ typedef struct git_http_auth_context git_http_auth_context;
20
+
21
+ struct git_http_auth_context {
22
+ /** Type of scheme */
23
+ git_http_authtype_t type;
24
+
25
+ /** Supported credentials */
26
+ git_credtype_t credtypes;
27
+
28
+ /** Sets the challenge on the authentication context */
29
+ int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
30
+
31
+ /** Gets the next authentication token from the context */
32
+ int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_cred *cred);
33
+
34
+ /** Frees the authentication context */
35
+ void (*free)(git_http_auth_context *ctx);
36
+ };
37
+
38
+ typedef struct {
39
+ /** Type of scheme */
40
+ git_http_authtype_t type;
41
+
42
+ /** Name of the scheme (as used in the Authorization header) */
43
+ const char *name;
44
+
45
+ /** Credential types this scheme supports */
46
+ git_credtype_t credtypes;
47
+
48
+ /** Function to initialize an authentication context */
49
+ int (*init_context)(
50
+ git_http_auth_context **out,
51
+ const gitno_connection_data *connection_data);
52
+ } git_http_auth_scheme;
53
+
54
+ int git_http_auth_dummy(
55
+ git_http_auth_context **out,
56
+ const gitno_connection_data *connection_data);
57
+
58
+ int git_http_auth_basic(
59
+ git_http_auth_context **out,
60
+ const gitno_connection_data *connection_data);
61
+
62
+ #endif
63
+
@@ -0,0 +1,275 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifdef GIT_GSSAPI
9
+
10
+ #include "git2.h"
11
+ #include "common.h"
12
+ #include "buffer.h"
13
+ #include "auth.h"
14
+
15
+ #include <gssapi.h>
16
+ #include <krb5.h>
17
+
18
+ static gss_OID_desc negotiate_oid_spnego =
19
+ { 6, (void *) "\x2b\x06\x01\x05\x05\x02" };
20
+ static gss_OID_desc negotiate_oid_krb5 =
21
+ { 9, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" };
22
+
23
+ static gss_OID negotiate_oids[] =
24
+ { &negotiate_oid_spnego, &negotiate_oid_krb5, NULL };
25
+
26
+ typedef struct {
27
+ git_http_auth_context parent;
28
+ unsigned configured : 1,
29
+ complete : 1;
30
+ git_buf target;
31
+ char *challenge;
32
+ gss_ctx_id_t gss_context;
33
+ gss_OID oid;
34
+ } http_auth_negotiate_context;
35
+
36
+ static void negotiate_err_set(
37
+ OM_uint32 status_major,
38
+ OM_uint32 status_minor,
39
+ const char *message)
40
+ {
41
+ gss_buffer_desc buffer = GSS_C_EMPTY_BUFFER;
42
+ OM_uint32 status_display, context = 0;
43
+
44
+ if (gss_display_status(&status_display, status_major, GSS_C_GSS_CODE,
45
+ GSS_C_NO_OID, &context, &buffer) == GSS_S_COMPLETE) {
46
+ giterr_set(GITERR_NET, "%s: %.*s (%d.%d)",
47
+ message, (int)buffer.length, (const char *)buffer.value,
48
+ status_major, status_minor);
49
+ gss_release_buffer(&status_minor, &buffer);
50
+ } else {
51
+ giterr_set(GITERR_NET, "%s: unknown negotiate error (%d.%d)",
52
+ message, status_major, status_minor);
53
+ }
54
+ }
55
+
56
+ static int negotiate_set_challenge(
57
+ git_http_auth_context *c,
58
+ const char *challenge)
59
+ {
60
+ http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
61
+
62
+ assert(ctx && ctx->configured && challenge);
63
+
64
+ git__free(ctx->challenge);
65
+
66
+ ctx->challenge = git__strdup(challenge);
67
+ GITERR_CHECK_ALLOC(ctx->challenge);
68
+
69
+ return 0;
70
+ }
71
+
72
+ static int negotiate_next_token(
73
+ git_buf *buf,
74
+ git_http_auth_context *c,
75
+ git_cred *cred)
76
+ {
77
+ http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
78
+ OM_uint32 status_major, status_minor;
79
+ gss_buffer_desc target_buffer = GSS_C_EMPTY_BUFFER,
80
+ input_token = GSS_C_EMPTY_BUFFER,
81
+ output_token = GSS_C_EMPTY_BUFFER;
82
+ gss_buffer_t input_token_ptr = GSS_C_NO_BUFFER;
83
+ git_buf input_buf = GIT_BUF_INIT;
84
+ gss_name_t server = NULL;
85
+ gss_OID mech;
86
+ size_t challenge_len;
87
+ int error = 0;
88
+
89
+ assert(buf && ctx && ctx->configured && cred && cred->credtype == GIT_CREDTYPE_DEFAULT);
90
+
91
+ if (ctx->complete)
92
+ return 0;
93
+
94
+ target_buffer.value = (void *)ctx->target.ptr;
95
+ target_buffer.length = ctx->target.size;
96
+
97
+ status_major = gss_import_name(&status_minor, &target_buffer,
98
+ GSS_C_NT_HOSTBASED_SERVICE, &server);
99
+
100
+ if (GSS_ERROR(status_major)) {
101
+ negotiate_err_set(status_major, status_minor,
102
+ "Could not parse principal");
103
+ error = -1;
104
+ goto done;
105
+ }
106
+
107
+ challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0;
108
+
109
+ if (challenge_len < 9) {
110
+ giterr_set(GITERR_NET, "No negotiate challenge sent from server");
111
+ error = -1;
112
+ goto done;
113
+ } else if (challenge_len > 9) {
114
+ if (git_buf_decode_base64(&input_buf,
115
+ ctx->challenge + 10, challenge_len - 10) < 0) {
116
+ giterr_set(GITERR_NET, "Invalid negotiate challenge from server");
117
+ error = -1;
118
+ goto done;
119
+ }
120
+
121
+ input_token.value = input_buf.ptr;
122
+ input_token.length = input_buf.size;
123
+ input_token_ptr = &input_token;
124
+ } else if (ctx->gss_context != GSS_C_NO_CONTEXT) {
125
+ giterr_set(GITERR_NET, "Could not restart authentication");
126
+ error = -1;
127
+ goto done;
128
+ }
129
+
130
+ mech = &negotiate_oid_spnego;
131
+
132
+ if (GSS_ERROR(status_major = gss_init_sec_context(
133
+ &status_minor,
134
+ GSS_C_NO_CREDENTIAL,
135
+ &ctx->gss_context,
136
+ server,
137
+ mech,
138
+ GSS_C_DELEG_FLAG | GSS_C_MUTUAL_FLAG,
139
+ GSS_C_INDEFINITE,
140
+ GSS_C_NO_CHANNEL_BINDINGS,
141
+ input_token_ptr,
142
+ NULL,
143
+ &output_token,
144
+ NULL,
145
+ NULL))) {
146
+ negotiate_err_set(status_major, status_minor, "Negotiate failure");
147
+ error = -1;
148
+ goto done;
149
+ }
150
+
151
+ /* This message merely told us auth was complete; we do not respond. */
152
+ if (status_major == GSS_S_COMPLETE) {
153
+ ctx->complete = 1;
154
+ goto done;
155
+ }
156
+
157
+ git_buf_puts(buf, "Authorization: Negotiate ");
158
+ git_buf_encode_base64(buf, output_token.value, output_token.length);
159
+ git_buf_puts(buf, "\r\n");
160
+
161
+ if (git_buf_oom(buf))
162
+ error = -1;
163
+
164
+ done:
165
+ gss_release_name(&status_minor, &server);
166
+ gss_release_buffer(&status_minor, (gss_buffer_t) &output_token);
167
+ git_buf_free(&input_buf);
168
+ return error;
169
+ }
170
+
171
+ static void negotiate_context_free(git_http_auth_context *c)
172
+ {
173
+ http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
174
+ OM_uint32 status_minor;
175
+
176
+ if (ctx->gss_context != GSS_C_NO_CONTEXT) {
177
+ gss_delete_sec_context(
178
+ &status_minor, &ctx->gss_context, GSS_C_NO_BUFFER);
179
+ ctx->gss_context = GSS_C_NO_CONTEXT;
180
+ }
181
+
182
+ git_buf_free(&ctx->target);
183
+
184
+ git__free(ctx->challenge);
185
+
186
+ ctx->configured = 0;
187
+ ctx->complete = 0;
188
+ ctx->oid = NULL;
189
+
190
+ git__free(ctx);
191
+ }
192
+
193
+ static int negotiate_init_context(
194
+ http_auth_negotiate_context *ctx,
195
+ const gitno_connection_data *connection_data)
196
+ {
197
+ OM_uint32 status_major, status_minor;
198
+ gss_OID item, *oid;
199
+ gss_OID_set mechanism_list;
200
+ size_t i;
201
+
202
+ /* Query supported mechanisms looking for SPNEGO) */
203
+ if (GSS_ERROR(status_major =
204
+ gss_indicate_mechs(&status_minor, &mechanism_list))) {
205
+ negotiate_err_set(status_major, status_minor,
206
+ "could not query mechanisms");
207
+ return -1;
208
+ }
209
+
210
+ if (mechanism_list) {
211
+ for (oid = negotiate_oids; *oid; oid++) {
212
+ for (i = 0; i < mechanism_list->count; i++) {
213
+ item = &mechanism_list->elements[i];
214
+
215
+ if (item->length == (*oid)->length &&
216
+ memcmp(item->elements, (*oid)->elements, item->length) == 0) {
217
+ ctx->oid = *oid;
218
+ break;
219
+ }
220
+
221
+ }
222
+
223
+ if (ctx->oid)
224
+ break;
225
+ }
226
+ }
227
+
228
+ gss_release_oid_set(&status_minor, &mechanism_list);
229
+
230
+ if (!ctx->oid) {
231
+ giterr_set(GITERR_NET, "Negotiate authentication is not supported");
232
+ return -1;
233
+ }
234
+
235
+ git_buf_puts(&ctx->target, "HTTP@");
236
+ git_buf_puts(&ctx->target, connection_data->host);
237
+
238
+ if (git_buf_oom(&ctx->target))
239
+ return -1;
240
+
241
+ ctx->gss_context = GSS_C_NO_CONTEXT;
242
+ ctx->configured = 1;
243
+
244
+ return 0;
245
+ }
246
+
247
+ int git_http_auth_negotiate(
248
+ git_http_auth_context **out,
249
+ const gitno_connection_data *connection_data)
250
+ {
251
+ http_auth_negotiate_context *ctx;
252
+
253
+ *out = NULL;
254
+
255
+ ctx = git__calloc(1, sizeof(http_auth_negotiate_context));
256
+ GITERR_CHECK_ALLOC(ctx);
257
+
258
+ if (negotiate_init_context(ctx, connection_data) < 0) {
259
+ git__free(ctx);
260
+ return -1;
261
+ }
262
+
263
+ ctx->parent.type = GIT_AUTHTYPE_NEGOTIATE;
264
+ ctx->parent.credtypes = GIT_CREDTYPE_DEFAULT;
265
+ ctx->parent.set_challenge = negotiate_set_challenge;
266
+ ctx->parent.next_token = negotiate_next_token;
267
+ ctx->parent.free = negotiate_context_free;
268
+
269
+ *out = (git_http_auth_context *)ctx;
270
+
271
+ return 0;
272
+ }
273
+
274
+ #endif /* GIT_GSSAPI */
275
+
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_auth_negotiate_h__
9
+ #define INCLUDE_auth_negotiate_h__
10
+
11
+ #include "git2.h"
12
+ #include "auth.h"
13
+
14
+ #ifdef GIT_GSSAPI
15
+
16
+ extern int git_http_auth_negotiate(
17
+ git_http_auth_context **out,
18
+ const gitno_connection_data *connection_data);
19
+
20
+ #else
21
+
22
+ #define git_http_auth_negotiate git_http_auth_dummy
23
+
24
+ #endif /* GIT_GSSAPI */
25
+
26
+ #endif
27
+
@@ -17,6 +17,40 @@ int git_cred_has_username(git_cred *cred)
17
17
  return 1;
18
18
  }
19
19
 
20
+ const char *git_cred__username(git_cred *cred)
21
+ {
22
+ switch (cred->credtype) {
23
+ case GIT_CREDTYPE_USERNAME:
24
+ {
25
+ git_cred_username *c = (git_cred_username *) cred;
26
+ return c->username;
27
+ }
28
+ case GIT_CREDTYPE_USERPASS_PLAINTEXT:
29
+ {
30
+ git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *) cred;
31
+ return c->username;
32
+ }
33
+ case GIT_CREDTYPE_SSH_KEY:
34
+ {
35
+ git_cred_ssh_key *c = (git_cred_ssh_key *) cred;
36
+ return c->username;
37
+ }
38
+ case GIT_CREDTYPE_SSH_CUSTOM:
39
+ {
40
+ git_cred_ssh_custom *c = (git_cred_ssh_custom *) cred;
41
+ return c->username;
42
+ }
43
+ case GIT_CREDTYPE_SSH_INTERACTIVE:
44
+ {
45
+ git_cred_ssh_interactive *c = (git_cred_ssh_interactive *) cred;
46
+ return c->username;
47
+ }
48
+
49
+ default:
50
+ return NULL;
51
+ }
52
+ }
53
+
20
54
  static void plaintext_free(struct git_cred *cred)
21
55
  {
22
56
  git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
@@ -129,6 +163,11 @@ static void default_free(struct git_cred *cred)
129
163
  git__free(c);
130
164
  }
131
165
 
166
+ static void username_free(struct git_cred *cred)
167
+ {
168
+ git__free(cred);
169
+ }
170
+
132
171
  int git_cred_ssh_key_new(
133
172
  git_cred **cred,
134
173
  const char *username,
@@ -263,3 +302,22 @@ int git_cred_default_new(git_cred **cred)
263
302
  *cred = c;
264
303
  return 0;
265
304
  }
305
+
306
+ int git_cred_username_new(git_cred **cred, const char *username)
307
+ {
308
+ git_cred_username *c;
309
+ size_t len;
310
+
311
+ assert(cred);
312
+
313
+ len = strlen(username);
314
+ c = git__malloc(sizeof(git_cred_username) + len + 1);
315
+ GITERR_CHECK_ALLOC(c);
316
+
317
+ c->parent.credtype = GIT_CREDTYPE_USERNAME;
318
+ c->parent.free = username_free;
319
+ memcpy(c->username, username, len + 1);
320
+
321
+ *cred = (git_cred *) c;
322
+ return 0;
323
+ }