]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix is_local_domain to support backend objects
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 8 Oct 2025 10:09:26 +0000 (11:09 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 8 Oct 2025 10:09:26 +0000 (11:09 +0100)
The is_local_domain function was directly accessing module_state.local_domains
as a table, which caused it to always return false when local_domains was
configured as a backend object (MapBackend, CDBBackend, etc).

Fixed by:
- Moving get_from_source helper function before is_local_domain
- Using get_from_source to handle both plain tables and backend objects
- Updating return logic to handle different truthy values from backends

lualib/lua_aliases.lua

index 3a98316b9c53a4290b85e846b1210ec6d819724b..b200185db886c1de18a43cd645781b5d9b9b4339 100644 (file)
@@ -491,6 +491,24 @@ end
 
 exports.parse_local_domains = parse_local_domains
 
+--- Get value from backend or table
+-- @param source backend object or table
+-- @param key lookup key
+-- @return value or nil
+local function get_from_source(source, key)
+  if not source then
+    return nil
+  end
+
+  -- If it's a backend object with :get() method
+  if type(source) == 'table' and source.get then
+    return source:get(key)
+  end
+
+  -- Otherwise treat as plain table
+  return source[key]
+end
+
 --- Check if a domain is local
 -- @param domain domain name to check
 -- @return true if domain is local, false otherwise
@@ -500,13 +518,13 @@ local function is_local_domain(domain)
   end
 
   domain = domain:lower()
-  local result = module_state.local_domains[domain] == true
+  local result = get_from_source(module_state.local_domains, domain)
 
   lua_util.debugm(N, module_state.config,
       'is_local_domain: domain=%s result=%s',
       domain, result)
 
-  return result
+  return result ~= nil and result ~= false
 end
 exports.is_local_domain = is_local_domain
 
@@ -595,24 +613,6 @@ local function apply_service_rules(email_addr)
 end
 exports.apply_service_rules = apply_service_rules
 
---- Get value from backend or table
--- @param source backend object or table
--- @param key lookup key
--- @return value or nil
-local function get_from_source(source, key)
-  if not source then
-    return nil
-  end
-
-  -- If it's a backend object with :get() method
-  if type(source) == 'table' and source.get then
-    return source:get(key)
-  end
-
-  -- Otherwise treat as plain table
-  return source[key]
-end
-
 --- Resolve one step of aliasing
 -- @param email_str normalized email string
 -- @return result (string, array of strings, or nil), rule_type