|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
Packit Service |
20376f |
* a Linking Exception. For full terms see the included COPYING file.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#include "common.h"
|
|
Packit Service |
20376f |
#include "git2/cred_helpers.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_cred_userpass(
|
|
Packit Service |
20376f |
git_cred **cred,
|
|
Packit Service |
20376f |
const char *url,
|
|
Packit Service |
20376f |
const char *user_from_url,
|
|
Packit Service |
20376f |
unsigned int allowed_types,
|
|
Packit Service |
20376f |
void *payload)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_cred_userpass_payload *userpass = (git_cred_userpass_payload*)payload;
|
|
Packit Service |
20376f |
const char *effective_username = NULL;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
GIT_UNUSED(url);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (!userpass || !userpass->password) return -1;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Username resolution: a username can be passed with the URL, the
|
|
Packit Service |
20376f |
* credentials payload, or both. Here's what we do. Note that if we get
|
|
Packit Service |
20376f |
* this far, we know that any password the url may contain has already
|
|
Packit Service |
20376f |
* failed at least once, so we ignore it.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* | Payload | URL | Used |
|
|
Packit Service |
20376f |
* +-------------+----------+-----------+
|
|
Packit Service |
20376f |
* | yes | no | payload |
|
|
Packit Service |
20376f |
* | yes | yes | payload |
|
|
Packit Service |
20376f |
* | no | yes | url |
|
|
Packit Service |
20376f |
* | no | no | FAIL |
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
if (userpass->username)
|
|
Packit Service |
20376f |
effective_username = userpass->username;
|
|
Packit Service |
20376f |
else if (user_from_url)
|
|
Packit Service |
20376f |
effective_username = user_from_url;
|
|
Packit Service |
20376f |
else
|
|
Packit Service |
20376f |
return -1;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (GIT_CREDTYPE_USERNAME & allowed_types)
|
|
Packit Service |
20376f |
return git_cred_username_new(cred, effective_username);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
|
|
Packit Service |
20376f |
git_cred_userpass_plaintext_new(cred, effective_username, userpass->password) < 0)
|
|
Packit Service |
20376f |
return -1;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return 0;
|
|
Packit Service |
20376f |
}
|