--- ../qmail-1.03/qmail-smtpd.c 1998-06-15 13:53:16.000000000 +0300 +++ qmail-smtpd.c 2004-03-22 10:46:40.000000000 +0200 @@ -23,6 +23,10 @@ #include "timeoutread.h" #include "timeoutwrite.h" #include "commands.h" +#include +#ifdef RELAYD +#include "relay.h" +#endif #define MAXHOPS 100 unsigned int databytes = 0; @@ -58,6 +62,9 @@ void err_noop() { out("250 ok\r\n"); } void err_vrfy() { out("252 send some mail, i'll try my best\r\n"); } void err_qqt() { out("451 qqt failure (#4.3.0)\r\n"); } +#ifdef RELAYD +void err_throttle() { out("453 Anti-SPAM policy: too many emails from this IP address. please try again later or contact \r\n"); } +#endif stralloc greeting = {0}; @@ -73,6 +80,9 @@ } void smtp_quit() { +#ifdef RELAYD + relayd_close(); +#endif smtp_greet("221 "); out("\r\n"); flush(); _exit(0); } @@ -222,6 +232,33 @@ stralloc mailfrom = {0}; stralloc rcptto = {0}; +#ifdef RELAYD +#define SPAMLOG "/tmp/spam.log" +int chkthrottle(void) { + int result; + + if (remoteip == NULL || mailfrom.s == NULL) return 0; + result = relayd_check_ip(remoteip); + + if (result < 0) return 0; + else if (result == 0) { + FILE *fd; + time_t now; + + fd = fopen(SPAMLOG, "a"); + if (fd != NULL) { + time(&now); + fprintf(fd, "Spam: IP '%s' mailfrom '%s' rcpto '%s' %s", remoteip, mailfrom.s, addr.s, ctime(&now)); + fclose(fd); + } + return 1; + } + + relayd_ack("", remoteip); + return 0; +} +#endif /* RELAYD */ + void smtp_helo(arg) char *arg; { smtp_greet("250 "); out("\r\n"); @@ -258,6 +295,9 @@ } else if (!addrallowed()) { err_nogateway(); return; } +#ifdef RELAYD + if (chkthrottle()) { err_throttle(); return; } +#endif if (!stralloc_cats(&rcptto,"T")) die_nomem(); if (!stralloc_cats(&rcptto,addr.s)) die_nomem(); if (!stralloc_0(&rcptto)) die_nomem(); @@ -386,7 +426,13 @@ qmail_put(&qqt,rcptto.s,rcptto.len); qqx = qmail_close(&qqt); - if (!*qqx) { acceptmessage(qp); return; } + if (!*qqx) { + acceptmessage(qp); +#ifdef RELAYD + relayd_commit(); +#endif + return; + } if (hops) { out("554 too many hops, this message is looping (#5.4.6)\r\n"); return; } if (databytes) if (!bytestooverflow) { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n"); return; } if (*qqx == 'D') out("554 "); else out("451 "); @@ -414,6 +460,9 @@ if (chdir(auto_qmail) == -1) die_control(); setup(); if (ipme_init() != 1) die_ipme(); +#ifdef RELAYD + relayd_open(); +#endif smtp_greet("220 "); out(" ESMTP\r\n"); if (commands(&ssin,&smtpcommands) == 0) die_read();