-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqmailtoaster-1.3.2.patch
14117 lines (13916 loc) · 410 KB
/
qmailtoaster-1.3.2.patch
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Naur qmail-1.03-original/base64.c qmail-1.03/base64.c
--- qmail-1.03-original/base64.c 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/base64.c 2011-01-23 10:39:17.000000000 -0500
@@ -0,0 +1,122 @@
+#include "base64.h"
+#include "stralloc.h"
+#include "substdio.h"
+#include "str.h"
+
+static char *b64alpha =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+#define B64PAD '='
+
+/* returns 0 ok, 1 illegal, -1 problem */
+
+int b64decode(in,l,out)
+const unsigned char *in;
+int l;
+stralloc *out; /* not null terminated */
+{
+ int p = 0;
+ int n;
+ unsigned int x;
+ int i, j;
+ char *s;
+ unsigned char b[3];
+
+ if (l == 0)
+ {
+ if (!stralloc_copys(out,"")) return -1;
+ return 0;
+ }
+
+ while(in[l-1] == B64PAD) {
+ p ++;
+ l--;
+ }
+
+ n = (l + p) / 4;
+ out->len = (n * 3) - p;
+ if (!stralloc_ready(out,out->len)) return -1;
+ s = out->s;
+
+ for(i = 0; i < n - 1 ; i++) {
+ x = 0;
+ for(j = 0; j < 4; j++) {
+ if(in[j] >= 'A' && in[j] <= 'Z')
+ x = (x << 6) + (unsigned int)(in[j] - 'A' + 0);
+ else if(in[j] >= 'a' && in[j] <= 'z')
+ x = (x << 6) + (unsigned int)(in[j] - 'a' + 26);
+ else if(in[j] >= '0' && in[j] <= '9')
+ x = (x << 6) + (unsigned int)(in[j] - '0' + 52);
+ else if(in[j] == '+')
+ x = (x << 6) + 62;
+ else if(in[j] == '/')
+ x = (x << 6) + 63;
+ else if(in[j] == '=')
+ x = (x << 6);
+ }
+
+ s[2] = (unsigned char)(x & 255); x >>= 8;
+ s[1] = (unsigned char)(x & 255); x >>= 8;
+ s[0] = (unsigned char)(x & 255); x >>= 8;
+ s += 3; in += 4;
+ }
+
+ x = 0;
+ for(j = 0; j < 4; j++) {
+ if(in[j] >= 'A' && in[j] <= 'Z')
+ x = (x << 6) + (unsigned int)(in[j] - 'A' + 0);
+ else if(in[j] >= 'a' && in[j] <= 'z')
+ x = (x << 6) + (unsigned int)(in[j] - 'a' + 26);
+ else if(in[j] >= '0' && in[j] <= '9')
+ x = (x << 6) + (unsigned int)(in[j] - '0' + 52);
+ else if(in[j] == '+')
+ x = (x << 6) + 62;
+ else if(in[j] == '/')
+ x = (x << 6) + 63;
+ else if(in[j] == '=')
+ x = (x << 6);
+ }
+
+ b[2] = (unsigned char)(x & 255); x >>= 8;
+ b[1] = (unsigned char)(x & 255); x >>= 8;
+ b[0] = (unsigned char)(x & 255); x >>= 8;
+
+ for(i = 0; i < 3 - p; i++)
+ s[i] = b[i];
+
+ return 0;
+}
+
+int b64encode(in,out)
+stralloc *in;
+stralloc *out; /* not null terminated */
+{
+ unsigned char a, b, c;
+ int i;
+ char *s;
+
+ if (in->len == 0)
+ {
+ if (!stralloc_copys(out,"")) return -1;
+ return 0;
+ }
+
+ if (!stralloc_ready(out,in->len / 3 * 4 + 4)) return -1;
+ s = out->s;
+
+ for (i = 0;i < in->len;i += 3) {
+ a = in->s[i];
+ b = i + 1 < in->len ? in->s[i + 1] : 0;
+ c = i + 2 < in->len ? in->s[i + 2] : 0;
+
+ *s++ = b64alpha[a >> 2];
+ *s++ = b64alpha[((a & 3 ) << 4) | (b >> 4)];
+
+ if (i + 1 >= in->len) *s++ = B64PAD;
+ else *s++ = b64alpha[((b & 15) << 2) | (c >> 6)];
+
+ if (i + 2 >= in->len) *s++ = B64PAD;
+ else *s++ = b64alpha[c & 63];
+ }
+ out->len = s - out->s;
+ return 0;
+}
diff -Naur qmail-1.03-original/base64.h qmail-1.03/base64.h
--- qmail-1.03-original/base64.h 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/base64.h 2011-01-23 10:39:17.000000000 -0500
@@ -0,0 +1,7 @@
+#ifndef BASE64_H
+#define BASE64_H
+
+extern int b64decode();
+extern int b64encode();
+
+#endif
diff -Naur qmail-1.03-original/byte_cspn.c qmail-1.03/byte_cspn.c
--- qmail-1.03-original/byte_cspn.c 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/byte_cspn.c 2011-01-23 10:39:17.000000000 -0500
@@ -0,0 +1,11 @@
+#include "byte.h"
+
+unsigned int byte_cspn(s,n,c)
+register char *s;
+register unsigned int n;
+register char *c;
+{
+ while(*c)
+ n = byte_chr(s,n,*c++);
+ return n;
+}
diff -Naur qmail-1.03-original/byte.h qmail-1.03/byte.h
--- qmail-1.03-original/byte.h 2011-01-23 10:36:12.000000000 -0500
+++ qmail-1.03/byte.h 2011-01-23 10:39:17.000000000 -0500
@@ -3,6 +3,8 @@
extern unsigned int byte_chr();
extern unsigned int byte_rchr();
+extern unsigned int byte_cspn();
+extern unsigned int byte_rcspn();
extern void byte_copy();
extern void byte_copyr();
extern int byte_diff();
diff -Naur qmail-1.03-original/byte_rcspn.c qmail-1.03/byte_rcspn.c
--- qmail-1.03-original/byte_rcspn.c 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/byte_rcspn.c 2011-01-23 10:39:17.000000000 -0500
@@ -0,0 +1,17 @@
+#include "byte.h"
+
+unsigned int byte_rcspn(s,n,c)
+register char *s;
+register unsigned int n;
+register char *c;
+{
+ unsigned int ret,pos,i;
+
+ for(ret = n,pos = 0;*c;++c) {
+ i = byte_rchr(s + pos,n - pos,*c) + pos;
+ if (i < n) ret = pos = i;
+ }
+
+ return ret;
+}
+
diff -Naur qmail-1.03-original/case_startb.c qmail-1.03/case_startb.c
--- qmail-1.03-original/case_startb.c 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/case_startb.c 2011-01-23 10:39:17.000000000 -0500
@@ -0,0 +1,21 @@
+#include "case.h"
+
+int case_startb(s,len,t)
+register char *s;
+unsigned int len;
+register char *t;
+{
+ register unsigned char x;
+ register unsigned char y;
+
+ for (;;) {
+ y = *t++ - 'A';
+ if (y <= 'Z' - 'A') y += 'a'; else y += 'A';
+ if (!y) return 1;
+ if (!len) return 0;
+ --len;
+ x = *s++ - 'A';
+ if (x <= 'Z' - 'A') x += 'a'; else x += 'A';
+ if (x != y) return 0;
+ }
+}
diff -Naur qmail-1.03-original/cdbmake_add.c qmail-1.03/cdbmake_add.c
--- qmail-1.03-original/cdbmake_add.c 2011-01-23 10:36:12.000000000 -0500
+++ qmail-1.03/cdbmake_add.c 2011-01-23 10:39:17.000000000 -0500
@@ -1,3 +1,4 @@
+#include "alloc.h"
#include "cdbmake.h"
void cdbmake_init(cdbm)
diff -Naur qmail-1.03-original/cdb_seek.c qmail-1.03/cdb_seek.c
--- qmail-1.03-original/cdb_seek.c 2011-01-23 10:36:12.000000000 -0500
+++ qmail-1.03/cdb_seek.c 2011-01-23 10:39:17.000000000 -0500
@@ -1,6 +1,5 @@
#include <sys/types.h>
#include <errno.h>
-extern int errno;
#include "cdb.h"
#ifndef SEEK_SET
diff -Naur qmail-1.03-original/CHANGES qmail-1.03/CHANGES
--- qmail-1.03-original/CHANGES 2011-01-23 10:36:12.000000000 -0500
+++ qmail-1.03/CHANGES 2011-01-23 10:39:17.000000000 -0500
@@ -1,3 +1,24 @@
+20040121 version: netqmail 1.05
+20040121 code: qmail-smtpd is protected from exceedingly long (eg 2GB)
+ header lines
+20040121 code: qmail_lspawn, qmail-newmrh, qmail-newu, and qmail-rspawn
+ are protected from misbehaving on hosts where the size of an
+ integer is not the same as the size of a character pointer
+ (eg 64 bit hosts with 32 bit ints)
+20031027 version: netqmail 1.04.
+20031027 doc: INSTALL points to http://lifewithqmail.org/lwq.html
+20031027 doc: qmail.7 identifies installation as netqmail and points to
+ http://qmail.org/
+20031027 doc: qmail-queue.8 adds explanation of $QMAILQUEUE
+20031027 doc: qmail-log.5 adds reference to errors from $QMAILQUEUE script
+20031027 doc: FAQ also points to http://cr.yp.to/qmail/faq.html and
+ http://qmail.org/
+20031027 code: qmail-smtpd identifies itself as netqmail
+20031027 code: if $QMAILQUEUE is set, it's invoked instead of qmail-queue
+20031024 code: changed errno from int to #include.
+20031024 code: fixed .qmail parsing bug.
+20031024 code: recognize 0.0.0.0 as a local address.
+20031024 code: sendmail's -f flag now overrides environment variables.
19980615 version: qmail 1.03.
19980614 doc: eliminated BIN.setup in favor of a web page.
19980614 code: added other auto* to qmail-showctl output.
diff -Naur qmail-1.03-original/chkspawn.c qmail-1.03/chkspawn.c
--- qmail-1.03-original/chkspawn.c 2011-01-23 10:36:12.000000000 -0500
+++ qmail-1.03/chkspawn.c 2011-01-23 10:39:17.000000000 -0500
@@ -22,8 +22,8 @@
_exit(1);
}
- if (auto_spawn > 255) {
- substdio_puts(subfderr,"Oops. You have set conf-spawn higher than 255.\n");
+ if (auto_spawn > 65000) {
+ substdio_puts(subfderr,"Oops. You have set conf-spawn higher than 65000.\n");
substdio_flush(subfderr);
_exit(1);
}
diff -Naur qmail-1.03-original/CHKUSER.automatic_patching qmail-1.03/CHKUSER.automatic_patching
--- qmail-1.03-original/CHKUSER.automatic_patching 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/CHKUSER.automatic_patching 2011-01-23 10:40:04.000000000 -0500
@@ -0,0 +1,94 @@
+Chkuser 2.0.9 automatic patching
+
+When to use automatic patching
+==============================
+
+The release.tar package contains some .patch files, ready for installation,
+trying to semplify the most frequent situations.
+
+You may use one of these patches if you have these sources:
+
+ - a clean qmail 1.03 or netqmail 1.05
+
+You may also consider using one of these patches if you have additional compatible
+patches installed. This means that these additional patches should not have changed
+the same sources and lines which are going to be used by chkuser.
+
+If you have any doubt, backup your sources and try the automatic installation,
+otherwise execute the manual installation (that's very easy).
+
+Backup
+======
+
+Save you qmail working sources before making any change.
+
+Basic installation
+==================
+
+Download the newest release.tar package and untar it. It will create a directory
+containing all release chkuser files and patches.
+
+Chose the most appropriate .patch file to be applied, according to your qmail
+installation: .patch files names are self-describing.
+
+Position in the qmail/netqmail source directory:
+
+ $ cd /usr/.../netqmail-1.05
+
+Apply selected patch:
+
+ $ patch < /path_to_chkuser_release_dir/netqmail-1.05_chkuser-2.x.x.patch
+
+No errors should be displayed. If you see any error, better you restore your
+sources and go to manual editing.
+
+editing vpopmail home path
+
+ If your production home path for vpopmail (or whatever you call him) user
+ is NOT /home/vpopmail, you must perform the following additional actions.
+
+ Edit Makefile, changing the line referring to vpopmail's home path and
+ putting the right home path:
+
+ VPOPMAIL_HOME=/home/vpopmail
+
+ Edit conf-cc, changing the string referring to vpopmail's home path and
+ putting the right home path:
+
+ cc -O2 -I/home/vpopmail/include
+
+chkuser settings
+================
+
+Edit chkuser_settings.h, uncommenting the options you prefer, and commenting the
+ones you don't want. Default settings should cover the most of situations.
+
+See the related settings pages for more informations.
+
+Make
+====
+Now, make (or gmake on *BSD) as your usual. No errors (just warnings) should
+come out. If you see any error, better you restore your sources
+and go to manual editing.
+
+Checking
+========
+Select a domain, contained in your rcpthosts, for which bouncing is enabled, and run:
+
+ $ ./qmail-smtpd
+ mail from <wrong_sender>
+ mail from <right_sender>
+ rcpt to: <fake_user@your_domain>
+ rcpt to: <real_user@your_domain>
+
+You should see error and ok messages, depending on the addresses you typed.
+
+Install
+=======
+Copy the new executable in the /var/qmail/bin directory (or make install).
+
+Running
+=======
+This patched qmail-smtpd must be executed in a different way than the normal one.
+See the running pages for detailed instructions.
+
diff -Naur qmail-1.03-original/chkuser.c qmail-1.03/chkuser.c
--- qmail-1.03-original/chkuser.c 1969-12-31 19:00:00.000000000 -0500
+++ qmail-1.03/chkuser.c 2011-01-23 10:40:06.000000000 -0500
@@ -0,0 +1,1258 @@
+
+/*
+ *
+ * 'chkuser.c' v.2.0.9
+ * for qmail/netqmail > 1.0.3 and vpopmail > 5.3.x
+ *
+ * Author: Antonio Nati [email protected]
+ * All rights on this software and
+ * the identifying words chkusr and chkuser reserved by the author
+ *
+ * This software may be freely used, modified and distributed,
+ * but this lines must be kept in every original or derived version.
+ * Original author "Antonio Nati" and the web URL
+ * "http://www.interazioni.it/opensource"
+ * must be indicated in every related work or web page
+ *
+ */
+
+#include <pwd.h>
+
+/* required by vpopmail */
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "dns.h"
+#include "env.h"
+#include "ipme.h"
+#include "now.h"
+#include "str.h"
+#include "open.h"
+#include "subfd.h"
+#include "substdio.h"
+#include "stralloc.h"
+
+#include "vpopmail.h"
+#include "vauth.h"
+#include "vpopmail_config.h"
+
+#include "chkuser.h"
+#include "chkuser_settings.h"
+
+#if defined _exit
+#undef _exit
+#endif
+
+extern void flush();
+extern void out (char *s);
+
+extern char *remotehost;
+extern char *remoteip;
+extern char *remoteinfo;
+extern char *relayclient;
+extern char *fakehelo;
+
+extern void die_nomem();
+
+#define DIE_NOMEM() die_nomem()
+
+#if defined CHKUSER_DEBUG
+
+#if defined CHKUSER_DEBUG_STDERR
+
+#define CHKUSER_DBG(a) write (STDERR_FILENO, a, strlen (a))
+#define CHKUSER_DBG_INT(a) { int x; char str[30]; sprintf (str, "%d", a); write (STDERR_FILENO, str, strlen (str));}
+
+#else
+
+#define CHKUSER_DBG(a) write (STDOUT_FILENO, a, strlen (a))
+#define CHKUSER_DBG_INT(a) { int x; char str[30]; sprintf (str, "%d", a); write (STDOUT_FILENO, str, strlen (str));}
+
+#endif
+#else
+
+#define CHKUSER_DBG(a) /* DBG dummy */
+#define CHKUSER_DBG_INT(a) /* DBG dummy */
+
+#endif
+
+static int intrusion_threshold_reached = 0;
+static int first_time_init_flag = 1;
+
+static int recipients = 0;
+static int wrong_recipients = 0;
+
+static stralloc user = {0};
+static stralloc domain = {0};
+static stralloc domain_path = {0};
+static stralloc tmp_path = {0};
+static stralloc alias_path = {0};
+
+#if defined CHKUSER_IDENTIFY_REMOTE_VARIABLE
+ static char *identify_remote;
+#endif
+
+#if defined CHKUSER_ENABLE_EXTENSIONS
+#define CHKUSER_ENABLE_USERS_EXTENSIONS
+#endif
+
+#if defined CHKUSER_ENABLE_LISTS
+#define CHKUSER_ENABLE_EZMLM_LISTS
+#endif
+
+#if defined CHKUSER_EXTENSION_DASH
+#define CHKUSER_USERS_DASH CHKUSER_EXTENSION_DASH
+#endif
+
+
+#if defined CHKUSER_ENABLE_VALIAS
+#error "chkuser setting error: CHKUSER_ENABLE_VALIAS has been substituted by VALIAS (within vpopmail includes); you don't need anymore this define"
+#endif
+
+#if defined CHKUSER_ENABLE_VAUTH_OPEN
+#error "chkuser setting error: CHKUSER_ENABLE_VAUTH_OPEN has been substituted by CHKUSER_ENABLE_VAUTH_OPEN_CALL; edit chkuser_settings.h and change your settings"
+#endif
+
+#if defined CHKUSER_ENABLE_VAUTH_OPEN_CALL
+ static int db_already_open = 0;
+#endif
+
+#if defined CHKUSER_ALWAYS_ON && defined CHKUSER_STARTING_VARIABLE
+#error "chkuser setting error: CHKUSER_ALWAYS_ON and CHKUSER_STARTING_VARIABLE are mutually esclusive. Edit your chkuser_settings.h and disable one of them"
+#endif
+
+ static int starting_value = 0;
+
+#if defined CHKUSER_STARTING_VARIABLE
+ static char *starting_string = 0;
+#endif
+
+#if defined CHKUSER_EXTRA_MUSTAUTH_VARIABLE
+ static int mustauth_value = 0;
+#endif
+
+
+#if defined CHKUSER_RCPT_LIMIT_VARIABLE
+ static char *maxrcpt_string = 0;
+ static int maxrcpt_limit = 0;
+ static int maxrcpt_limit_reached = 0;
+#endif
+
+#if defined CHKUSER_WRONGRCPT_LIMIT_VARIABLE
+ static char *maxwrongrcpt_string = 0;
+ static int maxwrongrcpt_limit = 0;
+ static int maxwrongrcpt_limit_reached = 0;
+#endif
+
+#if defined CHKUSER_MBXQUOTA_VARIABLE
+ static char *maxmbxquota_string = 0;
+ static int maxmbxquota_limit = 0;
+#endif
+
+ static unsigned int sender_nocheck = 0;
+
+#if defined CHKUSER_SENDER_FORMAT || defined CHKUSER_SENDER_MX
+static stralloc sender_user = {0};
+static stralloc sender_domain = {0};
+#endif
+
+#if defined CHKUSER_ENABLE_DOUBLEBOUNCE_VARIABLE
+static unsigned int enable_doublebounce = 0;
+#endif
+
+#if defined CHKUSER_ERROR_DELAY
+
+ static int chkuser_delay_interval = CHKUSER_ERROR_DELAY * 1000;
+
+#define CHKUSER_DELAY() chkuser_delay()
+
+void chkuser_delay (void) {
+
+ usleep (chkuser_delay_interval);
+
+#if defined CHKUSER_ERROR_DELAY_INCREASE
+ chkuser_delay_interval += CHKUSER_ERROR_DELAY_INCREASE * 1000;
+#endif
+}
+
+#if defined CHKUSER_RCPT_DELAY_ANYERROR
+#define CHKUSER_RCPT_DELAY_ANY() chkuser_delay()
+#else
+#define CHKUSER_RCPT_DELAY_ANY() /* no delay for any error */
+#endif
+
+#if defined CHKUSER_SENDER_DELAY_ANYERROR
+#define CHKUSER_SENDER_DELAY_ANY() chkuser_delay()
+#else
+#define CHKUSER_SENDER_DELAY_ANY() /* no delay for any error */
+#endif
+
+
+#else
+#define CHKUSER_DELAY() /* no delay */
+#define CHKUSER_RCPT_DELAY_ANY() /* no delay */
+#define CHKUSER_SENDER_DELAY_ANY() /* no delay */
+#endif
+
+#if defined CHKUSER_ENABLE_LOGGING
+
+static stralloc logstr = { 0 };
+
+static void chkuser_commonlog (char *sender, char *rcpt, char *title, char *description) {
+
+ substdio_puts (subfderr, "CHKUSER ");
+ substdio_puts (subfderr, title);
+ substdio_puts (subfderr, ": from <");
+ substdio_puts (subfderr, sender);
+ substdio_puts (subfderr, ":" );
+ if (remoteinfo) {
+ substdio_puts (subfderr, remoteinfo);
+ }
+ substdio_puts (subfderr, ":" );
+#if defined CHKUSER_IDENTIFY_REMOTE_VARIABLE
+ if (identify_remote) substdio_puts (subfderr, identify_remote);
+#endif
+ substdio_puts (subfderr, "> remote <");
+ if (fakehelo) substdio_puts (subfderr, fakehelo);
+ substdio_puts (subfderr, ":" );
+ if (remotehost) substdio_puts (subfderr, remotehost);
+ substdio_puts (subfderr, ":" );
+ if (remoteip) substdio_puts (subfderr, remoteip);
+ substdio_puts (subfderr, "> rcpt <");
+ substdio_puts (subfderr, rcpt);
+ substdio_puts (subfderr, "> : ");
+ substdio_puts (subfderr, description);
+ substdio_puts (subfderr, "\n");
+ substdio_flush (subfderr);
+}
+
+#else
+#define chkuser_commonlog(a,b,c,d) /* no log */
+#endif
+
+#if defined CHKUSER_SENDER_FORMAT
+
+static int check_sender_address_format (stralloc *user, stralloc *domain) {
+
+ int x;
+
+ for (x = 0; x < (user->len -1); ++x) {
+ if ((!isalnum (user->s[x]))
+
+#if defined CHKUSER_ALLOW_SENDER_SRS
+ && (user->s[x] != '#')
+ && (user->s[x] != '+')
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_1
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_1)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_2
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_2)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_3
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_3)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_4
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_4)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_5
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_5)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_6
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_6)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_7
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_7)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_8
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_8)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_9
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_9)
+#endif
+#if defined CHKUSER_ALLOW_SENDER_CHAR_10
+ && (user->s[x] != CHKUSER_ALLOW_SENDER_CHAR_10)
+#endif
+ && (user->s[x] != '_') && (user->s[x] != '-') && (user->s[x] != '.') && (user->s[x] != '=')) {
+ return 0;
+ }
+ }
+
+/*
+ * Be careful, this is a base check
+ * Minimum is x.xx + ending \0
+ * Minimum characters needed are 5
+ */
+#if defined CHKUSER_MIN_DOMAIN_LEN
+ if (domain->len < (CHKUSER_MIN_DOMAIN_LEN +1)) {
+ return 0;
+ }
+#endif
+
+/*
+ * This is a safety check
+ */
+#if defined CHKUSER_MIN_DOMAIN_LEN
+ if (domain->len < 2) {
+ return 0;
+ }
+#endif
+
+ for (x = 0; x < (domain->len -1); ++x) {
+ if ((!isalnum (domain->s[x])) && (domain->s[x] != '-') && (domain->s[x] != '.')) {
+ return 0;
+ }
+ }
+
+ if ((domain->s[0] == '-') || (domain->s[domain->len -2] == '-') || (domain->s[0] == '.') || (domain->s[domain->len -2] == '.')) {
+ return 0;
+ }
+ if (strstr (domain->s, "..") != NULL) {
+ return 0;
+ }
+ if (strncmp (domain->s, "xn--", 4) == 0) {
+ if (strstr (&domain->s[4], "--") != NULL)
+ return 0;
+ } else {
+ if (strstr (domain->s, "--") != NULL)
+ return 0;
+ }
+ if (strstr (domain->s, ".-") != NULL) {
+ return 0;
+ }
+ if (strstr (domain->s, "-.") != NULL) {
+ return 0;
+ }
+ if (strchr (domain->s, '.') == NULL) {
+ return 0;
+ }
+
+ return 1;
+}
+
+#endif
+
+#if defined CHKUSER_RCPT_FORMAT
+
+static int check_rcpt_address_format (stralloc *user, stralloc *domain) {
+
+ int x;
+
+ for (x = 0; x < (user->len -1); ++x) {
+ if ((!isalnum (user->s[x]))
+#if defined CHKUSER_ALLOW_RCPT_SRS
+ && (user->s[x] != '#')
+ && (user->s[x] != '+')
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_1
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_1)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_2
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_2)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_3
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_3)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_4
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_4)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_5
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_5)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_6
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_6)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_7
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_7)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_8
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_8)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_9
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_9)
+#endif
+#if defined CHKUSER_ALLOW_RCPT_CHAR_10
+ && (user->s[x] != CHKUSER_ALLOW_RCPT_CHAR_10)
+#endif
+ && (user->s[x] != '_') && (user->s[x] != '-') && (user->s[x] != '.') && (user->s[x] != '=')) {
+ return 0;
+ }
+ }
+
+/*
+ * Be careful, this is a base check
+ * Minimum is x.xx + ending \0
+ * Minimum characters needed are 5
+ */
+#if defined CHKUSER_MIN_DOMAIN_LEN
+ if (domain->len < (CHKUSER_MIN_DOMAIN_LEN +1)) {
+ return 0;
+ }
+#endif
+
+/*
+ * This is a safety check
+ */
+#if defined CHKUSER_MIN_DOMAIN_LEN
+ if (domain->len < 2) {
+ return 0;
+ }
+#endif
+ for (x = 0; x < (domain->len -1); ++x) {
+ if ((!isalnum (domain->s[x])) && (domain->s[x] != '-') && (domain->s[x] != '.')) {
+ return 0;
+ }
+ }
+
+ if ((domain->s[0] == '-') || (domain->s[domain->len -2] == '-') || (domain->s[0] == '.') || (domain->s[domain->len -2] == '.')) {
+ return 0;
+ }
+ if (strstr (domain->s, "..") != NULL) {
+ return 0;
+ }
+ if (strncmp (domain->s, "xn--", 4) == 0) {
+ if (strstr (&domain->s[4], "--") != NULL)
+ return 0;
+ } else {
+ if (strstr (domain->s, "--") != NULL)
+ return 0;
+ }
+ if (strstr (domain->s, ".-") != NULL) {
+ return 0;
+ }
+ if (strstr (domain->s, "-.") != NULL) {
+ return 0;
+ }
+ if (strchr (domain->s, '.') == NULL) {
+ return 0;
+ }
+
+ return 1;
+}
+
+#endif
+
+#if defined CHKUSER_SENDER_MX || defined CHKUSER_RCPT_MX
+
+static unsigned long mx_random;
+static ipalloc mx_ip = {0};
+
+static int chkuser_mx_lookup (stralloc *domain) {
+
+ int status;
+
+ mx_random = now() + getpid();
+ dns_init(0);
+ status = dns_mxip (&mx_ip, domain, mx_random);
+
+ if (status == DNS_MEM) DIE_NOMEM();
+
+ return status;
+}
+
+#endif
+
+
+void chkuser_cleanup (int exit_value) {
+
+#if defined CHKUSER_DB_CLEANUP
+ vclose ();
+#endif
+ _exit (exit_value);
+}
+
+static void first_time_init (void) {
+
+ starting_value = 0;
+
+#if defined CHKUSER_ALWAYS_ON
+ starting_value = 1;
+#endif
+
+#if defined CHKUSER_STARTING_VARIABLE
+ starting_string = env_get (CHKUSER_STARTING_VARIABLE);
+ if (starting_string) {
+ if (strcasecmp(starting_string, "ALWAYS") == 0) {
+ starting_value = 1;
+ } else if (strcasecmp(starting_string, "DOMAIN") == 0) {
+ starting_value = 0;
+ }
+ } else {
+ starting_string = "";
+ starting_value = -1;
+ }
+#endif
+
+#if defined CHKUSER_DISABLE_VARIABLE
+ if (env_get (CHKUSER_DISABLE_VARIABLE)) {
+ starting_value = -1;
+ }
+#endif
+
+#if defined CHKUSER_EXTRA_MUSTAUTH_VARIABLE
+ if (env_get (CHKUSER_EXTRA_MUSTAUTH_VARIABLE)) {
+ if (relayclient) {
+ mustauth_value = 0;
+ } else {
+ mustauth_value = 1;
+ }
+ }
+#endif
+
+
+#if defined CHKUSER_RCPT_LIMIT_VARIABLE
+ maxrcpt_string = env_get (CHKUSER_RCPT_LIMIT_VARIABLE);
+ if (maxrcpt_string) {
+ maxrcpt_limit = atoi (maxrcpt_string);
+ if (maxrcpt_limit < 1) {
+ maxrcpt_limit = 0;
+ }
+ } else {
+ maxrcpt_string = "";;
+ }
+#endif
+
+#if defined CHKUSER_WRONGRCPT_LIMIT_VARIABLE
+ maxwrongrcpt_string = env_get (CHKUSER_WRONGRCPT_LIMIT_VARIABLE);
+ if (maxwrongrcpt_string) {
+ maxwrongrcpt_limit = atoi (maxwrongrcpt_string);
+ if (maxwrongrcpt_limit < 1) {
+ maxwrongrcpt_limit = 0;
+ }
+ } else {
+ maxwrongrcpt_string = "";
+ }
+#endif
+
+#if defined CHKUSER_MBXQUOTA_VARIABLE
+ maxmbxquota_string = env_get (CHKUSER_MBXQUOTA_VARIABLE);
+ if (maxmbxquota_string) {
+ maxmbxquota_limit = atoi (maxmbxquota_string);
+ if (maxmbxquota_limit < 1) {
+ maxmbxquota_limit = 0;
+ }
+ } else {
+ maxmbxquota_string = "";
+ }
+#endif
+
+#if defined CHKUSER_SENDER_NOCHECK_VARIABLE
+
+ if (env_get (CHKUSER_SENDER_NOCHECK_VARIABLE)) {
+ sender_nocheck = 1;
+ } else {
+ sender_nocheck = 0;
+ }
+#endif
+
+#if defined CHKUSER_IDENTIFY_REMOTE_VARIABLE
+
+ identify_remote = env_get (CHKUSER_IDENTIFY_REMOTE_VARIABLE);
+#endif
+
+
+#if defined CHKUSER_ENABLE_DOUBLEBOUNCE_VARIABLE
+
+ if (env_get (CHKUSER_ENABLE_DOUBLEBOUNCE_VARIABLE)) {
+ enable_doublebounce = 1;
+ } else {
+ enable_doublebounce = 0;
+ }
+#endif
+
+ if (!stralloc_ready (&user, 300)) DIE_NOMEM();
+ if (!stralloc_ready (&domain, 500)) DIE_NOMEM();
+ if (!stralloc_ready (&domain_path, 1000)) DIE_NOMEM();
+ if (!stralloc_ready (&tmp_path, 1000)) DIE_NOMEM();
+ if (!stralloc_ready (&alias_path, 1000)) DIE_NOMEM();
+
+ first_time_init_flag = 0;
+
+}
+
+/*
+ * realrcpt ()
+ *
+ * Returns:
+ *
+ * CHKUSER_OK = 1 = Ok, recipients does exists
+ *
+ * 0 = Not in rcpthosts
+ *
+ * < 0 various errors
+ *
+ *
+ * Parameters:
+ * stralloc *sender = sender address
+ * stralloc *rcpt = rcpt address to check
+ *
+ *
+*/
+
+static int realrcpt (stralloc *sender, stralloc *rcpt)
+{
+ int count;
+ int retstat = CHKUSER_KO;
+ struct vqpasswd *user_passwd = NULL;
+ int fd_file = -1;
+ int read_char;
+ int offset;
+ char read_buf[1024];
+
+#if defined CHKUSER_ENABLE_UIDGID
+ uid_t eff_uid;
+ gid_t eff_gid;
+#endif
+
+#if defined CHKUSER_EXTRA_MUSTAUTH_VARIABLE
+ if (mustauth_value == 1) {
+ return CHKUSER_ERR_MUSTAUTH;
+ }
+#endif
+
+
+ if (starting_value == -1) {
+ if (addrallowed()) {
+ return CHKUSER_OK_NOCHECKALL;
+ } else {
+ if (relayclient) {
+ return CHKUSER_RELAYING;
+ }
+ return CHKUSER_NORCPTHOSTS;
+ }
+ }
+
+ if (intrusion_threshold_reached == 1) {