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 ;
sub new ($$$$$) {
2012-01-26 02:42:27 +04:00
my ( $ classname , $ bindir , $ binary_mapping , $ ldap , $ srcdir , $ server_maxtime ) = @ _ ;
2011-04-18 11:38:35 +04:00
my $ self = {
2012-01-26 02:42:27 +04:00
samba3 = > new Samba3 ( $ bindir , $ binary_mapping , $ srcdir , $ server_maxtime ) ,
samba4 = > new Samba4 ( $ bindir , $ binary_mapping , $ 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 ) = @ _ ;
if ( defined ( $ object - > { binary_mapping } - > { $ path } ) ) {
$ path = $ object - > { binary_mapping } - > { $ path } ;
}
2012-01-26 02:42:27 +04:00
my $ valpath = "$object->{bindir}/$path" ;
2011-04-27 05:19:20 +04:00
return $ valpath if ( - f $ valpath ) ;
return $ path ;
}
2011-08-26 10:02:01 +04:00
sub mk_krb5_conf ($$)
2011-04-19 10:38:46 +04:00
{
2011-08-26 10:02:01 +04:00
my ( $ ctx , $ other_realms_stanza ) = @ _ ;
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 }
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24 h
forwardable = yes
allow_weak_crypto = yes
[ realms ]
2011-08-26 10:02:01 +04:00
$ our_realms_stanza
$ other_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 ) = @ _ ;
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
}
" ;
return $ realms_stanza ;
}
2012-03-02 04:44:56 +04:00
sub get_interface ($)
{
my ( $ netbiosname ) = @ _ ;
$ netbiosname = lc ( $ netbiosname ) ;
my % interfaces = ( ) ;
$ interfaces { "locals3dc2" } = 2 ;
$ interfaces { "localmember3" } = 3 ;
$ interfaces { "localshare4" } = 4 ;
$ interfaces { "localserver5" } = 5 ;
$ interfaces { "localktest6" } = 6 ;
$ interfaces { "maptoguest" } = 7 ;
# 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 ;
$ interfaces { "plugindc" } = 30 ;
$ interfaces { "localsubdc" } = 31 ;
$ interfaces { "chgdcpass" } = 32 ;
# update lib/socket_wrapper/socket_wrapper.c
# #define MAX_WRAPPED_INTERFACES 32
# if you wish to have more than 32 interfaces
if ( not defined ( $ interfaces { $ netbiosname } ) ) {
die ( ) ;
}
return $ interfaces { $ netbiosname } ;
}
2011-04-18 11:38:35 +04:00
1 ;