Currently only provides "log_path" as a replacement for SCLogPath.
--- /dev/null
+Config Library
+##############
+
+The config library provides access to Suricata configuration settings.
+
+To use this library, you must require it::
+
+ local config = require("suricata.config")
+
+Functions
+*********
+
+``log_path()``
+==============
+
+Returns the configured log directory path.
+
+Example::
+
+ local config = require("suricata.config")
+
+ local log_path, err = config.log_path()
+ if log_path == nil then
+ print("failed to get log path " .. err)
+ end
.. toctree::
base64
+ config
dns
file
flowlib
It gives: tid (integer), tname (string), tgroup (string)
-SCLogPath
-~~~~~~~~~
-
-Expose the log path.
-
-::
-
-
- name = "fast_lua.log"
- function setup (args)
- filename = SCLogPath() .. "/" .. name
- file = assert(io.open(filename, "a"))
- end
SCByteVarGet
~~~~~~~~~~~~
::
+ local config = require("suricata.config")
local logger = require("suricata.log")
function init (args)
end
function setup (args)
- filename = SCLogPath() .. "/" .. name
+ filename = config.log_path() .. "/" .. name
file = assert(io.open(filename, "a"))
logger.info("HTTP Log Filename " .. filename)
http = 0
local packet = require("suricata.packet")
local rule = require("suricata.rule")
+local config = require("suricata.config")
function init()
local needs = {}
end
function setup()
- filename = SCLogPath() .. "/fast.log"
+ filename = config.log_path() .. "/fast.log"
file = assert(io.open(filename, "a"))
alert_count = 0
end
util-lua-base64lib.h \
util-lua-builtins.h \
util-lua-common.h \
+ util-lua-config.h \
util-lua-dataset.h \
util-lua-dnp3-objects.h \
util-lua-dnp3.h \
util-lua-base64lib.c \
util-lua-builtins.c \
util-lua-common.c \
+ util-lua-config.c \
util-lua-dataset.c \
util-lua-dnp3-objects.c \
util-lua-dnp3.c \
#include "suricata-common.h"
#include "util-lua-builtins.h"
#include "util-lua-base64lib.h"
+#include "util-lua-config.h"
#include "util-lua-dataset.h"
#include "util-lua-dnp3.h"
#include "util-lua-flowintlib.h"
static const luaL_Reg builtins[] = {
{ "suricata.base64", SCLuaLoadBase64Lib },
+ { "suricata.config", SCLuaLoadConfigLib },
{ "suricata.dataset", LuaLoadDatasetLib },
{ "suricata.dnp3", SCLuaLoadDnp3Lib },
{ "suricata.dns", SCLuaLoadDnsLib },
return LuaCallbackStreamingBufferPushToStack(luastate, b);
}
-static int LuaCallbackLogPath(lua_State *luastate)
-{
- const char *ld = SCConfigGetLogDirectory();
- if (ld == NULL)
- return LuaCallbackError(luastate, "internal error: no log dir");
-
- return LuaPushStringBuffer(luastate, (const uint8_t *)ld, strlen(ld));
-}
-
/** \internal
* \brief fill lua stack with thread info
* \param luastate the lua state
lua_pushcfunction(luastate, LuaCallbackStreamingBuffer);
lua_setglobal(luastate, "SCStreamingBuffer");
- lua_pushcfunction(luastate, LuaCallbackLogPath);
- lua_setglobal(luastate, "SCLogPath");
-
lua_pushcfunction(luastate, LuaCallbackThreadInfo);
lua_setglobal(luastate, "SCThreadInfo");
return 0;
--- /dev/null
+/* Copyright (C) 2025 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/**
+ * \file
+ *
+ * Configuration API for Lua.
+ *
+ * local config = require("suricata.config")
+ */
+
+#include "suricata-common.h"
+#include "util-lua-config.h"
+#include "conf.h"
+#include "util-conf.h"
+#include "app-layer-protos.h"
+#include "util-lua-common.h"
+#include "util-lua.h"
+
+#include "lauxlib.h"
+
+static int LuaConfigLogPath(lua_State *L)
+{
+ const char *ld = SCConfigGetLogDirectory();
+ if (ld == NULL)
+ return LuaCallbackError(L, "internal error: no log dir");
+
+ return LuaPushStringBuffer(L, (const uint8_t *)ld, strlen(ld));
+}
+
+static const luaL_Reg configlib[] = {
+ // clang-format off
+ { "log_path", LuaConfigLogPath },
+ { NULL, NULL },
+ // clang-format on
+};
+
+int SCLuaLoadConfigLib(lua_State *L)
+{
+ luaL_newlib(L, configlib);
+ return 1;
+}
--- /dev/null
+/* Copyright (C) 2025 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef UTIL_LUA_CONFIG_H
+#define UTIL_LUA_CONFIG_H
+
+#include "lua.h"
+
+int SCLuaLoadConfigLib(lua_State *luastate);
+
+#endif /* UTIL_LUA_CONFIG_H */
\ No newline at end of file