]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Use new version of register_symbol in rspamd plugins
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Apr 2016 09:41:29 +0000 (10:41 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Apr 2016 09:41:29 +0000 (10:41 +0100)
16 files changed:
src/lua/lua_config.c
src/plugins/lua/dcc.lua
src/plugins/lua/dmarc.lua
src/plugins/lua/emails.lua
src/plugins/lua/forged_recipients.lua
src/plugins/lua/ip_score.lua
src/plugins/lua/maillist.lua
src/plugins/lua/mime_types.lua
src/plugins/lua/multimap.lua
src/plugins/lua/once_received.lua
src/plugins/lua/phishing.lua
src/plugins/lua/ratelimit.lua
src/plugins/lua/rbl.lua
src/plugins/lua/spamassassin.lua
src/plugins/lua/trie.lua
src/plugins/lua/whitelist.lua

index a974a7f5278b0842810354ca7021d9797614ec85..0737584c5f449cc7617292549f9b60ea0efe084f 100644 (file)
@@ -968,6 +968,9 @@ lua_parse_symbol_type (const gchar *str)
                else if (strcmp (str, "normal") == 0) {
                        ret = SYMBOL_TYPE_NORMAL;
                }
+               else {
+                       msg_warn ("bad type: %s", str);
+               }
        }
 
        return ret;
@@ -1019,10 +1022,10 @@ lua_config_register_symbol (lua_State * L)
 
                type = lua_parse_symbol_type (type_str);
 
