2011-04-18 11:38:35 +04:00
#!/usr/bin/perl
# Bootstrap Samba and run a number of tests against it.
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU GPL, v3 or later.
package Samba ;
use strict ;
use target::Samba3 ;
use target::Samba4 ;
2012-03-04 10:30:45 +04:00
use POSIX ;
2013-11-08 12:49:25 +04:00
use Cwd qw( abs_path ) ;
2011-04-18 11:38:35 +04:00
sub new ($$$$$) {
2015-06-05 03:22:45 +03:00
my ( $ classname , $ bindir , $ ldap , $ srcdir , $ server_maxtime ) = @ _ ;
2011-04-18 11:38:35 +04:00
my $ self = {
2015-06-05 03:22:45 +03:00
samba3 = > new Samba3 ( $ bindir , $ srcdir , $ server_maxtime ) ,
samba4 = > new Samba4 ( $ bindir , $ ldap , $ srcdir , $ server_maxtime ) ,
2011-04-18 11:38:35 +04:00
} ;
bless $ self ;
return $ self ;
}
sub setup_env ($$$)
{
my ( $ self , $ envname , $ path ) = @ _ ;
$ ENV { ENVNAME } = $ envname ;
my $ env = $ self - > { samba4 } - > setup_env ( $ envname , $ path ) ;
2012-02-13 05:14:57 +04:00
if ( defined ( $ env ) and $ env ne "UNKNOWN" ) {
2011-04-27 06:10:12 +04:00
if ( not defined ( $ env - > { target } ) ) {
$ env - > { target } = $ self - > { samba4 } ;
}
2012-02-23 09:34:47 +04:00
} elsif ( defined ( $ env ) and $ env eq "UNKNOWN" ) {
2011-04-18 11:38:35 +04:00
$ env = $ self - > { samba3 } - > setup_env ( $ envname , $ path ) ;
2012-02-13 05:14:57 +04:00
if ( defined ( $ env ) and $ env ne "UNKNOWN" ) {
2011-04-27 06:10:12 +04:00
if ( not defined ( $ env - > { target } ) ) {
$ env - > { target } = $ self - > { samba3 } ;
}
2011-04-18 11:38:35 +04:00
}
}
2012-02-23 09:34:47 +04:00
if ( defined ( $ env ) and ( $ env eq "UNKNOWN" ) ) {
2011-04-18 11:38:35 +04:00
warn ( "Samba can't provide environment '$envname'" ) ;
2012-02-23 09:34:47 +04:00
return "UNKNOWN" ;
}
if ( not defined $ env ) {
warn ( "failed to start up environment '$envname'" ) ;
2011-04-18 11:38:35 +04:00
return undef ;
}
return $ env ;
}
2011-04-27 05:19:20 +04:00
sub bindir_path ($$) {
my ( $ object , $ path ) = @ _ ;
2012-01-26 02:42:27 +04:00
my $ valpath = "$object->{bindir}/$path" ;
2011-04-27 05:19:20 +04:00
2014-05-12 18:45:55 +04:00
return $ valpath if ( - f $ valpath or - d $ valpath ) ;
2011-04-27 05:19:20 +04:00
return $ path ;
}
2012-10-03 10:36:34 +04:00
sub nss_wrapper_winbind_so_path ($) {
my ( $ object ) = @ _ ;
my $ ret = $ ENV { NSS_WRAPPER_WINBIND_SO_PATH } ;
if ( not defined ( $ ret ) ) {
2014-12-18 22:13:44 +03:00
$ ret = bindir_path ( $ object , "shared/libnss_wrapper_winbind.so.2" ) ;
2013-11-08 12:49:25 +04:00
$ ret = abs_path ( $ ret ) ;
2012-10-03 10:36:34 +04:00
}
return $ ret ;
}
2016-01-09 23:21:25 +03:00
sub copy_file_content ($$)
{
my ( $ in , $ out ) = @ _ ;
open ( IN , "${in}" ) or die ( "failed to open in[${in}] for reading: $!" ) ;
open ( OUT , ">${out}" ) or die ( "failed to open out[${out}] for writing: $!" ) ;
while ( <IN> ) {
print OUT $ _ ;
}
close ( OUT ) ;
close ( IN ) ;
}
sub prepare_keyblobs ($)
{
my ( $ ctx ) = @ _ ;
my $ cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com" ;
my $ cacert = "$cadir/Public/CA-samba.example.com-cert.pem" ;
my $ cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem" ;
my $ dcdnsname = "$ctx->{hostname}.$ctx->{dnsname}" ;
my $ dcdir = "$cadir/DCs/$dcdnsname" ;
my $ dccert = "$dcdir/DC-$dcdnsname-cert.pem" ;
my $ dckey_private = "$dcdir/DC-$dcdnsname-private-key.pem" ;
2016-06-03 22:46:13 +03:00
my $ adminprincipalname = "administrator\@$ctx->{dnsname}" ;
my $ admindir = "$cadir/Users/$adminprincipalname" ;
my $ admincert = "$admindir/USER-$adminprincipalname-cert.pem" ;
my $ adminkey_private = "$admindir/USER-$adminprincipalname-private-key.pem" ;
2016-06-03 22:46:13 +03:00
my $ pkinitprincipalname = "pkinit\@$ctx->{dnsname}" ;
my $ pkinitdir = "$cadir/Users/$pkinitprincipalname" ;
my $ pkinitcert = "$pkinitdir/USER-$pkinitprincipalname-cert.pem" ;
my $ pkinitkey_private = "$pkinitdir/USER-$pkinitprincipalname-private-key.pem" ;
2016-01-09 23:21:25 +03:00
my $ tlsdir = "$ctx->{tlsdir}" ;
my $ pkinitdir = "$ctx->{prefix_abs}/pkinit" ;
#TLS and PKINIT crypto blobs
my $ dhfile = "$tlsdir/dhparms.pem" ;
my $ cafile = "$tlsdir/ca.pem" ;
my $ crlfile = "$tlsdir/crl.pem" ;
my $ certfile = "$tlsdir/cert.pem" ;
my $ keyfile = "$tlsdir/key.pem" ;
2016-06-03 22:46:13 +03:00
my $ admincertfile = "$pkinitdir/USER-$adminprincipalname-cert.pem" ;
my $ adminkeyfile = "$pkinitdir/USER-$adminprincipalname-private-key.pem" ;
2016-06-03 22:46:13 +03:00
my $ pkinitcertfile = "$pkinitdir/USER-$pkinitprincipalname-cert.pem" ;
my $ pkinitkeyfile = "$pkinitdir/USER-$pkinitprincipalname-private-key.pem" ;
2016-01-09 23:21:25 +03:00
mkdir ( $ tlsdir , 0700 ) ;
mkdir ( $ pkinitdir , 0700 ) ;
my $ oldumask = umask ;
umask 0077 ;
# This is specified here to avoid draining entropy on every run
# generate by
# openssl dhparam -out dhparms.pem -text -2 8192
open ( DHFILE , ">$dhfile" ) ;
print DHFILE << EOF ;
- - - - - BEGIN DH PARAMETERS - - - - -
MIIECAKCBAEAlcpjuJptCzC2bIIApLuyFLw2nODQUztqs /peysY9e3LgWh/x rc87
SWJNSUrqFJFh2m357WH0XGcTdTk0b /8aIYIWjbwEhWR/ 5 hZ + 1 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IM
XiXPAIwGclD59qm2cG8OdM9NA5pNMI119KuUAIJsUdgPbR1LkT2XTT15YVoHmFSQ
DlaWOXn4td031jr0EisX8QtFR7 + /0Nfoni6ydFGs5fNH/ L1ckq6FEO4OhgucJw9H
YRmiFlsQBQNny78vNchwZne3ZixkShtGW0hWDdi2n + h7St1peNJCNJjMbEhRsPRx
RmNGWh4AL8rho4RO9OBao0MnUdjbbffD + wIBAg ==
- - - - - END DH PARAMETERS - - - - -
EOF
close ( DHFILE ) ;
if ( ! - e $ { dckey_private } ) {
umask $ oldumask ;
return ;
}
copy_file_content ( $ { cacert } , $ { cafile } ) ;
copy_file_content ( $ { cacrl_pem } , $ { crlfile } ) ;
copy_file_content ( $ { dccert } , $ { certfile } ) ;
copy_file_content ( $ { dckey_private } , $ { keyfile } ) ;
2016-06-03 22:46:13 +03:00
if ( - e $ { adminkey_private } ) {
copy_file_content ( $ { admincert } , $ { admincertfile } ) ;
copy_file_content ( $ { adminkey_private } , $ { adminkeyfile } ) ;
2016-01-09 23:21:25 +03:00
}
2016-06-03 22:46:13 +03:00
if ( - e $ { pkinitkey_private } ) {
copy_file_content ( $ { pkinitcert } , $ { pkinitcertfile } ) ;
copy_file_content ( $ { pkinitkey_private } , $ { pkinitkeyfile } ) ;
}
2016-01-09 23:21:25 +03:00
# COMPAT stuff to be removed in a later commit
my $ kdccertfile = "$tlsdir/kdc.pem" ;
copy_file_content ( $ { dccert } , $ { kdccertfile } ) ;
umask $ oldumask ;
}
2011-08-26 10:02:01 +04:00
sub mk_krb5_conf ($$)
2011-04-19 10:38:46 +04:00
{
2015-03-24 21:05:10 +03:00
my ( $ ctx ) = @ _ ;
2011-04-19 10:38:46 +04:00
unless ( open ( KRB5CONF , ">$ctx->{krb5_conf}" ) ) {
2011-05-08 08:54:50 +04:00
warn ( "can't open $ctx->{krb5_conf}$?" ) ;
2011-04-19 10:38:46 +04:00
return undef ;
}
2011-08-26 10:02:01 +04:00
my $ our_realms_stanza = mk_realms_stanza ( $ ctx - > { realm } ,
$ ctx - > { dnsname } ,
$ ctx - > { domain } ,
$ ctx - > { kdc_ipv4 } ) ;
2011-04-19 10:38:46 +04:00
print KRB5CONF "
#Generated krb5.conf for $ctx->{realm}
[ libdefaults ]
default_realm = $ ctx - > { realm }
2015-07-09 11:11:22 +03:00
dns_lookup_realm = false
2015-03-24 21:05:10 +03:00
dns_lookup_kdc = true
2011-04-19 10:38:46 +04:00
ticket_lifetime = 24 h
forwardable = yes
allow_weak_crypto = yes
2016-04-27 02:00:14 +03:00
" ;
2016-09-22 19:46:28 +03:00
if ( defined ( $ ctx - > { krb5_ccname } ) ) {
print KRB5CONF "
default_ccache_name = $ ctx - > { krb5_ccname }
" ;
}
2016-04-27 02:00:14 +03:00
if ( defined ( $ ctx - > { supported_enctypes } ) ) {
print KRB5CONF "
default_etypes = $ ctx - > { supported_enctypes }
default_as_etypes = $ ctx - > { supported_enctypes }
default_tgs_enctypes = $ ctx - > { supported_enctypes }
default_tkt_enctypes = $ ctx - > { supported_enctypes }
permitted_enctypes = $ ctx - > { supported_enctypes }
" ;
}
print KRB5CONF "
2011-04-19 10:38:46 +04:00
[ realms ]
2011-08-26 10:02:01 +04:00
$ our_realms_stanza
2011-04-19 10:38:46 +04:00
" ;
2011-08-26 10:02:01 +04:00
2011-04-19 10:38:46 +04:00
if ( defined ( $ ctx - > { tlsdir } ) ) {
print KRB5CONF "
[ appdefaults ]
pkinit_anchors = FILE: $ ctx - > { tlsdir } / ca . pem
[ kdc ]
enable - pkinit = true
pkinit_identity = FILE: $ ctx - > { tlsdir } /kdc.pem,$ctx->{tlsdir}/ key . pem
pkinit_anchors = FILE: $ ctx - > { tlsdir } / ca . pem
" ;
}
close ( KRB5CONF ) ;
}
2011-08-26 10:02:01 +04:00
sub mk_realms_stanza ($$$$)
{
my ( $ realm , $ dnsname , $ domain , $ kdc_ipv4 ) = @ _ ;
2015-01-21 07:27:09 +03:00
my $ lc_domain = lc ( $ domain ) ;
2011-08-26 10:02:01 +04:00
my $ realms_stanza = "
$ realm = {
kdc = $ kdc_ipv4:88
admin_server = $ kdc_ipv4:88
default_domain = $ dnsname
}
$ dnsname = {
kdc = $ kdc_ipv4:88
admin_server = $ kdc_ipv4:88
default_domain = $ dnsname
}
$ domain = {
kdc = $ kdc_ipv4:88
admin_server = $ kdc_ipv4:88
default_domain = $ dnsname
}
2015-01-21 07:27:09 +03:00
$ lc_domain = {
kdc = $ kdc_ipv4:88
admin_server = $ kdc_ipv4:88
default_domain = $ dnsname
}
2011-08-26 10:02:01 +04:00
" ;
return $ realms_stanza ;
}
2012-03-02 04:44:56 +04:00
sub get_interface ($)
{
my ( $ netbiosname ) = @ _ ;
$ netbiosname = lc ( $ netbiosname ) ;
my % interfaces = ( ) ;
2015-03-06 11:34:11 +03:00
$ interfaces { "localnt4dc2" } = 3 ;
2015-03-06 12:01:33 +03:00
$ interfaces { "localnt4member3" } = 4 ;
2013-07-01 15:02:47 +04:00
$ interfaces { "localshare4" } = 5 ;
$ interfaces { "localktest6" } = 7 ;
$ interfaces { "maptoguest" } = 8 ;
2015-03-06 11:39:54 +03:00
$ interfaces { "localnt4dc9" } = 9 ;
2012-03-02 04:44:56 +04:00
# 11-16 used by selftest.pl for client interfaces
$ interfaces { "localdc" } = 21 ;
$ interfaces { "localvampiredc" } = 22 ;
$ interfaces { "s4member" } = 23 ;
$ interfaces { "localrpcproxy" } = 24 ;
$ interfaces { "dc5" } = 25 ;
$ interfaces { "dc6" } = 26 ;
$ interfaces { "dc7" } = 27 ;
$ interfaces { "rodc" } = 28 ;
$ interfaces { "localadmember" } = 29 ;
2015-03-05 20:08:43 +03:00
$ interfaces { "addc" } = 30 ;
2012-03-02 04:44:56 +04:00
$ interfaces { "localsubdc" } = 31 ;
$ interfaces { "chgdcpass" } = 32 ;
2012-07-06 09:39:09 +04:00
$ interfaces { "promotedvdc" } = 33 ;
2013-02-21 23:33:23 +04:00
$ interfaces { "rfc2307member" } = 34 ;
2015-05-15 10:43:29 +03:00
$ interfaces { "fileserver" } = 35 ;
2016-03-17 07:13:28 +03:00
$ interfaces { "fakednsforwarder1" } = 36 ;
$ interfaces { "fakednsforwarder2" } = 37 ;
2016-09-29 18:50:58 +03:00
$ interfaces { "s4member_dflt" } = 38 ;
2017-02-07 23:16:41 +03:00
$ interfaces { "vampire2000dc" } = 39 ;
2012-03-02 04:44:56 +04:00
# update lib/socket_wrapper/socket_wrapper.c
2015-08-07 03:53:08 +03:00
# #define MAX_WRAPPED_INTERFACES 40
# if you wish to have more than 40 interfaces
2012-03-02 04:44:56 +04:00
if ( not defined ( $ interfaces { $ netbiosname } ) ) {
die ( ) ;
}
return $ interfaces { $ netbiosname } ;
}
2012-03-04 10:30:45 +04:00
sub cleanup_child ($$)
{
my ( $ pid , $ name ) = @ _ ;
2014-09-04 14:55:53 +04:00
2016-05-14 01:49:40 +03:00
if ( ! defined ( $ pid ) ) {
print STDERR "cleanup_child: pid not defined ... not calling waitpid\n" ;
return - 1 ;
2014-09-04 14:55:53 +04:00
}
2016-05-14 01:49:40 +03:00
my $ childpid = waitpid ( $ pid , WNOHANG ) ;
2012-03-04 10:30:45 +04:00
if ( $ childpid == 0 ) {
} elsif ( $ childpid < 0 ) {
2016-05-14 01:38:48 +03:00
printf STDERR "%s child process %d isn't here any more\n" , $ name , $ pid ;
2012-03-04 10:30:45 +04:00
return $ childpid ;
2016-05-14 01:51:19 +03:00
} elsif ( $? & 127 ) {
2012-03-04 10:30:45 +04:00
printf STDERR "%s child process %d, died with signal %d, %s coredump\n" ,
2016-05-14 01:44:18 +03:00
$ name , $ childpid , ( $? & 127 ) , ( $? & 128 ) ? 'with' : 'without' ;
2012-03-04 10:30:45 +04:00
} else {
printf STDERR "%s child process %d exited with value %d\n" , $ name , $ childpid , $? >> 8 ;
}
return $ childpid ;
}
2011-04-18 11:38:35 +04:00
1 ;