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