s3: Make winbindd_register_handlers static
[Samba/id10ts.git] / selftest / target / Samba4.pm
blobfbc8117ed5a11dfea8677db77727de4cb67bff31
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}});
558 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
559 warn("can't open $ctx->{smb_conf}$?");
560 return undef;
562 my $acl = "false";
563 $acl = "true" if (defined $ENV{WITH_ACL});
564 print CONFFILE "
565 [global]
566 acl:search = $acl
567 netbios name = $ctx->{netbiosname}
568 posix:eadb = $ctx->{statedir}/eadb.tdb
569 workgroup = $ctx->{domain}
570 realm = $ctx->{realm}
571 private dir = $ctx->{privatedir}
572 pid directory = $ctx->{piddir}
573 ncalrpc dir = $ctx->{ncalrpcdir}
574 lock dir = $ctx->{lockdir}
575 state directory = $ctx->{statedir}
576 cache directory = $ctx->{cachedir}
577 winbindd socket directory = $ctx->{winbindd_socket_dir}
578 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
579 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
580 winbind separator = /
581 name resolve order = file bcast
582 interfaces = $ctx->{interfaces}
583 tls dh params file = $ctx->{tlsdir}/dhparms.pem
584 panic action = $RealBin/gdb_backtrace \%d
585 wins support = yes
586 server role = $ctx->{server_role}
587 server services = +echo +smb -s3fs
588 dcerpc endpoint servers = +winreg +srvsvc
589 notify:inotify = false
590 ldb:nosync = true
591 #We don't want to pass our self-tests if the PAC code is wrong
592 gensec:require_pac = true
593 log file = $ctx->{logdir}/log.\%m
594 log level = $ctx->{server_loglevel}
595 lanman auth = Yes
596 rndc command = true
597 dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file} -s $ctx->{smb_conf}
598 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
599 resolv:host file = $ctx->{dns_host_file}
600 dreplsrv:periodic_startup_interval = 0
601 dsdb:schema update allowed = yes
603 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
605 # remove this again, when our smb2 client library
606 # supports signin on compound related requests
607 server signing = on
610 print CONFFILE "
612 # Begin extra options
613 $ctx->{smb_conf_extra_options}
614 # End extra options
616 close(CONFFILE);
618 $self->mk_keyblobs($ctx->{tlsdir});
620 #Default the KDC IP to the server's IP
621 if (not defined($ctx->{kdc_ipv4})) {
622 $ctx->{kdc_ipv4} = $ctx->{ipv4};
625 Samba::mk_krb5_conf($ctx, "");
627 open(PWD, ">$ctx->{nsswrap_passwd}");
628 print PWD "
629 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
630 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
631 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
633 close(PWD);
635 open(GRP, ">$ctx->{nsswrap_group}");
636 print GRP "
637 root:x:0:
638 wheel:x:10:
639 users:x:100:
640 nobody:x:65533:
641 nogroup:x:65534:nobody
643 close(GRP);
645 my $configuration = "--configfile=$ctx->{smb_conf}";
647 #Ensure the config file is valid before we start
648 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
649 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
650 system("$testparm -v --suppress-prompt $configuration >&2");
651 warn("Failed to create a valid smb.conf configuration $testparm!");
652 return undef;
654 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) {
655 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
656 return undef;
659 my $ret = {
660 KRB5_CONFIG => $ctx->{krb5_conf},
661 PIDDIR => $ctx->{piddir},
662 SERVER => $ctx->{hostname},
663 SERVER_IP => $ctx->{ipv4},
664 NETBIOSNAME => $ctx->{netbiosname},
665 DOMAIN => $ctx->{domain},
666 USERNAME => $ctx->{username},
667 REALM => $ctx->{realm},
668 PASSWORD => $ctx->{password},
669 LDAPDIR => $ctx->{ldapdir},
670 LDAP_INSTANCE => $ctx->{ldap_instance},
671 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
672 NCALRPCDIR => $ctx->{ncalrpcdir},
673 LOCKDIR => $ctx->{lockdir},
674 STATEDIR => $ctx->{statedir},
675 CACHEDIR => $ctx->{cachedir},
676 PRIVATEDIR => $ctx->{privatedir},
677 SERVERCONFFILE => $ctx->{smb_conf},
678 CONFIGURATION => $configuration,
679 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
680 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
681 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
682 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
683 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
684 SAMBA_TEST_LOG_POS => 0,
685 NSS_WRAPPER_WINBIND_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
686 LOCAL_PATH => $ctx->{share}
689 return $ret;
693 # Step2 runs the provision script
695 sub provision_raw_step2($$$)
697 my ($self, $ctx, $ret) = @_;
699 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
700 unless (system($provision_cmd) == 0) {
701 warn("Unable to provision: \n$provision_cmd\n");
702 return undef;
705 return $ret;
708 sub provision($$$$$$$$$)
710 my ($self, $prefix, $server_role, $hostname,
711 $domain, $realm, $functional_level,
712 $password, $kdc_ipv4, $extra_smbconf_options, $extra_smbconf_shares,
713 $extra_provision_options) = @_;
715 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
716 $hostname,
717 $domain, $realm, $functional_level,
718 $password, $kdc_ipv4);
720 if (defined($extra_provision_options)) {
721 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
722 } else {
723 push (@{$ctx->{provision_options}}, "--use-ntvfs");
726 $ctx->{share} = "$ctx->{prefix_abs}/share";
727 push(@{$ctx->{directories}}, "$ctx->{share}");
728 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
729 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
731 # precreate directories for printer drivers
732 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
733 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
734 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
736 my $msdfs = "no";
737 $msdfs = "yes" if ($server_role eq "domain controller");
738 $ctx->{smb_conf_extra_options} = "
740 max xmit = 32K
741 server max protocol = SMB2
742 host msdfs = $msdfs
743 lanman auth = yes
745 $extra_smbconf_options
747 [tmp]
748 path = $ctx->{share}
749 read only = no
750 posix:sharedelay = 10000
751 posix:oplocktimeout = 3
752 posix:writetimeupdatedelay = 50000
754 [xcopy_share]
755 path = $ctx->{share}
756 read only = no
757 posix:sharedelay = 10000
758 posix:oplocktimeout = 3
759 posix:writetimeupdatedelay = 50000
760 create mask = 777
761 force create mode = 777
763 [posix_share]
764 path = $ctx->{share}
765 read only = no
766 create mask = 0777
767 force create mode = 0
768 directory mask = 0777
769 force directory mode = 0
771 [test1]
772 path = $ctx->{share}/test1
773 read only = no
774 posix:sharedelay = 10000
775 posix:oplocktimeout = 3
776 posix:writetimeupdatedelay = 50000
778 [test2]
779 path = $ctx->{share}/test2
780 read only = no
781 posix:sharedelay = 10000
782 posix:oplocktimeout = 3
783 posix:writetimeupdatedelay = 50000
785 [cifs]
786 read only = no
787 ntvfs handler = cifs
788 cifs:server = $ctx->{netbiosname}
789 cifs:share = tmp
790 cifs:use-s4u2proxy = yes
791 # There is no username specified here, instead the client is expected
792 # to log in with kerberos, and the serverwill use delegated credentials.
793 # Or the server tries s4u2self/s4u2proxy to impersonate the client
795 [simple]
796 path = $ctx->{share}
797 read only = no
798 ntvfs handler = simple
800 [sysvol]
801 path = $ctx->{statedir}/sysvol
802 read only = yes
804 [netlogon]
805 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
806 read only = no
808 [cifsposix]
809 copy = simple
810 ntvfs handler = cifsposix
812 $extra_smbconf_shares
815 if (defined($self->{ldap})) {
816 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
817 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
819 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
820 $ldap_uri =~ s|/|%2F|g;
821 $ldap_uri = "ldapi://$ldap_uri";
822 $ctx->{ldap_uri} = $ldap_uri;
824 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
827 my $ret = $self->provision_raw_step1($ctx);
828 unless (defined $ret) {
829 return undef;
832 if (defined($self->{ldap})) {
833 $ret->{LDAP_URI} = $ctx->{ldap_uri};
834 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
835 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
836 if ($self->{ldap} eq "openldap") {
837 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
838 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
840 } elsif ($self->{ldap} eq "fedora-ds") {
841 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
842 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
843 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
848 return $self->provision_raw_step2($ctx, $ret);
851 sub provision_member($$$)
853 my ($self, $prefix, $dcvars) = @_;
854 print "PROVISIONING MEMBER...";
856 my $ret = $self->provision($prefix,
857 "member server",
858 "s4member",
859 "SAMBADOMAIN",
860 "samba.example.com",
861 "2008",
862 "locMEMpass3",
863 $dcvars->{SERVER_IP},
864 "", "", undef);
865 unless ($ret) {
866 return undef;
869 my $samba_tool = Samba::bindir_path($self, "samba-tool");
870 my $cmd = "";
871 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
872 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
873 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
874 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
875 $cmd .= " --machinepass=machine$ret->{password}";
877 unless (system($cmd) == 0) {
878 warn("Join failed\n$cmd");
879 return undef;
882 $ret->{MEMBER_SERVER} = $ret->{SERVER};
883 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
884 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
885 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
886 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
888 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
889 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
890 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
891 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
892 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
894 return $ret;
897 sub provision_rpc_proxy($$$)
899 my ($self, $prefix, $dcvars) = @_;
900 print "PROVISIONING RPC PROXY...";
902 my $extra_smbconf_options = "
904 # rpc_proxy
905 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
906 dcerpc endpoint servers = epmapper, remote
907 dcerpc_remote:interfaces = rpcecho
909 [cifs_to_dc]
910 read only = no
911 ntvfs handler = cifs
912 cifs:server = $dcvars->{SERVER}
913 cifs:share = cifs
914 cifs:use-s4u2proxy = yes
915 # There is no username specified here, instead the client is expected
916 # to log in with kerberos, and the serverwill use delegated credentials.
917 # Or the server tries s4u2self/s4u2proxy to impersonate the client
921 my $ret = $self->provision($prefix,
922 "member server",
923 "localrpcproxy",
924 "SAMBADOMAIN",
925 "samba.example.com",
926 "2008",
927 "locRPCproxypass4",
928 $dcvars->{SERVER_IP},
929 $extra_smbconf_options, "", undef);
931 unless ($ret) {
932 return undef;
935 my $samba_tool = Samba::bindir_path($self, "samba-tool");
937 # The joind runs in the context of the rpc_proxy/member for now
938 my $cmd = "";
939 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
940 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
941 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
942 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
943 $cmd .= " --machinepass=machine$ret->{password}";
945 unless (system($cmd) == 0) {
946 warn("Join failed\n$cmd");
947 return undef;
950 # Setting up delegation runs in the context of the DC for now
951 $cmd = "";
952 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
953 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
954 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
955 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
957 unless (system($cmd) == 0) {
958 warn("Delegation failed\n$cmd");
959 return undef;
962 # Setting up delegation runs in the context of the DC for now
963 $cmd = "";
964 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
965 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
966 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
967 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
969 unless (system($cmd) == 0) {
970 warn("Delegation failed\n$cmd");
971 return undef;
974 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
975 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
976 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
977 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
978 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
980 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
981 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
982 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
983 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
984 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
986 return $ret;
989 sub provision_promoted_vampire_dc($$$)
991 my ($self, $prefix, $dcvars) = @_;
992 print "PROVISIONING VAMPIRE DC...";
994 # We do this so that we don't run the provision. That's the job of 'net vampire'.
995 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
996 "promotedvdc",
997 "SAMBADOMAIN",
998 "samba.example.com",
999 "2008",
1000 $dcvars->{PASSWORD},
1001 $dcvars->{SERVER_IP});
1003 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1005 $ctx->{smb_conf_extra_options} = "
1006 max xmit = 32K
1007 server max protocol = SMB2
1009 [sysvol]
1010 path = $ctx->{statedir}/sysvol
1011 read only = yes
1013 [netlogon]
1014 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1015 read only = no
1019 my $ret = $self->provision_raw_step1($ctx);
1020 unless ($ret) {
1021 return undef;
1024 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1025 my $cmd = "";
1026 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1027 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1028 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1029 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1030 $cmd .= " --machinepass=machine$ret->{password}";
1032 unless (system($cmd) == 0) {
1033 warn("Join failed\n$cmd");
1034 return undef;
1037 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1038 my $cmd = "";
1039 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1040 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1041 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1042 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1043 $cmd .= " --machinepass=machine$ret->{password} --use-ntvfs";
1045 unless (system($cmd) == 0) {
1046 warn("Join failed\n$cmd");
1047 return undef;
1050 $ret->{PROMOTED_VAMPIRE_DC_SERVER} = $ret->{SERVER};
1051 $ret->{PROMOTED_VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1052 $ret->{PROMOTED_VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1054 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1055 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1056 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1057 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1058 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1060 return $ret;
1063 sub provision_vampire_dc($$$)
1065 my ($self, $prefix, $dcvars) = @_;
1066 print "PROVISIONING VAMPIRE DC...";
1068 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1069 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1070 "localvampiredc",
1071 "SAMBADOMAIN",
1072 "samba.example.com",
1073 "2008",
1074 $dcvars->{PASSWORD},
1075 $dcvars->{SERVER_IP});
1077 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1079 $ctx->{smb_conf_extra_options} = "
1080 max xmit = 32K
1081 server max protocol = SMB2
1083 [sysvol]
1084 path = $ctx->{statedir}/sysvol
1085 read only = yes
1087 [netlogon]
1088 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1089 read only = no
1093 my $ret = $self->provision_raw_step1($ctx);
1094 unless ($ret) {
1095 return undef;
1098 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1099 my $cmd = "";
1100 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1101 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1102 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1103 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1104 $cmd .= " --machinepass=machine$ret->{password} --use-ntvfs";
1106 unless (system($cmd) == 0) {
1107 warn("Join failed\n$cmd");
1108 return undef;
1111 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1112 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1113 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1115 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1116 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1117 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1118 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1119 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1121 return $ret;
1124 sub provision_subdom_dc($$$)
1126 my ($self, $prefix, $dcvars) = @_;
1127 print "PROVISIONING SUBDOMAIN DC...";
1129 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1130 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1131 "localsubdc",
1132 "SAMBASUBDOM",
1133 "sub.samba.example.com",
1134 "2008",
1135 $dcvars->{PASSWORD},
1136 undef);
1138 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1140 $ctx->{smb_conf_extra_options} = "
1141 max xmit = 32K
1142 server max protocol = SMB2
1144 [sysvol]
1145 path = $ctx->{statedir}/sysvol
1146 read only = yes
1148 [netlogon]
1149 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1150 read only = no
1154 my $ret = $self->provision_raw_step1($ctx);
1155 unless ($ret) {
1156 return undef;
1159 my $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
1160 $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
1161 Samba::mk_krb5_conf($ctx, $dc_realms);
1163 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1164 my $cmd = "";
1165 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1166 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1167 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
1168 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1169 $cmd .= " --machinepass=machine$ret->{password} --use-ntvfs";
1171 unless (system($cmd) == 0) {
1172 warn("Join failed\n$cmd");
1173 return undef;
1176 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1177 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1178 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1180 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1181 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1182 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1183 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1184 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1186 return $ret;
1189 sub provision_dc($$)
1191 my ($self, $prefix) = @_;
1193 print "PROVISIONING DC...";
1194 my $extra_conf_options = "netbios aliases = localDC1-a";
1195 my $ret = $self->provision($prefix,
1196 "domain controller",
1197 "localdc",
1198 "SAMBADOMAIN",
1199 "samba.example.com",
1200 "2008",
1201 "locDCpass1",
1202 undef, $extra_conf_options, "", undef);
1204 return undef unless(defined $ret);
1205 unless($self->add_wins_config("$prefix/private")) {
1206 warn("Unable to add wins configuration");
1207 return undef;
1209 $ret->{NETBIOSALIAS} = "localdc1-a";
1210 $ret->{DC_SERVER} = $ret->{SERVER};
1211 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1212 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1213 $ret->{DC_USERNAME} = $ret->{USERNAME};
1214 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1216 return $ret;
1219 sub provision_fl2000dc($$)
1221 my ($self, $prefix) = @_;
1223 print "PROVISIONING DC...";
1224 my $ret = $self->provision($prefix,
1225 "domain controller",
1226 "dc5",
1227 "SAMBA2000",
1228 "samba2000.example.com",
1229 "2000",
1230 "locDCpass5",
1231 undef, "", "", undef);
1233 unless($self->add_wins_config("$prefix/private")) {
1234 warn("Unable to add wins configuration");
1235 return undef;
1238 return $ret;
1241 sub provision_fl2003dc($$)
1243 my ($self, $prefix) = @_;
1245 print "PROVISIONING DC...";
1246 my $ret = $self->provision($prefix,
1247 "domain controller",
1248 "dc6",
1249 "SAMBA2003",
1250 "samba2003.example.com",
1251 "2003",
1252 "locDCpass6",
1253 undef, "allow dns updates = nonsecure and secure", "", undef);
1255 unless($self->add_wins_config("$prefix/private")) {
1256 warn("Unable to add wins configuration");
1257 return undef;
1260 return $ret;
1263 sub provision_fl2008r2dc($$)
1265 my ($self, $prefix) = @_;
1267 print "PROVISIONING DC...";
1268 my $ret = $self->provision($prefix,
1269 "domain controller",
1270 "dc7",
1271 "SAMBA2008R2",
1272 "samba2008R2.example.com",
1273 "2008_R2",
1274 "locDCpass7",
1275 undef, "", "", undef);
1277 unless ($self->add_wins_config("$prefix/private")) {
1278 warn("Unable to add wins configuration");
1279 return undef;
1282 return $ret;
1286 sub provision_rodc($$$)
1288 my ($self, $prefix, $dcvars) = @_;
1289 print "PROVISIONING RODC...";
1291 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1292 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1293 "rodc",
1294 "SAMBADOMAIN",
1295 "samba.example.com",
1296 "2008",
1297 $dcvars->{PASSWORD},
1298 $dcvars->{SERVER_IP});
1299 unless ($ctx) {
1300 return undef;
1303 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1305 $ctx->{share} = "$ctx->{prefix_abs}/share";
1306 push(@{$ctx->{directories}}, "$ctx->{share}");
1308 $ctx->{smb_conf_extra_options} = "
1309 max xmit = 32K
1310 server max protocol = SMB2
1312 [sysvol]
1313 path = $ctx->{statedir}/sysvol
1314 read only = yes
1316 [netlogon]
1317 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1318 read only = yes
1320 [tmp]
1321 path = $ctx->{share}
1322 read only = no
1323 posix:sharedelay = 10000
1324 posix:oplocktimeout = 3
1325 posix:writetimeupdatedelay = 50000
1329 my $ret = $self->provision_raw_step1($ctx);
1330 unless ($ret) {
1331 return undef;
1334 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1335 my $cmd = "";
1336 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1337 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1338 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1339 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1340 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1342 unless (system($cmd) == 0) {
1343 warn("RODC join failed\n$cmd");
1344 return undef;
1347 # we overwrite the kdc after the RODC join
1348 # so that use the RODC as kdc and test
1349 # the proxy code
1350 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1351 Samba::mk_krb5_conf($ctx);
1353 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1354 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1355 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1357 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1358 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1359 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1360 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1361 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1363 return $ret;
1366 sub provision_plugin_s4_dc($$)
1368 my ($self, $prefix) = @_;
1370 my $prefix_abs = abs_path($prefix);
1372 my $bindir_abs = abs_path($self->{bindir});
1373 my $lockdir="$prefix_abs/lockdir";
1374 my $conffile="$prefix_abs/etc/smb.conf";
1376 my $extra_smbconf_options = "
1377 server services = -smb +s3fs
1378 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1380 kernel oplocks = no
1381 kernel change notify = no
1383 syslog = no
1384 printing = bsd
1385 printcap name = /dev/null
1387 max protocol = SMB3
1388 read only = no
1389 server signing = auto
1391 smbd:sharedelay = 100000
1392 smbd:writetimeupdatedelay = 500000
1393 create mask = 0777
1394 directory mask = 0777
1395 dos filemode = yes
1397 dcerpc endpoint servers = -winreg -srvsvc
1399 printcap name = /dev/null
1401 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1402 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1404 printing = vlp
1405 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1406 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1407 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1408 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1409 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1410 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1411 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1412 lpq cache time = 0
1416 my $extra_smbconf_shares = "
1418 [tmpenc]
1419 copy = tmp
1420 smb encrypt = required
1422 [tmpcase]
1423 copy = tmp
1424 case sensitive = yes
1426 [tmpguest]
1427 copy = tmp
1428 guest ok = yes
1430 [hideunread]
1431 copy = tmp
1432 hide unreadable = yes
1434 [durable]
1435 copy = tmp
1436 kernel share modes = no
1437 kernel oplocks = no
1438 posix locking = no
1440 [print\$]
1441 copy = tmp
1443 [print1]
1444 copy = tmp
1445 printable = yes
1447 [print2]
1448 copy = print1
1449 [print3]
1450 copy = print1
1451 [lp]
1452 copy = print1
1455 print "PROVISIONING PLUGIN S4 DC...";
1456 my $ret = $self->provision($prefix,
1457 "domain controller",
1458 "plugindc",
1459 "PLUGINDOMAIN",
1460 "plugin.samba.example.com",
1461 "2008",
1462 "locDCpass1",
1463 undef, $extra_smbconf_options,
1464 $extra_smbconf_shares, undef);
1466 return undef unless(defined $ret);
1467 unless($self->add_wins_config("$prefix/private")) {
1468 warn("Unable to add wins configuration");
1469 return undef;
1472 $ret->{DC_SERVER} = $ret->{SERVER};
1473 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1474 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1475 $ret->{DC_USERNAME} = $ret->{USERNAME};
1476 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1478 return $ret;
1481 sub provision_chgdcpass($$)
1483 my ($self, $prefix) = @_;
1485 print "PROVISIONING CHGDCPASS...";
1486 my $extra_provision_options = undef;
1487 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1488 my $ret = $self->provision($prefix,
1489 "domain controller",
1490 "chgdcpass",
1491 "CHDCDOMAIN",
1492 "chgdcpassword.samba.example.com",
1493 "2008",
1494 "chgDCpass1",
1495 undef, "server services = -dns", "",
1496 $extra_provision_options);
1498 return undef unless(defined $ret);
1499 unless($self->add_wins_config("$prefix/private")) {
1500 warn("Unable to add wins configuration");
1501 return undef;
1504 # Remove secrets.tdb from this environment to test that we still start up
1505 # on systems without the new matching secrets.tdb records
1506 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb")) {
1507 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1508 return undef;
1511 $ret->{DC_SERVER} = $ret->{SERVER};
1512 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1513 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1514 $ret->{DC_USERNAME} = $ret->{USERNAME};
1515 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1517 return $ret;
1520 sub teardown_env($$)
1522 my ($self, $envvars) = @_;
1523 my $pid;
1525 # This should cause samba to terminate gracefully
1526 close($envvars->{STDIN_PIPE});
1528 $pid = $envvars->{SAMBA_PID};
1529 my $count = 0;
1530 my $childpid;
1532 # This should give it time to write out the gcov data
1533 until ($count > 30) {
1534 if (Samba::cleanup_child($pid, "samba") == -1) {
1535 last;
1537 sleep(1);
1538 $count++;
1541 if ($count <= 20 && kill(0, $pid) == 0) {
1542 return;
1545 kill "TERM", $pid;
1547 until ($count > 20) {
1548 if (Samba::cleanup_child($pid, "samba") == -1) {
1549 last;
1551 sleep(1);
1552 $count++;
1555 # If it is still around, kill it
1556 if ($count > 20 && kill(0, $pid) == 0) {
1557 warn "server process $pid took more than $count seconds to exit, killing\n";
1558 kill 9, $pid;
1561 $self->slapd_stop($envvars) if ($self->{ldap});
1563 print $self->getlog_env($envvars);
1565 return;
1568 sub getlog_env($$)
1570 my ($self, $envvars) = @_;
1571 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1572 my $out = $title;
1574 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1576 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1577 while (<LOG>) {
1578 $out .= $_;
1580 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1581 close(LOG);
1583 return "" if $out eq $title;
1585 return $out;
1588 sub check_env($$)
1590 my ($self, $envvars) = @_;
1592 my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
1594 return ($childpid == 0);
1597 sub setup_env($$$)
1599 my ($self, $envname, $path) = @_;
1600 my $target3 = $self->{target3};
1602 $ENV{ENVNAME} = $envname;
1604 if (defined($self->{vars}->{$envname})) {
1605 return $self->{vars}->{$envname};
1608 if ($envname eq "dc") {
1609 return $self->setup_dc("$path/dc");
1610 } elsif ($envname eq "fl2000dc") {
1611 return $self->setup_fl2000dc("$path/fl2000dc");
1612 } elsif ($envname eq "fl2003dc") {
1613 return $self->setup_fl2003dc("$path/fl2003dc");
1614 } elsif ($envname eq "fl2008r2dc") {
1615 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1616 } elsif ($envname eq "rpc_proxy") {
1617 if (not defined($self->{vars}->{dc})) {
1618 $self->setup_dc("$path/dc");
1620 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1621 } elsif ($envname eq "vampire_dc") {
1622 if (not defined($self->{vars}->{dc})) {
1623 $self->setup_dc("$path/dc");
1625 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1626 } elsif ($envname eq "promoted_vampire_dc") {
1627 if (not defined($self->{vars}->{dc})) {
1628 $self->setup_dc("$path/dc");
1630 return $self->setup_promoted_vampire_dc("$path/promoted_vampire_dc", $self->{vars}->{dc});
1631 } elsif ($envname eq "subdom_dc") {
1632 if (not defined($self->{vars}->{dc})) {
1633 $self->setup_dc("$path/dc");
1635 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
1636 } elsif ($envname eq "s4member") {
1637 if (not defined($self->{vars}->{dc})) {
1638 $self->setup_dc("$path/dc");
1640 return $self->setup_member("$path/s4member", $self->{vars}->{dc});
1641 } elsif ($envname eq "rodc") {
1642 if (not defined($self->{vars}->{dc})) {
1643 $self->setup_dc("$path/dc");
1645 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1646 } elsif ($envname eq "chgdcpass") {
1647 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
1648 } elsif ($envname eq "s3member") {
1649 if (not defined($self->{vars}->{dc})) {
1650 $self->setup_dc("$path/dc");
1652 return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
1653 } elsif ($envname eq "plugin_s4_dc") {
1654 return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
1655 } else {
1656 return "UNKNOWN";
1660 sub setup_member($$$)
1662 my ($self, $path, $dc_vars) = @_;
1664 my $env = $self->provision_member($path, $dc_vars);
1666 if (defined $env) {
1667 $self->check_or_start($env, "single");
1669 $self->wait_for_start($env);
1671 $self->{vars}->{member} = $env;
1674 return $env;
1677 sub setup_rpc_proxy($$$)
1679 my ($self, $path, $dc_vars) = @_;
1681 my $env = $self->provision_rpc_proxy($path, $dc_vars);
1683 if (defined $env) {
1684 $self->check_or_start($env, "single");
1686 $self->wait_for_start($env);
1688 $self->{vars}->{rpc_proxy} = $env;
1690 return $env;
1693 sub setup_dc($$)
1695 my ($self, $path) = @_;
1697 my $env = $self->provision_dc($path);
1698 if (defined $env) {
1699 $self->check_or_start($env, "standard");
1701 $self->wait_for_start($env);
1703 $self->{vars}->{dc} = $env;
1705 return $env;
1708 sub setup_chgdcpass($$)
1710 my ($self, $path) = @_;
1712 my $env = $self->provision_chgdcpass($path);
1713 if (defined $env) {
1714 $self->check_or_start($env, "single");
1716 $self->wait_for_start($env);
1718 $self->{vars}->{chgdcpass} = $env;
1720 return $env;
1723 sub setup_fl2000dc($$)
1725 my ($self, $path) = @_;
1727 my $env = $self->provision_fl2000dc($path);
1728 if (defined $env) {
1729 $self->check_or_start($env, "single");
1731 $self->wait_for_start($env);
1733 $self->{vars}->{fl2000dc} = $env;
1736 return $env;
1739 sub setup_fl2003dc($$)
1741 my ($self, $path) = @_;
1743 my $env = $self->provision_fl2003dc($path);
1745 if (defined $env) {
1746 $self->check_or_start($env, "single");
1748 $self->wait_for_start($env);
1750 $self->{vars}->{fl2003dc} = $env;
1752 return $env;
1755 sub setup_fl2008r2dc($$)
1757 my ($self, $path) = @_;
1759 my $env = $self->provision_fl2008r2dc($path);
1761 if (defined $env) {
1762 $self->check_or_start($env, "single");
1764 $self->wait_for_start($env);
1766 $self->{vars}->{fl2008r2dc} = $env;
1769 return $env;
1772 sub setup_vampire_dc($$$)
1774 my ($self, $path, $dc_vars) = @_;
1776 my $env = $self->provision_vampire_dc($path, $dc_vars);
1778 if (defined $env) {
1779 $self->check_or_start($env, "single");
1781 $self->wait_for_start($env);
1783 $self->{vars}->{vampire_dc} = $env;
1785 # force replicated DC to update repsTo/repsFrom
1786 # for vampired partitions
1787 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1788 my $cmd = "";
1789 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1790 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1791 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1792 $cmd .= " $env->{CONFIGURATION}";
1793 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1794 unless (system($cmd) == 0) {
1795 warn("Failed to exec kcc\n$cmd");
1796 return undef;
1799 # as 'vampired' dc may add data in its local replica
1800 # we need to synchronize data between DCs
1801 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1802 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1803 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1804 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1805 $cmd .= " $dc_vars->{CONFIGURATION}";
1806 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1807 # replicate Configuration NC
1808 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1809 unless(system($cmd_repl) == 0) {
1810 warn("Failed to replicate\n$cmd_repl");
1811 return undef;
1813 # replicate Default NC
1814 $cmd_repl = "$cmd \"$base_dn\"";
1815 unless(system($cmd_repl) == 0) {
1816 warn("Failed to replicate\n$cmd_repl");
1817 return undef;
1821 return $env;
1824 sub setup_promoted_vampire_dc($$$)
1826 my ($self, $path, $dc_vars) = @_;
1828 my $env = $self->provision_promoted_vampire_dc($path, $dc_vars);
1830 if (defined $env) {
1831 $self->check_or_start($env, "single");
1833 $self->wait_for_start($env);
1835 $self->{vars}->{promoted_vampire_dc} = $env;
1837 # force replicated DC to update repsTo/repsFrom
1838 # for vampired partitions
1839 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1840 my $cmd = "";
1841 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1842 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1843 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1844 $cmd .= " $env->{CONFIGURATION}";
1845 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1846 unless (system($cmd) == 0) {
1847 warn("Failed to exec kcc\n$cmd");
1848 return undef;
1851 # as 'vampired' dc may add data in its local replica
1852 # we need to synchronize data between DCs
1853 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1854 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1855 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1856 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
1857 $cmd .= " $dc_vars->{CONFIGURATION}";
1858 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1859 # replicate Configuration NC
1860 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1861 unless(system($cmd_repl) == 0) {
1862 warn("Failed to replicate\n$cmd_repl");
1863 return undef;
1865 # replicate Default NC
1866 $cmd_repl = "$cmd \"$base_dn\"";
1867 unless(system($cmd_repl) == 0) {
1868 warn("Failed to replicate\n$cmd_repl");
1869 return undef;
1873 return $env;
1876 sub setup_subdom_dc($$$)
1878 my ($self, $path, $dc_vars) = @_;
1880 my $env = $self->provision_subdom_dc($path, $dc_vars);
1882 if (defined $env) {
1883 $self->check_or_start($env, "single");
1885 $self->wait_for_start($env);
1887 $self->{vars}->{subdom_dc} = $env;
1889 # force replicated DC to update repsTo/repsFrom
1890 # for primary domain partitions
1891 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1892 my $cmd = "";
1893 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1894 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1895 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1896 $cmd .= " $env->{CONFIGURATION}";
1897 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1898 unless (system($cmd) == 0) {
1899 warn("Failed to exec kcc\n$cmd");
1900 return undef;
1903 # as 'subdomain' dc may add data in its local replica
1904 # we need to synchronize data between DCs
1905 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
1906 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1907 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1908 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1909 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
1910 $cmd .= " $dc_vars->{CONFIGURATION}";
1911 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
1912 # replicate Configuration NC
1913 my $cmd_repl = "$cmd \"$config_dn\"";
1914 unless(system($cmd_repl) == 0) {
1915 warn("Failed to replicate\n$cmd_repl");
1916 return undef;
1918 # replicate Default NC
1919 $cmd_repl = "$cmd \"$base_dn\"";
1920 unless(system($cmd_repl) == 0) {
1921 warn("Failed to replicate\n$cmd_repl");
1922 return undef;
1926 return $env;
1929 sub setup_rodc($$$)
1931 my ($self, $path, $dc_vars) = @_;
1933 my $env = $self->provision_rodc($path, $dc_vars);
1935 unless ($env) {
1936 return undef;
1939 $self->check_or_start($env, "single");
1941 $self->wait_for_start($env);
1943 $self->{vars}->{rodc} = $env;
1945 return $env;
1948 sub setup_plugin_s4_dc($$)
1950 my ($self, $path) = @_;
1952 # If we didn't build with ADS, pretend this env was never available
1953 if (not $self->{target3}->have_ads()) {
1954 return "UNKNOWN";
1957 my $env = $self->provision_plugin_s4_dc($path);
1958 unless ($env) {
1959 return undef;
1962 $self->check_or_start($env, "single");
1964 $self->wait_for_start($env);
1966 $self->{vars}->{plugin_s4_dc} = $env;
1967 return $env;