• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22550237931

01 Mar 2026 06:56PM UTC coverage: 64.812% (-8.9%) from 73.687%
22550237931

Pull #14920

github

web-flow
Merge e05854a6d into 90823fa90
Pull Request #14920: draft: rust based configuration file parser and loader - v4

561 of 789 new or added lines in 4 files covered. (71.1%)

23225 existing lines in 498 files now uncovered.

131605 of 203055 relevant lines covered (64.81%)

2328818.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/util-lua-ssh.c
1
/* Copyright (C) 2014 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

19
/**
20
 * \file
21
 *
22
 * \author Mats Klepsland <mats.klepsland@gmail.com>
23
 *
24
 */
25

26
#include "suricata-common.h"
27
#include "util-lua-ssh.h"
28
#include "util-lua.h"
29
#include "util-lua-common.h"
30
#include "rust.h"
31

32
// #define SSH_MT "suricata:ssh:tx"
33
static const char ssh_tx[] = "suricata:ssh:tx";
34

35
struct LuaTx {
36
    void *tx; // SSHTransaction
37
};
38

39
static int LuaSshGetTx(lua_State *L)
UNCOV
40
{
×
UNCOV
41
    if (!(LuaStateNeedProto(L, ALPROTO_SSH))) {
×
42
        return LuaCallbackError(L, "error: protocol not ssh");
×
43
    }
×
UNCOV
44
    void *tx = LuaStateGetTX(L);
×
UNCOV
45
    if (tx == NULL) {
×
46
        return LuaCallbackError(L, "error: no tx available");
×
47
    }
×
UNCOV
48
    struct LuaTx *ltx = (struct LuaTx *)lua_newuserdata(L, sizeof(*ltx));
×
UNCOV
49
    if (ltx == NULL) {
×
50
        return LuaCallbackError(L, "error: fail to allocate user data");
×
51
    }
×
UNCOV
52
    ltx->tx = tx;
×
53

UNCOV
54
    luaL_getmetatable(L, ssh_tx);
×
UNCOV
55
    lua_setmetatable(L, -2);
×
56

UNCOV
57
    return 1;
×
UNCOV
58
}
×
59

60
static int LuaSshTxGetProto(lua_State *L, uint8_t flags)
UNCOV
61
{
×
UNCOV
62
    const uint8_t *buf = NULL;
×
UNCOV
63
    uint32_t b_len = 0;
×
UNCOV
64
    struct LuaTx *ltx = luaL_testudata(L, 1, ssh_tx);
×
UNCOV
65
    if (ltx == NULL) {
×
66
        lua_pushnil(L);
×
67
        return 1;
×
68
    }
×
UNCOV
69
    if (!SCSshTxGetProtocol(ltx->tx, flags, &buf, &b_len)) {
×
70
        lua_pushnil(L);
×
71
        return 1;
×
72
    }
×
UNCOV
73
    return LuaPushStringBuffer(L, buf, b_len);
×
UNCOV
74
}
×
75

76
static int LuaSshTxGetServerProto(lua_State *L)
UNCOV
77
{
×
UNCOV
78
    return LuaSshTxGetProto(L, STREAM_TOCLIENT);
×
UNCOV
79
}
×
80

81
static int LuaSshTxGetClientProto(lua_State *L)
82
{
×
83
    return LuaSshTxGetProto(L, STREAM_TOSERVER);
×
84
}
×
85

86
static int LuaSshTxGetSoftware(lua_State *L, uint8_t flags)
UNCOV
87
{
×
UNCOV
88
    const uint8_t *buf = NULL;
×
UNCOV
89
    uint32_t b_len = 0;
×
UNCOV
90
    struct LuaTx *ltx = luaL_testudata(L, 1, ssh_tx);
×
UNCOV
91
    if (ltx == NULL) {
×
92
        lua_pushnil(L);
×
93
        return 1;
×
94
    }
×
UNCOV
95
    if (!SCSshTxGetSoftware(ltx->tx, flags, &buf, &b_len)) {
×
96
        lua_pushnil(L);
×
97
        return 1;
×
98
    }
×
UNCOV
99
    return LuaPushStringBuffer(L, buf, b_len);
×
UNCOV
100
}
×
101

102
static int LuaSshTxGetServerSoftware(lua_State *L)
UNCOV
103
{
×
UNCOV
104
    return LuaSshTxGetSoftware(L, STREAM_TOCLIENT);
×
UNCOV
105
}
×
106

