From 36d4a2e9a84914ff3b31399b8b40662fdb8d5260 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Thu, 28 Apr 2022 18:58:11 +0200 Subject: [PATCH] Improve legacy config parsing --- CHANGELOG | 1 + minifirewall | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 20c4908..5f82a8d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ and this project **does not adhere to [Semantic Versioning](http://semver.org/sp * use long options in some places * output is normalized * source legacy config after macros but before DROP policy +* improve legacy config parsing ### Deprecated diff --git a/minifirewall b/minifirewall index a7c8aff..5a0a89f 100755 --- a/minifirewall +++ b/minifirewall @@ -214,7 +214,8 @@ source_configuration() { exit 1 fi - if grep -e "iptables" -e "ip6tables" "${config_file}" | grep -qvE "^#"; then + # If we find something other than a blank line, a comment or a variable assignment + if grep --quiet --extended-regexp --invert-match "^\s*(#|$|\w+=)" "${config_file}"; then # Backward compatible mode ########################### @@ -240,7 +241,8 @@ source_configuration() { # and not interfere with the configuration step. tmp_config_file=$(mktemp --tmpdir=/tmp minifirewall.XXX) - grep -E "^\s*[_a-zA-Z0-9]+=" "${config_file}" > "${tmp_config_file}" + # get only variable assignments + grep -E "^\s*\w+=" "${config_file}" > "${tmp_config_file}" source_file_or_error "${tmp_config_file}" rm -f "${tmp_config_file}"