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  SCLogInfo("Added \"%d\" reference types from the reference.config file",
340 #endif /* UNITTESTS */
341  return true;
342 }
343 
344 /**
345  * \brief Returns a new SCRConfReference instance. The reference string
346  * is converted into lowercase, before being assigned to the instance.
347  *
348  * \param system Pointer to the system.
349  * \param url Pointer to the reference url.
350  *
351  * \retval ref Pointer to the new instance of SCRConfReference.
352  */
354  const char *url)
355 {
356  SCRConfReference *ref = NULL;
357 
358  if (system == NULL) {
359  SCLogError("Invalid arguments. system NULL");
360  return NULL;
361  }
362 
363  if ((ref = SCMalloc(sizeof(SCRConfReference))) == NULL) {
364  return NULL;
365  }
366  memset(ref, 0, sizeof(SCRConfReference));
367 
368  if ((ref->system = SCRConfStringToLowercase(system)) == NULL) {
369  SCFree(ref);
370  return NULL;
371  }
372 
373  if (url != NULL && (ref->url = SCStrdup(url)) == NULL) {
374  SCFree(ref->system);
375  SCFree(ref);
376  return NULL;
377  }
378 
379  return ref;
380 }
381 
382 /**
383  * \brief Frees a SCRConfReference instance.
384  *
385  * \param Pointer to the SCRConfReference instance that has to be freed.
386  */
388 {
389  if (ref != NULL) {
390  if (ref->system != NULL)
391  SCFree(ref->system);
392 
393  if (ref->url != NULL)
394  SCFree(ref->url);
395 
396  SCFree(ref);
397  }
398 
399  return;
400 }
401 
402 /**
403  * \brief Hashing function to be used to hash the Reference name. Would be
404  * supplied as an argument to the HashTableInit function for
405  * DetectEngineCtx->reference_conf_ht.
406  *
407  * \param ht Pointer to the HashTable.
408  * \param data Pointer to the data to be hashed. In this case, the data
409  * would be a pointer to a SCRConfReference instance.
410  * \param datalen Not used by this function.
411  */
412 uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen)
413 {
414  SCRConfReference *ref = (SCRConfReference *)data;
415  uint32_t hash = 0;
416  int i = 0;
417 
418  int len = strlen(ref->system);
419 
420  for (i = 0; i < len; i++)
421  hash += u8_tolower((unsigned char)ref->system[i]);
422 
423  hash = hash % ht->array_size;
424 
425  return hash;
426 }
427 
428 /**
429  * \brief Used to compare two References that have been stored in the HashTable.
430  * This function is supplied as an argument to the HashTableInit function
431  * for DetectionEngineCtx->reference_conf_ct.
432  *
433  * \param data1 Pointer to the first SCRConfReference to be compared.
434  * \param len1 Not used by this function.
435  * \param data2 Pointer to the second SCRConfReference to be compared.
436  * \param len2 Not used by this function.
437  *
438  * \retval 1 On data1 and data2 being equal.
439  * \retval 0 On data1 and data2 not being equal.
440  */
441 char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
442  void *data2, uint16_t datalen2)
443 {
444  SCRConfReference *ref1 = (SCRConfReference *)data1;
445  SCRConfReference *ref2 = (SCRConfReference *)data2;
446  int len1 = 0;
447  int len2 = 0;
448 
449  if (ref1 == NULL || ref2 == NULL)
450  return 0;
451 
452  if (ref1->system == NULL || ref2->system == NULL)
453  return 0;
454 
455  len1 = strlen(ref1->system);
456  len2 = strlen(ref2->system);
457 
458  if (len1 == len2 && memcmp(ref1->system, ref2->system, len1) == 0) {
459  SCLogDebug("Match found inside Reference-Config hash function");
460  return 1;
461  }
462 
463  return 0;
464 }
465 
466 /**
467  * \brief Used to free the Reference Config Hash Data that was stored in
468  * DetectEngineCtx->reference_conf_ht Hashtable.
469  *
470  * \param data Pointer to the data that has to be freed.
471  */
472 void SCRConfReferenceHashFree(void *data)
473 {
475 
476  return;
477 }
478 
479 /**
480  * \brief Loads the Reference info from the reference.config file.
481  *
482  * The reference.config file contains references that can be used in
483  * Signatures. Each line of the file should have the following format -
484  * config reference: system_name, reference_url.
485  *
486  * \param de_ctx Pointer to the Detection Engine Context that should be updated
487  * with reference information.
488  *
489  * \retval 0 On success.
490  * \retval -1 On failure.
491  */
493 {
494  fd = SCRConfInitContextAndLocalResources(de_ctx, fd);
495  if (fd == NULL) {
496 #ifdef UNITTESTS
497  if (RunmodeIsUnittests()) {
498  return -1;
499  }
500 #endif
501  SCLogError("please check the \"reference-config-file\" "
502  "option in your suricata.yaml file");
503  return -1;
504  }
505 
506  bool rc = SCRConfParseFile(de_ctx, fd);
507  SCRConfDeInitLocalResources(de_ctx, fd);
508 
509  return rc ? 0 : -1;
510 }
511 
512 /**
513  * \brief Gets the reference config from the corresponding hash table stored
514  * in the Detection Engine Context's reference conf ht, given the
515  * reference name.
516  *
517  * \param ct_name Pointer to the reference name that has to be looked up.
518  * \param de_ctx Pointer to the Detection Engine Context.
519  *
520  * \retval lookup_rconf_info Pointer to the SCRConfReference instance from
521  * the hash table on success; NULL on failure.
522  */
523 SCRConfReference *SCRConfGetReference(const char *rconf_name,
525 {
526  SCRConfReference *ref_conf = SCRConfAllocSCRConfReference(rconf_name, NULL);
527  if (ref_conf == NULL)
528  return NULL;
530  ref_conf, 0);
531 
533  return lookup_ref_conf;
534 }
535 
536 /*----------------------------------Unittests---------------------------------*/
537 
538 
539 #ifdef UNITTESTS
540 
541 /**
542  * \brief Creates a dummy reference config, with all valid references, for
543  * testing purposes.
544  */
546 {
547  const char *buffer =
548  "config reference: one http://www.one.com\n"
549  "config reference: two http://www.two.com\n"
550  "config reference: three http://www.three.com\n"
551  "config reference: one http://www.one.com\n"
552  "config reference: three http://www.three.com\n";
553 
554  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
555  if (fd == NULL)
556  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
557 
558  return fd;
559 }
560 
561 /**
562  * \brief Creates a dummy reference config, with some valid references and a
563  * couple of invalid references, for testing purposes.
564  */
566 {
567  const char *buffer =
568  "config reference: one http://www.one.com\n"
569  "config_ reference: two http://www.two.com\n"
570  "config reference_: three http://www.three.com\n"
571  "config reference: four\n"
572  "config reference five http://www.five.com\n";
573 
574  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
575  if (fd == NULL)
576  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
577 
578  return fd;
579 }
580 
581 /**
582  * \brief Creates a dummy reference config, with all invalid references, for
583  * testing purposes.
584  */
586 {
587  const char *buffer =
588  "config reference one http://www.one.com\n"
589  "config_ reference: two http://www.two.com\n"
590  "config reference_: three http://www.three.com\n"
591  "config reference: four\n";
592 
593  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
594  if (fd == NULL)
595  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
596 
597  return fd;
598 }
599 
600 /**
601  * \test Check that the reference file is loaded and the detection engine
602  * content reference_conf_ht loaded with the reference data.
603  */
604 static int SCRConfTest01(void)
605 {
607  int result = 0;
608 
609  if (de_ctx == NULL)
610  return result;
611 
614 
615  if (de_ctx->reference_conf_ht == NULL)
616  goto end;
617 
618  result = (de_ctx->reference_conf_ht->count == 3);
619  if (result == 0)
620  printf("FAILED: de_ctx->reference_conf_ht->count %u: ", de_ctx->reference_conf_ht->count);
621 
622  end:
623  if (de_ctx != NULL)
625  return result;
626 }
627 
628 /**
629  * \test Check that invalid references present in the reference.config file
630  * aren't loaded.
631  */
632 static int SCRConfTest02(void)
633 {
635  int result = 0;
636 
637  if (de_ctx == NULL)
638  return result;
639 
642 
643  if (de_ctx->reference_conf_ht == NULL)
644  goto end;
645 
646  result = (de_ctx->reference_conf_ht->count == 0);
647 
648 
649  end:
650  if (de_ctx != NULL)
652  return result;
653 }
654 
655 /**
656  * \test Check that only valid references are loaded into the hash table from
657  * the reference.config file.
658  */
659 static int SCRConfTest03(void)
660 {
662  int result = 0;
663 
664  if (de_ctx == NULL)
665  return result;
666 
669 
670  if (de_ctx->reference_conf_ht == NULL)
671  goto end;
672 
673  result = (de_ctx->reference_conf_ht->count == 1);
674 
675  end:
676  if (de_ctx != NULL)
678  return result;
679 }
680 
681 /**
682  * \test Check if the reference info from the reference.config file have
683  * been loaded into the hash table.
684  */
685 static int SCRConfTest04(void)
686 {
688  int result = 1;
689 
690  if (de_ctx == NULL)
691  return 0;
692 
695 
696  if (de_ctx->reference_conf_ht == NULL)
697  goto end;
698 
699  result = (de_ctx->reference_conf_ht->count == 3);
700 
701  result &= (SCRConfGetReference("one", de_ctx) != NULL);
702  result &= (SCRConfGetReference("two", de_ctx) != NULL);
703  result &= (SCRConfGetReference("three", de_ctx) != NULL);
704  result &= (SCRConfGetReference("four", de_ctx) == NULL);
705 
706  end:
707  if (de_ctx != NULL)
709  return result;
710 }
711 
712 /**
713  * \test Check if the reference info from the invalid reference.config file
714  * have not been loaded into the hash table, and cross verify to check
715  * that the hash table contains no reference data.
716  */
717 static int SCRConfTest05(void)
718 {
720  int result = 1;
721 
722  if (de_ctx == NULL)
723  return 0;
724 
727 
728  if (de_ctx->reference_conf_ht == NULL)
729  goto end;
730 
731  result = (de_ctx->reference_conf_ht->count == 0);
732 
733  result &= (SCRConfGetReference("one", de_ctx) == NULL);
734  result &= (SCRConfGetReference("two", de_ctx) == NULL);
735  result &= (SCRConfGetReference("three", de_ctx) == NULL);
736  result &= (SCRConfGetReference("four", de_ctx) == NULL);
737  result &= (SCRConfGetReference("five", de_ctx) == NULL);
738 
739  end:
740  if (de_ctx != NULL)
742  return result;
743 }
744 
745 /**
746  * \test Check if the reference info from the reference.config file have
747  * been loaded into the hash table.
748  */
749 static int SCRConfTest06(void)
750 {
752  int result = 1;
753 
754  if (de_ctx == NULL)
755  return 0;
756 
759 
760  if (de_ctx->reference_conf_ht == NULL)
761  goto end;
762 
763  result = (de_ctx->reference_conf_ht->count == 1);
764 
765  result &= (SCRConfGetReference("one", de_ctx) != NULL);
766  result &= (SCRConfGetReference("two", de_ctx) == NULL);
767  result &= (SCRConfGetReference("three", de_ctx) == NULL);
768  result &= (SCRConfGetReference("four", de_ctx) == NULL);
769  result &= (SCRConfGetReference("five", de_ctx) == NULL);
770 
771  end:
772  if (de_ctx != NULL)
774  return result;
775 }
776 
777 #endif /* UNITTESTS */
778 
779 /**
780  * \brief This function registers unit tests for Reference Config API.
781  */
783 {
784 
785 #ifdef UNITTESTS
786  UtRegisterTest("SCRConfTest01", SCRConfTest01);
787  UtRegisterTest("SCRConfTest02", SCRConfTest02);
788  UtRegisterTest("SCRConfTest03", SCRConfTest03);
789  UtRegisterTest("SCRConfTest04", SCRConfTest04);
790  UtRegisterTest("SCRConfTest05", SCRConfTest05);
791  UtRegisterTest("SCRConfTest06", SCRConfTest06);
792 #endif /* UNITTESTS */
793 
794  return;
795 }
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:441
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:585
util-hash.h
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:826
SCRConfGenerateInvalidDummyReferenceConfigFD02
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
Definition: util-reference-config.c:565
DetectEngineCtx_::reference_conf_regex_match
pcre2_match_data * reference_conf_regex_match
Definition: detect.h:1022
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2592
HashTable_
Definition: util-hash.h:35
u8_tolower
#define u8_tolower(c)
Definition: suricata-common.h:431
SCReferenceConfDeinit
void SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
Definition: util-reference-config.c:74
DetectEngineCtx_::reference_conf_regex
pcre2_code * reference_conf_regex
Definition: detect.h:1021
SCFmemopen
#define SCFmemopen
Definition: util-fmemopen.h:52
DetectEngineCtx_::reference_conf_ht
HashTable * reference_conf_ht
Definition: detect.h:1020
util-unittest.h
HashTableFree
void HashTableFree(HashTable *ht)
Definition: util-hash.c:80
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:194
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:114
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:492
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:251
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:523
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:947
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:412
RunmodeGetCurrent
int RunmodeGetCurrent(void)
Definition: suricata.c:260
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
str
#define str(s)
Definition: suricata-common.h:286
SCRConfRegisterTests
void SCRConfRegisterTests(void)
This function registers unit tests for Reference Config API.
Definition: util-reference-config.c:782
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:2553
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:353
SCRConfGenerateValidDummyReferenceConfigFD01
FILE * SCRConfGenerateValidDummyReferenceConfigFD01(void)
Creates a dummy reference config, with all valid references, for testing purposes.
Definition: util-reference-config.c:545
SCRConfDeAllocSCRConfReference
void SCRConfDeAllocSCRConfReference(SCRConfReference *ref)
Frees a SCRConfReference instance.
Definition: util-reference-config.c:387
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:472