source: npl/mailserver/netqmail/qmail-tap.diff @ 0105685

gcc484ntopperl-5.22
Last change on this file since 0105685 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 9.8 KB
  • qmail-1.03

    diff -Nur qmail-1.03/error.h qmail-1.03.tap/error.h
    old new  
    11#ifndef ERROR_H
    22#define ERROR_H
     3#include <errno.h>
    34
    45extern int errno;
    56
  • qmail-1.03

    diff -Nur qmail-1.03/Makefile qmail-1.03.tap/Makefile
    old new  
    14191419        nroff -man qmail-qstat.8 > qmail-qstat.0
    14201420
    14211421qmail-queue: \
    1422 load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o \
    1423 datetime.a seek.a ndelay.a open.a sig.a alloc.a substdio.a error.a \
    1424 str.a fs.a auto_qmail.o auto_split.o auto_uids.o
     1422load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o qregex.o \
     1423datetime.a seek.a case.a ndelay.a open.a sig.a getln.a stralloc.a alloc.a \
     1424substdio.a error.a control.o constmap.o str.a fs.a auto_qmail.o \
     1425auto_split.o auto_uids.o
    14251426        ./load qmail-queue triggerpull.o fmtqfn.o now.o \
    1426         date822fmt.o datetime.a seek.a ndelay.a open.a sig.a \
    1427         alloc.a substdio.a error.a str.a fs.a auto_qmail.o \
    1428         auto_split.o auto_uids.o
     1427        date822fmt.o qregex.o control.o constmap.o datetime.a case.a seek.a \
     1428        ndelay.a open.a sig.a getln.a stralloc.a alloc.a substdio.a error.a \
     1429        str.a fs.a auto_qmail.o auto_split.o auto_uids.o
    14291430
    14301431qmail-queue.0: \
    14311432qmail-queue.8
     
    16811682constmap.h stralloc.h gen_alloc.h rcpthosts.h
    16821683        ./compile rcpthosts.c
    16831684
     1685qregex.o: \
     1686compile qregex.c qregex.h
     1687        ./compile qregex.c
     1688
    16841689readsubdir.o: \
    16851690compile readsubdir.c readsubdir.h direntry.h fmt.h scan.h str.h \
    16861691auto_split.h
  • qmail-control.9

    diff -Nur qmail-1.03/qmail-control.9 qmail-1.03.tap/qmail-control.9
    old new  
    6363.I rcpthosts    \fR(none)       \fRqmail-smtpd
    6464.I smtpgreeting \fIme   \fRqmail-smtpd
    6565.I smtproutes   \fR(none)       \fRqmail-remote
     66.I taps \fR(none)       \fRqmail-queue
    6667.I timeoutconnect       \fR60   \fRqmail-remote
    6768.I timeoutremote        \fR1200 \fRqmail-remote
    6869.I timeoutsmtpd \fR1200 \fRqmail-smtpd
     
    7273.SH "SEE ALSO"
    7374qmail-inject(8),
    7475qmail-qmqpc(8),
     76qmail-queue(8),
    7577qmail-remote(8),
    7678qmail-send(8),
    7779qmail-showctl(8),
  • qmail-queue.8

    diff -Nur qmail-1.03/qmail-queue.8 qmail-1.03.tap/qmail-queue.8
    old new  
    4040However, the recipients probably expect to see a proper header,
    4141as described in
    4242.BR qmail-header(5) .
     43.SH "CONTROL FILES"
     44.TP 5
     45.I taps
     46Should contain regex syntax of email addresses to tap and
     47the associated email address to send the copy to. The two
     48fields should be separated by a colon.
    4349.SH "FILESYSTEM RESTRICTIONS"
    4450.B qmail-queue
    4551imposes two constraints on the queue structure:
  • qmail-queue.c

    diff -Nur qmail-1.03/qmail-queue.c qmail-1.03.tap/qmail-queue.c
    old new  
    1616#include "auto_uids.h"
    1717#include "date822fmt.h"
    1818#include "fmtqfn.h"
     19#include "stralloc.h"
     20#include "constmap.h"
    1921
    2022#define DEATH 86400 /* 24 hours; _must_ be below q-s's OSSIFIED (36 hours) */
    2123#define ADDR 1003
     
    2527char outbuf[256];
    2628struct substdio ssout;
    2729
     30int tapok = 0;
     31stralloc tap = {0};
     32struct constmap maptap;
     33stralloc chkaddr = {0};
     34int tapped;
     35stralloc tapaddr = {0};
     36stralloc controlfile = {0};
     37
    2838datetime_sec starttime;
    2939struct datetime dt;
    3040unsigned long mypid;
     
    175185
    176186 alarm(DEATH);
    177187
     188 stralloc_copys( &controlfile, auto_qmail);
     189 stralloc_cats( &controlfile, "/control/taps");
     190 stralloc_0( &controlfile);
     191 tapok = control_readfile(&tap,controlfile.s,0);
     192 if (tapok == -1) die(65);
     193 if (!constmap_init(&maptap,tap.s,tap.len,0)) die(65);
     194
    178195 pidopen();
    179196 if (fstat(messfd,&pidst) == -1) die(63);
    180197
     
    219236 if (substdio_get(&ssin,&ch,1) < 1) die_read();
    220237 if (ch != 'F') die(91);
    221238 if (substdio_bput(&ssout,&ch,1) == -1) die_write();
     239 stralloc_0(&chkaddr);
    222240 for (len = 0;len < ADDR;++len)
    223241  {
     242   if ( len == 1 ) stralloc_copyb(&chkaddr, &ch,1);
     243   else if ( len > 1 ) stralloc_catb(&chkaddr, &ch,1);
    224244   if (substdio_get(&ssin,&ch,1) < 1) die_read();
    225245   if (substdio_put(&ssout,&ch,1) == -1) die_write();
    226246   if (!ch) break;
    227247  }
    228248 if (len >= ADDR) die(11);
    229249
     250 /* check the from address */
     251 stralloc_0(&chkaddr);
     252 if (tapped == 0 && tapcheck()==1 ) {
     253   tapped = 1;
     254   if ( tapaddr.len > 0 ) {
     255     if (substdio_bput(&ssout,"T",1) == -1) die_write();
     256     if (substdio_bput(&ssout,tapaddr.s,tapaddr.len) == -1) die_write();
     257     if (substdio_bput(&ssout,"",1) == -1) die_write();
     258   }
     259 }
     260
    230261 if (substdio_bput(&ssout,QUEUE_EXTRA,QUEUE_EXTRALEN) == -1) die_write();
    231262
    232263 for (;;)
     
    237268   if (substdio_bput(&ssout,&ch,1) == -1) die_write();
    238269   for (len = 0;len < ADDR;++len)
    239270    {
     271     if ( len == 1 ) stralloc_copyb(&chkaddr, &ch,1);
     272     else if ( len > 1 ) stralloc_catb(&chkaddr, &ch,1);
    240273     if (substdio_get(&ssin,&ch,1) < 1) die_read();
    241274     if (substdio_bput(&ssout,&ch,1) == -1) die_write();
    242275     if (!ch) break;
    243276    }
     277
     278    /* check the to address */
     279    stralloc_0(&chkaddr);
     280    if (tapped == 0 && tapcheck()==1 ) {
     281      tapped = 1;
     282      if ( tapaddr.len > 0 ) {
     283        if (substdio_bput(&ssout,"T",1) == -1) die_write();
     284        if (substdio_bput(&ssout,tapaddr.s,tapaddr.len) == -1) die_write();
     285        if (substdio_bput(&ssout,"",1) == -1) die_write();
     286       }
     287     }
     288
    244289   if (len >= ADDR) die(11);
    245290  }
    246291
     
    252297 triggerpull();
    253298 die(0);
    254299}
     300
     301int tapcheck()
     302{
     303  int i = 0;
     304  int j = 0;
     305  int x = 0;
     306  int negate = 0;
     307  stralloc curregex = {0};
     308  char tmpbuf[200];
     309
     310  while (j < tap.len) {
     311    i = j;
     312    while ((tap.s[i] != ':') && (i < tap.len)) i++;
     313    if (tap.s[j] == '!') {
     314      negate = 1;
     315      j++;
     316    }
     317    stralloc_copys(&tapaddr, &tap.s[i+1]);
     318
     319    stralloc_copyb(&curregex,tap.s + j,(i - j));
     320    stralloc_0(&curregex);
     321    x = matchregex(chkaddr.s, curregex.s, tmpbuf);
     322
     323    while ((tap.s[i] != '\0') && (i < tap.len)) i++;
     324 
     325    if ((negate) && (x == 0)) {
     326      return 1;
     327    }
     328    if (!(negate) && (x > 0)) {
     329      return 1;
     330    }
     331    j = i + 1;
     332    negate = 0;
     333
     334
     335  }
     336  return 0;
     337}
     338
  • qmail-1.03

    diff -Nur qmail-1.03/qregex.c qmail-1.03.tap/qregex.c
    old new  
     1/*
     2 * qregex (v2)
     3 * $Id: qregex.c,v 2.1 2001/12/28 07:05:21 evan Exp $
     4 *
     5 * Author  : Evan Borgstrom (evan at unixpimps dot org)
     6 * Created : 2001/12/14 23:08:16
     7 * Modified: $Date: 2001/12/28 07:05:21 $
     8 * Revision: $Revision: 2.1 $
     9 *
     10 * Do POSIX regex matching on addresses for anti-relay / spam control.
     11 * It logs to the maillog
     12 * See the qregex-readme file included with this tarball.
     13 * If you didn't get this file in a tarball please see the following URL:
     14 *  http://www.unixpimps.org/software/qregex
     15 *
     16 * qregex.c is released under a BSD style copyright.
     17 * See http://www.unixpimps.org/software/qregex/copyright.html
     18 *
     19 * Note: this revision follows the coding guidelines set forth by the rest of
     20 *       the qmail code and that described at the following URL.
     21 *       http://cr.yp.to/qmail/guarantee.html
     22 *
     23 */
     24
     25#include <sys/types.h>
     26#include <regex.h>
     27#include "qregex.h"
     28
     29#define REGCOMP(X,Y)    regcomp(&X, Y, REG_EXTENDED|REG_ICASE)
     30#define REGEXEC(X,Y)    regexec(&X, Y, (size_t)0, (regmatch_t *)0, (int)0)
     31
     32int matchregex(char *text, char *regex) {
     33  regex_t qreg;
     34  int retval = 0;
     35
     36
     37  /* build the regex */
     38  if ((retval = REGCOMP(qreg, regex)) != 0) {
     39    regfree(&qreg);
     40    return(-retval);
     41  }
     42
     43  /* execute the regex */
     44  if ((retval = REGEXEC(qreg, text)) != 0) {
     45    /* did we just not match anything? */
     46    if (retval == REG_NOMATCH) {
     47      regfree(&qreg);
     48      return(0);
     49    }
     50    regfree(&qreg);
     51    return(-retval);
     52  }
     53
     54  /* signal the match */
     55  regfree(&qreg);
     56  return(1);
     57}
  • qmail-1.03

    diff -Nur qmail-1.03/qregex.h qmail-1.03.tap/qregex.h
    old new  
     1/* simple header file for the matchregex prototype */
     2#ifndef _QREGEX_H_
     3#define _QREGEX_H_
     4int matchregex(char *text, char *regex);
     5#endif
  • README.tap

    diff -Nur qmail-1.03/README.tap qmail-1.03.tap/README.tap
    old new  
     1qmail provides the ability to make a copy of each email that flows through the system.
     2This is done using the QUEUE_EXTRA code. See qmail FAQ #8.2
     3
     4The qmail tap patch adds additional functionality:
     51) Specify which email addresses to tap using a regex style control file. With the
     6   regex function, you can specify full domains or individual email addresses.
     7
     82) Specify which email address to send the emails to.
     9
     103) Qmail does not need to be restated to when the taps control file is changed.
     11
     12The regex match is applied to both the to and from email addresses. So email
     13sent to or from the addresses will be copied. Matching is case insensitive.
     14If there are multiple matches, the first match is used.
     15
     16The queue tap patch adds a new control file:
     17
     18/var/qmail/control/taps
     19Contains a regex style list of addresses to tap and the email
     20address of where you want the copy sent to.
     21
     22Examples:
     23a) To tap a whole domain add a line like:
     24.*@domain.com:joe@example.com
     25
     26
     27b) To tap an individual email address add a line like:
     28user@domain.com:other@example.com
  • qmail-1.03

    diff -Nur qmail-1.03/TARGETS qmail-1.03.tap/TARGETS
    old new  
    385385man
    386386setup
    387387check
     388qregex.o
Note: See TracBrowser for help on using the repository browser.