suricata
util-reference-config.c File Reference
#include "suricata-common.h"
#include "detect.h"
#include "detect-engine.h"
#include "util-hash.h"
#include "util-reference-config.h"
#include "conf.h"
#include "util-unittest.h"
#include "util-error.h"
#include "util-debug.h"
#include "util-fmemopen.h"
Include dependency graph for util-reference-config.c:

Go to the source code of this file.

Macros

#define SC_RCONF_REGEX   "^\\s*config\\s+reference\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s+(.+)\\s*$"
 
#define SC_RCONF_DEFAULT_FILE_PATH   CONFIG_DIR "/reference.config"
 
#define MAX_SUBSTRINGS   30
 

Functions

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 HashTableInit function for DetectEngineCtx->reference_conf_ht. More...
 
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 an argument to the HashTableInit function for DetectionEngineCtx->reference_conf_ct. More...
 
void SCRConfReferenceHashFree (void *data)
 Used to free the Reference Config Hash Data that was stored in DetectEngineCtx->reference_conf_ht Hashtable. More...
 
void SCReferenceConfInit (void)
 
void SCReferenceConfDeinit (void)
 
void SCRConfDeInitContext (DetectEngineCtx *de_ctx)
 Releases de_ctx resources related to Reference Config API. More...
 
SCRConfReferenceSCRConfAllocSCRConfReference (const char *system, const char *url)
 Returns a new SCRConfReference instance. The reference string is converted into lowercase, before being assigned to the instance. More...
 
void SCRConfDeAllocSCRConfReference (SCRConfReference *ref)
 Frees a SCRConfReference instance. More...
 
int SCRConfLoadReferenceConfigFile (DetectEngineCtx *de_ctx, FILE *fd)
 Loads the Reference info from the reference.config file. More...
 
SCRConfReferenceSCRConfGetReference (const char *rconf_name, DetectEngineCtx *de_ctx)
 Gets the refernce config from the corresponding hash table stored in the Detection Engine Context's reference conf ht, given the reference name. More...
 
FILE * SCRConfGenerateValidDummyReferenceConfigFD01 (void)
 Creates a dummy reference config, with all valid references, for testing purposes. More...
 
FILE * SCRConfGenerateInValidDummyReferenceConfigFD02 (void)
 Creates a dummy reference config, with some valid references and a couple of invalid references, for testing purposes. More...
 
FILE * SCRConfGenerateInValidDummyReferenceConfigFD03 (void)
 Creates a dummy reference config, with all invalid references, for testing purposes. More...
 
void SCRConfRegisterTests (void)
 This function registers unit tests for Reference Config API. More...
 

Detailed Description

Macro Definition Documentation

#define MAX_SUBSTRINGS   30

Referenced by SCRConfDeInitContext().

#define SC_RCONF_DEFAULT_FILE_PATH   CONFIG_DIR "/reference.config"

Definition at line 42 of file util-reference-config.c.

Referenced by SCReferenceConfDeinit().

#define SC_RCONF_REGEX   "^\\s*config\\s+reference\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s+(.+)\\s*$"

Definition at line 39 of file util-reference-config.c.

Referenced by SCReferenceConfInit().

Function Documentation

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.

Parameters
systemPointer to the system.
urlPointer to the reference url.
Return values
refPointer to the new instance of SCRConfReference.

Definition at line 366 of file util-reference-config.c.

References SC_ERR_INVALID_SIGNATURE, SCFree, SCLogError, SCMalloc, SCStrdup, SCRConfReference_::system, and SCRConfReference_::url.

Referenced by SCRConfDeInitContext(), and SCRConfGetReference().

Here is the caller graph for this function:

void SCRConfDeAllocSCRConfReference ( SCRConfReference ref)

Frees a SCRConfReference instance.

Parameters
Pointerto the SCRConfReference instance that has to be freed.

Definition at line 400 of file util-reference-config.c.

References SCFree, SCRConfReference_::system, and SCRConfReference_::url.

Referenced by SCRConfDeInitContext(), SCRConfGetReference(), and SCRConfReferenceHashFree().

Here is the caller graph for this function:

void SCRConfDeInitContext ( DetectEngineCtx de_ctx)

Releases de_ctx resources related to Reference Config API.

Definition at line 202 of file util-reference-config.c.

