diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-01-29 18:30:13 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-01-29 18:30:13 +0000 |
commit | ebc0a487e134164469b34c87848836d601f54eaf (patch) | |
tree | d30ef71c852e9de2878b60bcc67d3afc27a742f3 /src/libserver | |
parent | d4d323b04e9eef2416b1a49f6cf1be1cc5c511fc (diff) | |
download | rspamd-ebc0a487e134164469b34c87848836d601f54eaf.tar.gz rspamd-ebc0a487e134164469b34c87848836d601f54eaf.zip |
Add configuration routine to parse keypairs.
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/cfg_rcl.c | 65 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.h | 15 |
2 files changed, 80 insertions, 0 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index e53dfba6a..b16c24846 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -1765,6 +1765,71 @@ rspamd_rcl_parse_struct_time (struct rspamd_config *cfg, } gboolean +rspamd_rcl_parse_struct_keypair (struct rspamd_config *cfg, + const ucl_object_t *obj, + gpointer ud, + struct rspamd_rcl_section *section, + GError **err) +{ + struct rspamd_rcl_struct_parser *pd = ud; + gpointer *target; + gpointer key; + const gchar *val, *sem = NULL, *pk = NULL, *sk = NULL; + gchar keybuf[256]; + const ucl_object_t *elt; + + target = (gpointer *)(((gchar *)pd->user_struct) + pd->offset); + if (obj->type == UCL_STRING) { + /* Pk and Sk are just linked all together */ + val = ucl_object_tostring (obj); + if ((sem = strchr (val, ':')) != NULL) { + sk = val; + pk = sem + 1; + } + else { + /* Try to parse the key as is */ + key = rspamd_http_connection_make_key ((gchar *)val, strlen (val)); + if (key != NULL) { + *target = key; + return TRUE; + } + + return FALSE; + } + } + else if (obj->type == UCL_OBJECT) { + elt = ucl_object_find_key (obj, "pubkey"); + if (elt == NULL || !ucl_object_tostring_safe (elt, &pk)) { + return FALSE; + } + elt = ucl_object_find_key (obj, "privkey"); + if (elt == NULL || !ucl_object_tostring_safe (elt, &sk)) { + return FALSE; + } + } + + if (sk == NULL || pk == NULL) { + return FALSE; + } + + if (!sem) { + rspamd_snprintf (keybuf, sizeof (keybuf), "%s%s", sk, pk); + } + else { + rspamd_snprintf (keybuf, sizeof (keybuf), "%*s%s", sem - sk, sk, pk); + } + + key = rspamd_http_connection_make_key (keybuf, strlen (val)); + if (key != NULL) { + /* XXX: clean buffer after usage */ + *target = key; + return TRUE; + } + + return FALSE; +} + +gboolean rspamd_rcl_parse_struct_string_list (struct rspamd_config *cfg, const ucl_object_t *obj, gpointer ud, diff --git a/src/libserver/cfg_rcl.h b/src/libserver/cfg_rcl.h index 97f092ec3..ca856a38d 100644 --- a/src/libserver/cfg_rcl.h +++ b/src/libserver/cfg_rcl.h @@ -215,6 +215,21 @@ gboolean rspamd_rcl_parse_struct_boolean (struct rspamd_config *cfg, GError **err); /** + * Parse a keypair field of a structure + * @param cfg config pointer + * @param obj object to parse + * @param ud struct_parser structure (flags mean the exact structure used) + * @param section the current section + * @param err error pointer + * @return TRUE if a value has been successfully parsed + */ +gboolean rspamd_rcl_parse_struct_keypair (struct rspamd_config *cfg, + const ucl_object_t *obj, + gpointer ud, + struct rspamd_rcl_section *section, + GError **err); + +/** * Utility functions */ |