/src/suricata7/src/detect-requires.c
Line | Count | Source |
1 | | /* Copyright (C) 2023 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 "detect-requires.h" |
19 | | #include "suricata-common.h" |
20 | | #include "detect-engine.h" |
21 | | #include "rust.h" |
22 | | |
23 | | /* Set to true if unknown requirements should be ingored. In Suricata |
24 | | * 8, unknown requirements are treated as unsatisfied requirements. */ |
25 | | static int g_ignore_unknown_requirements = 0; |
26 | | |
27 | | static int DetectRequiresSetup(DetectEngineCtx *de_ctx, Signature *s, const char *rawstr) |
28 | 39.8k | { |
29 | 39.8k | if (de_ctx->requirements == NULL) { |
30 | 2.09k | de_ctx->requirements = (void *)SCDetectRequiresStatusNew(); |
31 | 2.09k | BUG_ON(de_ctx->requirements == NULL); |
32 | 2.09k | } |
33 | | |
34 | 39.8k | const char *errmsg = NULL; |
35 | 39.8k | int res = SCDetectCheckRequires( |
36 | 39.8k | rawstr, PROG_VER, &errmsg, de_ctx->requirements, g_ignore_unknown_requirements); |
37 | 39.8k | if (res == -1) { |
38 | | // The requires expression is bad, log an error. |
39 | 1.10k | SCLogError("%s: %s", errmsg, rawstr); |
40 | 1.10k | de_ctx->sigerror = errmsg; |
41 | 38.7k | } else if (res < -1) { |
42 | | // This Suricata instance didn't meet the requirements. |
43 | 18.0k | SCLogInfo("Suricata did not meet the rule requirements: %s: %s", errmsg, rawstr); |
44 | 18.0k | return -4; |
45 | 18.0k | } |
46 | 21.7k | return res; |
47 | 39.8k | } |
48 | | |
49 | | void DetectRequiresRegister(void) |
50 | 74 | { |
51 | 74 | ConfGetBool("ignore-unknown-requirements", &g_ignore_unknown_requirements); |
52 | | |
53 | 74 | sigmatch_table[DETECT_REQUIRES].name = "requires"; |
54 | 74 | sigmatch_table[DETECT_REQUIRES].desc = "require Suricata version or features"; |
55 | 74 | sigmatch_table[DETECT_REQUIRES].url = "/rules/meta-keywords.html#requires"; |
56 | 74 | sigmatch_table[DETECT_REQUIRES].Setup = DetectRequiresSetup; |
57 | 74 | } |