2007-03-06 00:28:55 +03: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 Samba4 ;
use strict ;
2007-04-17 17:06:00 +04:00
use Cwd qw( abs_path ) ;
2007-03-06 00:28:55 +03:00
use FindBin qw( $RealBin ) ;
use POSIX ;
2007-03-21 18:57:07 +03:00
sub new ($$$$) {
my ( $ classname , $ bindir , $ ldap , $ setupdir ) = @ _ ;
2007-04-17 04:30:01 +04:00
my $ self = {
vars = > { } ,
ldap = > $ ldap ,
bindir = > $ bindir ,
setupdir = > $ setupdir
} ;
2007-03-21 18:57:07 +03:00
bless $ self ;
return $ self ;
}
2007-04-23 11:33:15 +04:00
sub openldap_start ($$$) {
my ( $ slapd_conf , $ uri , $ logs ) = @ _ ;
my $ oldpath = $ ENV { PATH } ;
$ ENV { PATH } = "/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}" ;
2007-04-28 19:17:03 +04:00
system ( "slapd -d0 -f $slapd_conf -h $uri > $logs 2>&1 &" ) ;
2007-04-23 11:33:15 +04:00
$ ENV { PATH } = $ oldpath ;
}
2007-04-11 00:19:31 +04:00
sub slapd_start ($$)
2007-03-06 00:28:55 +03:00
{
2007-04-12 16:45:41 +04:00
my $ count = 0 ;
2007-04-11 00:19:31 +04:00
my ( $ self , $ env_vars ) = @ _ ;
my $ uri = $ env_vars - > { LDAP_URI } ;
2007-03-06 09:30:36 +03:00
# running slapd in the background means it stays in the same process group, so it can be
# killed by timelimit
2007-04-17 04:30:01 +04:00
if ( $ self - > { ldap } eq "fedora" ) {
system ( "$ENV{FEDORA_DS_PREFIX}/sbin/ns-slapd -D $env_vars->{FEDORA_DS_DIR} -d0 -i $env_vars->{FEDORA_DS_PIDFILE}> $env_vars->{LDAPDIR}/logs 2>&1 &" ) ;
} elsif ( $ self - > { ldap } eq "openldap" ) {
2007-04-23 11:33:15 +04:00
openldap_start ( $ env_vars - > { SLAPD_CONF } , $ uri , "$env_vars->{LDAPDIR}/logs" ) ;
2007-03-06 00:28:55 +03:00
}
2007-03-21 18:57:07 +03:00
while ( system ( "$self->{bindir}/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null" ) != 0 ) {
2007-03-07 14:05:59 +03:00
$ count + + ;
2007-04-23 11:33:15 +04:00
if ( $ count > 40 ) {
2007-04-11 00:19:31 +04:00
$ self - > slapd_stop ( $ env_vars ) ;
2007-03-07 14:05:59 +03:00
return 0 ;
}
sleep ( 1 ) ;
}
2007-03-06 09:30:36 +03:00
return 1 ;
2007-03-06 00:28:55 +03:00
}
2007-04-11 00:19:31 +04:00
sub slapd_stop ($$)
2007-03-06 00:28:55 +03:00
{
2007-04-11 00:19:31 +04:00
my ( $ self , $ envvars ) = @ _ ;
2007-04-17 04:30:01 +04:00
if ( $ self - > { ldap } eq "fedora" ) {
2007-04-11 00:19:31 +04:00
system ( "$envvars->{LDAPDIR}/slapd-samba4/stop-slapd" ) ;
2007-04-17 04:30:01 +04:00
} elsif ( $ self - > { ldap } eq "openldap" ) {
2007-04-11 09:01:02 +04:00
open ( IN , "<$envvars->{OPENLDAP_PIDFILE}" ) or
die ( "unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}" ) ;
2007-03-06 00:28:55 +03:00
kill 9 , <IN> ;
close ( IN ) ;
}
2007-04-24 01:56:23 +04:00
return 1 ;
2007-03-06 00:28:55 +03:00
}
2007-04-11 07:45:39 +04:00
sub check_or_start ($$$)
2007-03-06 00:28:55 +03:00
{
2007-04-11 07:45:39 +04:00
my ( $ self , $ env_vars , $ max_time ) = @ _ ;
2007-03-21 18:57:07 +03:00
return 0 if ( - p $ env_vars - > { SMBD_TEST_FIFO } ) ;
unlink ( $ env_vars - > { SMBD_TEST_FIFO } ) ;
POSIX:: mkfifo ( $ env_vars - > { SMBD_TEST_FIFO } , 0700 ) ;
unlink ( $ env_vars - > { SMBD_TEST_LOG } ) ;
2007-03-06 00:28:55 +03:00
2007-03-21 18:57:07 +03:00
print "STARTING SMBD... " ;
2007-03-06 00:28:55 +03:00
my $ pid = fork ( ) ;
if ( $ pid == 0 ) {
2007-03-21 18:57:07 +03:00
open STDIN , $ env_vars - > { SMBD_TEST_FIFO } ;
open STDOUT , ">$env_vars->{SMBD_TEST_LOG}" ;
2007-03-06 00:28:55 +03:00
open STDERR , '>&STDOUT' ;
2007-04-17 07:47:51 +04:00
2007-04-17 19:33:50 +04:00
SocketWrapper:: set_default_iface ( $ env_vars - > { SOCKET_WRAPPER_DEFAULT_IFACE } ) ;
2007-04-17 07:47:51 +04:00
my $ valgrind = "" ;
if ( defined ( $ ENV { SMBD_VALGRIND } ) ) {
$ valgrind = $ ENV { SMBD_VALGRIND } ;
}
$ ENV { KRB5_CONFIG } = $ env_vars - > { KRB5_CONFIG } ;
2007-04-23 11:33:15 +04:00
# Start slapd before smbd, but with the fifo on stdin
if ( defined ( $ self - > { ldap } ) ) {
$ self - > slapd_start ( $ env_vars ) or
die ( "couldn't start slapd (2nd time)" ) ;
}
2007-03-06 00:28:55 +03:00
my $ optarg = "" ;
if ( defined ( $ max_time ) ) {
$ optarg = "--maximum-runtime=$max_time " ;
}
2007-04-17 04:30:01 +04:00
my $ ret = system ( "$valgrind $self->{bindir}/smbd $optarg $env_vars->{CONFIGURATION} -M single -i --leak-report-full" ) ;
2007-03-06 00:28:55 +03:00
if ( $? == - 1 ) {
print "Unable to start smbd: $ret: $!\n" ;
exit 1 ;
}
2007-03-21 18:57:07 +03:00
unlink ( $ env_vars - > { SMBD_TEST_FIFO } ) ;
2007-03-06 00:28:55 +03:00
my $ exit = $? >> 8 ;
if ( $ ret == 0 ) {
print "smbd exits with status $exit\n" ;
} elsif ( $ ret & 127 ) {
print "smbd got signal " . ( $ ret & 127 ) . " and exits with $exit!\n" ;
} else {
$ ret = $? >> 8 ;
print "smbd failed with status $exit!\n" ;
}
exit $ exit ;
}
print "DONE\n" ;
2007-03-21 18:57:07 +03:00
open ( DATA , ">$env_vars->{SMBD_TEST_FIFO}" ) ;
2007-03-06 00:28:55 +03:00
return $ pid ;
}
2007-04-04 16:23:10 +04:00
sub wait_for_start ($$)
2007-03-06 00:28:55 +03:00
{
2007-04-04 16:23:10 +04:00
my ( $ self , $ testenv_vars ) = @ _ ;
2007-03-06 00:28:55 +03:00
# give time for nbt server to register its names
print "delaying for nbt name registration\n" ;
2007-04-28 12:58:40 +04:00
sleep 2 ;
2007-03-06 00:28:55 +03:00
# This will return quickly when things are up, but be slow if we
# need to wait for (eg) SSL init
2007-04-04 16:23:10 +04:00
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}" ) ;
2007-04-28 12:58:40 +04:00
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}" ) ;
2007-04-04 16:23:10 +04:00
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}" ) ;
2007-04-28 12:58:40 +04:00
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}" ) ;
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}" ) ;
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}" ) ;
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}" ) ;
2007-04-23 11:33:15 +04:00
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}" ) ;
2007-04-28 12:58:40 +04:00
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}" ) ;
system ( "bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}" ) ;
2007-04-18 18:02:26 +04:00
print $ self - > getlog_env ( $ testenv_vars ) ;
2007-03-06 00:28:55 +03:00
}
2007-04-17 04:30:01 +04:00
sub write_ldb_file ($$$)
{
my ( $ self , $ file , $ ldif ) = @ _ ;
open ( LDIF , "|$self->{bindir}/ldbadd -H $file >/dev/null" ) ;
print LDIF $ ldif ;
return close ( LDIF ) ;
}
sub add_wins_config ($$)
{
my ( $ self , $ privatedir ) = @ _ ;
return $ self - > write_ldb_file ( "$privatedir/wins_config.ldb" , "
dn: name = TORTURE_6 , CN = PARTNERS
objectClass: wreplPartner
name: TORTURE_6
address: 127.0 .0 .6
pullInterval: 0
pushChangeCount: 0
type: 0x3
" ) ;
}
sub mk_fedora ($$$$$$)
{
my ( $ self , $ ldapdir , $ basedn , $ root , $ password , $ privatedir , $ configuration ) = @ _ ;
2007-04-20 15:40:44 +04:00
mkdir ( $ ldapdir , 0777 ) ;
2007-04-17 04:53:07 +04:00
2007-04-17 04:30:01 +04:00
my $ fedora_ds_inf = "$ldapdir/fedorads.inf" ;
my $ fedora_ds_initial_ldif = "$ldapdir/fedorads-initial.ldif" ;
#Make the subdirectory be as fedora DS would expect
my $ fedora_ds_dir = "$ldapdir/slapd-samba4" ;
my $ pidfile = "$fedora_ds_dir/logs/slapd-samba4.pid" ;
open ( CONF , ">$fedora_ds_inf" ) ;
print CONF "
[ General ]
SuiteSpotUserID = $ root
2007-04-17 05:06:10 +04:00
FullMachineName = localhost
2007-04-17 04:30:01 +04:00
ServerRoot = $ ldapdir
[ slapd ]
ldapifilepath = $ ldapdir / ldapi
Suffix = $ basedn
2007-04-17 05:06:10 +04:00
RootDN = cn = Manager , $ basedn
RootDNPwd = $ password
ServerIdentifier = samba4
2007-04-24 11:57:44 +04:00
#InstallLdifFile=$fedora_ds_initial_ldif
2007-04-17 04:30:01 +04:00
inst_dir = $ fedora_ds_dir
config_dir = $ fedora_ds_dir
schema_dir = $ fedora_ds_dir / schema
lock_dir = $ fedora_ds_dir / lock
log_dir = $ fedora_ds_dir / logs
run_dir = $ fedora_ds_dir / logs
db_dir = $ fedora_ds_dir / db
bak_dir = $ fedora_ds_dir / bak
tmp_dir = $ fedora_ds_dir / tmp
ldif_dir = $ fedora_ds_dir / ldif
cert_dir = $ fedora_ds_dir
start_server = 0
2007-05-21 08:10:13 +04:00
install_full_schema = 0
2007-04-17 04:30:01 +04:00
" ;
close ( CONF ) ;
2007-04-17 04:53:07 +04:00
open ( LDIF , ">$fedora_ds_initial_ldif" ) ;
2007-04-17 04:30:01 +04:00
2007-04-24 11:57:44 +04:00
my $ dir = getcwd ( ) ;
chdir "$ENV{FEDORA_DS_PREFIX}/bin" || die ;
if ( system ( "perl $ENV{FEDORA_DS_PREFIX}/bin/ds_newinst.pl $fedora_ds_inf >&2" ) != 0 ) {
chdir $ dir ;
die ( "perl $ENV{FEDORA_DS_PREFIX}/bin/ds_newinst.pl $fedora_ds_inf FAILED: $?" ) ;
}
chdir $ dir || die ;
2007-04-23 11:33:15 +04:00
2007-04-24 11:57:44 +04:00
open ( LDIF , ">>$fedora_ds_dir/dse.ldif" ) ;
print LDIF " dn: cn = \ " cn = Configuration , $ basedn \ " , cn = mapping tree , cn = config
2007-04-23 11:33:15 +04:00
objectclass: top
objectclass: extensibleObject
objectclass: nsMappingTree
nsslapd - state: backend
nsslapd - backend: configData
cn: cn = Configuration , $ basedn
dn: cn = configData , cn = ldbm database , cn = plugins , cn = config
objectclass: extensibleObject
objectclass: nsBackendInstance
nsslapd - suffix: cn = Configuration , $ basedn
2007-04-24 11:57:44 +04:00
cn: configData
2007-04-23 11:33:15 +04:00
dn: cn = \ " cn = Schema , cn = Configuration , $ basedn \ " , cn = mapping tree , cn = config
objectclass: top
objectclass: extensibleObject
objectclass: nsMappingTree
nsslapd - state: backend
nsslapd - backend: schemaData
cn: cn = Schema , cn = Configuration , $ basedn
dn: cn = schemaData , cn = ldbm database , cn = plugins , cn = config
objectclass: extensibleObject
objectclass: nsBackendInstance
nsslapd - suffix: cn = Schema , cn = Configuration , $ basedn
2007-04-24 11:57:44 +04:00
cn: schemaData
2007-04-17 04:30:01 +04:00
" ;
2007-04-17 04:53:07 +04:00
close ( LDIF ) ;
2007-04-17 04:30:01 +04:00
2007-04-22 01:09:56 +04:00
system ( "$self->{bindir}/ad2oLschema $configuration -H $privatedir/sam.ldb --option=convert:target=fedora-ds -I $self->{setupdir}/schema-map-fedora-ds-1.0 -O $fedora_ds_dir/schema/99_ad.ldif >&2" ) == 0 or die ( "schema conversion for Fedora DS failed" ) ;
2007-04-17 04:30:01 +04:00
return ( $ fedora_ds_dir , $ pidfile ) ;
}
2007-04-23 11:33:15 +04:00
sub write_openldap_dbconfig ($) {
my ( $ ldapdbdir ) = @ _ ;
open ( CONF , ">$ldapdbdir/DB_CONFIG" ) ;
print CONF "
#
# Set the database in memory cache size.
#
set_cachesize 0 524288 0
#
# Set database flags (this is a test environment, we don't need to fsync()).
#
set_flags DB_TXN_NOSYNC
#
# Set log values.
#
set_lg_regionmax 104857
set_lg_max 1048576
set_lg_bsize 209715
set_lg_dir $ ldapdbdir / bdb - logs
#
# Set temporary file creation directory.
#
set_tmp_dir $ ldapdbdir / tmp
" ;
close ( CONF ) ;
}
2007-04-17 04:30:01 +04:00
sub mk_openldap ($$$$$$$$)
{
my ( $ self , $ ldapdir , $ basedn , $ password , $ privatedir , $ dnsname , $ configuration , $ provision_options ) = @ _ ;
my $ slapd_conf = "$ldapdir/slapd.conf" ;
my $ pidfile = "$ldapdir/slapd.pid" ;
my $ modconf = "$ldapdir/modules.conf" ;
2007-04-23 11:33:15 +04:00
mkdir ( $ _ , 0777 ) foreach ( $ ldapdir , "$ldapdir/db" , "$ldapdir/db/user" , "$ldapdir/db/config" , "$ldapdir/db/schema" , "$ldapdir/db/bdb-logs" ,
2007-04-17 04:30:01 +04:00
"$ldapdir/db/tmp" ) ;
open ( CONF , ">$slapd_conf" ) ;
print CONF "
loglevel 0
include $ ldapdir / ad . schema
pidfile $ pidfile
argsfile $ ldapdir / slapd . args
sasl - realm $ dnsname
access to * by * write
allow update_anon
authz - regexp
uid = ( [ ^ , ] * ) , cn = $ dnsname , cn = digest - md5 , cn = auth
ldap: // / $ basedn ? ? sub ? ( samAccountName = \ $ 1 )
authz - regexp
uid = ( [ ^ , ] * ) , cn = ( [ ^ , ] * ) , cn = digest - md5 , cn = auth
ldap: // / $ basedn ? ? sub ? ( samAccountName = \ $ 1 )
include $ modconf
defaultsearchbase \ " $ basedn \ "
backend bdb
2007-04-23 11:33:15 +04:00
database bdb
suffix \ " cn = Schema , cn = Configuration , $ basedn \ "
directory $ ldapdir /db/sc hema
index objectClass eq
index samAccountName eq
index name eq
index objectCategory eq
index lDAPDisplayName eq
index subClassOf eq
database bdb
suffix \ " cn = Configuration , $ basedn \ "
directory $ ldapdir /db/co nfig
index objectClass eq
index samAccountName eq
index name eq
index objectSid eq
index objectCategory eq
index nCName eq pres
index subClassOf eq
index dnsRoot eq
index nETBIOSName eq pres
2007-04-17 04:30:01 +04:00
database bdb
suffix \ " $ basedn \ "
rootdn \ " cn = Manager , $ basedn \ "
rootpw $ password
2007-04-23 11:33:15 +04:00
directory $ ldapdir /db/ user
2007-04-17 04:30:01 +04:00
index objectClass eq
index samAccountName eq
index name eq
index objectSid eq
index objectCategory eq
index member eq
index uidNumber eq
index gidNumber eq
index unixName eq
index privilege eq
index nCName eq pres
index lDAPDisplayName eq
index subClassOf eq
index dnsRoot eq
index nETBIOSName eq pres
#syncprov is stable in OpenLDAP 2.3, and available in 2.2.
#We only need this for the contextCSN attribute anyway....
overlay syncprov
syncprov - checkpoint 100 10
syncprov - sessionlog 100
" ;
close ( CONF ) ;
2007-04-23 11:33:15 +04:00
write_openldap_dbconfig ( "$ldapdir/db/user" ) ;
write_openldap_dbconfig ( "$ldapdir/db/config" ) ;
write_openldap_dbconfig ( "$ldapdir/db/schema" ) ;
2007-04-17 04:30:01 +04:00
#This uses the provision we just did, to read out the schema
2007-04-22 01:09:56 +04:00
system ( "$self->{bindir}/ad2oLschema $configuration -H $privatedir/sam.ldb -I $self->{setupdir}/schema-map-openldap-2.3 -O $ldapdir/ad.schema >&2" ) == 0 or die ( "schema conversion for OpenLDAP failed" ) ;
2007-04-17 04:30:01 +04:00
#Now create an LDAP baseDN
2007-04-22 01:09:56 +04:00
system ( "$self->{bindir}/smbscript $self->{setupdir}/provision $provision_options --ldap-base >&2" ) == 0 or die ( "creating an OpenLDAP basedn failed" ) ;
2007-04-17 04:30:01 +04:00
my $ oldpath = $ ENV { PATH } ;
$ ENV { PATH } = "/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}" ;
unlink ( $ modconf ) ;
open ( CONF , ">$modconf" ) ; close ( CONF ) ;
if ( system ( "slaptest -u -f $slapd_conf >&2" ) != 0 ) {
open ( CONF , ">$modconf" ) ;
# enable slapd modules
print CONF "
modulepath /usr/ lib / ldap
moduleload back_bdb
moduleload syncprov
" ;
close ( CONF ) ;
}
system ( "slaptest -u -f $slapd_conf" ) == 0 or die ( "slaptest still fails after adding modules" ) ;
2007-05-29 16:18:41 +04:00
system ( "slapadd -b cn=Configuration,$basedn -f $slapd_conf -l $ldapdir/$dnsname-config.ldif >/dev/null" ) == 0 or die ( "slapadd failed" ) ;
system ( "slapadd -b cn=Schema,cn=Configuration,$basedn -f $slapd_conf -l $ldapdir/$dnsname-schema.ldif >/dev/null" ) == 0 or die ( "slapadd failed" ) ;
2007-04-17 04:30:01 +04:00
2007-05-21 16:03:15 +04:00
system ( "slaptest -u -f $slapd_conf >/dev/null" ) == 0 or
2007-04-17 04:30:01 +04:00
die ( "slaptest after database load failed" ) ;
$ ENV { PATH } = $ oldpath ;
return ( $ slapd_conf , $ pidfile ) ;
}
2007-04-29 17:54:51 +04:00
sub provision ($$$$$$)
2007-04-17 04:30:01 +04:00
{
2007-04-29 17:54:51 +04:00
my ( $ self , $ prefix , $ server_role , $ netbiosname , $ netbiosalias , $ swiface , $ password ) = @ _ ;
2007-04-17 04:30:01 +04:00
my $ smbd_loglevel = 1 ;
my $ username = "administrator" ;
2007-04-29 17:54:51 +04:00
my $ domain = "SAMBADOMAIN" ;
2007-04-17 04:30:01 +04:00
my $ realm = "SAMBA.EXAMPLE.COM" ;
my $ dnsname = "samba.example.com" ;
my $ basedn = "dc=samba,dc=example,dc=com" ;
my $ root = ( $ ENV { USER } or $ ENV { LOGNAME } or `whoami` ) ;
2007-04-30 00:37:59 +04:00
my $ srcdir = "$RealBin/.." ;
2007-04-20 15:40:44 +04:00
- d $ prefix or mkdir ( $ prefix , 0777 ) or die ( "Unable to create $prefix" ) ;
2007-04-17 17:06:00 +04:00
my $ prefix_abs = abs_path ( $ prefix ) ;
2007-04-17 04:30:01 +04:00
my $ tmpdir = "$prefix_abs/tmp" ;
my $ etcdir = "$prefix_abs/etc" ;
my $ piddir = "$prefix_abs/pid" ;
my $ conffile = "$etcdir/smb.conf" ;
my $ krb5_config = "$etcdir/krb5.conf" ;
my $ privatedir = "$prefix_abs/private" ;
my $ ncalrpcdir = "$prefix_abs/ncalrpc" ;
2007-04-17 19:33:50 +04:00
my $ lockdir = "$prefix_abs/lockdir" ;
2007-04-17 04:30:01 +04:00
my $ winbindd_socket_dir = "$prefix_abs/winbind_socket" ;
2007-04-17 19:33:50 +04:00
2007-04-17 04:30:01 +04:00
my $ configuration = "--configfile=$conffile" ;
2007-05-29 16:18:41 +04:00
my $ ldapdir = "$privatedir/ldap" ;
2007-04-17 04:30:01 +04:00
my $ tlsdir = "$privatedir/tls" ;
2007-04-17 19:33:50 +04:00
my $ ifaceipv4 = "127.0.0.$swiface" ;
my $ interfaces = "$ifaceipv4/8" ;
2007-04-17 04:30:01 +04:00
( system ( "rm -rf $prefix/*" ) == 0 ) or die ( "Unable to clean up" ) ;
2007-04-20 15:40:44 +04:00
mkdir ( $ _ , 0777 ) foreach ( $ privatedir , $ etcdir , $ piddir , $ ncalrpcdir , $ lockdir ,
2007-04-17 04:30:01 +04:00
$ tmpdir ) ;
2007-05-01 07:28:12 +04:00
my $ auth_methods = "anonymous sam_ignoredomain" ;
$ auth_methods = "anonymous sam winbind" if $ server_role eq "member server" ;
my $ localdomain = $ domain ;
$ localdomain = $ netbiosname if $ server_role eq "member server" ;
my $ localrealm = $ realm ;
$ localrealm = $ netbiosname if $ server_role eq "member server" ;
2007-04-17 04:30:01 +04:00
open ( CONFFILE , ">$conffile" ) ;
print CONFFILE "
[ global ]
netbios name = $ netbiosname
2007-04-29 17:54:51 +04:00
netbios aliases = $ netbiosalias
2007-04-17 04:30:01 +04:00
workgroup = $ domain
realm = $ realm
private dir = $ privatedir
pid directory = $ piddir
ncalrpc dir = $ ncalrpcdir
lock dir = $ lockdir
setup directory = $ self - > { setupdir }
js include = $ srcdir /scripting/ libjs
winbindd socket directory = $ winbindd_socket_dir
name resolve order = bcast
2007-04-17 19:33:50 +04:00
interfaces = $ interfaces
2007-04-17 04:30:01 +04:00
tls dh params file = $ tlsdir / dhparms . pem
panic action = $ srcdir /script/g db_backtrace \ % PID % \ % PROG %
wins support = yes
server role = $ server_role
2007-05-01 07:28:12 +04:00
auth methods = $ auth_methods
2007-04-17 04:30:01 +04:00
max xmit = 32 K
server max protocol = SMB2
notify:inotify = false
ldb:nosync = true
system : anonymous = true
#We don't want to pass our self-tests if the PAC code is wrong
gensec:require_pac = true
log level = $ smbd_loglevel
[ tmp ]
path = $ tmpdir
read only = no
ntvfs handler = posix
posix:sharedelay = 100000
posix:eadb = $ lockdir / eadb . tdb
[ cifs ]
read only = no
ntvfs handler = cifs
2007-04-17 07:52:08 +04:00
cifs:server = $ netbiosname
2007-04-17 04:30:01 +04:00
cifs:share = tmp
2007-04-17 07:52:08 +04:00
#There is no username specified here, instead the client is expected
#to log in with kerberos, and smbd will used delegated credentials.
2007-04-17 04:30:01 +04:00
[ simple ]
path = $ tmpdir
read only = no
ntvfs handler = simple
2007-04-30 17:17:19 +04:00
[ cifsposix ]
2007-04-17 04:30:01 +04:00
copy = simple
ntvfs handler = cifsposix
" ;
close ( CONFFILE ) ;
die ( "Unable to create key blobs" ) if
( system ( "TLSDIR=$tlsdir $RealBin/mk-keyblobs.sh" ) != 0 ) ;
open ( KRB5CONF , ">$krb5_config" ) ;
print KRB5CONF "
#Generated krb5.conf for $realm
[ libdefaults ]
default_realm = $ realm
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24 h
forwardable = yes
[ realms ]
$ realm = {
kdc = 127.0 .0 .1 : 88
admin_server = 127.0 .0 .1 : 88
default_domain = $ dnsname
}
$ dnsname = {
kdc = 127.0 .0 .1 : 88
admin_server = 127.0 .0 .1 : 88
default_domain = $ dnsname
}
$ domain = {
kdc = 127.0 .0 .1 : 88
admin_server = 127.0 .0 .1 : 88
default_domain = $ dnsname
}
[ appdefaults ]
pkinit_anchors = FILE: $ tlsdir / ca . pem
[ kdc ]
enable - pkinit = true
pkinit_identity = FILE: $ tlsdir /kdc.pem,$tlsdir/ key . pem
pkinit_anchors = FILE: $ tlsdir / ca . pem
[ domain_realm ]
. $ dnsname = $ realm
" ;
close ( KRB5CONF ) ;
#Ensure the config file is valid before we start
if ( system ( "$self->{bindir}/testparm $configuration -v --suppress-prompt >/dev/null 2>&1" ) != 0 ) {
2007-04-30 17:03:03 +04:00
system ( "$self->{bindir}/testparm -v --suppress-prompt $configuration >&2" ) ;
2007-04-22 01:09:56 +04:00
die ( "Failed to create a valid smb.conf configuration!" ) ;
2007-04-17 04:30:01 +04:00
}
2007-05-01 07:30:04 +04:00
( system ( "($self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$netbiosname\" ) >/dev/null 2>&1" ) == 0 ) or die ( "Failed to create a valid smb.conf configuration!" ) ;
2007-04-17 04:30:01 +04:00
my @ provision_options = ( $ configuration ) ;
push ( @ provision_options , "--host-name=$netbiosname" ) ;
2007-04-17 19:33:50 +04:00
push ( @ provision_options , "--host-ip=$ifaceipv4" ) ;
2007-04-17 04:30:01 +04:00
push ( @ provision_options , "--quiet" ) ;
2007-05-01 07:28:12 +04:00
push ( @ provision_options , "--domain $localdomain" ) ;
push ( @ provision_options , "--realm $localrealm" ) ;
2007-04-17 04:30:01 +04:00
push ( @ provision_options , "--adminpass $password" ) ;
2007-04-28 13:01:52 +04:00
push ( @ provision_options , "--krbtgtpass krbtgt$password" ) ;
push ( @ provision_options , "--machinepass machine$password" ) ;
2007-04-17 04:30:01 +04:00
push ( @ provision_options , "--root=$root" ) ;
push ( @ provision_options , "--simple-bind-dn=cn=Manager,$basedn" ) ;
push ( @ provision_options , "--password=$password" ) ;
push ( @ provision_options , "--root=$root" ) ;
( system ( "$self->{bindir}/smbscript $self->{setupdir}/provision " . join ( ' ' , @ provision_options ) . ">&2" ) == 0 ) or die ( "Unable to provision" ) ;
my $ ldap_uri = "$ldapdir/ldapi" ;
$ ldap_uri =~ s | / | % 2F | g ;
$ ldap_uri = "ldapi://$ldap_uri" ;
my $ ret = {
KRB5_CONFIG = > $ krb5_config ,
PIDDIR = > $ piddir ,
2007-04-29 17:54:51 +04:00
SERVER = > $ netbiosname ,
2007-04-28 12:57:06 +04:00
SERVER_IP = > $ ifaceipv4 ,
2007-04-17 04:30:01 +04:00
NETBIOSNAME = > $ netbiosname ,
2007-04-29 17:54:51 +04:00
NETBIOSALIAS = > $ netbiosalias ,
2007-04-17 04:30:01 +04:00
LDAP_URI = > $ ldap_uri ,
DOMAIN = > $ domain ,
USERNAME = > $ username ,
REALM = > $ realm ,
PASSWORD = > $ password ,
LDAPDIR = > $ ldapdir ,
WINBINDD_SOCKET_DIR = > $ winbindd_socket_dir ,
NCALRPCDIR = > $ ncalrpcdir ,
2007-04-17 19:33:50 +04:00
CONFIGURATION = > $ configuration ,
SOCKET_WRAPPER_DEFAULT_IFACE = > $ swiface
2007-04-17 04:30:01 +04:00
} ;
2007-04-23 11:33:15 +04:00
if ( defined ( $ self - > { ldap } ) ) {
if ( $ self - > { ldap } eq "openldap" ) {
( $ ret - > { SLAPD_CONF } , $ ret - > { OPENLDAP_PIDFILE } ) = $ self - > mk_openldap ( $ ldapdir , $ basedn , $ password , $ privatedir , $ dnsname , $ configuration , join ( ' ' , @ provision_options ) ) or die ( "Unable to create openldap directories" ) ;
} elsif ( $ self - > { ldap } eq "fedora" ) {
( $ ret - > { FEDORA_DS_DIR } , $ ret - > { FEDORA_DS_PIDFILE } ) = $ self - > mk_fedora ( $ ldapdir , $ basedn , $ root , $ password , $ privatedir , $ configuration ) or die ( "Unable to create fedora ds directories" ) ;
push ( @ provision_options , "--ldap-module=nsuniqueid" ) ;
}
$ self - > slapd_start ( $ ret ) or
die ( "couldn't start slapd" ) ;
2007-04-24 01:56:23 +04:00
$ ret - > { PROVISION_OPTIONS } = join ( ' ' , @ provision_options ) ;
2007-04-23 11:33:15 +04:00
print "LDAP PROVISIONING..." ;
$ self - > provision_ldap ( $ ret ) ;
$ self - > slapd_stop ( $ ret ) or
die ( "couldn't stop slapd" ) ;
2007-04-24 01:56:23 +04:00
} else {
$ ret - > { PROVISION_OPTIONS } = join ( ' ' , @ provision_options ) ;
}
2007-04-17 04:30:01 +04:00
return $ ret ;
}
2007-04-12 12:33:35 +04:00
sub provision_member ($$$)
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2007-04-17 04:30:01 +04:00
print "PROVISIONING MEMBER..." ;
2007-04-29 17:54:51 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"member server" ,
"localmember3" ,
"localmember" ,
3 ,
"localmemberpass" ) ;
2007-04-17 04:30:01 +04:00
$ ret or die ( "Unable to provision" ) ;
2007-04-12 12:33:35 +04:00
2007-04-30 15:16:50 +04:00
my $ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
$ cmd . = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" " ;
$ cmd . = "$self->{bindir}/net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member" ;
$ cmd . = " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}" ;
system ( $ cmd ) == 0 or die ( "Join failed\n$cmd" ) ;
2007-04-16 14:44:26 +04:00
2007-04-17 04:30:01 +04:00
$ ret - > { SMBD_TEST_FIFO } = "$prefix/smbd_test.fifo" ;
$ ret - > { SMBD_TEST_LOG } = "$prefix/smbd_test.log" ;
2007-04-18 18:02:26 +04:00
$ ret - > { SMBD_TEST_LOG_POS } = 0 ;
2007-04-28 12:57:06 +04:00
$ ret - > { DC_SERVER } = $ dcvars - > { SERVER } ;
$ ret - > { DC_SERVER_IP } = $ dcvars - > { SERVER_IP } ;
$ ret - > { DC_NETBIOSNAME } = $ dcvars - > { NETBIOSNAME } ;
$ ret - > { DC_NETBIOSALIAS } = $ dcvars - > { NETBIOSALIAS } ;
$ ret - > { DC_USERNAME } = $ dcvars - > { USERNAME } ;
$ ret - > { DC_PASSWORD } = $ dcvars - > { PASSWORD } ;
2007-04-17 04:30:01 +04:00
return $ ret ;
2007-04-12 12:33:35 +04:00
}
sub provision_dc ($$)
2007-03-06 00:28:55 +03:00
{
2007-04-11 00:19:31 +04:00
my ( $ self , $ prefix ) = @ _ ;
2007-03-21 18:57:07 +03:00
2007-04-17 04:30:01 +04:00
print "PROVISIONING DC..." ;
2007-04-29 17:54:51 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
"localdc1" ,
"localdc" ,
1 ,
"localdcpass" ) ;
2007-04-17 04:30:01 +04:00
$ self - > add_wins_config ( "$prefix/private" ) or
die ( "Unable to add wins configuration" ) ;
$ ret - > { SMBD_TEST_FIFO } = "$prefix/smbd_test.fifo" ;
$ ret - > { SMBD_TEST_LOG } = "$prefix/smbd_test.log" ;
2007-04-18 18:02:26 +04:00
$ ret - > { SMBD_TEST_LOG_POS } = 0 ;
2007-04-17 04:30:01 +04:00
return $ ret ;
2007-03-06 00:28:55 +03:00
}
2007-04-11 09:01:02 +04:00
sub provision_ldap ($$)
2007-03-21 18:57:07 +03:00
{
2007-04-11 09:01:02 +04:00
my ( $ self , $ envvars ) = @ _ ;
2007-04-17 04:30:01 +04:00
my $ provision_aci = "" ;
if ( $ self - > { ldap } eq "fedora" ) {
#it is easier to base64 encode this than correctly escape it:
# (targetattr = "*") (version 3.0;acl "full access to all by all";allow (all)(userdn = "ldap:///anyone");)
$ provision_aci = "--aci=aci:: KHRhcmdldGF0dHIgPSAiKiIpICh2ZXJzaW9uIDMuMDthY2wgImZ1bGwgYWNjZXNzIHRvIGFsbCBieSBhbGwiO2FsbG93IChhbGwpKHVzZXJkbiA9ICJsZGFwOi8vL2FueW9uZSIpOykK" ;
}
system ( "$self->{bindir}/smbscript $self->{setupdir}/provision $envvars->{PROVISION_OPTIONS} \"$provision_aci\" --ldap-backend=$envvars->{LDAP_URI}" ) and
die ( "LDAP PROVISIONING failed: $self->{bindir}/smbscript $self->{setupdir}/provision $envvars->{PROVISION_OPTIONS} \"$provision_aci\" --ldap-backend=$envvars->{LDAP_URI}" ) ;
2007-03-21 18:57:07 +03:00
}
2007-04-11 00:19:31 +04:00
sub teardown_env ($$)
2007-03-21 18:57:07 +03:00
{
2007-04-11 00:19:31 +04:00
my ( $ self , $ envvars ) = @ _ ;
2007-03-21 18:57:07 +03:00
close ( DATA ) ;
sleep ( 2 ) ;
my $ failed = $? >> 8 ;
2007-04-11 00:19:31 +04:00
if ( - f "$envvars->{PIDDIR}/smbd.pid" ) {
open ( IN , "<$envvars->{PIDDIR}/smbd.pid" ) or die ( "unable to open smbd pid file" ) ;
2007-03-21 18:57:07 +03:00
kill 9 , <IN> ;
close ( IN ) ;
}
2007-04-11 00:19:31 +04:00
$ self - > slapd_stop ( $ envvars ) if ( $ self - > { ldap } ) ;
2007-03-21 18:57:07 +03:00
2007-04-19 20:37:11 +04:00
print $ self - > getlog_env ( $ envvars ) ;
2007-03-21 18:57:07 +03:00
return $ failed ;
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
my $ title = "SMBD LOG of: $envvars->{NETBIOSNAME}\n" ;
my $ out = $ title ;
open ( LOG , "<$envvars->{SMBD_TEST_LOG}" ) ;
seek ( LOG , $ envvars - > { SMBD_TEST_LOG_POS } , SEEK_SET ) ;
while ( <LOG> ) {
$ out . = $ _ ;
}
$ envvars - > { SMBD_TEST_LOG_POS } = tell ( LOG ) ;
close ( LOG ) ;
return "" if $ out eq $ title ;
return $ out ;
}
2007-04-19 18:54:09 +04:00
sub check_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
2007-04-19 19:03:35 +04:00
return 1 if ( - p $ envvars - > { SMBD_TEST_FIFO } ) ;
2007-04-19 20:37:11 +04:00
print $ self - > getlog_env ( $ envvars ) ;
2007-04-19 19:03:35 +04:00
return 0 ;
2007-04-19 18:54:09 +04:00
}
2007-04-11 07:45:39 +04:00
sub setup_env ($$$)
2007-03-06 00:28:55 +03:00
{
2007-04-11 07:45:39 +04:00
my ( $ self , $ envname , $ path ) = @ _ ;
2007-04-18 18:02:26 +04:00
2007-04-11 00:19:31 +04:00
if ( $ envname eq "dc" ) {
2007-04-11 07:45:39 +04:00
return $ self - > setup_dc ( "$path/dc" ) ;
2007-04-12 12:33:35 +04:00
} elsif ( $ envname eq "member" ) {
if ( not defined ( $ self - > { vars } - > { dc } ) ) {
$ self - > setup_dc ( "$path/dc" ) ;
}
return $ self - > setup_member ( "$path/member" , $ self - > { vars } - > { dc } ) ;
2007-04-11 00:19:31 +04:00
} else {
2007-04-12 12:33:35 +04:00
die ( "Samba4 can't provide environment '$envname'" ) ;
2007-04-11 00:19:31 +04:00
}
}
2007-04-12 12:33:35 +04:00
sub setup_member ($$$$)
{
my ( $ self , $ path , $ dc_vars ) = @ _ ;
my $ env = $ self - > provision_member ( $ path , $ dc_vars ) ;
2007-04-30 13:35:32 +04:00
$ self - > check_or_start ( $ env , ( $ ENV { SMBD_MAXTIME } or 7500 ) ) ;
2007-04-12 12:33:35 +04:00
$ self - > wait_for_start ( $ env ) ;
return $ env ;
}
2007-04-11 07:45:39 +04:00
sub setup_dc ($$)
2007-04-11 00:19:31 +04:00
{
2007-04-11 07:45:39 +04:00
my ( $ self , $ path ) = @ _ ;
2007-04-04 16:23:10 +04:00
2007-04-12 12:33:35 +04:00
my $ env = $ self - > provision_dc ( $ path ) ;
2007-04-04 16:23:10 +04:00
2007-04-11 07:45:39 +04:00
$ self - > check_or_start ( $ env ,
2007-04-30 13:35:32 +04:00
( $ ENV { SMBD_MAXTIME } or 7500 ) ) ;
2007-04-04 16:23:10 +04:00
$ self - > wait_for_start ( $ env ) ;
2007-04-12 12:33:35 +04:00
$ self - > { vars } - > { dc } = $ env ;
2007-04-04 16:23:10 +04:00
return $ env ;
2007-03-06 00:28:55 +03:00
}
2007-04-11 00:19:31 +04:00
sub stop ($)
{
my ( $ self ) = @ _ ;
}
2007-03-06 00:28:55 +03:00
1 ;