107
static int LuaSshTxGetClientSoftware(lua_State *L)
UNCOV
108
{
×
UNCOV
109
    return LuaSshTxGetSoftware(L, STREAM_TOSERVER);
×
UNCOV
110
}
×
111

112
static int LuaSshTxGetHassh(lua_State *L, uint8_t flags)
UNCOV
113
{
×
UNCOV
114
    const uint8_t *buf = NULL;
×
UNCOV
115
    uint32_t b_len = 0;
×
UNCOV
116
    struct LuaTx *ltx = luaL_testudata(L, 1, ssh_tx);
×
UNCOV
117
    if (ltx == NULL) {
×
118
        lua_pushnil(L);
×
119
        return 1;
×
120
    }
×
UNCOV
121
    if (SCSshTxGetHassh(ltx->tx, flags, &buf, &b_len) != 1) {
×
122
        lua_pushnil(L);
×
123
        return 1;
×
124
    }
×
UNCOV
125
    return LuaPushStringBuffer(L, buf, b_len);
×
UNCOV
126
}
×
127

128
static int LuaSshTxGetClientHassh(lua_State *L)
UNCOV
129
{
×
UNCOV
130
    return LuaSshTxGetHassh(L, STREAM_TOSERVER);
×
UNCOV
131
}
×
132

133
static int LuaSshTxGetServerHassh(lua_State *L)
UNCOV
134
{
×
UNCOV
135
    return LuaSshTxGetHassh(L, STREAM_TOCLIENT);
×
UNCOV
136
}
×
137

138
static int LuaSshTxGetHasshString(lua_State *L, uint8_t flags)
139
{
×
140
    const uint8_t *buf = NULL;
×
141
    uint32_t b_len = 0;
×
142
    struct LuaTx *ltx = luaL_testudata(L, 1, ssh_tx);
×
143
    if (ltx == NULL) {
×
144
        lua_pushnil(L);
×
145
        return 1;
×
146
    }
×
147
    if (SCSshTxGetHasshString(ltx->tx, flags, &buf, &b_len) != 1) {
×
148
        lua_pushnil(L);
×
149
        return 1;
×
150
    }
×
151
    return LuaPushStringBuffer(L, buf, b_len);
×
152
}
×
153

154
static int LuaSshTxGetClientHasshString(lua_State *L)
155
{
×
156
    return LuaSshTxGetHasshString(L, STREAM_TOSERVER);
×
157
}
×
158

159
static int LuaSshTxGetServerHasshString(lua_State *L)
160
{
×
161
    return LuaSshTxGetHasshString(L, STREAM_TOCLIENT);
×
162
}
×
163

164
static const struct luaL_Reg txlib[] = {
165
    // clang-format off
166
    { "server_proto", LuaSshTxGetServerProto },
167
    { "server_software", LuaSshTxGetServerSoftware },
168
    { "client_proto", LuaSshTxGetClientProto },
169
    { "client_software", LuaSshTxGetClientSoftware },
170
    { "client_hassh", LuaSshTxGetClientHassh },
171
    { "server_hassh", LuaSshTxGetServerHassh },
172
    { "client_hassh_string", LuaSshTxGetClientHasshString },
173
    { "server_hassh_string", LuaSshTxGetServerHasshString },
174
    { NULL, NULL, }
175
    // clang-format on
176
};
177

178
static int LuaSshEnableHassh(lua_State *L)
UNCOV
179
{
×
UNCOV
180
    SCSshEnableHassh();
×
UNCOV
181
    return 1;
×
UNCOV
182
}
×
183

184
static const struct luaL_Reg sshlib[] = {
185
    // clang-format off
186
    { "get_tx", LuaSshGetTx },
187
    { "enable_hassh", LuaSshEnableHassh },
188
    { NULL, NULL,},
189
    // clang-format on
190
};
191

192
int SCLuaLoadSshLib(lua_State *L)
UNCOV
193
{
×
UNCOV
194
    luaL_newmetatable(L, ssh_tx);
×
UNCOV
195
    lua_pushvalue(L, -1);
×
UNCOV
196
    lua_setfield(L, -2, "__index");
×
UNCOV
197
    luaL_setfuncs(L, txlib, 0);
×
198

UNCOV
199
    luaL_newlib(L, sshlib);
×
UNCOV
200
    return 1;
×
UNCOV
201
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc