summaryrefslogtreecommitdiff
blob: 601dfd5fb262d31d48f3235523c206f70ec7e395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
diff -ur qmail-1.03.orig/Makefile qmail-1.03/Makefile
--- qmail-1.03.orig/Makefile	2003-08-12 21:33:21.000000000 -0700
+++ qmail-1.03/Makefile	2003-08-12 21:34:08.000000000 -0700
@@ -807,7 +807,7 @@
 predate datemail mailsubj qmail-upq qmail-showctl qmail-newu \
 qmail-pw2u qmail-qread qmail-qstat qmail-tcpto qmail-tcpok \
 qmail-pop3d qmail-popup qmail-qmqpc qmail-qmqpd qmail-qmtpd \
-qmail-smtpd sendmail tcp-env qmail-newmrh config config-fast dnscname \
+qmail-smtpd sendmail tcp-env qmail-newmrh qmail-newbrt config config-fast dnscname \
 dnsptr dnsip dnsmxip dnsfq hostname ipmeprint qreceipt qsmhook qbiff \
 forward preline condredirect bouncesaying except maildirmake \
 maildir2mbox maildirwatch qail elq pinq idedit install-big install \
@@ -963,7 +963,7 @@
 man: \
 qmail-local.0 qmail-lspawn.0 qmail-getpw.0 qmail-remote.0 \
 qmail-rspawn.0 qmail-clean.0 qmail-send.0 qmail-start.0 splogger.0 \
-qmail-queue.0 qmail-inject.0 mailsubj.0 qmail-showctl.0 qmail-newu.0 \
+qmail-queue.0 qmail-inject.0 mailsubj.0 qmail-showctl.0 qmail-newbrt.0 qmail-newu.0 \
 qmail-pw2u.0 qmail-qread.0 qmail-qstat.0 qmail-tcpto.0 qmail-tcpok.0 \
 qmail-pop3d.0 qmail-popup.0 qmail-qmqpc.0 qmail-qmqpd.0 qmail-qmtpd.0 \
 qmail-smtpd.0 tcp-env.0 qmail-newmrh.0 qreceipt.0 qbiff.0 forward.0 \
@@ -1280,6 +1280,31 @@
 uint32.h substdio.h
 	./compile qmail-newmrh.c
 
+qmail-newbrt: \
+load qmail-newbrt.o cdbmss.o getln.a open.a cdbmake.a seek.a case.a \
+stralloc.a alloc.a strerr.a substdio.a error.a str.a auto_qmail.o
+	./load qmail-newbrt cdbmss.o getln.a open.a cdbmake.a \
+	seek.a case.a stralloc.a alloc.a strerr.a substdio.a \
+	error.a str.a auto_qmail.o 
+
+qmail-newbrt.o: \
+compile qmail-newbrt.c strerr.h stralloc.h gen_alloc.h substdio.h \
+getln.h exit.h readwrite.h open.h auto_qmail.h cdbmss.h cdbmake.h \
+uint32.h substdio.h
+	./compile qmail-newbrt.c
+
+qmail-newbrt.0: \
+qmail-newbrt.8
+	nroff -man qmail-newbrt.8 > qmail-newbrt.0
+
+qmail-newbrt.8: \
+qmail-newbrt.9 conf-break conf-spawn
+	cat qmail-newbrt.9 \
+	| sed s}QMAILHOME}"`head -1 conf-qmail`"}g \
+	| sed s}BREAK}"`head -1 conf-break`"}g \
+	| sed s}SPAWN}"`head -1 conf-spawn`"}g \
+	> qmail-newbrt.8
+
 qmail-newu: \
 load qmail-newu.o cdbmss.o getln.a open.a seek.a cdbmake.a case.a \
 stralloc.a alloc.a substdio.a error.a str.a auto_qmail.o
diff -ur qmail-1.03.orig/TARGETS qmail-1.03/TARGETS
--- qmail-1.03.orig/TARGETS	2003-08-12 21:33:21.000000000 -0700
+++ qmail-1.03/TARGETS	2003-08-12 21:34:08.000000000 -0700
@@ -237,6 +237,8 @@
 cdbmake_add.o
 cdbmake.a
 qmail-newu
+qmail-newbrt.o
+qmail-newbrt
 qmail-pw2u.o
 qmail-pw2u
 qmail-qread.o
@@ -349,6 +351,8 @@
 qmail-inject.0
 mailsubj.0
 qmail-showctl.0
+qmail-newbrt.8
+qmail-newbrt.0
 qmail-newu.8
 qmail-newu.0
 qmail-pw2u.8
diff -ur qmail-1.03.orig/hier.c qmail-1.03/hier.c
--- qmail-1.03.orig/hier.c	2003-08-12 21:33:19.000000000 -0700
+++ qmail-1.03/hier.c	2003-08-12 21:34:08.000000000 -0700
@@ -111,6 +111,7 @@
   c(auto_qmail,"bin","qmail-clean",auto_uido,auto_gidq,0711);
   c(auto_qmail,"bin","qmail-send",auto_uido,auto_gidq,0711);
   c(auto_qmail,"bin","splogger",auto_uido,auto_gidq,0711);
+  c(auto_qmail,"bin","qmail-newbrt",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","qmail-newu",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","qmail-newmrh",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","qmail-pw2u",auto_uido,auto_gidq,0711);
@@ -223,6 +224,8 @@
   c(auto_qmail,"man/cat8","qmail-inject.0",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/man8","qmail-showctl.8",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/cat8","qmail-showctl.0",auto_uido,auto_gidq,0644);
+  c(auto_qmail,"man/man8","qmail-newbrt.8",auto_uido,auto_gidq,0644);
+  c(auto_qmail,"man/cat8","qmail-newbrt.0",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/man8","qmail-newmrh.8",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/cat8","qmail-newmrh.0",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/man8","qmail-newu.8",auto_uido,auto_gidq,0644);
diff -ur qmail-1.03.orig/install-big.c qmail-1.03/install-big.c
--- qmail-1.03.orig/install-big.c	1998-06-15 03:53:16.000000000 -0700
+++ qmail-1.03/install-big.c	2003-08-12 21:34:08.000000000 -0700
@@ -109,6 +109,7 @@
   c(auto_qmail,"bin","qmail-clean",auto_uido,auto_gidq,0711);
   c(auto_qmail,"bin","qmail-send",auto_uido,auto_gidq,0711);
   c(auto_qmail,"bin","splogger",auto_uido,auto_gidq,0711);
+  c(auto_qmail,"bin","qmail-newbrt",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","qmail-newu",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","qmail-newmrh",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","qmail-pw2u",auto_uido,auto_gidq,0711);
@@ -221,6 +222,8 @@
   c(auto_qmail,"man/cat8","qmail-inject.0",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/man8","qmail-showctl.8",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/cat8","qmail-showctl.0",auto_uido,auto_gidq,0644);
+  c(auto_qmail,"man/man8","qmail-newmbrt.8",auto_uido,auto_gidq,0644);
+  c(auto_qmail,"man/cat8","qmail-newmbrt.0",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/man8","qmail-newmrh.8",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/cat8","qmail-newmrh.0",auto_uido,auto_gidq,0644);
   c(auto_qmail,"man/man8","qmail-newu.8",auto_uido,auto_gidq,0644);
Only in qmail-1.03: qmail-newbrt.9
Only in qmail-1.03: qmail-newbrt.c
diff -ur qmail-1.03.orig/qmail-showctl.c qmail-1.03/qmail-showctl.c
--- qmail-1.03.orig/qmail-showctl.c	1998-06-15 03:53:16.000000000 -0700
+++ qmail-1.03/qmail-showctl.c	2003-08-12 21:34:08.000000000 -0700
@@ -215,6 +215,27 @@
   }
 
   do_lst("badmailfrom","Any MAIL FROM is allowed.",""," not accepted in MAIL FROM.");
+
+  if (do_lst("badrcptto","Any RCPT TO is allowed."," not accepted in RCPT TO ","."))
+    do_lst("morebadrcptto","No effect."," no accepted in RCPT TO ",".");
+  else
+    do_lst("morebadrcptto","No badrcptto; morebadrcpto is irrelevant.","No badrcptto; doesn't matter that morebadrcptto has ",".");
+  /* XXX: check badrcptto.cdb contents */
+  substdio_puts(subfdout,"\nmorebadrcptto.cdb: ");
+  if (stat("morebadrcptto",&stmrh) == -1)
+    if (stat("morebadrcptto.cdb",&stmrhcdb) == -1)
+      substdio_puts(subfdout,"(Default.) No effect.\n");
+    else
+      substdio_puts(subfdout,"Oops! morebadrcptto.cdb exists but morebadrcptto doesn't.\n");
+  else
+    if (stat("morebadrcptto.cdb",&stmrhcdb) == -1)
+      substdio_puts(subfdout,"Oops! morebadrcptto exists but morebadrcptto.cdb doesn't.\n");
+    else
+      if (stmrh.st_mtime > stmrhcdb.st_mtime)
+        substdio_puts(subfdout,"Oops! morebadrcptto.cdb is older than morebadrcptto.\n");
+      else
+        substdio_puts(subfdout,"Modified recently enough; hopefully up to date.\n");
+
   do_str("bouncefrom",0,"MAILER-DAEMON","Bounce user name is ");
   do_str("bouncehost",1,"bouncehost","Bounce host name is ");
   do_int("concurrencylocal","10","Local concurrency is ","");
@@ -268,6 +289,7 @@
     if (str_equal(d->d_name,"bouncefrom")) continue;
     if (str_equal(d->d_name,"bouncehost")) continue;
     if (str_equal(d->d_name,"badmailfrom")) continue;
+    if (str_equal(d->d_name,"badrcptto")) continue;
     if (str_equal(d->d_name,"bouncefrom")) continue;
     if (str_equal(d->d_name,"bouncehost")) continue;
     if (str_equal(d->d_name,"concurrencylocal")) continue;
@@ -283,6 +305,8 @@
     if (str_equal(d->d_name,"localiphost")) continue;
     if (str_equal(d->d_name,"locals")) continue;
     if (str_equal(d->d_name,"me")) continue;
+    if (str_equal(d->d_name,"morebadrcptto")) continue;
+    if (str_equal(d->d_name,"morebadrcptto.cdb")) continue;
     if (str_equal(d->d_name,"morercpthosts")) continue;
     if (str_equal(d->d_name,"morercpthosts.cdb")) continue;
     if (str_equal(d->d_name,"percenthack")) continue;
diff -ur qmail-1.03.orig/qmail-smtpd.8 qmail-1.03/qmail-smtpd.8
--- qmail-1.03.orig/qmail-smtpd.8	2003-08-12 21:33:19.000000000 -0700
+++ qmail-1.03/qmail-smtpd.8	2003-08-12 21:34:08.000000000 -0700
@@ -92,6 +92,13 @@
 the client-presented certificates during a TLS-encrypted session.
 
 .TP 5
+.I badrcptto
+Unacceptable envelope recipient addresses.
+.B qmail-smtpd
+will reject every recipient address for a message
+if the envelope recipient address is listed in
+.IR badrcptto .
+.TP 5
 .I databytes
 Maximum number of bytes allowed in a message,
 or 0 for no limit.
@@ -139,6 +146,23 @@
 This is done before
 .IR rcpthosts .
 .TP 5
+.I morebadrcptto
+Extra not allowed RCPT TO addresses.
+If
+.I badrcptto
+and
+.I morebadrcptto
+both exist,
+.I morebardrcptto
+is effectively appended to
+.IR badrcptto .
+
+You must run
+.B qmail-newbrt
+whenever
+.I morebadrcptto
+changes.
+.TP 5
 .I morercpthosts
 Extra allowed RCPT domains.
 If
diff -ur qmail-1.03.orig/qmail-smtpd.c qmail-1.03/qmail-smtpd.c
--- qmail-1.03.orig/qmail-smtpd.c	2003-08-12 21:33:22.000000000 -0700
+++ qmail-1.03/qmail-smtpd.c	2003-08-13 00:25:13.000000000 -0700
@@ -25,12 +25,19 @@
 #include "commands.h"
 #include "wait.h"
 #include "fd.h"
+#include "cdb.h"
 
 #define AUTHCRAM
 #define MAXHOPS 100
 unsigned int databytes = 0;
 int timeout = 1200;
 
+char *remoteip;
+char *remotehost;
+char *remoteinfo;
+char *local;
+char *relayclient;
+
 const char *protocol = "SMTP";
 
 #ifdef TLS
@@ -59,17 +66,52 @@
 char ssoutbuf[512];
 substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof ssoutbuf);
 
+/* write errors to stderr */
+char erroutbuf[512];
+substdio errout = SUBSTDIO_FDBUF(safewrite,2,erroutbuf,sizeof erroutbuf);
+
 void flush() { substdio_flush(&ssout); }
 void out(s) char *s; { substdio_puts(&ssout,s); }
 
+void eflush() {  substdio_flush(&errout); }
+void eout(s) char *s; { substdio_puts(&errout,s); }
+void enew() { substdio_puts(&errout,"qmail-smtpd: "); }
+
 void die_read() { _exit(1); }
-void die_alarm() { out("451 timeout (#4.4.2)\r\n"); flush(); _exit(1); }
-void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); }
-void die_control() { out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); }
-void die_ipme() { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); }
-void straynewline() { out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); flush(); _exit(1); }
+
+void die_alarm()
+{
+  enew(); eout("Connection to "); eout(remoteip); eout(" timed out.\n");
+  out("451 timeout (#4.4.2)\r\n"); flush(); eflush(); _exit(1);
+}
+void die_nomem()
+{
+  enew(); eout("Out of memory while connected to "); eout(remoteip); eout("!\n");
+  out("421 out of memory (#4.3.0)\r\n"); flush(); eflush(); _exit(1);
+}
+void die_control( char* msg )
+{
+  enew(); 
+  if(msg) { eout("("); eout(msg); eout(") "); }
+  eout("Unable to read controls!\n");
+  out("421 unable to read controls (#4.3.0)\r\n"); flush(); eflush(); 
+  _exit(1);
+}
+void die_ipme()
+{
+  enew(); eout("Unable to figure out my IP addresses!\n");
+  out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush();
+  eflush(); _exit(1);
+}
+void straynewline()
+{
+  enew(); eout("Stray newline from "); eout(remoteip); eout(".\n");
+  out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); flush();
+  eflush(); _exit(1);
+}
 
 void err_bmf() { out("553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n"); }
