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