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