Changeset

2928:b0d92332b87f

mod_firewall: Add special case for $local zone (fixes #1090)
author Kim Alvefur <zash@zash.se>
date Mon, 12 Mar 2018 12:26:15 +0100
parents 2927:7953b7dde6e7
children 2929:3a104a900af1
files mod_firewall/conditions.lib.lua mod_firewall/mod_firewall.lua
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_firewall/conditions.lib.lua	Sat Mar 10 05:01:15 2018 +0100
+++ b/mod_firewall/conditions.lib.lua	Mon Mar 12 12:26:15 2018 +0100
@@ -87,12 +87,14 @@
 end
 
 local function zone_check(zone, which)
+	local zone_var = zone;
+	if zone == "$local" then zone_var = "_local" end
 	local which_not = which == "from" and "to" or "from";
 	return ("(zone_%s[%s_host] or zone_%s[%s] or zone_%s[bare_%s]) "
 		.."and not(zone_%s[%s_host] or zone_%s[%s] or zone_%s[bare_%s])"
 		)
-		:format(zone, which, zone, which, zone, which,
-		zone, which_not, zone, which_not, zone, which_not), {
+		:format(zone_var, which, zone_var, which, zone_var, which,
+		zone_var, which_not, zone_var, which_not, zone_var, which_not), {
 			"split_to", "split_from", "bare_to", "bare_from", "zone:"..zone
 		};
 end
--- a/mod_firewall/mod_firewall.lua	Sat Mar 10 05:01:15 2018 +0100
+++ b/mod_firewall/mod_firewall.lua	Mon Mar 12 12:26:15 2018 +0100
@@ -183,8 +183,13 @@
 	is_admin = { global_code = [[local is_admin = require "core.usermanager".is_admin;]]};
 	core_post_stanza = { global_code = [[local core_post_stanza = prosody.core_post_stanza;]] };
 	zone = { global_code = function (zone)
-		assert(idsafe(zone), "Invalid zone name: "..zone);
-		return ("local zone_%s = zones[%q] or {};"):format(zone, zone);
+		local var = zone;
+		if var == "$local" then
+			var = "_local"; -- See #1090
+		else
+			assert(idsafe(var), "Invalid zone name: "..zone);
+		end
+		return ("local zone_%s = zones[%q] or {};"):format(var, zone);
 	end };
 	date_time = { global_code = [[local os_date = os.date]]; local_code = [[local current_date_time = os_date("*t");]] };
 	time = { local_code = function (what)