65 const char *conf_var_name,
70 const char *conf_var_type_name = NULL;
71 char conf_var_full_name[2048];
72 const char *conf_var_full_name_value = NULL;
74 if (conf_var_name == NULL)
77 while (conf_var_name[0] !=
'\0' && isspace((
unsigned char)conf_var_name[0])) {
81 (conf_var_name[0] ==
'$') ? conf_var_name++ : conf_var_name;
84 if (conf_var_type_name == NULL)
88 if (snprintf(conf_var_full_name,
sizeof(conf_var_full_name),
"%s.%s.%s",
93 if (snprintf(conf_var_full_name,
sizeof(conf_var_full_name),
"%s.%s",
94 conf_var_type_name, conf_var_name) < 0) {
100 SCLogError(
"Variable \"%s\" is not defined in "
101 "configuration file",
106 SCLogDebug(
"Value obtained from the yaml conf file, for the var "
107 "\"%s\" is \"%s\"", conf_var_name, conf_var_full_name_value);
117 static const char *dummy_conf_string =
121 "default-log-dir: /var/log/suricata\n"
125 " default-log-level: debug\n"
127 " default-format: \"<%t> - <%l>\"\n"
129 " default-startup-message: Your IDS has started.\n"
131 " default-output-filter:\n"
135 " - interface: console\n"
138 " - interface: file\n"
139 " filename: /var/log/suricata.log\n"
141 " - interface: syslog\n"
142 " facility: local5\n"
155 " HOME_NET: \"[192.168.0.0/16,10.8.0.0/16,127.0.0.1,2001:888:"
156 "13c5:5AFE::/64,2001:888:13c5:CAFE::/64]\"\n"
158 " EXTERNAL_NET: \"[!192.168.0.0/16,2000::/3]\"\n"
160 " HTTP_SERVERS: \"!192.168.0.0/16\"\n"
162 " SMTP_SERVERS: \"!192.168.0.0/16\"\n"
164 " SQL_SERVERS: \"!192.168.0.0/16\"\n"
166 " DNS_SERVERS: any\n"
168 " TELNET_SERVERS: any\n"
170 " AIM_SERVERS: any\n"
174 " HTTP_PORTS: \"80:81,88\"\n"
176 " SHELLCODE_PORTS: 80\n"
178 " ORACLE_PORTS: 1521\n"
187 static int SCRuleVarsPositiveTest01(
void)
196 "[192.168.0.0/16,10.8.0.0/16,127.0.0.1,2001:888:13c5:"
197 "5AFE::/64,2001:888:13c5:CAFE::/64]") == 0);
200 "[!192.168.0.0/16,2000::/3]") == 0);
203 "!192.168.0.0/16") == 0);
206 "!192.168.0.0/16") == 0);
209 "!192.168.0.0/16") == 0);
248 static int SCRuleVarsNegativeTest02(
void)
268 static int SCRuleVarsPositiveTest03(
void)
279 "alert tcp [$HTTP_SERVERS,$HOME_NET,192.168.2.5] $HTTP_PORTS -> $EXTERNAL_NET "
280 "[80,[!$HTTP_PORTS,$ORACLE_PORTS]] (msg:\"Rule Vars Test\"; sid:1;)");
293 static int SCRuleVarsNegativeTest04(
void)
303 de_ctx,
"alert tcp $HTTP_SERVER any -> any any (msg:\"Rule Vars Test\"; sid:1;)");
306 de_ctx,
"alert tcp $http_servers any -> any any (msg:\"Rule Vars Test\"; sid:1;)");
309 "alert tcp $http_servers any -> any $HTTP_PORTS (msg:\"Rule Vars Test\"; sid:1;)");
312 "alert tcp !$TELNET_SERVERS !80 -> any !$SSH_PORTS (msg:\"Rule Vars Test\"; sid:1;)");
321 static const char *dummy_mt_conf_string =
328 " HOME_NET: \"[1.2.3.4]\"\n"
330 " HTTP_PORTS: \"12345\"\n"
337 " HOME_NET: \"[8.8.8.8]\"\n"
339 " HTTP_PORTS: \"54321\"\n"
346 static int SCRuleVarsMTest01(
void)
388 UtRegisterTest(
"SCRuleVarsPositiveTest01", SCRuleVarsPositiveTest01);
389 UtRegisterTest(
"SCRuleVarsNegativeTest02", SCRuleVarsNegativeTest02);
390 UtRegisterTest(
"SCRuleVarsPositiveTest03", SCRuleVarsPositiveTest03);
391 UtRegisterTest(
"SCRuleVarsNegativeTest04", SCRuleVarsNegativeTest04);