comparison src/dnsbl.cpp @ 124:ea6f9c812faa stable-5-16

put hostname in smtp message for uribl style lookups
author carl
date Thu, 16 Mar 2006 15:20:37 -0800
parents ecd97e7eb1f0
children 05ae49d37896
comparison
equal deleted inserted replaced
123:ecd97e7eb1f0 124:ea6f9c812faa
656 656
657 657
658 //////////////////////////////////////////////// 658 ////////////////////////////////////////////////
659 // lookup the domain name part of a hostname on two lists 659 // lookup the domain name part of a hostname on two lists
660 // 660 //
661 bool uriblookup(mlfiPriv &priv ,char *hostname, char *top) ; 661 // if we find part of the hostname on the uribl, return
662 bool uriblookup(mlfiPriv &priv, char *hostname, char *top) { 662 // true and point found to the part of the hostname that we found.
663 // otherwise, return false and preserve the value of found.
664 //
665 bool uriblookup(mlfiPriv &priv ,char *hostname, char *top, char *&found) ;
666 bool uriblookup(mlfiPriv &priv, char *hostname, char *top, char *&found) {
663 // top is pointer to '.' char at end of base domain, or null for ip address form 667 // top is pointer to '.' char at end of base domain, or null for ip address form
664 // so for hostname of www.fred.mydomain.co.uk 668 // so for hostname of www.fred.mydomain.co.uk
665 // top points to-----------------------^ 669 // top points to-----------------------^
666 // and we end up looking at only mydomain.co.uk, ignoring the www.fred stuff 670 // and we end up looking at only mydomain.co.uk, ignoring the www.fred stuff
667 char buf[maxlen]; 671 char buf[maxlen];
668 char buf2[maxlen];
669 const char *uriblname[2] = { "multi.surbl.org", "multi.uribl.com" };
670
671 if (top) { 672 if (top) {
672 // add one more component 673 // add one more component
673 *top = '\0'; 674 *top = '\0';
674 char *x = strrchr(hostname, '.'); 675 char *x = strrchr(hostname, '.');
675 if (x) hostname = x+1; 676 if (x) hostname = x+1;
680 if (debug_syslog > 2) { 681 if (debug_syslog > 2) {
681 char tmp[maxlen]; 682 char tmp[maxlen];
682 snprintf(tmp, sizeof(tmp), "found %s on %s", hostname, priv.uribl_suffix); 683 snprintf(tmp, sizeof(tmp), "found %s on %s", hostname, priv.uribl_suffix);
683 my_syslog(tmp); 684 my_syslog(tmp);
684 } 685 }
686 found = hostname;
685 return true; 687 return true;
686 } 688 }
687 return false; 689 return false;
688 } 690 }
689 691
690 692
691 //////////////////////////////////////////////// 693 ////////////////////////////////////////////////
692 // uribl checker 694 // uribl checker
693 // ------------- 695 // -------------
694 // hostname MUST not have a trailing dot 696 // hostname MUST not have a trailing dot
695 // If tld, two level lookup. 697 // If tld, two level lookup.
696 // Else, look up three level domain. 698 // Else, look up three level domain.
697 bool check_uribl(mlfiPriv &priv, char *hostname) ; 699 //
698 bool check_uribl(mlfiPriv &priv, char *hostname) { 700 // if we find part of the hostname on the uribl, return
701 // true and point found to the part of the hostname that we found.
702 // otherwise, return false and preserve the value of found.
703 //
704 bool check_uribl(mlfiPriv &priv, char *hostname, char *&found) ;
705 bool check_uribl(mlfiPriv &priv, char *hostname, char *&found) {
699 in_addr ip; 706 in_addr ip;
700 if (inet_aton(hostname, &ip)) { 707 if (inet_aton(hostname, &ip)) {
701 const u_char *src = (const u_char *)&ip.s_addr; 708 const u_char *src = (const u_char *)&ip.s_addr;
702 char adr[sizeof "255.255.255.255"]; 709 static char adr[sizeof "255.255.255.255"];
703 snprintf(adr, sizeof(adr), "%u.%u.%u.%u", src[3], src[2], src[1], src[0]); 710 snprintf(adr, sizeof(adr), "%u.%u.%u.%u", src[3], src[2], src[1], src[0]);
704 return (uriblookup(priv, adr, NULL)); 711 return (uriblookup(priv, adr, NULL, found));
705 } 712 }
706 713
707 char *top, *top2, *top3; 714 char *top, *top2, *top3;
708 top = strrchr(hostname, '.'); 715 top = strrchr(hostname, '.');
709 if (top) { 716 if (top) {
713 720
714 if (top2) { 721 if (top2) {
715 string_set::iterator i = priv.memory->get_cctlds()->find(top2+1); 722 string_set::iterator i = priv.memory->get_cctlds()->find(top2+1);
716 string_set::iterator x = priv.memory->get_cctlds()->end(); 723 string_set::iterator x = priv.memory->get_cctlds()->end();
717 // if we have a 2-level-cctld, just look at top three levels of the name 724 // if we have a 2-level-cctld, just look at top three levels of the name
718 if (i != x) return uriblookup(priv, hostname, top2); 725 if (i != x) return uriblookup(priv, hostname, top2, found);
719 726
720 *top2 = '\0'; 727 *top2 = '\0';
721 top3 = strrchr(hostname, '.'); 728 top3 = strrchr(hostname, '.');
722 *top2 = '.'; 729 *top2 = '.';
723 730
724 // if we have more than 3 levels in the name, look at the top three levels of the name 731 // if we have more than 3 levels in the name, look at the top three levels of the name
725 if (top3 && uriblookup(priv, hostname, top2)) return true; 732 if (top3 && uriblookup(priv, hostname, top2, found)) return true;
726 // if that was not found, fall thru to looking at the top two levels 733 // if that was not found, fall thru to looking at the top two levels
727 } 734 }
728 // look at the top two levels of the name 735 // look at the top two levels of the name
729 return uriblookup(priv, hostname, top); 736 return uriblookup(priv, hostname, top, found);
730 } 737 }
731 return false; 738 return false;
732 } 739 }
733 740
734 741
735 //////////////////////////////////////////////// 742 ////////////////////////////////////////////////
736 // check the hosts from the body against the content filter and uribl dnsbls 743 // check the hosts from the body against the content filter and uribl dnsbls
737 // 744 //
738 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip); 745 //
739 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip) { 746 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip, char *&found);
747 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&msg, char *&host, int &ip, char *&found) {
748 found = NULL; // normally ip address style
740 if (!priv.content_suffix && !priv.uribl_suffix) return false; // nothing to check 749 if (!priv.content_suffix && !priv.uribl_suffix) return false; // nothing to check
741 CONFIG &dc = *priv.pc; 750 CONFIG &dc = *priv.pc;
742 string_set &hosts = priv.memory->get_hosts(); 751 string_set &hosts = priv.memory->get_hosts();
743 string_set &ignore = *priv.content_host_ignore; 752 string_set &ignore = *priv.content_host_ignore;
744 753
783 if (ip) { 792 if (ip) {
784 int_set::iterator i = ips.find(ip); 793 int_set::iterator i = ips.find(ip);
785 if (i == ips.end()) { 794 if (i == ips.end()) {
786 // we haven't looked this up yet 795 // we haven't looked this up yet
787 ips.insert(ip); 796 ips.insert(ip);
788 if (check_single(priv, ip, priv.content_suffix)) { 797 // check dnsbl style list
798 if (priv.content_suffix && check_single(priv, ip, priv.content_suffix)) {
789 msg = priv.content_message; 799 msg = priv.content_message;
790 return true; 800 return true;
791 } 801 }
792 // Check uribl & surbl 802 // Check uribl & surbl style list
793 if (check_uribl(priv, host)) { 803 if (priv.uribl_suffix && check_uribl(priv, host, found)) {
794 msg = priv.uribl_message; 804 msg = priv.uribl_message;
795 return true; 805 return true;
796 } 806 }
797 } 807 }
798 } 808 }
993 limit = max(limit, con.get_host_limit()); 1003 limit = max(limit, con.get_host_limit());
994 } 1004 }
995 } 1005 }
996 bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content() 1006 bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content()
997 if (!rejecting) { 1007 if (!rejecting) {
998 char *fmt; 1008 char *fmt, *found;
999 if (check_hosts(priv, random, limit, fmt, host, ip)) { 1009 if (check_hosts(priv, random, limit, fmt, host, ip, found)) {
1000 char adr[sizeof "255.255.255.255"]; 1010 if (found) {
1001 adr[0] = '\0'; 1011 // uribl style
1002 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr)); 1012 snprintf(buf, sizeof(buf), fmt, host, found);
1003 snprintf(buf, sizeof(buf), fmt, host, adr); 1013 }
1014 else {
1015 // dnsbl style
1016 char adr[sizeof "255.255.255.255"];
1017 adr[0] = '\0';
1018 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
1019 snprintf(buf, sizeof(buf), fmt, host, adr);
1020 }
1004 msg = buf; 1021 msg = buf;
1005 rejecting = true; 1022 rejecting = true;
1006 } 1023 }
1007 } 1024 }
1008 if (!rejecting) { 1025 if (!rejecting) {