s4: Re-add --ldapadminpass as an option to provision
[ira/wip.git] / selftest / target / Samba4.pm
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
5
6 package Samba4;
7
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12
13 sub new($$$$$) {
14         my ($classname, $bindir, $ldap, $setupdir, $exeext) = @_;
15         $exeext = "" unless defined($exeext);
16         my $self = { 
17                 vars => {}, 
18                 ldap => $ldap, 
19                 bindir => $bindir, 
20                 setupdir => $setupdir,
21                 exeext => $exeext
22         };
23         bless $self;
24         return $self;
25 }
26
27 sub bindir_path($$) {
28         my ($self, $path) = @_;
29
30         return "$self->{bindir}/$path$self->{exeext}";
31 }
32
33 sub openldap_start($$$) {
34 }
35
36 sub slapd_start($$)
37 {
38         my $count = 0;
39         my ($self, $env_vars) = @_;
40
41         my $uri = $env_vars->{LDAP_URI};
42
43         # running slapd in the background means it stays in the same process group, so it can be
44         # killed by timelimit
45         if ($self->{ldap} eq "fedora-ds") {
46                 system("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd -D $env_vars->{FEDORA_DS_DIR} -d0 -i $env_vars->{FEDORA_DS_PIDFILE}> $env_vars->{LDAPDIR}/logs 2>&1 &");
47         } elsif ($self->{ldap} eq "openldap") {
48                 system("$ENV{OPENLDAP_SLAPD} -d0 -F $env_vars->{SLAPD_CONF_D} -h $uri > $env_vars->{LDAPDIR}/logs 2>&1 &");
49         }
50         my $ldbsearch = $self->bindir_path("ldbsearch");
51         while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
52                 $count++;
53                 if ($count > 40) {
54                     $self->slapd_stop($env_vars);
55                     return 0;
56                 }
57                 sleep(1);
58         }
59         return 1;
60 }
61
62 sub slapd_stop($$)
63 {
64         my ($self, $envvars) = @_;
65         if ($self->{ldap} eq "fedora-ds") {
66                 system("$envvars->{LDAPDIR}/slapd-samba4/stop-slapd");
67         } elsif ($self->{ldap} eq "openldap") {
68                 open(IN, "<$envvars->{OPENLDAP_PIDFILE}") or 
69                         die("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
70                 kill 9, <IN>;
71                 close(IN);
72         }
73         return 1;
74 }
75
76 sub check_or_start($$$) 
77 {
78         my ($self, $env_vars, $max_time) = @_;
79         return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
80
81         unlink($env_vars->{SAMBA_TEST_FIFO});
82         POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
83         unlink($env_vars->{SAMBA_TEST_LOG});
84         
85         print "STARTING SAMBA... ";
86         my $pid = fork();
87         if ($pid == 0) {
88                 open STDIN, $env_vars->{SAMBA_TEST_FIFO};
89                 # we want out from samba to go to the log file, but also
90                 # to the users terminal when running 'make test' on the command
91                 # line. This puts it on stderr on the terminal
92                 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
93                 open STDERR, '>&STDOUT';
94
95                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
96
97                 my $valgrind = "";
98                 if (defined($ENV{SAMBA_VALGRIND})) {
99                     $valgrind = $ENV{SAMBA_VALGRIND};
100                 } 
101
102                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG}; 
103                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
104
105                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
106                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
107
108                 $ENV{UID_WRAPPER} = "1";
109
110                 # Start slapd before samba, but with the fifo on stdin
111                 if (defined($self->{ldap})) {
112                     $self->slapd_start($env_vars) or 
113                         die("couldn't start slapd (main run)");
114                 }
115
116                 my $optarg = "";
117                 if (defined($max_time)) {
118                         $optarg = "--maximum-runtime=$max_time ";
119                 }
120                 if (defined($ENV{SAMBA_OPTIONS})) {
121                         $optarg.= " $ENV{SAMBA_OPTIONS}";
122                 }
123                 my $samba = $self->bindir_path("samba");
124
125                 # allow selection of the process model using
126                 # the environment varibale SAMBA_PROCESS_MODEL
127                 # that allows us to change the process model for 
128                 # individual machines in the build farm
129                 my $model = "single";
130                 if (defined($ENV{SAMBA_PROCESS_MODEL})) {
131                         $model = $ENV{SAMBA_PROCESS_MODEL};
132                 }
133                 my $ret = system("$valgrind $samba $optarg $env_vars->{CONFIGURATION} -M $model -i");
134                 if ($? == -1) {
135                         print "Unable to start $samba: $ret: $!\n";
136                         exit 1;
137                 }
138                 unlink($env_vars->{SAMBA_TEST_FIFO});
139                 my $exit = $? >> 8;
140                 if ( $ret == 0 ) {
141                         print "$samba exits with status $exit\n";
142                 } elsif ( $ret & 127 ) {
143                         print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
144                 } else {
145                         $ret = $? >> 8;
146                         print "$samba failed with status $exit!\n";
147                 }
148                 exit $exit;
149         }
150         print "DONE\n";
151
152         open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
153
154         return $pid;
155 }
156
157 sub wait_for_start($$)
158 {
159         my ($self, $testenv_vars) = @_;
160         # give time for nbt server to register its names
161         print "delaying for nbt name registration\n";
162         sleep 2;
163
164         # This will return quickly when things are up, but be slow if we 
165         # need to wait for (eg) SSL init 
166         my $nmblookup = $self->bindir_path("nmblookup");
167         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
168         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
169         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
170         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
171         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
172         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
173         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
174         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
175         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
176         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
177         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
178         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
179
180         print $self->getlog_env($testenv_vars);
181 }
182
183 sub write_ldb_file($$$)
184 {
185         my ($self, $file, $ldif) = @_;
186
187         my $ldbadd = $self->bindir_path("ldbadd");
188         open(LDIF, "|$ldbadd -H $file >/dev/null");
189         print LDIF $ldif;
190         return close(LDIF);
191 }
192
193 sub add_wins_config($$)
194 {
195         my ($self, $privatedir) = @_;
196
197         return $self->write_ldb_file("$privatedir/wins_config.ldb", "
198 dn: name=TORTURE_6,CN=PARTNERS
199 objectClass: wreplPartner
200 name: TORTURE_6
201 address: 127.0.0.6
202 pullInterval: 0
203 pushChangeCount: 0
204 type: 0x3
205 ");
206 }
207
208 sub mk_fedora_ds($$)
209 {
210         my ($self, $ldapdir) = @_;
211
212         #Make the subdirectory be as fedora DS would expect
213         my $fedora_ds_dir = "$ldapdir/slapd-samba4";
214
215         my $pidfile = "$fedora_ds_dir/logs/slapd-samba4.pid";
216
217         return ($fedora_ds_dir, $pidfile);
218 }
219
220 sub mk_openldap($$)
221 {
222         my ($self, $ldapdir) = @_;
223
224         my $slapd_conf_d = "$ldapdir/slapd.d";
225         my $pidfile = "$ldapdir/slapd.pid";
226
227         return ($slapd_conf_d, $pidfile);
228 }
229
230 sub mk_keyblobs($$)
231 {
232         my ($self, $tlsdir) = @_;
233
234         #TLS and PKINIT crypto blobs
235         my $dhfile = "$tlsdir/dhparms.pem";
236         my $cafile = "$tlsdir/ca.pem";
237         my $certfile = "$tlsdir/cert.pem";
238         my $reqkdc = "$tlsdir/req-kdc.der";
239         my $kdccertfile = "$tlsdir/kdc.pem";
240         my $keyfile = "$tlsdir/key.pem";
241         my $adminkeyfile = "$tlsdir/adminkey.pem";
242         my $reqadmin = "$tlsdir/req-admin.der";
243         my $admincertfile = "$tlsdir/admincert.pem";
244         my $admincertupnfile = "$tlsdir/admincertupn.pem";
245
246         mkdir($tlsdir, 0777);
247
248         #This is specified here to avoid draining entropy on every run
249         open(DHFILE, ">$dhfile");
250         print DHFILE <<EOF;
251 -----BEGIN DH PARAMETERS-----
252 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
253 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
254 YX70obsCAQI=
255 -----END DH PARAMETERS-----
256 EOF
257         close(DHFILE);
258
259         #Likewise, we pregenerate the key material.  This allows the 
260         #other certificates to be pre-generated
261         open(KEYFILE, ">$keyfile");
262         print KEYFILE <<EOF;
263 -----BEGIN RSA PRIVATE KEY-----
264 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
265 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
266 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
267 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
268 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
269 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
270 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
271 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
272 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
273 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
274 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
275 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
276 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
277 -----END RSA PRIVATE KEY-----
278 EOF
279         close(KEYFILE);
280
281         open(ADMINKEYFILE, ">$adminkeyfile");
282
283         print ADMINKEYFILE <<EOF;
284 -----BEGIN RSA PRIVATE KEY-----
285 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
286 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
287 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
288 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
289 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
290 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
291 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
292 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
293 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
294 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
295 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
296 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
297 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
298 -----END RSA PRIVATE KEY-----
299 EOF
300
301         #generated with 
302         # hxtool issue-certificate --self-signed --issue-ca \
303         # --ca-private-key="FILE:$KEYFILE" \
304         # --subject="CN=CA,DC=samba,DC=example,DC=com" \
305         # --certificate="FILE:$CAFILE" --lifetime="25 years"
306
307         open(CAFILE, ">$cafile");
308         print CAFILE <<EOF;
309 -----BEGIN CERTIFICATE-----
310 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
311 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
312 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
313 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
314 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
315 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
316 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
317 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
318 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
319 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
320 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
321 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
322 -----END CERTIFICATE-----
323 EOF
324
325         #generated with GNUTLS internally in Samba.  
326
327         open(CERTFILE, ">$certfile");
328         print CERTFILE <<EOF;
329 -----BEGIN CERTIFICATE-----
330 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
331 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
332 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
333 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
334 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
335 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
336 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
337 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
338 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
339 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
340 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
341 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
342 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
343 -----END CERTIFICATE-----
344 EOF
345         close(CERTFILE);
346
347         #KDC certificate
348         # hxtool request-create \
349         # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
350         # --key="FILE:$KEYFILE" $KDCREQ
351
352         # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
353         # --type="pkinit-kdc" \
354         # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
355         # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
356         # --lifetime="25 years"
357
358         open(KDCCERTFILE, ">$kdccertfile");
359         print KDCCERTFILE <<EOF;
360 -----BEGIN CERTIFICATE-----
361 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
362 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
363 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
364 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
365 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
366 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
367 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
368 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
369 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
370 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
371 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
372 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
373 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
374 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
375 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
376 -----END CERTIFICATE-----
377 EOF
378
379         # hxtool request-create \
380         # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
381         # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
382
383         # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
384         # --type="pkinit-client" \
385         # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
386         # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
387         # --lifetime="25 years"
388         
389         open(ADMINCERTFILE, ">$admincertfile");
390         print ADMINCERTFILE <<EOF;
391 -----BEGIN CERTIFICATE-----
392 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
393 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
394 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
395 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
396 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
397 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
398 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
399 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
400 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
401 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
402 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
403 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
404 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
405 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
406 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
407 -----END CERTIFICATE-----
408 EOF
409         close(ADMINCERTFILE);
410
411         # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
412         # --type="pkinit-client" \
413         # --ms-upn="administrator@samba.example.com" \
414         # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
415         # --lifetime="25 years"
416         
417         open(ADMINCERTUPNFILE, ">$admincertupnfile");
418         print ADMINCERTUPNFILE <<EOF;
419 -----BEGIN CERTIFICATE-----
420 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
421 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
422 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
423 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
424 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
425 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
426 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
427 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
428 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
429 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
430 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
431 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
432 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
433 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
434 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
435 -----END CERTIFICATE-----
436 EOF
437 }
438
439 #
440 # provision_raw_prepare() is also used by Samba34.pm!
441 #
442 sub provision_raw_prepare($$$$$$$)
443 {
444         my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password, $kdc_ipv4) = @_;
445         my $ctx;
446
447         -d $prefix or mkdir($prefix, 0777) or die("Unable to create $prefix");
448         my $prefix_abs = abs_path($prefix);
449
450         die ("prefix=''") if $prefix_abs eq "";
451         die ("prefix='/'") if $prefix_abs eq "/";
452
453         (system("rm -rf $prefix_abs/*") == 0) or die("Unable to clean up");
454
455         $ctx->{prefix} = $prefix;
456         $ctx->{prefix_abs} = $prefix_abs;
457         $ctx->{server_role} = $server_role;
458         $ctx->{netbiosname} = $netbiosname;
459         $ctx->{netbiosalias} = $netbiosalias;
460         $ctx->{swiface} = $swiface;
461         $ctx->{password} = $password;
462         $ctx->{kdc_ipv4} = $kdc_ipv4;
463
464         $ctx->{server_loglevel} = 1;
465         $ctx->{username} = "Administrator";
466         $ctx->{domain} = "SAMBADOMAIN";
467         $ctx->{realm} = "SAMBA.EXAMPLE.COM";
468         $ctx->{dnsname} = "samba.example.com";
469         $ctx->{basedn} = "dc=samba,dc=example,dc=com";
470
471         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
472         chomp $unix_name;
473         $ctx->{unix_name} = $unix_name;
474         $ctx->{unix_uid} = $>;
475         $ctx->{unix_gids_str} = $);
476         @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
477
478         $ctx->{etcdir} = "$prefix_abs/etc";
479         $ctx->{piddir} = "$prefix_abs/pid";
480         $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
481         $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
482         $ctx->{privatedir} = "$prefix_abs/private";
483         $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
484         $ctx->{lockdir} = "$prefix_abs/lockdir";
485         $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
486         $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
487         $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
488         $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
489         $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
490
491         $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
492
493         $ctx->{ipv4} = "127.0.0.$swiface";
494         $ctx->{interfaces} = "$ctx->{ipv4}/8";
495
496         $ctx->{localbasedn} = $ctx->{basedn};
497         $ctx->{localbasedn} = "CN=$netbiosname" if $server_role eq "member server";
498
499         push(@{$ctx->{directories}}, $ctx->{privatedir});
500         push(@{$ctx->{directories}}, $ctx->{etcdir});
501         push(@{$ctx->{directories}}, $ctx->{piddir});
502         push(@{$ctx->{directories}}, $ctx->{ncalrpcdir});
503         push(@{$ctx->{directories}}, $ctx->{lockdir});
504
505         $ctx->{smb_conf_extra_options} = "";
506
507         my @provision_options = ();
508         push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
509         push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
510         if (defined($ENV{GDB_PROVISION})) {
511                 push (@provision_options, "gdb --args");
512         }
513         if (defined($ENV{VALGRIND_PROVISION})) {
514                 push (@provision_options, "valgrind");
515         }
516         if (defined($ENV{PYTHON})) {
517                 push (@provision_options, $ENV{PYTHON});
518         }
519         push (@provision_options, "$self->{setupdir}/provision");
520         push (@provision_options, "--configfile=$ctx->{smb_conf}");
521         push (@provision_options, "--host-name=$ctx->{netbiosname}");
522         push (@provision_options, "--host-ip=$ctx->{ipv4}");
523         push (@provision_options, "--quiet");
524         push (@provision_options, "--domain=$ctx->{domain}");
525         push (@provision_options, "--realm=$ctx->{realm}");
526         push (@provision_options, "--adminpass=$ctx->{password}");
527         push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
528         push (@provision_options, "--machinepass=machine$ctx->{password}");
529         push (@provision_options, "--root=$ctx->{unix_name}");
530         push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
531
532         @{$ctx->{provision_options}} = @provision_options;
533
534         return $ctx;
535 }
536
537 #
538 # provision_raw_step1() is also used by Samba34.pm!
539 #
540 # Step1 creates the basic configuration
541 #
542 sub provision_raw_step1($$)
543 {
544         my ($self, $ctx) = @_;
545
546         mkdir($_, 0777) foreach (@{$ctx->{directories}});
547
548         open(CONFFILE, ">$ctx->{smb_conf}")
549                 or die("can't open $ctx->{smb_conf}$?");
550         print CONFFILE "
551 [global]
552         netbios name = $ctx->{netbiosname}
553         netbios aliases = $ctx->{netbiosalias}
554         workgroup = $ctx->{domain}
555         realm = $ctx->{realm}
556         private dir = $ctx->{privatedir}
557         pid directory = $ctx->{piddir}
558         ncalrpc dir = $ctx->{ncalrpcdir}
559         lock dir = $ctx->{lockdir}
560         setup directory = $self->{setupdir}
561         modules dir = $self->{bindir}/modules
562         winbindd socket directory = $ctx->{winbindd_socket_dir}
563         winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
564         ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
565         winbind separator = /
566         name resolve order = bcast
567         interfaces = $ctx->{interfaces}
568         tls dh params file = $ctx->{tlsdir}/dhparms.pem
569         panic action = $RealBin/gdb_backtrace \%PID% \%PROG%
570         wins support = yes
571         server role = $ctx->{server_role}
572         notify:inotify = false
573         ldb:nosync = true
574 #We don't want to pass our self-tests if the PAC code is wrong
575         gensec:require_pac = true
576         log level = $ctx->{server_loglevel}
577         lanman auth = Yes
578
579         # Begin extra options
580         $ctx->{smb_conf_extra_options}
581         # End extra options
582 ";
583         close(CONFFILE);
584
585         $self->mk_keyblobs($ctx->{tlsdir});
586
587         open(KRB5CONF, ">$ctx->{krb5_conf}")
588                 or die("can't open $ctx->{krb5_conf}$?");
589         print KRB5CONF "
590 #Generated krb5.conf for $ctx->{realm}
591
592 [libdefaults]
593  default_realm = $ctx->{realm}
594  dns_lookup_realm = false
595  dns_lookup_kdc = false
596  ticket_lifetime = 24h
597  forwardable = yes
598
599 [realms]
600  $ctx->{realm} = {
601   kdc = $ctx->{kdc_ipv4}:88
602   admin_server = $ctx->{kdc_ipv4}:88
603   default_domain = $ctx->{dnsname}
604  }
605  $ctx->{dnsname} = {
606   kdc = $ctx->{kdc_ipv4}:88
607   admin_server = $ctx->{kdc_ipv4}:88
608   default_domain = $ctx->{dnsname}
609  }
610  $ctx->{domain} = {
611   kdc = $ctx->{kdc_ipv4}:88
612   admin_server = $ctx->{kdc_ipv4}:88
613   default_domain = $ctx->{dnsname}
614  }
615
616 [appdefaults]
617         pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
618
619 [kdc]
620         enable-pkinit = true
621         pkinit_identity = FILE:$ctx->{tlsdir}/kdc.pem,$ctx->{tlsdir}/key.pem
622         pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
623
624 [domain_realm]
625  .$ctx->{dnsname} = $ctx->{realm}
626 ";
627         close(KRB5CONF);
628
629         open(PWD, ">$ctx->{nsswrap_passwd}");
630         print PWD "
631 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
632 $ctx->{unix_name}:x:$ctx->{unix_uid}:@{$ctx->{unix_gids}}[0]:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
633 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
634 ";
635         close(PWD);
636
637         open(GRP, ">$ctx->{nsswrap_group}");
638         print GRP "
639 root:x:0:
640 wheel:x:10:
641 users:x:100:
642 nobody:x:65533:
643 nogroup:x:65534:nobody
644 ";
645         close(GRP);
646
647         my $configuration = "--configfile=$ctx->{smb_conf}";
648
649 #Ensure the config file is valid before we start
650         my $testparm = $self->bindir_path("testparm");
651         if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
652                 system("$testparm -v --suppress-prompt $configuration >&2");
653                 die("Failed to create a valid smb.conf configuration $testparm!");
654         }
655
656         (system("($testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$ctx->{netbiosname}\" ) >/dev/null 2>&1") == 0) or die("Failed to create a valid smb.conf configuration! $self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
657
658         my $ret = {
659                 KRB5_CONFIG => $ctx->{krb5_conf},
660                 PIDDIR => $ctx->{piddir},
661                 SERVER => $ctx->{netbiosname},
662                 SERVER_IP => $ctx->{ipv4},
663                 NETBIOSNAME => $ctx->{netbiosname},
664                 NETBIOSALIAS => $ctx->{netbiosalias},
665                 DOMAIN => $ctx->{domain},
666                 USERNAME => $ctx->{username},
667                 REALM => $ctx->{realm},
668                 PASSWORD => $ctx->{password},
669                 LDAPDIR => $ctx->{ldapdir},
670                 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
671                 NCALRPCDIR => $ctx->{ncalrpcdir},
672                 LOCKDIR => $ctx->{lockdir},
673                 SERVERCONFFILE => $ctx->{smb_conf},
674                 CONFIGURATION => $configuration,
675                 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
676                 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
677                 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
678                 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
679                 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
680                 SAMBA_TEST_LOG_POS => 0,
681         };
682
683         return $ret;
684 }
685
686 #
687 # provision_raw_step2() is also used by Samba34.pm!
688 #
689 # Step2 runs the provision script
690 #
691 sub provision_raw_step2($$$)
692 {
693         my ($self, $ctx, $ret) = @_;
694
695         my $provision_cmd = join(" ", @{$ctx->{provision_options}});
696         (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n");
697
698         return $ret;
699 }
700
701 sub provision($$$$$$$)
702 {
703         my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password, $kdc_ipv4) = @_;
704
705         my $ctx = $self->provision_raw_prepare($prefix, $server_role,
706                                                $netbiosname, $netbiosalias,
707                                                $swiface, $password, $kdc_ipv4);
708
709         $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
710         push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
711         push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test1");
712         push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test2");
713
714         $ctx->{smb_conf_extra_options} = "
715
716         max xmit = 32K
717         server max protocol = SMB2
718
719 [tmp]
720         path = $ctx->{tmpdir}
721         read only = no
722         posix:sharedelay = 100000
723         posix:eadb = $ctx->{lockdir}/eadb.tdb
724         posix:oplocktimeout = 3
725         posix:writetimeupdatedelay = 500000
726
727 [test1]
728         path = $ctx->{tmpdir}/test1
729         read only = no
730         posix:sharedelay = 100000
731         posix:eadb = $ctx->{lockdir}/eadb.tdb
732         posix:oplocktimeout = 3
733         posix:writetimeupdatedelay = 500000
734
735 [test2]
736         path = $ctx->{tmpdir}/test2
737         read only = no
738         posix:sharedelay = 100000
739         posix:eadb = $ctx->{lockdir}/eadb.tdb
740         posix:oplocktimeout = 3
741         posix:writetimeupdatedelay = 500000
742
743 [cifs]
744         read only = no
745         ntvfs handler = cifs
746         cifs:server = $ctx->{netbiosname}
747         cifs:share = tmp
748 #There is no username specified here, instead the client is expected
749 #to log in with kerberos, and the serverwill use delegated credentials.
750
751 [simple]
752         path = $ctx->{tmpdir}
753         read only = no
754         ntvfs handler = simple
755
756 [sysvol]
757         path = $ctx->{lockdir}/sysvol
758         read only = yes
759
760 [netlogon]
761         path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
762         read only = no
763
764 [cifsposix]
765         copy = simple
766         ntvfs handler = cifsposix
767 ";
768
769         if (defined($self->{ldap})) {
770                 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
771                 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
772
773                 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
774                 $ldap_uri =~ s|/|%2F|g;
775                 $ldap_uri = "ldapi://$ldap_uri";
776                 $ctx->{ldap_uri} = $ldap_uri;
777         }
778
779         my $ret = $self->provision_raw_step1($ctx);
780
781         if (defined($self->{ldap})) {
782                 $ret->{LDAP_URI} = $ctx->{ldap_uri};
783                 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
784                 if ($self->{ldap} eq "openldap") {
785                         push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
786                         ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx->{ldapdir}) or die("Unable to create openldap directories");
787
788                 } elsif ($self->{ldap} eq "fedora-ds") {
789                         push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
790                         push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
791                         ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx->{ldapdir}) or die("Unable to create fedora ds directories");
792                 }
793
794         }
795
796         $ret = $self->provision_raw_step2($ctx, $ret);
797
798         return $ret;
799 }
800
801 sub provision_member($$$)
802 {
803         my ($self, $prefix, $dcvars) = @_;
804         print "PROVISIONING MEMBER...";
805
806         my $ret = $self->provision($prefix,
807                                    "member server",
808                                    "localmember3",
809                                    "localmember",
810                                    3,
811                                    "localmemberpass",
812                                    $dcvars->{SERVER_IP});
813
814         $ret or die("Unable to provision");
815
816         my $net = $self->bindir_path("net");
817         my $cmd = "";
818         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
819         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
820         $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
821         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
822
823         system($cmd) == 0 or die("Join failed\n$cmd");
824
825         $ret->{DC_SERVER} = $dcvars->{SERVER};
826         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
827         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
828         $ret->{DC_NETBIOSALIAS} = $dcvars->{NETBIOSALIAS};
829         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
830         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
831
832         return $ret;
833 }
834
835 sub provision_dc($$)
836 {
837         my ($self, $prefix) = @_;
838
839         print "PROVISIONING DC...";
840         my $ret = $self->provision($prefix,
841                                    "domain controller",
842                                    "localdc1",
843                                    "localdc",
844                                    1,
845                                    "localdcpass",
846                                    "127.0.0.1");
847
848         $self->add_wins_config("$prefix/private") or 
849                 die("Unable to add wins configuration");
850
851         return $ret;
852 }
853
854 sub teardown_env($$)
855 {
856         my ($self, $envvars) = @_;
857         my $pid;
858
859         close(DATA);
860
861         if (-f "$envvars->{PIDDIR}/samba.pid" ) {
862                 open(IN, "<$envvars->{PIDDIR}/samba.pid") or die("unable to open server pid file");
863                 $pid = <IN>;
864                 close(IN);
865
866                 # Give the process 20 seconds to exit.  gcov needs
867                 # this time to write out the covarge data
868                 my $count = 0;
869                 until (kill(0, $pid) == 0) {
870                     # if no process sucessfully signalled, then we are done
871                     sleep(1);
872                     $count++;
873                     last if $count > 20;
874                 }
875                 
876                 # If it is still around, kill it
877                 if ($count > 20) {
878                     print "server process $pid took more than $count seconds to exit, killing\n";
879                     kill 9, $pid;
880                 }
881         }
882
883         my $failed = $? >> 8;
884
885         $self->slapd_stop($envvars) if ($self->{ldap});
886
887         print $self->getlog_env($envvars);
888
889         return $failed;
890 }
891
892 sub getlog_env($$)
893 {
894         my ($self, $envvars) = @_;
895         my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
896         my $out = $title;
897
898         open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
899
900         seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
901         while (<LOG>) {
902                 $out .= $_;
903         }
904         $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
905         close(LOG);
906
907         return "" if $out eq $title;
908  
909         return $out;
910 }
911
912 sub check_env($$)
913 {
914         my ($self, $envvars) = @_;
915
916         return 1 if (-p $envvars->{SAMBA_TEST_FIFO});
917
918         print $self->getlog_env($envvars);
919
920         return 0;
921 }
922
923 sub setup_env($$$)
924 {
925         my ($self, $envname, $path) = @_;
926
927         if ($envname eq "dc") {
928                 return $self->setup_dc("$path/dc");
929         } elsif ($envname eq "member") {
930                 if (not defined($self->{vars}->{dc})) {
931                         $self->setup_dc("$path/dc");
932                 }
933                 return $self->setup_member("$path/member", $self->{vars}->{dc});
934         } else {
935                 die("Samba4 can't provide environment '$envname'");
936         }
937 }
938
939 sub setup_member($$$$)
940 {
941         my ($self, $path, $dc_vars) = @_;
942
943         my $env = $self->provision_member($path, $dc_vars);
944
945         $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
946
947         $self->wait_for_start($env);
948
949         return $env;
950 }
951
952 sub setup_dc($$)
953 {
954         my ($self, $path) = @_;
955
956         my $env = $self->provision_dc($path);
957
958         $self->check_or_start($env, 
959                 ($ENV{SMBD_MAXTIME} or 7500));
960
961         $self->wait_for_start($env);
962
963         $self->{vars}->{dc} = $env;
964
965         return $env;
966 }
967
968 sub stop($)
969 {
970         my ($self) = @_;
971 }
972
973 1;