2017-10-28 15:31:37 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-02-06 17:33:17 +03:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
#include "sftp.c"
|
|
|
|
|
2015-09-11 17:26:53 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
2018-08-22 09:35:19 +03:00
|
|
|
#include <errno.h>
|
2011-02-06 17:33:17 +03:00
|
|
|
|
2015-09-11 17:26:53 +03:00
|
|
|
static int sshd_setup(void **state)
|
|
|
|
{
|
2018-11-27 18:52:19 +03:00
|
|
|
torture_setup_sshd_server(state, false);
|
2015-09-07 11:39:51 +03:00
|
|
|
|
|
|
|
return 0;
|
2011-02-06 17:33:17 +03:00
|
|
|
}
|
|
|
|
|
2015-09-11 17:26:53 +03:00
|
|
|
static int sshd_teardown(void **state) {
|
|
|
|
torture_teardown_sshd_server(state);
|
2011-02-06 17:33:17 +03:00
|
|
|
|
2015-09-11 17:26:53 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int session_setup(void **state)
|
|
|
|
{
|
|
|
|
struct torture_state *s = *state;
|
|
|
|
struct passwd *pwd;
|
2018-08-22 09:35:19 +03:00
|
|
|
int rc;
|
2015-09-11 17:26:53 +03:00
|
|
|
|
|
|
|
pwd = getpwnam("bob");
|
|
|
|
assert_non_null(pwd);
|
2018-08-22 09:35:19 +03:00
|
|
|
|
|
|
|
rc = setuid(pwd->pw_uid);
|
|
|
|
assert_return_code(rc, errno);
|
2015-09-11 17:26:53 +03:00
|
|
|
|
2018-11-26 15:48:37 +03:00
|
|
|
s->ssh.session = torture_ssh_session(s,
|
|
|
|
TORTURE_SSH_SERVER,
|
2015-09-11 17:26:53 +03:00
|
|
|
NULL,
|
|
|
|
TORTURE_SSH_USER_ALICE,
|
|
|
|
NULL);
|
|
|
|
assert_non_null(s->ssh.session);
|
2011-02-13 12:44:09 +03:00
|
|
|
|
2015-09-11 17:26:53 +03:00
|
|
|
s->ssh.tsftp = torture_sftp_session(s->ssh.session);
|
|
|
|
assert_non_null(s->ssh.tsftp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int session_teardown(void **state)
|
|
|
|
{
|
|
|
|
struct torture_state *s = *state;
|
|
|
|
|
|
|
|
torture_rmdirs(s->ssh.tsftp->testdir);
|
|
|
|
torture_sftp_close(s->ssh.tsftp);
|
|
|
|
ssh_disconnect(s->ssh.session);
|
|
|
|
ssh_free(s->ssh.session);
|
2015-09-07 11:39:51 +03:00
|
|
|
|
|
|
|
return 0;
|
2011-02-06 17:33:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void torture_sftp_mkdir(void **state) {
|
2015-09-11 17:26:53 +03:00
|
|
|
struct torture_state *s = *state;
|
|
|
|
|
|
|
|
struct torture_sftp *t = s->ssh.tsftp;
|
2012-10-08 01:23:33 +04:00
|
|
|
char tmpdir[128] = {0};
|
2011-02-06 17:33:17 +03:00
|
|
|
int rc;
|
|
|
|
|
2019-01-15 15:45:10 +03:00
|
|
|
assert_non_null(t);
|
2011-02-13 12:44:09 +03:00
|
|
|
|
2012-10-08 01:23:33 +04:00
|
|
|
snprintf(tmpdir, sizeof(tmpdir) - 1, "%s/mkdir_test", t->testdir);
|
2011-02-06 17:33:17 +03:00
|
|
|
|
|
|
|
rc = sftp_mkdir(t->sftp, tmpdir, 0755);
|
2011-08-24 23:31:26 +04:00
|
|
|
if(rc != SSH_OK)
|
|
|
|
fprintf(stderr,"error:%s\n",ssh_get_error(t->sftp->session));
|
2011-02-06 17:33:17 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
|
|
|
|
/* check if it really has been created */
|
|
|
|
assert_true(torture_isdir(tmpdir));
|
|
|
|
|
|
|
|
rc = sftp_rmdir(t->sftp, tmpdir);
|
|
|
|
assert_true(rc == 0);
|
|
|
|
|
|
|
|
/* check if it has been deleted */
|
|
|
|
assert_false(torture_isdir(tmpdir));
|
|
|
|
}
|
|
|
|
|
|
|
|
int torture_run_tests(void) {
|
|
|
|
int rc;
|
2015-09-07 11:39:51 +03:00
|
|
|
struct CMUnitTest tests[] = {
|
2015-09-11 17:26:53 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_sftp_mkdir,
|
|
|
|
session_setup,
|
|
|
|
session_teardown)
|
2011-02-06 17:33:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
ssh_init();
|
|
|
|
|
2014-09-02 11:07:17 +04:00
|
|
|
torture_filter_tests(tests);
|
2015-09-11 17:26:53 +03:00
|
|
|
rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
|
|
|
|
|
2011-02-06 17:33:17 +03:00
|
|
|
ssh_finalize();
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|