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.
10 use FindBin
qw($RealBin);
14 my ($classname, $bindir, $ldap, $setupdir, $exeext) = @_;
15 $exeext = "" unless defined($exeext);
20 setupdir => $setupdir,
28 my ($self, $path) = @_;
30 return "$self->{bindir}/$path$self->{exeext}";
33 sub openldap_start($$$) {
34 my ($slapd_conf, $uri, $logs) = @_;
35 my $oldpath = $ENV{PATH};
38 if (defined $ENV{OPENLDAP_ROOT}) {
39 $olroot = "$ENV{OPENLDAP_ROOT}";
40 $olpath = "$olroot/libexec:$olroot/sbin:";
42 $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}";
43 system("slapd -d0 -f $slapd_conf -h $uri > $logs 2>&1 &");
44 $ENV{PATH} = $oldpath;
50 my ($self, $env_vars) = @_;
52 my $uri = $env_vars->{LDAP_URI};
54 # running slapd in the background means it stays in the same process group, so it can be
56 if ($self->{ldap} eq "fedora-ds") {
57 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 &");
58 } elsif ($self->{ldap} eq "openldap") {
59 openldap_start($env_vars->{SLAPD_CONF}, $uri, "$env_vars->{LDAPDIR}/logs");
61 my $ldbsearch = $self->bindir_path("ldbsearch");
62 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
65 $self->slapd_stop($env_vars);
75 my ($self, $envvars) = @_;
76 if ($self->{ldap} eq "fedora-ds") {
77 system("$envvars->{LDAPDIR}/slapd-samba4/stop-slapd");
78 } elsif ($self->{ldap} eq "openldap") {
79 open(IN, "<$envvars->{OPENLDAP_PIDFILE}") or
80 die("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
87 sub check_or_start($$$)
89 my ($self, $env_vars, $max_time) = @_;
90 return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
92 unlink($env_vars->{SAMBA_TEST_FIFO});
93 POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
94 unlink($env_vars->{SAMBA_TEST_LOG});
96 print "STARTING SAMBA... ";
99 open STDIN, $env_vars->{SAMBA_TEST_FIFO};
100 open STDOUT, ">$env_vars->{SAMBA_TEST_LOG}";
101 open STDERR, '>&STDOUT';
103 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
106 if (defined($ENV{SAMBA_VALGRIND})) {
107 $valgrind = $ENV{SAMBA_VALGRIND};
110 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
111 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
113 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
114 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
116 # Start slapd before samba, but with the fifo on stdin
117 if (defined($self->{ldap})) {
118 $self->slapd_start($env_vars) or
119 die("couldn't start slapd (2nd time)");
123 if (defined($max_time)) {
124 $optarg = "--maximum-runtime=$max_time ";
126 if (defined($ENV{SAMBA_OPTIONS})) {
127 $optarg.= " $ENV{SAMBA_OPTIONS}";
129 my $samba = $self->bindir_path("samba");
130 my $ret = system("$valgrind $samba $optarg $env_vars->{CONFIGURATION} -M single -i --leak-report-full");
132 print "Unable to start $samba: $ret: $!\n";
135 unlink($env_vars->{SAMBA_TEST_FIFO});
138 print "$samba exits with status $exit\n";
139 } elsif ( $ret & 127 ) {
140 print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
143 print "$samba failed with status $exit!\n";
149 open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
154 sub wait_for_start($$)
156 my ($self, $testenv_vars) = @_;
157 # give time for nbt server to register its names
158 print "delaying for nbt name registration\n";
161 # This will return quickly when things are up, but be slow if we
162 # need to wait for (eg) SSL init
163 my $nmblookup = $self->bindir_path("nmblookup");
164 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
165 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
166 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
167 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
168 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
169 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
170 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
171 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
172 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
173 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
174 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
175 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
177 print $self->getlog_env($testenv_vars);
180 sub write_ldb_file($$$)
182 my ($self, $file, $ldif) = @_;
184 my $ldbadd = $self->bindir_path("ldbadd");
185 open(LDIF, "|$ldbadd -H $file >/dev/null");
190 sub add_wins_config($$)
192 my ($self, $privatedir) = @_;
194 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
195 dn: name=TORTURE_6,CN=PARTNERS
196 objectClass: wreplPartner
205 sub mk_fedora_ds($$$)
207 my ($self, $ldapdir, $configuration) = @_;
209 my $fedora_ds_inf = "$ldapdir/fedorads.inf";
210 my $fedora_ds_extra_ldif = "$ldapdir/fedorads-partitions.ldif";
212 #Make the subdirectory be as fedora DS would expect
213 my $fedora_ds_dir = "$ldapdir/slapd-samba4";
215 my $pidfile = "$fedora_ds_dir/logs/slapd-samba4.pid";
218 chdir "$ENV{FEDORA_DS_ROOT}/bin" || die;
219 if (system("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf >&2") != 0) {
221 die("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf FAILED: $?");
225 return ($fedora_ds_dir, $pidfile);
230 my ($self, $ldapdir, $configuration) = @_;
232 my $slapd_conf = "$ldapdir/slapd.conf";
233 my $pidfile = "$ldapdir/slapd.pid";
234 my $modconf = "$ldapdir/modules.conf";
236 my $oldpath = $ENV{PATH};
239 if (defined $ENV{OPENLDAP_ROOT}) {
240 $olroot = "$ENV{OPENLDAP_ROOT}";
241 $olpath = "$olroot/libexec:$olroot/sbin:";
243 $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}";
247 #This code tries to guess what modules we need to load (if any) by trying different combinations in the modules.conf
249 # Try without any slapd modules
250 open(CONF, ">$modconf"); close(CONF);
252 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
253 open(CONF, ">$modconf");
254 # enable slapd modules
263 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
264 open(CONF, ">$modconf");
265 # enable slapd modules, and the module for back_hdb
276 system("slaptest -u -f $slapd_conf") == 0 or die("slaptest still fails after adding modules");
279 $ENV{PATH} = $oldpath;
281 return ($slapd_conf, $pidfile);
286 my ($self, $tlsdir) = @_;
288 #TLS and PKINIT crypto blobs
289 my $dhfile = "$tlsdir/dhparms.pem";
290 my $cafile = "$tlsdir/ca.pem";
291 my $certfile = "$tlsdir/cert.pem";
292 my $reqkdc = "$tlsdir/req-kdc.der";
293 my $kdccertfile = "$tlsdir/kdc.pem";
294 my $keyfile = "$tlsdir/key.pem";
295 my $adminkeyfile = "$tlsdir/adminkey.pem";
296 my $reqadmin = "$tlsdir/req-admin.der";
297 my $admincertfile = "$tlsdir/admincert.pem";
299 mkdir($tlsdir, 0777);
301 #This is specified here to avoid draining entropy on every run
302 open(DHFILE, ">$dhfile");
304 -----BEGIN DH PARAMETERS-----
305 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
306 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
308 -----END DH PARAMETERS-----
312 #Likewise, we pregenerate the key material. This allows the
313 #other certificates to be pre-generated
314 open(KEYFILE
, ">$keyfile");
316 -----BEGIN RSA PRIVATE KEY-----
317 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
318 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
319 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
320 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
321 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
322 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
323 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
324 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
325 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
326 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
327 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
328 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
329 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
330 -----END RSA PRIVATE KEY-----
334 open(ADMINKEYFILE
, ">$adminkeyfile");
336 print ADMINKEYFILE
<<EOF;
337 -----BEGIN RSA PRIVATE KEY-----
338 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
339 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
340 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
341 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
342 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
343 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
344 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
345 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
346 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
347 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
348 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
349 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
350 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
351 -----END RSA PRIVATE KEY-----
355 # hxtool issue-certificate --self-signed --issue-ca \
356 # --ca-private-key="FILE:$KEYFILE" \
357 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
358 # --certificate="FILE:$CAFILE" --lifetime="25 years"
360 open(CAFILE
, ">$cafile");
362 -----BEGIN CERTIFICATE-----
363 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
364 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
365 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
366 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
367 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
368 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
369 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
370 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
371 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
372 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
373 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
374 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
375 -----END CERTIFICATE-----
378 #generated with GNUTLS internally in Samba.
380 open(CERTFILE
, ">$certfile");
381 print CERTFILE
<<EOF;
382 -----BEGIN CERTIFICATE-----
383 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
384 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
385 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
386 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
387 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
388 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
389 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
390 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
391 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
392 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
393 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
394 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
395 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
396 -----END CERTIFICATE-----
401 # hxtool request-create \
402 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
403 # --key="FILE:$KEYFILE" $KDCREQ
405 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
406 # --type="pkinit-kdc" \
407 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
408 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
409 # --lifetime="25 years"
411 open(KDCCERTFILE
, ">$kdccertfile");
412 print KDCCERTFILE
<<EOF;
413 -----BEGIN CERTIFICATE-----
414 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
415 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
416 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
417 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
418 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
419 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
420 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
421 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
422 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
423 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
424 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
425 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
426 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
427 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
428 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
429 -----END CERTIFICATE-----
432 # hxtool request-create \
433 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
434 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
436 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
437 # --type="pkinit-client" \
438 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
439 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
440 # --lifetime="25 years"
442 open(ADMINCERTFILE
, ">$admincertfile");
443 print ADMINCERTFILE
<<EOF;
444 -----BEGIN CERTIFICATE-----
445 MIIDHTCCAoagAwIBAgIUC0W5dW/N9kE+NgD0mKK34YgyqQ0wCwYJKoZIhvcNAQEFMFIxEzAR
446 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
447 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMyMzAwWhgPMjAzMzAyMjQx
448 MzIzMDBaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
449 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
450 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
451 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
452 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
453 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
454 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
455 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1hZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
456 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
457 HRMEAjAAMA0GCSqGSIb3DQEBBQUAA4GBAHsqSqul0hZCXn4t8Kfp3v/JLMiUMJihR1XOgzoa
458 ufLOQ1HNzFUHKuo1JEQ1+i5gHT/arLu/ZBF4BfQol7vW27gKIEt0fkRV8EvoPxXvSokHq0Ku
459 HCuPOhYNEP3wYiwB3g93NMCinWVlz0mh5aijEU7y/XrjlZxBKFFrTE+BJi1o
460 -----END CERTIFICATE-----
462 close(ADMINCERTFILE
);
466 # provision_raw_prepare() is also used by Samba34.pm!
468 sub provision_raw_prepare
($$$$$$$)
470 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password, $kdc_ipv4) = @_;
473 -d
$prefix or mkdir($prefix, 0777) or die("Unable to create $prefix");
474 my $prefix_abs = abs_path
($prefix);
476 die ("prefix=''") if $prefix_abs eq "";
477 die ("prefix='/'") if $prefix_abs eq "/";
479 (system("rm -rf $prefix_abs/*") == 0) or die("Unable to clean up");
481 $ctx->{prefix
} = $prefix;
482 $ctx->{prefix_abs
} = $prefix_abs;
483 $ctx->{server_role
} = $server_role;
484 $ctx->{netbiosname
} = $netbiosname;
485 $ctx->{netbiosalias
} = $netbiosalias;
486 $ctx->{swiface
} = $swiface;
487 $ctx->{password
} = $password;
488 $ctx->{kdc_ipv4
} = $kdc_ipv4;
490 $ctx->{server_loglevel
} = 1;
491 $ctx->{username
} = "administrator";
492 $ctx->{domain
} = "SAMBADOMAIN";
493 $ctx->{realm
} = "SAMBA.EXAMPLE.COM";
494 $ctx->{dnsname
} = "samba.example.com";
495 $ctx->{basedn
} = "dc=samba,dc=example,dc=com";
497 my $unix_name = ($ENV{USER
} or $ENV{LOGNAME
} or `whoami`);
499 $ctx->{unix_name
} = $unix_name;
500 $ctx->{unix_uid
} = $>;
501 $ctx->{unix_gids_str
} = $);
502 @
{$ctx->{unix_gids
}} = split(" ", $ctx->{unix_gids_str
});
504 $ctx->{etcdir
} = "$prefix_abs/etc";
505 $ctx->{piddir
} = "$prefix_abs/pid";
506 $ctx->{smb_conf
} = "$ctx->{etcdir}/smb.conf";
507 $ctx->{krb5_conf
} = "$ctx->{etcdir}/krb5.conf";
508 $ctx->{privatedir
} = "$prefix_abs/private";
509 $ctx->{ncalrpcdir
} = "$prefix_abs/ncalrpc";
510 $ctx->{lockdir
} = "$prefix_abs/lockdir";
511 $ctx->{winbindd_socket_dir
} = "$prefix_abs/winbindd_socket";
512 $ctx->{winbindd_privileged_socket_dir
} = "$prefix_abs/winbindd_privileged_socket";
513 $ctx->{ntp_signd_socket_dir
} = "$prefix_abs/ntp_signd_socket";
514 $ctx->{nsswrap_passwd
} = "$ctx->{etcdir}/passwd";
515 $ctx->{nsswrap_group
} = "$ctx->{etcdir}/group";
517 $ctx->{tlsdir
} = "$ctx->{privatedir}/tls";
519 $ctx->{ipv4
} = "127.0.0.$swiface";
520 $ctx->{interfaces
} = "$ctx->{ipv4}/8";
522 $ctx->{localbasedn
} = $ctx->{basedn
};
523 $ctx->{localbasedn
} = "CN=$netbiosname" if $server_role eq "member server";
525 push(@
{$ctx->{directories
}}, $ctx->{privatedir
});
526 push(@
{$ctx->{directories
}}, $ctx->{etcdir
});
527 push(@
{$ctx->{directories
}}, $ctx->{piddir
});
528 push(@
{$ctx->{directories
}}, $ctx->{ncalrpcdir
});
529 push(@
{$ctx->{directories
}}, $ctx->{lockdir
});
531 $ctx->{smb_conf_extra_options
} = "";
533 my @provision_options = ();
534 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
535 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
536 if (defined($ENV{GDB_PROVISION
})) {
537 push (@provision_options, "gdb --args");
539 if (defined($ENV{VALGRIND_PROVISION
})) {
540 push (@provision_options, "valgrind");
542 if (defined($ENV{PYTHON
})) {
543 push (@provision_options, $ENV{PYTHON
});
545 push (@provision_options, "$self->{setupdir}/provision");
546 push (@provision_options, "--configfile=$ctx->{smb_conf}");
547 push (@provision_options, "--host-name=$ctx->{netbiosname}");
548 push (@provision_options, "--host-ip=$ctx->{ipv4}");
549 push (@provision_options, "--quiet");
550 push (@provision_options, "--domain=$ctx->{domain}");
551 push (@provision_options, "--realm=$ctx->{realm}");
552 push (@provision_options, "--adminpass=$ctx->{password}");
553 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
554 push (@provision_options, "--machinepass=machine$ctx->{password}");
555 push (@provision_options, "--root=$ctx->{unix_name}");
556 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
558 @
{$ctx->{provision_options
}} = @provision_options;
564 # provision_raw_step1() is also used by Samba34.pm!
566 # Step1 creates the basic configuration
568 sub provision_raw_step1
($$)
570 my ($self, $ctx) = @_;
572 mkdir($_, 0777) foreach (@
{$ctx->{directories
}});
574 open(CONFFILE
, ">$ctx->{smb_conf}")
575 or die("can't open $ctx->{smb_conf}$?");
578 netbios name = $ctx->{netbiosname}
579 netbios aliases = $ctx->{netbiosalias}
580 workgroup = $ctx->{domain}
581 realm = $ctx->{realm}
582 private dir = $ctx->{privatedir}
583 pid directory = $ctx->{piddir}
584 ncalrpc dir = $ctx->{ncalrpcdir}
585 lock dir = $ctx->{lockdir}
586 setup directory = $self->{setupdir}
587 modules dir = $self->{bindir}/modules
588 winbindd socket directory = $ctx->{winbindd_socket_dir}
589 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
590 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
591 winbind separator = /
592 name resolve order = bcast
593 interfaces = $ctx->{interfaces}
594 tls dh params file = $ctx->{tlsdir}/dhparms.pem
595 panic action = $RealBin/gdb_backtrace \%PID% \%PROG%
597 server role = $ctx->{server_role}
598 notify:inotify = false
600 #We don't want to pass our self-tests if the PAC code is wrong
601 gensec:require_pac = true
602 log level = $ctx->{server_loglevel}
605 # Begin extra options
606 $ctx->{smb_conf_extra_options}
611 $self->mk_keyblobs($ctx->{tlsdir
});
613 open(KRB5CONF
, ">$ctx->{krb5_conf}")
614 or die("can't open $ctx->{krb5_conf}$?");
616 #Generated krb5.conf for $ctx->{realm}
619 default_realm = $ctx->{realm}
620 dns_lookup_realm = false
621 dns_lookup_kdc = false
622 ticket_lifetime = 24h
627 kdc = $ctx->{kdc_ipv4}:88
628 admin_server = $ctx->{kdc_ipv4}:88
629 default_domain = $ctx->{dnsname}
632 kdc = $ctx->{kdc_ipv4}:88
633 admin_server = $ctx->{kdc_ipv4}:88
634 default_domain = $ctx->{dnsname}
637 kdc = $ctx->{kdc_ipv4}:88
638 admin_server = $ctx->{kdc_ipv4}:88
639 default_domain = $ctx->{dnsname}
643 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
647 pkinit_identity = FILE:$ctx->{tlsdir}/kdc.pem,$ctx->{tlsdir}/key.pem
648 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
651 .$ctx->{dnsname} = $ctx->{realm}
655 open(PWD
, ">$ctx->{nsswrap_passwd}");
657 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
658 $ctx->{unix_name}:x:$ctx->{unix_uid}:@{$ctx->{unix_gids}}[0]:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
659 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
663 open(GRP
, ">$ctx->{nsswrap_group}");
669 nogroup:x:65534:nobody
673 my $configuration = "--configfile=$ctx->{smb_conf}";
675 #Ensure the config file is valid before we start
676 my $testparm = $self->bindir_path("testparm");
677 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
678 system("$testparm -v --suppress-prompt $configuration >&2");
679 die("Failed to create a valid smb.conf configuration $testparm!");
682 (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");
685 KRB5_CONFIG
=> $ctx->{krb5_conf
},
686 PIDDIR
=> $ctx->{piddir
},
687 SERVER
=> $ctx->{netbiosname
},
688 SERVER_IP
=> $ctx->{ipv4
},
689 NETBIOSNAME
=> $ctx->{netbiosname
},
690 NETBIOSALIAS
=> $ctx->{netbiosalias
},
691 DOMAIN
=> $ctx->{domain
},
692 USERNAME
=> $ctx->{username
},
693 REALM
=> $ctx->{realm
},
694 PASSWORD
=> $ctx->{password
},
695 LDAPDIR
=> $ctx->{ldapdir
},
696 WINBINDD_SOCKET_DIR
=> $ctx->{winbindd_socket_dir
},
697 NCALRPCDIR
=> $ctx->{ncalrpcdir
},
698 LOCKDIR
=> $ctx->{lockdir
},
699 SERVERCONFFILE
=> $ctx->{smb_conf
},
700 CONFIGURATION
=> $configuration,
701 SOCKET_WRAPPER_DEFAULT_IFACE
=> $ctx->{swiface
},
702 NSS_WRAPPER_PASSWD
=> $ctx->{nsswrap_passwd
},
703 NSS_WRAPPER_GROUP
=> $ctx->{nsswrap_group
},
704 SAMBA_TEST_FIFO
=> "$ctx->{prefix}/samba_test.fifo",
705 SAMBA_TEST_LOG
=> "$ctx->{prefix}/samba_test.log",
706 SAMBA_TEST_LOG_POS
=> 0,
713 # provision_raw_step2() is also used by Samba34.pm!
715 # Step2 runs the provision script
717 sub provision_raw_step2
($$$)
719 my ($self, $ctx, $ret) = @_;
721 my $provision_cmd = join(" ", @
{$ctx->{provision_options
}});
722 (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n");
727 sub provision
($$$$$$$)
729 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password, $kdc_ipv4) = @_;
731 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
732 $netbiosname, $netbiosalias,
733 $swiface, $password, $kdc_ipv4);
735 $ctx->{tmpdir
} = "$ctx->{prefix_abs}/tmp";
736 push(@
{$ctx->{directories
}}, "$ctx->{tmpdir}");
737 push(@
{$ctx->{directories
}}, "$ctx->{tmpdir}/test1");
738 push(@
{$ctx->{directories
}}, "$ctx->{tmpdir}/test2");
740 $ctx->{smb_conf_extra_options
} = "
743 server max protocol = SMB2
746 path = $ctx->{tmpdir}
748 ntvfs handler = posix
749 posix:sharedelay = 100000
750 posix:eadb = $ctx->{lockdir}/eadb.tdb
751 posix:oplocktimeout = 3
752 posix:writetimeupdatedelay = 500000
755 path = $ctx->{tmpdir}/test1
757 ntvfs handler = posix
758 posix:sharedelay = 100000
759 posix:eadb = $ctx->{lockdir}/eadb.tdb
760 posix:oplocktimeout = 3
761 posix:writetimeupdatedelay = 500000
764 path = $ctx->{tmpdir}/test2
766 ntvfs handler = posix
767 posix:sharedelay = 100000
768 posix:eadb = $ctx->{lockdir}/eadb.tdb
769 posix:oplocktimeout = 3
770 posix:writetimeupdatedelay = 500000
775 cifs:server = $ctx->{netbiosname}
777 #There is no username specified here, instead the client is expected
778 #to log in with kerberos, and the serverwill use delegated credentials.
781 path = $ctx->{tmpdir}
783 ntvfs handler = simple
786 path = $ctx->{lockdir}/sysvol
790 path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
795 ntvfs handler = cifsposix
798 if (defined($self->{ldap
})) {
799 $ctx->{ldapdir
} = "$ctx->{privatedir}/ldap";
800 push(@
{$ctx->{directories
}}, "$ctx->{ldapdir}");
802 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
803 $ldap_uri =~ s
|/|%2F|g
;
804 $ldap_uri = "ldapi://$ldap_uri";
805 $ctx->{ldap_uri
} = $ldap_uri;
808 my $ret = $self->provision_raw_step1($ctx);
810 if (defined($self->{ldap
})) {
811 my $configuration = "--configfile=$ctx->{smb_conf}";
813 $ret->{LDAP_URI
} = $ctx->{ldap_uri
};
814 push (@
{$ctx->{provision_options
}},"--ldap-backend=$ctx->{ldap_uri}");
816 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");
818 push (@
{$ctx->{provision_options
}}, "--password=$ctx->{password}");
820 if ($self->{ldap
} eq "openldap") {
821 push (@
{$ctx->{provision_options
}}, "--username=samba-admin");
822 push (@
{$ctx->{provision_options
}}, "--ldap-backend-type=openldap");
824 ($ret->{SLAPD_CONF
}, $ret->{OPENLDAP_PIDFILE
}) = $self->mk_openldap($ctx->{ldapdir
}, $configuration) or die("Unable to create openldap directories");
826 } elsif ($self->{ldap
} eq "fedora-ds") {
827 push (@
{$ctx->{provision_options
}}, "--simple-bind-dn=cn=Manager,$ctx->{localbasedn}");
828 push (@
{$ctx->{provision_options
}}, "--ldap-backend-type=fedora-ds");
830 ($ret->{FEDORA_DS_DIR
}, $ret->{FEDORA_DS_PIDFILE
}) = $self->mk_fedora_ds($ctx->{ldapdir
}, $configuration) or die("Unable to create fedora ds directories");
833 $self->slapd_start($ret) or die("couldn't start slapd");
836 $ret = $self->provision_raw_step2($ctx, $ret);
838 if (defined($self->{ldap
})) {
839 $self->slapd_stop($ret) or die("couldn't stop slapd");
845 sub provision_member
($$$)
847 my ($self, $prefix, $dcvars) = @_;
848 print "PROVISIONING MEMBER...";
850 my $ret = $self->provision($prefix,
856 $dcvars->{SERVER_IP
});
858 $ret or die("Unable to provision");
860 my $net = $self->bindir_path("net");
862 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
863 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
864 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
865 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
867 system($cmd) == 0 or die("Join failed\n$cmd");
869 $ret->{DC_SERVER
} = $dcvars->{SERVER
};
870 $ret->{DC_SERVER_IP
} = $dcvars->{SERVER_IP
};
871 $ret->{DC_NETBIOSNAME
} = $dcvars->{NETBIOSNAME
};
872 $ret->{DC_NETBIOSALIAS
} = $dcvars->{NETBIOSALIAS
};
873 $ret->{DC_USERNAME
} = $dcvars->{USERNAME
};
874 $ret->{DC_PASSWORD
} = $dcvars->{PASSWORD
};
881 my ($self, $prefix) = @_;
883 print "PROVISIONING DC...";
884 my $ret = $self->provision($prefix,
892 $self->add_wins_config("$prefix/private") or
893 die("Unable to add wins configuration");
900 my ($self, $envvars) = @_;
905 if (-f
"$envvars->{PIDDIR}/samba.pid" ) {
906 open(IN
, "<$envvars->{PIDDIR}/samba.pid") or die("unable to open server pid file");
910 # Give the process 20 seconds to exit. gcov needs
911 # this time to write out the covarge data
913 until (kill(0, $pid) == 0) {
914 # if no process sucessfully signalled, then we are done
920 # If it is still around, kill it
922 print "server process $pid took more than $count seconds to exit, killing\n";
927 my $failed = $?
>> 8;
929 $self->slapd_stop($envvars) if ($self->{ldap
});
931 print $self->getlog_env($envvars);
938 my ($self, $envvars) = @_;
939 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
942 open(LOG
, "<$envvars->{SAMBA_TEST_LOG}");
944 seek(LOG
, $envvars->{SAMBA_TEST_LOG_POS
}, SEEK_SET
);
948 $envvars->{SAMBA_TEST_LOG_POS
} = tell(LOG
);
951 return "" if $out eq $title;
958 my ($self, $envvars) = @_;
960 return 1 if (-p
$envvars->{SAMBA_TEST_FIFO
});
962 print $self->getlog_env($envvars);
969 my ($self, $envname, $path) = @_;
971 if ($envname eq "dc") {
972 return $self->setup_dc("$path/dc");
973 } elsif ($envname eq "member") {
974 if (not defined($self->{vars
}->{dc
})) {
975 $self->setup_dc("$path/dc");
977 return $self->setup_member("$path/member", $self->{vars
}->{dc
});
979 die("Samba4 can't provide environment '$envname'");
983 sub setup_member
($$$$)
985 my ($self, $path, $dc_vars) = @_;
987 my $env = $self->provision_member($path, $dc_vars);
989 $self->check_or_start($env, ($ENV{SMBD_MAXTIME
} or 7500));
991 $self->wait_for_start($env);
998 my ($self, $path) = @_;
1000 my $env = $self->provision_dc($path);
1002 $self->check_or_start($env,
1003 ($ENV{SMBD_MAXTIME
} or 7500));
1005 $self->wait_for_start($env);
1007 $self->{vars
}->{dc
} = $env;