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 (
ConfGet(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);
118 static 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"
188 static 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);
250 static int SCRuleVarsNegativeTest02(
void)
270 static 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;)");
295 static 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;)");
323 static 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"
348 static int SCRuleVarsMTest01(
void)
403 UtRegisterTest(
"SCRuleVarsPositiveTest01", SCRuleVarsPositiveTest01);
404 UtRegisterTest(
"SCRuleVarsNegativeTest02", SCRuleVarsNegativeTest02);
405 UtRegisterTest(
"SCRuleVarsPositiveTest03", SCRuleVarsPositiveTest03);
406 UtRegisterTest(
"SCRuleVarsNegativeTest04", SCRuleVarsNegativeTest04);