selftest: move all winbind test rules to one place
[samba.git] / selftest / target / Samba4.pm
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
5
6 package Samba4;
7
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12 use SocketWrapper;
13 use target::Samba;
14 use target::Samba3;
15
16 sub new($$$$$) {
17         my ($classname, $bindir, $binary_mapping, $ldap, $srcdir, $server_maxtime) = @_;
18
19         my $self = {
20                 vars => {},
21                 ldap => $ldap,
22                 bindir => $bindir,
23                 binary_mapping => $binary_mapping,
24                 srcdir => $srcdir,
25                 server_maxtime => $server_maxtime,
26                 target3 => new Samba3($bindir, $binary_mapping, $srcdir, $server_maxtime)
27         };
28         bless $self;
29         return $self;
30 }
31
32 sub scriptdir_path($$) {
33         my ($self, $path) = @_;
34         return "$self->{srcdir}/source4/scripting/$path";
35 }
36
37 sub openldap_start($$$) {
38 }
39
40 sub slapd_start($$)
41 {
42         my $count = 0;
43         my ($self, $env_vars, $STDIN_READER) = @_;
44         my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
45
46         my $uri = $env_vars->{LDAP_URI};
47
48         if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
49             print "A SLAPD is still listening to $uri before we started the LDAP backend.  Aborting!";
50             return 1;
51         }
52         # running slapd in the background means it stays in the same process group, so it can be
53         # killed by timelimit
54         my $pid = fork();
55         if ($pid == 0) {
56                 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
57                 open STDERR, '>&STDOUT';
58                 close($env_vars->{STDIN_PIPE});
59                 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
60
61                 if ($self->{ldap} eq "fedora-ds") {
62                         exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
63                 } elsif ($self->{ldap} eq "openldap") {
64                         exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
65                 }
66                 die("Unable to start slapd: $!");
67         }
68         $env_vars->{SLAPD_PID} = $pid;
69         sleep(1);
70         while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
71                 $count++;
72                 if ($count > 40) {
73                         $self->slapd_stop($env_vars);
74                         return 0;
75                 }
76                 sleep(1);
77         }
78         return 1;
79 }
80
81 sub slapd_stop($$)
82 {
83         my ($self, $envvars) = @_;
84         kill 9, $envvars->{SLAPD_PID};
85         return 1;
86 }
87
88 sub check_or_start($$$)
89 {
90         my ($self, $env_vars, $process_model) = @_;
91         my $STDIN_READER;
92
93         return 0 if $self->check_env($env_vars);
94
95         # use a pipe for stdin in the child processes. This allows
96         # those processes to monitor the pipe for EOF to ensure they
97         # exit when the test script exits
98         pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
99
100         # Start slapd before samba, but with the fifo on stdin
101         if (defined($self->{ldap})) {
102                 unless($self->slapd_start($env_vars, $STDIN_READER)) {
103                         warn("couldn't start slapd (main run)");
104                         return undef;
105                 }
106         }
107
108         print "STARTING SAMBA...";
109         my $pid = fork();
110         if ($pid == 0) {
111                 # we want out from samba to go to the log file, but also
112                 # to the users terminal when running 'make test' on the command
113                 # line. This puts it on stderr on the terminal
114                 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
115                 open STDERR, '>&STDOUT';
116
117                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
118
119                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
120                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
121                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
122
123                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
124                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
125                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
126                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
127                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
128
129                 $ENV{UID_WRAPPER} = "1";
130
131                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
132                 my @preargs = ();
133                 my @optargs = ();
134                 if (defined($ENV{SAMBA_OPTIONS})) {
135                         @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
136                 }
137                 if(defined($ENV{SAMBA_VALGRIND})) {
138                         @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
139                 }
140
141                 close($env_vars->{STDIN_PIPE});
142                 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
143
144                 exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
145         }
146         $env_vars->{SAMBA_PID} = $pid;
147         print "DONE\n";
148
149         close($STDIN_READER);
150
151         return $pid;
152 }
153
154 sub wait_for_start($$)
155 {
156         my ($self, $testenv_vars) = @_;
157         my $ret;
158         # give time for nbt server to register its names
159         print "delaying for nbt name registration\n";
160         sleep 2;
161
162         # This will return quickly when things are up, but be slow if we
163         # need to wait for (eg) SSL init
164         my $nmblookup =  Samba::bindir_path($self, "nmblookup4");
165         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
166         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
167         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
168         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
169         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
170         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
171         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
172         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
173         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
174         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
175         system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
176         system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
177
178         # Ensure we have the first RID Set before we start tests.  This makes the tests more reliable.
179         if ($testenv_vars->{SERVER_ROLE} eq "domain controller" and not ($testenv_vars->{NETBIOS_NAME} eq "rodc")) {
180             # Add hosts file for name lookups
181             $ENV{NSS_WRAPPER_HOSTS} = $testenv_vars->{NSS_WRAPPER_HOSTS};
182
183             print "waiting for working LDAP and a RID Set to be allocated\n";
184             my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
185             my $count = 0;
186             my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
187             my $rid_set_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
188             sleep(1);
189             while (system("$ldbsearch -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$rid_set_dn\" rIDAllocationPool > /dev/null") != 0) {
190                 $count++;
191                 if ($count > 40) {
192                     $ret = 1;
193                     last;
194                 }
195                 sleep(1);
196             }
197         }
198         print $self->getlog_env($testenv_vars);
199
200         return $ret
201 }
202
203 sub write_ldb_file($$$)
204 {
205         my ($self, $file, $ldif) = @_;
206
207         my $ldbadd =  Samba::bindir_path($self, "ldbadd");
208         open(LDIF, "|$ldbadd -H $file >/dev/null");
209         print LDIF $ldif;
210         return(close(LDIF));
211 }
212
213 sub add_wins_config($$)
214 {
215         my ($self, $privatedir) = @_;
216
217         return $self->write_ldb_file("$privatedir/wins_config.ldb", "
218 dn: name=TORTURE_11,CN=PARTNERS
219 objectClass: wreplPartner
220 name: TORTURE_11
221 address: 127.0.0.11
222 pullInterval: 0
223 pushChangeCount: 0
224 type: 0x3
225 ");
226 }
227
228 sub mk_fedora_ds($$)
229 {
230         my ($self, $ctx) = @_;
231
232         #Make the subdirectory be as fedora DS would expect
233         my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
234
235         my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
236
237         return ($fedora_ds_dir, $pidfile);
238 }
239
240 sub mk_openldap($$)
241 {
242         my ($self, $ctx) = @_;
243
244         my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
245         my $pidfile = "$ctx->{ldapdir}/slapd.pid";
246
247         return ($slapd_conf_d, $pidfile);
248 }
249
250 sub mk_keyblobs($$)
251 {
252         my ($self, $tlsdir) = @_;
253
254         #TLS and PKINIT crypto blobs
255         my $dhfile = "$tlsdir/dhparms.pem";
256         my $cafile = "$tlsdir/ca.pem";
257         my $certfile = "$tlsdir/cert.pem";
258         my $reqkdc = "$tlsdir/req-kdc.der";
259         my $kdccertfile = "$tlsdir/kdc.pem";
260         my $keyfile = "$tlsdir/key.pem";
261         my $adminkeyfile = "$tlsdir/adminkey.pem";
262         my $reqadmin = "$tlsdir/req-admin.der";
263         my $admincertfile = "$tlsdir/admincert.pem";
264         my $admincertupnfile = "$tlsdir/admincertupn.pem";
265
266         mkdir($tlsdir, 0700);
267         my $oldumask = umask;
268         umask 0077;
269
270         #This is specified here to avoid draining entropy on every run
271         open(DHFILE, ">$dhfile");
272         print DHFILE <<EOF;
273 -----BEGIN DH PARAMETERS-----
274 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
275 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
276 YX70obsCAQI=
277 -----END DH PARAMETERS-----
278 EOF
279         close(DHFILE);
280
281         #Likewise, we pregenerate the key material.  This allows the
282         #other certificates to be pre-generated
283         open(KEYFILE, ">$keyfile");
284         print KEYFILE <<EOF;
285 -----BEGIN RSA PRIVATE KEY-----
286 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
287 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
288 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
289 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
290 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
291 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
292 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
293 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
294 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
295 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
296 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
297 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
298 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
299 -----END RSA PRIVATE KEY-----
300 EOF
301         close(KEYFILE);
302
303         open(ADMINKEYFILE, ">$adminkeyfile");
304
305         print ADMINKEYFILE <<EOF;
306 -----BEGIN RSA PRIVATE KEY-----
307 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
308 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
309 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
310 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
311 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
312 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
313 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
314 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
315 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
316 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
317 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
318 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
319 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
320 -----END RSA PRIVATE KEY-----
321 EOF
322
323         #generated with
324         # hxtool issue-certificate --self-signed --issue-ca \
325         # --ca-private-key="FILE:$KEYFILE" \
326         # --subject="CN=CA,DC=samba,DC=example,DC=com" \
327         # --certificate="FILE:$CAFILE" --lifetime="25 years"
328
329         open(CAFILE, ">$cafile");
330         print CAFILE <<EOF;
331 -----BEGIN CERTIFICATE-----
332 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
333 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
334 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
335 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
336 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
337 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
338 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
339 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
340 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
341 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
342 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
343 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
344 -----END CERTIFICATE-----
345 EOF
346
347         #generated with GNUTLS internally in Samba.
348
349         open(CERTFILE, ">$certfile");
350         print CERTFILE <<EOF;
351 -----BEGIN CERTIFICATE-----
352 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
353 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
354 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
355 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
356 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
357 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
358 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
359 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
360 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
361 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
362 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
363 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
364 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
365 -----END CERTIFICATE-----
366 EOF
367         close(CERTFILE);
368
369         #KDC certificate
370         # hxtool request-create \
371         # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
372         # --key="FILE:$KEYFILE" $KDCREQ
373
374         # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
375         # --type="pkinit-kdc" \
376         # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
377         # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
378         # --lifetime="25 years"
379
380         open(KDCCERTFILE, ">$kdccertfile");
381         print KDCCERTFILE <<EOF;
382 -----BEGIN CERTIFICATE-----
383 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
384 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
385 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
386 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
387 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
388 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
389 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
390 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
391 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
392 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
393 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
394 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
395 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
396 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
397 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
398 -----END CERTIFICATE-----
399 EOF
400
401         # hxtool request-create \
402         # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
403         # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
404
405         # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
406         # --type="pkinit-client" \
407         # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
408         # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
409         # --lifetime="25 years"
410         
411         open(ADMINCERTFILE, ">$admincertfile");
412         print ADMINCERTFILE <<EOF;
413 -----BEGIN CERTIFICATE-----
414 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
415 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
416 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
417 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
418 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
419 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
420 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
421 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
422 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
423 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
424 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
425 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
426 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
427 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
428 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
429 -----END CERTIFICATE-----
430 EOF
431         close(ADMINCERTFILE);
432
433         # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
434         # --type="pkinit-client" \
435         # --ms-upn="administrator@samba.example.com" \
436         # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
437         # --lifetime="25 years"
438         
439         open(ADMINCERTUPNFILE, ">$admincertupnfile");
440         print ADMINCERTUPNFILE <<EOF;
441 -----BEGIN CERTIFICATE-----
442 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
443 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
444 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
445 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
446 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
447 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
448 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
449 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
450 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
451 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
452 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
453 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
454 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
455 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
456 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
457 -----END CERTIFICATE-----
458 EOF
459
460         umask $oldumask;
461 }
462
463 sub provision_raw_prepare($$$$$$$$$$)
464 {
465         my ($self, $prefix, $server_role, $hostname,
466             $domain, $realm, $functional_level,
467             $password, $kdc_ipv4) = @_;
468         my $ctx;
469         my $netbiosname = uc($hostname);
470
471         unless(-d $prefix or mkdir($prefix, 0777)) {
472                 warn("Unable to create $prefix");
473                 return undef;
474         }
475         my $prefix_abs = abs_path($prefix);
476
477         die ("prefix=''") if $prefix_abs eq "";
478         die ("prefix='/'") if $prefix_abs eq "/";
479
480         unless (system("rm -rf $prefix_abs/*") == 0) {
481                 warn("Unable to clean up");
482         }
483
484         
485         my $swiface = Samba::get_interface($hostname);
486
487         $ctx->{prefix} = $prefix;
488         $ctx->{prefix_abs} = $prefix_abs;
489         
490         $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
491
492         $ctx->{server_role} = $server_role;
493         $ctx->{hostname} = $hostname;
494         $ctx->{netbiosname} = $netbiosname;
495         $ctx->{swiface} = $swiface;
496         $ctx->{password} = $password;
497         $ctx->{kdc_ipv4} = $kdc_ipv4;
498
499 #
500 # Set smbd log level here.
501 #
502         $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
503         $ctx->{username} = "Administrator";
504         $ctx->{domain} = $domain;
505         $ctx->{realm} = uc($realm);
506         $ctx->{dnsname} = lc($realm);
507
508         $ctx->{functional_level} = $functional_level;
509
510         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
511         chomp $unix_name;
512         $ctx->{unix_name} = $unix_name;
513         $ctx->{unix_uid} = $>;
514         my @mygid = split(" ", $();
515         $ctx->{unix_gid} = $mygid[0];
516         $ctx->{unix_gids_str} = $);
517         @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
518
519         $ctx->{etcdir} = "$prefix_abs/etc";
520         $ctx->{piddir} = "$prefix_abs/pid";
521         $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
522         $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
523         $ctx->{privatedir} = "$prefix_abs/private";
524         $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
525         $ctx->{lockdir} = "$prefix_abs/lockdir";
526         $ctx->{logdir} = "$prefix_abs/logs";
527         $ctx->{statedir} = "$prefix_abs/statedir";
528         $ctx->{cachedir} = "$prefix_abs/cachedir";
529         $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
530         $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
531         $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
532         $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
533         $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
534         $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
535
536         $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
537
538         $ctx->{ipv4} = "127.0.0.$swiface";
539         $ctx->{interfaces} = "$ctx->{ipv4}/8";
540
541         push(@{$ctx->{directories}}, $ctx->{privatedir});
542         push(@{$ctx->{directories}}, $ctx->{etcdir});
543         push(@{$ctx->{directories}}, $ctx->{piddir});
544         push(@{$ctx->{directories}}, $ctx->{lockdir});
545         push(@{$ctx->{directories}}, $ctx->{logdir});
546         push(@{$ctx->{directories}}, $ctx->{statedir});
547         push(@{$ctx->{directories}}, $ctx->{cachedir});
548
549         $ctx->{smb_conf_extra_options} = "";
550
551         my @provision_options = ();
552         push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
553         push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
554         push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
555         if (defined($ENV{GDB_PROVISION})) {
556                 push (@provision_options, "gdb --args");
557                 if (!defined($ENV{PYTHON})) {
558                     push (@provision_options, "env");
559                     push (@provision_options, "python");
560                 }
561         }
562         if (defined($ENV{VALGRIND_PROVISION})) {
563                 push (@provision_options, "valgrind");
564                 if (!defined($ENV{PYTHON})) {
565                     push (@provision_options, "env");
566                     push (@provision_options, "python");
567                 }
568         }
569         if (defined($ENV{PYTHON})) {
570                 push (@provision_options, $ENV{PYTHON});
571         }
572         push (@provision_options, Samba::bindir_path($self, "samba-tool"));
573         push (@provision_options, "domain");
574         push (@provision_options, "provision");
575         push (@provision_options, "--configfile=$ctx->{smb_conf}");
576         push (@provision_options, "--host-name=$ctx->{hostname}");
577         push (@provision_options, "--host-ip=$ctx->{ipv4}");
578         push (@provision_options, "--quiet");
579         push (@provision_options, "--domain=$ctx->{domain}");
580         push (@provision_options, "--realm=$ctx->{realm}");
581         push (@provision_options, "--adminpass=$ctx->{password}");
582         push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
583         push (@provision_options, "--machinepass=machine$ctx->{password}");
584         push (@provision_options, "--root=$ctx->{unix_name}");
585         push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
586         push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
587
588         @{$ctx->{provision_options}} = @provision_options;
589
590         return $ctx;
591 }
592
593 #
594 # Step1 creates the basic configuration
595 #
596 sub provision_raw_step1($$)
597 {
598         my ($self, $ctx) = @_;
599
600         mkdir($_, 0777) foreach (@{$ctx->{directories}});
601
602         ##
603         ## lockdir and piddir must be 0755
604         ##
605         chmod 0755, $ctx->{lockdir};
606         chmod 0755, $ctx->{piddir};
607
608         unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
609                 warn("can't open $ctx->{smb_conf}$?");
610                 return undef;
611         }
612         print CONFFILE "
613 [global]
614         netbios name = $ctx->{netbiosname}
615         posix:eadb = $ctx->{statedir}/eadb.tdb
616         workgroup = $ctx->{domain}
617         realm = $ctx->{realm}
618         private dir = $ctx->{privatedir}
619         pid directory = $ctx->{piddir}
620         ncalrpc dir = $ctx->{ncalrpcdir}
621         lock dir = $ctx->{lockdir}
622         state directory = $ctx->{statedir}
623         cache directory = $ctx->{cachedir}
624         winbindd socket directory = $ctx->{winbindd_socket_dir}
625         winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
626         ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
627         winbind separator = /
628         name resolve order = file bcast
629         interfaces = $ctx->{interfaces}
630         tls dh params file = $ctx->{tlsdir}/dhparms.pem
631         panic action = $RealBin/gdb_backtrace \%d
632         wins support = yes
633         server role = $ctx->{server_role}
634         server services = +echo +smb -s3fs
635         dcerpc endpoint servers = +winreg +srvsvc
636         notify:inotify = false
637         ldb:nosync = true
638 #We don't want to pass our self-tests if the PAC code is wrong
639         gensec:require_pac = true
640         log file = $ctx->{logdir}/log.\%m
641         log level = $ctx->{server_loglevel}
642         lanman auth = Yes
643         rndc command = true
644         dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file} -s $ctx->{smb_conf}
645         spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
646         resolv:host file = $ctx->{dns_host_file}
647         dreplsrv:periodic_startup_interval = 0
648         dsdb:schema update allowed = yes
649
650         vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
651
652         # remove this again, when our smb2 client library
653         # supports signin on compound related requests
654         server signing = on
655
656         idmap_ldb:use rfc2307=yes
657         winbind enum users = yes
658         winbind enum groups = yes
659 ";
660
661         print CONFFILE "
662
663         # Begin extra options
664         $ctx->{smb_conf_extra_options}
665         # End extra options
666 ";
667         close(CONFFILE);
668
669         $self->mk_keyblobs($ctx->{tlsdir});
670
671         #Default the KDC IP to the server's IP
672         if (not defined($ctx->{kdc_ipv4})) {
673              $ctx->{kdc_ipv4} = $ctx->{ipv4};
674         }
675
676         Samba::mk_krb5_conf($ctx, "");
677
678         open(PWD, ">$ctx->{nsswrap_passwd}");
679         print PWD "
680 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
681 $ctx->{unix_name}:x:$ctx->{unix_uid}:100:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
682 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
683 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
684 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
685 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
686 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
687 ";
688         close(PWD);
689         my $uid_rfc2307test = 65533;
690
691         open(GRP, ">$ctx->{nsswrap_group}");
692         print GRP "
693 root:x:0:
694 wheel:x:10:
695 users:x:100:
696 nobody:x:65533:
697 nogroup:x:65534:nobody
698 $ctx->{unix_name}:x:$ctx->{unix_gid}:
699 ";
700         close(GRP);
701         my $gid_rfc2307test = 65532;
702
703         my $hostname = lc($ctx->{hostname});
704         open(HOSTS, ">>$ctx->{nsswrap_hosts}");
705         print HOSTS "$ctx->{ipv4} ${hostname}.samba.example.com ${hostname}
706 ";
707         close(HOSTS);
708
709         my $configuration = "--configfile=$ctx->{smb_conf}";
710
711 #Ensure the config file is valid before we start
712         my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
713         if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
714                 system("$testparm -v --suppress-prompt $configuration >&2");
715                 warn("Failed to create a valid smb.conf configuration $testparm!");
716                 return undef;
717         }
718         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) {
719                 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
720                 return undef;
721         }
722
723         my $ret = {
724                 KRB5_CONFIG => $ctx->{krb5_conf},
725                 PIDDIR => $ctx->{piddir},
726                 SERVER => $ctx->{hostname},
727                 SERVER_IP => $ctx->{ipv4},
728                 NETBIOSNAME => $ctx->{netbiosname},
729                 DOMAIN => $ctx->{domain},
730                 USERNAME => $ctx->{username},
731                 REALM => $ctx->{realm},
732                 PASSWORD => $ctx->{password},
733                 LDAPDIR => $ctx->{ldapdir},
734                 LDAP_INSTANCE => $ctx->{ldap_instance},
735                 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
736                 NCALRPCDIR => $ctx->{ncalrpcdir},
737                 LOCKDIR => $ctx->{lockdir},
738                 STATEDIR => $ctx->{statedir},
739                 CACHEDIR => $ctx->{cachedir},
740                 PRIVATEDIR => $ctx->{privatedir},
741                 SERVERCONFFILE => $ctx->{smb_conf},
742                 CONFIGURATION => $configuration,
743                 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
744                 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
745                 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
746                 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
747                 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
748                 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
749                 SAMBA_TEST_LOG_POS => 0,
750                 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
751                 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
752                 LOCAL_PATH => $ctx->{share},
753                 UID_RFC2307TEST => $uid_rfc2307test,
754                 GID_RFC2307TEST => $gid_rfc2307test,
755                 SERVER_ROLE => $ctx->{server_role}
756         };
757
758         return $ret;
759 }
760
761 #
762 # Step2 runs the provision script
763 #
764 sub provision_raw_step2($$$)
765 {
766         my ($self, $ctx, $ret) = @_;
767
768         my $provision_cmd = join(" ", @{$ctx->{provision_options}});
769         unless (system($provision_cmd) == 0) {
770                 warn("Unable to provision: \n$provision_cmd\n");
771                 return undef;
772         }
773
774         return $ret;
775 }
776
777 sub provision($$$$$$$$$)
778 {
779         my ($self, $prefix, $server_role, $hostname,
780             $domain, $realm, $functional_level,
781             $password, $kdc_ipv4, $extra_smbconf_options, $extra_smbconf_shares,
782             $extra_provision_options) = @_;
783
784         my $ctx = $self->provision_raw_prepare($prefix, $server_role,
785                                                $hostname,
786                                                $domain, $realm, $functional_level,
787                                                $password, $kdc_ipv4);
788
789         if (defined($extra_provision_options)) {
790                 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
791         } else {
792                 push (@{$ctx->{provision_options}}, "--use-ntvfs");
793         }
794
795         $ctx->{share} = "$ctx->{prefix_abs}/share";
796         push(@{$ctx->{directories}}, "$ctx->{share}");
797         push(@{$ctx->{directories}}, "$ctx->{share}/test1");
798         push(@{$ctx->{directories}}, "$ctx->{share}/test2");
799
800         # precreate directories for printer drivers
801         push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
802         push(@{$ctx->{directories}}, "$ctx->{share}/x64");
803         push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
804
805         my $msdfs = "no";
806         $msdfs = "yes" if ($server_role eq "domain controller");
807         $ctx->{smb_conf_extra_options} = "
808
809         max xmit = 32K
810         server max protocol = SMB2
811         host msdfs = $msdfs
812         lanman auth = yes
813         allow nt4 crypto = yes
814
815         $extra_smbconf_options
816
817 [tmp]
818         path = $ctx->{share}
819         read only = no
820         posix:sharedelay = 10000
821         posix:oplocktimeout = 3
822         posix:writetimeupdatedelay = 50000
823
824 [xcopy_share]
825         path = $ctx->{share}
826         read only = no
827         posix:sharedelay = 10000
828         posix:oplocktimeout = 3
829         posix:writetimeupdatedelay = 50000
830         create mask = 777
831         force create mode = 777
832
833 [posix_share]
834         path = $ctx->{share}
835         read only = no
836         create mask = 0777
837         force create mode = 0
838         directory mask = 0777
839         force directory mode = 0
840
841 [test1]
842         path = $ctx->{share}/test1
843         read only = no
844         posix:sharedelay = 10000
845         posix:oplocktimeout = 3
846         posix:writetimeupdatedelay = 50000
847
848 [test2]
849         path = $ctx->{share}/test2
850         read only = no
851         posix:sharedelay = 10000
852         posix:oplocktimeout = 3
853         posix:writetimeupdatedelay = 50000
854
855 [cifs]
856         read only = no
857         ntvfs handler = cifs
858         cifs:server = $ctx->{netbiosname}
859         cifs:share = tmp
860         cifs:use-s4u2proxy = yes
861         # There is no username specified here, instead the client is expected
862         # to log in with kerberos, and the serverwill use delegated credentials.
863         # Or the server tries s4u2self/s4u2proxy to impersonate the client
864
865 [simple]
866         path = $ctx->{share}
867         read only = no
868         ntvfs handler = simple
869
870 [sysvol]
871         path = $ctx->{statedir}/sysvol
872         read only = no
873
874 [netlogon]
875         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
876         read only = no
877
878 [cifsposix]
879         copy = simple
880         ntvfs handler = cifsposix
881
882 $extra_smbconf_shares
883 ";
884
885         if (defined($self->{ldap})) {
886                 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
887                 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
888
889                 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
890                 $ldap_uri =~ s|/|%2F|g;
891                 $ldap_uri = "ldapi://$ldap_uri";
892                 $ctx->{ldap_uri} = $ldap_uri;
893
894                 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
895         }
896
897         my $ret = $self->provision_raw_step1($ctx);
898         unless (defined $ret) {
899                 return undef;
900         }
901
902         if (defined($self->{ldap})) {
903                 $ret->{LDAP_URI} = $ctx->{ldap_uri};
904                 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
905                 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
906                 if ($self->{ldap} eq "openldap") {
907                         push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
908                         ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
909
910                 } elsif ($self->{ldap} eq "fedora-ds") {
911                         push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
912                         push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
913                         ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
914                 }
915
916         }
917
918         return $self->provision_raw_step2($ctx, $ret);
919 }
920
921 sub provision_s4member($$$)
922 {
923         my ($self, $prefix, $dcvars) = @_;
924         print "PROVISIONING MEMBER...";
925
926         my $ret = $self->provision($prefix,
927                                    "member server",
928                                    "s4member",
929                                    "SAMBADOMAIN",
930                                    "samba.example.com",
931                                    "2008",
932                                    "locMEMpass3",
933                                    $dcvars->{SERVER_IP},
934                                    "", "", undef);
935         unless ($ret) {
936                 return undef;
937         }
938
939         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
940         my $cmd = "";
941         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
942         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
943         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
944         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
945         $cmd .= " --machinepass=machine$ret->{PASSWORD}";
946
947         unless (system($cmd) == 0) {
948                 warn("Join failed\n$cmd");
949                 return undef;
950         }
951
952         $ret->{MEMBER_SERVER} = $ret->{SERVER};
953         $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
954         $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
955         $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
956         $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
957
958         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
959         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
960         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
961         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
962         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
963
964         return $ret;
965 }
966
967 sub provision_rpc_proxy($$$)
968 {
969         my ($self, $prefix, $dcvars) = @_;
970         print "PROVISIONING RPC PROXY...";
971
972         my $extra_smbconf_options = "
973
974         # rpc_proxy
975         dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
976         dcerpc endpoint servers = epmapper, remote
977         dcerpc_remote:interfaces = rpcecho
978
979 [cifs_to_dc]
980         read only = no
981         ntvfs handler = cifs
982         cifs:server = $dcvars->{SERVER}
983         cifs:share = cifs
984         cifs:use-s4u2proxy = yes
985         # There is no username specified here, instead the client is expected
986         # to log in with kerberos, and the serverwill use delegated credentials.
987         # Or the server tries s4u2self/s4u2proxy to impersonate the client
988
989 ";
990
991         my $ret = $self->provision($prefix,
992                                    "member server",
993                                    "localrpcproxy",
994                                    "SAMBADOMAIN",
995                                    "samba.example.com",
996                                    "2008",
997                                    "locRPCproxypass4",
998                                    $dcvars->{SERVER_IP},
999                                    $extra_smbconf_options, "", undef);
1000
1001         unless ($ret) {
1002                 return undef;
1003         }
1004
1005         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1006
1007         # The joind runs in the context of the rpc_proxy/member for now
1008         my $cmd = "";
1009         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1010         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1011         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1012         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1013         $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1014
1015         unless (system($cmd) == 0) {
1016                 warn("Join failed\n$cmd");
1017                 return undef;
1018         }
1019
1020         # Setting up delegation runs in the context of the DC for now
1021         $cmd = "";
1022         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1023         $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1024         $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1025         $cmd .= " $dcvars->{CONFIGURATION}";
1026         print $cmd;
1027
1028         unless (system($cmd) == 0) {
1029                 warn("Delegation failed\n$cmd");
1030                 return undef;
1031         }
1032
1033         # Setting up delegation runs in the context of the DC for now
1034         $cmd = "";
1035         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1036         $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1037         $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1038         $cmd .= " $dcvars->{CONFIGURATION}";
1039
1040         unless (system($cmd) == 0) {
1041                 warn("Delegation failed\n$cmd");
1042                 return undef;
1043         }
1044
1045         $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1046         $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1047         $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1048         $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1049         $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1050
1051         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1052         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1053         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1054         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1055         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1056
1057         return $ret;
1058 }
1059
1060 sub provision_promoted_dc($$$)
1061 {
1062         my ($self, $prefix, $dcvars) = @_;
1063         print "PROVISIONING VAMPIRE DC...";
1064
1065         # We do this so that we don't run the provision.  That's the job of 'net vampire'.
1066         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1067                                                "promotedvdc",
1068                                                "SAMBADOMAIN",
1069                                                "samba.example.com",
1070                                                "2008",
1071                                                $dcvars->{PASSWORD},
1072                                                $dcvars->{SERVER_IP});
1073
1074         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1075
1076         $ctx->{smb_conf_extra_options} = "
1077         max xmit = 32K
1078         server max protocol = SMB2
1079
1080 [sysvol]
1081         path = $ctx->{statedir}/sysvol
1082         read only = yes
1083
1084 [netlogon]
1085         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1086         read only = no
1087
1088 ";
1089
1090         my $ret = $self->provision_raw_step1($ctx);
1091         unless ($ret) {
1092                 return undef;
1093         }
1094
1095         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1096         my $cmd = "";
1097         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1098         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1099         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1100         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1101         $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1102
1103         unless (system($cmd) == 0) {
1104                 warn("Join failed\n$cmd");
1105                 return undef;
1106         }
1107
1108         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1109         my $cmd = "";
1110         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1111         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1112         $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1113         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1114         $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1115
1116         unless (system($cmd) == 0) {
1117                 warn("Join failed\n$cmd");
1118                 return undef;
1119         }
1120
1121         $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1122         $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1123         $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1124
1125         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1126         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1127         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1128         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1129         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1130
1131         return $ret;
1132 }
1133
1134 sub provision_vampire_dc($$$)
1135 {
1136         my ($self, $prefix, $dcvars) = @_;
1137         print "PROVISIONING VAMPIRE DC...";
1138
1139         # We do this so that we don't run the provision.  That's the job of 'net vampire'.
1140         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1141                                                "localvampiredc",
1142                                                "SAMBADOMAIN",
1143                                                "samba.example.com",
1144                                                "2008",
1145                                                $dcvars->{PASSWORD},
1146                                                $dcvars->{SERVER_IP});
1147
1148         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1149
1150         $ctx->{smb_conf_extra_options} = "
1151         max xmit = 32K
1152         server max protocol = SMB2
1153
1154 [sysvol]
1155         path = $ctx->{statedir}/sysvol
1156         read only = yes
1157
1158 [netlogon]
1159         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1160         read only = no
1161
1162 ";
1163
1164         my $ret = $self->provision_raw_step1($ctx);
1165         unless ($ret) {
1166                 return undef;
1167         }
1168
1169         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1170         my $cmd = "";
1171         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1172         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1173         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1174         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1175         $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1176
1177         unless (system($cmd) == 0) {
1178                 warn("Join failed\n$cmd");
1179                 return undef;
1180         }
1181
1182         $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1183         $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1184         $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1185
1186         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1187         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1188         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1189         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1190         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1191
1192         return $ret;
1193 }
1194
1195 sub provision_subdom_dc($$$)
1196 {
1197         my ($self, $prefix, $dcvars) = @_;
1198         print "PROVISIONING SUBDOMAIN DC...";
1199
1200         # We do this so that we don't run the provision.  That's the job of 'net vampire'.
1201         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1202                                                "localsubdc",
1203                                                "SAMBASUBDOM",
1204                                                "sub.samba.example.com",
1205                                                "2008",
1206                                                $dcvars->{PASSWORD},
1207                                                undef);
1208
1209         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1210
1211         $ctx->{smb_conf_extra_options} = "
1212         max xmit = 32K
1213         server max protocol = SMB2
1214
1215 [sysvol]
1216         path = $ctx->{statedir}/sysvol
1217         read only = yes
1218
1219 [netlogon]
1220         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1221         read only = no
1222
1223 ";
1224
1225         my $ret = $self->provision_raw_step1($ctx);
1226         unless ($ret) {
1227                 return undef;
1228         }
1229
1230         my $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
1231                                                 $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
1232         Samba::mk_krb5_conf($ctx, $dc_realms);
1233
1234         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1235         my $cmd = "";
1236         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1237         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1238         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1239         $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1240         $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1241
1242         unless (system($cmd) == 0) {
1243                 warn("Join failed\n$cmd");
1244                 return undef;
1245         }
1246
1247         $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1248         $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1249         $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1250
1251         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1252         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1253         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1254         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1255         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1256
1257         return $ret;
1258 }
1259
1260 sub provision_dc($$)
1261 {
1262         my ($self, $prefix) = @_;
1263
1264         print "PROVISIONING DC...";
1265         my $extra_conf_options = "netbios aliases = localDC1-a";
1266         my $ret = $self->provision($prefix,
1267                                    "domain controller",
1268                                    "localdc",
1269                                    "SAMBADOMAIN",
1270                                    "samba.example.com",
1271                                    "2008",
1272                                    "locDCpass1",
1273                                    undef, $extra_conf_options, "", undef);
1274
1275         return undef unless(defined $ret);
1276         unless($self->add_wins_config("$prefix/private")) {
1277                 warn("Unable to add wins configuration");
1278                 return undef;
1279         }
1280         $ret->{NETBIOSALIAS} = "localdc1-a";
1281         $ret->{DC_SERVER} = $ret->{SERVER};
1282         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1283         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1284         $ret->{DC_USERNAME} = $ret->{USERNAME};
1285         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1286
1287         return $ret;
1288 }
1289
1290 sub provision_fl2000dc($$)
1291 {
1292         my ($self, $prefix) = @_;
1293
1294         print "PROVISIONING DC...";
1295         my $ret = $self->provision($prefix,
1296                                    "domain controller",
1297                                    "dc5",
1298                                    "SAMBA2000",
1299                                    "samba2000.example.com",
1300                                    "2000",
1301                                    "locDCpass5",
1302                                    undef, "", "", undef);
1303
1304         unless($self->add_wins_config("$prefix/private")) {
1305                 warn("Unable to add wins configuration");
1306                 return undef;
1307         }
1308
1309         return $ret;
1310 }
1311
1312 sub provision_fl2003dc($$)
1313 {
1314         my ($self, $prefix) = @_;
1315
1316         print "PROVISIONING DC...";
1317         my $ret = $self->provision($prefix,
1318                                    "domain controller",
1319                                    "dc6",
1320                                    "SAMBA2003",
1321                                    "samba2003.example.com",
1322                                    "2003",
1323                                    "locDCpass6",
1324                                    undef, "allow dns updates = nonsecure and secure", "", undef);
1325
1326         unless (defined $ret) {
1327                 return undef;
1328         }
1329
1330         $ret->{DC_SERVER} = $ret->{SERVER};
1331         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1332         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1333         $ret->{DC_USERNAME} = $ret->{USERNAME};
1334         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1335
1336         my @samba_tool_options;
1337         push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1338         push (@samba_tool_options, "domain");
1339         push (@samba_tool_options, "passwordsettings");
1340         push (@samba_tool_options, "set");
1341         push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1342         push (@samba_tool_options, "--min-pwd-age=0");
1343         push (@samba_tool_options, "--history-length=1");
1344
1345         my $samba_tool_cmd = join(" ", @samba_tool_options);
1346
1347         unless (system($samba_tool_cmd) == 0) {
1348                 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1349                 return undef;
1350         }
1351
1352         return $ret;
1353
1354         unless($self->add_wins_config("$prefix/private")) {
1355                 warn("Unable to add wins configuration");
1356                 return undef;
1357         }
1358
1359         return $ret;
1360 }
1361
1362 sub provision_fl2008r2dc($$)
1363 {
1364         my ($self, $prefix) = @_;
1365
1366         print "PROVISIONING DC...";
1367         my $ret = $self->provision($prefix,
1368                                    "domain controller",
1369                                    "dc7",
1370                                    "SAMBA2008R2",
1371                                    "samba2008R2.example.com",
1372                                    "2008_R2",
1373                                    "locDCpass7",
1374                                    undef, "", "", undef);
1375
1376         unless ($self->add_wins_config("$prefix/private")) {
1377                 warn("Unable to add wins configuration");
1378                 return undef;
1379         }
1380
1381         return $ret;
1382 }
1383
1384
1385 sub provision_rodc($$$)
1386 {
1387         my ($self, $prefix, $dcvars) = @_;
1388         print "PROVISIONING RODC...";
1389
1390         # We do this so that we don't run the provision.  That's the job of 'net join RODC'.
1391         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1392                                                "rodc",
1393                                                "SAMBADOMAIN",
1394                                                "samba.example.com",
1395                                                "2008",
1396                                                $dcvars->{PASSWORD},
1397                                                $dcvars->{SERVER_IP});
1398         unless ($ctx) {
1399                 return undef;
1400         }
1401
1402         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1403
1404         $ctx->{share} = "$ctx->{prefix_abs}/share";
1405         push(@{$ctx->{directories}}, "$ctx->{share}");
1406
1407         $ctx->{smb_conf_extra_options} = "
1408         max xmit = 32K
1409         server max protocol = SMB2
1410
1411 [sysvol]
1412         path = $ctx->{statedir}/sysvol
1413         read only = yes
1414
1415 [netlogon]
1416         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1417         read only = yes
1418
1419 [tmp]
1420         path = $ctx->{share}
1421         read only = no
1422         posix:sharedelay = 10000
1423         posix:oplocktimeout = 3
1424         posix:writetimeupdatedelay = 50000
1425
1426 ";
1427
1428         my $ret = $self->provision_raw_step1($ctx);
1429         unless ($ret) {
1430                 return undef;
1431         }
1432
1433         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1434         my $cmd = "";
1435         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1436         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1437         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1438         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1439         $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1440
1441         unless (system($cmd) == 0) {
1442                 warn("RODC join failed\n$cmd");
1443                 return undef;
1444         }
1445
1446         # we overwrite the kdc after the RODC join
1447         # so that use the RODC as kdc and test
1448         # the proxy code
1449         $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1450         Samba::mk_krb5_conf($ctx);
1451
1452         $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1453         $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1454         $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1455
1456         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1457         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1458         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1459         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1460         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1461
1462         return $ret;
1463 }
1464
1465 sub provision_plugin_s4_dc($$)
1466 {
1467         my ($self, $prefix) = @_;
1468
1469         my $prefix_abs = abs_path($prefix);
1470
1471         my $bindir_abs = abs_path($self->{bindir});
1472         my $lockdir="$prefix_abs/lockdir";
1473         my $conffile="$prefix_abs/etc/smb.conf";
1474
1475         my $extra_smbconf_options = "
1476         server services = -smb +s3fs
1477         xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1478
1479         dbwrap_tdb_mutexes:* = yes
1480
1481         kernel oplocks = no
1482         kernel change notify = no
1483
1484         syslog = no
1485         printing = bsd
1486         printcap name = /dev/null
1487
1488         max protocol = SMB3
1489         read only = no
1490         server signing = auto
1491
1492         smbd:sharedelay = 100000
1493         smbd:writetimeupdatedelay = 500000
1494         create mask = 755
1495         dos filemode = yes
1496
1497         dcerpc endpoint servers = -winreg -srvsvc
1498
1499         printcap name = /dev/null
1500
1501         addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1502         deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1503
1504         printing = vlp
1505         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1506         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1507         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1508         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1509         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1510         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1511         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1512         lpq cache time = 0
1513         print notify backchannel = yes
1514
1515 ";
1516
1517         my $extra_smbconf_shares = "
1518
1519 [tmpenc]
1520         copy = tmp
1521         smb encrypt = required
1522
1523 [tmpcase]
1524         copy = tmp
1525         case sensitive = yes
1526
1527 [tmpguest]
1528         copy = tmp
1529         guest ok = yes
1530
1531 [hideunread]
1532         copy = tmp
1533         hide unreadable = yes
1534
1535 [durable]
1536         copy = tmp
1537         kernel share modes = no
1538         kernel oplocks = no
1539         posix locking = no
1540
1541 [print\$]
1542         copy = tmp
1543
1544 [print1]
1545         copy = tmp
1546         printable = yes
1547
1548 [print2]
1549         copy = print1
1550 [print3]
1551         copy = print1
1552 [lp]
1553         copy = print1
1554 ";
1555
1556         print "PROVISIONING PLUGIN S4 DC...";
1557         my $ret = $self->provision($prefix,
1558                                    "domain controller",
1559                                    "plugindc",
1560                                    "PLUGINDOMAIN",
1561                                    "plugindc.samba.example.com",
1562                                    "2008",
1563                                    "locDCpass1",
1564                                    undef, $extra_smbconf_options,
1565                                    $extra_smbconf_shares, undef);
1566
1567         return undef unless(defined $ret);
1568         unless($self->add_wins_config("$prefix/private")) {
1569                 warn("Unable to add wins configuration");
1570                 return undef;
1571         }
1572
1573         $ret->{DC_SERVER} = $ret->{SERVER};
1574         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1575         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1576         $ret->{DC_USERNAME} = $ret->{USERNAME};
1577         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1578
1579         return $ret;
1580 }
1581
1582 sub provision_chgdcpass($$)
1583 {
1584         my ($self, $prefix) = @_;
1585
1586         print "PROVISIONING CHGDCPASS...";
1587         my $extra_provision_options = undef;
1588         push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1589         my $ret = $self->provision($prefix,
1590                                    "domain controller",
1591                                    "chgdcpass",
1592                                    "CHDCDOMAIN",
1593                                    "chgdcpassword.samba.example.com",
1594                                    "2008",
1595                                    "chgDCpass1",
1596                                    undef, "", "",
1597                                    $extra_provision_options);
1598
1599         return undef unless(defined $ret);
1600         unless($self->add_wins_config("$prefix/private")) {
1601                 warn("Unable to add wins configuration");
1602                 return undef;
1603         }
1604         
1605         # Remove secrets.tdb from this environment to test that we still start up
1606         # on systems without the new matching secrets.tdb records
1607         unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1608                 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1609                 return undef;
1610         }
1611             
1612         $ret->{DC_SERVER} = $ret->{SERVER};
1613         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1614         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1615         $ret->{DC_USERNAME} = $ret->{USERNAME};
1616         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1617
1618         return $ret;
1619 }
1620
1621 sub teardown_env($$)
1622 {
1623         my ($self, $envvars) = @_;
1624         my $pid;
1625
1626         # This should cause samba to terminate gracefully
1627         close($envvars->{STDIN_PIPE});
1628
1629         $pid = $envvars->{SAMBA_PID};
1630         my $count = 0;
1631         my $childpid;
1632
1633         # This should give it time to write out the gcov data
1634         until ($count > 30) {
1635             if (Samba::cleanup_child($pid, "samba") == -1) {
1636                 last;
1637             }
1638             sleep(1);
1639             $count++;
1640         }
1641
1642         if ($count > 30 || kill(0, $pid)) {
1643             kill "TERM", $pid;
1644
1645             until ($count > 40) {
1646                 if (Samba::cleanup_child($pid, "samba") == -1) {
1647                     last;
1648                 }
1649                 sleep(1);
1650                 $count++;
1651             }
1652             # If it is still around, kill it
1653             warn "server process $pid took more than $count seconds to exit, killing\n";
1654             kill 9, $pid;
1655         }
1656
1657         $self->slapd_stop($envvars) if ($self->{ldap});
1658
1659         print $self->getlog_env($envvars);
1660
1661         return;
1662 }
1663
1664 sub getlog_env($$)
1665 {
1666         my ($self, $envvars) = @_;
1667         my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1668         my $out = $title;
1669
1670         open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1671
1672         seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1673         while (<LOG>) {
1674                 $out .= $_;
1675         }
1676         $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1677         close(LOG);
1678
1679         return "" if $out eq $title;
1680
1681         return $out;
1682 }
1683
1684 sub check_env($$)
1685 {
1686         my ($self, $envvars) = @_;
1687
1688         my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
1689
1690         return ($childpid == 0);
1691 }
1692
1693 sub setup_env($$$)
1694 {
1695         my ($self, $envname, $path) = @_;
1696         my $target3 = $self->{target3};
1697
1698         $ENV{ENVNAME} = $envname;
1699
1700         if (defined($self->{vars}->{$envname})) {
1701                 return $self->{vars}->{$envname};
1702         }
1703
1704         if ($envname eq "dc") {
1705                 return $self->setup_dc("$path/dc");
1706         } elsif ($envname eq "fl2000dc") {
1707                 return $self->setup_fl2000dc("$path/fl2000dc");
1708         } elsif ($envname eq "fl2003dc") {
1709                 return $self->setup_fl2003dc("$path/fl2003dc");
1710         } elsif ($envname eq "fl2008r2dc") {
1711                 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1712         } elsif ($envname eq "rpc_proxy") {
1713                 if (not defined($self->{vars}->{dc})) {
1714                         $self->setup_dc("$path/dc");
1715                 }
1716                 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1717         } elsif ($envname eq "vampire_dc") {
1718                 if (not defined($self->{vars}->{dc})) {
1719                         $self->setup_dc("$path/dc");
1720                 }
1721                 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1722         } elsif ($envname eq "promoted_dc") {
1723                 if (not defined($self->{vars}->{dc})) {
1724                         $self->setup_dc("$path/dc");
1725                 }
1726                 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{dc});
1727         } elsif ($envname eq "subdom_dc") {
1728                 if (not defined($self->{vars}->{dc})) {
1729                         $self->setup_dc("$path/dc");
1730                 }
1731                 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
1732         } elsif ($envname eq "s4member") {
1733                 if (not defined($self->{vars}->{dc})) {
1734                         $self->setup_dc("$path/dc");
1735                 }
1736                 return $self->setup_s4member("$path/s4member", $self->{vars}->{dc});
1737         } elsif ($envname eq "rodc") {
1738                 if (not defined($self->{vars}->{dc})) {
1739                         $self->setup_dc("$path/dc");
1740                 }
1741                 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1742         } elsif ($envname eq "chgdcpass") {
1743                 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
1744         } elsif ($envname eq "s3member") {
1745                 if (not defined($self->{vars}->{dc})) {
1746                         $self->setup_dc("$path/dc");
1747                 }
1748                 return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
1749         } elsif ($envname eq "plugin_s4_dc") {
1750                 return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
1751         } elsif ($envname eq "s3member_rfc2307") {
1752                 if (not defined($self->{vars}->{dc})) {
1753                         $self->setup_dc("$path/dc");
1754                 }
1755                 return $target3->setup_admember_rfc2307("$path/s3member_rfc2307",
1756                                                         $self->{vars}->{dc}, 34);
1757         } else {
1758                 return "UNKNOWN";
1759         }
1760 }
1761
1762 sub setup_s4member($$$)
1763 {
1764         my ($self, $path, $dc_vars) = @_;
1765
1766         my $env = $self->provision_s4member($path, $dc_vars);
1767
1768         if (defined $env) {
1769                 $self->check_or_start($env, "single");
1770
1771                 $self->wait_for_start($env);
1772
1773                 $self->{vars}->{s4member} = $env;
1774         }
1775
1776         return $env;
1777 }
1778
1779 sub setup_rpc_proxy($$$)
1780 {
1781         my ($self, $path, $dc_vars) = @_;
1782
1783         my $env = $self->provision_rpc_proxy($path, $dc_vars);
1784
1785         if (defined $env) {
1786                 $self->check_or_start($env, "single");
1787
1788                 $self->wait_for_start($env);
1789
1790                 $self->{vars}->{rpc_proxy} = $env;
1791         }
1792         return $env;
1793 }
1794
1795 sub setup_dc($$)
1796 {
1797         my ($self, $path) = @_;
1798
1799         my $env = $self->provision_dc($path);
1800         if (defined $env) {
1801                 $self->check_or_start($env, "standard");
1802
1803                 $self->wait_for_start($env);
1804
1805                 $self->{vars}->{dc} = $env;
1806         }
1807         return $env;
1808 }
1809
1810 sub setup_chgdcpass($$)
1811 {
1812         my ($self, $path) = @_;
1813
1814         my $env = $self->provision_chgdcpass($path);
1815         if (defined $env) {
1816                 $self->check_or_start($env, "single");
1817
1818                 $self->wait_for_start($env);
1819
1820                 $self->{vars}->{chgdcpass} = $env;
1821         }
1822         return $env;
1823 }
1824
1825 sub setup_fl2000dc($$)
1826 {
1827         my ($self, $path) = @_;
1828
1829         my $env = $self->provision_fl2000dc($path);
1830         if (defined $env) {
1831                 $self->check_or_start($env, "single");
1832
1833                 $self->wait_for_start($env);
1834
1835                 $self->{vars}->{fl2000dc} = $env;
1836         }
1837
1838         return $env;
1839 }
1840
1841 sub setup_fl2003dc($$)
1842 {
1843         my ($self, $path) = @_;
1844
1845         my $env = $self->provision_fl2003dc($path);
1846
1847         if (defined $env) {
1848                 $self->check_or_start($env, "single");
1849
1850                 $self->wait_for_start($env);
1851
1852                 $self->{vars}->{fl2003dc} = $env;
1853         }
1854         return $env;
1855 }
1856
1857 sub setup_fl2008r2dc($$)
1858 {
1859         my ($self, $path) = @_;
1860
1861         my $env = $self->provision_fl2008r2dc($path);
1862
1863         if (defined $env) {
1864                 $self->check_or_start($env, "single");
1865
1866                 $self->wait_for_start($env);
1867
1868                 $self->{vars}->{fl2008r2dc} = $env;
1869         }
1870
1871         return $env;
1872 }
1873
1874 sub setup_vampire_dc($$$)
1875 {
1876         my ($self, $path, $dc_vars) = @_;
1877
1878         my $env = $self->provision_vampire_dc($path, $dc_vars);
1879
1880         if (defined $env) {
1881                 $self->check_or_start($env, "single");
1882
1883                 $self->wait_for_start($env);
1884
1885                 $self->{vars}->{vampire_dc} = $env;
1886
1887                 # force replicated DC to update repsTo/repsFrom
1888                 # for vampired partitions
1889                 my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1890                 my $cmd = "";
1891                 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1892                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1893                 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1894                 $cmd .= " $env->{CONFIGURATION}";
1895                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1896                 unless (system($cmd) == 0) {
1897                         warn("Failed to exec kcc\n$cmd");
1898                         return undef;
1899                 }
1900
1901                 # as 'vampired' dc may add data in its local replica
1902                 # we need to synchronize data between DCs
1903                 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1904                 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1905                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1906                 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1907                 $cmd .= " $dc_vars->{CONFIGURATION}";
1908                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1909                 # replicate Configuration NC
1910                 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1911                 unless(system($cmd_repl) == 0) {
1912                         warn("Failed to replicate\n$cmd_repl");
1913                         return undef;
1914                 }
1915                 # replicate Default NC
1916                 $cmd_repl = "$cmd \"$base_dn\"";
1917                 unless(system($cmd_repl) == 0) {
1918                         warn("Failed to replicate\n$cmd_repl");
1919                         return undef;
1920                 }
1921         }
1922
1923         return $env;
1924 }
1925
1926 sub setup_promoted_dc($$$)
1927 {
1928         my ($self, $path, $dc_vars) = @_;
1929
1930         my $env = $self->provision_promoted_dc($path, $dc_vars);
1931
1932         if (defined $env) {
1933                 $self->check_or_start($env, "single");
1934
1935                 $self->wait_for_start($env);
1936
1937                 $self->{vars}->{promoted_dc} = $env;
1938
1939                 # force replicated DC to update repsTo/repsFrom
1940                 # for vampired partitions
1941                 my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1942                 my $cmd = "";
1943                 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1944                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1945                 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1946                 $cmd .= " $env->{CONFIGURATION}";
1947                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1948                 unless (system($cmd) == 0) {
1949                         warn("Failed to exec kcc\n$cmd");
1950                         return undef;
1951                 }
1952
1953                 # as 'vampired' dc may add data in its local replica
1954                 # we need to synchronize data between DCs
1955                 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1956                 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1957                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1958                 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1959                 $cmd .= " $dc_vars->{CONFIGURATION}";
1960                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1961                 # replicate Configuration NC
1962                 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1963                 unless(system($cmd_repl) == 0) {
1964                         warn("Failed to replicate\n$cmd_repl");
1965                         return undef;
1966                 }
1967                 # replicate Default NC
1968                 $cmd_repl = "$cmd \"$base_dn\"";
1969                 unless(system($cmd_repl) == 0) {
1970                         warn("Failed to replicate\n$cmd_repl");
1971                         return undef;
1972                 }
1973         }
1974
1975         return $env;
1976 }
1977
1978 sub setup_subdom_dc($$$)
1979 {
1980         my ($self, $path, $dc_vars) = @_;
1981
1982         my $env = $self->provision_subdom_dc($path, $dc_vars);
1983
1984         if (defined $env) {
1985                 $self->check_or_start($env, "single");
1986
1987                 $self->wait_for_start($env);
1988
1989                 $self->{vars}->{subdom_dc} = $env;
1990
1991                 # force replicated DC to update repsTo/repsFrom
1992                 # for primary domain partitions
1993                 my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1994                 my $cmd = "";
1995                 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1996                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1997                 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1998                 $cmd .= " $env->{CONFIGURATION}";
1999                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2000                 unless (system($cmd) == 0) {
2001                         warn("Failed to exec kcc\n$cmd");
2002                         return undef;
2003                 }
2004
2005                 # as 'subdomain' dc may add data in its local replica
2006                 # we need to synchronize data between DCs
2007                 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2008                 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2009                 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2010                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2011                 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2012                 $cmd .= " $dc_vars->{CONFIGURATION}";
2013                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2014                 # replicate Configuration NC
2015                 my $cmd_repl = "$cmd \"$config_dn\"";
2016                 unless(system($cmd_repl) == 0) {
2017                         warn("Failed to replicate\n$cmd_repl");
2018                         return undef;
2019                 }
2020                 # replicate Default NC
2021                 $cmd_repl = "$cmd \"$base_dn\"";
2022                 unless(system($cmd_repl) == 0) {
2023                         warn("Failed to replicate\n$cmd_repl");
2024                         return undef;
2025                 }
2026         }
2027
2028         return $env;
2029 }
2030
2031 sub setup_rodc($$$)
2032 {
2033         my ($self, $path, $dc_vars) = @_;
2034
2035         my $env = $self->provision_rodc($path, $dc_vars);
2036
2037         unless ($env) {
2038                 return undef;
2039         }
2040
2041         $self->check_or_start($env, "single");
2042
2043         $self->wait_for_start($env);
2044
2045         $self->{vars}->{rodc} = $env;
2046
2047         return $env;
2048 }
2049
2050 sub setup_plugin_s4_dc($$)
2051 {
2052         my ($self, $path) = @_;
2053
2054         # If we didn't build with ADS, pretend this env was never available
2055         if (not $self->{target3}->have_ads()) {
2056                return "UNKNOWN";
2057         }
2058
2059         my $env = $self->provision_plugin_s4_dc($path);
2060         unless ($env) {
2061                 return undef;
2062         }
2063
2064         $self->check_or_start($env, "single");
2065         
2066         $self->wait_for_start($env);
2067         
2068         $self->{vars}->{plugin_s4_dc} = $env;
2069         return $env;
2070 }
2071
2072 1;