Commit 1c847169db1c68864c43e95cf96380cec71ba72a

Edward Thomson 2019-08-21T16:38:59

http: allow dummy negotiation scheme to fail to act The dummy negotiation scheme is used for known authentication strategies that do not wish to act. For example, when a server requests the "Negotiate" scheme but libgit2 is not built with Negotiate support, and will use the "dummy" strategy which will simply not act. Instead of setting `out` to NULL and returning a successful code, return `GIT_PASSTHROUGH` to indicate that it did not act and catch that error code.

diff --git a/src/transports/auth.c b/src/transports/auth.c
index 773e302..4fcf73c 100644
--- a/src/transports/auth.c
+++ b/src/transports/auth.c
@@ -70,6 +70,6 @@ int git_http_auth_dummy(
 	GIT_UNUSED(url);
 
 	*out = NULL;
-	return 0;
+	return GIT_PASSTHROUGH;
 }
 
diff --git a/src/transports/http.c b/src/transports/http.c
index d727851..7ec681c 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -430,6 +430,7 @@ static int init_auth(http_server *server)
 	git_http_auth_scheme *s, *scheme = NULL;
 	char *c, *challenge = NULL;
 	size_t i;
+	int error;
 
 	git_vector_foreach(&server->auth_challenges, i, c) {
 		s = scheme_for_challenge(c);
@@ -446,12 +447,14 @@ static int init_auth(http_server *server)
 		return -1;
 	}
 
-	if (scheme->init_context(&server->auth_context, &server->url) < 0)
-		return -1;
+	if ((error = scheme->init_context(&server->auth_context, &server->url)) == GIT_PASSTHROUGH)
+		return 0;
+	else if (error < 0)
+		return error;
 
 	if (server->auth_context->set_challenge &&
-		server->auth_context->set_challenge(server->auth_context, challenge) < 0)
-		return -1;
+		(error = server->auth_context->set_challenge(server->auth_context, challenge)) < 0)
+		return error;
 
 	return 0;
 }