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-hashlib.h"
23 #include "util-lua-packetlib.h"
24 
25 #include "lauxlib.h"
26 
27 static const luaL_Reg builtins[] = {
28  { "suricata.base64", SCLuaLoadBase64Lib },
29  { "suricata.dataset", LuaLoadDatasetLib },
30  { "suricata.hashlib", SCLuaLoadHashlib },
31  { "suricata.packet", LuaLoadPacketLib },
32  { NULL, NULL },
33 };
34 
35 /**
36  * \brief Load a Suricata built-in module in a sand-boxed environment.
37  */
38 bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
39 {
40  for (const luaL_Reg *lib = builtins; lib->name; lib++) {
41  if (strcmp(name, lib->name) == 0) {
42  lib->func(L);
43  return true;
44  }
45  }
46  return false;
47 }
48 
49 /**
50  * \brief Register Suricata built-in modules for loading in a
51  * non-sandboxed environment.
52  */
54 {
55  for (const luaL_Reg *lib = builtins; lib->name; lib++) {
56  luaL_requiref(L, lib->name, lib->func, 0);
57  lua_pop(L, 1);
58  }
59 }
LuaLoadPacketLib
int LuaLoadPacketLib(lua_State *luastate)
Definition: util-lua-packetlib.c:273
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:515
util-lua-packetlib.h
name
const char * name
Definition: tm-threads.c:2081
SCLuaRequirefBuiltIns
void SCLuaRequirefBuiltIns(lua_State *L)
Register Suricata built-in modules for loading in a non-sandboxed environment.
Definition: util-lua-builtins.c:53
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:38
suricata-common.h
util-lua-base64lib.h