summaryrefslogtreecommitdiffstats
path: root/src/settings.c
diff options
context:
space:
mode:
authorcebka@lenovo-laptop <cebka@lenovo-laptop>2009-12-30 15:54:48 +0300
committercebka@lenovo-laptop <cebka@lenovo-laptop>2009-12-30 15:54:48 +0300
commit7d7440b2114b4c81816882433294f9c951bc39e8 (patch)
tree4a8b8c19f7a72e5113193b2c3667b5fb9f5f02b3 /src/settings.c
parente413f4ee9cd298baab701df31ab4c1cb91c7c4b6 (diff)
downloadrspamd-7d7440b2114b4c81816882433294f9c951bc39e8.tar.gz
rspamd-7d7440b2114b4c81816882433294f9c951bc39e8.zip
* Add support of whitelists in settings (by Anton Nekhoroshin)
Diffstat (limited to 'src/settings.c')
-rw-r--r--src/settings.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/settings.c b/src/settings.c
index 6de04a7eb..cd7167edd 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -53,6 +53,9 @@ settings_free (gpointer data)
if (s->reject_scores) {
g_hash_table_destroy (s->reject_scores);
}
+ if (s->whitelist) {
+ g_hash_table_destroy (s->whitelist);
+ }
g_free (s);
}
@@ -101,7 +104,7 @@ void
json_fin_cb (memory_pool_t * pool, struct map_cb_data *data)
{
struct json_buf *jb;
- int nelts, i;
+ int nelts, i, n, a;
json_t *js, *cur_elt, *cur_nm, *it_val;
json_error_t je;
struct rspamd_settings *cur_settings;
@@ -154,6 +157,7 @@ json_fin_cb (memory_pool_t * pool, struct map_cb_data *data)
cur_settings->metric_scores = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
cur_settings->reject_scores = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
cur_settings->factors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ cur_settings->whitelist = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
cur_settings->statfile_alias = NULL;
cur_settings->want_spam = FALSE;
@@ -217,6 +221,18 @@ json_fin_cb (memory_pool_t * pool, struct map_cb_data *data)
json_it = json_object_iter_next(cur_nm, json_it);
}
}
+ /* Whitelist object */
+ cur_nm = json_object_get (cur_elt, "whitelist");
+ if (cur_nm != NULL && json_is_array (cur_nm)) {
+ n = json_array_size(cur_nm);
+ for(a = 0; a < n; a++) {
+ it_val = json_array_get(cur_nm, a);
+ if (it_val && json_is_string (it_val)) {
+ g_hash_table_insert (cur_settings->whitelist, g_strdup (json_string_value (it_val)), g_strdup (json_string_value (it_val)));
+ }
+
+ }
+ }
/* Want spam */
cur_nm = json_object_get (cur_elt, "want_spam");
if (cur_nm != NULL) {
@@ -302,6 +318,29 @@ check_setting (struct worker_task *task, struct rspamd_settings **user_settings,
return FALSE;
}
+static gboolean
+check_whitelist(struct worker_task *task, struct rspamd_settings *s)
+{
+ char *src_email = NULL, *src_domain = NULL;
+
+ if (task->from != NULL) {
+ src_email = task->from;
+ } else {
+ return FALSE;
+ }
+
+ src_domain = strchr (src_email, '@');
+ if(src_domain != NULL) {
+ src_domain++;
+ }
+
+ if (((g_hash_table_lookup (s->whitelist, src_email) != NULL) ||
+ ( (src_domain != NULL) && (g_hash_table_lookup (s->whitelist, src_domain) != NULL)) )) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
gboolean
check_metric_settings (struct worker_task * task, struct metric * metric, double *score, double *rscore)
{
@@ -312,7 +351,11 @@ check_metric_settings (struct worker_task * task, struct metric * metric, double
if (check_setting (task, &us, &ds)) {
if (us != NULL) {
- /* First search in user's settings */
+ /* First look in user white list */
+ if (check_whitelist(task, us)) {
+ *score = DEFAULT_REJECT_SCORE;
+ return TRUE;
+ }
if ((rs = g_hash_table_lookup (us->reject_scores, metric->name)) != NULL) {
*rscore = *rs;
}
@@ -330,6 +373,10 @@ check_metric_settings (struct worker_task * task, struct metric * metric, double
}
}
else if (ds != NULL) {
+ if (check_whitelist(task, ds)) {
+ *score = DEFAULT_REJECT_SCORE;
+ return TRUE;
+ }
if ((rs = g_hash_table_lookup (ds->reject_scores, metric->name)) != NULL) {
*rscore = *rs;
}