References HashTable_::count, HashTableAdd(), HashTableFree(), HashTableLookup(), MAX_SUBSTRINGS, DetectEngineCtx_::reference_conf_ht, SC_ERR_PCRE_GET_SUBSTRING, SC_ERR_REFERENCE_CONFIG, SCLogDebug, SCLogError, SCLogInfo, SCRConfAllocSCRConfReference(), SCRConfDeAllocSCRConfReference(), SCStrdup, and str.

Referenced by DetectEngineCtxFree().

Here is the call graph for this function:

Here is the caller graph for this function:

FILE* SCRConfGenerateInValidDummyReferenceConfigFD02 ( void  )

Creates a dummy reference config, with some valid references and a couple of invalid references, for testing purposes.

Definition at line 578 of file util-reference-config.c.

References SCFmemopen, and SCLogDebug.

Referenced by SCRConfGenerateInValidDummyReferenceConfigFD03().

Here is the caller graph for this function:

FILE* SCRConfGenerateInValidDummyReferenceConfigFD03 ( void  )
FILE* SCRConfGenerateValidDummyReferenceConfigFD01 ( void  )

Creates a dummy reference config, with all valid references, for testing purposes.

Definition at line 558 of file util-reference-config.c.

References SCFmemopen, and SCLogDebug.

Referenced by DetectReferenceFree(), and SCRConfGenerateInValidDummyReferenceConfigFD03().

Here is the caller graph for this function:

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 reference conf ht, given the reference name.

Parameters
ct_namePointer to the reference name that has to be looked up.
de_ctxPointer to the Detection Engine Context.
Return values
lookup_rconf_infoPointer to the SCRConfReference instance from the hash table on success; NULL on failure.

Definition at line 536 of file util-reference-config.c.

References HashTableLookup(), DetectEngineCtx_::reference_conf_ht, SCRConfAllocSCRConfReference(), and SCRConfDeAllocSCRConfReference().

Referenced by DetectReferenceFree(), and SCRConfGenerateInValidDummyReferenceConfigFD03().

Here is the call graph for this function:

Here is the caller graph for this function:

int SCRConfLoadReferenceConfigFile ( DetectEngineCtx de_ctx,
FILE *  fd 
)

Loads the Reference info from the reference.config file.

The reference.config file contains references that can be used in Signatures. Each line of the file should have the following format - config reference: system_name, reference_url.

Parameters
de_ctxPointer to the Detection Engine Context that should be updated with reference information.
Return values
0On success.
-1On failure.

Definition at line 505 of file util-reference-config.c.

References RunmodeIsUnittests(), SC_ERR_OPENING_FILE, and SCLogError.

Referenced by DetectEngineInspectBufferGeneric(), DetectReferenceFree(), and SCRConfGenerateInValidDummyReferenceConfigFD03().

Here is the call graph for this function:

Here is the caller graph for this function:

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 an argument to the HashTableInit function for DetectionEngineCtx->reference_conf_ct.

Parameters
data1Pointer to the first SCRConfReference to be compared.
len1Not used by this function.
data2Pointer to the second SCRConfReference to be compared.
len2Not used by this function.
Return values
1On data1 and data2 being equal.
0On data1 and data2 not being equal.

Definition at line 454 of file util-reference-config.c.

References SCLogDebug, and SCRConfReference_::system.

Referenced by SCReferenceConfDeinit().

Here is the caller graph for this function:

void SCRConfReferenceHashFree ( void *  data)

Used to free the Reference Config Hash Data that was stored in DetectEngineCtx->reference_conf_ht Hashtable.

Parameters
dataPointer to the data that has to be freed.

Definition at line 485 of file util-reference-config.c.

References SCRConfDeAllocSCRConfReference().

Referenced by SCReferenceConfDeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

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 HashTableInit function for DetectEngineCtx->reference_conf_ht.

Parameters
htPointer to the HashTable.
dataPointer to the data to be hashed. In this case, the data would be a pointer to a SCRConfReference instance.
datalenNot used by this function.

Definition at line 425 of file util-reference-config.c.

References HashTable_::array_size, len, and SCRConfReference_::system.

Referenced by SCReferenceConfDeinit().

Here is the caller graph for this function:

void SCRConfRegisterTests ( void  )

This function registers unit tests for Reference Config API.

Definition at line 795 of file util-reference-config.c.

References UtRegisterTest().

Here is the call graph for this function:

void SCReferenceConfInit ( void  )

Definition at line 56 of file util-reference-config.c.

References SC_RCONF_REGEX, and SCLogDebug.

Referenced by DetectSetupParseRegexes(), PostRunDeinit(), and RunUnittests().

Here is the caller graph for this function: