maxrcpt patch for qmail-smtpd To: djb-qmail@xxxxxxxxxxxxxxxxxxxx Subject: maxrcpt patch for qmail-smtpd From: Michael Samuel Date: Wed, 12 Nov 1997 15:18:38 +1100 (EST) Mailing-list: contact djb-qmail-help@xxxxxxxxxxxxxxxxxxxx; run by ezmlm -----BEGIN PGP SIGNED MESSAGE----- Here is a patch for qmail-smtpd to read a control file to limit the number of rcpt to commands. In the patch I have a thank-you to Sam, this is referring to mrsam@xxxxxxxxxxxxx who gave me the ideas on how to start off. Anyway, it is a "Do what you like with it, but don't blame me" license, but if it doesn't work, tell me what went wrong if you like and I will try to figure it out. Michael Samuel, Surf-Net City - Internet Cafe and Internet Service Providers Phone: +61 3 9593-9977 E-Mail: michael@xxxxxxxxxxxxxxxxxx -----BEGIN PGP SIGNATURE----- Version: 2.6.3ia Charset: noconv iQCVAwUBNGkuIUqgdYLWa7qBAQHEiwP+JqNDMZDLwLY7CUdmkuY0OUHwSaFCJJiS T853fUkupG2kQz6WU8m0RXWd4Rhr+BT8+hqjDDPQYfWzK6QcEf563D0Mp7nA0ZuQ s+XHKflwb8PAZBp+lpzkMsgDg/B8mlw9dnJ4pGeP1keWR/5cgBFM78XsthW2rLXd EIXiZJ7AEhc= =5RMp -----END PGP SIGNATURE----- Here is a patch I rigged up limit the number of RCPT TO: commands per E-Mail messages. It reads the file control/maxrcpt relative to your qmail directory stucture (usually /var/qmail/control/maxrcpt). In that file you should have a integer, which represents the maximum number of recipients per E-Mail Messages. Apparently one of the SMTP rfcs recommends a minimum of 100 recipients per message be allowed. Just something to keep in mind anyway. If /var/qmail/control/maxrcpt doesn't exist, it does not impose a limit and skips the rcpt part of the code, so unless I missed something in the source, you could even have more than MAXINT. I would like to thank Sam from the qmail list for giving me a good start to this patch, and anyone else who offered me suggestions from the qmail list. (When I refer to qmail list, I'm referring to djb-qmail@xxxxxxxxxxxxxxxxxxxx) To apply the patch, enter the qmail source directory and type: patch -p1 < ~/qmail-1.01-maxrcpt.patch Assuming that the patch is in your home directory. diff -C 4 -c qmail-1.01/qmail-smtpd.c qmail-1.01-maxrcpt/qmail-smtpd.c *** qmail-1.01/qmail-smtpd.c Tue Apr 15 15:05:23 1997 --- qmail-1.01-maxrcpt/qmail-smtpd.c Tue Nov 11 22:44:19 1997 *************** *** 21,28 **** --- 21,30 ---- #include "exit.h" #define MAXHOPS 100 int timeout = 1200; + int rcptcounter = 0; + int maxrcpt = -1; char ssoutbuf[512]; substdio ssout = SUBSTDIO_FDBUF(write,1,ssoutbuf,sizeof(ssoutbuf)); *************** *** 277,293 **** --- 279,298 ---- seenmail = 0; out("250 flushed\r\n"); } void smtp_mail(arg) char *arg; { if (seenmail) { err_seenmail(); return; } + rcptcounter = 0; if (!arg) { err_syntax(); return; } if (!addrparse(arg)) { err_syntax(); return; } bmfcheck(); seenmail = 1; out("250 ok\r\n"); if (!stralloc_copys(&rcptto,"")) outofmem(); if (!stralloc_copys(&mailfrom,addr.s)) outofmem(); if (!stralloc_0(&mailfrom)) outofmem(); } void smtp_rcpt(arg) char *arg; { + rcptcounter++; if (!seenmail) { err_wantmail(); return; } + if (checkrcptcount() == 1) {err_syntax(); return; } if (!arg) { err_syntax(); return; } if (!addrparse(arg)) { err_syntax(); return; } if (flagbarf) { err_bmf(); return; } if (relayclient) *************** *** 401,408 **** --- 406,414 ---- switch(control_rldef(&liphost,"control/localiphost",1,(char *) 0)) { case -1: die(); case 1: liphostok = 1; } if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die(); if (timeout <= 0) timeout = 1; + if (control_readint(&maxrcpt,"control/maxrcpt") == -1) die(); switch(control_readfile(&rcpthosts,"control/rcpthosts",0)) { case -1: die(); case 1: *************** *** 446,449 **** --- 452,462 ---- cmd.s[cmd.len++] = 0; doit(cmd.s); } } + + int checkrcptcount() { + if (maxrcpt == -1) {return 0;} + else if (rcptcounter > maxrcpt) {return 1;} + else {return 0;} + } +