Mercurial > dnsbl
comparison src/dnsbl.cpp @ 119:d9d2f8699621
uribl patch from Jeff Evans <jeffe@tricab.com>
author | carl |
---|---|
date | Sun, 12 Mar 2006 12:38:43 -0800 |
parents | aa07452e641b |
children | 1d9e6c1b8872 |
comparison
equal
deleted
inserted
replaced
118:13fcb0c66763 | 119:d9d2f8699621 |
---|---|
230 only_whites = true; | 230 only_whites = true; |
231 memory = NULL; | 231 memory = NULL; |
232 scanner = NULL; | 232 scanner = NULL; |
233 content_suffix = NULL; | 233 content_suffix = NULL; |
234 content_message = NULL; | 234 content_message = NULL; |
235 uribl_suffix = NULL; | |
236 uribl_message = NULL; | |
235 content_host_ignore = NULL; | 237 content_host_ignore = NULL; |
236 } | 238 } |
237 | 239 |
238 mlfiPriv::~mlfiPriv() { | 240 mlfiPriv::~mlfiPriv() { |
239 return_fd(); | 241 return_fd(); |
257 only_whites = true; | 259 only_whites = true; |
258 memory = NULL; | 260 memory = NULL; |
259 scanner = NULL; | 261 scanner = NULL; |
260 content_suffix = NULL; | 262 content_suffix = NULL; |
261 content_message = NULL; | 263 content_message = NULL; |
264 uribl_suffix = NULL; | |
265 uribl_message = NULL; | |
262 content_host_ignore = NULL; | 266 content_host_ignore = NULL; |
263 } | 267 } |
264 } | 268 } |
265 | 269 |
266 void mlfiPriv::get_fd() { | 270 void mlfiPriv::get_fd() { |
367 // the content filtering parameters | 371 // the content filtering parameters |
368 memory = new recorder(this, con.get_html_tags(), con.get_content_tlds(), con.get_content_cctlds()); | 372 memory = new recorder(this, con.get_html_tags(), con.get_content_tlds(), con.get_content_cctlds()); |
369 scanner = new url_scanner(memory); | 373 scanner = new url_scanner(memory); |
370 content_suffix = con.get_content_suffix(); | 374 content_suffix = con.get_content_suffix(); |
371 content_message = con.get_content_message(); | 375 content_message = con.get_content_message(); |
376 uribl_suffix = con.get_uribl_suffix(); | |
377 uribl_message = con.get_uribl_message(); | |
372 content_host_ignore = &con.get_content_host_ignore(); | 378 content_host_ignore = &con.get_content_host_ignore(); |
373 } | 379 } |
374 } | 380 } |
375 | 381 |
376 #define MLFIPRIV ((struct mlfiPriv *) smfi_getpriv(ctx)) | 382 #define MLFIPRIV ((struct mlfiPriv *) smfi_getpriv(ctx)) |
667 *top = '\0'; | 673 *top = '\0'; |
668 char *x = strrchr(hostname, '.'); | 674 char *x = strrchr(hostname, '.'); |
669 if (x) hostname = x+1; | 675 if (x) hostname = x+1; |
670 *top = '.'; | 676 *top = '.'; |
671 } | 677 } |
672 for (int i=0; i<2; i++) { | 678 snprintf(buf, sizeof(buf), "%s.%s", hostname, priv.uribl_suffix); |
673 snprintf(buf, sizeof(buf), "%s.%s", hostname, uriblname[i]); | 679 if (dns_interface(priv, buf, false, NULL)) { |
674 if (debug_syslog > 2) { | 680 if (debug_syslog > 2) { |
675 char tmp[maxlen]; | 681 char tmp[maxlen]; |
676 snprintf(tmp, sizeof(tmp), "Looking up %s on %s", hostname, uriblname[i]); | 682 snprintf(tmp, sizeof(tmp), "found %s on %s", hostname, priv.uribl_suffix); |
677 my_syslog(tmp); | 683 my_syslog(tmp); |
678 } | 684 } |
679 if (dns_interface(priv, buf, false, NULL)) return true; | 685 return true; |
680 } | 686 } |
681 return false; | 687 return false; |
682 } | 688 } |
683 | 689 |
684 | 690 |
725 return false; | 731 return false; |
726 } | 732 } |
727 | 733 |
728 | 734 |
729 //////////////////////////////////////////////// | 735 //////////////////////////////////////////////// |
730 // check the hosts from the body against the content dnsbl | 736 // check the hosts from the body against the content filter and uribl dnsbls |
731 // | 737 // |
732 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int &ip); | 738 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip); |
733 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int &ip) { | 739 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip) { |
740 if (!priv.content_suffix && !priv.uribl_suffix) return false; // nothing to check | |
734 CONFIG &dc = *priv.pc; | 741 CONFIG &dc = *priv.pc; |
735 string_set &hosts = priv.memory->get_hosts(); | 742 string_set &hosts = priv.memory->get_hosts(); |
736 string_set &ignore = *priv.content_host_ignore; | 743 string_set &ignore = *priv.content_host_ignore; |
737 char *suffix = priv.content_suffix; | |
738 | 744 |
739 int count = 0; | 745 int count = 0; |
740 int cnt = hosts.size(); // number of hosts we could look at | 746 int cnt = hosts.size(); // number of hosts we could look at |
741 int_set ips; | 747 int_set ips; |
742 ns_map nameservers; | 748 ns_map nameservers; |
777 if (ip) { | 783 if (ip) { |
778 int_set::iterator i = ips.find(ip); | 784 int_set::iterator i = ips.find(ip); |
779 if (i == ips.end()) { | 785 if (i == ips.end()) { |
780 // we haven't looked this up yet | 786 // we haven't looked this up yet |
781 ips.insert(ip); | 787 ips.insert(ip); |
782 if (check_single(priv, ip, suffix)) return true; | 788 if (check_single(priv, ip, priv.content_suffix)) { |
789 msg = priv.content_message; | |
790 return true; | |
791 } | |
783 // Check uribl & surbl | 792 // Check uribl & surbl |
784 if (check_uribl(priv, host)) return true; | 793 if (check_uribl(priv, host)) { |
794 msg = priv.uribl_message; | |
795 return true; | |
796 } | |
785 } | 797 } |
786 } | 798 } |
787 } | 799 } |
788 limit *= 4; // allow average of 3 ns per host name | 800 limit *= 4; // allow average of 3 ns per host name |
789 for (ns_mapper::iterator i=nameservers.ns_ip.begin(); i!=nameservers.ns_ip.end(); i++) { | 801 for (ns_mapper::iterator i=nameservers.ns_ip.begin(); i!=nameservers.ns_ip.end(); i++) { |
790 count++; | 802 count++; |
791 if ((count > limit) && (limit > 0)) { | 803 if ((count > limit) && (limit > 0)) return false; // too many name servers to check them all |
792 if (random) continue; // don't complain | |
793 return true; | |
794 } | |
795 host = (*i).first; // a transient reference that needs to be replaced before we return it | 804 host = (*i).first; // a transient reference that needs to be replaced before we return it |
796 ip = (*i).second; | 805 ip = (*i).second; |
797 if (!ip) ip = dns_interface(priv, host, false, NULL); | 806 if (!ip) ip = dns_interface(priv, host, false, NULL); |
798 if (debug_syslog > 2) { | 807 if (debug_syslog > 2) { |
799 char buf[maxlen]; | 808 char buf[maxlen]; |
810 } | 819 } |
811 if (ip) { | 820 if (ip) { |
812 int_set::iterator i = ips.find(ip); | 821 int_set::iterator i = ips.find(ip); |
813 if (i == ips.end()) { | 822 if (i == ips.end()) { |
814 ips.insert(ip); | 823 ips.insert(ip); |
815 if (check_single(priv, ip, suffix)) { | 824 if (check_single(priv, ip, priv.content_suffix)) { |
825 msg = priv.content_message; | |
816 string_map::iterator j = nameservers.ns_host.find(host); | 826 string_map::iterator j = nameservers.ns_host.find(host); |
817 if (j != nameservers.ns_host.end()) { | 827 if (j != nameservers.ns_host.end()) { |
818 char *refer = (*j).second; | 828 char *refer = (*j).second; |
819 char buf[maxlen]; | 829 char buf[maxlen]; |
820 snprintf(buf, sizeof(buf), "%s with nameserver %s", refer, host); | 830 snprintf(buf, sizeof(buf), "%s with nameserver %s", refer, host); |
983 limit = max(limit, con.get_host_limit()); | 993 limit = max(limit, con.get_host_limit()); |
984 } | 994 } |
985 } | 995 } |
986 bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content() | 996 bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content() |
987 if (!rejecting) { | 997 if (!rejecting) { |
988 if (check_hosts(priv, random, limit, host, ip)) { | 998 char *msg; |
999 if (check_hosts(priv, random, limit, msg, host, ip)) { | |
989 char adr[sizeof "255.255.255.255"]; | 1000 char adr[sizeof "255.255.255.255"]; |
990 adr[0] = '\0'; | 1001 adr[0] = '\0'; |
991 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr)); | 1002 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr)); |
992 snprintf(buf, sizeof(buf), priv.content_message, host, adr); | 1003 snprintf(buf, sizeof(buf), msg, host, adr); |
993 msg = buf; | 1004 msg = buf; |
994 rejecting = true; | 1005 rejecting = true; |
995 } | 1006 } |
996 } | 1007 } |
997 if (!rejecting) { | 1008 if (!rejecting) { |