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.
15 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
18 samba3
=> new Samba3
($bindir, $srcdir, $server_maxtime),
19 samba4
=> new Samba4
($bindir, $ldap, $srcdir, $server_maxtime),
25 %Samba::ENV_DEPS
= (%Samba3::ENV_DEPS
, %Samba4::ENV_DEPS
);
28 %Samba::ENV_TARGETS
= (
29 (map { $_ => "Samba3" } keys %Samba3::ENV_DEPS
),
30 (map { $_ => "Samba4" } keys %Samba4::ENV_DEPS
),
34 %Samba::ENV_NEEDS_AD_DC
= (
35 (map { $_ => 1 } keys %Samba4::ENV_DEPS
)
38 foreach my $env (keys %Samba3::ENV_DEPS
) {
39 $ENV_NEEDS_AD_DC{$env} = ($env =~ /^ad_/);
44 my ($self, $envname, $path) = @_;
46 my $targetname = $ENV_TARGETS{$envname};
47 if (not defined($targetname)) {
48 warn("Samba can't provide environment '$envname'");
53 "Samba3" => $self->{samba3
},
54 "Samba4" => $self->{samba4
}
56 my $target = $targetlookup{$targetname};
58 if (defined($target->{vars
}->{$envname})) {
59 return $target->{vars
}->{$envname};
63 foreach(@
{$ENV_DEPS{$envname}}) {
64 my $vars = $self->setup_env($_, $path);
66 push(@dep_vars, $vars);
68 warn("Failed setting up $_ as a dependency of $envname");
73 $ENV{ENVNAME
} = $envname;
74 # Avoid hitting system krb5.conf -
75 # An env that needs Kerberos will reset this to the real value.
76 $ENV{KRB5_CONFIG
} = "$path/no_krb5.conf";
78 my $setup_name = $ENV_TARGETS{$envname}."::setup_".$envname;
79 my $setup_sub = \
&$setup_name;
80 my $env = &$setup_sub($target, "$path/$envname", @dep_vars);
82 if (not defined($env)) {
83 warn("failed to start up environment '$envname'");
87 $target->{vars
}->{$envname} = $env;
88 $target->{vars
}->{$envname}->{target
} = $target;
94 my ($object, $path) = @_;
96 my $valpath = "$object->{bindir}/$path";
99 if (defined $ENV{'PYTHON'}) {
100 $python_cmd = $ENV{'PYTHON'} . " ";
103 if (-f
$valpath or -d
$valpath) {
106 # make sure we prepend samba-tool with calling $PYTHON python version
107 if ($path eq "samba-tool") {
108 $result = $python_cmd . $result;
113 sub nss_wrapper_winbind_so_path
($) {
115 my $ret = $ENV{NSS_WRAPPER_WINBIND_SO_PATH
};
116 if (not defined($ret)) {
117 $ret = bindir_path
($object, "shared/libnss_wrapper_winbind.so.2");
118 $ret = abs_path
($ret);
123 sub copy_file_content
($$)
126 open(IN
, "${in}") or die("failed to open in[${in}] for reading: $!");
127 open(OUT
, ">${out}") or die("failed to open out[${out}] for writing: $!");
135 sub prepare_keyblobs
($)
139 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
140 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
141 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
142 my $dcdnsname = "$ctx->{hostname}.$ctx->{dnsname}";
143 my $dcdir = "$cadir/DCs/$dcdnsname";
144 my $dccert = "$dcdir/DC-$dcdnsname-cert.pem";
145 my $dckey_private = "$dcdir/DC-$dcdnsname-private-key.pem";
146 my $adminprincipalname = "administrator\@$ctx->{dnsname}";
147 my $admindir = "$cadir/Users/$adminprincipalname";
148 my $admincert = "$admindir/USER-$adminprincipalname-cert.pem";
149 my $adminkey_private = "$admindir/USER-$adminprincipalname-private-key.pem";
150 my $pkinitprincipalname = "pkinit\@$ctx->{dnsname}";
151 my $pkinitdir = "$cadir/Users/$pkinitprincipalname";
152 my $pkinitcert = "$pkinitdir/USER-$pkinitprincipalname-cert.pem";
153 my $pkinitkey_private = "$pkinitdir/USER-$pkinitprincipalname-private-key.pem";
155 my $tlsdir = "$ctx->{tlsdir}";
156 my $pkinitdir = "$ctx->{prefix_abs}/pkinit";
157 #TLS and PKINIT crypto blobs
158 my $dhfile = "$tlsdir/dhparms.pem";
159 my $cafile = "$tlsdir/ca.pem";
160 my $crlfile = "$tlsdir/crl.pem";
161 my $certfile = "$tlsdir/cert.pem";
162 my $keyfile = "$tlsdir/key.pem";
163 my $admincertfile = "$pkinitdir/USER-$adminprincipalname-cert.pem";
164 my $adminkeyfile = "$pkinitdir/USER-$adminprincipalname-private-key.pem";
165 my $pkinitcertfile = "$pkinitdir/USER-$pkinitprincipalname-cert.pem";
166 my $pkinitkeyfile = "$pkinitdir/USER-$pkinitprincipalname-private-key.pem";
168 mkdir($tlsdir, 0700);
169 mkdir($pkinitdir, 0700);
170 my $oldumask = umask;
173 # This is specified here to avoid draining entropy on every run
175 # openssl dhparam -out dhparms.pem -text -2 8192
176 open(DHFILE
, ">$dhfile");
178 -----BEGIN DH PARAMETERS-----
179 MIIECAKCBAEAlcpjuJptCzC2bIIApLuyFLw2nODQUztqs/peysY9e3LgWh/xrc87
180 SWJNSUrqFJFh2m357WH0XGcTdTk0b/8aIYIWjbwEhWR/5hZ+1x2TDrX1awkYayAe
181 pr0arycmWHaAmhw+m+dBdj2O2jRMe7gn0ha85JALNl+Z3wv2q2eys8TIiQ2dbHPx
182 XvpMmlAv7QHZnpSpX/XgueQr6T3EYggljppZwk1fe4W2cxBjCv9w/Q83pJXMEVVB
183 WESEQPZC38v6hVIXIlF4J7jXjV3+NtCLL4nvsy0jrLEntyKz5OB8sNPRzJr0Ju2Y
184 yXORCSMMXMygP+dxJtQ6txzQYWyaCYN1HqHDZy3cFL9Qy8kTFqIcW56Lti2GsW/p
185 jSMzEOa1NevhKNFL3dSZJx5m+5ZeMvWXlCqXSptmVdbs5wz5jkMUm/E6pVfM5lyb
186 Ttlcq2iYPqnJz1jcL5xwhoufID8zSJCPJ7C0jb0Ngy5wLIUZfjXJUXxUyxTnNR9i
187 N9Sc+UkDvLxnCW+qzjyPXGlQU1SsJwMLWa2ZecL/uYE4bOdcN3g+5WHkevyDnXqR
188 +yy9x7sGXjBT3bRWK5tVHJWOi6eBu1hp39U6aK8oOJWiUt3vmC2qEdIsT6JaLNNi
189 YKrSfRGBf19IJBaagen1S19bb3dnmwoU1RaWM0EeJQW1oXOBg7zLisB2yuu5azBn
190 tse00+0nc+GbH2y+jP0sE7xil1QeilZl+aQ3tX9vL0cnCa+8602kXxU7P5HaX2+d
191 05pvoHmeZbDV85io36oF976gBYeYN+qAkTUMsIZhuLQDuyn0963XOLyn1Pm6SBrU
192 OkIZXW7WoKEuO/YSfizUIqXwmAMJjnEMJCWG51MZZKx//9Hsdp1RXSm/bRSbvXB7
193 MscjvQYWmfCFnIk8LYnEt3Yey40srEiS9xyZqdrvobxz+sU1XcqR38kpVf4gKASL
194 xURia64s4emuJF+YHIObyydazQ+6/wX/C+m+nyfhuxSO6j1janPwtYbU+Uj3TzeM
195 04K1mpPQpZcaMdZZiNiu7i8VJlOPKAz7aJT8TnMMF5GMyzyLpSMpc+NF9L/BSocV
196 /cUM4wQT2PTHrcyYzmTVH7c9bzBkuxqrwVB1BY1jitDV9LIYIVBglKcX88qrfHIM
197 XiXPAIwGclD59qm2cG8OdM9NA5pNMI119KuUAIJsUdgPbR1LkT2XTT15YVoHmFSQ
198 DlaWOXn4td031jr0EisX8QtFR7+/0Nfoni6ydFGs5fNH/L1ckq6FEO4OhgucJw9H
199 YRmiFlsQBQNny78vNchwZne3ZixkShtGW0hWDdi2n+h7St1peNJCNJjMbEhRsPRx
200 RmNGWh4AL8rho4RO9OBao0MnUdjbbffD+wIBAg==
201 -----END DH PARAMETERS-----
205 if (! -e
${dckey_private
}) {
210 copy_file_content
(${cacert
}, ${cafile
});
211 copy_file_content
(${cacrl_pem
}, ${crlfile
});
212 copy_file_content
(${dccert
}, ${certfile
});
213 copy_file_content
(${dckey_private
}, ${keyfile
});
214 if (-e
${adminkey_private
}) {
215 copy_file_content
(${admincert
}, ${admincertfile
});
216 copy_file_content
(${adminkey_private
}, ${adminkeyfile
});
218 if (-e
${pkinitkey_private
}) {
219 copy_file_content
(${pkinitcert
}, ${pkinitcertfile
});
220 copy_file_content
(${pkinitkey_private
}, ${pkinitkeyfile
});
223 # COMPAT stuff to be removed in a later commit
224 my $kdccertfile = "$tlsdir/kdc.pem";
225 copy_file_content
(${dccert
}, ${kdccertfile
});
234 unless (open(KRB5CONF
, ">$ctx->{krb5_conf}")) {
235 warn("can't open $ctx->{krb5_conf}$?");
239 my $our_realms_stanza = mk_realms_stanza
($ctx->{realm
},
244 #Generated krb5.conf for $ctx->{realm}
247 default_realm = $ctx->{realm}
248 dns_lookup_realm = false
249 dns_lookup_kdc = true
250 ticket_lifetime = 24h
252 allow_weak_crypto = yes
253 # Set the grace clocskew to 5 seconds
254 # This is especially required by samba3.raw.session krb5 and
257 # We are running on the same machine, do not correct
258 # system clock differences
263 if (defined($ctx->{krb5_ccname
})) {
265 default_ccache_name = $ctx->{krb5_ccname}
270 if (defined($ctx->{supported_enctypes
})) {
272 default_etypes = $ctx->{supported_enctypes}
273 default_as_etypes = $ctx->{supported_enctypes}
274 default_tgs_enctypes = $ctx->{supported_enctypes}
275 default_tkt_enctypes = $ctx->{supported_enctypes}
276 permitted_enctypes = $ctx->{supported_enctypes}
286 if (defined($ctx->{tlsdir
})) {
290 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
294 pkinit_identity = FILE:$ctx->{tlsdir}/kdc.pem,$ctx->{tlsdir}/key.pem
295 pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
302 sub mk_realms_stanza
($$$$)
304 my ($realm, $dnsname, $domain, $kdc_ipv4) = @_;
305 my $lc_domain = lc($domain);
307 my $realms_stanza = "
310 admin_server = $kdc_ipv4:88
311 default_domain = $dnsname
315 admin_server = $kdc_ipv4:88
316 default_domain = $dnsname
320 admin_server = $kdc_ipv4:88
321 default_domain = $dnsname
325 admin_server = $kdc_ipv4:88
326 default_domain = $dnsname
330 return $realms_stanza;
333 sub mk_mitkdc_conf
($$)
335 # samba_kdb_dir is the path to mit_samba.so
336 my ($ctx, $samba_kdb_dir) = @_;
338 unless (open(KDCCONF
, ">$ctx->{mitkdc_conf}")) {
339 warn("can't open $ctx->{mitkdc_conf}$?");
344 # Generated kdc.conf for $ctx->{realm}
361 db_module_dir = $samba_kdb_dir
376 kdc = FILE:$ctx->{logdir}/mit_kdc.log
384 my ($netbiosname) = @_;
385 $netbiosname = lc($netbiosname);
388 $interfaces{"localnt4dc2"} = 3;
389 $interfaces{"localnt4member3"} = 4;
390 $interfaces{"localshare4"} = 5;
392 $interfaces{"localktest6"} = 7;
393 $interfaces{"maptoguest"} = 8;
394 $interfaces{"localnt4dc9"} = 9;
396 # 11-16 used by selftest.pl for client interfaces
398 $interfaces{"addc_no_nss"} = 17;
399 $interfaces{"addc_no_ntlm"} = 18;
400 $interfaces{"idmapadmember"} = 19;
401 $interfaces{"idmapridmember"} = 20;
402 $interfaces{"localdc"} = 21;
403 $interfaces{"localvampiredc"} = 22;
404 $interfaces{"s4member"} = 23;
405 $interfaces{"localrpcproxy"} = 24;
406 $interfaces{"dc5"} = 25;
407 $interfaces{"dc6"} = 26;
408 $interfaces{"dc7"} = 27;
409 $interfaces{"rodc"} = 28;
410 $interfaces{"localadmember"} = 29;
411 $interfaces{"addc"} = 30;
412 $interfaces{"localsubdc"} = 31;
413 $interfaces{"chgdcpass"} = 32;
414 $interfaces{"promotedvdc"} = 33;
415 $interfaces{"rfc2307member"} = 34;
416 $interfaces{"fileserver"} = 35;
417 $interfaces{"fakednsforwarder1"} = 36;
418 $interfaces{"fakednsforwarder2"} = 37;
419 $interfaces{"s4member_dflt"} = 38;
420 $interfaces{"vampire2000dc"} = 39;
421 $interfaces{"backupfromdc"} = 40;
422 $interfaces{"restoredc"} = 41;
423 $interfaces{"renamedc"} = 42;
424 $interfaces{"labdc"} = 43;
425 $interfaces{"offlinebackupdc"} = 44;
426 $interfaces{"customdc"} = 45;
427 $interfaces{"prockilldc"} = 46;
428 $interfaces{"proclimitdc"} = 47;
430 # update lib/socket_wrapper/socket_wrapper.c
431 # #define MAX_WRAPPED_INTERFACES 64
432 # if you wish to have more than 64 interfaces
434 if (not defined($interfaces{$netbiosname})) {
438 return $interfaces{$netbiosname};
441 sub cleanup_child
($$)
443 my ($pid, $name) = @_;
445 if (!defined($pid)) {
446 print STDERR
"cleanup_child: pid not defined ... not calling waitpid\n";
450 my $childpid = waitpid($pid, WNOHANG
);
452 if ($childpid == 0) {
453 } elsif ($childpid < 0) {
454 printf STDERR
"%s child process %d isn't here any more\n", $name, $pid;
457 printf STDERR
"%s child process %d, died with signal %d, %s coredump\n",
458 $name, $childpid, ($?
& 127), ($?
& 128) ?
'with' : 'without';
460 printf STDERR
"%s child process %d exited with value %d\n", $name, $childpid, $?
>> 8;
465 sub random_domain_sid
()
467 my $domain_sid = "S-1-5-21-". int(rand(4294967295)) . "-" . int(rand(4294967295)) . "-" . int(rand(4294967295));