diff --git a/lib/puppet/provider/firewall/firewall.rb b/lib/puppet/provider/firewall/firewall.rb index 503a1b57e..61bfc1acc 100644 --- a/lib/puppet/provider/firewall/firewall.rb +++ b/lib/puppet/provider/firewall/firewall.rb @@ -19,7 +19,7 @@ class Puppet::Provider::Firewall::Firewall # Regex used to retrieve table name $table_name_regex = %r{^\*(nat|mangle|filter|raw|rawpost|broute|security)} # Regex used to retrieve Rules - $rules_regex = %r{(-A.*)\n} + $rules_regex = %r{^(-A.*)\n} # Base command $base_command = { 'IPv4' => 'iptables -t', @@ -466,6 +466,9 @@ def self.get_rules(context, basic, protocols = ['IPv4', 'IPv6']) iptables_list.scan($table_regex).each do |table| table_name = table[0].scan($table_name_regex)[0][0] table[0].scan($rules_regex).each do |rule| + # iptables-save escapes ' symbol in it's output for some reason which leads to an incorrect command + # We need to manually replace \' to ' + rule[0].gsub!("\\'", "'") raw_rules = if basic Puppet::Provider::Firewall::Firewall.rule_to_name(context, rule[0], table_name, protocol) else @@ -489,7 +492,7 @@ def self.rule_to_name(_context, rule, table_name, protocol) rule_hash[:table] = table_name rule_hash[:protocol] = protocol - name_regex = Regexp.new("#{$resource_map[:name]}\\s(?:\"([^\"]*)|([^\"\\s]*))") + name_regex = Regexp.new("#{$resource_map[:name]}\\s+(?:\"(.+?(?