Go to the documentation of this file.
42 #define DETECT_CLASSCONFIG_REGEX "^\\s*config\\s*classification\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s*,\\s*(.+)\\s*,\\s*(\\d+)\\s*$"
45 #if defined OS_WIN32 || defined __CYGWIN__
46 #define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "\\\\classification.config"
48 #define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config"
53 void *data2, uint16_t datalen2);
58 const char *classtype,
const char *classtype_desc,
int priority);
70 PCRE2_UCHAR errbuffer[256];
71 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
128 const char *filename = SCClassConfGetConfFilename(
de_ctx);
129 if ( (fd = fopen(filename,
"r")) == NULL) {
134 SCLogWarning(
"could not open: \"%s\": %s", filename, strerror(errno));
155 const char *log_filename = NULL;
158 char config_value[256];
159 snprintf(config_value,
sizeof(config_value),
164 if (
SCConfGet(config_value, &log_filename) != 1) {
165 if (
SCConfGet(
"classification-file", &log_filename) != 1) {
170 if (
SCConfGet(
"classification-file", &log_filename) != 1) {
181 static void SCClassConfDeInitLocalResources(FILE *fd)
204 static char *SCClassConfStringToLowercase(
const char *
str)
206 char *new_str = NULL;
207 char *temp_str = NULL;
215 while (*temp_str !=
'\0') {
216 *temp_str =
u8_tolower((
unsigned char)*temp_str);
238 char ct_priority_str[16];
239 uint32_t ct_priority = 0;
240 uint16_t ct_id = index;
251 "classification.config file %s: \"%s\"",
252 SCClassConfGetConfFilename(
de_ctx), rawstr);
256 size_t copylen =
sizeof(ct_name);
258 ret = pcre2_substring_copy_bynumber(
261 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
266 copylen =
sizeof(ct_desc);
267 ret = pcre2_substring_copy_bynumber(
270 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
275 copylen =
sizeof(ct_priority_str);
276 ret = pcre2_substring_copy_bynumber(
279 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
287 ct_new = SCClassConfAllocClasstype(ct_id, ct_name, ct_desc, ct_priority);
294 if (ct_lookup == NULL) {
298 SCLogDebug(
"Duplicate classtype found inside classification.config");
322 static int SCClassConfIsLineBlankOrComment(
char *line)
324 while (*line !=
'\0') {
330 if (!isspace((
unsigned char)*line))
352 while (fgets(line,
sizeof(line), fd) != NULL) {
353 if (SCClassConfIsLineBlankOrComment(line))
365 SCLogInfo(
"tenant id %d: Added \"%d\" classification types from the classification file",
368 SCLogInfo(
"Added \"%d\" classification types from the classification file",
388 const char *classtype,
389 const char *classtype_desc,
394 if (classtype == NULL)
400 if ((ct->
classtype = SCClassConfStringToLowercase(classtype)) == NULL) {
401 SCClassConfDeAllocClasstype(ct);
405 if (classtype_desc != NULL &&
409 SCClassConfDeAllocClasstype(ct);
456 for (i = 0; i <
len; i++)
478 void *data2, uint16_t datalen2)
483 if (ct1 == NULL || ct2 == NULL)
490 SCLogDebug(
"Match found inside Classification-Config hash function");
505 SCClassConfDeAllocClasstype(ch);
522 fd = SCClassConfInitContextAndLocalResources(
de_ctx, fd);
529 SCLogError(
"please check the \"classification-file\" "
530 "option in your suricata.yaml file");
535 if (!SCClassConfParseFile(
de_ctx, fd)) {
536 SCLogWarning(
"Error loading classification configuration from %s",
537 SCClassConfGetConfFilename(
de_ctx));
541 SCClassConfDeInitLocalResources(fd);
564 char name[strlen(ct_name) + 1];
566 for (s = 0; s < strlen(ct_name); s++)
573 return lookup_ct_info;
590 "config classification: nothing-wrong,Nothing Wrong With Us,3\n"
591 "config classification: unknown,Unknown are we,3\n"
592 "config classification: bad-unknown,We think it's bad, 2\n";
594 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
596 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
610 "config classification: not-suspicious,Not Suspicious Traffic,3\n"
611 "onfig classification: unknown,Unknown Traffic,3\n"
612 "config classification: _badunknown,Potentially Bad Traffic, 2\n"
613 "config classification: bamboola1,Unknown Traffic,3\n"
614 "config classification: misc-activity,Misc activity,-1\n"
615 "config classification: policy-violation,Potential Corporate "
616 "config classification: bamboola,Unknown Traffic,3\n";
618 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
620 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
634 "conig classification: not-suspicious,Not Suspicious Traffic,3\n"
635 "onfig classification: unknown,Unknown Traffic,3\n"
636 "config classification: _badunknown,Potentially Bad Traffic, 2\n"
637 "config classification: misc-activity,Misc activity,-1\n";
639 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
641 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
650 static int SCClassConfTest01(
void)
677 static int SCClassConfTest02(
void)
703 static int SCClassConfTest03(
void)
722 static int SCClassConfTest04(
void)
750 static int SCClassConfTest05(
void)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
HashTable * class_conf_ht
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void SCClassSCConfInit(DetectEngineCtx *de_ctx)
main detection engine ctx
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
uint32_t SCClassConfClasstypeHashFunc(HashTable *ht, void *data, uint16_t datalen)
Hashing function to be used to hash the Classtype name. Would be supplied as an argument to the HashT...
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
void SCClassConfClasstypeHashFree(void *ch)
Used to free the Classification Config Hash Data that was stored in DetectEngineCtx->class_conf_ht Ha...
#define DETECT_CLASSCONFIG_REGEX
pcre2_code * class_conf_regex
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
void HashTableFree(HashTable *ht)
Free a HashTable and all its contents.
FILE * SCClassConfGenerateInvalidDummyClassConfigFD02(void)
Creates a dummy classification file, with some valid Classtypes and a couple of invalid Classtypes,...
pcre2_match_data * class_conf_regex_match
#define PASS
Pass the test.
Container for a Classtype from the Classification.config file.
#define SC_CLASS_CONF_DEF_CONF_FILEPATH
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
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,...
void SCClassConfDeinit(DetectEngineCtx *de_ctx)
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
#define SCLogWarning(...)
Macro used to log WARNING messages.
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
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...
int RunmodeIsUnittests(void)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
FILE * SCClassConfGenerateInvalidDummyClassConfigFD03(void)
Creates a dummy classification file, with all invalid Classtypes, for testing purposes.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
#define DEBUG_VALIDATE_MARK_SANITIZED(ptr)
#define CLASSTYPE_DESC_MAX_LEN
void SCClassConfRegisterTests(void)
This function registers unit tests for Classification Config API.
#define SCLogError(...)
Macro used to log ERROR messages.
#define CLASSTYPE_NAME_MAX_LEN
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
DetectEngineCtx * DetectEngineCtxInit(void)
char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
Used to compare two Classtypes that have been stored in the HashTable. This function is supplied as a...
FILE * SCClassConfGenerateValidDummyClassConfigFD01(void)
Creates a dummy classification file, with all valid Classtypes, for testing purposes.
#define DEBUG_VALIDATE_BUG_ON(exp)
bool SCClassConfLoadClassificationConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Classtype info from the classification.config file.
void SCClassConfDeInitContext(DetectEngineCtx *de_ctx)
Releases resources used by the Classification Config API.