2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
10 #include "git2/credential_helpers.h"
12 int git_credential_userpass(
13 git_credential
**cred
,
15 const char *user_from_url
,
16 unsigned int allowed_types
,
19 git_credential_userpass_payload
*userpass
= (git_credential_userpass_payload
*)payload
;
20 const char *effective_username
= NULL
;
24 if (!userpass
|| !userpass
->password
) return -1;
26 /* Username resolution: a username can be passed with the URL, the
27 * credentials payload, or both. Here's what we do. Note that if we get
28 * this far, we know that any password the url may contain has already
29 * failed at least once, so we ignore it.
31 * | Payload | URL | Used |
32 * +-------------+----------+-----------+
33 * | yes | no | payload |
34 * | yes | yes | payload |
38 if (userpass
->username
)
39 effective_username
= userpass
->username
;
40 else if (user_from_url
)
41 effective_username
= user_from_url
;
45 if (GIT_CREDENTIAL_USERNAME
& allowed_types
)
46 return git_credential_username_new(cred
, effective_username
);
48 if ((GIT_CREDENTIAL_USERPASS_PLAINTEXT
& allowed_types
) == 0 ||
49 git_credential_userpass_plaintext_new(cred
, effective_username
, userpass
->password
) < 0)
55 /* Deprecated credential functions */
57 #ifndef GIT_DEPRECATE_HARD
58 int git_cred_userpass(
61 const char *user_from_url
,
62 unsigned int allowed_types
,
65 return git_credential_userpass(out
, url
, user_from_url
,
66 allowed_types
, payload
);