return FALSE;
}
cfg->log_type = RSPAMD_LOG_FILE;
- cfg->log_file = rspamd_expand_path (cfg->cfg_pool, ucl_object_tostring (val));
+ cfg->log_file = memory_pool_strdup (cfg->cfg_pool, ucl_object_tostring (val));
}
else if (g_ascii_strcasecmp (log_type, "syslog") == 0) {
/* Need to get facility */
rspamd_rcl_lua_handler (struct config_file *cfg, ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
- const gchar *lua_src = rspamd_expand_path (cfg->cfg_pool, ucl_object_tostring (obj));
+ const gchar *lua_src = memory_pool_strdup (cfg->cfg_pool, ucl_object_tostring (obj));
gchar *cur_dir, *lua_dir, *lua_file, *tmp1, *tmp2;
lua_State *L = cfg->lua_state;
LL_FOREACH (val, cur) {
if (ucl_object_tostring_safe (cur, &data)) {
- if (!rspamd_rcl_add_module_path (cfg, rspamd_expand_path (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_module_path (cfg, memory_pool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
}
}
else if (ucl_object_tostring_safe (obj, &data)) {
- if (!rspamd_rcl_add_module_path (cfg, rspamd_expand_path (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_module_path (cfg, memory_pool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
target = (gchar **)(((gchar *)pd->user_struct) + pd->offset);
switch (obj->type) {
case UCL_STRING:
- if (pd->flags & RSPAMD_CL_FLAG_STRING_PATH) {
- *target = rspamd_expand_path (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
- else {
- *target = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
+ *target = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
break;
case UCL_INT:
*target = memory_pool_alloc (cfg->cfg_pool, num_str_len);
for (cur = obj; cur != NULL; cur = cur->next) {
switch (cur->type) {
case UCL_STRING:
- if (pd->flags & RSPAMD_CL_FLAG_STRING_PATH) {
- val = rspamd_expand_path (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
- else {
- val = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
+ val = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
break;
case UCL_INT:
val = memory_pool_alloc (cfg->cfg_pool, num_str_len);
return NULL;
}
+
+/*
+ * Variables:
+ * $CONFDIR - configuration directory
+ * $RUNDIR - local states directory
+ * $DBDIR - databases dir
+ * $LOGDIR - logs dir
+ * $PLUGINSDIR - pluggins dir
+ * $PREFIX - installation prefix
+ * $VERSION - rspamd version
+ */
+
+#define RSPAMD_CONFDIR_MACRO "CONFDIR"
+#define RSPAMD_RUNDIR_MACRO "RUNDIR"
+#define RSPAMD_DBDIR_MACRO "DBDIR"
+#define RSPAMD_LOGDIR_MACRO "LOGDIR"
+#define RSPAMD_PLUGINSDIR_MACRO "PLUGINSDIR"
+#define RSPAMD_PREFIX_MACRO "PREFIX"
+#define RSPAMD_VERSION_MACRO "VERSION"
+
+static void
+rspamd_ucl_add_conf_variables (struct ucl_parser *parser)
+{
+ ucl_parser_register_variable (parser, RSPAMD_CONFDIR_MACRO, RSPAMD_CONFDIR);
+ ucl_parser_register_variable (parser, RSPAMD_RUNDIR_MACRO, RSPAMD_RUNDIR);
+ ucl_parser_register_variable (parser, RSPAMD_DBDIR_MACRO, RSPAMD_DBDIR);
+ ucl_parser_register_variable (parser, RSPAMD_LOGDIR_MACRO, RSPAMD_LOGDIR);
+ ucl_parser_register_variable (parser, RSPAMD_PLUGINSDIR_MACRO, RSPAMD_PLUGINSDIR);
+ ucl_parser_register_variable (parser, RSPAMD_PREFIX_MACRO, RSPAMD_PREFIX);
+ ucl_parser_register_variable (parser, RSPAMD_VERSION_MACRO, RVERSION);
+}
+
gboolean
read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar *convert_to)
{
}
else {
parser = ucl_parser_new (0);
+ rspamd_ucl_add_conf_variables (parser);
if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
msg_err ("ucl parser error: %s", ucl_parser_get_error (parser));
munmap (data, st.st_size);
return p - buf;
#endif
}
-
-/*
- * Variables:
- * $CONFDIR - configuration directory
- * $RUNDIR - local states directory
- * $DBDIR - databases dir
- * $LOGDIR - logs dir
- * $PLUGINSDIR - pluggins dir
- * $PREFIX - installation prefix
- * $VERSION - rspamd version
- */
-
-#define RSPAMD_CONFDIR_MACRO "CONFDIR"
-#define RSPAMD_RUNDIR_MACRO "RUNDIR"
-#define RSPAMD_DBDIR_MACRO "DBDIR"
-#define RSPAMD_LOGDIR_MACRO "LOGDIR"
-#define RSPAMD_PLUGINSDIR_MACRO "PLUGINSDIR"
-#define RSPAMD_PREFIX_MACRO "PREFIX"
-#define RSPAMD_VERSION_MACRO "VERSION"
-
-static const gchar *
-rspamd_check_path_variable (const gchar *in, gsize *len)
-{
- switch (*in) {
- case 'C':
- if (strncmp (in, RSPAMD_CONFDIR_MACRO, sizeof (RSPAMD_CONFDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_CONFDIR) - 1;
- in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
- }
- break;
- case 'R':
- if (strncmp (in, RSPAMD_RUNDIR_MACRO, sizeof (RSPAMD_RUNDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_RUNDIR) - 1;
- in += sizeof (RSPAMD_RUNDIR_MACRO) - 1;
- }
- break;
- case 'D':
- if (strncmp (in, RSPAMD_DBDIR_MACRO, sizeof (RSPAMD_DBDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_DBDIR) - 1;
- in += sizeof (RSPAMD_DBDIR_MACRO) - 1;
- }
- break;
- case 'L':
- if (strncmp (in, RSPAMD_LOGDIR_MACRO, sizeof (RSPAMD_LOGDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_LOGDIR) - 1;
- in += sizeof (RSPAMD_LOGDIR_MACRO) - 1;
- }
- break;
- case 'P':
- if (strncmp (in, RSPAMD_PREFIX_MACRO, sizeof (RSPAMD_PREFIX_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_PREFIX) - 1;
- in += sizeof (RSPAMD_PREFIX_MACRO) - 1;
- }
- else if (strncmp (in, RSPAMD_PLUGINSDIR_MACRO, sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_PLUGINSDIR) - 1;
- in += sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1;
- }
- break;
- case 'V':
- if (strncmp (in, RSPAMD_VERSION_MACRO, sizeof (RSPAMD_VERSION_MACRO) - 1) == 0) {
- *len += sizeof (RVERSION) - 1;
- in += sizeof (RSPAMD_VERSION_MACRO) - 1;
- }
- break;
- }
-
- return in;
-}
-
-static const gchar *
-rspamd_expand_path_variable (const gchar *in, gchar **dest)
-{
- gchar *d = *dest;
- const gchar *v = in + 1;
-
- *d = *v;
- in ++;
-
- switch (*v) {
- case 'C':
- if (strncmp (v, RSPAMD_CONFDIR_MACRO, sizeof (RSPAMD_CONFDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_CONFDIR, sizeof (RSPAMD_CONFDIR) - 1);
- d += sizeof (RSPAMD_CONFDIR) - 1;
- in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
- }
- break;
- case 'R':
- if (strncmp (v, RSPAMD_RUNDIR_MACRO, sizeof (RSPAMD_RUNDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_RUNDIR, sizeof (RSPAMD_RUNDIR) - 1);
- d += sizeof (RSPAMD_RUNDIR) - 1;
- in += sizeof (RSPAMD_RUNDIR_MACRO) - 1;
- }
- break;
- case 'D':
- if (strncmp (v, RSPAMD_DBDIR_MACRO, sizeof (RSPAMD_DBDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_DBDIR, sizeof (RSPAMD_DBDIR) - 1);
- d += sizeof (RSPAMD_DBDIR) - 1;
- in += sizeof (RSPAMD_DBDIR_MACRO) - 1;
- }
- break;
- case 'L':
- if (strncmp (v, RSPAMD_LOGDIR_MACRO, sizeof (RSPAMD_LOGDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_LOGDIR, sizeof (RSPAMD_LOGDIR) - 1);
- d += sizeof (RSPAMD_LOGDIR) - 1;
- in += sizeof (RSPAMD_LOGDIR_MACRO) - 1;
- }
- break;
- case 'P':
- if (strncmp (v, RSPAMD_PREFIX_MACRO, sizeof (RSPAMD_PREFIX_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_PREFIX, sizeof (RSPAMD_PREFIX) - 1);
- d += sizeof (RSPAMD_PREFIX) - 1;
- in += sizeof (RSPAMD_PREFIX_MACRO) - 1;
- }
- else if (strncmp (v, RSPAMD_PLUGINSDIR_MACRO, sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_PLUGINSDIR, sizeof (RSPAMD_PLUGINSDIR) - 1);
- d += sizeof (RSPAMD_PLUGINSDIR) - 1;
- in += sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1;
- }
- break;
- case 'V':
- if (strncmp (v, RSPAMD_VERSION_MACRO, sizeof (RSPAMD_VERSION_MACRO) - 1) == 0) {
- memcpy (d, RVERSION, sizeof (RVERSION) - 1);
- d += sizeof (RVERSION) - 1;
- in += sizeof (RSPAMD_VERSION_MACRO) - 1;
- }
- break;
- }
-
- *dest = d;
- return in;
-}
-
-gchar*
-rspamd_expand_path (memory_pool_t *pool, const gchar *path)
-{
- const gchar *p = path;
- gchar *dest, *d;
- gsize len = 0, orig_len = 0;
-
- while (*p != '\0') {
- if (*p == '$') {
- len ++;
- p = rspamd_check_path_variable (p + 1, &len);
- }
- else {
- len ++;
- }
- orig_len ++;
- p ++;
- }
-
- if (len == orig_len) {
- return memory_pool_strdup (pool, path);
- }
-
- dest = memory_pool_alloc (pool, len + 1);
- p = path;
- d = dest;
-
- while (*p != '\0') {
- if (*p == '$') {
- p = rspamd_expand_path_variable (p, &d);
- }
- else {
- *d++ = *p++;
- }
- }
-
- *d = '\0';
-
- msg_debug ("expanded %s to %s", path, dest);
-
- return dest;
-}
-
/*
* vi:ts=4
*/