Go to the documentation of this file.
38 #define SC_RCONF_REGEX "^\\s*config\\s+reference\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s+(.+)\\s*$"
41 #define SC_RCONF_DEFAULT_FILE_PATH CONFIG_DIR "/reference.config"
46 void *data2, uint16_t datalen2);
59 pcre2_compile((PCRE2_SPTR8)
SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
61 PCRE2_UCHAR errbuffer[256];
62 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
117 const char *filename = SCRConfGetConfFilename(
de_ctx);
118 if ((fd = fopen(filename,
"r")) == NULL) {
124 SCLogError(
"Error opening file: \"%s\": %s", filename, strerror(errno));
145 const char *path = NULL;
148 char config_value[256];
149 snprintf(config_value,
sizeof(config_value),
154 if (
SCConfGet(config_value, &path) != 1) {
155 if (
SCConfGet(
"reference-config-file", &path) != 1) {
160 if (
SCConfGet(
"reference-config-file", &path) != 1) {
170 static void SCRConfDeInitLocalResources(FILE *fd)
193 static char *SCRConfStringToLowercase(
const char *
str)
195 char *new_str = NULL;
196 char *temp_str = NULL;
203 while (*temp_str !=
'\0') {
204 *temp_str =
u8_tolower((
unsigned char)*temp_str);
235 "reference.config file");
240 size_t copylen =
sizeof(system);
241 ret = pcre2_substring_copy_bynumber(
244 SCLogError(
"pcre2_substring_copy_bynumber() failed");
249 copylen =
sizeof(url);
250 ret = pcre2_substring_copy_bynumber(
253 SCLogError(
"pcre2_substring_copy_bynumber() failed");
265 if (ref_lookup == NULL) {
270 SCLogDebug(
"Duplicate reference found inside reference.config");
292 static int SCRConfIsLineBlankOrComment(
char *line)
294 while (*line !=
'\0') {
300 if (!isspace((
unsigned char)*line))
321 while (fgets(line,
sizeof(line), fd) != NULL) {
322 if (SCRConfIsLineBlankOrComment(line))
326 if (is_conf_test_mode) {
334 SCLogInfo(
"tenant id %d: Added \"%d\" reference types from the reference.config file",
337 SCLogInfo(
"Added \"%d\" reference types from the reference.config file",
357 if (system == NULL) {
366 if ((ref->
system = SCRConfStringToLowercase(system)) == NULL) {
371 if (url != NULL && (ref->
url =
SCStrdup(url)) == NULL) {
391 if (ref->
url != NULL)
416 for (i = 0; i <
len; i++)
438 void *data2, uint16_t datalen2)
443 if (ref1 == NULL || ref2 == NULL)
450 SCLogDebug(
"Match found inside Reference-Config hash function");
483 fd = SCRConfInitContextAndLocalResources(
de_ctx, fd);
490 SCLogError(
"please check the \"reference-config-file\" "
491 "option in your suricata.yaml file");
495 bool rc = SCRConfParseFile(
de_ctx, fd);
496 SCRConfDeInitLocalResources(fd);
516 if (ref_conf == NULL)
522 return lookup_ref_conf;
537 "config reference: one http://www.one.com\n"
538 "config reference: two http://www.two.com\n"
539 "config reference: three http://www.three.com\n"
540 "config reference: one http://www.one.com\n"
541 "config reference: three http://www.three.com\n";
543 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
545 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
557 "config reference: one http://www.one.com\n"
558 "config_ reference: two http://www.two.com\n"
559 "config reference_: three http://www.three.com\n"
560 "config reference: four\n"
561 "config reference five http://www.five.com\n";
563 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
565 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
577 "config reference one http://www.one.com\n"
578 "config_ reference: two http://www.two.com\n"
579 "config reference_: three http://www.three.com\n"
580 "config reference: four\n";
582 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
584 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
593 static int SCRConfTest01(
void)
622 static int SCRConfTest02(
void)
650 static int SCRConfTest03(
void)
677 static int SCRConfTest04(
void)
710 static int SCRConfTest05(
void)
743 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,...
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
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)
Free a HashTable and all its contents.
void SCRConfDeInitContext(DetectEngineCtx *de_ctx)
Releases de_ctx resources related to Reference Config API.
SCRunMode SCRunmodeGet(void)
Get the current run mode.
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.
void SCReferenceSCConfInit(DetectEngineCtx *de_ctx)
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 ...
#define DEBUG_VALIDATE_MARK_SANITIZED(ptr)
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...
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...