Commit 216165ec by Josh Bleecher Snyder

transports: use GIT_EAUTH for authentication failures

When the failure is clearly an auth failure
(as opposed to possibly an auth failure),
use the error code GIT_EAUTH instead of GIT_ERROR.

While we're here, fix a typo and improve an error message.

Fixes #5389.
parent d4d26e8d
...@@ -67,6 +67,7 @@ v0.28 + 1 ...@@ -67,6 +67,7 @@ v0.28 + 1
is now hidden, and a new `git_cred_get_username` function has been provided. is now hidden, and a new `git_cred_get_username` function has been provided.
* Some errors of class `GIT_ERROR_NET` now have class `GIT_ERROR_HTTP`. * Some errors of class `GIT_ERROR_NET` now have class `GIT_ERROR_HTTP`.
Most authentication failures now have error code `GIT_EAUTH` instead of `GIT_ERROR`.
### Breaking CMake configuration changes ### Breaking CMake configuration changes
......
...@@ -18,7 +18,7 @@ static int basic_next_token( ...@@ -18,7 +18,7 @@ static int basic_next_token(
{ {
git_credential_userpass_plaintext *cred; git_credential_userpass_plaintext *cred;
git_buf raw = GIT_BUF_INIT; git_buf raw = GIT_BUF_INIT;
int error = -1; int error = GIT_EAUTH;
GIT_UNUSED(ctx); GIT_UNUSED(ctx);
......
...@@ -260,7 +260,7 @@ static int negotiate_init_context( ...@@ -260,7 +260,7 @@ static int negotiate_init_context(
if (!ctx->oid) { if (!ctx->oid) {
git_error_set(GIT_ERROR_NET, "negotiate authentication is not supported"); git_error_set(GIT_ERROR_NET, "negotiate authentication is not supported");
return -1; return GIT_EAUTH;
} }
git_buf_puts(&ctx->target, "HTTP@"); git_buf_puts(&ctx->target, "HTTP@");
......
...@@ -84,7 +84,7 @@ static int ntlm_next_token( ...@@ -84,7 +84,7 @@ static int ntlm_next_token(
git_buf input_buf = GIT_BUF_INIT; git_buf input_buf = GIT_BUF_INIT;
const unsigned char *msg; const unsigned char *msg;
size_t challenge_len, msg_len; size_t challenge_len, msg_len;
int error = -1; int error = GIT_EAUTH;
assert(buf && ctx && ctx->ntlm); assert(buf && ctx && ctx->ntlm);
......
...@@ -159,7 +159,7 @@ static int handle_auth( ...@@ -159,7 +159,7 @@ static int handle_auth(
if (error > 0) { if (error > 0) {
git_error_set(GIT_ERROR_HTTP, "%s authentication required but no callback set", server_type); git_error_set(GIT_ERROR_HTTP, "%s authentication required but no callback set", server_type);
error = -1; error = GIT_EAUTH;
} }
if (!error) if (!error)
...@@ -176,7 +176,7 @@ GIT_INLINE(int) handle_remote_auth( ...@@ -176,7 +176,7 @@ GIT_INLINE(int) handle_remote_auth(
if (response->server_auth_credtypes == 0) { if (response->server_auth_credtypes == 0) {
git_error_set(GIT_ERROR_HTTP, "server requires authentication that we do not support"); git_error_set(GIT_ERROR_HTTP, "server requires authentication that we do not support");
return -1; return GIT_EAUTH;
} }
/* Otherwise, prompt for credentials. */ /* Otherwise, prompt for credentials. */
...@@ -198,7 +198,7 @@ GIT_INLINE(int) handle_proxy_auth( ...@@ -198,7 +198,7 @@ GIT_INLINE(int) handle_proxy_auth(
if (response->proxy_auth_credtypes == 0) { if (response->proxy_auth_credtypes == 0) {
git_error_set(GIT_ERROR_HTTP, "proxy requires authentication that we do not support"); git_error_set(GIT_ERROR_HTTP, "proxy requires authentication that we do not support");
return -1; return GIT_EAUTH;
} }
/* Otherwise, prompt for credentials. */ /* Otherwise, prompt for credentials. */
...@@ -256,7 +256,7 @@ static int handle_response( ...@@ -256,7 +256,7 @@ static int handle_response(
} else if (response->status == GIT_HTTP_STATUS_UNAUTHORIZED || } else if (response->status == GIT_HTTP_STATUS_UNAUTHORIZED ||
response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) { response->status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
git_error_set(GIT_ERROR_HTTP, "unexpected authentication failure"); git_error_set(GIT_ERROR_HTTP, "unexpected authentication failure");
return -1; return GIT_EAUTH;
} }
if (response->status != GIT_HTTP_STATUS_OK) { if (response->status != GIT_HTTP_STATUS_OK) {
...@@ -413,7 +413,7 @@ static int http_stream_read( ...@@ -413,7 +413,7 @@ static int http_stream_read(
if (stream->state == HTTP_STATE_SENDING_REQUEST) { if (stream->state == HTTP_STATE_SENDING_REQUEST) {
git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays"); git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays");
error = -1; error = GIT_ERROR; /* not GIT_EAUTH, because the exact cause is unclear */
goto done; goto done;
} }
...@@ -551,7 +551,7 @@ static int http_stream_write( ...@@ -551,7 +551,7 @@ static int http_stream_write(
if (stream->state == HTTP_STATE_NONE) { if (stream->state == HTTP_STATE_NONE) {
git_error_set(GIT_ERROR_HTTP, git_error_set(GIT_ERROR_HTTP,
"too many redirects or authentication replays"); "too many redirects or authentication replays");
error = -1; error = GIT_ERROR; /* not GIT_EAUTH because the exact cause is unclear */
goto done; goto done;
} }
......
...@@ -585,8 +585,8 @@ static int apply_credentials( ...@@ -585,8 +585,8 @@ static int apply_credentials(
if (auth->connection_affinity) if (auth->connection_affinity)
free_auth_context(server); free_auth_context(server);
} else if (!token.size) { } else if (!token.size) {
git_error_set(GIT_ERROR_HTTP, "failed to respond to authentication challange"); git_error_set(GIT_ERROR_HTTP, "failed to respond to authentication challenge");
error = -1; error = GIT_EAUTH;
goto done; goto done;
} }
......
...@@ -461,13 +461,13 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char * ...@@ -461,13 +461,13 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char *
if (no_callback) { if (no_callback) {
git_error_set(GIT_ERROR_SSH, "authentication required but no callback set"); git_error_set(GIT_ERROR_SSH, "authentication required but no callback set");
return -1; return GIT_EAUTH;
} }
if (!(cred->credtype & auth_methods)) { if (!(cred->credtype & auth_methods)) {
cred->free(cred); cred->free(cred);
git_error_set(GIT_ERROR_SSH, "callback returned unsupported credentials type"); git_error_set(GIT_ERROR_SSH, "authentication callback returned unsupported credentials type");
return -1; return GIT_EAUTH;
} }
*out = cred; *out = cred;
...@@ -805,7 +805,7 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use ...@@ -805,7 +805,7 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
/* either error, or the remote accepts NONE auth, which is bizarre, let's punt */ /* either error, or the remote accepts NONE auth, which is bizarre, let's punt */
if (list == NULL && !libssh2_userauth_authenticated(session)) { if (list == NULL && !libssh2_userauth_authenticated(session)) {
ssh_error(session, "Failed to retrieve list of SSH authentication methods"); ssh_error(session, "Failed to retrieve list of SSH authentication methods");
return -1; return GIT_EAUTH;
} }
ptr = list; ptr = list;
......
...@@ -146,7 +146,7 @@ static int apply_userpass_credentials(HINTERNET request, DWORD target, int mecha ...@@ -146,7 +146,7 @@ static int apply_userpass_credentials(HINTERNET request, DWORD target, int mecha
native_scheme = WINHTTP_AUTH_SCHEME_BASIC; native_scheme = WINHTTP_AUTH_SCHEME_BASIC;
} else { } else {
git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme"); git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme");
error = -1; error = GIT_EAUTH;
goto done; goto done;
} }
...@@ -185,7 +185,7 @@ static int apply_default_credentials(HINTERNET request, DWORD target, int mechan ...@@ -185,7 +185,7 @@ static int apply_default_credentials(HINTERNET request, DWORD target, int mechan
native_scheme = WINHTTP_AUTH_SCHEME_NTLM; native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
} else { } else {
git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme"); git_error_set(GIT_ERROR_HTTP, "invalid authentication scheme");
return -1; return GIT_EAUTH;
} }
/* /*
...@@ -602,7 +602,7 @@ static int parse_unauthorized_response( ...@@ -602,7 +602,7 @@ static int parse_unauthorized_response(
*/ */
if (!WinHttpQueryAuthSchemes(request, &supported, &first, &target)) { if (!WinHttpQueryAuthSchemes(request, &supported, &first, &target)) {
git_error_set(GIT_ERROR_OS, "failed to parse supported auth schemes"); git_error_set(GIT_ERROR_OS, "failed to parse supported auth schemes");
return -1; return GIT_EAUTH;
} }
if (WINHTTP_AUTH_SCHEME_NTLM & supported) { if (WINHTTP_AUTH_SCHEME_NTLM & supported) {
...@@ -972,7 +972,7 @@ replay: ...@@ -972,7 +972,7 @@ replay:
/* Enforce a reasonable cap on the number of replays */ /* Enforce a reasonable cap on the number of replays */
if (replay_count++ >= GIT_HTTP_REPLAY_MAX) { if (replay_count++ >= GIT_HTTP_REPLAY_MAX) {
git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays"); git_error_set(GIT_ERROR_HTTP, "too many redirects or authentication replays");
return -1; return GIT_ERROR; /* not GIT_EAUTH because the exact cause is not clear */
} }
/* Connect if necessary */ /* Connect if necessary */
......
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