From 1adbe3b23a9ce4c3a859d5e6c28fcdb740354b3e Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 18 Feb 2016 10:38:11 +0200 Subject: [PATCH] No user definitions in dbfwfilter rules is treated as an error again The lack of user definition lines in the dbfwfilter rule file was ignored previously but this change makes the lack of users an error again. Also added function documentation to some of the functions. --- server/modules/filter/dbfwfilter/dbfwfilter.c | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 4c53ff573..087653381 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -1529,6 +1529,13 @@ bool define_regex_rule(void* scanner, char* pattern) return re != NULL; } +/** + * @brief Find a rule by name + * + * @param rules List of all rules + * @param name Name of the rule + * @return Pointer to the rule or NULL if rule was not found + */ static RULE* find_rule_by_name(RULE* rules, const char* name) { while (rules) @@ -1543,6 +1550,14 @@ static RULE* find_rule_by_name(RULE* rules, const char* name) return NULL; } +/** + * @brief Process the user templates into actual user definitions + * + * @param instance Filter instance + * @param templates User templates + * @param rules List of all rules + * @return True on success, false on error. + */ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templates, RULE* rules) { @@ -1616,13 +1631,20 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ } templates = templates->next; } + + if (templates == NULL) + { + MXS_ERROR("No user definitions found in the rule file."); + rval = false; + } + return rval; } /** * Read a rule file from disk and process it into rule and user definitions * @param filename Name of the file - * @param instance Filter isntance + * @param instance Filter instance * @return True on success, false on error. */ static bool process_rule_file(const char* filename, FW_INSTANCE* instance) @@ -1656,6 +1678,7 @@ static bool process_rule_file(const char* filename, FW_INSTANCE* instance) { rc = 1; free_rules(pstack.rule); + MXS_ERROR("Failed to process rule file '%s'.", filename); } free_user_templates(pstack.templates);