mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-02 12:29:08 +00:00
parent
72629a10e3
commit
59bccf33c4
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user