-               if (!name && type != SYMBOL_TYPE_CALLBACK) {
+               if (!name && !(type & SYMBOL_TYPE_CALLBACK)) {
                        return luaL_error (L, "no symbol name but type is not callback");
                }
-               else if (type != SYMBOL_TYPE_VIRTUAL && cbref == -1) {
+               else if (!(type & SYMBOL_TYPE_VIRTUAL) && cbref == -1) {
                        return luaL_error (L, "no callback for symbol %s", name);
                }
 
index 9dc7a8ea9d190e88e255e678c3abbcc3ea4adec1..216139fabd238d585d1d00a64b395e1b19a19b10 100644 (file)
@@ -116,7 +116,10 @@ end
 
 -- Configuration
 if opts and opts['host'] then
-  rspamd_config:register_symbol(symbol_bulk, 1.0, check_dcc)
+  rspamd_config:register_symbol({
+    name = symbol_bulk,
+    callback = check_dcc
+  })
   rspamd_config:set_metric_symbol({
     group = 'dcc',
     score = 2.0,
index fd0e9912a1789a88fd392155f9b806c63565f28e..924b020179d9f70b4546dd3dd9df680e1d136d7a 100644 (file)
@@ -306,12 +306,33 @@ if dkim_opts then
   check_mopt('dkim_allow_symbol', 'symbol_allow')
 end
 
-local id = rspamd_config:register_callback_symbol('DMARC_CALLBACK', 1.0,
-  dmarc_callback)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_ALLOW', -1, id)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_REJECT', 1, id)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_QUARANTINE', 1, id)
-rspamd_config:register_virtual_symbol('DMARC_POLICY_SOFTFAIL', 1, id)
+local id = rspamd_config:register_symbol({
+  name = 'DMARC_CALLBACK',
+  type = 'callback',
+  callback = dmarc_callback
+})
+rspamd_config:register_symbol({
+  name = 'DMARC_POLICY_ALLOW',
+  flags = 'nice',
+  parent = id,
+  type = 'virtual'
+})
+rspamd_config:register_symbol({
+  name = 'DMARC_POLICY_REJECT',
+  parent = id,
+  type = 'virtual'
+})
+rspamd_config:register_symbol({
+  name = 'DMARC_POLICY_QUARANTINE',
+  parent = id,
+  type = 'virtual'
+})
+rspamd_config:register_symbol({
+  name = 'DMARC_POLICY_SOFTFAIL',
+  parent = id,
+  type = 'virtual'
+})
+
 rspamd_config:register_dependency(id, symbols['spf_allow_symbol'])
 rspamd_config:register_dependency(id, symbols['dkim_allow_symbol'])
 
index 621bc6a01d05f0f3c9c318fe0b19703ff146f38a..32dc001039abc0d5fa585f09defd5e09c609bbf2 100644 (file)
@@ -38,10 +38,10 @@ local function check_email_rule(task, rule, addr)
     else
       to_resolve = string.format('%s.%s.%s', addr:get_user(), addr:get_host(), rule['dnsbl'])
     end
-    
+
     task:get_resolver():resolve_a({
-      task=task, 
-      name = to_resolve, 
+      task=task,
+      name = to_resolve,
       callback = emails_dns_cb})
   elseif rule['map'] then
     if rule['domain_only'] then
@@ -74,7 +74,7 @@ local function check_emails(task)
           check_email_rule(task, rule, addr)
         end
         checked[to_check] = true
-      end 
+      end
     end
   end
 end
@@ -102,8 +102,15 @@ end
 
 if table.maxn(rules) > 0 then
   -- add fake symbol to check all maps inside a single callback
-  local id = rspamd_config:register_callback_symbol(1.0, check_emails)
+  local id = rspamd_config:register_symbol({
+    type = 'callback',
+    callback = check_emails
+  })
   for _,rule in ipairs(rules) do
-    rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id)
+    rspamd_config:register_symbol({
+      name = rule['symbol'],
+      type = 'virtual',
+      parent = id
+    })
   end
 end
index 533626748c93fb4450b767ff2a52610239a833dd..a9347a685a3b0cd994a677f9812e9c209915ac65 100644 (file)
@@ -22,74 +22,76 @@ local symbol_rcpt = 'FORGED_RECIPIENTS'
 local symbol_sender = 'FORGED_SENDER'
 
 local function check_forged_headers(task)
-       local smtp_rcpt = task:get_recipients(1)
-       local res = false
-       local score = 1.0
+  local smtp_rcpt = task:get_recipients(1)
+  local res = false
+  local score = 1.0
 
-       if smtp_rcpt then
-               local mime_rcpt = task:get_recipients(2)
-               local count = 0
-               if mime_rcpt then
-                       count = table.maxn(mime_rcpt)
-               end
-               if count > 0 and count < table.maxn(smtp_rcpt) then
-                       task:insert_result(symbol_rcpt, 1)
-               elseif count > 0 then
-                       -- Find pair for each smtp recipient recipient in To or Cc headers
-                       for _,sr in ipairs(smtp_rcpt) do
-                               if mime_rcpt then
-                                       for _,mr in ipairs(mime_rcpt) do
-                                               if mr['addr'] and sr['addr'] and
-                                                               string.lower(mr['addr']) == string.lower(sr['addr']) then
-                                                       res = true
-                                                       break
-                                               elseif mr['user'] and sr['user'] and
-                                                               string.lower(mr['user']) == string.lower(sr['user']) then
-                                                       -- If we have the same username but for another domain, then
-                                                       -- lower the overall score
-                                                       score = score / 2
-                                               end
-                                       end
-                               end
-                               if not res then
-                                       task:insert_result(symbol_rcpt, score)
-                                       break
-                               end
-                       end
-               end
-       end
-       -- Check sender
-       local smtp_from = task:get_from(1)
-       if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then
-               local mime_from = task:get_from(2)
-               if not mime_from or not mime_from[1] or
-                 not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
-                       task:insert_result(symbol_sender, 1)
-               end
-       end
-end
-
--- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
-       if rspamd_config:get_api_version() >= 1 then
-               rspamd_config:register_module_option('forged_recipients', 'symbol_rcpt', 'string')
-               rspamd_config:register_module_option('forged_recipients', 'symbol_sender', 'string')
-       end
+  if smtp_rcpt then
+    local mime_rcpt = task:get_recipients(2)
+    local count = 0
+    if mime_rcpt then
+      count = table.maxn(mime_rcpt)
+    end
+    if count > 0 and count < table.maxn(smtp_rcpt) then
+      task:insert_result(symbol_rcpt, 1)
+    elseif count > 0 then
+      -- Find pair for each smtp recipient recipient in To or Cc headers
+      for _,sr in ipairs(smtp_rcpt) do
+        if mime_rcpt then
+          for _,mr in ipairs(mime_rcpt) do
+            if mr['addr'] and sr['addr'] and
+              string.lower(mr['addr']) == string.lower(sr['addr']) then
+              res = true
+              break
+            elseif mr['user'] and sr['user'] and
+              string.lower(mr['user']) == string.lower(sr['user']) then
+              -- If we have the same username but for another domain, then
+              -- lower the overall score
+              score = score / 2
+            end
+          end
+        end
+        if not res then
+          task:insert_result(symbol_rcpt, score)
+          break
+        end
+      end
+    end
+  end
+  -- Check sender
+  local smtp_from = task:get_from(1)
+  if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then
+    local mime_from = task:get_from(2)
+    if not mime_from or not mime_from[1] or
+      not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
+      task:insert_result(symbol_sender, 1)
+    end
+  end
 end
 
 -- Configuration
 local opts =  rspamd_config:get_all_opt('forged_recipients')
 if opts then
-       if opts['symbol_rcpt'] or opts['symbol_sender'] then
-    local id = rspamd_config:register_callback_symbol(1.0,
-      check_forged_headers)
-               if opts['symbol_rcpt'] then
-                       symbol_rcpt = opts['symbol_rcpt']
-                       rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, id)
-               end
-               if opts['symbol_sender'] then
-                       symbol_sender = opts['symbol_sender']
-                       rspamd_config:register_virtual_symbol(symbol_sender, 1.0, id)
-               end
-       end
+  if opts['symbol_rcpt'] or opts['symbol_sender'] then
+    local id = rspamd_config:register_symbol({
+      callback = check_forged_headers,
+      type = 'callback',
+    })
+    if opts['symbol_rcpt'] then
+      symbol_rcpt = opts['symbol_rcpt']
+      rspamd_config:register_symbol({
+        name = symbol_rcpt,
+        type = 'virtual',
+        parent = id,
+      })
+    end
+    if opts['symbol_sender'] then
+      symbol_sender = opts['symbol_sender']
+       rspamd_config:register_symbol({
+        name = symbol_sender,
+        type = 'virtual',
+        parent = id,
+      })
+    end
+  end
 end
index c18e11e0a4230ed4a042e470b225fdc03ddac55f..7d12f1a5e28a590d9cac69c8cf4b93688934a211 100644 (file)
@@ -355,6 +355,9 @@ if upstreams then
   if options['asn_provider'] then
     rspamd_config:register_pre_filter(asn_check)
   end
-  rspamd_config:register_symbol(options['symbol'], 1.0, ip_score_check)
+  rspamd_config:register_symbol({
+    name = options['symbol'],
+    callback = ip_score_check
+  })
   rspamd_config:register_post_filter(ip_score_set)
 end
index 5f683a0039ffc62451c6194f1f4289bc27a6a26f..42cdc917698d17e9ae81a597850fd971ecf6fe82 100644 (file)
@@ -267,16 +267,15 @@ local function check_maillist(task)
     task:insert_result(symbol, 0.5, 'generic')
   end
 end
--- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
-  if rspamd_config:get_api_version() >= 1 then
-    rspamd_config:register_module_option('maillist', 'symbol', 'string')
-  end
-end
+
+
 -- Configuration
 local opts =  rspamd_config:get_all_opt('maillist')if opts then
   if opts['symbol'] then
     symbol = opts['symbol']
-    rspamd_config:register_symbol(symbol, 1.0, check_maillist)
+    rspamd_config:register_symbol({
+      name = symbol,
+      callback = check_maillist
+    })
   end
 end
index 2c168393b8dffb111bb6720f94a10f38c2069d37..f51e20cb7a4ee76cf118f3b78fa617619f702c57 100644 (file)
@@ -115,10 +115,26 @@ if opts then
         description = 'mime types map'
       })
     end
