Mercurial > dnsbl
diff src/context.cpp @ 168:6bac960af6b4
add generic reverse dns filtering regex
author | carl |
---|---|
date | Thu, 30 Aug 2007 11:08:46 -0700 |
parents | 9b129ed78d7d |
children | bd33eaccfed8 |
line wrap: on
line diff
--- a/src/context.cpp Mon Aug 27 20:49:19 2007 -0700 +++ b/src/context.cpp Thu Aug 30 11:08:46 2007 -0700 @@ -33,6 +33,7 @@ char *token_envfrom; char *token_envto; char *token_filter; +char *token_generic; char *token_host_limit; char *token_html_limit; char *token_html_tags; @@ -670,6 +671,8 @@ name = name_; verify_host = NULL; verifier = NULL; + generic_regx = NULL; + generic_message = NULL; autowhite_file = NULL; whitelister = NULL; env_from_default = (parent) ? token_inherit : token_unknown; @@ -694,6 +697,7 @@ // delete the underlying DNSBL objects. delete d; } + if (generic_regx && strlen(generic_regx)) regfree(&generic_pattern); } @@ -712,6 +716,30 @@ } +bool CONTEXT::set_generic(char *regx, char *msg) +{ + int rc = 0; + if (generic_regx && strlen(generic_regx)) regfree(&generic_pattern); + generic_regx = regx; + generic_message = msg; + if (generic_regx && strlen(generic_regx)) { + rc = regcomp(&generic_pattern, regx, REG_NOSUB | REG_ICASE | REG_EXTENDED); + } + return rc; // true iff bad pattern +} + + +char *CONTEXT::generic_match(char *client) +{ + if (parent && !generic_regx) return parent->generic_match(client); + if (!strlen(generic_regx)) return NULL; + if (0 == regexec(&generic_pattern, client, 0, NULL, 0)) { + return generic_message; + } + return NULL; +} + + bool CONTEXT::cover_env_to(char *to) { char buffer[maxlen]; char *x = strchr(to, '@'); @@ -983,6 +1011,11 @@ printf("%s verify %s; \n", indent, verify_host); } + if (generic_regx) { + printf("%s generic \"%s\" \n", indent, generic_regx); + printf("%s \"%s\"; \n", indent, generic_message); + } + if (autowhite_file && whitelister) { printf("%s autowhite %d %s; \n", indent, whitelister->get_days(), autowhite_file); } @@ -1331,6 +1364,21 @@ //////////////////////////////////////////////// // +bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me); +bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me) { + char *regx = tok.next(); + char *msg = tok.next(); + if (!tsa(tok, token_semi)) return false; + if (me.set_generic(regx, msg)) { + tok.token_error("invalid regular expression %s", regx, regx); + return false; + } + return true; +} + + +//////////////////////////////////////////////// +// bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me); bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me) { int days = tok.nextint(); @@ -1470,6 +1518,9 @@ else if (have == token_verify) { if (!parse_verify(tok, dc, *con)) return false; } + else if (have == token_generic) { + if (!parse_generic(tok, dc, *con)) return false; + } else if (have == token_autowhite) { if (!parse_autowhite(tok, dc, *con)) return false; } @@ -1542,6 +1593,7 @@ token_envfrom = register_string("env_from"); token_envto = register_string("env_to"); token_filter = register_string("filter"); + token_generic = register_string("generic"); token_host_limit = register_string("host_limit"); token_html_limit = register_string("html_limit"); token_html_tags = register_string("html_tags");