spoolss: accept XPS_PASS datatype used by Windows 8
[Samba.git] / selftest / target / Samba4.pm
blob96d1657ea8f0075c5bccbca3b4b807212ba1f846
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, $server_maxtime) = @_;
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)
28 bless $self;
29 return $self;
32 sub scriptdir_path($$) {
33 my ($self, $path) = @_;
34 return "$self->{srcdir}/source4/scripting/$path";
37 sub openldap_start($$$) {
40 sub slapd_start($$)
42 my $count = 0;
43 my ($self, $env_vars, $STDIN_READER) = @_;
44 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
46 my $uri = $env_vars->{LDAP_URI};
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;
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: $!";
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);
66 die("Unable to start slapd: $!");
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;
76 sleep(1);
78 return 1;
81 sub slapd_stop($$)
83 my ($self, $envvars) = @_;
84 kill 9, $envvars->{SLAPD_PID};
85 return 1;
88 sub check_or_start($$$)
90 my ($self, $env_vars, $process_model) = @_;
91 my $STDIN_READER;
93 return 0 if $self->check_env($env_vars);
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});
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;
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';
117 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
119 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
120 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
121 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
123 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
124 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
125 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
127 $ENV{UID_WRAPPER} = "1";
129 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
130 my @preargs = ();
131 my @optargs = ();
132 if (defined($ENV{SAMBA_OPTIONS})) {
133 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
135 if(defined($ENV{SAMBA_VALGRIND})) {
136 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
139 close($env_vars->{STDIN_PIPE});
140 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
142 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: $!");
144 $env_vars->{SAMBA_PID} = $pid;
145 print "DONE\n";
147 close($STDIN_READER);
149 return $pid;
152 sub wait_for_start($$)
154 my ($self, $testenv_vars) = @_;
155 my $ret;
156 # give time for nbt server to register its names
157 print "delaying for nbt name registration\n";
158 sleep 2;
160 # This will return quickly when things are up, but be slow if we
161 # need to wait for (eg) SSL init
162 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
163 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
164 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
165 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
166 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
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->{SERVER}");
170 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
171 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
172 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
173 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
174 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
176 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
177 if ($testenv_vars->{SERVER_ROLE} eq "domain controller" and not ($testenv_vars->{NETBIOS_NAME} eq "rodc")) {
178 print "waiting for working LDAP and a RID Set to be allocated\n";
179 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
180 my $count = 0;
181 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
182 my $rid_set_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
183 sleep(1);
184 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) {
185 $count++;
186 if ($count > 40) {
187 $ret = 1;
188 last;
190 sleep(1);
193 print $self->getlog_env($testenv_vars);
195 return $ret
198 sub write_ldb_file($$$)
200 my ($self, $file, $ldif) = @_;
202 my $ldbadd = Samba::bindir_path($self, "ldbadd");
203 open(LDIF, "|$ldbadd -H $file >/dev/null");
204 print LDIF $ldif;
205 return(close(LDIF));
208 sub add_wins_config($$)
210 my ($self, $privatedir) = @_;
212 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
213 dn: name=TORTURE_11,CN=PARTNERS
214 objectClass: wreplPartner
215 name: TORTURE_11
216 address: 127.0.0.11
217 pullInterval: 0
218 pushChangeCount: 0
219 type: 0x3
223 sub mk_fedora_ds($$)
225 my ($self, $ctx) = @_;
227 #Make the subdirectory be as fedora DS would expect
228 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
230 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
232 return ($fedora_ds_dir, $pidfile);
235 sub mk_openldap($$)
237 my ($self, $ctx) = @_;
239 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
240 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
242 return ($slapd_conf_d, $pidfile);
245 sub mk_keyblobs($$)
247 my ($self, $tlsdir) = @_;
249 #TLS and PKINIT crypto blobs
250 my $dhfile = "$tlsdir/dhparms.pem";
251 my $cafile = "$tlsdir/ca.pem";
252 my $certfile = "$tlsdir/cert.pem";
253 my $reqkdc = "$tlsdir/req-kdc.der";
254 my $kdccertfile = "$tlsdir/kdc.pem";
255 my $keyfile = "$tlsdir/key.pem";
256 my $adminkeyfile = "$tlsdir/adminkey.pem";
257 my $reqadmin = "$tlsdir/req-admin.der";
258 my $admincertfile = "$tlsdir/admincert.pem";
259 my $admincertupnfile = "$tlsdir/admincertupn.pem";
261 mkdir($tlsdir, 0700);
262 my $oldumask = umask;
263 umask 0077;
265 #This is specified here to avoid draining entropy on every run
266 open(DHFILE, ">$dhfile");
267 print DHFILE <<EOF;
268 -----BEGIN DH PARAMETERS-----
269 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
270 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
271 YX70obsCAQI=
272 -----END DH PARAMETERS-----
274 close(DHFILE);
276 #Likewise, we pregenerate the key material. This allows the
277 #other certificates to be pre-generated
278 open(KEYFILE, ">$keyfile");
279 print KEYFILE <<EOF;
280 -----BEGIN RSA PRIVATE KEY-----
281 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
282 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
283 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
284 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
285 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
286 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
287 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
288 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
289 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
290 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
291 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
292 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
293 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
294 -----END RSA PRIVATE KEY-----
296 close(KEYFILE);
298 open(ADMINKEYFILE, ">$adminkeyfile");
300 print ADMINKEYFILE <<EOF;
301 -----BEGIN RSA PRIVATE KEY-----
302 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
303 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
304 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
305 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
306 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
307 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
308 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
309 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
310 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
311 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
312 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
313 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
314 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
315 -----END RSA PRIVATE KEY-----
318 #generated with
319 # hxtool issue-certificate --self-signed --issue-ca \
320 # --ca-private-key="FILE:$KEYFILE" \
321 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
322 # --certificate="FILE:$CAFILE" --lifetime="25 years"
324 open(CAFILE, ">$cafile");
325 print CAFILE <<EOF;
326 -----BEGIN CERTIFICATE-----
327 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
328 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
329 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
330 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
331 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
332 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
333 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
334 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
335 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
336 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
337 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
338 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
339 -----END CERTIFICATE-----
342 #generated with GNUTLS internally in Samba.
344 open(CERTFILE, ">$certfile");
345 print CERTFILE <<EOF;
346 -----BEGIN CERTIFICATE-----
347 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
348 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
349 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
350 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
351 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
352 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
353 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
354 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
355 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
356 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
357 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
358 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
359 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
360 -----END CERTIFICATE-----
362 close(CERTFILE);
364 #KDC certificate
365 # hxtool request-create \
366 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
367 # --key="FILE:$KEYFILE" $KDCREQ
369 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
370 # --type="pkinit-kdc" \
371 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
372 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
373 # --lifetime="25 years"
375 open(KDCCERTFILE, ">$kdccertfile");
376 print KDCCERTFILE <<EOF;
377 -----BEGIN CERTIFICATE-----
378 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
379 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
380 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
381 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
382 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
383 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
384 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
385 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
386 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
387 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
388 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
389 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
390 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
391 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
392 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
393 -----END CERTIFICATE-----
396 # hxtool request-create \
397 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
398 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
400 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
401 # --type="pkinit-client" \
402 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
403 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
404 # --lifetime="25 years"
406 open(ADMINCERTFILE, ">$admincertfile");
407 print ADMINCERTFILE <<EOF;
408 -----BEGIN CERTIFICATE-----
409 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
410 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
411 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
412 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
413 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
414 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
415 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
416 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
417 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
418 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
419 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
420 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
421 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
422 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
423 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
424 -----END CERTIFICATE-----
426 close(ADMINCERTFILE);
428 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
429 # --type="pkinit-client" \
430 # --ms-upn="administrator@samba.example.com" \
431 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
432 # --lifetime="25 years"
434 open(ADMINCERTUPNFILE, ">$admincertupnfile");
435 print ADMINCERTUPNFILE <<EOF;
436 -----BEGIN CERTIFICATE-----
437 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
438 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
439 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
440 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
441 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
442 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
443 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
444 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
445 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
446 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
447 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
448 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
449 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
450 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
451 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
452 -----END CERTIFICATE-----
455 umask $oldumask;
458 sub provision_raw_prepare($$$$$$$$$$)
460 my ($self, $prefix, $server_role, $hostname,
461 $domain, $realm, $functional_level,
462 $password, $kdc_ipv4) = @_;
463 my $ctx;
464 my $netbiosname = uc($hostname);
466 unless(-d $prefix or mkdir($prefix, 0777)) {
467 warn("Unable to create $prefix");
468 return undef;
470 my $prefix_abs = abs_path($prefix);
472 die ("prefix=''") if $prefix_abs eq "";
473 die ("prefix='/'") if $prefix_abs eq "/";
475 unless (system("rm -rf $prefix_abs/*") == 0) {
476 warn("Unable to clean up");
480 my $swiface = Samba::get_interface($hostname);
482 $ctx->{prefix} = $prefix;
483 $ctx->{prefix_abs} = $prefix_abs;
485 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
487 $ctx->{server_role} = $server_role;
488 $ctx->{hostname} = $hostname;
489 $ctx->{netbiosname} = $netbiosname;
490 $ctx->{swiface} = $swiface;
491 $ctx->{password} = $password;
492 $ctx->{kdc_ipv4} = $kdc_ipv4;
495 # Set smbd log level here.
497 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
498 $ctx->{username} = "Administrator";
499 $ctx->{domain} = $domain;
500 $ctx->{realm} = uc($realm);
501 $ctx->{dnsname} = lc($realm);
503 $ctx->{functional_level} = $functional_level;
505 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
506 chomp $unix_name;
507 $ctx->{unix_name} = $unix_name;
508 $ctx->{unix_uid} = $>;
509 $ctx->{unix_gids_str} = $);
510 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
512 $ctx->{etcdir} = "$prefix_abs/etc";
513 $ctx->{piddir} = "$prefix_abs/pid";
514 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
515 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
516 $ctx->{privatedir} = "$prefix_abs/private";
517 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
518 $ctx->{lockdir} = "$prefix_abs/lockdir";
519 $ctx->{logdir} = "$prefix_abs/logs";
520 $ctx->{statedir} = "$prefix_abs/statedir";
521 $ctx->{cachedir} = "$prefix_abs/cachedir";
522 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
523 $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
524 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
525 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
526 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
528 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
530 $ctx->{ipv4} = "127.0.0.$swiface";
531 $ctx->{interfaces} = "$ctx->{ipv4}/8";
533 push(@{$ctx->{directories}}, $ctx->{privatedir});
534 push(@{$ctx->{directories}}, $ctx->{etcdir});
535 push(@{$ctx->{directories}}, $ctx->{piddir});
536 push(@{$ctx->{directories}}, $ctx->{lockdir});
537 push(@{$ctx->{directories}}, $ctx->{logdir});
538 push(@{$ctx->{directories}}, $ctx->{statedir});
539 push(@{$ctx->{directories}}, $ctx->{cachedir});
541 $ctx->{smb_conf_extra_options} = "";
543 my @provision_options = ();
544 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
545 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
546 if (defined($ENV{GDB_PROVISION})) {
547 push (@provision_options, "gdb --args");
548 if (!defined($ENV{PYTHON})) {
549 push (@provision_options, "env");
550 push (@provision_options, "python");
553 if (defined($ENV{VALGRIND_PROVISION})) {
554 push (@provision_options, "valgrind");
555 if (!defined($ENV{PYTHON})) {
556 push (@provision_options, "env");
557 push (@provision_options, "python");
560 if (defined($ENV{PYTHON})) {
561 push (@provision_options, $ENV{PYTHON});
563 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
564 push (@provision_options, "domain");
565 push (@provision_options, "provision");
566 push (@provision_options, "--configfile=$ctx->{smb_conf}");
567 push (@provision_options, "--host-name=$ctx->{hostname}");
568 push (@provision_options, "--host-ip=$ctx->{ipv4}");
569 push (@provision_options, "--quiet");
570 push (@provision_options, "--domain=$ctx->{domain}");
571 push (@provision_options, "--realm=$ctx->{realm}");
572 push (@provision_options, "--adminpass=$ctx->{password}");
573 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
574 push (@provision_options, "--machinepass=machine$ctx->{password}");
575 push (@provision_options, "--root=$ctx->{unix_name}");
576 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
577 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
579 @{$ctx->{provision_options}} = @provision_options;
581 return $ctx;
585 # Step1 creates the basic configuration
587 sub provision_raw_step1($$)
589 my ($self, $ctx) = @_;
591 mkdir($_, 0777) foreach (@{$ctx->{directories}});
594 ## lockdir and piddir must be 0755
596 chmod 0755, $ctx->{lockdir};
597 chmod 0755, $ctx->{piddir};
599 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
600 warn("can't open $ctx->{smb_conf}$?");
601 return undef;
603 print CONFFILE "
604 [global]
605 netbios name = $ctx->{netbiosname}
606 posix:eadb = $ctx->{statedir}/eadb.tdb
607 workgroup = $ctx->{domain}
608 realm = $ctx->{realm}
609 private dir = $ctx->{privatedir}
610 pid directory = $ctx->{piddir}
611 ncalrpc dir = $ctx->{ncalrpcdir}
612 lock dir = $ctx->{lockdir}
613 state directory = $ctx->{statedir}
614 cache directory = $ctx->{cachedir}
615 winbindd socket directory = $ctx->{winbindd_socket_dir}
616 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
617 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
618 winbind separator = /
619 name resolve order = file bcast
620 interfaces = $ctx->{interfaces}
621 tls dh params file = $ctx->{tlsdir}/dhparms.pem
622 panic action = $RealBin/gdb_backtrace \%d
623 wins support = yes
624 server role = $ctx->{server_role}
625 server services = +echo +smb -s3fs
626 dcerpc endpoint servers = +winreg +srvsvc
627 notify:inotify = false
628 ldb:nosync = true
629 #We don't want to pass our self-tests if the PAC code is wrong
630 gensec:require_pac = true
631 log file = $ctx->{logdir}/log.\%m
632 log level = $ctx->{server_loglevel}
633 lanman auth = Yes
634 rndc command = true
635 dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file} -s $ctx->{smb_conf}
636 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
637 resolv:host file = $ctx->{dns_host_file}
638 dreplsrv:periodic_startup_interval = 0
639 dsdb:schema update allowed = yes
641 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
643 # remove this again, when our smb2 client library
644 # supports signin on compound related requests
645 server signing = on
647 idmap_ldb:use rfc2307=yes
650 print CONFFILE "
652 # Begin extra options
653 $ctx->{smb_conf_extra_options}
654 # End extra options
656 close(CONFFILE);
658 $self->mk_keyblobs($ctx->{tlsdir});
660 #Default the KDC IP to the server's IP
661 if (not defined($ctx->{kdc_ipv4})) {
662 $ctx->{kdc_ipv4} = $ctx->{ipv4};
665 Samba::mk_krb5_conf($ctx, "");
667 open(PWD, ">$ctx->{nsswrap_passwd}");
668 print PWD "
669 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
670 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
671 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
673 close(PWD);
674 my $uid_rfc2307test = 65533;
676 open(GRP, ">$ctx->{nsswrap_group}");
677 print GRP "
678 root:x:0:
679 wheel:x:10:
680 users:x:100:
681 nobody:x:65533:
682 nogroup:x:65534:nobody
684 close(GRP);
685 my $gid_rfc2307test = 65532;
687 my $configuration = "--configfile=$ctx->{smb_conf}";
689 #Ensure the config file is valid before we start
690 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
691 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
692 system("$testparm -v --suppress-prompt $configuration >&2");
693 warn("Failed to create a valid smb.conf configuration $testparm!");
694 return undef;
696 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) {
697 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
698 return undef;
701 my $ret = {
702 KRB5_CONFIG => $ctx->{krb5_conf},
703 PIDDIR => $ctx->{piddir},
704 SERVER => $ctx->{hostname},
705 SERVER_IP => $ctx->{ipv4},
706 NETBIOSNAME => $ctx->{netbiosname},
707 DOMAIN => $ctx->{domain},
708 USERNAME => $ctx->{username},
709 REALM => $ctx->{realm},
710 PASSWORD => $ctx->{password},
711 LDAPDIR => $ctx->{ldapdir},
712 LDAP_INSTANCE => $ctx->{ldap_instance},
713 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
714 NCALRPCDIR => $ctx->{ncalrpcdir},
715 LOCKDIR => $ctx->{lockdir},
716 STATEDIR => $ctx->{statedir},
717 CACHEDIR => $ctx->{cachedir},
718 PRIVATEDIR => $ctx->{privatedir},
719 SERVERCONFFILE => $ctx->{smb_conf},
720 CONFIGURATION => $configuration,
721 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
722 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
723 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
724 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
725 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
726 SAMBA_TEST_LOG_POS => 0,
727 NSS_WRAPPER_WINBIND_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
728 LOCAL_PATH => $ctx->{share},
729 UID_RFC2307TEST => $uid_rfc2307test,
730 GID_RFC2307TEST => $gid_rfc2307test,
731 SERVER_ROLE => $ctx->{server_role}
734 return $ret;
738 # Step2 runs the provision script
740 sub provision_raw_step2($$$)
742 my ($self, $ctx, $ret) = @_;
744 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
745 unless (system($provision_cmd) == 0) {
746 warn("Unable to provision: \n$provision_cmd\n");
747 return undef;
750 return $ret;
753 sub provision($$$$$$$$$)
755 my ($self, $prefix, $server_role, $hostname,
756 $domain, $realm, $functional_level,
757 $password, $kdc_ipv4, $extra_smbconf_options, $extra_smbconf_shares,
758 $extra_provision_options) = @_;
760 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
761 $hostname,
762 $domain, $realm, $functional_level,
763 $password, $kdc_ipv4);
765 if (defined($extra_provision_options)) {
766 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
767 } else {
768 push (@{$ctx->{provision_options}}, "--use-ntvfs");
771 $ctx->{share} = "$ctx->{prefix_abs}/share";
772 push(@{$ctx->{directories}}, "$ctx->{share}");
773 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
774 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
776 # precreate directories for printer drivers
777 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
778 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
779 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
781 my $msdfs = "no";
782 $msdfs = "yes" if ($server_role eq "domain controller");
783 $ctx->{smb_conf_extra_options} = "
785 max xmit = 32K
786 server max protocol = SMB2
787 host msdfs = $msdfs
788 lanman auth = yes
790 $extra_smbconf_options
792 [tmp]
793 path = $ctx->{share}
794 read only = no
795 posix:sharedelay = 10000
796 posix:oplocktimeout = 3
797 posix:writetimeupdatedelay = 50000
799 [xcopy_share]
800 path = $ctx->{share}
801 read only = no
802 posix:sharedelay = 10000
803 posix:oplocktimeout = 3
804 posix:writetimeupdatedelay = 50000
805 create mask = 777
806 force create mode = 777
808 [posix_share]
809 path = $ctx->{share}
810 read only = no
811 create mask = 0777
812 force create mode = 0
813 directory mask = 0777
814 force directory mode = 0
816 [test1]
817 path = $ctx->{share}/test1
818 read only = no
819 posix:sharedelay = 10000
820 posix:oplocktimeout = 3
821 posix:writetimeupdatedelay = 50000
823 [test2]
824 path = $ctx->{share}/test2
825 read only = no
826 posix:sharedelay = 10000
827 posix:oplocktimeout = 3
828 posix:writetimeupdatedelay = 50000
830 [cifs]
831 read only = no
832 ntvfs handler = cifs
833 cifs:server = $ctx->{netbiosname}
834 cifs:share = tmp
835 cifs:use-s4u2proxy = yes
836 # There is no username specified here, instead the client is expected
837 # to log in with kerberos, and the serverwill use delegated credentials.
838 # Or the server tries s4u2self/s4u2proxy to impersonate the client
840 [simple]
841 path = $ctx->{share}
842 read only = no
843 ntvfs handler = simple
845 [sysvol]
846 path = $ctx->{statedir}/sysvol
847 read only = no
849 [netlogon]
850 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
851 read only = no
853 [cifsposix]
854 copy = simple
855 ntvfs handler = cifsposix
857 $extra_smbconf_shares
860 if (defined($self->{ldap})) {
861 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
862 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
864 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
865 $ldap_uri =~ s|/|%2F|g;
866 $ldap_uri = "ldapi://$ldap_uri";
867 $ctx->{ldap_uri} = $ldap_uri;
869 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
872 my $ret = $self->provision_raw_step1($ctx);
873 unless (defined $ret) {
874 return undef;
877 if (defined($self->{ldap})) {
878 $ret->{LDAP_URI} = $ctx->{ldap_uri};
879 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
880 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
881 if ($self->{ldap} eq "openldap") {
882 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
883 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
885 } elsif ($self->{ldap} eq "fedora-ds") {
886 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
887 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
888 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
893 return $self->provision_raw_step2($ctx, $ret);
896 sub provision_member($$$)
898 my ($self, $prefix, $dcvars) = @_;
899 print "PROVISIONING MEMBER...";
901 my $ret = $self->provision($prefix,
902 "member server",
903 "s4member",
904 "SAMBADOMAIN",
905 "samba.example.com",
906 "2008",
907 "locMEMpass3",
908 $dcvars->{SERVER_IP},
909 "", "", undef);
910 unless ($ret) {
911 return undef;
914 my $samba_tool = Samba::bindir_path($self, "samba-tool");
915 my $cmd = "";
916 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
917 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
918 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
919 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
920 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
922 unless (system($cmd) == 0) {
923 warn("Join failed\n$cmd");
924 return undef;
927 $ret->{MEMBER_SERVER} = $ret->{SERVER};
928 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
929 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
930 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
931 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
933 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
934 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
935 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
936 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
937 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
939 return $ret;
942 sub provision_rpc_proxy($$$)
944 my ($self, $prefix, $dcvars) = @_;
945 print "PROVISIONING RPC PROXY...";
947 my $extra_smbconf_options = "
949 # rpc_proxy
950 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
951 dcerpc endpoint servers = epmapper, remote
952 dcerpc_remote:interfaces = rpcecho
954 [cifs_to_dc]
955 read only = no
956 ntvfs handler = cifs
957 cifs:server = $dcvars->{SERVER}
958 cifs:share = cifs
959 cifs:use-s4u2proxy = yes
960 # There is no username specified here, instead the client is expected
961 # to log in with kerberos, and the serverwill use delegated credentials.
962 # Or the server tries s4u2self/s4u2proxy to impersonate the client
966 my $ret = $self->provision($prefix,
967 "member server",
968 "localrpcproxy",
969 "SAMBADOMAIN",
970 "samba.example.com",
971 "2008",
972 "locRPCproxypass4",
973 $dcvars->{SERVER_IP},
974 $extra_smbconf_options, "", undef);
976 unless ($ret) {
977 return undef;
980 my $samba_tool = Samba::bindir_path($self, "samba-tool");
982 # The joind runs in the context of the rpc_proxy/member for now
983 my $cmd = "";
984 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
985 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
986 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
987 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
988 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
990 unless (system($cmd) == 0) {
991 warn("Join failed\n$cmd");
992 return undef;
995 # Setting up delegation runs in the context of the DC for now
996 $cmd = "";
997 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
998 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
999 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1000 $cmd .= " $dcvars->{CONFIGURATION}";
1001 print $cmd;
1003 unless (system($cmd) == 0) {
1004 warn("Delegation failed\n$cmd");
1005 return undef;
1008 # Setting up delegation runs in the context of the DC for now
1009 $cmd = "";
1010 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1011 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1012 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1013 $cmd .= " $dcvars->{CONFIGURATION}";
1015 unless (system($cmd) == 0) {
1016 warn("Delegation failed\n$cmd");
1017 return undef;
1020 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1021 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1022 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1023 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1024 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1026 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1027 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1028 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1029 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1030 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1032 return $ret;
1035 sub provision_promoted_dc($$$)
1037 my ($self, $prefix, $dcvars) = @_;
1038 print "PROVISIONING VAMPIRE DC...";
1040 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1041 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1042 "promotedvdc",
1043 "SAMBADOMAIN",
1044 "samba.example.com",
1045 "2008",
1046 $dcvars->{PASSWORD},
1047 $dcvars->{SERVER_IP});
1049 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1051 $ctx->{smb_conf_extra_options} = "
1052 max xmit = 32K
1053 server max protocol = SMB2
1055 [sysvol]
1056 path = $ctx->{statedir}/sysvol
1057 read only = yes
1059 [netlogon]
1060 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1061 read only = no
1065 my $ret = $self->provision_raw_step1($ctx);
1066 unless ($ret) {
1067 return undef;
1070 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1071 my $cmd = "";
1072 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1073 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1074 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1075 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1076 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1078 unless (system($cmd) == 0) {
1079 warn("Join failed\n$cmd");
1080 return undef;
1083 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1084 my $cmd = "";
1085 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1086 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1087 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1088 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1089 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1091 unless (system($cmd) == 0) {
1092 warn("Join failed\n$cmd");
1093 return undef;
1096 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1097 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1098 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1100 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1101 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1102 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1103 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1104 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1106 return $ret;
1109 sub provision_vampire_dc($$$)
1111 my ($self, $prefix, $dcvars) = @_;
1112 print "PROVISIONING VAMPIRE DC...";
1114 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1115 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1116 "localvampiredc",
1117 "SAMBADOMAIN",
1118 "samba.example.com",
1119 "2008",
1120 $dcvars->{PASSWORD},
1121 $dcvars->{SERVER_IP});
1123 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1125 $ctx->{smb_conf_extra_options} = "
1126 max xmit = 32K
1127 server max protocol = SMB2
1129 [sysvol]
1130 path = $ctx->{statedir}/sysvol
1131 read only = yes
1133 [netlogon]
1134 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1135 read only = no
1139 my $ret = $self->provision_raw_step1($ctx);
1140 unless ($ret) {
1141 return undef;
1144 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1145 my $cmd = "";
1146 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1147 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1148 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1149 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1150 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1152 unless (system($cmd) == 0) {
1153 warn("Join failed\n$cmd");
1154 return undef;
1157 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1158 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1159 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1161 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1162 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1163 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1164 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1165 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1167 return $ret;
1170 sub provision_subdom_dc($$$)
1172 my ($self, $prefix, $dcvars) = @_;
1173 print "PROVISIONING SUBDOMAIN DC...";
1175 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1176 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1177 "localsubdc",
1178 "SAMBASUBDOM",
1179 "sub.samba.example.com",
1180 "2008",
1181 $dcvars->{PASSWORD},
1182 undef);
1184 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1186 $ctx->{smb_conf_extra_options} = "
1187 max xmit = 32K
1188 server max protocol = SMB2
1190 [sysvol]
1191 path = $ctx->{statedir}/sysvol
1192 read only = yes
1194 [netlogon]
1195 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1196 read only = no
1200 my $ret = $self->provision_raw_step1($ctx);
1201 unless ($ret) {
1202 return undef;
1205 my $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
1206 $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
1207 Samba::mk_krb5_conf($ctx, $dc_realms);
1209 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1210 my $cmd = "";
1211 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1212 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1213 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1214 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1215 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1217 unless (system($cmd) == 0) {
1218 warn("Join failed\n$cmd");
1219 return undef;
1222 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1223 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1224 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1226 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1227 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1228 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1229 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1230 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1232 return $ret;
1235 sub provision_dc($$)
1237 my ($self, $prefix) = @_;
1239 print "PROVISIONING DC...";
1240 my $extra_conf_options = "netbios aliases = localDC1-a";
1241 my $ret = $self->provision($prefix,
1242 "domain controller",
1243 "localdc",
1244 "SAMBADOMAIN",
1245 "samba.example.com",
1246 "2008",
1247 "locDCpass1",
1248 undef, $extra_conf_options, "", undef);
1250 return undef unless(defined $ret);
1251 unless($self->add_wins_config("$prefix/private")) {
1252 warn("Unable to add wins configuration");
1253 return undef;
1255 $ret->{NETBIOSALIAS} = "localdc1-a";
1256 $ret->{DC_SERVER} = $ret->{SERVER};
1257 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1258 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1259 $ret->{DC_USERNAME} = $ret->{USERNAME};
1260 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1262 return $ret;
1265 sub provision_fl2000dc($$)
1267 my ($self, $prefix) = @_;
1269 print "PROVISIONING DC...";
1270 my $ret = $self->provision($prefix,
1271 "domain controller",
1272 "dc5",
1273 "SAMBA2000",
1274 "samba2000.example.com",
1275 "2000",
1276 "locDCpass5",
1277 undef, "", "", undef);
1279 unless($self->add_wins_config("$prefix/private")) {
1280 warn("Unable to add wins configuration");
1281 return undef;
1284 return $ret;
1287 sub provision_fl2003dc($$)
1289 my ($self, $prefix) = @_;
1291 print "PROVISIONING DC...";
1292 my $ret = $self->provision($prefix,
1293 "domain controller",
1294 "dc6",
1295 "SAMBA2003",
1296 "samba2003.example.com",
1297 "2003",
1298 "locDCpass6",
1299 undef, "allow dns updates = nonsecure and secure", "", undef);
1301 unless($self->add_wins_config("$prefix/private")) {
1302 warn("Unable to add wins configuration");
1303 return undef;
1306 return $ret;
1309 sub provision_fl2008r2dc($$)
1311 my ($self, $prefix) = @_;
1313 print "PROVISIONING DC...";
1314 my $ret = $self->provision($prefix,
1315 "domain controller",
1316 "dc7",
1317 "SAMBA2008R2",
1318 "samba2008R2.example.com",
1319 "2008_R2",
1320 "locDCpass7",
1321 undef, "", "", undef);
1323 unless ($self->add_wins_config("$prefix/private")) {
1324 warn("Unable to add wins configuration");
1325 return undef;
1328 return $ret;
1332 sub provision_rodc($$$)
1334 my ($self, $prefix, $dcvars) = @_;
1335 print "PROVISIONING RODC...";
1337 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1338 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1339 "rodc",
1340 "SAMBADOMAIN",
1341 "samba.example.com",
1342 "2008",
1343 $dcvars->{PASSWORD},
1344 $dcvars->{SERVER_IP});
1345 unless ($ctx) {
1346 return undef;
1349 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1351 $ctx->{share} = "$ctx->{prefix_abs}/share";
1352 push(@{$ctx->{directories}}, "$ctx->{share}");
1354 $ctx->{smb_conf_extra_options} = "
1355 max xmit = 32K
1356 server max protocol = SMB2
1358 [sysvol]
1359 path = $ctx->{statedir}/sysvol
1360 read only = yes
1362 [netlogon]
1363 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1364 read only = yes
1366 [tmp]
1367 path = $ctx->{share}
1368 read only = no
1369 posix:sharedelay = 10000
1370 posix:oplocktimeout = 3
1371 posix:writetimeupdatedelay = 50000
1375 my $ret = $self->provision_raw_step1($ctx);
1376 unless ($ret) {
1377 return undef;
1380 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1381 my $cmd = "";
1382 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1383 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1384 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1385 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1386 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1388 unless (system($cmd) == 0) {
1389 warn("RODC join failed\n$cmd");
1390 return undef;
1393 # we overwrite the kdc after the RODC join
1394 # so that use the RODC as kdc and test
1395 # the proxy code
1396 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1397 Samba::mk_krb5_conf($ctx);
1399 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1400 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1401 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1403 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1404 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1405 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1406 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1407 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1409 return $ret;
1412 sub provision_plugin_s4_dc($$)
1414 my ($self, $prefix) = @_;
1416 my $prefix_abs = abs_path($prefix);
1418 my $bindir_abs = abs_path($self->{bindir});
1419 my $lockdir="$prefix_abs/lockdir";
1420 my $conffile="$prefix_abs/etc/smb.conf";
1422 my $extra_smbconf_options = "
1423 server services = -smb +s3fs
1424 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1426 kernel oplocks = no
1427 kernel change notify = no
1429 syslog = no
1430 printing = bsd
1431 printcap name = /dev/null
1433 max protocol = SMB3
1434 read only = no
1435 server signing = auto
1437 smbd:sharedelay = 100000
1438 smbd:writetimeupdatedelay = 500000
1439 create mask = 755
1440 dos filemode = yes
1442 dcerpc endpoint servers = -winreg -srvsvc
1444 printcap name = /dev/null
1446 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1447 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1449 printing = vlp
1450 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1451 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1452 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1453 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1454 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1455 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1456 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1457 lpq cache time = 0
1458 print notify backchannel = yes
1462 my $extra_smbconf_shares = "
1464 [tmpenc]
1465 copy = tmp
1466 smb encrypt = required
1468 [tmpcase]
1469 copy = tmp
1470 case sensitive = yes
1472 [tmpguest]
1473 copy = tmp
1474 guest ok = yes
1476 [hideunread]
1477 copy = tmp
1478 hide unreadable = yes
1480 [durable]
1481 copy = tmp
1482 kernel share modes = no
1483 kernel oplocks = no
1484 posix locking = no
1486 [print\$]
1487 copy = tmp
1489 [print1]
1490 copy = tmp
1491 printable = yes
1493 [print2]
1494 copy = print1
1495 [print3]
1496 copy = print1
1497 [lp]
1498 copy = print1
1501 print "PROVISIONING PLUGIN S4 DC...";
1502 my $ret = $self->provision($prefix,
1503 "domain controller",
1504 "plugindc",
1505 "PLUGINDOMAIN",
1506 "plugindc.samba.example.com",
1507 "2008",
1508 "locDCpass1",
1509 undef, $extra_smbconf_options,
1510 $extra_smbconf_shares, undef);
1512 return undef unless(defined $ret);
1513 unless($self->add_wins_config("$prefix/private")) {
1514 warn("Unable to add wins configuration");
1515 return undef;
1518 $ret->{DC_SERVER} = $ret->{SERVER};
1519 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1520 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1521 $ret->{DC_USERNAME} = $ret->{USERNAME};
1522 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1524 return $ret;
1527 sub provision_chgdcpass($$)
1529 my ($self, $prefix) = @_;
1531 print "PROVISIONING CHGDCPASS...";
1532 my $extra_provision_options = undef;
1533 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1534 my $ret = $self->provision($prefix,
1535 "domain controller",
1536 "chgdcpass",
1537 "CHDCDOMAIN",
1538 "chgdcpassword.samba.example.com",
1539 "2008",
1540 "chgDCpass1",
1541 undef, "", "",
1542 $extra_provision_options);
1544 return undef unless(defined $ret);
1545 unless($self->add_wins_config("$prefix/private")) {
1546 warn("Unable to add wins configuration");
1547 return undef;
1550 # Remove secrets.tdb from this environment to test that we still start up
1551 # on systems without the new matching secrets.tdb records
1552 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1553 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1554 return undef;
1557 $ret->{DC_SERVER} = $ret->{SERVER};
1558 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1559 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1560 $ret->{DC_USERNAME} = $ret->{USERNAME};
1561 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1563 return $ret;
1566 sub teardown_env($$)
1568 my ($self, $envvars) = @_;
1569 my $pid;
1571 # This should cause samba to terminate gracefully
1572 close($envvars->{STDIN_PIPE});
1574 $pid = $envvars->{SAMBA_PID};
1575 my $count = 0;
1576 my $childpid;
1578 # This should give it time to write out the gcov data
1579 until ($count > 30) {
1580 if (Samba::cleanup_child($pid, "samba") == -1) {
1581 last;
1583 sleep(1);
1584 $count++;
1587 if ($count > 30 || kill(0, $pid)) {
1588 kill "TERM", $pid;
1590 until ($count > 40) {
1591 if (Samba::cleanup_child($pid, "samba") == -1) {
1592 last;
1594 sleep(1);
1595 $count++;
1597 # If it is still around, kill it
1598 warn "server process $pid took more than $count seconds to exit, killing\n";
1599 kill 9, $pid;
1602 $self->slapd_stop($envvars) if ($self->{ldap});
1604 print $self->getlog_env($envvars);
1606 return;
1609 sub getlog_env($$)
1611 my ($self, $envvars) = @_;
1612 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1613 my $out = $title;
1615 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1617 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1618 while (<LOG>) {
1619 $out .= $_;
1621 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1622 close(LOG);
1624 return "" if $out eq $title;
1626 return $out;
1629 sub check_env($$)
1631 my ($self, $envvars) = @_;
1633 my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
1635 return ($childpid == 0);
1638 sub setup_env($$$)
1640 my ($self, $envname, $path) = @_;
1641 my $target3 = $self->{target3};
1643 $ENV{ENVNAME} = $envname;
1645 if (defined($self->{vars}->{$envname})) {
1646 return $self->{vars}->{$envname};
1649 if ($envname eq "dc") {
1650 return $self->setup_dc("$path/dc");
1651 } elsif ($envname eq "fl2000dc") {
1652 return $self->setup_fl2000dc("$path/fl2000dc");
1653 } elsif ($envname eq "fl2003dc") {
1654 return $self->setup_fl2003dc("$path/fl2003dc");
1655 } elsif ($envname eq "fl2008r2dc") {
1656 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1657 } elsif ($envname eq "rpc_proxy") {
1658 if (not defined($self->{vars}->{dc})) {
1659 $self->setup_dc("$path/dc");
1661 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1662 } elsif ($envname eq "vampire_dc") {
1663 if (not defined($self->{vars}->{dc})) {
1664 $self->setup_dc("$path/dc");
1666 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1667 } elsif ($envname eq "promoted_dc") {
1668 if (not defined($self->{vars}->{dc})) {
1669 $self->setup_dc("$path/dc");
1671 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{dc});
1672 } elsif ($envname eq "subdom_dc") {
1673 if (not defined($self->{vars}->{dc})) {
1674 $self->setup_dc("$path/dc");
1676 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
1677 } elsif ($envname eq "s4member") {
1678 if (not defined($self->{vars}->{dc})) {
1679 $self->setup_dc("$path/dc");
1681 return $self->setup_member("$path/s4member", $self->{vars}->{dc});
1682 } elsif ($envname eq "rodc") {
1683 if (not defined($self->{vars}->{dc})) {
1684 $self->setup_dc("$path/dc");
1686 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1687 } elsif ($envname eq "chgdcpass") {
1688 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
1689 } elsif ($envname eq "s3member") {
1690 if (not defined($self->{vars}->{dc})) {
1691 $self->setup_dc("$path/dc");
1693 return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
1694 } elsif ($envname eq "plugin_s4_dc") {
1695 return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
1696 } elsif ($envname eq "s3member_rfc2307") {
1697 if (not defined($self->{vars}->{dc})) {
1698 $self->setup_dc("$path/dc");
1700 return $target3->setup_admember_rfc2307("$path/s3member_rfc2307",
1701 $self->{vars}->{dc}, 34);
1702 } else {
1703 return "UNKNOWN";
1707 sub setup_member($$$)
1709 my ($self, $path, $dc_vars) = @_;
1711 my $env = $self->provision_member($path, $dc_vars);
1713 if (defined $env) {
1714 $self->check_or_start($env, "single");
1716 $self->wait_for_start($env);
1718 $self->{vars}->{member} = $env;
1721 return $env;
1724 sub setup_rpc_proxy($$$)
1726 my ($self, $path, $dc_vars) = @_;
1728 my $env = $self->provision_rpc_proxy($path, $dc_vars);
1730 if (defined $env) {
1731 $self->check_or_start($env, "single");
1733 $self->wait_for_start($env);
1735 $self->{vars}->{rpc_proxy} = $env;
1737 return $env;
1740 sub setup_dc($$)
1742 my ($self, $path) = @_;
1744 my $env = $self->provision_dc($path);
1745 if (defined $env) {
1746 $self->check_or_start($env, "standard");
1748 $self->wait_for_start($env);
1750 $self->{vars}->{dc} = $env;
1752 return $env;
1755 sub setup_chgdcpass($$)
1757 my ($self, $path) = @_;
1759 my $env = $self->provision_chgdcpass($path);
1760 if (defined $env) {
1761 $self->check_or_start($env, "single");
1763 $self->wait_for_start($env);
1765 $self->{vars}->{chgdcpass} = $env;
1767 return $env;
1770 sub setup_fl2000dc($$)
1772 my ($self, $path) = @_;
1774 my $env = $self->provision_fl2000dc($path);
1775 if (defined $env) {
1776 $self->check_or_start($env, "single");
1778 $self->wait_for_start($env);
1780 $self->{vars}->{fl2000dc} = $env;
1783 return $env;
1786 sub setup_fl2003dc($$)
1788 my ($self, $path) = @_;
1790 my $env = $self->provision_fl2003dc($path);
1792 if (defined $env) {
1793 $self->check_or_start($env, "single");
1795 $self->wait_for_start($env);
1797 $self->{vars}->{fl2003dc} = $env;
1799 return $env;
1802 sub setup_fl2008r2dc($$)
1804 my ($self, $path) = @_;
1806 my $env = $self->provision_fl2008r2dc($path);
1808 if (defined $env) {
1809 $self->check_or_start($env, "single");
1811 $self->wait_for_start($env);
1813 $self->{vars}->{fl2008r2dc} = $env;
1816 return $env;
1819 sub setup_vampire_dc($$$)
1821 my ($self, $path, $dc_vars) = @_;
1823 my $env = $self->provision_vampire_dc($path, $dc_vars);
1825 if (defined $env) {
1826 $self->check_or_start($env, "single");
1828 $self->wait_for_start($env);
1830 $self->{vars}->{vampire_dc} = $env;
1832 # force replicated DC to update repsTo/repsFrom
1833 # for vampired partitions
1834 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1835 my $cmd = "";
1836 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1837 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1838 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1839 $cmd .= " $env->{CONFIGURATION}";
1840 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1841 unless (system($cmd) == 0) {
1842 warn("Failed to exec kcc\n$cmd");
1843 return undef;
1846 # as 'vampired' dc may add data in its local replica
1847 # we need to synchronize data between DCs
1848 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1849 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1850 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1851 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1852 $cmd .= " $dc_vars->{CONFIGURATION}";
1853 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1854 # replicate Configuration NC
1855 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1856 unless(system($cmd_repl) == 0) {
1857 warn("Failed to replicate\n$cmd_repl");
1858 return undef;
1860 # replicate Default NC
1861 $cmd_repl = "$cmd \"$base_dn\"";
1862 unless(system($cmd_repl) == 0) {
1863 warn("Failed to replicate\n$cmd_repl");
1864 return undef;
1868 return $env;
1871 sub setup_promoted_dc($$$)
1873 my ($self, $path, $dc_vars) = @_;
1875 my $env = $self->provision_promoted_dc($path, $dc_vars);
1877 if (defined $env) {
1878 $self->check_or_start($env, "single");
1880 $self->wait_for_start($env);
1882 $self->{vars}->{promoted_dc} = $env;
1884 # force replicated DC to update repsTo/repsFrom
1885 # for vampired partitions
1886 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1887 my $cmd = "";
1888 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1889 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1890 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1891 $cmd .= " $env->{CONFIGURATION}";
1892 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1893 unless (system($cmd) == 0) {
1894 warn("Failed to exec kcc\n$cmd");
1895 return undef;
1898 # as 'vampired' dc may add data in its local replica
1899 # we need to synchronize data between DCs
1900 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1901 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1902 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1903 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1904 $cmd .= " $dc_vars->{CONFIGURATION}";
1905 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1906 # replicate Configuration NC
1907 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1908 unless(system($cmd_repl) == 0) {
1909 warn("Failed to replicate\n$cmd_repl");
1910 return undef;
1912 # replicate Default NC
1913 $cmd_repl = "$cmd \"$base_dn\"";
1914 unless(system($cmd_repl) == 0) {
1915 warn("Failed to replicate\n$cmd_repl");
1916 return undef;
1920 return $env;
1923 sub setup_subdom_dc($$$)
1925 my ($self, $path, $dc_vars) = @_;
1927 my $env = $self->provision_subdom_dc($path, $dc_vars);
1929 if (defined $env) {
1930 $self->check_or_start($env, "single");
1932 $self->wait_for_start($env);
1934 $self->{vars}->{subdom_dc} = $env;
1936 # force replicated DC to update repsTo/repsFrom
1937 # for primary domain partitions
1938 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1939 my $cmd = "";
1940 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1941 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1942 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1943 $cmd .= " $env->{CONFIGURATION}";
1944 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1945 unless (system($cmd) == 0) {
1946 warn("Failed to exec kcc\n$cmd");
1947 return undef;
1950 # as 'subdomain' dc may add data in its local replica
1951 # we need to synchronize data between DCs
1952 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
1953 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1954 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1955 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1956 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
1957 $cmd .= " $dc_vars->{CONFIGURATION}";
1958 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1959 # replicate Configuration NC
1960 my $cmd_repl = "$cmd \"$config_dn\"";
1961 unless(system($cmd_repl) == 0) {
1962 warn("Failed to replicate\n$cmd_repl");
1963 return undef;
1965 # replicate Default NC
1966 $cmd_repl = "$cmd \"$base_dn\"";
1967 unless(system($cmd_repl) == 0) {
1968 warn("Failed to replicate\n$cmd_repl");
1969 return undef;
1973 return $env;
1976 sub setup_rodc($$$)
1978 my ($self, $path, $dc_vars) = @_;
1980 my $env = $self->provision_rodc($path, $dc_vars);
1982 unless ($env) {
1983 return undef;
1986 $self->check_or_start($env, "single");
1988 $self->wait_for_start($env);
1990 $self->{vars}->{rodc} = $env;
1992 return $env;
1995 sub setup_plugin_s4_dc($$)
1997 my ($self, $path) = @_;
1999 # If we didn't build with ADS, pretend this env was never available
2000 if (not $self->{target3}->have_ads()) {
2001 return "UNKNOWN";
2004 my $env = $self->provision_plugin_s4_dc($path);
2005 unless ($env) {
2006 return undef;
2009 $self->check_or_start($env, "single");
2011 $self->wait_for_start($env);
2013 $self->{vars}->{plugin_s4_dc} = $env;
2014 return $env;