/
acl.c
4966 lines (4153 loc) · 144 KB
/
acl.c
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
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
/* Copyright (c) The Exim Maintainers 2020 - 2023 */
/* Copyright (c) University of Cambridge 1995 - 2018 */
/* See the file NOTICE for conditions of use and distribution. */
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Code for handling Access Control Lists (ACLs) */
#include "exim.h"
#ifndef MACRO_PREDEF
/* Default callout timeout */
#define CALLOUT_TIMEOUT_DEFAULT 30
/* Default quota cache TTLs */
#define QUOTA_POS_DEFAULT (5*60)
#define QUOTA_NEG_DEFAULT (60*60)
/* ACL verb codes - keep in step with the table of verbs that follows */
enum { ACL_ACCEPT, ACL_DEFER, ACL_DENY, ACL_DISCARD, ACL_DROP, ACL_REQUIRE,
ACL_WARN };
/* ACL verbs */
static uschar *verbs[] = {
[ACL_ACCEPT] = US"accept",
[ACL_DEFER] = US"defer",
[ACL_DENY] = US"deny",
[ACL_DISCARD] = US"discard",
[ACL_DROP] = US"drop",
[ACL_REQUIRE] = US"require",
[ACL_WARN] = US"warn"
};
/* For each verb, the conditions for which "message" or "log_message" are used
are held as a bitmap. This is to avoid expanding the strings unnecessarily. For
"accept", the FAIL case is used only after "endpass", but that is selected in
the code. */
static int msgcond[] = {
[ACL_ACCEPT] = BIT(OK) | BIT(FAIL) | BIT(FAIL_DROP),
[ACL_DEFER] = BIT(OK),
[ACL_DENY] = BIT(OK),
[ACL_DISCARD] = BIT(OK) | BIT(FAIL) | BIT(FAIL_DROP),
[ACL_DROP] = BIT(OK),
[ACL_REQUIRE] = BIT(FAIL) | BIT(FAIL_DROP),
[ACL_WARN] = BIT(OK)
};
#endif
/* ACL condition and modifier codes - keep in step with the table that
follows.
down. */
enum { ACLC_ACL,
ACLC_ADD_HEADER,
ACLC_AUTHENTICATED,
#ifdef EXPERIMENTAL_BRIGHTMAIL
ACLC_BMI_OPTIN,
#endif
ACLC_CONDITION,
ACLC_CONTINUE,
ACLC_CONTROL,
#ifdef EXPERIMENTAL_DCC
ACLC_DCC,
#endif
#ifdef WITH_CONTENT_SCAN
ACLC_DECODE,
#endif
ACLC_DELAY,
#ifndef DISABLE_DKIM
ACLC_DKIM_SIGNER,
ACLC_DKIM_STATUS,
#endif
#ifdef SUPPORT_DMARC
ACLC_DMARC_STATUS,
#endif
ACLC_DNSLISTS,
ACLC_DOMAINS,
ACLC_ENCRYPTED,
ACLC_ENDPASS,
ACLC_HOSTS,
ACLC_LOCAL_PARTS,
ACLC_LOG_MESSAGE,
ACLC_LOG_REJECT_TARGET,
ACLC_LOGWRITE,
#ifdef WITH_CONTENT_SCAN
ACLC_MALWARE,
#endif
ACLC_MESSAGE,
#ifdef WITH_CONTENT_SCAN
ACLC_MIME_REGEX,
#endif
ACLC_QUEUE,
ACLC_RATELIMIT,
ACLC_RECIPIENTS,
#ifdef WITH_CONTENT_SCAN
ACLC_REGEX,
#endif
ACLC_REMOVE_HEADER,
ACLC_SEEN,
ACLC_SENDER_DOMAINS,
ACLC_SENDERS,
ACLC_SET,
#ifdef WITH_CONTENT_SCAN
ACLC_SPAM,
#endif
#ifdef SUPPORT_SPF
ACLC_SPF,
ACLC_SPF_GUESS,
#endif
ACLC_UDPSEND,
ACLC_VERIFY };
/* ACL conditions/modifiers: "delay", "control", "continue", "endpass",
"message", "log_message", "log_reject_target", "logwrite", "queue" and "set" are
modifiers that look like conditions but always return TRUE. They are used for
their side effects. Do not invent new modifier names that result in one name
being the prefix of another; the binary-search in the list will go wrong. */
typedef struct condition_def {
uschar *name;
/* Flag to indicate the condition/modifier has a string expansion done
at the outer level. In the other cases, expansion already occurs in the
checking functions. */
BOOL expand_at_top:1;
BOOL is_modifier:1;
/* Bit map vector of which conditions and modifiers are not allowed at certain
times. For each condition and modifier, there's a bitmap of dis-allowed times.
For some, it is easier to specify the negation of a small number of allowed
times. */
unsigned forbids;
} condition_def;
static condition_def conditions[] = {
[ACLC_ACL] = { US"acl", FALSE, FALSE, 0 },
[ACLC_ADD_HEADER] = { US"add_header", TRUE, TRUE,
(unsigned int)
~(ACL_BIT_MAIL | ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
#ifndef DISABLE_PRDR
ACL_BIT_PRDR |
#endif
ACL_BIT_MIME | ACL_BIT_NOTSMTP |
ACL_BIT_DKIM |
ACL_BIT_NOTSMTP_START),
},
[ACLC_AUTHENTICATED] = { US"authenticated", FALSE, FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START |
ACL_BIT_CONNECT | ACL_BIT_HELO,
},
#ifdef EXPERIMENTAL_BRIGHTMAIL
[ACLC_BMI_OPTIN] = { US"bmi_optin", TRUE, TRUE,
ACL_BIT_AUTH |
ACL_BIT_CONNECT | ACL_BIT_HELO |
ACL_BIT_DATA | ACL_BIT_MIME |
# ifndef DISABLE_PRDR
ACL_BIT_PRDR |
# endif
ACL_BIT_ETRN | ACL_BIT_EXPN |
ACL_BIT_MAILAUTH |
ACL_BIT_MAIL | ACL_BIT_STARTTLS |
ACL_BIT_VRFY | ACL_BIT_PREDATA |
ACL_BIT_NOTSMTP_START,
},
#endif
[ACLC_CONDITION] = { US"condition", TRUE, FALSE, 0 },
[ACLC_CONTINUE] = { US"continue", TRUE, TRUE, 0 },
/* Certain types of control are always allowed, so we let it through
always and check in the control processing itself. */
[ACLC_CONTROL] = { US"control", TRUE, TRUE, 0 },
#ifdef EXPERIMENTAL_DCC
[ACLC_DCC] = { US"dcc", TRUE, FALSE,
(unsigned int)
~(ACL_BIT_DATA |
# ifndef DISABLE_PRDR
ACL_BIT_PRDR |
# endif
ACL_BIT_NOTSMTP),
},
#endif
#ifdef WITH_CONTENT_SCAN
[ACLC_DECODE] = { US"decode", TRUE, FALSE, (unsigned int) ~ACL_BIT_MIME },
#endif
[ACLC_DELAY] = { US"delay", TRUE, TRUE, ACL_BIT_NOTQUIT },
#ifndef DISABLE_DKIM
[ACLC_DKIM_SIGNER] = { US"dkim_signers", TRUE, FALSE, (unsigned int) ~ACL_BIT_DKIM },
[ACLC_DKIM_STATUS] = { US"dkim_status", TRUE, FALSE,
(unsigned int)
~(ACL_BIT_DKIM | ACL_BIT_DATA | ACL_BIT_MIME
# ifndef DISABLE_PRDR
| ACL_BIT_PRDR
# endif
),
},
#endif
#ifdef SUPPORT_DMARC
[ACLC_DMARC_STATUS] = { US"dmarc_status", TRUE, FALSE, (unsigned int) ~ACL_BIT_DATA },
#endif
/* Explicit key lookups can be made in non-smtp ACLs so pass
always and check in the verify processing itself. */
[ACLC_DNSLISTS] = { US"dnslists", TRUE, FALSE, 0 },
[ACLC_DOMAINS] = { US"domains", FALSE, FALSE,
(unsigned int)
~(ACL_BIT_RCPT | ACL_BIT_VRFY
#ifndef DISABLE_PRDR
|ACL_BIT_PRDR
#endif
),
},
[ACLC_ENCRYPTED] = { US"encrypted", FALSE, FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START |
ACL_BIT_CONNECT
},
[ACLC_ENDPASS] = { US"endpass", TRUE, TRUE, 0 },
[ACLC_HOSTS] = { US"hosts", FALSE, FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START,
},
[ACLC_LOCAL_PARTS] = { US"local_parts", FALSE, FALSE,
(unsigned int)
~(ACL_BIT_RCPT | ACL_BIT_VRFY
#ifndef DISABLE_PRDR
| ACL_BIT_PRDR
#endif
),
},
[ACLC_LOG_MESSAGE] = { US"log_message", TRUE, TRUE, 0 },
[ACLC_LOG_REJECT_TARGET] = { US"log_reject_target", TRUE, TRUE, 0 },
[ACLC_LOGWRITE] = { US"logwrite", TRUE, TRUE, 0 },
#ifdef WITH_CONTENT_SCAN
[ACLC_MALWARE] = { US"malware", TRUE, FALSE,
(unsigned int)
~(ACL_BIT_DATA |
# ifndef DISABLE_PRDR
ACL_BIT_PRDR |
# endif
ACL_BIT_NOTSMTP),
},
#endif
[ACLC_MESSAGE] = { US"message", TRUE, TRUE, 0 },
#ifdef WITH_CONTENT_SCAN
[ACLC_MIME_REGEX] = { US"mime_regex", TRUE, FALSE, (unsigned int) ~ACL_BIT_MIME },
#endif
[ACLC_QUEUE] = { US"queue", TRUE, TRUE,
ACL_BIT_NOTSMTP |
#ifndef DISABLE_PRDR
ACL_BIT_PRDR |
#endif
ACL_BIT_DATA,
},
[ACLC_RATELIMIT] = { US"ratelimit", TRUE, FALSE, 0 },
[ACLC_RECIPIENTS] = { US"recipients", FALSE, FALSE, (unsigned int) ~ACL_BIT_RCPT },
#ifdef WITH_CONTENT_SCAN
[ACLC_REGEX] = { US"regex", TRUE, FALSE,
(unsigned int)
~(ACL_BIT_DATA |
# ifndef DISABLE_PRDR
ACL_BIT_PRDR |
# endif
ACL_BIT_NOTSMTP |
ACL_BIT_MIME),
},
#endif
[ACLC_REMOVE_HEADER] = { US"remove_header", TRUE, TRUE,
(unsigned int)
~(ACL_BIT_MAIL|ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
#ifndef DISABLE_PRDR
ACL_BIT_PRDR |
#endif
ACL_BIT_MIME | ACL_BIT_NOTSMTP |
ACL_BIT_NOTSMTP_START),
},
[ACLC_SEEN] = { US"seen", TRUE, FALSE, 0 },
[ACLC_SENDER_DOMAINS] = { US"sender_domains", FALSE, FALSE,
ACL_BIT_AUTH | ACL_BIT_CONNECT |
ACL_BIT_HELO |
ACL_BIT_MAILAUTH | ACL_BIT_QUIT |
ACL_BIT_ETRN | ACL_BIT_EXPN |
ACL_BIT_STARTTLS | ACL_BIT_VRFY,
},
[ACLC_SENDERS] = { US"senders", FALSE, FALSE,
ACL_BIT_AUTH | ACL_BIT_CONNECT |
ACL_BIT_HELO |
ACL_BIT_MAILAUTH | ACL_BIT_QUIT |
ACL_BIT_ETRN | ACL_BIT_EXPN |
ACL_BIT_STARTTLS | ACL_BIT_VRFY,
},
[ACLC_SET] = { US"set", TRUE, TRUE, 0 },
#ifdef WITH_CONTENT_SCAN
[ACLC_SPAM] = { US"spam", TRUE, FALSE,
(unsigned int) ~(ACL_BIT_DATA |
# ifndef DISABLE_PRDR
ACL_BIT_PRDR |
# endif
ACL_BIT_NOTSMTP),
},
#endif
#ifdef SUPPORT_SPF
[ACLC_SPF] = { US"spf", TRUE, FALSE,
ACL_BIT_AUTH | ACL_BIT_CONNECT |
ACL_BIT_HELO | ACL_BIT_MAILAUTH |
ACL_BIT_ETRN | ACL_BIT_EXPN |
ACL_BIT_STARTTLS | ACL_BIT_VRFY |
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START,
},
[ACLC_SPF_GUESS] = { US"spf_guess", TRUE, FALSE,
ACL_BIT_AUTH | ACL_BIT_CONNECT |
ACL_BIT_HELO | ACL_BIT_MAILAUTH |
ACL_BIT_ETRN | ACL_BIT_EXPN |
ACL_BIT_STARTTLS | ACL_BIT_VRFY |
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START,
},
#endif
[ACLC_UDPSEND] = { US"udpsend", TRUE, TRUE, 0 },
/* Certain types of verify are always allowed, so we let it through
always and check in the verify function itself */
[ACLC_VERIFY] = { US"verify", TRUE, FALSE, 0 },
};
#ifdef MACRO_PREDEF
# include "macro_predef.h"
void
features_acl(void)
{
for (condition_def * c = conditions; c < conditions + nelem(conditions); c++)
{
uschar buf[64], * p, * s;
int n = sprintf(CS buf, "_ACL_%s_", c->is_modifier ? "MOD" : "COND");
for (p = buf + n, s = c->name; *s; s++) *p++ = toupper(*s);
*p = '\0';
builtin_macro_create(buf);
}
}
#endif
#ifndef MACRO_PREDEF
/* Return values from decode_control(); used as index so keep in step
with the controls_list table that follows! */
enum {
CONTROL_AUTH_UNADVERTISED,
#ifdef EXPERIMENTAL_BRIGHTMAIL
CONTROL_BMI_RUN,
#endif
CONTROL_CASEFUL_LOCAL_PART,
CONTROL_CASELOWER_LOCAL_PART,
CONTROL_CUTTHROUGH_DELIVERY,
CONTROL_DEBUG,
#ifndef DISABLE_DKIM
CONTROL_DKIM_VERIFY,
#endif
#ifdef SUPPORT_DMARC
CONTROL_DMARC_VERIFY,
CONTROL_DMARC_FORENSIC,
#endif
CONTROL_DSCP,
CONTROL_ENFORCE_SYNC,
CONTROL_ERROR, /* pseudo-value for decode errors */
CONTROL_FAKEDEFER,
CONTROL_FAKEREJECT,
CONTROL_FREEZE,
CONTROL_NO_CALLOUT_FLUSH,
CONTROL_NO_DELAY_FLUSH,
CONTROL_NO_ENFORCE_SYNC,
#ifdef WITH_CONTENT_SCAN
CONTROL_NO_MBOX_UNSPOOL,
#endif
CONTROL_NO_MULTILINE,
CONTROL_NO_PIPELINING,
CONTROL_QUEUE,
CONTROL_SUBMISSION,
CONTROL_SUPPRESS_LOCAL_FIXUPS,
#ifdef SUPPORT_I18N
CONTROL_UTF8_DOWNCONVERT,
#endif
};
/* Structure listing various control arguments, with their characteristics.
For each control, there's a bitmap of dis-allowed times. For some, it is easier
to specify the negation of a small number of allowed times. */
typedef struct control_def {
uschar *name;
BOOL has_option; /* Has /option(s) following */
unsigned forbids; /* bitmap of dis-allowed times */
} control_def;
static control_def controls_list[] = {
/* name has_option forbids */
[CONTROL_AUTH_UNADVERTISED] =
{ US"allow_auth_unadvertised", FALSE,
(unsigned)
~(ACL_BIT_CONNECT | ACL_BIT_HELO)
},
#ifdef EXPERIMENTAL_BRIGHTMAIL
[CONTROL_BMI_RUN] =
{ US"bmi_run", FALSE, 0 },
#endif
[CONTROL_CASEFUL_LOCAL_PART] =
{ US"caseful_local_part", FALSE, (unsigned) ~ACL_BIT_RCPT },
[CONTROL_CASELOWER_LOCAL_PART] =
{ US"caselower_local_part", FALSE, (unsigned) ~ACL_BIT_RCPT },
[CONTROL_CUTTHROUGH_DELIVERY] =
{ US"cutthrough_delivery", TRUE, 0 },
[CONTROL_DEBUG] =
{ US"debug", TRUE, 0 },
#ifndef DISABLE_DKIM
[CONTROL_DKIM_VERIFY] =
{ US"dkim_disable_verify", FALSE,
ACL_BIT_DATA | ACL_BIT_NOTSMTP |
# ifndef DISABLE_PRDR
ACL_BIT_PRDR |
# endif
ACL_BIT_NOTSMTP_START
},
#endif
#ifdef SUPPORT_DMARC
[CONTROL_DMARC_VERIFY] =
{ US"dmarc_disable_verify", FALSE,
ACL_BIT_DATA | ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
[CONTROL_DMARC_FORENSIC] =
{ US"dmarc_enable_forensic", FALSE,
ACL_BIT_DATA | ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
#endif
[CONTROL_DSCP] =
{ US"dscp", TRUE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START | ACL_BIT_NOTQUIT
},
[CONTROL_ENFORCE_SYNC] =
{ US"enforce_sync", FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
/* Pseudo-value for decode errors */
[CONTROL_ERROR] =
{ US"error", FALSE, 0 },
[CONTROL_FAKEDEFER] =
{ US"fakedefer", TRUE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
#ifndef DISABLE_PRDR
ACL_BIT_PRDR |
#endif
ACL_BIT_MIME)
},
[CONTROL_FAKEREJECT] =
{ US"fakereject", TRUE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
#ifndef DISABLE_PRDR
ACL_BIT_PRDR |
#endif
ACL_BIT_MIME)
},
[CONTROL_FREEZE] =
{ US"freeze", TRUE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
// ACL_BIT_PRDR| /* Not allow one user to freeze for all */
ACL_BIT_NOTSMTP | ACL_BIT_MIME)
},
[CONTROL_NO_CALLOUT_FLUSH] =
{ US"no_callout_flush", FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
[CONTROL_NO_DELAY_FLUSH] =
{ US"no_delay_flush", FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
[CONTROL_NO_ENFORCE_SYNC] =
{ US"no_enforce_sync", FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
#ifdef WITH_CONTENT_SCAN
[CONTROL_NO_MBOX_UNSPOOL] =
{ US"no_mbox_unspool", FALSE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
// ACL_BIT_PRDR| /* Not allow one user to freeze for all */
ACL_BIT_MIME)
},
#endif
[CONTROL_NO_MULTILINE] =
{ US"no_multiline_responses", FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
[CONTROL_NO_PIPELINING] =
{ US"no_pipelining", FALSE,
ACL_BIT_NOTSMTP | ACL_BIT_NOTSMTP_START
},
[CONTROL_QUEUE] =
{ US"queue", TRUE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT |
ACL_BIT_PREDATA | ACL_BIT_DATA |
// ACL_BIT_PRDR| /* Not allow one user to freeze for all */
ACL_BIT_NOTSMTP | ACL_BIT_MIME)
},
[CONTROL_SUBMISSION] =
{ US"submission", TRUE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT | ACL_BIT_PREDATA)
},
[CONTROL_SUPPRESS_LOCAL_FIXUPS] =
{ US"suppress_local_fixups", FALSE,
(unsigned)
~(ACL_BIT_MAIL | ACL_BIT_RCPT | ACL_BIT_PREDATA |
ACL_BIT_NOTSMTP_START)
},
#ifdef SUPPORT_I18N
[CONTROL_UTF8_DOWNCONVERT] =
{ US"utf8_downconvert", TRUE, (unsigned) ~(ACL_BIT_RCPT | ACL_BIT_VRFY)
}
#endif
};
/* Support data structures for Client SMTP Authorization. acl_verify_csa()
caches its result in a tree to avoid repeated DNS queries. The result is an
integer code which is used as an index into the following tables of
explanatory strings and verification return codes. */
static tree_node *csa_cache = NULL;
enum { CSA_UNKNOWN, CSA_OK, CSA_DEFER_SRV, CSA_DEFER_ADDR,
CSA_FAIL_EXPLICIT, CSA_FAIL_DOMAIN, CSA_FAIL_NOADDR, CSA_FAIL_MISMATCH };
/* The acl_verify_csa() return code is translated into an acl_verify() return
code using the following table. It is OK unless the client is definitely not
authorized. This is because CSA is supposed to be optional for sending sites,
so recipients should not be too strict about checking it - especially because
DNS problems are quite likely to occur. It's possible to use $csa_status in
further ACL conditions to distinguish ok, unknown, and defer if required, but
the aim is to make the usual configuration simple. */
static int csa_return_code[] = {
[CSA_UNKNOWN] = OK,
[CSA_OK] = OK,
[CSA_DEFER_SRV] = OK,
[CSA_DEFER_ADDR] = OK,
[CSA_FAIL_EXPLICIT] = FAIL,
[CSA_FAIL_DOMAIN] = FAIL,
[CSA_FAIL_NOADDR] = FAIL,
[CSA_FAIL_MISMATCH] = FAIL
};
static uschar *csa_status_string[] = {
[CSA_UNKNOWN] = US"unknown",
[CSA_OK] = US"ok",
[CSA_DEFER_SRV] = US"defer",
[CSA_DEFER_ADDR] = US"defer",
[CSA_FAIL_EXPLICIT] = US"fail",
[CSA_FAIL_DOMAIN] = US"fail",
[CSA_FAIL_NOADDR] = US"fail",
[CSA_FAIL_MISMATCH] = US"fail"
};
static uschar *csa_reason_string[] = {
[CSA_UNKNOWN] = US"unknown",
[CSA_OK] = US"ok",
[CSA_DEFER_SRV] = US"deferred (SRV lookup failed)",
[CSA_DEFER_ADDR] = US"deferred (target address lookup failed)",
[CSA_FAIL_EXPLICIT] = US"failed (explicit authorization required)",
[CSA_FAIL_DOMAIN] = US"failed (host name not authorized)",
[CSA_FAIL_NOADDR] = US"failed (no authorized addresses)",
[CSA_FAIL_MISMATCH] = US"failed (client address mismatch)"
};
/* Options for the ratelimit condition. Note that there are two variants of
the per_rcpt option, depending on the ACL that is used to measure the rate.
However any ACL must be able to look up per_rcpt rates in /noupdate mode,
so the two variants must have the same internal representation as well as
the same configuration string. */
enum {
RATE_PER_WHAT, RATE_PER_CLASH, RATE_PER_ADDR, RATE_PER_BYTE, RATE_PER_CMD,
RATE_PER_CONN, RATE_PER_MAIL, RATE_PER_RCPT, RATE_PER_ALLRCPTS
};
#define RATE_SET(var,new) \
(((var) == RATE_PER_WHAT) ? ((var) = RATE_##new) : ((var) = RATE_PER_CLASH))
static uschar *ratelimit_option_string[] = {
[RATE_PER_WHAT] = US"?",
[RATE_PER_CLASH] = US"!",
[RATE_PER_ADDR] = US"per_addr",
[RATE_PER_BYTE] = US"per_byte",
[RATE_PER_CMD] = US"per_cmd",
[RATE_PER_CONN] = US"per_conn",
[RATE_PER_MAIL] = US"per_mail",
[RATE_PER_RCPT] = US"per_rcpt",
[RATE_PER_ALLRCPTS] = US"per_rcpt"
};
/* Enable recursion between acl_check_internal() and acl_check_condition() */
static int acl_check_wargs(int, address_item *, const uschar *, uschar **,
uschar **);
static acl_block * acl_current = NULL;
/*************************************************
* Find control in list *
*************************************************/
/* The lists are always in order, so binary chop can be used.
Arguments:
name the control name to search for
ol the first entry in the control list
last one more than the offset of the last entry in the control list
Returns: index of a control entry, or -1 if not found
*/
static int
find_control(const uschar * name, control_def * ol, int last)
{
for (int first = 0; last > first; )
{
int middle = (first + last)/2;
uschar * s = ol[middle].name;
int c = Ustrncmp(name, s, Ustrlen(s));
if (c == 0) return middle;
else if (c > 0) first = middle + 1;
else last = middle;
}
return -1;
}
/*************************************************
* Pick out condition from list *
*************************************************/
/* Use a binary chop method
Arguments:
name name to find
list list of conditions
end size of list
Returns: offset in list, or -1 if not found
*/
static int
acl_checkcondition(uschar * name, condition_def * list, int end)
{
for (int start = 0; start < end; )
{
int mid = (start + end)/2;
int c = Ustrcmp(name, list[mid].name);
if (c == 0) return mid;
if (c < 0) end = mid;
else start = mid + 1;
}
return -1;
}
/*************************************************
* Pick out name from list *
*************************************************/
/* Use a binary chop method
Arguments:
name name to find
list list of names
end size of list
Returns: offset in list, or -1 if not found
*/
static int
acl_checkname(uschar *name, uschar **list, int end)
{
for (int start = 0; start < end; )
{
int mid = (start + end)/2;
int c = Ustrcmp(name, list[mid]);
if (c == 0) return mid;
if (c < 0) end = mid; else start = mid + 1;
}
return -1;
}
static BOOL
acl_varname_to_cond(const uschar ** sp, acl_condition_block * cond, uschar ** error)
{
const uschar * s = *sp, * endptr;
#ifndef DISABLE_DKIM
if ( Ustrncmp(s, "dkim_verify_status", 18) == 0
|| Ustrncmp(s, "dkim_verify_reason", 18) == 0)
{
endptr = s+18;
if (isalnum(*endptr))
{
*error = string_sprintf("invalid variable name after \"set\" in ACL "
"modifier \"set %s\" "
"(only \"dkim_verify_status\" or \"dkim_verify_reason\" permitted)",
s);
return FALSE;
}
cond->u.varname = string_copyn(s, 18);
}
else
#endif
{
if (Ustrncmp(s, "acl_c", 5) != 0 && Ustrncmp(s, "acl_m", 5) != 0)
{
*error = string_sprintf("invalid variable name after \"set\" in ACL "
"modifier \"set %s\" (must start \"acl_c\" or \"acl_m\")", s);
return FALSE;
}
endptr = s + 5;
if (!isdigit(*endptr) && *endptr != '_')
{
*error = string_sprintf("invalid variable name after \"set\" in ACL "
"modifier \"set %s\" (digit or underscore must follow acl_c or acl_m)",
s);
return FALSE;
}
for ( ; *endptr && *endptr != '=' && !isspace(*endptr); endptr++)
if (!isalnum(*endptr) && *endptr != '_')
{
*error = string_sprintf("invalid character \"%c\" in variable name "
"in ACL modifier \"set %s\"", *endptr, s);
return FALSE;
}
cond->u.varname = string_copyn(s + 4, endptr - s - 4);
}
s = endptr;
Uskip_whitespace(&s);
*sp = s;
return TRUE;
}
static BOOL
acl_data_to_cond(const uschar * s, acl_condition_block * cond,
const uschar * name, uschar ** error)
{
if (*s++ != '=')
{
*error = string_sprintf("\"=\" missing after ACL \"%s\" %s", name,
conditions[cond->type].is_modifier ? US"modifier" : US"condition");
return FALSE;;
}
Uskip_whitespace(&s);
cond->arg = string_copy(s);
return TRUE;
}
/*************************************************
* Read and parse one ACL *
*************************************************/
/* This function is called both from readconf in order to parse the ACLs in the
configuration file, and also when an ACL is encountered dynamically (e.g. as
the result of an expansion). It is given a function to call in order to
retrieve the lines of the ACL. This function handles skipping comments and
blank lines (where relevant).
Arguments:
func function to get next line of ACL
error where to put an error message
Returns: pointer to ACL, or NULL
NULL can be legal (empty ACL); in this case error will be NULL
*/
acl_block *
acl_read(uschar *(*func)(void), uschar **error)
{
acl_block *yield = NULL;
acl_block **lastp = &yield;
acl_block *this = NULL;
acl_condition_block *cond;
acl_condition_block **condp = NULL;
const uschar * s;
*error = NULL;
while ((s = (*func)()))
{
int v, c;
BOOL negated = FALSE;
const uschar * saveline = s;
uschar name[EXIM_DRIVERNAME_MAX];
/* Conditions (but not verbs) are allowed to be negated by an initial
exclamation mark. */
if (Uskip_whitespace(&s) == '!')
{
negated = TRUE;
s++;
}
/* Read the name of a verb or a condition, or the start of a new ACL, which
can be started by a name, or by a macro definition. */
s = readconf_readname(name, sizeof(name), s);
if (*s == ':' || (isupper(name[0]) && *s == '=')) return yield;
/* If a verb is unrecognized, it may be another condition or modifier that
continues the previous verb. */
if ((v = acl_checkname(name, verbs, nelem(verbs))) < 0)
{
if (!this)
{
*error = string_sprintf("unknown ACL verb \"%s\" in \"%s\"", name,
saveline);
return NULL;
}
}
/* New verb */
else
{
if (negated)
{
*error = string_sprintf("malformed ACL line \"%s\"", saveline);
return NULL;
}
*lastp = this = store_get(sizeof(acl_block), GET_UNTAINTED);
lastp = &this->next;
this->next = NULL;
this->condition = NULL;
this->verb = v;
this->srcline = config_lineno; /* for debug output */
this->srcfile = config_filename; /**/
condp = &this->condition;
if (!*s) continue; /* No condition on this line */
if (*s == '!')
{
negated = TRUE;
s++;
}
s = readconf_readname(name, sizeof(name), s); /* Condition name */
}
/* Handle a condition or modifier. */
if ((c = acl_checkcondition(name, conditions, nelem(conditions))) < 0)
{
*error = string_sprintf("unknown ACL condition/modifier in \"%s\"",
saveline);
return NULL;
}
/* The modifiers may not be negated */
if (negated && conditions[c].is_modifier)
{
*error = string_sprintf("ACL error: negation is not allowed with "
"\"%s\"", conditions[c].name);
return NULL;
}
/* ENDPASS may occur only with ACCEPT or DISCARD. */
if (c == ACLC_ENDPASS &&
this->verb != ACL_ACCEPT &&
this->verb != ACL_DISCARD)
{
*error = string_sprintf("ACL error: \"%s\" is not allowed with \"%s\"",
conditions[c].name, verbs[this->verb]);
return NULL;
}
cond = store_get(sizeof(acl_condition_block), GET_UNTAINTED);
cond->next = NULL;
cond->type = c;
cond->u.negated = negated;
*condp = cond;
condp = &cond->next;
/* The "set" modifier is different in that its argument is "name=value"
rather than just a value, and we can check the validity of the name, which
gives us a variable name to insert into the data block. The original ACL
variable names were acl_c0 ... acl_c9 and acl_m0 ... acl_m9. This was
extended to 20 of each type, but after that people successfully argued for
arbitrary names. In the new scheme, the names must start with acl_c or acl_m.
After that, we allow alphanumerics and underscores, but the first character
after c or m must be a digit or an underscore. This retains backwards
compatibility. */
if (c == ACLC_SET)
if (!acl_varname_to_cond(&s, cond, error)) return NULL;
/* For "set", we are now positioned for the data. For the others, only
"endpass" has no data */
if (c != ACLC_ENDPASS)
if (!acl_data_to_cond(s, cond, name, error)) return NULL;
}
return yield;
}
/*************************************************
* Set up added header line(s) *
*************************************************/
/* This function is called by the add_header modifier, and also from acl_warn()
to implement the now-deprecated way of adding header lines using "message" on a
"warn" verb. The argument is treated as a sequence of header lines which are
added to a chain, provided there isn't an identical one already there.
Argument: string of header lines
Returns: nothing
*/
static void
setup_header(const uschar *hstring)
{
const uschar *p, *q;
int hlen = Ustrlen(hstring);
/* Ignore any leading newlines */
while (*hstring == '\n') hstring++, hlen--;
/* An empty string does nothing; ensure exactly one final newline. */
if (hlen <= 0) return;
if (hstring[--hlen] != '\n') /* no newline */
q = string_sprintf("%s\n", hstring);
else if (hstring[hlen-1] == '\n') /* double newline */
{
uschar * s = string_copy(hstring);
while(s[--hlen] == '\n')
s[hlen+1] = '\0';