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"
44 static pcre2_code *regex = NULL;
45 static pcre2_match_data *regex_match = NULL;
50 void *data2, uint16_t datalen2);
62 regex = pcre2_compile((PCRE2_SPTR8)
SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
64 PCRE2_UCHAR errbuffer[256];
65 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
67 "pcre2 compile of \"%s\" failed at "
72 regex_match = pcre2_match_data_create_from_pattern(regex, NULL);
80 pcre2_code_free(regex);
83 if (regex_match != NULL) {
84 pcre2_match_data_free(regex_match);
122 const char *filename = SCRConfGetConfFilename(
de_ctx);
123 if ((fd = fopen(filename,
"r")) == NULL) {
150 const char *path = NULL;
153 char config_value[256];
154 snprintf(config_value,
sizeof(config_value),
159 if (
ConfGet(config_value, &path) != 1) {
160 if (
ConfGet(
"reference-config-file", &path) != 1) {
165 if (
ConfGet(
"reference-config-file", &path) != 1) {
202 static char *SCRConfStringToLowercase(
const char *
str)
204 char *new_str = NULL;
205 char *temp_str = NULL;
212 while (*temp_str !=
'\0') {
213 *temp_str =
u8_tolower((
unsigned char)*temp_str);
240 ret = pcre2_match(regex, (PCRE2_SPTR8)line, strlen(line), 0, 0, regex_match, NULL);
243 "reference.config file");
248 size_t copylen =
sizeof(system);
249 ret = pcre2_substring_copy_bynumber(regex_match, 1, (PCRE2_UCHAR8 *)system, ©len);
256 copylen =
sizeof(url);
257 ret = pcre2_substring_copy_bynumber(regex_match, 2, (PCRE2_UCHAR8 *)url, ©len);
271 if (ref_lookup == NULL) {
276 SCLogDebug(
"Duplicate reference found inside reference.config");
298 static int SCRConfIsLineBlankOrComment(
char *line)
300 while (*line !=
'\0') {
306 if (!isspace((
unsigned char)*line))
329 while (fgets(line,
sizeof(line), fd) != NULL) {
330 if (SCRConfIsLineBlankOrComment(line))
334 if (is_conf_test_mode) {
342 SCLogInfo(
"Added \"%d\" reference types from the reference.config file",
362 if (system == NULL) {
372 if ((ref->
system = SCRConfStringToLowercase(system)) == NULL) {
377 if (url != NULL && (ref->
url =
SCStrdup(url)) == NULL) {
397 if (ref->
url != NULL)
424 for (i = 0; i <
len; i++)
446 void *data2, uint16_t datalen2)
453 if (ref1 == NULL || ref2 == NULL)
459 len1 = strlen(ref1->
system);
460 len2 = strlen(ref2->
system);
462 if (len1 == len2 && memcmp(ref1->
system, ref2->
system, len1) == 0) {
463 SCLogDebug(
"Match found inside Reference-Config hash function");
498 fd = SCRConfInitContextAndLocalResources(
de_ctx, fd);
506 "option in your suricata.yaml file");
510 bool rc = SCRConfParseFile(
de_ctx, fd);
511 SCRConfDeInitLocalResources(
de_ctx, fd);
531 if (ref_conf == NULL)
537 return lookup_ref_conf;
552 "config reference: one http://www.one.com\n"
553 "config reference: two http://www.two.com\n"
554 "config reference: three http://www.three.com\n"
555 "config reference: one http://www.one.com\n"
556 "config reference: three http://www.three.com\n";
558 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
560 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
572 "config reference: one http://www.one.com\n"
573 "config_ reference: two http://www.two.com\n"
574 "config reference_: three http://www.three.com\n"
575 "config reference: four\n"
576 "config reference five http://www.five.com\n";
578 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
580 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
592 "config reference one http://www.one.com\n"
593 "config_ reference: two http://www.two.com\n"
594 "config reference_: three http://www.three.com\n"
595 "config reference: four\n";
597 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
599 SCLogDebug(
"Error with SCFmemopen() called by Reference Config test code");
608 static int SCRConfTest01(
void)
636 static int SCRConfTest02(
void)
663 static int SCRConfTest03(
void)
689 static int SCRConfTest04(
void)
721 static int SCRConfTest05(
void)
753 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...
void SCReferenceConfDeinit(void)
void SCReferenceConfInit(void)
#define SC_RCONF_DEFAULT_FILE_PATH
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
main detection engine ctx
@ SC_ERR_INVALID_SIGNATURE
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
@ SC_ERR_PCRE_GET_SUBSTRING
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.
FILE * SCRConfGenerateInValidDummyReferenceConfigFD03(void)
Creates a dummy reference config, with all invalid references, for testing purposes.
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
#define REFERENCE_SYSTEM_NAME_MAX
FILE * SCRConfGenerateInValidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
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 ...
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
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 SCLogWarning(err_code,...)
Macro used to log WARNING 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...
@ SC_ERR_REFERENCE_CONFIG