/src/suricata7/src/detect-nocase.c
Line | Count | Source |
1 | | /* Copyright (C) 2007-2010 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 | | * \file |
20 | | * |
21 | | * \author Victor Julien <victor@inliniac.net> |
22 | | * |
23 | | * Implements the nocase keyword |
24 | | */ |
25 | | |
26 | | #include "suricata-common.h" |
27 | | #include "suricata.h" |
28 | | #include "decode.h" |
29 | | |
30 | | #include "detect.h" |
31 | | #include "detect-parse.h" |
32 | | #include "detect-content.h" |
33 | | #include "detect-nocase.h" |
34 | | |
35 | | #include "util-debug.h" |
36 | | |
37 | | static int DetectNocaseSetup (DetectEngineCtx *, Signature *, const char *); |
38 | | |
39 | | void DetectNocaseRegister(void) |
40 | 73 | { |
41 | 73 | sigmatch_table[DETECT_NOCASE].name = "nocase"; |
42 | 73 | sigmatch_table[DETECT_NOCASE].desc = "modify content match to be case insensitive"; |
43 | 73 | sigmatch_table[DETECT_NOCASE].url = "/rules/payload-keywords.html#nocase"; |
44 | 73 | sigmatch_table[DETECT_NOCASE].Setup = DetectNocaseSetup; |
45 | 73 | sigmatch_table[DETECT_NOCASE].flags |= SIGMATCH_NOOPT; |
46 | 73 | } |
47 | | |
48 | | /** |
49 | | * \internal |
50 | | * \brief Apply the nocase keyword to the last pattern match, either content or uricontent |
51 | | * \param det_ctx detection engine ctx |
52 | | * \param s signature |
53 | | * \param nullstr should be null |
54 | | * \retval 0 ok |
55 | | * \retval -1 failure |
56 | | */ |
57 | | static int DetectNocaseSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr) |
58 | 95.2k | { |
59 | 95.2k | SCEnter(); |
60 | | |
61 | 95.2k | SigMatch *pm = NULL; |
62 | 95.2k | int ret = -1; |
63 | | |
64 | 95.2k | if (nullstr != NULL) { |
65 | 0 | SCLogError("nocase has value"); |
66 | 0 | goto end; |
67 | 0 | } |
68 | | |
69 | | /* retrieve the sm to apply the nocase against */ |
70 | 95.2k | pm = DetectGetLastSMFromLists(s, DETECT_CONTENT, -1); |
71 | 95.2k | if (pm == NULL) { |
72 | 3.19k | SCLogError("nocase needs " |
73 | 3.19k | "preceding content option"); |
74 | 3.19k | goto end; |
75 | 3.19k | } |
76 | | |
77 | 92.0k | DetectContentData *cd = (DetectContentData *)pm->ctx; |
78 | 92.0k | ret = DetectContentConvertToNocase(de_ctx, cd); |
79 | 95.2k | end: |
80 | 95.2k | SCReturnInt(ret); |
81 | 92.0k | } |