Add a payload param to git_cred_acquire_cb Fixes #1128.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
diff --git a/include/git2/remote.h b/include/git2/remote.h
index af73ca8..82aff38 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -313,7 +313,8 @@ GIT_EXTERN(void) git_remote_check_cert(git_remote *remote, int check);
*/
GIT_EXTERN(void) git_remote_set_cred_acquire_cb(
git_remote *remote,
- git_cred_acquire_cb cred_acquire_cb);
+ git_cred_acquire_cb cred_acquire_cb,
+ void *payload);
/**
* Sets a custom transport for the remote. The caller can use this function
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 00beb44..c2f2052 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -65,7 +65,8 @@ GIT_EXTERN(int) git_cred_userpass_plaintext_new(
typedef int (*git_cred_acquire_cb)(
git_cred **cred,
const char *url,
- unsigned int allowed_types);
+ unsigned int allowed_types,
+ void *payload);
/*
*** End interface for credentials acquisition ***
@@ -94,6 +95,7 @@ typedef struct git_transport {
int (*connect)(struct git_transport *transport,
const char *url,
git_cred_acquire_cb cred_acquire_cb,
+ void *cred_acquire_payload,
int direction,
int flags);
diff --git a/src/remote.c b/src/remote.c
index 5b75e51..670904b 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -90,10 +90,9 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con
/* name is optional */
assert(out && repo && url);
- remote = git__malloc(sizeof(git_remote));
+ remote = git__calloc(1, sizeof(git_remote));
GITERR_CHECK_ALLOC(remote);
- memset(remote, 0x0, sizeof(git_remote));
remote->repo = repo;
remote->check_cert = 1;
remote->update_fetchhead = 1;
@@ -509,7 +508,7 @@ int git_remote_connect(git_remote *remote, git_direction direction)
if (!remote->check_cert)
flags |= GIT_TRANSPORTFLAGS_NO_CHECK_CERT;
- if (t->connect(t, url, remote->cred_acquire_cb, direction, flags) < 0)
+ if (t->connect(t, url, remote->cred_acquire_cb, remote->cred_acquire_payload, direction, flags) < 0)
goto on_error;
remote->transport = t;
@@ -1019,11 +1018,13 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks
void git_remote_set_cred_acquire_cb(
git_remote *remote,
- git_cred_acquire_cb cred_acquire_cb)
+ git_cred_acquire_cb cred_acquire_cb,
+ void *payload)
{
assert(remote);
remote->cred_acquire_cb = cred_acquire_cb;
+ remote->cred_acquire_payload = payload;
}
int git_remote_set_transport(git_remote *remote, git_transport *transport)
diff --git a/src/remote.h b/src/remote.h
index 06f712f..8d39244 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -23,6 +23,7 @@ struct git_remote {
struct git_refspec fetch;
struct git_refspec push;
git_cred_acquire_cb cred_acquire_cb;
+ void *cred_acquire_payload;
git_transport *transport;
git_repository *repo;
git_remote_callbacks callbacks;
diff --git a/src/transports/http.c b/src/transports/http.c
index 02f7492..fd1a99f 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -256,7 +256,8 @@ static int on_headers_complete(http_parser *parser)
if (t->owner->cred_acquire_cb(&t->cred,
t->owner->url,
- allowed_types) < 0)
+ allowed_types,
+ t->owner->cred_acquire_payload) < 0)
return PARSE_ERROR_GENERIC;
assert(t->cred);
diff --git a/src/transports/local.c b/src/transports/local.c
index 768daf3..53b2494 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -143,6 +143,7 @@ static int local_connect(
git_transport *transport,
const char *url,
git_cred_acquire_cb cred_acquire_cb,
+ void *cred_acquire_payload,
int direction, int flags)
{
git_repository *repo;
@@ -152,6 +153,7 @@ static int local_connect(
git_buf buf = GIT_BUF_INIT;
GIT_UNUSED(cred_acquire_cb);
+ GIT_UNUSED(cred_acquire_payload);
t->url = git__strdup(url);
GITERR_CHECK_ALLOC(t->url);
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 5300a47..8b89fa2 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -62,6 +62,7 @@ static int git_smart__connect(
git_transport *transport,
const char *url,
git_cred_acquire_cb cred_acquire_cb,
+ void *cred_acquire_payload,
int direction,
int flags)
{
@@ -81,6 +82,7 @@ static int git_smart__connect(
t->direction = direction;
t->flags = flags;
t->cred_acquire_cb = cred_acquire_cb;
+ t->cred_acquire_payload = cred_acquire_payload;
if (GIT_DIRECTION_FETCH == t->direction)
service = GIT_SERVICE_UPLOADPACK_LS;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index ea2784b..c86b1cb 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -125,6 +125,7 @@ typedef struct {
git_remote *owner;
char *url;
git_cred_acquire_cb cred_acquire_cb;
+ void *cred_acquire_payload;
int direction;
int flags;
git_transport_message_cb progress_cb;
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 80ff726..a733159 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -694,12 +694,13 @@ int git_smart__push(git_transport *transport, git_push *push)
* the data from the push report to do this without another network call */
if (push->specs.length) {
git_cred_acquire_cb cred_cb = t->cred_acquire_cb;
+ void *cred_payload = t->cred_acquire_payload;
int flags = t->flags;
url = git__strdup(t->url);
if (!url || t->parent.close(&t->parent) < 0 ||
- t->parent.connect(&t->parent, url, cred_cb, GIT_DIRECTION_PUSH, flags))
+ t->parent.connect(&t->parent, url, cred_cb, cred_payload, GIT_DIRECTION_PUSH, flags))
goto on_error;
}
diff --git a/tests-clar/network/push.c b/tests-clar/network/push.c
index acc376d..f885609 100644
--- a/tests-clar/network/push.c
+++ b/tests-clar/network/push.c
@@ -27,10 +27,12 @@ static git_oid _oid_b1;
/* git_oid *oid, git_repository *repo, (string literal) blob */
#define CREATE_BLOB(oid, repo, blob) git_blob_create_frombuffer(oid, repo, blob, sizeof(blob) - 1)
-static int cred_acquire_cb(git_cred **cred, const char *url, unsigned int allowed_types)
+static int cred_acquire_cb(git_cred **cred, const char *url, unsigned int allowed_types, void *payload)
{
GIT_UNUSED(url);
+ *((bool*)payload) = true;
+
if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass) < 0)
return -1;
@@ -130,6 +132,7 @@ void test_network_push__initialize(void)
git_vector delete_specs = GIT_VECTOR_INIT;
size_t i;
char *curr_del_spec;
+ bool cred_acquire_called = false;
_repo = cl_git_sandbox_init("push_src");
@@ -165,7 +168,7 @@ void test_network_push__initialize(void)
if (_remote_url) {
cl_git_pass(git_remote_add(&_remote, _repo, "test", _remote_url));
- git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb);
+ git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &cred_acquire_called);
record_callbacks_data_clear(&_record_cbs_data);
git_remote_set_callbacks(_remote, &_record_cbs);