comparison 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
comparison
equal deleted inserted replaced
167:9b129ed78d7d 168:6bac960af6b4
31 char *token_dnsbl; 31 char *token_dnsbl;
32 char *token_dnsbll; 32 char *token_dnsbll;
33 char *token_envfrom; 33 char *token_envfrom;
34 char *token_envto; 34 char *token_envto;
35 char *token_filter; 35 char *token_filter;
36 char *token_generic;
36 char *token_host_limit; 37 char *token_host_limit;
37 char *token_html_limit; 38 char *token_html_limit;
38 char *token_html_tags; 39 char *token_html_tags;
39 char *token_ignore; 40 char *token_ignore;
40 char *token_include; 41 char *token_include;
668 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) { 669 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) {
669 parent = parent_; 670 parent = parent_;
670 name = name_; 671 name = name_;
671 verify_host = NULL; 672 verify_host = NULL;
672 verifier = NULL; 673 verifier = NULL;
674 generic_regx = NULL;
675 generic_message = NULL;
673 autowhite_file = NULL; 676 autowhite_file = NULL;
674 whitelister = NULL; 677 whitelister = NULL;
675 env_from_default = (parent) ? token_inherit : token_unknown; 678 env_from_default = (parent) ? token_inherit : token_unknown;
676 content_filtering = (parent) ? parent->content_filtering : false; 679 content_filtering = (parent) ? parent->content_filtering : false;
677 content_suffix = NULL; 680 content_suffix = NULL;
692 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { 695 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
693 DNSBLP d = (*i).second; 696 DNSBLP d = (*i).second;
694 // delete the underlying DNSBL objects. 697 // delete the underlying DNSBL objects.
695 delete d; 698 delete d;
696 } 699 }
700 if (generic_regx && strlen(generic_regx)) regfree(&generic_pattern);
697 } 701 }
698 702
699 703
700 bool CONTEXT::is_parent(CONTEXTP p) { 704 bool CONTEXT::is_parent(CONTEXTP p) {
701 if (p == parent) return true; 705 if (p == parent) return true;
707 char *CONTEXT::get_full_name(char *buffer, int size) { 711 char *CONTEXT::get_full_name(char *buffer, int size) {
708 if (!parent) return name; 712 if (!parent) return name;
709 char buf[maxlen]; 713 char buf[maxlen];
710 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name); 714 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name);
711 return buffer; 715 return buffer;
716 }
717
718
719 bool CONTEXT::set_generic(char *regx, char *msg)
720 {
721 int rc = 0;
722 if (generic_regx && strlen(generic_regx)) regfree(&generic_pattern);
723 generic_regx = regx;
724 generic_message = msg;
725 if (generic_regx && strlen(generic_regx)) {
726 rc = regcomp(&generic_pattern, regx, REG_NOSUB | REG_ICASE | REG_EXTENDED);
727 }
728 return rc; // true iff bad pattern
729 }
730
731
732 char *CONTEXT::generic_match(char *client)
733 {
734 if (parent && !generic_regx) return parent->generic_match(client);
735 if (!strlen(generic_regx)) return NULL;
736 if (0 == regexec(&generic_pattern, client, 0, NULL, 0)) {
737 return generic_message;
738 }
739 return NULL;
712 } 740 }
713 741
714 742
715 bool CONTEXT::cover_env_to(char *to) { 743 bool CONTEXT::cover_env_to(char *to) {
716 char buffer[maxlen]; 744 char buffer[maxlen];
981 1009
982 if (verify_host) { 1010 if (verify_host) {
983 printf("%s verify %s; \n", indent, verify_host); 1011 printf("%s verify %s; \n", indent, verify_host);
984 } 1012 }
985 1013
1014 if (generic_regx) {
1015 printf("%s generic \"%s\" \n", indent, generic_regx);
1016 printf("%s \"%s\"; \n", indent, generic_message);
1017 }
1018
986 if (autowhite_file && whitelister) { 1019 if (autowhite_file && whitelister) {
987 printf("%s autowhite %d %s; \n", indent, whitelister->get_days(), autowhite_file); 1020 printf("%s autowhite %d %s; \n", indent, whitelister->get_days(), autowhite_file);
988 } 1021 }
989 1022
990 for (context_map::iterator i=children.begin(); i!=children.end(); i++) { 1023 for (context_map::iterator i=children.begin(); i!=children.end(); i++) {
1329 } 1362 }
1330 1363
1331 1364
1332 //////////////////////////////////////////////// 1365 ////////////////////////////////////////////////
1333 // 1366 //
1367 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me);
1368 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
1369 char *regx = tok.next();
1370 char *msg = tok.next();
1371 if (!tsa(tok, token_semi)) return false;
1372 if (me.set_generic(regx, msg)) {
1373 tok.token_error("invalid regular expression %s", regx, regx);
1374 return false;
1375 }
1376 return true;
1377 }
1378
1379
1380 ////////////////////////////////////////////////
1381 //
1334 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me); 1382 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me);
1335 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me) { 1383 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
1336 int days = tok.nextint(); 1384 int days = tok.nextint();
1337 char *fn = tok.next(); 1385 char *fn = tok.next();
1338 if (!tsa(tok, token_semi)) return false; 1386 if (!tsa(tok, token_semi)) return false;
1467 else if (have == token_envto) { 1515 else if (have == token_envto) {
1468 if (!parse_envto(tok, dc, *con)) return false; 1516 if (!parse_envto(tok, dc, *con)) return false;
1469 } 1517 }
1470 else if (have == token_verify) { 1518 else if (have == token_verify) {
1471 if (!parse_verify(tok, dc, *con)) return false; 1519 if (!parse_verify(tok, dc, *con)) return false;
1520 }
1521 else if (have == token_generic) {
1522 if (!parse_generic(tok, dc, *con)) return false;
1472 } 1523 }
1473 else if (have == token_autowhite) { 1524 else if (have == token_autowhite) {
1474 if (!parse_autowhite(tok, dc, *con)) return false; 1525 if (!parse_autowhite(tok, dc, *con)) return false;
1475 } 1526 }
1476 else if (have == token_envfrom) { 1527 else if (have == token_envfrom) {
1540 token_dnsbl = register_string("dnsbl"); 1591 token_dnsbl = register_string("dnsbl");
1541 token_dnsbll = register_string("dnsbl_list"); 1592 token_dnsbll = register_string("dnsbl_list");
1542 token_envfrom = register_string("env_from"); 1593 token_envfrom = register_string("env_from");
1543 token_envto = register_string("env_to"); 1594 token_envto = register_string("env_to");
1544 token_filter = register_string("filter"); 1595 token_filter = register_string("filter");
1596 token_generic = register_string("generic");
1545 token_host_limit = register_string("host_limit"); 1597 token_host_limit = register_string("host_limit");
1546 token_html_limit = register_string("html_limit"); 1598 token_html_limit = register_string("html_limit");
1547 token_html_tags = register_string("html_tags"); 1599 token_html_tags = register_string("html_tags");
1548 token_ignore = register_string("ignore"); 1600 token_ignore = register_string("ignore");
1549 token_include = register_string("include"); 1601 token_include = register_string("include");