comparison src/dnsbl.cpp @ 74:b7449114ebb0

start coding on new config syntax
author carl
date Sun, 10 Jul 2005 14:19:00 -0700
parents 2b369f7db7bf
children 1142e46be550
comparison
equal deleted inserted replaced
73:2b369f7db7bf 74:b7449114ebb0
117 ~ns_map(); 117 ~ns_map();
118 void add(char *name, char *refer); 118 void add(char *name, char *refer);
119 }; 119 };
120 120
121 121
122 void ns_map::~ns_map() { 122 ns_map::~ns_map() {
123 for (string_map::iterator i=ns_host.begin(); i!=ns_host.end(); i++) { 123 for (string_map::iterator i=ns_host.begin(); i!=ns_host.end(); i++) {
124 char *x = (*i).first; 124 char *x = (*i).first;
125 char *y = (*i).second; 125 char *y = (*i).second;
126 free(x); 126 free(x);
127 free(y); 127 free(y);
633 633
634 //////////////////////////////////////////////// 634 ////////////////////////////////////////////////
635 // check the hosts from the body against the content dnsbl 635 // check the hosts from the body against the content dnsbl
636 // 636 //
637 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int ip); 637 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int ip);
638 bool check_hosts(mlfiPriv &priv) { 638 bool check_hosts(mlfiPriv &priv, bool random, int limit, char *&host, int ip) {
639 static buf[2000];
640 CONFIG &dc = *priv.pc; 639 CONFIG &dc = *priv.pc;
641 string_set &hosts = priv.memory->hosts; 640 string_set &hosts = priv.memory->get_hosts();
642 string_set &ignore = dc.get_content_host_ignore(); 641 string_set &ignore = dc.get_content_host_ignore();
643 642
644 int count = 0; 643 int count = 0;
645 int cnt = hosts.size(); // number of hosts we could look at 644 int cnt = hosts.size(); // number of hosts we could look at
646 int_set ips; 645 int_set ips;
679 } 678 }
680 if (ip) { 679 if (ip) {
681 int_set::iterator i = ips.find(ip); 680 int_set::iterator i = ips.find(ip);
682 if (i == ips.end()) { 681 if (i == ips.end()) {
683 ips.insert(ip); 682 ips.insert(ip);
684 if (check_single(priv, ip, dc.content_suffix)) { 683 if (check_single(priv, ip, dc.get_content_suffix())) {
685 return true; 684 return true;
686 } 685 }
687 } 686 }
688 } 687 }
689 } 688 }
712 } 711 }
713 if (ip) { 712 if (ip) {
714 int_set::iterator i = ips.find(ip); 713 int_set::iterator i = ips.find(ip);
715 if (i == ips.end()) { 714 if (i == ips.end()) {
716 ips.insert(ip); 715 ips.insert(ip);
717 if (check_single(priv, ip, dc.content_suffix)) { 716 if (check_single(priv, ip, dc.get_content_suffix())) {
718 string_map::iterator j = nameservers.ns_host.find(host); 717 string_map::iterator j = nameservers.ns_host.find(host);
719 if (j != nameservers.ns_host.end()) { 718 if (j != nameservers.ns_host.end()) {
720 char *refer = (*j).second; 719 char *refer = (*j).second;
721 char buf[1000]; 720 char buf[1000];
722 snprintf(buf, sizeof(buf), "%s with nameserver %s", refer, host); 721 snprintf(buf, sizeof(buf), "%s with nameserver %s", refer, host);
776 else if (fromvalue == token_white) { 775 else if (fromvalue == token_white) {
777 st = white; 776 st = white;
778 } 777 }
779 else { 778 else {
780 // check the dns based lists 779 // check the dns based lists
781 st = check_dnsbl(priv, con.get_dnsbl_list(), rejectlist); 780 st = (check_dnsbl(priv, con.get_dnsbl_list(), rejectlist)) ? black : oksofar;
782 } 781 }
783 if (st == reject) { 782 if (st == reject) {
784 // reject the recipient based on some dnsbl 783 // reject the recipient based on some dnsbl
785 char adr[sizeof "255.255.255.255"]; 784 char adr[sizeof "255.255.255.255"];
786 adr[0] = '\0'; 785 adr[0] = '\0';
831 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; 830 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE;
832 else { 831 else {
833 char *msg = NULL; 832 char *msg = NULL;
834 string_set alive; 833 string_set alive;
835 bool random = false; 834 bool random = false;
836 bool limit = 0; 835 int limit = 0;
837 for (context_map::iterator i=env_to.begin(); i!=env_to.end(); i++) { 836 for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) {
838 char *rcpt = (*i).first; 837 char *rcpt = (*i).first;
839 CONTEXT &con = *((*i).second); 838 CONTEXT &con = *((*i).second);
840 if (!con.acceptable_content(priv.memory, msg)) { 839 if (!con.acceptable_content(*priv.memory, msg)) {
841 // bad html tags or excessive hosts 840 // bad html tags or excessive hosts
842 smfi_delrcpt(ctx, rcpt); 841 smfi_delrcpt(ctx, rcpt);
843 } 842 }
844 else { 843 else {
845 alive.insert(rcpt); 844 alive.insert(rcpt);
925 newc->generation = generation++; 924 newc->generation = generation++;
926 pthread_mutex_unlock(&config_mutex); 925 pthread_mutex_unlock(&config_mutex);
927 char buf[200]; 926 char buf[200];
928 snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation); 927 snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation);
929 my_syslog(buf); 928 my_syslog(buf);
930 if (load_conf(*newc, "dnsbl.conf") { 929 if (load_conf(*newc, "dnsbl.conf")) {
931 newc->load_time = time(NULL); 930 newc->load_time = time(NULL);
932 return newc; 931 return newc;
933 } 932 }
934 delete newc; 933 delete newc;
935 return NULL; 934 return NULL;
950 if (!loader_run) break; 949 if (!loader_run) break;
951 CONFIG &dc = *config; 950 CONFIG &dc = *config;
952 time_t then = dc.load_time; 951 time_t then = dc.load_time;
953 struct stat st; 952 struct stat st;
954 bool reload = false; 953 bool reload = false;
955 for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { 954 for (string_set::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) {
956 char *fn = *i; 955 char *fn = *i;
957 if (stat(fn, &st)) reload = true; // file disappeared 956 if (stat(fn, &st)) reload = true; // file disappeared
958 else if (st.st_mtime > then) reload = true; // file modified 957 else if (st.st_mtime > then) reload = true; // file modified
959 if (reload) break; 958 if (reload) break;
960 } 959 }