diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-04-16 12:03:20 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-04-16 12:03:20 +0200 |
commit | 172786ec1b7eab7ffdb13b64c5a18f38083d2c2c (patch) | |
tree | b35e1a5253a624ac78a0228f58eaef3c01ef6230 /examples | |
parent | 611fbe4f9b7d2682c8b2653e8abc9dcf5a9a984c (diff) | |
download | libgit2-172786ec1b7eab7ffdb13b64c5a18f38083d2c2c.tar.gz |
examples: use username provided via URL
The credentials callback may be passed a username in case where
the URL already includes the expected username. As we usually
cannot use a different username in such context, we should use
that one if provided and not ask the user for a diferent
username.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/common.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/common.c b/examples/common.c index 0b52eb583..4cd9f2bec 100644 --- a/examples/common.c +++ b/examples/common.c @@ -353,14 +353,19 @@ int cred_acquire_cb(git_cred **out, int error = 1; UNUSED(url); - UNUSED(username_from_url); UNUSED(payload); + if (username_from_url) { + if ((username = strdup(username_from_url)) == NULL) + goto out; + } else if ((error = ask(&username, "Username:", 0)) < 0) { + goto out; + } + if (allowed_types & GIT_CREDTYPE_SSH_KEY) { int n; - if ((error = ask(&username, "Username:", 0)) < 0 || - (error = ask(&privkey, "SSH Key:", 0)) < 0 || + if ((error = ask(&privkey, "SSH Key:", 0)) < 0 || (error = ask(&password, "Password:", 1)) < 0) goto out; @@ -371,15 +376,11 @@ int cred_acquire_cb(git_cred **out, error = git_cred_ssh_key_new(out, username, pubkey, privkey, password); } else if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT) { - if ((error = ask(&username, "Username:", 0)) < 0 || - (error = ask(&password, "Password:", 1)) < 0) + if ((error = ask(&password, "Password:", 1)) < 0) goto out; error = git_cred_userpass_plaintext_new(out, username, password); } else if (allowed_types & GIT_CREDTYPE_USERNAME) { - if ((error = ask(&username, "Username:", 0)) < 0) - goto out; - error = git_cred_username_new(out, username); } |