From 9573c8e2d5ca31d743955f2183e3c46a437ebdd4 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 29 May 2019 15:08:02 +0200 Subject: [PATCH] cLib: Pass on 'Invalid credentials' as an error Instead of just the generic error message. --- gj_common/common.c | 5 +++++ gj_common/gitjournal.c | 6 +++++- gj_common/gitjournal.h | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gj_common/common.c b/gj_common/common.c index 12d8721e..dede87bb 100644 --- a/gj_common/common.c +++ b/gj_common/common.c @@ -45,6 +45,11 @@ gj_error *gj_error_info(int err) error->message = (char *)malloc(256); ERR_error_string(error->code, error->message); break; + + case GJ_ERR_INVALID_CREDENTIALS: + error->code = err; + error->message = "Invalid Credentials"; + break; } return error; } diff --git a/gj_common/gitjournal.c b/gj_common/gitjournal.c index 77a354ea..6331c341 100644 --- a/gj_common/gitjournal.c +++ b/gj_common/gitjournal.c @@ -268,6 +268,7 @@ void gj_set_ssh_keys_paths(char *public_key, char *private_key, char *passcode) typedef struct { bool first_time; + int error_code; } gj_credentials_payload; int credentials_cb(git_cred **out, const char *url, const char *username_from_url, @@ -281,6 +282,7 @@ int credentials_cb(git_cred **out, const char *url, const char *username_from_ur gj_credentials_payload *gj_payload = (gj_credentials_payload *)payload; if (!gj_payload->first_time) { + gj_payload->error_code = GJ_ERR_INVALID_CREDENTIALS; gj_log_internal("GitJournal: Credentials have been tried and they failed\n"); return -1; } @@ -324,7 +326,7 @@ int gj_git_clone(const char *clone_url, const char *git_base_path) options.fetch_opts.callbacks.transfer_progress = fetch_progress; options.fetch_opts.callbacks.certificate_check = certificate_check_cb; - gj_credentials_payload gj_payload = {true}; + gj_credentials_payload gj_payload = {true, 0}; options.fetch_opts.callbacks.payload = (void *)&gj_payload; options.fetch_opts.callbacks.credentials = credentials_cb; @@ -335,6 +337,8 @@ int gj_git_clone(const char *clone_url, const char *git_base_path) cleanup: git_repository_free(repo); + if (gj_payload.error_code != 0) + return gj_payload.error_code; return err; } diff --git a/gj_common/gitjournal.h b/gj_common/gitjournal.h index 44cd8f9c..0ddd0ac4 100644 --- a/gj_common/gitjournal.h +++ b/gj_common/gitjournal.h @@ -42,6 +42,7 @@ int gj_generate_ssh_keys(const char *private_key_path, #define GJ_ERR_EMPTY_COMMIT -954 #define GJ_ERR_PULL_INVALID_STATE -955 #define GJ_ERR_OPENSSL -956 -#define GJ_ERR_LAST -956 +#define GJ_ERR_INVALID_CREDENTIALS -957 +#define GJ_ERR_LAST -957 #endif