diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2019-03-21 13:55:54 -1000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-06-10 19:58:22 +0100 |
commit | 10e8fe555e55d6b28b7e601acbc6d52159735069 (patch) | |
tree | 6a8ef2f57773adb4ef1d0451bf72183b1adfbf2d | |
parent | 9050c69c0ea4ee5dc8e55ff12736ecd2425c9dc0 (diff) | |
download | libgit2-10e8fe555e55d6b28b7e601acbc6d52159735069.tar.gz |
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.
-rw-r--r-- | src/transports/auth.c | 1 | ||||
-rw-r--r-- | src/transports/auth.h | 3 | ||||
-rw-r--r-- | src/transports/auth_negotiate.c | 10 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/transports/auth.c b/src/transports/auth.c index ea6cb6502..849a6ce3d 100644 --- a/src/transports/auth.c +++ b/src/transports/auth.c @@ -52,6 +52,7 @@ static git_http_auth_context basic_context = { GIT_CREDTYPE_USERPASS_PLAINTEXT, NULL, basic_next_token, + NULL, NULL }; diff --git a/src/transports/auth.h b/src/transports/auth.h index 7b64770d6..9ead5583f 100644 --- a/src/transports/auth.h +++ b/src/transports/auth.h @@ -33,6 +33,9 @@ struct git_http_auth_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); + /** Examines if all tokens have been presented. */ + int (*is_complete)(git_http_auth_context *ctx); + /** Frees the authentication context */ void (*free)(git_http_auth_context *ctx); }; diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c index 03d333626..d5c3d1666 100644 --- a/src/transports/auth_negotiate.c +++ b/src/transports/auth_negotiate.c @@ -170,6 +170,15 @@ done: 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) { http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c; @@ -266,6 +275,7 @@ int git_http_auth_negotiate( ctx->parent.credtypes = GIT_CREDTYPE_DEFAULT; ctx->parent.set_challenge = negotiate_set_challenge; ctx->parent.next_token = negotiate_next_token; + ctx->parent.is_complete = negotiate_is_complete; ctx->parent.free = negotiate_context_free; *out = (git_http_auth_context *)ctx; |