Coverage Report

Created: 2026-11-12 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata8/src/util-lua-builtins.c
Line
Count
Source
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-ntp.h"
40
#include "util-lua-util.h"
41
42
#include "lauxlib.h"
43
44
static const luaL_Reg builtins[] = {
45
    { "suricata.base64", SCLuaLoadBase64Lib },
46
    { "suricata.bytevar", LuaLoadBytevarLib },
47
    { "suricata.config", SCLuaLoadConfigLib },
48
    { "suricata.dataset", LuaLoadDatasetLib },
49
    { "suricata.dnp3", SCLuaLoadDnp3Lib },
50
    { "suricata.dns", SCLuaLoadDnsLib },
51
    { "suricata.file", SCLuaLoadFileLib },
52
    { "suricata.flow", LuaLoadFlowLib },
53
    { "suricata.flowint", LuaLoadFlowintLib },
54
    { "suricata.flowvar", LuaLoadFlowvarLib },
55
    { "suricata.hashlib", SCLuaLoadHashlib },
56
    { "suricata.http", SCLuaLoadHttpLib },
57
    { "suricata.ja3", SCLuaLoadJa3Lib },
58
    { "suricata.log", SCLuaLoadLogLib },
59
    { "suricata.ntp", SCLuaLoadNtpLib },
60
    { "suricata.packet", LuaLoadPacketLib },
61
    { "suricata.rule", SCLuaLoadRuleLib },
62
    { "suricata.smtp", SCLuaLoadSmtpLib },
63
    { "suricata.ssh", SCLuaLoadSshLib },
64
    { "suricata.tls", SCLuaLoadTlsLib },
65
    { "suricata.util", SCLuaLoadUtilLib },
66
    { NULL, NULL },
67
};
68
69
/**
70
 * \brief Load a Suricata built-in module in a sand-boxed environment.
71
 */
72
bool SCLuaLoadBuiltIns(lua_State *L, const char *name)
73
0
{
74
0
    for (const luaL_Reg *lib = builtins; lib->name; lib++) {
75
0
        if (strcmp(name, lib->name) == 0) {
76
0
            lib->func(L);
77
0
            return true;
78
0
        }
79
0
    }
80
0
    return false;
81
0
}
82
83
/**
84
 * \brief Register Suricata built-in modules for loading in a
85
 *     non-sandboxed environment.
86
 */
87
void SCLuaRequirefBuiltIns(lua_State *L)
88
0
{
89
0
    for (const luaL_Reg *lib = builtins; lib->name; lib++) {
90
0
        luaL_requiref(L, lib->name, lib->func, 0);
91
0
        lua_pop(L, 1);
92
0
    }
93
0
}