/* * badrcptto plugin for qmail-spp * * Reject mails if recipient address is listed in * CONTROL/badrcptto. addresses can be a lead part * of it, ignore case, and compared with its length. * * compile: gcc badrcptto.c -o badrcptto * license: public domain * * Hiroshi Tsukamoto [ h1r.org ] * */ #include #include #include #define BRTFILE "/var/qmail/control/badrcptto" #define logmsg(s) fputs("badrcptto: " s, stderr) #define BUFSIZE 1024 #define MIN_LEN 3 static char *id = "$Id: badrcptto.c,v 1.7 2006/05/10 09:28:29 hirobo Exp $"; int checkbmf(char *addr) { FILE *fp; static char buff[BUFSIZE]; size_t rcptlen, bmflen; int retval; retval = 1; if ((fp = fopen(BRTFILE, "r")) == NULL) { logmsg("file badrcptto not found\n"); return -1; } if ((rcptlen = strlen(addr)) >= BUFSIZE) { logmsg("too long RCPTTO\n"); return -1; } if (rcptlen == 0) { logmsg("no RCPTTO\n"); return -1; } while(fgets(buff, BUFSIZE - 1, fp)) { /* skip blank line and too short badrcptto strings */ if ((bmflen = strlen(buff) - 1) < MIN_LEN) continue; /* skip comment */ if (buff[0] == '#') continue; if (bmflen > rcptlen) continue; if (!strncasecmp(addr, buff, bmflen)) { retval = 0; break; } } fclose(fp); return retval; } int main (int argc, char **argv) { char *rcpt; if (getenv("RELAYCLIENT")) exit(0); if (!(rcpt = getenv("SMTPRCPTTO"))) { logmsg("Error - can not read SMTPRCPTTO\n"); exit(0); } if (!checkbmf(rcpt)) { puts("E550 Requested action not taken: mailbox unavailable (#5.1.1)"); fprintf(stderr, "badrcptto: [%s] RCPT=%s SENDER=%s\n", getenv("TCPREMOTEIP"), rcpt, getenv("SMTPMAILFROM")); } exit(0); }