Testsuite: find a group name if 'mail' is not available.
[exim.git] / test / runtest
CommitLineData
b057ad11
HSHR
1#! /usr/bin/env perl
2# We use env, because in some environments of our build farm
3# the Perl 5.010 interpreter is only reachable via $PATH
151b83f8 4
151b83f8
PH
5###############################################################################
6# This is the controlling script for the "new" test suite for Exim. It should #
7# be possible to export this suite for running on a wide variety of hosts, in #
8# contrast to the old suite, which was very dependent on the environment of #
9# Philip Hazel's desktop computer. This implementation inspects the version #
10# of Exim that it finds, and tests only those features that are included. The #
11# surrounding environment is also tested to discover what is available. See #
12# the README file for details of how it all works. #
13# #
14# Implementation started: 03 August 2005 by Philip Hazel #
15# Placed in the Exim CVS: 06 February 2006 #
16###############################################################################
17
3ff2360f 18#use strict;
b057ad11
HSHR
19use 5.010;
20use warnings;
21
151b83f8
PH
22use Errno;
23use FileHandle;
df613eb4 24use IO::Socket::INET;
151b83f8 25use Socket;
f675bf30 26use Time::Local;
28e8a0f7
HSHR
27use Cwd;
28use File::Basename;
1f187290
HSHR
29use FindBin qw'$Bin';
30
31use lib "$Bin/lib";
32use Exim::Runtest;
33
2f8e6f30 34use if $ENV{DEBUG} && $ENV{DEBUG} =~ /\bruntest\b/ => ('Smart::Comments' => '####');
151b83f8
PH
35
36
37# Start by initializing some global variables
38
b1770b6e 39$testversion = "4.80 (08-May-12)";
151b83f8 40
83e2f8a2
PP
41# This gets embedded in the D-H params filename, and the value comes
42# from asking GnuTLS for "normal", but there appears to be no way to
43# use certtool/... to ask what that value currently is. *sigh*
9d26b8c0
PP
44# We also clamp it because of NSS interop, see addition of tls_dh_max_bits.
45# This value is correct as of GnuTLS 2.12.18 as clamped by tls_dh_max_bits.
46# normal = 2432 tls_dh_max_bits = 2236
47$gnutls_dh_bits_normal = 2236;
83e2f8a2 48
37acd760 49$cf = "bin/cf -exact";
151b83f8
PH
50$cr = "\r";
51$debug = 0;
2c9f7ff8 52$flavour = 'FOO';
c1c469db 53$force_continue = 0;
151b83f8 54$force_update = 0;
c1c469db 55$log_failed_filename = "failed-summary.log";
151b83f8
PH
56$more = "less -XF";
57$optargs = "";
58$save_output = 0;
59$server_opts = "";
2c9f7ff8 60$valgrind = 0;
151b83f8
PH
61
62$have_ipv4 = 1;
63$have_ipv6 = 1;
21c28500 64$have_largefiles = 0;
151b83f8
PH
65
66$test_start = 1;
67$test_end = $test_top = 8999;
68$test_special_top = 9999;
69@test_list = ();
70@test_dirs = ();
71
72
73# Networks to use for DNS tests. We need to choose some networks that will
74# never be used so that there is no chance that the host on which we are
75# running is actually in one of the test networks. Private networks such as
76# the IPv4 10.0.0.0/8 network are no good because hosts may well use them.
77# Rather than use some unassigned numbers (that might become assigned later),
78# I have chosen some multicast networks, in the belief that such addresses
79# won't ever be assigned to hosts. This is the only place where these numbers
80# are defined, so it is trivially possible to change them should that ever
81# become necessary.
82
83$parm_ipv4_test_net = "224";
84$parm_ipv6_test_net = "ff00";
85
86# Port numbers are currently hard-wired
87
88$parm_port_n = 1223; # Nothing listening on this port
89$parm_port_s = 1224; # Used for the "server" command
90$parm_port_d = 1225; # Used for the Exim daemon
91$parm_port_d2 = 1226; # Additional for daemon
92$parm_port_d3 = 1227; # Additional for daemon
93$parm_port_d4 = 1228; # Additional for daemon
df613eb4 94my $dynamic_socket; # allocated later for PORT_DYNAMIC
151b83f8 95
1f187290
HSHR
96# Find a suiteable group name for test (currently only 0001
97# uses a group name. A numeric group id would do
98my $parm_mailgroup = Exim::Runtest::mailgroup('mail');
99
df88d501 100# Manually set locale
d63a9563 101$ENV{LC_ALL} = 'C';
df88d501 102
895ddecb
HSHR
103# In some environments USER does not exists, but we
104# need it for some test(s)
105$ENV{USER} = getpwuid($>)
106 if not exists $ENV{USER};
151b83f8 107
d63a9563
HSHR
108my ($parm_configure_owner, $parm_configure_group);
109my ($parm_ipv4, $parm_ipv6);
110my $parm_hostname;
151b83f8
PH
111
112###############################################################################
113###############################################################################
114
115# Define a number of subroutines
116
117###############################################################################
118###############################################################################
119
120
121##################################################
122# Handle signals #
123##################################################
124
125sub pipehandler { $sigpipehappened = 1; }
126
127sub inthandler { print "\n"; tests_exit(-1, "Caught SIGINT"); }
128
129
130##################################################
131# Do global macro substitutions #
132##################################################
133
134# This function is applied to configurations, command lines and data lines in
135# scripts, and to lines in the files of the aux-var-src and the dnszones-src
136# directory. It takes one argument: the current test number, or zero when
137# setting up files before running any tests.
138
139sub do_substitute{
140s?\bCALLER\b?$parm_caller?g;
1b781f48 141s?\bCALLERGROUP\b?$parm_caller_group?g;
151b83f8
PH
142s?\bCALLER_UID\b?$parm_caller_uid?g;
143s?\bCALLER_GID\b?$parm_caller_gid?g;
144s?\bCLAMSOCKET\b?$parm_clamsocket?g;
145s?\bDIR/?$parm_cwd/?g;
146s?\bEXIMGROUP\b?$parm_eximgroup?g;
147s?\bEXIMUSER\b?$parm_eximuser?g;
148s?\bHOSTIPV4\b?$parm_ipv4?g;
149s?\bHOSTIPV6\b?$parm_ipv6?g;
150s?\bHOSTNAME\b?$parm_hostname?g;
151s?\bPORT_D\b?$parm_port_d?g;
152s?\bPORT_D2\b?$parm_port_d2?g;
153s?\bPORT_D3\b?$parm_port_d3?g;
154s?\bPORT_D4\b?$parm_port_d4?g;
155s?\bPORT_N\b?$parm_port_n?g;
156s?\bPORT_S\b?$parm_port_s?g;
157s?\bTESTNUM\b?$_[0]?g;
158s?(\b|_)V4NET([\._])?$1$parm_ipv4_test_net$2?g;
159s?\bV6NET:?$parm_ipv6_test_net:?g;
df613eb4 160s?\bPORT_DYNAMIC\b?$dynamic_socket->sockport()?eg;
1f187290 161s?\bMAILGROUP\b?$parm_mailgroup?g;
151b83f8
PH
162}
163
164
1ca9f507
PP
165##################################################
166# Any state to be preserved across tests #
167##################################################
168
169my $TEST_STATE = {};
170
151b83f8
PH
171
172##################################################
173# Subroutine to tidy up and exit #
174##################################################
175
176# In all cases, we check for any Exim daemons that have been left running, and
177# kill them. Then remove all the spool data, test output, and the modified Exim
178# binary if we are ending normally.
179
180# Arguments:
181# $_[0] = 0 for a normal exit; full cleanup done
182# $_[0] > 0 for an error exit; no files cleaned up
183# $_[0] < 0 for a "die" exit; $_[1] contains a message
184
185sub tests_exit{
186my($rc) = $_[0];
187my($spool);
188
189# Search for daemon pid files and kill the daemons. We kill with SIGINT rather
190# than SIGTERM to stop it outputting "Terminated" to the terminal when not in
191# the background.
192
1ca9f507
PP
193if (exists $TEST_STATE->{exim_pid})
194 {
195 $pid = $TEST_STATE->{exim_pid};
196 print "Tidyup: killing wait-mode daemon pid=$pid\n";
ee15e974 197 system("sudo kill -INT $pid");
1ca9f507
PP
198 }
199
151b83f8
PH
200if (opendir(DIR, "spool"))
201 {
202 my(@spools) = sort readdir(DIR);
203 closedir(DIR);
204 foreach $spool (@spools)
205 {
206 next if $spool !~ /^exim-daemon./;
207 open(PID, "spool/$spool") || die "** Failed to open \"spool/$spool\": $!\n";
208 chomp($pid = <PID>);
209 close(PID);
210 print "Tidyup: killing daemon pid=$pid\n";
ee15e974 211 system("sudo rm -f spool/$spool; sudo kill -INT $pid");
151b83f8
PH
212 }
213 }
214else
215 { die "** Failed to opendir(\"spool\"): $!\n" unless $!{ENOENT}; }
216
217# Close the terminal input and remove the test files if all went well, unless
218# the option to save them is set. Always remove the patched Exim binary. Then
219# exit normally, or die.
220
221close(T);
222system("sudo /bin/rm -rf ./spool test-* ./dnszones/*")
223 if ($rc == 0 && !$save_output);
224
b3e39dd7
TL
225system("sudo /bin/rm -rf ./eximdir/*")
226 if (!$save_output);
6bf5d8f2
PP
227
228print "\nYou were in test $test at the end there.\n\n" if defined $test;
151b83f8
PH
229exit $rc if ($rc >= 0);
230die "** runtest error: $_[1]\n";
231}
232
233
234
235##################################################
236# Subroutines used by the munging subroutine #
237##################################################
238
239# This function is used for things like message ids, where we want to generate
240# more than one value, but keep a consistent mapping throughout.
241#
242# Arguments:
243# $oldid the value from the file
244# $base a base string into which we insert a sequence
245# $sequence the address of the current sequence counter
246
247sub new_value {
248my($oldid, $base, $sequence) = @_;
249my($newid) = $cache{$oldid};
250if (! defined $newid)
251 {
252 $newid = sprintf($base, $$sequence++);
253 $cache{$oldid} = $newid;
254 }
255return $newid;
256}
257
258
f675bf30
JH
259# This is used while munging the output from exim_dumpdb.
260# May go wrong across DST changes.
151b83f8
PH
261
262sub date_seconds {
263my($day,$month,$year,$hour,$min,$sec) =
264 $_[0] =~ /^(\d\d)-(\w\w\w)-(\d{4})\s(\d\d):(\d\d):(\d\d)/;
f675bf30
JH
265my($mon);
266if ($month =~ /Jan/) {$mon = 0;}
267elsif($month =~ /Feb/) {$mon = 1;}
268elsif($month =~ /Mar/) {$mon = 2;}
269elsif($month =~ /Apr/) {$mon = 3;}
270elsif($month =~ /May/) {$mon = 4;}
271elsif($month =~ /Jun/) {$mon = 5;}
272elsif($month =~ /Jul/) {$mon = 6;}
273elsif($month =~ /Aug/) {$mon = 7;}
274elsif($month =~ /Sep/) {$mon = 8;}
275elsif($month =~ /Oct/) {$mon = 9;}
276elsif($month =~ /Nov/) {$mon = 10;}
277elsif($month =~ /Dec/) {$mon = 11;}
278return timelocal($sec,$min,$hour,$day,$mon,$year);
151b83f8
PH
279}
280
281
282# This is a subroutine to sort maildir files into time-order. The second field
283# is the microsecond field, and may vary in length, so must be compared
284# numerically.
285
286sub maildirsort {
287return $a cmp $b if ($a !~ /^\d+\.H\d/ || $b !~ /^\d+\.H\d/);
288my($x1,$y1) = $a =~ /^(\d+)\.H(\d+)/;
289my($x2,$y2) = $b =~ /^(\d+)\.H(\d+)/;
290return ($x1 != $x2)? ($x1 <=> $x2) : ($y1 <=> $y2);
291}
292
293
294
295##################################################
296# Subroutine list files below a directory #
297##################################################
298
299# This is used to build up a list of expected mail files below a certain path
300# in the directory tree. It has to be recursive in order to deal with multiple
301# maildir mailboxes.
302
303sub list_files_below {
304my($dir) = $_[0];
305my(@yield) = ();
306my(@sublist, $file);
307
308opendir(DIR, $dir) || tests_exit(-1, "Failed to open $dir: $!");
309@sublist = sort maildirsort readdir(DIR);
310closedir(DIR);
311
312foreach $file (@sublist)
313 {
314 next if $file eq "." || $file eq ".." || $file eq "CVS";
315 if (-d "$dir/$file")
316 { @yield = (@yield, list_files_below("$dir/$file")); }
317 else
318 { push @yield, "$dir/$file"; }
319 }
320
321return @yield;
322}
323
324
325
326##################################################
327# Munge a file before comparing #
328##################################################
329
330# The pre-processing turns all dates, times, Exim versions, message ids, and so
331# on into standard values, so that the compare works. Perl's substitution with
332# an expression provides a neat way to do some of these changes.
333
334# We keep a global associative array for repeatedly turning the same values
335# into the same standard values throughout the data from a single test.
336# Message ids get this treatment (can't be made reliable for times), and
337# times in dumped retry databases are also handled in a special way, as are
338# incoming port numbers.
339
340# On entry to the subroutine, the file to write to is already opened with the
341# name MUNGED. The input file name is the only argument to the subroutine.
342# Certain actions are taken only when the name contains "stderr", "stdout",
343# or "log". The yield of the function is 1 if a line matching "*** truncated
344# ***" is encountered; otherwise it is 0.
345
346sub munge {
347my($file) = $_[0];
c9a55f6a 348my($extra) = $_[1];
151b83f8
PH
349my($yield) = 0;
350my(@saved) = ();
351
2f8e6f30
HSHR
352local $_;
353
151b83f8
PH
354open(IN, "$file") || tests_exit(-1, "Failed to open $file: $!");
355
356my($is_log) = $file =~ /log/;
357my($is_stdout) = $file =~ /stdout/;
358my($is_stderr) = $file =~ /stderr/;
359
360# Date pattern
361
362$date = "\\d{2}-\\w{3}-\\d{4}\\s\\d{2}:\\d{2}:\\d{2}";
363
364# Pattern for matching pids at start of stderr lines; initially something
365# that won't match.
366
367$spid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
368
369# Scan the file and make the changes. Near the bottom there are some changes
370# that are specific to certain file types, though there are also some of those
371# inline too.
372
bc3c7bb7 373LINE: while(<IN>)
151b83f8 374 {
8f1cff48 375RESET_AFTER_EXTRA_LINE_READ:
c9a55f6a
JH
376 # Custom munges
377 if ($extra)
378 {
379 next if $extra =~ m%^/% && eval $extra;
380 eval $extra if $extra =~ m/^s/;
381 }
382
151b83f8
PH
383 # Check for "*** truncated ***"
384 $yield = 1 if /\*\*\* truncated \*\*\*/;
385
386 # Replace the name of this host
387 s/\Q$parm_hostname\E/the.local.host.name/g;
388
389 # But convert "name=the.local.host address=127.0.0.1" to use "localhost"
390 s/name=the\.local\.host address=127\.0\.0\.1/name=localhost address=127.0.0.1/g;
391
d40f27c3
JH
392 # The name of the shell may vary
393 s/\s\Q$parm_shell\E\b/ ENV_SHELL/;
394
151b83f8
PH
395 # Replace the path to the testsuite directory
396 s?\Q$parm_cwd\E?TESTSUITE?g;
397
398 # Replace the Exim version number (may appear in various places)
a769a501 399 # patchexim should have fixed this for us
026d45f5 400 #s/(Exim) \d+\.\d+[\w_-]*/$1 x.yz/i;
151b83f8
PH
401
402 # Replace Exim message ids by a unique series
403 s/((?:[^\W_]{6}-){2}[^\W_]{2})
404 /new_value($1, "10Hm%s-0005vi-00", \$next_msgid)/egx;
405
406 # The names of lock files appear in some error and debug messages
407 s/\.lock(\.[-\w]+)+(\.[\da-f]+){2}/.lock.test.ex.dddddddd.pppppppp/;
408
409 # Unless we are in an IPv6 test, replace IPv4 and/or IPv6 in "listening on
410 # port" message, because it is not always the same.
411 s/port (\d+) \([^)]+\)/port $1/g
412 if !$is_ipv6test && m/listening for SMTP(S?) on port/;
413
414 # Challenges in SPA authentication
415 s/TlRMTVNTUAACAAAAAAAAAAAoAAABgg[\w+\/]+/TlRMTVNTUAACAAAAAAAAAAAoAAABggAAAEbBRwqFwwIAAAAAAAAAAAAt1sgAAAAA/;
416
417 # PRVS values
85b6260a
PH
418 s?prvs=([^/]+)/[\da-f]{10}@?prvs=$1/xxxxxxxxxx@?g; # Old form
419 s?prvs=[\da-f]{10}=([^@]+)@?prvs=xxxxxxxxxx=$1@?g; # New form
151b83f8
PH
420
421 # Error lines on stdout from SSL contain process id values and file names.
422 # They also contain a source file name and line number, which may vary from
423 # release to release.
424 s/^\d+:error:/pppp:error:/;
425 s/:(?:\/[^\s:]+\/)?([^\/\s]+\.c):\d+:/:$1:dddd:/;
426
b6d22362
PH
427 # There are differences in error messages between OpenSSL versions
428 s/SSL_CTX_set_cipher_list/SSL_connect/;
429
151b83f8
PH
430 # One error test in expansions mentions base 62 or 36
431 s/is not a base (36|62) number/is not a base 36\/62 number/;
432
433 # This message sometimes has a different number of seconds
434 s/forced fail after \d seconds/forced fail after d seconds/;
435
436 # This message may contain a different DBM library name
437 s/Failed to open \S+( \([^\)]+\))? file/Failed to open DBM file/;
438
439 # The message for a non-listening FIFO varies
440 s/:[^:]+: while opening named pipe/: Error: while opening named pipe/;
441
151b83f8
PH
442 # Debugging output of lists of hosts may have different sort keys
443 s/sort=\S+/sort=xx/ if /^\S+ (?:\d+\.){3}\d+ mx=\S+ sort=\S+/;
444
445 # Random local part in callout cache testing
446 s/myhost.test.ex-\d+-testing/myhost.test.ex-dddddddd-testing/;
9bfc60eb 447 s/the.local.host.name-\d+-testing/the.local.host.name-dddddddd-testing/;
151b83f8 448
1b781f48
PH
449 # File descriptor numbers may vary
450 s/^writing data block fd=\d+/writing data block fd=dddd/;
fc43746d 451 s/(running as transport filter:) fd_write=\d+ fd_read=\d+/$1 fd_write=dddd fd_read=dddd/;
1b781f48 452
151b83f8
PH
453
454 # ======== Dumpdb output ========
455 # This must be before the general date/date munging.
456 # Time data lines, which look like this:
457 # 25-Aug-2000 12:11:37 25-Aug-2000 12:11:37 26-Aug-2000 12:11:37
458 if (/^($date)\s+($date)\s+($date)(\s+\*)?\s*$/)
459 {
460 my($date1,$date2,$date3,$expired) = ($1,$2,$3,$4);
461 $expired = "" if !defined $expired;
462 my($increment) = date_seconds($date3) - date_seconds($date2);
463
464 # We used to use globally unique replacement values, but timing
465 # differences make this impossible. Just show the increment on the
466 # last one.
467
468 printf MUNGED ("first failed = time last try = time2 next try = time2 + %s%s\n",
469 $increment, $expired);
470 next;
471 }
472
473 # more_errno values in exim_dumpdb output which are times
474 s/T:(\S+)\s-22\s(\S+)\s/T:$1 -22 xxxx /;
475
476
477 # ======== Dates and times ========
478
479 # Dates and times are all turned into the same value - trying to turn
480 # them into different ones cannot be done repeatedly because they are
481 # real time stamps generated while running the test. The actual date and
482 # time used was fixed when I first started running automatic Exim tests.
483
484 # Date/time in header lines and SMTP responses
485 s/[A-Z][a-z]{2},\s\d\d?\s[A-Z][a-z]{2}\s\d\d\d\d\s\d\d\:\d\d:\d\d\s[-+]\d{4}
486 /Tue, 2 Mar 1999 09:44:33 +0000/gx;
487
488 # Date/time in logs and in one instance of a filter test
489 s/^\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d(\s[+-]\d\d\d\d)?/1999-03-02 09:44:33/gx;
490 s/^Logwrite\s"\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Logwrite "1999-03-02 09:44:33/gx;
491
492 # Date/time in message separators
493 s/(?:[A-Z][a-z]{2}\s){2}\d\d\s\d\d:\d\d:\d\d\s\d\d\d\d
494 /Tue Mar 02 09:44:33 1999/gx;
495
496 # Date of message arrival in spool file as shown by -Mvh
497 s/^\d{9,10}\s0$/ddddddddd 0/;
498
499 # Date/time in mbx mailbox files
500 s/\d\d-\w\w\w-\d\d\d\d\s\d\d:\d\d:\d\d\s[-+]\d\d\d\d,/06-Sep-1999 15:52:48 +0100,/gx;
501
ea49d0e1 502 # Dates/times in debugging output for writing retry records
151b83f8
PH
503 if (/^ first failed=(\d+) last try=(\d+) next try=(\d+) (.*)$/)
504 {
505 my($next) = $3 - $2;
506 $_ = " first failed=dddd last try=dddd next try=+$next $4\n";
507 }
c816d124 508 s/^(\s*)now=\d+ first_failed=\d+ next_try=\d+ expired=(\d)/$1now=tttt first_failed=tttt next_try=tttt expired=$2/;
148e1ac6 509 s/^(\s*)received_time=\d+ diff=\d+ timeout=(\d+)/$1received_time=tttt diff=tttt timeout=$2/;
151b83f8
PH
510
511 # Time to retry may vary
ea49d0e1
PH
512 s/time to retry = \S+/time to retry = tttt/;
513 s/retry record exists: age=\S+/retry record exists: age=ttt/;
727071f8 514 s/failing_interval=\S+ message_age=\S+/failing_interval=ttt message_age=ttt/;
151b83f8
PH
515
516 # Date/time in exim -bV output
517 s/\d\d-[A-Z][a-z]{2}-\d{4}\s\d\d:\d\d:\d\d/07-Mar-2000 12:21:52/g;
518
1cc59d37 519 # Time on queue tolerance
74377a62 520 s/(QT|D)=1s/$1=0s/;
1cc59d37 521
f3f065bb
PH
522 # Eximstats heading
523 s/Exim\sstatistics\sfrom\s\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d\sto\s
524 \d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d/Exim statistics from <time> to <time>/x;
525
7f8794a2
JH
526 # Treat ECONNRESET the same as ECONNREFUSED. At least some systems give
527 # us the former on a new connection.
528 s/(could not connect to .*: Connection) reset by peer$/$1 refused/;
151b83f8 529
6bf5d8f2
PP
530 # ======== TLS certificate algorithms ========
531 # Test machines might have various different TLS library versions supporting
532 # different protocols; can't rely upon TLS 1.2's AES256-GCM-SHA384, so we
533 # treat the standard algorithms the same.
534 # So far, have seen:
d7e464f4 535 # TLSv1:AES128-GCM-SHA256:128
6bf5d8f2 536 # TLSv1:AES256-SHA:256
ce42f3ed 537 # TLSv1.1:AES256-SHA:256
6bf5d8f2 538 # TLSv1.2:AES256-GCM-SHA384:256
1508acb8 539 # TLSv1.2:DHE-RSA-AES256-SHA:256
75fe387d 540 # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
6bf5d8f2
PP
541 # We also need to handle the ciphersuite without the TLS part present, for
542 # client-ssl's output. We also see some older forced ciphersuites, but
543 # negotiating TLS 1.2 instead of 1.0.
544 # Mail headers (...), log-lines X=..., client-ssl output ...
545 # (and \b doesn't match between ' ' and '(' )
546
25ae05f8 547 s/( (?: (?:\b|\s) [\(=] ) | \s )TLSv1\.[12]:/$1TLSv1:/xg;
d7e464f4
JH
548 s/\bAES128-GCM-SHA256:128\b/AES256-SHA:256/g;
549 s/\bAES128-GCM-SHA256\b/AES256-SHA/g;
6bf5d8f2 550 s/\bAES256-GCM-SHA384\b/AES256-SHA/g;
1508acb8 551 s/\bDHE-RSA-AES256-SHA\b/AES256-SHA/g;
6bf5d8f2 552
75fe387d 553 # GnuTLS have seen:
62b56dbf
JH
554 # TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256
555 # TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128
75fe387d
PP
556 # TLS1.2:RSA_AES_256_CBC_SHA1:256 (canonical)
557 # TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128
558 #
559 # X=TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256
bc9a5bcb
JH
560 # X=TLS1.2:RSA_AES_256_CBC_SHA1:256
561 # X=TLS1.1:RSA_AES_256_CBC_SHA1:256
75fe387d
PP
562 # X=TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256
563 # and as stand-alone cipher:
62b56dbf 564 # ECDHE-RSA-AES256-SHA
75fe387d
PP
565 # DHE-RSA-AES256-SHA256
566 # DHE-RSA-AES256-SHA
567 # picking latter as canonical simply because regex easier that way.
568 s/\bDHE_RSA_AES_128_CBC_SHA1:128/RSA_AES_256_CBC_SHA1:256/g;
62b56dbf
JH
569 s/TLS1.[012]:((EC)?DHE_)?RSA_AES_(256|128)_(CBC|GCM)_SHA(1|256|384):(256|128)/TLS1.x:xxxxRSA_AES_256_CBC_SHAnnn:256/g;
570 s/\b(ECDHE-RSA-AES256-SHA|DHE-RSA-AES256-SHA256)\b/AES256-SHA/g;
571
572 # GnuTLS library error message changes
573 s/No certificate was found/The peer did not send any certificate/g;
574#(dodgy test?) s/\(certificate verification failed\): invalid/\(gnutls_handshake\): The peer did not send any certificate./g;
575 s/\(gnutls_priority_set\): No or insufficient priorities were set/\(gnutls_handshake\): Could not negotiate a supported cipher suite/g;
576
2b4a568d
JH
577 # (this new one is a generic channel-read error, but the testsuite
578 # only hits it in one place)
c562fd30 579 s/TLS error on connection \(gnutls_handshake\): Error in the pull function\./a TLS session is required but an attempt to start TLS failed/g;
2b4a568d 580
62b56dbf 581 # (replace old with new, hoping that old only happens in one situation)
09b16492
JH
582 s/TLS error on connection to \d{1,3}(.\d{1,3}){3} \[\d{1,3}(.\d{1,3}){3}\] \(gnutls_handshake\): A TLS packet with unexpected length was received./a TLS session is required for ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4], but an attempt to start TLS failed/g;
583 s/TLS error on connection from \[127.0.0.1\] \(recv\): A TLS packet with unexpected length was received./TLS error on connection from [127.0.0.1] (recv): The TLS connection was non-properly terminated./g;
75fe387d 584
348051ad 585 # signature algorithm names
2335af87 586 s/RSA-SHA1/RSA-SHA/;
348051ad 587
6bf5d8f2 588
eeeda78a 589 # ======== Caller's login, uid, gid, home, gecos ========
151b83f8
PH
590
591 s/\Q$parm_caller_home\E/CALLER_HOME/g; # NOTE: these must be done
592 s/\b\Q$parm_caller\E\b/CALLER/g; # in this order!
593 s/\b\Q$parm_caller_group\E\b/CALLER/g; # In case group name different
594
595 s/\beuid=$parm_caller_uid\b/euid=CALLER_UID/g;
596 s/\begid=$parm_caller_gid\b/egid=CALLER_GID/g;
597
598 s/\buid=$parm_caller_uid\b/uid=CALLER_UID/g;
599 s/\bgid=$parm_caller_gid\b/gid=CALLER_GID/g;
600
903546d8 601 s/\bname="?$parm_caller_gecos"?/name=CALLER_GECOS/g;
eeeda78a 602
151b83f8
PH
603 # When looking at spool files with -Mvh, we will find not only the caller
604 # login, but also the uid and gid. It seems that $) in some Perls gives all
605 # the auxiliary gids as well, so don't bother checking for that.
606
607 s/^CALLER $> \d+$/CALLER UID GID/;
608
609 # There is one case where the caller's login is forced to something else,
610 # in order to test the processing of logins that contain spaces. Weird what
611 # some people do, isn't it?
612
613 s/^spaced user $> \d+$/CALLER UID GID/;
614
615
616 # ======== Exim's login ========
ebeaf996
PH
617 # For messages received by the daemon, this is in the -H file, which some
618 # tests inspect. For bounce messages, this will appear on the U= lines in
619 # logs and also after Received: and in addresses. In one pipe test it appears
620 # after "Running as:". It also appears in addresses, and in the names of lock
151b83f8
PH
621 # files.
622
623 s/U=$parm_eximuser/U=EXIMUSER/;
624 s/user=$parm_eximuser/user=EXIMUSER/;
625 s/login=$parm_eximuser/login=EXIMUSER/;
626 s/Received: from $parm_eximuser /Received: from EXIMUSER /;
627 s/Running as: $parm_eximuser/Running as: EXIMUSER/;
628 s/\b$parm_eximuser@/EXIMUSER@/;
629 s/\b$parm_eximuser\.lock\./EXIMUSER.lock./;
630
631 s/\beuid=$parm_exim_uid\b/euid=EXIM_UID/g;
632 s/\begid=$parm_exim_gid\b/egid=EXIM_GID/g;
633
634 s/\buid=$parm_exim_uid\b/uid=EXIM_UID/g;
635 s/\bgid=$parm_exim_gid\b/gid=EXIM_GID/g;
636
ebeaf996
PH
637 s/^$parm_eximuser $parm_exim_uid $parm_exim_gid/EXIMUSER EXIM_UID EXIM_GID/;
638
151b83f8
PH
639
640 # ======== General uids, gids, and pids ========
641 # Note: this must come after munges for caller's and exim's uid/gid
642
a4dc33a8
PH
643 # These are for systems where long int is 64
644 s/\buid=4294967295/uid=-1/;
645 s/\beuid=4294967295/euid=-1/;
646 s/\bgid=4294967295/gid=-1/;
647 s/\begid=4294967295/egid=-1/;
648
151b83f8
PH
649 s/\bgid=\d+/gid=gggg/;
650 s/\begid=\d+/egid=gggg/;
651 s/\bpid=\d+/pid=pppp/;
652 s/\buid=\d+/uid=uuuu/;
653 s/\beuid=\d+/euid=uuuu/;
654 s/set_process_info:\s+\d+/set_process_info: pppp/;
655 s/queue run pid \d+/queue run pid ppppp/;
656 s/process \d+ running as transport filter/process pppp running as transport filter/;
657 s/process \d+ writing to transport filter/process pppp writing to transport filter/;
658 s/reading pipe for subprocess \d+/reading pipe for subprocess pppp/;
659 s/remote delivery process \d+ ended/remote delivery process pppp ended/;
660
661 # Pid in temp file in appendfile transport
662 s"test-mail/temp\.\d+\."test-mail/temp.pppp.";
663
f3f065bb
PH
664 # Optional pid in log lines
665 s/^(\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d)(\s[+-]\d\d\d\d|)(\s\[\d+\])/
666 "$1$2 [" . new_value($3, "%s", \$next_pid) . "]"/gxe;
667
151b83f8
PH
668 # Detect a daemon stderr line with a pid and save the pid for subsequent
669 # removal from following lines.
670 $spid = $1 if /^(\s*\d+) (?:listening|LOG: MAIN|(?:daemon_smtp_port|local_interfaces) overridden by)/;
671 s/^$spid //;
672
673 # Queue runner waiting messages
674 s/waiting for children of \d+/waiting for children of pppp/;
675 s/waiting for (\S+) \(\d+\)/waiting for $1 (pppp)/;
676
e498ab40
JH
677 # The spool header file name varies with PID
678 s%^(Writing spool header file: .*/hdr).[0-9]{1,5}%$1.pppp%;
679
151b83f8
PH
680 # ======== Port numbers ========
681 # Incoming port numbers may vary, but not in daemon startup line.
682
683 s/^Port: (\d+)/"Port: " . new_value($1, "%s", \$next_port)/e;
684 s/\(port=(\d+)/"(port=" . new_value($1, "%s", \$next_port)/e;
685
686 # This handles "connection from" and the like, when the port is given
4311097e
PH
687 if (!/listening for SMTP on/ && !/Connecting to/ && !/=>/ && !/->/
688 && !/\*>/ && !/Connection refused/)
151b83f8
PH
689 {
690 s/\[([a-z\d:]+|\d+(?:\.\d+){3})\]:(\d+)/"[".$1."]:".new_value($2,"%s",\$next_port)/ie;
691 }
692
693 # Port in host address in spool file output from -Mvh
694 s/^-host_address (.*)\.\d+/-host_address $1.9999/;
695
df613eb4
HSHR
696 if ($dynamic_socket and $dynamic_socket->opened and my $port = $dynamic_socket->sockport) {
697 s/^Connecting to 127\.0\.0\.1 port \K$port/<dynamic port>/;
698 }
699
151b83f8
PH
700
701 # ======== Local IP addresses ========
702 # The amount of space between "host" and the address in verification output
703 # depends on the length of the host name. We therefore reduce it to one space
704 # for all of them.
37acd760
JJ
705 # Also, the length of space at the end of the host line is dependent
706 # on the length of the longest line, so strip it also on otherwise
707 # un-rewritten lines like localhost
151b83f8
PH
708
709 s/^\s+host\s(\S+)\s+(\S+)/ host $1 $2/;
710 s/^\s+(host\s\S+\s\S+)\s+(port=.*)/ host $1 $2/;
711 s/^\s+(host\s\S+\s\S+)\s+(?=MX=)/ $1 /;
712 s/host\s\Q$parm_ipv4\E\s\[\Q$parm_ipv4\E\]/host ipv4.ipv4.ipv4.ipv4 [ipv4.ipv4.ipv4.ipv4]/;
713 s/host\s\Q$parm_ipv6\E\s\[\Q$parm_ipv6\E\]/host ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6 [ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6]/;
714 s/\b\Q$parm_ipv4\E\b/ip4.ip4.ip4.ip4/g;
48dc5470 715 s/(^|\W)\K\Q$parm_ipv6\E/ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6/g;
75758eeb 716 s/\b\Q$parm_ipv4r\E\b/ip4-reverse/g;
48dc5470 717 s/(^|\W)\K\Q$parm_ipv6r\E/ip6-reverse/g;
37acd760 718 s/^(\s+host\s\S+\s+\[\S+\]) +$/$1 /;
151b83f8
PH
719
720
721 # ======== Test network IP addresses ========
722 s/(\b|_)\Q$parm_ipv4_test_net\E(?=\.\d+\.\d+\.\d+\b|_|\.rbl|\.in-addr|\.test\.again\.dns)/$1V4NET/g;
723 s/\b\Q$parm_ipv6_test_net\E(?=:[\da-f]+:[\da-f]+:[\da-f]+)/V6NET/gi;
724
725
726 # ======== IP error numbers and messages ========
727 # These vary between operating systems
728 s/Can't assign requested address/Network Error/;
729 s/Cannot assign requested address/Network Error/;
730 s/Operation timed out/Connection timed out/;
731 s/Address family not supported by protocol family/Network Error/;
732 s/Network is unreachable/Network Error/;
733 s/Invalid argument/Network Error/;
734
735 s/\(\d+\): Network/(dd): Network/;
736 s/\(\d+\): Connection refused/(dd): Connection refused/;
737 s/\(\d+\): Connection timed out/(dd): Connection timed out/;
738 s/\d+ 65 Connection refused/dd 65 Connection refused/;
739 s/\d+ 321 Connection timed out/dd 321 Connection timed out/;
740
741
742 # ======== Other error numbers ========
743 s/errno=\d+/errno=dd/g;
744
f4bb1d53
HSHR
745 # ======== System Error Messages ======
746 # depending on the underlaying file system the error message seems to differ
747 s/(?: is not a regular file)|(?: has too many links \(\d+\))/ not a regular file or too many links/;
151b83f8
PH
748
749 # ======== Output from ls ========
750 # Different operating systems use different spacing on long output
c1e49b79
PP
751 #s/ +/ /g if /^[-rwd]{10} /;
752 # (Bug 1226) SUSv3 allows a trailing printable char for modified access method control.
753 # Handle only the Gnu and MacOS space, dot, plus and at-sign. A full [[:graph:]]
754 # unfortunately matches a non-ls linefull of dashes.
755 # Allow the case where we've already picked out the file protection bits.
6f99d4d9 756 if (s/^([-d](?:[-r][-w][-SsTtx]){3})[.+@]?( +|$)/$1$2/) {
8dfac759
PP
757 s/ +/ /g;
758 }
151b83f8
PH
759
760
761 # ======== Message sizes =========
762 # Message sizes vary, owing to different logins and host names that get
763 # automatically inserted. I can't think of any way of even approximately
764 # comparing these.
765
766 s/([\s,])S=\d+\b/$1S=sss/;
767 s/:S\d+\b/:Ssss/;
768 s/^(\s*\d+m\s+)\d+(\s+[a-z0-9-]{16} <)/$1sss$2/i if $is_stdout;
1f253d34 769 s/\sSIZE=\d+\b/ SIZE=ssss/;
151b83f8
PH
770 s/\ssize=\d+\b/ size=sss/ if $is_stderr;
771 s/old size = \d+\b/old size = sssss/;
772 s/message size = \d+\b/message size = sss/;
773 s/this message = \d+\b/this message = sss/;
774 s/Size of headers = \d+/Size of headers = sss/;
775 s/sum=(?!0)\d+/sum=dddd/;
3b5d5078
JH
776 s/(?<=sum=dddd )count=\d+\b/count=dd/;
777 s/(?<=sum=0 )count=\d+\b/count=dd/;
151b83f8
PH
778 s/,S is \d+\b/,S is ddddd/;
779 s/\+0100,\d+;/+0100,ddd;/;
780 s/\(\d+ bytes written\)/(ddd bytes written)/;
781 s/added '\d+ 1'/added 'ddd 1'/;
f3f065bb
PH
782 s/Received\s+\d+/Received nnn/;
783 s/Delivered\s+\d+/Delivered nnn/;
151b83f8
PH
784
785
a98e6aca
HSHR
786 # ======== Values in spool space failure message ========
787 s/space=\d+ inodes=[+-]?\d+/space=xxxxx inodes=xxxxx/;
788
789
151b83f8
PH
790 # ======== Filter sizes ========
791 # The sizes of filter files may vary because of the substitution of local
792 # filenames, logins, etc.
793
794 s/^\d+(?= bytes read from )/ssss/;
795
796
797 # ======== OpenSSL error messages ========
798 # Different releases of the OpenSSL libraries seem to give different error
799 # numbers, or handle specific bad conditions in different ways, leading to
800 # different wording in the error messages, so we cannot compare them.
801
c562fd30 802 s/(TLS error on connection (?:from .* )?\(SSL_\w+\): error:)(.*)/$1 <<detail omitted>>/;
5f921f97 803 next if /SSL verify error: depth=0 error=certificate not trusted/;
151b83f8 804
151b83f8
PH
805 # ======== Maildir things ========
806 # timestamp output in maildir processing
807 s/(timestamp=|\(timestamp_only\): )\d+/$1ddddddd/g;
808
809 # maildir delivery files appearing in log lines (in cases of error)
810 s/writing to(?: file)? tmp\/\d+\.[^.]+\.(\S+)/writing to tmp\/MAILDIR.$1/;
811
812 s/renamed tmp\/\d+\.[^.]+\.(\S+) as new\/\d+\.[^.]+\.(\S+)/renamed tmp\/MAILDIR.$1 as new\/MAILDIR.$1/;
813
814 # Maildir file names in general
815 s/\b\d+\.H\d+P\d+\b/dddddddddd.HddddddPddddd/;
816
817 # Maildirsize data
01c490df 818 while (/^\d+S,\d+C\s*$/)
151b83f8 819 {
21c28500 820 print MUNGED;
151b83f8
PH
821 while (<IN>)
822 {
823 last if !/^\d+ \d+\s*$/;
824 print MUNGED "ddd d\n";
825 }
826 last if !defined $_;
827 }
01c490df 828 last if !defined $_;
151b83f8
PH
829
830
831 # ======== Output from the "fd" program about open descriptors ========
832 # The statuses seem to be different on different operating systems, but
833 # at least we'll still be checking the number of open fd's.
834
835 s/max fd = \d+/max fd = dddd/;
836 s/status=0 RDONLY/STATUS/g;
837 s/status=1 WRONLY/STATUS/g;
838 s/status=2 RDWR/STATUS/g;
839
840
841 # ======== Contents of spool files ========
842 # A couple of tests dump the contents of the -H file. The length fields
843 # will be wrong because of different user names, etc.
844 s/^\d\d\d(?=[PFS*])/ddd/;
845
846
1bad4ba4
JH
847 # ========= Exim lookups ==================
848 # Lookups have a char which depends on the number of lookup types compiled in,
849 # in stderr output. Replace with a "0". Recognising this while avoiding
850 # other output is fragile; perhaps the debug output should be revised instead.
851 s%(?<!sqlite)(?<!lsearch\*@)(?<!lsearch\*)(?<!lsearch)[0-?]TESTSUITE/aux-fixed/%0TESTSUITE/aux-fixed/%g;
44e6236d 852
151b83f8 853 # ==========================================================
bfd86064 854 # MIME boundaries in RFC3461 DSN messages
05faa88b 855 s/\d{8,10}-eximdsn-\d+/NNNNNNNNNN-eximdsn-MMMMMMMMMM/;
bfd86064
JH
856
857 # ==========================================================
151b83f8
PH
858 # Some munging is specific to the specific file types
859
860 # ======== stdout ========
861
862 if ($is_stdout)
863 {
f3d7df6c
PH
864 # Skip translate_ip_address and use_classresources in -bP output because
865 # they aren't always there.
151b83f8
PH
866
867 next if /translate_ip_address =/;
f3d7df6c 868 next if /use_classresources/;
151b83f8
PH
869
870 # In certain filter tests, remove initial filter lines because they just
871 # clog up by repetition.
872
873 if ($rmfiltertest)
874 {
875 next if /^(Sender\staken\sfrom|
876 Return-path\scopied\sfrom|
877 Sender\s+=|
878 Recipient\s+=)/x;
879 if (/^Testing \S+ filter/)
880 {
881 $_ = <IN>; # remove blank line
882 next;
883 }
884 }
903546d8
JH
885
886 # openssl version variances
887 next if /^SSL info: unknown state/;
888 next if /^SSL info: SSLv2\/v3 write client hello A/;
d7e464f4 889 next if /^SSL info: SSLv3 read server key exchange A/;
fc96d1e8
JH
890 next if /SSL verify error: depth=0 error=certificate not trusted/;
891 s/SSL3_READ_BYTES/ssl3_read_bytes/;
fc4fcc34
JH
892
893 # gnutls version variances
894 next if /^Error in the pull function./;
151b83f8
PH
895 }
896
897 # ======== stderr ========
898
899 elsif ($is_stderr)
900 {
901 # The very first line of debugging output will vary
902
903 s/^Exim version .*/Exim version x.yz ..../;
904
905 # Debugging lines for Exim terminations
906
907 s/(?<=^>>>>>>>>>>>>>>>> Exim pid=)\d+(?= terminating)/pppp/;
908
909 # IP address lookups use gethostbyname() when IPv6 is not supported,
910 # and gethostbyname2() or getipnodebyname() when it is.
911
4af1b6ca 912 s/\b(gethostbyname2?|\bgetipnodebyname)(\(af=inet\))?/get[host|ipnode]byname[2]/;
151b83f8 913
f2dd649a
NM
914 # drop gnutls version strings
915 next if /GnuTLS compile-time version: \d+[\.\d]+$/;
916 next if /GnuTLS runtime version: \d+[\.\d]+$/;
917
64fa3c1f
JJ
918 # drop openssl version strings
919 next if /OpenSSL compile-time version: OpenSSL \d+[\.\da-z]+/;
920 next if /OpenSSL runtime version: OpenSSL \d+[\.\da-z]+/;
921
8f1cff48
PP
922 # drop lookups
923 next if /^Lookups \(built-in\):/;
a769a501
PP
924 next if /^Loading lookup modules from/;
925 next if /^Loaded \d+ lookup modules/;
8f1cff48
PP
926 next if /^Total \d+ lookups/;
927
bdf15279
PP
928 # drop compiler information
929 next if /^Compiler:/;
930
8f1cff48
PP
931 # and the ugly bit
932 # different libraries will have different numbers (possibly 0) of follow-up
933 # lines, indenting with more data
934 if (/^Library version:/) {
935 while (1) {
936 $_ = <IN>;
937 next if /^\s/;
938 goto RESET_AFTER_EXTRA_LINE_READ;
939 }
940 }
941
942 # drop other build-time controls emitted for debugging
943 next if /^WHITELIST_D_MACROS:/;
944 next if /^TRUSTED_CONFIG_LIST:/;
945
946 # As of Exim 4.74, we log when a setgid fails; because we invoke Exim
947 # with -be, privileges will have been dropped, so this will always
948 # be the case
42ec9880 949 next if /^changing group to \d+ failed: (Operation not permitted|Not owner)/;
8f1cff48 950
9d26b8c0
PP
951 # We might not keep this check; rather than change all the tests, just
952 # ignore it as long as it succeeds; then we only need to change the
953 # TLS tests where tls_require_ciphers has been set.
954 if (m{^changed uid/gid: calling tls_validate_require_cipher}) {
955 my $discard = <IN>;
956 next;
957 }
958 next if /^tls_validate_require_cipher child \d+ ended: status=0x0/;
959
8f1cff48 960 # We invoke Exim with -D, so we hit this new messag as of Exim 4.73:
43236f35 961 next if /^macros_trusted overridden to true by whitelisting/;
8f1cff48 962
151b83f8
PH
963 # We have to omit the localhost ::1 address so that all is well in
964 # the IPv4-only case.
965
966 print MUNGED "MUNGED: ::1 will be omitted in what follows\n"
967 if (/looked up these IP addresses/);
968 next if /name=localhost address=::1/;
969
f2dd649a
NM
970 # drop pdkim debugging header
971 next if /^PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<+$/;
972
151b83f8
PH
973 # Various other IPv6 lines must be omitted too
974
975 next if /using host_fake_gethostbyname for \S+ \(IPv6\)/;
976 next if /get\[host\|ipnode\]byname\[2\]\(af=inet6\)/;
977 next if /DNS lookup of \S+ \(AAAA\) using fakens/;
978 next if / in dns_ipv4_lookup?/;
979
980 if (/DNS lookup of \S+ \(AAAA\) gave NO_DATA/)
981 {
982 $_= <IN>; # Gets "returning DNS_NODATA"
983 next;
984 }
985
986 # Skip tls_advertise_hosts and hosts_require_tls checks when the options
987 # are unset, because tls ain't always there.
988
989 next if /in\s(?:tls_advertise_hosts\?|hosts_require_tls\?)
23f3dc67 990 \sno\s\((option\sunset|end\sof\slist)\)/x;
151b83f8
PH
991
992 # Skip auxiliary group lists because they will vary.
993
994 next if /auxiliary group list:/;
995
996 # Skip "extracted from gecos field" because the gecos field varies
997
998 next if /extracted from gecos field/;
999
1000 # Skip "waiting for data on socket" and "read response data: size=" lines
1001 # because some systems pack more stuff into packets than others.
1002
1003 next if /waiting for data on socket/;
1004 next if /read response data: size=/;
1005
1006 # If Exim is compiled with readline support but it can't find the library
1007 # to load, there will be an extra debug line. Omit it.
1008
1009 next if /failed to load readline:/;
1010
1011 # Some DBM libraries seem to make DBM files on opening with O_RDWR without
1012 # O_CREAT; other's don't. In the latter case there is some debugging output
1013 # which is not present in the former. Skip the relevant lines (there are
1014 # two of them).
1015
1016 if (/TESTSUITE\/spool\/db\/\S+ appears not to exist: trying to create/)
1017 {
1018 $_ = <IN>;
1019 next;
1020 }
1021
1022 # Some tests turn on +expand debugging to check on expansions.
1023 # Unfortunately, the Received: expansion varies, depending on whether TLS
1024 # is compiled or not. So we must remove the relevant debugging if it is.
1025
1026 if (/^condition: def:tls_cipher/)
1027 {
1028 while (<IN>) { last if /^condition: def:sender_address/; }
1029 }
1030 elsif (/^expanding: Received: /)
1031 {
1032 while (<IN>) { last if !/^\s/; }
1033 }
1034
a2550b67
JH
1035 # remote port numbers vary
1036 s/(Connection request from 127.0.0.1 port) \d{1,5}/$1 sssss/;
1037
1038 # Skip hosts_require_dane checks when the options
1039 # are unset, because dane ain't always there.
1040
1041 next if /in\shosts_require_dane\?\sno\s\(option\sunset\)/x;
1042
1043 # SUPPORT_PROXY
1044 next if /host in hosts_proxy\?/;
1045
1046 # Experimental_International
1047 next if / in smtputf8_advertise_hosts\? no \(option unset\)/;
1048
1049 # Environment cleaning
1050 next if /\w+ in keep_environment\? (yes|no)/;
1051
76003495
JH
1052 # Sizes vary with test hostname
1053 s/^cmd buf flush \d+ bytes$/cmd buf flush ddd bytes/;
1054
ddf1b11a 1055 # Spool filesystem free space changes on different systems.
ad424056 1056 s/^((?:spool|log) directory space =) -?\d+K (inodes =)\s*-?\d+/$1 nnnnnK $2 nnnnn/;
ddf1b11a 1057
7373d852 1058 # Non-TLS builds have different expansions for received_header_text
340f3113 1059 if (s/(with \$received_protocol)\}\} \$\{if def:tls_cipher \{\(\$tls_cipher\)\n$/$1/)
7373d852
JH
1060 {
1061 $_ .= <IN>;
340f3113 1062 s/\s+\}\}(?=\(Exim )/\}\} /;
7373d852 1063 }
340f3113
JH
1064 if (/^ condition: def:tls_cipher$/)
1065 {
1066 <IN>; <IN>; <IN>; <IN>; <IN>; <IN>;
1067 <IN>; <IN>; <IN>; <IN>; <IN>; next;
1068 }
1069
1070 # Not all platforms build with DKIM enabled
1071 next if /^PDKIM >> Body data for hash, canonicalized/;
7373d852 1072
ef817659 1073 # Not all platforms support TCP Fast Open, and the compile omits the check
cb340d8d 1074 if (s/\S+ in hosts_try_fastopen\? no \(option unset\)\n$//)
ef817659 1075 {
7373d852
JH
1076 $_ .= <IN>;
1077 s/ \.\.\. >>> / ... /;
ef817659
JH
1078 }
1079
8170f6f7 1080 next if /^(ppppp )?setsockopt FASTOPEN: Protocol not available$/;
7373d852 1081
151b83f8
PH
1082 # When Exim is checking the size of directories for maildir, it uses
1083 # the check_dir_size() function to scan directories. Of course, the order
1084 # of the files that are obtained using readdir() varies from system to
1085 # system. We therefore buffer up debugging lines from check_dir_size()
1086 # and sort them before outputting them.
1087
1088 if (/^check_dir_size:/ || /^skipping TESTSUITE\/test-mail\//)
1089 {
1090 push @saved, $_;
1091 }
1092 else
1093 {
1094 if (@saved > 0)
1095 {
1096 print MUNGED "MUNGED: the check_dir_size lines have been sorted " .
1097 "to ensure consistency\n";
1098 @saved = sort(@saved);
1099 print MUNGED @saved;
1100 @saved = ();
1101 }
1102
1103 # Skip some lines that Exim puts out at the start of debugging output
1104 # because they will be different in different binaries.
1105
1106 print MUNGED
1107 unless (/^Berkeley DB: / ||
1108 /^Probably (?:Berkeley DB|ndbm|GDBM)/ ||
1109 /^Authenticators:/ ||
1110 /^Lookups:/ ||
1111 /^Support for:/ ||
1112 /^Routers:/ ||
1113 /^Transports:/ ||
1114 /^log selectors =/ ||
1115 /^cwd=/ ||
21c28500 1116 /^Fixed never_users:/ ||
c9fb6994 1117 /^Configure owner:/ ||
21c28500 1118 /^Size of off_t:/
151b83f8 1119 );
9d4319df
JH
1120
1121
151b83f8
PH
1122 }
1123
1124 next;
1125 }
1126
42ec9880
JH
1127 # ======== log ========
1128
1129 elsif ($is_log)
1130 {
1131 # Berkeley DB version differences
1132 next if / Berkeley DB error: /;
1133 }
1134
151b83f8
PH
1135 # ======== All files other than stderr ========
1136
1137 print MUNGED;
1138 }
1139
1140close(IN);
1141return $yield;
1142}
1143
1144
1145
1146
1147##################################################
1148# Subroutine to interact with caller #
1149##################################################
1150
1151# Arguments: [0] the prompt string
1152# [1] if there is a U in the prompt and $force_update is true
c1c469db 1153# [2] if there is a C in the prompt and $force_continue is true
2f8e6f30 1154# Returns: returns the answer
151b83f8
PH
1155
1156sub interact{
1157print $_[0];
1158if ($_[1]) { $_ = "u"; print "... update forced\n"; }
c1c469db 1159 elsif ($_[2]) { $_ = "c"; print "... continue forced\n"; }
151b83f8
PH
1160 else { $_ = <T>; }
1161}
1162
1163
1164
c1c469db
TL
1165##################################################
1166# Subroutine to log in force_continue mode #
1167##################################################
1168
1169# In force_continue mode, we just want a terse output to a statically
1170# named logfile. If multiple files in same batch (stdout, stderr, etc)
1171# all have mismatches, it will log multiple times.
1172#
1173# Arguments: [0] the logfile to append to
1174# [1] the testno that failed
1175# Returns: nothing
1176
1177
1178
1179sub log_failure {
1180 my $logfile = shift();
1181 my $testno = shift();
1182 my $detail = shift() || '';
1183 if ( open(my $fh, ">>", $logfile) ) {
1184 print $fh "Test $testno $detail failed\n";
1185 close $fh;
1186 }
1187}
1188
1189
151b83f8
PH
1190
1191##################################################
1192# Subroutine to compare one output file #
1193##################################################
1194
1195# When an Exim server is part of the test, its output is in separate files from
1196# an Exim client. The server data is concatenated with the client data as part
1197# of the munging operation.
1198#
1199# Arguments: [0] the name of the main raw output file
1200# [1] the name of the server raw output file or undef
1201# [2] where to put the munged copy
1202# [3] the name of the saved file
1203# [4] TRUE if this is a log file whose deliveries must be sorted
c9a55f6a 1204# [5] optionally, a custom munge command
151b83f8
PH
1205#
1206# Returns: 0 comparison succeeded or differences to be ignored
cc442294 1207# 1 comparison failed; files may have been updated (=> re-compare)
151b83f8
PH
1208#
1209# Does not return if the user replies "Q" to a prompt.
1210
1211sub check_file{
c9a55f6a 1212my($rf,$rsf,$mf,$sf,$sortfile,$extra) = @_;
151b83f8
PH
1213
1214# If there is no saved file, the raw files must either not exist, or be
1215# empty. The test ! -s is TRUE if the file does not exist or is empty.
1216
28e8a0f7
HSHR
1217# we check if there is a flavour specific file, but we remember
1218# the original file name as "generic"
1219$sf_generic = $sf;
1220$sf_flavour = "$sf_generic.$flavour";
1221$sf_current = -e $sf_flavour ? $sf_flavour : $sf_generic;
1222
1223if (! -e $sf_current)
151b83f8 1224 {
148e1ac6 1225 return 0 if (! -s $rf && (! defined $rsf || ! -s $rsf));
151b83f8
PH
1226
1227 print "\n";
1228 print "** $rf is not empty\n" if (-s $rf);
1229 print "** $rsf is not empty\n" if (defined $rsf && -s $rsf);
1230
1231 for (;;)
1232 {
1233 print "Continue, Show, or Quit? [Q] ";
efede112 1234 $_ = $force_continue ? "c" : <T>;
151b83f8 1235 tests_exit(1) if /^q?$/i;
c1c469db 1236 log_failure($log_failed_filename, $testno, $rf) if (/^c$/i && $force_continue);
151b83f8
PH
1237 return 0 if /^c$/i;
1238 last if (/^s$/);
1239 }
1240
1241 foreach $f ($rf, $rsf)
1242 {
1243 if (defined $f && -s $f)
1244 {
1245 print "\n";
1246 print "------------ $f -----------\n"
1247 if (defined $rf && -s $rf && defined $rsf && -s $rsf);
bc64a74d 1248 system("$more '$f'");
151b83f8
PH
1249 }
1250 }
1251
1252 print "\n";
1253 for (;;)
1254 {
c1c469db 1255 interact("Continue, Update & retry, Quit? [Q] ", $force_update, $force_continue);
151b83f8 1256 tests_exit(1) if /^q?$/i;
c1c469db 1257 log_failure($log_failed_filename, $testno, $rsf) if (/^c$/i && $force_continue);
151b83f8
PH
1258 return 0 if /^c$/i;
1259 last if (/^u$/i);
1260 }
1261 }
1262
2f8e6f30
HSHR
1263#### $_
1264
151b83f8
PH
1265# Control reaches here if either (a) there is a saved file ($sf), or (b) there
1266# was a request to create a saved file. First, create the munged file from any
1267# data that does exist.
1268
1269open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
c9a55f6a 1270my($truncated) = munge($rf, $extra) if -e $rf;
151b83f8
PH
1271if (defined $rsf && -e $rsf)
1272 {
1273 print MUNGED "\n******** SERVER ********\n";
c9a55f6a 1274 $truncated |= munge($rsf, $extra);
151b83f8
PH
1275 }
1276close(MUNGED);
1277
1278# If a saved file exists, do the comparison. There are two awkward cases:
1279#
1280# If "*** truncated ***" was found in the new file, it means that a log line
1281# was overlong, and truncated. The problem is that it may be truncated at
1282# different points on different systems, because of different user name
1283# lengths. We reload the file and the saved file, and remove lines from the new
1284# file that precede "*** truncated ***" until we reach one that matches the
1285# line that precedes it in the saved file.
1286#
1287# If $sortfile is set, we are dealing with a mainlog file where the deliveries
1288# for an individual message might vary in their order from system to system, as
1289# a result of parallel deliveries. We load the munged file and sort sequences
1290# of delivery lines.
1291
28e8a0f7 1292if (-e $sf_current)
151b83f8
PH
1293 {
1294 # Deal with truncated text items
1295
1296 if ($truncated)
1297 {
1298 my(@munged, @saved, $i, $j, $k);
1299
1300 open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
1301 @munged = <MUNGED>;
1302 close(MUNGED);
28e8a0f7 1303 open(SAVED, $sf_current) || tests_exit(-1, "Failed to open $sf_current: $!");
151b83f8
PH
1304 @saved = <SAVED>;
1305 close(SAVED);
1306
1307 $j = 0;
1308 for ($i = 0; $i < @munged; $i++)
1309 {
1310 if ($munged[$i] =~ /\*\*\* truncated \*\*\*/)
1311 {
1312 for (; $j < @saved; $j++)
1313 { last if $saved[$j] =~ /\*\*\* truncated \*\*\*/; }
1314 last if $j >= @saved; # not found in saved
1315
1316 for ($k = $i - 1; $k >= 0; $k--)
1317 { last if $munged[$k] eq $saved[$j - 1]; }
1318
1319 last if $k <= 0; # failed to find previous match
1320 splice @munged, $k + 1, $i - $k - 1;
1321 $i = $k + 1;
1322 }
1323 }
1324
1325 open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
1326 for ($i = 0; $i < @munged; $i++)
1327 { print MUNGED $munged[$i]; }
1328 close(MUNGED);
1329 }
1330
1331 # Deal with log sorting
1332
1333 if ($sortfile)
1334 {
1335 my(@munged, $i, $j);
1336
1337 open(MUNGED, "$mf") || tests_exit(-1, "Failed to open $mf: $!");
1338 @munged = <MUNGED>;
1339 close(MUNGED);
1340
1341 for ($i = 0; $i < @munged; $i++)
1342 {
1343 if ($munged[$i] =~ /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/)
1344 {
1345 for ($j = $i + 1; $j < @munged; $j++)
1346 {
1347 last if $munged[$j] !~
1348 /^[-\d]{10}\s[:\d]{8}\s[-A-Za-z\d]{16}\s[-=*]>/;
1349 }
1350 @temp = splice(@munged, $i, $j - $i);
1351 @temp = sort(@temp);
1352 splice(@munged, $i, 0, @temp);
1353 }
1354 }
1355
1356 open(MUNGED, ">$mf") || tests_exit(-1, "Failed to open $mf: $!");
1357 print MUNGED "**NOTE: The delivery lines in this file have been sorted.\n";
1358 for ($i = 0; $i < @munged; $i++)
1359 { print MUNGED $munged[$i]; }
1360 close(MUNGED);
1361 }
1362
1363 # Do the comparison
1364
28e8a0f7 1365 return 0 if (system("$cf '$mf' '$sf_current' >test-cf") == 0);
151b83f8
PH
1366
1367 # Handle comparison failure
1368
28e8a0f7 1369 print "** Comparison of $mf with $sf_current failed";
151b83f8
PH
1370 system("$more test-cf");
1371
1372 print "\n";
1373 for (;;)
1374 {
28e8a0f7
HSHR
1375 interact("Continue, Retry, Update current"
1376 . ($sf_current ne $sf_flavour ? "/Save for flavour '$flavour'" : "")
1377 . " & retry, Quit? [Q] ", $force_update, $force_continue);
151b83f8 1378 tests_exit(1) if /^q?$/i;
28e8a0f7 1379 log_failure($log_failed_filename, $testno, $sf_current) if (/^c$/i && $force_continue);
151b83f8 1380 return 0 if /^c$/i;
cc442294 1381 return 1 if /^r$/i;
28e8a0f7 1382 last if (/^[us]$/i);
151b83f8
PH
1383 }
1384 }
1385
1386# Update or delete the saved file, and give the appropriate return code.
1387
1388if (-s $mf)
28e8a0f7
HSHR
1389 {
1390 my $sf = /^u/i ? $sf_current : $sf_flavour;
1391 tests_exit(-1, "Failed to cp $mf $sf") if system("cp '$mf' '$sf'") != 0;
1392 }
151b83f8 1393else
28e8a0f7
HSHR
1394 {
1395 # if we deal with a flavour file, we can't delete it, because next time the generic
1396 # file would be used again
1397 if ($sf_current eq $sf_flavour) {
1398 open(FOO, ">$sf_current");
1399 close(FOO);
1400 }
1401 else {
1402 tests_exit(-1, "Failed to unlink $sf_current") if !unlink($sf_current);
1403 }
1404 }
151b83f8
PH
1405
1406return 1;
1407}
1408
1409
1410
1411##################################################
c9a55f6a
JH
1412# Custom munges
1413# keyed by name of munge; value is a ref to a hash
1414# which is keyed by file, value a string to look for.
1415# Usable files are:
1416# paniclog, rejectlog, mainlog, stdout, stderr, msglog, mail
1417# Search strings starting with 's' do substitutions;
1418# with '/' do line-skips.
74377a62 1419# Triggered by a scriptfile line "munge <name>"
c9a55f6a
JH
1420##################################################
1421$munges =
1422 { 'dnssec' =>
cf407cb6 1423 { 'stderr' => '/^Reverse DNS security status: unverified\n/' },
c9a55f6a
JH
1424
1425 'gnutls_unexpected' =>
cf407cb6 1426 { 'mainlog' => '/\(recv\): A TLS packet with unexpected length was received./' },
c9a55f6a
JH
1427
1428 'gnutls_handshake' =>
cf407cb6 1429 { 'mainlog' => 's/\(gnutls_handshake\): Error in the push function/\(gnutls_handshake\): A TLS packet with unexpected length was received/' },
c9a55f6a 1430
74377a62 1431 'optional_events' =>
cf407cb6 1432 { 'stdout' => '/event_action =/' },
74377a62
JH
1433
1434 'optional_ocsp' =>
cf407cb6
JH
1435 { 'stderr' => '/127.0.0.1 in hosts_requ(ire|est)_ocsp/' },
1436
79547a5a
JH
1437 'optional_cert_hostnames' =>
1438 { 'stderr' => '/in tls_verify_cert_hostnames\? no/' },
1439
ac9a0d91
JH
1440 'loopback' =>
1441 { 'stdout' => 's/[[](127\.0\.0\.1|::1)]/[IP_LOOPBACK_ADDR]/' },
1442
35deab6a
JH
1443 'scanfile_size' =>
1444 { 'stdout' => 's/(Content-length:) \d\d\d/$1 ddd/' },
1445
846430d9
JH
1446 'delay_1500' =>
1447 { 'stderr' => 's/(1[5-9]|23\d)\d\d msec/ssss msec/' },
1448
b3ef41c9
JH
1449 'tls_anycipher' =>
1450 { 'mainlog' => 's/ X=TLS\S+ / X=TLS_proto_and_cipher /' },
1451
ae9d18bc 1452 'debug_pid' =>
b1cf8494 1453 { 'stderr' => 's/(^\s{0,4}|(?<=Process )|(?<=child ))\d{1,5}/ppppp/g' },
ae9d18bc 1454
d658adda
JH
1455 'optional_dsn_info' =>
1456 { 'mail' => '/^(X-(Remote-MTA-(smtp-greeting|helo-response)|Exim-Diagnostic|(body|message)-linecount):|Remote-MTA: X-ip;)/'
6636495c
JH
1457 },
1458
06685b44 1459 'optional_config' =>
4dce3152
JH
1460 { 'stdout' => '/^(
1461 dkim_(canon|domain|private_key|selector|sign_headers|strict)
1462 |gnutls_require_(kx|mac|protocols)
1463 |hosts_(requ(est|ire)|try)_(dane|ocsp)
1464 |hosts_(avoid|nopass|require|verify_avoid)_tls
06685b44 1465 |socks_proxy
4dce3152
JH
1466 |tls_[^ ]*
1467 )($|[ ]=)/x' },
79c904e1 1468
6636495c
JH
1469 'sys_bindir' =>
1470 { 'mainlog' => 's%/(usr/)?bin/%SYSBINDIR/%' },
d658adda 1471
a0418528
JH
1472 'sync_check_data' =>
1473 { 'mainlog' => 's/^(.* SMTP protocol synchronization error .* next input=.{8}).*$/$1<suppressed>/',
1474 'rejectlog' => 's/^(.* SMTP protocol synchronization error .* next input=.{8}).*$/$1<suppressed>/'},
1475
b0d68adc 1476 'debuglog_stdout' =>
ba59b14d 1477 { 'stdout' => 's/^\d\d:\d\d:\d\d\s+\d+ //;
b0d68adc
JH
1478 s/Process \d+ is ready for new message/Process pppp is ready for new message/'
1479 },
74ba91b1
JH
1480
1481 'timeout_errno' => # actual errno differs Solaris vs. Linux
1482 { 'mainlog' => 's/(host deferral .* errno) <\d+> /$1 <EEE> /' },
c9a55f6a
JH
1483 };
1484
1485
1486##################################################
151b83f8
PH
1487# Subroutine to check the output of a test #
1488##################################################
1489
1490# This function is called when the series of subtests is complete. It makes
c9a55f6a 1491# use of check_file(), whose arguments are:
151b83f8
PH
1492#
1493# [0] the name of the main raw output file
1494# [1] the name of the server raw output file or undef
1495# [2] where to put the munged copy
1496# [3] the name of the saved file
1497# [4] TRUE if this is a log file whose deliveries must be sorted
c9a55f6a 1498# [5] an optional custom munge command
151b83f8 1499#
ac9a0d91 1500# Arguments: Optionally, name of a single custom munge to run.
151b83f8 1501# Returns: 0 if the output compared equal
cc442294 1502# 1 if re-run needed (files may have been updated)
151b83f8
PH
1503
1504sub check_output{
c9a55f6a 1505my($mungename) = $_[0];
151b83f8 1506my($yield) = 0;
c9a55f6a 1507my($munge) = $munges->{$mungename} if defined $mungename;
151b83f8
PH
1508
1509$yield = 1 if check_file("spool/log/paniclog",
1510 "spool/log/serverpaniclog",
1511 "test-paniclog-munged",
c9a55f6a
JH
1512 "paniclog/$testno", 0,
1513 $munge->{'paniclog'});
151b83f8
PH
1514
1515$yield = 1 if check_file("spool/log/rejectlog",
1516 "spool/log/serverrejectlog",
1517 "test-rejectlog-munged",
c9a55f6a
JH
1518 "rejectlog/$testno", 0,
1519 $munge->{'rejectlog'});
151b83f8
PH
1520
1521$yield = 1 if check_file("spool/log/mainlog",
1522 "spool/log/servermainlog",
1523 "test-mainlog-munged",
c9a55f6a
JH
1524 "log/$testno", $sortlog,
1525 $munge->{'mainlog'});
151b83f8
PH
1526
1527if (!$stdout_skip)
1528 {
1529 $yield = 1 if check_file("test-stdout",
1530 "test-stdout-server",
1531 "test-stdout-munged",
c9a55f6a
JH
1532 "stdout/$testno", 0,
1533 $munge->{'stdout'});
151b83f8
PH
1534 }
1535
1536if (!$stderr_skip)
1537 {
1538 $yield = 1 if check_file("test-stderr",
1539 "test-stderr-server",
1540 "test-stderr-munged",
c9a55f6a
JH
1541 "stderr/$testno", 0,
1542 $munge->{'stderr'});
151b83f8
PH
1543 }
1544
1545# Compare any delivered messages, unless this test is skipped.
1546
1547if (! $message_skip)
1548 {
1549 my($msgno) = 0;
1550
1551 # Get a list of expected mailbox files for this script. We don't bother with
1552 # directories, just the files within them.
1553
1554 foreach $oldmail (@oldmails)
1555 {
1556 next unless $oldmail =~ /^mail\/$testno\./;
1557 print ">> EXPECT $oldmail\n" if $debug;
1558 $expected_mails{$oldmail} = 1;
1559 }
1560
1561 # If there are any files in test-mail, compare them. Note that "." and
1562 # ".." are automatically omitted by list_files_below().
1563
1564 @mails = list_files_below("test-mail");
1565
1566 foreach $mail (@mails)
1567 {
1568 next if $mail eq "test-mail/oncelog";
1569
1570 $saved_mail = substr($mail, 10); # Remove "test-mail/"
1571 $saved_mail =~ s/^$parm_caller(\/|$)/CALLER/; # Convert caller name
1572
1573 if ($saved_mail =~ /(\d+\.[^.]+\.)/)
1574 {
1575 $msgno++;
1576 $saved_mail =~ s/(\d+\.[^.]+\.)/$msgno./gx;
1577 }
1578
1579 print ">> COMPARE $mail mail/$testno.$saved_mail\n" if $debug;
1580 $yield = 1 if check_file($mail, undef, "test-mail-munged",
c9a55f6a
JH
1581 "mail/$testno.$saved_mail", 0,
1582 $munge->{'mail'});
151b83f8
PH
1583 delete $expected_mails{"mail/$testno.$saved_mail"};
1584 }
1585
1586 # Complain if not all expected mails have been found
1587
1588 if (scalar(keys %expected_mails) != 0)
1589 {
1590 foreach $key (keys %expected_mails)
1591 { print "** no test file found for $key\n"; }
1592
1593 for (;;)
1594 {
c1c469db 1595 interact("Continue, Update & retry, or Quit? [Q] ", $force_update, $force_continue);
151b83f8 1596 tests_exit(1) if /^q?$/i;
c1c469db 1597 log_failure($log_failed_filename, $testno, "missing email") if (/^c$/i && $force_continue);
151b83f8
PH
1598 last if /^c$/i;
1599
1600 # For update, we not only have to unlink the file, but we must also
1601 # remove it from the @oldmails vector, as otherwise it will still be
1602 # checked for when we re-run the test.
1603
1604 if (/^u$/i)
1605 {
1606 foreach $key (keys %expected_mails)
1607 {
1608 my($i);
1609 tests_exit(-1, "Failed to unlink $key") if !unlink("$key");
1610 for ($i = 0; $i < @oldmails; $i++)
1611 {
1612 if ($oldmails[$i] eq $key)
1613 {
1614 splice @oldmails, $i, 1;
1615 last;
1616 }
1617 }
1618 }
1619 last;
1620 }
1621 }
1622 }
1623 }
1624
1625# Compare any remaining message logs, unless this test is skipped.
1626
1627if (! $msglog_skip)
1628 {
1629 # Get a list of expected msglog files for this test
1630
1631 foreach $oldmsglog (@oldmsglogs)
1632 {
1633 next unless $oldmsglog =~ /^$testno\./;
1634 $expected_msglogs{$oldmsglog} = 1;
1635 }
1636
1637 # If there are any files in spool/msglog, compare them. However, we have
1638 # to munge the file names because they are message ids, which are
1639 # time dependent.
1640
1641 if (opendir(DIR, "spool/msglog"))
1642 {
1643 @msglogs = sort readdir(DIR);
1644 closedir(DIR);
1645
1646 foreach $msglog (@msglogs)
1647 {
1648 next if ($msglog eq "." || $msglog eq ".." || $msglog eq "CVS");
1649 ($munged_msglog = $msglog) =~
1650 s/((?:[^\W_]{6}-){2}[^\W_]{2})
1651 /new_value($1, "10Hm%s-0005vi-00", \$next_msgid)/egx;
1652 $yield = 1 if check_file("spool/msglog/$msglog", undef,
c9a55f6a
JH
1653 "test-msglog-munged", "msglog/$testno.$munged_msglog", 0,
1654 $munge->{'msglog'});
151b83f8
PH
1655 delete $expected_msglogs{"$testno.$munged_msglog"};
1656 }
1657 }
1658
1659 # Complain if not all expected msglogs have been found
1660
1661 if (scalar(keys %expected_msglogs) != 0)
1662 {
1663 foreach $key (keys %expected_msglogs)
1664 {
1665 print "** no test msglog found for msglog/$key\n";
1666 ($msgid) = $key =~ /^\d+\.(.*)$/;
1667 foreach $cachekey (keys %cache)
1668 {
1669 if ($cache{$cachekey} eq $msgid)
1670 {
1671 print "** original msgid $cachekey\n";
1672 last;
1673 }
1674 }
1675 }
1676
1677 for (;;)
1678 {
c1c469db 1679 interact("Continue, Update, or Quit? [Q] ", $force_update, $force_continue);
151b83f8 1680 tests_exit(1) if /^q?$/i;
c1c469db 1681 log_failure($log_failed_filename, $testno, "missing msglog") if (/^c$/i && $force_continue);
151b83f8
PH
1682 last if /^c$/i;
1683 if (/^u$/i)
1684 {
1685 foreach $key (keys %expected_msglogs)
1686 {
1687 tests_exit(-1, "Failed to unlink msglog/$key")
1688 if !unlink("msglog/$key");
1689 }
1690 last;
1691 }
1692 }
1693 }
1694 }
1695
1696return $yield;
1697}
1698
1699
1700
1701##################################################
1702# Subroutine to run one "system" command #
1703##################################################
1704
1705# We put this in a subroutine so that the command can be reflected when
1706# debugging.
1707#
1708# Argument: the command to be run
1709# Returns: nothing
1710
1711sub run_system {
1712my($cmd) = $_[0];
1713if ($debug)
1714 {
1715 my($prcmd) = $cmd;
1716 $prcmd =~ s/; /;\n>> /;
1717 print ">> $prcmd\n";
1718 }
1719system("$cmd");
1720}
1721
1722
1723
1724##################################################
1725# Subroutine to run one script command #
1726##################################################
1727
1728# The <SCRIPT> file is open for us to read an optional return code line,
1729# followed by the command line and any following data lines for stdin. The
1730# command line can be continued by the use of \. Data lines are not continued
1731# in this way. In all lines, the following substutions are made:
1732#
1733# DIR => the current directory
1734# CALLER => the caller of this script
1735#
1736# Arguments: the current test number
1737# reference to the subtest number, holding previous value
1738# reference to the expected return code value
1739# reference to where to put the command name (for messages)
1ca9f507 1740# auxilliary information returned from a previous run
151b83f8
PH
1741#
1742# Returns: 0 the commmand was executed inline, no subprocess was run
1743# 1 a non-exim command was run and waited for
1744# 2 an exim command was run and waited for
1745# 3 a command was run and not waited for (daemon, server, exim_lock)
1746# 4 EOF was encountered after an initial return code line
1ca9f507
PP
1747# Optionally alse a second parameter, a hash-ref, with auxilliary information:
1748# exim_pid: pid of a run process
c9a55f6a 1749# munge: name of a post-script results munger
151b83f8
PH
1750
1751sub run_command{
1752my($testno) = $_[0];
1753my($subtestref) = $_[1];
1754my($commandnameref) = $_[3];
1ca9f507 1755my($aux_info) = $_[4];
151b83f8
PH
1756my($yield) = 1;
1757
bc3c7bb7
HSHR
1758our %ENV = map { $_ => $ENV{$_} } grep { /^(?:USER|SHELL|PATH|TERM|EXIM_TEST_.*)$/ } keys %ENV;
1759
151b83f8
PH
1760if (/^(\d+)\s*$/) # Handle unusual return code
1761 {
1762 my($r) = $_[2];
1763 $$r = $1 << 8;
1764 $_ = <SCRIPT>;
1765 return 4 if !defined $_; # Missing command
1766 $lineno++;
1767 }
1768
1769chomp;
1770$wait_time = 0;
1771
1772# Handle concatenated command lines
1773
1774s/\s+$//;
1775while (substr($_, -1) eq"\\")
1776 {
1777 my($temp);
1778 $_ = substr($_, 0, -1);
1779 chomp($temp = <SCRIPT>);
1780 if (defined $temp)
1781 {
1782 $lineno++;
1783 $temp =~ s/\s+$//;
1784 $temp =~ s/^\s+//;
1785 $_ .= $temp;
1786 }
1787 }
1788
1789# Do substitutions
1790
1791do_substitute($testno);
1792if ($debug) { printf ">> $_\n"; }
1793
1794# Pass back the command name (for messages)
1795
1796($$commandnameref) = /^(\S+)/;
1797
1798# Here follows code for handling the various different commands that are
1799# supported by this script. The first group of commands are all freestanding
1800# in that they share no common code and are not followed by any data lines.
1801
1802
1803###################
1804###################
1805
1806# The "dbmbuild" command runs exim_dbmbuild. This is used both to test the
1807# utility and to make DBM files for testing DBM lookups.
1808
1809if (/^dbmbuild\s+(\S+)\s+(\S+)/)
1810 {
1811 run_system("(./eximdir/exim_dbmbuild $parm_cwd/$1 $parm_cwd/$2;" .
1812 "echo exim_dbmbuild exit code = \$?)" .
1813 ">>test-stdout");
1814 return 1;
1815 }
1816
1817
1818# The "dump" command runs exim_dumpdb. On different systems, the output for
1819# some types of dump may appear in a different order because it's just hauled
1820# out of the DBM file. We can solve this by sorting. Ignore the leading
1821# date/time, as it will be flattened later during munging.
1822
1823if (/^dump\s+(\S+)/)
1824 {
1825 my($which) = $1;
1826 my(@temp);
1827 print ">> ./eximdir/exim_dumpdb $parm_cwd/spool $which\n" if $debug;
1828 open(IN, "./eximdir/exim_dumpdb $parm_cwd/spool $which |");
a0ff7619
JH
1829 open(OUT, ">>test-stdout");
1830 print OUT "+++++++++++++++++++++++++++\n";
1831
1832 if ($which eq "retry")
151b83f8 1833 {
a0ff7619
JH
1834 $/ = "\n ";
1835 @temp = <IN>;
1836 $/ = "\n";
1837
151b83f8 1838 @temp = sort {
a0ff7619
JH
1839 my($aa) = split(' ', $a);
1840 my($bb) = split(' ', $b);
1841 return $aa cmp $bb;
151b83f8 1842 } @temp;
a0ff7619
JH
1843
1844 foreach $item (@temp)
1845 {
7f8794a2 1846 $item =~ s/^\s*(.*)\n(.*)\n?\s*$/$1\n$2/m;
a0ff7619
JH
1847 print OUT " $item\n";
1848 }
151b83f8 1849 }
a0ff7619
JH
1850 else
1851 {
1852 @temp = <IN>;
1853 if ($which eq "callout")
1854 {
1855 @temp = sort {
1856 my($aa) = substr $a, 21;
1857 my($bb) = substr $b, 21;
1858 return $aa cmp $bb;
1859 } @temp;
1860 }
1861 print OUT @temp;
1862 }
1863
1864 close(IN);
151b83f8
PH
1865 close(OUT);
1866 return 1;
1867 }
1868
1869
1870# The "echo" command is a way of writing comments to the screen.
1871
1872if (/^echo\s+(.*)$/)
1873 {
1874 print "$1\n";
1875 return 0;
1876 }
1877
1878
1879# The "exim_lock" command runs exim_lock in the same manner as "server",
1880# but it doesn't use any input.
1881
1882if (/^exim_lock\s+(.*)$/)
1883 {
1884 $cmd = "./eximdir/exim_lock $1 >>test-stdout";
1885 $server_pid = open SERVERCMD, "|$cmd" ||
1886 tests_exit(-1, "Failed to run $cmd\n");
1887
1888 # This gives the process time to get started; otherwise the next
1889 # process may not find it there when it expects it.
1890
6588a918 1891 select(undef, undef, undef, 0.1);
151b83f8
PH
1892 return 3;
1893 }
1894
1895
1896# The "exinext" command runs exinext
1897
1898if (/^exinext\s+(.*)/)
1899 {
1900 run_system("(./eximdir/exinext " .
1901 "-DEXIM_PATH=$parm_cwd/eximdir/exim " .
1902 "-C $parm_cwd/test-config $1;" .
1903 "echo exinext exit code = \$?)" .
1904 ">>test-stdout");
1905 return 1;
1906 }
1907
1908
f3f065bb
PH
1909# The "exigrep" command runs exigrep on the current mainlog
1910
1911if (/^exigrep\s+(.*)/)
1912 {
1913 run_system("(./eximdir/exigrep " .
1914 "$1 $parm_cwd/spool/log/mainlog;" .
1915 "echo exigrep exit code = \$?)" .
1916 ">>test-stdout");
1917 return 1;
1918 }
1919
1920
1921# The "eximstats" command runs eximstats on the current mainlog
1922
1923if (/^eximstats\s+(.*)/)
1924 {
1925 run_system("(./eximdir/eximstats " .
1926 "$1 $parm_cwd/spool/log/mainlog;" .
1927 "echo eximstats exit code = \$?)" .
1928 ">>test-stdout");
1929 return 1;
1930 }
1931
1932
151b83f8
PH
1933# The "gnutls" command makes a copy of saved GnuTLS parameter data in the
1934# spool directory, to save Exim from re-creating it each time.
1935
1936if (/^gnutls/)
1937 {
83e2f8a2
PP
1938 my $gen_fn = "spool/gnutls-params-$gnutls_dh_bits_normal";
1939 run_system "sudo cp -p aux-fixed/gnutls-params $gen_fn;" .
1940 "sudo chown $parm_eximuser:$parm_eximgroup $gen_fn;" .
1941 "sudo chmod 0400 $gen_fn";
151b83f8
PH
1942 return 1;
1943 }
1944
1945
1946# The "killdaemon" command should ultimately follow the starting of any Exim
1947# daemon with the -bd option. We kill with SIGINT rather than SIGTERM to stop
1948# it outputting "Terminated" to the terminal when not in the background.
1949
1950if (/^killdaemon/)
1951 {
1ca9f507
PP
1952 my $return_extra = {};
1953 if (exists $aux_info->{exim_pid})
1954 {
1955 $pid = $aux_info->{exim_pid};
1956 $return_extra->{exim_pid} = undef;
1957 print ">> killdaemon: recovered pid $pid\n" if $debug;
3ff2360f
JH
1958 if ($pid)
1959 {
ed54e8ae 1960 run_system("sudo /bin/kill -INT $pid");
3ff2360f
JH
1961 wait;
1962 }
1ca9f507
PP
1963 } else {
1964 $pid = `cat $parm_cwd/spool/exim-daemon.*`;
3ff2360f
JH
1965 if ($pid)
1966 {
ed54e8ae 1967 run_system("sudo /bin/kill -INT $pid");
3ff2360f
JH
1968 close DAEMONCMD; # Waits for process
1969 }
1ca9f507 1970 }
3ff2360f 1971 run_system("sudo /bin/rm -f spool/exim-daemon.*");
1ca9f507 1972 return (1, $return_extra);
151b83f8
PH
1973 }
1974
1975
1976# The "millisleep" command is like "sleep" except that its argument is in
1977# milliseconds, thus allowing for a subsecond sleep, which is, in fact, all it
1978# is used for.
1979
1980elsif (/^millisleep\s+(.*)$/)
1981 {
1982 select(undef, undef, undef, $1/1000);
1983 return 0;
1984 }
1985
1986
c9a55f6a
JH
1987# The "munge" command selects one of a hardwired set of test-result modifications
1988# to be made before result compares are run agains the golden set. This lets
1989# us account for test-system dependent things which only affect a few, but known,
1990# test-cases.
1991# Currently only the last munge takes effect.
1992
1993if (/^munge\s+(.*)$/)
1994 {
1995 return (0, { munge => $1 });
1996 }
1997
1998
151b83f8
PH
1999# The "sleep" command does just that. For sleeps longer than 1 second we
2000# tell the user what's going on.
2001
2002if (/^sleep\s+(.*)$/)
2003 {
2004 if ($1 == 1)
2005 {
2006 sleep(1);
2007 }
2008 else
2009 {
2010 printf(" Test %d sleep $1 ", $$subtestref);
2011 for (1..$1)
2012 {
2013 print ".";
2014 sleep(1);
2015 }
2016 printf("\r Test %d $cr", $$subtestref);
2017 }
2018 return 0;
2019 }
2020
2021
2022# Various Unix management commands are recognized
2023
21c28500 2024if (/^(ln|ls|du|mkdir|mkfifo|touch|cp|cat)\s/ ||
4e192008 2025 /^sudo\s(rmdir|rm|mv|chown|chmod)\s/)
151b83f8
PH
2026 {
2027 run_system("$_ >>test-stdout 2>>test-stderr");
2028 return 1;
2029 }
2030
2031
2032
2033###################
2034###################
2035
2036# The next group of commands are also freestanding, but they are all followed
2037# by data lines.
2038
2039
2040# The "server" command starts up a script-driven server that runs in parallel
2041# with the following exim command. Therefore, we want to run a subprocess and
2042# not yet wait for it to complete. The waiting happens after the next exim
2043# command, triggered by $server_pid being non-zero. The server sends its output
2044# to a different file. The variable $server_opts, if not empty, contains
2045# options to disable IPv4 or IPv6 if necessary.
b9d9c5a2 2046# This works because "server" swallows its stdin before waiting for a connection.
151b83f8
PH
2047
2048if (/^server\s+(.*)$/)
2049 {
f41e0506
JH
2050 $pidfile = "$parm_cwd/aux-var/server-daemon.pid";
2051 $cmd = "./bin/server $server_opts -oP $pidfile $1 >>test-stdout-server";
151b83f8
PH
2052 print ">> $cmd\n" if ($debug);
2053 $server_pid = open SERVERCMD, "|$cmd" || tests_exit(-1, "Failed to run $cmd");
2054 SERVERCMD->autoflush(1);
2055 print ">> Server pid is $server_pid\n" if $debug;
2056 while (<SCRIPT>)
2057 {
2058 $lineno++;
2059 last if /^\*{4}\s*$/;
2060 print SERVERCMD;
2061 }
2062 print SERVERCMD "++++\n"; # Send end to server; can't send EOF yet
2063 # because close() waits for the process.
2064
f41e0506 2065 # Interlock the server startup; otherwise the next
151b83f8 2066 # process may not find it there when it expects it.
f41e0506 2067 while (! stat("$pidfile") ) { select(undef, undef, undef, 0.3); }
151b83f8
PH
2068 return 3;
2069 }
2070
2071
2072# The "write" command is a way of creating files of specific sizes for
2073# buffering tests, or containing specific data lines from within the script
2074# (rather than hold lots of little files). The "catwrite" command does the
2075# same, but it also copies the lines to test-stdout.
2076
2077if (/^(cat)?write\s+(\S+)(?:\s+(.*))?\s*$/)
2078 {
2079 my($cat) = defined $1;
2080 @sizes = ();
2081 @sizes = split /\s+/, $3 if defined $3;
2082 open FILE, ">$2" || tests_exit(-1, "Failed to open \"$2\": $!");
2083
2084 if ($cat)
2085 {
2086 open CAT, ">>test-stdout" ||
2087 tests_exit(-1, "Failed to open test-stdout: $!");
2088 print CAT "==========\n";
2089 }
2090
2091 if (scalar @sizes > 0)
2092 {
2093 # Pre-data
2094
2095 while (<SCRIPT>)
2096 {
2097 $lineno++;
2098 last if /^\+{4}\s*$/;
2099 print FILE;
2100 print CAT if $cat;
2101 }
2102
2103 # Sized data
2104
2105 while (scalar @sizes > 0)
2106 {
2107 ($count,$len,$leadin) = (shift @sizes) =~ /(\d+)x(\d+)(?:=(.*))?/;
2108 $leadin = "" if !defined $leadin;
2109 $leadin =~ s/_/ /g;
2110 $len -= length($leadin) + 1;
2111 while ($count-- > 0)
2112 {
2113 print FILE $leadin, "a" x $len, "\n";
2114 print CAT $leadin, "a" x $len, "\n" if $cat;
2115 }
2116 }
2117 }
2118
2119 # Post data, or only data if no sized data
2120
2121 while (<SCRIPT>)
2122 {
2123 $lineno++;
2124 last if /^\*{4}\s*$/;
2125 print FILE;
2126 print CAT if $cat;
2127 }
2128 close FILE;
2129
2130 if ($cat)
2131 {
2132 print CAT "==========\n";
2133 close CAT;
2134 }
2135
2136 return 0;
2137 }
2138
2139
2140###################
2141###################
2142
2143# From this point on, script commands are implemented by setting up a shell
2144# command in the variable $cmd. Shared code to run this command and handle its
2145# input and output follows.
2146
cfc54830
PH
2147# The "client", "client-gnutls", and "client-ssl" commands run a script-driven
2148# program that plays the part of an email client. We also have the availability
2149# of running Perl for doing one-off special things. Note that all these
2150# commands expect stdin data to be supplied.
151b83f8 2151
cfc54830 2152if (/^client/ || /^(sudo\s+)?perl\b/)
151b83f8
PH
2153 {
2154 s"client"./bin/client";
2155 $cmd = "$_ >>test-stdout 2>>test-stderr";
2156 }
2157
2158# For the "exim" command, replace the text "exim" with the path for the test
2159# binary, plus -D options to pass over various parameters, and a -C option for
2160# the testing configuration file. When running in the test harness, Exim does
2161# not drop privilege when -C and -D options are present. To run the exim
2162# command as root, we use sudo.
2163
bc3c7bb7 2164elsif (/^((?i:[A-Z\d_]+=\S+\s+)+)?(\d+)?\s*(sudo(?:\s+-u\s+(\w+))?\s+)?exim(_\S+)?\s+(.*)$/)
151b83f8 2165 {
4c7220eb 2166 $args = $6;
151b83f8 2167 my($envset) = (defined $1)? $1 : "";
4c7220eb
HSHR
2168 my($sudo) = (defined $3)? "sudo " . (defined $4 ? "-u $4 ":"") : "";
2169 my($special)= (defined $5)? $5 : "";
151b83f8
PH
2170 $wait_time = (defined $2)? $2 : 0;
2171
2172 # Return 2 rather than 1 afterwards
2173
2174 $yield = 2;
2175
2176 # Update the test number
2177
2178 $$subtestref = $$subtestref + 1;
2179 printf(" Test %d $cr", $$subtestref);
2180
2181 # Copy the configuration file, making the usual substitutions.
2182
2183 open (IN, "$parm_cwd/confs/$testno") ||
2184 tests_exit(-1, "Couldn't open $parm_cwd/confs/$testno: $!\n");
2185 open (OUT, ">test-config") ||
2186 tests_exit(-1, "Couldn't open test-config: $!\n");
2187 while (<IN>)
2188 {
2189 do_substitute($testno);
2190 print OUT;
2191 }
2192 close(IN);
2193 close(OUT);
2194
2195 # The string $msg1 in args substitutes the message id of the first
2196 # message on the queue, and so on. */
2197
2198 if ($args =~ /\$msg/)
2199 {
2200 my($listcmd) = "$parm_cwd/eximdir/exim -bp " .
2201 "-DEXIM_PATH=$parm_cwd/eximdir/exim " .
2202 "-C $parm_cwd/test-config |";
2203 print ">> Getting queue list from:\n>> $listcmd\n" if ($debug);
2204 open (QLIST, $listcmd) || tests_exit(-1, "Couldn't run \"exim -bp\": $!\n");
2205 my(@msglist) = ();
2206 while (<QLIST>) { push (@msglist, $1) if /^\s*\d+[smhdw]\s+\S+\s+(\S+)/; }
2207 close(QLIST);
2208
2209 # Done backwards just in case there are more than 9
2210
25adc2a8 2211 for (my $i = @msglist; $i > 0; $i--) { $args =~ s/\$msg$i/$msglist[$i-1]/g; }
3ff2360f
JH
2212 if ( $args =~ /\$msg\d/ )
2213 {
8334b9b8
TL
2214 tests_exit(-1, "Not enough messages in spool, for test $testno line $lineno\n")
2215 unless $force_continue;
3ff2360f 2216 }
151b83f8
PH
2217 }
2218
2219 # If -d is specified in $optargs, remove it from $args; i.e. let
2220 # the command line for runtest override. Then run Exim.
2221
2222 $args =~ s/(?:^|\s)-d\S*// if $optargs =~ /(?:^|\s)-d/;
2223
2c9f7ff8
JH
2224 my $opt_valgrind = $valgrind ? "valgrind --leak-check=yes --suppressions=$parm_cwd/aux-fixed/valgrind.supp " : "";
2225
2226 $cmd = "$envset$sudo$opt_valgrind" .
2227 "$parm_cwd/eximdir/exim$special$optargs " .
151b83f8
PH
2228 "-DEXIM_PATH=$parm_cwd/eximdir/exim$special " .
2229 "-C $parm_cwd/test-config $args " .
2230 ">>test-stdout 2>>test-stderr";
151b83f8
PH
2231 # If the command is starting an Exim daemon, we run it in the same
2232 # way as the "server" command above, that is, we don't want to wait
2233 # for the process to finish. That happens when "killdaemon" is obeyed later
2234 # in the script. We also send the stderr output to test-stderr-server. The
2235 # daemon has its log files put in a different place too (by configuring with
2236 # log_file_path). This requires the directory to be set up in advance.
2237 #
2238 # There are also times when we want to run a non-daemon version of Exim
2239 # (e.g. a queue runner) with the server configuration. In this case,
2240 # we also define -DNOTDAEMON.
2241
2242 if ($cmd =~ /\s-DSERVER=server\s/ && $cmd !~ /\s-DNOTDAEMON\s/)
2243 {
f41e0506 2244 $pidfile = "$parm_cwd/spool/exim-daemon.pid";
151b83f8
PH
2245 if ($debug) { printf ">> daemon: $cmd\n"; }
2246 run_system("sudo mkdir spool/log 2>/dev/null");
2247 run_system("sudo chown $parm_eximuser:$parm_eximgroup spool/log");
2248
2249 # Before running the command, convert the -bd option into -bdf so that an
2250 # Exim daemon doesn't double fork. This means that when we wait close
1b781f48
PH
2251 # DAEMONCMD, it waits for the correct process. Also, ensure that the pid
2252 # file is written to the spool directory, in case the Exim binary was
2253 # built with PID_FILE_PATH pointing somewhere else.
151b83f8 2254
f41e0506
JH
2255 if ($cmd =~ /\s-oP\s/)
2256 {
2257 ($pidfile = $cmd) =~ s/^.*-oP ([^ ]+).*$/$1/;
2258 $cmd =~ s!\s-bd\s! -bdf !;
2259 }
2260 else
2261 {
2262 $pidfile = "$parm_cwd/spool/exim-daemon.pid";
2263 $cmd =~ s!\s-bd\s! -bdf -oP $pidfile !;
2264 }
151b83f8
PH
2265 print ">> |${cmd}-server\n" if ($debug);
2266 open DAEMONCMD, "|${cmd}-server" || tests_exit(-1, "Failed to run $cmd");
2267 DAEMONCMD->autoflush(1);
2268 while (<SCRIPT>) { $lineno++; last if /^\*{4}\s*$/; } # Ignore any input
f41e0506
JH
2269
2270 # Interlock with daemon startup
2271 while (! stat("$pidfile") ) { select(undef, undef, undef, 0.3); }
151b83f8
PH
2272 return 3; # Don't wait
2273 }
1ca9f507
PP
2274 elsif ($cmd =~ /\s-DSERVER=wait:(\d+)\s/)
2275 {
df613eb4
HSHR
2276
2277 # The port and the $dynamic_socket was already allocated while parsing the
2278 # script file, where -DSERVER=wait:PORT_DYNAMIC was encountered.
2279
1ca9f507
PP
2280 my $listen_port = $1;
2281 if ($debug) { printf ">> wait-mode daemon: $cmd\n"; }
2282 run_system("sudo mkdir spool/log 2>/dev/null");
2283 run_system("sudo chown $parm_eximuser:$parm_eximgroup spool/log");
2284
1ca9f507
PP
2285 my $pid = fork();
2286 if (not defined $pid) { die "** fork failed: $!\n" }
2287 if (not $pid) {
2288 close(STDIN);
df613eb4
HSHR
2289 open(STDIN, '<&', $dynamic_socket) or die "** dup sock to stdin failed: $!\n";
2290 close($dynamic_socket);
1ca9f507
PP
2291 print "[$$]>> ${cmd}-server\n" if ($debug);
2292 exec "exec ${cmd}-server";
df613eb4 2293 die "Can't exec ${cmd}-server: $!\n";
1ca9f507
PP
2294 }
2295 while (<SCRIPT>) { $lineno++; last if /^\*{4}\s*$/; } # Ignore any input
2296 select(undef, undef, undef, 0.3); # Let the daemon get going
2297 return (3, { exim_pid => $pid }); # Don't wait
2298 }
151b83f8
PH
2299 }
2300
bdf36f7c
JH
2301# The "background" command is run but not waited-for, like exim -DSERVER=server.
2302# One script line is read and fork-exec'd. The PID is stored for a later
2303# killdaemon.
2304
2305elsif (/^background$/)
2306 {
2307 my $line;
2308# $pidfile = "$parm_cwd/aux-var/server-daemon.pid";
2309
2310 $_ = <SCRIPT>; $lineno++;
2311 chomp;
2312 $line = $_;
2313 if ($debug) { printf ">> daemon: $line >>test-stdout 2>>test-stderr\n"; }
2314
2315 my $pid = fork();
2316 if (not defined $pid) { die "** fork failed: $!\n" }
2317 if (not $pid) {
2318 print "[$$]>> ${line}\n" if ($debug);
2319 close(STDIN);
2320 open(STDIN, "<", "test-stdout");
2321 close(STDOUT);
2322 open(STDOUT, ">>", "test-stdout");
2323 close(STDERR);
2324 open(STDERR, ">>", "test-stderr-server");
2325 exec "exec ${line}";
2326 exit(1);
2327 }
2328
2329# open(my $fh, ">", $pidfile) ||
2330# tests_exit(-1, "Failed to open $pidfile: $!");
2331# printf($fh, "%d\n", $pid);
2332# close($fh);
2333
2334 while (<SCRIPT>) { $lineno++; last if /^\*{4}\s*$/; } # Ignore any input
2335 select(undef, undef, undef, 0.3); # Let the daemon get going
2336 return (3, { exim_pid => $pid }); # Don't wait
2337 }
2338
2339
151b83f8
PH
2340
2341# Unknown command
2342
2343else { tests_exit(-1, "Command unrecognized in line $lineno: $_"); }
2344
2345
2346# Run the command, with stdin connected to a pipe, and write the stdin data
2347# to it, with appropriate substitutions. If a line ends with \NONL\, chop off
2348# the terminating newline (and the \NONL\). If the command contains
2349# -DSERVER=server add "-server" to the command, where it will adjoin the name
2350# for the stderr file. See comment above about the use of -DSERVER.
2351
2352$stderrsuffix = ($cmd =~ /\s-DSERVER=server\s/)? "-server" : "";
2353print ">> |${cmd}${stderrsuffix}\n" if ($debug);
2354open CMD, "|${cmd}${stderrsuffix}" || tests_exit(1, "Failed to run $cmd");
2355
2356CMD->autoflush(1);
2357while (<SCRIPT>)
2358 {
2359 $lineno++;
2360 last if /^\*{4}\s*$/;
2361 do_substitute($testno);
2362 if (/^(.*)\\NONL\\\s*$/) { print CMD $1; } else { print CMD; }
2363 }
2364
2365# For timeout tests, wait before closing the pipe; we expect a
2366# SIGPIPE error in this case.
2367
2368if ($wait_time > 0)
2369 {
2370 printf(" Test %d sleep $wait_time ", $$subtestref);
2371 while ($wait_time-- > 0)
2372 {
2373 print ".";
2374 sleep(1);
2375 }
2376 printf("\r Test %d $cr", $$subtestref);
2377 }
2378
2379$sigpipehappened = 0;
2380close CMD; # Waits for command to finish
2381return $yield; # Ran command and waited
2382}
2383
2384
2385
2386
2387###############################################################################
2388###############################################################################
2389
d63a9563 2390# Here begins the Main Program ...
151b83f8
PH
2391
2392###############################################################################
2393###############################################################################
2394
2395
2396autoflush STDOUT 1;
2397print "Exim tester $testversion\n";
2398
26ab1da3
HSHR
2399# extend the PATH with .../sbin
2400# we map all (.../bin) to (.../sbin:.../bin)
2401$ENV{PATH} = do {
2402 my %seen = map { $_, 1 } split /:/, $ENV{PATH};
25adc2a8
HSHR
2403 join ':' => map { m{(.*)/bin$}
2404 ? ( $seen{"$1/sbin"} ? () : ("$1/sbin"), $_)
2405 : ($_) }
26ab1da3
HSHR
2406 split /:/, $ENV{PATH};
2407};
151b83f8
PH
2408
2409##################################################
650ececb
PP
2410# Some tests check created file modes #
2411##################################################
2412
2413umask 022;
2414
2415
2416##################################################
151b83f8
PH
2417# Check for the "less" command #
2418##################################################
2419
d63a9563 2420$more = 'more' if system('which less >/dev/null 2>&1') != 0;
151b83f8
PH
2421
2422
2423
2424##################################################
2425# Check for sudo access to root #
2426##################################################
2427
2428print "You need to have sudo access to root to run these tests. Checking ...\n";
d63a9563 2429if (system('sudo true >/dev/null') != 0)
151b83f8
PH
2430 {
2431 die "** Test for sudo failed: testing abandoned.\n";
2432 }
2433else
2434 {
2435 print "Test for sudo OK\n";
2436 }
2437
2438
2439
2440##################################################
2441# See if an Exim binary has been given #
2442##################################################
2443
2444# If the first character of the first argument is '/', the argument is taken
1c143d9d
HSHR
2445# as the path to the binary. If the first argument does not start with a
2446# '/' but exists in the file system, it's assumed to be the Exim binary.
151b83f8 2447
1c143d9d 2448$parm_exim = (@ARGV > 0 && (-x $ARGV[0] or $ARGV[0] =~ m?^/?))? Cwd::abs_path(shift @ARGV) : "";
151b83f8
PH
2449print "Exim binary is $parm_exim\n" if $parm_exim ne "";
2450
2451
2452
2453##################################################
2454# Sort out options and which tests are to be run #
2455##################################################
2456
2457# There are a few possible options for the test script itself; after these, any
2458# options are passed on to Exim calls within the tests. Typically, this is used
2459# to turn on Exim debugging while setting up a test.
2460
2461while (@ARGV > 0 && $ARGV[0] =~ /^-/)
2462 {
2463 my($arg) = shift @ARGV;
2464 if ($optargs eq "")
2465 {
2466 if ($arg eq "-DEBUG") { $debug = 1; $cr = "\n"; next; }
2467 if ($arg eq "-DIFF") { $cf = "diff -u"; next; }
825fae12
TL
2468 if ($arg eq "-CONTINUE"){$force_continue = 1;
2469 $more = "cat";
2470 next; }
151b83f8
PH
2471 if ($arg eq "-UPDATE") { $force_update = 1; next; }
2472 if ($arg eq "-NOIPV4") { $have_ipv4 = 0; next; }
2473 if ($arg eq "-NOIPV6") { $have_ipv6 = 0; next; }
2474 if ($arg eq "-KEEP") { $save_output = 1; next; }
2c9f7ff8 2475 if ($arg eq "-VALGRIND") { $valgrind = 1; next; }
28e8a0f7 2476 if ($arg =~ /^-FLAVOU?R$/) { $flavour = shift; next; }
151b83f8
PH
2477 }
2478 $optargs .= " $arg";
2479 }
2480
2481# Any subsequent arguments are a range of test numbers.
2482
2483if (@ARGV > 0)
2484 {
2485 $test_end = $test_start = $ARGV[0];
2486 $test_end = $ARGV[1] if (@ARGV > 1);
2487 $test_end = ($test_start >= 9000)? $test_special_top : $test_top
2488 if $test_end eq "+";
2489 die "** Test numbers out of order\n" if ($test_end < $test_start);
2490 }
2491
2492
2493##################################################
2494# Make the command's directory current #
2495##################################################
2496
2497# After doing so, we find its absolute path name.
2498
2499$cwd = $0;
2500$cwd = '.' if ($cwd !~ s|/[^/]+$||);
2501chdir($cwd) || die "** Failed to chdir to \"$cwd\": $!\n";
2502$parm_cwd = Cwd::getcwd();
2503
2504
2505##################################################
2506# Search for an Exim binary to test #
2507##################################################
2508
2509# If an Exim binary hasn't been provided, try to find one. We can handle the
2510# case where exim-testsuite is installed alongside Exim source directories. For
2511# PH's private convenience, if there's a directory just called "exim4", that
2512# takes precedence; otherwise exim-snapshot takes precedence over any numbered
2513# releases.
2514
2515if ($parm_exim eq "")
2516 {
2517 my($use_srcdir) = "";
2518
2519 opendir DIR, ".." || die "** Failed to opendir \"..\": $!\n";
2520 while ($f = readdir(DIR))
2521 {
2522 my($srcdir);
2523
2524 # Try this directory if it is "exim4" or if it is exim-snapshot or exim-n.m
2525 # possibly followed by -RCx where n.m is greater than any previously tried
2526 # directory. Thus, we should choose the highest version of Exim that has
2527 # been compiled.
2528
969e6431 2529 if ($f eq "exim4" || $f eq "exim-snapshot" || $f eq 'src')
151b83f8
PH
2530 { $srcdir = $f; }
2531 else
2532 { $srcdir = $f
2533 if ($f =~ /^exim-\d+\.\d+(-RC\d+)?$/ && $f gt $use_srcdir); }
2534
2535 # Look for a build directory with a binary in it. If we find a binary,
2536 # accept this source directory.
2537
2538 if ($srcdir)
2539 {
2540 opendir SRCDIR, "../$srcdir" ||
2541 die "** Failed to opendir \"$cwd/../$srcdir\": $!\n";
2542 while ($f = readdir(SRCDIR))
2543 {
2544 if ($f =~ /^build-/ && -e "../$srcdir/$f/exim")
2545 {
2546 $use_srcdir = $srcdir;
2547 $parm_exim = "$cwd/../$srcdir/$f/exim";
2548 $parm_exim =~ s'/[^/]+/\.\./'/';
2549 last;
2550 }
2551 }
2552 closedir(SRCDIR);
2553 }
2554
2555 # If we have found "exim4" or "exim-snapshot", that takes precedence.
2556 # Otherwise, continue to see if there's a later version.
2557
2558 last if $use_srcdir eq "exim4" || $use_srcdir eq "exim-snapshot";
2559 }
2560 closedir(DIR);
2561 print "Exim binary found in $parm_exim\n" if $parm_exim ne "";
2562 }
2563
2564# If $parm_exim is still empty, ask the caller
2565
2566if ($parm_exim eq "")
2567 {
2568 print "** Did not find an Exim binary to test\n";
2569 for ($i = 0; $i < 5; $i++)
2570 {
2571 my($trybin);
2572 print "** Enter pathname for Exim binary: ";
2573 chomp($trybin = <STDIN>);
2574 if (-e $trybin)
2575 {
2576 $parm_exim = $trybin;
2577 last;
2578 }
2579 else
2580 {
2581 print "** $trybin does not exist\n";
2582 }
2583 }
2584 die "** Too many tries\n" if $parm_exim eq "";
2585 }
2586
2587
2588
2589##################################################
2590# Find what is in the binary #
2591##################################################
2592
5f122889
PP
2593# deal with TRUSTED_CONFIG_LIST restrictions
2594unlink("$parm_cwd/test-config") if -e "$parm_cwd/test-config";
72acdf0f
JH
2595open (IN, "$parm_cwd/confs/0000") ||
2596 tests_exit(-1, "Couldn't open $parm_cwd/confs/0000: $!\n");
2597open (OUT, ">test-config") ||
2598 tests_exit(-1, "Couldn't open test-config: $!\n");
2599while (<IN>) { print OUT; }
2600close(IN);
2601close(OUT);
5f122889
PP
2602
2603print("Probing with config file: $parm_cwd/test-config\n");
2604open(EXIMINFO, "$parm_exim -d -C $parm_cwd/test-config -DDIR=$parm_cwd " .
32ca7e2d 2605 "-bP exim_user exim_group 2>&1|") ||
151b83f8
PH
2606 die "** Cannot run $parm_exim: $!\n";
2607while(<EXIMINFO>)
2608 {
c039ce61
HSHR
2609 if (my ($version) = /^Exim version (\S+)/) {
2610 my $git = `git describe --dirty=-XX --match 'exim-4*'`;
2611 if (defined $git and $? == 0) {
2612 chomp $git;
2613 $version =~ s/^\d+\K\./_/;
2614 $git =~ s/^exim-//i;
2615 $git =~ s/.*-\Kg([[:xdigit:]]+(?:-XX)?)/$1/;
2616 print "\n*** Version mismatch (Exim: $version vs. GIT: $git). ***\n\n"
2617 if not $version eq $git;
2618 }
2619 }
151b83f8
PH
2620 $parm_eximuser = $1 if /^exim_user = (.*)$/;
2621 $parm_eximgroup = $1 if /^exim_group = (.*)$/;
32ca7e2d 2622 $parm_trusted_config_list = $1 if /^TRUSTED_CONFIG_LIST:.*?"(.*?)"$/;
c9fb6994
HSHR
2623 ($parm_configure_owner, $parm_configure_group) = ($1, $2)
2624 if /^Configure owner:\s*(\d+):(\d+)/;
38956337 2625 print "$_" if /wrong owner/;
151b83f8
PH
2626 }
2627close(EXIMINFO);
2628
2629if (defined $parm_eximuser)
2630 {
2631 if ($parm_eximuser =~ /^\d+$/) { $parm_exim_uid = $parm_eximuser; }
2632 else { $parm_exim_uid = getpwnam($parm_eximuser); }
2633 }
5f122889
PP
2634else
2635 {
2636 print "Unable to extract exim_user from binary.\n";
2637 print "Check if Exim refused to run; if so, consider:\n";
2638 print " TRUSTED_CONFIG_LIST ALT_CONFIG_PREFIX WHITELIST_D_MACROS\n";
3ce8303e 2639 print "If debug permission denied, are you in the exim group?\n";
5f122889
PP
2640 die "Failing to get information from binary.\n";
2641 }
151b83f8
PH
2642
2643if (defined $parm_eximgroup)
2644 {
2645 if ($parm_eximgroup =~ /^\d+$/) { $parm_exim_gid = $parm_eximgroup; }
2646 else { $parm_exim_gid = getgrnam($parm_eximgroup); }
2647 }
2648
32ca7e2d
HSHR
2649# check the permissions on the TRUSTED_CONFIG_LIST
2650if (defined $parm_trusted_config_list)
2651 {
2652 die "TRUSTED_CONFIG_LIST: $parm_trusted_config_list: $!\n"
2653 if not -f $parm_trusted_config_list;
2654
2655 die "TRUSTED_CONFIG_LIST $parm_trusted_config_list must not be world writable!\n"
2656 if 02 & (stat _)[2];
2657
2658 die sprintf "TRUSTED_CONFIG_LIST: $parm_trusted_config_list %d is group writable, but not owned by group '%s' or '%s'.\n",
2659 (stat _)[1],
2660 scalar(getgrgid 0), scalar(getgrgid $>)
2661 if (020 & (stat _)[2]) and not ((stat _)[5] == $> or (stat _)[5] == 0);
2662
2663 die sprintf "TRUSTED_CONFIG_LIST: $parm_trusted_config_list is not owned by user '%s' or '%s'.\n",
2664 scalar(getpwuid 0), scalar(getpwuid $>)
2665 if (not (-o _ or (stat _)[4] == 0));
2666
2667 open(TCL, $parm_trusted_config_list) or die "Can't open $parm_trusted_config_list: $!\n";
2668 my $test_config = getcwd() . '/test-config';
2669 die "Can't find '$test_config' in TRUSTED_CONFIG_LIST $parm_trusted_config_list."
2670 if not grep { /^$test_config$/ } <TCL>;
2671 }
2672else
2673 {
2674 die "Unable to check the TRUSTED_CONFIG_LIST, seems to be empty?\n";
2675 }
2676
c9fb6994
HSHR
2677die "CONFIGURE_OWNER ($parm_configure_owner) does not match the user invoking $0 ($>)\n"
2678 if $parm_configure_owner != $>;
2679
2680die "CONFIGURE_GROUP ($parm_configure_group) does not match the group invoking $0 ($))\n"
2681 if 0020 & (stat "$parm_cwd/test-config")[2]
2682 and $parm_configure_group != $);
2683
2684
b6a0dbb2 2685open(EXIMINFO, "$parm_exim -d-all+transport -bV -C $parm_cwd/test-config -DDIR=$parm_cwd |") ||
151b83f8
PH
2686 die "** Cannot run $parm_exim: $!\n";
2687
2688print "-" x 78, "\n";
2689
2690while (<EXIMINFO>)
2691 {
2692 my(@temp);
2693
b6a0dbb2 2694 if (/^(Exim|Library) version/) { print; }
151b83f8 2695
21c28500
PH
2696 elsif (/^Size of off_t: (\d+)/)
2697 {
e1b3d58d 2698 print;
21c28500 2699 $have_largefiles = 1 if $1 > 4;
e1b3d58d
JJ
2700 die "** Size of off_t > 32 which seems improbable, not running tests\n"
2701 if ($1 > 32);
21c28500
PH
2702 }
2703
2704 elsif (/^Support for: (.*)/)
151b83f8
PH
2705 {
2706 print;
2707 @temp = split /(\s+)/, $1;
2708 push(@temp, ' ');
2709 %parm_support = @temp;
2710 }
2711
33191679 2712 elsif (/^Lookups \(built-in\): (.*)/)
151b83f8
PH
2713 {
2714 print;
2715 @temp = split /(\s+)/, $1;
2716 push(@temp, ' ');
2717 %parm_lookups = @temp;
2718 }
2719
21c28500 2720 elsif (/^Authenticators: (.*)/)
151b83f8
PH
2721 {
2722 print;
2723 @temp = split /(\s+)/, $1;
2724 push(@temp, ' ');
2725 %parm_authenticators = @temp;
2726 }
2727
21c28500 2728 elsif (/^Routers: (.*)/)
151b83f8
PH
2729 {
2730 print;
2731 @temp = split /(\s+)/, $1;
2732 push(@temp, ' ');
2733 %parm_routers = @temp;
2734 }
2735
2736 # Some transports have options, e.g. appendfile/maildir. For those, ensure
2737 # that the basic transport name is set, and then the name with each of the
2738 # options.
2739
21c28500 2740 elsif (/^Transports: (.*)/)
151b83f8
PH
2741 {
2742 print;
2743 @temp = split /(\s+)/, $1;
2744 my($i,$k);
2745 push(@temp, ' ');
2746 %parm_transports = @temp;
2747 foreach $k (keys %parm_transports)
2748 {
2749 if ($k =~ "/")
2750 {
2751 @temp = split /\//, $k;
2752 $parm_transports{"$temp[0]"} = " ";
2753 for ($i = 1; $i < @temp; $i++)
2754 { $parm_transports{"$temp[0]/$temp[$i]"} = " "; }
2755 }
2756 }
2757 }
2758 }
2759close(EXIMINFO);
2760print "-" x 78, "\n";
2761
5f122889 2762unlink("$parm_cwd/test-config");
151b83f8
PH
2763
2764##################################################
2765# Check for SpamAssassin and ClamAV #
2766##################################################
2767
2768# These are crude tests. If they aren't good enough, we'll have to improve
2769# them, for example by actually passing a message through spamc or clamscan.
2770
2771if (defined $parm_support{'Content_Scanning'})
2772 {
3ff2360f
JH
2773 my $sock = new FileHandle;
2774
151b83f8
PH
2775 if (system("spamc -h 2>/dev/null >/dev/null") == 0)
2776 {
151b83f8
PH
2777 print "The spamc command works:\n";
2778
2779 # This test for an active SpamAssassin is courtesy of John Jetmore.
2780 # The tests are hard coded to localhost:783, so no point in making
2781 # this test flexible like the clamav test until the test scripts are
2782 # changed. spamd doesn't have the nice PING/PONG protoccol that
2783 # clamd does, but it does respond to errors in an informative manner,
2784 # so use that.
2785
2786 my($sint,$sport) = ('127.0.0.1',783);
2787 eval
2788 {
2789 my $sin = sockaddr_in($sport, inet_aton($sint))
2790 or die "** Failed packing $sint:$sport\n";
3ff2360f 2791 socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp'))
151b83f8
PH
2792 or die "** Unable to open socket $sint:$sport\n";
2793
2794 local $SIG{ALRM} =
2795 sub { die "** Timeout while connecting to socket $sint:$sport\n"; };
2796 alarm(5);
3ff2360f 2797 connect($sock, $sin)
151b83f8
PH
2798 or die "** Unable to connect to socket $sint:$sport\n";
2799 alarm(0);
2800
3ff2360f
JH
2801 select((select($sock), $| = 1)[0]);
2802 print $sock "bad command\r\n";
151b83f8
PH
2803
2804 $SIG{ALRM} =
2805 sub { die "** Timeout while reading from socket $sint:$sport\n"; };
2806 alarm(10);
3ff2360f 2807 my $res = <$sock>;
151b83f8
PH
2808 alarm(0);
2809
2810 $res =~ m|^SPAMD/|
2811 or die "** Did not get SPAMD from socket $sint:$sport. "
2812 ."It said: $res\n";
2813 };
2814 alarm(0);
2815 if($@)
2816 {
2817 print " $@";
2818 print " Assume SpamAssassin (spamd) is not running\n";
2819 }
2820 else
2821 {
2822 $parm_running{'SpamAssassin'} = ' ';
2823 print " SpamAssassin (spamd) seems to be running\n";
2824 }
2825 }
2826 else
2827 {
2828 print "The spamc command failed: assume SpamAssassin (spamd) is not running\n";
2829 }
2830
2831 # For ClamAV, we need to find the clamd socket for use in the Exim
2832 # configuration. Search for the clamd configuration file.
2833
2834 if (system("clamscan -h 2>/dev/null >/dev/null") == 0)
2835 {
2836 my($f, $clamconf, $test_prefix);
2837
2838 print "The clamscan command works";
2839
2840 $test_prefix = $ENV{EXIM_TEST_PREFIX};
2841 $test_prefix = "" if !defined $test_prefix;
2842
2843 foreach $f ("$test_prefix/etc/clamd.conf",
2844 "$test_prefix/usr/local/etc/clamd.conf",
2845 "$test_prefix/etc/clamav/clamd.conf", "")
2846 {
2847 if (-e $f)
2848 {
2849 $clamconf = $f;
2850 last;
2851 }
2852 }
2853
11b3bc4d
PH
2854 # Read the ClamAV configuration file and find the socket interface.
2855
151b83f8
PH
2856 if ($clamconf ne "")
2857 {
11b3bc4d 2858 my $socket_domain;
151b83f8
PH
2859 open(IN, "$clamconf") || die "\n** Unable to open $clamconf: $!\n";
2860 while (<IN>)
2861 {
2862 if (/^LocalSocket\s+(.*)/)
2863 {
2864 $parm_clamsocket = $1;
11b3bc4d 2865 $socket_domain = AF_UNIX;
151b83f8
PH
2866 last;
2867 }
11b3bc4d
PH
2868 if (/^TCPSocket\s+(\d+)/)
2869 {
2870 if (defined $parm_clamsocket)
2871 {
2872 $parm_clamsocket .= " $1";
2873 $socket_domain = AF_INET;
2874 last;
2875 }
2876 else
2877 {
2878 $parm_clamsocket = " $1";
2879 }
2880 }
2881 elsif (/^TCPAddr\s+(\S+)/)
2882 {
2883 if (defined $parm_clamsocket)
2884 {
2885 $parm_clamsocket = $1 . $parm_clamsocket;
2886 $socket_domain = AF_INET;
2887 last;
2888 }
2889 else
2890 {
2891 $parm_clamsocket = $1;
2892 }
2893 }
151b83f8
PH
2894 }
2895 close(IN);
11b3bc4d
PH
2896
2897 if (defined $socket_domain)
151b83f8
PH
2898 {
2899 print ":\n The clamd socket is $parm_clamsocket\n";
2900 # This test for an active ClamAV is courtesy of Daniel Tiefnig.
2901 eval
2902 {
11b3bc4d
PH
2903 my $socket;
2904 if ($socket_domain == AF_UNIX)
2905 {
2906 $socket = sockaddr_un($parm_clamsocket) or die "** Failed packing '$parm_clamsocket'\n";
2907 }
2908 elsif ($socket_domain == AF_INET)
2909 {
2910 my ($ca_host, $ca_port) = split(/\s+/,$parm_clamsocket);
2911 my $ca_hostent = gethostbyname($ca_host) or die "** Failed to get raw address for host '$ca_host'\n";
2912 $socket = sockaddr_in($ca_port, $ca_hostent) or die "** Failed packing '$parm_clamsocket'\n";
2913 }
2914 else
2915 {
2916 die "** Unknown socket domain '$socket_domain' (should not happen)\n";
2917 }
3ff2360f 2918 socket($sock, $socket_domain, SOCK_STREAM, 0) or die "** Unable to open socket '$parm_clamsocket'\n";
151b83f8
PH
2919 local $SIG{ALRM} = sub { die "** Timeout while connecting to socket '$parm_clamsocket'\n"; };
2920 alarm(5);
3ff2360f 2921 connect($sock, $socket) or die "** Unable to connect to socket '$parm_clamsocket'\n";
151b83f8
PH
2922 alarm(0);
2923
3ff2360f
JH
2924 my $ofh = select $sock; $| = 1; select $ofh;
2925 print $sock "PING\n";
151b83f8
PH
2926
2927 $SIG{ALRM} = sub { die "** Timeout while reading from socket '$parm_clamsocket'\n"; };
2928 alarm(10);
3ff2360f 2929 my $res = <$sock>;
151b83f8
PH
2930 alarm(0);
2931
2932 $res =~ /PONG/ or die "** Did not get PONG from socket '$parm_clamsocket'. It said: $res\n";
2933 };
2934 alarm(0);
2935
2936 if($@)
2937 {
520de300 2938 print " $@";
151b83f8
PH
2939 print " Assume ClamAV is not running\n";
2940 }
2941 else
2942 {
2943 $parm_running{'ClamAV'} = ' ';
2944 print " ClamAV seems to be running\n";
2945 }
2946 }
2947 else
2948 {
11b3bc4d 2949 print ", but the socket for clamd could not be determined\n";
151b83f8
PH
2950 print "Assume ClamAV is not running\n";
2951 }
2952 }
2953
2954 else
2955 {
2956 print ", but I can't find a configuration for clamd\n";
2957 print "Assume ClamAV is not running\n";
2958 }
2959 }
2960 }
2961
2962
2963##################################################
bdf36f7c
JH
2964# Check for redis #
2965##################################################
de78e2d5 2966if (defined $parm_lookups{'redis'})
bdf36f7c
JH
2967 {
2968 if (system("redis-server -v 2>/dev/null >/dev/null") == 0)
2969 {
2970 print "The redis-server command works\n";
2971 $parm_running{'redis'} = ' ';
2972 }
2973 else
2974 {
2975 print "The redis-server command failed: assume Redis not installed\n";
2976 }
2977 }
2978
2979##################################################
151b83f8
PH
2980# Test for the basic requirements #
2981##################################################
2982
2983# This test suite assumes that Exim has been built with at least the "usual"
2984# set of routers, transports, and lookups. Ensure that this is so.
2985
2986$missing = "";
2987
2988$missing .= " Lookup: lsearch\n" if (!defined $parm_lookups{'lsearch'});
2989
2990$missing .= " Router: accept\n" if (!defined $parm_routers{'accept'});
2991$missing .= " Router: dnslookup\n" if (!defined $parm_routers{'dnslookup'});
2992$missing .= " Router: manualroute\n" if (!defined $parm_routers{'manualroute'});
2993$missing .= " Router: redirect\n" if (!defined $parm_routers{'redirect'});
2994
2995$missing .= " Transport: appendfile\n" if (!defined $parm_transports{'appendfile'});
2996$missing .= " Transport: autoreply\n" if (!defined $parm_transports{'autoreply'});
2997$missing .= " Transport: pipe\n" if (!defined $parm_transports{'pipe'});
2998$missing .= " Transport: smtp\n" if (!defined $parm_transports{'smtp'});
2999
3000if ($missing ne "")
3001 {
3002 print "\n";
3003 print "** Many features can be included or excluded from Exim binaries.\n";
3004 print "** This test suite requires that Exim is built to contain a certain\n";
3005 print "** set of basic facilities. It seems that some of these are missing\n";
3006 print "** from the binary that is under test, so the test cannot proceed.\n";
3007 print "** The missing facilities are:\n";
3008 print "$missing";
3009 die "** Test script abandoned\n";
3010 }
3011
3012
3013##################################################
3014# Check for the auxiliary programs #
3015##################################################
3016
3017# These are always required:
3018
3019for $prog ("cf", "checkaccess", "client", "client-ssl", "client-gnutls",
3020 "fakens", "iefbr14", "server")
3021 {
3022 next if ($prog eq "client-ssl" && !defined $parm_support{'OpenSSL'});
3023 next if ($prog eq "client-gnutls" && !defined $parm_support{'GnuTLS'});
3024 if (!-e "bin/$prog")
3025 {
3026 print "\n";
3027 print "** bin/$prog does not exist. Have you run ./configure and make?\n";
3028 die "** Test script abandoned\n";
3029 }
3030 }
3031
3032# If the "loaded" binary is missing, we cut out tests for ${dlfunc. It isn't
3033# compiled on systems where we don't know how to. However, if Exim does not
3034# have that functionality compiled, we needn't bother.
3035
3036$dlfunc_deleted = 0;
3037if (defined $parm_support{'Expand_dlfunc'} && !-e "bin/loaded")
3038 {
3039 delete $parm_support{'Expand_dlfunc'};
3040 $dlfunc_deleted = 1;
3041 }
3042
3043
3044##################################################
3045# Find environmental details #
3046##################################################
3047
3048# Find the caller of this program.
3049
3050($parm_caller,$pwpw,$parm_caller_uid,$parm_caller_gid,$pwquota,$pwcomm,
eeeda78a 3051 $parm_caller_gecos, $parm_caller_home) = getpwuid($>);
151b83f8
PH
3052
3053$pwpw = $pwpw; # Kill Perl warnings
3054$pwquota = $pwquota;
3055$pwcomm = $pwcomm;
151b83f8
PH
3056
3057$parm_caller_group = getgrgid($parm_caller_gid);
3058
42ec9880 3059print "Program caller is $parm_caller ($parm_caller_uid), whose group is $parm_caller_group ($parm_caller_gid)\n";
151b83f8
PH
3060print "Home directory is $parm_caller_home\n";
3061
5f122889
PP
3062unless (defined $parm_eximgroup)
3063 {
3064 print "Unable to derive \$parm_eximgroup.\n";
3065 die "** ABANDONING.\n";
3066 }
3067
151b83f8
PH
3068print "You need to be in the Exim group to run these tests. Checking ...";
3069
3070if (`groups` =~ /\b\Q$parm_eximgroup\E\b/)
3071 {
3072 print " OK\n";
3073 }
3074else
3075 {
3076 print "\nOh dear, you are not in the Exim group.\n";
3077 die "** Testing abandoned.\n";
3078 }
3079
3080# Find this host's IP addresses - there may be many, of course, but we keep
3081# one of each type (IPv4 and IPv6).
3082
bb660b56
HSHR
3083open(IFCONFIG, '-|', (grep { -x "$_/ip" } split /:/, $ENV{PATH}) ? 'ip address' : 'ifconfig -a')
3084 or die "** Cannot run 'ip address' or 'ifconfig -a'\n";
d63a9563 3085while (not ($parm_ipv4 and $parm_ipv6) and defined($_ = <IFCONFIG>))
151b83f8 3086 {
8bcf5607 3087 if (not $parm_ipv4 and /^\s*inet(?:\saddr)?:?\s?(\d+\.\d+\.\d+\.\d+)(?:\/\d+)?\s/i)
151b83f8 3088 {
d63a9563
HSHR
3089 next if $1 =~ /^(?:127|10)\./;
3090 $parm_ipv4 = $1;
151b83f8
PH
3091 }
3092
d63a9563 3093 if (not $parm_ipv6 and /^\s*inet6(?:\saddr)?:?\s?([abcdef\d:]+)(?:\/\d+)/i)
151b83f8 3094 {
d63a9563
HSHR
3095 next if $1 eq '::1' or $1 =~ /^fe80/i;
3096 $parm_ipv6 = $1;
151b83f8
PH
3097 }
3098 }
3099close(IFCONFIG);
3100
3101# Use private IP addresses if there are no public ones.
3102
151b83f8
PH
3103# If either type of IP address is missing, we need to set the value to
3104# something other than empty, because that wrecks the substitutions. The value
3105# is reflected, so use a meaningful string. Set appropriate options for the
3106# "server" command. In practice, however, many tests assume 127.0.0.1 is
3107# available, so things will go wrong if there is no IPv4 address. The lack
3108# of IPV4 or IPv6 can be simulated by command options, which force $have_ipv4
3109# and $have_ipv6 false.
3110
d63a9563 3111if (not $parm_ipv4)
151b83f8
PH
3112 {
3113 $have_ipv4 = 0;
3114 $parm_ipv4 = "<no IPv4 address found>";
3115 $server_opts .= " -noipv4";
3116 }
3117elsif ($have_ipv4 == 0)
3118 {
3119 $parm_ipv4 = "<IPv4 testing disabled>";
3120 $server_opts .= " -noipv4";
3121 }
3122else
3123 {
3124 $parm_running{"IPv4"} = " ";
3125 }
3126
d63a9563 3127if (not $parm_ipv6)
151b83f8
PH
3128 {
3129 $have_ipv6 = 0;
3130 $parm_ipv6 = "<no IPv6 address found>";
3131 $server_opts .= " -noipv6";
3132 delete($parm_support{"IPv6"});
3133 }
3134elsif ($have_ipv6 == 0)
3135 {
3136 $parm_ipv6 = "<IPv6 testing disabled>";
3137 $server_opts .= " -noipv6";
3138 delete($parm_support{"IPv6"});
3139 }
3140elsif (!defined $parm_support{'IPv6'})
3141 {
3142 $have_ipv6 = 0;
3143 $parm_ipv6 = "<no IPv6 support in Exim binary>";
3144 $server_opts .= " -noipv6";
3145 }
3146else
3147 {
3148 $parm_running{"IPv6"} = " ";
3149 }
3150
3151print "IPv4 address is $parm_ipv4\n";
3152print "IPv6 address is $parm_ipv6\n";
3153
75758eeb
PH
3154# For munging test output, we need the reversed IP addresses.
3155
3156$parm_ipv4r = ($parm_ipv4 !~ /^\d/)? "" :
3157 join(".", reverse(split /\./, $parm_ipv4));
3158
1b781f48 3159$parm_ipv6r = $parm_ipv6; # Appropriate if not in use
75758eeb
PH
3160if ($parm_ipv6 =~ /^[\da-f]/)
3161 {
3162 my(@comps) = split /:/, $parm_ipv6;
3163 my(@nibbles);
3164 foreach $comp (@comps)
3165 {
3166 push @nibbles, sprintf("%lx", hex($comp) >> 8);
3167 push @nibbles, sprintf("%lx", hex($comp) & 0xff);
3168 }
3169 $parm_ipv6r = join(".", reverse(@nibbles));
3170 }
3171
151b83f8
PH
3172# Find the host name, fully qualified.
3173
3174chomp($temp = `hostname`);
d36e39d7 3175die "'hostname' didn't return anything\n" unless defined $temp and length $temp;
32c5107f
JH
3176if ($temp =~ /\./)
3177 {
3178 $parm_hostname = $temp;
3179 }
3180else
3181 {
3182 $parm_hostname = (gethostbyname($temp))[0];
3183 $parm_hostname = "no.host.name.found" unless defined $parm_hostname and length $parm_hostname;
3184 }
151b83f8
PH
3185print "Hostname is $parm_hostname\n";
3186
3187if ($parm_hostname !~ /\./)
3188 {
3189 print "\n*** Host name is not fully qualified: this may cause problems ***\n\n";
3190 }
3191
05e0ef26
TL
3192if ($parm_hostname =~ /[[:upper:]]/)
3193 {
3194 print "\n*** Host name has upper case characters: this may cause problems ***\n\n";
3195 }
3196
151b83f8
PH
3197
3198
3199##################################################
3200# Create a testing version of Exim #
3201##################################################
3202
3203# We want to be able to run Exim with a variety of configurations. Normally,
3204# the use of -C to change configuration causes Exim to give up its root
3205# privilege (unless the caller is exim or root). For these tests, we do not
3206# want this to happen. Also, we want Exim to know that it is running in its
3207# test harness.
3208
3209# We achieve this by copying the binary and patching it as we go. The new
3210# binary knows it is a testing copy, and it allows -C and -D without loss of
3211# privilege. Clearly, this file is dangerous to have lying around on systems
3212# where there are general users with login accounts. To protect against this,
3213# we put the new binary in a special directory that is accessible only to the
3214# caller of this script, who is known to have sudo root privilege from the test
3215# that was done above. Furthermore, we ensure that the binary is deleted at the
3216# end of the test. First ensure the directory exists.
3217
3218if (-d "eximdir")
3219 { unlink "eximdir/exim"; } # Just in case
3220else
3221 {
3222 mkdir("eximdir", 0710) || die "** Unable to mkdir $parm_cwd/eximdir: $!\n";
3223 system("sudo chgrp $parm_eximgroup eximdir");
3224 }
3225
3226# The construction of the patched binary must be done as root, so we use
3227# a separate script. As well as indicating that this is a test-harness binary,
3228# the version number is patched to "x.yz" so that its length is always the
3229# same. Otherwise, when it appears in Received: headers, it affects the length
3230# of the message, which breaks certain comparisons.
3231
3232die "** Unable to make patched exim: $!\n"
3233 if (system("sudo ./patchexim $parm_exim") != 0);
3234
3235# From this point on, exits from the program must go via the subroutine
3236# tests_exit(), so that suitable cleaning up can be done when required.
3237# Arrange to catch interrupting signals, to assist with this.
3238
3239$SIG{'INT'} = \&inthandler;
3240$SIG{'PIPE'} = \&pipehandler;
3241
3242# For some tests, we need another copy of the binary that is setuid exim rather
3243# than root.
3244
3245system("sudo cp eximdir/exim eximdir/exim_exim;" .
3246 "sudo chown $parm_eximuser eximdir/exim_exim;" .
3247 "sudo chgrp $parm_eximgroup eximdir/exim_exim;" .
3248 "sudo chmod 06755 eximdir/exim_exim");
3249
3250
3251##################################################
3252# Make copies of utilities we might need #
3253##################################################
3254
3255# Certain of the tests make use of some of Exim's utilities. We do not need
3256# to be root to copy these.
3257
1ca9f507 3258($parm_exim_dir) = $parm_exim =~ m?^(.*)/exim?;
151b83f8
PH
3259
3260$dbm_build_deleted = 0;
3261if (defined $parm_lookups{'dbm'} &&
3262 system("cp $parm_exim_dir/exim_dbmbuild eximdir") != 0)
3263 {
3264 delete $parm_lookups{'dbm'};
3265 $dbm_build_deleted = 1;
3266 }
3267
3268if (system("cp $parm_exim_dir/exim_dumpdb eximdir") != 0)
3269 {
3270 tests_exit(-1, "Failed to make a copy of exim_dumpdb: $!");
3271 }
3272
3273if (system("cp $parm_exim_dir/exim_lock eximdir") != 0)
3274 {
3275 tests_exit(-1, "Failed to make a copy of exim_lock: $!");
3276 }
3277
3278if (system("cp $parm_exim_dir/exinext eximdir") != 0)
3279 {
3280 tests_exit(-1, "Failed to make a copy of exinext: $!");
3281 }
3282
f3f065bb
PH
3283if (system("cp $parm_exim_dir/exigrep eximdir") != 0)
3284 {
3285 tests_exit(-1, "Failed to make a copy of exigrep: $!");
3286 }
3287
3288if (system("cp $parm_exim_dir/eximstats eximdir") != 0)
3289 {
3290 tests_exit(-1, "Failed to make a copy of eximstats: $!");
3291 }
3292
151b83f8
PH
3293
3294##################################################
3295# Check that the Exim user can access stuff #
3296##################################################
3297
3298# We delay this test till here so that we can check access to the actual test
3299# binary. This will be needed when Exim re-exec's itself to do deliveries.
3300
3301print "Exim user is $parm_eximuser ($parm_exim_uid)\n";
3302print "Exim group is $parm_eximgroup ($parm_exim_gid)\n";
a56f166d
JJ
3303
3304if ($parm_caller_uid eq $parm_exim_uid) {
3305 tests_exit(-1, "Exim user ($parm_eximuser,$parm_exim_uid) cannot be "
3306 ."the same as caller ($parm_caller,$parm_caller_uid)");
3307}
b43517ed
JH
3308if ($parm_caller_gid eq $parm_exim_gid) {
3309 tests_exit(-1, "Exim group ($parm_eximgroup,$parm_exim_gid) cannot be "
3310 ."the same as caller's ($parm_caller) group as it confuses "
3311 ."results analysis");
3312}
a56f166d 3313
151b83f8
PH
3314print "The Exim user needs access to the test suite directory. Checking ...";
3315
3316if (($rc = system("sudo bin/checkaccess $parm_cwd/eximdir/exim $parm_eximuser $parm_eximgroup")) != 0)
3317 {
3318 my($why) = "unknown failure $rc";
3319 $rc >>= 8;
3320 $why = "Couldn't find user \"$parm_eximuser\"" if $rc == 1;
3321 $why = "Couldn't find group \"$parm_eximgroup\"" if $rc == 2;
3322 $why = "Couldn't read auxiliary group list" if $rc == 3;
3323 $why = "Couldn't get rid of auxiliary groups" if $rc == 4;
3324 $why = "Couldn't set gid" if $rc == 5;
3325 $why = "Couldn't set uid" if $rc == 6;
3326 $why = "Couldn't open \"$parm_cwd/eximdir/exim\"" if $rc == 7;
3327 print "\n** $why\n";
3328 tests_exit(-1, "$parm_eximuser cannot access the test suite directory");
3329 }
3330else
3331 {
3332 print " OK\n";
3333 }
3334
3335
3336##################################################
3337# Create a list of available tests #
3338##################################################
3339
3340# The scripts directory contains a number of subdirectories whose names are
3341# of the form 0000-xxxx, 1100-xxxx, 2000-xxxx, etc. Each set of tests apart
3342# from the first requires certain optional features to be included in the Exim
3343# binary. These requirements are contained in a file called "REQUIRES" within
3344# the directory. We scan all these tests, discarding those that cannot be run
3345# because the current binary does not support the right facilities, and also
3346# those that are outside the numerical range selected.
3347
28e8a0f7 3348print "\nTest range is $test_start to $test_end (flavour $flavour)\n";
151b83f8
PH
3349print "Omitting \${dlfunc expansion tests (loadable module not present)\n"
3350 if $dlfunc_deleted;
3351print "Omitting dbm tests (unable to copy exim_dbmbuild)\n"
3352 if $dbm_build_deleted;
3353
3354opendir(DIR, "scripts") || tests_exit(-1, "Failed to opendir(\"scripts\"): $!");
3355@test_dirs = sort readdir(DIR);
3356closedir(DIR);
3357
9e146c9f
PH
3358# Remove . and .. and CVS from the list.
3359
3360for ($i = 0; $i < @test_dirs; $i++)
3361 {
3362 my($d) = $test_dirs[$i];
3363 if ($d eq "." || $d eq ".." || $d eq "CVS")
3364 {
3365 splice @test_dirs, $i, 1;
3366 $i--;
3367 }
3368 }
3369
3370# Scan for relevant tests
3371
151b83f8
PH
3372for ($i = 0; $i < @test_dirs; $i++)
3373 {
3374 my($testdir) = $test_dirs[$i];
3375 my($wantthis) = 1;
3376
151b83f8
PH
3377 print ">>Checking $testdir\n" if $debug;
3378
3379 # Skip this directory if the first test is equal or greater than the first
3380 # test in the next directory.
3381
3382 next if ($i < @test_dirs - 1) &&
3383 ($test_start >= substr($test_dirs[$i+1], 0, 4));
3384
3385 # No need to carry on if the end test is less than the first test in this
3386 # subdirectory.
3387
3388 last if $test_end < substr($testdir, 0, 4);
3389
3390 # Check requirements, if any.
3391
3392 if (open(REQUIRES, "scripts/$testdir/REQUIRES"))
3393 {
3394 while (<REQUIRES>)
3395 {
3396 next if /^\s*$/;
3397 s/\s+$//;
3398 if (/^support (.*)$/)
3399 {
3400 if (!defined $parm_support{$1}) { $wantthis = 0; last; }
3401 }
3402 elsif (/^running (.*)$/)
3403 {
3404 if (!defined $parm_running{$1}) { $wantthis = 0; last; }
3405 }
3406 elsif (/^lookup (.*)$/)
3407 {
3408 if (!defined $parm_lookups{$1}) { $wantthis = 0; last; }
3409 }
3410 elsif (/^authenticators? (.*)$/)
3411 {
3412 if (!defined $parm_authenticators{$1}) { $wantthis = 0; last; }
3413 }
3414 elsif (/^router (.*)$/)
3415 {
3416 if (!defined $parm_routers{$1}) { $wantthis = 0; last; }
3417 }
3418 elsif (/^transport (.*)$/)
3419 {
3420 if (!defined $parm_transports{$1}) { $wantthis = 0; last; }
3421 }
3422 else
3423 {
3424 tests_exit(-1, "Unknown line in \"scripts/$testdir/REQUIRES\": \"$_\"");
3425 }
3426 }
3427 close(REQUIRES);
3428 }
3429 else
3430 {
3431 tests_exit(-1, "Failed to open \"scripts/$testdir/REQUIRES\": $!")
3432 unless $!{ENOENT};
3433 }
3434
3435 # Loop if we do not want the tests in this subdirectory.
3436
3437 if (!$wantthis)
3438 {
3439 chomp;
3440 print "Omitting tests in $testdir (missing $_)\n";
3441 next;
3442 }
3443
3444 # We want the tests from this subdirectory, provided they are in the
3445 # range that was selected.
3446
3447 opendir(SUBDIR, "scripts/$testdir") ||
3448 tests_exit(-1, "Failed to opendir(\"scripts/$testdir\"): $!");
3449 @testlist = sort readdir(SUBDIR);
3450 close(SUBDIR);
3451
3452 foreach $test (@testlist)
3453 {
28e8a0f7 3454 next if $test !~ /^\d{4}(?:\.\d+)?$/;
151b83f8
PH
3455 next if $test < $test_start || $test > $test_end;
3456 push @test_list, "$testdir/$test";
3457 }
3458 }
3459
3460print ">>Test List: @test_list\n", if $debug;
3461
3462
3463##################################################
3464# Munge variable auxiliary data #
3465##################################################
3466
3467# Some of the auxiliary data files have to refer to the current testing
3468# directory and other parameter data. The generic versions of these files are
3469# stored in the aux-var-src directory. At this point, we copy each of them
3470# to the aux-var directory, making appropriate substitutions. There aren't very
3471# many of them, so it's easiest just to do this every time. Ensure the mode
3472# is standardized, as this path is used as a test for the ${stat: expansion.
3473
3474# A similar job has to be done for the files in the dnszones-src directory, to
3475# make the fake DNS zones for testing. Most of the zone files are copied to
3476# files of the same name, but db.ipv4.V4NET and db.ipv6.V6NET use the testing
3477# networks that are defined by parameter.
3478
3479foreach $basedir ("aux-var", "dnszones")
3480 {
3481 system("sudo rm -rf $parm_cwd/$basedir");
3482 mkdir("$parm_cwd/$basedir", 0777);
3483 chmod(0755, "$parm_cwd/$basedir");
3484
3485 opendir(AUX, "$parm_cwd/$basedir-src") ||
3486 tests_exit(-1, "Failed to opendir $parm_cwd/$basedir-src: $!");
3487 my(@filelist) = readdir(AUX);
3488 close(AUX);
3489
3490 foreach $file (@filelist)
3491 {
3492 my($outfile) = $file;
3493 next if $file =~ /^\./;
3494
3495 if ($file eq "db.ip4.V4NET")
3496 {
3497 $outfile = "db.ip4.$parm_ipv4_test_net";
3498 }
3499 elsif ($file eq "db.ip6.V6NET")
3500 {
3501 my(@nibbles) = reverse(split /\s*/, $parm_ipv6_test_net);
3502 $" = '.';
3503 $outfile = "db.ip6.@nibbles";
3504 $" = ' ';
3505 }
3506
3507 print ">>Copying $basedir-src/$file to $basedir/$outfile\n" if $debug;
3508 open(IN, "$parm_cwd/$basedir-src/$file") ||
3509 tests_exit(-1, "Failed to open $parm_cwd/$basedir-src/$file: $!");
3510 open(OUT, ">$parm_cwd/$basedir/$outfile") ||
3511 tests_exit(-1, "Failed to open $parm_cwd/$basedir/$outfile: $!");
3512 while (<IN>)
3513 {
3514 do_substitute(0);
3515 print OUT;
3516 }
3517 close(IN);
3518 close(OUT);
3519 }
3520 }
3521
d40f27c3
JH
3522# Set a user's shell, distinguishable from /bin/sh
3523
3524symlink("/bin/sh","aux-var/sh");
3525$ENV{'SHELL'} = $parm_shell = $parm_cwd . "/aux-var/sh";
151b83f8
PH
3526
3527##################################################
3528# Create fake DNS zones for this host #
3529##################################################
3530
3531# There are fixed zone files for 127.0.0.1 and ::1, but we also want to be
3532# sure that there are forward and reverse registrations for this host, using
3533# its real IP addresses. Dynamically created zone files achieve this.
3534
3535if ($have_ipv4 || $have_ipv6)
3536 {
3537 my($shortname,$domain) = $parm_hostname =~ /^([^.]+)(.*)/;
3538 open(OUT, ">$parm_cwd/dnszones/db$domain") ||
3539 tests_exit(-1, "Failed to open $parm_cwd/dnszones/db$domain: $!");
3540 print OUT "; This is a dynamically constructed fake zone file.\n" .
3541 "; The following line causes fakens to return PASS_ON\n" .
3542 "; for queries that it cannot answer\n\n" .
3543 "PASS ON NOT FOUND\n\n";
3544 print OUT "$shortname A $parm_ipv4\n" if $have_ipv4;
3545 print OUT "$shortname AAAA $parm_ipv6\n" if $have_ipv6;
3546 print OUT "\n; End\n";
3547 close(OUT);
3548 }
3549
3550if ($have_ipv4 && $parm_ipv4 ne "127.0.0.1")
3551 {
3552 my(@components) = $parm_ipv4 =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)/;
3553 open(OUT, ">$parm_cwd/dnszones/db.ip4.$components[0]") ||
3554 tests_exit(-1,
3555 "Failed to open $parm_cwd/dnszones/db.ip4.$components[0]: $!");
3556 print OUT "; This is a dynamically constructed fake zone file.\n" .
3557 "; The zone is $components[0].in-addr.arpa.\n\n" .
3558 "$components[3].$components[2].$components[1] PTR $parm_hostname.\n\n" .
3559 "; End\n";
3560 close(OUT);
3561 }
3562
3563if ($have_ipv6 && $parm_ipv6 ne "::1")
3564 {
6f99d4d9
JH
3565 my($exp_v6) = $parm_ipv6;
3566 $exp_v6 =~ s/[^:]//g;
3567 if ( $parm_ipv6 =~ /^([^:].+)::$/ ) {
3568 $exp_v6 = $1 . ':0' x (9-length($exp_v6));
3569 } elsif ( $parm_ipv6 =~ /^(.+)::(.+)$/ ) {
3570 $exp_v6 = $1 . ':0' x (8-length($exp_v6)) . ':' . $2;
3571 } elsif ( $parm_ipv6 =~ /^::(.+[^:])$/ ) {
3572 $exp_v6 = '0:' x (9-length($exp_v6)) . $1;
d37842eb
TL
3573 } else {
3574 $exp_v6 = $parm_ipv6;
6f99d4d9
JH
3575 }
3576 my(@components) = split /:/, $exp_v6;
151b83f8
PH
3577 my(@nibbles) = reverse (split /\s*/, shift @components);
3578 my($sep) = "";
3579
3580 $" = ".";
3581 open(OUT, ">$parm_cwd/dnszones/db.ip6.@nibbles") ||
3582 tests_exit(-1,
3583 "Failed to open $parm_cwd/dnszones/db.ip6.@nibbles: $!");
3584 print OUT "; This is a dynamically constructed fake zone file.\n" .
3585 "; The zone is @nibbles.ip6.arpa.\n\n";
3586
3587 @components = reverse @components;
3588 foreach $c (@components)
3589 {
3590 $c = "0$c" until $c =~ /^..../;
3591 @nibbles = reverse(split /\s*/, $c);
3592 print OUT "$sep@nibbles";
3593 $sep = ".";
3594 }
3595
3596 print OUT " PTR $parm_hostname.\n\n; End\n";
3597 close(OUT);
3598 $" = " ";
3599 }
3600
3601
3602
3603##################################################
3604# Create lists of mailboxes and message logs #
3605##################################################
3606
3607# We use these lists to check that a test has created the expected files. It
3608# should be faster than looking for the file each time. For mailboxes, we have
3609# to scan a complete subtree, in order to handle maildirs. For msglogs, there
3610# is just a flat list of files.
3611
3612@oldmails = list_files_below("mail");
3613opendir(DIR, "msglog") || tests_exit(-1, "Failed to opendir msglog: $!");
3614@oldmsglogs = readdir(DIR);
3615closedir(DIR);
3616
3617
3618
3619##################################################
3620# Run the required tests #
3621##################################################
3622
3623# Each test script contains a number of tests, separated by a line that
3624# contains ****. We open input from the terminal so that we can read responses
3625# to prompts.
3626
0b9ead6d
HSHR
3627if (not $force_continue) {
3628 # runtest needs to interact if we're not in continue
3629 # mode. It does so by communicate to /dev/tty
3630 open(T, "/dev/tty") or tests_exit(-1, "Failed to open /dev/tty: $!");
3631}
3632
151b83f8
PH
3633
3634print "\nPress RETURN to run the tests: ";
efede112 3635$_ = $force_continue ? "c" : <T>;
151b83f8
PH
3636print "\n";
3637
3638$lasttestdir = "";
3639
3640foreach $test (@test_list)
3641 {
3642 local($lineno) = 0;
3643 local($commandno) = 0;
3644 local($subtestno) = 0;
28e8a0f7 3645 (local $testno = $test) =~ s|.*/||;
151b83f8
PH
3646 local($sortlog) = 0;
3647
3648 my($gnutls) = 0;
3649 my($docheck) = 1;
3650 my($thistestdir) = substr($test, 0, -5);
3651
df613eb4
HSHR
3652 $dynamic_socket->close() if $dynamic_socket;
3653
151b83f8
PH
3654 if ($lasttestdir ne $thistestdir)
3655 {
3656 $gnutls = 0;
3657 if (-s "scripts/$thistestdir/REQUIRES")
3658 {
3659 my($indent) = "";
3660 print "\n>>> The following tests require: ";
3661 open(IN, "scripts/$thistestdir/REQUIRES") ||
3662 tests_exit(-1, "Failed to open scripts/$thistestdir/REQUIRES: $1");
3663 while (<IN>)
3664 {
3665 $gnutls = 1 if /^support GnuTLS/;
3666 print $indent, $_;
3667 $indent = ">>> ";
3668 }
3669 close(IN);
3670 }
3671 }
3672 $lasttestdir = $thistestdir;
3673
3674 # Remove any debris in the spool directory and the test-mail directory
3675 # and also the files for collecting stdout and stderr. Then put back
3676 # the test-mail directory for appendfile deliveries.
3677
3678 system "sudo /bin/rm -rf spool test-*";
3679 system "mkdir test-mail 2>/dev/null";
3680
3681 # A privileged Exim will normally make its own spool directory, but some of
3682 # the tests run in unprivileged modes that don't always work if the spool
3683 # directory isn't already there. What is more, we want anybody to be able
3684 # to read it in order to find the daemon's pid.
3685
3686 system "mkdir spool; " .
3687 "sudo chown $parm_eximuser:$parm_eximgroup spool; " .
3688 "sudo chmod 0755 spool";
3689
3690 # Empty the cache that keeps track of things like message id mappings, and
3691 # set up the initial sequence strings.
3692
3693 undef %cache;
3694 $next_msgid = "aX";
f3f065bb 3695 $next_pid = 1234;
151b83f8
PH
3696 $next_port = 1111;
3697 $message_skip = 0;
3698 $msglog_skip = 0;
3699 $stderr_skip = 0;
3700 $stdout_skip = 0;
3701 $rmfiltertest = 0;
3702 $is_ipv6test = 0;
ac9a0d91 3703 $TEST_STATE->{munge} = "";
151b83f8
PH
3704
3705 # Remove the associative arrays used to hold checked mail files and msglogs
3706
3707 undef %expected_mails;
3708 undef %expected_msglogs;
3709
3710 # Open the test's script
151b83f8
PH
3711 open(SCRIPT, "scripts/$test") ||
3712 tests_exit(-1, "Failed to open \"scripts/$test\": $!");
770feb2f
TL
3713 # Run through the script once to set variables which should be global
3714 while (<SCRIPT>)
3715 {
3716 if (/^no_message_check/) { $message_skip = 1; next; }
3717 if (/^no_msglog_check/) { $msglog_skip = 1; next; }
3718 if (/^no_stderr_check/) { $stderr_skip = 1; next; }
3719 if (/^no_stdout_check/) { $stdout_skip = 1; next; }
3720 if (/^rmfiltertest/) { $rmfiltertest = 1; next; }
3721 if (/^sortlog/) { $sortlog = 1; next; }
df613eb4
HSHR
3722 if (/\bPORT_DYNAMIC\b/) {
3723 for (my $port = 1024; $port < 65000; $port++) {
3724 $dynamic_socket = IO::Socket::INET->new(
3725 LocalHost => '127.0.0.1',
3726 LocalPort => $port,
3727 Listen => 10,
3728 ReuseAddr => 1,
3729 ) and last;
3730 }
3731 }
770feb2f
TL
3732 }
3733 # Reset to beginning of file for per test interpreting/processing
3734 seek(SCRIPT, 0, 0);
151b83f8
PH
3735
3736 # The first line in the script must be a comment that is used to identify
3737 # the set of tests as a whole.
3738
3739 $_ = <SCRIPT>;
3740 $lineno++;
3741 tests_exit(-1, "Missing identifying comment at start of $test") if (!/^#/);
3742 printf("%s %s", (substr $test, 5), (substr $_, 2));
3743
3744 # Loop for each of the subtests within the script. The variable $server_pid
3745 # is used to remember the pid of a "server" process, for which we do not
3746 # wait until we have waited for a subsequent command.
3747
3748 local($server_pid) = 0;
3749 for ($commandno = 1; !eof SCRIPT; $commandno++)
3750 {
3751 # Skip further leading comments and blank lines, handle the flag setting
3752 # commands, and deal with tests for IP support.
3753
3754 while (<SCRIPT>)
3755 {
3756 $lineno++;
770feb2f
TL
3757 # Could remove these variable settings because they are already
3758 # set above, but doesn't hurt to leave them here.
151b83f8
PH
3759 if (/^no_message_check/) { $message_skip = 1; next; }
3760 if (/^no_msglog_check/) { $msglog_skip = 1; next; }
3761 if (/^no_stderr_check/) { $stderr_skip = 1; next; }
3762 if (/^no_stdout_check/) { $stdout_skip = 1; next; }
3763 if (/^rmfiltertest/) { $rmfiltertest = 1; next; }
3764 if (/^sortlog/) { $sortlog = 1; next; }
3765
21c28500
PH
3766 if (/^need_largefiles/)
3767 {
3768 next if $have_largefiles;
3769 print ">>> Large file support is needed for test $testno, but is not available: skipping\n";
3770 $docheck = 0; # don't check output
3771 undef $_; # pretend EOF
3772 last;
3773 }
3774
151b83f8
PH
3775 if (/^need_ipv4/)
3776 {
3777 next if $have_ipv4;
3778 print ">>> IPv4 is needed for test $testno, but is not available: skipping\n";
3779 $docheck = 0; # don't check output
3780 undef $_; # pretend EOF
3781 last;
3782 }
3783
3784 if (/^need_ipv6/)
3785 {
3786 if ($have_ipv6)
3787 {
3788 $is_ipv6test = 1;
3789 next;
3790 }
3791 print ">>> IPv6 is needed for test $testno, but is not available: skipping\n";
3792 $docheck = 0; # don't check output
3793 undef $_; # pretend EOF
3794 last;
3795 }
3796
3797 if (/^need_move_frozen_messages/)
3798 {
3799 next if defined $parm_support{"move_frozen_messages"};
3800 print ">>> move frozen message support is needed for test $testno, " .
3801 "but is not\n>>> available: skipping\n";
3802 $docheck = 0; # don't check output
3803 undef $_; # pretend EOF
3804 last;
3805 }
3806
3807 last unless /^(#|\s*$)/;
3808 }
3809 last if !defined $_; # Hit EOF
3810
3811 my($subtest_startline) = $lineno;
3812
59eaad2b
JH
3813 # Now run the command. The function returns 0 for an inline command,
3814 # 1 if a non-exim command was run and waited for, 2 if an exim
3815 # command was run and waited for, and 3 if a command
151b83f8
PH
3816 # was run and not waited for (usually a daemon or server startup).
3817
3818 my($commandname) = "";
3819 my($expectrc) = 0;
1ca9f507 3820 my($rc, $run_extra) = run_command($testno, \$subtestno, \$expectrc, \$commandname, $TEST_STATE);
151b83f8
PH
3821 my($cmdrc) = $?;
3822
f41e0506
JH
3823$0 = "[runtest $testno]";
3824
1ca9f507
PP
3825 if ($debug) {
3826 print ">> rc=$rc cmdrc=$cmdrc\n";
3827 if (defined $run_extra) {
3828 foreach my $k (keys %$run_extra) {
3829 my $v = defined $run_extra->{$k} ? qq!"$run_extra->{$k}"! : '<undef>';
3830 print ">> $k -> $v\n";
3831 }
3832 }
3833 }
3834 $run_extra = {} unless defined $run_extra;
3835 foreach my $k (keys %$run_extra) {
3836 if (exists $TEST_STATE->{$k}) {
3837 my $nv = defined $run_extra->{$k} ? qq!"$run_extra->{$k}"! : 'removed';
3838 print ">> override of $k; was $TEST_STATE->{$k}, now $nv\