summaryrefslogtreecommitdiff
path: root/src/transports
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2020-01-18 13:51:40 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2020-01-26 18:39:41 +0000
commit3f54ba8b61869f42b2bbd1a60091a0be640bc8fc (patch)
treed2ea442f1ab5ecb7a0f8c10d3a26664bc4c44cdc /src/transports
parent4460bf40c9e935acb853b5d61279a50014ede0b3 (diff)
downloadlibgit2-3f54ba8b61869f42b2bbd1a60091a0be640bc8fc.tar.gz
credential: change git_cred to git_credentialethomson/credtype
We avoid abbreviations where possible; rename git_cred to git_credential. In addition, we have standardized on a trailing `_t` for enum types, instead of using "type" in the name. So `git_credtype_t` has become `git_credential_t` and its members have become `GIT_CREDENTIAL` instead of `GIT_CREDTYPE`. Finally, the source and header files have been renamed to `credential` instead of `cred`. Keep previous name and values as deprecated, and include the new header files from the previous ones.
Diffstat (limited to 'src/transports')
-rw-r--r--src/transports/auth.c12
-rw-r--r--src/transports/auth.h6
-rw-r--r--src/transports/auth_negotiate.c8
-rw-r--r--src/transports/auth_ntlm.c14
-rw-r--r--src/transports/cred.c390
-rw-r--r--src/transports/credential.c476
-rw-r--r--src/transports/credential_helpers.c (renamed from src/transports/cred_helpers.c)29
-rw-r--r--src/transports/http.c22
-rw-r--r--src/transports/httpclient.c14
-rw-r--r--src/transports/httpclient.h22
-rw-r--r--src/transports/local.c2
-rw-r--r--src/transports/smart.c4
-rw-r--r--src/transports/smart.h2
-rw-r--r--src/transports/ssh.c56
-rw-r--r--src/transports/winhttp.c48
15 files changed, 602 insertions, 503 deletions
diff --git a/src/transports/auth.c b/src/transports/auth.c
index b5f9b4099..4aa3df021 100644
--- a/src/transports/auth.c
+++ b/src/transports/auth.c
@@ -9,25 +9,25 @@
#include "git2.h"
#include "buffer.h"
-#include "git2/sys/cred.h"
+#include "git2/sys/credential.h"
static int basic_next_token(
git_buf *out,
git_http_auth_context *ctx,
- git_cred *c)
+ git_credential *c)
{
- git_cred_userpass_plaintext *cred;
+ git_credential_userpass_plaintext *cred;
git_buf raw = GIT_BUF_INIT;
int error = -1;
GIT_UNUSED(ctx);
- if (c->credtype != GIT_CREDTYPE_USERPASS_PLAINTEXT) {
+ if (c->credtype != GIT_CREDENTIAL_USERPASS_PLAINTEXT) {
git_error_set(GIT_ERROR_INVALID, "invalid credential type for basic auth");
goto on_error;
}
- cred = (git_cred_userpass_plaintext *)c;
+ cred = (git_credential_userpass_plaintext *)c;
git_buf_printf(&raw, "%s:%s", cred->username, cred->password);
@@ -48,7 +48,7 @@ on_error:
static git_http_auth_context basic_context = {
GIT_HTTP_AUTH_BASIC,
- GIT_CREDTYPE_USERPASS_PLAINTEXT,
+ GIT_CREDENTIAL_USERPASS_PLAINTEXT,
0,
NULL,
basic_next_token,
diff --git a/src/transports/auth.h b/src/transports/auth.h
index 762467678..9caac4676 100644
--- a/src/transports/auth.h
+++ b/src/transports/auth.h
@@ -26,7 +26,7 @@ struct git_http_auth_context {
git_http_auth_t type;
/** Supported credentials */
- git_credtype_t credtypes;
+ git_credential_t credtypes;
/** Connection affinity or request affinity */
unsigned connection_affinity : 1;
@@ -35,7 +35,7 @@ struct git_http_auth_context {
int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
/** Gets the next authentication token from the context */
- int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_cred *cred);
+ int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_credential *cred);
/** Examines if all tokens have been presented. */
int (*is_complete)(git_http_auth_context *ctx);
@@ -52,7 +52,7 @@ typedef struct {
const char *name;
/** Credential types this scheme supports */
- git_credtype_t credtypes;
+ git_credential_t credtypes;
/** Function to initialize an authentication context */
int (*init_context)(
diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c
index 8fa44cd72..8a614b81a 100644
--- a/src/transports/auth_negotiate.c
+++ b/src/transports/auth_negotiate.c
@@ -12,7 +12,7 @@
#include "git2.h"
#include "buffer.h"
#include "auth.h"
-#include "git2/sys/cred.h"
+#include "git2/sys/credential.h"
#ifdef GIT_GSSFRAMEWORK
#import <GSS/GSS.h>
@@ -94,7 +94,7 @@ static void negotiate_context_dispose(http_auth_negotiate_context *ctx)
static int negotiate_next_token(
git_buf *buf,
git_http_auth_context *c,
- git_cred *cred)
+ git_credential *cred)
{
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
OM_uint32 status_major, status_minor;
@@ -108,7 +108,7 @@ static int negotiate_next_token(
size_t challenge_len;
int error = 0;
- assert(buf && ctx && ctx->configured && cred && cred->credtype == GIT_CREDTYPE_DEFAULT);
+ assert(buf && ctx && ctx->configured && cred && cred->credtype == GIT_CREDENTIAL_DEFAULT);
if (ctx->complete)
return 0;
@@ -292,7 +292,7 @@ int git_http_auth_negotiate(
}
ctx->parent.type = GIT_HTTP_AUTH_NEGOTIATE;
- ctx->parent.credtypes = GIT_CREDTYPE_DEFAULT;
+ ctx->parent.credtypes = GIT_CREDENTIAL_DEFAULT;
ctx->parent.connection_affinity = 1;
ctx->parent.set_challenge = negotiate_set_challenge;
ctx->parent.next_token = negotiate_next_token;
diff --git a/src/transports/auth_ntlm.c b/src/transports/auth_ntlm.c
index 7d9c5976d..02a861f07 100644
--- a/src/transports/auth_ntlm.c
+++ b/src/transports/auth_ntlm.c
@@ -10,7 +10,7 @@
#include "buffer.h"
#include "auth.h"
#include "auth_ntlm.h"
-#include "git2/sys/cred.h"
+#include "git2/sys/credential.h"
#ifdef GIT_NTLM
@@ -39,15 +39,15 @@ static int ntlm_set_challenge(
return 0;
}
-static int ntlm_set_credentials(http_auth_ntlm_context *ctx, git_cred *_cred)
+static int ntlm_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cred)
{
- git_cred_userpass_plaintext *cred;
+ git_credential_userpass_plaintext *cred;
const char *sep, *username;
char *domain = NULL, *domainuser = NULL;
int error = 0;
- assert(_cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT);
- cred = (git_cred_userpass_plaintext *)_cred;
+ assert(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
+ cred = (git_credential_userpass_plaintext *)_cred;
if ((sep = strchr(cred->username, '\\')) != NULL) {
domain = strndup(cred->username, (sep - cred->username));
@@ -78,7 +78,7 @@ done:
static int ntlm_next_token(
git_buf *buf,
git_http_auth_context *c,
- git_cred *cred)
+ git_credential *cred)
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
git_buf input_buf = GIT_BUF_INIT;
@@ -208,7 +208,7 @@ int git_http_auth_ntlm(
}
ctx->parent.type = GIT_HTTP_AUTH_NTLM;
- ctx->parent.credtypes = GIT_CREDTYPE_USERPASS_PLAINTEXT;
+ ctx->parent.credtypes = GIT_CREDENTIAL_USERPASS_PLAINTEXT;
ctx->parent.connection_affinity = 1;
ctx->parent.set_challenge = ntlm_set_challenge;
ctx->parent.next_token = ntlm_next_token;
diff --git a/src/transports/cred.c b/src/transports/cred.c
deleted file mode 100644
index 80c4d3698..000000000
--- a/src/transports/cred.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#include "common.h"
-
-#include "git2/cred.h"
-#include "git2/sys/cred.h"
-#include "git2/cred_helpers.h"
-
-static int git_cred_ssh_key_type_new(
- git_cred **cred,
- const char *username,
- const char *publickey,
- const char *privatekey,
- const char *passphrase,
- git_credtype_t credtype);
-
-int git_cred_has_username(git_cred *cred)
-{
- if (cred->credtype == GIT_CREDTYPE_DEFAULT)
- return 0;
-
- return 1;
-}
-
-const char *git_cred_get_username(git_cred *cred)
-{
- switch (cred->credtype) {
- case GIT_CREDTYPE_USERNAME:
- {
- git_cred_username *c = (git_cred_username *) cred;
- return c->username;
- }
- case GIT_CREDTYPE_USERPASS_PLAINTEXT:
- {
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *) cred;
- return c->username;
- }
- case GIT_CREDTYPE_SSH_KEY:
- case GIT_CREDTYPE_SSH_MEMORY:
- {
- git_cred_ssh_key *c = (git_cred_ssh_key *) cred;
- return c->username;
- }
- case GIT_CREDTYPE_SSH_CUSTOM:
- {
- git_cred_ssh_custom *c = (git_cred_ssh_custom *) cred;
- return c->username;
- }
- case GIT_CREDTYPE_SSH_INTERACTIVE:
- {
- git_cred_ssh_interactive *c = (git_cred_ssh_interactive *) cred;
- return c->username;
- }
-
- default:
- return NULL;
- }
-}
-
-static void plaintext_free(struct git_cred *cred)
-{
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
-
- git__free(c->username);
-
- /* Zero the memory which previously held the password */
- if (c->password) {
- size_t pass_len = strlen(c->password);
- git__memzero(c->password, pass_len);
- git__free(c->password);
- }
-
- git__free(c);
-}
-
-int git_cred_userpass_plaintext_new(
- git_cred **cred,
- const char *username,
- const char *password)
-{
- git_cred_userpass_plaintext *c;
-
- assert(cred && username && password);
-
- c = git__malloc(sizeof(git_cred_userpass_plaintext));
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->parent.credtype = GIT_CREDTYPE_USERPASS_PLAINTEXT;
- c->parent.free = plaintext_free;
- c->username = git__strdup(username);
-
- if (!c->username) {
- git__free(c);
- return -1;
- }
-
- c->password = git__strdup(password);
-
- if (!c->password) {
- git__free(c->username);
- git__free(c);
- return -1;
- }
-
- *cred = &c->parent;
- return 0;
-}
-
-static void ssh_key_free(struct git_cred *cred)
-{
- git_cred_ssh_key *c =
- (git_cred_ssh_key *)cred;
-
- git__free(c->username);
-
- if (c->privatekey) {
- /* Zero the memory which previously held the private key */
- size_t key_len = strlen(c->privatekey);
- git__memzero(c->privatekey, key_len);
- git__free(c->privatekey);
- }
-
- if (c->passphrase) {
- /* Zero the memory which previously held the passphrase */
- size_t pass_len = strlen(c->passphrase);
- git__memzero(c->passphrase, pass_len);
- git__free(c->passphrase);
- }
-
- if (c->publickey) {
- /* Zero the memory which previously held the public key */
- size_t key_len = strlen(c->publickey);
- git__memzero(c->publickey, key_len);
- git__free(c->publickey);
- }
-
- git__free(c);
-}
-
-static void ssh_interactive_free(struct git_cred *cred)
-{
- git_cred_ssh_interactive *c = (git_cred_ssh_interactive *)cred;
-
- git__free(c->username);
-
- git__free(c);
-}
-
-static void ssh_custom_free(struct git_cred *cred)
-{
- git_cred_ssh_custom *c = (git_cred_ssh_custom *)cred;
-
- git__free(c->username);
-
- if (c->publickey) {
- /* Zero the memory which previously held the publickey */
- size_t key_len = strlen(c->publickey);
- git__memzero(c->publickey, key_len);
- git__free(c->publickey);
- }
-
- git__free(c);
-}
-
-static void default_free(struct git_cred *cred)
-{
- git_cred_default *c = (git_cred_default *)cred;
-
- git__free(c);
-}
-
-static void username_free(struct git_cred *cred)
-{
- git__free(cred);
-}
-
-int git_cred_ssh_key_new(
- git_cred **cred,
- const char *username,
- const char *publickey,
- const char *privatekey,
- const char *passphrase)
-{
- return git_cred_ssh_key_type_new(
- cred,
- username,
- publickey,
- privatekey,
- passphrase,
- GIT_CREDTYPE_SSH_KEY);
-}
-
-int git_cred_ssh_key_memory_new(
- git_cred **cred,
- const char *username,
- const char *publickey,
- const char *privatekey,
- const char *passphrase)
-{
-#ifdef GIT_SSH_MEMORY_CREDENTIALS
- return git_cred_ssh_key_type_new(
- cred,
- username,
- publickey,
- privatekey,
- passphrase,
- GIT_CREDTYPE_SSH_MEMORY);
-#else
- GIT_UNUSED(cred);
- GIT_UNUSED(username);
- GIT_UNUSED(publickey);
- GIT_UNUSED(privatekey);
- GIT_UNUSED(passphrase);
-
- git_error_set(GIT_ERROR_INVALID,
- "this version of libgit2 was not built with ssh memory credentials.");
- return -1;
-#endif
-}
-
-static int git_cred_ssh_key_type_new(
- git_cred **cred,
- const char *username,
- const char *publickey,
- const char *privatekey,
- const char *passphrase,
- git_credtype_t credtype)
-{
- git_cred_ssh_key *c;
-
- assert(username && cred && privatekey);
-
- c = git__calloc(1, sizeof(git_cred_ssh_key));
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->parent.credtype = credtype;
- c->parent.free = ssh_key_free;
-
- c->username = git__strdup(username);
- GIT_ERROR_CHECK_ALLOC(c->username);
-
- c->privatekey = git__strdup(privatekey);
- GIT_ERROR_CHECK_ALLOC(c->privatekey);
-
- if (publickey) {
- c->publickey = git__strdup(publickey);
- GIT_ERROR_CHECK_ALLOC(c->publickey);
- }
-
- if (passphrase) {
- c->passphrase = git__strdup(passphrase);
- GIT_ERROR_CHECK_ALLOC(c->passphrase);
- }
-
- *cred = &c->parent;
- return 0;
-}
-
-int git_cred_ssh_interactive_new(
- git_cred **out,
- const char *username,
- git_cred_ssh_interactive_cb prompt_callback,
- void *payload)
-{
- git_cred_ssh_interactive *c;
-
- assert(out && username && prompt_callback);
-
- c = git__calloc(1, sizeof(git_cred_ssh_interactive));
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->parent.credtype = GIT_CREDTYPE_SSH_INTERACTIVE;
- c->parent.free = ssh_interactive_free;
-
- c->username = git__strdup(username);
- GIT_ERROR_CHECK_ALLOC(c->username);
-
- c->prompt_callback = prompt_callback;
- c->payload = payload;
-
- *out = &c->parent;
- return 0;
-}
-
-int git_cred_ssh_key_from_agent(git_cred **cred, const char *username) {
- git_cred_ssh_key *c;
-
- assert(username && cred);
-
- c = git__calloc(1, sizeof(git_cred_ssh_key));
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->parent.credtype = GIT_CREDTYPE_SSH_KEY;
- c->parent.free = ssh_key_free;
-
- c->username = git__strdup(username);
- GIT_ERROR_CHECK_ALLOC(c->username);
-
- c->privatekey = NULL;
-
- *cred = &c->parent;
- return 0;
-}
-
-int git_cred_ssh_custom_new(
- git_cred **cred,
- const char *username,
- const char *publickey,
- size_t publickey_len,
- git_cred_sign_cb sign_callback,
- void *payload)
-{
- git_cred_ssh_custom *c;
-
- assert(username && cred);
-
- c = git__calloc(1, sizeof(git_cred_ssh_custom));
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->parent.credtype = GIT_CREDTYPE_SSH_CUSTOM;
- c->parent.free = ssh_custom_free;
-
- c->username = git__strdup(username);
- GIT_ERROR_CHECK_ALLOC(c->username);
-
- if (publickey_len > 0) {
- c->publickey = git__malloc(publickey_len);
- GIT_ERROR_CHECK_ALLOC(c->publickey);
-
- memcpy(c->publickey, publickey, publickey_len);
- }
-
- c->publickey_len = publickey_len;
- c->sign_callback = sign_callback;
- c->payload = payload;
-
- *cred = &c->parent;
- return 0;
-}
-
-int git_cred_default_new(git_cred **cred)
-{
- git_cred_default *c;
-
- assert(cred);
-
- c = git__calloc(1, sizeof(git_cred_default));
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->credtype = GIT_CREDTYPE_DEFAULT;
- c->free = default_free;
-
- *cred = c;
- return 0;
-}
-
-int git_cred_username_new(git_cred **cred, const char *username)
-{
- git_cred_username *c;
- size_t len, allocsize;
-
- assert(cred);
-
- len = strlen(username);
-
- GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_cred_username), len);
- GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1);
- c = git__malloc(allocsize);
- GIT_ERROR_CHECK_ALLOC(c);
-
- c->parent.credtype = GIT_CREDTYPE_USERNAME;
- c->parent.free = username_free;
- memcpy(c->username, username, len + 1);
-
- *cred = (git_cred *) c;
- return 0;
-}
-
-void git_cred_free(git_cred *cred)
-{
- if (!cred)
- return;
-
- cred->free(cred);
-}
diff --git a/src/transports/credential.c b/src/transports/credential.c
new file mode 100644
index 000000000..0cf50a029
--- /dev/null
+++ b/src/transports/credential.c
@@ -0,0 +1,476 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "common.h"
+
+#include "git2/credential.h"
+#include "git2/sys/credential.h"
+#include "git2/credential_helpers.h"
+
+static int git_credential_ssh_key_type_new(
+ git_credential **cred,
+ const char *username,
+ const char *publickey,
+ const char *privatekey,
+ const char *passphrase,
+ git_credential_t credtype);
+
+int git_credential_has_username(git_credential *cred)
+{
+ if (cred->credtype == GIT_CREDENTIAL_DEFAULT)
+ return 0;
+
+ return 1;
+}
+
+const char *git_credential_get_username(git_credential *cred)
+{
+ switch (cred->credtype) {
+ case GIT_CREDENTIAL_USERNAME:
+ {
+ git_credential_username *c = (git_credential_username *) cred;
+ return c->username;
+ }
+ case GIT_CREDENTIAL_USERPASS_PLAINTEXT:
+ {
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *) cred;
+ return c->username;
+ }
+ case GIT_CREDENTIAL_SSH_KEY:
+ case GIT_CREDENTIAL_SSH_MEMORY:
+ {
+ git_credential_ssh_key *c = (git_credential_ssh_key *) cred;
+ return c->username;
+ }
+ case GIT_CREDENTIAL_SSH_CUSTOM:
+ {
+ git_credential_ssh_custom *c = (git_credential_ssh_custom *) cred;
+ return c->username;
+ }
+ case GIT_CREDENTIAL_SSH_INTERACTIVE:
+ {
+ git_credential_ssh_interactive *c = (git_credential_ssh_interactive *) cred;
+ return c->username;
+ }
+
+ default:
+ return NULL;
+ }
+}
+
+static void plaintext_free(struct git_credential *cred)
+{
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
+
+ git__free(c->username);
+
+ /* Zero the memory which previously held the password */
+ if (c->password) {
+ size_t pass_len = strlen(c->password);
+ git__memzero(c->password, pass_len);
+ git__free(c->password);
+ }
+
+ git__free(c);
+}
+
+int git_credential_userpass_plaintext_new(
+ git_credential **cred,
+ const char *username,
+ const char *password)
+{
+ git_credential_userpass_plaintext *c;
+
+ assert(cred && username && password);
+
+ c = git__malloc(sizeof(git_credential_userpass_plaintext));
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->parent.credtype = GIT_CREDENTIAL_USERPASS_PLAINTEXT;
+ c->parent.free = plaintext_free;
+ c->username = git__strdup(username);
+
+ if (!c->username) {
+ git__free(c);
+ return -1;
+ }
+
+ c->password = git__strdup(password);
+
+ if (!c->password) {
+ git__free(c->username);
+ git__free(c);
+ return -1;
+ }
+
+ *cred = &c->parent;
+ return 0;
+}
+
+static void ssh_key_free(struct git_credential *cred)
+{
+ git_credential_ssh_key *c =
+ (git_credential_ssh_key *)cred;
+
+ git__free(c->username);
+
+ if (c->privatekey) {
+ /* Zero the memory which previously held the private key */
+ size_t key_len = strlen(c->privatekey);
+ git__memzero(c->privatekey, key_len);
+ git__free(c->privatekey);
+ }
+
+ if (c->passphrase) {
+ /* Zero the memory which previously held the passphrase */
+ size_t pass_len = strlen(c->passphrase);
+ git__memzero(c->passphrase, pass_len);
+ git__free(c->passphrase);
+ }
+
+ if (c->publickey) {
+ /* Zero the memory which previously held the public key */
+ size_t key_len = strlen(c->publickey);
+ git__memzero(c->publickey, key_len);
+ git__free(c->publickey);
+ }
+
+ git__free(c);
+}
+
+static void ssh_interactive_free(struct git_credential *cred)
+{
+ git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred;
+
+ git__free(c->username);
+
+ git__free(c);
+}
+
+static void ssh_custom_free(struct git_credential *cred)
+{
+ git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred;
+
+ git__free(c->username);
+
+ if (c->publickey) {
+ /* Zero the memory which previously held the publickey */
+ size_t key_len = strlen(c->publickey);
+ git__memzero(c->publickey, key_len);
+ git__free(c->publickey);
+ }
+
+ git__free(c);
+}
+
+static void default_free(struct git_credential *cred)
+{
+ git_credential_default *c = (git_credential_default *)cred;
+
+ git__free(c);
+}
+
+static void username_free(struct git_credential *cred)
+{
+ git__free(cred);
+}
+
+int git_credential_ssh_key_new(
+ git_credential **cred,
+ const char *username,
+ const char *publickey,
+ const char *privatekey,
+ const char *passphrase)
+{
+ return git_credential_ssh_key_type_new(
+ cred,
+ username,
+ publickey,
+ privatekey,
+ passphrase,
+ GIT_CREDENTIAL_SSH_KEY);
+}
+
+int git_credential_ssh_key_memory_new(
+ git_credential **cred,
+ const char *username,
+ const char *publickey,
+ const char *privatekey,
+ const char *passphrase)
+{
+#ifdef GIT_SSH_MEMORY_CREDENTIALS
+ return git_credential_ssh_key_type_new(
+ cred,
+ username,
+ publickey,
+ privatekey,
+ passphrase,
+ GIT_CREDENTIAL_SSH_MEMORY);
+#else
+ GIT_UNUSED(cred);
+ GIT_UNUSED(username);
+ GIT_UNUSED(publickey);
+ GIT_UNUSED(privatekey);
+ GIT_UNUSED(passphrase);
+
+ git_error_set(GIT_ERROR_INVALID,
+ "this version of libgit2 was not built with ssh memory credentials.");
+ return -1;
+#endif
+}
+
+static int git_credential_ssh_key_type_new(
+ git_credential **cred,
+ const char *username,
+ const char *publickey,
+ const char *privatekey,
+ const char *passphrase,
+ git_credential_t credtype)
+{
+ git_credential_ssh_key *c;
+
+ assert(username && cred && privatekey);
+
+ c = git__calloc(1, sizeof(git_credential_ssh_key));
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->parent.credtype = credtype;
+ c->parent.free = ssh_key_free;
+
+ c->username = git__strdup(username);
+ GIT_ERROR_CHECK_ALLOC(c->username);
+
+ c->privatekey = git__strdup(privatekey);
+ GIT_ERROR_CHECK_ALLOC(c->privatekey);
+
+ if (publickey) {
+ c->publickey = git__strdup(publickey);
+ GIT_ERROR_CHECK_ALLOC(c->publickey);
+ }
+
+ if (passphrase) {
+ c->passphrase = git__strdup(passphrase);
+ GIT_ERROR_CHECK_ALLOC(c->passphrase);
+ }
+
+ *cred = &c->parent;
+ return 0;
+}
+
+int git_credential_ssh_interactive_new(
+ git_credential **out,
+ const char *username,
+ git_credential_ssh_interactive_cb prompt_callback,
+ void *payload)
+{
+ git_credential_ssh_interactive *c;
+
+ assert(out && username && prompt_callback);
+
+ c = git__calloc(1, sizeof(git_credential_ssh_interactive));
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->parent.credtype = GIT_CREDENTIAL_SSH_INTERACTIVE;
+ c->parent.free = ssh_interactive_free;
+
+ c->username = git__strdup(username);
+ GIT_ERROR_CHECK_ALLOC(c->username);
+
+ c->prompt_callback = prompt_callback;
+ c->payload = payload;
+
+ *out = &c->parent;
+ return 0;
+}
+
+int git_credential_ssh_key_from_agent(git_credential **cred, const char *username) {
+ git_credential_ssh_key *c;
+
+ assert(username && cred);
+
+ c = git__calloc(1, sizeof(git_credential_ssh_key));
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->parent.credtype = GIT_CREDENTIAL_SSH_KEY;
+ c->parent.free = ssh_key_free;
+
+ c->username = git__strdup(username);
+ GIT_ERROR_CHECK_ALLOC(c->username);
+
+ c->privatekey = NULL;
+
+ *cred = &c->parent;
+ return 0;
+}
+
+int git_credential_ssh_custom_new(
+ git_credential **cred,
+ const char *username,
+ const char *publickey,
+ size_t publickey_len,
+ git_credential_sign_cb sign_callback,
+ void *payload)
+{
+ git_credential_ssh_custom *c;
+
+ assert(username && cred);
+
+ c = git__calloc(1, sizeof(git_credential_ssh_custom));
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->parent.credtype = GIT_CREDENTIAL_SSH_CUSTOM;
+ c->parent.free = ssh_custom_free;
+
+ c->username = git__strdup(username);
+ GIT_ERROR_CHECK_ALLOC(c->username);
+
+ if (publickey_len > 0) {
+ c->publickey = git__malloc(publickey_len);
+ GIT_ERROR_CHECK_ALLOC(c->publickey);
+
+ memcpy(c->publickey, publickey, publickey_len);
+ }
+
+ c->publickey_len = publickey_len;
+ c->sign_callback = sign_callback;
+ c->payload = payload;
+
+ *cred = &c->parent;
+ return 0;
+}
+
+int git_credential_default_new(git_credential **cred)
+{
+ git_credential_default *c;
+
+ assert(cred);
+
+ c = git__calloc(1, sizeof(git_credential_default));
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->credtype = GIT_CREDENTIAL_DEFAULT;
+ c->free = default_free;
+
+ *cred = c;
+ return 0;
+}
+
+int git_credential_username_new(git_credential **cred, const char *username)
+{
+ git_credential_username *c;
+ size_t len, allocsize;
+
+ assert(cred);
+
+ len = strlen(username);
+
+ GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_credential_username), len);
+ GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1);
+ c = git__malloc(allocsize);
+ GIT_ERROR_CHECK_ALLOC(c);
+
+ c->parent.credtype = GIT_CREDENTIAL_USERNAME;
+ c->parent.free = username_free;
+ memcpy(c->username, username, len + 1);
+
+ *cred = (git_credential *) c;
+ return 0;
+}
+
+void git_credential_free(git_credential *cred)
+{
+ if (!cred)
+ return;
+
+ cred->free(cred);
+}
+
+/* Deprecated credential functions */
+
+int git_cred_has_username(git_credential *cred)
+{
+ return git_credential_has_username(cred);
+}
+
+const char *git_cred_get_username(git_credential *cred)
+{
+ return git_credential_get_username(cred);
+}
+
+int git_cred_userpass_plaintext_new(
+ git_credential **out,
+ const char *username,
+ const char *password)
+{
+ return git_credential_userpass_plaintext_new(out,username, password);
+}
+
+int git_cred_default_new(git_credential **out)
+{
+ return git_credential_default_new(out);
+}
+
+int git_cred_username_new(git_credential **out, const char *username)
+{
+ return git_credential_username_new(out, username);
+}
+
+int git_cred_ssh_key_new(
+ git_credential **out,
+ const char *username,
+ const char *publickey,
+ const char *privatekey,
+ const char *passphrase)
+{
+ return git_credential_ssh_key_new(out, username,
+ publickey, privatekey, passphrase);
+}
+
+int git_cred_ssh_key_memory_new(
+ git_credential **out,
+ const char *username,
+ const char *publickey,
+ const char *privatekey,
+ const char *passphrase)
+{
+ return git_credential_ssh_key_memory_new(out, username,
+ publickey, privatekey, passphrase);
+}
+
+int git_cred_ssh_interactive_new(
+ git_credential **out,
+ const char *username,
+ git_credential_ssh_interactive_cb prompt_callback,
+ void *payload)
+{
+ return git_credential_ssh_interactive_new(out, username,
+ prompt_callback, payload);
+}
+
+int git_cred_ssh_key_from_agent(
+ git_credential **out,
+ const char *username)
+{
+ return git_credential_ssh_key_from_agent(out, username);
+}
+
+int git_cred_ssh_custom_new(
+ git_credential **out,
+ const char *username,
+ const char *publickey,
+ size_t publickey_len,
+ git_credential_sign_cb sign_callback,
+ void *payload)
+{
+ return git_credential_ssh_custom_new(out, username,
+ publickey, publickey_len, sign_callback, payload);
+}
+
+void git_cred_free(git_credential *cred)
+{
+ git_credential_free(cred);
+}
diff --git a/src/transports/cred_helpers.c b/src/transports/credential_helpers.c
index fdc56b17e..6b975e126 100644
--- a/src/transports/cred_helpers.c
+++ b/src/transports/credential_helpers.c
@@ -7,16 +7,16 @@
#include "common.h"
-#include "git2/cred_helpers.h"
+#include "git2/credential_helpers.h"
-int git_cred_userpass(
- git_cred **cred,
+int git_credential_userpass(
+ git_credential **cred,
const char *url,
const char *user_from_url,
unsigned int allowed_types,
void *payload)
{
- git_cred_userpass_payload *userpass = (git_cred_userpass_payload*)payload;
+ git_credential_userpass_payload *userpass = (git_credential_userpass_payload*)payload;
const char *effective_username = NULL;
GIT_UNUSED(url);
@@ -42,12 +42,25 @@ int git_cred_userpass(
else
return -1;
- if (GIT_CREDTYPE_USERNAME & allowed_types)
- return git_cred_username_new(cred, effective_username);
+ if (GIT_CREDENTIAL_USERNAME & allowed_types)
+ return git_credential_username_new(cred, effective_username);
- if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
- git_cred_userpass_plaintext_new(cred, effective_username, userpass->password) < 0)
+ if ((GIT_CREDENTIAL_USERPASS_PLAINTEXT & allowed_types) == 0 ||
+ git_credential_userpass_plaintext_new(cred, effective_username, userpass->password) < 0)
return -1;
return 0;
}
+
+/* Deprecated credential functions */
+
+int git_cred_userpass(
+ git_credential **out,
+ const char *url,
+ const char *user_from_url,
+ unsigned int allowed_types,
+ void *payload)
+{
+ return git_credential_userpass(out, url, user_from_url,
+ allowed_types, payload);
+}
diff --git a/src/transports/http.c b/src/transports/http.c
index 36f038ead..294bab5dc 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -16,7 +16,7 @@
#include "netops.h"
#include "global.h"
#include "remote.h"
-#include "git2/sys/cred.h"
+#include "git2/sys/credential.h"
#include "smart.h"
#include "auth.h"
#include "http.h"
@@ -54,7 +54,7 @@ typedef struct {
typedef struct {
git_net_url url;
- git_cred *cred;
+ git_credential *cred;
unsigned auth_schemetypes;
unsigned url_cred_presented : 1;
} http_server;
@@ -100,24 +100,24 @@ static const http_service receive_pack_service = {
#define OWNING_SUBTRANSPORT(s) ((http_subtransport *)(s)->parent.subtransport)
static int apply_url_credentials(
- git_cred **cred,
+ git_credential **cred,
unsigned int allowed_types,
const char *username,
const char *password)
{
- if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT)
- return git_cred_userpass_plaintext_new(cred, username, password);
+ if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT)
+ return git_credential_userpass_plaintext_new(cred, username, password);
- if ((allowed_types & GIT_CREDTYPE_DEFAULT) && *username == '\0' && *password == '\0')
- return git_cred_default_new(cred);
+ if ((allowed_types & GIT_CREDENTIAL_DEFAULT) && *username == '\0' && *password == '\0')
+ return git_credential_default_new(cred);
return GIT_PASSTHROUGH;
}
-GIT_INLINE(void) free_cred(git_cred **cred)
+GIT_INLINE(void) free_cred(git_credential **cred)
{
if (*cred) {
- git_cred_free(*cred);
+ git_credential_free(*cred);
(*cred) = NULL;
}
}
@@ -128,7 +128,7 @@ static int handle_auth(
const char *url,
unsigned int allowed_schemetypes,
unsigned int allowed_credtypes,
- git_cred_acquire_cb callback,
+ git_credential_acquire_cb callback,
void *callback_payload)
{
int error = 1;
@@ -137,7 +137,7 @@ static int handle_auth(
free_cred(&server->cred);
/* Start with URL-specified credentials, if there were any. */
- if ((allowed_credtypes & GIT_CREDTYPE_USERPASS_PLAINTEXT) &&
+ if ((allowed_credtypes & GIT_CREDENTIAL_USERPASS_PLAINTEXT) &&
!server->url_cred_presented &&
server->url.username &&
server->url.password) {
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index 7f44a26dc..f5c2ce58d 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -16,7 +16,7 @@
#include "auth.h"
#include "auth_negotiate.h"
#include "auth_ntlm.h"
-#include "git2/sys/cred.h"
+#include "git2/sys/credential.h"
#include "net.h"
#include "stream.h"
#include "streams/socket.h"
@@ -24,9 +24,9 @@
#include "auth.h"
static git_http_auth_scheme auth_schemes[] = {
- { GIT_HTTP_AUTH_NEGOTIATE, "Negotiate", GIT_CREDTYPE_DEFAULT, git_http_auth_negotiate },
- { GIT_HTTP_AUTH_NTLM, "NTLM", GIT_CREDTYPE_USERPASS_PLAINTEXT, git_http_auth_ntlm },
- { GIT_HTTP_AUTH_BASIC, "Basic", GIT_CREDTYPE_USERPASS_PLAINTEXT, git_http_auth_basic },
+ { GIT_HTTP_AUTH_NEGOTIATE, "Negotiate", GIT_CREDENTIAL_DEFAULT, git_http_auth_negotiate },
+ { GIT_HTTP_AUTH_NTLM, "NTLM", GIT_CREDENTIAL_USERPASS_PLAINTEXT, git_http_auth_ntlm },
+ { GIT_HTTP_AUTH_BASIC, "Basic", GIT_CREDENTIAL_USERPASS_PLAINTEXT, git_http_auth_basic },
};
#define GIT_READ_BUFFER_SIZE 8192
@@ -456,7 +456,7 @@ static bool best_scheme_and_challenge(
git_http_auth_scheme **scheme_out,
const char **challenge_out,
git_vector *challenges,
- git_cred *credentials)
+ git_credential *credentials)
{
const char *challenge;
size_t i, j;
@@ -504,7 +504,7 @@ static const char *challenge_for_context(
static const char *init_auth_context(
git_http_server *server,
git_vector *challenges,
- git_cred *credentials)
+ git_credential *credentials)
{
git_http_auth_scheme *scheme;
const char *challenge;
@@ -540,7 +540,7 @@ static int apply_credentials(
git_buf *buf,
git_http_server *server,
const char *header_name,
- git_cred *credentials)
+ git_credential *credentials)
{
git_http_auth_context *auth = server->auth_context;
git_vector *challenges = &server->auth_challenges;
diff --git a/src/transports/httpclient.h b/src/transports/httpclient.h
index da764fd28..2a83bee3e 100644
--- a/src/transports/httpclient.h
+++ b/src/transports/httpclient.h
@@ -32,21 +32,21 @@ typedef enum {
/** An HTTP request */
typedef struct {
- git_http_method method; /**< Method for the request */
- git_net_url *url; /**< Full request URL */
- git_net_url *proxy; /**< Proxy to use */
+ git_http_method method; /**< Method for the request */
+ git_net_url *url; /**< Full request URL */
+ git_net_url *proxy; /**< Proxy to use */
/* Headers */
- const char *accept; /**< Contents of the Accept header */
- const char *content_type; /**< Content-Type header (for POST) */
- git_cred *credentials; /**< Credentials to authenticate with */
- git_cred *proxy_credentials; /**< Credentials for proxy */
- git_strarray *custom_headers; /**< Additional headers to deliver */
+ const char *accept; /**< Contents of the Accept header */
+ const char *content_type; /**< Content-Type header (for POST) */
+ git_credential *credentials; /**< Credentials to authenticate with */
+ git_credential *proxy_credentials; /**< Credentials for proxy */
+ git_strarray *custom_headers; /**< Additional headers to deliver */
/* To POST a payload, either set content_length OR set chunked. */
- size_t content_length; /**< Length of the POST body */
- unsigned chunked : 1, /**< Post with chunking */
- expect_continue : 1; /**< Use expect/continue negotiation */
+ size_t content_length; /**< Length of the POST body */
+ unsigned chunked : 1, /**< Post with chunking */
+ expect_continue : 1; /**< Use expect/continue negotiation */
} git_http_request;
typedef struct {
diff --git a/src/transports/local.c b/src/transports/local.c
index cfc6c2a57..24af7f063 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -201,7 +201,7 @@ on_error:
static int local_connect(
git_transport *transport,
const char *url,
- git_cred_acquire_cb cred_acquire_cb,
+ git_credential_acquire_cb cred_acquire_cb,
void *cred_acquire_payload,
const git_proxy_options *proxy,
int direction, int flags)
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 8e8af00c3..bb4d2a228 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -206,7 +206,7 @@ static void free_symrefs(git_vector *symrefs)
static int git_smart__connect(
git_transport *transport,
const char *url,
- git_cred_acquire_cb cred_acquire_cb,
+ git_credential_acquire_cb cred_acquire_cb,
void *cred_acquire_payload,
const git_proxy_options *proxy,
int direction,
@@ -489,7 +489,7 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce
return t->certificate_check_cb(cert, valid, hostname, t->message_cb_payload);
}
-int git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods)
+int git_transport_smart_credentials(git_credential **out, git_transport *transport, const char *user, int methods)
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 53e9773e1..18e0b7e9f 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -137,7 +137,7 @@ typedef struct {
git_transport parent;
git_remote *owner;
char *url;
- git_cred_acquire_cb cred_acquire_cb;
+ git_credential_acquire_cb cred_acquire_cb;
void *cred_acquire_payload;
git_proxy_options proxy;
int direction;
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 18d90a964..68b3cbeda 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -19,8 +19,8 @@
#include "smart.h"
#include "streams/socket.h"
-#include "git2/cred.h"
-#include "git2/sys/cred.h"
+#include "git2/credential.h"
+#include "git2/sys/credential.h"
#ifdef GIT_SSH
@@ -45,7 +45,7 @@ typedef struct {
git_smart_subtransport parent;
transport_smart *owner;
ssh_stream *current_stream;
- git_cred *cred;
+ git_credential *cred;
char *cmd_uploadpack;
char *cmd_receivepack;
} ssh_subtransport;
@@ -291,7 +291,7 @@ static int git_ssh_extract_url_parts(
return 0;
}
-static int ssh_agent_auth(LIBSSH2_SESSION *session, git_cred_ssh_key *c) {
+static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) {
int rc = LIBSSH2_ERROR_NONE;
struct libssh2_agent_publickey *curr, *prev = NULL;
@@ -346,21 +346,21 @@ shutdown:
}
static int _git_ssh_authenticate_session(
- LIBSSH2_SESSION* session,
- git_cred* cred)
+ LIBSSH2_SESSION *session,
+ git_credential *cred)
{
int rc;
do {
git_error_clear();
switch (cred->credtype) {
- case GIT_CREDTYPE_USERPASS_PLAINTEXT: {
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
+ case GIT_CREDENTIAL_USERPASS_PLAINTEXT: {
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
rc = libssh2_userauth_password(session, c->username, c->password);
break;
}
- case GIT_CREDTYPE_SSH_KEY: {
- git_cred_ssh_key *c = (git_cred_ssh_key *)cred;
+ case GIT_CREDENTIAL_SSH_KEY: {
+ git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
if (c->privatekey)
rc = libssh2_userauth_publickey_fromfile(
@@ -371,17 +371,17 @@ static int _git_ssh_authenticate_session(
break;
}
- case GIT_CREDTYPE_SSH_CUSTOM: {
- git_cred_ssh_custom *c = (git_cred_ssh_custom *)cred;
+ case GIT_CREDENTIAL_SSH_CUSTOM: {
+ git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred;
rc = libssh2_userauth_publickey(
session, c->username, (const unsigned char *)c->publickey,
c->publickey_len, c->sign_callback, &c->payload);
break;
}
- case GIT_CREDTYPE_SSH_INTERACTIVE: {
+ case GIT_CREDENTIAL_SSH_INTERACTIVE: {
void **abstract = libssh2_session_abstract(session);
- git_cred_ssh_interactive *c = (git_cred_ssh_interactive *)cred;
+ git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred;
/* ideally, we should be able to set this by calling
* libssh2_session_init_ex() instead of libssh2_session_init().
@@ -401,8 +401,8 @@ static int _git_ssh_authenticate_session(
break;
}
#ifdef GIT_SSH_MEMORY_CREDENTIALS
- case GIT_CREDTYPE_SSH_MEMORY: {
- git_cred_ssh_key *c = (git_cred_ssh_key *)cred;
+ case GIT_CREDENTIAL_SSH_MEMORY: {
+ git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
assert(c->username);
assert(c->privatekey);
@@ -438,10 +438,10 @@ static int _git_ssh_authenticate_session(
return 0;
}
-static int request_creds(git_cred **out, ssh_subtransport *t, const char *user, int auth_methods)
+static int request_creds(git_credential **out, ssh_subtransport *t, const char *user, int auth_methods)
{
int error, no_callback = 0;
- git_cred *cred = NULL;
+ git_credential *cred = NULL;
if (!t->owner->cred_acquire_cb) {
no_callback = 1;
@@ -520,7 +520,7 @@ static int _git_ssh_setup_conn(
int auth_methods, error = 0;
size_t i;
ssh_stream *s;
- git_cred *cred = NULL;
+ git_credential *cred = NULL;
LIBSSH2_SESSION* session=NULL;
LIBSSH2_CHANNEL* channel=NULL;
@@ -609,16 +609,16 @@ post_extract:
/* we need the username to ask for auth methods */
if (!urldata.username) {
- if ((error = request_creds(&cred, t, NULL, GIT_CREDTYPE_USERNAME)) < 0)
+ if ((error = request_creds(&cred, t, NULL, GIT_CREDENTIAL_USERNAME)) < 0)
goto done;
- urldata.username = git__strdup(((git_cred_username *) cred)->username);
+ urldata.username = git__strdup(((git_credential_username *) cred)->username);
cred->free(cred);
cred = NULL;
if (!urldata.username)
goto done;
} else if (urldata.username && urldata.password) {
- if ((error = git_cred_userpass_plaintext_new(&cred, urldata.username, urldata.password)) < 0)
+ if ((error = git_credential_userpass_plaintext_new(&cred, urldata.username, urldata.password)) < 0)
goto done;
}
@@ -639,7 +639,7 @@ post_extract:
if ((error = request_creds(&cred, t, urldata.username, auth_methods)) < 0)
goto done;
- if (strcmp(urldata.username, git_cred_get_username(cred))) {
+ if (strcmp(urldata.username, git_credential_get_username(cred))) {
git_error_set(GIT_ERROR_SSH, "username does not match previous request");
error = -1;
goto done;
@@ -814,23 +814,23 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
ptr++;
if (!git__prefixcmp(ptr, SSH_AUTH_PUBLICKEY)) {
- *out |= GIT_CREDTYPE_SSH_KEY;
- *out |= GIT_CREDTYPE_SSH_CUSTOM;
+ *out |= GIT_CREDENTIAL_SSH_KEY;
+ *out |= GIT_CREDENTIAL_SSH_CUSTOM;
#ifdef GIT_SSH_MEMORY_CREDENTIALS
- *out |= GIT_CREDTYPE_SSH_MEMORY;
+ *out |= GIT_CREDENTIAL_SSH_MEMORY;
#endif
ptr += strlen(SSH_AUTH_PUBLICKEY);
continue;
}
if (!git__prefixcmp(ptr, SSH_AUTH_PASSWORD)) {
- *out |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
+ *out |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
ptr += strlen(SSH_AUTH_PASSWORD);
continue;
}
if (!git__prefixcmp(ptr, SSH_AUTH_KEYBOARD_INTERACTIVE)) {
- *out |= GIT_CREDTYPE_SSH_INTERACTIVE;
+ *out |= GIT_CREDENTIAL_SSH_INTERACTIVE;
ptr += strlen(SSH_AUTH_KEYBOARD_INTERACTIVE);
continue;
}
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index e9e53ae86..ee8cb1543 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -19,7 +19,7 @@
#include "repository.h"
#include "global.h"
#include "http.h"
-#include "git2/sys/cred.h"
+#include "git2/sys/credential.h"
#include <wincrypt.h>
#include <winhttp.h>
@@ -113,7 +113,7 @@ typedef struct {
typedef struct {
git_net_url url;
- git_cred *cred;
+ git_credential *cred;
int auth_mechanisms;
bool url_cred_presented;
} winhttp_server;
@@ -129,9 +129,9 @@ typedef struct {
HINTERNET connection;
} winhttp_subtransport;
-static int apply_userpass_credentials(HINTERNET request, DWORD target, int mechanisms, git_cred *cred)
+static int apply_userpass_credentials(HINTERNET request, DWORD target, int mechanisms, git_credential *cred)
{
- git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
+ git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred;
wchar_t *user = NULL, *pass = NULL;
int user_len = 0, pass_len = 0, error = 0;
DWORD native_scheme;
@@ -206,22 +206,22 @@ static int apply_default_credentials(HINTERNET request, DWORD target, int mechan
}
static int acquire_url_cred(
- git_cred **cred,
+ git_credential **cred,
unsigned int allowed_types,
const char *username,
const char *password)
{
- if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT)
- return git_cred_userpass_plaintext_new(cred, username, password);
+ if (allowed_types & GIT_CREDENTIAL_USERPASS_PLAINTEXT)
+ return git_credential_userpass_plaintext_new(cred, username, password);
- if ((allowed_types & GIT_CREDTYPE_DEFAULT) && *username == '\0' && *password == '\0')
- return git_cred_default_new(cred);
+ if ((allowed_types & GIT_CREDENTIAL_DEFAULT) && *username == '\0' && *password == '\0')
+ return git_credential_default_new(cred);
return 1;
}
static int acquire_fallback_cred(
- git_cred **cred,
+ git_credential **cred,
const char *url,
unsigned int allowed_types)
{
@@ -229,7 +229,7 @@ static int acquire_fallback_cred(
/* If the target URI supports integrated Windows authentication
* as an authentication mechanism */
- if (GIT_CREDTYPE_DEFAULT & allowed_types) {
+ if (GIT_CREDENTIAL_DEFAULT & allowed_types) {
wchar_t *wide_url;
HRESULT hCoInitResult;
@@ -253,13 +253,13 @@ static int acquire_fallback_cred(
(URLZONE_LOCAL_MACHINE == dwZone ||
URLZONE_INTRANET == dwZone ||
URLZONE_TRUSTED == dwZone)) {
- git_cred *existing = *cred;
+ git_credential *existing = *cred;
if (existing)
existing->free(existing);
/* Then use default Windows credentials to authenticate this request */
- error = git_cred_default_new(cred);
+ error = git_credential_default_new(cred);
}
pISM->lpVtbl->Release(pISM);
@@ -345,7 +345,7 @@ static int apply_credentials(
HINTERNET request,
git_net_url *url,
int target,
- git_cred *creds,
+ git_credential *creds,
int mechanisms)
{
int error = 0;
@@ -353,9 +353,9 @@ static int apply_credentials(
GIT_UNUSED(url);
/* If we have creds, just apply them */
- if (creds && creds->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT)
+ if (creds && creds->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT)
error = apply_userpass_credentials(request, target, mechanisms, creds);
- else if (creds && creds->credtype == GIT_CREDTYPE_DEFAULT)
+ else if (creds && creds->credtype == GIT_CREDENTIAL_DEFAULT)
error = apply_default_credentials(request, target, mechanisms);
return error;
@@ -606,23 +606,23 @@ static int parse_unauthorized_response(
}
if (WINHTTP_AUTH_SCHEME_NTLM & supported) {
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
- *allowed_types |= GIT_CREDTYPE_DEFAULT;
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
+ *allowed_types |= GIT_CREDENTIAL_DEFAULT;
*allowed_mechanisms |= GIT_WINHTTP_AUTH_NTLM;
}
if (WINHTTP_AUTH_SCHEME_NEGOTIATE & supported) {
- *allowed_types |= GIT_CREDTYPE_DEFAULT;
+ *allowed_types |= GIT_CREDENTIAL_DEFAULT;
*allowed_mechanisms |= GIT_WINHTTP_AUTH_NEGOTIATE;
}
if (WINHTTP_AUTH_SCHEME_BASIC & supported) {
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
*allowed_mechanisms |= GIT_WINHTTP_AUTH_BASIC;
}
if (WINHTTP_AUTH_SCHEME_DIGEST & supported) {
- *allowed_types |= GIT_CREDTYPE_USERPASS_PLAINTEXT;
+ *allowed_types |= GIT_CREDENTIAL_USERPASS_PLAINTEXT;
*allowed_mechanisms |= GIT_WINHTTP_AUTH_DIGEST;
}
@@ -907,7 +907,7 @@ static int acquire_credentials(
HINTERNET request,
winhttp_server *server,
const char *url_str,
- git_cred_acquire_cb cred_cb,
+ git_credential_acquire_cb cred_cb,
void *cred_cb_payload)
{
int allowed_types;
@@ -917,7 +917,7 @@ static int acquire_credentials(
return -1;
if (allowed_types) {
- git_cred_free(server->cred);
+ git_credential_free(server->cred);
server->cred = NULL;
/* Start with URL-specified credentials, if there were any. */
@@ -933,7 +933,7 @@ static int acquire_credentials(
if (error > 0 && cred_cb) {
error = cred_cb(&server->cred, url_str, server->url.username, allowed_types, cred_cb_payload);
- /* Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set */
+ /* Treat GIT_PASSTHROUGH as though git_credential_acquire_cb isn't set */
if (error == GIT_PASSTHROUGH)
error = 1;
else if (error < 0)