diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-08-14 09:39:40 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-08-14 10:22:35 -0700 |
commit | 777cbd9cfe7cd026315bfcbac15126512a016a90 (patch) | |
tree | fc766dd92e36449f039e5694941a96b4d19c41a8 /core/git-access.c | |
parent | a62e225e03d5f1118d4a29574517db69a8e8acb5 (diff) | |
download | subsurface-777cbd9cfe7cd026315bfcbac15126512a016a90.tar.gz |
Fix cloud storage authentication attempt counting
The authentication count was a static counter in the authentication
callback, which gets incremented until we consider the authentication to
have failed.
The problem with that is that it doesn't get incremented for just _one_
authentication operation, it gets incremented each time you try to load
or save, so eventually the code considers authentication to have failed
even if nothing ever went wrong.
This fixes it by making it static to the whole git-access file, and have
each operation clear it before starting a new remote access.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/git-access.c')
-rw-r--r-- | core/git-access.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/core/git-access.c b/core/git-access.c index 6fe90b0a9..458a7dd9a 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -185,6 +185,8 @@ static int reset_to_remote(git_repository *repo, git_reference *local, const git return 0; } +static int auth_attempt = 0; + int credential_ssh_cb(git_cred **out, const char *url, const char *username_from_url, @@ -194,7 +196,6 @@ int credential_ssh_cb(git_cred **out, (void) url; (void) allowed_types; (void) payload; - static int attempt = 0; const char *priv_key = format_string("%s/%s", system_default_directory(), "ssrf_remote.key"); const char *passphrase = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup(""); @@ -202,9 +203,8 @@ int credential_ssh_cb(git_cred **out, /* Bail out from libgit authentication loop when credentials are * incorrect */ - if (attempt++ > 2) { + if (auth_attempt++ > 2) { report_error("Authentication to cloud storage failed."); - attempt = 0; return GIT_EUSER; } @@ -221,16 +221,14 @@ int credential_https_cb(git_cred **out, (void) username_from_url; (void) payload; (void) allowed_types; - static int attempt = 0; const char *username = prefs.cloud_storage_email_encoded; const char *password = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup(""); /* Bail out from libgit authentication loop when credentials are * incorrect */ - if (attempt++ > 2) { + if (auth_attempt++ > 2) { report_error("Authentication to cloud storage failed."); - attempt = 0; return GIT_EUSER; } return git_cred_userpass_plaintext_new(out, username, password); @@ -273,6 +271,7 @@ static int update_remote(git_repository *repo, git_remote *origin, git_reference refspec.count = 1; refspec.strings = (char **)&name; + auth_attempt = 0; opts.callbacks.push_transfer_progress = &push_transfer_progress_cb; if (rt == RT_SSH) opts.callbacks.credentials = credential_ssh_cb; @@ -529,6 +528,7 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c git_reference_list(&refspec, repo); git_push_options opts = GIT_PUSH_OPTIONS_INIT; opts.callbacks.transfer_progress = &transfer_progress_cb; + auth_attempt = 0; if (rt == RT_SSH) opts.callbacks.credentials = credential_ssh_cb; else if (rt == RT_HTTPS) @@ -592,6 +592,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc fprintf(stderr, "git storage: fetch remote\n"); git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; opts.callbacks.transfer_progress = &transfer_progress_cb; + auth_attempt = 0; if (rt == RT_SSH) opts.callbacks.credentials = credential_ssh_cb; else if (rt == RT_HTTPS) @@ -710,6 +711,7 @@ static git_repository *create_local_repo(const char *localdir, const char *remot if (verbose) fprintf(stderr, "git storage: create_local_repo\n"); + auth_attempt = 0; opts.fetch_opts.callbacks.transfer_progress = &transfer_progress_cb; if (rt == RT_SSH) opts.fetch_opts.callbacks.credentials = credential_ssh_cb; |