-    local id = rspamd_config:register_callback_symbol(1.0, check_mime_type)
-    rspamd_config:register_virtual_symbol(settings['symbol_unknown'], 1.0, id)
-    rspamd_config:register_virtual_symbol(settings['symbol_bad'], 1.0, id)
-    rspamd_config:register_virtual_symbol(settings['symbol_good'], 1.0, id)
-    rspamd_config:register_virtual_symbol(settings['symbol_attachment'], 1.0, id)
+    local id = rspamd_config:register_symbol({
+      callback = check_mime_type,
+      type = 'callback'
+    })
+
+    rspamd_config:register_symbol({
+      type = 'virtual',
+      name = settings['symbol_unknown'],
+      parent = id
+    })
+    rspamd_config:register_symbol({
+      type = 'virtual',
+      name = settings['symbol_good'],
+      flags = 'nice',
+      parent = id
+    })
+    rspamd_config:register_symbol({
+      type = 'virtual',
+      name = settings['symbol_attachment'],
+      parent = id
+    })
   end
 end
index d89b90aab235383f1a4807d692b456b0380bc79c..9f0d9284933bf0d918b24536c17b9800077a1ed9 100644 (file)
@@ -482,10 +482,18 @@ if opts and type(opts) == 'table' then
   end
   -- add fake symbol to check all maps inside a single callback
   if _.any(function(r) return not r['prefilter'] end, rules) then
