suricata
util-lua-builtins.c
Go to the documentation of this file.
1/* Copyright (C) 2025 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#include "suricata-common.h"
19#include "util-lua-builtins.h"
20#include "util-lua-base64lib.h"
21#include "util-lua-bytevarlib.h"
22#include "util-lua-config.h"
23#include "util-lua-dataset.h"
24#include "util-lua-dnp3.h"
25#include "util-lua-flowintlib.h"
26#include "util-lua-flowvarlib.h"
27#include "util-lua-http.h"
28#include "util-lua-dns.h"
29#include "util-lua-smtp.h"
30#include "util-lua-ssh.h"
31#include "util-lua-flowlib.h"
32#include "util-lua-hashlib.h"
33#include "util-lua-tls.h"
34#include "util-lua-packetlib.h"
35#include "util-lua-rule.h"
36#include "util-lua-ja3.h"
37#include "util-lua-filelib.h"
38#include "util-lua-log.h"
39#include "util-lua-util.h"
40
41#include "lauxlib.h"
42
43static const luaL_Reg builtins[] = {
44 { "suricata.base64", SCLuaLoadBase64Lib },
45 { "suricata.bytevar", LuaLoadBytevarLib },
46 { "suricata.config", SCLuaLoadConfigLib },
47 { "suricata.dataset", LuaLoadDatasetLib },
48 { "suricata.dnp3", SCLuaLoadDnp3Lib },
49 { "suricata.dns", SCLuaLoadDnsLib },
50 { "suricata.file", SCLuaLoadFileLib },
51 { "suricata.flow", LuaLoadFlowLib },
52 { "suricata.flowint", LuaLoadFlowintLib },
53 { "suricata.flowvar", LuaLoadFlowvarLib },
54 { "suricata.hashlib", SCLuaLoadHashlib },
55 { "suricata.http", SCLuaLoadHttpLib },
56 { "suricata.ja3", SCLuaLoadJa3Lib },
57 { "suricata.log", SCLuaLoadLogLib },
58 { "suricata.packet", LuaLoadPacketLib },
59 { "suricata.rule", SCLuaLoadRuleLib },
60 { "suricata.smtp", SCLuaLoadSmtpLib },
61 { "suricata.ssh", SCLuaLoadSshLib },
62 { "suricata.tls", SCLuaLoadTlsLib },
63 { "suricata.util", SCLuaLoadUtilLib },
64 { NULL, NULL },
65};
66
67/**
68 * \brief Load a Suricata built-in module in a sand-boxed environment.
69 */
70bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
71{
72 for (const luaL_Reg *lib = builtins; lib->name; lib++) {
73 if (strcmp(name, lib->name) == 0) {
74 lib->func(L);
75 return true;
76 }
77 }
78 return false;
79}
80
81/**
82 * \brief Register Suricata built-in modules for loading in a
83 * non-sandboxed environment.
84 */
86{
87 for (const luaL_Reg *lib = builtins; lib->name; lib++) {
88 luaL_requiref(L, lib->name, lib->func, 0);
89 lua_pop(L, 1);
90 }
91}
void LuaLoadDatasetLib(lua_State *luastate)
struct lua_State lua_State
const char * name
int SCLuaLoadBase64Lib(lua_State *L)
void SCLuaRequirefBuiltIns(lua_State *L)
Register Suricata built-in modules for loading in a non-sandboxed environment.
bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
Load a Suricata built-in module in a sand-boxed environment.
int LuaLoadBytevarLib(lua_State *L)
int SCLuaLoadConfigLib(lua_State *L)
int SCLuaLoadDnp3Lib(lua_State *L)
int SCLuaLoadDnsLib(lua_State *L)
int SCLuaLoadFileLib(lua_State *L)
int LuaLoadFlowintLib(lua_State *L)
int LuaLoadFlowLib(lua_State *luastate)
int LuaLoadFlowvarLib(lua_State *L)
int SCLuaLoadHashlib(lua_State *L)
int SCLuaLoadHttpLib(lua_State *luastate)
int SCLuaLoadJa3Lib(lua_State *L)
int SCLuaLoadLogLib(lua_State *L)
int LuaLoadPacketLib(lua_State *luastate)
int SCLuaLoadRuleLib(lua_State *L)
int SCLuaLoadSmtpLib(lua_State *L)
int SCLuaLoadSshLib(lua_State *L)
int SCLuaLoadTlsLib(lua_State *L)
int SCLuaLoadUtilLib(lua_State *L)