mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
cLib: Pass on 'Invalid credentials' as an error
Instead of just the generic error message.
This commit is contained in:
@ -45,6 +45,11 @@ gj_error *gj_error_info(int err)
|
|||||||
error->message = (char *)malloc(256);
|
error->message = (char *)malloc(256);
|
||||||
ERR_error_string(error->code, error->message);
|
ERR_error_string(error->code, error->message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GJ_ERR_INVALID_CREDENTIALS:
|
||||||
|
error->code = err;
|
||||||
|
error->message = "Invalid Credentials";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,7 @@ void gj_set_ssh_keys_paths(char *public_key, char *private_key, char *passcode)
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool first_time;
|
bool first_time;
|
||||||
|
int error_code;
|
||||||
} gj_credentials_payload;
|
} gj_credentials_payload;
|
||||||
|
|
||||||
int credentials_cb(git_cred **out, const char *url, const char *username_from_url,
|
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;
|
gj_credentials_payload *gj_payload = (gj_credentials_payload *)payload;
|
||||||
if (!gj_payload->first_time)
|
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");
|
gj_log_internal("GitJournal: Credentials have been tried and they failed\n");
|
||||||
return -1;
|
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.transfer_progress = fetch_progress;
|
||||||
options.fetch_opts.callbacks.certificate_check = certificate_check_cb;
|
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.payload = (void *)&gj_payload;
|
||||||
options.fetch_opts.callbacks.credentials = credentials_cb;
|
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:
|
cleanup:
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
|
|
||||||
|
if (gj_payload.error_code != 0)
|
||||||
|
return gj_payload.error_code;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ int gj_generate_ssh_keys(const char *private_key_path,
|
|||||||
#define GJ_ERR_EMPTY_COMMIT -954
|
#define GJ_ERR_EMPTY_COMMIT -954
|
||||||
#define GJ_ERR_PULL_INVALID_STATE -955
|
#define GJ_ERR_PULL_INVALID_STATE -955
|
||||||
#define GJ_ERR_OPENSSL -956
|
#define GJ_ERR_OPENSSL -956
|
||||||
#define GJ_ERR_LAST -956
|
#define GJ_ERR_INVALID_CREDENTIALS -957
|
||||||
|
#define GJ_ERR_LAST -957
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user