@@ -81,11 +81,19 @@ static char* get_password(SEXP cb, const char *url, const char **username, int r
8181static int get_key_files (SEXP cb , auth_key_data * out , int verbose ){
8282 if (!Rf_isFunction (cb ))
8383 Rf_error ("cb must be a function" );
84- int err ;
84+ int err = 0 ;
8585 SEXP call = PROTECT (Rf_lcons (cb , R_NilValue ));
8686 SEXP res = PROTECT (verbose ? R_tryEval (call , R_GlobalEnv , & err ) :
8787 R_tryEvalSilent (call , R_GlobalEnv , & err ));
88+ if (res && Rf_inherits (res , "try-error" )){
89+ static char custom_callback_error [1000 ] = {0 };
90+ snprintf (custom_callback_error , 999 , "SSH authentication failure: %s" , CHAR (STRING_ELT (res , 0 )));
91+ giterr_set_str (GIT_ERROR_CALLBACK , custom_callback_error );
92+ UNPROTECT (2 );
93+ return -1 ;
94+ }
8895 if (err || !Rf_isString (res )){
96+ giterr_set_str (GIT_ERROR_CALLBACK , "Failed to read local SSH key from callback function" );
8997 UNPROTECT (2 );
9098 return -1 ;
9199 }
@@ -171,7 +179,7 @@ static int auth_callback(git_cred **cred, const char *url, const char *username,
171179 auth_callback_data_t * cb_data = payload ;
172180 const char * ssh_user = username ? username : "git" ;
173181 int verbose = cb_data -> verbose ;
174- char custom_callback_error [ 1000 ] = "Authentication failure" ;
182+ git_error_clear () ;
175183
176184#if AT_LEAST_LIBGIT2 (0 , 20 )
177185
@@ -200,11 +208,6 @@ static int auth_callback(git_cred **cred, const char *url, const char *username,
200208 key_data .key_path , key_data .pass_phrase )){
201209 print_if_verbose ("Trying to authenticate '%s' using provided ssh-key...\n" , ssh_user );
202210 return 0 ;
203- #if R_VERSION < 263424
204- //TODO: better fallback for this non-API call in R 4.5....
205- } else if (R_curErrorBuf ()){
206- snprintf (custom_callback_error , 999 , "SSH authentication failure: %s" , R_curErrorBuf ());
207- #endif
208211 }
209212 }
210213
@@ -230,6 +233,7 @@ static int auth_callback(git_cred **cred, const char *url, const char *username,
230233 char * pass = get_password (cb_data -> getcred , url , & username , cb_data -> retries );
231234 if (!username || !pass ){
232235 print_if_verbose ("Credential lookup failed\n" );
236+ giterr_set_str (GIT_ERROR_CALLBACK , "HTTPS Authentication failure" );
233237 goto failure ;
234238 } else {
235239 return git_cred_userpass_plaintext_new (cred , username , pass );
@@ -238,7 +242,6 @@ static int auth_callback(git_cred **cred, const char *url, const char *username,
238242 }
239243 print_if_verbose ("All authentication methods failed\n" );
240244failure :
241- giterr_set_str (GIT_ERROR_CALLBACK , custom_callback_error );
242245 return GIT_EAUTH ;
243246}
244247
0 commit comments