Mercurial > dnsbl
comparison src/dnsbl.cpp @ 77:8487650c98ee
start coding on new config syntax
author | carl |
---|---|
date | Sat, 16 Jul 2005 14:11:07 -0700 |
parents | 81f1e400e8ab |
children | b6beb282fd83 |
comparison
equal
deleted
inserted
replaced
76:81f1e400e8ab | 77:8487650c98ee |
---|---|
249 pthread_mutex_unlock(&config_mutex); | 249 pthread_mutex_unlock(&config_mutex); |
250 reset(true); | 250 reset(true); |
251 } | 251 } |
252 | 252 |
253 void mlfiPriv::reset(bool final) { | 253 void mlfiPriv::reset(bool final) { |
254 if (debug_syslog) my_syslog(this, "mlfiPriv::reset"); | |
255 if (mailaddr) free(mailaddr); | 254 if (mailaddr) free(mailaddr); |
256 if (queueid) free(queueid); | 255 if (queueid) free(queueid); |
257 discard(env_to); | 256 discard(env_to); |
258 if (memory) delete memory; | 257 if (memory) delete memory; |
259 if (scanner) delete scanner; | 258 if (scanner) delete scanner; |
267 scanner = NULL; | 266 scanner = NULL; |
268 content_suffix = NULL; | 267 content_suffix = NULL; |
269 content_message = NULL; | 268 content_message = NULL; |
270 content_host_ignore = NULL; | 269 content_host_ignore = NULL; |
271 } | 270 } |
272 if (debug_syslog) my_syslog("mlfiPriv::reset exit"); | |
273 } | 271 } |
274 | 272 |
275 void mlfiPriv::get_fd() { | 273 void mlfiPriv::get_fd() { |
276 err = true; | 274 err = true; |
277 fd = NULL_SOCKET; | 275 fd = NULL_SOCKET; |
368 } | 366 } |
369 return rs; | 367 return rs; |
370 } | 368 } |
371 | 369 |
372 void mlfiPriv::need_content_filter(char *rcpt, CONTEXT &con) { | 370 void mlfiPriv::need_content_filter(char *rcpt, CONTEXT &con) { |
373 if (debug_syslog) my_syslog(this, "need_content_filter"); | |
374 register_string(env_to, rcpt, &con); | 371 register_string(env_to, rcpt, &con); |
375 if (!memory) { | 372 if (!memory) { |
376 // first recipient that needs content filtering sets all | 373 // first recipient that needs content filtering sets all |
377 // the content filtering parameters | 374 // the content filtering parameters |
378 memory = new recorder(this, con.get_html_tags(), con.get_content_tlds()); | 375 memory = new recorder(this, con.get_html_tags(), con.get_content_tlds()); |
379 scanner = new url_scanner(memory); | 376 scanner = new url_scanner(memory); |
380 content_suffix = con.get_content_suffix(); | 377 content_suffix = con.get_content_suffix(); |
381 content_message = con.get_content_message(); | 378 content_message = con.get_content_message(); |
382 content_host_ignore = &con.get_content_host_ignore(); | 379 content_host_ignore = &con.get_content_host_ignore(); |
383 } | 380 } |
384 if (debug_syslog) my_syslog(this, "need_content_filter exit"); | |
385 } | 381 } |
386 | 382 |
387 #define MLFIPRIV ((struct mlfiPriv *) smfi_getpriv(ctx)) | 383 #define MLFIPRIV ((struct mlfiPriv *) smfi_getpriv(ctx)) |
388 | 384 |
389 | 385 |
775 //////////////////////////////////////////////// | 771 //////////////////////////////////////////////// |
776 // start of sendmail milter interfaces | 772 // start of sendmail milter interfaces |
777 // | 773 // |
778 sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) | 774 sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr) |
779 { | 775 { |
780 if (debug_syslog) my_syslog("mlfi_connect"); | |
781 // allocate some private memory | 776 // allocate some private memory |
782 mlfiPriv *priv = new mlfiPriv; | 777 mlfiPriv *priv = new mlfiPriv; |
783 if (hostaddr->sa_family == AF_INET) { | 778 if (hostaddr->sa_family == AF_INET) { |
784 priv->ip = ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr; | 779 priv->ip = ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr; |
785 } | 780 } |
792 } | 787 } |
793 | 788 |
794 sfsistat mlfi_envfrom(SMFICTX *ctx, char **from) | 789 sfsistat mlfi_envfrom(SMFICTX *ctx, char **from) |
795 { | 790 { |
796 mlfiPriv &priv = *MLFIPRIV; | 791 mlfiPriv &priv = *MLFIPRIV; |
797 if (debug_syslog) my_syslog(&priv, "mlfi_envfrom"); | |
798 priv.mailaddr = to_lower_string(from[0]); | 792 priv.mailaddr = to_lower_string(from[0]); |
799 priv.authenticated = (smfi_getsymval(ctx, "{auth_authen}") != NULL); | 793 priv.authenticated = (smfi_getsymval(ctx, "{auth_authen}") != NULL); |
800 return SMFIS_CONTINUE; | 794 return SMFIS_CONTINUE; |
801 } | 795 } |
802 | 796 |
803 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt) | 797 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt) |
804 { | 798 { |
805 DNSBLP rejectlist = NULL; // list that caused the reject | 799 DNSBLP rejectlist = NULL; // list that caused the reject |
806 mlfiPriv &priv = *MLFIPRIV; | 800 mlfiPriv &priv = *MLFIPRIV; |
807 if (debug_syslog) my_syslog(&priv, "mlfi_envrcpt"); | |
808 CONFIG &dc = *priv.pc; | 801 CONFIG &dc = *priv.pc; |
809 if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, "i")); | 802 if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, "i")); |
810 char *rcptaddr = rcpt[0]; | 803 char *rcptaddr = rcpt[0]; |
811 char *loto = to_lower_string(rcptaddr); | 804 char *loto = to_lower_string(rcptaddr); |
812 if (debug_syslog) my_syslog(&priv, "finding context"); | |
813 CONTEXT &con = *(dc.find_context(loto)->find_context(priv.mailaddr)); | 805 CONTEXT &con = *(dc.find_context(loto)->find_context(priv.mailaddr)); |
814 if (debug_syslog) { | 806 if (debug_syslog) { |
815 char buf[maxlen]; | 807 char buf[maxlen]; |
816 char msg[maxlen]; | 808 char msg[maxlen]; |
817 snprintf(msg, sizeof(msg), "from <%s> to <%s> using context %s", priv.mailaddr, loto, con.get_full_name(buf,maxlen)); | 809 snprintf(msg, sizeof(msg), "from <%s> to <%s> using context %s", priv.mailaddr, loto, con.get_full_name(buf,maxlen)); |
818 my_syslog(&priv, msg); | 810 my_syslog(&priv, msg); |
819 } | 811 } |
820 if (debug_syslog) my_syslog(&priv, "finding from value"); | |
821 char *fromvalue = con.find_from(priv.mailaddr); | 812 char *fromvalue = con.find_from(priv.mailaddr); |
822 free(loto); | 813 free(loto); |
823 status st; | 814 status st; |
824 if (fromvalue == token_black) { | 815 if (fromvalue == token_black) { |
825 st = black; | 816 st = black; |
827 else if (fromvalue == token_white) { | 818 else if (fromvalue == token_white) { |
828 st = white; | 819 st = white; |
829 } | 820 } |
830 else { | 821 else { |
831 // check the dns based lists | 822 // check the dns based lists |
832 if (debug_syslog) my_syslog(&priv, "checking dns lists"); | |
833 st = (check_dnsbl(priv, con.get_dnsbl_list(), rejectlist)) ? black : oksofar; | 823 st = (check_dnsbl(priv, con.get_dnsbl_list(), rejectlist)) ? black : oksofar; |
834 } | 824 } |
835 if (st == reject) { | 825 if (st == reject) { |
836 // reject the recipient based on some dnsbl | 826 // reject the recipient based on some dnsbl |
837 char adr[sizeof "255.255.255.255"]; | 827 char adr[sizeof "255.255.255.255"]; |
847 smfi_setreply(ctx, "550", "5.7.1", "no such user"); | 837 smfi_setreply(ctx, "550", "5.7.1", "no such user"); |
848 return SMFIS_REJECT; | 838 return SMFIS_REJECT; |
849 } | 839 } |
850 else { | 840 else { |
851 // accept the recipient | 841 // accept the recipient |
852 if (debug_syslog) my_syslog(&priv, "checking content filtering"); | |
853 if (!con.get_content_filtering()) st = white; | 842 if (!con.get_content_filtering()) st = white; |
854 if (st == oksofar) { | 843 if (st == oksofar) { |
855 // but remember the non-whites | 844 // but remember the non-whites |
856 priv.need_content_filter(rcptaddr, con); | 845 priv.need_content_filter(rcptaddr, con); |
857 priv.only_whites = false; | 846 priv.only_whites = false; |
864 } | 853 } |
865 | 854 |
866 sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len) | 855 sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len) |
867 { | 856 { |
868 mlfiPriv &priv = *MLFIPRIV; | 857 mlfiPriv &priv = *MLFIPRIV; |
869 if (debug_syslog) my_syslog(&priv, "mlfi_body"); | |
870 if (priv.authenticated) return SMFIS_CONTINUE; | 858 if (priv.authenticated) return SMFIS_CONTINUE; |
871 if (priv.only_whites) return SMFIS_CONTINUE; | 859 if (priv.only_whites) return SMFIS_CONTINUE; |
872 priv.scanner->scan(data, len); | 860 priv.scanner->scan(data, len); |
873 return SMFIS_CONTINUE; | 861 return SMFIS_CONTINUE; |
874 } | 862 } |
875 | 863 |
876 sfsistat mlfi_eom(SMFICTX *ctx) | 864 sfsistat mlfi_eom(SMFICTX *ctx) |
877 { | 865 { |
878 if (debug_syslog) my_syslog("mlfi_eom"); | |
879 sfsistat rc; | 866 sfsistat rc; |
880 mlfiPriv &priv = *MLFIPRIV; | 867 mlfiPriv &priv = *MLFIPRIV; |
881 if (debug_syslog) my_syslog(&priv, "mlfi_eom"); | |
882 CONFIG &dc = *priv.pc; | 868 CONFIG &dc = *priv.pc; |
883 char *host = NULL; | 869 char *host = NULL; |
884 int ip; | 870 int ip; |
885 status st; | 871 status st; |
886 // process end of message | 872 // process end of message |
939 } | 925 } |
940 | 926 |
941 sfsistat mlfi_abort(SMFICTX *ctx) | 927 sfsistat mlfi_abort(SMFICTX *ctx) |
942 { | 928 { |
943 mlfiPriv &priv = *MLFIPRIV; | 929 mlfiPriv &priv = *MLFIPRIV; |
944 if (debug_syslog) my_syslog(&priv, "mlfi_abort"); | |
945 priv.reset(); | 930 priv.reset(); |
946 return SMFIS_CONTINUE; | 931 return SMFIS_CONTINUE; |
947 } | 932 } |
948 | 933 |
949 sfsistat mlfi_close(SMFICTX *ctx) | 934 sfsistat mlfi_close(SMFICTX *ctx) |
950 { | 935 { |
951 mlfiPriv *priv = MLFIPRIV; | 936 mlfiPriv *priv = MLFIPRIV; |
952 if (debug_syslog) my_syslog(priv, "mlfi_close"); | |
953 if (!priv) return SMFIS_CONTINUE; | 937 if (!priv) return SMFIS_CONTINUE; |
954 delete priv; | 938 delete priv; |
955 smfi_setpriv(ctx, NULL); | 939 smfi_setpriv(ctx, NULL); |
956 return SMFIS_CONTINUE; | 940 return SMFIS_CONTINUE; |
957 } | 941 } |