From 64a42f0a9a0a7a28d3cff8dca1b45e3067aae63d Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 16 Feb 2024 19:30:30 -0600 Subject: [PATCH] Progress: Continue refactoring firewall from 0.6.x to 0.7.x/0.8.x. This fixes some obvious problems. The firewall rules are not currently working and I am going to guess that it might be related to the buffering logic. --- level_3/firewall/c/main/common.c | 69 ++++++---------------------- level_3/firewall/c/main/common/enumeration.h | 40 ++++++++-------- level_3/firewall/c/main/operate.c | 1 + level_3/firewall/c/main/print/message.c | 2 +- level_3/firewall/c/main/print/warning.c | 2 +- 5 files changed, 38 insertions(+), 76 deletions(-) diff --git a/level_3/firewall/c/main/common.c b/level_3/firewall/c/main/common.c index 00e3fe4..68012dd 100644 --- a/level_3/firewall/c/main/common.c +++ b/level_3/firewall/c/main/common.c @@ -82,66 +82,45 @@ extern "C" { return; } - f_number_unsigned_t at = 0; f_number_unsigned_t index = 0; if (main->program.parameters.array[firewall_parameter_operation_start_e].result & f_console_result_found_e) { - main->setting.flag &= ~firewall_main_flag_operation_lock_e; - main->setting.flag &= ~firewall_main_flag_operation_restart_e; - main->setting.flag &= ~firewall_main_flag_operation_show_e; - main->setting.flag &= ~firewall_main_flag_operation_stop_e; - + main->setting.flag &= ~firewall_main_flag_operation_e; main->setting.flag |= firewall_main_flag_operation_start_e; - at = main->program.parameters.array[firewall_parameter_operation_start_e].values.array[0]; + index = main->program.parameters.array[firewall_parameter_operation_start_e].location; } if (main->program.parameters.array[firewall_parameter_operation_stop_e].result & f_console_result_found_e) { - if (!(main->setting.flag & firewall_main_flag_operation_e) || (main->program.parameters.array[at].values.array[0] > main->program.parameters.array[firewall_parameter_operation_stop_e].values.array[0])) { - main->setting.flag &= ~firewall_main_flag_operation_lock_e; - main->setting.flag &= ~firewall_main_flag_operation_restart_e; - main->setting.flag &= ~firewall_main_flag_operation_show_e; - main->setting.flag &= ~firewall_main_flag_operation_start_e; - + if (!(main->setting.flag & firewall_main_flag_operation_e) || main->program.parameters.array[firewall_parameter_operation_stop_e].location > index) { + main->setting.flag &= ~firewall_main_flag_operation_e; main->setting.flag |= firewall_main_flag_operation_stop_e; - at = main->program.parameters.array[firewall_parameter_operation_stop_e].values.array[0]; + index = main->program.parameters.array[firewall_parameter_operation_stop_e].location; } } if (main->program.parameters.array[firewall_parameter_operation_restart_e].result & f_console_result_found_e) { - if (!(main->setting.flag & firewall_main_flag_operation_e) || (main->program.parameters.array[at].values.array[0] > main->program.parameters.array[firewall_parameter_operation_restart_e].values.array[0])) { - main->setting.flag &= ~firewall_main_flag_operation_lock_e; - main->setting.flag &= ~firewall_main_flag_operation_show_e; - main->setting.flag &= ~firewall_main_flag_operation_start_e; - main->setting.flag &= ~firewall_main_flag_operation_stop_e; - + if (!(main->setting.flag & firewall_main_flag_operation_e) || main->program.parameters.array[firewall_parameter_operation_restart_e].location > index) { + main->setting.flag &= ~firewall_main_flag_operation_e; main->setting.flag |= firewall_main_flag_operation_restart_e; - at = main->program.parameters.array[firewall_parameter_operation_restart_e].values.array[0]; + index = main->program.parameters.array[firewall_parameter_operation_restart_e].location; } } if (main->program.parameters.array[firewall_parameter_operation_lock_e].result & f_console_result_found_e) { - if (!(main->setting.flag & firewall_main_flag_operation_e) || (main->program.parameters.array[at].values.array[0] > main->program.parameters.array[firewall_parameter_operation_lock_e].values.array[0])) { - main->setting.flag &= ~firewall_main_flag_operation_restart_e; - main->setting.flag &= ~firewall_main_flag_operation_show_e; - main->setting.flag &= ~firewall_main_flag_operation_start_e; - main->setting.flag &= ~firewall_main_flag_operation_stop_e; - + if (!(main->setting.flag & firewall_main_flag_operation_e) || main->program.parameters.array[firewall_parameter_operation_lock_e].location > index) { + main->setting.flag &= ~firewall_main_flag_operation_e; main->setting.flag |= firewall_main_flag_operation_lock_e; - at = main->program.parameters.array[firewall_parameter_operation_lock_e].values.array[0]; + index = main->program.parameters.array[firewall_parameter_operation_lock_e].location; } } if (main->program.parameters.array[firewall_parameter_operation_show_e].result & f_console_result_found_e) { - if (!(main->setting.flag & firewall_main_flag_operation_e) || (main->program.parameters.array[at].values.array[0] > main->program.parameters.array[firewall_parameter_operation_show_e].values.array[0])) { - main->setting.flag &= ~firewall_main_flag_operation_lock_e; - main->setting.flag &= ~firewall_main_flag_operation_restart_e; - main->setting.flag &= ~firewall_main_flag_operation_start_e; - main->setting.flag &= ~firewall_main_flag_operation_stop_e; - + if (!(main->setting.flag & firewall_main_flag_operation_e) || main->program.parameters.array[firewall_parameter_operation_show_e].location > index) { + main->setting.flag &= ~firewall_main_flag_operation_e; main->setting.flag |= firewall_main_flag_operation_show_e; } } @@ -157,11 +136,11 @@ extern "C" { if (main->program.parameters.remaining.used) { main->setting.flag &= ~firewall_main_flag_operation_show_filter_nat_mangle_e; - for (at = 0; at < main->program.parameters.remaining.used; ++at) { + for (f_number_unsigned_t i = 0; i < main->program.parameters.remaining.used; ++i) { if (firewall_signal_check(main)) return; - index = main->program.parameters.remaining.array[at]; + index = main->program.parameters.remaining.array[i]; if (f_compare_dynamic(firewall_show_nat_s, main->program.parameters.arguments.array[index]) == F_equal_to) { main->setting.flag |= firewall_main_flag_operation_show_nat_e; @@ -181,24 +160,6 @@ extern "C" { main->setting.flag |= firewall_main_flag_operation_show_filter_nat_mangle_e; } } - else { - // @todo - - // Example: - /* - for (f_number_unsigned_t number = 0; index < main->program.parameters.remaining.used; ++index) { - - if (control_signal_check(main)) return; - - number = main->program.parameters.remaining.array[index]; - - // Statically allocate the inner strings. - main->setting.actions.array[main->setting.actions.used].string = main->program.parameters.arguments.array[number].string; - main->setting.actions.array[main->setting.actions.used].used = main->program.parameters.arguments.array[number].used; - main->setting.actions.array[main->setting.actions.used++].size = 0; - } // for - */ - } } #endif // _di_firewall_setting_load_ diff --git a/level_3/firewall/c/main/common/enumeration.h b/level_3/firewall/c/main/common/enumeration.h index fbcf193..d13cd6b 100644 --- a/level_3/firewall/c/main/common/enumeration.h +++ b/level_3/firewall/c/main/common/enumeration.h @@ -29,8 +29,8 @@ extern "C" { * - operation_show: Perform the show operation. * - operation_show_nat: For the show operation, show nat. * - operation_show_mangle: For the show operation, show mangle. - * - operation_show_filter: For the show operation, show ports. - * - operation_show_filter_nat_mangle: A helper flag representing the show nat, show mangle, and short port flags set. + * - operation_show_filter: For the show operation, show filter. + * - operation_show_filter_nat_mangle: A helper flag representing the show nat, show mangle, and short filter flags set. * - operation_start: Perform the start operation. * - operation_start_restart: A helper flag representing both the start and restart operation flag set. * - operation_stop: Perform the stop operation. @@ -47,24 +47,24 @@ extern "C" { firewall_main_flag_none_e = 0x0, firewall_main_flag_copyright_e = 0x1, firewall_main_flag_help_e = 0x2, - firewall_main_flag_operation_e = 0x4, - firewall_main_flag_operation_lock_e = 0x8, - firewall_main_flag_operation_restart_e = 0x10, - firewall_main_flag_operation_show_e = 0x20, - firewall_main_flag_operation_show_nat_e = 0x40, - firewall_main_flag_operation_show_mangle_e = 0x80, - firewall_main_flag_operation_show_filter_e = 0x100, - firewall_main_flag_operation_show_filter_nat_mangle_e = 0x1c0, - firewall_main_flag_operation_start_e = 0x200, - firewall_main_flag_operation_start_restart_e = 0x210, - firewall_main_flag_operation_stop_e = 0x400, - firewall_main_flag_operation_stop_restart_e = 0x410, - firewall_main_flag_operation_stop_restart_lock_e = 0x418, - firewall_main_flag_pipe_e = 0x800, - firewall_main_flag_print_first_e = 0x1000, - firewall_main_flag_print_last_e = 0x2000, - firewall_main_flag_version_e = 0x4000, - firewall_main_flag_version_copyright_help_e = 0x4003, + firewall_main_flag_operation_e = 0x31c, + firewall_main_flag_operation_lock_e = 0x4, + firewall_main_flag_operation_restart_e = 0x8, + firewall_main_flag_operation_show_e = 0x10, + firewall_main_flag_operation_show_nat_e = 0x20, + firewall_main_flag_operation_show_mangle_e = 0x40, + firewall_main_flag_operation_show_filter_e = 0x80, + firewall_main_flag_operation_show_filter_nat_mangle_e = 0xe0, + firewall_main_flag_operation_start_e = 0x100, + firewall_main_flag_operation_start_restart_e = 0x108, + firewall_main_flag_operation_stop_e = 0x200, + firewall_main_flag_operation_stop_restart_e = 0x208, + firewall_main_flag_operation_stop_restart_lock_e = 0x20c, + firewall_main_flag_pipe_e = 0x400, + firewall_main_flag_print_first_e = 0x800, + firewall_main_flag_print_last_e = 0x1000, + firewall_main_flag_version_e = 0x2000, + firewall_main_flag_version_copyright_help_e = 0x2003, }; // enum #endif // _di_firewall_main_flag_e_ diff --git a/level_3/firewall/c/main/operate.c b/level_3/firewall/c/main/operate.c index 62c478a..e9ee255 100644 --- a/level_3/firewall/c/main/operate.c +++ b/level_3/firewall/c/main/operate.c @@ -356,6 +356,7 @@ extern "C" { parameters.array = show_arrays[i]; parameters.used = show_lengths[i]; + return_code = 0; firewall_print_message_show_header(&main->program.output, show_lefts[i], show_headers[i], show_rights[i]); diff --git a/level_3/firewall/c/main/print/message.c b/level_3/firewall/c/main/print/message.c index 7c6bf35..18879c0 100644 --- a/level_3/firewall/c/main/print/message.c +++ b/level_3/firewall/c/main/print/message.c @@ -47,7 +47,7 @@ extern "C" { fl_print_format("%[%Q%] ", print->to, print->set->standout, left, print->set->standout); } - fll_print_format("%[%Q%]", print->to, print->set->standout, print->set->standout, print->set->title, print->set->title, print->set->standout, print->set->standout, f_string_eol_s); + fll_print_format("%[%Q%]", print->to, print->set->title, header, print->set->title, f_string_eol_s); if (left.used) { fl_print_format(" %[%Q%]", print->to, print->set->standout, right, print->set->standout); diff --git a/level_3/firewall/c/main/print/warning.c b/level_3/firewall/c/main/print/warning.c index fae2355..2d44f2b 100644 --- a/level_3/firewall/c/main/print/warning.c +++ b/level_3/firewall/c/main/print/warning.c @@ -67,7 +67,7 @@ extern "C" { else { fl_print_format(" %[the object '%]", print->to, print->context, print->prefix, print->context); fl_print_format(f_string_format_Q_range_single_s.string, print->to, print->notable, buffer, range, print->notable); - fl_print_format("%[' has no content.%]%r", print->to, print->context, print->context, f_string_eol_s); + fl_print_format("%[' is invalid.%]%r", print->to, print->context, print->context, f_string_eol_s); } f_file_stream_unlock(print->to); -- 1.8.3.1