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));
118 const char *filename = SCRConfGetConfFilename(
de_ctx);
119 if ((fd = fopen(filename,
"r")) == NULL) {
125 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 (
ConfGet(config_value, &path) != 1) {
155 if (
ConfGet(
"reference-config-file", &path) != 1) {
160 if (
ConfGet(
"reference-config-file", &path) != 1) {
197 static char *SCRConfStringToLowercase(
const char *
str)
199 char *new_str = NULL;
200 char *temp_str = NULL;
207 while (*temp_str !=
'\0') {
208 *temp_str =
u8_tolower((
unsigned char)*temp_str);
239 "reference.config file");
244 size_t copylen =
sizeof(system);
245 ret = pcre2_substring_copy_bynumber(
248 SCLogError(
"pcre2_substring_copy_bynumber() failed");
253 copylen =
sizeof(url);
254 ret = pcre2_substring_copy_bynumber(
257 SCLogError(
"pcre2_substring_copy_bynumber() failed");
269 if (ref_lookup == NULL) {
274 SCLogDebug(
"Duplicate reference found inside reference.config");
296 static int SCRConfIsLineBlankOrComment(
char *line)
298 while (*line !=
'\0') {
304 if (!isspace((
unsigned char)*line))
325 while (fgets(line,
sizeof(line), fd) != NULL) {
326 if (SCRConfIsLineBlankOrComment(line))
330 if (is_conf_test_mode) {
338 SCLogInfo(
"tenant id %d: Added \"%d\" reference types from the reference.config file",
341 SCLogInfo(
"Added \"%d\" reference types from the reference.config file",
361 if (system == NULL) {
370 if ((ref->
system = SCRConfStringToLowercase(system)) == NULL) {
375 if (url != NULL && (ref->
url =
SCStrdup(url)) == NULL) {
395 if (ref->
url != NULL)
422 for (i = 0; i <
len; i++)
444 void *data2, uint16_t datalen2)
451 if (ref1 == NULL || ref2 == NULL)
457 len1 = strlen(ref1->
system);
458 len2 = strlen(ref2->
system);
460 if (len1 == len2 && memcmp(ref1->
system, ref2->
system, len1) == 0) {
461 SCLogDebug(
"Match found inside Reference-Config hash function");
496 fd = SCRConfInitContextAndLocalResources(
de_ctx, fd);
503 SCLogError(
"please check the \"reference-config-file\" "
504 "option in your suricata.yaml file");
508 bool rc = SCRConfParseFile(
de_ctx, fd);
509 SCRConfDeInitLocalResources(
de_ctx, fd);
529 if (ref_conf == NULL)
535 return lookup_ref_conf;
550 "config reference: one http://www.one.com\n"
551 "config reference: two http://www.two.com\n"
552 "config reference: three http://www.three.com\n"
553 "config reference: one http://www.one.com\n"
554 "config reference: three http://www.three.com\n";
556 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
558 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
570 "config reference: one http://www.one.com\n"
571 "config_ reference: two http://www.two.com\n"
572 "config reference_: three http://www.three.com\n"
573 "config reference: four\n"
574 "config reference five http://www.five.com\n";
576 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
578 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
590 "config reference one http://www.one.com\n"
591 "config_ reference: two http://www.two.com\n"
592 "config reference_: three http://www.three.com\n"
593 "config reference: four\n";
595 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
597 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
606 static int SCRConfTest01(
void)
634 static int SCRConfTest02(
void)
661 static int SCRConfTest03(
void)
687 static int SCRConfTest04(
void)
719 static int SCRConfTest05(
void)
751 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...
int SCRunmodeGet(void)
Get the current run mode.
#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...
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...