diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-01-13 18:03:40 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-01-19 09:45:08 +0200 |
commit | b188f005878458dfeb875fd40b26ebf9d37b655b (patch) | |
tree | b78016ea4fff362d7a1a1b1406978d47021e9133 /core/git-access.c | |
parent | 88658bd9e36710d8dffdf4eea890fec4fa670bde (diff) | |
download | subsurface-b188f005878458dfeb875fd40b26ebf9d37b655b.tar.gz |
Factor out counting of authentication attempts into function
Moreover, make the maximum number of authentication attempts a
const variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/git-access.c')
-rw-r--r-- | core/git-access.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/core/git-access.c b/core/git-access.c index 27cfe7831..864516e41 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -187,6 +187,16 @@ static int reset_to_remote(git_repository *repo, git_reference *local, const git } static int auth_attempt = 0; +static const int max_auth_attempts = 2; + +static bool exceeded_auth_attempts() +{ + if (auth_attempt++ > max_auth_attempts) { + report_error("Authentication to cloud storage failed."); + return true; + } + return false; +} int credential_ssh_cb(git_cred **out, const char *url, @@ -198,11 +208,8 @@ int credential_ssh_cb(git_cred **out, (void) allowed_types; (void) payload; - /* Bail out from libgit authentication loop when credentials are incorrect */ - if (auth_attempt++ > 2) { - report_error("Authentication to cloud storage failed."); + if (exceeded_auth_attempts()) return GIT_EUSER; - } char *priv_key = format_string("%s/%s", system_default_directory(), "ssrf_remote.key"); const char *passphrase = prefs.cloud_storage_password ? prefs.cloud_storage_password : ""; @@ -223,11 +230,8 @@ int credential_https_cb(git_cred **out, (void) payload; (void) allowed_types; - /* Bail out from libgit authentication loop when credentials are incorrect */ - if (auth_attempt++ > 2) { - report_error("Authentication to cloud storage failed."); + if (exceeded_auth_attempts()) return GIT_EUSER; - } const char *username = prefs.cloud_storage_email_encoded; const char *password = prefs.cloud_storage_password ? prefs.cloud_storage_password : ""; |