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 static pcre2_code *regex = NULL;
45 static pcre2_match_data *regex_match = NULL;
46 
47 /* the hash functions */
48 uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen);
49 char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
50  void *data2, uint16_t datalen2);
51 void SCRConfReferenceHashFree(void *ch);
52 
53 /* used to get the reference.config file path */
54 static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx);
55 
57 {
58  int en;
59  PCRE2_SIZE eo;
60  int opts = 0;
61 
62  regex = pcre2_compile((PCRE2_SPTR8)SC_RCONF_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
63  if (regex == NULL) {
64  PCRE2_UCHAR errbuffer[256];
65  pcre2_get_error_message(en, errbuffer, sizeof(errbuffer));
66  SCLogWarning("pcre2 compile of \"%s\" failed at "
67  "offset %d: %s",
68  SC_RCONF_REGEX, (int)eo, errbuffer);
69  return;
70  }
71  regex_match = pcre2_match_data_create_from_pattern(regex, NULL);
72 
73  return;
74 }
75 
77 {
78  if (regex != NULL) {
79  pcre2_code_free(regex);
80  regex = NULL;
81  }
82  if (regex_match != NULL) {
83  pcre2_match_data_free(regex_match);
84  regex_match = NULL;
85  }
86 }
87 
88 
89 /**
90  * \brief Inits the context to be used by the Reference Config parsing API.
91  *
92  * This function initializes the hash table to be used by the Detection
93  * Engine Context to hold the data from reference.config file,
94  * obtains the file descriptor to parse the reference.config file, and
95  * inits the regex used to parse the lines from reference.config file.
96  *
97  * \param de_ctx Pointer to the Detection Engine Context.
98  *
99  * \note if file open fails, we leave de_ctx->reference_conf_ht initialized
100  *
101  * \retval 0 On success.
102  * \retval -1 On failure.
103  */
104 static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
105 {
106  /* init the hash table to be used by the reference config references */
110  if (de_ctx->reference_conf_ht == NULL) {
111  SCLogError("Error initializing the hash "
112  "table");
113  return NULL;
114  }
115 
116  /* if it is not NULL, use the file descriptor. The hack so that we can
117  * avoid using a dummy reference file for testing purposes and
118  * instead use an input stream against a buffer containing the
119  * reference strings */
120  if (fd == NULL) {
121  const char *filename = SCRConfGetConfFilename(de_ctx);
122  if ((fd = fopen(filename, "r")) == NULL) {
123 #ifdef UNITTESTS
124  if (RunmodeIsUnittests()) {
125  return NULL; // silently fail
126  }
127 #endif
128  SCLogError("Error opening file: \"%s\": %s", filename, strerror(errno));
129  return NULL;
130  }
131  }
132 
133  return fd;
134 }
135 
136 
137 /**
138  * \brief Returns the path for the Reference Config file. We check if we
139  * can retrieve the path from the yaml conf file. If it is not present,
140  * return the default path for the reference.config file which is
141  * "./reference.config".
142  *
143  * \retval log_filename Pointer to a string containing the path for the
144  * reference.config file.
145  */
146 static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx)
147 {
148  const char *path = NULL;
149 
150  if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) {
151  char config_value[256];
152  snprintf(config_value, sizeof(config_value),
153  "%s.reference-config-file", de_ctx->config_prefix);
154 
155  /* try loading prefix setting, fall back to global if that
156  * fails. */
157  if (ConfGet(config_value, &path) != 1) {
158  if (ConfGet("reference-config-file", &path) != 1) {
159  return (char *)SC_RCONF_DEFAULT_FILE_PATH;
160  }
161  }
162  } else {
163  if (ConfGet("reference-config-file", &path) != 1) {
164  return (char *)SC_RCONF_DEFAULT_FILE_PATH;
165  }
166  }
167  return path;
168 }
169 
170 /**
171  * \brief Releases local resources used by the Reference Config API.
172  */
173 static void SCRConfDeInitLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
174 {
175  if (fd != NULL) {
176  fclose(fd);
177  }
178 
179  return;
180 }
181 
182 /**
183  * \brief Releases de_ctx resources related to Reference Config API.
184  */
186 {
187  if (de_ctx->reference_conf_ht != NULL)
189 
190  de_ctx->reference_conf_ht = NULL;
191 
192  return;
193 }
194 
195 /**
196  * \brief Converts a string to lowercase.
197  *
198  * \param str Pointer to the string to be converted.
199  */
200 static char *SCRConfStringToLowercase(const char *str)
201 {
202  char *new_str = NULL;
203  char *temp_str = NULL;
204 
205  if ((new_str = SCStrdup(str)) == NULL) {
206  return NULL;
207  }
208 
209  temp_str = new_str;
210  while (*temp_str != '\0') {
211  *temp_str = u8_tolower((unsigned char)*temp_str);
212  temp_str++;
213  }
214 
215  return new_str;
216 }
217 
218 /**
219  * \brief Parses a line from the reference config file and adds it to Reference
220  * Config hash table DetectEngineCtx->reference_conf_ht.
221  *
222  * \param rawstr Pointer to the string to be parsed.
223  * \param de_ctx Pointer to the Detection Engine Context.
224  *
225  * \retval 0 On success.
226  * \retval -1 On failure.
227  */
229 {
230  char system[REFERENCE_SYSTEM_NAME_MAX];
231  char url[REFERENCE_CONTENT_NAME_MAX];
232 
233  SCRConfReference *ref_new = NULL;
234  SCRConfReference *ref_lookup = NULL;
235 
236  int ret = 0;
237 
238  ret = pcre2_match(regex, (PCRE2_SPTR8)line, strlen(line), 0, 0, regex_match, NULL);
239  if (ret < 0) {
240  SCLogError("Invalid Reference Config in "
241  "reference.config file");
242  goto error;
243  }
244 
245  /* retrieve the reference system */
246  size_t copylen = sizeof(system);
247  ret = pcre2_substring_copy_bynumber(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(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 = RunmodeGetCurrent();
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  SCLogInfo("Added \"%d\" reference types from the reference.config file",
339 #endif /* UNITTESTS */
340  return true;
341 }
342 
343 /**
344  * \brief Returns a new SCRConfReference instance. The reference string
345  * is converted into lowercase, before being assigned to the instance.
346  *
347  * \param system Pointer to the system.
348  * \param url Pointer to the reference url.
349  *
350  * \retval ref Pointer to the new instance of SCRConfReference.
351  */
353  const char *url)
354 {
355  SCRConfReference *ref = NULL;
356 
357  if (system == NULL) {
358  SCLogError("Invalid arguments. system NULL");
359  return NULL;
360  }
361 
362  if ((ref = SCMalloc(sizeof(SCRConfReference))) == NULL) {
363  return NULL;
364  }
365  memset(ref, 0, sizeof(SCRConfReference));
366 
367  if ((ref->system = SCRConfStringToLowercase(system)) == NULL) {
368  SCFree(ref);
369  return NULL;
370  }
371 
372  if (url != NULL && (ref->url = SCStrdup(url)) == NULL) {
373  SCFree(ref->system);
374  SCFree(ref);
375  return NULL;
376  }
377 
378  return ref;
379 }
380 
381 /**
382  * \brief Frees a SCRConfReference instance.
383  *
384  * \param Pointer to the SCRConfReference instance that has to be freed.
385  */
387 {
388  if (ref != NULL) {
389  if (ref->system != NULL)
390  SCFree(ref->system);
391 
392  if (ref->url != NULL)
393  SCFree(ref->url);
394 
395  SCFree(ref);
396  }
397 
398  return;
399 }
400 
401 /**
402  * \brief Hashing function to be used to hash the Reference name. Would be
403  * supplied as an argument to the HashTableInit function for
404  * DetectEngineCtx->reference_conf_ht.
405  *
406  * \param ht Pointer to the HashTable.
407  * \param data Pointer to the data to be hashed. In this case, the data
408  * would be a pointer to a SCRConfReference instance.
409  * \param datalen Not used by this function.
410  */
411 uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen)
412 {
413  SCRConfReference *ref = (SCRConfReference *)data;
414  uint32_t hash = 0;
415  int i = 0;
416 
417  int len = strlen(ref->system);
418 
419  for (i = 0; i < len; i++)
420  hash += u8_tolower((unsigned char)ref->system[i]);
421 
422  hash = hash % ht->array_size;
423 
424  return hash;
425 }
426 
427 /**
428  * \brief Used to compare two References that have been stored in the HashTable.
429  * This function is supplied as an argument to the HashTableInit function
430  * for DetectionEngineCtx->reference_conf_ct.
431  *
432  * \param data1 Pointer to the first SCRConfReference to be compared.
433  * \param len1 Not used by this function.
434  * \param data2 Pointer to the second SCRConfReference to be compared.
435  * \param len2 Not used by this function.
436  *
437  * \retval 1 On data1 and data2 being equal.
438  * \retval 0 On data1 and data2 not being equal.
439  */
440 char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
441  void *data2, uint16_t datalen2)
442 {
443  SCRConfReference *ref1 = (SCRConfReference *)data1;
444  SCRConfReference *ref2 = (SCRConfReference *)data2;
445  int len1 = 0;
446  int len2 = 0;
447 
448  if (ref1 == NULL || ref2 == NULL)
449  return 0;
450 
451  if (ref1->system == NULL || ref2->system == NULL)
452  return 0;
453 
454  len1 = strlen(ref1->system);
455  len2 = strlen(ref2->system);
456 
457  if (len1 == len2 && memcmp(ref1->system, ref2->system, len1) == 0) {
458  SCLogDebug("Match found inside Reference-Config hash function");
459  return 1;
460  }
461 
462  return 0;
463 }
464 
465 /**
466  * \brief Used to free the Reference Config Hash Data that was stored in
467  * DetectEngineCtx->reference_conf_ht Hashtable.
468  *
469  * \param data Pointer to the data that has to be freed.
470  */
471 void SCRConfReferenceHashFree(void *data)
472 {
474 
475  return;
476 }
477 
478 /**
479  * \brief Loads the Reference info from the reference.config file.
480  *
481  * The reference.config file contains references that can be used in
482  * Signatures. Each line of the file should have the following format -
483  * config reference: system_name, reference_url.
484  *
485  * \param de_ctx Pointer to the Detection Engine Context that should be updated
486  * with reference information.
487  *
488  * \retval 0 On success.
489  * \retval -1 On failure.
490  */
492 {
493  fd = SCRConfInitContextAndLocalResources(de_ctx, fd);
494  if (fd == NULL) {
495 #ifdef UNITTESTS
496  if (RunmodeIsUnittests()) {
497  return -1;
498  }
499 #endif
500  SCLogError("please check the \"reference-config-file\" "
501  "option in your suricata.yaml file");
502  return -1;
503  }
504 
505  bool rc = SCRConfParseFile(de_ctx, fd);
506  SCRConfDeInitLocalResources(de_ctx, fd);
507 
508  return rc ? 0 : -1;
509 }
510 
511 /**
512  * \brief Gets the reference config from the corresponding hash table stored
513  * in the Detection Engine Context's reference conf ht, given the
514  * reference name.
515  *
516  * \param ct_name Pointer to the reference name that has to be looked up.
517  * \param de_ctx Pointer to the Detection Engine Context.
518  *
519  * \retval lookup_rconf_info Pointer to the SCRConfReference instance from
520  * the hash table on success; NULL on failure.
521  */
522 SCRConfReference *SCRConfGetReference(const char *rconf_name,
524 {
525  SCRConfReference *ref_conf = SCRConfAllocSCRConfReference(rconf_name, NULL);
526  if (ref_conf == NULL)
527  return NULL;
529  ref_conf, 0);
530 
532  return lookup_ref_conf;
533 }
534 
535 /*----------------------------------Unittests---------------------------------*/
536 
537 
538 #ifdef UNITTESTS
539 
540 /**
541  * \brief Creates a dummy reference config, with all valid references, for
542  * testing purposes.
543  */
545 {
546  const char *buffer =
547  "config reference: one http://www.one.com\n"
548  "config reference: two http://www.two.com\n"
549  "config reference: three http://www.three.com\n"
550  "config reference: one http://www.one.com\n"
551  "config reference: three http://www.three.com\n";
552 
553  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
554  if (fd == NULL)
555  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
556 
557  return fd;
558 }
559 
560 /**
561  * \brief Creates a dummy reference config, with some valid references and a
562  * couple of invalid references, for testing purposes.
563  */
565 {
566  const char *buffer =
567  "config reference: one http://www.one.com\n"
568  "config_ reference: two http://www.two.com\n"
569  "config reference_: three http://www.three.com\n"
570  "config reference: four\n"
571  "config reference five http://www.five.com\n";
572 
573  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
574  if (fd == NULL)
575  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
576 
577  return fd;
578 }
579 
580 /**
581  * \brief Creates a dummy reference config, with all invalid references, for
582  * testing purposes.
583  */
585 {
586  const char *buffer =
587  "config reference one http://www.one.com\n"
588  "config_ reference: two http://www.two.com\n"
589  "config reference_: three http://www.three.com\n"
590  "config reference: four\n";
591 
592  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
593  if (fd == NULL)
594  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
595 
596  return fd;
597 }
598 
599 /**
600  * \test Check that the reference file is loaded and the detection engine
601  * content reference_conf_ht loaded with the reference data.
602  */
603 static int SCRConfTest01(void)
604 {
606  int result = 0;
607 
608  if (de_ctx == NULL)
609  return result;
610 
613 
614  if (de_ctx->reference_conf_ht == NULL)
615  goto end;
616 
617  result = (de_ctx->reference_conf_ht->count == 3);
618  if (result == 0)
619  printf("FAILED: de_ctx->reference_conf_ht->count %u: ", de_ctx->reference_conf_ht->count);
620 
621  end:
622  if (de_ctx != NULL)
624  return result;
625 }
626 
627 /**
628  * \test Check that invalid references present in the reference.config file
629  * aren't loaded.
630  */
631 static int SCRConfTest02(void)
632 {
634  int result = 0;
635 
636  if (de_ctx == NULL)
637  return result;
638 
641 
642  if (de_ctx->reference_conf_ht == NULL)
643  goto end;
644 
645  result = (de_ctx->reference_conf_ht->count == 0);
646 
647 
648  end:
649  if (de_ctx != NULL)
651  return result;
652 }
653 
654 /**
655  * \test Check that only valid references are loaded into the hash table from
656  * the reference.config file.
657  */
658 static int SCRConfTest03(void)
659 {
661  int result = 0;
662 
663  if (de_ctx == NULL)
664  return result;
665 
668 
669  if (de_ctx->reference_conf_ht == NULL)
670  goto end;
671 
672  result = (de_ctx->reference_conf_ht->count == 1);
673 
674  end:
675  if (de_ctx != NULL)
677  return result;
678 }
679 
680 /**
681  * \test Check if the reference info from the reference.config file have
682  * been loaded into the hash table.
683  */
684 static int SCRConfTest04(void)
685 {
687  int result = 1;
688 
689  if (de_ctx == NULL)
690  return 0;
691 
694 
695  if (de_ctx->reference_conf_ht == NULL)
696  goto end;
697 
698  result = (de_ctx->reference_conf_ht->count == 3);
699 
700  result &= (SCRConfGetReference("one", de_ctx) != NULL);
701  result &= (SCRConfGetReference("two", de_ctx) != NULL);
702  result &= (SCRConfGetReference("three", de_ctx) != NULL);
703  result &= (SCRConfGetReference("four", de_ctx) == NULL);
704 
705  end:
706  if (de_ctx != NULL)
708  return result;
709 }
710 
711 /**
712  * \test Check if the reference info from the invalid reference.config file
713  * have not been loaded into the hash table, and cross verify to check
714  * that the hash table contains no reference data.
715  */
716 static int SCRConfTest05(void)
717 {
719  int result = 1;
720 
721  if (de_ctx == NULL)
722  return 0;
723 
726 
727  if (de_ctx->reference_conf_ht == NULL)
728  goto end;
729 
730  result = (de_ctx->reference_conf_ht->count == 0);
731 
732  result &= (SCRConfGetReference("one", de_ctx) == NULL);
733  result &= (SCRConfGetReference("two", de_ctx) == NULL);
734  result &= (SCRConfGetReference("three", de_ctx) == NULL);
735  result &= (SCRConfGetReference("four", de_ctx) == NULL);
736  result &= (SCRConfGetReference("five", de_ctx) == NULL);
737 
738  end:
739  if (de_ctx != NULL)
741  return result;
742 }
743 
744 /**
745  * \test Check if the reference info from the reference.config file have
746  * been loaded into the hash table.
747  */
748 static int SCRConfTest06(void)
749 {
751  int result = 1;
752 
753  if (de_ctx == NULL)
754  return 0;
755 
758 
759  if (de_ctx->reference_conf_ht == NULL)
760  goto end;
761 
762  result = (de_ctx->reference_conf_ht->count == 1);
763 
764  result &= (SCRConfGetReference("one", de_ctx) != NULL);
765  result &= (SCRConfGetReference("two", de_ctx) == NULL);
766  result &= (SCRConfGetReference("three", de_ctx) == NULL);
767  result &= (SCRConfGetReference("four", de_ctx) == NULL);
768  result &= (SCRConfGetReference("five", de_ctx) == NULL);
769 
770  end:
771  if (de_ctx != NULL)
773  return result;
774 }
775 
776 #endif /* UNITTESTS */
777 
778 /**
779  * \brief This function registers unit tests for Reference Config API.
780  */
782 {
783 
784 #ifdef UNITTESTS
785  UtRegisterTest("SCRConfTest01", SCRConfTest01);
786  UtRegisterTest("SCRConfTest02", SCRConfTest02);
787  UtRegisterTest("SCRConfTest03", SCRConfTest03);
788  UtRegisterTest("SCRConfTest04", SCRConfTest04);
789  UtRegisterTest("SCRConfTest05", SCRConfTest05);
790  UtRegisterTest("SCRConfTest06", SCRConfTest06);
791 #endif /* UNITTESTS */
792 
793  return;
794 }
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:440
len
uint8_t len
Definition: app-layer-dnp3.h:2
SCReferenceConfDeinit
void SCReferenceConfDeinit(void)
Definition: util-reference-config.c:76
detect-engine.h
SCReferenceConfInit
void SCReferenceConfInit(void)
Definition: util-reference-config.c:56
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
util-hash.h
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:787
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2455
HashTable_
Definition: util-hash.h:35
u8_tolower
#define u8_tolower(c)
Definition: suricata-common.h:425
SCFmemopen
#define SCFmemopen
Definition: util-fmemopen.h:52
DetectEngineCtx_::reference_conf_ht
HashTable * reference_conf_ht
Definition: detect.h:818
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:185
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
SCRConfGenerateInValidDummyReferenceConfigFD03
FILE * SCRConfGenerateInValidDummyReferenceConfigFD03(void)
Creates a dummy reference config, with all invalid references, for testing purposes.
Definition: util-reference-config.c:584
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
SCRConfGenerateInValidDummyReferenceConfigFD02
FILE * SCRConfGenerateInValidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
Definition: util-reference-config.c:564
SCRConfLoadReferenceConfigFile
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Reference info from the reference.config file.
Definition: util-reference-config.c:491
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:228
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:232
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:522
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:919
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:411
RunmodeGetCurrent
int RunmodeGetCurrent(void)
Definition: suricata.c:241
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
str
#define str(s)
Definition: suricata-common.h:280
SCRConfRegisterTests
void SCRConfRegisterTests(void)
This function registers unit tests for Reference Config API.
Definition: util-reference-config.c:781
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:2416
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:352
SCRConfGenerateValidDummyReferenceConfigFD01
FILE * SCRConfGenerateValidDummyReferenceConfigFD01(void)
Creates a dummy reference config, with all valid references, for testing purposes.
Definition: util-reference-config.c:544
SCRConfDeAllocSCRConfReference
void SCRConfDeAllocSCRConfReference(SCRConfReference *ref)
Frees a SCRConfReference instance.
Definition: util-reference-config.c:386
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:471