selftest/Samba4: also bind to ipv6
[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->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
540         $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
541
542         push(@{$ctx->{directories}}, $ctx->{privatedir});
543         push(@{$ctx->{directories}}, $ctx->{etcdir});
544         push(@{$ctx->{directories}}, $ctx->{piddir});
545         push(@{$ctx->{directories}}, $ctx->{lockdir});
546         push(@{$ctx->{directories}}, $ctx->{logdir});
547         push(@{$ctx->{directories}}, $ctx->{statedir});
548         push(@{$ctx->{directories}}, $ctx->{cachedir});
549
550         $ctx->{smb_conf_extra_options} = "";
551
552         my @provision_options = ();
553         push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
554         push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
555         push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
556         if (defined($ENV{GDB_PROVISION})) {
557                 push (@provision_options, "gdb --args");
558                 if (!defined($ENV{PYTHON})) {
559                     push (@provision_options, "env");
560                     push (@provision_options, "python");
561                 }
562         }
563         if (defined($ENV{VALGRIND_PROVISION})) {
564                 push (@provision_options, "valgrind");
565                 if (!defined($ENV{PYTHON})) {
566                     push (@provision_options, "env");
567                     push (@provision_options, "python");
568                 }
569         }
570         if (defined($ENV{PYTHON})) {
571                 push (@provision_options, $ENV{PYTHON});
572         }
573         push (@provision_options, Samba::bindir_path($self, "samba-tool"));
574         push (@provision_options, "domain");
575         push (@provision_options, "provision");
576         push (@provision_options, "--configfile=$ctx->{smb_conf}");
577         push (@provision_options, "--host-name=$ctx->{hostname}");
578         push (@provision_options, "--host-ip=$ctx->{ipv4}");
579         push (@provision_options, "--quiet");
580         push (@provision_options, "--domain=$ctx->{domain}");
581         push (@provision_options, "--realm=$ctx->{realm}");
582         push (@provision_options, "--adminpass=$ctx->{password}");
583         push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
584         push (@provision_options, "--machinepass=machine$ctx->{password}");
585         push (@provision_options, "--root=$ctx->{unix_name}");
586         push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
587         push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
588
589         @{$ctx->{provision_options}} = @provision_options;
590
591         return $ctx;
592 }
593
594 #
595 # Step1 creates the basic configuration
596 #
597 sub provision_raw_step1($$)
598 {
599         my ($self, $ctx) = @_;
600
601         mkdir($_, 0777) foreach (@{$ctx->{directories}});
602
603         ##
604         ## lockdir and piddir must be 0755
605         ##
606         chmod 0755, $ctx->{lockdir};
607         chmod 0755, $ctx->{piddir};
608
609         unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
610                 warn("can't open $ctx->{smb_conf}$?");
611                 return undef;
612         }
613         print CONFFILE "
614 [global]
615         netbios name = $ctx->{netbiosname}
616         posix:eadb = $ctx->{statedir}/eadb.tdb
617         workgroup = $ctx->{domain}
618         realm = $ctx->{realm}
619         private dir = $ctx->{privatedir}
620         pid directory = $ctx->{piddir}
621         ncalrpc dir = $ctx->{ncalrpcdir}
622         lock dir = $ctx->{lockdir}
623         state directory = $ctx->{statedir}
624         cache directory = $ctx->{cachedir}
625         winbindd socket directory = $ctx->{winbindd_socket_dir}
626         winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
627         ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
628         winbind separator = /
629         name resolve order = file bcast
630         interfaces = $ctx->{interfaces}
631         tls dh params file = $ctx->{tlsdir}/dhparms.pem
632         panic action = $RealBin/gdb_backtrace \%d
633         wins support = yes
634         server role = $ctx->{server_role}
635         server services = +echo +smb -s3fs
636         dcerpc endpoint servers = +winreg +srvsvc
637         notify:inotify = false
638         ldb:nosync = true
639 #We don't want to pass our self-tests if the PAC code is wrong
640         gensec:require_pac = true
641         log file = $ctx->{logdir}/log.\%m
642         log level = $ctx->{server_loglevel}
643         lanman auth = Yes
644         rndc command = true
645         dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file} -s $ctx->{smb_conf}
646         spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
647         resolv:host file = $ctx->{dns_host_file}
648         dreplsrv:periodic_startup_interval = 0
649         dsdb:schema update allowed = yes
650
651         vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
652
653         # remove this again, when our smb2 client library
654         # supports signin on compound related requests
655         server signing = on
656
657         idmap_ldb:use rfc2307=yes
658         winbind enum users = yes
659         winbind enum groups = yes
660 ";
661
662         print CONFFILE "
663
664         # Begin extra options
665         $ctx->{smb_conf_extra_options}
666         # End extra options
667 ";
668         close(CONFFILE);
669
670         $self->mk_keyblobs($ctx->{tlsdir});
671
672         #Default the KDC IP to the server's IP
673         if (not defined($ctx->{kdc_ipv4})) {
674              $ctx->{kdc_ipv4} = $ctx->{ipv4};
675         }
676
677         Samba::mk_krb5_conf($ctx, "");
678
679         open(PWD, ">$ctx->{nsswrap_passwd}");
680         print PWD "
681 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
682 $ctx->{unix_name}:x:$ctx->{unix_uid}:100:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
683 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
684 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
685 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
686 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
687 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
688 ";
689         close(PWD);
690         my $uid_rfc2307test = 65533;
691
692         open(GRP, ">$ctx->{nsswrap_group}");
693         print GRP "
694 root:x:0:
695 wheel:x:10:
696 users:x:100:
697 nobody:x:65533:
698 nogroup:x:65534:nobody
699 $ctx->{unix_name}:x:$ctx->{unix_gid}:
700 ";
701         close(GRP);
702         my $gid_rfc2307test = 65532;
703
704         my $hostname = lc($ctx->{hostname});
705         open(HOSTS, ">>$ctx->{nsswrap_hosts}");
706         print HOSTS "$ctx->{ipv4} ${hostname}.samba.example.com ${hostname}\n";
707         print HOSTS "$ctx->{ipv6} ${hostname}.samba.example.com ${hostname}\n";
708         close(HOSTS);
709
710         my $configuration = "--configfile=$ctx->{smb_conf}";
711
712 #Ensure the config file is valid before we start
713         my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
714         if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
715                 system("$testparm -v --suppress-prompt $configuration >&2");
716                 warn("Failed to create a valid smb.conf configuration $testparm!");
717                 return undef;
718         }
719         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) {
720                 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
721                 return undef;
722         }
723
724         my $ret = {
725                 KRB5_CONFIG => $ctx->{krb5_conf},
726                 PIDDIR => $ctx->{piddir},
727                 SERVER => $ctx->{hostname},
728                 SERVER_IP => $ctx->{ipv4},
729                 SERVER_IPV6 => $ctx->{ipv6},
730                 NETBIOSNAME => $ctx->{netbiosname},
731                 DOMAIN => $ctx->{domain},
732                 USERNAME => $ctx->{username},
733                 REALM => $ctx->{realm},
734                 PASSWORD => $ctx->{password},
735                 LDAPDIR => $ctx->{ldapdir},
736                 LDAP_INSTANCE => $ctx->{ldap_instance},
737                 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
738                 NCALRPCDIR => $ctx->{ncalrpcdir},
739                 LOCKDIR => $ctx->{lockdir},
740                 STATEDIR => $ctx->{statedir},
741                 CACHEDIR => $ctx->{cachedir},
742                 PRIVATEDIR => $ctx->{privatedir},
743                 SERVERCONFFILE => $ctx->{smb_conf},
744                 CONFIGURATION => $configuration,
745                 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
746                 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
747                 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
748                 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
749                 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
750                 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
751                 SAMBA_TEST_LOG_POS => 0,
752                 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
753                 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
754                 LOCAL_PATH => $ctx->{share},
755                 UID_RFC2307TEST => $uid_rfc2307test,
756                 GID_RFC2307TEST => $gid_rfc2307test,
757                 SERVER_ROLE => $ctx->{server_role}
758         };
759
760         return $ret;
761 }
762
763 #
764 # Step2 runs the provision script
765 #
766 sub provision_raw_step2($$$)
767 {
768         my ($self, $ctx, $ret) = @_;
769
770         my $provision_cmd = join(" ", @{$ctx->{provision_options}});
771         unless (system($provision_cmd) == 0) {
772                 warn("Unable to provision: \n$provision_cmd\n");
773                 return undef;
774         }
775
776         return $ret;
777 }
778
779 sub provision($$$$$$$$$)
780 {
781         my ($self, $prefix, $server_role, $hostname,
782             $domain, $realm, $functional_level,
783             $password, $kdc_ipv4, $extra_smbconf_options, $extra_smbconf_shares,
784             $extra_provision_options) = @_;
785
786         my $ctx = $self->provision_raw_prepare($prefix, $server_role,
787                                                $hostname,
788                                                $domain, $realm, $functional_level,
789                                                $password, $kdc_ipv4);
790
791         if (defined($extra_provision_options)) {
792                 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
793         } else {
794                 push (@{$ctx->{provision_options}}, "--use-ntvfs");
795         }
796
797         $ctx->{share} = "$ctx->{prefix_abs}/share";
798         push(@{$ctx->{directories}}, "$ctx->{share}");
799         push(@{$ctx->{directories}}, "$ctx->{share}/test1");
800         push(@{$ctx->{directories}}, "$ctx->{share}/test2");
801
802         # precreate directories for printer drivers
803         push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
804         push(@{$ctx->{directories}}, "$ctx->{share}/x64");
805         push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
806
807         my $msdfs = "no";
808         $msdfs = "yes" if ($server_role eq "domain controller");
809         $ctx->{smb_conf_extra_options} = "
810
811         max xmit = 32K
812         server max protocol = SMB2
813         host msdfs = $msdfs
814         lanman auth = yes
815         allow nt4 crypto = yes
816
817         $extra_smbconf_options
818
819 [tmp]
820         path = $ctx->{share}
821         read only = no
822         posix:sharedelay = 10000
823         posix:oplocktimeout = 3
824         posix:writetimeupdatedelay = 50000
825
826 [xcopy_share]
827         path = $ctx->{share}
828         read only = no
829         posix:sharedelay = 10000
830         posix:oplocktimeout = 3
831         posix:writetimeupdatedelay = 50000
832         create mask = 777
833         force create mode = 777
834
835 [posix_share]
836         path = $ctx->{share}
837         read only = no
838         create mask = 0777
839         force create mode = 0
840         directory mask = 0777
841         force directory mode = 0
842
843 [test1]
844         path = $ctx->{share}/test1
845         read only = no
846         posix:sharedelay = 10000
847         posix:oplocktimeout = 3
848         posix:writetimeupdatedelay = 50000
849
850 [test2]
851         path = $ctx->{share}/test2
852         read only = no
853         posix:sharedelay = 10000
854         posix:oplocktimeout = 3
855         posix:writetimeupdatedelay = 50000
856
857 [cifs]
858         path = $ctx->{share}/_ignore_cifs_
859         read only = no
860         ntvfs handler = cifs
861         cifs:server = $ctx->{netbiosname}
862         cifs:share = tmp
863         cifs:use-s4u2proxy = yes
864         # There is no username specified here, instead the client is expected
865         # to log in with kerberos, and the serverwill use delegated credentials.
866         # Or the server tries s4u2self/s4u2proxy to impersonate the client
867
868 [simple]
869         path = $ctx->{share}
870         read only = no
871         ntvfs handler = simple
872
873 [sysvol]
874         path = $ctx->{statedir}/sysvol
875         read only = no
876
877 [netlogon]
878         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
879         read only = no
880
881 [cifsposix]
882         copy = simple
883         ntvfs handler = cifsposix
884
885 [vfs_fruit]
886         path = $ctx->{share}
887         vfs objects = catia fruit streams_xattr
888         fruit:ressource = file
889         fruit:metadata = netatalk
890         fruit:locking = netatalk
891         fruit:encoding = native
892
893 $extra_smbconf_shares
894 ";
895
896         if (defined($self->{ldap})) {
897                 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
898                 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
899
900                 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
901                 $ldap_uri =~ s|/|%2F|g;
902                 $ldap_uri = "ldapi://$ldap_uri";
903                 $ctx->{ldap_uri} = $ldap_uri;
904
905                 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
906         }
907
908         my $ret = $self->provision_raw_step1($ctx);
909         unless (defined $ret) {
910                 return undef;
911         }
912
913         if (defined($self->{ldap})) {
914                 $ret->{LDAP_URI} = $ctx->{ldap_uri};
915                 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
916                 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
917                 if ($self->{ldap} eq "openldap") {
918                         push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
919                         ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
920
921                 } elsif ($self->{ldap} eq "fedora-ds") {
922                         push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
923                         push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
924                         ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
925                 }
926
927         }
928
929         return $self->provision_raw_step2($ctx, $ret);
930 }
931
932 sub provision_s4member($$$)
933 {
934         my ($self, $prefix, $dcvars) = @_;
935         print "PROVISIONING MEMBER...";
936         my $extra_smb_conf = "
937         passdb backend = samba_dsdb
938 winbindd:use external pipes = true
939
940 rpc_server:default = external
941 rpc_server:svcctl = embedded
942 rpc_server:srvsvc = embedded
943 rpc_server:eventlog = embedded
944 rpc_server:ntsvcs = embedded
945 rpc_server:winreg = embedded
946 rpc_server:spoolss = embedded
947 rpc_daemon:spoolssd = embedded
948 rpc_server:tcpip = no
949 ";
950         my $ret = $self->provision($prefix,
951                                    "member server",
952                                    "s4member",
953                                    "SAMBADOMAIN",
954                                    "samba.example.com",
955                                    "2008",
956                                    "locMEMpass3",
957                                    $dcvars->{SERVER_IP},
958                                    $extra_smb_conf, "", undef);
959         unless ($ret) {
960                 return undef;
961         }
962
963         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
964         my $cmd = "";
965         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
966         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
967         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
968         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
969         $cmd .= " --machinepass=machine$ret->{PASSWORD}";
970
971         unless (system($cmd) == 0) {
972                 warn("Join failed\n$cmd");
973                 return undef;
974         }
975
976         $ret->{MEMBER_SERVER} = $ret->{SERVER};
977         $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
978         $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
979         $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
980         $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
981         $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
982
983         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
984         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
985         $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
986         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
987         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
988         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
989
990         return $ret;
991 }
992
993 sub provision_rpc_proxy($$$)
994 {
995         my ($self, $prefix, $dcvars) = @_;
996         print "PROVISIONING RPC PROXY...";
997
998         my $extra_smbconf_options = "
999         passdb backend = samba_dsdb
1000
1001         # rpc_proxy
1002         dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1003         dcerpc endpoint servers = epmapper, remote
1004         dcerpc_remote:interfaces = rpcecho
1005
1006 [cifs_to_dc]
1007         path = /tmp/_ignore_cifs_to_dc_/_none_
1008         read only = no
1009         ntvfs handler = cifs
1010         cifs:server = $dcvars->{SERVER}
1011         cifs:share = cifs
1012         cifs:use-s4u2proxy = yes
1013         # There is no username specified here, instead the client is expected
1014         # to log in with kerberos, and the serverwill use delegated credentials.
1015         # Or the server tries s4u2self/s4u2proxy to impersonate the client
1016
1017 ";
1018
1019         my $ret = $self->provision($prefix,
1020                                    "member server",
1021                                    "localrpcproxy",
1022                                    "SAMBADOMAIN",
1023                                    "samba.example.com",
1024                                    "2008",
1025                                    "locRPCproxypass4",
1026                                    $dcvars->{SERVER_IP},
1027                                    $extra_smbconf_options, "", undef);
1028
1029         unless ($ret) {
1030                 return undef;
1031         }
1032
1033         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1034
1035         # The joind runs in the context of the rpc_proxy/member for now
1036         my $cmd = "";
1037         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1038         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1039         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1040         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1041         $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1042
1043         unless (system($cmd) == 0) {
1044                 warn("Join failed\n$cmd");
1045                 return undef;
1046         }
1047
1048         # Setting up delegation runs in the context of the DC for now
1049         $cmd = "";
1050         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1051         $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1052         $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1053         $cmd .= " $dcvars->{CONFIGURATION}";
1054         print $cmd;
1055
1056         unless (system($cmd) == 0) {
1057                 warn("Delegation failed\n$cmd");
1058                 return undef;
1059         }
1060
1061         # Setting up delegation runs in the context of the DC for now
1062         $cmd = "";
1063         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1064         $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1065         $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1066         $cmd .= " $dcvars->{CONFIGURATION}";
1067
1068         unless (system($cmd) == 0) {
1069                 warn("Delegation failed\n$cmd");
1070                 return undef;
1071         }
1072
1073         $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1074         $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1075         $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1076         $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1077         $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1078         $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1079
1080         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1081         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1082         $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1083         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1084         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1085         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1086
1087         return $ret;
1088 }
1089
1090 sub provision_promoted_dc($$$)
1091 {
1092         my ($self, $prefix, $dcvars) = @_;
1093         print "PROVISIONING VAMPIRE DC...";
1094
1095         # We do this so that we don't run the provision.  That's the job of 'net vampire'.
1096         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1097                                                "promotedvdc",
1098                                                "SAMBADOMAIN",
1099                                                "samba.example.com",
1100                                                "2008",
1101                                                $dcvars->{PASSWORD},
1102                                                $dcvars->{SERVER_IP});
1103
1104         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1105
1106         $ctx->{smb_conf_extra_options} = "
1107         max xmit = 32K
1108         server max protocol = SMB2
1109
1110 [sysvol]
1111         path = $ctx->{statedir}/sysvol
1112         read only = yes
1113
1114 [netlogon]
1115         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1116         read only = no
1117
1118 ";
1119
1120         my $ret = $self->provision_raw_step1($ctx);
1121         unless ($ret) {
1122                 return undef;
1123         }
1124
1125         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1126         my $cmd = "";
1127         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1128         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1129         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1130         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1131         $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1132
1133         unless (system($cmd) == 0) {
1134                 warn("Join failed\n$cmd");
1135                 return undef;
1136         }
1137
1138         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1139         my $cmd = "";
1140         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1141         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1142         $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1143         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1144         $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1145
1146         unless (system($cmd) == 0) {
1147                 warn("Join failed\n$cmd");
1148                 return undef;
1149         }
1150
1151         $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1152         $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1153         $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1154         $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1155
1156         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1157         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1158         $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1159         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1160         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1161         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1162
1163         return $ret;
1164 }
1165
1166 sub provision_vampire_dc($$$)
1167 {
1168         my ($self, $prefix, $dcvars) = @_;
1169         print "PROVISIONING VAMPIRE DC...";
1170
1171         # We do this so that we don't run the provision.  That's the job of 'net vampire'.
1172         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1173                                                "localvampiredc",
1174                                                "SAMBADOMAIN",
1175                                                "samba.example.com",
1176                                                "2008",
1177                                                $dcvars->{PASSWORD},
1178                                                $dcvars->{SERVER_IP});
1179
1180         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1181
1182         $ctx->{smb_conf_extra_options} = "
1183         max xmit = 32K
1184         server max protocol = SMB2
1185
1186 [sysvol]
1187         path = $ctx->{statedir}/sysvol
1188         read only = yes
1189
1190 [netlogon]
1191         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1192         read only = no
1193
1194 ";
1195
1196         my $ret = $self->provision_raw_step1($ctx);
1197         unless ($ret) {
1198                 return undef;
1199         }
1200
1201         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1202         my $cmd = "";
1203         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1204         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1205         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1206         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1207         $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1208
1209         unless (system($cmd) == 0) {
1210                 warn("Join failed\n$cmd");
1211                 return undef;
1212         }
1213
1214         $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1215         $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1216         $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1217         $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1218
1219         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1220         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1221         $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1222         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1223         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1224         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1225
1226         return $ret;
1227 }
1228
1229 sub provision_subdom_dc($$$)
1230 {
1231         my ($self, $prefix, $dcvars) = @_;
1232         print "PROVISIONING SUBDOMAIN DC...";
1233
1234         # We do this so that we don't run the provision.  That's the job of 'net vampire'.
1235         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1236                                                "localsubdc",
1237                                                "SAMBASUBDOM",
1238                                                "sub.samba.example.com",
1239                                                "2008",
1240                                                $dcvars->{PASSWORD},
1241                                                undef);
1242
1243         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1244
1245         $ctx->{smb_conf_extra_options} = "
1246         max xmit = 32K
1247         server max protocol = SMB2
1248
1249 [sysvol]
1250         path = $ctx->{statedir}/sysvol
1251         read only = yes
1252
1253 [netlogon]
1254         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1255         read only = no
1256
1257 ";
1258
1259         my $ret = $self->provision_raw_step1($ctx);
1260         unless ($ret) {
1261                 return undef;
1262         }
1263
1264         my $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
1265                                                 $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
1266         Samba::mk_krb5_conf($ctx, $dc_realms);
1267
1268         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1269         my $cmd = "";
1270         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1271         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1272         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1273         $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1274         $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1275
1276         unless (system($cmd) == 0) {
1277                 warn("Join failed\n$cmd");
1278                 return undef;
1279         }
1280
1281         $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1282         $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1283         $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1284         $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1285
1286         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1287         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1288         $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1289         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1290         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1291         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1292
1293         return $ret;
1294 }
1295
1296 sub provision_dc($$)
1297 {
1298         my ($self, $prefix) = @_;
1299
1300         print "PROVISIONING DC...";
1301         my $extra_conf_options = "netbios aliases = localDC1-a
1302         server services = +winbind -winbindd";
1303         my $ret = $self->provision($prefix,
1304                                    "domain controller",
1305                                    "localdc",
1306                                    "SAMBADOMAIN",
1307                                    "samba.example.com",
1308                                    "2008",
1309                                    "locDCpass1",
1310                                    undef, $extra_conf_options, "", undef);
1311
1312         return undef unless(defined $ret);
1313         unless($self->add_wins_config("$prefix/private")) {
1314                 warn("Unable to add wins configuration");
1315                 return undef;
1316         }
1317         $ret->{NETBIOSALIAS} = "localdc1-a";
1318         $ret->{DC_SERVER} = $ret->{SERVER};
1319         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1320         $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1321         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1322         $ret->{DC_USERNAME} = $ret->{USERNAME};
1323         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1324
1325         return $ret;
1326 }
1327
1328 sub provision_fl2000dc($$)
1329 {
1330         my ($self, $prefix) = @_;
1331
1332         print "PROVISIONING DC...";
1333         my $ret = $self->provision($prefix,
1334                                    "domain controller",
1335                                    "dc5",
1336                                    "SAMBA2000",
1337                                    "samba2000.example.com",
1338                                    "2000",
1339                                    "locDCpass5",
1340                                    undef, "", "", undef);
1341
1342         unless($self->add_wins_config("$prefix/private")) {
1343                 warn("Unable to add wins configuration");
1344                 return undef;
1345         }
1346
1347         return $ret;
1348 }
1349
1350 sub provision_fl2003dc($$)
1351 {
1352         my ($self, $prefix) = @_;
1353
1354         print "PROVISIONING DC...";
1355         my $extra_conf_options = "allow dns updates = nonsecure and secure";
1356         my $ret = $self->provision($prefix,
1357                                    "domain controller",
1358                                    "dc6",
1359                                    "SAMBA2003",
1360                                    "samba2003.example.com",
1361                                    "2003",
1362                                    "locDCpass6",
1363                                    undef, $extra_conf_options, "", undef);
1364
1365         unless (defined $ret) {
1366                 return undef;
1367         }
1368
1369         $ret->{DC_SERVER} = $ret->{SERVER};
1370         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1371         $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1372         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1373         $ret->{DC_USERNAME} = $ret->{USERNAME};
1374         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1375
1376         my @samba_tool_options;
1377         push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1378         push (@samba_tool_options, "domain");
1379         push (@samba_tool_options, "passwordsettings");
1380         push (@samba_tool_options, "set");
1381         push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1382         push (@samba_tool_options, "--min-pwd-age=0");
1383         push (@samba_tool_options, "--history-length=1");
1384
1385         my $samba_tool_cmd = join(" ", @samba_tool_options);
1386
1387         unless (system($samba_tool_cmd) == 0) {
1388                 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1389                 return undef;
1390         }
1391
1392         return $ret;
1393
1394         unless($self->add_wins_config("$prefix/private")) {
1395                 warn("Unable to add wins configuration");
1396                 return undef;
1397         }
1398
1399         return $ret;
1400 }
1401
1402 sub provision_fl2008r2dc($$)
1403 {
1404         my ($self, $prefix) = @_;
1405
1406         print "PROVISIONING DC...";
1407         my $ret = $self->provision($prefix,
1408                                    "domain controller",
1409                                    "dc7",
1410                                    "SAMBA2008R2",
1411                                    "samba2008R2.example.com",
1412                                    "2008_R2",
1413                                    "locDCpass7",
1414                                    undef, "", "", undef);
1415
1416         unless ($self->add_wins_config("$prefix/private")) {
1417                 warn("Unable to add wins configuration");
1418                 return undef;
1419         }
1420
1421         return $ret;
1422 }
1423
1424
1425 sub provision_rodc($$$)
1426 {
1427         my ($self, $prefix, $dcvars) = @_;
1428         print "PROVISIONING RODC...";
1429
1430         # We do this so that we don't run the provision.  That's the job of 'net join RODC'.
1431         my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1432                                                "rodc",
1433                                                "SAMBADOMAIN",
1434                                                "samba.example.com",
1435                                                "2008",
1436                                                $dcvars->{PASSWORD},
1437                                                $dcvars->{SERVER_IP});
1438         unless ($ctx) {
1439                 return undef;
1440         }
1441
1442         push (@{$ctx->{provision_options}}, "--use-ntvfs");
1443
1444         $ctx->{share} = "$ctx->{prefix_abs}/share";
1445         push(@{$ctx->{directories}}, "$ctx->{share}");
1446
1447         $ctx->{smb_conf_extra_options} = "
1448         max xmit = 32K
1449         server max protocol = SMB2
1450
1451 [sysvol]
1452         path = $ctx->{statedir}/sysvol
1453         read only = yes
1454
1455 [netlogon]
1456         path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1457         read only = yes
1458
1459 [tmp]
1460         path = $ctx->{share}
1461         read only = no
1462         posix:sharedelay = 10000
1463         posix:oplocktimeout = 3
1464         posix:writetimeupdatedelay = 50000
1465
1466 ";
1467
1468         my $ret = $self->provision_raw_step1($ctx);
1469         unless ($ret) {
1470                 return undef;
1471         }
1472
1473         my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1474         my $cmd = "";
1475         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1476         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1477         $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1478         $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1479         $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1480
1481         unless (system($cmd) == 0) {
1482                 warn("RODC join failed\n$cmd");
1483                 return undef;
1484         }
1485
1486         # we overwrite the kdc after the RODC join
1487         # so that use the RODC as kdc and test
1488         # the proxy code
1489         $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1490         Samba::mk_krb5_conf($ctx);
1491
1492         $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1493         $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1494         $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1495         $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1496
1497         $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1498         $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1499         $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1500         $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1501         $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1502         $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1503
1504         return $ret;
1505 }
1506
1507 sub provision_plugin_s4_dc($$)
1508 {
1509         my ($self, $prefix) = @_;
1510
1511         my $prefix_abs = abs_path($prefix);
1512
1513         my $bindir_abs = abs_path($self->{bindir});
1514         my $lockdir="$prefix_abs/lockdir";
1515         my $conffile="$prefix_abs/etc/smb.conf";
1516
1517         my $extra_smbconf_options = "
1518         server services = -smb +s3fs
1519         xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1520
1521         dbwrap_tdb_mutexes:* = yes
1522
1523         kernel oplocks = no
1524         kernel change notify = no
1525
1526         syslog = no
1527         printing = bsd
1528         printcap name = /dev/null
1529
1530         max protocol = SMB3
1531         read only = no
1532         server signing = auto
1533
1534         smbd:sharedelay = 100000
1535         smbd:writetimeupdatedelay = 500000
1536         create mask = 755
1537         dos filemode = yes
1538
1539         dcerpc endpoint servers = -winreg -srvsvc
1540
1541         printcap name = /dev/null
1542
1543         addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1544         deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1545
1546         printing = vlp
1547         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1548         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1549         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1550         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1551         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1552         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1553         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1554         lpq cache time = 0
1555         print notify backchannel = yes
1556 ";
1557
1558         my $extra_smbconf_shares = "
1559
1560 [tmpenc]
1561         copy = tmp
1562         smb encrypt = required
1563
1564 [tmpcase]
1565         copy = tmp
1566         case sensitive = yes
1567
1568 [tmpguest]
1569         copy = tmp
1570         guest ok = yes
1571
1572 [hideunread]
1573         copy = tmp
1574         hide unreadable = yes
1575
1576 [durable]
1577         copy = tmp
1578         kernel share modes = no
1579         kernel oplocks = no
1580         posix locking = no
1581
1582 [print\$]
1583         copy = tmp
1584
1585 [print1]
1586         copy = tmp
1587         printable = yes
1588
1589 [print2]
1590         copy = print1
1591 [print3]
1592         copy = print1
1593 [lp]
1594         copy = print1
1595 ";
1596
1597         print "PROVISIONING PLUGIN S4 DC...";
1598         my $ret = $self->provision($prefix,
1599                                    "domain controller",
1600                                    "plugindc",
1601                                    "PLUGINDOMAIN",
1602                                    "plugindc.samba.example.com",
1603                                    "2008",
1604                                    "locDCpass1",
1605                                    undef, $extra_smbconf_options,
1606                                    $extra_smbconf_shares, undef);
1607
1608         return undef unless(defined $ret);
1609         unless($self->add_wins_config("$prefix/private")) {
1610                 warn("Unable to add wins configuration");
1611                 return undef;
1612         }
1613
1614         $ret->{DC_SERVER} = $ret->{SERVER};
1615         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1616         $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1617         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1618         $ret->{DC_USERNAME} = $ret->{USERNAME};
1619         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1620
1621         return $ret;
1622 }
1623
1624 sub provision_chgdcpass($$)
1625 {
1626         my ($self, $prefix) = @_;
1627
1628         print "PROVISIONING CHGDCPASS...";
1629         my $extra_provision_options = undef;
1630         push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1631         my $extra_conf_options = "server services = +winbind -winbindd";
1632         my $ret = $self->provision($prefix,
1633                                    "domain controller",
1634                                    "chgdcpass",
1635                                    "CHDCDOMAIN",
1636                                    "chgdcpassword.samba.example.com",
1637                                    "2008",
1638                                    "chgDCpass1",
1639                                    undef, $extra_conf_options, "",
1640                                    $extra_provision_options);
1641
1642         return undef unless(defined $ret);
1643         unless($self->add_wins_config("$prefix/private")) {
1644                 warn("Unable to add wins configuration");
1645                 return undef;
1646         }
1647         
1648         # Remove secrets.tdb from this environment to test that we
1649         # still start up on systems without the new matching
1650         # secrets.tdb records.  For this reason we don't run winbindd
1651         # in this environment
1652         unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1653                 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1654                 return undef;
1655         }
1656             
1657         $ret->{DC_SERVER} = $ret->{SERVER};
1658         $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1659         $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1660         $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1661         $ret->{DC_USERNAME} = $ret->{USERNAME};
1662         $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1663
1664         return $ret;
1665 }
1666
1667 sub teardown_env($$)
1668 {
1669         my ($self, $envvars) = @_;
1670         my $pid;
1671
1672         # This should cause samba to terminate gracefully
1673         close($envvars->{STDIN_PIPE});
1674
1675         $pid = $envvars->{SAMBA_PID};
1676         my $count = 0;
1677         my $childpid;
1678
1679         # This should give it time to write out the gcov data
1680         until ($count > 30) {
1681             if (Samba::cleanup_child($pid, "samba") == -1) {
1682                 last;
1683             }
1684             sleep(1);
1685             $count++;
1686         }
1687
1688         if ($count > 30 || kill(0, $pid)) {
1689             kill "TERM", $pid;
1690
1691             until ($count > 40) {
1692                 if (Samba::cleanup_child($pid, "samba") == -1) {
1693                     last;
1694                 }
1695                 sleep(1);
1696                 $count++;
1697             }
1698             # If it is still around, kill it
1699             warn "server process $pid took more than $count seconds to exit, killing\n";
1700             kill 9, $pid;
1701         }
1702
1703         $self->slapd_stop($envvars) if ($self->{ldap});
1704
1705         print $self->getlog_env($envvars);
1706
1707         return;
1708 }
1709
1710 sub getlog_env($$)
1711 {
1712         my ($self, $envvars) = @_;
1713         my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1714         my $out = $title;
1715
1716         open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1717
1718         seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1719         while (<LOG>) {
1720                 $out .= $_;
1721         }
1722         $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1723         close(LOG);
1724
1725         return "" if $out eq $title;
1726
1727         return $out;
1728 }
1729
1730 sub check_env($$)
1731 {
1732         my ($self, $envvars) = @_;
1733
1734         my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
1735
1736         return ($childpid == 0);
1737 }
1738
1739 sub setup_env($$$)
1740 {
1741         my ($self, $envname, $path) = @_;
1742         my $target3 = $self->{target3};
1743
1744         $ENV{ENVNAME} = $envname;
1745
1746         if (defined($self->{vars}->{$envname})) {
1747                 return $self->{vars}->{$envname};
1748         }
1749
1750         if ($envname eq "dc") {
1751                 return $self->setup_dc("$path/dc");
1752         } elsif ($envname eq "fl2000dc") {
1753                 return $self->setup_fl2000dc("$path/fl2000dc");
1754         } elsif ($envname eq "fl2003dc") {
1755                 return $self->setup_fl2003dc("$path/fl2003dc");
1756         } elsif ($envname eq "fl2008r2dc") {
1757                 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1758         } elsif ($envname eq "rpc_proxy") {
1759                 if (not defined($self->{vars}->{dc})) {
1760                         $self->setup_dc("$path/dc");
1761                 }
1762                 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1763         } elsif ($envname eq "vampire_dc") {
1764                 if (not defined($self->{vars}->{dc})) {
1765                         $self->setup_dc("$path/dc");
1766                 }
1767                 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1768         } elsif ($envname eq "promoted_dc") {
1769                 if (not defined($self->{vars}->{dc})) {
1770                         $self->setup_dc("$path/dc");
1771                 }
1772                 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{dc});
1773         } elsif ($envname eq "subdom_dc") {
1774                 if (not defined($self->{vars}->{dc})) {
1775                         $self->setup_dc("$path/dc");
1776                 }
1777                 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
1778         } elsif ($envname eq "s4member") {
1779                 if (not defined($self->{vars}->{dc})) {
1780                         $self->setup_dc("$path/dc");
1781                 }
1782                 return $self->setup_s4member("$path/s4member", $self->{vars}->{dc});
1783         } elsif ($envname eq "rodc") {
1784                 if (not defined($self->{vars}->{dc})) {
1785                         $self->setup_dc("$path/dc");
1786                 }
1787                 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1788         } elsif ($envname eq "chgdcpass") {
1789                 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
1790         } elsif ($envname eq "s3member") {
1791                 if (not defined($self->{vars}->{dc})) {
1792                         $self->setup_dc("$path/dc");
1793                 }
1794                 return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
1795         } elsif ($envname eq "plugin_s4_dc") {
1796                 return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
1797         } elsif ($envname eq "s3member_rfc2307") {
1798                 if (not defined($self->{vars}->{dc})) {
1799                         $self->setup_dc("$path/dc");
1800                 }
1801                 return $target3->setup_admember_rfc2307("$path/s3member_rfc2307",
1802                                                         $self->{vars}->{dc}, 34);
1803         } else {
1804                 return "UNKNOWN";
1805         }
1806 }
1807
1808 sub setup_s4member($$$)
1809 {
1810         my ($self, $path, $dc_vars) = @_;
1811
1812         my $env = $self->provision_s4member($path, $dc_vars);
1813
1814         if (defined $env) {
1815                 $self->check_or_start($env, "single");
1816
1817                 $self->wait_for_start($env);
1818
1819                 $self->{vars}->{s4member} = $env;
1820         }
1821
1822         return $env;
1823 }
1824
1825 sub setup_rpc_proxy($$$)
1826 {
1827         my ($self, $path, $dc_vars) = @_;
1828
1829         my $env = $self->provision_rpc_proxy($path, $dc_vars);
1830
1831         if (defined $env) {
1832                 $self->check_or_start($env, "single");
1833
1834                 $self->wait_for_start($env);
1835
1836                 $self->{vars}->{rpc_proxy} = $env;
1837         }
1838         return $env;
1839 }
1840
1841 sub setup_dc($$)
1842 {
1843         my ($self, $path) = @_;
1844
1845         my $env = $self->provision_dc($path);
1846         if (defined $env) {
1847                 $self->check_or_start($env, "standard");
1848
1849                 $self->wait_for_start($env);
1850
1851                 $self->{vars}->{dc} = $env;
1852         }
1853         return $env;
1854 }
1855
1856 sub setup_chgdcpass($$)
1857 {
1858         my ($self, $path) = @_;
1859
1860         my $env = $self->provision_chgdcpass($path);
1861         if (defined $env) {
1862                 $self->check_or_start($env, "single");
1863
1864                 $self->wait_for_start($env);
1865
1866                 $self->{vars}->{chgdcpass} = $env;
1867         }
1868         return $env;
1869 }
1870
1871 sub setup_fl2000dc($$)
1872 {
1873         my ($self, $path) = @_;
1874
1875         my $env = $self->provision_fl2000dc($path);
1876         if (defined $env) {
1877                 $self->check_or_start($env, "single");
1878
1879                 $self->wait_for_start($env);
1880
1881                 $self->{vars}->{fl2000dc} = $env;
1882         }
1883
1884         return $env;
1885 }
1886
1887 sub setup_fl2003dc($$)
1888 {
1889         my ($self, $path) = @_;
1890
1891         my $env = $self->provision_fl2003dc($path);
1892
1893         if (defined $env) {
1894                 $self->check_or_start($env, "single");
1895
1896                 $self->wait_for_start($env);
1897
1898                 $self->{vars}->{fl2003dc} = $env;
1899         }
1900         return $env;
1901 }
1902
1903 sub setup_fl2008r2dc($$)
1904 {
1905         my ($self, $path) = @_;
1906
1907         my $env = $self->provision_fl2008r2dc($path);
1908
1909         if (defined $env) {
1910                 $self->check_or_start($env, "single");
1911
1912                 $self->wait_for_start($env);
1913
1914                 $self->{vars}->{fl2008r2dc} = $env;
1915         }
1916
1917         return $env;
1918 }
1919
1920 sub setup_vampire_dc($$$)
1921 {
1922         my ($self, $path, $dc_vars) = @_;
1923
1924         my $env = $self->provision_vampire_dc($path, $dc_vars);
1925
1926         if (defined $env) {
1927                 $self->check_or_start($env, "single");
1928
1929                 $self->wait_for_start($env);
1930
1931                 $self->{vars}->{vampire_dc} = $env;
1932
1933                 # force replicated DC to update repsTo/repsFrom
1934                 # for vampired partitions
1935                 my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1936                 my $cmd = "";
1937                 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1938                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1939                 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1940                 $cmd .= " $env->{CONFIGURATION}";
1941                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1942                 unless (system($cmd) == 0) {
1943                         warn("Failed to exec kcc\n$cmd");
1944                         return undef;
1945                 }
1946
1947                 # as 'vampired' dc may add data in its local replica
1948                 # we need to synchronize data between DCs
1949                 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1950                 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1951                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1952                 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1953                 $cmd .= " $dc_vars->{CONFIGURATION}";
1954                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1955                 # replicate Configuration NC
1956                 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1957                 unless(system($cmd_repl) == 0) {
1958                         warn("Failed to replicate\n$cmd_repl");
1959                         return undef;
1960                 }
1961                 # replicate Default NC
1962                 $cmd_repl = "$cmd \"$base_dn\"";
1963                 unless(system($cmd_repl) == 0) {
1964                         warn("Failed to replicate\n$cmd_repl");
1965                         return undef;
1966                 }
1967         }
1968
1969         return $env;
1970 }
1971
1972 sub setup_promoted_dc($$$)
1973 {
1974         my ($self, $path, $dc_vars) = @_;
1975
1976         my $env = $self->provision_promoted_dc($path, $dc_vars);
1977
1978         if (defined $env) {
1979                 $self->check_or_start($env, "single");
1980
1981                 $self->wait_for_start($env);
1982
1983                 $self->{vars}->{promoted_dc} = $env;
1984
1985                 # force replicated DC to update repsTo/repsFrom
1986                 # for vampired partitions
1987                 my $samba_tool =  Samba::bindir_path($self, "samba-tool");
1988                 my $cmd = "";
1989                 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1990                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1991                 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1992                 $cmd .= " $env->{CONFIGURATION}";
1993                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1994                 unless (system($cmd) == 0) {
1995                         warn("Failed to exec kcc\n$cmd");
1996                         return undef;
1997                 }
1998
1999                 # as 'vampired' dc may add data in its local replica
2000                 # we need to synchronize data between DCs
2001                 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2002                 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2003                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2004                 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2005                 $cmd .= " $dc_vars->{CONFIGURATION}";
2006                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2007                 # replicate Configuration NC
2008                 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2009                 unless(system($cmd_repl) == 0) {
2010                         warn("Failed to replicate\n$cmd_repl");
2011                         return undef;
2012                 }
2013                 # replicate Default NC
2014                 $cmd_repl = "$cmd \"$base_dn\"";
2015                 unless(system($cmd_repl) == 0) {
2016                         warn("Failed to replicate\n$cmd_repl");
2017                         return undef;
2018                 }
2019         }
2020
2021         return $env;
2022 }
2023
2024 sub setup_subdom_dc($$$)
2025 {
2026         my ($self, $path, $dc_vars) = @_;
2027
2028         my $env = $self->provision_subdom_dc($path, $dc_vars);
2029
2030         if (defined $env) {
2031                 $self->check_or_start($env, "single");
2032
2033                 $self->wait_for_start($env);
2034
2035                 $self->{vars}->{subdom_dc} = $env;
2036
2037                 # force replicated DC to update repsTo/repsFrom
2038                 # for primary domain partitions
2039                 my $samba_tool =  Samba::bindir_path($self, "samba-tool");
2040                 my $cmd = "";
2041                 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2042                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2043                 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
2044                 $cmd .= " $env->{CONFIGURATION}";
2045                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2046                 unless (system($cmd) == 0) {
2047                         warn("Failed to exec kcc\n$cmd");
2048                         return undef;
2049                 }
2050
2051                 # as 'subdomain' dc may add data in its local replica
2052                 # we need to synchronize data between DCs
2053                 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2054                 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2055                 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2056                 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2057                 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2058                 $cmd .= " $dc_vars->{CONFIGURATION}";
2059                 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2060                 # replicate Configuration NC
2061                 my $cmd_repl = "$cmd \"$config_dn\"";
2062                 unless(system($cmd_repl) == 0) {
2063                         warn("Failed to replicate\n$cmd_repl");
2064                         return undef;
2065                 }
2066                 # replicate Default NC
2067                 $cmd_repl = "$cmd \"$base_dn\"";
2068                 unless(system($cmd_repl) == 0) {
2069                         warn("Failed to replicate\n$cmd_repl");
2070                         return undef;
2071                 }
2072         }
2073
2074         return $env;
2075 }
2076
2077 sub setup_rodc($$$)
2078 {
2079         my ($self, $path, $dc_vars) = @_;
2080
2081         my $env = $self->provision_rodc($path, $dc_vars);
2082
2083         unless ($env) {
2084                 return undef;
2085         }
2086
2087         $self->check_or_start($env, "single");
2088
2089         $self->wait_for_start($env);
2090
2091         $self->{vars}->{rodc} = $env;
2092
2093         return $env;
2094 }
2095
2096 sub setup_plugin_s4_dc($$)
2097 {
2098         my ($self, $path) = @_;
2099
2100         # If we didn't build with ADS, pretend this env was never available
2101         if (not $self->{target3}->have_ads()) {
2102                return "UNKNOWN";
2103         }
2104
2105         my $env = $self->provision_plugin_s4_dc($path);
2106         unless ($env) {
2107                 return undef;
2108         }
2109
2110         $self->check_or_start($env, "single");
2111         
2112         $self->wait_for_start($env);
2113         
2114         $self->{vars}->{plugin_s4_dc} = $env;
2115         return $env;
2116 }
2117
2118 1;