aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_common.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-27 12:03:54 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-27 12:03:54 +0000
commit2ad0276a3189c61e673ea716dbd461ac6ee59f87 (patch)
tree45acbd68e2c2e28eeb445c90a61ecbb7689b20a5 /src/lua/lua_common.c
parentdf2fba1c90b25c486d4c33f6c99b2cc2d768063c (diff)
downloadrspamd-2ad0276a3189c61e673ea716dbd461ac6ee59f87.tar.gz
rspamd-2ad0276a3189c61e673ea716dbd461ac6ee59f87.zip
[Minor] Pass variables from the environment to rspamd_env
Diffstat (limited to 'src/lua/lua_common.c')
-rw-r--r--src/lua/lua_common.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 7f49c090d..1c687fb48 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -541,6 +541,7 @@ void
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");
@@ -559,52 +560,52 @@ rspamd_lua_set_env (lua_State *L, GHashTable *vars)
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;
}
@@ -718,6 +719,29 @@ rspamd_lua_set_env (lua_State *L, GHashTable *vars)
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");
}