}
}
+gboolean
+rspamd_check_module (struct rspamd_config *cfg, module_t *mod)
+{
+ gboolean ret = TRUE;
+
+ if (mod != NULL) {
+ if (mod->module_version != RSPAMD_CUR_MODULE_VERSION) {
+ msg_err_config ("module %s has incorrect version %xd (%xd expected)",
+ mod->name, mod->module_version, RSPAMD_CUR_MODULE_VERSION);
+ ret = FALSE;
+ }
+ if (ret && mod->rspamd_version != RSPAMD_VERSION_NUM) {
+ msg_err_config ("module %s has incorrect rspamd version %xd (%xd expected)",
+ mod->name, mod->rspamd_version, RSPAMD_VERSION_NUM);
+ ret = FALSE;
+ }
+ if (ret && strcmp (mod->rspamd_features, RSPAMD_FEATURES) != 0) {
+ msg_err_config ("module %s has incorrect rspamd features '%s' ('%s' expected)",
+ mod->name, mod->rspamd_features, RSPAMD_FEATURES);
+ ret = FALSE;
+ }
+ }
+ else {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
+gboolean
+rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk)
+{
+ gboolean ret = TRUE;
+
+ if (wrk != NULL) {
+ if (wrk->worker_version != RSPAMD_CUR_WORKER_VERSION) {
+ msg_err_config ("worker %s has incorrect version %xd (%xd expected)",
+ wrk->name, wrk->worker_version, RSPAMD_CUR_WORKER_VERSION);
+ ret = FALSE;
+ }
+ if (ret && wrk->rspamd_version != RSPAMD_VERSION_NUM) {
+ msg_err_config ("worker %s has incorrect rspamd version %xd (%xd expected)",
+ wrk->name, wrk->rspamd_version, RSPAMD_VERSION_NUM);
+ ret = FALSE;
+ }
+ if (ret && strcmp (wrk->rspamd_features, RSPAMD_FEATURES) != 0) {
+ msg_err_config ("worker %s has incorrect rspamd features '%s' ('%s' expected)",
+ wrk->name, wrk->rspamd_features, RSPAMD_FEATURES);
+ ret = FALSE;
+ }
+ }
+ else {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
gboolean
rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
{
if (!reconfig) {
for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod ++) {
mod = *pmod;
- mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
- if (mod->module_init_func (cfg, &mod_ctx) == 0) {
- g_hash_table_insert (cfg->c_modules,
- (gpointer) mod->name,
- mod_ctx);
- mod_ctx->mod = mod;
+ if (rspamd_check_module (cfg, mod)) {
+ mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
+
+ if (mod->module_init_func (cfg, &mod_ctx) == 0) {
+ g_hash_table_insert (cfg->c_modules,
+ (gpointer) mod->name,
+ mod_ctx);
+ mod_ctx->mod = mod;
+ }
}
}
+
+ cur = g_list_first (cfg->dynamic_modules);
+
+ while (cur) {
+ mod = cur->data;
+
+ if (rspamd_check_module (cfg, mod)) {
+ mod_ctx = g_slice_alloc0 (sizeof (struct module_ctx));
+
+ if (mod->module_init_func (cfg, &mod_ctx) == 0) {
+ g_hash_table_insert (cfg->c_modules,
+ (gpointer) mod->name,
+ mod_ctx);
+ mod_ctx->mod = mod;
+ }
+ }
+
+ cur = g_list_next (cur);
+ }
}
+ /* Now check what's enabled */
cur = g_list_first (cfg->filters);
while (cur) {
worker_t *
rspamd_get_worker_by_type (struct rspamd_config *cfg, GQuark type)
{
- worker_t **cur;
+ worker_t **pwrk, *wrk;
+ GList *cur;
- cur = cfg->compiled_workers;
- while (cur && *cur) {
- if (g_quark_from_string ((*cur)->name) == type) {
- return *cur;
+ pwrk = cfg->compiled_workers;
+ while (pwrk && *pwrk) {
+ if (rspamd_check_worker (cfg, *pwrk)) {
+ if (g_quark_from_string ((*pwrk)->name) == type) {
+ return *pwrk;
+ }
}
- cur++;
+
+ pwrk++;
+ }
+
+ cur = g_list_first (cfg->dynamic_workers);
+ while (cur) {
+ wrk = cur->data;
+
+ if (rspamd_check_worker (cfg, wrk)) {
+ if (g_quark_from_string (wrk->name) == type) {
+ return wrk;
+ }
+ }
+
+ cur = g_list_next (cur);
}
return NULL;
#define RSPAMD_FEATURE_SNOWBALL "1"
#endif
+#define RSPAMD_CUR_MODULE_VERSION 0x1
+#define RSPAMD_CUR_WORKER_VERSION 0x1
+
#define RSPAMD_FEATURES \
RSPAMD_FEATURE_HYPERSCAN RSPAMD_FEATURE_PCRE2 \
RSPAMD_FEATURE_FANN RSPAMD_FEATURE_SNOWBALL
#define RSPAMD_MODULE_VER \
- 0x1, /* Module version */ \
+ RSPAMD_CUR_MODULE_VERSION, /* Module version */ \
RSPAMD_VERSION_NUM, /* Rspamd version */ \
RSPAMD_FEATURES /* Compilation features */ \
#define RSPAMD_WORKER_VER \
- 0x1, /* Worker version */ \
+ RSPAMD_CUR_WORKER_VERSION, /* Worker version */ \
RSPAMD_VERSION_NUM, /* Rspamd version */ \
RSPAMD_FEATURES /* Compilation features */ \
/**
gboolean threaded;
gboolean killable;
gint listen_type;
- guint module_version;
+ guint worker_version;
guint64 rspamd_version;
const gchar *rspamd_features;
} worker_t;
+/**
+ * Check if loaded worker is compatible with rspamd
+ * @param cfg
+ * @param wrk
+ * @return
+ */
+gboolean rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk);
+
+/**
+ * Check if loaded module is compatible with rspamd
+ * @param cfg
+ * @param wrk
+ * @return
+ */
+gboolean rspamd_check_module (struct rspamd_config *cfg, module_t *wrk);
+
struct pidfh;
struct rspamd_config;
struct tokenizer;