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:
Jakub Jelen
2018-12-05 12:09:07 +01:00
committed by Andreas Schneider
parent 8f887e82c7
commit 21e2522360
9 changed files with 108 additions and 95 deletions

View 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);

View File

@@ -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"