Go to the documentation of this file.
39 #define SC_RCONF_REGEX "^\\s*config\\s+reference\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s+(.+)\\s*$"
42 #define SC_RCONF_DEFAULT_FILE_PATH CONFIG_DIR "/reference.config"
47 void *data2, uint16_t datalen2);
60 pcre2_compile((PCRE2_SPTR8)
SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
62 PCRE2_UCHAR errbuffer[256];
63 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
119 const char *filename = SCRConfGetConfFilename(
de_ctx);
120 if ((fd = fopen(filename,
"r")) == NULL) {
126 SCLogError(
"Error opening file: \"%s\": %s", filename, strerror(errno));
146 const char *path = NULL;
149 char config_value[256];
150 snprintf(config_value,
sizeof(config_value),
155 if (
ConfGet(config_value, &path) != 1) {
156 if (
ConfGet(
"reference-config-file", &path) != 1) {
161 if (
ConfGet(
"reference-config-file", &path) != 1) {
198 static char *SCRConfStringToLowercase(
const char *
str)
200 char *new_str = NULL;
201 char *temp_str = NULL;
208 while (*temp_str !=
'\0') {
209 *temp_str =
u8_tolower((
unsigned char)*temp_str);
240 "reference.config file");
245 size_t copylen =
sizeof(system);
246 ret = pcre2_substring_copy_bynumber(
249 SCLogError(
"pcre2_substring_copy_bynumber() failed");
254 copylen =
sizeof(url);
255 ret = pcre2_substring_copy_bynumber(
258 SCLogError(
"pcre2_substring_copy_bynumber() failed");
270 if (ref_lookup == NULL) {
275 SCLogDebug(
"Duplicate reference found inside reference.config");
297 static int SCRConfIsLineBlankOrComment(
char *line)
299 while (*line !=
'\0') {
305 if (!isspace((
unsigned char)*line))
326 while (fgets(line,
sizeof(line), fd) != NULL) {
327 if (SCRConfIsLineBlankOrComment(line))
331 if (is_conf_test_mode) {
338 SCLogInfo(
"Added \"%d\" reference types from the reference.config file",
358 if (system == NULL) {
368 if ((ref->
system = SCRConfStringToLowercase(system)) == NULL) {
373 if (url != NULL && (ref->
url =
SCStrdup(url)) == NULL) {
393 if (ref->
url != NULL)
420 for (i = 0; i <
len; i++)
442 void *data2, uint16_t datalen2)
449 if (ref1 == NULL || ref2 == NULL)
455 len1 = strlen(ref1->
system);
456 len2 = strlen(ref2->
system);
458 if (len1 == len2 && memcmp(ref1->
system, ref2->
system, len1) == 0) {
459 SCLogDebug(
"Match found inside Reference-Config hash function");
494 fd = SCRConfInitContextAndLocalResources(
de_ctx, fd);
501 SCLogError(
"please check the \"reference-config-file\" "
502 "option in your suricata.yaml file");
506 bool rc = SCRConfParseFile(
de_ctx, fd);
507 SCRConfDeInitLocalResources(
de_ctx, fd);
527 if (ref_conf == NULL)
533 return lookup_ref_conf;
548 "config reference: one http://www.one.com\n"
549 "config reference: two http://www.two.com\n"
550 "config reference: three http://www.three.com\n"
551 "config reference: one http://www.one.com\n"
552 "config reference: three http://www.three.com\n";
554 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
556 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
568 "config reference: one http://www.one.com\n"
569 "config_ reference: two http://www.two.com\n"
570 "config reference_: three http://www.three.com\n"
571 "config reference: four\n"
572 "config reference five http://www.five.com\n";
574 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
576 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
588 "config reference one http://www.one.com\n"
589 "config_ reference: two http://www.two.com\n"
590 "config reference_: three http://www.three.com\n"
591 "config reference: four\n";
593 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
595 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
604 static int SCRConfTest01(
void)
632 static int SCRConfTest02(
void)
659 static int SCRConfTest03(
void)
685 static int SCRConfTest04(
void)
717 static int SCRConfTest05(
void)
749 static int SCRConfTest06(
void)
char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
Used to compare two References that have been stored in the HashTable. This function is supplied as a...
#define SC_RCONF_DEFAULT_FILE_PATH
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD03(void)
Creates a dummy reference config, with all invalid references, for testing purposes.
main detection engine ctx
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
pcre2_match_data * reference_conf_regex_match
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
void SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
pcre2_code * reference_conf_regex
HashTable * reference_conf_ht
void HashTableFree(HashTable *ht)
void SCRConfDeInitContext(DetectEngineCtx *de_ctx)
Releases de_ctx resources related to Reference Config API.
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
#define SCLogWarning(...)
Macro used to log WARNING messages.
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
#define REFERENCE_SYSTEM_NAME_MAX
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Reference info from the reference.config file.
int SCRConfAddReference(DetectEngineCtx *de_ctx, const char *line)
Parses a line from the reference config file and adds it to Reference Config hash table DetectEngineC...
int RunmodeIsUnittests(void)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
SCRConfReference * SCRConfGetReference(const char *rconf_name, DetectEngineCtx *de_ctx)
Gets the reference config from the corresponding hash table stored in the Detection Engine Context's ...
void SCReferenceConfInit(DetectEngineCtx *de_ctx)
Holds a reference from the file - reference.config.
uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen)
Hashing function to be used to hash the Reference name. Would be supplied as an argument to the HashT...
int RunmodeGetCurrent(void)
void SCRConfRegisterTests(void)
This function registers unit tests for Reference Config API.
#define SCLogError(...)
Macro used to log ERROR messages.
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)
SCRConfReference * SCRConfAllocSCRConfReference(const char *system, const char *url)
Returns a new SCRConfReference instance. The reference string is converted into lowercase,...
FILE * SCRConfGenerateValidDummyReferenceConfigFD01(void)
Creates a dummy reference config, with all valid references, for testing purposes.
void SCRConfDeAllocSCRConfReference(SCRConfReference *ref)
Frees a SCRConfReference instance.
#define REFERENCE_CONTENT_NAME_MAX
void SCRConfReferenceHashFree(void *ch)
Used to free the Reference Config Hash Data that was stored in DetectEngineCtx->reference_conf_ht Has...