]> source.dussan.org Git - rspamd.git/commitdiff
Do not parse URLs for getting TLD in lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 21 Dec 2015 09:43:53 +0000 (09:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 21 Dec 2015 09:43:53 +0000 (09:43 +0000)
src/plugins/lua/dmarc.lua
src/plugins/lua/rbl.lua
src/plugins/lua/whitelist.lua

index 01eb3bfb1efe559101e73542d3a3826a2adcd844..f9bf43ccc08a496fcc926f8221fc47cee81dbac8 100644 (file)
@@ -32,6 +32,7 @@ local rspamd_logger = require "rspamd_logger"
 local rspamd_redis = require "rspamd_redis"
 local rspamd_url = require "rspamd_url"
 local upstream_list = require "rspamd_upstream_list"
+local rspamd_util = require "rspamd_util"
 
 --local dumper = require 'pl.pretty'.dump
 
@@ -67,12 +68,7 @@ local function dmarc_callback(task)
   local dmarc_domain
 
   if from and from[1] and from[1]['domain'] and not from[2] then
-    local url_from = rspamd_url.create(task:get_mempool(), from[1]['domain'])
-    if url_from then
-      dmarc_domain = url_from:get_tld()
-    else
-      return
-    end
+    dmarc_domain = rspamd_util.get_tld(from[1]['domain'])
   else
     return
   end
index c1ea77ef168c052881173c2fad4d9e0e96d60fad..0a2b9bdd9c55bc8f855d4521f3755fd9f54737f8 100644 (file)
@@ -36,6 +36,7 @@ local private_ips = nil
 local rspamd_logger = require 'rspamd_logger'
 local rspamd_ip = require 'rspamd_ip'
 local rspamd_url = require 'rspamd_url'
+local rspamd_util = require 'rspamd_util'
 
 local symbols = {
   dkim_allow_symbol = 'R_DKIM_ALLOW',
@@ -163,8 +164,8 @@ local function rbl_cb (task)
            end
          end
          task:get_resolver():resolve_a({task = task,
-           name = havegot['helo'] .. '.' .. rbl['rbl'], 
-           callback = rbl_dns_cb, 
+           name = havegot['helo'] .. '.' .. rbl['rbl'],
+           callback = rbl_dns_cb,
            option = k})
        end)()
       end
@@ -185,17 +186,12 @@ local function rbl_cb (task)
           end
           for _, d in ipairs(havegot['dkim']) do
             if rbl['dkim_domainonly'] then
-              local url_from = rspamd_url.create(task:get_mempool(), d)
-              if url_from then
-                d = url_from:get_tld()
-              else
-                return
-              end
+              d = rspamd_util.get_tld(d)
             end
-            
+
             task:get_resolver():resolve_a({task = task,
-              name = d .. '.' .. rbl['rbl'], 
-              callback = rbl_dns_cb, 
+              name = d .. '.' .. rbl['rbl'],
+              callback = rbl_dns_cb,
               option = k})
           end
         end)()
@@ -224,7 +220,7 @@ local function rbl_cb (task)
                 if validate_dns(localpart) and validate_dns(domainpart) then
                   table.insert(cleanList, localpart .. '.' .. domainpart)
                 end
-              end 
+              end
             end
             havegot['emails'] = cleanList
             if not next(havegot['emails']) then
@@ -235,15 +231,15 @@ local function rbl_cb (task)
           if rbl['emails'] == 'domain_only' then
             for domain, _ in pairs(havegot['emails']) do
               task:get_resolver():resolve_a({task = task,
-                name = domain .. '.' .. rbl['rbl'], 
-                callback = rbl_dns_cb, 
+                name = domain .. '.' .. rbl['rbl'],
+                callback = rbl_dns_cb,
                 option = k})
             end
           else
             for _, email in pairs(havegot['emails']) do
               task:get_resolver():resolve_a({task = task,
-                name = email .. '.' .. rbl['rbl'], 
-                callback = rbl_dns_cb, 
+                name = email .. '.' .. rbl['rbl'],
+                callback = rbl_dns_cb,
                 option = k})
             end
           end
@@ -264,7 +260,7 @@ local function rbl_cb (task)
          end
          task:get_resolver():resolve_a({task = task,
            name = havegot['rdns'] .. '.' .. rbl['rbl'],
-           callback = rbl_dns_cb, 
+           callback = rbl_dns_cb,
            option = k})
        end)()
       end
@@ -284,8 +280,8 @@ local function rbl_cb (task)
          if (havegot['from']:get_version() == 6 and rbl['ipv6']) or
            (havegot['from']:get_version() == 4 and rbl['ipv4']) then
            task:get_resolver():resolve_a({task = task,
-             name = ip_to_rbl(havegot['from'], rbl['rbl']), 
-             callback = rbl_dns_cb, 
+             name = ip_to_rbl(havegot['from'], rbl['rbl']),
+             callback = rbl_dns_cb,
              option = k})
          end
        end)()
@@ -311,8 +307,8 @@ local function rbl_cb (task)
                 not rbl['exclude_private_ips']) and ((rbl['exclude_local_ips'] and
                 not is_excluded_ip(rh['real_ip'])) or not rbl['exclude_local_ips']) then
                   task:get_resolver():resolve_a({task = task,
-                    name = ip_to_rbl(rh['real_ip'], rbl['rbl']), 
-                    callback = rbl_dns_cb, 
+                    name = ip_to_rbl(rh['real_ip'], rbl['rbl']),
+                    callback = rbl_dns_cb,
                     option = k})
               end
            end
index 6bcc84bbaa03af313097f024b9c1502f1a56d29b..3028a279fb9dc04f16bba9559697aab98e0da09c 100644 (file)
@@ -26,6 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 local rspamd_logger = require "rspamd_logger"
 local rspamd_url = require "rspamd_url"
+local rspamd_util = require "rspamd_util"
 local ucl = require "ucl"
 require "fun" ()
 
@@ -41,14 +42,10 @@ local function whitelist_cb(symbol, rule, task)
   local from = task:get_from(1)
   if from and from[1] and from[1]['domain'] then
     local domain = from[1]['domain']
-    local url_domain = rspamd_url.create(task:get_mempool(), 'http://' .. domain)
+    domain = rspamd_util.get_tld(domain)
     local found = false
     local mult = 1.0
 
-    if url_domain then
-      domain = url_domain:get_tld()
-    end
-
     if rule['map'] then
       local val = rule['map']:get_key(domain)
       if val then
@@ -191,4 +188,4 @@ local configure_whitelist_module = function()
   end
 end
 
-configure_whitelist_module()
\ No newline at end of file
+configure_whitelist_module()