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