Mercurial > dnsbl
comparison src/dnsbl.cpp @ 9:8c65411cd7ab
integration work on url scanner
author | carl |
---|---|
date | Thu, 22 Apr 2004 14:00:02 -0700 |
parents | dbe18921f741 |
children | 2c206836b4cc |
comparison
equal
deleted
inserted
replaced
8:dbe18921f741 | 9:8c65411cd7ab |
---|---|
7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its | 7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its |
8 suppliers. Inspired by the DCC by Rhyolite Software | 8 suppliers. Inspired by the DCC by Rhyolite Software |
9 | 9 |
10 -p port The port through which the MTA will connect to this milter. | 10 -p port The port through which the MTA will connect to this milter. |
11 -t sec The timeout value. | 11 -t sec The timeout value. |
12 -c Check the config, and print a copy to stderr. Don't start the | 12 -c Check the config, and print a copy to stdout. Don't start the |
13 milter or do anything with the socket. | 13 milter or do anything with the socket. |
14 | 14 |
15 */ | 15 */ |
16 | 16 |
17 | 17 |
18 // from sendmail sample | 18 // from sendmail sample |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 #include <sys/stat.h> | 20 #include <sys/stat.h> |
21 #include <errno.h> | 21 #include <errno.h> |
22 //#include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 #include <sysexits.h> | 22 #include <sysexits.h> |
26 #include <unistd.h> | 23 #include <unistd.h> |
27 | 24 |
28 // needed for socket io | 25 // needed for socket io |
29 #include <sys/ioctl.h> | 26 #include <sys/ioctl.h> |
114 dnsbllp_map dnsblls; | 111 dnsbllp_map dnsblls; |
115 from_map env_from; | 112 from_map env_from; |
116 string_map env_to_dnsbll; // map recipient to a named dnsbll | 113 string_map env_to_dnsbll; // map recipient to a named dnsbll |
117 string_map env_to_chkfrom; // map recipient to a named from map | 114 string_map env_to_chkfrom; // map recipient to a named from map |
118 char * content_suffix; // for sbl url body filtering | 115 char * content_suffix; // for sbl url body filtering |
119 char * content_message; | 116 char * content_message; // "" |
120 CONFIG(); | 117 CONFIG(); |
121 ~CONFIG(); | 118 ~CONFIG(); |
122 }; | 119 }; |
123 CONFIG::CONFIG() { | 120 CONFIG::CONFIG() { |
124 reference_count = 0; | 121 reference_count = 0; |
155 | 152 |
156 | 153 |
157 //////////////////////////////////////////////// | 154 //////////////////////////////////////////////// |
158 // helper to discard the strings held by a string_set | 155 // helper to discard the strings held by a string_set |
159 // | 156 // |
160 static void discard(string_set s); | 157 static void discard(string_set &s); |
161 static void discard(string_set s) { | 158 static void discard(string_set &s) { |
162 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { | 159 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { |
163 free(*i); | 160 free(*i); |
164 } | 161 } |
162 s.clear(); | |
165 } | 163 } |
166 | 164 |
167 | 165 |
168 //////////////////////////////////////////////// | 166 //////////////////////////////////////////////// |
169 // mail filter private data, held for us by sendmail | 167 // mail filter private data, held for us by sendmail |
432 CONFIG &dc = *priv.pc; | 430 CONFIG &dc = *priv.pc; |
433 if (!dc.content_suffix) return oksofar; | 431 if (!dc.content_suffix) return oksofar; |
434 int count = 0; | 432 int count = 0; |
435 for (string_set::iterator i=priv.urls.begin(); i!=priv.urls.end(); i++) { | 433 for (string_set::iterator i=priv.urls.begin(); i!=priv.urls.end(); i++) { |
436 count++; | 434 count++; |
437 if (count > 20) break; // silly to check too many urls | 435 if (count > 20) return oksofar; // silly to check too many urls |
438 url = *i; | 436 url = *i; |
439 char buf[200]; | 437 char buf[200]; |
440 snprintf(buf, sizeof(buf), "looking for url %s", url); | 438 snprintf(buf, sizeof(buf), "looking for url %s", url); |
441 my_syslog(buf); | 439 my_syslog(buf); |
442 ip = protected_dns_interface(url); | 440 ip = protected_dns_interface(url); |
443 if (ip) { | 441 if (ip) { |
444 status st = check_single(ip, dc.content_suffix); | 442 status st = check_single(ip, dc.content_suffix); |
445 if (st == reject) return st; | 443 if (st == reject) return st; |
446 } | 444 } |
447 } | 445 } |
446 return oksofar; | |
448 } | 447 } |
449 | 448 |
450 | 449 |
451 //////////////////////////////////////////////// | 450 //////////////////////////////////////////////// |
452 // start of sendmail milter interfaces | 451 // start of sendmail milter interfaces |
614 }; | 613 }; |
615 | 614 |
616 | 615 |
617 static void dumpit(char *name, string_map map); | 616 static void dumpit(char *name, string_map map); |
618 static void dumpit(char *name, string_map map) { | 617 static void dumpit(char *name, string_map map) { |
619 fprintf(stderr, "\n"); | 618 fprintf(stdout, "\n"); |
620 for (string_map::iterator i=map.begin(); i!=map.end(); i++) { | 619 for (string_map::iterator i=map.begin(); i!=map.end(); i++) { |
621 fprintf(stderr, "%s %s->%s\n", name, (*i).first, (*i).second); | 620 fprintf(stdout, "%s %s->%s\n", name, (*i).first, (*i).second); |
622 } | 621 } |
623 } | 622 } |
624 | 623 |
625 | 624 |
626 static void dumpit(from_map map); | 625 static void dumpit(from_map map); |
637 static void dumpit(CONFIG &dc); | 636 static void dumpit(CONFIG &dc); |
638 static void dumpit(CONFIG &dc) { | 637 static void dumpit(CONFIG &dc) { |
639 dumpit(dc.env_from); | 638 dumpit(dc.env_from); |
640 dumpit("envelope to (dnsbl list)", dc.env_to_dnsbll); | 639 dumpit("envelope to (dnsbl list)", dc.env_to_dnsbll); |
641 dumpit("envelope to (from map)", dc.env_to_chkfrom); | 640 dumpit("envelope to (from map)", dc.env_to_chkfrom); |
642 fprintf(stderr, "\ndnsbls\n"); | 641 fprintf(stdout, "\ndnsbls\n"); |
643 for (dnsblp_map::iterator i=dc.dnsbls.begin(); i!=dc.dnsbls.end(); i++) { | 642 for (dnsblp_map::iterator i=dc.dnsbls.begin(); i!=dc.dnsbls.end(); i++) { |
644 fprintf(stderr, "%s %s %s\n", (*i).first, (*i).second->suffix, (*i).second->message); | 643 fprintf(stdout, "%s %s %s\n", (*i).first, (*i).second->suffix, (*i).second->message); |
645 } | 644 } |
646 fprintf(stderr, "\ndnsbl_lists\n"); | 645 fprintf(stdout, "\ndnsbl_lists\n"); |
647 for (dnsbllp_map::iterator i=dc.dnsblls.begin(); i!=dc.dnsblls.end(); i++) { | 646 for (dnsbllp_map::iterator i=dc.dnsblls.begin(); i!=dc.dnsblls.end(); i++) { |
648 char *name = (*i).first; | 647 char *name = (*i).first; |
649 DNSBLL &dl = *((*i).second); | 648 DNSBLL &dl = *((*i).second); |
650 fprintf(stderr, "%s", name); | 649 fprintf(stdout, "%s", name); |
651 for (DNSBLL::iterator j=dl.begin(); j!=dl.end(); j++) { | 650 for (DNSBLL::iterator j=dl.begin(); j!=dl.end(); j++) { |
652 DNSBL &d = **j; | 651 DNSBL &d = **j; |
653 fprintf(stderr, " %s", d.suffix); | 652 fprintf(stdout, " %s", d.suffix); |
654 } | 653 } |
655 fprintf(stderr, "\n"); | 654 fprintf(stdout, "\n"); |
656 } | 655 } |
657 fprintf(stderr, "\nfiles\n"); | 656 if (dc.content_suffix) { |
657 fprintf(stdout, "\ncontent filtering enabled with %s %s\n", dc.content_suffix, dc.content_message); | |
658 } | |
659 fprintf(stdout, "\nfiles\n"); | |
658 for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { | 660 for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { |
659 char *f = *i; | 661 char *f = *i; |
660 fprintf(stderr, "config includes %s\n", f); | 662 fprintf(stdout, "config includes %s\n", f); |
661 } | 663 } |
662 } | 664 } |
663 | 665 |
664 | 666 |
665 //////////////////////////////////////////////// | 667 //////////////////////////////////////////////// |
964 | 966 |
965 | 967 |
966 static void usage(char *prog); | 968 static void usage(char *prog); |
967 static void usage(char *prog) | 969 static void usage(char *prog) |
968 { | 970 { |
969 fprintf(stderr, "Usage: %s -p socket-addr [-t timeout]\n", prog); | 971 fprintf(stderr, "Usage: %s [-c] -p socket-addr [-t timeout]\n", prog); |
970 fprintf(stderr, "where socket-addr is for the connection to sendmail and should be one of\n"); | 972 fprintf(stderr, "where socket-addr is for the connection to sendmail and should be one of\n"); |
971 fprintf(stderr, " inet:port@local-ip-address\n"); | 973 fprintf(stderr, " inet:port@local-ip-address\n"); |
972 fprintf(stderr, " local:local-domain-socket-file-name\n"); | 974 fprintf(stderr, " local:local-domain-socket-file-name\n"); |
975 fprintf(stderr, "-c will load and dump the config to stdout\n"); | |
973 } | 976 } |
974 | 977 |
975 | 978 |
976 int main(int argc, char**argv) | 979 int main(int argc, char**argv) |
977 { | 980 { |