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) = @_;
25 sub openldap_start($$$) {
26 my ($slapd_conf, $uri, $logs) = @_;
27 my $oldpath = $ENV{PATH};
30 if (defined $ENV{OPENLDAP_ROOT}) {
31 $olroot = "$ENV{OPENLDAP_ROOT}";
32 $olpath = "$olroot/libexec:$olroot/sbin:";
34 $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}";
35 system("slapd -d63 -f $slapd_conf -h $uri > $logs 2>&1 &");
36 $ENV{PATH} = $oldpath;
42 my ($self, $env_vars) = @_;
44 my $uri = $env_vars->{LDAP_URI};
46 # running slapd in the background means it stays in the same process group, so it can be
48 if ($self->{ldap} eq "fedora-ds") {
49 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 &");
50 } elsif ($self->{ldap} eq "openldap") {
51 openldap_start($env_vars->{SLAPD_CONF}, $uri, "$env_vars->{LDAPDIR}/logs");
53 while (system("$self->{bindir}/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
56 $self->slapd_stop($env_vars);
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}");
78 sub check_or_start($$$)
80 my ($self, $env_vars, $max_time) = @_;
81 return 0 if ( -p $env_vars->{SMBD_TEST_FIFO});
83 unlink($env_vars->{SMBD_TEST_FIFO});
84 POSIX::mkfifo($env_vars->{SMBD_TEST_FIFO}, 0700);
85 unlink($env_vars->{SMBD_TEST_LOG});
87 print "STARTING SMBD... ";
90 open STDIN, $env_vars->{SMBD_TEST_FIFO};
91 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
92 open STDERR, '>&STDOUT';
94 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
97 if (defined($ENV{SMBD_VALGRIND})) {
98 $valgrind = $ENV{SMBD_VALGRIND};
101 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
103 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
104 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
106 # Start slapd before smbd, but with the fifo on stdin
107 if (defined($self->{ldap})) {
108 $self->slapd_start($env_vars) or
109 die("couldn't start slapd (2nd time)");
113 if (defined($max_time)) {
114 $optarg = "--maximum-runtime=$max_time ";
116 if (defined($ENV{SMBD_OPTIONS})) {
117 $optarg.= " $ENV{SMBD_OPTIONS}";
119 my $ret = system("$valgrind $self->{bindir}/smbd $optarg $env_vars->{CONFIGURATION} -M single -i --leak-report-full");
121 print "Unable to start smbd: $ret: $!\n";
124 unlink($env_vars->{SMBD_TEST_FIFO});
127 print "smbd exits with status $exit\n";
128 } elsif ( $ret & 127 ) {
129 print "smbd got signal ".($ret & 127)." and exits with $exit!\n";
132 print "smbd failed with status $exit!\n";
138 open(DATA, ">$env_vars->{SMBD_TEST_FIFO}");
143 sub wait_for_start($$)
145 my ($self, $testenv_vars) = @_;
146 # give time for nbt server to register its names
147 print "delaying for nbt name registration\n";
150 # This will return quickly when things are up, but be slow if we
151 # need to wait for (eg) SSL init
152 system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
153 system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
154 system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
155 system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
156 system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
157 system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
158 system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
159 system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
160 system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
161 system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
162 system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
163 system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
165 print $self->getlog_env($testenv_vars);
168 sub write_ldb_file($$$)
170 my ($self, $file, $ldif) = @_;
172 open(LDIF, "|$self->{bindir}/ldbadd -H $file >/dev/null");
177 sub add_wins_config($$)
179 my ($self, $privatedir) = @_;
181 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
182 dn: name=TORTURE_6,CN=PARTNERS
183 objectClass: wreplPartner
192 sub mk_fedora_ds($$$)
194 my ($self, $ldapdir, $configuration) = @_;
196 my $fedora_ds_inf = "$ldapdir/fedorads.inf";
197 my $fedora_ds_extra_ldif = "$ldapdir/fedorads-partitions.ldif";
199 #Make the subdirectory be as fedora DS would expect
200 my $fedora_ds_dir = "$ldapdir/slapd-samba4";
202 my $pidfile = "$fedora_ds_dir/logs/slapd-samba4.pid";
205 chdir "$ENV{FEDORA_DS_ROOT}/bin" || die;
206 if (system("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf >&2") != 0) {
208 die("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf FAILED: $?");
212 return ($fedora_ds_dir, $pidfile);
217 my ($self, $ldapdir, $configuration) = @_;
219 my $slapd_conf = "$ldapdir/slapd.conf";
220 my $pidfile = "$ldapdir/slapd.pid";
221 my $modconf = "$ldapdir/modules.conf";
223 my $oldpath = $ENV{PATH};
226 if (defined $ENV{OPENLDAP_ROOT}) {
227 $olroot = "$ENV{OPENLDAP_ROOT}";
228 $olpath = "$olroot/libexec:$olroot/sbin:";
230 $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}";
233 open(CONF, ">$modconf"); close(CONF);
235 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
236 open(CONF, ">$modconf");
237 # enable slapd modules
239 modulepath $olroot/libexec/openldap
246 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
247 open(CONF, ">$modconf");
248 # enable slapd modules
250 modulepath $olroot/libexec/openldap
259 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
260 open(CONF, ">$modconf");
261 # enable slapd modules
271 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
272 open(CONF, ">$modconf");
273 # enable slapd modules
275 modulepath /usr/lib/ldap
284 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
285 open(CONF, ">$modconf");
286 # enable slapd modules (Fedora layout)
288 modulepath /usr/lib/openldap
296 if (system("slaptest -u -f $slapd_conf >&2") != 0) {
297 open(CONF, ">$modconf");
298 # enable slapd modules (Fedora x86_64 layout)
300 modulepath /usr/lib64/openldap
308 system("slaptest -u -f $slapd_conf") == 0 or die("slaptest still fails after adding modules");
311 $ENV{PATH} = $oldpath;
313 return ($slapd_conf, $pidfile);
318 my ($self, $tlsdir) = @_;
320 #TLS and PKINIT crypto blobs
321 my $dhfile = "$tlsdir/dhparms.pem";
322 my $cafile = "$tlsdir/ca.pem";
323 my $certfile = "$tlsdir/cert.pem";
324 my $reqkdc = "$tlsdir/req-kdc.der";
325 my $kdccertfile = "$tlsdir/kdc.pem";
326 my $keyfile = "$tlsdir/key.pem";
327 my $adminkeyfile = "$tlsdir/adminkey.pem";
328 my $reqadmin = "$tlsdir/req-admin.der";
329 my $admincertfile = "$tlsdir/admincert.pem";
331 mkdir($tlsdir, 0777);
333 #This is specified here to avoid draining entropy on every run
334 open(DHFILE, ">$dhfile");
336 -----BEGIN DH PARAMETERS-----
337 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
338 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
340 -----END DH PARAMETERS-----
344 #Likewise, we pregenerate the key material. This allows the
345 #other certificates to be pre-generated
346 open(KEYFILE
, ">$keyfile");
348 -----BEGIN RSA PRIVATE KEY-----
349 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
350 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
351 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
352 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
353 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
354 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
355 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
356 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
357 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
358 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
359 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
360 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
361 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
362 -----END RSA PRIVATE KEY-----
366 open(ADMINKEYFILE
, ">$adminkeyfile");
368 print ADMINKEYFILE
<<EOF;
369 -----BEGIN RSA PRIVATE KEY-----
370 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
371 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
372 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
373 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
374 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
375 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
376 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
377 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
378 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
379 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
380 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
381 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
382 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
383 -----END RSA PRIVATE KEY-----
387 # hxtool issue-certificate --self-signed --issue-ca \
388 # --ca-private-key="FILE:$KEYFILE" \
389 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
390 # --certificate="FILE:$CAFILE" --lifetime="25 years"
392 open(CAFILE
, ">$cafile");
394 -----BEGIN CERTIFICATE-----
395 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
396 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
397 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
398 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
399 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
400 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
401 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
402 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
403 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
404 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
405 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
406 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
407 -----END CERTIFICATE-----
410 #generated with GNUTLS internally in Samba.
412 open(CERTFILE
, ">$certfile");
413 print CERTFILE
<<EOF;
414 -----BEGIN CERTIFICATE-----
415 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
416 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
417 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
418 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
419 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
420 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
421 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
422 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
423 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
424 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
425 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
426 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
427 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
428 -----END CERTIFICATE-----
433 # hxtool request-create \
434 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
435 # --key="FILE:$KEYFILE" $KDCREQ
437 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
438 # --type="pkinit-kdc" \
439 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
440 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
441 # --lifetime="25 years"
443 open(KDCCERTFILE
, ">$kdccertfile");
444 print KDCCERTFILE
<<EOF;
445 -----BEGIN CERTIFICATE-----
446 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
447 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
448 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
449 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
450 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
451 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
452 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
453 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
454 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
455 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
456 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
457 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
458 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
459 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
460 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
461 -----END CERTIFICATE-----
464 # hxtool request-create \
465 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
466 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
468 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
469 # --type="pkinit-client" \
470 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
471 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
472 # --lifetime="25 years"
474 open(ADMINCERTFILE
, ">$admincertfile");
475 print ADMINCERTFILE
<<EOF;
476 -----BEGIN CERTIFICATE-----
477 MIIDHTCCAoagAwIBAgIUC0W5dW/N9kE+NgD0mKK34YgyqQ0wCwYJKoZIhvcNAQEFMFIxEzAR
478 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
479 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMyMzAwWhgPMjAzMzAyMjQx
480 MzIzMDBaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
481 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
482 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
483 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
484 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
485 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
486 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
487 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1hZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
488 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
489 HRMEAjAAMA0GCSqGSIb3DQEBBQUAA4GBAHsqSqul0hZCXn4t8Kfp3v/JLMiUMJihR1XOgzoa
490 ufLOQ1HNzFUHKuo1JEQ1+i5gHT/arLu/ZBF4BfQol7vW27gKIEt0fkRV8EvoPxXvSokHq0Ku
491 HCuPOhYNEP3wYiwB3g93NMCinWVlz0mh5aijEU7y/XrjlZxBKFFrTE+BJi1o
492 -----END CERTIFICATE-----
494 close(ADMINCERTFILE
);
497 sub provision
($$$$$$)
499 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password) = @_;
501 my $smbd_loglevel = 1;
502 my $username = "administrator";
503 my $domain = "SAMBADOMAIN";
504 my $realm = "SAMBA.EXAMPLE.COM";
505 my $dnsname = "samba.example.com";
506 my $basedn = "dc=samba,dc=example,dc=com";
507 my $unix_name = ($ENV{USER
} or $ENV{LOGNAME
} or `whoami`);
510 my $unix_gids_str = $);
511 my @unix_gids = split(" ", $unix_gids_str);
512 my $srcdir="$RealBin/..";
513 -d
$prefix or mkdir($prefix, 0777) or die("Unable to create $prefix");
514 my $prefix_abs = abs_path
($prefix);
515 my $tmpdir = "$prefix_abs/tmp";
516 my $etcdir = "$prefix_abs/etc";
517 my $piddir = "$prefix_abs/pid";
518 my $conffile = "$etcdir/smb.conf";
519 my $krb5_config = "$etcdir/krb5.conf";
520 my $privatedir = "$prefix_abs/private";
521 my $ncalrpcdir = "$prefix_abs/ncalrpc";
522 my $lockdir = "$prefix_abs/lockdir";
523 my $winbindd_socket_dir = "$prefix_abs/winbind_socket";
524 my $winbindd_priv_pipe_dir = "$privatedir/smbd.tmp/winbind_pipe";
525 my $nsswrap_passwd = "$etcdir/passwd";
526 my $nsswrap_group = "$etcdir/group";
528 my $configuration = "--configfile=$conffile";
529 my $ldapdir = "$privatedir/ldap";
531 my $tlsdir = "$privatedir/tls";
533 my $ifaceipv4 = "127.0.0.$swiface";
534 my $interfaces = "$ifaceipv4/8";
536 (system("rm -rf $prefix/*") == 0) or die("Unable to clean up");
537 mkdir($_, 0777) foreach ($privatedir, $etcdir, $piddir, $ncalrpcdir, $lockdir,
538 $tmpdir, "$tmpdir/test1", "$tmpdir/test2");
541 my $localbasedn = $basedn;
542 $localbasedn = "CN=$netbiosname" if $server_role eq "member server";
544 open(CONFFILE
, ">$conffile");
547 netbios name = $netbiosname
548 netbios aliases = $netbiosalias
551 private dir = $privatedir
552 pid directory = $piddir
553 ncalrpc dir = $ncalrpcdir
555 setup directory = $self->{setupdir}
556 modules dir = $self->{bindir}/modules
557 js include = $srcdir/scripting/libjs
558 winbindd socket directory = $winbindd_socket_dir
559 winbind separator = /
560 name resolve order = bcast
561 interfaces = $interfaces
562 tls dh params file = $tlsdir/dhparms.pem
563 panic action = $srcdir/script/gdb_backtrace \%PID% \%PROG%
565 server role = $server_role
567 server max protocol = SMB2
568 notify:inotify = false
570 system:anonymous = true
571 #We don't want to pass our self-tests if the PAC code is wrong
572 gensec:require_pac = true
573 log level = $smbd_loglevel
578 ntvfs handler = posix
579 posix:sharedelay = 100000
580 posix:eadb = $lockdir/eadb.tdb
581 posix:oplocktimeout = 3
586 ntvfs handler = posix
587 posix:sharedelay = 100000
588 posix:eadb = $lockdir/eadb.tdb
589 posix:oplocktimeout = 3
594 ntvfs handler = posix
595 posix:sharedelay = 100000
596 posix:eadb = $lockdir/eadb.tdb
597 posix:oplocktimeout = 3
602 cifs:server = $netbiosname
604 #There is no username specified here, instead the client is expected
605 #to log in with kerberos, and smbd will used delegated credentials.
610 ntvfs handler = simple
613 path = $lockdir/sysvol
617 path = $lockdir/sysvol/$dnsname/scripts
622 ntvfs handler = cifsposix
626 $self->mk_keyblobs($tlsdir);
628 open(KRB5CONF
, ">$krb5_config");
630 #Generated krb5.conf for $realm
633 default_realm = $realm
634 dns_lookup_realm = false
635 dns_lookup_kdc = false
636 ticket_lifetime = 24h
642 admin_server = 127.0.0.1:88
643 default_domain = $dnsname
647 admin_server = 127.0.0.1:88
648 default_domain = $dnsname
652 admin_server = 127.0.0.1:88
653 default_domain = $dnsname
657 pkinit_anchors = FILE:$tlsdir/ca.pem
661 pkinit_identity = FILE:$tlsdir/kdc.pem,$tlsdir/key.pem
662 pkinit_anchors = FILE:$tlsdir/ca.pem
669 open(PWD
, ">$nsswrap_passwd");
671 root:x:0:0:root gecos:$prefix_abs:/bin/false
672 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
673 nobody:x:65534:65533:nobody gecos:$prefix_abs:/bin/false
677 open(GRP
, ">$nsswrap_group");
683 nogroup:x:65534:nobody
687 #Ensure the config file is valid before we start
688 if (system("$self->{bindir}/testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
689 system("$self->{bindir}/testparm -v --suppress-prompt $configuration >&2");
690 die("Failed to create a valid smb.conf configuration!");
693 (system("($self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$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");
695 my @provision_options = ();
696 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$nsswrap_passwd\"");
697 push (@provision_options, "NSS_WRAPPER_GROUP=\"$nsswrap_group\"");
698 if (defined($ENV{GDB_PROVISION
})) {
699 push (@provision_options, "gdb --args");
701 if (defined($ENV{VALGRIND_PROVISION
})) {
702 push (@provision_options, "valgrind");
704 if (defined($ENV{PROVISION_EJS
})) {
705 push (@provision_options, "$self->{bindir}/smbscript");
706 push (@provision_options, "$self->{setupdir}/provision.js");
708 push (@provision_options, "$self->{bindir}/smbpython");
709 push (@provision_options, "$self->{setupdir}/provision");
711 push (@provision_options, split(' ', $configuration));
712 push (@provision_options, "--host-name=$netbiosname");
713 push (@provision_options, "--host-ip=$ifaceipv4");
714 push (@provision_options, "--quiet");
715 push (@provision_options, "--domain=$domain");
716 push (@provision_options, "--realm=$realm");
717 push (@provision_options, "--adminpass=$password");
718 push (@provision_options, "--krbtgtpass=krbtgt$password");
719 push (@provision_options, "--machinepass=machine$password");
720 push (@provision_options, "--root=$unix_name");
721 push (@provision_options, "--simple-bind-dn=cn=Manager,$localbasedn");
722 push (@provision_options, "--password=$password");
723 push (@provision_options, "--server-role=\"$server_role\"");
725 my $ldap_uri= "$ldapdir/ldapi";
726 $ldap_uri =~ s
|/|%2F|g
;
727 $ldap_uri = "ldapi://$ldap_uri";
730 KRB5_CONFIG
=> $krb5_config,
732 SERVER
=> $netbiosname,
733 SERVER_IP
=> $ifaceipv4,
734 NETBIOSNAME
=> $netbiosname,
735 NETBIOSALIAS
=> $netbiosalias,
736 LDAP_URI
=> $ldap_uri,
738 USERNAME
=> $username,
740 PASSWORD
=> $password,
742 WINBINDD_SOCKET_DIR
=> $winbindd_socket_dir,
743 WINBINDD_PRIV_PIPE_DIR
=> $winbindd_priv_pipe_dir,
744 NCALRPCDIR
=> $ncalrpcdir,
746 CONFIGURATION
=> $configuration,
747 SOCKET_WRAPPER_DEFAULT_IFACE
=> $swiface,
748 NSS_WRAPPER_PASSWD
=> $nsswrap_passwd,
749 NSS_WRAPPER_GROUP
=> $nsswrap_group,
752 if (defined($self->{ldap
})) {
754 push (@provision_options, "--ldap-backend=$ldap_uri");
755 system("$self->{bindir}/smbpython $self->{setupdir}/provision-backend $configuration --ldap-manager-pass=$password --root=$unix_name --realm=$realm --domain=$domain --host-name=$netbiosname --ldap-backend-type=$self->{ldap}>&2") == 0 or die("backend provision failed");
757 if ($self->{ldap
} eq "openldap") {
758 ($ret->{SLAPD_CONF
}, $ret->{OPENLDAP_PIDFILE
}) = $self->mk_openldap($ldapdir, $configuration) or die("Unable to create openldap directories");
759 push (@provision_options, "--ldap-backend-type=openldap");
760 } elsif ($self->{ldap
} eq "fedora-ds") {
761 ($ret->{FEDORA_DS_DIR
}, $ret->{FEDORA_DS_PIDFILE
}) = $self->mk_fedora_ds($ldapdir, $configuration) or die("Unable to create fedora ds directories");
762 push (@provision_options, "--ldap-backend-type=fedora-ds");
763 push (@provision_options, "'--aci=aci:: KHRhcmdldGF0dHIgPSAiKiIpICh2ZXJzaW9uIDMuMDthY2wgImZ1bGwgYWNjZXNzIHRvIGFsbCBieSBhbGwiO2FsbG93IChhbGwpKHVzZXJkbiA9ICJsZGFwOi8vL2FueW9uZSIpOykK'");
766 $self->slapd_start($ret) or
767 die("couldn't start slapd");
770 my $provision_cmd = join(" ", @provision_options);
771 (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n");
773 if (defined($self->{ldap
})) {
774 $self->slapd_stop($ret) or
775 die("couldn't stop slapd");
781 sub provision_member
($$$)
783 my ($self, $prefix, $dcvars) = @_;
784 print "PROVISIONING MEMBER...";
786 my $ret = $self->provision($prefix,
793 $ret or die("Unable to provision");
796 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
797 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
798 $cmd .= "$self->{bindir}/net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
799 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
801 system($cmd) == 0 or die("Join failed\n$cmd");
803 $ret->{SMBD_TEST_FIFO
} = "$prefix/smbd_test.fifo";
804 $ret->{SMBD_TEST_LOG
} = "$prefix/smbd_test.log";
805 $ret->{SMBD_TEST_LOG_POS
} = 0;
807 $ret->{DC_SERVER
} = $dcvars->{SERVER
};
808 $ret->{DC_SERVER_IP
} = $dcvars->{SERVER_IP
};
809 $ret->{DC_NETBIOSNAME
} = $dcvars->{NETBIOSNAME
};
810 $ret->{DC_NETBIOSALIAS
} = $dcvars->{NETBIOSALIAS
};
811 $ret->{DC_USERNAME
} = $dcvars->{USERNAME
};
812 $ret->{DC_PASSWORD
} = $dcvars->{PASSWORD
};
819 my ($self, $prefix) = @_;
821 print "PROVISIONING DC...";
822 my $ret = $self->provision($prefix,
829 $self->add_wins_config("$prefix/private") or
830 die("Unable to add wins configuration");
832 $ret->{SMBD_TEST_FIFO
} = "$prefix/smbd_test.fifo";
833 $ret->{SMBD_TEST_LOG
} = "$prefix/smbd_test.log";
834 $ret->{SMBD_TEST_LOG_POS
} = 0;
840 my ($self, $envvars) = @_;
845 if (-f
"$envvars->{PIDDIR}/smbd.pid" ) {
846 open(IN
, "<$envvars->{PIDDIR}/smbd.pid") or die("unable to open smbd pid file");
850 # Give the process 20 seconds to exit. gcov needs
851 # this time to write out the covarge data
853 until (kill(0, $pid) == 0) {
854 # if no process sucessfully signalled, then we are done
860 # If it is still around, kill it
862 print "smbd process $pid took more than $count seconds to exit, killing\n";
867 my $failed = $?
>> 8;
869 $self->slapd_stop($envvars) if ($self->{ldap
});
871 print $self->getlog_env($envvars);
878 my ($self, $envvars) = @_;
879 my $title = "SMBD LOG of: $envvars->{NETBIOSNAME}\n";
882 open(LOG
, "<$envvars->{SMBD_TEST_LOG}");
884 seek(LOG
, $envvars->{SMBD_TEST_LOG_POS
}, SEEK_SET
);
888 $envvars->{SMBD_TEST_LOG_POS
} = tell(LOG
);
891 return "" if $out eq $title;
898 my ($self, $envvars) = @_;
900 return 1 if (-p
$envvars->{SMBD_TEST_FIFO
});
902 print $self->getlog_env($envvars);
909 my ($self, $envname, $path) = @_;
911 if ($envname eq "dc") {
912 return $self->setup_dc("$path/dc");
913 } elsif ($envname eq "member") {
914 if (not defined($self->{vars
}->{dc
})) {
915 $self->setup_dc("$path/dc");
917 return $self->setup_member("$path/member", $self->{vars
}->{dc
});
919 die("Samba4 can't provide environment '$envname'");
923 sub setup_member
($$$$)
925 my ($self, $path, $dc_vars) = @_;
927 my $env = $self->provision_member($path, $dc_vars);
929 $self->check_or_start($env, ($ENV{SMBD_MAXTIME
} or 7500));
931 $self->wait_for_start($env);
938 my ($self, $path) = @_;
940 my $env = $self->provision_dc($path);
942 $self->check_or_start($env,
943 ($ENV{SMBD_MAXTIME
} or 7500));
945 $self->wait_for_start($env);
947 $self->{vars
}->{dc
} = $env;