2010-06-25 18:19:19 +04:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
#include <libssh/priv.h>
|
|
|
|
#include <libssh/callbacks.h>
|
|
|
|
|
|
|
|
static int myauthcallback (const char *prompt, char *buf, size_t len,
|
2010-12-28 16:04:44 +03:00
|
|
|
int echo, int verify, void *userdata) {
|
|
|
|
(void) prompt;
|
|
|
|
(void) buf;
|
|
|
|
(void) len;
|
|
|
|
(void) echo;
|
|
|
|
(void) verify;
|
|
|
|
(void) userdata;
|
|
|
|
return 0;
|
2010-06-25 18:19:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
static void setup(void **state) {
|
|
|
|
struct ssh_callbacks_struct *cb;
|
2010-06-25 18:19:19 +04:00
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
cb = malloc(sizeof(struct ssh_callbacks_struct));
|
|
|
|
assert_false(cb == NULL);
|
2010-06-25 18:19:19 +04:00
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
cb->userdata = (void *) 0x0badc0de;
|
|
|
|
cb->auth_function = myauthcallback;
|
2010-06-25 18:19:19 +04:00
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
ssh_callbacks_init(cb);
|
|
|
|
*state = cb;
|
2010-06-25 18:19:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
static void teardown(void **state) {
|
|
|
|
free(*state);
|
2010-06-25 18:19:19 +04:00
|
|
|
}
|
2010-12-28 16:04:44 +03:00
|
|
|
|
|
|
|
static void torture_callbacks_size(void **state) {
|
|
|
|
struct ssh_callbacks_struct *cb = *state;;
|
|
|
|
|
|
|
|
assert_int_not_equal(cb->size, 0);
|
2010-06-25 18:19:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
static void torture_callbacks_exists(void **state) {
|
|
|
|
struct ssh_callbacks_struct *cb = *state;
|
2010-06-25 18:19:19 +04:00
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
assert_int_not_equal(ssh_callbacks_exists(cb, auth_function), 0);
|
|
|
|
assert_int_equal(ssh_callbacks_exists(cb, log_function), 0);
|
2010-06-25 18:19:19 +04:00
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
/*
|
|
|
|
* We redefine size so auth_function is outside the range of
|
|
|
|
* callbacks->size.
|
|
|
|
*/
|
|
|
|
cb->size = (unsigned char *) &cb->auth_function - (unsigned char *) cb;
|
|
|
|
assert_int_equal(ssh_callbacks_exists(cb, auth_function), 0);
|
|
|
|
|
|
|
|
/* Now make it one pointer bigger so we spill over the auth_function slot */
|
|
|
|
cb->size += sizeof(void *);
|
|
|
|
assert_int_not_equal(ssh_callbacks_exists(cb, auth_function), 0);
|
2010-06-25 18:19:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 16:04:44 +03:00
|
|
|
int torture_run_tests(void) {
|
|
|
|
const UnitTest tests[] = {
|
|
|
|
unit_test_setup_teardown(torture_callbacks_size, setup, teardown),
|
|
|
|
unit_test_setup_teardown(torture_callbacks_exists, setup, teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return run_tests(tests);
|
|
|
|
}
|