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 
130  return fd;
131 }
132 
133 
134 /**
135  * \brief Returns the path for the Reference Config file. We check if we
136  * can retrieve the path from the yaml conf file. If it is not present,
137  * return the default path for the reference.config file which is
138  * "./reference.config".
139  *
140  * \retval log_filename Pointer to a string containing the path for the
141  * reference.config file.
142  */
143 static const char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx)
144 {
145  const char *path = NULL;
146 
147  if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) {
148  char config_value[256];
149  snprintf(config_value, sizeof(config_value),
150  "%s.reference-config-file", de_ctx->config_prefix);
151 
152  /* try loading prefix setting, fall back to global if that
153  * fails. */
154  if (SCConfGet(config_value, &path) != 1) {
155  if (SCConfGet("reference-config-file", &path) != 1) {
156  return (char *)SC_RCONF_DEFAULT_FILE_PATH;
157  }
158  }
159  } else {
160  if (SCConfGet("reference-config-file", &path) != 1) {
161  return (char *)SC_RCONF_DEFAULT_FILE_PATH;
162  }
163  }
164  return path;
165 }
166 
167 /**
168  * \brief Releases local resources used by the Reference Config API.
169  */
170 static void SCRConfDeInitLocalResources(FILE *fd)
171 {
172  if (fd != NULL) {
173  fclose(fd);
174  }
175 }
176 
177 /**
178  * \brief Releases de_ctx resources related to Reference Config API.
179  */
181 {
182  if (de_ctx->reference_conf_ht != NULL)
184 
185  de_ctx->reference_conf_ht = NULL;
186 }
187 
188 /**
189  * \brief Converts a string to lowercase.
190  *
191  * \param str Pointer to the string to be converted.
192  */
193 static char *SCRConfStringToLowercase(const char *str)
194 {
195  char *new_str = NULL;
196  char *temp_str = NULL;
197 
198  if ((new_str = SCStrdup(str)) == NULL) {
199  return NULL;
200  }
201 
202  temp_str = new_str;
203  while (*temp_str != '\0') {
204  *temp_str = u8_tolower((unsigned char)*temp_str);
205  temp_str++;
206  }
207 
208  return new_str;
209 }
210 
211 /**
212  * \brief Parses a line from the reference config file and adds it to Reference
213  * Config hash table DetectEngineCtx->reference_conf_ht.
214  *
215  * \param rawstr Pointer to the string to be parsed.
216  * \param de_ctx Pointer to the Detection Engine Context.
217  *
218  * \retval 0 On success.
219  * \retval -1 On failure.
220  */
222 {
223  char system[REFERENCE_SYSTEM_NAME_MAX];
224  char url[REFERENCE_CONTENT_NAME_MAX];
225 
226  SCRConfReference *ref_new = NULL;
227  SCRConfReference *ref_lookup = NULL;
228 
229  int ret = 0;
230 
231  ret = pcre2_match(de_ctx->reference_conf_regex, (PCRE2_SPTR8)line, strlen(line), 0, 0,
233  if (ret < 0) {
234  SCLogError("Invalid Reference Config in "
235  "reference.config file");
236  goto error;
237  }
238 
239  /* retrieve the reference system */
240  size_t copylen = sizeof(system);
241  ret = pcre2_substring_copy_bynumber(
242  de_ctx->reference_conf_regex_match, 1, (PCRE2_UCHAR8 *)system, &copylen);
243  if (ret < 0) {
244  SCLogError("pcre2_substring_copy_bynumber() failed");
245  goto error;
246  }
247 
248  /* retrieve the reference url */
249  copylen = sizeof(url);
250  ret = pcre2_substring_copy_bynumber(
251  de_ctx->reference_conf_regex_match, 2, (PCRE2_UCHAR8 *)url, &copylen);
252  if (ret < 0) {
253  SCLogError("pcre2_substring_copy_bynumber() failed");
254  goto error;
255  }
256 
257  /* Create a new instance of the parsed Reference string */
258  ref_new = SCRConfAllocSCRConfReference(system, url);
259  if (ref_new == NULL)
260  goto error;
261 
262  /* Check if the Reference is present in the HashTable. In case it's present
263  * ignore it, as it's a duplicate. If not present, add it to the table */
264  ref_lookup = HashTableLookup(de_ctx->reference_conf_ht, ref_new, 0);
265  if (ref_lookup == NULL) {
266  if (HashTableAdd(de_ctx->reference_conf_ht, ref_new, 0) < 0) {
267  SCLogDebug("HashTable Add failed");
268  }
269  } else {
270  SCLogDebug("Duplicate reference found inside reference.config");
272  }
273 
274  return 0;
275 
276  error:
277  return -1;
278 }
279 
280 /**
281  * \brief Checks if a string is a comment or a blank line.
282  *
283  * Comments lines are lines of the following format -
284  * "# This is a comment string" or
285  * " # This is a comment string".
286  *
287  * \param line String that has to be checked.
288  *
289  * \retval 1 On the argument string being a comment or blank line.
290  * \retval 0 Otherwise.
291  */
292 static int SCRConfIsLineBlankOrComment(char *line)
293 {
294  while (*line != '\0') {
295  /* we have a comment */
296  if (*line == '#')
297  return 1;
298 
299  /* this line is neither a comment line, nor a blank line */
300  if (!isspace((unsigned char)*line))
301  return 0;
302 
303  line++;
304  }
305 
306  /* we have a blank line */
307  return 1;
308 }
309 
310 /**
311  * \brief Parses the Reference Config file and updates the
312  * DetectionEngineCtx->reference_conf_ht with the Reference information.
313  *
314  * \param de_ctx Pointer to the Detection Engine Context.
315  */
316 static bool SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
317 {
318  char line[1024];
319  int runmode = SCRunmodeGet();
320  bool is_conf_test_mode = runmode == RUNMODE_CONF_TEST;
321  while (fgets(line, sizeof(line), fd) != NULL) {
322  if (SCRConfIsLineBlankOrComment(line))
323  continue;
324 
325  if (SCRConfAddReference(de_ctx, line) != 0) {
326  if (is_conf_test_mode) {
327  return false;
328  }
329  }
330  }
331 
332 #ifdef UNITTESTS
333  if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0)
334  SCLogInfo("tenant id %d: Added \"%d\" reference types from the reference.config file",
336  else
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 = SCCalloc(1, sizeof(SCRConfReference))) == NULL) {
363  return NULL;
364  }
365 
366  if ((ref->system = SCRConfStringToLowercase(system)) == NULL) {
367  SCFree(ref);
368  return NULL;
369  }
370 
371  if (url != NULL && (ref->url = SCStrdup(url)) == NULL) {
372  SCFree(ref->system);
373  SCFree(ref);
374  return NULL;
375  }
376 
377  return ref;
378 }
379 
380 /**
381  * \brief Frees a SCRConfReference instance.
382  *
383  * \param Pointer to the SCRConfReference instance that has to be freed.
384  */
386 {
387  if (ref != NULL) {
388  if (ref->system != NULL)
389  SCFree(ref->system);
390 
391  if (ref->url != NULL)
392  SCFree(ref->url);
393 
394  SCFree(ref);
395  }
396 }
397 
398 /**
399  * \brief Hashing function to be used to hash the Reference name. Would be
400  * supplied as an argument to the HashTableInit function for
401  * DetectEngineCtx->reference_conf_ht.
402  *
403  * \param ht Pointer to the HashTable.
404  * \param data Pointer to the data to be hashed. In this case, the data
405  * would be a pointer to a SCRConfReference instance.
406  * \param datalen Not used by this function.
407  */
408 uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen)
409 {
410  SCRConfReference *ref = (SCRConfReference *)data;
411  uint32_t hash = 0;
412  size_t i = 0;
413 
414  size_t len = strlen(ref->system);
415 
416  for (i = 0; i < len; i++)
417  hash += u8_tolower((unsigned char)ref->system[i]);
418 
419  hash = hash % ht->array_size;
420 
421  return hash;
422 }
423 
424 /**
425  * \brief Used to compare two References that have been stored in the HashTable.
426  * This function is supplied as an argument to the HashTableInit function
427  * for DetectionEngineCtx->reference_conf_ct.
428  *
429  * \param data1 Pointer to the first SCRConfReference to be compared.
430  * \param len1 Not used by this function.
431  * \param data2 Pointer to the second SCRConfReference to be compared.
432  * \param len2 Not used by this function.
433  *
434  * \retval 1 On data1 and data2 being equal.
435  * \retval 0 On data1 and data2 not being equal.
436  */
437 char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
438  void *data2, uint16_t datalen2)
439 {
440  SCRConfReference *ref1 = (SCRConfReference *)data1;
441  SCRConfReference *ref2 = (SCRConfReference *)data2;
442 
443  if (ref1 == NULL || ref2 == NULL)
444  return 0;
445 
446  if (ref1->system == NULL || ref2->system == NULL)
447  return 0;
448 
449  if (strcmp(ref1->system, ref2->system) == 0) {
450  SCLogDebug("Match found inside Reference-Config hash function");
451  return 1;
452  }
453 
454  return 0;
455 }
456 
457 /**
458  * \brief Used to free the Reference Config Hash Data that was stored in
459  * DetectEngineCtx->reference_conf_ht Hashtable.
460  *
461  * \param data Pointer to the data that has to be freed.
462  */
463 void SCRConfReferenceHashFree(void *data)
464 {
466 }
467 
468 /**
469  * \brief Loads the Reference info from the reference.config file.
470  *
471  * The reference.config file contains references that can be used in
472  * Signatures. Each line of the file should have the following format -
473  * config reference: system_name, reference_url.
474  *
475  * \param de_ctx Pointer to the Detection Engine Context that should be updated
476  * with reference information.
477  *
478  * \retval 0 On success.
479  * \retval -1 On failure.
480  */
482 {
483  fd = SCRConfInitContextAndLocalResources(de_ctx, fd);
484  if (fd == NULL) {
485 #ifdef UNITTESTS
486  if (RunmodeIsUnittests()) {
487  return -1;
488  }
489 #endif
490  SCLogError("please check the \"reference-config-file\" "
491  "option in your suricata.yaml file");
492  return -1;
493  }
494 
495  bool rc = SCRConfParseFile(de_ctx, fd);
496  SCRConfDeInitLocalResources(fd);
497 
498  return rc ? 0 : -1;
499 }
500 
501 /**
502  * \brief Gets the reference config from the corresponding hash table stored
503  * in the Detection Engine Context's reference conf ht, given the
504  * reference name.
505  *
506  * \param ct_name Pointer to the reference name that has to be looked up.
507  * \param de_ctx Pointer to the Detection Engine Context.
508  *
509  * \retval lookup_rconf_info Pointer to the SCRConfReference instance from
510  * the hash table on success; NULL on failure.
511  */
512 SCRConfReference *SCRConfGetReference(const char *rconf_name,
514 {
515  SCRConfReference *ref_conf = SCRConfAllocSCRConfReference(rconf_name, NULL);
516  if (ref_conf == NULL)
517  return NULL;
519  ref_conf, 0);
520 
522  return lookup_ref_conf;
523 }
524 
525 /*----------------------------------Unittests---------------------------------*/
526 
527 
528 #ifdef UNITTESTS
529 
530 /**
531  * \brief Creates a dummy reference config, with all valid references, for
532  * testing purposes.
533  */
535 {
536  const char *buffer =
537  "config reference: one http://www.one.com\n"
538  "config reference: two http://www.two.com\n"
539  "config reference: three http://www.three.com\n"
540  "config reference: one http://www.one.com\n"
541  "config reference: three http://www.three.com\n";
542 
543  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
544  if (fd == NULL)
545  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
546 
547  return fd;
548 }
549 
550 /**
551  * \brief Creates a dummy reference config, with some valid references and a
552  * couple of invalid references, for testing purposes.
553  */
555 {
556  const char *buffer =
557  "config reference: one http://www.one.com\n"
558  "config_ reference: two http://www.two.com\n"
559  "config reference_: three http://www.three.com\n"
560  "config reference: four\n"
561  "config reference five http://www.five.com\n";
562 
563  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
564  if (fd == NULL)
565  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
566 
567  return fd;
568 }
569 
570 /**
571  * \brief Creates a dummy reference config, with all invalid references, for
572  * testing purposes.
573  */
575 {
576  const char *buffer =
577  "config reference one http://www.one.com\n"
578  "config_ reference: two http://www.two.com\n"
579  "config reference_: three http://www.three.com\n"
580  "config reference: four\n";
581 
582  FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
583  if (fd == NULL)
584  SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
585 
586  return fd;
587 }
588 
589 /**
590  * \test Check that the reference file is loaded and the detection engine
591  * content reference_conf_ht loaded with the reference data.
592  */
593 static int SCRConfTest01(void)
594 {
596  int result = 0;
597 
598  if (de_ctx == NULL)
599  return result;
600 
604 
605  if (de_ctx->reference_conf_ht == NULL)
606  goto end;
607 
608  result = (de_ctx->reference_conf_ht->count == 3);
609  if (result == 0)
610  printf("FAILED: de_ctx->reference_conf_ht->count %u: ", de_ctx->reference_conf_ht->count);
611 
612  end:
613  if (de_ctx != NULL)
615  return result;
616 }
617 
618 /**
619  * \test Check that invalid references present in the reference.config file
620  * aren't loaded.
621  */
622 static int SCRConfTest02(void)
623 {
625  int result = 0;
626 
627  if (de_ctx == NULL)
628  return result;
629 
633 
634  if (de_ctx->reference_conf_ht == NULL)
635  goto end;
636 
637  result = (de_ctx->reference_conf_ht->count == 0);
638 
639 
640  end:
641  if (de_ctx != NULL)
643  return result;
644 }
645 
646 /**
647  * \test Check that only valid references are loaded into the hash table from
648  * the reference.config file.
649  */
650 static int SCRConfTest03(void)
651 {
653  int result = 0;
654 
655  if (de_ctx == NULL)
656  return result;
657 
661 
662  if (de_ctx->reference_conf_ht == NULL)
663  goto end;
664 
665  result = (de_ctx->reference_conf_ht->count == 1);
666 
667  end:
668  if (de_ctx != NULL)
670  return result;
671 }
672 
673 /**
674  * \test Check if the reference info from the reference.config file have
675  * been loaded into the hash table.
676  */
677 static int SCRConfTest04(void)
678 {
680  int result = 1;
681 
682  if (de_ctx == NULL)
683  return 0;
684 
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 
721 
722  if (de_ctx->reference_conf_ht == NULL)
723  goto end;
724 
725  result = (de_ctx->reference_conf_ht->count == 0);
726 
727  result &= (SCRConfGetReference("one", de_ctx) == NULL);
728  result &= (SCRConfGetReference("two", de_ctx) == NULL);
729  result &= (SCRConfGetReference("three", de_ctx) == NULL);
730  result &= (SCRConfGetReference("four", de_ctx) == NULL);
731  result &= (SCRConfGetReference("five", de_ctx) == NULL);
732 
733  end:
734  if (de_ctx != NULL)
736  return result;
737 }
738 
739 /**
740  * \test Check if the reference info from the reference.config file have
741  * been loaded into the hash table.
742  */
743 static int SCRConfTest06(void)
744 {
746  int result = 1;
747 
748  if (de_ctx == NULL)
749  return 0;
750 
754 
755  if (de_ctx->reference_conf_ht == NULL)
756  goto end;
757 
758  result = (de_ctx->reference_conf_ht->count == 1);
759 
760  result &= (SCRConfGetReference("one", de_ctx) != NULL);
761  result &= (SCRConfGetReference("two", de_ctx) == NULL);
762  result &= (SCRConfGetReference("three", de_ctx) == NULL);
763  result &= (SCRConfGetReference("four", de_ctx) == NULL);
764  result &= (SCRConfGetReference("five", de_ctx) == NULL);
765 
766  end:
767  if (de_ctx != NULL)
769  return result;
770 }
771 
772 #endif /* UNITTESTS */
773 
774 /**
775  * \brief This function registers unit tests for Reference Config API.
776  */
778 {
779 
780 #ifdef UNITTESTS
781  UtRegisterTest("SCRConfTest01", SCRConfTest01);
782  UtRegisterTest("SCRConfTest02", SCRConfTest02);
783  UtRegisterTest("SCRConfTest03", SCRConfTest03);
784  UtRegisterTest("SCRConfTest04", SCRConfTest04);
785  UtRegisterTest("SCRConfTest05", SCRConfTest05);
786  UtRegisterTest("SCRConfTest06", SCRConfTest06);
787 #endif /* UNITTESTS */
788 }
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:437
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: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:282
SCRConfGenerateInvalidDummyReferenceConfigFD03
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD03(void)
Creates a dummy reference config, with all invalid references, for testing purposes.
Definition: util-reference-config.c:574
util-hash.h
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:973
SCRConfGenerateInvalidDummyReferenceConfigFD02
FILE * SCRConfGenerateInvalidDummyReferenceConfigFD02(void)
Creates a dummy reference config, with some valid references and a couple of invalid references,...
Definition: util-reference-config.c:554
SCConfGet
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:351
DetectEngineCtx_::reference_conf_regex_match
pcre2_match_data * reference_conf_regex_match
Definition: detect.h:1173
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2715
HashTable_
Definition: util-hash.h:35
u8_tolower
#define u8_tolower(c)
Definition: suricata-common.h:461
SCReferenceConfDeinit
void SCReferenceConfDeinit(DetectEngineCtx *de_ctx)
Definition: util-reference-config.c:72
DetectEngineCtx_::reference_conf_regex
pcre2_code * reference_conf_regex
Definition: detect.h:1172
SCFmemopen
#define SCFmemopen
Definition: util-fmemopen.h:52
DetectEngineCtx_::reference_conf_ht
HashTable * reference_conf_ht
Definition: detect.h:1171
util-unittest.h
HashTableFree
void HashTableFree(HashTable *ht)
Free a HashTable and all its contents.
Definition: util-hash.c:112
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:180
SCRunmodeGet
SCRunMode SCRunmodeGet(void)
Get the current run mode.
Definition: suricata.c:301
util-debug.h
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
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:262
HashTableAdd
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:132
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:481
conf.h
SCReferenceSCConfInit
void SCReferenceSCConfInit(DetectEngineCtx *de_ctx)
Definition: util-reference-config.c:52
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:221
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:292
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:232
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:512
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:1098
DEBUG_VALIDATE_MARK_SANITIZED
#define DEBUG_VALIDATE_MARK_SANITIZED(ptr)
Definition: util-validate.h:111
suricata-common.h
HashTable_::count
uint32_t count
Definition: util-hash.h:40
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:408
str
#define str(s)
Definition: suricata-common.h:316
SCRConfRegisterTests
void SCRConfRegisterTests(void)
This function registers unit tests for Reference Config API.
Definition: util-reference-config.c:777
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
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:2676
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:534
SCRConfDeAllocSCRConfReference
void SCRConfDeAllocSCRConfReference(SCRConfReference *ref)
Frees a SCRConfReference instance.
Definition: util-reference-config.c:385
RUNMODE_CONF_TEST
@ RUNMODE_CONF_TEST
Definition: runmodes.h:56
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:463
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DetectEngineCtx_::tenant_id
uint32_t tenant_id
Definition: detect.h:980