-    local id = rspamd_config:register_callback_symbol_priority(1.0, -1,
-      multimap_filter_callback)
+    local id = rspamd_config:register_symbol({
+      type = 'callback',
+      priority = -1,
+      callback = multimap_filter_callback,
+      flags = 'empty'
+    })
     for i,rule in ipairs(rules) do
-      rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id)
+      rspamd_config:register_symbol({
+        type = 'virtual',
+        name = rule['symbol'],
+        parent = id,
+      })
     end
   end
 
index d192c0b794446230733e09880e7c53c304727836..274504cf2645e011b9f5ef31d26d5512709adaea 100644 (file)
@@ -144,7 +144,11 @@ if opts then
   if opts['symbol'] then
     local symbol = opts['symbol']
 
-    local id = rspamd_config:register_symbol(symbol, 1.0, check_quantity_received)
+    local id = rspamd_config:register_symbol({
+      name = symbol,
+      callback = check_quantity_received,
+      type = 'callback',
+    })
 
     for n,v in pairs(opts) do
       if n == 'symbol_strict' then
@@ -167,7 +171,16 @@ if opts then
         whitelist = rspamd_config:add_radix_map (v, 'once received whitelist')
       end
     end
-    rspamd_config:register_virtual_symbol(symbol_rdns, 1.0, id)
-    rspamd_config:register_virtual_symbol(symbol_strict, 1.0, id)
+
+    rspamd_config:register_symbol({
+      name = symbol_rdns,
+      type = 'virtual',
+      parent = id
+    })
+      rspamd_config:register_symbol({
+      name = symbol_strict,
+      type = 'virtual',
+      parent = id
+    })
   end
 end
index d2b85dac582ab67b22abd8c346e5854d01495927..338d16fdddfc0a415fa0e04f61d85be10ddd8b8f 100644 (file)
@@ -108,21 +108,15 @@ local function phishing_map(mapname, phishmap)
   end
 end
 
