[c5c522c] | 1 | diff -Nur qmail-1.03/error.h qmail-1.03.tap/error.h |
---|
| 2 | --- qmail-1.03/error.h 1998-06-15 05:53:16.000000000 -0500 |
---|
| 3 | +++ qmail-1.03.tap/error.h 2005-06-06 13:02:38.000000000 -0500 |
---|
| 4 | @@ -1,5 +1,6 @@ |
---|
| 5 | #ifndef ERROR_H |
---|
| 6 | #define ERROR_H |
---|
| 7 | +#include <errno.h> |
---|
| 8 | |
---|
| 9 | extern int errno; |
---|
| 10 | |
---|
| 11 | diff -Nur qmail-1.03/Makefile qmail-1.03.tap/Makefile |
---|
| 12 | --- qmail-1.03/Makefile 1998-06-15 05:53:16.000000000 -0500 |
---|
| 13 | +++ qmail-1.03.tap/Makefile 2005-02-15 12:50:37.000000000 -0600 |
---|
| 14 | @@ -1419,13 +1419,14 @@ |
---|
| 15 | nroff -man qmail-qstat.8 > qmail-qstat.0 |
---|
| 16 | |
---|
| 17 | qmail-queue: \ |
---|
| 18 | -load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o \ |
---|
| 19 | -datetime.a seek.a ndelay.a open.a sig.a alloc.a substdio.a error.a \ |
---|
| 20 | -str.a fs.a auto_qmail.o auto_split.o auto_uids.o |
---|
| 21 | +load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o qregex.o \ |
---|
| 22 | +datetime.a seek.a case.a ndelay.a open.a sig.a getln.a stralloc.a alloc.a \ |
---|
| 23 | +substdio.a error.a control.o constmap.o str.a fs.a auto_qmail.o \ |
---|
| 24 | +auto_split.o auto_uids.o |
---|
| 25 | ./load qmail-queue triggerpull.o fmtqfn.o now.o \ |
---|
| 26 | - date822fmt.o datetime.a seek.a ndelay.a open.a sig.a \ |
---|
| 27 | - alloc.a substdio.a error.a str.a fs.a auto_qmail.o \ |
---|
| 28 | - auto_split.o auto_uids.o |
---|
| 29 | + date822fmt.o qregex.o control.o constmap.o datetime.a case.a seek.a \ |
---|
| 30 | + ndelay.a open.a sig.a getln.a stralloc.a alloc.a substdio.a error.a \ |
---|
| 31 | + str.a fs.a auto_qmail.o auto_split.o auto_uids.o |
---|
| 32 | |
---|
| 33 | qmail-queue.0: \ |
---|
| 34 | qmail-queue.8 |
---|
| 35 | @@ -1681,6 +1682,10 @@ |
---|
| 36 | constmap.h stralloc.h gen_alloc.h rcpthosts.h |
---|
| 37 | ./compile rcpthosts.c |
---|
| 38 | |
---|
| 39 | +qregex.o: \ |
---|
| 40 | +compile qregex.c qregex.h |
---|
| 41 | + ./compile qregex.c |
---|
| 42 | + |
---|
| 43 | readsubdir.o: \ |
---|
| 44 | compile readsubdir.c readsubdir.h direntry.h fmt.h scan.h str.h \ |
---|
| 45 | auto_split.h |
---|
| 46 | diff -Nur qmail-1.03/qmail-control.9 qmail-1.03.tap/qmail-control.9 |
---|
| 47 | --- qmail-1.03/qmail-control.9 1998-06-15 05:53:16.000000000 -0500 |
---|
| 48 | +++ qmail-1.03.tap/qmail-control.9 2005-06-06 13:10:03.000000000 -0500 |
---|
| 49 | @@ -63,6 +63,7 @@ |
---|
| 50 | .I rcpthosts \fR(none) \fRqmail-smtpd |
---|
| 51 | .I smtpgreeting \fIme \fRqmail-smtpd |
---|
| 52 | .I smtproutes \fR(none) \fRqmail-remote |
---|
| 53 | +.I taps \fR(none) \fRqmail-queue |
---|
| 54 | .I timeoutconnect \fR60 \fRqmail-remote |
---|
| 55 | .I timeoutremote \fR1200 \fRqmail-remote |
---|
| 56 | .I timeoutsmtpd \fR1200 \fRqmail-smtpd |
---|
| 57 | @@ -72,6 +73,7 @@ |
---|
| 58 | .SH "SEE ALSO" |
---|
| 59 | qmail-inject(8), |
---|
| 60 | qmail-qmqpc(8), |
---|
| 61 | +qmail-queue(8), |
---|
| 62 | qmail-remote(8), |
---|
| 63 | qmail-send(8), |
---|
| 64 | qmail-showctl(8), |
---|
| 65 | diff -Nur qmail-1.03/qmail-queue.8 qmail-1.03.tap/qmail-queue.8 |
---|
| 66 | --- qmail-1.03/qmail-queue.8 1998-06-15 05:53:16.000000000 -0500 |
---|
| 67 | +++ qmail-1.03.tap/qmail-queue.8 2005-06-06 13:11:01.000000000 -0500 |
---|
| 68 | @@ -40,6 +40,12 @@ |
---|
| 69 | However, the recipients probably expect to see a proper header, |
---|
| 70 | as described in |
---|
| 71 | .BR qmail-header(5) . |
---|
| 72 | +.SH "CONTROL FILES" |
---|
| 73 | +.TP 5 |
---|
| 74 | +.I taps |
---|
| 75 | +Should contain regex syntax of email addresses to tap and |
---|
| 76 | +the associated email address to send the copy to. The two |
---|
| 77 | +fields should be separated by a colon. |
---|
| 78 | .SH "FILESYSTEM RESTRICTIONS" |
---|
| 79 | .B qmail-queue |
---|
| 80 | imposes two constraints on the queue structure: |
---|
| 81 | diff -Nur qmail-1.03/qmail-queue.c qmail-1.03.tap/qmail-queue.c |
---|
| 82 | --- qmail-1.03/qmail-queue.c 1998-06-15 05:53:16.000000000 -0500 |
---|
| 83 | +++ qmail-1.03.tap/qmail-queue.c 2005-05-17 14:59:00.000000000 -0500 |
---|
| 84 | @@ -16,6 +16,8 @@ |
---|
| 85 | #include "auto_uids.h" |
---|
| 86 | #include "date822fmt.h" |
---|
| 87 | #include "fmtqfn.h" |
---|
| 88 | +#include "stralloc.h" |
---|
| 89 | +#include "constmap.h" |
---|
| 90 | |
---|
| 91 | #define DEATH 86400 /* 24 hours; _must_ be below q-s's OSSIFIED (36 hours) */ |
---|
| 92 | #define ADDR 1003 |
---|
| 93 | @@ -25,6 +27,14 @@ |
---|
| 94 | char outbuf[256]; |
---|
| 95 | struct substdio ssout; |
---|
| 96 | |
---|
| 97 | +int tapok = 0; |
---|
| 98 | +stralloc tap = {0}; |
---|
| 99 | +struct constmap maptap; |
---|
| 100 | +stralloc chkaddr = {0}; |
---|
| 101 | +int tapped; |
---|
| 102 | +stralloc tapaddr = {0}; |
---|
| 103 | +stralloc controlfile = {0}; |
---|
| 104 | + |
---|
| 105 | datetime_sec starttime; |
---|
| 106 | struct datetime dt; |
---|
| 107 | unsigned long mypid; |
---|
| 108 | @@ -175,6 +185,13 @@ |
---|
| 109 | |
---|
| 110 | alarm(DEATH); |
---|
| 111 | |
---|
| 112 | + stralloc_copys( &controlfile, auto_qmail); |
---|
| 113 | + stralloc_cats( &controlfile, "/control/taps"); |
---|
| 114 | + stralloc_0( &controlfile); |
---|
| 115 | + tapok = control_readfile(&tap,controlfile.s,0); |
---|
| 116 | + if (tapok == -1) die(65); |
---|
| 117 | + if (!constmap_init(&maptap,tap.s,tap.len,0)) die(65); |
---|
| 118 | + |
---|
| 119 | pidopen(); |
---|
| 120 | if (fstat(messfd,&pidst) == -1) die(63); |
---|
| 121 | |
---|
| 122 | @@ -219,14 +236,28 @@ |
---|
| 123 | if (substdio_get(&ssin,&ch,1) < 1) die_read(); |
---|
| 124 | if (ch != 'F') die(91); |
---|
| 125 | if (substdio_bput(&ssout,&ch,1) == -1) die_write(); |
---|
| 126 | + stralloc_0(&chkaddr); |
---|
| 127 | for (len = 0;len < ADDR;++len) |
---|
| 128 | { |
---|
| 129 | + if ( len == 1 ) stralloc_copyb(&chkaddr, &ch,1); |
---|
| 130 | + else if ( len > 1 ) stralloc_catb(&chkaddr, &ch,1); |
---|
| 131 | if (substdio_get(&ssin,&ch,1) < 1) die_read(); |
---|
| 132 | if (substdio_put(&ssout,&ch,1) == -1) die_write(); |
---|
| 133 | if (!ch) break; |
---|
| 134 | } |
---|
| 135 | if (len >= ADDR) die(11); |
---|
| 136 | |
---|
| 137 | + /* check the from address */ |
---|
| 138 | + stralloc_0(&chkaddr); |
---|
| 139 | + if (tapped == 0 && tapcheck()==1 ) { |
---|
| 140 | + tapped = 1; |
---|
| 141 | + if ( tapaddr.len > 0 ) { |
---|
| 142 | + if (substdio_bput(&ssout,"T",1) == -1) die_write(); |
---|
| 143 | + if (substdio_bput(&ssout,tapaddr.s,tapaddr.len) == -1) die_write(); |
---|
| 144 | + if (substdio_bput(&ssout,"",1) == -1) die_write(); |
---|
| 145 | + } |
---|
| 146 | + } |
---|
| 147 | + |
---|
| 148 | if (substdio_bput(&ssout,QUEUE_EXTRA,QUEUE_EXTRALEN) == -1) die_write(); |
---|
| 149 | |
---|
| 150 | for (;;) |
---|
| 151 | @@ -237,10 +268,24 @@ |
---|
| 152 | if (substdio_bput(&ssout,&ch,1) == -1) die_write(); |
---|
| 153 | for (len = 0;len < ADDR;++len) |
---|
| 154 | { |
---|
| 155 | + if ( len == 1 ) stralloc_copyb(&chkaddr, &ch,1); |
---|
| 156 | + else if ( len > 1 ) stralloc_catb(&chkaddr, &ch,1); |
---|
| 157 | if (substdio_get(&ssin,&ch,1) < 1) die_read(); |
---|
| 158 | if (substdio_bput(&ssout,&ch,1) == -1) die_write(); |
---|
| 159 | if (!ch) break; |
---|
| 160 | } |
---|
| 161 | + |
---|
| 162 | + /* check the to address */ |
---|
| 163 | + stralloc_0(&chkaddr); |
---|
| 164 | + if (tapped == 0 && tapcheck()==1 ) { |
---|
| 165 | + tapped = 1; |
---|
| 166 | + if ( tapaddr.len > 0 ) { |
---|
| 167 | + if (substdio_bput(&ssout,"T",1) == -1) die_write(); |
---|
| 168 | + if (substdio_bput(&ssout,tapaddr.s,tapaddr.len) == -1) die_write(); |
---|
| 169 | + if (substdio_bput(&ssout,"",1) == -1) die_write(); |
---|
| 170 | + } |
---|
| 171 | + } |
---|
| 172 | + |
---|
| 173 | if (len >= ADDR) die(11); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | @@ -252,3 +297,42 @@ |
---|
| 177 | triggerpull(); |
---|
| 178 | die(0); |
---|
| 179 | } |
---|
| 180 | + |
---|
| 181 | +int tapcheck() |
---|
| 182 | +{ |
---|
| 183 | + int i = 0; |
---|
| 184 | + int j = 0; |
---|
| 185 | + int x = 0; |
---|
| 186 | + int negate = 0; |
---|
| 187 | + stralloc curregex = {0}; |
---|
| 188 | + char tmpbuf[200]; |
---|
| 189 | + |
---|
| 190 | + while (j < tap.len) { |
---|
| 191 | + i = j; |
---|
| 192 | + while ((tap.s[i] != ':') && (i < tap.len)) i++; |
---|
| 193 | + if (tap.s[j] == '!') { |
---|
| 194 | + negate = 1; |
---|
| 195 | + j++; |
---|
| 196 | + } |
---|
| 197 | + stralloc_copys(&tapaddr, &tap.s[i+1]); |
---|
| 198 | + |
---|
| 199 | + stralloc_copyb(&curregex,tap.s + j,(i - j)); |
---|
| 200 | + stralloc_0(&curregex); |
---|
| 201 | + x = matchregex(chkaddr.s, curregex.s, tmpbuf); |
---|
| 202 | + |
---|
| 203 | + while ((tap.s[i] != '\0') && (i < tap.len)) i++; |
---|
| 204 | + |
---|
| 205 | + if ((negate) && (x == 0)) { |
---|
| 206 | + return 1; |
---|
| 207 | + } |
---|
| 208 | + if (!(negate) && (x > 0)) { |
---|
| 209 | + return 1; |
---|
| 210 | + } |
---|
| 211 | + j = i + 1; |
---|
| 212 | + negate = 0; |
---|
| 213 | + |
---|
| 214 | + |
---|
| 215 | + } |
---|
| 216 | + return 0; |
---|
| 217 | +} |
---|
| 218 | + |
---|
| 219 | diff -Nur qmail-1.03/qregex.c qmail-1.03.tap/qregex.c |
---|
| 220 | --- qmail-1.03/qregex.c 1969-12-31 18:00:00.000000000 -0600 |
---|
| 221 | +++ qmail-1.03.tap/qregex.c 2005-02-15 12:48:58.000000000 -0600 |
---|
| 222 | @@ -0,0 +1,57 @@ |
---|
| 223 | +/* |
---|
| 224 | + * qregex (v2) |
---|
| 225 | + * $Id: qregex.c,v 2.1 2001/12/28 07:05:21 evan Exp $ |
---|
| 226 | + * |
---|
| 227 | + * Author : Evan Borgstrom (evan at unixpimps dot org) |
---|
| 228 | + * Created : 2001/12/14 23:08:16 |
---|
| 229 | + * Modified: $Date: 2001/12/28 07:05:21 $ |
---|
| 230 | + * Revision: $Revision: 2.1 $ |
---|
| 231 | + * |
---|
| 232 | + * Do POSIX regex matching on addresses for anti-relay / spam control. |
---|
| 233 | + * It logs to the maillog |
---|
| 234 | + * See the qregex-readme file included with this tarball. |
---|
| 235 | + * If you didn't get this file in a tarball please see the following URL: |
---|
| 236 | + * http://www.unixpimps.org/software/qregex |
---|
| 237 | + * |
---|
| 238 | + * qregex.c is released under a BSD style copyright. |
---|
| 239 | + * See http://www.unixpimps.org/software/qregex/copyright.html |
---|
| 240 | + * |
---|
| 241 | + * Note: this revision follows the coding guidelines set forth by the rest of |
---|
| 242 | + * the qmail code and that described at the following URL. |
---|
| 243 | + * http://cr.yp.to/qmail/guarantee.html |
---|
| 244 | + * |
---|
| 245 | + */ |
---|
| 246 | + |
---|
| 247 | +#include <sys/types.h> |
---|
| 248 | +#include <regex.h> |
---|
| 249 | +#include "qregex.h" |
---|
| 250 | + |
---|
| 251 | +#define REGCOMP(X,Y) regcomp(&X, Y, REG_EXTENDED|REG_ICASE) |
---|
| 252 | +#define REGEXEC(X,Y) regexec(&X, Y, (size_t)0, (regmatch_t *)0, (int)0) |
---|
| 253 | + |
---|
| 254 | +int matchregex(char *text, char *regex) { |
---|
| 255 | + regex_t qreg; |
---|
| 256 | + int retval = 0; |
---|
| 257 | + |
---|
| 258 | + |
---|
| 259 | + /* build the regex */ |
---|
| 260 | + if ((retval = REGCOMP(qreg, regex)) != 0) { |
---|
| 261 | + regfree(&qreg); |
---|
| 262 | + return(-retval); |
---|
| 263 | + } |
---|
| 264 | + |
---|
| 265 | + /* execute the regex */ |
---|
| 266 | + if ((retval = REGEXEC(qreg, text)) != 0) { |
---|
| 267 | + /* did we just not match anything? */ |
---|
| 268 | + if (retval == REG_NOMATCH) { |
---|
| 269 | + regfree(&qreg); |
---|
| 270 | + return(0); |
---|
| 271 | + } |
---|
| 272 | + regfree(&qreg); |
---|
| 273 | + return(-retval); |
---|
| 274 | + } |
---|
| 275 | + |
---|
| 276 | + /* signal the match */ |
---|
| 277 | + regfree(&qreg); |
---|
| 278 | + return(1); |
---|
| 279 | +} |
---|
| 280 | diff -Nur qmail-1.03/qregex.h qmail-1.03.tap/qregex.h |
---|
| 281 | --- qmail-1.03/qregex.h 1969-12-31 18:00:00.000000000 -0600 |
---|
| 282 | +++ qmail-1.03.tap/qregex.h 2005-02-15 12:48:58.000000000 -0600 |
---|
| 283 | @@ -0,0 +1,5 @@ |
---|
| 284 | +/* simple header file for the matchregex prototype */ |
---|
| 285 | +#ifndef _QREGEX_H_ |
---|
| 286 | +#define _QREGEX_H_ |
---|
| 287 | +int matchregex(char *text, char *regex); |
---|
| 288 | +#endif |
---|
| 289 | diff -Nur qmail-1.03/README.tap qmail-1.03.tap/README.tap |
---|
| 290 | --- qmail-1.03/README.tap 1969-12-31 18:00:00.000000000 -0600 |
---|
| 291 | +++ qmail-1.03.tap/README.tap 2005-06-07 09:48:41.000000000 -0500 |
---|
| 292 | @@ -0,0 +1,28 @@ |
---|
| 293 | +qmail provides the ability to make a copy of each email that flows through the system. |
---|
| 294 | +This is done using the QUEUE_EXTRA code. See qmail FAQ #8.2 |
---|
| 295 | + |
---|
| 296 | +The qmail tap patch adds additional functionality: |
---|
| 297 | +1) Specify which email addresses to tap using a regex style control file. With the |
---|
| 298 | + regex function, you can specify full domains or individual email addresses. |
---|
| 299 | + |
---|
| 300 | +2) Specify which email address to send the emails to. |
---|
| 301 | + |
---|
| 302 | +3) Qmail does not need to be restated to when the taps control file is changed. |
---|
| 303 | + |
---|
| 304 | +The regex match is applied to both the to and from email addresses. So email |
---|
| 305 | +sent to or from the addresses will be copied. Matching is case insensitive. |
---|
| 306 | +If there are multiple matches, the first match is used. |
---|
| 307 | + |
---|
| 308 | +The queue tap patch adds a new control file: |
---|
| 309 | + |
---|
| 310 | +/var/qmail/control/taps |
---|
| 311 | +Contains a regex style list of addresses to tap and the email |
---|
| 312 | +address of where you want the copy sent to. |
---|
| 313 | + |
---|
| 314 | +Examples: |
---|
| 315 | +a) To tap a whole domain add a line like: |
---|
| 316 | +.*@domain.com:joe@example.com |
---|
| 317 | + |
---|
| 318 | + |
---|
| 319 | +b) To tap an individual email address add a line like: |
---|
| 320 | +user@domain.com:other@example.com |
---|
| 321 | diff -Nur qmail-1.03/TARGETS qmail-1.03.tap/TARGETS |
---|
| 322 | --- qmail-1.03/TARGETS 1998-06-15 05:53:16.000000000 -0500 |
---|
| 323 | +++ qmail-1.03.tap/TARGETS 2005-02-15 12:48:21.000000000 -0600 |
---|
| 324 | @@ -385,3 +385,4 @@ |
---|
| 325 | man |
---|
| 326 | setup |
---|
| 327 | check |
---|
| 328 | +qregex.o |
---|