Commit 10e8fe55 by Edward Thomson

transports: add an `is_complete` function for auth

Some authentication mechanisms (like HTTP Basic and Digest) have a
one-step mechanism to create credentials, but there are more complex
mechanisms like NTLM and Negotiate that require challenge/response after
negotiation, requiring several round-trips.  Add an `is_complete`
function to know when they have round-tripped enough to be a single
authentication and should now either have succeeded or failed to
authenticate.
parent 9050c69c
...@@ -52,6 +52,7 @@ static git_http_auth_context basic_context = { ...@@ -52,6 +52,7 @@ static git_http_auth_context basic_context = {
GIT_CREDTYPE_USERPASS_PLAINTEXT, GIT_CREDTYPE_USERPASS_PLAINTEXT,
NULL, NULL,
basic_next_token, basic_next_token,
NULL,
NULL NULL
}; };
......
...@@ -33,6 +33,9 @@ struct git_http_auth_context { ...@@ -33,6 +33,9 @@ struct git_http_auth_context {
/** Gets the next authentication token from the context */ /** Gets the next authentication token from the context */
int (*next_token)(git_buf *out, git_http_auth_context *ctx, const char *header_name, git_cred *cred); int (*next_token)(git_buf *out, git_http_auth_context *ctx, const char *header_name, git_cred *cred);
/** Examines if all tokens have been presented. */
int (*is_complete)(git_http_auth_context *ctx);
/** Frees the authentication context */ /** Frees the authentication context */
void (*free)(git_http_auth_context *ctx); void (*free)(git_http_auth_context *ctx);
}; };
......
...@@ -170,6 +170,15 @@ done: ...@@ -170,6 +170,15 @@ done:
return error; return error;
} }
static int negotiate_is_complete(git_http_auth_context *c)
{
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
assert(ctx);
return (ctx->complete == 1);
}
static void negotiate_context_free(git_http_auth_context *c) static void negotiate_context_free(git_http_auth_context *c)
{ {
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c; http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
...@@ -266,6 +275,7 @@ int git_http_auth_negotiate( ...@@ -266,6 +275,7 @@ int git_http_auth_negotiate(
ctx->parent.credtypes = GIT_CREDTYPE_DEFAULT; ctx->parent.credtypes = GIT_CREDTYPE_DEFAULT;
ctx->parent.set_challenge = negotiate_set_challenge; ctx->parent.set_challenge = negotiate_set_challenge;
ctx->parent.next_token = negotiate_next_token; ctx->parent.next_token = negotiate_next_token;
ctx->parent.is_complete = negotiate_is_complete;
ctx->parent.free = negotiate_context_free; ctx->parent.free = negotiate_context_free;
*out = (git_http_auth_context *)ctx; *out = (git_http_auth_context *)ctx;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment