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));
154 const char *log_filename = NULL;
157 char config_value[256];
158 snprintf(config_value,
sizeof(config_value),
163 if (
SCConfGet(config_value, &log_filename) != 1) {
164 if (
SCConfGet(
"classification-file", &log_filename) != 1) {
169 if (
SCConfGet(
"classification-file", &log_filename) != 1) {
180 static void SCClassConfDeInitLocalResources(FILE *fd)
203 static char *SCClassConfStringToLowercase(
const char *
str)
205 char *new_str = NULL;
206 char *temp_str = NULL;
214 while (*temp_str !=
'\0') {
215 *temp_str =
u8_tolower((
unsigned char)*temp_str);
237 char ct_priority_str[16];
238 uint32_t ct_priority = 0;
239 uint16_t ct_id = index;
250 "classification.config file %s: \"%s\"",
251 SCClassConfGetConfFilename(
de_ctx), rawstr);
255 size_t copylen =
sizeof(ct_name);
257 ret = pcre2_substring_copy_bynumber(
260 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
265 copylen =
sizeof(ct_desc);
266 ret = pcre2_substring_copy_bynumber(
269 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
274 copylen =
sizeof(ct_priority_str);
275 ret = pcre2_substring_copy_bynumber(
278 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
286 ct_new = SCClassConfAllocClasstype(ct_id, ct_name, ct_desc, ct_priority);
293 if (ct_lookup == NULL) {
297 SCLogDebug(
"Duplicate classtype found inside classification.config");
321 static int SCClassConfIsLineBlankOrComment(
char *line)
323 while (*line !=
'\0') {
329 if (!isspace((
unsigned char)*line))
351 while (fgets(line,
sizeof(line), fd) != NULL) {
352 if (SCClassConfIsLineBlankOrComment(line))
364 SCLogInfo(
"tenant id %d: Added \"%d\" classification types from the classification file",
367 SCLogInfo(
"Added \"%d\" classification types from the classification file",
387 const char *classtype,
388 const char *classtype_desc,
393 if (classtype == NULL)
399 if ((ct->
classtype = SCClassConfStringToLowercase(classtype)) == NULL) {
400 SCClassConfDeAllocClasstype(ct);
404 if (classtype_desc != NULL &&
408 SCClassConfDeAllocClasstype(ct);
455 for (i = 0; i <
len; i++)
477 void *data2, uint16_t datalen2)
484 if (ct1 == NULL || ct2 == NULL)
494 SCLogDebug(
"Match found inside Classification-Config hash function");
509 SCClassConfDeAllocClasstype(ch);
526 fd = SCClassConfInitContextAndLocalResources(
de_ctx, fd);
533 SCLogError(
"please check the \"classification-file\" "
534 "option in your suricata.yaml file");
539 if (!SCClassConfParseFile(
de_ctx, fd)) {
540 SCLogWarning(
"Error loading classification configuration from %s",
541 SCClassConfGetConfFilename(
de_ctx));
545 SCClassConfDeInitLocalResources(fd);
568 char name[strlen(ct_name) + 1];
570 for (s = 0; s < strlen(ct_name); s++)
577 return lookup_ct_info;
594 "config classification: nothing-wrong,Nothing Wrong With Us,3\n"
595 "config classification: unknown,Unknown are we,3\n"
596 "config classification: bad-unknown,We think it's bad, 2\n";
598 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
600 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
614 "config classification: not-suspicious,Not Suspicious Traffic,3\n"
615 "onfig classification: unknown,Unknown Traffic,3\n"
616 "config classification: _badunknown,Potentially Bad Traffic, 2\n"
617 "config classification: bamboola1,Unknown Traffic,3\n"
618 "config classification: misc-activity,Misc activity,-1\n"
619 "config classification: policy-violation,Potential Corporate "
620 "config classification: bamboola,Unknown Traffic,3\n";
622 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
624 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
638 "conig classification: not-suspicious,Not Suspicious Traffic,3\n"
639 "onfig classification: unknown,Unknown Traffic,3\n"
640 "config classification: _badunknown,Potentially Bad Traffic, 2\n"
641 "config classification: misc-activity,Misc activity,-1\n";
643 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
645 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
654 static int SCClassConfTest01(
void)
681 static int SCClassConfTest02(
void)
707 static int SCClassConfTest03(
void)
726 static int SCClassConfTest04(
void)
754 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 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.