s3-waf: fix the the waf build.
[Samba.git] / selftest / target / Samba4.pm
blobe82ccfdfab264d0aeff95d8bc47cc845a746199b
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;
13 sub new($$$$$) {
14 my ($classname, $bindir, $ldap, $setupdir, $exeext) = @_;
15 $exeext = "" unless defined($exeext);
16 my $self = {
17 vars => {},
18 ldap => $ldap,
19 bindir => $bindir,
20 setupdir => $setupdir,
21 exeext => $exeext
23 bless $self;
24 return $self;
27 sub bindir_path($$) {
28 my ($self, $path) = @_;
30 return "$self->{bindir}/$path$self->{exeext}";
33 sub openldap_start($$$) {
36 sub slapd_start($$)
38 my $count = 0;
39 my ($self, $env_vars) = @_;
40 my $ldbsearch = $self->bindir_path("ldbsearch");
42 my $uri = $env_vars->{LDAP_URI};
44 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
45 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
46 return 1;
48 # running slapd in the background means it stays in the same process group, so it can be
49 # killed by timelimit
50 if ($self->{ldap} eq "fedora-ds") {
51 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 &");
52 } elsif ($self->{ldap} eq "openldap") {
53 system("$ENV{OPENLDAP_SLAPD} -d0 -F $env_vars->{SLAPD_CONF_D} -h $uri > $env_vars->{LDAPDIR}/logs 2>&1 &");
55 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
56 $count++;
57 if ($count > 40) {
58 $self->slapd_stop($env_vars);
59 return 0;
61 sleep(1);
63 return 1;
66 sub slapd_stop($$)
68 my ($self, $envvars) = @_;
69 if ($self->{ldap} eq "fedora-ds") {
70 system("$envvars->{LDAPDIR}/slapd-$envvars->{LDAP_INSTANCE}/stop-slapd");
71 } elsif ($self->{ldap} eq "openldap") {
72 open(IN, "<$envvars->{OPENLDAP_PIDFILE}") or
73 die("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
74 kill 9, <IN>;
75 close(IN);
77 return 1;
80 sub check_or_start($$$)
82 my ($self, $env_vars, $max_time) = @_;
83 return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
85 unlink($env_vars->{SAMBA_TEST_FIFO});
86 POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
87 unlink($env_vars->{SAMBA_TEST_LOG});
89 print "STARTING SAMBA... ";
90 my $pid = fork();
91 if ($pid == 0) {
92 open STDIN, $env_vars->{SAMBA_TEST_FIFO};
93 # we want out from samba to go to the log file, but also
94 # to the users terminal when running 'make test' on the command
95 # line. This puts it on stderr on the terminal
96 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
97 open STDERR, '>&STDOUT';
99 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
101 my $valgrind = "";
102 if (defined($ENV{SAMBA_VALGRIND})) {
103 $valgrind = $ENV{SAMBA_VALGRIND};
106 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
107 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
109 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
110 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
112 $ENV{UID_WRAPPER} = "1";
114 # Start slapd before samba, but with the fifo on stdin
115 if (defined($self->{ldap})) {
116 $self->slapd_start($env_vars) or
117 die("couldn't start slapd (main run)");
120 my $optarg = "";
121 if (defined($max_time)) {
122 $optarg = "--maximum-runtime=$max_time ";
124 if (defined($ENV{SAMBA_OPTIONS})) {
125 $optarg.= " $ENV{SAMBA_OPTIONS}";
127 my $samba = $self->bindir_path("samba");
129 # allow selection of the process model using
130 # the environment varibale SAMBA_PROCESS_MODEL
131 # that allows us to change the process model for
132 # individual machines in the build farm
133 my $model = "single";
134 if (defined($ENV{SAMBA_PROCESS_MODEL})) {
135 $model = $ENV{SAMBA_PROCESS_MODEL};
137 my $ret = system("$valgrind $samba $optarg $env_vars->{CONFIGURATION} -M $model -i");
138 if ($? == -1) {
139 print "Unable to start $samba: $ret: $!\n";
140 exit 1;
142 unlink($env_vars->{SAMBA_TEST_FIFO});
143 my $exit = $? >> 8;
144 if ( $ret == 0 ) {
145 print "$samba exits with status $exit\n";
146 } elsif ( $ret & 127 ) {
147 print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
148 } else {
149 $ret = $? >> 8;
150 print "$samba failed with status $exit!\n";
152 exit $exit;
154 print "DONE\n";
156 open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
158 return $pid;
161 sub wait_for_start($$)
163 my ($self, $testenv_vars) = @_;
164 # give time for nbt server to register its names
165 print "delaying for nbt name registration\n";
166 sleep 2;
168 # This will return quickly when things are up, but be slow if we
169 # need to wait for (eg) SSL init
170 my $nmblookup = $self->bindir_path("nmblookup");
171 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
172 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
173 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
174 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
175 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
176 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
177 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
178 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
179 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
180 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
181 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}");
182 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
184 print $self->getlog_env($testenv_vars);
187 sub write_ldb_file($$$)
189 my ($self, $file, $ldif) = @_;
191 my $ldbadd = $self->bindir_path("ldbadd");
192 open(LDIF, "|$ldbadd -H $file >/dev/null");
193 print LDIF $ldif;
194 return close(LDIF);
197 sub add_wins_config($$)
199 my ($self, $privatedir) = @_;
201 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
202 dn: name=TORTURE_6,CN=PARTNERS
203 objectClass: wreplPartner
204 name: TORTURE_6
205 address: 127.0.0.6
206 pullInterval: 0
207 pushChangeCount: 0
208 type: 0x3
212 sub mk_fedora_ds($$)
214 my ($self, $ctx) = @_;
216 #Make the subdirectory be as fedora DS would expect
217 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
219 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
221 return ($fedora_ds_dir, $pidfile);
224 sub mk_openldap($$)
226 my ($self, $ctx) = @_;
228 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
229 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
231 return ($slapd_conf_d, $pidfile);
234 sub mk_keyblobs($$)
236 my ($self, $tlsdir) = @_;
238 #TLS and PKINIT crypto blobs
239 my $dhfile = "$tlsdir/dhparms.pem";
240 my $cafile = "$tlsdir/ca.pem";
241 my $certfile = "$tlsdir/cert.pem";
242 my $reqkdc = "$tlsdir/req-kdc.der";
243 my $kdccertfile = "$tlsdir/kdc.pem";
244 my $keyfile = "$tlsdir/key.pem";
245 my $adminkeyfile = "$tlsdir/adminkey.pem";
246 my $reqadmin = "$tlsdir/req-admin.der";
247 my $admincertfile = "$tlsdir/admincert.pem";
248 my $admincertupnfile = "$tlsdir/admincertupn.pem";
250 mkdir($tlsdir, 0777);
252 #This is specified here to avoid draining entropy on every run
253 open(DHFILE, ">$dhfile");
254 print DHFILE <<EOF;
255 -----BEGIN DH PARAMETERS-----
256 MGYCYQC/eWD2xkb7uELmqLi+ygPMKyVcpHUo2yCluwnbPutEueuxrG/Cys8j8wLO
257 svCN/jYNyR2NszOmg7ZWcOC/4z/4pWDVPUZr8qrkhj5MRKJc52MncfaDglvEdJrv
258 YX70obsCAQI=
259 -----END DH PARAMETERS-----
261 close(DHFILE);
263 #Likewise, we pregenerate the key material. This allows the
264 #other certificates to be pre-generated
265 open(KEYFILE, ">$keyfile");
266 print KEYFILE <<EOF;
267 -----BEGIN RSA PRIVATE KEY-----
268 MIICXQIBAAKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpc
269 ol3+S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H
270 6H+pPqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQAB
271 AoGAAqDLzFRR/BF1kpsiUfL4WFvTarCe9duhwj7ORc6fs785qAXuwUYAJ0Uvzmy6
272 HqoGv3t3RfmeHDmjcpPHsbOKnsOQn2MgmthidQlPBMWtQMff5zdoYNUFiPS0XQBq
273 szNW4PRjaA9KkLQVTwnzdXGkBSkn/nGxkaVu7OR3vJOBoo0CQQDO4upypesnbe6p
274 9/xqfZ2uim8IwV1fLlFClV7WlCaER8tsQF4lEi0XSzRdXGUD/dilpY88Nb+xok/X
275 8Z8OvgAXAkEA+pcLsx1gN7kxnARxv54jdzQjC31uesJgMKQXjJ0h75aUZwTNHmZQ
276 vPxi6u62YiObrN5oivkixwFNncT9MxTxVQJBAMaWUm2SjlLe10UX4Zdm1MEB6OsC
277 kVoX37CGKO7YbtBzCfTzJGt5Mwc1DSLA2cYnGJqIfSFShptALlwedot0HikCQAJu
278 jNKEKnbf+TdGY8Q0SKvTebOW2Aeg80YFkaTvsXCdyXrmdQcifw4WdO9KucJiDhSz
279 Y9hVapz7ykEJtFtWjLECQQDIlfc63I5ZpXfg4/nN4IJXUW6AmPVOYIA5215itgki
280 cSlMYli1H9MEXH0pQMGv5Qyd0OYIx2DDg96mZ+aFvqSG
281 -----END RSA PRIVATE KEY-----
283 close(KEYFILE);
285 open(ADMINKEYFILE, ">$adminkeyfile");
287 print ADMINKEYFILE <<EOF;
288 -----BEGIN RSA PRIVATE KEY-----
289 MIICXQIBAAKBgQD0+OL7TQBj0RejbIH1+g5GeRaWaM9xF43uE5y7jUHEsi5owhZF
290 5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMFxB6esnXhl0Jpip1JkUMM
291 XLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xdl3JRlwIDAQAB
292 AoGAP8mjCP628Ebc2eACQzOWjgEvwYCPK4qPmYOf1zJkArzG2t5XAGJ5WGrENRuB
293 cm3XFh1lpmaADl982UdW3gul4gXUy6w4XjKK4vVfhyHj0kZ/LgaXUK9BAGhroJ2L
294 osIOUsaC6jdx9EwSRctwdlF3wWJ8NK0g28AkvIk+FlolW4ECQQD7w5ouCDnf58CN
295 u4nARx4xv5XJXekBvOomkCQAmuOsdOb6b9wn3mm2E3au9fueITjb3soMR31AF6O4
296 eAY126rXAkEA+RgHzybzZEP8jCuznMqoN2fq/Vrs6+W3M8/G9mzGEMgLLpaf2Jiz
297 I9tLZ0+OFk9tkRaoCHPfUOCrVWJZ7Y53QQJBAMhoA6rw0WDyUcyApD5yXg6rusf4
298 ASpo/tqDkqUIpoL464Qe1tjFqtBM3gSXuhs9xsz+o0bzATirmJ+WqxrkKTECQHt2
299 OLCpKqwAspU7N+w32kaUADoRLisCEdrhWklbwpQgwsIVsCaoEOpt0CLloJRYTANE
300 yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
301 +cfgNl57YHMTZFwgUVFRdJNpjH/WdZ5QxDcIVli0q+Ko
302 -----END RSA PRIVATE KEY-----
305 #generated with
306 # hxtool issue-certificate --self-signed --issue-ca \
307 # --ca-private-key="FILE:$KEYFILE" \
308 # --subject="CN=CA,DC=samba,DC=example,DC=com" \
309 # --certificate="FILE:$CAFILE" --lifetime="25 years"
311 open(CAFILE, ">$cafile");
312 print CAFILE <<EOF;
313 -----BEGIN CERTIFICATE-----
314 MIICcTCCAdqgAwIBAgIUaBPmjnPVqyFqR5foICmLmikJTzgwCwYJKoZIhvcNAQEFMFIxEzAR
315 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
316 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTIyMzEyWhgPMjAzMzAyMjQx
317 MjIzMTJaMFIxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
318 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMIGfMA0GCSqGSIb3DQEBAQUA
319 A4GNADCBiQKBgQDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+S9/6
320 I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+pPqVIRLOmrWIm
321 ai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABo0IwQDAOBgNVHQ8BAf8EBAMC
322 AaYwHQYDVR0OBBYEFMLZufegDKLZs0VOyFXYK1L6M8oyMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
323 KoZIhvcNAQEFBQADgYEAAZJbCAAkaqgFJ0xgNovn8Ydd0KswQPjicwiODPgw9ZPoD2HiOUVO
324 yYDRg/dhFF9y656OpcHk4N7qZ2sl3RlHkzDu+dseETW+CnKvQIoXNyeARRJSsSlwrwcoD4JR
325 HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
326 -----END CERTIFICATE-----
329 #generated with GNUTLS internally in Samba.
331 open(CERTFILE, ">$certfile");
332 print CERTFILE <<EOF;
333 -----BEGIN CERTIFICATE-----
334 MIICYTCCAcygAwIBAgIE5M7SRDALBgkqhkiG9w0BAQUwZTEdMBsGA1UEChMUU2Ft
335 YmEgQWRtaW5pc3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1
336 dG9nZW5lcmF0ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMB4XDTA2MDgw
337 NDA0MzY1MloXDTA4MDcwNDA0MzY1MlowZTEdMBsGA1UEChMUU2FtYmEgQWRtaW5p
338 c3RyYXRpb24xNDAyBgNVBAsTK1NhbWJhIC0gdGVtcG9yYXJ5IGF1dG9nZW5lcmF0
339 ZWQgY2VydGlmaWNhdGUxDjAMBgNVBAMTBVNhbWJhMIGcMAsGCSqGSIb3DQEBAQOB
340 jAAwgYgCgYDKg6pAwCHUMA1DfHDmWhZfd+F0C+9Jxcqvpw9ii9En3E1uflpcol3+
341 S9/6I/uaTmJHZre+DF3dTzb/UOZo0Zem8N+IzzkgoGkFafjXuT3BL5UPY2/H6H+p
342 PqVIRLOmrWImai359YyoKhFyo37Y6HPeU8QcZ+u2rS9geapIWfeuowIDAQABoyUw
343 IzAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAsGCSqGSIb3DQEB
344 BQOBgQAmkN6XxvDnoMkGcWLCTwzxGfNNSVcYr7TtL2aJh285Xw9zaxcm/SAZBFyG
345 LYOChvh6hPU7joMdDwGfbiLrBnMag+BtGlmPLWwp/Kt1wNmrRhduyTQFhN3PP6fz
346 nBr9vVny2FewB2gHmelaPS//tXdxivSXKz3NFqqXLDJjq7P8wA==
347 -----END CERTIFICATE-----
349 close(CERTFILE);
351 #KDC certificate
352 # hxtool request-create \
353 # --subject="CN=krbtgt,CN=users,DC=samba,DC=example,DC=com" \
354 # --key="FILE:$KEYFILE" $KDCREQ
356 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
357 # --type="pkinit-kdc" \
358 # --pk-init-principal="krbtgt/SAMBA.EXAMPLE.COM@SAMBA.EXAMPLE.COM" \
359 # --req="PKCS10:$KDCREQ" --certificate="FILE:$KDCCERTFILE" \
360 # --lifetime="25 years"
362 open(KDCCERTFILE, ">$kdccertfile");
363 print KDCCERTFILE <<EOF;
364 -----BEGIN CERTIFICATE-----
365 MIIDDDCCAnWgAwIBAgIUI2Tzj+JnMzMcdeabcNo30rovzFAwCwYJKoZIhvcNAQEFMFIxEzAR
366 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
367 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDgwMzAxMTMxOTIzWhgPMjAzMzAyMjQx
368 MzE5MjNaMGYxEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
369 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMQ8wDQYDVQQDDAZrcmJ0
370 Z3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMqDqkDAIdQwDUN8cOZaFl934XQL70nF
371 yq+nD2KL0SfcTW5+WlyiXf5L3/oj+5pOYkdmt74MXd1PNv9Q5mjRl6bw34jPOSCgaQVp+Ne5
372 PcEvlQ9jb8fof6k+pUhEs6atYiZqLfn1jKgqEXKjftjoc95TxBxn67atL2B5qkhZ966jAgMB
373 AAGjgcgwgcUwDgYDVR0PAQH/BAQDAgWgMBIGA1UdJQQLMAkGBysGAQUCAwUwVAYDVR0RBE0w
374 S6BJBgYrBgEFAgKgPzA9oBMbEVNBTUJBLkVYQU1QTEUuQ09NoSYwJKADAgEBoR0wGxsGa3Ji
375 dGd0GxFTQU1CQS5FWEFNUExFLkNPTTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS+jPK
376 MjAdBgNVHQ4EFgQUwtm596AMotmzRU7IVdgrUvozyjIwCQYDVR0TBAIwADANBgkqhkiG9w0B
377 AQUFAAOBgQBmrVD5MCmZjfHp1nEnHqTIh8r7lSmVtDx4s9MMjxm9oNrzbKXynvdhwQYFVarc
378 ge4yRRDXtSebErOl71zVJI9CVeQQpwcH+tA85oGA7oeFtO/S7ls581RUU6tGgyxV4veD+lJv
379 KPH5LevUtgD+q9H4LU4Sq5N3iFwBaeryB0g2wg==
380 -----END CERTIFICATE-----
383 # hxtool request-create \
384 # --subject="CN=Administrator,CN=users,DC=samba,DC=example,DC=com" \
385 # --key="FILE:$ADMINKEYFILE" $ADMINREQFILE
387 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
388 # --type="pkinit-client" \
389 # --pk-init-principal="administrator@SAMBA.EXAMPLE.COM" \
390 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTFILE" \
391 # --lifetime="25 years"
393 open(ADMINCERTFILE, ">$admincertfile");
394 print ADMINCERTFILE <<EOF;
395 -----BEGIN CERTIFICATE-----
396 MIIDHTCCAoagAwIBAgIUUggzW4lLRkMKe1DAR2NKatkMDYwwCwYJKoZIhvcNAQELMFIxEzAR
397 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
398 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMjE1WhgPMjAzNDA3MjIw
399 MzMyMTVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
400 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
401 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
402 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
403 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
404 l3JRlwIDAQABo4HSMIHPMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
405 BgEFBQcDAgYKKwYBBAGCNxQCAjBIBgNVHREEQTA/oD0GBisGAQUCAqAzMDGgExsRU0FNQkEu
406 RVhBTVBMRS5DT02hGjAYoAMCAQGhETAPGw1BZG1pbmlzdHJhdG9yMB8GA1UdIwQYMBaAFMLZ
407 ufegDKLZs0VOyFXYK1L6M8oyMB0GA1UdDgQWBBQg81bLyfCA88C2B/BDjXlGuaFaxjAJBgNV
408 HRMEAjAAMA0GCSqGSIb3DQEBCwUAA4GBAEf/OSHUDJaGdtWGNuJeqcVYVMwrfBAc0OSwVhz1
409 7/xqKHWo8wIMPkYRtaRHKLNDsF8GkhQPCpVsa6mX/Nt7YQnNvwd+1SBP5E8GvwWw9ZzLJvma
410 nk2n89emuayLpVtp00PymrDLRBcNaRjFReQU8f0o509kiVPHduAp3jOiy13l
411 -----END CERTIFICATE-----
413 close(ADMINCERTFILE);
415 # hxtool issue-certificate --ca-certificate=FILE:$CAFILE,$KEYFILE \
416 # --type="pkinit-client" \
417 # --ms-upn="administrator@samba.example.com" \
418 # --req="PKCS10:$ADMINREQFILE" --certificate="FILE:$ADMINCERTUPNFILE" \
419 # --lifetime="25 years"
421 open(ADMINCERTUPNFILE, ">$admincertupnfile");
422 print ADMINCERTUPNFILE <<EOF;
423 -----BEGIN CERTIFICATE-----
424 MIIDDzCCAnigAwIBAgIUUp3CJMuNaEaAdPKp3QdNIwG7a4wwCwYJKoZIhvcNAQELMFIxEzAR
425 BgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxlMRUwEwYKCZImiZPy
426 LGQBGQwFc2FtYmExCzAJBgNVBAMMAkNBMCIYDzIwMDkwNzI3MDMzMzA1WhgPMjAzNDA3MjIw
427 MzMzMDVaMG0xEzARBgoJkiaJk/IsZAEZDANjb20xFzAVBgoJkiaJk/IsZAEZDAdleGFtcGxl
428 MRUwEwYKCZImiZPyLGQBGQwFc2FtYmExDjAMBgNVBAMMBXVzZXJzMRYwFAYDVQQDDA1BZG1p
429 bmlzdHJhdG9yMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQD0+OL7TQBj0RejbIH1+g5G
430 eRaWaM9xF43uE5y7jUHEsi5owhZF5iIoHZeeL6cpDF5y1BZRs0JlA1VqMry1jjKlzFYVEMMF
431 xB6esnXhl0Jpip1JkUMMXLOP1m/0dqayuHBWozj9f/cdyCJr0wJIX1Z8Pr+EjYRGPn/MF0xd
432 l3JRlwIDAQABo4HEMIHBMA4GA1UdDwEB/wQEAwIFoDAoBgNVHSUEITAfBgcrBgEFAgMEBggr
433 BgEFBQcDAgYKKwYBBAGCNxQCAjA6BgNVHREEMzAxoC8GCisGAQQBgjcUAgOgIQwfYWRtaW5p
434 c3RyYXRvckBzYW1iYS5leGFtcGxlLmNvbTAfBgNVHSMEGDAWgBTC2bn3oAyi2bNFTshV2CtS
435 +jPKMjAdBgNVHQ4EFgQUIPNWy8nwgPPAtgfwQ415RrmhWsYwCQYDVR0TBAIwADANBgkqhkiG
436 9w0BAQsFAAOBgQBk42+egeUB3Ji2PC55fbt3FNKxvmm2xUUFkV9POK/YR9rajKOwk5jtYSeS
437 Zd7J9s//rNFNa7waklFkDaY56+QWTFtdvxfE+KoHaqt6X8u6pqi7p3M4wDKQox+9Dx8yWFyq
438 Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
439 -----END CERTIFICATE-----
444 # provision_raw_prepare() is also used by Samba34.pm!
446 sub provision_raw_prepare($$$$$$$)
448 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password, $kdc_ipv4) = @_;
449 my $ctx;
451 -d $prefix or mkdir($prefix, 0777) or die("Unable to create $prefix");
452 my $prefix_abs = abs_path($prefix);
454 die ("prefix=''") if $prefix_abs eq "";
455 die ("prefix='/'") if $prefix_abs eq "/";
457 (system("rm -rf $prefix_abs/*") == 0) or die("Unable to clean up");
459 $ctx->{prefix} = $prefix;
460 $ctx->{prefix_abs} = $prefix_abs;
462 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
464 $ctx->{server_role} = $server_role;
465 $ctx->{netbiosname} = $netbiosname;
466 $ctx->{netbiosalias} = $netbiosalias;
467 $ctx->{swiface} = $swiface;
468 $ctx->{password} = $password;
469 $ctx->{kdc_ipv4} = $kdc_ipv4;
471 $ctx->{server_loglevel} = 1;
472 $ctx->{username} = "Administrator";
473 $ctx->{domain} = "SAMBADOMAIN";
474 $ctx->{realm} = "SAMBA.EXAMPLE.COM";
475 $ctx->{dnsname} = "samba.example.com";
476 $ctx->{basedn} = "dc=samba,dc=example,dc=com";
477 $ctx->{sid_generator} = "internal";
479 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
480 chomp $unix_name;
481 $ctx->{unix_name} = $unix_name;
482 $ctx->{unix_uid} = $>;
483 $ctx->{unix_gids_str} = $);
484 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
486 $ctx->{etcdir} = "$prefix_abs/etc";
487 $ctx->{piddir} = "$prefix_abs/pid";
488 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
489 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
490 $ctx->{privatedir} = "$prefix_abs/private";
491 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
492 $ctx->{lockdir} = "$prefix_abs/lockdir";
493 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
494 $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
495 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
496 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
497 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
499 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
501 $ctx->{ipv4} = "127.0.0.$swiface";
502 $ctx->{interfaces} = "$ctx->{ipv4}/8";
504 $ctx->{localbasedn} = $ctx->{basedn};
505 $ctx->{localbasedn} = "CN=$netbiosname" if $server_role eq "member server";
507 push(@{$ctx->{directories}}, $ctx->{privatedir});
508 push(@{$ctx->{directories}}, $ctx->{etcdir});
509 push(@{$ctx->{directories}}, $ctx->{piddir});
510 push(@{$ctx->{directories}}, $ctx->{ncalrpcdir});
511 push(@{$ctx->{directories}}, $ctx->{lockdir});
513 $ctx->{smb_conf_extra_options} = "";
515 my @provision_options = ();
516 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
517 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
518 if (defined($ENV{GDB_PROVISION})) {
519 push (@provision_options, "gdb --args");
521 if (defined($ENV{VALGRIND_PROVISION})) {
522 push (@provision_options, "valgrind");
524 if (defined($ENV{PYTHON})) {
525 push (@provision_options, $ENV{PYTHON});
527 push (@provision_options, "$self->{setupdir}/provision");
528 push (@provision_options, "--configfile=$ctx->{smb_conf}");
529 push (@provision_options, "--host-name=$ctx->{netbiosname}");
530 push (@provision_options, "--host-ip=$ctx->{ipv4}");
531 push (@provision_options, "--quiet");
532 push (@provision_options, "--domain=$ctx->{domain}");
533 push (@provision_options, "--realm=$ctx->{realm}");
534 push (@provision_options, "--adminpass=$ctx->{password}");
535 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
536 push (@provision_options, "--machinepass=machine$ctx->{password}");
537 push (@provision_options, "--root=$ctx->{unix_name}");
538 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
540 @{$ctx->{provision_options}} = @provision_options;
542 return $ctx;
546 # provision_raw_step1() is also used by Samba34.pm!
548 # Step1 creates the basic configuration
550 sub provision_raw_step1($$)
552 my ($self, $ctx) = @_;
554 mkdir($_, 0777) foreach (@{$ctx->{directories}});
556 open(CONFFILE, ">$ctx->{smb_conf}")
557 or die("can't open $ctx->{smb_conf}$?");
558 print CONFFILE "
559 [global]
560 netbios name = $ctx->{netbiosname}
561 netbios aliases = $ctx->{netbiosalias}
562 posix:eadb = $ctx->{lockdir}/eadb.tdb
563 workgroup = $ctx->{domain}
564 realm = $ctx->{realm}
565 private dir = $ctx->{privatedir}
566 pid directory = $ctx->{piddir}
567 ncalrpc dir = $ctx->{ncalrpcdir}
568 lock dir = $ctx->{lockdir}
569 setup directory = $self->{setupdir}
570 modules dir = $self->{bindir}/modules
571 winbindd socket directory = $ctx->{winbindd_socket_dir}
572 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
573 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
574 winbind separator = /
575 name resolve order = bcast file
576 interfaces = $ctx->{interfaces}
577 tls dh params file = $ctx->{tlsdir}/dhparms.pem
578 panic action = $RealBin/gdb_backtrace \%PID% \%PROG%
579 wins support = yes
580 server role = $ctx->{server_role}
581 notify:inotify = false
582 ldb:nosync = true
583 #We don't want to pass our self-tests if the PAC code is wrong
584 gensec:require_pac = true
585 log level = $ctx->{server_loglevel}
586 lanman auth = Yes
587 rndc command = true
588 dns update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file}
589 spn update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_spnupdate
590 resolv:host file = $ctx->{dns_host_file}
593 if (defined($ctx->{sid_generator}) && $ctx->{sid_generator} ne "internal") {
594 print CONFFILE "
595 sid generator = $ctx->{sid_generator}";
598 print CONFFILE "
600 # Begin extra options
601 $ctx->{smb_conf_extra_options}
602 # End extra options
604 close(CONFFILE);
606 $self->mk_keyblobs($ctx->{tlsdir});
608 open(KRB5CONF, ">$ctx->{krb5_conf}")
609 or die("can't open $ctx->{krb5_conf}$?");
610 print KRB5CONF "
611 #Generated krb5.conf for $ctx->{realm}
613 [libdefaults]
614 default_realm = $ctx->{realm}
615 dns_lookup_realm = false
616 dns_lookup_kdc = false
617 ticket_lifetime = 24h
618 forwardable = yes
620 [realms]
621 $ctx->{realm} = {
622 kdc = $ctx->{kdc_ipv4}:88
623 admin_server = $ctx->{kdc_ipv4}:88
624 default_domain = $ctx->{dnsname}
626 $ctx->{dnsname} = {
627 kdc = $ctx->{kdc_ipv4}:88
628 admin_server = $ctx->{kdc_ipv4}:88
629 default_domain = $ctx->{dnsname}
631 $ctx->{domain} = {
632 kdc = $ctx->{kdc_ipv4}:88
633 admin_server = $ctx->{kdc_ipv4}:88
634 default_domain = $ctx->{dnsname}
637 [appdefaults]
638 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
640 [kdc]
641 enable-pkinit = true
642 pkinit_identity = FILE:$ctx->{tlsdir}/kdc.pem,$ctx->{tlsdir}/key.pem
643 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
645 [domain_realm]
646 .$ctx->{dnsname} = $ctx->{realm}
648 close(KRB5CONF);
650 open(PWD, ">$ctx->{nsswrap_passwd}");
651 print PWD "
652 root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
653 $ctx->{unix_name}:x:$ctx->{unix_uid}:@{$ctx->{unix_gids}}[0]:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
654 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
656 close(PWD);
658 open(GRP, ">$ctx->{nsswrap_group}");
659 print GRP "
660 root:x:0:
661 wheel:x:10:
662 users:x:100:
663 nobody:x:65533:
664 nogroup:x:65534:nobody
666 close(GRP);
668 my $configuration = "--configfile=$ctx->{smb_conf}";
670 #Ensure the config file is valid before we start
671 my $testparm = $self->bindir_path("testparm");
672 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
673 system("$testparm -v --suppress-prompt $configuration >&2");
674 die("Failed to create a valid smb.conf configuration $testparm!");
677 (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) or die("Failed to create a valid smb.conf configuration! $self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
679 my $ret = {
680 KRB5_CONFIG => $ctx->{krb5_conf},
681 PIDDIR => $ctx->{piddir},
682 SERVER => $ctx->{netbiosname},
683 SERVER_IP => $ctx->{ipv4},
684 NETBIOSNAME => $ctx->{netbiosname},
685 NETBIOSALIAS => $ctx->{netbiosalias},
686 DOMAIN => $ctx->{domain},
687 USERNAME => $ctx->{username},
688 REALM => $ctx->{realm},
689 PASSWORD => $ctx->{password},
690 LDAPDIR => $ctx->{ldapdir},
691 LDAP_INSTANCE => $ctx->{ldap_instance},
692 WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
693 NCALRPCDIR => $ctx->{ncalrpcdir},
694 LOCKDIR => $ctx->{lockdir},
695 SERVERCONFFILE => $ctx->{smb_conf},
696 CONFIGURATION => $configuration,
697 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
698 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
699 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
700 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
701 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
702 SAMBA_TEST_LOG_POS => 0,
705 return $ret;
709 # provision_raw_step2() is also used by Samba34.pm!
711 # Step2 runs the provision script
713 sub provision_raw_step2($$$)
715 my ($self, $ctx, $ret) = @_;
717 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
718 (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n");
720 return $ret;
723 sub provision($$$$$$$)
725 my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, $swiface, $password, $kdc_ipv4, $extra_smbconf_options) = @_;
727 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
728 $netbiosname, $netbiosalias,
729 $swiface, $password, $kdc_ipv4);
731 $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
732 push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
733 push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test1");
734 push(@{$ctx->{directories}}, "$ctx->{tmpdir}/test2");
735 my $msdfs = "no";
736 $msdfs = "yes" if ($server_role eq "domain controller");
737 $ctx->{smb_conf_extra_options} = "
739 max xmit = 32K
740 server max protocol = SMB2
741 $extra_smbconf_options
742 host msdfs = $msdfs
744 [tmp]
745 path = $ctx->{tmpdir}
746 read only = no
747 posix:sharedelay = 10000
748 posix:oplocktimeout = 3
749 posix:writetimeupdatedelay = 500000
751 [test1]
752 path = $ctx->{tmpdir}/test1
753 read only = no
754 posix:sharedelay = 10000
755 posix:oplocktimeout = 3
756 posix:writetimeupdatedelay = 50000
758 [test2]
759 path = $ctx->{tmpdir}/test2
760 read only = no
761 posix:sharedelay = 10000
762 posix:oplocktimeout = 3
763 posix:writetimeupdatedelay = 50000
765 [cifs]
766 read only = no
767 ntvfs handler = cifs
768 cifs:server = $ctx->{netbiosname}
769 cifs:share = tmp
770 #There is no username specified here, instead the client is expected
771 #to log in with kerberos, and the serverwill use delegated credentials.
773 [simple]
774 path = $ctx->{tmpdir}
775 read only = no
776 ntvfs handler = simple
778 [sysvol]
779 path = $ctx->{lockdir}/sysvol
780 read only = yes
782 [netlogon]
783 path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
784 read only = no
786 [cifsposix]
787 copy = simple
788 ntvfs handler = cifsposix
791 if (defined($self->{ldap})) {
792 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
793 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
795 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
796 $ldap_uri =~ s|/|%2F|g;
797 $ldap_uri = "ldapi://$ldap_uri";
798 $ctx->{ldap_uri} = $ldap_uri;
800 if ($self->{ldap} eq "fedora-ds") {
801 $ctx->{sid_generator} = "backend";
804 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
807 my $ret = $self->provision_raw_step1($ctx);
809 if (defined($self->{ldap})) {
810 $ret->{LDAP_URI} = $ctx->{ldap_uri};
811 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
812 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
813 if ($self->{ldap} eq "openldap") {
814 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
815 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
817 } elsif ($self->{ldap} eq "fedora-ds") {
818 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
819 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
820 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
825 $ret = $self->provision_raw_step2($ctx, $ret);
827 return $ret;
830 sub provision_member($$$)
832 my ($self, $prefix, $dcvars) = @_;
833 print "PROVISIONING MEMBER...";
835 my $ret = $self->provision($prefix,
836 "member server",
837 "localmember3",
838 "localmember",
840 "locMEMpass0",
841 $dcvars->{SERVER_IP},
842 "");
844 $ret or die("Unable to provision");
846 my $net = $self->bindir_path("net");
847 my $cmd = "";
848 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
849 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
850 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
851 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
853 system($cmd) == 0 or die("Join failed\n$cmd");
855 $ret->{MEMBER_SERVER} = $ret->{SERVER};
856 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
857 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
858 $ret->{MEMBER_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
859 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
860 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
862 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
863 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
864 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
865 $ret->{DC_NETBIOSALIAS} = $dcvars->{DC_NETBIOSALIAS};
866 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
867 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
869 return $ret;
872 sub provision_rpc_proxy($$$)
874 my ($self, $prefix, $dcvars) = @_;
875 print "PROVISIONING RPC PROXY...";
877 my $extra_smbconf_options = "dcerpc_remote:binding = ncacn_ip_tcp:localdc1
878 dcerpc endpoint servers = epmapper, remote
879 dcerpc_remote:interfaces = rpcecho
882 my $ret = $self->provision($prefix,
883 "member server",
884 "localrpcproxy4",
885 "localrpcproxy",
887 "locRPCproxypass0",
888 $dcvars->{SERVER_IP},
889 $extra_smbconf_options);
891 $ret or die("Unable to provision");
893 my $net = $self->bindir_path("net");
894 my $cmd = "";
895 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
896 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
897 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
898 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
900 system($cmd) == 0 or die("Join failed\n$cmd");
902 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
903 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
904 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
905 $ret->{RPC_PROXY_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
906 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
907 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
909 return $ret;
912 sub provision_dc($$)
914 my ($self, $prefix) = @_;
916 print "PROVISIONING DC...";
917 my $ret = $self->provision($prefix,
918 "domain controller",
919 "localdc1",
920 "localdc",
922 "locDCpass0",
923 "127.0.0.1", "");
925 $self->add_wins_config("$prefix/private") or
926 die("Unable to add wins configuration");
928 $ret->{DC_SERVER} = $ret->{SERVER};
929 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
930 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
931 $ret->{DC_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
932 $ret->{DC_USERNAME} = $ret->{USERNAME};
933 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
935 return $ret;
938 sub teardown_env($$)
940 my ($self, $envvars) = @_;
941 my $pid;
943 close(DATA);
945 if (-f "$envvars->{PIDDIR}/samba.pid" ) {
946 open(IN, "<$envvars->{PIDDIR}/samba.pid") or die("unable to open server pid file");
947 $pid = <IN>;
948 close(IN);
950 # Give the process 20 seconds to exit. gcov needs
951 # this time to write out the covarge data
952 my $count = 0;
953 until (kill(0, $pid) == 0) {
954 # if no process sucessfully signalled, then we are done
955 sleep(1);
956 $count++;
957 last if $count > 20;
960 # If it is still around, kill it
961 if ($count > 20) {
962 print "server process $pid took more than $count seconds to exit, killing\n";
963 kill 9, $pid;
967 my $failed = $? >> 8;
969 $self->slapd_stop($envvars) if ($self->{ldap});
971 print $self->getlog_env($envvars);
973 return $failed;
976 sub getlog_env($$)
978 my ($self, $envvars) = @_;
979 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME}\n";
980 my $out = $title;
982 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
984 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
985 while (<LOG>) {
986 $out .= $_;
988 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
989 close(LOG);
991 return "" if $out eq $title;
993 return $out;
996 sub check_env($$)
998 my ($self, $envvars) = @_;
1000 return 1 if (-p $envvars->{SAMBA_TEST_FIFO});
1002 print $self->getlog_env($envvars);
1004 return 0;
1007 sub setup_env($$$)
1009 my ($self, $envname, $path) = @_;
1011 if ($envname eq "dc") {
1012 return $self->setup_dc("$path/dc");
1013 } elsif ($envname eq "rpc_proxy") {
1014 if (not defined($self->{vars}->{dc})) {
1015 $self->setup_dc("$path/dc");
1017 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1018 } elsif ($envname eq "member") {
1019 if (not defined($self->{vars}->{dc})) {
1020 $self->setup_dc("$path/dc");
1022 return $self->setup_member("$path/member", $self->{vars}->{dc});
1023 } elsif ($envname eq "all") {
1024 if (not defined($self->{vars}->{dc})) {
1025 $self->setup_dc("$path/dc");
1027 my $ret = $self->setup_member("$path/member", $self->{vars}->{dc});
1028 if (not defined($self->{vars}->{rpc_proxy})) {
1029 my $rpc_proxy_ret = $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
1031 $ret->{RPC_PROXY_SERVER} = $rpc_proxy_ret->{SERVER};
1032 $ret->{RPC_PROXY_SERVER_IP} = $rpc_proxy_ret->{SERVER_IP};
1033 $ret->{RPC_PROXY_NETBIOSNAME} = $rpc_proxy_ret->{NETBIOSNAME};
1034 $ret->{RPC_PROXY_NETBIOSALIAS} = $rpc_proxy_ret->{NETBIOSALIAS};
1035 $ret->{RPC_PROXY_USERNAME} = $rpc_proxy_ret->{USERNAME};
1036 $ret->{RPC_PROXY_PASSWORD} = $rpc_proxy_ret->{PASSWORD};
1038 return $ret;
1039 } else {
1040 die("Samba4 can't provide environment '$envname'");
1044 sub setup_member($$$$)
1046 my ($self, $path, $dc_vars) = @_;
1048 my $env = $self->provision_member($path, $dc_vars);
1050 $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
1052 $self->wait_for_start($env);
1054 $self->{vars}->{member} = $env;
1056 return $env;
1059 sub setup_rpc_proxy($$$$)
1061 my ($self, $path, $dc_vars) = @_;
1063 my $env = $self->provision_rpc_proxy($path, $dc_vars);
1065 $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
1067 $self->wait_for_start($env);
1069 $self->{vars}->{rpc_proxy} = $env;
1071 return $env;
1074 sub setup_dc($$)
1076 my ($self, $path) = @_;
1078 my $env = $self->provision_dc($path);
1080 $self->check_or_start($env,
1081 ($ENV{SMBD_MAXTIME} or 7500));
1083 $self->wait_for_start($env);
1085 $self->{vars}->{dc} = $env;
1087 return $env;
1090 sub stop($)
1092 my ($self) = @_;