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