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