((uc) >= 0x205F && (uc) <= 0x206F) || \
(uc) == 0xFEFF)
+#define RSPAMD_LEN_CHECK_STARTS_WITH(s, len, lit) \
+ ((len) >= sizeof(lit) - 1 && g_ascii_strncasecmp ((s), (lit), sizeof(lit) - 1) == 0)
+
#endif /* SRC_LIBUTIL_STR_UTIL_H_ */
return TRUE;
}
-#define LEN_CHECK_STARTS_WITH(s, len, lit) \
- ((len) >= sizeof(lit) - 1 && g_ascii_strncasecmp ((s), (lit), sizeof(lit) - 1) == 0)
gboolean
rspamd_upstreams_parse_line_len (struct upstream_list *ups,
const gchar *str, gsize len, guint16 def_port, void *data)
guint span_len;
gboolean ret = FALSE;
- if (LEN_CHECK_STARTS_WITH(p, len, "random:")) {
+ if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "random:")) {
ups->rot_alg = RSPAMD_UPSTREAM_RANDOM;
p += sizeof ("random:") - 1;
}
- else if (LEN_CHECK_STARTS_WITH(p, len, "master-slave:")) {
+ else if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "master-slave:")) {
ups->rot_alg = RSPAMD_UPSTREAM_MASTER_SLAVE;
p += sizeof ("master-slave:") - 1;
}
- else if (LEN_CHECK_STARTS_WITH(p, len, "round-robin:")) {
+ else if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "round-robin:")) {
ups->rot_alg = RSPAMD_UPSTREAM_ROUND_ROBIN;
p += sizeof ("round-robin:") - 1;
}
- else if (LEN_CHECK_STARTS_WITH(p, len, "hash:")) {
+ else if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "hash:")) {
ups->rot_alg = RSPAMD_UPSTREAM_HASHED;
p += sizeof ("hash:") - 1;
}
- else if (LEN_CHECK_STARTS_WITH(p, len, "sequential:")) {
+ else if (RSPAMD_LEN_CHECK_STARTS_WITH(p, len, "sequential:")) {
ups->rot_alg = RSPAMD_UPSTREAM_SEQUENTIAL;
p += sizeof ("sequential:") - 1;
}
return ret;
}
-#undef LEN_CHECK_STARTS_WITH
gboolean
rspamd_upstreams_parse_line (struct upstream_list *ups,
rspamd_lua_set_env (lua_State *L, GHashTable *vars)
{
gint orig_top = lua_gettop (L);
+ gchar **env = g_get_environ ();
/* Set known paths as rspamd_paths global */
lua_getglobal (L, "rspamd_paths");
const gchar *t;
/* Try environment */
- t = getenv ("SHAREDIR");
+ t = g_environ_getenv (env, "SHAREDIR");
if (t) {
sharedir = t;
}
- t = getenv ("PLUGINSDIR");
+ t = g_environ_getenv (env, "PLUGINSDIR");
if (t) {
pluginsdir = t;
}
- t = getenv ("RULESDIR");
+ t = g_environ_getenv (env, "RULESDIR");
if (t) {
rulesdir = t;
}
- t = getenv ("DBDIR");
+ t = g_environ_getenv (env, "DBDIR");
if (t) {
dbdir = t;
}
- t = getenv ("RUNDIR");
+ t = g_environ_getenv (env, "RUNDIR");
if (t) {
rundir = t;
}
- t = getenv ("LUALIBDIR");
+ t = g_environ_getenv (env, "LUALIBDIR");
if (t) {
lualibdir = t;
}
- t = getenv ("LOGDIR");
+ t = g_environ_getenv (env, "LOGDIR");
if (t) {
logdir = t;
}
- t = getenv ("WWWDIR");
+ t = g_environ_getenv (env, "WWWDIR");
if (t) {
wwwdir = t;
}
- t = getenv ("CONFDIR");
+ t = g_environ_getenv (env, "CONFDIR");
if (t) {
confdir = t;
}
- t = getenv ("LOCAL_CONFDIR");
+ t = g_environ_getenv (env, "LOCAL_CONFDIR");
if (t) {
local_confdir = t;
}
lua_pushinteger (L, RSPAMD_VERSION_NUM);
lua_settable (L, -3);
+ if (env) {
+ gint lim = g_strv_length (env);
+
+ for (gint i = 0; i < lim; i++) {
+ if (RSPAMD_LEN_CHECK_STARTS_WITH(env[i], strlen (env[i]), "RSPAMD_")) {
+ const char *var = env[i] + sizeof ("RSPAMD_") - 1, *value;
+ gint varlen;
+
+ varlen = strcspn (var, "=");
+ value = var + varlen;
+
+ if (*value == '=') {
+ value ++;
+
+ lua_pushlstring (L, var, varlen);
+ lua_pushstring (L, value);
+ lua_settable (L, -3);
+ }
+
+ }
+ }
+ }
+
lua_setglobal (L, "rspamd_env");
}