66 const char *conf_var_name,
71 const char *conf_var_type_name = NULL;
72 char conf_var_full_name[2048];
73 const char *conf_var_full_name_value = NULL;
75 if (conf_var_name == NULL)
78 while (conf_var_name[0] !=
'\0' && isspace((
unsigned char)conf_var_name[0])) {
82 (conf_var_name[0] ==
'$') ? conf_var_name++ : conf_var_name;
85 if (conf_var_type_name == NULL)
89 if (snprintf(conf_var_full_name,
sizeof(conf_var_full_name),
"%s.%s.%s",
94 if (snprintf(conf_var_full_name,
sizeof(conf_var_full_name),
"%s.%s",
95 conf_var_type_name, conf_var_name) < 0) {
100 if (
SCConfGet(conf_var_full_name, &conf_var_full_name_value) != 1) {
101 SCLogError(
"Variable \"%s\" is not defined in "
102 "configuration file",
107 SCLogDebug(
"Value obtained from the yaml conf file, for the var "
108 "\"%s\" is \"%s\"", conf_var_name, conf_var_full_name_value);
118static const char *dummy_conf_string =
122 "default-log-dir: /var/log/suricata\n"
126 " default-log-level: debug\n"
128 " default-format: \"<%t> - <%l>\"\n"
130 " default-startup-message: Your IDS has started.\n"
132 " default-output-filter:\n"
136 " - interface: console\n"
139 " - interface: file\n"
140 " filename: /var/log/suricata.log\n"
142 " - interface: syslog\n"
143 " facility: local5\n"
156 " HOME_NET: \"[192.168.0.0/16,10.8.0.0/16,127.0.0.1,2001:888:"
157 "13c5:5AFE::/64,2001:888:13c5:CAFE::/64]\"\n"
159 " EXTERNAL_NET: \"[!192.168.0.0/16,2000::/3]\"\n"
161 " HTTP_SERVERS: \"!192.168.0.0/16\"\n"
163 " SMTP_SERVERS: \"!192.168.0.0/16\"\n"
165 " SQL_SERVERS: \"!192.168.0.0/16\"\n"
167 " DNS_SERVERS: any\n"
169 " TELNET_SERVERS: any\n"
171 " AIM_SERVERS: any\n"
175 " HTTP_PORTS: \"80:81,88\"\n"
177 " SHELLCODE_PORTS: 80\n"
179 " ORACLE_PORTS: 1521\n"
188static int SCRuleVarsPositiveTest01(
void)
197 "[192.168.0.0/16,10.8.0.0/16,127.0.0.1,2001:888:13c5:"
198 "5AFE::/64,2001:888:13c5:CAFE::/64]") == 0);
201 "[!192.168.0.0/16,2000::/3]") == 0);
204 "!192.168.0.0/16") == 0);
207 "!192.168.0.0/16") == 0);
210 "!192.168.0.0/16") == 0);
250static int SCRuleVarsNegativeTest02(
void)
270static int SCRuleVarsPositiveTest03(
void)
281 "alert tcp [$HTTP_SERVERS,$HOME_NET,192.168.2.5] $HTTP_PORTS -> $EXTERNAL_NET "
282 "[80,[!$HTTP_PORTS,$ORACLE_PORTS]] (msg:\"Rule Vars Test\"; sid:1;)");
295static int SCRuleVarsNegativeTest04(
void)
305 de_ctx,
"alert tcp $HTTP_SERVER any -> any any (msg:\"Rule Vars Test\"; sid:1;)");
308 de_ctx,
"alert tcp $http_servers any -> any any (msg:\"Rule Vars Test\"; sid:1;)");
311 "alert tcp $http_servers any -> any $HTTP_PORTS (msg:\"Rule Vars Test\"; sid:1;)");
314 "alert tcp !$TELNET_SERVERS !80 -> any !$SSH_PORTS (msg:\"Rule Vars Test\"; sid:1;)");
323static const char *dummy_mt_conf_string =
330 " HOME_NET: \"[1.2.3.4]\"\n"
332 " HTTP_PORTS: \"12345\"\n"
339 " HOME_NET: \"[8.8.8.8]\"\n"
341 " HTTP_PORTS: \"54321\"\n"
348static int SCRuleVarsMTest01(
void)
403 UtRegisterTest(
"SCRuleVarsPositiveTest01", SCRuleVarsPositiveTest01);
404 UtRegisterTest(
"SCRuleVarsNegativeTest02", SCRuleVarsNegativeTest02);
405 UtRegisterTest(
"SCRuleVarsPositiveTest03", SCRuleVarsPositiveTest03);
406 UtRegisterTest(
"SCRuleVarsNegativeTest04", SCRuleVarsNegativeTest04);
int SCConfYamlLoadString(const char *string, size_t len)
Load configuration from a YAML string.
void SCConfInit(void)
Initialize the configuration system.
void SCConfDeInit(void)
De-initializes the configuration system.
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void SCConfCreateContextBackup(void)
Creates a backup of the conf_hash hash_table used by the conf API.
void SCConfRestoreContextBackup(void)
Restores the backup of the hash_table present in backup_conf_hash back to conf_hash.
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
main detection engine ctx
#define SCReturnCharPtr(x)
#define SCLogError(...)
Macro used to log ERROR messages.
const char * SCMapEnumValueToName(int enum_value, SCEnumCharMap *table)
Maps an enum value to a string name, from the supplied table.
const char * SCRuleVarsGetConfVar(const DetectEngineCtx *de_ctx, const char *conf_var_name, SCRuleVarsType conf_vars_type)
SCEnumCharMap sc_rule_vars_type_map[]
void SCRuleVarsRegisterTests(void)
@ SC_RULE_VARS_PORT_GROUPS
@ SC_RULE_VARS_ADDRESS_GROUPS