From e7f18139626a283e2a8e178c63b5adfa073de1b5 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Sun, 20 Dec 2015 18:17:42 -0800 Subject: [PATCH] [test suite] implement different access stanza init strategy, 'complete cycle, include (3)' test passes now --- server/access.c | 43 +++++++++++++++++++++++-------------- server/access.h | 1 + server/config_init.c | 4 ++++ test/test-fwknop.pl | 2 ++ test/tests/rijndael_hmac.pl | 1 + 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/server/access.c b/server/access.c index b7e096aa..ce621a41 100644 --- a/server/access.c +++ b/server/access.c @@ -54,6 +54,14 @@ DECLARE_TEST_SUITE(access, "Access test suite"); #endif +static int do_acc_stanza_init = 1; + +void enable_acc_stanzas_init(void) +{ + do_acc_stanza_init = 1; + return; +} + /* Add an access string entry */ static void @@ -1036,10 +1044,19 @@ free_acc_stanzas(fko_srv_options_t *opts) static void acc_stanza_init(fko_srv_options_t *opts) { - /* Free any resources first (in case of reconfig). Assume non-NULL - * entry needs to be freed. - */ - free_acc_stanzas(opts); + if(do_acc_stanza_init) + { + log_msg(LOG_DEBUG, "Initialize access stanzas"); + + /* Free any resources first (in case of reconfig). Assume non-NULL + * entry needs to be freed. + */ + free_acc_stanzas(opts); + + /* Make sure to only initialize access stanzas once. + */ + do_acc_stanza_init = 0; + } return; } @@ -1355,12 +1372,6 @@ parse_access_folder(fko_srv_options_t *opts, char *access_folder, int *depth) char include_file[MAX_PATH_LEN] = {0}; struct dirent *dp; - (*depth)++; - if ((*depth) == 1) - { - acc_stanza_init(opts); - } - if(strlen(access_folder) > 1) chop_char(access_folder, PATH_SEP); @@ -1466,12 +1477,11 @@ parse_access_file(fko_srv_options_t *opts, char *access_filename, int *depth) return EXIT_FAILURE; } - /* Initialize the access list, but only if we are processing the root access.conf. + log_msg(LOG_DEBUG, "Opened access file: %s", access_filename); + + /* Initialize the access list */ - if ((*depth) == 1) - { - acc_stanza_init(opts); - } + acc_stanza_init(opts); /* Now walk through access file pulling the access entries into the * current stanza. @@ -1889,7 +1899,8 @@ parse_access_file(fko_srv_options_t *opts, char *access_filename, int *depth) } fclose(file_ptr); - (*depth)--; + if(*depth > 0) + (*depth)--; if(*depth == 0) //means we just closed the root access.conf { diff --git a/server/access.h b/server/access.h index 84bb0fdf..5bd41285 100644 --- a/server/access.h +++ b/server/access.h @@ -52,6 +52,7 @@ int compare_addr_list(acc_int_list_t *source_list, const uint32_t ip); int acc_check_port_access(acc_stanza_t *acc, char *port_str); void dump_access_list(const fko_srv_options_t *opts); int expand_acc_port_list(acc_port_list_t **plist, char *plist_str); +void enable_acc_stanzas_init(void); void free_acc_stanzas(fko_srv_options_t *opts); void free_acc_port_list(acc_port_list_t *plist); diff --git a/server/config_init.c b/server/config_init.c index a2f0f3ce..3a5c5842 100644 --- a/server/config_init.c +++ b/server/config_init.c @@ -1020,6 +1020,10 @@ config_init(fko_srv_options_t *opts, int argc, char **argv) */ optind = 0; + /* Enable access.conf parsing (in case this is a re-config) + */ + enable_acc_stanzas_init(); + /* First, scan the command-line args to see if we are in key-generation * mode. This is independent of config parsing and other operations, so * it is done as the very first thing. Also handle printing of the fwknop diff --git a/test/test-fwknop.pl b/test/test-fwknop.pl index db3c827f..afd8f7b1 100755 --- a/test/test-fwknop.pl +++ b/test/test-fwknop.pl @@ -2618,7 +2618,9 @@ sub _client_send_spa_packet() { for (;;) { $tries++; + ### default stanza regex match my $server_receive_re = qr/stanza\s.*\sSPA Packet from IP/; + $server_receive_re = $test_hr->{'server_receive_re'} if $test_hr->{'server_receive_re'}; diff --git a/test/tests/rijndael_hmac.pl b/test/tests/rijndael_hmac.pl index ba93dae8..2d2175aa 100644 --- a/test/tests/rijndael_hmac.pl +++ b/test/tests/rijndael_hmac.pl @@ -174,6 +174,7 @@ 'cmdline' => $default_client_hmac_args, 'fwknopd_cmdline' => "$fwknopdCmd -c $cf{'def'} --access-folder conf/access-include/defaults " . "-d $default_digest_file -p $default_pid_file $intf_str", + 'server_receive_re' => qr/stanza\s\#2.*\sSPA Packet from IP/, 'fw_rule_created' => $NEW_RULE_REQUIRED, 'fw_rule_removed' => $NEW_RULE_REMOVED, 'key_file' => $cf{'rc_hmac_b64_key'},