fix Ń•ome == to correct shell test in commented stuff
[Samba.git] / selftest / target / Samba4.pm
blob37c9550a7afde7357b74da822066f0776e9a54af
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;
14 sub new($$$$$) {
15 my ($classname, $bindir, $ldap, $setupdir, $exeext) = @_;
16 $exeext = "" unless defined($exeext);
17 my $self = {
18 vars => {},
19 ldap => $ldap,
20 bindir => $bindir,
21 setupdir => $setupdir,
22 exeext => $exeext
24 bless $self;
25 return $self;
28 sub bindir_path($$) {
29 my ($self, $path) = @_;
31 my $valpath = "$self->{bindir}/$path$self->{exeext}";
33 return $valpath if (-f $valpath);
34 return $path;
37 sub openldap_start($$$) {
40 sub slapd_start($$)
42 my $count = 0;
43 my ($self, $env_vars) = @_;
44 my $ldbsearch = $self->bindir_path("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, $max_time) = @_;
89 return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
91 unlink($env_vars->{SAMBA_TEST_FIFO});
92 POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
93 unlink($env_vars->{SAMBA_TEST_LOG});
95 my $pwd = `pwd`;
96 print "STARTING SAMBA for $ENV{ENVNAME}\n";
97 my $pid = fork();
98 if ($pid == 0) {
99 open STDIN, $env_vars->{SAMBA_TEST_FIFO};
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 my $valgrind = "";
109 if (defined($ENV{SAMBA_VALGRIND})) {
110 $valgrind = $ENV{SAMBA_VALGRIND};
113 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
114 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
116 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
117 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
119 $ENV{UID_WRAPPER} = "1";
121 # Start slapd before samba, but with the fifo on stdin
122 if (defined($self->{ldap})) {
123 unless($self->slapd_start($env_vars)) {
124 warn("couldn't start slapd (main run)");
125 return undef;
129 my $optarg = "";
130 if (defined($max_time)) {
131 $optarg = "--maximum-runtime=$max_time ";
133 if (defined($ENV{SAMBA_OPTIONS})) {
134 $optarg.= " $ENV{SAMBA_OPTIONS}";
136 my $samba = $self->bindir_path("samba");
138 # allow selection of the process model using
139 # the environment varibale SAMBA_PROCESS_MODEL
140 # that allows us to change the process model for
141 # individual machines in the build farm
142 my $model = "single";
143 if (defined($ENV{SAMBA_PROCESS_MODEL})) {
144 $model = $ENV{SAMBA_PROCESS_MODEL};
146 chomp($pwd);
147 my $cmdline = "$valgrind ${pwd}/$samba $optarg $env_vars->{CONFIGURATION} -M $model -i";
148 my $ret = system("$cmdline");
149 if ($ret == -1) {
150 print "Unable to start $cmdline: $ret: $!\n";
151 exit 1;
153 my $exit = ($ret >> 8);
154 unlink($env_vars->{SAMBA_TEST_FIFO});
155 if ($ret == 0) {
156 print "$samba exited with no error\n";
157 exit 0;
158 } elsif ( $ret & 127 ) {
159 print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
160 } else {
161 print "$samba failed with status $exit!\n";
163 if ($exit == 0) {
164 $exit = -1;
166 exit $exit;
168 print "DONE\n";
170 open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
172 return $pid;
175 sub wait_for_start($$)
177 my ($self, $testenv_vars) = @_;
178 # give time for nbt server to register its names
179 print "delaying for nbt name registration\n";
180 sleep 2;
182 # This will return quickly when things are up, but be slow if we
183 # need to wait for (eg) SSL init
184 my $nmblookup = $self->bindir_path("nmblookup");
185 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
186 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
187 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
188 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
189 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
190 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
191 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
192 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
193 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
194 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
195 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
198 print $self->getlog_env($testenv_vars);
201 sub write_ldb_file($$$)
203 my ($self, $file, $ldif) = @_;
205 my $ldbadd = $self->bindir_path("ldbadd");
206 open(LDIF, "|$ldbadd -H $file >/dev/null");
207 print LDIF $ldif;
208 return(close(LDIF));
211 sub add_wins_config($$)
213 my ($self, $privatedir) = @_;
215 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
216 dn: name=TORTURE_11,CN=PARTNERS
217 objectClass: wreplPartner
218 name: TORTURE_11
219 address: 127.0.0.11
220 pullInterval: 0
221 pushChangeCount: 0
222 type: 0x3
226 sub mk_fedora_ds($$)
228 my ($self, $ctx) = @_;
230 #Make the subdirectory be as fedora DS would expect
231 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
233 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
235 return ($fedora_ds_dir, $pidfile);
238 sub mk_openldap($$)
240 my ($self, $ctx) = @_;
242 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
243 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
245 return ($slapd_conf_d, $pidfile);
248 sub mk_keyblobs($$)
250 my ($self, $tlsdir) = @_;
252 #TLS and PKINIT crypto blobs
253 my $dhfile = "$tlsdir/dhparms.pem";
254 my $cafile = "$tlsdir/ca.pem";
255 my $certfile = "$tlsdir/cert.pem";
256 my $reqkdc = "$tlsdir/req-kdc.der";
257 my $kdccertfile = "$tlsdir/kdc.pem";
258 my $keyfile = "$tlsdir/key.pem";
259 my $adminkeyfile = "$tlsdir/adminkey.pem";
260 my $reqadmin = "$tlsdir/req-admin.der";
261 my $admincertfile = "$tlsdir/admincert.pem";
262 my $admincertupnfile = "$tlsdir/admincertupn.pem";
264 mkdir($tlsdir, 0777);
266 #This is specified here to avoid draining entropy on every run
267 open(DHFILE, ">$dhfile");
268 print DHFILE <<EOF;
269 -----BEGIN DH PARAMETERS-----
270 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
271 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
272 YX70obsCAQI=
273 -----END DH PARAMETERS-----
275 close(DHFILE);
277 #Likewise, we pregenerate the key material. This allows the
278 #other certificates to be pre-generated
279 open(KEYFILE, ">$keyfile");
280 print KEYFILE <<EOF;
281 -----BEGIN RSA PRIVATE KEY-----
282 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
283 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
284 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
285 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
286 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
287 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
288 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
289 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
290 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
291 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
292 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
293 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
294 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
295 -----END RSA PRIVATE KEY-----
297 close(KEYFILE);
299 open(ADMINKEYFILE, ">$adminkeyfile");
301 print ADMINKEYFILE <<EOF;
302 -----BEGIN RSA PRIVATE KEY-----
303 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
304 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
305 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
306 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
307 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
308 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
309 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
310 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
311 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
312 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
313 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
314 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
315 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
316 -----END RSA PRIVATE KEY-----
319 #generated with
320 # hxtool issue-certificate --self-signed --issue-ca \
321 # --ca-private-key="FILE:$KEYFILE" \
322 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
323 # --certificate="FILE:$CAFILE" --lifetime="25 years"
325 open(CAFILE, ">$cafile");
326 print CAFILE <<EOF;
327 -----BEGIN CERTIFICATE-----
328 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
329 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
330 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
331 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
332 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
333 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
334 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
335 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
336 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
337 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
338 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
339 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
340 -----END CERTIFICATE-----
343 #generated with GNUTLS internally in Samba.
345 open(CERTFILE, ">$certfile");
346 print CERTFILE <<EOF;
347 -----BEGIN CERTIFICATE-----
348 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
349 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
350 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
351 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
352 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
353 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
354 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
355 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
356 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
357 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
358 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
359 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
360 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
361 -----END CERTIFICATE-----
363 close(CERTFILE);
365 #KDC certificate
366 # hxtool request-create \
367 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
368 # --key="FILE:$KEYFILE" $KDCREQ
370 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
371 # --type="pkinit-kdc" \
372 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
373 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
374 # --lifetime="25 years"
376 open(KDCCERTFILE, ">$kdccertfile");
377 print KDCCERTFILE <<EOF;
378 -----BEGIN CERTIFICATE-----
379 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
380 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
381 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
382 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
383 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
384 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
385 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
386 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
387 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
388 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
389 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
390 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
391 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
392 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
393 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
394 -----END CERTIFICATE-----
397 # hxtool request-create \
398 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
399 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
401 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
402 # --type="pkinit-client" \
403 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
404 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
405 # --lifetime="25 years"
407 open(ADMINCERTFILE, ">$admincertfile");
408 print ADMINCERTFILE <<EOF;
409 -----BEGIN CERTIFICATE-----
410 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
411 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
412 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
413 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
414 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
415 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
416 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
417 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
418 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
419 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
420 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
421 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
422 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
423 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
424 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
425 -----END CERTIFICATE-----
427 close(ADMINCERTFILE);
429 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
430 # --type="pkinit-client" \
431 # --ms-upn="administrator@samba.example.com" \
432 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
433 # --lifetime="25 years"
435 open(ADMINCERTUPNFILE, ">$admincertupnfile");
436 print ADMINCERTUPNFILE <<EOF;
437 -----BEGIN CERTIFICATE-----
438 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
439 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
440 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
441 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
442 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
443 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
444 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
445 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
446 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
447 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
448 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
449 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
450 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
451 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
452 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
453 -----END CERTIFICATE-----
457 sub provision_raw_prepare($$$$$$$$$$)
459 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias,
460 $domain, $realm, $functional_level,
461 $swiface, $password, $kdc_ipv4) = @_;
462 my $ctx;
464 unless(-d $prefix or mkdir($prefix, 0777)) {
465 warn("Unable to create $prefix");
466 return undef;
468 my $prefix_abs = abs_path($prefix);
470 die ("prefix=''") if $prefix_abs eq "";
471 die ("prefix='/'") if $prefix_abs eq "/";
473 unless (system("rm -rf $prefix_abs/*") == 0) {
474 warn("Unable to clean up");
477 $ctx->{prefix} = $prefix;
478 $ctx->{prefix_abs} = $prefix_abs;
480 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
482 $ctx->{server_role} = $server_role;
483 $ctx->{netbiosname} = $netbiosname;
484 $ctx->{netbiosalias} = $netbiosalias;
485 $ctx->{swiface} = $swiface;
486 $ctx->{password} = $password;
487 $ctx->{kdc_ipv4} = $kdc_ipv4;
489 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
490 $ctx->{username} = "Administrator";
491 $ctx->{domain} = $domain;
492 $ctx->{realm} = uc($realm);
493 $ctx->{dnsname} = lc($realm);
494 $ctx->{sid_generator} = "internal";
496 $ctx->{functional_level} = $functional_level;
498 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
499 chomp $unix_name;
500 $ctx->{unix_name} = $unix_name;
501 $ctx->{unix_uid} = $>;
502 $ctx->{unix_gids_str} = $);
503 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
505 $ctx->{etcdir} = "$prefix_abs/etc";
506 $ctx->{piddir} = "$prefix_abs/pid";
507 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
508 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
509 $ctx->{privatedir} = "$prefix_abs/private";
510 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
511 $ctx->{lockdir} = "$prefix_abs/lockdir";
512 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
513 $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
514 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
515 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
516 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
518 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
520 $ctx->{ipv4} = "127.0.0.$swiface";
521 $ctx->{interfaces} = "$ctx->{ipv4}/8";
523 push(@{$ctx->{directories}}, $ctx->{privatedir});
524 push(@{$ctx->{directories}}, $ctx->{etcdir});
525 push(@{$ctx->{directories}}, $ctx->{piddir});
526 push(@{$ctx->{directories}}, $ctx->{ncalrpcdir});
527 push(@{$ctx->{directories}}, $ctx->{lockdir});
529 $ctx->{smb_conf_extra_options} = "";
531 my @provision_options = ();
532 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
533 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
534 if (defined($ENV{GDB_PROVISION})) {
535 push (@provision_options, "gdb --args");
536 if (!defined($ENV{PYTHON})) {
537 push (@provision_options, "env");
538 push (@provision_options, "python");
541 if (defined($ENV{VALGRIND_PROVISION})) {
542 push (@provision_options, "valgrind");
543 if (!defined($ENV{PYTHON})) {
544 push (@provision_options, "env");
545 push (@provision_options, "python");
548 if (defined($ENV{PYTHON})) {
549 push (@provision_options, $ENV{PYTHON});
551 push (@provision_options, "$self->{setupdir}/provision");
552 push (@provision_options, "--configfile=$ctx->{smb_conf}");
553 push (@provision_options, "--host-name=$ctx->{netbiosname}");
554 push (@provision_options, "--host-ip=$ctx->{ipv4}");
555 push (@provision_options, "--quiet");
556 push (@provision_options, "--domain=$ctx->{domain}");
557 push (@provision_options, "--realm=$ctx->{realm}");
558 push (@provision_options, "--adminpass=$ctx->{password}");
559 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
560 push (@provision_options, "--machinepass=machine$ctx->{password}");
561 push (@provision_options, "--root=$ctx->{unix_name}");
562 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
563 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
565 @{$ctx->{provision_options}} = @provision_options;
567 return $ctx;
571 # Step1 creates the basic configuration
573 sub provision_raw_step1($$)
575 my ($self, $ctx) = @_;
577 mkdir($_, 0777) foreach (@{$ctx->{directories}});
579 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
580 warn("can't open $ctx->{smb_conf}$?");
581 return undef;
583 print CONFFILE "
584 [global]
585 netbios name = $ctx->{netbiosname}
586 netbios aliases = $ctx->{netbiosalias}
587 posix:eadb = $ctx->{lockdir}/eadb.tdb
588 workgroup = $ctx->{domain}
589 realm = $ctx->{realm}
590 private dir = $ctx->{privatedir}
591 pid directory = $ctx->{piddir}
592 ncalrpc dir = $ctx->{ncalrpcdir}
593 lock dir = $ctx->{lockdir}
594 setup directory = $self->{setupdir}
595 winbindd socket directory = $ctx->{winbindd_socket_dir}
596 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
597 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
598 winbind separator = /
599 name resolve order = file bcast
600 interfaces = $ctx->{interfaces}
601 tls dh params file = $ctx->{tlsdir}/dhparms.pem
602 panic action = $RealBin/gdb_backtrace \%PID% \%PROG%
603 wins support = yes
604 server role = $ctx->{server_role}
605 notify:inotify = false
606 ldb:nosync = true
607 #We don't want to pass our self-tests if the PAC code is wrong
608 gensec:require_pac = true
609 log level = $ctx->{server_loglevel}
610 lanman auth = Yes
611 rndc command = true
612 dns update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file}
613 spn update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_spnupdate
614 resolv:host file = $ctx->{dns_host_file}
615 dreplsrv:periodic_startup_interval = 0
618 if (defined($ctx->{sid_generator}) && $ctx->{sid_generator} ne "internal") {
619 print CONFFILE "
620 sid generator = $ctx->{sid_generator}";
623 print CONFFILE "
625 # Begin extra options
626 $ctx->{smb_conf_extra_options}
627 # End extra options
629 close(CONFFILE);
631 $self->mk_keyblobs($ctx->{tlsdir});
633 unless (open(KRB5CONF, ">$ctx->{krb5_conf}")) {
634 warn("can't open $ctx->{krb5_conf}$?");
635 return undef;
637 print KRB5CONF "
638 #Generated krb5.conf for $ctx->{realm}
640 [libdefaults]
641 default_realm = $ctx->{realm}
642 dns_lookup_realm = false
643 dns_lookup_kdc = false
644 ticket_lifetime = 24h
645 forwardable = yes
646 allow_weak_crypto = yes
648 [realms]
649 $ctx->{realm} = {
650 kdc = $ctx->{kdc_ipv4}:88
651 admin_server = $ctx->{kdc_ipv4}:88
652 default_domain = $ctx->{dnsname}
654 $ctx->{dnsname} = {
655 kdc = $ctx->{kdc_ipv4}:88
656 admin_server = $ctx->{kdc_ipv4}:88
657 default_domain = $ctx->{dnsname}
659 $ctx->{domain} = {
660 kdc = $ctx->{kdc_ipv4}:88
661 admin_server = $ctx->{kdc_ipv4}:88
662 default_domain = $ctx->{dnsname}
665 [appdefaults]
666 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
668 [kdc]
669 enable-pkinit = true
670 pkinit_identity = FILE:$ctx->{tlsdir}/kdc.pem,$ctx->{tlsdir}/key.pem
671 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
673 [domain_realm]
674 .$ctx->{dnsname} = $ctx->{realm}
676 close(KRB5CONF);
678 open(PWD, ">$ctx->{nsswrap_passwd}");
679 print PWD "
680 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
681 $ctx->{unix_name}:x:$ctx->{unix_uid}:@{$ctx->{unix_gids}}[0]:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
682 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
684 close(PWD);
686 open(GRP, ">$ctx->{nsswrap_group}");
687 print GRP "
688 root:x:0:
689 wheel:x:10:
690 users:x:100:
691 nobody:x:65533:
692 nogroup:x:65534:nobody
694 close(GRP);
696 my $configuration = "--configfile=$ctx->{smb_conf}";
698 #Ensure the config file is valid before we start
699 my $testparm = $self->bindir_path("../scripting/bin/testparm");
700 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
701 system("$testparm -v --suppress-prompt $configuration >&2");
702 warn("Failed to create a valid smb.conf configuration $testparm!");
703 return undef;
705 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) {
706 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
707 return undef;
710 my $ret = {
711 KRB5_CONFIG => $ctx->{krb5_conf},
712 PIDDIR => $ctx->{piddir},
713 SERVER => $ctx->{netbiosname},
714 SERVER_IP => $ctx->{ipv4},
715 NETBIOSNAME => $ctx->{netbiosname},
716 NETBIOSALIAS => $ctx->{netbiosalias},
717 DOMAIN => $ctx->{domain},
718 USERNAME => $ctx->{username},
719 REALM => $ctx->{realm},
720 PASSWORD => $ctx->{password},
721 LDAPDIR => $ctx->{ldapdir},
722 LDAP_INSTANCE => $ctx->{ldap_instance},
723 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
724 NCALRPCDIR => $ctx->{ncalrpcdir},
725 LOCKDIR => $ctx->{lockdir},
726 SERVERCONFFILE => $ctx->{smb_conf},
727 CONFIGURATION => $configuration,
728 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
729 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
730 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
731 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
732 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
733 SAMBA_TEST_LOG_POS => 0,
736 return $ret;
740 # Step2 runs the provision script
742 sub provision_raw_step2($$$)
744 my ($self, $ctx, $ret) = @_;
746 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
747 unless (system($provision_cmd) == 0) {
748 warn("Unable to provision: \n$provision_cmd\n");
749 return undef;
752 return $ret;
755 sub provision($$$$$$$$$)
757 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias,
758 $domain, $realm, $functional_level,
759 $swiface, $password, $kdc_ipv4, $extra_smbconf_options) = @_;
761 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
762 $netbiosname, $netbiosalias,
763 $domain, $realm, $functional_level,
764 $swiface, $password, $kdc_ipv4);
766 $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
767 push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
768 push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test1");
769 push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test2");
770 my $msdfs = "no";
771 $msdfs = "yes" if ($server_role eq "domain controller");
772 $ctx->{smb_conf_extra_options} = "
774 max xmit = 32K
775 server max protocol = SMB2
776 $extra_smbconf_options
777 host msdfs = $msdfs
778 lanman auth = yes
780 [tmp]
781 path = $ctx->{tmpdir}
782 read only = no
783 posix:sharedelay = 10000
784 posix:oplocktimeout = 3
785 posix:writetimeupdatedelay = 500000
787 [test1]
788 path = $ctx->{tmpdir}/test1
789 read only = no
790 posix:sharedelay = 10000
791 posix:oplocktimeout = 3
792 posix:writetimeupdatedelay = 50000
794 [test2]
795 path = $ctx->{tmpdir}/test2
796 read only = no
797 posix:sharedelay = 10000
798 posix:oplocktimeout = 3
799 posix:writetimeupdatedelay = 50000
801 [cifs]
802 read only = no
803 ntvfs handler = cifs
804 cifs:server = $ctx->{netbiosname}
805 cifs:share = tmp
806 #There is no username specified here, instead the client is expected
807 #to log in with kerberos, and the serverwill use delegated credentials.
809 [simple]
810 path = $ctx->{tmpdir}
811 read only = no
812 ntvfs handler = simple
814 [sysvol]
815 path = $ctx->{lockdir}/sysvol
816 read only = yes
818 [netlogon]
819 path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
820 read only = no
822 [cifsposix]
823 copy = simple
824 ntvfs handler = cifsposix
827 if (defined($self->{ldap})) {
828 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
829 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
831 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
832 $ldap_uri =~ s|/|%2F|g;
833 $ldap_uri = "ldapi://$ldap_uri";
834 $ctx->{ldap_uri} = $ldap_uri;
835 if ($self->{ldap} eq "fedora-ds") {
836 $ctx->{sid_generator} = "backend";
839 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
842 my $ret = $self->provision_raw_step1($ctx);
843 unless (defined $ret) {
844 return undef;
847 if (defined($self->{ldap})) {
848 $ret->{LDAP_URI} = $ctx->{ldap_uri};
849 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
850 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
851 if ($self->{ldap} eq "openldap") {
852 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
853 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
855 } elsif ($self->{ldap} eq "fedora-ds") {
856 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
857 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
858 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
863 return $self->provision_raw_step2($ctx, $ret);
866 sub provision_member($$$)
868 my ($self, $prefix, $dcvars) = @_;
869 print "PROVISIONING MEMBER...";
871 my $ret = $self->provision($prefix,
872 "member server",
873 "localmember",
874 "member3",
875 "SAMBADOMAIN",
876 "samba.example.com",
877 "2008",
879 "locMEMpass3",
880 $dcvars->{SERVER_IP},
881 "");
882 unless ($ret) {
883 return undef;
886 my $samba_tool = $self->bindir_path("samba-tool");
887 my $cmd = "";
888 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
889 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
890 $cmd .= "$samba_tool join $ret->{CONFIGURATION} $dcvars->{REALM} member";
891 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
893 unless (system($cmd) == 0) {
894 warn("Join failed\n$cmd");
895 return undef;
898 $ret->{MEMBER_SERVER} = $ret->{SERVER};
899 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
900 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
901 $ret->{MEMBER_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
902 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
903 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
905 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
906 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
907 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
908 $ret->{DC_NETBIOSALIAS} = $dcvars->{DC_NETBIOSALIAS};
909 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
910 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
912 return $ret;
915 sub provision_rpc_proxy($$$)
917 my ($self, $prefix, $dcvars) = @_;
918 print "PROVISIONING RPC PROXY...";
920 my $extra_smbconf_options = "dcerpc_remote:binding = ncacn_ip_tcp:localdc
921 dcerpc endpoint servers = epmapper, remote
922 dcerpc_remote:interfaces = rpcecho
925 my $ret = $self->provision($prefix,
926 "member server",
927 "localrpcproxy",
928 "rpcproxy4",
929 "SAMBADOMAIN",
930 "samba.example.com",
931 "2008",
933 "locRPCproxypass4",
934 $dcvars->{SERVER_IP},
935 $extra_smbconf_options);
937 unless ($ret) {
938 return undef;
941 my $samba_tool = $self->bindir_path("samba-tool");
942 my $cmd = "";
943 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
944 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
945 $cmd .= "$samba_tool join $ret->{CONFIGURATION} $dcvars->{REALM} member";
946 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
948 unless (system($cmd) == 0) {
949 warn("Join failed\n$cmd");
950 return undef;
953 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
954 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
955 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
956 $ret->{RPC_PROXY_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
957 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
958 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
960 return $ret;
963 sub provision_vampire_dc($$$)
965 my ($self, $prefix, $dcvars) = @_;
966 print "PROVISIONING VAMPIRE DC...";
968 # We do this so that we don't run the provision. That's the job of 'net vampire'.
969 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
970 "localvampiredc",
971 "dc2",
972 "SAMBADOMAIN",
973 "samba.example.com",
974 "2008",
975 2, $dcvars->{PASSWORD},
976 $dcvars->{SERVER_IP});
978 $ctx->{smb_conf_extra_options} = "
979 max xmit = 32K
980 server max protocol = SMB2
982 [sysvol]
983 path = $ctx->{lockdir}/sysvol
984 read only = yes
986 [netlogon]
987 path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
988 read only = no
992 my $ret = $self->provision_raw_step1($ctx);
993 unless ($ret) {
994 return undef;
997 my $samba_tool = $self->bindir_path("samba-tool");
998 my $cmd = "";
999 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1000 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1001 $cmd .= "$samba_tool join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1002 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1004 unless (system($cmd) == 0) {
1005 warn("Join failed\n$cmd");
1006 return undef;
1009 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1010 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1011 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1012 $ret->{VAMPIRE_DC_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
1014 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1015 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1016 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1017 $ret->{DC_NETBIOSALIAS} = $dcvars->{DC_NETBIOSALIAS};
1018 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1019 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1021 return $ret;
1024 sub provision_dc($$)
1026 my ($self, $prefix) = @_;
1028 print "PROVISIONING DC...";
1029 my $ret = $self->provision($prefix,
1030 "domain controller",
1031 "localdc",
1032 "dc1",
1033 "SAMBADOMAIN",
1034 "samba.example.com",
1035 "2008",
1037 "locDCpass1",
1038 "127.0.0.1", "");
1040 return undef unless(defined $ret);
1041 unless($self->add_wins_config("$prefix/private")) {
1042 warn("Unable to add wins configuration");
1043 return undef;
1046 $ret->{DC_SERVER} = $ret->{SERVER};
1047 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1048 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1049 $ret->{DC_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
1050 $ret->{DC_USERNAME} = $ret->{USERNAME};
1051 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1053 return $ret;
1056 sub provision_fl2000dc($$)
1058 my ($self, $prefix) = @_;
1060 print "PROVISIONING DC...";
1061 my $ret = $self->provision($prefix,
1062 "domain controller",
1063 "dc5",
1064 "localfl2000dc",
1065 "SAMBA2000",
1066 "samba2000.example.com",
1067 "2000",
1069 "locDCpass5",
1070 "127.0.0.5", "");
1072 unless($self->add_wins_config("$prefix/private")) {
1073 warn("Unable to add wins configuration");
1074 return undef;
1077 return $ret;
1080 sub provision_fl2003dc($$)
1082 my ($self, $prefix) = @_;
1084 print "PROVISIONING DC...";
1085 my $ret = $self->provision($prefix,
1086 "domain controller",
1087 "dc6",
1088 "localfl2003dc",
1089 "SAMBA2003",
1090 "samba2003.example.com",
1091 "2003",
1093 "locDCpass6",
1094 "127.0.0.6", "");
1096 unless($self->add_wins_config("$prefix/private")) {
1097 warn("Unable to add wins configuration");
1098 return undef;
1101 return $ret;
1104 sub provision_fl2008r2dc($$)
1106 my ($self, $prefix) = @_;
1108 print "PROVISIONING DC...";
1109 my $ret = $self->provision($prefix,
1110 "domain controller",
1111 "dc7",
1112 "localfl2000r2dc",
1113 "SAMBA2008R2",
1114 "samba2008R2.example.com",
1115 "2008_R2",
1117 "locDCpass7",
1118 "127.0.0.7", "");
1120 unless ($self->add_wins_config("$prefix/private")) {
1121 warn("Unable to add wins configuration");
1122 return undef;
1125 return $ret;
1129 sub provision_rodc($$$)
1131 my ($self, $prefix, $dcvars) = @_;
1132 print "PROVISIONING RODC...";
1134 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1135 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1136 "rodc",
1137 "dc8",
1138 "SAMBADOMAIN",
1139 "samba.example.com",
1140 "2008",
1141 8, $dcvars->{PASSWORD},
1142 $dcvars->{SERVER_IP});
1143 unless ($ctx) {
1144 return undef;
1147 $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
1148 push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
1150 $ctx->{smb_conf_extra_options} = "
1151 max xmit = 32K
1152 server max protocol = SMB2
1154 [sysvol]
1155 path = $ctx->{lockdir}/sysvol
1156 read only = yes
1158 [netlogon]
1159 path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
1160 read only = yes
1162 [tmp]
1163 path = $ctx->{tmpdir}
1164 read only = no
1165 posix:sharedelay = 10000
1166 posix:oplocktimeout = 3
1167 posix:writetimeupdatedelay = 500000
1171 my $ret = $self->provision_raw_step1($ctx);
1172 unless ($ret) {
1173 return undef;
1176 my $samba_tool = $self->bindir_path("samba-tool");
1177 my $cmd = "";
1178 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1179 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1180 $cmd .= "$samba_tool join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1181 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1182 $cmd .= " --server=$dcvars->{DC_SERVER}";
1184 unless (system($cmd) == 0) {
1185 warn("RODC join failed\n$cmd");
1186 return undef;
1189 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1190 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1191 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1192 $ret->{RODC_DC_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
1194 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1195 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1196 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1197 $ret->{DC_NETBIOSALIAS} = $dcvars->{DC_NETBIOSALIAS};
1198 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1199 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1201 return $ret;
1204 sub teardown_env($$)
1206 my ($self, $envvars) = @_;
1207 my $pid;
1209 close(DATA);
1211 if (open(IN, "<$envvars->{PIDDIR}/samba.pid")) {
1212 $pid = <IN>;
1213 close(IN);
1215 # Give the process 20 seconds to exit. gcov needs
1216 # this time to write out the covarge data
1217 my $count = 0;
1218 until (kill(0, $pid) == 0) {
1219 # if no process sucessfully signalled, then we are done
1220 sleep(1);
1221 $count++;
1222 last if $count > 20;
1225 # If it is still around, kill it
1226 if ($count > 20) {
1227 print "server process $pid took more than $count seconds to exit, killing\n";
1228 kill 9, $pid;
1232 my $failed = $? >> 8;
1234 $self->slapd_stop($envvars) if ($self->{ldap});
1236 print $self->getlog_env($envvars);
1238 return $failed;
1241 sub getlog_env($$)
1243 my ($self, $envvars) = @_;
1244 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
1245 my $out = $title;
1247 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1249 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1250 while (<LOG>) {
1251 $out .= $_;
1253 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1254 close(LOG);
1256 return "" if $out eq $title;
1258 return $out;
1261 sub check_env($$)
1263 my ($self, $envvars) = @_;
1265 return (-p $envvars->{SAMBA_TEST_FIFO});
1268 sub setup_env($$$)
1270 my ($self, $envname, $path) = @_;
1272 $ENV{ENVNAME} = $envname;
1274 if ($envname eq "dc") {
1275 return $self->setup_dc("$path/dc");
1276 } elsif ($envname eq "fl2000dc") {
1277 return $self->setup_fl2000dc("$path/fl2000dc");
1278 } elsif ($envname eq "fl2003dc") {
1279 return $self->setup_fl2003dc("$path/fl2003dc");
1280 } elsif ($envname eq "fl2008r2dc") {
1281 return $self->setup_fl2008r2dc("$path/fl2008r2dc");
1282 } elsif ($envname eq "rpc_proxy") {
1283 if (not defined($self->{vars}->{dc})) {
1284 $self->setup_dc("$path/dc");
1286 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1287 } elsif ($envname eq "vampire_dc") {
1288 if (not defined($self->{vars}->{dc})) {
1289 $self->setup_dc("$path/dc");
1291 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
1292 } elsif ($envname eq "member") {
1293 if (not defined($self->{vars}->{dc})) {
1294 $self->setup_dc("$path/dc");
1296 return $self->setup_member("$path/member", $self->{vars}->{dc});
1297 } elsif ($envname eq "rodc") {
1298 if (not defined($self->{vars}->{dc})) {
1299 $self->setup_dc("$path/dc");
1301 return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
1302 } elsif ($envname eq "all") {
1303 if (not defined($self->{vars}->{dc})) {
1304 $ENV{ENVNAME} = "dc";
1305 $self->setup_dc("$path/dc");
1307 my $ret = $self->setup_member("$path/member", $self->{vars}->{dc});
1308 if (not defined($self->{vars}->{rpc_proxy})) {
1309 $ENV{ENVNAME} = "rpc_proxy";
1310 my $rpc_proxy_ret = $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1312 $ret->{RPC_PROXY_SERVER} = $rpc_proxy_ret->{SERVER};
1313 $ret->{RPC_PROXY_SERVER_IP} = $rpc_proxy_ret->{SERVER_IP};
1314 $ret->{RPC_PROXY_NETBIOSNAME} = $rpc_proxy_ret->{NETBIOSNAME};
1315 $ret->{RPC_PROXY_NETBIOSALIAS} = $rpc_proxy_ret->{NETBIOSALIAS};
1316 $ret->{RPC_PROXY_USERNAME} = $rpc_proxy_ret->{USERNAME};
1317 $ret->{RPC_PROXY_PASSWORD} = $rpc_proxy_ret->{PASSWORD};
1319 if (not defined($self->{vars}->{fl2000dc})) {
1320 $ENV{ENVNAME} = "fl2000dc";
1321 my $fl2000dc_ret = $self->setup_fl2000dc("$path/fl2000dc", $self->{vars}->{dc});
1323 $ret->{FL2000DC_SERVER} = $fl2000dc_ret->{SERVER};
1324 $ret->{FL2000DC_SERVER_IP} = $fl2000dc_ret->{SERVER_IP};
1325 $ret->{FL2000DC_NETBIOSNAME} = $fl2000dc_ret->{NETBIOSNAME};
1326 $ret->{FL2000DC_NETBIOSALIAS} = $fl2000dc_ret->{NETBIOSALIAS};
1327 $ret->{FL2000DC_USERNAME} = $fl2000dc_ret->{USERNAME};
1328 $ret->{FL2000DC_PASSWORD} = $fl2000dc_ret->{PASSWORD};
1330 if (not defined($self->{vars}->{fl2003dc})) {
1331 $ENV{ENVNAME} = "fl2003dc";
1332 my $fl2003dc_ret = $self->setup_fl2003dc("$path/fl2003dc", $self->{vars}->{dc});
1334 $ret->{FL2003DC_SERVER} = $fl2003dc_ret->{SERVER};
1335 $ret->{FL2003DC_SERVER_IP} = $fl2003dc_ret->{SERVER_IP};
1336 $ret->{FL2003DC_NETBIOSNAME} = $fl2003dc_ret->{NETBIOSNAME};
1337 $ret->{FL2003DC_NETBIOSALIAS} = $fl2003dc_ret->{NETBIOSALIAS};
1338 $ret->{FL2003DC_USERNAME} = $fl2003dc_ret->{USERNAME};
1339 $ret->{FL2003DC_PASSWORD} = $fl2003dc_ret->{PASSWORD};
1341 if (not defined($self->{vars}->{fl2008r2dc})) {
1342 $ENV{ENVNAME} = "fl2008r2dc";
1343 my $fl2008r2dc_ret = $self->setup_fl2008r2dc("$path/fl2008r2dc", $self->{vars}->{dc});
1345 $ret->{FL2008R2DC_SERVER} = $fl2008r2dc_ret->{SERVER};
1346 $ret->{FL2008R2DC_SERVER_IP} = $fl2008r2dc_ret->{SERVER_IP};
1347 $ret->{FL2008R2DC_NETBIOSNAME} = $fl2008r2dc_ret->{NETBIOSNAME};
1348 $ret->{FL2008R2DC_NETBIOSALIAS} = $fl2008r2dc_ret->{NETBIOSALIAS};
1349 $ret->{FL2008R2DC_USERNAME} = $fl2008r2dc_ret->{USERNAME};
1350 $ret->{FL2008R2DC_PASSWORD} = $fl2008r2dc_ret->{PASSWORD};
1352 return $ret;
1353 } else {
1354 warn("Samba4 can't provide environment '$envname'");
1355 return undef;
1359 sub setup_member($$$)
1361 my ($self, $path, $dc_vars) = @_;
1363 my $env = $self->provision_member($path, $dc_vars);
1365 if (defined $env) {
1366 $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
1368 $self->wait_for_start($env);
1370 $self->{vars}->{member} = $env;
1373 return $env;
1376 sub setup_rpc_proxy($$$)
1378 my ($self, $path, $dc_vars) = @_;
1380 my $env = $self->provision_rpc_proxy($path, $dc_vars);
1382 if (defined $env) {
1383 $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
1385 $self->wait_for_start($env);
1387 $self->{vars}->{rpc_proxy} = $env;
1389 return $env;
1392 sub setup_dc($$)
1394 my ($self, $path) = @_;
1396 my $env = $self->provision_dc($path);
1397 if (defined $env) {
1398 $self->check_or_start($env,
1399 ($ENV{SMBD_MAXTIME} or 7500));
1401 $self->wait_for_start($env);
1403 $self->{vars}->{dc} = $env;
1405 return $env;
1408 sub setup_fl2000dc($$)
1410 my ($self, $path) = @_;
1412 my $env = $self->provision_fl2000dc($path);
1413 if (defined $env) {
1414 $self->check_or_start($env,
1415 ($ENV{SMBD_MAXTIME} or 7500));
1417 $self->wait_for_start($env);
1419 $self->{vars}->{fl2000dc} = $env;
1422 return $env;
1425 sub setup_fl2003dc($$)
1427 my ($self, $path) = @_;
1429 my $env = $self->provision_fl2003dc($path);
1431 if (defined $env) {
1432 $self->check_or_start($env,
1433 ($ENV{SMBD_MAXTIME} or 7500));
1435 $self->wait_for_start($env);
1437 $self->{vars}->{fl2003dc} = $env;
1439 return $env;
1442 sub setup_fl2008r2dc($$)
1444 my ($self, $path) = @_;
1446 my $env = $self->provision_fl2008r2dc($path);
1448 if (defined $env) {
1449 $self->check_or_start($env,
1450 ($ENV{SMBD_MAXTIME} or 7500));
1452 $self->wait_for_start($env);
1454 $self->{vars}->{fl2008r2dc} = $env;
1457 return $env;
1460 sub setup_vampire_dc($$$)
1462 my ($self, $path, $dc_vars) = @_;
1464 my $env = $self->provision_vampire_dc($path, $dc_vars);
1466 if (defined $env) {
1467 $self->check_or_start($env,
1468 ($ENV{SMBD_MAXTIME} or 7500));
1470 $self->wait_for_start($env);
1472 $self->{vars}->{vampire_dc} = $env;
1474 # force replicated DC to update repsTo/repsFrom
1475 # for vampired partitions
1476 my $samba_tool = $self->bindir_path("samba-tool");
1477 my $cmd = "";
1478 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1479 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1480 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
1481 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1482 unless (system($cmd) == 0) {
1483 warn("Failed to exec kcc\n$cmd");
1484 return undef;
1487 # as 'vampired' dc may add data in its local replica
1488 # we need to synchronize data between DCs
1489 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
1490 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
1491 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
1492 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{VAMPIRE_DC_SERVER}";
1493 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
1494 # replicate Configuration NC
1495 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
1496 unless(system($cmd_repl) == 0) {
1497 warn("Failed to replicate\n$cmd_repl");
1498 return undef;
1500 # replicate Default NC
1501 $cmd_repl = "$cmd \"$base_dn\"";
1502 unless(system($cmd_repl) == 0) {
1503 warn("Failed to replicate\n$cmd_repl");
1504 return undef;
1508 return $env;
1511 sub setup_rodc($$$)
1513 my ($self, $path, $dc_vars) = @_;
1515 my $env = $self->provision_rodc($path, $dc_vars);
1517 unless ($env) {
1518 return undef;
1521 $self->check_or_start($env,
1522 ($ENV{SMBD_MAXTIME} or 7500));
1524 $self->wait_for_start($env);
1526 $self->{vars}->{rodc} = $env;
1528 return $env;