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
|
#!/usr/bin/perl -w
require 5;
use strict;
use Debconf::Client::ConfModule ':all';
use Carp;
sub get_value($) {
my $key = shift;
my($code,$text) = get($key);
return $text if ($code == 0);
croak("Unable to fetch value for \"$key\" (debconf code $code)\n");
}
version('2.0');
#my $capb = capb('backup multiselect');
######################################################################
# Get data, mainly from Debconf
my $syshostname;
chomp($syshostname = `hostname --fqdn`);
my $configtype = get_value("exim/eximconfig/configtype");
my $visiblename;
if ($configtype eq 'satellite') {
$visiblename = get_value("exim/eximconfig/satellite_hostname");
}
elsif ($configtype eq 'local') {
$visiblename = $syshostname;
}
elsif ($configtype eq 'none') {
# leave their configuration alone
exit(0);
}
else {
$visiblename = get_value("exim/eximconfig/visible_hostname");
}
my @local_domains = ($visiblename, "localhost");
my @relay_domains = ();
my @relay_nets = ('127.0.0.1', '::::1');
if ($configtype eq 'satellite' || $configtype eq 'internet' || $configtype eq 'smarthost') {
push @local_domains, split(/[ ,]+/, get_value("exim/eximconfig/other_hostnames"));
push @relay_domains, split(/[ ,]+/, get_value("exim/eximconfig/relay_domains"));
push @relay_nets, split(/[ ,]+/, get_value("exim/eximconfig/relay_nets"));
}
my $readhost;
if ($configtype eq 'satellite') {
$readhost = get_value("exim/eximconfig/readhost");
}
my $smarthost;
if ($configtype eq 'smarthost' || $configtype eq 'satellite') {
$smarthost = get_value("exim/eximconfig/smarthost");
}
my $overwrite_aliases = get_value("exim/eximconfig/overwrite_aliases") eq 'true';
my @postmasters = split(/[ ,]+/, get_value("exim/eximconfig/postmaster"));
my $mailbox_format = get_value("exim/eximconfig/mailbox_format");
my $local_delivery;
if ($mailbox_format eq 'spool') {
$local_delivery = 'mail_spool';
}
elsif ($mailbox_format eq 'maildir') {
$local_delivery = 'maildir_home';
}
else {
die "Unrecognised mailbox format \"$mailbox_format\"\n";
}
my $use_maildrop = ($mailbox_format eq 'maildir') && (get_value("exim/eximconfig/auto_maildrop") eq 'true');
my $use_procmail = ($mailbox_format eq 'spool') && (get_value("exim/eximconfig/auto_procmail") eq 'true');
# Read password file and find users that need redirection
my @redirusers = ('nobody', 'hostmaster', 'usenet', 'news', 'webmaster', 'www', 'ftp', 'abuse', 'noc', 'security');
while (my @a = getpwent) {
next unless ($a[2] < 1000);
next if ($a[0] eq 'root');
push @redirusers, $a[0];
}
######################################################################
# Show summary on stderr
sub say {
my @words = map { split(/\s+/, $_) } @_;
my $out = '';
while (@words) {
my $word = shift @words;
if (length($out)+length($word)+1 > 70) {
print STDERR "$out\n";
$out = '';
}
$out .= "$word ";
}
print STDERR "$out\n" if ($out);
print STDERR "\n";
}
say("Now using your answers to debconf questions to configure Exim 4. \
Use \"dpkg-reconfigure exim\" to change your configuration, or \
to disable automatic rebuilding of your configuration on each \
and every upgrade.");
say("Mail generated on this system will have \
'".($configtype eq 'satellite' ? $readhost : $visiblename)."' used \
as the domain part (after the \@) in the From: field and similar places.");
say("The following domain(s) will be recognised as referring to this system: ", @local_domains);
if (@relay_domains) {
say("Messages for the following domains will be relayed: ", @relay_domains);
}
say("Mail for postmaster, root etc. will be sent to: ", @postmasters);
if ($configtype ne 'satellite') {
if ($mailbox_format eq 'spool') {
say("Local mail is delivered to /var/spool/mail/\$USER mailboxes.", $use_procmail ? ".procmail files will automatically be used by procmail if found" : "");
}
elsif ($mailbox_format eq 'maildir') {
say("Local mail is delivered to \$HOME/Maildir directories.", $use_procmail ? ".mailfilter files will automatically be used by maildrop if found" : "");
}
}
if ($configtype eq 'internet') {
say("Outbound remote mail is lookup up in the Internet DNS, and delivered using that data if any is found; otherwise such messages are bounced.");
}
elsif ($configtype eq 'smarthost') {
say("Outbound remote mail is sent via $smarthost");
}
elsif ($configtype eq 'satellite') {
say("All mail is being routed and delivered via $smarthost");
}
elsif ($configtype eq 'local') {
say("Any mail destined for remote addresses is bounced.");
}
say("Note that you can set email addresses used for outgoing mail by editing /etc/email-addresses.");
######################################################################
# Write $visiblename into /etc/mailname
if (open(MAILNAME, ">/etc/mailname")) {
print STDERR "Writing /etc/mailname...\n";
print MAILNAME "$visiblename\n";
close(MAILNAME);
}
else {
warn "Unable to write /etc/mailname: $!\n";
}
######################################################################
# This subroutine autodetects whether a file was generated ourselves
sub autogenerated($) {
my $filename = shift;
open(FILE, $filename) or die "Unable to read $filename: $!\n";
my $top = <FILE>;
close FILE;
return ($top eq "# AUTOGENERATED\n");
}
######################################################################
# Write /etc/aliases
if ($overwrite_aliases) {
if (open(ALIASES, ">/etc/aliases.exim-pkg-new.$$")) {
print STDERR "Writing /etc/aliases...\n";
print ALIASES <<EOF
# AUTOGENERATED
#
# This is the aliases file - it says who gets mail for whom.
#
# This file automatically generated. You must reconfigure Exim to stop
# regenerating this file before you make changes yourself, or your
# changes will be lost when you upgrade Exim.
# (use: dpkg-reconfigure exim)
#
EOF
;
print ALIASES "root: ".join(', ', map { "real-$_" } @postmasters)."\n";
print ALIASES "postmaster: root\n";
print ALIASES "mailer-daemon: postmaster\n";
foreach my $redir (@redirusers) {
print ALIASES "$redir: root\n";
}
close(ALIASES);
if (-f "/etc/aliases" && !autogenerated("/etc/aliases")) {
print "Backing up old /etc/aliases to /etc/aliases.O...\n";
unlink("/etc/aliases.O");
rename("/etc/aliases", "/etc/aliases.O")
or die "Unable to rename /etc/aliases to /etc/aliases.O: $!\n";
}
rename("/etc/aliases.exim-pkg-new.$$", "/etc/aliases")
or die "Unable to rename /etc/aliases.exim-pkg-new.$$ to /etc/aliases: $!\n";
}
else {
warn "Unable to write /etc/aliases.exim-pkg-new.$$: $!\n";
}
}
else {
print STDERR "Not writing /etc/aliases by user request\n";
}
######################################################################
# Write /etc/exim4/exim4.conf
unless (open(EXIMCONF, ">/etc/exim4/exim4.conf.exim-pkg-new.$$")) {
die "Unable to write /etc/exim4/exim4.conf.exim-pkg-new.$$: $!\n";
}
print STDERR "Writing /etc/exim4/exim4.conf...\n";
my $local_domains = join(' : ', '@', @local_domains);
my $relay_domains = join(' : ', @relay_domains);
my $relay_nets = join(' : ', @relay_nets);
my $now = localtime(time);
print EXIMCONF <<EOF;
# AUTOGENERATED
# Runtime configuration file for Exim
# This file generated by debconf_eximconfig, $now
# THIS FILE WILL BE REGENERATED EVERY TIME THE EXIM PACKAGE IS UPGRADED
# UNLESS YOU RUN
# dpkg-reconfigure exim
# AND CHOOSE "NONE" AS THE CONFIGURATION TYPE.
# (you can check what the configuration type is currently set to using
# the command
# debconf-show exim | grep configtype
# )
# Main configuration settings
# Let Exim autodetct this; we autodetected $syshostname at run-time
# primary_hostname =
EOF
print EXIMCONF "domainlist local_domains = $local_domains\n";
print EXIMCONF "domainlist relay_to_domains = $relay_domains\n";
print EXIMCONF "hostlist relay_from_hosts = $relay_nets\n\n";
print EXIMCONF "qualify_domain = $visiblename\n\n";
print EXIMCONF <<EOF;
acl_smtp_rcpt = acl_check_rcpt
# qualify_recipient =
# allow_domain_literals
never_users = root
host_lookup = *
rfc1413_hosts = *
rfc1413_query_timeout = 30s
# sender_unqualified_hosts =
# recipient_unqualified_hosts =
# percent_hack_domains =
ignore_bounce_errors_after = 2d
timeout_frozen_after = 7d
freeze_tell = postmaster
received_header_text = "Received: \\
\${if def:sender_rcvhost {from \${sender_rcvhost}\\n\\t}\\
{\${if def:sender_ident {from \${sender_ident} }}\\
\${if def:sender_helo_name {(helo=\${sender_helo_name})\\n\\t}}}}\\
by \${primary_hostname} \\
\${if def:received_protocol {with \${received_protocol}}} \\
(Exim \${version_number} #\${compile_number} (Debian) [+araqnid])\\n\\t\\
id \${message_id}\\
\${if def:received_for {\\n\\tfor <\$received_for>}}"
begin acl
acl_check_rcpt:
accept hosts = :
deny local_parts = ^.[\@\%!/|] : ^\\\\.
accept local_parts = postmaster
domains = +local_domains
require verify = sender
# deny message = rejected because \$sender_host_address is in a black list at \$dnslist_domain\\n\$dnslist_text
# dnslists = black.list.example.com
# warn message = X-Warning: \$sender_host_address is in a black list at \$dnslist_domain
# dnslists = black.list.example.com
accept domains = +local_domains
endpass
message = unknown user
verify = recipient
accept domains = +relay_to_domains
endpass
message = unrouteable address
verify = recipient
accept hosts = +relay_from_hosts
accept authenticated = *
deny message = relay not permitted
begin routers
EOF
;
if ($configtype eq 'internet') {
print EXIMCONF <<EOF;
dnslookup:
driver = dnslookup
domains = ! +local_domains
transport = remote_smtp
ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8
no_more
EOF
}
elsif ($configtype eq 'smarthost' || $configtype eq 'satellite') {
print EXIMCONF <<EOF;
smarthost:
driver = manualroute
domains = ! +local_domains
transport = remote_smtp
route_list = * $smarthost
no_more
EOF
}
else {
print EXIMCONF <<EOF;
# Stand-alone system, so generate an error for amil to a non-local domain
nonlocal:
driver = redirect
allow_fail
data = :fail: Mailing to remote domains not supported
no_more
domains = ! +local_domains
EOF
}
print EXIMCONF <<EOF;
# The "no_more" above means that all routers below here are for
# domains in the local_domains list, i.e. just like Exim 3 directors.
real_local:
driver = accept
local_part_prefix = real-
check_local_user
transport = $local_delivery
system_aliases:
driver = redirect
allow_fail
allow_defer
data = \${lookup{\$local_part}lsearch{/etc/aliases}}
file_transport = address_file
pipe_transport = address_pipe
EOF
;
if ($configtype eq 'satellite') {
print EXIMCONF <<EOF;
hub_user:
driver = redirect
data = \${local_part}\@$readhost
check_local_user
EOF
;
}
print EXIMCONF <<EOF;
userforward:
driver = redirect
check_local_user
file = \$home/.forward
no_verify
no_expn
check_ancestor
# allow_filter
file_transport = address_file
pipe_transport = address_pipe
reply_transport = address_reply
EOF
if ($use_procmail) {
print EXIMCONF <<EOF;
procmail:
driver = accept
check_local_user
transport = procmail_pipe
require_files = \${local_part}:\${home}/.procmailrc:+/usr/bin/procmail
no_verify
no_expn
EOF
}
if ($use_maildrop) {
print EXIMCONF <<EOF;
maildrop:
driver = accept
check_local_user
transport = maildrop_pipe
require_files = \${local_part}:\${home}/.mailfilter:+/usr/bin/maildrop
no_verify
no_expn
EOF
}
print EXIMCONF <<EOF;
local_user:
driver = accept
check_local_user
transport = $local_delivery
begin transports
EOF
;
if ($configtype ne 'local') {
print EXIMCONF <<EOF;
remote_smtp:
driver = smtp
EOF
;
}
if ($mailbox_format eq 'spool') {
print EXIMCONF <<EOF;
mail_spool:
driver = appendfile
file = /var/spool/mail/\$local_part
delivery_date_add
envelope_to_add
return_path_add
group = mail
mode = 0660
EOF
}
if ($mailbox_format eq 'maildir') {
print EXIMCONF <<EOF;
maildir_home:
driver = appendfile
directory = \$home/Maildir
maildir_format
mode = 0600
EOF
}
print EXIMCONF <<EOF;
address_pipe:
driver = pipe
return_output
address_file:
driver = appendfile
delivery_date_add
envelope_to_add
return_path_add
address_reply:
driver = autoreply
EOF
if ($use_maildrop) {
print EXIMCONF <<EOF;
maildrop_pipe:
driver = pipe
path = "/bin:/usr/bin:/usr/local/bin"
command = "/usr/bin/maildrop"
return_path_add
delivery_date_add
envelope_to_add
EOF
}
if ($use_procmail) {
print EXIMCONF <<EOF;
procmail_pipe:
driver = pipe
path = "/bin:/usr/bin:/usr/local/bin"
command = "/usr/bin/procmail"
return_path_add
delivery_date_add
envelope_to_add
EOF
}
print EXIMCONF <<EOF;
begin retry
# Domain Error Retries
# ------ ----- -------
* * F,2h,15m; G,16h,1h,1.5; F,4d,6h
begin rewrite
EOF
;
print EXIMCONF <<EOF;
# This rewriting rule is particularly useful for dialup users who
# don't have their own domain, but could be useful for anyone.
# It looks up the real address of all local users in a file
EOF
;
for my $domain (@local_domains) {
print EXIMCONF "*\@$domain \${lookup{\${local_part}}lsearch{/etc/email-addresses}{\$value}fail} Ffrs\n";
}
if ($configtype eq 'satellite') {
print EXIMCONF <<EOF
# These rewriters make sure the mail messages appear to have originated
# from the real mail-reading host.
EOF
;
my $fuser = $postmasters[0];
for my $domain (@local_domains) {
print EXIMCONF "^(?i)(root|postmaster|mailer-daemon)\@$domain \$\{local_part\}\@in.limbo Ffr\n"
if (@postmasters);
print EXIMCONF "*\@$domain \$\{local_part\}\@$readhost Ffr\n";
}
print EXIMCONF "*\@in.limbo $fuser\@$readhost Ffr\n"
if (@postmasters);
}
print EXIMCONF <<'EOF';
begin authenticators
# The examples below are for server side authentication; they allow two
# styles of plain-text authentication against an /etc/exim4/passwd file
# which should have user IDs in the first column and crypted passwords
# in the second.
# plain:
# driver = plaintext
# public_name = PLAIN
# server_condition = "${if crypteq{$2}{${extract{1}{:}{${lookup{$1}lsearch{/etc/exim4/passwd}{$value}{*:*}}}}}{1}{0}}"
# server_set_id = $1
#
# login:
# driver = plaintext
# public_name = LOGIN
# server_prompts = "Username:: : Password::"
# server_condition = "${if crypteq{$3}{${extract{1}{:}{${lookup{$2}lsearch{/etc/exim4/passwd}{$value}{*:*}}}}}{1}{0}}"
# server_set_id = $3
#
# cram_md5:
# driver = cram_md5
# public_name = CRAM-MD5
# server_condition = "${if crypteq{$2}{${extract{1}{:}{${lookup{$1}lsearch{/etc/exim4/passwd}{$value}{*:*}}}}}{1}{0}}"
# server_set_id = $1
# Here is an example of CRAM-MD5 authentication against PostgreSQL:
#
# psqldb_auth:
# driver = cram_md5
# public_name = CRAM-MD5
# server_condition = "${if crypteq{$2}{${lookup pgsql{SELECT pw FROM users WHERE username = '${quote_pgsql:$1}'}{$value}fail}{1}{0}}"
# server_set_id = $1
# These examples below are the equivalent for client side authentication.
# They assume that you only use client side authentication to connect to
# one host (such as a smarthost at your ISP), or else use the same user
# name and password everywhere
# plain:
# driver = plaintext
# public_name = PLAIN
# client_send = "^username^password"
#
# login:
# driver = plaintext
# public_name = LOGIN
# client_send = ": username : password"
#
# cram_md5:
# driver = cram_md5
# public_name = CRAM-MD5
# client_name = username
# client_secret = password
EOF
;
close(EXIMCONF);
unlink("/etc/exim4/exim4.conf.O");
if (-f "/etc/exim4/exim4.conf") {
rename("/etc/exim4/exim4.conf", "/etc/exim4/exim4.conf.O")
or die "Unable to move /etc/exim4/exim4.conf to /etc/exim4/exim4.conf.O: $!\n";
}
rename("/etc/exim4/exim4.conf.exim-pkg-new.$$", "/etc/exim4/exim4.conf")
or die "Unable to move /etc/exim4/exim4.conf.exim-pkg-new.$$ to /etc/exim4/exim4.conf: $!\n";
|