selftest/Samba4: pass '--machinepass' to 'samba-tool domain join'
[Samba/gebeck_regimport.git] / selftest / target / Samba4.pm
blob9419921643763de21cb3e3920a89577fbf09d813
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;
12 use SocketWrapper;
13 use target::Samba;
14 use target::Samba3;
16 sub new($$$$$) {
17 my ($classname, $bindir, $binary_mapping, $ldap, $srcdir, $exeext, $server_maxtime) = @_;
18 $exeext = "" unless defined($exeext);
20 my $self = {
21 vars => {},
22 ldap => $ldap,
23 bindir => $bindir,
24 binary_mapping => $binary_mapping,
25 srcdir => $srcdir,
26 exeext => $exeext,
27 server_maxtime => $server_maxtime,
28 target3 => new Samba3($bindir, $binary_mapping, $srcdir, $exeext, $server_maxtime)
30 bless $self;
31 return $self;
34 sub scriptdir_path($$) {
35 my ($self, $path) = @_;
36 return "$self->{srcdir}/source4/scripting/$path";
39 sub openldap_start($$$) {
42 sub slapd_start($$)
44 my $count = 0;
45 my ($self, $env_vars) = @_;
46 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
48 my $uri = $env_vars->{LDAP_URI};
50 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
51 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
52 return 1;
54 # running slapd in the background means it stays in the same process group, so it can be
55 # killed by timelimit
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 system("$ENV{OPENLDAP_SLAPD} -d0 -F $env_vars->{SLAPD_CONF_D} -h $uri > $env_vars->{LDAPDIR}/logs 2>&1 &");
61 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
62 $count++;
63 if ($count > 40) {
64 $self->slapd_stop($env_vars);
65 return 0;
67 sleep(1);
69 return 1;
72 sub slapd_stop($$)
74 my ($self, $envvars) = @_;
75 if ($self->{ldap} eq "fedora-ds") {
76 system("$envvars->{LDAPDIR}/slapd-$envvars->{LDAP_INSTANCE}/stop-slapd");
77 } elsif ($self->{ldap} eq "openldap") {
78 unless (open(IN, "<$envvars->{OPENLDAP_PIDFILE}")) {
79 warn("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
80 return 0;
82 kill 9, <IN>;
83 close(IN);
85 return 1;
88 sub check_or_start($$$)
90 my ($self, $env_vars, $process_model) = @_;
91 return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
93 unlink($env_vars->{SAMBA_TEST_FIFO});
94 POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
95 unlink($env_vars->{SAMBA_TEST_LOG});
97 my $pwd = `pwd`;
98 print "STARTING SAMBA for $ENV{ENVNAME}\n";
99 my $pid = fork();
100 if ($pid == 0) {
101 open STDIN, $env_vars->{SAMBA_TEST_FIFO};
102 # we want out from samba to go to the log file, but also
103 # to the users terminal when running 'make test' on the command
104 # line. This puts it on stderr on the terminal
105 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
106 open STDERR, '>&STDOUT';
108 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
110 my $valgrind = "";
111 if (defined($ENV{SAMBA_VALGRIND})) {
112 $valgrind = $ENV{SAMBA_VALGRIND};
115 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
116 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
118 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
119 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
121 $ENV{UID_WRAPPER} = "1";
123 # Start slapd before samba, but with the fifo on stdin
124 if (defined($self->{ldap})) {
125 unless($self->slapd_start($env_vars)) {
126 warn("couldn't start slapd (main run)");
127 return undef;
131 my $optarg = "";
132 $optarg = "--maximum-runtime=$self->{server_maxtime}";
133 if (defined($ENV{SAMBA_OPTIONS})) {
134 $optarg.= " $ENV{SAMBA_OPTIONS}";
136 my $samba = Samba::bindir_path($self, "samba");
138 chomp($pwd);
139 my $cmdline = "$valgrind ${pwd}/$samba $optarg $env_vars->{CONFIGURATION} -M $process_model -i";
140 my $ret = system("$cmdline");
141 if ($ret == -1) {
142 print "Unable to start $cmdline: $ret: $!\n";
143 exit 1;
145 my $exit = ($ret >> 8);
146 unlink($env_vars->{SAMBA_TEST_FIFO});
147 if ($ret == 0) {
148 print "$samba exited with no error\n";
149 exit 0;
150 } elsif ( $ret & 127 ) {
151 print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
152 } else {
153 print "$samba failed with status $exit!\n";
155 if ($exit == 0) {
156 $exit = -1;
158 exit $exit;
160 print "DONE\n";
162 open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
164 return $pid;
167 sub wait_for_start($$)
169 my ($self, $testenv_vars) = @_;
170 # give time for nbt server to register its names
171 print "delaying for nbt name registration\n";
172 sleep 2;
174 # This will return quickly when things are up, but be slow if we
175 # need to wait for (eg) SSL init
176 my $nmblookup = Samba::bindir_path($self, "nmblookup");
177 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
178 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
179 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
180 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
181 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
182 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
183 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
184 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
185 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
186 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
187 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
188 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
190 print $self->getlog_env($testenv_vars);
193 sub write_ldb_file($$$)
195 my ($self, $file, $ldif) = @_;
197 my $ldbadd = Samba::bindir_path($self, "ldbadd");
198 open(LDIF, "|$ldbadd -H $file >/dev/null");
199 print LDIF $ldif;
200 return(close(LDIF));
203 sub add_wins_config($$)
205 my ($self, $privatedir) = @_;
207 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
208 dn: name=TORTURE_11,CN=PARTNERS
209 objectClass: wreplPartner
210 name: TORTURE_11
211 address: 127.0.0.11
212 pullInterval: 0
213 pushChangeCount: 0
214 type: 0x3
218 sub mk_fedora_ds($$)
220 my ($self, $ctx) = @_;
222 #Make the subdirectory be as fedora DS would expect
223 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
225 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
227 return ($fedora_ds_dir, $pidfile);
230 sub mk_openldap($$)
232 my ($self, $ctx) = @_;
234 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
235 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
237 return ($slapd_conf_d, $pidfile);
240 sub mk_keyblobs($$)
242 my ($self, $tlsdir) = @_;
244 #TLS and PKINIT crypto blobs
245 my $dhfile = "$tlsdir/dhparms.pem";
246 my $cafile = "$tlsdir/ca.pem";
247 my $certfile = "$tlsdir/cert.pem";
248 my $reqkdc = "$tlsdir/req-kdc.der";
249 my $kdccertfile = "$tlsdir/kdc.pem";
250 my $keyfile = "$tlsdir/key.pem";
251 my $adminkeyfile = "$tlsdir/adminkey.pem";
252 my $reqadmin = "$tlsdir/req-admin.der";
253 my $admincertfile = "$tlsdir/admincert.pem";
254 my $admincertupnfile = "$tlsdir/admincertupn.pem";
256 mkdir($tlsdir, 0777);
258 #This is specified here to avoid draining entropy on every run
259 open(DHFILE, ">$dhfile");
260 print DHFILE <<EOF;
261 -----BEGIN DH PARAMETERS-----
262 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
263 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
264 YX70obsCAQI=
265 -----END DH PARAMETERS-----
267 close(DHFILE);
269 #Likewise, we pregenerate the key material. This allows the
270 #other certificates to be pre-generated
271 open(KEYFILE, ">$keyfile");
272 print KEYFILE <<EOF;
273 -----BEGIN RSA PRIVATE KEY-----
274 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
275 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
276 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
277 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
278 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
279 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
280 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
281 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
282 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
283 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
284 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
285 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
286 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
287 -----END RSA PRIVATE KEY-----
289 close(KEYFILE);
291 open(ADMINKEYFILE, ">$adminkeyfile");
293 print ADMINKEYFILE <<EOF;
294 -----BEGIN RSA PRIVATE KEY-----
295 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
296 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
297 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
298 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
299 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
300 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
301 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
302 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
303 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
304 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
305 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
306 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
307 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
308 -----END RSA PRIVATE KEY-----
311 #generated with
312 # hxtool issue-certificate --self-signed --issue-ca \
313 # --ca-private-key="FILE:$KEYFILE" \
314 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
315 # --certificate="FILE:$CAFILE" --lifetime="25 years"
317 open(CAFILE, ">$cafile");
318 print CAFILE <<EOF;
319 -----BEGIN CERTIFICATE-----
320 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
321 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
322 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
323 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
324 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
325 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
326 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
327 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
328 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
329 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
330 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
331 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
332 -----END CERTIFICATE-----
335 #generated with GNUTLS internally in Samba.
337 open(CERTFILE, ">$certfile");
338 print CERTFILE <<EOF;
339 -----BEGIN CERTIFICATE-----
340 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
341 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
342 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
343 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
344 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
345 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
346 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
347 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
348 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
349 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
350 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
351 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
352 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
353 -----END CERTIFICATE-----
355 close(CERTFILE);
357 #KDC certificate
358 # hxtool request-create \
359 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
360 # --key="FILE:$KEYFILE" $KDCREQ
362 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
363 # --type="pkinit-kdc" \
364 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
365 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
366 # --lifetime="25 years"
368 open(KDCCERTFILE, ">$kdccertfile");
369 print KDCCERTFILE <<EOF;
370 -----BEGIN CERTIFICATE-----
371 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
372 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
373 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
374 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
375 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
376 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
377 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
378 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
379 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
380 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
381 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
382 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
383 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
384 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
385 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
386 -----END CERTIFICATE-----
389 # hxtool request-create \
390 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
391 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
393 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
394 # --type="pkinit-client" \
395 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
396 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
397 # --lifetime="25 years"
399 open(ADMINCERTFILE, ">$admincertfile");
400 print ADMINCERTFILE <<EOF;
401 -----BEGIN CERTIFICATE-----
402 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
403 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
404 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
405 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
406 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
407 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
408 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
409 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
410 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
411 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
412 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
413 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
414 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
415 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
416 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
417 -----END CERTIFICATE-----
419 close(ADMINCERTFILE);
421 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
422 # --type="pkinit-client" \
423 # --ms-upn="administrator@samba.example.com" \
424 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
425 # --lifetime="25 years"
427 open(ADMINCERTUPNFILE, ">$admincertupnfile");
428 print ADMINCERTUPNFILE <<EOF;
429 -----BEGIN CERTIFICATE-----
430 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
431 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
432 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
433 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
434 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
435 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
436 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
437 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
438 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
439 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
440 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
441 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
442 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
443 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
444 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
445 -----END CERTIFICATE-----
449 sub provision_raw_prepare($$$$$$$$$$)
451 my ($self, $prefix, $server_role, $hostname,
452 $domain, $realm, $functional_level,
453 $swiface, $password, $kdc_ipv4) = @_;
454 my $ctx;
455 my $netbiosname = uc($hostname);
457 unless(-d $prefix or mkdir($prefix, 0777)) {
458 warn("Unable to create $prefix");
459 return undef;
461 my $prefix_abs = abs_path($prefix);
463 die ("prefix=''") if $prefix_abs eq "";
464 die ("prefix='/'") if $prefix_abs eq "/";
466 unless (system("rm -rf $prefix_abs/*") == 0) {
467 warn("Unable to clean up");
470 $ctx->{prefix} = $prefix;
471 $ctx->{prefix_abs} = $prefix_abs;
473 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
475 $ctx->{server_role} = $server_role;
476 $ctx->{hostname} = $hostname;
477 $ctx->{netbiosname} = $netbiosname;
478 $ctx->{swiface} = $swiface;
479 $ctx->{password} = $password;
480 $ctx->{kdc_ipv4} = $kdc_ipv4;
482 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
483 $ctx->{username} = "Administrator";
484 $ctx->{domain} = $domain;
485 $ctx->{realm} = uc($realm);
486 $ctx->{dnsname} = lc($realm);
487 $ctx->{sid_generator} = "internal";
489 $ctx->{functional_level} = $functional_level;
491 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
492 chomp $unix_name;
493 $ctx->{unix_name} = $unix_name;
494 $ctx->{unix_uid} = $>;
495 $ctx->{unix_gids_str} = $);
496 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
498 $ctx->{etcdir} = "$prefix_abs/etc";
499 $ctx->{piddir} = "$prefix_abs/pid";
500 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
501 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
502 $ctx->{privatedir} = "$prefix_abs/private";
503 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
504 $ctx->{lockdir} = "$prefix_abs/lockdir";
505 $ctx->{statedir} = "$prefix_abs/statedir";
506 $ctx->{cachedir} = "$prefix_abs/cachedir";
507 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
508 $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
509 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
510 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
511 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
513 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
515 $ctx->{ipv4} = "127.0.0.$swiface";
516 $ctx->{interfaces} = "$ctx->{ipv4}/8";
518 push(@{$ctx->{directories}}, $ctx->{privatedir});
519 push(@{$ctx->{directories}}, $ctx->{etcdir});
520 push(@{$ctx->{directories}}, $ctx->{piddir});
521 push(@{$ctx->{directories}}, $ctx->{lockdir});
522 push(@{$ctx->{directories}}, $ctx->{statedir});
523 push(@{$ctx->{directories}}, $ctx->{cachedir});
525 $ctx->{smb_conf_extra_options} = "";
527 my @provision_options = ();
528 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
529 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
530 if (defined($ENV{GDB_PROVISION})) {
531 push (@provision_options, "gdb --args");
532 if (!defined($ENV{PYTHON})) {
533 push (@provision_options, "env");
534 push (@provision_options, "python");
537 if (defined($ENV{VALGRIND_PROVISION})) {
538 push (@provision_options, "valgrind");
539 if (!defined($ENV{PYTHON})) {
540 push (@provision_options, "env");
541 push (@provision_options, "python");
544 if (defined($ENV{PYTHON})) {
545 push (@provision_options, $ENV{PYTHON});
547 push (@provision_options, "$self->{srcdir}/source4/setup/provision");
548 push (@provision_options, "--configfile=$ctx->{smb_conf}");
549 push (@provision_options, "--host-name=$ctx->{hostname}");
550 push (@provision_options, "--host-ip=$ctx->{ipv4}");
551 push (@provision_options, "--quiet");
552 push (@provision_options, "--domain=$ctx->{domain}");
553 push (@provision_options, "--realm=$ctx->{realm}");
554 push (@provision_options, "--adminpass=$ctx->{password}");
555 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
556 push (@provision_options, "--machinepass=machine$ctx->{password}");
557 push (@provision_options, "--root=$ctx->{unix_name}");
558 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
559 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
560 push (@provision_options, "--dns-backend=BIND9_DLZ");
562 @{$ctx->{provision_options}} = @provision_options;
564 return $ctx;
568 # Step1 creates the basic configuration
570 sub provision_raw_step1($$)
572 my ($self, $ctx) = @_;
574 mkdir($_, 0777) foreach (@{$ctx->{directories}});
576 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
577 warn("can't open $ctx->{smb_conf}$?");
578 return undef;
580 my $acl = "false";
581 $acl = "true" if (defined $ENV{WITH_ACL});
582 print CONFFILE "
583 [global]
584 acl:search = $acl
585 netbios name = $ctx->{netbiosname}
586 posix:eadb = $ctx->{statedir}/eadb.tdb
587 workgroup = $ctx->{domain}
588 realm = $ctx->{realm}
589 private dir = $ctx->{privatedir}
590 pid directory = $ctx->{piddir}
591 ncalrpc dir = $ctx->{ncalrpcdir}
592 lock dir = $ctx->{lockdir}
593 state directory = $ctx->{statedir}
594 cache directory = $ctx->{cachedir}
595 winbindd socket directory = $ctx->{winbindd_socket_dir}
596 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
597 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
598 winbind separator = /
599 name resolve order = file bcast
600 interfaces = $ctx->{interfaces}
601 tls dh params file = $ctx->{tlsdir}/dhparms.pem
602 panic action = $RealBin/gdb_backtrace \%d
603 wins support = yes
604 server role = $ctx->{server_role}
605 server services = +echo +dns
606 notify:inotify = false
607 ldb:nosync = true
608 #We don't want to pass our self-tests if the PAC code is wrong
609 gensec:require_pac = true
610 log level = $ctx->{server_loglevel}
611 lanman auth = Yes
612 rndc command = true
613 dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file}
614 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate
615 resolv:host file = $ctx->{dns_host_file}
616 dreplsrv:periodic_startup_interval = 0
617 dsdb:schema update allowed = yes
619 passdb backend = samba4
621 # remove this again, when our smb2 client library
622 # supports signin on compound related requests
623 server signing = on
626 if (defined($ctx->{sid_generator}) && $ctx->{sid_generator} ne "internal") {
627 print CONFFILE "
628 sid generator = $ctx->{sid_generator}";
631 print CONFFILE "
633 # Begin extra options
634 $ctx->{smb_conf_extra_options}
635 # End extra options
637 close(CONFFILE);
639 $self->mk_keyblobs($ctx->{tlsdir});
641 #Default the KDC IP to the server's IP
642 if (not defined($ctx->{kdc_ipv4})) {
643 $ctx->{kdc_ipv4} = $ctx->{ipv4};
646 Samba::mk_krb5_conf($ctx, "");
648 open(PWD, ">$ctx->{nsswrap_passwd}");
649 print PWD "
650 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
651 $ctx->{unix_name}:x:$ctx->{unix_uid}:@{$ctx->{unix_gids}}[0]:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
652 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
654 close(PWD);
656 open(GRP, ">$ctx->{nsswrap_group}");
657 print GRP "
658 root:x:0:
659 wheel:x:10:
660 users:x:100:
661 nobody:x:65533:
662 nogroup:x:65534:nobody
664 close(GRP);
666 my $configuration = "--configfile=$ctx->{smb_conf}";
668 #Ensure the config file is valid before we start
669 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
670 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
671 system("$testparm -v --suppress-prompt $configuration >&2");
672 warn("Failed to create a valid smb.conf configuration $testparm!");
673 return undef;
675 unless (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) {
676 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
677 return undef;
680 my $ret = {
681 KRB5_CONFIG => $ctx->{krb5_conf},
682 PIDDIR => $ctx->{piddir},
683 SERVER => $ctx->{hostname},
684 SERVER_IP => $ctx->{ipv4},
685 NETBIOSNAME => $ctx->{netbiosname},
686 DOMAIN => $ctx->{domain},
687 USERNAME => $ctx->{username},
688 REALM => $ctx->{realm},
689 PASSWORD => $ctx->{password},
690 LDAPDIR => $ctx->{ldapdir},
691 LDAP_INSTANCE => $ctx->{ldap_instance},
692 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
693 NCALRPCDIR => $ctx->{ncalrpcdir},
694 LOCKDIR => $ctx->{lockdir},
695 STATEDIR => $ctx->{statedir},
696 CACHEDIR => $ctx->{cachedir},
697 SERVERCONFFILE => $ctx->{smb_conf},
698 CONFIGURATION => $configuration,
699 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
700 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
701 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
702 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
703 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
704 SAMBA_TEST_LOG_POS => 0,
707 return $ret;
711 # Step2 runs the provision script
713 sub provision_raw_step2($$$)
715 my ($self, $ctx, $ret) = @_;
717 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
718 unless (system($provision_cmd) == 0) {
719 warn("Unable to provision: \n$provision_cmd\n");
720 return undef;
723 return $ret;
726 sub provision($$$$$$$$$)
728 my ($self, $prefix, $server_role, $hostname,
729 $domain, $realm, $functional_level,
730 $swiface, $password, $kdc_ipv4, $extra_smbconf_options) = @_;
732 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
733 $hostname,
734 $domain, $realm, $functional_level,
735 $swiface, $password, $kdc_ipv4);
737 $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
738 push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
739 push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test1");
740 push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test2");
741 my $msdfs = "no";
742 $msdfs = "yes" if ($server_role eq "domain controller");
743 $ctx->{smb_conf_extra_options} = "
745 max xmit = 32K
746 server max protocol = SMB2
747 host msdfs = $msdfs
748 lanman auth = yes
750 $extra_smbconf_options
752 [tmp]
753 path = $ctx->{tmpdir}
754 read only = no
755 posix:sharedelay = 10000
756 posix:oplocktimeout = 3
757 posix:writetimeupdatedelay = 500000
759 [xcopy_share]
760 path = $ctx->{tmpdir}
761 read only = no
762 posix:sharedelay = 10000
763 posix:oplocktimeout = 3
764 posix:writetimeupdatedelay = 500000
766 [test1]
767 path = $ctx->{tmpdir}/test1
768 read only = no
769 posix:sharedelay = 10000
770 posix:oplocktimeout = 3
771 posix:writetimeupdatedelay = 50000
773 [test2]
774 path = $ctx->{tmpdir}/test2
775 read only = no
776 posix:sharedelay = 10000
777 posix:oplocktimeout = 3
778 posix:writetimeupdatedelay = 50000
780 [cifs]
781 read only = no
782 ntvfs handler = cifs
783 cifs:server = $ctx->{netbiosname}
784 cifs:share = tmp
785 cifs:use-s4u2proxy = yes
786 # There is no username specified here, instead the client is expected
787 # to log in with kerberos, and the serverwill use delegated credentials.
788 # Or the server tries s4u2self/s4u2proxy to impersonate the client
790 [simple]
791 path = $ctx->{tmpdir}
792 read only = no
793 ntvfs handler = simple
795 [sysvol]
796 path = $ctx->{statedir}/sysvol
797 read only = yes
799 [netlogon]
800 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
801 read only = no
803 [cifsposix]
804 copy = simple
805 ntvfs handler = cifsposix
808 if (defined($self->{ldap})) {
809 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
810 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
812 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
813 $ldap_uri =~ s|/|%2F|g;
814 $ldap_uri = "ldapi://$ldap_uri";
815 $ctx->{ldap_uri} = $ldap_uri;
816 if ($self->{ldap} eq "fedora-ds") {
817 $ctx->{sid_generator} = "backend";
820 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
823 my $ret = $self->provision_raw_step1($ctx);
824 unless (defined $ret) {
825 return undef;
828 if (defined($self->{ldap})) {
829 $ret->{LDAP_URI} = $ctx->{ldap_uri};
830 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
831 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
832 if ($self->{ldap} eq "openldap") {
833 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
834 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
836 } elsif ($self->{ldap} eq "fedora-ds") {
837 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
838 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
839 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
844 return $self->provision_raw_step2($ctx, $ret);
847 sub provision_member($$$)
849 my ($self, $prefix, $dcvars) = @_;
850 print "PROVISIONING MEMBER...";
852 my $ret = $self->provision($prefix,
853 "member server",
854 "s4member",
855 "SAMBADOMAIN",
856 "samba.example.com",
857 "2008",
859 "locMEMpass3",
860 $dcvars->{SERVER_IP},
861 "");
862 unless ($ret) {
863 return undef;
866 my $samba_tool = Samba::bindir_path($self, "samba-tool");
867 my $cmd = "";
868 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
869 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
870 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
871 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
872 $cmd .= " --machinepass=machine$ret->{password}";
874 unless (system($cmd) == 0) {
875 warn("Join failed\n$cmd");
876 return undef;
879 $ret->{MEMBER_SERVER} = $ret->{SERVER};
880 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
881 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
882 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
883 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
885 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
886 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
887 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
888 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
889 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
891 return $ret;
894 sub provision_rpc_proxy($$$)
896 my ($self, $prefix, $dcvars) = @_;
897 print "PROVISIONING RPC PROXY...";
899 my $extra_smbconf_options = "
901 # rpc_proxy
902 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
903 dcerpc endpoint servers = epmapper, remote
904 dcerpc_remote:interfaces = rpcecho
906 [cifs_to_dc]
907 read only = no
908 ntvfs handler = cifs
909 cifs:server = $dcvars->{SERVER}
910 cifs:share = cifs
911 cifs:use-s4u2proxy = yes
912 # There is no username specified here, instead the client is expected
913 # to log in with kerberos, and the serverwill use delegated credentials.
914 # Or the server tries s4u2self/s4u2proxy to impersonate the client
918 my $ret = $self->provision($prefix,
919 "member server",
920 "localrpcproxy",
921 "SAMBADOMAIN",
922 "samba.example.com",
923 "2008",
925 "locRPCproxypass4",
926 $dcvars->{SERVER_IP},
927 $extra_smbconf_options);
929 unless ($ret) {
930 return undef;
933 my $samba_tool = Samba::bindir_path($self, "samba-tool");
935 # The joind runs in the context of the rpc_proxy/member for now
936 my $cmd = "";
937 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
938 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
939 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
940 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
941 $cmd .= " --machinepass=machine$ret->{password}";
943 unless (system($cmd) == 0) {
944 warn("Join failed\n$cmd");
945 return undef;
948 # Setting up delegation runs in the context of the DC for now
949 $cmd = "";
950 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
951 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
952 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
953 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
955 unless (system($cmd) == 0) {
956 warn("Delegation failed\n$cmd");
957 return undef;
960 # Setting up delegation runs in the context of the DC for now
961 $cmd = "";
962 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
963 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
964 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
965 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
967 unless (system($cmd) == 0) {
968 warn("Delegation failed\n$cmd");
969 return undef;
972 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
973 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
974 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
975 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
976 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
978 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
979 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
980 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
981 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
982 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
984 return $ret;
987 sub provision_vampire_dc($$$)
989 my ($self, $prefix, $dcvars) = @_;
990 print "PROVISIONING VAMPIRE DC...";
992 # We do this so that we don't run the provision. That's the job of 'net vampire'.
993 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
994 "localvampiredc",
995 "SAMBADOMAIN",
996 "samba.example.com",
997 "2008",
998 22, $dcvars->{PASSWORD},
999 $dcvars->{SERVER_IP});
1001 $ctx->{smb_conf_extra_options} = "
1002 max xmit = 32K
1003 server max protocol = SMB2
1005 [sysvol]
1006 path = $ctx->{statedir}/sysvol
1007 read only = yes
1009 [netlogon]
1010 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1011 read only = no
1015 my $ret = $self->provision_raw_step1($ctx);
1016 unless ($ret) {
1017 return undef;
1020 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1021 my $cmd = "";
1022 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1023 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1024 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1025 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1026 $cmd .= " --machinepass=machine$ret->{password}";
1028 unless (system($cmd) == 0) {
1029 warn("Join failed\n$cmd");
1030 return undef;
1033 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1034 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1035 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1037 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1038 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1039 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1040 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1041 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1043 return $ret;
1046 sub provision_subdom_dc($$$)
1048 my ($self, $prefix, $dcvars) = @_;
1049 print "PROVISIONING SUBDOMAIN DC...";
1051 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1052 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1053 "localsubdc",
1054 "SAMBASUBDOM",
1055 "sub.samba.example.com",
1056 "2008",
1057 31, $dcvars->{PASSWORD},
1058 undef);
1060 $ctx->{smb_conf_extra_options} = "
1061 max xmit = 32K
1062 server max protocol = SMB2
1064 [sysvol]
1065 path = $ctx->{statedir}/sysvol
1066 read only = yes
1068 [netlogon]
1069 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1070 read only = no
1074 my $ret = $self->provision_raw_step1($ctx);
1075 unless ($ret) {
1076 return undef;
1079 my $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
1080 $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
1081 Samba::mk_krb5_conf($ctx, $dc_realms);
1083 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1084 my $cmd = "";
1085 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1086 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1087 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1088 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1089 $cmd .= " --machinepass=machine$ret->{password}";
1091 unless (system($cmd) == 0) {
1092 warn("Join failed\n$cmd");
1093 return undef;
1096 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1097 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1098 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1100 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1101 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1102 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1103 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1104 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1106 return $ret;
1109 sub provision_dc($$)
1111 my ($self, $prefix) = @_;
1113 print "PROVISIONING DC...";
1114 my $ret = $self->provision($prefix,
1115 "domain controller",
1116 "localdc",
1117 "SAMBADOMAIN",
1118 "samba.example.com",
1119 "2008",
1121 "locDCpass1",
1122 undef, "netbios aliases = DC1");
1124 return undef unless(defined $ret);
1125 unless($self->add_wins_config("$prefix/private")) {
1126 warn("Unable to add wins configuration");
1127 return undef;
1130 $ret->{NETBIOSALIAS} = "DC1";
1131 $ret->{DC_SERVER} = $ret->{SERVER};
1132 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1133 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1134 $ret->{DC_USERNAME} = $ret->{USERNAME};
1135 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1137 return $ret;
1140 sub provision_fl2000dc($$)
1142 my ($self, $prefix) = @_;
1144 print "PROVISIONING DC...";
1145 my $ret = $self->provision($prefix,
1146 "domain controller",
1147 "dc5",
1148 "SAMBA2000",
1149 "samba2000.example.com",
1150 "2000",
1152 "locDCpass5",
1153 undef, "");
1155 unless($self->add_wins_config("$prefix/private")) {
1156 warn("Unable to add wins configuration");
1157 return undef;
1160 return $ret;
1163 sub provision_fl2003dc($$)
1165 my ($self, $prefix) = @_;
1167 print "PROVISIONING DC...";
1168 my $ret = $self->provision($prefix,
1169 "domain controller",
1170 "dc6",
1171 "SAMBA2003",
1172 "samba2003.example.com",
1173 "2003",
1175 "locDCpass6",
1176 undef, "");
1178 unless($self->add_wins_config("$prefix/private")) {
1179 warn("Unable to add wins configuration");
1180 return undef;
1183 return $ret;
1186 sub provision_fl2008r2dc($$)
1188 my ($self, $prefix) = @_;
1190 print "PROVISIONING DC...";
1191 my $ret = $self->provision($prefix,
1192 "domain controller",
1193 "dc7",
1194 "SAMBA2008R2",
1195 "samba2008R2.example.com",
1196 "2008_R2",
1198 "locDCpass7",
1199 undef, "");
1201 unless ($self->add_wins_config("$prefix/private")) {
1202 warn("Unable to add wins configuration");
1203 return undef;
1206 return $ret;
1210 sub provision_rodc($$$)
1212 my ($self, $prefix, $dcvars) = @_;
1213 print "PROVISIONING RODC...";
1215 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1216 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1217 "rodc",
1218 "SAMBADOMAIN",
1219 "samba.example.com",
1220 "2008",
1221 28, $dcvars->{PASSWORD},
1222 $dcvars->{SERVER_IP});
1223 unless ($ctx) {
1224 return undef;
1227 $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
1228 push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
1230 $ctx->{smb_conf_extra_options} = "
1231 max xmit = 32K
1232 server max protocol = SMB2
1234 [sysvol]
1235 path = $ctx->{statedir}/sysvol
1236 read only = yes
1238 [netlogon]
1239 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1240 read only = yes
1242 [tmp]
1243 path = $ctx->{tmpdir}
1244 read only = no
1245 posix:sharedelay = 10000
1246 posix:oplocktimeout = 3
1247 posix:writetimeupdatedelay = 500000
1251 my $ret = $self->provision_raw_step1($ctx);
1252 unless ($ret) {
1253 return undef;
1256 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1257 my $cmd = "";
1258 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1259 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1260 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1261 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1262 $cmd .= " --server=$dcvars->{DC_SERVER}";
1264 unless (system($cmd) == 0) {
1265 warn("RODC join failed\n$cmd");
1266 return undef;
1269 # we overwrite the kdc after the RODC join
1270 # so that use the RODC as kdc and test
1271 # the proxy code
1272 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1273 Samba::mk_krb5_conf($ctx);
1275 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1276 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1277 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1279 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1280 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1281 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1282 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1283 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1285 return $ret;
1288 sub provision_plugin_s4_dc($$)
1290 my ($self, $prefix) = @_;
1292 my $extra_smbconf_options = "
1293 server services = -smb
1294 dcerpc endpoint servers = -unixinfo -rpcecho -spoolss -winreg -wkssvc -srvsvc
1297 print "PROVISIONING PLUGIN S4 DC...";
1298 my $ret = $self->provision($prefix,
1299 "domain controller",
1300 "plugindc",
1301 "PLUGINDOMAIN",
1302 "plugin.samba.example.com",
1303 "2008",
1305 "locDCpass1",
1306 undef, $extra_smbconf_options);
1308 return undef unless(defined $ret);
1309 unless($self->add_wins_config("$prefix/private")) {
1310 warn("Unable to add wins configuration");
1311 return undef;
1314 $ret->{DC_SERVER} = $ret->{SERVER};
1315 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1316 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1317 $ret->{DC_USERNAME} = $ret->{USERNAME};
1318 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1320 return $ret;
1323 sub teardown_env($$)
1325 my ($self, $envvars) = @_;
1326 my $pid;
1328 close(DATA);
1330 if (open(IN, "<$envvars->{PIDDIR}/samba.pid")) {
1331 $pid = <IN>;
1332 close(IN);
1334 # Give the process 20 seconds to exit. gcov needs
1335 # this time to write out the covarge data
1336 my $count = 0;
1337 until (kill(0, $pid) == 0) {
1338 # if no process sucessfully signalled, then we are done
1339 sleep(1);
1340 $count++;
1341 last if $count > 20;
1344 # If it is still around, kill it
1345 if ($count > 20) {
1346 print "server process $pid took more than $count seconds to exit, killing\n";
1347 kill 9, $pid;
1351 my $failed = $? >> 8;
1353 $self->slapd_stop($envvars) if ($self->{ldap});
1355 print $self->getlog_env($envvars);
1357 return $failed;
1360 sub getlog_env($$)
1362 my ($self, $envvars) = @_;
1363 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1364 my $out = $title;
1366 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1368 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1369 while (<LOG>) {
1370 $out .= $_;
1372 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1373 close(LOG);
1375 return "" if $out eq $title;
1377 return $out;
1380 sub check_env($$)
1382 my ($self, $envvars) = @_;
1384 return (-p $envvars->{SAMBA_TEST_FIFO});
1387 sub setup_env($$$)
1389 my ($self, $envname, $path) = @_;
1390 my $target3 = $self->{target3};
1392 $ENV{ENVNAME} = $envname;
1394 if ($envname eq "dc") {
1395 return $self->setup_dc("$path/dc");
1396 } elsif ($envname eq "fl2000dc") {
1397 return $self->setup_fl2000dc("$path/fl2000dc");
1398 } elsif ($envname eq "fl2003dc") {
1399 return $self->setup_fl2003dc("$path/fl2003dc");
1400 } elsif ($envname eq "fl2008r2dc") {
1401 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1402 } elsif ($envname eq "rpc_proxy") {
1403 if (not defined($self->{vars}->{dc})) {
1404 $self->setup_dc("$path/dc");
1406 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1407 } elsif ($envname eq "vampire_dc") {
1408 if (not defined($self->{vars}->{dc})) {
1409 $self->setup_dc("$path/dc");
1411 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1412 } elsif ($envname eq "subdom_dc") {
1413 if (not defined($self->{vars}->{dc})) {
1414 $self->setup_dc("$path/dc");
1416 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
1417 } elsif ($envname eq "s4member") {
1418 if (not defined($self->{vars}->{dc})) {
1419 $self->setup_dc("$path/dc");
1421 return $self->setup_member("$path/s4member", $self->{vars}->{dc});
1422 } elsif ($envname eq "rodc") {
1423 if (not defined($self->{vars}->{dc})) {
1424 $self->setup_dc("$path/dc");
1426 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1427 } elsif ($envname eq "s3member") {
1428 if (not defined($self->{vars}->{dc})) {
1429 $self->setup_dc("$path/dc");
1431 return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
1432 } elsif ($envname eq "plugin_s4_dc") {
1433 return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
1434 } else {
1435 return undef;
1439 sub setup_member($$$)
1441 my ($self, $path, $dc_vars) = @_;
1443 my $env = $self->provision_member($path, $dc_vars);
1445 if (defined $env) {
1446 $self->check_or_start($env, "single");
1448 $self->wait_for_start($env);
1450 $self->{vars}->{member} = $env;
1453 return $env;
1456 sub setup_rpc_proxy($$$)
1458 my ($self, $path, $dc_vars) = @_;
1460 my $env = $self->provision_rpc_proxy($path, $dc_vars);
1462 if (defined $env) {
1463 $self->check_or_start($env, "single");
1465 $self->wait_for_start($env);
1467 $self->{vars}->{rpc_proxy} = $env;
1469 return $env;
1472 sub setup_dc($$)
1474 my ($self, $path) = @_;
1476 my $env = $self->provision_dc($path);
1477 if (defined $env) {
1478 $self->check_or_start($env, "standard");
1480 $self->wait_for_start($env);
1482 $self->{vars}->{dc} = $env;
1484 return $env;
1487 sub setup_fl2000dc($$)
1489 my ($self, $path) = @_;
1491 my $env = $self->provision_fl2000dc($path);
1492 if (defined $env) {
1493 $self->check_or_start($env, "single");
1495 $self->wait_for_start($env);
1497 $self->{vars}->{fl2000dc} = $env;
1500 return $env;
1503 sub setup_fl2003dc($$)
1505 my ($self, $path) = @_;
1507 my $env = $self->provision_fl2003dc($path);
1509 if (defined $env) {
1510 $self->check_or_start($env, "single");
1512 $self->wait_for_start($env);
1514 $self->{vars}->{fl2003dc} = $env;
1516 return $env;
1519 sub setup_fl2008r2dc($$)
1521 my ($self, $path) = @_;
1523 my $env = $self->provision_fl2008r2dc($path);
1525 if (defined $env) {
1526 $self->check_or_start($env, "single");
1528 $self->wait_for_start($env);
1530 $self->{vars}->{fl2008r2dc} = $env;
1533 return $env;
1536 sub setup_vampire_dc($$$)
1538 my ($self, $path, $dc_vars) = @_;
1540 my $env = $self->provision_vampire_dc($path, $dc_vars);
1542 if (defined $env) {
1543 $self->check_or_start($env, "single");
1545 $self->wait_for_start($env);
1547 $self->{vars}->{vampire_dc} = $env;
1549 # force replicated DC to update repsTo/repsFrom
1550 # for vampired partitions
1551 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1552 my $cmd = "";
1553 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1554 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1555 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1556 $cmd .= " $env->{CONFIGURATION}";
1557 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1558 unless (system($cmd) == 0) {
1559 warn("Failed to exec kcc\n$cmd");
1560 return undef;
1563 # as 'vampired' dc may add data in its local replica
1564 # we need to synchronize data between DCs
1565 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1566 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1567 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1568 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{VAMPIRE_DC_SERVER}";
1569 $cmd .= " $dc_vars->{CONFIGURATION}";
1570 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1571 # replicate Configuration NC
1572 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1573 unless(system($cmd_repl) == 0) {
1574 warn("Failed to replicate\n$cmd_repl");
1575 return undef;
1577 # replicate Default NC
1578 $cmd_repl = "$cmd \"$base_dn\"";
1579 unless(system($cmd_repl) == 0) {
1580 warn("Failed to replicate\n$cmd_repl");
1581 return undef;
1585 return $env;
1588 sub setup_subdom_dc($$$)
1590 my ($self, $path, $dc_vars) = @_;
1592 my $env = $self->provision_subdom_dc($path, $dc_vars);
1594 if (defined $env) {
1595 $self->check_or_start($env, "single");
1597 $self->wait_for_start($env);
1599 $self->{vars}->{subdom_dc} = $env;
1601 # force replicated DC to update repsTo/repsFrom
1602 # for primary domain partitions
1603 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1604 my $cmd = "";
1605 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1606 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1607 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1608 $cmd .= " $env->{CONFIGURATION}";
1609 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1610 unless (system($cmd) == 0) {
1611 warn("Failed to exec kcc\n$cmd");
1612 return undef;
1615 # as 'subdomain' dc may add data in its local replica
1616 # we need to synchronize data between DCs
1617 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
1618 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1619 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1620 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1621 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
1622 $cmd .= " $dc_vars->{CONFIGURATION}";
1623 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1624 # replicate Configuration NC
1625 my $cmd_repl = "$cmd \"$config_dn\"";
1626 unless(system($cmd_repl) == 0) {
1627 warn("Failed to replicate\n$cmd_repl");
1628 return undef;
1630 # replicate Default NC
1631 $cmd_repl = "$cmd \"$base_dn\"";
1632 unless(system($cmd_repl) == 0) {
1633 warn("Failed to replicate\n$cmd_repl");
1634 return undef;
1638 return $env;
1641 sub setup_rodc($$$)
1643 my ($self, $path, $dc_vars) = @_;
1645 my $env = $self->provision_rodc($path, $dc_vars);
1647 unless ($env) {
1648 return undef;
1651 $self->check_or_start($env, "single");
1653 $self->wait_for_start($env);
1655 $self->{vars}->{rodc} = $env;
1657 return $env;
1660 sub setup_plugin_s4_dc($$)
1662 my ($self, $path) = @_;
1664 my $env = $self->provision_plugin_s4_dc($path);
1665 if (defined $env) {
1666 $self->check_or_start($env, "single");
1668 $self->wait_for_start($env);
1670 my $s3_part_env = $self->{target3}->setup_plugin_s4_dc($path, $env, 30);
1671 if (not defined($s3_part_env)) {
1672 return undef;
1675 $self->{vars}->{plugin_s4_dc} = $s3_part_env;
1677 return $env;