diff options
| author | Ben Straub <bs@github.com> | 2013-01-31 14:41:01 -0800 |
|---|---|---|
| committer | Ben Straub <bs@github.com> | 2013-01-31 14:41:01 -0800 |
| commit | 54ffc1f773369d797e4065fcd62719cd4c22c04c (patch) | |
| tree | 4def77676b333526fed51f31ada5669b64f4d5ee /src | |
| parent | cd74cbba18db33091056b098889e82de598a6cdd (diff) | |
| download | libgit2-54ffc1f773369d797e4065fcd62719cd4c22c04c.tar.gz | |
HTTP: use creds in url if available
Diffstat (limited to 'src')
| -rw-r--r-- | src/transports/http.c | 14 | ||||
| -rw-r--r-- | src/transports/winhttp.c | 5 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/transports/http.c b/src/transports/http.c index 6c116d8e7..964bafb19 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -63,6 +63,7 @@ typedef struct { char *user_from_url; char *pass_from_url; git_cred *cred; + git_cred *url_cred; http_authmechanism_t auth_mechanism; unsigned connected : 1, use_ssl : 1; @@ -146,6 +147,14 @@ static int gen_request( apply_basic_credential(buf, t->cred) < 0) return -1; + /* Use url-parsed basic auth if username and password are both provided */ + if (!t->cred && t->user_from_url && t->pass_from_url) { + if (!t->url_cred && + git_cred_userpass_plaintext_new(&t->url_cred, t->user_from_url, t->pass_from_url) < 0) + return -1; + if (apply_basic_credential(buf, t->url_cred) < 0) return -1; + } + git_buf_puts(buf, "\r\n"); if (git_buf_oom(buf)) @@ -812,6 +821,11 @@ static int http_close(git_smart_subtransport *subtransport) t->cred = NULL; } + if (t->url_cred) { + t->url_cred->free(t->url_cred); + t->url_cred = NULL; + } + if (t->host) { git__free(t->host); t->host = NULL; diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 4ac085ed3..780b84e45 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -960,6 +960,11 @@ static int winhttp_close(git_smart_subtransport *subtransport) t->cred = NULL; } + if (t->url_cred) { + t->url_cred->free(t->url_cred); + t->url_cred = NULL; + } + if (t->connection) { if (!WinHttpCloseHandle(t->connection)) { giterr_set(GITERR_OS, "Unable to close connection"); |
