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