mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-18 15:20:56 +03:00
- fix skip auth if `userauthlist` is NULL. Closes #836 (Reported-by: @sudipm-mukherjee on github) - fix most silenced `checksrc` warnings. - sync examples/tests code between each other. (output messages, error handling, declaration order, comments) - stop including unnecessary headers. - always deinitialize in case of error. - drop some redundant variables. - add error handling where missing. - show more error codes. - switch `perror()` to `fprintf()`. - fix some `printf()`s to be `fprintf()`. - formatting. Closes #960
36 lines
1003 B
C
36 lines
1003 B
C
#include "runner.h"
|
|
|
|
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
|
static const char *KEY_FILE_PRIVATE = "key_dsa_wrong";
|
|
static const char *KEY_FILE_PUBLIC = "key_dsa_wrong.pub";
|
|
|
|
int test(LIBSSH2_SESSION *session)
|
|
{
|
|
int rc;
|
|
|
|
const char *userauth_list =
|
|
libssh2_userauth_list(session, USERNAME,
|
|
(unsigned int)strlen(USERNAME));
|
|
if(!userauth_list) {
|
|
print_last_session_error("libssh2_userauth_list");
|
|
return 1;
|
|
}
|
|
|
|
if(!strstr(userauth_list, "publickey")) {
|
|
fprintf(stderr, "'publickey' was expected in userauth list: %s\n",
|
|
userauth_list);
|
|
return 1;
|
|
}
|
|
|
|
rc = libssh2_userauth_publickey_fromfile_ex(
|
|
session, USERNAME, (unsigned int)strlen(USERNAME),
|
|
srcdir_path(KEY_FILE_PUBLIC), srcdir_path(KEY_FILE_PRIVATE),
|
|
NULL);
|
|
if(rc == 0) {
|
|
fprintf(stderr, "Public-key auth succeeded with wrong key\n");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|