diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-06-24 12:27:58 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-06-24 12:27:58 +0100 |
commit | 3d5281ec7b5f97763ec92555492a322127dc4bb4 (patch) | |
tree | a8840f51a24c36a53ead52214ff39519ad61367f /src/lua/lua_config.c | |
parent | 014c2a2585f1c3aef3f5e6aefeaa5fe0d4310f3e (diff) | |
download | rspamd-3d5281ec7b5f97763ec92555492a322127dc4bb4.tar.gz rspamd-3d5281ec7b5f97763ec92555492a322127dc4bb4.zip |
[Minor] Settings: Add preliminary policies support
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r-- | src/lua/lua_config.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 9f7952cc3..8948dd3ae 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -3475,6 +3475,7 @@ lua_config_register_settings_id (lua_State *L) if (cfg != NULL && settings_name) { ucl_object_t *sym_enabled, *sym_disabled; + enum rspamd_config_settings_policy policy = RSPAMD_SETTINGS_POLICY_DEFAULT; sym_enabled = ucl_object_lua_import (L, 3); @@ -3493,8 +3494,40 @@ lua_config_register_settings_id (lua_State *L) return luaL_error (L, "invalid symbols enabled"); } + /* Check policy */ + if (lua_isstring (L, 5)) { + const gchar *policy_str = lua_tostring (L, 5); + + if (strcmp (policy_str, "default") == 0) { + policy = RSPAMD_SETTINGS_POLICY_DEFAULT; + } + else if (strcmp (policy_str, "implicit_allow") == 0) { + policy = RSPAMD_SETTINGS_POLICY_IMPLICIT_ALLOW; + } + else if (strcmp (policy_str, "implicit_deny") == 0) { + policy = RSPAMD_SETTINGS_POLICY_IMPLICIT_DENY; + } + else { + return luaL_error (L, "invalid settings policy: %s", policy_str); + } + } + else { + /* Apply heuristic */ + if (!sym_enabled) { + policy = RSPAMD_SETTINGS_POLICY_IMPLICIT_ALLOW; + } + } + rspamd_config_register_settings_id (cfg, settings_name, sym_enabled, - sym_disabled); + sym_disabled, policy); + + if (sym_enabled) { + ucl_object_unref (sym_enabled); + } + + if (sym_disabled) { + ucl_object_unref (sym_disabled); + } } else { return luaL_error (L, "invalid arguments"); |