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));
144 const char *path = NULL;
147 char config_value[256];
148 snprintf(config_value,
sizeof(config_value),
153 if (
ConfGet(config_value, &path) != 1) {
154 if (
ConfGet(
"reference-config-file", &path) != 1) {
159 if (
ConfGet(
"reference-config-file", &path) != 1) {
169 static void SCRConfDeInitLocalResources(FILE *fd)
192 static char *SCRConfStringToLowercase(
const char *
str)
194 char *new_str = NULL;
195 char *temp_str = NULL;
202 while (*temp_str !=
'\0') {
203 *temp_str =
u8_tolower((
unsigned char)*temp_str);
234 "reference.config file");
239 size_t copylen =
sizeof(system);
240 ret = pcre2_substring_copy_bynumber(
243 SCLogError(
"pcre2_substring_copy_bynumber() failed");
248 copylen =
sizeof(url);
249 ret = pcre2_substring_copy_bynumber(
252 SCLogError(
"pcre2_substring_copy_bynumber() failed");
264 if (ref_lookup == NULL) {
269 SCLogDebug(
"Duplicate reference found inside reference.config");
291 static int SCRConfIsLineBlankOrComment(
char *line)
293 while (*line !=
'\0') {
299 if (!isspace((
unsigned char)*line))
320 while (fgets(line,
sizeof(line), fd) != NULL) {
321 if (SCRConfIsLineBlankOrComment(line))
325 if (is_conf_test_mode) {
333 SCLogInfo(
"tenant id %d: Added \"%d\" reference types from the reference.config file",
336 SCLogInfo(
"Added \"%d\" reference types from the reference.config file",
356 if (system == NULL) {
365 if ((ref->
system = SCRConfStringToLowercase(system)) == NULL) {
370 if (url != NULL && (ref->
url =
SCStrdup(url)) == NULL) {
390 if (ref->
url != NULL)
415 for (i = 0; i <
len; i++)
437 void *data2, uint16_t datalen2)
444 if (ref1 == NULL || ref2 == NULL)
450 len1 = strlen(ref1->
system);
451 len2 = strlen(ref2->
system);
453 if (len1 == len2 && memcmp(ref1->
system, ref2->
system, len1) == 0) {
454 SCLogDebug(
"Match found inside Reference-Config hash function");
487 fd = SCRConfInitContextAndLocalResources(
de_ctx, fd);
494 SCLogError(
"please check the \"reference-config-file\" "
495 "option in your suricata.yaml file");
499 bool rc = SCRConfParseFile(
de_ctx, fd);
500 SCRConfDeInitLocalResources(fd);
520 if (ref_conf == NULL)
526 return lookup_ref_conf;
541 "config reference: one http://www.one.com\n"
542 "config reference: two http://www.two.com\n"
543 "config reference: three http://www.three.com\n"
544 "config reference: one http://www.one.com\n"
545 "config reference: three http://www.three.com\n";
547 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
549 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
561 "config reference: one http://www.one.com\n"
562 "config_ reference: two http://www.two.com\n"
563 "config reference_: three http://www.three.com\n"
564 "config reference: four\n"
565 "config reference five http://www.five.com\n";
567 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
569 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
581 "config reference one http://www.one.com\n"
582 "config_ reference: two http://www.two.com\n"
583 "config reference_: three http://www.three.com\n"
584 "config reference: four\n";
586 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
588 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
597 static int SCRConfTest01(
void)
625 static int SCRConfTest02(
void)
652 static int SCRConfTest03(
void)
678 static int SCRConfTest04(
void)
710 static int SCRConfTest05(
void)
742 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...