--- Registration
-if type(rspamd_config.get_api_version) ~= 'nil' then
-  if rspamd_config:get_api_version() >= 1 then
-    rspamd_config:register_module_option('phishing', 'symbol', 'string')
-    rspamd_config:register_module_option('phishing', 'domains', 'map')
-    rspamd_config:register_module_option('phishing', 'strict_domains', 'string')
-    rspamd_config:register_module_option('phishing', 'redirector_domains', 'string')
-  end
-end
 
 if opts then
   if opts['symbol'] then
     symbol = opts['symbol']
     -- Register symbol's callback
-    rspamd_config:register_symbol(symbol, 1.0, phishing_cb)
+    rspamd_config:register_symbol({
+      name = symbol,
+      callback = phishing_cb
+    })
   end
   if opts['domains'] and type(opt['domains']) == 'string' then
     domains = rspamd_config:add_hash_map (opts['domains'])
index a6328eb4ddd03d8983be7d520cc85bcece3e9891..2604423e8351556c31bbb0d6e8303a938d156820 100644 (file)
@@ -435,7 +435,11 @@ if opts then
       if not ratelimit_symbol then
         rspamd_config:register_pre_filter(rate_test)
       else
-        rspamd_config:register_symbol(ratelimit_symbol, 1.0, rate_test)
+        rspamd_config:register_symbol({
+          name = ratelimit_symbol,
+          callback = rate_test,
+          flags = 'empty'
+        })
       end
 
       rspamd_config:register_post_filter(rate_set)
index 45880d5a33056c11fbb05f14e08680a72cf0b13e..91e20dc5b83774fc812134964990bed4da1744a8 100644 (file)
@@ -363,7 +363,11 @@ local white_symbols = {}
 local black_symbols = {}
 local need_dkim = false
 
-local id = rspamd_config:register_callback_symbol_priority(1.0, 0, rbl_cb)
+local id = rspamd_config:register_symbol({
+  type = 'callback',
+  callback = rbl_cb,
+  flags = 'empty,nice'
+})
 
 for key,rbl in pairs(opts['rbls']) do
   for default, default_v in pairs(default_defaults) do
@@ -374,7 +378,12 @@ for key,rbl in pairs(opts['rbls']) do
   if type(rbl['returncodes']) == 'table' then
     for s,_ in pairs(rbl['returncodes']) do
       if type(rspamd_config.get_api_version) ~= 'nil' then
-        rspamd_config:register_virtual_symbol(s, 1, id)
+        rspamd_config:register_symbol({
+          name = s,
+          parent = id,
+          type = 'virtual'
+        })
+
         if rbl['dkim'] then
           need_dkim = true
         end
@@ -411,7 +420,12 @@ for key,rbl in pairs(opts['rbls']) do
       rbl['symbol'] = key
   end
   if type(rspamd_config.get_api_version) ~= 'nil' and rbl['symbol'] then
-    rspamd_config:register_virtual_symbol(rbl['symbol'], 1, id)
+    rspamd_config:register_symbol({
+      name = rbl['symbol'],
+      parent = id,
+      type = 'virtual'
+    })
+
     if rbl['dkim'] then
       need_dkim = true
     end
index e025714ceb8a8549180ae131e082992cb7fb2368..f90a838c301e264613eb66142c32be3094698a11 100644 (file)
@@ -1419,7 +1419,11 @@ local function post_process()
             one_shot = true })
           scores_added[k] = 1
         end
-        rspamd_config:register_symbol(k, calculate_score(k, r), meta_cb)
+        rspamd_config:register_symbol({
+          name = k,
+          weight = calculate_score(k, r),
+          callback = meta_cb
+        })
         r['expression'] = expression
         if not atoms[k] then
           atoms[k] = meta_cb
index 7295c907fd8f97990e53acea596079f20985dc1f..4a1fdfd4ee1731df3e480f21984984f7ebfd9f0b 100644 (file)
@@ -27,13 +27,13 @@ local raw_trie
 local mime_patterns = {}
 local raw_patterns = {}
 
