Go to the documentation of this file.
39 #define PARSE_REGEX "^\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s*$"
45 static void DetectClasstypeRegisterTests(
void);
70 static int DetectClasstypeParseRawString(
const char *rawstr,
char *out,
size_t outsize)
76 pcre2_match_data *match = NULL;
85 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)e, &pcre2len);
87 SCLogError(
"pcre2_substring_copy_bynumber failed");
97 pcre2_match_data_free(match);
102 pcre2_match_data_free(match);
125 "keyword detected.");
129 "keyword detected. Using instance with highest priority");
133 if (DetectClasstypeParseRawString(rawstr, parsed_ct_name,
sizeof(parsed_ct_name)) < 0) {
134 SCLogError(
"invalid value for classtype keyword: "
144 SCLogError(
"unknown classtype '%s'", parsed_ct_name);
150 "unknown classtype: \"%s\", using default priority %d. "
151 "This message won't be shown again for this classtype",
155 "unknown classtype: \"%s\", using default priority %d. "
156 "This message won't be shown again for this classtype",
160 "using default priority %d. "
161 "This message won't be shown again for this classtype",
166 snprintf(
str,
sizeof(
str),
167 "config classification: %s,Unknown Classtype,%d\n",
183 bool update_ct =
false;
187 }
else if (s->
prio == -1) {
197 if (real_ct && update_ct) {
209 static int DetectClasstypeTest01(
void)
218 "(msg:\"Classtype test\"; "
219 "Classtype:not_available; sid:1;)");
232 static int DetectClasstypeTest02(
void)
242 "(Classtype:bad-unknown; sid:1;)");
246 "(Classtype:not-there; sid:2;)");
250 "(Classtype:Bad-UnkNown; sid:3;)");
254 "(Classtype:nothing-wrong; sid:4;)");
258 "(Classtype:attempted_dos; Classtype:bad-unknown; sid:5;)");
264 "(Classtype:nothing-wrong; Classtype:Bad-UnkNown; sid:6;)");
276 static int DetectClasstypeTest03(
void)
286 "(msg:\"Classtype test\"; Classtype:bad-unknown; priority:1; sid:1;)");
291 "(msg:\"Classtype test\"; Classtype:unKnoWn; "
292 "priority:3; sid:2;)");
297 "Classtype:nothing-wrong; priority:1; sid:3;)");
301 "(msg:\"Classtype test\"; Classtype:bad-unknown; Classtype:undefined; "
302 "priority:5; sid:4;)");
313 static void DetectClasstypeRegisterTests(
void)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
SigTableElmt * sigmatch_table
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define SIG_FLAG_INIT_PRIO_EXPLICIT
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
size_t strlcpy(char *dst, const char *src, size_t siz)
#define PASS
Pass the test.
Container for a Classtype from the Classification.config file.
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
int SCClassConfAddClasstype(DetectEngineCtx *de_ctx, char *rawstr, uint16_t index)
Parses a line from the classification file and adds it to Classtype hash table in DetectEngineCtx,...
bool SigMatchStrictEnabled(const enum DetectKeywordId id)
#define SCLogWarning(...)
Macro used to log WARNING messages.
SCClassConfClasstype * SCClassConfGetClasstype(const char *ct_name, DetectEngineCtx *de_ctx)
Gets the classtype from the corresponding hash table stored in the Detection Engine Context's class c...
SignatureInitData * init_data
#define SCLogError(...)
Macro used to log ERROR messages.
#define CLASSTYPE_NAME_MAX_LEN
DetectEngineCtx * DetectEngineCtxInit(void)
FILE * SCClassConfGenerateValidDummyClassConfigFD01(void)
Creates a dummy classification file, with all valid Classtypes, for testing purposes.
#define DETECT_DEFAULT_PRIO
void DetectClasstypeRegister(void)
Registers the handler functions for the "Classtype" keyword.
bool SCClassConfLoadClassificationConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Classtype info from the classification.config file.
void(* RegisterTests)(void)