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-dataset.h"
22 #include "util-lua-dnp3.h"
23 #include "util-lua-flowintlib.h"
24 #include "util-lua-flowvarlib.h"
25 #include "util-lua-http.h"
26 #include "util-lua-dns.h"
27 #include "util-lua-smtp.h"
28 #include "util-lua-ssh.h"
29 #include "util-lua-flowlib.h"
30 #include "util-lua-hashlib.h"
31 #include "util-lua-packetlib.h"
32 #include "util-lua-rule.h"
33 #include "util-lua-ja3.h"
34 
35 #include "lauxlib.h"
36 
37 static const luaL_Reg builtins[] = {
38  { "suricata.base64", SCLuaLoadBase64Lib },
39  { "suricata.dataset", LuaLoadDatasetLib },
40  { "suricata.dnp3", SCLuaLoadDnp3Lib },
41  { "suricata.dns", SCLuaLoadDnsLib },
42  { "suricata.flow", LuaLoadFlowLib },
43  { "suricata.flowint", LuaLoadFlowintLib },
44  { "suricata.flowvar", LuaLoadFlowvarLib },
45  { "suricata.hashlib", SCLuaLoadHashlib },
46  { "suricata.http", SCLuaLoadHttpLib },
47  { "suricata.ja3", SCLuaLoadJa3Lib },
48  { "suricata.packet", LuaLoadPacketLib },
49  { "suricata.rule", SCLuaLoadRuleLib },
50  { "suricata.smtp", SCLuaLoadSmtpLib },
51  { "suricata.ssh", SCLuaLoadSshLib },
52  { NULL, NULL },
53 };
54 
55 /**
56  * \brief Load a Suricata built-in module in a sand-boxed environment.
57  */
58 bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
59 {
60  for (const luaL_Reg *lib = builtins; lib->name; lib++) {
61  if (strcmp(name, lib->name) == 0) {
62  lib->func(L);
63  return true;
64  }
65  }
66  return false;
67 }
68 
69 /**
70  * \brief Register Suricata built-in modules for loading in a
71  * non-sandboxed environment.
72  */
74 {
75  for (const luaL_Reg *lib = builtins; lib->name; lib++) {
76  luaL_requiref(L, lib->name, lib->func, 0);
77  lua_pop(L, 1);
78  }
79 }
util-lua-ssh.h
LuaLoadPacketLib
int LuaLoadPacketLib(lua_State *luastate)
Definition: util-lua-packetlib.c:273
util-lua-ja3.h
util-lua-dataset.h
util-lua-builtins.h
SCLuaLoadHashlib
int SCLuaLoadHashlib(lua_State *L)
Definition: util-lua-hashlib.c:409
util-lua-hashlib.h
SCLuaLoadBase64Lib
int SCLuaLoadBase64Lib(lua_State *L)
Definition: util-lua-base64lib.c:113
LuaLoadDatasetLib
void LuaLoadDatasetLib(lua_State *luastate)
Definition: util-lua-dataset.c:123
lua_State
struct lua_State lua_State
Definition: suricata-common.h:523
SCLuaLoadDnp3Lib
int SCLuaLoadDnp3Lib(lua_State *L)
Definition: util-lua-dnp3.c:202
util-lua-packetlib.h
SCLuaLoadHttpLib
int SCLuaLoadHttpLib(lua_State *luastate)
Definition: util-lua-http.c:319
util-lua-dnp3.h
name
const char * name
Definition: tm-threads.c:2123
util-lua-flowlib.h
SCLuaRequirefBuiltIns
void SCLuaRequirefBuiltIns(lua_State *L)
Register Suricata built-in modules for loading in a non-sandboxed environment.
Definition: util-lua-builtins.c:73
SCLuaLoadBuiltIns
bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
Load a Suricata built-in module in a sand-boxed environment.
Definition: util-lua-builtins.c:58
util-lua-smtp.h
LuaLoadFlowLib
int LuaLoadFlowLib(lua_State *luastate)
Definition: util-lua-flowlib.c:286
suricata-common.h
util-lua-dns.h
SCLuaLoadSmtpLib
int SCLuaLoadSmtpLib(lua_State *L)
Definition: util-lua-smtp.c:165
LuaLoadFlowvarLib
int LuaLoadFlowvarLib(lua_State *L)
Definition: util-lua-flowvarlib.c:136
util-lua-flowintlib.h
SCLuaLoadDnsLib
int SCLuaLoadDnsLib(lua_State *L)
Definition: util-lua-dns.c:163
util-lua-rule.h
SCLuaLoadSshLib
int SCLuaLoadSshLib(lua_State *L)
Definition: util-lua-ssh.c:192
util-lua-base64lib.h
util-lua-flowvarlib.h
util-lua-http.h
LuaLoadFlowintLib
int LuaLoadFlowintLib(lua_State *L)
Definition: util-lua-flowintlib.c:180
SCLuaLoadJa3Lib
int SCLuaLoadJa3Lib(lua_State *L)
Definition: util-lua-ja3.c:197
SCLuaLoadRuleLib
int SCLuaLoadRuleLib(lua_State *L)
Definition: util-lua-rule.c:170