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