File Coverage

deps/libgit2/src/libgit2/transports/credential_helpers.c
Criterion Covered Total %
statement 0 18 0.0
branch 0 10 0.0
condition n/a
subroutine n/a
pod n/a
total 0 28 0.0


line stmt bran cond sub pod time code
1             /*
2             * Copyright (C) the libgit2 contributors. All rights reserved.
3             *
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.
6             */
7              
8             #include "common.h"
9              
10             #include "git2/credential_helpers.h"
11              
12 0           int git_credential_userpass(
13             git_credential **cred,
14             const char *url,
15             const char *user_from_url,
16             unsigned int allowed_types,
17             void *payload)
18             {
19 0           git_credential_userpass_payload *userpass = (git_credential_userpass_payload*)payload;
20 0           const char *effective_username = NULL;
21              
22 0           GIT_UNUSED(url);
23              
24 0 0         if (!userpass || !userpass->password) return -1;
    0          
25              
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.
30             *
31             * | Payload | URL | Used |
32             * +-------------+----------+-----------+
33             * | yes | no | payload |
34             * | yes | yes | payload |
35             * | no | yes | url |
36             * | no | no | FAIL |
37             */
38 0 0         if (userpass->username)
39 0           effective_username = userpass->username;
40 0 0         else if (user_from_url)
41 0           effective_username = user_from_url;
42             else
43 0           return -1;
44              
45 0 0         if (GIT_CREDENTIAL_USERNAME & allowed_types)
46 0           return git_credential_username_new(cred, effective_username);
47              
48 0           if ((GIT_CREDENTIAL_USERPASS_PLAINTEXT & allowed_types) == 0 ||
49 0           git_credential_userpass_plaintext_new(cred, effective_username, userpass->password) < 0)
50 0           return -1;
51              
52 0           return 0;
53             }
54              
55             /* Deprecated credential functions */
56              
57             #ifndef GIT_DEPRECATE_HARD
58 0           int git_cred_userpass(
59             git_credential **out,
60             const char *url,
61             const char *user_from_url,
62             unsigned int allowed_types,
63             void *payload)
64             {
65 0           return git_credential_userpass(out, url, user_from_url,
66             allowed_types, payload);
67             }
68             #endif