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