summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transports/cred_helpers.c21
-rw-r--r--src/transports/http.c1
2 files changed, 20 insertions, 2 deletions
diff --git a/src/transports/cred_helpers.c b/src/transports/cred_helpers.c
index 8d8eb9990..a05d5e874 100644
--- a/src/transports/cred_helpers.c
+++ b/src/transports/cred_helpers.c
@@ -11,17 +11,34 @@
int git_cred_userpass(
git_cred **cred,
const char *url,
+ const char *user_from_url,
unsigned int allowed_types,
void *payload)
{
git_cred_userpass_payload *userpass = (git_cred_userpass_payload*)payload;
+ const char *effective_username = NULL;
GIT_UNUSED(url);
- if (!userpass || !userpass->username || !userpass->password) return -1;
+ if (!userpass || !userpass->password) return -1;
+
+ /* Username resolution: a username can be passed with the URL, the
+ * credentials payload, or both. Here's what we do.
+ *
+ * | Payload | URL | Used |
+ * +-------------+----------+-----------+
+ * | yes | no | payload |
+ * | yes | yes | payload |
+ * | no | yes | url |
+ * | no | no | FAIL |
+ */
+ effective_username = userpass->username;
+ if (!userpass->username && user_from_url)
+ effective_username = user_from_url;
+ if (!effective_username) return -1;
if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
- git_cred_userpass_plaintext_new(cred, userpass->username, userpass->password) < 0)
+ git_cred_userpass_plaintext_new(cred, effective_username, userpass->password) < 0)
return -1;
return 0;
diff --git a/src/transports/http.c b/src/transports/http.c
index e5bb1071f..144906474 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -257,6 +257,7 @@ static int on_headers_complete(http_parser *parser)
if (t->owner->cred_acquire_cb(&t->cred,
t->owner->url,
+ t->user_from_url,
allowed_types,
t->owner->cred_acquire_payload) < 0)
return PARSE_ERROR_GENERIC;