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
1.0 KiB
C
36 lines
1.0 KiB
C
#include "runner.h"
|
|
|
|
/* configured in Dockerfile */
|
|
static const char *PASSWORD = "my test password";
|
|
static const char *WRONG_USERNAME = "i dont exist";
|
|
|
|
int test(LIBSSH2_SESSION *session)
|
|
{
|
|
int rc;
|
|
|
|
const char *userauth_list =
|
|
libssh2_userauth_list(session, WRONG_USERNAME,
|
|
(unsigned int)strlen(WRONG_USERNAME));
|
|
if(!userauth_list) {
|
|
print_last_session_error("libssh2_userauth_list");
|
|
return 1;
|
|
}
|
|
|
|
if(!strstr(userauth_list, "password")) {
|
|
fprintf(stderr, "'password' was expected in userauth list: %s\n",
|
|
userauth_list);
|
|
return 1;
|
|
}
|
|
|
|
rc = libssh2_userauth_password_ex(session, WRONG_USERNAME,
|
|
(unsigned int)strlen(WRONG_USERNAME),
|
|
PASSWORD,
|
|
(unsigned int)strlen(PASSWORD), NULL);
|
|
if(rc == 0) {
|
|
fprintf(stderr, "Password auth succeeded with wrong username\n");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|