+void err_brt() { out("550 sorry, this message is not deliverable (#5.7.1)\r\n"); }
 #ifndef TLS
 void err_nogateway() { out("553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)\r\n"); }
 #else
@@ -116,12 +158,6 @@
   smtp_greet("221 "); out("\r\n"); flush(); _exit(0);
 }
 
-char *remoteip;
-char *remotehost;
-char *remoteinfo;
-char *local;
-char *relayclient;
-
 stralloc helohost = {0};
 char *fakehelo; /* pointer into helohost, or 0 */
 
@@ -136,28 +172,43 @@
 int bmfok = 0;
 stralloc bmf = {0};
 struct constmap mapbmf;
+int brtok = 0;
+stralloc brt = {0};
+struct constmap mapbrt;
+int fdmbrt;
 
 void setup()
 {
   char *x;
   unsigned long u;
  
-  if (control_init() == -1) die_control();
+  if (control_init() == -1) die_control("control_init == -1");
   if (control_rldef(&greeting,"control/smtpgreeting",1,(char *) 0) != 1)
-    die_control();
+    die_control("control/smtpgreeting bad");
   liphostok = control_rldef(&liphost,"control/localiphost",1,(char *) 0);
-  if (liphostok == -1) die_control();
-  if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control();
+  if (liphostok == -1) die_control("control/localiphost bad");
+  if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control("control/timeoutsmtpd bad");
   if (timeout <= 0) timeout = 1;
 
-  if (rcpthosts_init() == -1) die_control();
+  if (rcpthosts_init() == -1) die_control("rcpthosts_init == -1");
 
   bmfok = control_readfile(&bmf,"control/badmailfrom",0);
-  if (bmfok == -1) die_control();
+  if (bmfok == -1) die_control("control/badmailfrom bad");
   if (bmfok)
     if (!constmap_init(&mapbmf,bmf.s,bmf.len,0)) die_nomem();
+
+  brtok = control_readfile(&brt,"control/badrcptto",0);
+  if (brtok == -1) die_control("control/badrcptto bad");
+  if (brtok)
+    if (!constmap_init(&mapbrt,brt.s,brt.len,0)) die_nomem();
  
-  if (control_readint(&databytes,"control/databytes") == -1) die_control();
+  fdmbrt = -1;
+  fdmbrt = open_read("control/morebadrcptto.cdb");
+  if (fdmbrt != -1) { enew(); eout("morebadrcptto != -1\n"); eflush(); }
+  if (fdmbrt == -1) if (errno != error_noent) { die_control("control/morebadrcptto.cdb inaccessible"); };
+
+
+  if (control_readint(&databytes,"control/databytes") == -1) die_control("control/databytes bad");
   x = env_get("DATABYTES");
   if (x) { scan_ulong(x,&u); databytes = u; }
   if (!(databytes + 1)) --databytes;
@@ -276,6 +327,14 @@
   return 1;
 }
 
