-
Notifications
You must be signed in to change notification settings - Fork 36
/
maiad
executable file
·16009 lines (14971 loc) · 698 KB
/
maiad
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
#!/usr/bin/perl -T
# This is maiad, a derivative of amavisd-new that has been modified to
# include support for Maia Mailguard. Maia Mailguard is a set of PHP and
# Perl scripts designed to offer users the ability to view and modify personal
# virus- and spam-checking preferences, whitelists/blacklists, manage their
# quarantined files, and report spam effectively.
#
# Maia Mailguard was written by Robert LeBlanc <rjl@renaissoft.com>
# and David Morton <mortonda@dgrmm.net>, and is
# available at http://www.maiamailguard.com/
#
# $Id: maiad 1579 2012-03-07 02:04:26Z dmorton $
#------------------------------------------------------------------------------
# What follows here are the comments from amavisd-new 2.2.1:
#
# This is amavisd-new.
# It is an interface between message transfer agent (MTA) and virus
# scanners and/or spam scanners, functioning as a mail content filter.
#
# It is a performance-enhanced and feature-enriched version of amavisd
# (which in turn is a daemonized version of AMaViS), initially based
# on amavisd-snapshot-20020300).
#
# All work since amavisd-snapshot-20020300:
# Copyright (C) 2002,2003,2004 Mark Martinec, All Rights Reserved.
# with contributions from the amavis-* mailing lists and individuals,
# as acknowledged in the release notes.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Author: Mark Martinec <mark.martinec@ijs.si>
# Patches and problem reports are welcome.
#
# The latest version of this program is available at:
# http://www.ijs.si/software/amavisd/
#------------------------------------------------------------------------------
# Here is a boilerplate from the amavisd(-snapshot) version,
# which is the version that served as a base code for the initial
# version of amavisd-new. License terms were the same:
#
# Author: Chris Mason <cmason@unixzone.com>
# Current maintainer: Lars Hecking <lhecking@users.sourceforge.net>
# Based on work by:
# Mogens Kjaer, Carlsberg Laboratory, <mk@crc.dk>
# Juergen Quade, Softing GmbH, <quade@softing.com>
# Christian Bricart <shiva@aachalon.de>
# Rainer Link <link@foo.fh-furtwangen.de>
# This script is part of the AMaViS package. For more information see:
# http://amavis.org/
# Copyright (C) 2000 - 2002 the people mentioned above
# This software is licensed under the GNU General Public License (GPL)
# See: http://www.gnu.org/copyleft/gpl.html
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#Index of packages in this file
# Amavis::Boot
# Amavis::Conf
# Amavis::Lock
# Amavis::Log
# Amavis::Timing
# Amavis::Util
# Amavis::rfc2821_2822_Tools
# Amavis::Lookup::RE
# Amavis::Lookup::Label
# Amavis::Lookup
# Amavis::Expand
# Amavis::In::Connection
# Amavis::In::Message::PerRecip
# Amavis::In::Message
# Amavis::Out::EditHeader
# Amavis::Out::Local
# Amavis::Out
# Amavis::UnmangleSender
# Amavis::Unpackers::NewFilename
# Amavis::Unpackers::Part
# Amavis::Unpackers::OurFiler
# Amavis::Unpackers::Validity
# Amavis::Unpackers::MIME
# Amavis::Notify
# Amavis::Cache
# Amavis
#optionally compiled-in packages: ---------------------------------------------
# Amavis::DB::SNMP
# Amavis::DB
# Amavis::Cache
# Amavis::Lookup::SQLfield
# Amavis::Lookup::SQL
# Amavis::Lookup::LDAP
# Amavis::Lookup::LDAPattr
# Amavis::In::AMCL
# Amavis::In::SMTP
# Amavis::AV
# Amavis::SpamControl
# Amavis::Unpackers
#Maia-related packages: --------------------------------------------------------
# Amavis::Maia
#------------------------------------------------------------------------------
#
package Amavis::Boot;
use strict;
use re 'taint';
# Fetch all required modules (or nicely report missing ones), and compile them
# once-and-for-all at the parent process, so that forked children can inherit
# and share already compiled code in memory. Children will still need to 'use'
# modules if they want to inherit from their name space.
#
sub fetch_modules($$@) {
my($reason, $required, @modules) = @_;
my(@missing);
for my $m (@modules) {
local($_) = $m;
$_ .= /^auto::/ ? '.al' : '.pm' if !/\.(pm|pl|al)\z/;
s[::][/]g;
eval { require $_ } or push(@missing, $m);
}
die "ERROR: MISSING $reason:\n" . join('', map { " $_\n" } @missing)
if $required && @missing;
\@missing;
}
BEGIN {
fetch_modules('REQUIRED BASIC MODULES', 1, qw(
Exporter POSIX Fcntl Socket Errno Carp Time::HiRes
IO::Handle IO::File IO::Socket IO::Socket::UNIX IO::Socket::INET
IO::Wrap IO::Stringy Digest::MD5 Unix::Syslog File::Basename File::Copy
Mail::Field Mail::Address Mail::Header Mail::Internet
MIME::Base64 MIME::QuotedPrint MIME::Words
MIME::Head MIME::Body MIME::Entity MIME::Parser MIME::Decoder
MIME::Decoder::Base64 MIME::Decoder::Binary MIME::Decoder::QuotedPrint
MIME::Decoder::NBit MIME::Decoder::UU MIME::Decoder::Gzip64
Net::Cmd Net::SMTP Net::Server Net::Server::PreForkSimple
));
# with earlier versions of Perl one may need to add additional modules
# to the list, such as: auto::POSIX::setgid auto::POSIX::setuid ...
fetch_modules('OPTIONAL BASIC MODULES', 0, qw(
Carp::Heavy auto::POSIX::setgid auto::POSIX::setuid
MIME::Decoder::BinHex
));
}
1;
#
package Amavis::Conf;
use strict;
use re 'taint';
# prototypes
sub D_REJECT();
sub D_BOUNCE();
sub D_DISCARD();
sub D_PASS();
BEGIN {
use Exporter ();
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
$VERSION = '2.034';
@ISA = qw(Exporter);
@EXPORT = ();
@EXPORT_OK = ();
%EXPORT_TAGS = (
'dynamic_confvars' => [qw(
$policy_bank_name $protocol @inet_acl
$log_level $log_templ $log_recip_templ $forward_method $notify_method
$amavis_auth_user $amavis_auth_pass $auth_reauthenticate_forwarded
$auth_required_out $auth_required_inp @auth_mech_avail
$local_client_bind_address
$localhost_name $smtpd_greeting_banner $smtpd_quit_banner
$smtpd_message_size_limit
$final_virus_destiny $final_spam_destiny
$final_banned_destiny $final_bad_header_destiny
$warnvirussender $warnspamsender $warnbannedsender $warnbadhsender
$warn_offsite
@av_scanners @av_scanners_backup $first_infected_stops_scan
$bypass_decode_parts
$defang_virus $defang_banned $defang_spam
$defang_bad_header $defang_undecipherable $defang_all
$undecipherable_subject_tag
$sa_spam_report_header $sa_spam_level_char
$sa_mail_body_size_limit
$localpart_is_case_sensitive
$recipient_delimiter $replace_existing_extension
$hdr_encoding $bdy_encoding $hdr_encoding_qb
$notify_xmailer_header $X_HEADER_TAG $X_HEADER_LINE
$remove_existing_x_scanned_headers $remove_existing_spam_headers
$hdrfrom_notify_sender $hdrfrom_notify_recip
$hdrfrom_notify_admin $hdrfrom_notify_spamadmin
$mailfrom_notify_sender $mailfrom_notify_recip
$mailfrom_notify_admin $mailfrom_notify_spamadmin
$mailfrom_to_quarantine
$virus_quarantine_method $spam_quarantine_method
$banned_files_quarantine_method $bad_header_quarantine_method
%local_delivery_aliases
$notify_sender_templ
$notify_virus_sender_templ $notify_spam_sender_templ
$notify_virus_admin_templ $notify_spam_admin_templ
$notify_virus_recips_templ $notify_spam_recips_templ
$banned_namepath_re
$per_recip_whitelist_sender_lookup_tables
$per_recip_blacklist_sender_lookup_tables
@local_domains_maps @mynetworks_maps
@bypass_virus_checks_maps @bypass_spam_checks_maps
@bypass_banned_checks_maps @bypass_header_checks_maps
@virus_lovers_maps @spam_lovers_maps
@banned_files_lovers_maps @bad_header_lovers_maps
@warnvirusrecip_maps @warnbannedrecip_maps @warnbadhrecip_maps
@newvirus_admin_maps @virus_admin_maps
@banned_admin_maps @bad_header_admin_maps @spam_admin_maps
@virus_quarantine_to_maps
@banned_quarantine_to_maps @bad_header_quarantine_to_maps
@spam_quarantine_to_maps @spam_quarantine_bysender_to_maps
@banned_filename_maps
@spam_tag_level_maps @spam_tag2_level_maps @spam_kill_level_maps
@spam_dsn_cutoff_level_maps @spam_modifies_subj_maps
@spam_subject_tag_maps @spam_subject_tag2_maps
@whitelist_sender_maps @blacklist_sender_maps @score_sender_maps
@message_size_limit_maps
@addr_extension_virus_maps @addr_extension_spam_maps
@addr_extension_banned_maps @addr_extension_bad_header_maps
@debug_sender_maps
)],
'confvars' => [qw(
$myproduct_name $myversion_id $myversion_id_numeric $myversion_date
$myversion $myhostname @additional_perl_modules
$MYHOME $TEMPBASE $QUARANTINEDIR
$daemonize $pid_file $lock_file $db_home
$enable_db $enable_global_cache
$daemon_user $daemon_group $daemon_chroot_dir $path
$DEBUG $DO_SYSLOG $SYSLOG_LEVEL $LOGFILE
$max_servers $max_requests $child_timeout
%current_policy_bank %policy_bank %interface_policy
$inet_socket_port $inet_socket_bind
$insert_received_line $relayhost_is_client $smtpd_recipient_limit
$MAXLEVELS $MAXFILES
$MIN_EXPANSION_QUOTA $MIN_EXPANSION_FACTOR
$MAX_EXPANSION_QUOTA $MAX_EXPANSION_FACTOR
@lookup_sql_dsn
$sql_select_policy $sql_select_white_black_list
$virus_check_negative_ttl $virus_check_positive_ttl
$spam_check_negative_ttl $spam_check_positive_ttl
$enable_ldap $default_ldap $virus_lovers_ldap $spam_lovers_ldap
$banned_files_lovers_ldap $bad_header_lovers_ldap
$bypass_virus_checks_ldap $bypass_spam_checks_ldap
$bypass_banned_checks_ldap $bypass_header_checks_ldap
$spam_tag_level_ldap $spam_tag2_level_ldap $spam_kill_level_ldap
$spam_modifies_subj_ldap $local_domains_ldap
$spam_quarantine_to_ldap $virus_quarantine_to_ldap
$banned_quarantine_to_ldap $bad_header_quarantine_to_ldap
$spam_whitelist_sender_ldap $spam_blacklist_sender_ldap
@keep_decoded_original_maps @map_full_type_to_short_type_maps
@viruses_that_fake_sender_maps @non_malware_viruses_maps
%no_autocreate_domains @no_autocreate_domains_acl $no_autocreate_domains_re
$key_file
)],
'unpack' => [qw(
$file $arc $gzip $bzip2 $lzop $lha $unarj $uncompress $unfreeze
$unrar $zoo $pax $cpio $ar $rpm2cpio $cabextract $ripole
)],
'sa' => [qw(
$helpers_home $dspam
$sa_local_tests_only $sa_auto_whitelist $sa_timeout $sa_debug
)],
'platform' => [qw(
$can_truncate $unicode_aware $eol $encryption_key
&D_REJECT &D_BOUNCE &D_DISCARD &D_PASS
)],
# other variables settable by user in maiad.conf,
# but not directly accessible by the program
'hidden_confvars' => [qw(
$mydomain
)],
# legacy variables, predeclared for compatibility of maiad.conf
# The rest of the program does not use them directly and they should not be
# visible in other modules, but may be referenced throgh @*_maps variables.
'legacy_confvars' => [qw(
%local_domains @local_domains_acl $local_domains_re @mynetworks
%bypass_virus_checks @bypass_virus_checks_acl $bypass_virus_checks_re
%bypass_spam_checks @bypass_spam_checks_acl $bypass_spam_checks_re
%bypass_banned_checks @bypass_banned_checks_acl $bypass_banned_checks_re
%bypass_header_checks @bypass_header_checks_acl $bypass_header_checks_re
%virus_lovers @virus_lovers_acl $virus_lovers_re
%spam_lovers @spam_lovers_acl $spam_lovers_re
%banned_files_lovers @banned_files_lovers_acl $banned_files_lovers_re
%bad_header_lovers @bad_header_lovers_acl $bad_header_lovers_re
%virus_admin %spam_admin
$newvirus_admin $virus_admin $banned_admin $bad_header_admin $spam_admin
$warnvirusrecip $warnbannedrecip $warnbadhrecip
$virus_quarantine_to $banned_quarantine_to $bad_header_quarantine_to
$spam_quarantine_to $spam_quarantine_bysender_to
$keep_decoded_original_re $map_full_type_to_short_type_re
$banned_filename_re $viruses_that_fake_sender_re $non_malware_viruses_re
$sa_tag_level_deflt $sa_tag2_level_deflt $sa_kill_level_deflt
$sa_dsn_cutoff_level $sa_spam_modifies_subj
$sa_spam_subject_tag1 $sa_spam_subject_tag
%whitelist_sender @whitelist_sender_acl $whitelist_sender_re
%blacklist_sender @blacklist_sender_acl $blacklist_sender_re
$addr_extension_virus $addr_extension_spam
$addr_extension_banned $addr_extension_bad_header
$gets_addr_in_quoted_form @debug_sender_acl $unix_socketname
)],
);
Exporter::export_tags qw(dynamic_confvars confvars unpack sa platform
hidden_confvars legacy_confvars);
} # BEGIN
use POSIX qw(uname);
use Carp ();
use Errno qw(ENOENT EACCES);
use IO::File;
use vars @EXPORT;
sub c($); sub cr($); sub ca($); # prototypes
use subs qw(c cr ca); # access subroutine to new-style config variables
BEGIN { push(@EXPORT,qw(c cr ca)) }
{ # initialize new-style hash (policy bank) containing dynamic config settings
for my $tag (@EXPORT_TAGS{'dynamic_confvars'}) {
for my $v (@$tag) {
if ($v !~ /^([%\$\@])(.*)\z/) { die "Unsupported variable type: $v" }
else {
no strict 'refs'; my($type,$name) = ($1,$2);
$current_policy_bank{$name} = $type eq '$' ? \${"Amavis::Conf::$name"}
: $type eq '@' ? \@{"Amavis::Conf::$name"}
: $type eq '%' ? \%{"Amavis::Conf::$name"}
: undef;
}
}
}
$current_policy_bank{'policy_bank_name'} = ''; # builtin policy
$current_policy_bank{'policy_bank_path'} = '';
$policy_bank{''} = { %current_policy_bank }; # copy
}
# new-style access to dynamic config variables
# return a config variable value - usually a scalar;
# one level of indirection for scalars is allowed
sub c($) {
my($name) = @_;
if (!exists $current_policy_bank{$name}) {
Carp::croak(sprintf('No entry "%s" in policy bank "%s"',
$name, $current_policy_bank{'policy_bank_name'}));
}
my($var) = $current_policy_bank{$name}; my($r) = ref($var);
!$r ? $var : $r eq 'SCALAR' ? $$var
: $r eq 'ARRAY' ? @$var : $r eq 'HASH' ? %$var : $var;
}
# return a ref to a config variable value, or undef if var is undefined
sub cr($) {
my($name) = @_;
if (!exists $current_policy_bank{$name}) {
Carp::croak(sprintf('No entry "%s" in policy bank "%s"',
$name, $current_policy_bank{'policy_bank_name'}));
}
my($var) = $current_policy_bank{$name};
!defined($var) ? undef : !ref($var) ? \$var : $var;
}
# return a ref to a config variable value (which is supposed to be an array),
# converting undef to an empty array, and a scalar to a one-element array
# if necessary
sub ca($) {
my($name) = @_;
if (!exists $current_policy_bank{$name}) {
Carp::croak(sprintf('No entry "%s" in policy bank "%s"',
$name, $current_policy_bank{'policy_bank_name'}));
}
my($var) = $current_policy_bank{$name};
!defined($var) ? [] : !ref($var) ? [$var] : $var;
}
$myproduct_name = 'maiad';
$myversion_id = '1.0.4.1524'; $myversion_date = '20150107';
$myversion = "Maia Mailguard 1.0.4.1524";
$myversion_id_numeric = # x.yyyzzz, allows numerical comparision, like Perl $]
sprintf("%8.6f", $1 + ($2 + $3/1000)/1000)
if $myversion_id =~ /^(\d+)(?:\.(\d*)(?:\.(\d*))?)?(.*)$/;
$eol = "\n"; # native record separator in files: LF or CRLF or even CR
$unicode_aware = $]>=5.008 && length("\x{263a}")==1 && eval { require Encode };
# serves only as a quick default for other configuration settings
$MYHOME = '/var/lib/maia';
$mydomain = '!change-mydomain-variable!.example.com';#intentionally bad default
# Create debugging output - true: log to stderr; false: log to syslog/file
$DEBUG = 0;
# Cause Net::Server parameters 'background' and 'setsid' to be set,
# resulting in the program to detach itself from the terminal
$daemonize = 1;
# Net::Server pre-forking settings - defaults, overruled by maiad.conf
$max_servers = 2; # number of pre-forked children
$max_requests = 10; # retire a child after that many accepts
$child_timeout = 8*60; # abort child if it does not complete each task in n sec
# Can file be truncated?
# Set to 1 if 'truncate' works (it is XPG4-UNIX standard feature,
# not required by Posix).
# Things will go faster with SMTP-in, otherwise (e.g. with milter)
# it makes no difference as file truncation will not be used.
$can_truncate = 1;
# expiration time of cached results: time to live in seconds
# (how long the result of a virus/spam test remains valid)
$virus_check_negative_ttl= 3*60; # time to remember that mail was not infected
$virus_check_positive_ttl= 30*60; # time to remember that mail was infected
$spam_check_negative_ttl = 30*60; # time to remember that mail was not spam
$spam_check_positive_ttl = 30*60; # time to remember that mail was spam
#
# NOTE:
# Cache size will be determined by the largest of the $*_ttl values.
# Depending on the mail rate, the cache database may grow quite large.
# Reasonable compromise for the max value is 15 minutes to 2 hours.
# Customizable notification messages, logging
$SYSLOG_LEVEL = 'mail.debug';
$enable_db = 0; # load optional modules Amavis::DB & Amavis::DB::SNMP
$enable_global_cache = 0; # enable use of bdb-based Amavis::Cache
# Where to find SQL server(s) and database to support SQL lookups?
# A list of triples: (dsn,user,passw). Specify more than one
# for multiple (backup) SQL servers.
#
#@lookup_sql_dsn =
# ( ['DBI:mysql:mail:host1', 'some-username1', 'some-password1'],
# ['DBI:mysql:mail:host2', 'some-username2', 'some-password2'] );
# The SQL select clause to fetch per-recipient policy settings
# The %k will be replaced by a comma-separated list of query addresses
# (e.g. full address, domain only, catchall). Use ORDER, if there
# is a chance that multiple records will match - the first match wins
# If field names are not unique (e.g. 'id'), the later field overwrites the
# earlier in a hash returned by lookup, which is why we use '*,users.id'.
$sql_select_policy =
'SELECT *,users.id FROM users,policy'
. ' WHERE (users.policy_id=policy.id) AND (users.email IN (%k))'
. ' ORDER BY users.priority DESC';
# The SQL select clause to check sender in per-recipient whitelist/blacklist
# The first SELECT argument '?' will be users.id from recipient SQL lookup,
# the %k will be sender addresses (e.g. full address, domain only, catchall).
# Only the first occurrence of '?' will be replaced by users.id, subsequent
# occurrences of '?' will see empty string as an argument. There can be zero
# or more occurrences of %k, lookup keys will be multiplied accordingly.
# Up until version 2.2.0 the '?' had to be placed before the '%k';
# starting with 2.2.1 this restriction is lifted.
$sql_select_white_black_list =
'SELECT wblist.wb FROM wblist,mailaddr,users'
. ' WHERE (users.id=?)'
. ' AND (wblist.rid=users.maia_user_id)'
. ' AND (wblist.sid=mailaddr.id)'
. ' AND (mailaddr.email IN (%k))'
. ' ORDER BY mailaddr.priority DESC';
#
# Receiving mail related
# $inet_socket_port = 10024; # accept SMTP on this TCP port
# $inet_socket_port = [10024,10026,10027]; # ...possibly on more than one
$inet_socket_bind = '127.0.0.1'; # limit socket bind to loopback interface
@inet_acl = qw( 127.0.0.1 ::1 ); # allow SMTP access only from localhost
@mynetworks = qw( 127.0.0.0/8 ::1 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 );
$forward_method = 'smtp:[127.0.0.1]:10025';
$notify_method = $forward_method;
$virus_quarantine_method = 'local:virus-%i-%n';
$spam_quarantine_method = 'local:spam-%b-%i-%n';
$banned_files_quarantine_method = 'local:banned-%i-%n';
$bad_header_quarantine_method = 'local:badh-%i-%n';
$insert_received_line = 1; # insert 'Received:' header field? (not with milter)
$remove_existing_x_scanned_headers = 0;
$remove_existing_spam_headers = 1;
# encoding (charset in MIME terminology)
# to be used in RFC 2047-encoded ...
$hdr_encoding = 'iso-8859-1'; # ... header field bodies
$bdy_encoding = 'iso-8859-1'; # ... notification body text
# encoding (encoding in MIME terminology)
$hdr_encoding_qb = 'Q'; # quoted-printable (default)
#$hdr_encoding_qb = 'B'; # base64 (usual for far east charsets)
$smtpd_recipient_limit = 1100; # max recipients (RCPT TO) - sanity limit
# $myhostname is used by SMTP server module in the initial SMTP welcome line,
# in inserted 'Received:' lines, Message-ID in notifications, log entries, ...
$myhostname = (uname)[1]; # should be a FQDN !
$smtpd_greeting_banner = '${helo-name} ${protocol} ${product} service ready';
$smtpd_quit_banner = '${helo-name} ${product} closing transmission channel';
# $localhost_name is the name of THIS host running maiad
# (typically 'localhost'). It is used in HELO SMTP command
# when reinjecting mail back to MTA via SMTP for final delivery.
$localhost_name = 'localhost';
# @auth_mech_avail = ('PLAIN','LOGIN'); # empty list disables incoming AUTH
#$auth_required_inp = 1; # incoming SMTP authentication required by maiad?
#$auth_required_out = 1; # SMTP authentication required by MTA
# SMTP AUTH username and password for notification submissions
# (and reauthentication of forwarded mail if requested)
#$amavis_auth_user = undef; # perhaps: 'maia'
#$amavis_auth_pass = undef;
#$auth_reauthenticate_forwarded = undef; # supply our own credentials also
# for forwarded (passed) mail
# whom quarantined messages appear to be sent from (envelope sender)
$mailfrom_to_quarantine = undef; # original sender if undef, or set explicitly
# where to send quarantined malware
# Specify undef to disable, or e-mail address containing '@',
# or just a local part, which will be mapped by %local_delivery_aliases
# into local mailbox name or directory. The lookup key is a recipient address
$virus_quarantine_to = undef; # %local_delivery_aliases mapped
$banned_quarantine_to = undef; # %local_delivery_aliases mapped
$bad_header_quarantine_to = undef; # %local_delivery_aliases
$spam_quarantine_to = undef; # %local_delivery_aliases mapped
$banned_admin = \@virus_admin_maps; # compatibility
$bad_header_admin = \@virus_admin_maps; # compatibility
# similar to $spam_quarantine_to, but the lookup key is the sender address
$spam_quarantine_bysender_to = undef; # dflt: no by-sender spam quarantine
# quarantine directory or mailbox file or empty
# (only used if $virus_quarantine_to specifies direct local delivery)
$QUARANTINEDIR = undef; # no quarantine unless overridden by config
$undecipherable_subject_tag = '***UNCHECKED*** ';
# string to prepend to Subject header field when message qualifies as spam
# $sa_spam_subject_tag1 = undef; # example: '***possible SPAM*** '
# $sa_spam_subject_tag = undef; # example: '***SPAM*** '
$sa_spam_modifies_subj = 1; # true for compatibility; can be a
# lookup table indicating per-recip settings
$sa_spam_level_char = '*'; # character to be used in X-Spam-Level bar;
# empty or undef disables adding this header field
# $sa_spam_report_header = undef; # insert X-Spam-Report header field?
$sa_local_tests_only = 0;
$sa_debug = 0;
$sa_timeout = 30; # timeout in seconds for a call to SpamAssassin
# MIME defanging is only activated when enabled and malware is allowed to pass
# $defang_virus = undef;
# $defang_banned = undef;
# $defang_spam = undef;
# $defang_bad_header = undef;
# $defang_undecipherable = undef;
# $defang_all = undef;
$MIN_EXPANSION_FACTOR = 5; # times original mail size
$MAX_EXPANSION_FACTOR = 500; # times original mail size
# See maiad.conf and README.lookups for details.
# What to do with the message (this is independent of quarantining):
# Reject: tell MTA to generate a non-delivery notification, MTA gets 5xx
# Bounce: generate a non-delivery notification by ourselves, MTA gets 250
# Discard: drop the message and pretend it was delivered, MTA gets 250
# Pass: deliver/accept the message
#
# Bounce and Reject are similar: in both cases sender gets a non-delivery
# notification, either generated by maiad, or by MTA. The notification
# issued by maiad may be more informative, while on the other hand
# MTA may be able to do a true reject on the original SMTP session
# (e.g. with sendmail milter), or else it just generates normal non-delivery
# notification / bounce (e.g. with Postfix, Exim). As a consequence,
# with Postfix and Exim and dual-sendmail setup the Bounce is more informative
# than Reject, but sendmail-milter users may prefer Reject.
#
# Bounce and Discard are similar: in both cases maiad confirms
# to MTA the message reception with success code 250. The difference is
# in sender notification: Bounce sends a non-delivery notification to sender,
# Discard does not, the message is silently dropped. Quarantine and
# admin notifications are not affected by any of these settings.
#
# COMPATIBITITY NOTE: the separation of *_destiny values into
# D_BOUNCE, D_REJECT, D_DISCARD and D_PASS made settings $warnvirussender
# and $warnspamsender only still useful with D_PASS. The combination of
# D_DISCARD + $warn*sender=1 is mapped into D_BOUNCE for compatibility.
# intentionally leave value -1 unassigned for compatibility
sub D_REJECT () { -3 }
sub D_BOUNCE () { -2 }
sub D_DISCARD() { 0 }
sub D_PASS () { 1 }
# The following symbolic constants can be used in *destiny settings:
#
# D_PASS mail will pass to recipients, regardless of contents;
#
# D_DISCARD mail will not be delivered to its recipients, sender will NOT be
# notified. Effectively we lose mail (but it will be quarantined
# unless disabled). Not a decent thing to do for a mailer.
#
# D_BOUNCE mail will not be delivered to its recipients, a non-delivery
# notification (bounce) will be sent to the sender by maiad;
# Exception: bounce (DSN) will not be sent if a virus name matches
# $viruses_that_fake_sender_maps, or to messages from mailing lists
# (Precedence: bulk|list|junk), or for spam exceeding
# spam_dsn_cutoff_level
#
# D_REJECT mail will not be delivered to its recipients, sender should
# preferably get a reject, e.g. SMTP permanent reject response
# (e.g. with milter), or non-delivery notification from MTA
# (e.g. Postfix). If this is not possible (e.g. different recipients
# have different tolerances to bad mail contents and not using LMTP)
# maiad sends a bounce by itself (same as D_BOUNCE).
#
# Notes:
# D_REJECT and D_BOUNCE are similar, the difference is in who is responsible
# for informing the sender about non-delivery, and how informative
# the notification can be (maiad knows more than MTA);
# With D_REJECT, MTA may reject original SMTP, or send DSN (delivery status
# notification, colloquially called 'bounce') - depending on MTA;
# Best suited for sendmail milter, especially for spam.
# With D_BOUNCE, maiad (not MTA) sends DSN (can better explain the
# reason for mail non-delivery but unable to reject the original
# SMTP session, is in position to suppress DSN if considered
# unsuitable). Best suited for Postfix and other dual-MTA setups.
$final_virus_destiny = D_DISCARD; # D_REJECT, D_BOUNCE, D_DISCARD, D_PASS
$final_banned_destiny = D_DISCARD; # D_REJECT, D_BOUNCE, D_DISCARD, D_PASS
$final_spam_destiny = D_DISCARD; # D_REJECT, D_BOUNCE, D_DISCARD, D_PASS
$final_bad_header_destiny = D_DISCARD; # D_REJECT, D_BOUNCE, D_DISCARD, D_PASS
# If you decide to pass viruses (or spam) to certain users using
# %virus_lovers/@virus_lovers_acl/$virus_lovers_re, (or *spam_lovers*),
# %bypass_virus_checks/@bypass_virus_checks_acl, or $final_virus_destiny=D_PASS
# ($final_spam_destiny=D_PASS), you can set the variable $addr_extension_virus
# ($addr_extension_spam) to some string, and the recipient address will have
# this string appended as an address extension to the local-part of the
# address. This extension can be used by final local delivery agent to place
# such mail in different folders. Leave these variables undefined or empty
# strings to prevent appending address extensions. Setting has no effect
# on users which will not be receiving viruses (spam). Recipients which
# do not match access lists in @local_domains_maps are not affected (i.e.
# non-local recipients).
#
# LDAs usually default to stripping away address extension if no special
# handling for it is specified, so having this option enabled normally
# does no harm, provided the $recipients_delimiter character matches
# the setting at the final MTA's local delivery agent (LDA).
#
# $addr_extension_virus = 'virus'; # for example
# $addr_extension_spam = 'spam';
# $addr_extension_banned = 'banned';
# $addr_extension_bad_header = 'badh';
# Delimiter between local part of the recipient address and address extension
# (which can optionally be added, see variables $addr_extension_virus and
# $addr_extension_spam). E.g. recipient address <user@domain.example> gets
# changed to <user+virus@domain.example>.
#
# Delimiter should match equivalent (final) MTA delimiter setting.
# (e.g. for Postfix add 'recipient_delimiter = +' to main.cf).
# Setting it to an empty string or to undef disables this feature
# regardless of $addr_extension_virus and $addr_extension_spam settings.
$recipient_delimiter = undef;
$replace_existing_extension = 1; # true: replace ext; false: append ext
# Affects matching of localpart of e-mail addresses (left of '@')
# in lookups: true = case sensitive, false = case insensitive
$localpart_is_case_sensitive = 0;
# first match wins, more specific entries should precede general ones!
# the result may be a string or a ref to a list of strings;
# see also sub decompose_part()
$map_full_type_to_short_type_re = Amavis::Lookup::RE->new(
[qr/^empty\z/ => 'empty'],
[qr/^directory\z/ => 'dir'],
[qr/^can't (stat|read)\b/ => 'dat'], # file(1) diagnostics
[qr/^cannot open\b/ => 'dat'], # file(1) diagnostics
[qr/^ERROR: Corrupted\b/ => 'dat'], # file(1) diagnostics
[qr/can't read magic file|couldn't find any magic files/ => 'dat'],
[qr/^data\z/ => 'dat'],
[qr/^ISO-8859.*\btext\b/ => 'txt'],
[qr/^Non-ISO.*ASCII\b.*\btext\b/ => 'txt'],
[qr/^Unicode\b.*\btext\b/i => 'txt'],
[qr/^'diff' output text\b/ => 'txt'],
[qr/^GNU message catalog\b/ => 'mo'],
[qr/^PGP encrypted data\b/ => 'pgp'],
[qr/^PGP armored data( signed)? message\b/ => ['pgp','pgp.asc'] ],
[qr/^PGP armored\b/ => ['pgp','pgp.asc'] ],
### 'file' is a bit too trigger happy to claim something is 'mail text'
# [qr/^RFC 822 mail text\b/ => 'mail'],
[qr/^(ASCII|smtp|RFC 822) mail text\b/ => 'txt'],
[qr/^JPEG image data\b/ =>['image','jpg'] ],
[qr/^GIF image data\b/ =>['image','gif'] ],
[qr/^PNG image data\b/ =>['image','png'] ],
[qr/^TIFF image data\b/ =>['image','tif'] ],
[qr/^PCX\b.*\bimage data\b/ =>['image','pcx'] ],
[qr/^PC bitmap data\b/ =>['image','bmp'] ],
[qr/^MP2\b/ =>['audio','mpa','mp2'] ],
[qr/^MP3\b/ =>['audio','mpa','mp3'] ],
[qr/^MPEG video stream data\b/ =>['movie','mpv'] ],
[qr/^MPEG system stream data\b/ =>['movie','mpg'] ],
[qr/^MPEG\b/ =>['movie','mpg'] ],
[qr/^Microsoft ASF\b/ =>['movie','wmv'] ],
[qr/^RIFF\b.*\bAVI\b/ =>['movie','avi'] ],
[qr/^RIFF\b.*\bWAVE audio\b/ =>['audio','wav'] ],
[qr/^Macromedia Flash data\b/ => 'swf'],
[qr/^HTML document text\b/ => 'html'],
[qr/^XML document text\b/ => 'xml'],
[qr/^exported SGML document text\b/ => 'sgml'],
[qr/^PostScript document text\b/ => 'ps'],
[qr/^PDF document\b/ => 'pdf'],
[qr/^Rich Text Format data\b/ => 'rtf'],
[qr/^Microsoft Office Document\b/i => 'doc'], # OLE2: doc, ppt, xls, ...
[qr/^LaTeX\b.*\bdocument text\b/ => 'lat'],
[qr/^TeX DVI file\b/ => 'dvi'],
[qr/\bdocument text\b/ => 'txt'],
[qr/^compiled Java class data\b/ => 'java'],
[qr/^MS Windows 95 Internet shortcut text\b/ => 'url'],
[qr/^frozen\b/ => 'F'],
[qr/^gzip compressed\b/ => 'gz'],
[qr/^bzip compressed\b/ => 'bz'],
[qr/^bzip2 compressed\b/ => 'bz2'],
[qr/^lzop compressed\b/ => 'lzo'],
[qr/^compress'd/ => 'Z'],
[qr/^Zip archive\b/i => 'zip'],
[qr/^RAR archive\b/i => 'rar'],
[qr/^LHa.*\barchive\b/i => 'lha'], # or .lzh
[qr/^ARC archive\b/i => 'arc'],
[qr/^ARJ archive\b/i => 'arj'],
[qr/^Zoo archive\b/i => 'zoo'],
[qr/^(\S+\s+)?tar archive\b/i => 'tar'],
[qr/^(\S+\s+)?cpio archive\b/i => 'cpio'],
[qr/^Debian binary package\b/i => 'deb'], # standard Unix archive (ar)
[qr/^current ar archive\b/i => 'a'], # standard Unix archive (ar)
[qr/^RPM\b/ => 'rpm'],
[qr/^(Transport Neutral Encapsulation Format|TNEF)\b/i => 'tnef'],
[qr/^Microsoft cabinet file\b/i => 'cab'],
[qr/^(uuencoded|xxencoded)\b/i => 'uue'],
[qr/^binhex\b/i => 'hqx'],
[qr/^(ASCII|text)\b/i => 'asc'],
[qr/^Emacs.*byte-compiled Lisp data/i => 'asc'], # BinHex with an empty line
[qr/\bscript text executable\b/ => 'txt'],
[qr/^MS-DOS\b.*\bexecutable\b/ => ['exe','exe-ms'] ],
[qr/^MS Windows\b.*\bexecutable\b/ => ['exe','exe-ms'] ],
[qr/^PA-RISC.*\bexecutable\b/ => ['exe','exe-unix'] ],
[qr/^ELF .*\bexecutable\b/ => ['exe','exe-unix'] ],
[qr/^COFF format .*\bexecutable\b/ => ['exe','exe-unix'] ],
[qr/^executable \(RISC System\b/ => ['exe','exe-unix'] ],
[qr/^VMS\b.*\bexecutable\b/ => ['exe','exe-vms'] ],
[qr/\bexecutable\b/i => 'exe'],
[qr/^MS Windows\b.*\bDLL\b/ => 'dll'],
[qr/\bshared object, \b/i => 'so'],
[qr/\brelocatable, \b/i => 'o'],
[qr/\btext\b/i => 'asc'],
[qr/.*/ => 'dat'], # catchall
);
# MS Windows PE 32-bit Intel 80386 GUI executable not relocatable
# MS-DOS executable (EXE), OS/2 or MS Windows
# PA-RISC1.1 executable dynamically linked
# PA-RISC1.1 shared executable dynamically linked
# ELF 64-bit LSB executable, Alpha (unofficial), version 1 (FreeBSD), for FreeBSD 5.0.1, dynamically linked (uses shared libs), stripped
# ELF 64-bit LSB executable, Alpha (unofficial), version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), stripped
# ELF 64-bit MSB executable, SPARC V9, version 1 (FreeBSD), for FreeBSD 5.0, dynamically linked (uses shared libs), stripped
# ELF 64-bit MSB shared object, SPARC V9, version 1 (FreeBSD), stripped
# ELF 32-bit LSB executable, Intel 80386, version 1, dynamically`
# ELF 32-bit MSB executable, SPARC, version 1, dynamically linke`
# COFF format alpha executable paged stripped - version 3.11-10
# COFF format alpha executable paged dynamically linked stripped`
# COFF format alpha demand paged executable or object module stripped - version 3.11-10
# COFF format alpha paged dynamically linked not stripped shared`
# executable (RISC System/6000 V3.1) or obj module
# VMS VAX executable
# Define aliase names in this module to make it simpler to call
# these routines from maiad.conf
*read_text = \&Amavis::Util::read_text;
*read_l10n_templates = \&Amavis::Util::read_l10n_templates;
*read_hash = \&Amavis::Util::read_hash;
*ask_daemon = \&Amavis::AV::ask_daemon;
*sophos_savi = \&Amavis::AV::ask_sophos_savi;
*ask_clamav = \&Amavis::AV::ask_clamav;
sub new_RE { Amavis::Lookup::RE->new(@_) }
sub build_default_maps() {
@local_domains_maps = (
\%local_domains, \@local_domains_acl, \$local_domains_re);
@mynetworks_maps = (\@mynetworks);
@bypass_virus_checks_maps = (
\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
@bypass_spam_checks_maps = (
\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
@bypass_banned_checks_maps = (
\%bypass_banned_checks, \@bypass_banned_checks_acl, \$bypass_banned_checks_re);
@bypass_header_checks_maps = (
\%bypass_header_checks, \@bypass_header_checks_acl, \$bypass_header_checks_re);
@virus_lovers_maps = (
\%virus_lovers, \@virus_lovers_acl, \$virus_lovers_re);
@spam_lovers_maps = (
\%spam_lovers, \@spam_lovers_acl, \$spam_lovers_re);
@banned_files_lovers_maps = (
\%banned_files_lovers, \@banned_files_lovers_acl, \$banned_files_lovers_re);
@bad_header_lovers_maps = (
\%bad_header_lovers, \@bad_header_lovers_acl, \$bad_header_lovers_re);
@warnvirusrecip_maps = (\$warnvirusrecip);
@warnbannedrecip_maps = (\$warnbannedrecip);
@warnbadhrecip_maps = (\$warnbadhrecip);
@newvirus_admin_maps = (\$newvirus_admin);
@virus_admin_maps = (\%virus_admin, \$virus_admin);
@banned_admin_maps = (\$banned_admin);
@bad_header_admin_maps= (\$bad_header_admin);
@spam_admin_maps = (\%spam_admin, \$spam_admin);
@virus_quarantine_to_maps = (\$virus_quarantine_to);
@banned_quarantine_to_maps = (\$banned_quarantine_to);
@bad_header_quarantine_to_maps = (\$bad_header_quarantine_to);
@spam_quarantine_to_maps = (\$spam_quarantine_to);
@spam_quarantine_bysender_to_maps = (\$spam_quarantine_bysender_to);
@keep_decoded_original_maps = (\$keep_decoded_original_re);
@map_full_type_to_short_type_maps = (\$map_full_type_to_short_type_re);
@banned_filename_maps = (\$banned_filename_re);
@viruses_that_fake_sender_maps = (\$viruses_that_fake_sender_re, 1);
@non_malware_viruses_maps = (\$non_malware_viruses_re);
@spam_tag_level_maps = (\$sa_tag_level_deflt);
@spam_tag2_level_maps = (\$sa_tag2_level_deflt);
@spam_kill_level_maps = (\$sa_kill_level_deflt);
@spam_dsn_cutoff_level_maps = (\$sa_dsn_cutoff_level);
@spam_modifies_subj_maps = (\$sa_spam_modifies_subj);
@spam_subject_tag_maps = (\$sa_spam_subject_tag1); # note: inconsistent
@spam_subject_tag2_maps = (\$sa_spam_subject_tag); # note: inconsistent
@whitelist_sender_maps = (
\%whitelist_sender, \@whitelist_sender_acl, \$whitelist_sender_re);
@blacklist_sender_maps = (
\%blacklist_sender, \@blacklist_sender_acl, \$blacklist_sender_re);
@score_sender_maps = (); # new variable, no backwards compatibility needed
@message_size_limit_maps = (); # new variable
@addr_extension_virus_maps = (\$addr_extension_virus);
@addr_extension_spam_maps = (\$addr_extension_spam);
@addr_extension_banned_maps = (\$addr_extension_banned);
@addr_extension_bad_header_maps = (\$addr_extension_bad_header);
@debug_sender_maps = (\@debug_sender_acl);
}
# prepend a lookup table label object for logging purposes
sub label_default_maps() {
for my $varname (qw(
@local_domains_maps @mynetworks_maps
@bypass_virus_checks_maps @bypass_spam_checks_maps
@bypass_banned_checks_maps @bypass_header_checks_maps
@virus_lovers_maps @spam_lovers_maps
@banned_files_lovers_maps @bad_header_lovers_maps
@warnvirusrecip_maps @warnbannedrecip_maps @warnbadhrecip_maps
@newvirus_admin_maps @virus_admin_maps
@banned_admin_maps @bad_header_admin_maps @spam_admin_maps
@virus_quarantine_to_maps
@banned_quarantine_to_maps @bad_header_quarantine_to_maps
@spam_quarantine_to_maps @spam_quarantine_bysender_to_maps
@keep_decoded_original_maps @map_full_type_to_short_type_maps
@banned_filename_maps @viruses_that_fake_sender_maps
@non_malware_viruses_maps
@spam_tag_level_maps @spam_tag2_level_maps @spam_kill_level_maps
@spam_dsn_cutoff_level_maps @spam_modifies_subj_maps
@spam_subject_tag_maps @spam_subject_tag2_maps
@whitelist_sender_maps @blacklist_sender_maps @score_sender_maps
@message_size_limit_maps
@addr_extension_virus_maps @addr_extension_spam_maps
@addr_extension_banned_maps @addr_extension_bad_header_maps
@debug_sender_maps ))
{
my($g) = $varname; $g =~ s{\@}{Amavis::Conf::}; # qualified variable name
my($label) = $varname; $label=~s/^\@//; $label=~s/_maps$//;
{ no strict 'refs';
unshift(@$g, # NOTE: a symbolic reference
Amavis::Lookup::Label->new($label)) if @$g; # no label if empty
}
}
}
# read and evaluate configuration files (one or more)
sub read_config(@) {
my(@config_files) = @_;
for my $config_file (@config_files) {
my($msg, $fh);
my($errn) = stat($config_file) ? 0 : 0+$!;
if ($errn == ENOENT) { $msg = "does not exist" }
elsif ($errn) { $msg = "is inaccessible: $!" }
elsif (-d _) { $msg = "is a directory" }
elsif (!-f _) { $msg = "is not a regular file" }
elsif ($> && -o _) { $msg = "is owned by EUID $>, should be owned by root"}
elsif ($> && -w _) { $msg = "is writable by EUID $>, EGID $)" }
if (defined $msg) { die "Config file \"$config_file\" $msg," }
$! = undef; my($rv) = do $config_file;
if (!defined($rv)) {
if ($@ ne '') { die "Error in config file \"$config_file\": $@" }
else { die "Error reading config file \"$config_file\": $!" }
}
}
$daemon_chroot_dir = '' if !defined $daemon_chroot_dir; # avoids warnings
# some sensible defaults for essential settings
$TEMPBASE = "$MYHOME/tmp" if !defined $TEMPBASE;
$helpers_home = $MYHOME if !defined $helpers_home;
$db_home = "$MYHOME/db" if !defined $db_home;
$lock_file = "/var/lock/maia/maiad.lock" if !defined $lock_file;
$pid_file = "/var/run/maia/maiad.pid" if !defined $pid_file;
$encryption_key = undef;
if (defined $key_file) {
my $fh = new IO::File;
if ($fh->open("<" . $key_file)) {
sysread($fh, $encryption_key, 56);
$fh->close;
} else {
die "Encyption key not found or unreadable: $key_file \nIf you don't need encryption in the database, comment out \$key_file in maiad.conf\n$!";
}
}
$X_HEADER_TAG = 'X-Virus-Scanned' if !defined $X_HEADER_TAG;
$X_HEADER_LINE= "$myproduct_name at $mydomain" if !defined $X_HEADER_LINE;
$notify_method = $forward_method;
my($pname) = "\"Content-filter at $myhostname\"";
$hdrfrom_notify_sender = "$pname <postmaster\@$myhostname>"
if !defined $hdrfrom_notify_sender;
$hdrfrom_notify_recip = $mailfrom_notify_recip ne ''
? "$pname <$mailfrom_notify_recip>"
: $hdrfrom_notify_sender if !defined $hdrfrom_notify_recip;
$hdrfrom_notify_admin = $mailfrom_notify_admin ne ''
? "$pname <$mailfrom_notify_admin>"
: $hdrfrom_notify_sender if !defined $hdrfrom_notify_admin;
$hdrfrom_notify_spamadmin = $mailfrom_notify_spamadmin ne ''
? "$pname <$mailfrom_notify_spamadmin>"
: $hdrfrom_notify_sender if !defined $hdrfrom_notify_spamadmin;
# compatibility with deprecated $warn*sender and old *_destiny values
# map old values <0, =0, >0 into D_REJECT/D_BOUNCE, D_DISCARD, D_PASS
for ($final_virus_destiny, $final_banned_destiny, $final_spam_destiny) {
if ($_ > 0) { $_ = D_PASS }
elsif ($_ < 0 && $_ != D_BOUNCE && $_ != D_REJECT) { # compatibility
# favour Reject with sendmail milter, Bounce with others
$_ = c('forward_method') eq '' ? D_REJECT : D_BOUNCE;
}
}
if ($final_virus_destiny == D_DISCARD && c('warnvirussender') )
{ $final_virus_destiny = D_BOUNCE }
if ($final_spam_destiny == D_DISCARD && c('warnspamsender') )
{ $final_spam_destiny = D_BOUNCE }
if ($final_banned_destiny == D_DISCARD && c('warnbannedsender') )
{ $final_banned_destiny = D_BOUNCE }
if ($final_bad_header_destiny == D_DISCARD && c('warnbadhsender') )
{ $final_bad_header_destiny = D_BOUNCE }
}