summaryrefslogtreecommitdiffstats
path: root/qmail-newbrt.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-02-04 02:55:38 +0100
committermanuel <manuel@mausz.at>2013-02-04 02:55:38 +0100
commitfd404641357a4a3bc0a55cb31deb3d4bad4ec2ee (patch)
tree903f803763dc4e9329179102a52a4687ed664cc6 /qmail-newbrt.c
parentee944357ee374402f20eb1297a0b596f7ef4ea8d (diff)
downloadqmail-fd404641357a4a3bc0a55cb31deb3d4bad4ec2ee.tar.gz
qmail-fd404641357a4a3bc0a55cb31deb3d4bad4ec2ee.tar.bz2
qmail-fd404641357a4a3bc0a55cb31deb3d4bad4ec2ee.zip
[PATCH] badrcptto support
qmail-gentoo-1.03-r16-badrcptto-morebadrcptto-accdias
Diffstat (limited to 'qmail-newbrt.c')
-rw-r--r--qmail-newbrt.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/qmail-newbrt.c b/qmail-newbrt.c
new file mode 100644
index 0000000..9344444
--- /dev/null
+++ b/qmail-newbrt.c
@@ -0,0 +1,70 @@
1#include "strerr.h"
2#include "stralloc.h"
3#include "substdio.h"
4#include "getln.h"
5#include "exit.h"
6#include "readwrite.h"
7#include "open.h"
8#include "auto_qmail.h"
9#include "cdbmss.h"
10
11#define FATAL "qmail-newbrt: fatal: "
12
13void die_read()
14{
15 strerr_die2sys(111,FATAL,"unable to read control/morebadrcptto: ");
16}
17void die_write()
18{
19 strerr_die2sys(111,FATAL,"unable to write to control/morebadrcptto.tmp: ");
20}
21
22char inbuf[1024];
23substdio ssin;
24
25int fd;
26int fdtemp;
27
28struct cdbmss cdbmss;
29stralloc line = {0};
30int match;
31
32void main()
33{
34 umask(033);
35 if (chdir(auto_qmail) == -1)
36 strerr_die4sys(111,FATAL,"unable to chdir to ",auto_qmail,": ");
37
38 fd = open_read("control/morebadrcptto");
39 if (fd == -1) die_read();
40
41 substdio_fdbuf(&ssin,read,fd,inbuf,sizeof inbuf);
42
43 fdtemp = open_trunc("control/morebadrcptto.tmp");
44 if (fdtemp == -1) die_write();
45
46 if (cdbmss_start(&cdbmss,fdtemp) == -1) die_write();
47
48 for (;;) {
49 if (getln(&ssin,&line,&match,'\n') != 0) die_read();
50 case_lowerb(line.s,line.len);
51 while (line.len) {
52 if (line.s[line.len - 1] == ' ') { --line.len; continue; }
53 if (line.s[line.len - 1] == '\n') { --line.len; continue; }
54 if (line.s[line.len - 1] == '\t') { --line.len; continue; }
55 if (line.s[0] != '#')
56 if (cdbmss_add(&cdbmss,line.s,line.len,"",0) == -1)
57 die_write();
58 break;
59 }
60 if (!match) break;
61 }
62
63 if (cdbmss_finish(&cdbmss) == -1) die_write();
64 if (fsync(fdtemp) == -1) die_write();
65 if (close(fdtemp) == -1) die_write(); /* NFS stupidity */
66 if (rename("control/morebadrcptto.tmp","control/morebadrcptto.cdb") == -1)
67 strerr_die2sys(111,FATAL,"unable to move control/morebadrcpto.tmp to control/morebadrcptto.cdb");
68
69 _exit(0);
70}