+static void log_deny(m,f,t) char *m,*f,*t;
+{
+  enew(); eout(m); eout(" check failed ("); eout(f); eout(") -> (");
+  eout(t); eout(") ["); eout(remoteip); eout("] (HELO "); 
+  eout(helohost.s); eout(")\n");
+  eflush();
+} 
+
 int bmfcheck()
 {
   int j;
@@ -287,11 +346,24 @@
   return 0;
 }
 
+int brtcheck()
+{
+  int j;
+  if (brtok) if (constmap(&mapbrt,addr.s,addr.len - 1)) return 1;
+  if (fdmbrt != -1 ) {
+    uint32 dlen;
+    j = cdb_seek(fdmbrt, addr.s, addr.len - 1, &dlen);
+    if (j == -1) die_control("brtcheck failed (cdb_seek)");
+    if (j) return j;
+  }
+  return 0;
+}
+
 int addrallowed()
 {
   int r;
   r = rcpthosts(addr.s,str_len(addr.s));
-  if (r == -1) die_control();
+  if (r == -1) die_control("addrallowed failed");
 #ifdef TLS
   if (r == 0) if (tls_verify()) r = -2;
 #endif
@@ -316,6 +388,7 @@
 
 int seenmail = 0;
 int flagbarf; /* defined if seenmail */
+int flagbrt; /* defined if any bad rcpts */
 stralloc mailfrom = {0};
 stralloc rcptto = {0};
 
@@ -376,6 +449,10 @@
   }
   else
     if (!addrallowed()) { err_nogateway(); return; }
