source src/transports/credential_helpers.c
| Line | Flow | Count | Block(s) | Source |
|---|---|---|---|---|
| 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 | ![]() |
9 | 2 | 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 | 9 | 2 | git_credential_userpass_payload *userpass = (git_credential_userpass_payload*)payload; | |
| 20 | 9 | 2 | const char *effective_username = NULL; | |
| 21 | - | |||
| 22 | - | GIT_UNUSED(url); | ||
| 23 | - | |||
| 24 | 9 | 2-4 | if (!userpass || !userpass->password) return -1; | |
| 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 | 6 | 5 | if (userpass->username) | |
| 39 | 5 | 6 | effective_username = userpass->username; | |
| 40 | 1 | 7 | else if (user_from_url) | |
| 41 | 1 | 8 | effective_username = user_from_url; | |
| 42 | - | else | ||
| 43 | ##### | 9 | return -1; | |
| 44 | - | |||
| 45 | 6 | 10 | if (GIT_CREDENTIAL_USERNAME & allowed_types) | |
| 46 | ##### | 11 | return git_credential_username_new(cred, effective_username); | |
| 47 | - | |||
| 48 | 6 | 12,14 | if ((GIT_CREDENTIAL_USERPASS_PLAINTEXT & allowed_types) == 0 || | |
| 49 | 5 | 13 | git_credential_userpass_plaintext_new(cred, effective_username, userpass->password) < 0) | |
| 50 | 1 | 15 | return -1; | |
| 51 | - | |||
| 52 | 5 | 16 | return 0; | |
| 53 | - | } | ||
| 54 | - | |||
| 55 | - | /* Deprecated credential functions */ | ||
| 56 | - | |||
| 57 | - | #ifndef GIT_DEPRECATE_HARD | ||
| 58 | ##### | 2 | 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 | ##### | 2 | return git_credential_userpass(out, url, user_from_url, | |
| 66 | - | allowed_types, payload); | ||
| 67 | - | } | ||
| 68 | - | #endif |