--- here we store params for each pattern, so for each i = 1..n patterns[i] 
+-- here we store params for each pattern, so for each i = 1..n patterns[i]
 -- should have corresponding params[i]
 local mime_params = {}
 local raw_params = {}
 
 local function tries_callback(task)
-  
+
   local matched = {}
 
   local function gen_trie_cb(raw)
@@ -43,11 +43,11 @@ local function tries_callback(task)
       patterns = raw_patterns
       params = raw_params
     end
-    
+
     return function (idx, pos)
       local param = params[idx]
       local pattern = patterns[idx]
-      
+
       if param['multi'] or not matched[pattern] then
         rspamd_logger.debugx(task, "<%1> matched pattern %2 at pos %3",
           task:get_message_id(), pattern, pos)
@@ -58,7 +58,7 @@ local function tries_callback(task)
       end
     end
   end
-  
+
   if mime_trie then
     mime_trie:search_mime(task, gen_trie_cb(false))
   end
@@ -71,7 +71,7 @@ local function process_single_pattern(pat, symbol, cf)
   if pat then
     local multi = false
     if cf['multi'] then multi = true end
-    
+
     if cf['raw'] then
       table.insert(raw_patterns, pat)
       table.insert(raw_params, {symbol=symbol, multi=multi})
@@ -84,7 +84,7 @@ end
 
 local function process_trie_file(symbol, cf)
   file = io.open(cf['file'])
-  
+
   if not file then
     rspamd_logger.errx(rspamd_config, 'Cannot open trie file %1', cf['file'])
   else
@@ -102,15 +102,15 @@ end
 
 local function process_trie_conf(symbol, cf)
   local raw = false
-  
+
   if type(cf) ~= 'table' then
     rspamd_logger.errx(rspamd_config, 'invalid value for symbol %1: "%2", expected table',
       symbol, cf)
     return
   end
-  
+
   if cf['raw'] then raw = true end
-  
+
   if cf['file'] then
     process_trie_file(symbol, cf)
   elseif cf['patterns'] then
@@ -125,7 +125,7 @@ if opts then
   for sym, opt in pairs(opts) do
      process_trie_conf(sym, opt)
   end
-  
+
   if #raw_patterns > 0 then
     raw_trie = rspamd_trie.create(raw_patterns)
     rspamd_logger.infox(rspamd_config, 'registered raw search trie from %1 patterns', #raw_patterns)
@@ -135,17 +135,24 @@ if opts then
     mime_trie = rspamd_trie.create(mime_patterns)
     rspamd_logger.infox(rspamd_config, 'registered mime search trie from %1 patterns', #mime_patterns)
   end
-  
+
   local id = -1
   if mime_trie or raw_trie then
-    id = rspamd_config:register_callback_symbol('TRIE', 1.0, tries_callback)
+    id = rspamd_config:register_symbol({
+      type = 'callback',
+      callback = tries_callback
+    })
   else
     rspamd_logger.errx(rspamd_config, 'no tries defined')
   end
-  
+
   if id ~= -1 then
     for sym, opt in pairs(opts) do
-      rspamd_config:register_virtual_symbol(sym, 1.0, id)
+      rspamd_config:register_symbol({
+        name = sym,
+        type = 'virtual',
+        parent = id
+      })
     end
   end
 end
index 202d854657db94cd7b752d22190bb9870bbca86b..8c4f4cbcc0be6fa570f07648396af109be4f6335 100644 (file)
@@ -180,8 +180,11 @@ local configure_whitelist_module = function()
           return
         end
 
-        local id = rspamd_config:register_symbol(symbol, -1.0,
-          gen_whitelist_cb(symbol, rule))
+        local id = rspamd_config:register_symbol({
+          name = symbol,
+          flags = 'nice,empty',
+          callback = gen_whitelist_cb(symbol, rule)
+        })
 
         if rule['valid_spf'] then
           rspamd_config:register_dependency(id, options['spf_allow_symbol'])