comparison src/dnsbl.cpp @ 167:9b129ed78d7d stable-6-0-6

actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
author carl
date Mon, 27 Aug 2007 20:49:19 -0700
parents bf828f785407
children 6bac960af6b4
comparison
equal deleted inserted replaced
166:7161d8451fcf 167:9b129ed78d7d
249 mailaddr = NULL; 249 mailaddr = NULL;
250 queueid = NULL; 250 queueid = NULL;
251 authenticated = NULL; 251 authenticated = NULL;
252 have_whites = false; 252 have_whites = false;
253 only_whites = true; 253 only_whites = true;
254 want_spamassassin = false;
254 memory = NULL; 255 memory = NULL;
255 scanner = NULL; 256 scanner = NULL;
256 assassin = NULL; 257 assassin = NULL;
257 content_suffix = NULL; 258 content_suffix = NULL;
258 content_message = NULL; 259 content_message = NULL;
284 mailaddr = NULL; 285 mailaddr = NULL;
285 queueid = NULL; 286 queueid = NULL;
286 authenticated = NULL; 287 authenticated = NULL;
287 have_whites = false; 288 have_whites = false;
288 only_whites = true; 289 only_whites = true;
290 want_spamassassin = false;
289 memory = NULL; 291 memory = NULL;
290 scanner = NULL; 292 scanner = NULL;
291 assassin = NULL; 293 assassin = NULL;
292 content_suffix = NULL; 294 content_suffix = NULL;
293 content_message = NULL; 295 content_message = NULL;
962 mlfiPriv &priv = *MLFIPRIV; 964 mlfiPriv &priv = *MLFIPRIV;
963 priv.mailaddr = to_lower_string(from[0]); 965 priv.mailaddr = to_lower_string(from[0]);
964 priv.queueid = strdup(smfi_getsymval(ctx, "i")); 966 priv.queueid = strdup(smfi_getsymval(ctx, "i"));
965 priv.authenticated = smfi_getsymval(ctx, "{auth_authen}"); 967 priv.authenticated = smfi_getsymval(ctx, "{auth_authen}");
966 if (priv.authenticated) priv.authenticated = strdup(priv.authenticated); 968 if (priv.authenticated) priv.authenticated = strdup(priv.authenticated);
967 priv.assassin = new SpamAssassin; 969 if (spamc != spamc_empty) {
968 priv.assassin->mlfi_connect(&priv, priv.ip); 970 priv.assassin = new SpamAssassin(&priv, priv.ip, priv.helo, priv.mailaddr, priv.queueid);
969 priv.assassin->mlfi_helo(priv.helo); 971 }
970 priv.assassin->mlfi_envfrom(priv.mailaddr, priv.queueid);
971 return SMFIS_CONTINUE; 972 return SMFIS_CONTINUE;
972 } 973 }
973 974
974 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt) 975 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt)
975 { 976 {
976 DNSBLP rejectlist = NULL; // list that caused the reject 977 DNSBLP rejectlist = NULL; // list that caused the reject
977 mlfiPriv &priv = *MLFIPRIV; 978 mlfiPriv &priv = *MLFIPRIV;
978 CONFIG &dc = *priv.pc; 979 CONFIG &dc = *priv.pc;
979 char *rcptaddr = rcpt[0]; 980 char *rcptaddr = rcpt[0];
980 char *loto = to_lower_string(rcptaddr); 981 char *loto = to_lower_string(rcptaddr);
981 priv.assassin->mlfi_envrcpt(ctx, loto); 982 if (priv.assassin) priv.assassin->mlfi_envrcpt(ctx, loto);
982 // priv.mailaddr sending original message to loto 983 // priv.mailaddr sending original message to loto
983 CONTEXT &con = *(dc.find_context(loto)->find_context(priv.mailaddr)); 984 CONTEXT &con = *(dc.find_context(loto)->find_context(priv.mailaddr));
984 VERIFYP ver = con.find_verify(loto); 985 VERIFYP ver = con.find_verify(loto);
985 char *fromvalue = con.find_from(priv.mailaddr); 986 char *fromvalue = con.find_from(priv.mailaddr);
986 // loto sending a reply back to priv.mailaddr 987 // loto sending a reply back to priv.mailaddr
1068 if (!con.get_content_filtering()) st = white; 1069 if (!con.get_content_filtering()) st = white;
1069 if (st == oksofar) { 1070 if (st == oksofar) {
1070 // but remember the non-whites 1071 // but remember the non-whites
1071 priv.need_content_filter(rcptaddr, con); 1072 priv.need_content_filter(rcptaddr, con);
1072 priv.only_whites = false; 1073 priv.only_whites = false;
1074 priv.want_spamassassin |= (priv.assassin) && // have spam assassin available and
1075 (con.get_spamassassin_limit() != 0); // want to use it with a non-zero score
1073 } 1076 }
1074 if (st == white) { 1077 if (st == white) {
1075 priv.have_whites = true; 1078 priv.have_whites = true;
1076 } 1079 }
1077 return SMFIS_CONTINUE; 1080 return SMFIS_CONTINUE;
1078 } 1081 }
1079 1082
1080 sfsistat mlfi_header(SMFICTX* ctx, char* headerf, char* headerv) 1083 sfsistat mlfi_header(SMFICTX* ctx, char* headerf, char* headerv)
1081 { 1084 {
1082 mlfiPriv &priv = *MLFIPRIV; 1085 mlfiPriv &priv = *MLFIPRIV;
1083 if (priv.authenticated) return SMFIS_CONTINUE; 1086 if (priv.authenticated) return SMFIS_CONTINUE;
1084 if (priv.only_whites) return SMFIS_CONTINUE; 1087 if (priv.only_whites) return SMFIS_CONTINUE;
1085 priv.assassin->mlfi_header(headerf, headerv); 1088 if (priv.want_spamassassin) priv.assassin->mlfi_header(headerf, headerv);
1086 return SMFIS_CONTINUE; 1089 return SMFIS_CONTINUE;
1087 } 1090 }
1088 1091
1089 sfsistat mlfi_eoh(SMFICTX* ctx) 1092 sfsistat mlfi_eoh(SMFICTX* ctx)
1090 { 1093 {
1091 mlfiPriv &priv = *MLFIPRIV; 1094 mlfiPriv &priv = *MLFIPRIV;
1092 if (priv.authenticated) return SMFIS_CONTINUE; 1095 if (priv.authenticated) return SMFIS_CONTINUE;
1093 if (priv.only_whites) return SMFIS_CONTINUE; 1096 if (priv.only_whites) return SMFIS_CONTINUE;
1094 priv.assassin->mlfi_eoh(); 1097 if (priv.want_spamassassin) priv.assassin->mlfi_eoh();
1095 return SMFIS_CONTINUE; 1098 return SMFIS_CONTINUE;
1096 } 1099 }
1097 1100
1098 sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len) 1101 sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len)
1099 { 1102 {
1100 mlfiPriv &priv = *MLFIPRIV; 1103 mlfiPriv &priv = *MLFIPRIV;
1101 if (priv.authenticated) return SMFIS_CONTINUE; 1104 if (priv.authenticated) return SMFIS_CONTINUE;
1102 if (priv.only_whites) return SMFIS_CONTINUE; 1105 if (priv.only_whites) return SMFIS_CONTINUE;
1103 priv.assassin->mlfi_body(data, len); 1106 if (priv.want_spamassassin) priv.assassin->mlfi_body(data, len);
1104 priv.scanner->scan(data, len); 1107 priv.scanner->scan(data, len);
1105 return SMFIS_CONTINUE; 1108 return SMFIS_CONTINUE;
1106 } 1109 }
1107 1110
1108 sfsistat mlfi_eom(SMFICTX *ctx) 1111 sfsistat mlfi_eom(SMFICTX *ctx)
1114 int ip; 1117 int ip;
1115 status st; 1118 status st;
1116 // process end of message 1119 // process end of message
1117 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; 1120 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE;
1118 else { 1121 else {
1119 int score = priv.assassin->mlfi_eom(); 1122 int score = (priv.want_spamassassin) ? priv.assassin->mlfi_eom() : 0;
1120 // assert env_to not empty 1123 // assert env_to not empty
1121 char buf[maxlen]; 1124 char buf[maxlen];
1122 char *msg = NULL; 1125 string msg;
1123 string_set alive; 1126 string_set alive;
1124 bool random = false; 1127 bool random = false;
1125 int limit = 0; 1128 int limit = 0;
1126 for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) { 1129 for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) {
1127 char *rcpt = (*i).first; 1130 char *rcpt = (*i).first;
1149 char adr[sizeof "255.255.255.255"]; 1152 char adr[sizeof "255.255.255.255"];
1150 adr[0] = '\0'; 1153 adr[0] = '\0';
1151 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr)); 1154 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
1152 snprintf(buf, sizeof(buf), fmt, host, adr); 1155 snprintf(buf, sizeof(buf), fmt, host, adr);
1153 } 1156 }
1154 msg = buf; 1157 msg = string(buf);
1155 rejecting = true; 1158 rejecting = true;
1156 } 1159 }
1157 } 1160 }
1158 if (!rejecting) { 1161 if (!rejecting) {
1159 rc = SMFIS_CONTINUE; 1162 rc = SMFIS_CONTINUE;
1160 } 1163 }
1161 else if (!priv.have_whites) { 1164 else if (!priv.have_whites) {
1162 // can reject the entire message 1165 // can reject the entire message
1163 smfi_setreply(ctx, "550", "5.7.1", msg); 1166 snprintf(buf, sizeof(buf), "%s", msg.c_str());
1167 smfi_setreply(ctx, "550", "5.7.1", buf);
1164 rc = SMFIS_REJECT; 1168 rc = SMFIS_REJECT;
1165 } 1169 }
1166 else { 1170 else {
1167 // need to accept it but remove the recipients that don't want it 1171 // need to accept it but remove the recipients that don't want it
1168 for (string_set::iterator i=alive.begin(); i!=alive.end(); i++) { 1172 for (string_set::iterator i=alive.begin(); i!=alive.end(); i++) {