mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
config: Get rid of the dynamic seen array
* This makes the array constant in the session structure, avoiding allocations and frees while parsing the file * It also drops passing the seen array to all the functions, because it is already part of the passed session * The test cases are adjusted to match these changes Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
8f887e82c7
commit
21e2522360
@@ -92,8 +92,6 @@ static void torture_client_config_system(void **state)
|
||||
struct torture_state *s = *state;
|
||||
int ret = 0;
|
||||
|
||||
assert_true(s->ssh.session->opts.options_seen == NULL);
|
||||
|
||||
/* The first tests assumes there is system-wide configuration file
|
||||
* setting Ciphers to some non-default value. We do not have any control
|
||||
* of that in this test case.
|
||||
@@ -121,8 +119,6 @@ static void torture_client_config_emulate(void **state)
|
||||
char *filename = NULL;
|
||||
int ret = 0;
|
||||
|
||||
assert_true(s->ssh.session->opts.options_seen == NULL);
|
||||
|
||||
/* The first tests assumes there is system-wide configuration file
|
||||
* setting Ciphers to some non-default value. We do not have any control
|
||||
* of that in this test case
|
||||
@@ -151,8 +147,6 @@ static void torture_client_config_autoparse(void **state)
|
||||
struct torture_state *s = *state;
|
||||
int ret = 0;
|
||||
|
||||
assert_true(s->ssh.session->opts.options_seen == NULL);
|
||||
|
||||
ret = ssh_connect(s->ssh.session);
|
||||
assert_ssh_return_code(s->ssh.session, ret);
|
||||
|
||||
@@ -169,8 +163,6 @@ static void torture_client_config_suppress(void **state)
|
||||
bool b = false;
|
||||
int ret = 0;
|
||||
|
||||
assert_true(s->ssh.session->opts.options_seen == NULL);
|
||||
|
||||
ret = ssh_options_set(s->ssh.session, SSH_OPTIONS_PROCESS_CONFIG, &b);
|
||||
assert_ssh_return_code(s->ssh.session, ret);
|
||||
|
||||
|
||||
@@ -1163,6 +1163,10 @@ void torture_write_file(const char *filename, const char *data){
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void torture_reset_config(ssh_session session)
|
||||
{
|
||||
memset(session->opts.options_seen, 0, sizeof(session->opts.options_seen));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct argument_s arguments;
|
||||
|
||||
@@ -120,6 +120,8 @@ void torture_setup_sshd_server(void **state);
|
||||
void torture_teardown_socket_dir(void **state);
|
||||
void torture_teardown_sshd_server(void **state);
|
||||
|
||||
void torture_reset_config(ssh_session session);
|
||||
|
||||
/*
|
||||
* This function must be defined in every unit test file.
|
||||
*/
|
||||
|
||||
@@ -156,7 +156,6 @@ static int teardown(void **state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief tests ssh_config_parse_file with Include directives
|
||||
*/
|
||||
@@ -300,7 +299,7 @@ static void torture_config_auth_methods(void **state) {
|
||||
assert_int_equal(session->opts.flags, 0);
|
||||
|
||||
/* gradually enable them again */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "gss");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
||||
assert_true(ret == 0);
|
||||
@@ -355,34 +354,34 @@ static void torture_config_match(void **state)
|
||||
assert_string_equal(session->opts.host, "all-matched.com");
|
||||
|
||||
/* Hostname example does simple hostname matching */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "example");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_true(ret == 0);
|
||||
assert_string_equal(session->opts.host, "example.com");
|
||||
|
||||
/* We can match also both hosts from a comma separated list */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "example1");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_true(ret == 0);
|
||||
assert_string_equal(session->opts.host, "exampleN");
|
||||
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "example2");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_true(ret == 0);
|
||||
assert_string_equal(session->opts.host, "exampleN");
|
||||
|
||||
/* We can match by user */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_USER, "guest");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
assert_true(ret == 0);
|
||||
assert_string_equal(session->opts.host, "guest.com");
|
||||
|
||||
/* We can combine two options on a single line to match both of them */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_USER, "tester");
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
@@ -390,7 +389,7 @@ static void torture_config_match(void **state)
|
||||
assert_string_equal(session->opts.host, "testhost.com");
|
||||
|
||||
/* We can also negate conditions */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_USER, "not-tester");
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost");
|
||||
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
||||
|
||||
@@ -462,26 +462,26 @@ static void torture_options_config_host(void **state) {
|
||||
|
||||
assert_int_equal(session->opts.port, 42);
|
||||
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost2");
|
||||
ssh_options_parse_config(session, "test_config");
|
||||
assert_int_equal(session->opts.port, 43);
|
||||
|
||||
session->opts.port = 0;
|
||||
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost3");
|
||||
ssh_options_parse_config(session, "test_config");
|
||||
assert_int_equal(session->opts.port, 43);
|
||||
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost4");
|
||||
ssh_options_parse_config(session, "test_config");
|
||||
assert_int_equal(session->opts.port, 44);
|
||||
|
||||
session->opts.port = 0;
|
||||
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost5");
|
||||
ssh_options_parse_config(session, "test_config");
|
||||
assert_int_equal(session->opts.port, 44);
|
||||
@@ -509,7 +509,7 @@ static void torture_options_config_match(void **state)
|
||||
assert_ssh_return_code_equal(session, rv, SSH_ERROR);
|
||||
|
||||
/* The Match all keyword needs to be the only one (start) */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match all host local\n",
|
||||
@@ -520,7 +520,7 @@ static void torture_options_config_match(void **state)
|
||||
assert_ssh_return_code_equal(session, rv, SSH_ERROR);
|
||||
|
||||
/* The Match all keyword needs to be the only one (end) */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match host local all\n",
|
||||
@@ -531,7 +531,7 @@ static void torture_options_config_match(void **state)
|
||||
assert_ssh_return_code_equal(session, rv, SSH_ERROR);
|
||||
|
||||
/* The Match host keyword requires an argument */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match host\n",
|
||||
@@ -542,7 +542,7 @@ static void torture_options_config_match(void **state)
|
||||
assert_ssh_return_code_equal(session, rv, SSH_ERROR);
|
||||
|
||||
/* The Match user keyword requires an argument */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match user\n",
|
||||
@@ -553,7 +553,7 @@ static void torture_options_config_match(void **state)
|
||||
assert_ssh_return_code_equal(session, rv, SSH_ERROR);
|
||||
|
||||
/* The Match canonical keyword is ignored */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match canonical\n"
|
||||
@@ -570,7 +570,7 @@ static void torture_options_config_match(void **state)
|
||||
session->opts.port = 0;
|
||||
|
||||
/* The Match originalhost keyword is ignored */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match originalhost origin\n"
|
||||
@@ -587,7 +587,7 @@ static void torture_options_config_match(void **state)
|
||||
session->opts.port = 0;
|
||||
|
||||
/* The Match localuser keyword is ignored */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match originalhost origin\n"
|
||||
@@ -604,7 +604,7 @@ static void torture_options_config_match(void **state)
|
||||
session->opts.port = 0;
|
||||
|
||||
/* The Match exec keyword is ignored */
|
||||
SAFE_FREE(session->opts.options_seen);
|
||||
torture_reset_config(session);
|
||||
config = fopen("test_config", "w");
|
||||
assert_non_null(config);
|
||||
fputs("Match exec /bin/true\n"
|
||||
|
||||
Reference in New Issue
Block a user