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>
This commit is contained in:
Berthold Stoeger 2018-01-13 18:03:40 +01:00 committed by Dirk Hohndel
parent 88658bd9e3
commit b188f00587

View file

@ -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 : "";