suricata
util-reference-config.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22  */
23 
24 #include "suricata-common.h"
25 #include "detect.h"
26 #include "detect-engine.h"
27 #include "util-hash.h"
28 
29 #include "util-reference-config.h"
30 #include "conf.h"
31 #include "util-unittest.h"
32 #include "util-debug.h"
33 #include "util-fmemopen.h"
34 
35 /* Regex to parse each line from reference.config file. The first substring
36  * is for the system name and the second for the url */
37 /*-----------------------------------------------------------system-------------------url----*/
38 #define SC_RCONF_REGEX "^\\s*config\\s+reference\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s+(.+)\\s*$"
39 
40 /* Default path for the reference.conf file */
41 #define SC_RCONF_DEFAULT_FILE_PATH CONFIG_DIR "/reference.config"
42 
43 /* the hash functions */
44 uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen);
45 char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
46  void *data2, uint16_t datalen2);
47 void SCRConfReferenceHashFree(void *ch);
48 
49 /* used to get the reference.config file path */
50 static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx);
51 
53 {
54  int en;
55  PCRE2_SIZE eo;
56  int opts = 0;
57 
59  pcre2_compile((PCRE2_SPTR8)SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
60  if (de_ctx->reference_conf_regex == NULL) {
61  PCRE2_UCHAR errbuffer[256];
62  pcre2_get_error_message(en, errbuffer, sizeof(errbuffer));
63  SCLogWarning("pcre2 compile of \"%s\" failed at "
64  "offset %d: %s",
65  SC_RCONF_REGEX, (int)eo, errbuffer);
66  return;
67  }
69  pcre2_match_data_create_from_pattern(de_ctx->reference_conf_regex, NULL);
70  return;
71 }
72 
74 {
75  if (de_ctx->reference_conf_regex != NULL) {
76  pcre2_code_free(de_ctx->reference_conf_regex);
78  }
79  if (de_ctx->reference_conf_regex_match != NULL) {
80  pcre2_match_data_free(de_ctx->reference_conf_regex_match);
82  }
83 }
84 
85 
86 /**
87  * \brief Inits the context to be used by the Reference Config parsing API.
88  *
89  * This function initializes the hash table to be used by the Detection
90  * Engine Context to hold the data from reference.config file,
91  * obtains the file descriptor to parse the reference.config file, and
92  * inits the regex used to parse the lines from reference.config file.
93  *
94  * \param de_ctx Pointer to the Detection Engine Context.
95  *
96  * \note if file open fails, we leave de_ctx->reference_conf_ht initialized
97  *
98  * \retval 0 On success.
99  * \retval -1 On failure.
100  */
101 static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
102 {
103  /* init the hash table to be used by the reference config references */
107  if (de_ctx->reference_conf_ht == NULL) {
108  SCLogError("Error initializing the hash "
109  "table");
110  return NULL;
111  }
112 
113  /* if it is not NULL, use the file descriptor. The hack so that we can
114  * avoid using a dummy reference file for testing purposes and
115  * instead use an input stream against a buffer containing the
116  * reference strings */
117  if (fd == NULL) {
118  const char *filename = SCRConfGetConfFilename(de_ctx);
119  if ((fd = fopen(filename, "r")) == NULL) {
120 #ifdef UNITTESTS
121  if (RunmodeIsUnittests()) {
122  return NULL; // silently fail
123  }
124 #endif
125  SCLogError("Error opening file: \"%s\": %s", filename, strerror(errno));
126  return NULL;
127  }
128  }
129 
130  return fd;
131 }
132 
133 
134 /**
135  * \brief Returns the path for the Reference Config file. We check if we
136  * can retrieve the path from the yaml conf file. If it is not present,
137  * return the default path for the reference.config file which is
138  * "./reference.config".
139  *
140  * \retval log_filename Pointer to a string containing the path for the
141  * reference.config file.
142  */
143 static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx)
144 {
145  const char *path = NULL;
146 
147  if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) {
148  char config_value[256];
149  snprintf(config_value, sizeof(config_value),
150  "%s.reference-config-file", de_ctx->config_prefix);
151 
152  /* try loading prefix setting, fall back to global if that
153  * fails. */
154  if (ConfGet(config_value, &path) != 1) {
155  if (ConfGet("reference-config-file", &path) != 1) {
156  return (char *)SC_RCONF_DEFAULT_FILE_PATH;
157  }
158  }
159  } else {
160  if (ConfGet("reference-config-file", &path) != 1) {
161  return (char *)SC_RCONF_DEFAULT_FILE_PATH;
162  }
163  }
164  return path;
165 }
166 
167 /**
168  * \brief Releases local resources used by the Reference Config API.
169  */
170 static void SCRConfDeInitLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
171 {
172  if (fd != NULL) {
173  fclose(fd);
174  }
175 
176  return;
177 }
178 
179 /**
180  * \brief Releases de_ctx resources related to Reference Config API.
181  */
183 {
184  if (de_ctx->reference_conf_ht != NULL)
186 
187  de_ctx->reference_conf_ht = NULL;
188 
189  return;
190 }
191 
192 /**
193  * \brief Converts a string to lowercase.
194  *
195  * \param str Pointer to the string to be converted.
196  */
197 static char *SCRConfStringToLowercase(const char *str)
198 {
199  char *new_str = NULL;
200  char *temp_str = NULL;
201 
202  if ((new_str = SCStrdup(str)) == NULL) {
203  return NULL;
204  }
205 
206  temp_str = new_str;
207  while (*temp_str != '\0') {
208  *temp_str = u8_tolower((unsigned char)*temp_str);
209  temp_str++;
210  }
211 
212  return new_str;
213 }
214 
215 /**
216  * \brief Parses a line from the reference config file and adds it to Reference
217  * Config hash table DetectEngineCtx->reference_conf_ht.
218  *
219  * \param rawstr Pointer to the string to be parsed.
220  * \param de_ctx Pointer to the Detection Engine Context.
221  *
222  * \retval 0 On success.
223  * \retval -1 On failure.
224  */
226 {
227  char system[REFERENCE_SYSTEM_NAME_MAX];
228  char url[REFERENCE_CONTENT_NAME_MAX];
229 
230  SCRConfReference *ref_new = NULL;
231  SCRConfReference *ref_lookup = NULL;
232 
233  int ret = 0;
234 
235  ret = pcre2_match(de_ctx->reference_conf_regex, (PCRE2_SPTR8)line, strlen(line), 0, 0,
237  if (ret < 0) {
238  SCLogError("Invalid Reference Config in "
239  "reference.config file");
240  goto error;
241  }
242 
243  /* retrieve the reference system */
244  size_t copylen = sizeof(system);
245  ret = pcre2_substring_copy_bynumber(
246  de_ctx->reference_conf_regex_match, 1, (PCRE2_UCHAR8 *)system, &copylen);
247  if (ret < 0) {
248  SCLogError("pcre2_substring_copy_bynumber() failed");
249  goto error;
250  }
251 
252  /* retrieve the reference url */
253  copylen = sizeof(url);
254  ret = pcre2_substring_copy_bynumber(
255  de_ctx->reference_conf_regex_match, 2, (PCRE2_UCHAR8 *)url, &copylen);
256  if (ret < 0) {
257  SCLogError("pcre2_substring_copy_bynumber() failed");
258  goto error;
259  }
260 
261  /* Create a new instance of the parsed Reference string */
262  ref_new = SCRConfAllocSCRConfReference(system, url);
263  if (ref_new == NULL)
264  goto error;
265 
266  /* Check if the Reference is present in the HashTable. In case it's present
267  * ignore it, as it's a duplicate. If not present, add it to the table */
268  ref_lookup = HashTableLookup(de_ctx->reference_conf_ht, ref_new, 0);
269  if (ref_lookup == NULL) {
270  if (HashTableAdd(de_ctx->reference_conf_ht, ref_new, 0) < 0) {
271  SCLogDebug("HashTable Add failed");
272  }
273  } else {
274  SCLogDebug("Duplicate reference found inside reference.config");
276  }
277 
278  return 0;
279 
280  error:
281  return -1;
282 }
283 
284 /**
285  * \brief Checks if a string is a comment or a blank line.
286  *
287  * Comments lines are lines of the following format -
288  * "# This is a comment string" or
289  * " # This is a comment string".
290  *
291  * \param line String that has to be checked.
292  *
293  * \retval 1 On the argument string being a comment or blank line.
294  * \retval 0 Otherwise.
295  */
296 static int SCRConfIsLineBlankOrComment(char *line)
297 {
298  while (*line != '\0') {
299  /* we have a comment */
300  if (*line == '#')
301  return 1;
302 
303  /* this line is neither a comment line, nor a blank line */
304  if (!isspace((unsigned char)*line))
305  return 0;
306 
307  line++;
308  }
309 
310  /* we have a blank line */
311  return 1;
312 }
313 
314 /**
315  * \brief Parses the Reference Config file and updates the
316  * DetectionEngineCtx->reference_conf_ht with the Reference information.
317  *
318  * \param de_ctx Pointer to the Detection Engine Context.
319  */
320 static bool SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
321 {
322  char line[1024];
323  int runmode = SCRunmodeGet();
324  bool is_conf_test_mode = runmode == RUNMODE_CONF_TEST;
325  while (fgets(line, sizeof(line), fd) != NULL) {
326  if (SCRConfIsLineBlankOrComment(line))
327  continue;
328 
329  if (SCRConfAddReference(de_ctx, line) != 0) {
330  if (is_conf_test_mode) {
331  return false;
332  }
333  }
334  }
335 
336 #ifdef UNITTESTS
337  if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0)
338  SCLogInfo("tenant id %d: Added \"%d\" reference types from the reference.config file",
340  else
341  SCLogInfo("Added \"%d\" reference types from the reference.config file",
343 #endif /* UNITTESTS */
344  return true;
345 }
346 
347 /**
348  * \brief Returns a new SCRConfReference instance. The reference string
349  * is converted into lowercase, before being assigned to the instance.
350  *
351  * \param system Pointer to the system.
352  * \param url Pointer to the reference url.
353  *
354  * \retval ref Pointer to the new instance of SCRConfReference.
355  */
357  const char *url)
358 {
359  SCRConfReference *ref = NULL;
360 
361  if (system == NULL) {
362  SCLogError("Invalid arguments. system NULL");
363  return NULL;
364  }
365 
366  if ((ref = SCCalloc(1, sizeof(SCRConfReference))) == NULL) {
367  return NULL;
368  }
369 
370  if ((ref->system = SCRConfStringToLowercase(system)) == NULL) {
371  SCFree(ref);
372  return NULL;
373  }
374 
375  if (url != NULL && (ref->url = SCStrdup(url)) == NULL) {
376  SCFree(ref->system);
377  SCFree(ref);
378  return NULL;
379  }
380 
381  return ref;
382 }
383 
384 /**
385  * \brief Frees a SCRConfReference instance.
386  *
387  * \param Pointer to the SCRConfReference instance that has to be freed.
388  */
390 {
391  if (ref != NULL) {
392  if (ref->system != NULL)
393  SCFree(ref->system);
394 
395  if (ref->url != NULL)
396  SCFree(ref->url);
397 
398  SCFree(ref);
399  }
400 
401  return;
402 }
403 
404 /**
405  * \brief Hashing function to be used to hash the Reference name. Would be
406  * supplied as an argument to the HashTableInit function for
407  * DetectEngineCtx->reference_conf_ht.
408  *
409  * \param ht Pointer to the HashTable.
410  * \param data Pointer to the data to be hashed. In this case, the data
411  * would be a pointer to a SCRConfReference instance.
412  * \param datalen Not used by this function.
413  */
414 uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen)
415 {
416  SCRConfReference *ref = (SCRConfReference *)data;
417  uint32_t hash = 0;
418  int i = 0;
419 
420  int len = strlen(ref->system);
421 
422  for (i = 0; i < len; i++)
423  hash += u8_tolower((unsigned char)ref->system[i]);
424 
425  hash = hash % ht->array_size;
426 
427  return hash;
428 }
429 
430 /**
431  * \brief Used to compare two References that have been stored in the HashTable.
432  * This function is supplied as an argument to the HashTableInit function
433  * for DetectionEngineCtx->reference_conf_ct.
434  *
435  * \param data1 Pointer to the first SCRConfReference to be compared.
436  * \param len1 Not used by this function.
437  * \param data2 Pointer to the second SCRConfReference to be compared.
438  * \param len2 Not used by this function.
439  *
440  * \retval 1 On data1 and data2 being equal.
441  * \retval 0 On data1 and data2 not being equal.
442  */
443 char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
444  void *data2, uint16_t datalen2)
445 {
446  SCRConfReference *ref1 = (SCRConfReference *)data1;
447  SCRConfReference *ref2 = (SCRConfReference *)data2;
448  int len1 = 0;
449  int len2 = 0;
450 
451  if (ref1 == NULL || ref2 == NULL)
452  return 0;
453 
454  if (ref1->system == NULL || ref2->system == NULL)
455  return 0;
456 
457  len1 = strlen(ref1->system);
458  len2 = strlen(ref2->system);
459 
460  if (len1 == len2 && memcmp(ref1->system, ref2->system, len1) == 0) {
461  SCLogDebug("Match found inside Reference-Config hash function");
462  return 1;
463  }
464 
465  return 0;
466 }
467 
468 /**
469  * \brief Used to free the Reference Config Hash Data that was stored in
470  * DetectEngineCtx->reference_conf_ht Hashtable.
471  *
472  * \param data Pointer to the data that has to be freed.
473  */
474 void SCRConfReferenceHashFree(void *data)
475 {
477 
478  return;
479 }
480 
481 /**
482  * \brief Loads the Reference info from the reference.config file.
483  *
484  * The reference.config file contains references that can be used in
485  * Signatures. Each line of the file should have the following format -
486  * config reference: system_name, reference_url.
487  *
488  * \param de_ctx Pointer to the Detection Engine Context that should be updated
489  * with reference information.
490  *
491  * \retval 0 On success.
492  * \retval -1 On failure.
493  */
495 {
496  fd = SCRConfInitContextAndLocalResources(de_ctx, fd);
497  if (fd == NULL) {
498 #ifdef UNITTESTS
499  if (RunmodeIsUnittests()) {
500  return -1;
501  }
502 #endif
503  SCLogError("please check the \"reference-config-file\" "
504  "option in your suricata.yaml file");
505  return -1;
506  }
507 
508  bool rc = SCRConfParseFile(de_ctx, fd);
509  SCRConfDeInitLocalResources(de_ctx, fd);
510 
511  return rc ? 0 : -1;
512 }
513 
514 /**
515  * \brief Gets the reference config from the corresponding hash table stored
516  * in the Detection Engine Context's reference conf ht, given the
517  * reference name.
518  *
519  * \param ct_name Pointer to the reference name that has to be looked up.
520  * \param de_ctx Pointer to the Detection Engine Context.
521  *
522  * \retval lookup_rconf_info Pointer to the SCRConfReference instance from
523  * the hash table on success; NULL on failure.
524  */
525 SCRConfReference *SCRConfGetReference(const char *rconf_name,
527 {
528  SCRConfReference *ref_conf = SCRConfAllocSCRConfReference(rconf_name, NULL);
529  if (ref_conf == NULL)
530  return NULL;
532  ref_conf, 0);
533 
535  return lookup_ref_conf;
536 }
537 
538 /*----------------------------------Unittests---------------------------------*/
539 
540 
541 #ifdef UNITTESTS
542 
543 /**
544  * \brief Creates a dummy reference config, with all valid references, for
545  * testing purposes.
546  */
548 {
549  const char *buffer =
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";
555 
556  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
557  if (fd == NULL)
558  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
559 
560  return fd;
561 }
562 
563 /**
564  * \brief Creates a dummy reference config, with some valid references and a
565  * couple of invalid references, for testing purposes.
566  */
568 {
569  const char *buffer =
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";
575 
576  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
577  if (fd == NULL)
578  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
579 
580  return fd;
581 }
582 
583 /**
584  * \brief Creates a dummy reference config, with all invalid references, for
585  * testing purposes.
586  */
588 {
589  const char *buffer =
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";
594 
595  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
596  if (fd == NULL)
597  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
598 
599  return fd;
600 }
601 
602 /**
603  * \test Check that the reference file is loaded and the detection engine
604  * content reference_conf_ht loaded with the reference data.
605  */
606 static int SCRConfTest01(void)
607 {
609  int result = 0;
610 
611  if (de_ctx == NULL)
612  return result;
613 
616 
617  if (de_ctx->reference_conf_ht == NULL)
618  goto end;
619 
620  result = (de_ctx->reference_conf_ht->count == 3);
621  if (result == 0)
622  printf("FAILED: de_ctx->reference_conf_ht->count %u: ", de_ctx->reference_conf_ht->count);
623 
624  end:
625  if (de_ctx != NULL)
627  return result;
628 }
629 
630 /**
631  * \test Check that invalid references present in the reference.config file
632  * aren't loaded.
633  */
634 static int SCRConfTest02(void)
635 {
637  int result = 0;
638 
639  if (de_ctx == NULL)
640  return result;
641 
644 
645  if (de_ctx->reference_conf_ht == NULL)
646  goto end;
647 
648  result = (de_ctx->reference_conf_ht->count == 0);
649 
650 
651  end:
652  if (de_ctx != NULL)
654  return result;
655 }
656 
657 /**
658  * \test Check that only valid references are loaded into the hash table from
659  * the reference.config file.
660  */
661 static int SCRConfTest03(void)
662 {
664  int result = 0;
665 
666  if (de_ctx == NULL)
667  return result;
668 
671 
672  if (de_ctx->reference_conf_ht == NULL)
673  goto end;
674 
675  result = (de_ctx->reference_conf_ht->count == 1);
676 
677  end:
678  if (de_ctx != NULL)
680  return result;
681 }
682 
683 /**
684  * \test Check if the reference info from the reference.config file have
685  * been loaded into the hash table.
686  */
687 static int SCRConfTest04(void)
688 {
690  int result = 1;
691 
692  if (de_ctx == NULL)
693  return 0;
694 
697 
698  if (de_ctx->reference_conf_ht == NULL)
699  goto end;
700 
701  result = (de_ctx->reference_conf_ht->count == 3);
702 
703  result &= (SCRConfGetReference("one", de_ctx) != NULL);
704  result &= (SCRConfGetReference("two", de_ctx) != NULL);
705  result &= (SCRConfGetReference("three", de_ctx) != NULL);
706  result &= (SCRConfGetReference("four", de_ctx) == NULL);
707 
708  end:
709  if (de_ctx != NULL)
711  return result;
712 }
713 
714 /**
715  * \test Check if the reference info from the invalid reference.config file
716  * have not been loaded into the hash table, and cross verify to check
717  * that the hash table contains no reference data.
718  */
719 static int SCRConfTest05(void)
720 {
722  int result = 1;
723 
724  if (de_ctx == NULL)
725  return 0;
726 
729 
730  if (de_ctx->reference_conf_ht == NULL)
731  goto end;
732 
733  result = (de_ctx->reference_conf_ht->count == 0);
734 
735  result &= (SCRConfGetReference("one", de_ctx) == NULL);
736  result &= (SCRConfGetReference("two", de_ctx) == NULL);
737  result &= (SCRConfGetReference("three", de_ctx) == NULL);
738  result &= (SCRConfGetReference("four", de_ctx) == NULL);
739  result &= (SCRConfGetReference("five", de_ctx) == NULL);
740 
741  end:
742  if (de_ctx != NULL)
744  return result;
745 }
746 
747 /**
748  * \test Check if the reference info from the reference.config file have
749  * been loaded into the hash table.
750  */
751 static int SCRConfTest06(void)
752 {
754  int result = 1;
755 
756  if (de_ctx == NULL)
757  return 0;
758 
761 
762  if (de_ctx->reference_conf_ht == NULL)
763  goto end;
764 
765  result = (de_ctx->reference_conf_ht->count == 1);
766 
767  result &= (SCRConfGetReference("one", de_ctx) != NULL);
768  result &= (SCRConfGetReference("two", de_ctx) == NULL);
769  result &= (SCRConfGetReference("three", de_ctx) == NULL);
770  result &= (SCRConfGetReference("four", de_ctx) == NULL);
771  result &= (SCRConfGetReference("five", de_ctx) == NULL);
772 
773  end:
774  if (de_ctx != NULL)
776  return result;
777 }
778 
779 #endif /* UNITTESTS */
780 
781 /**
782  * \brief This function registers unit tests for Reference Config API.
783  */
785 {
786 
787 #ifdef UNITTESTS
788  UtRegisterTest("SCRConfTest01", SCRConfTest01);
789  UtRegisterTest("SCRConfTest02", SCRConfTest02);
790  UtRegisterTest("SCRConfTest03", SCRConfTest03);
791  UtRegisterTest("SCRConfTest04", SCRConfTest04);
792  UtRegisterTest("SCRConfTest05", SCRConfTest05);
793  UtRegisterTest("SCRConfTest06", SCRConfTest06);
794 #endif /* UNITTESTS */
795 
796  return;
797 }
SCRConfReferenceHashCompareFunc
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...
Definition: util-reference-config.c:443
len
uint8_t len
Definition: app-layer-dnp3.h:2
detect-engine.h
SCRunmodeGet
int SCRunmodeGet(void)
Get the current run mode.
Definition: suricata.c:263
util-fmemopen.h
SC_RCONF_DEFAULT_FILE_PATH
#define SC_RCONF_DEFAULT_FILE_PATH
Definition: util-reference-config.c:41
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
SCRConfGenerateInvalidDummyReferenceConfigFD03
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD03(void)
Creates a dummy reference config, with all invalid references, for testing purposes.
Definition: util-reference-config.c:587
util-hash.h
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:839
SCRConfGenerateInvalidDummyReferenceConfigFD02
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
Definition: util-reference-config.c:567
DetectEngineCtx_::reference_conf_regex_match
pcre2_match_data * reference_conf_regex_match
Definition: detect.h:1037
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2533
HashTable_
Definition: util-hash.h:35
u8_tolower
#define u8_tolower(c)
Definition: suricata-common.h:436
SCReferenceConfDeinit
void SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
Definition: util-reference-config.c:73
DetectEngineCtx_::reference_conf_regex
pcre2_code * reference_conf_regex
Definition: detect.h:1036
SCFmemopen
#define SCFmemopen
Definition: util-fmemopen.h:52
DetectEngineCtx_::reference_conf_ht
HashTable * reference_conf_ht
Definition: detect.h:1035
util-unittest.h
HashTableFree
void HashTableFree(HashTable *ht)
Definition: util-hash.c:78
HashTable_::array_size
uint32_t array_size
Definition: util-hash.h:37
SCRConfDeInitContext
void SCRConfDeInitContext(DetectEngineCtx *de_ctx)
Releases de_ctx resources related to Reference Config API.
Definition: util-reference-config.c:182
ConfGet
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:335
util-debug.h
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
RUNMODE_CONF_TEST
@ RUNMODE_CONF_TEST
Definition: runmodes.h:54
util-reference-config.h
HashTableLookup
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:183
detect.h
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
HashTableAdd
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:104
REFERENCE_SYSTEM_NAME_MAX
#define REFERENCE_SYSTEM_NAME_MAX
Definition: util-reference-config.h:29
SCRConfLoadReferenceConfigFile
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Reference info from the reference.config file.
Definition: util-reference-config.c:494
conf.h
SCRConfAddReference
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...
Definition: util-reference-config.c:225
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:254
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:224
SCRConfGetReference
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 ...
Definition: util-reference-config.c:525
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:962
SCReferenceConfInit
void SCReferenceConfInit(DetectEngineCtx *de_ctx)
Definition: util-reference-config.c:52
suricata-common.h
HashTable_::count
uint32_t count
Definition: util-hash.h:39
SC_RCONF_REGEX
#define SC_RCONF_REGEX
Definition: util-reference-config.c:38
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
SCRConfReference_
Holds a reference from the file - reference.config.
Definition: util-reference-config.h:35
SCRConfReferenceHashFunc
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...
Definition: util-reference-config.c:414
str
#define str(s)
Definition: suricata-common.h:291
SCRConfRegisterTests
void SCRConfRegisterTests(void)
This function registers unit tests for Reference Config API.
Definition: util-reference-config.c:784
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
HashTableInit
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
Definition: util-hash.c:35
SCRConfReference_::system
char * system
Definition: util-reference-config.h:37
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2494
SCRConfReference_::url
char * url
Definition: util-reference-config.h:39
SCRConfAllocSCRConfReference
SCRConfReference * SCRConfAllocSCRConfReference(const char *system, const char *url)
Returns a new SCRConfReference instance. The reference string is converted into lowercase,...
Definition: util-reference-config.c:356
SCRConfGenerateValidDummyReferenceConfigFD01
FILE * SCRConfGenerateValidDummyReferenceConfigFD01(void)
Creates a dummy reference config, with all valid references, for testing purposes.
Definition: util-reference-config.c:547
SCRConfDeAllocSCRConfReference
void SCRConfDeAllocSCRConfReference(SCRConfReference *ref)
Frees a SCRConfReference instance.
Definition: util-reference-config.c:389
REFERENCE_CONTENT_NAME_MAX
#define REFERENCE_CONTENT_NAME_MAX
Definition: util-reference-config.h:30
SCRConfReferenceHashFree
void SCRConfReferenceHashFree(void *ch)
Used to free the Reference Config Hash Data that was stored in DetectEngineCtx->reference_conf_ht Has...
Definition: util-reference-config.c:474
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DetectEngineCtx_::tenant_id
uint32_t tenant_id
Definition: detect.h:845