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 (
SCConfGet(config_value, &path) != 1) {
154 if (
SCConfGet(
"reference-config-file", &path) != 1) {
159 if (
SCConfGet(
"reference-config-file", &path) != 1) {
169static void SCRConfDeInitLocalResources(FILE *fd)
192static 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");
291static 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");
597static int SCRConfTest01(
void)
625static int SCRConfTest02(
void)
652static int SCRConfTest03(
void)
678static int SCRConfTest04(
void)
710static int SCRConfTest05(
void)
742static int SCRConfTest06(
void)
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
main detection engine ctx
pcre2_match_data * reference_conf_regex_match
HashTable * reference_conf_ht
pcre2_code * reference_conf_regex
Holds a reference from the file - reference.config.
SCRunMode SCRunmodeGet(void)
Get the current run mode.
int RunmodeIsUnittests(void)
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCLogError(...)
Macro used to log ERROR messages.
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
void HashTableFree(HashTable *ht)
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD03(void)
Creates a dummy reference config, with all invalid references, for testing purposes.
void SCReferenceSCConfInit(DetectEngineCtx *de_ctx)
void SCRConfReferenceHashFree(void *ch)
Used to free the Reference Config Hash Data that was stored in DetectEngineCtx->reference_conf_ht Has...
FILE * SCRConfGenerateValidDummyReferenceConfigFD01(void)
Creates a dummy reference config, with all valid references, for testing purposes.
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...
#define SC_RCONF_DEFAULT_FILE_PATH
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...
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...
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
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 SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
void SCRConfRegisterTests(void)
This function registers unit tests for Reference Config API.
void SCRConfDeAllocSCRConfReference(SCRConfReference *ref)
Frees a SCRConfReference instance.
void SCRConfDeInitContext(DetectEngineCtx *de_ctx)
Releases de_ctx resources related to Reference Config API.
SCRConfReference * SCRConfAllocSCRConfReference(const char *system, const char *url)
Returns a new SCRConfReference instance. The reference string is converted into lowercase,...
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Reference info from the reference.config file.
#define REFERENCE_SYSTEM_NAME_MAX
#define REFERENCE_CONTENT_NAME_MAX