+  if (!env_get("RELAYCLIENT") && brtcheck()) { 
+    flagbrt = 1; 
+    log_deny("BAD RCPT TO", mailfrom.s,addr.s);
+  }
   if (!stralloc_cats(&rcptto,"T")) die_nomem();
   if (!stralloc_cats(&rcptto,addr.s)) die_nomem();
   if (!stralloc_0(&rcptto)) die_nomem();
@@ -495,6 +572,7 @@
  
   if (!seenmail) { err_wantmail(); return; }
   if (!rcptto.len) { err_wantrcpt(); return; }
+  if (flagbrt) { err_brt(); return; }
   seenmail = 0;
   if (databytes) bytestooverflow = databytes + 1;
   if (qmail_open(&qqt) == -1) { err_qqt(); return; }
@@ -810,7 +888,7 @@
       constmap_free(&mapclients);
     }
   case 0: alloc_free(clients.s); return 0;
-  case -1: die_control();
+  case -1: die_control("tls_verify failed");
   }
 
   if (ssl_timeoutrehandshake(timeout, ssl_rfd, ssl_wfd, ssl) <= 0) {
@@ -892,7 +970,7 @@
   ciphers = env_get("TLSCIPHERS");
   if (!ciphers) {
     if (control_readfile(&saciphers, "control/tlsserverciphers") == -1)
-      { SSL_free(myssl); die_control(); }
+      { SSL_free(myssl); die_control("control/tlsserverciphers bad"); }
     if (saciphers.len) { /* convert all '\0's except the last one to ':' */
       int i;
       for (i = 0; i < saciphers.len - 1; ++i)
@@ -959,7 +1037,7 @@
   childargs = argv + 2;
 
   sig_pipeignore();
-  if (chdir(auto_qmail) == -1) die_control();
+  if (chdir(auto_qmail) == -1) die_control("chdir failed");
   setup();
   if (ipme_init() != 1) die_ipme();
   smtp_greet("220 ");
diff -urN qmail-1.03.orig/qmail-newbrt.9 qmail-1.03/qmail-newbrt.9
--- qmail-1.03.orig/qmail-newbrt.9	1969-12-31 21:00:00.000000000 -0300
+++ qmail-1.03/qmail-newbrt.9	2003-04-28 02:32:33.000000000 -0300
@@ -0,0 +1,41 @@
+.TH qmail-newbrt 8
+.SH NAME
+qmail-newbrt \- prepare morebadrcptto for qmail-smtpd
+.SH SYNOPSIS
+.B qmail-newbrt
+.SH DESCRIPTION
+.B qmail-newbrt
+reads the instructions in
+.B QMAILHOME/control/morebadrcptto
+and writes them into
+.B QMAILHOME/control/morebadrcptto.cdb
+in a binary format suited
+for quick access by
+.BR qmail-smtpd .
+
+If there is a problem with
+.BR control/morebadrcptto ,
+.B qmail-newbrt
+complains and leaves
+.B control/morebadrcptto.cdb
+alone.
+
+.B qmail-newbrt
+ensures that
+.B control/morebadrcptto.cdb
+is updated atomically,
+so
+.B qmail-smtpd
+never has to wait for
+.B qmail-newbrt
+to finish.
+However,
+.B qmail-newbrt
+makes no attempt to protect against two simultaneous updates of
+.BR control/morebadrcptto.cdb .
+
+The binary
+.B control/morebadrcptto.cdb
+format is portable across machines.
+.SH "SEE ALSO"
+qmail-smtpd(8)
diff -urN qmail-1.03.orig/qmail-newbrt.c qmail-1.03/qmail-newbrt.c
--- qmail-1.03.orig/qmail-newbrt.c	1969-12-31 21:00:00.000000000 -0300
+++ qmail-1.03/qmail-newbrt.c	2003-04-28 01:54:33.000000000 -0300
@@ -0,0 +1,70 @@
+#include "strerr.h"
+#include "stralloc.h"
+#include "substdio.h"
+#include "getln.h"
+#include "exit.h"
+#include "readwrite.h"
+#include "open.h"
+#include "auto_qmail.h"
+#include "cdbmss.h"
+
+#define FATAL "qmail-newbrt: fatal: "
+
+void die_read()
+{
+  strerr_die2sys(111,FATAL,"unable to read control/morebadrcptto: ");
+}
+void die_write()
+{
+  strerr_die2sys(111,FATAL,"unable to write to control/morebadrcptto.tmp: ");
+}
+
+char inbuf[1024];
+substdio ssin;
+
+int fd;
+int fdtemp;
+
+struct cdbmss cdbmss;
+stralloc line = {0};
+int match;
+
+void main()
+{
+  umask(033);
+  if (chdir(auto_qmail) == -1)
+    strerr_die4sys(111,FATAL,"unable to chdir to ",auto_qmail,": ");
+
+  fd = open_read("control/morebadrcptto");
+  if (fd == -1) die_read();
+
+  substdio_fdbuf(&ssin,read,fd,inbuf,sizeof inbuf);
+
+  fdtemp = open_trunc("control/morebadrcptto.tmp");
+  if (fdtemp == -1) die_write();
+
+  if (cdbmss_start(&cdbmss,fdtemp) == -1) die_write();
+
+  for (;;) {
+    if (getln(&ssin,&line,&match,'\n') != 0) die_read();
+    case_lowerb(line.s,line.len);
+    while (line.len) {
+      if (line.s[line.len - 1] == ' ') { --line.len; continue; }
+      if (line.s[line.len - 1] == '\n') { --line.len; continue; }
+      if (line.s[line.len - 1] == '\t') { --line.len; continue; }
+      if (line.s[0] != '#')
+	if (cdbmss_add(&cdbmss,line.s,line.len,"",0) == -1)
+	  die_write();
+      break;
+    }
+    if (!match) break;
+  }
+
+  if (cdbmss_finish(&cdbmss) == -1) die_write();
+  if (fsync(fdtemp) == -1) die_write();
+  if (close(fdtemp) == -1) die_write(); /* NFS stupidity */
+  if (rename("control/morebadrcptto.tmp","control/morebadrcptto.cdb") == -1)
+    strerr_die2sys(111,FATAL,"unable to move control/morebadrcpto.tmp to control/morebadrcptto.cdb");
+
+  _exit(0);
+}