diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-08-11 23:30:47 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-08-12 12:07:21 +0200 |
commit | 7affc2f7dec48dc886e9838b102bdd42d06b1d2d (patch) | |
tree | 984e652bbdf601f9c37a6aa15262a04f2b679038 /src/transports/cred.c | |
parent | a25519acc106acf6e1f376c81a078c78778015ed (diff) | |
download | libgit2-7affc2f7dec48dc886e9838b102bdd42d06b1d2d.tar.gz |
Include username in each credential type
Key-based authentication also needs an username, so include it in each
one.
Also stop assuming a default username of "git" in the ssh transport
which has no business making such a decision.
Diffstat (limited to 'src/transports/cred.c')
-rw-r--r-- | src/transports/cred.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/transports/cred.c b/src/transports/cred.c index a6727e902..35aaf4f91 100644 --- a/src/transports/cred.c +++ b/src/transports/cred.c @@ -9,6 +9,31 @@ #include "smart.h" #include "git2/cred_helpers.h" +int git_cred_has_username(git_cred *cred) +{ + int ret = 0; + + switch (cred->credtype) { + case GIT_CREDTYPE_USERPASS_PLAINTEXT: { + git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred; + ret = !!c->username; + break; + } + case GIT_CREDTYPE_SSH_KEYFILE_PASSPHRASE: { + git_cred_ssh_keyfile_passphrase *c = (git_cred_ssh_keyfile_passphrase *)cred; + ret = !!c->username; + break; + } + case GIT_CREDTYPE_SSH_PUBLICKEY: { + git_cred_ssh_publickey *c = (git_cred_ssh_publickey *)cred; + ret = !!c->username; + break; + } + } + + return ret; +} + static void plaintext_free(struct git_cred *cred) { git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred; @@ -64,6 +89,7 @@ static void ssh_keyfile_passphrase_free(struct git_cred *cred) git_cred_ssh_keyfile_passphrase *c = (git_cred_ssh_keyfile_passphrase *)cred; + git__free(c->username); git__free(c->publickey); git__free(c->privatekey); @@ -82,6 +108,7 @@ static void ssh_publickey_free(struct git_cred *cred) { git_cred_ssh_publickey *c = (git_cred_ssh_publickey *)cred; + git__free(c->username); git__free(c->publickey); git__memzero(c, sizeof(*c)); @@ -90,6 +117,7 @@ static void ssh_publickey_free(struct git_cred *cred) int git_cred_ssh_keyfile_passphrase_new( git_cred **cred, + const char *username, const char *publickey, const char *privatekey, const char *passphrase) @@ -104,6 +132,11 @@ int git_cred_ssh_keyfile_passphrase_new( c->parent.credtype = GIT_CREDTYPE_SSH_KEYFILE_PASSPHRASE; c->parent.free = ssh_keyfile_passphrase_free; + if (username) { + c->username = git__strdup(username); + GITERR_CHECK_ALLOC(c->username); + } + c->privatekey = git__strdup(privatekey); GITERR_CHECK_ALLOC(c->privatekey); @@ -123,6 +156,7 @@ int git_cred_ssh_keyfile_passphrase_new( int git_cred_ssh_publickey_new( git_cred **cred, + const char *username, const char *publickey, size_t publickey_len, git_cred_sign_callback sign_callback, @@ -138,6 +172,11 @@ int git_cred_ssh_publickey_new( c->parent.credtype = GIT_CREDTYPE_SSH_PUBLICKEY; c->parent.free = ssh_publickey_free; + if (username) { + c->username = git__strdup(username); + GITERR_CHECK_ALLOC(c->username); + } + if (publickey_len > 0) { c->publickey = git__malloc(publickey_len); GITERR_CHECK_ALLOC(c->publickey); |