fileserver: raise the debug level for share connection from non IPC to 2
[Samba/vl.git] / selftest / target / Samba4.pm
blob495cc23d5c5d1b410b405c0630580d91837695fe
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) = @_;
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 if ($self->{ldap} eq "fedora-ds") {
55 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 &");
56 } elsif ($self->{ldap} eq "openldap") {
57 system("$ENV{OPENLDAP_SLAPD} -d0 -F $env_vars->{SLAPD_CONF_D} -h $uri > $env_vars->{LDAPDIR}/logs 2>&1 &");
59 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
60 $count++;
61 if ($count > 40) {
62 $self->slapd_stop($env_vars);
63 return 0;
65 sleep(1);
67 return 1;
70 sub slapd_stop($$)
72 my ($self, $envvars) = @_;
73 if ($self->{ldap} eq "fedora-ds") {
74 system("$envvars->{LDAPDIR}/slapd-$envvars->{LDAP_INSTANCE}/stop-slapd");
75 } elsif ($self->{ldap} eq "openldap") {
76 unless (open(IN, "<$envvars->{OPENLDAP_PIDFILE}")) {
77 warn("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
78 return 0;
80 kill 9, <IN>;
81 close(IN);
83 return 1;
86 sub check_or_start($$$)
88 my ($self, $env_vars, $process_model) = @_;
90 return 0 if $self->check_env($env_vars);
92 # use a pipe for stdin in the child processes. This allows
93 # those processes to monitor the pipe for EOF to ensure they
94 # exit when the test script exits
95 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
97 print "STARTING SAMBA...";
98 my $pid = fork();
99 if ($pid == 0) {
100 # we want out from samba to go to the log file, but also
101 # to the users terminal when running 'make test' on the command
102 # line. This puts it on stderr on the terminal
103 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
104 open STDERR, '>&STDOUT';
106 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
108 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
109 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
110 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
112 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
113 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
114 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
116 $ENV{UID_WRAPPER} = "1";
118 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
119 my @preargs = ();
120 my @optargs = ();
121 if (defined($ENV{SAMBA_OPTIONS})) {
122 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
124 if(defined($ENV{SAMBA_VALGRIND})) {
125 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
128 close($env_vars->{STDIN_PIPE});
129 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
131 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: $!");
133 $env_vars->{SAMBA_PID} = $pid;
134 print "DONE\n";
136 close(STDIN_READER);
138 return $pid;
141 sub wait_for_start($$)
143 my ($self, $testenv_vars) = @_;
144 # give time for nbt server to register its names
145 print "delaying for nbt name registration\n";
146 sleep 2;
148 # This will return quickly when things are up, but be slow if we
149 # need to wait for (eg) SSL init
150 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
151 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
152 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
153 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
154 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
155 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
156 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
157 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
158 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
159 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
160 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
161 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
162 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
164 print $self->getlog_env($testenv_vars);
167 sub write_ldb_file($$$)
169 my ($self, $file, $ldif) = @_;
171 my $ldbadd = Samba::bindir_path($self, "ldbadd");
172 open(LDIF, "|$ldbadd -H $file >/dev/null");
173 print LDIF $ldif;
174 return(close(LDIF));
177 sub add_wins_config($$)
179 my ($self, $privatedir) = @_;
181 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
182 dn: name=TORTURE_11,CN=PARTNERS
183 objectClass: wreplPartner
184 name: TORTURE_11
185 address: 127.0.0.11
186 pullInterval: 0
187 pushChangeCount: 0
188 type: 0x3
192 sub mk_fedora_ds($$)
194 my ($self, $ctx) = @_;
196 #Make the subdirectory be as fedora DS would expect
197 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
199 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
201 return ($fedora_ds_dir, $pidfile);
204 sub mk_openldap($$)
206 my ($self, $ctx) = @_;
208 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
209 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
211 return ($slapd_conf_d, $pidfile);
214 sub mk_keyblobs($$)
216 my ($self, $tlsdir) = @_;
218 #TLS and PKINIT crypto blobs
219 my $dhfile = "$tlsdir/dhparms.pem";
220 my $cafile = "$tlsdir/ca.pem";
221 my $certfile = "$tlsdir/cert.pem";
222 my $reqkdc = "$tlsdir/req-kdc.der";
223 my $kdccertfile = "$tlsdir/kdc.pem";
224 my $keyfile = "$tlsdir/key.pem";
225 my $adminkeyfile = "$tlsdir/adminkey.pem";
226 my $reqadmin = "$tlsdir/req-admin.der";
227 my $admincertfile = "$tlsdir/admincert.pem";
228 my $admincertupnfile = "$tlsdir/admincertupn.pem";
230 mkdir($tlsdir, 0777);
232 #This is specified here to avoid draining entropy on every run
233 open(DHFILE, ">$dhfile");
234 print DHFILE <<EOF;
235 -----BEGIN DH PARAMETERS-----
236 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
237 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
238 YX70obsCAQI=
239 -----END DH PARAMETERS-----
241 close(DHFILE);
243 #Likewise, we pregenerate the key material. This allows the
244 #other certificates to be pre-generated
245 open(KEYFILE, ">$keyfile");
246 print KEYFILE <<EOF;
247 -----BEGIN RSA PRIVATE KEY-----
248 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
249 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
250 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
251 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
252 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
253 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
254 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
255 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
256 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
257 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
258 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
259 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
260 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
261 -----END RSA PRIVATE KEY-----
263 close(KEYFILE);
265 open(ADMINKEYFILE, ">$adminkeyfile");
267 print ADMINKEYFILE <<EOF;
268 -----BEGIN RSA PRIVATE KEY-----
269 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
270 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
271 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
272 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
273 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
274 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
275 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
276 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
277 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
278 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
279 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
280 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
281 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
282 -----END RSA PRIVATE KEY-----
285 #generated with
286 # hxtool issue-certificate --self-signed --issue-ca \
287 # --ca-private-key="FILE:$KEYFILE" \
288 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
289 # --certificate="FILE:$CAFILE" --lifetime="25 years"
291 open(CAFILE, ">$cafile");
292 print CAFILE <<EOF;
293 -----BEGIN CERTIFICATE-----
294 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
295 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
296 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
297 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
298 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
299 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
300 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
301 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
302 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
303 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
304 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
305 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
306 -----END CERTIFICATE-----
309 #generated with GNUTLS internally in Samba.
311 open(CERTFILE, ">$certfile");
312 print CERTFILE <<EOF;
313 -----BEGIN CERTIFICATE-----
314 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
315 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
316 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
317 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
318 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
319 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
320 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
321 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
322 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
323 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
324 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
325 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
326 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
327 -----END CERTIFICATE-----
329 close(CERTFILE);
331 #KDC certificate
332 # hxtool request-create \
333 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
334 # --key="FILE:$KEYFILE" $KDCREQ
336 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
337 # --type="pkinit-kdc" \
338 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
339 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
340 # --lifetime="25 years"
342 open(KDCCERTFILE, ">$kdccertfile");
343 print KDCCERTFILE <<EOF;
344 -----BEGIN CERTIFICATE-----
345 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
346 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
347 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
348 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
349 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
350 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
351 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
352 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
353 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
354 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
355 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
356 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
357 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
358 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
359 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
360 -----END CERTIFICATE-----
363 # hxtool request-create \
364 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
365 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
367 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
368 # --type="pkinit-client" \
369 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
370 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
371 # --lifetime="25 years"
373 open(ADMINCERTFILE, ">$admincertfile");
374 print ADMINCERTFILE <<EOF;
375 -----BEGIN CERTIFICATE-----
376 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
377 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
378 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
379 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
380 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
381 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
382 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
383 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
384 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
385 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
386 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
387 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
388 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
389 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
390 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
391 -----END CERTIFICATE-----
393 close(ADMINCERTFILE);
395 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
396 # --type="pkinit-client" \
397 # --ms-upn="administrator@samba.example.com" \
398 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
399 # --lifetime="25 years"
401 open(ADMINCERTUPNFILE, ">$admincertupnfile");
402 print ADMINCERTUPNFILE <<EOF;
403 -----BEGIN CERTIFICATE-----
404 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
405 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
406 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
407 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
408 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
409 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
410 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
411 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
412 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
413 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
414 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
415 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
416 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
417 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
418 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
419 -----END CERTIFICATE-----
423 sub provision_raw_prepare($$$$$$$$$$)
425 my ($self, $prefix, $server_role, $hostname,
426 $domain, $realm, $functional_level,
427 $password, $kdc_ipv4) = @_;
428 my $ctx;
429 my $netbiosname = uc($hostname);
431 unless(-d $prefix or mkdir($prefix, 0777)) {
432 warn("Unable to create $prefix");
433 return undef;
435 my $prefix_abs = abs_path($prefix);
437 die ("prefix=''") if $prefix_abs eq "";
438 die ("prefix='/'") if $prefix_abs eq "/";
440 unless (system("rm -rf $prefix_abs/*") == 0) {
441 warn("Unable to clean up");
445 my $swiface = Samba::get_interface($hostname);
447 $ctx->{prefix} = $prefix;
448 $ctx->{prefix_abs} = $prefix_abs;
450 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
452 $ctx->{server_role} = $server_role;
453 $ctx->{hostname} = $hostname;
454 $ctx->{netbiosname} = $netbiosname;
455 $ctx->{swiface} = $swiface;
456 $ctx->{password} = $password;
457 $ctx->{kdc_ipv4} = $kdc_ipv4;
460 # Set smbd log level here.
462 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
463 $ctx->{username} = "Administrator";
464 $ctx->{domain} = $domain;
465 $ctx->{realm} = uc($realm);
466 $ctx->{dnsname} = lc($realm);
468 $ctx->{functional_level} = $functional_level;
470 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
471 chomp $unix_name;
472 $ctx->{unix_name} = $unix_name;
473 $ctx->{unix_uid} = $>;
474 $ctx->{unix_gids_str} = $);
475 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
477 $ctx->{etcdir} = "$prefix_abs/etc";
478 $ctx->{piddir} = "$prefix_abs/pid";
479 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
480 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
481 $ctx->{privatedir} = "$prefix_abs/private";
482 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
483 $ctx->{lockdir} = "$prefix_abs/lockdir";
484 $ctx->{logdir} = "$prefix_abs/logs";
485 $ctx->{statedir} = "$prefix_abs/statedir";
486 $ctx->{cachedir} = "$prefix_abs/cachedir";
487 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
488 $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
489 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
490 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
491 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
493 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
495 $ctx->{ipv4} = "127.0.0.$swiface";
496 $ctx->{interfaces} = "$ctx->{ipv4}/8";
498 push(@{$ctx->{directories}}, $ctx->{privatedir});
499 push(@{$ctx->{directories}}, $ctx->{etcdir});
500 push(@{$ctx->{directories}}, $ctx->{piddir});
501 push(@{$ctx->{directories}}, $ctx->{lockdir});
502 push(@{$ctx->{directories}}, $ctx->{logdir});
503 push(@{$ctx->{directories}}, $ctx->{statedir});
504 push(@{$ctx->{directories}}, $ctx->{cachedir});
506 $ctx->{smb_conf_extra_options} = "";
508 my @provision_options = ();
509 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
510 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
511 if (defined($ENV{GDB_PROVISION})) {
512 push (@provision_options, "gdb --args");
513 if (!defined($ENV{PYTHON})) {
514 push (@provision_options, "env");
515 push (@provision_options, "python");
518 if (defined($ENV{VALGRIND_PROVISION})) {
519 push (@provision_options, "valgrind");
520 if (!defined($ENV{PYTHON})) {
521 push (@provision_options, "env");
522 push (@provision_options, "python");
525 if (defined($ENV{PYTHON})) {
526 push (@provision_options, $ENV{PYTHON});
528 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
529 push (@provision_options, "domain");
530 push (@provision_options, "provision");
531 push (@provision_options, "--configfile=$ctx->{smb_conf}");
532 push (@provision_options, "--host-name=$ctx->{hostname}");
533 push (@provision_options, "--host-ip=$ctx->{ipv4}");
534 push (@provision_options, "--quiet");
535 push (@provision_options, "--domain=$ctx->{domain}");
536 push (@provision_options, "--realm=$ctx->{realm}");
537 push (@provision_options, "--adminpass=$ctx->{password}");
538 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
539 push (@provision_options, "--machinepass=machine$ctx->{password}");
540 push (@provision_options, "--root=$ctx->{unix_name}");
541 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
542 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
544 @{$ctx->{provision_options}} = @provision_options;
546 return $ctx;
550 # Step1 creates the basic configuration
552 sub provision_raw_step1($$)
554 my ($self, $ctx) = @_;
556 mkdir($_, 0777) foreach (@{$ctx->{directories}});
559 ## lockdir and piddir must be 0755
561 chmod 0755, $ctx->{lockdir};
562 chmod 0755, $ctx->{piddir};
564 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
565 warn("can't open $ctx->{smb_conf}$?");
566 return undef;
568 print CONFFILE "
569 [global]
570 netbios name = $ctx->{netbiosname}
571 posix:eadb = $ctx->{statedir}/eadb.tdb
572 workgroup = $ctx->{domain}
573 realm = $ctx->{realm}
574 private dir = $ctx->{privatedir}
575 pid directory = $ctx->{piddir}
576 ncalrpc dir = $ctx->{ncalrpcdir}
577 lock dir = $ctx->{lockdir}
578 state directory = $ctx->{statedir}
579 cache directory = $ctx->{cachedir}
580 winbindd socket directory = $ctx->{winbindd_socket_dir}
581 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
582 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
583 winbind separator = /
584 name resolve order = file bcast
585 interfaces = $ctx->{interfaces}
586 tls dh params file = $ctx->{tlsdir}/dhparms.pem
587 panic action = $RealBin/gdb_backtrace \%d
588 wins support = yes
589 server role = $ctx->{server_role}
590 server services = +echo +smb -s3fs
591 dcerpc endpoint servers = +winreg +srvsvc
592 notify:inotify = false
593 ldb:nosync = true
594 #We don't want to pass our self-tests if the PAC code is wrong
595 gensec:require_pac = true
596 log file = $ctx->{logdir}/log.\%m
597 log level = $ctx->{server_loglevel}
598 lanman auth = Yes
599 rndc command = true
600 dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file} -s $ctx->{smb_conf}
601 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
602 resolv:host file = $ctx->{dns_host_file}
603 dreplsrv:periodic_startup_interval = 0
604 dsdb:schema update allowed = yes
606 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
608 # remove this again, when our smb2 client library
609 # supports signin on compound related requests
610 server signing = on
612 idmap_ldb:use rfc2307=yes
615 print CONFFILE "
617 # Begin extra options
618 $ctx->{smb_conf_extra_options}
619 # End extra options
621 close(CONFFILE);
623 $self->mk_keyblobs($ctx->{tlsdir});
625 #Default the KDC IP to the server's IP
626 if (not defined($ctx->{kdc_ipv4})) {
627 $ctx->{kdc_ipv4} = $ctx->{ipv4};
630 Samba::mk_krb5_conf($ctx, "");
632 open(PWD, ">$ctx->{nsswrap_passwd}");
633 print PWD "
634 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
635 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
636 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
638 close(PWD);
639 my $uid_rfc2307test = 65533;
641 open(GRP, ">$ctx->{nsswrap_group}");
642 print GRP "
643 root:x:0:
644 wheel:x:10:
645 users:x:100:
646 nobody:x:65533:
647 nogroup:x:65534:nobody
649 close(GRP);
650 my $gid_rfc2307test = 65532;
652 my $configuration = "--configfile=$ctx->{smb_conf}";
654 #Ensure the config file is valid before we start
655 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
656 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
657 system("$testparm -v --suppress-prompt $configuration >&2");
658 warn("Failed to create a valid smb.conf configuration $testparm!");
659 return undef;
661 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) {
662 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
663 return undef;
666 my $ret = {
667 KRB5_CONFIG => $ctx->{krb5_conf},
668 PIDDIR => $ctx->{piddir},
669 SERVER => $ctx->{hostname},
670 SERVER_IP => $ctx->{ipv4},
671 NETBIOSNAME => $ctx->{netbiosname},
672 DOMAIN => $ctx->{domain},
673 USERNAME => $ctx->{username},
674 REALM => $ctx->{realm},
675 PASSWORD => $ctx->{password},
676 LDAPDIR => $ctx->{ldapdir},
677 LDAP_INSTANCE => $ctx->{ldap_instance},
678 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
679 NCALRPCDIR => $ctx->{ncalrpcdir},
680 LOCKDIR => $ctx->{lockdir},
681 STATEDIR => $ctx->{statedir},
682 CACHEDIR => $ctx->{cachedir},
683 PRIVATEDIR => $ctx->{privatedir},
684 SERVERCONFFILE => $ctx->{smb_conf},
685 CONFIGURATION => $configuration,
686 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
687 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
688 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
689 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
690 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
691 SAMBA_TEST_LOG_POS => 0,
692 NSS_WRAPPER_WINBIND_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
693 LOCAL_PATH => $ctx->{share},
694 UID_RFC2307TEST => $uid_rfc2307test,
695 GID_RFC2307TEST => $gid_rfc2307test
698 return $ret;
702 # Step2 runs the provision script
704 sub provision_raw_step2($$$)
706 my ($self, $ctx, $ret) = @_;
708 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
709 unless (system($provision_cmd) == 0) {
710 warn("Unable to provision: \n$provision_cmd\n");
711 return undef;
714 return $ret;
717 sub provision($$$$$$$$$)
719 my ($self, $prefix, $server_role, $hostname,
720 $domain, $realm, $functional_level,
721 $password, $kdc_ipv4, $extra_smbconf_options, $extra_smbconf_shares,
722 $extra_provision_options) = @_;
724 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
725 $hostname,
726 $domain, $realm, $functional_level,
727 $password, $kdc_ipv4);
729 if (defined($extra_provision_options)) {
730 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
731 } else {
732 push (@{$ctx->{provision_options}}, "--use-ntvfs");
735 $ctx->{share} = "$ctx->{prefix_abs}/share";
736 push(@{$ctx->{directories}}, "$ctx->{share}");
737 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
738 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
740 # precreate directories for printer drivers
741 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
742 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
743 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
745 my $msdfs = "no";
746 $msdfs = "yes" if ($server_role eq "domain controller");
747 $ctx->{smb_conf_extra_options} = "
749 max xmit = 32K
750 server max protocol = SMB2
751 host msdfs = $msdfs
752 lanman auth = yes
754 $extra_smbconf_options
756 [tmp]
757 path = $ctx->{share}
758 read only = no
759 posix:sharedelay = 10000
760 posix:oplocktimeout = 3
761 posix:writetimeupdatedelay = 50000
763 [xcopy_share]
764 path = $ctx->{share}
765 read only = no
766 posix:sharedelay = 10000
767 posix:oplocktimeout = 3
768 posix:writetimeupdatedelay = 50000
769 create mask = 777
770 force create mode = 777
772 [posix_share]
773 path = $ctx->{share}
774 read only = no
775 create mask = 0777
776 force create mode = 0
777 directory mask = 0777
778 force directory mode = 0
780 [test1]
781 path = $ctx->{share}/test1
782 read only = no
783 posix:sharedelay = 10000
784 posix:oplocktimeout = 3
785 posix:writetimeupdatedelay = 50000
787 [test2]
788 path = $ctx->{share}/test2
789 read only = no
790 posix:sharedelay = 10000
791 posix:oplocktimeout = 3
792 posix:writetimeupdatedelay = 50000
794 [cifs]
795 read only = no
796 ntvfs handler = cifs
797 cifs:server = $ctx->{netbiosname}
798 cifs:share = tmp
799 cifs:use-s4u2proxy = yes
800 # There is no username specified here, instead the client is expected
801 # to log in with kerberos, and the serverwill use delegated credentials.
802 # Or the server tries s4u2self/s4u2proxy to impersonate the client
804 [simple]
805 path = $ctx->{share}
806 read only = no
807 ntvfs handler = simple
809 [sysvol]
810 path = $ctx->{statedir}/sysvol
811 read only = no
813 [netlogon]
814 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
815 read only = no
817 [cifsposix]
818 copy = simple
819 ntvfs handler = cifsposix
821 $extra_smbconf_shares
824 if (defined($self->{ldap})) {
825 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
826 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
828 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
829 $ldap_uri =~ s|/|%2F|g;
830 $ldap_uri = "ldapi://$ldap_uri";
831 $ctx->{ldap_uri} = $ldap_uri;
833 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
836 my $ret = $self->provision_raw_step1($ctx);
837 unless (defined $ret) {
838 return undef;
841 if (defined($self->{ldap})) {
842 $ret->{LDAP_URI} = $ctx->{ldap_uri};
843 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
844 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
845 if ($self->{ldap} eq "openldap") {
846 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
847 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
849 } elsif ($self->{ldap} eq "fedora-ds") {
850 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
851 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
852 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
857 return $self->provision_raw_step2($ctx, $ret);
860 sub provision_member($$$)
862 my ($self, $prefix, $dcvars) = @_;
863 print "PROVISIONING MEMBER...";
865 my $ret = $self->provision($prefix,
866 "member server",
867 "s4member",
868 "SAMBADOMAIN",
869 "samba.example.com",
870 "2008",
871 "locMEMpass3",
872 $dcvars->{SERVER_IP},
873 "", "", undef);
874 unless ($ret) {
875 return undef;
878 my $samba_tool = Samba::bindir_path($self, "samba-tool");
879 my $cmd = "";
880 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
881 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
882 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
883 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
884 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
886 unless (system($cmd) == 0) {
887 warn("Join failed\n$cmd");
888 return undef;
891 $ret->{MEMBER_SERVER} = $ret->{SERVER};
892 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
893 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
894 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
895 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
897 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
898 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
899 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
900 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
901 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
903 return $ret;
906 sub provision_rpc_proxy($$$)
908 my ($self, $prefix, $dcvars) = @_;
909 print "PROVISIONING RPC PROXY...";
911 my $extra_smbconf_options = "
913 # rpc_proxy
914 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
915 dcerpc endpoint servers = epmapper, remote
916 dcerpc_remote:interfaces = rpcecho
918 [cifs_to_dc]
919 read only = no
920 ntvfs handler = cifs
921 cifs:server = $dcvars->{SERVER}
922 cifs:share = cifs
923 cifs:use-s4u2proxy = yes
924 # There is no username specified here, instead the client is expected
925 # to log in with kerberos, and the serverwill use delegated credentials.
926 # Or the server tries s4u2self/s4u2proxy to impersonate the client
930 my $ret = $self->provision($prefix,
931 "member server",
932 "localrpcproxy",
933 "SAMBADOMAIN",
934 "samba.example.com",
935 "2008",
936 "locRPCproxypass4",
937 $dcvars->{SERVER_IP},
938 $extra_smbconf_options, "", undef);
940 unless ($ret) {
941 return undef;
944 my $samba_tool = Samba::bindir_path($self, "samba-tool");
946 # The joind runs in the context of the rpc_proxy/member for now
947 my $cmd = "";
948 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
949 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
950 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
951 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
952 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
954 unless (system($cmd) == 0) {
955 warn("Join failed\n$cmd");
956 return undef;
959 # Setting up delegation runs in the context of the DC for now
960 $cmd = "";
961 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
962 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
963 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
964 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
966 unless (system($cmd) == 0) {
967 warn("Delegation failed\n$cmd");
968 return undef;
971 # Setting up delegation runs in the context of the DC for now
972 $cmd = "";
973 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
974 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
975 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
976 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
978 unless (system($cmd) == 0) {
979 warn("Delegation failed\n$cmd");
980 return undef;
983 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
984 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
985 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
986 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
987 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
989 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
990 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
991 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
992 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
993 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
995 return $ret;
998 sub provision_promoted_dc($$$)
1000 my ($self, $prefix, $dcvars) = @_;
1001 print "PROVISIONING VAMPIRE DC...";
1003 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1004 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1005 "promotedvdc",
1006 "SAMBADOMAIN",
1007 "samba.example.com",
1008 "2008",
1009 $dcvars->{PASSWORD},
1010 $dcvars->{SERVER_IP});
1012 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1014 $ctx->{smb_conf_extra_options} = "
1015 max xmit = 32K
1016 server max protocol = SMB2
1018 [sysvol]
1019 path = $ctx->{statedir}/sysvol
1020 read only = yes
1022 [netlogon]
1023 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1024 read only = no
1028 my $ret = $self->provision_raw_step1($ctx);
1029 unless ($ret) {
1030 return undef;
1033 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1034 my $cmd = "";
1035 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1036 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1037 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1038 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1039 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1041 unless (system($cmd) == 0) {
1042 warn("Join failed\n$cmd");
1043 return undef;
1046 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1047 my $cmd = "";
1048 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1049 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1050 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1051 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1052 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1054 unless (system($cmd) == 0) {
1055 warn("Join failed\n$cmd");
1056 return undef;
1059 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1060 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1061 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1063 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1064 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1065 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1066 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1067 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1069 return $ret;
1072 sub provision_vampire_dc($$$)
1074 my ($self, $prefix, $dcvars) = @_;
1075 print "PROVISIONING VAMPIRE DC...";
1077 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1078 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1079 "localvampiredc",
1080 "SAMBADOMAIN",
1081 "samba.example.com",
1082 "2008",
1083 $dcvars->{PASSWORD},
1084 $dcvars->{SERVER_IP});
1086 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1088 $ctx->{smb_conf_extra_options} = "
1089 max xmit = 32K
1090 server max protocol = SMB2
1092 [sysvol]
1093 path = $ctx->{statedir}/sysvol
1094 read only = yes
1096 [netlogon]
1097 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1098 read only = no
1102 my $ret = $self->provision_raw_step1($ctx);
1103 unless ($ret) {
1104 return undef;
1107 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1108 my $cmd = "";
1109 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1110 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1111 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1112 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1113 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1115 unless (system($cmd) == 0) {
1116 warn("Join failed\n$cmd");
1117 return undef;
1120 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1121 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1122 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1124 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1125 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1126 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1127 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1128 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1130 return $ret;
1133 sub provision_subdom_dc($$$)
1135 my ($self, $prefix, $dcvars) = @_;
1136 print "PROVISIONING SUBDOMAIN DC...";
1138 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1139 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1140 "localsubdc",
1141 "SAMBASUBDOM",
1142 "sub.samba.example.com",
1143 "2008",
1144 $dcvars->{PASSWORD},
1145 undef);
1147 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1149 $ctx->{smb_conf_extra_options} = "
1150 max xmit = 32K
1151 server max protocol = SMB2
1153 [sysvol]
1154 path = $ctx->{statedir}/sysvol
1155 read only = yes
1157 [netlogon]
1158 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1159 read only = no
1163 my $ret = $self->provision_raw_step1($ctx);
1164 unless ($ret) {
1165 return undef;
1168 my $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
1169 $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
1170 Samba::mk_krb5_conf($ctx, $dc_realms);
1172 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1173 my $cmd = "";
1174 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1175 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1176 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1177 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1178 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1180 unless (system($cmd) == 0) {
1181 warn("Join failed\n$cmd");
1182 return undef;
1185 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1186 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1187 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1189 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1190 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1191 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1192 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1193 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1195 return $ret;
1198 sub provision_dc($$)
1200 my ($self, $prefix) = @_;
1202 print "PROVISIONING DC...";
1203 my $extra_conf_options = "netbios aliases = localDC1-a";
1204 my $ret = $self->provision($prefix,
1205 "domain controller",
1206 "localdc",
1207 "SAMBADOMAIN",
1208 "samba.example.com",
1209 "2008",
1210 "locDCpass1",
1211 undef, $extra_conf_options, "", undef);
1213 return undef unless(defined $ret);
1214 unless($self->add_wins_config("$prefix/private")) {
1215 warn("Unable to add wins configuration");
1216 return undef;
1218 $ret->{NETBIOSALIAS} = "localdc1-a";
1219 $ret->{DC_SERVER} = $ret->{SERVER};
1220 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1221 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1222 $ret->{DC_USERNAME} = $ret->{USERNAME};
1223 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1225 return $ret;
1228 sub provision_fl2000dc($$)
1230 my ($self, $prefix) = @_;
1232 print "PROVISIONING DC...";
1233 my $ret = $self->provision($prefix,
1234 "domain controller",
1235 "dc5",
1236 "SAMBA2000",
1237 "samba2000.example.com",
1238 "2000",
1239 "locDCpass5",
1240 undef, "", "", undef);
1242 unless($self->add_wins_config("$prefix/private")) {
1243 warn("Unable to add wins configuration");
1244 return undef;
1247 return $ret;
1250 sub provision_fl2003dc($$)
1252 my ($self, $prefix) = @_;
1254 print "PROVISIONING DC...";
1255 my $ret = $self->provision($prefix,
1256 "domain controller",
1257 "dc6",
1258 "SAMBA2003",
1259 "samba2003.example.com",
1260 "2003",
1261 "locDCpass6",
1262 undef, "allow dns updates = nonsecure and secure", "", undef);
1264 unless($self->add_wins_config("$prefix/private")) {
1265 warn("Unable to add wins configuration");
1266 return undef;
1269 return $ret;
1272 sub provision_fl2008r2dc($$)
1274 my ($self, $prefix) = @_;
1276 print "PROVISIONING DC...";
1277 my $ret = $self->provision($prefix,
1278 "domain controller",
1279 "dc7",
1280 "SAMBA2008R2",
1281 "samba2008R2.example.com",
1282 "2008_R2",
1283 "locDCpass7",
1284 undef, "", "", undef);
1286 unless ($self->add_wins_config("$prefix/private")) {
1287 warn("Unable to add wins configuration");
1288 return undef;
1291 return $ret;
1295 sub provision_rodc($$$)
1297 my ($self, $prefix, $dcvars) = @_;
1298 print "PROVISIONING RODC...";
1300 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1301 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1302 "rodc",
1303 "SAMBADOMAIN",
1304 "samba.example.com",
1305 "2008",
1306 $dcvars->{PASSWORD},
1307 $dcvars->{SERVER_IP});
1308 unless ($ctx) {
1309 return undef;
1312 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1314 $ctx->{share} = "$ctx->{prefix_abs}/share";
1315 push(@{$ctx->{directories}}, "$ctx->{share}");
1317 $ctx->{smb_conf_extra_options} = "
1318 max xmit = 32K
1319 server max protocol = SMB2
1321 [sysvol]
1322 path = $ctx->{statedir}/sysvol
1323 read only = yes
1325 [netlogon]
1326 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1327 read only = yes
1329 [tmp]
1330 path = $ctx->{share}
1331 read only = no
1332 posix:sharedelay = 10000
1333 posix:oplocktimeout = 3
1334 posix:writetimeupdatedelay = 50000
1338 my $ret = $self->provision_raw_step1($ctx);
1339 unless ($ret) {
1340 return undef;
1343 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1344 my $cmd = "";
1345 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1346 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1347 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1348 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1349 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1351 unless (system($cmd) == 0) {
1352 warn("RODC join failed\n$cmd");
1353 return undef;
1356 # we overwrite the kdc after the RODC join
1357 # so that use the RODC as kdc and test
1358 # the proxy code
1359 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1360 Samba::mk_krb5_conf($ctx);
1362 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1363 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1364 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1366 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1367 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1368 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1369 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1370 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1372 return $ret;
1375 sub provision_plugin_s4_dc($$)
1377 my ($self, $prefix) = @_;
1379 my $prefix_abs = abs_path($prefix);
1381 my $bindir_abs = abs_path($self->{bindir});
1382 my $lockdir="$prefix_abs/lockdir";
1383 my $conffile="$prefix_abs/etc/smb.conf";
1385 my $extra_smbconf_options = "
1386 server services = -smb +s3fs
1387 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1389 kernel oplocks = no
1390 kernel change notify = no
1392 syslog = no
1393 printing = bsd
1394 printcap name = /dev/null
1396 max protocol = SMB3
1397 read only = no
1398 server signing = auto
1400 smbd:sharedelay = 100000
1401 smbd:writetimeupdatedelay = 500000
1402 create mask = 755
1403 dos filemode = yes
1405 dcerpc endpoint servers = -winreg -srvsvc
1407 printcap name = /dev/null
1409 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1410 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1412 printing = vlp
1413 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1414 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1415 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1416 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1417 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1418 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1419 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1420 lpq cache time = 0
1424 my $extra_smbconf_shares = "
1426 [tmpenc]
1427 copy = tmp
1428 smb encrypt = required
1430 [tmpcase]
1431 copy = tmp
1432 case sensitive = yes
1434 [tmpguest]
1435 copy = tmp
1436 guest ok = yes
1438 [hideunread]
1439 copy = tmp
1440 hide unreadable = yes
1442 [durable]
1443 copy = tmp
1444 kernel share modes = no
1445 kernel oplocks = no
1446 posix locking = no
1448 [print\$]
1449 copy = tmp
1451 [print1]
1452 copy = tmp
1453 printable = yes
1455 [print2]
1456 copy = print1
1457 [print3]
1458 copy = print1
1459 [lp]
1460 copy = print1
1463 print "PROVISIONING PLUGIN S4 DC...";
1464 my $ret = $self->provision($prefix,
1465 "domain controller",
1466 "plugindc",
1467 "PLUGINDOMAIN",
1468 "plugin.samba.example.com",
1469 "2008",
1470 "locDCpass1",
1471 undef, $extra_smbconf_options,
1472 $extra_smbconf_shares, undef);
1474 return undef unless(defined $ret);
1475 unless($self->add_wins_config("$prefix/private")) {
1476 warn("Unable to add wins configuration");
1477 return undef;
1480 $ret->{DC_SERVER} = $ret->{SERVER};
1481 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1482 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1483 $ret->{DC_USERNAME} = $ret->{USERNAME};
1484 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1486 return $ret;
1489 sub provision_chgdcpass($$)
1491 my ($self, $prefix) = @_;
1493 print "PROVISIONING CHGDCPASS...";
1494 my $extra_provision_options = undef;
1495 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1496 my $ret = $self->provision($prefix,
1497 "domain controller",
1498 "chgdcpass",
1499 "CHDCDOMAIN",
1500 "chgdcpassword.samba.example.com",
1501 "2008",
1502 "chgDCpass1",
1503 undef, "server services = -dns", "",
1504 $extra_provision_options);
1506 return undef unless(defined $ret);
1507 unless($self->add_wins_config("$prefix/private")) {
1508 warn("Unable to add wins configuration");
1509 return undef;
1512 # Remove secrets.tdb from this environment to test that we still start up
1513 # on systems without the new matching secrets.tdb records
1514 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1515 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1516 return undef;
1519 $ret->{DC_SERVER} = $ret->{SERVER};
1520 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1521 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1522 $ret->{DC_USERNAME} = $ret->{USERNAME};
1523 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1525 return $ret;
1528 sub teardown_env($$)
1530 my ($self, $envvars) = @_;
1531 my $pid;
1533 # This should cause samba to terminate gracefully
1534 close($envvars->{STDIN_PIPE});
1536 $pid = $envvars->{SAMBA_PID};
1537 my $count = 0;
1538 my $childpid;
1540 # This should give it time to write out the gcov data
1541 until ($count > 30) {
1542 if (Samba::cleanup_child($pid, "samba") == -1) {
1543 last;
1545 sleep(1);
1546 $count++;
1549 if ($count <= 20 && kill(0, $pid) == 0) {
1550 return;
1553 kill "TERM", $pid;
1555 until ($count > 20) {
1556 if (Samba::cleanup_child($pid, "samba") == -1) {
1557 last;
1559 sleep(1);
1560 $count++;
1563 # If it is still around, kill it
1564 if ($count > 20 && kill(0, $pid) == 0) {
1565 warn "server process $pid took more than $count seconds to exit, killing\n";
1566 kill 9, $pid;
1569 $self->slapd_stop($envvars) if ($self->{ldap});
1571 print $self->getlog_env($envvars);
1573 return;
1576 sub getlog_env($$)
1578 my ($self, $envvars) = @_;
1579 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1580 my $out = $title;
1582 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1584 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1585 while (<LOG>) {
1586 $out .= $_;
1588 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1589 close(LOG);
1591 return "" if $out eq $title;
1593 return $out;
1596 sub check_env($$)
1598 my ($self, $envvars) = @_;
1600 my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
1602 return ($childpid == 0);
1605 sub setup_env($$$)
1607 my ($self, $envname, $path) = @_;
1608 my $target3 = $self->{target3};
1610 $ENV{ENVNAME} = $envname;
1612 if (defined($self->{vars}->{$envname})) {
1613 return $self->{vars}->{$envname};
1616 if ($envname eq "dc") {
1617 return $self->setup_dc("$path/dc");
1618 } elsif ($envname eq "fl2000dc") {
1619 return $self->setup_fl2000dc("$path/fl2000dc");
1620 } elsif ($envname eq "fl2003dc") {
1621 return $self->setup_fl2003dc("$path/fl2003dc");
1622 } elsif ($envname eq "fl2008r2dc") {
1623 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1624 } elsif ($envname eq "rpc_proxy") {
1625 if (not defined($self->{vars}->{dc})) {
1626 $self->setup_dc("$path/dc");
1628 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1629 } elsif ($envname eq "vampire_dc") {
1630 if (not defined($self->{vars}->{dc})) {
1631 $self->setup_dc("$path/dc");
1633 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1634 } elsif ($envname eq "promoted_dc") {
1635 if (not defined($self->{vars}->{dc})) {
1636 $self->setup_dc("$path/dc");
1638 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{dc});
1639 } elsif ($envname eq "subdom_dc") {
1640 if (not defined($self->{vars}->{dc})) {
1641 $self->setup_dc("$path/dc");
1643 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
1644 } elsif ($envname eq "s4member") {
1645 if (not defined($self->{vars}->{dc})) {
1646 $self->setup_dc("$path/dc");
1648 return $self->setup_member("$path/s4member", $self->{vars}->{dc});
1649 } elsif ($envname eq "rodc") {
1650 if (not defined($self->{vars}->{dc})) {
1651 $self->setup_dc("$path/dc");
1653 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1654 } elsif ($envname eq "chgdcpass") {
1655 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
1656 } elsif ($envname eq "s3member") {
1657 if (not defined($self->{vars}->{dc})) {
1658 $self->setup_dc("$path/dc");
1660 return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
1661 } elsif ($envname eq "plugin_s4_dc") {
1662 return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
1663 } elsif ($envname eq "s3member_rfc2307") {
1664 if (not defined($self->{vars}->{dc})) {
1665 $self->setup_dc("$path/dc");
1667 return $target3->setup_admember_rfc2307("$path/s3member_rfc2307",
1668 $self->{vars}->{dc}, 34);
1669 } else {
1670 return "UNKNOWN";
1674 sub setup_member($$$)
1676 my ($self, $path, $dc_vars) = @_;
1678 my $env = $self->provision_member($path, $dc_vars);
1680 if (defined $env) {
1681 $self->check_or_start($env, "single");
1683 $self->wait_for_start($env);
1685 $self->{vars}->{member} = $env;
1688 return $env;
1691 sub setup_rpc_proxy($$$)
1693 my ($self, $path, $dc_vars) = @_;
1695 my $env = $self->provision_rpc_proxy($path, $dc_vars);
1697 if (defined $env) {
1698 $self->check_or_start($env, "single");
1700 $self->wait_for_start($env);
1702 $self->{vars}->{rpc_proxy} = $env;
1704 return $env;
1707 sub setup_dc($$)
1709 my ($self, $path) = @_;
1711 my $env = $self->provision_dc($path);
1712 if (defined $env) {
1713 $self->check_or_start($env, "standard");
1715 $self->wait_for_start($env);
1717 $self->{vars}->{dc} = $env;
1719 return $env;
1722 sub setup_chgdcpass($$)
1724 my ($self, $path) = @_;
1726 my $env = $self->provision_chgdcpass($path);
1727 if (defined $env) {
1728 $self->check_or_start($env, "single");
1730 $self->wait_for_start($env);
1732 $self->{vars}->{chgdcpass} = $env;
1734 return $env;
1737 sub setup_fl2000dc($$)
1739 my ($self, $path) = @_;
1741 my $env = $self->provision_fl2000dc($path);
1742 if (defined $env) {
1743 $self->check_or_start($env, "single");
1745 $self->wait_for_start($env);
1747 $self->{vars}->{fl2000dc} = $env;
1750 return $env;
1753 sub setup_fl2003dc($$)
1755 my ($self, $path) = @_;
1757 my $env = $self->provision_fl2003dc($path);
1759 if (defined $env) {
1760 $self->check_or_start($env, "single");
1762 $self->wait_for_start($env);
1764 $self->{vars}->{fl2003dc} = $env;
1766 return $env;
1769 sub setup_fl2008r2dc($$)
1771 my ($self, $path) = @_;
1773 my $env = $self->provision_fl2008r2dc($path);
1775 if (defined $env) {
1776 $self->check_or_start($env, "single");
1778 $self->wait_for_start($env);
1780 $self->{vars}->{fl2008r2dc} = $env;
1783 return $env;
1786 sub setup_vampire_dc($$$)
1788 my ($self, $path, $dc_vars) = @_;
1790 my $env = $self->provision_vampire_dc($path, $dc_vars);
1792 if (defined $env) {
1793 $self->check_or_start($env, "single");
1795 $self->wait_for_start($env);
1797 $self->{vars}->{vampire_dc} = $env;
1799 # force replicated DC to update repsTo/repsFrom
1800 # for vampired partitions
1801 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1802 my $cmd = "";
1803 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1804 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1805 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1806 $cmd .= " $env->{CONFIGURATION}";
1807 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1808 unless (system($cmd) == 0) {
1809 warn("Failed to exec kcc\n$cmd");
1810 return undef;
1813 # as 'vampired' dc may add data in its local replica
1814 # we need to synchronize data between DCs
1815 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1816 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1817 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1818 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1819 $cmd .= " $dc_vars->{CONFIGURATION}";
1820 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1821 # replicate Configuration NC
1822 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1823 unless(system($cmd_repl) == 0) {
1824 warn("Failed to replicate\n$cmd_repl");
1825 return undef;
1827 # replicate Default NC
1828 $cmd_repl = "$cmd \"$base_dn\"";
1829 unless(system($cmd_repl) == 0) {
1830 warn("Failed to replicate\n$cmd_repl");
1831 return undef;
1835 return $env;
1838 sub setup_promoted_dc($$$)
1840 my ($self, $path, $dc_vars) = @_;
1842 my $env = $self->provision_promoted_dc($path, $dc_vars);
1844 if (defined $env) {
1845 $self->check_or_start($env, "single");
1847 $self->wait_for_start($env);
1849 $self->{vars}->{promoted_dc} = $env;
1851 # force replicated DC to update repsTo/repsFrom
1852 # for vampired partitions
1853 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1854 my $cmd = "";
1855 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1856 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1857 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1858 $cmd .= " $env->{CONFIGURATION}";
1859 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1860 unless (system($cmd) == 0) {
1861 warn("Failed to exec kcc\n$cmd");
1862 return undef;
1865 # as 'vampired' dc may add data in its local replica
1866 # we need to synchronize data between DCs
1867 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1868 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1869 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1870 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1871 $cmd .= " $dc_vars->{CONFIGURATION}";
1872 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1873 # replicate Configuration NC
1874 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1875 unless(system($cmd_repl) == 0) {
1876 warn("Failed to replicate\n$cmd_repl");
1877 return undef;
1879 # replicate Default NC
1880 $cmd_repl = "$cmd \"$base_dn\"";
1881 unless(system($cmd_repl) == 0) {
1882 warn("Failed to replicate\n$cmd_repl");
1883 return undef;
1887 return $env;
1890 sub setup_subdom_dc($$$)
1892 my ($self, $path, $dc_vars) = @_;
1894 my $env = $self->provision_subdom_dc($path, $dc_vars);
1896 if (defined $env) {
1897 $self->check_or_start($env, "single");
1899 $self->wait_for_start($env);
1901 $self->{vars}->{subdom_dc} = $env;
1903 # force replicated DC to update repsTo/repsFrom
1904 # for primary domain partitions
1905 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1906 my $cmd = "";
1907 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1908 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1909 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1910 $cmd .= " $env->{CONFIGURATION}";
1911 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1912 unless (system($cmd) == 0) {
1913 warn("Failed to exec kcc\n$cmd");
1914 return undef;
1917 # as 'subdomain' dc may add data in its local replica
1918 # we need to synchronize data between DCs
1919 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
1920 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1921 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1922 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1923 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
1924 $cmd .= " $dc_vars->{CONFIGURATION}";
1925 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1926 # replicate Configuration NC
1927 my $cmd_repl = "$cmd \"$config_dn\"";
1928 unless(system($cmd_repl) == 0) {
1929 warn("Failed to replicate\n$cmd_repl");
1930 return undef;
1932 # replicate Default NC
1933 $cmd_repl = "$cmd \"$base_dn\"";
1934 unless(system($cmd_repl) == 0) {
1935 warn("Failed to replicate\n$cmd_repl");
1936 return undef;
1940 return $env;
1943 sub setup_rodc($$$)
1945 my ($self, $path, $dc_vars) = @_;
1947 my $env = $self->provision_rodc($path, $dc_vars);
1949 unless ($env) {
1950 return undef;
1953 $self->check_or_start($env, "single");
1955 $self->wait_for_start($env);
1957 $self->{vars}->{rodc} = $env;
1959 return $env;
1962 sub setup_plugin_s4_dc($$)
1964 my ($self, $path) = @_;
1966 # If we didn't build with ADS, pretend this env was never available
1967 if (not $self->{target3}->have_ads()) {
1968 return "UNKNOWN";
1971 my $env = $self->provision_plugin_s4_dc($path);
1972 unless ($env) {
1973 return undef;
1976 $self->check_or_start($env, "single");
1978 $self->wait_for_start($env);
1980 $self->{vars}->{plugin_s4_dc} = $env;
1981 return $env;