]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix issues with compatibility tokenization.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Jul 2015 14:32:00 +0000 (15:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 27 Jul 2015 14:32:00 +0000 (15:32 +0100)
src/libstat/stat_process.c
src/libstat/tokenizers/osb.c

index 3ec579049aef9747689a31a0aba8176e98744baa..141b2dfd5a5fc9e2643b58fb3a761551df057bc1 100644 (file)
@@ -157,6 +157,7 @@ rspamd_stat_get_tokenizer_runtime (struct rspamd_tokenizer_config *cf,
 
        tok = rspamd_mempool_alloc (task->task_pool, sizeof (*tok));
        tok->tokenizer = rspamd_stat_get_tokenizer (name);
+       tok->tkcf = cf;
 
        if (tok->tokenizer == NULL) {
                return NULL;
@@ -168,7 +169,6 @@ rspamd_stat_get_tokenizer_runtime (struct rspamd_tokenizer_config *cf,
 
        tok->config = conf;
        tok->conf_len = conf_len;
-       tok->tkcf = cf;
        tok->tokens = g_tree_new (token_node_compare_func);
        rspamd_mempool_add_destructor (task->task_pool,
                        (rspamd_mempool_destruct_t)g_tree_destroy, tok->tokens);
@@ -295,13 +295,17 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx,
                }
 
                cl_runtime->clcf = clcf;
+
                bk = rspamd_stat_get_backend (clcf->backend);
                if (bk == NULL) {
-                       msg_warn ("backend of type %s is not defined", clcf->backend);
-                       cur = g_list_next (cur);
-                       continue;
+                       g_set_error (err, rspamd_stat_quark(), 500,
+                                       "backend %s is not defined", clcf->backend);
+                       g_list_free (cl_runtimes);
+                       return NULL;
                }
 
+               cl_runtime->backend = bk;
+
                curst = st_list;
                while (curst != NULL) {
                        stcf = (struct rspamd_statfile_config *)curst->data;
@@ -348,15 +352,14 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx,
                                        return NULL;
                                }
                        }
-                       else {
-                               if (!cl_runtime->tok->tokenizer->compatible_config (
-                                               cl_runtime->tok, tok_config, conf_len)) {
-                                       g_set_error (err, rspamd_stat_quark(), 500,
-                                                       "incompatible tokenizer for statfile %s", stcf->symbol);
-                                       g_list_free (cl_runtimes);
 
-                                       return NULL;
-                               }
+                       if (!cl_runtime->tok->tokenizer->compatible_config (
+                                       cl_runtime->tok, tok_config, conf_len)) {
+                               g_set_error (err, rspamd_stat_quark(), 500,
+                                               "incompatible tokenizer for statfile %s", stcf->symbol);
+                               g_list_free (cl_runtimes);
+
+                               return NULL;
                        }
 
                        st_runtime = rspamd_mempool_alloc0 (task->task_pool,
index 40dec0d820d25ad04be5607ba045e6b1ebca74c7..bbb2656c23dc143312c77eee03eb1efdfd5fb1a8 100644 (file)
@@ -347,8 +347,16 @@ rspamd_tokenizer_osb_load_config (rspamd_mempool_t *pool,
 {
        struct rspamd_osb_tokenizer_config *osb_cf;
 
-       if (ptr == NULL) {
+       if (ptr == NULL || len == 0) {
                osb_cf = rspamd_tokenizer_osb_config_from_ucl (pool, rt->tkcf->opts);
+
+               if (osb_cf->ht != RSPAMD_OSB_HASH_COMPAT) {
+                       /* Trying to load incompatible configuration */
+                       msg_err ("cannot load tokenizer configuration from a legacy statfile,"
+                                       " maybe you have forgotten to set 'compat' option in the "
+                                       "tokenizer configuration");
+                       return FALSE;
+               }
        }
        else {
                g_assert (len == sizeof (*osb_cf));