2007-03-21 18:57:07 +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 Samba3 ;
use strict ;
2007-04-18 04:12:39 +04:00
use Cwd qw( abs_path ) ;
2007-03-21 18:57:07 +03:00
use FindBin qw( $RealBin ) ;
2007-09-02 03:11:48 +04:00
use POSIX ;
2011-04-27 05:19:20 +04:00
use target::Samba ;
2007-03-21 18:57:07 +03:00
2012-02-14 02:04:16 +04:00
sub have_ads ($) {
2012-02-18 03:35:24 +04:00
my ( $ self ) = @ _ ;
2012-02-14 02:04:16 +04:00
my $ found_ads = 0 ;
2012-02-18 03:35:24 +04:00
my $ smbd_build_options = Samba:: bindir_path ( $ self , "smbd" ) . " -b|" ;
open ( IN , $ smbd_build_options ) or die ( "Unable to run $smbd_build_options: $!" ) ;
while ( <IN> ) {
if ( /WITH_ADS/ ) {
$ found_ads = 1 ;
}
}
close IN ;
2012-02-14 02:04:16 +04:00
# If we were not built with ADS support, pretend we were never even available
2013-07-03 23:49:43 +04:00
print "smbd does not have ADS support\n" unless $ found_ads ;
2012-02-14 02:04:16 +04:00
return $ found_ads ;
}
2013-11-18 17:54:26 +04:00
# return smb.conf parameters applicable to @path, based on the underlying
# filesystem type
sub get_fs_specific_conf ($$)
{
my ( $ self , $ path ) = @ _ ;
my $ mods = "" ;
my $ stat_out = `stat --file-system $path` or return "" ;
if ( $ stat_out =~ m/Type:\s+btrfs/ ) {
$ mods . = "btrfs " ;
}
if ( $ mods ) {
return "vfs objects = $mods" ;
}
return undef ;
}
2007-04-18 04:12:39 +04:00
sub new ($$) {
2012-01-26 02:42:27 +04:00
my ( $ classname , $ bindir , $ binary_mapping , $ srcdir , $ server_maxtime ) = @ _ ;
2011-04-15 06:27:30 +04:00
my $ self = { vars = > { } ,
bindir = > $ bindir ,
binary_mapping = > $ binary_mapping ,
srcdir = > $ srcdir ,
2011-04-19 07:50:40 +04:00
server_maxtime = > $ server_maxtime
2011-02-22 03:56:18 +03:00
} ;
2007-03-21 18:57:07 +03:00
bless $ self ;
return $ self ;
}
2007-04-18 04:12:39 +04:00
sub teardown_env ($$)
2007-03-21 18:57:07 +03:00
{
2007-04-18 04:12:39 +04:00
my ( $ self , $ envvars ) = @ _ ;
2012-03-02 11:20:45 +04:00
my $ count = 0 ;
2013-11-18 17:54:26 +04:00
2012-03-02 11:20:45 +04:00
# This should cause smbd to terminate gracefully
close ( $ envvars - > { STDIN_PIPE } ) ;
2007-03-21 18:57:07 +03:00
2012-03-04 11:34:34 +04:00
my $ smbdpid = $ envvars - > { SMBD_TL_PID } ;
my $ nmbdpid = $ envvars - > { NMBD_TL_PID } ;
my $ winbinddpid = $ envvars - > { WINBINDD_TL_PID } ;
# This should give it time to write out the gcov data
until ( $ count > 20 ) {
2012-03-05 04:12:00 +04:00
my $ smbdchild = Samba:: cleanup_child ( $ smbdpid , "smbd" ) ;
my $ nmbdchild = Samba:: cleanup_child ( $ nmbdpid , "nmbd" ) ;
my $ winbinddchild = Samba:: cleanup_child ( $ winbinddpid , "winbindd" ) ;
if ( $ smbdchild == - 1
&& $ nmbdchild == - 1
&& $ winbinddchild == - 1 ) {
2012-03-04 11:34:34 +04:00
last ;
}
2012-03-02 11:20:45 +04:00
sleep ( 1 ) ;
$ count + + ;
}
2012-03-04 11:34:34 +04:00
if ( $ count <= 20 && kill ( 0 , $ smbdpid , $ nmbdpid , $ winbinddpid ) == 0 ) {
2012-03-02 11:20:45 +04:00
return ;
}
2007-09-02 21:47:35 +04:00
$ self - > stop_sig_term ( $ smbdpid ) ;
$ self - > stop_sig_term ( $ nmbdpid ) ;
2009-01-28 19:28:51 +03:00
$ self - > stop_sig_term ( $ winbinddpid ) ;
2009-03-20 16:25:15 +03:00
2012-03-02 11:20:45 +04:00
$ count = 0 ;
2012-03-04 11:34:34 +04:00
until ( $ count > 10 ) {
2012-03-05 04:12:00 +04:00
my $ smbdchild = Samba:: cleanup_child ( $ smbdpid , "smbd" ) ;
my $ nmbdchild = Samba:: cleanup_child ( $ nmbdpid , "nmbd" ) ;
my $ winbinddchild = Samba:: cleanup_child ( $ winbinddpid , "winbindd" ) ;
if ( $ smbdchild == - 1
&& $ nmbdchild == - 1
&& $ winbinddchild == - 1 ) {
2012-03-04 11:34:34 +04:00
last ;
}
2012-03-02 11:20:45 +04:00
sleep ( 1 ) ;
$ count + + ;
}
2012-03-04 11:34:34 +04:00
if ( $ count <= 10 && kill ( 0 , $ smbdpid , $ nmbdpid , $ winbinddpid ) == 0 ) {
2012-03-02 11:20:45 +04:00
return ;
}
2009-03-20 16:25:15 +03:00
2012-03-02 11:20:45 +04:00
warn ( "timelimit process did not quit on SIGTERM, sending SIGKILL" ) ;
2007-09-02 21:47:35 +04:00
$ self - > stop_sig_kill ( $ smbdpid ) ;
$ self - > stop_sig_kill ( $ nmbdpid ) ;
2009-01-28 19:28:51 +03:00
$ self - > stop_sig_kill ( $ winbinddpid ) ;
2007-04-18 04:12:39 +04:00
return 0 ;
}
2007-09-02 03:11:48 +04:00
sub getlog_env_app ($$$)
{
my ( $ self , $ envvars , $ name ) = @ _ ;
my $ title = "$name LOG of: $envvars->{NETBIOSNAME}\n" ;
my $ out = $ title ;
open ( LOG , "<" . $ envvars - > { $ name . "_TEST_LOG" } ) ;
seek ( LOG , $ envvars - > { $ name . "_TEST_LOG_POS" } , SEEK_SET ) ;
while ( <LOG> ) {
$ out . = $ _ ;
}
$ envvars - > { $ name . "_TEST_LOG_POS" } = tell ( LOG ) ;
close ( LOG ) ;
return "" if $ out eq $ title ;
return $ out ;
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
2007-09-30 13:08:10 +04:00
my $ ret = "" ;
2007-04-18 18:02:26 +04:00
2007-09-30 13:08:10 +04:00
$ ret . = $ self - > getlog_env_app ( $ envvars , "SMBD" ) ;
$ ret . = $ self - > getlog_env_app ( $ envvars , "NMBD" ) ;
2009-01-28 19:28:51 +03:00
$ ret . = $ self - > getlog_env_app ( $ envvars , "WINBINDD" ) ;
2007-09-30 13:08:10 +04:00
return $ ret ;
2007-04-18 18:02:26 +04:00
}
2007-04-19 18:54:09 +04:00
sub check_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
2012-03-02 11:20:45 +04:00
my $ childpid = waitpid ( - 1 , WNOHANG ) ;
2007-04-19 18:54:09 +04:00
# TODO ...
return 1 ;
}
2007-04-18 04:12:39 +04:00
sub setup_env ($$$)
{
my ( $ self , $ envname , $ path ) = @ _ ;
2013-03-19 18:43:12 +04:00
$ ENV { ENVNAME } = $ envname ;
2012-02-15 01:55:05 +04:00
if ( defined ( $ self - > { vars } - > { $ envname } ) ) {
return $ self - > { vars } - > { $ envname } ;
}
2011-04-18 09:28:40 +04:00
if ( $ envname eq "s3dc" ) {
return $ self - > setup_s3dc ( "$path/s3dc" ) ;
2012-09-26 04:40:17 +04:00
} elsif ( $ envname eq "simpleserver" ) {
return $ self - > setup_simpleserver ( "$path/simpleserver" ) ;
2011-07-22 07:00:21 +04:00
} elsif ( $ envname eq "maptoguest" ) {
return $ self - > setup_maptoguest ( "$path/maptoguest" ) ;
2011-04-04 13:13:17 +04:00
} elsif ( $ envname eq "ktest" ) {
return $ self - > setup_ktest ( "$path/ktest" ) ;
2009-01-28 23:01:04 +03:00
} elsif ( $ envname eq "member" ) {
2011-04-18 09:28:40 +04:00
if ( not defined ( $ self - > { vars } - > { s3dc } ) ) {
if ( not defined ( $ self - > setup_s3dc ( "$path/s3dc" ) ) ) {
2011-04-12 03:05:34 +04:00
return undef ;
}
2009-01-28 23:01:04 +03:00
}
2011-04-18 09:28:40 +04:00
return $ self - > setup_member ( "$path/member" , $ self - > { vars } - > { s3dc } ) ;
2007-04-18 04:12:39 +04:00
} else {
2012-02-13 05:14:57 +04:00
return "UNKNOWN" ;
2007-04-18 04:12:39 +04:00
}
}
2011-04-18 09:28:40 +04:00
sub setup_s3dc ($$)
2007-04-18 04:12:39 +04:00
{
my ( $ self , $ path ) = @ _ ;
2007-03-21 18:57:07 +03:00
2011-04-18 09:28:40 +04:00
print "PROVISIONING S3DC..." ;
2009-01-28 22:30:16 +03:00
2011-04-18 09:28:40 +04:00
my $ s3dc_options = "
2009-01-28 22:30:16 +03:00
domain master = yes
domain logons = yes
2009-05-08 02:18:28 +04:00
lanman auth = yes
2012-03-06 15:04:55 +04:00
rpc_server:epmapper = external
rpc_server:spoolss = external
rpc_server:lsarpc = external
rpc_server:samr = external
rpc_server:netlogon = external
2012-03-07 14:39:14 +04:00
rpc_server:register_embedded_np = yes
2012-03-06 15:04:55 +04:00
rpc_daemon:epmd = fork
rpc_daemon:spoolssd = fork
rpc_daemon:lsasd = fork
2009-01-28 22:30:16 +03:00
" ;
my $ vars = $ self - > provision ( $ path ,
2011-04-18 09:28:40 +04:00
"LOCALS3DC2" ,
"locals3dc2pass" ,
$ s3dc_options ) ;
2007-04-18 04:12:39 +04:00
2011-04-12 03:05:34 +04:00
$ vars or return undef ;
2012-11-23 03:02:33 +04:00
if ( not $ self - > check_or_start ( $ vars , "yes" , "yes" , "yes" ) ) {
2011-04-12 03:05:34 +04:00
return undef ;
}
2007-04-18 04:12:39 +04:00
2011-02-21 08:01:44 +03:00
$ vars - > { DC_SERVER } = $ vars - > { SERVER } ;
$ vars - > { DC_SERVER_IP } = $ vars - > { SERVER_IP } ;
2014-06-19 19:21:16 +04:00
$ vars - > { DC_SERVER_IPV6 } = $ vars - > { SERVER_IPV6 } ;
2011-02-21 08:01:44 +03:00
$ vars - > { DC_NETBIOSNAME } = $ vars - > { NETBIOSNAME } ;
$ vars - > { DC_USERNAME } = $ vars - > { USERNAME } ;
$ vars - > { DC_PASSWORD } = $ vars - > { PASSWORD } ;
2011-04-18 09:28:40 +04:00
$ self - > { vars } - > { s3dc } = $ vars ;
2009-01-28 23:01:04 +03:00
2007-04-18 04:12:39 +04:00
return $ vars ;
}
2009-01-28 23:01:04 +03:00
sub setup_member ($$$)
{
2011-04-18 09:28:40 +04:00
my ( $ self , $ prefix , $ s3dcvars ) = @ _ ;
2014-09-09 11:47:05 +04:00
my $ count = 0 ;
my $ rc ;
2009-01-28 23:01:04 +03:00
print "PROVISIONING MEMBER..." ;
my $ member_options = "
security = domain
2009-03-06 18:35:34 +03:00
server signing = on
2013-05-13 13:14:26 +04:00
dbwrap_tdb_mutexes: * = yes
2009-01-28 23:01:04 +03:00
" ;
my $ ret = $ self - > provision ( $ prefix ,
"LOCALMEMBER3" ,
"localmember3pass" ,
$ member_options ) ;
2011-04-12 03:05:34 +04:00
$ ret or return undef ;
2009-01-28 23:01:04 +03:00
2014-09-09 11:47:05 +04:00
my $ nmblookup = Samba:: bindir_path ( $ self , "nmblookup" ) ;
do {
print "Waiting for the LOGON SERVER registration ...\n" ;
$ rc = system ( "$nmblookup $ret->{CONFIGURATION} $ret->{DOMAIN}\#1c" ) ;
if ( $ rc != 0 ) {
sleep ( 1 ) ;
}
$ count + + ;
} while ( $ rc != 0 && $ count < 10 ) ;
if ( $ count == 10 ) {
print "NMBD not reachable after 10 retries\n" ;
teardown_env ( $ self , $ ret ) ;
return 0 ;
}
2011-04-27 05:19:20 +04:00
my $ net = Samba:: bindir_path ( $ self , "net" ) ;
2009-01-28 23:01:04 +03:00
my $ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
2011-04-18 09:28:40 +04:00
$ cmd . = "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member" ;
$ cmd . = " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}" ;
2009-01-28 23:01:04 +03:00
2011-04-27 16:18:18 +04:00
if ( system ( $ cmd ) != 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2009-01-28 23:01:04 +03:00
2012-11-23 03:02:33 +04:00
if ( not $ self - > check_or_start ( $ ret , "yes" , "yes" , "yes" ) ) {
2011-04-12 03:05:34 +04:00
return undef ;
}
2009-01-28 23:01:04 +03:00
2011-04-18 09:28:40 +04:00
$ ret - > { DC_SERVER } = $ s3dcvars - > { SERVER } ;
$ ret - > { DC_SERVER_IP } = $ s3dcvars - > { SERVER_IP } ;
2014-06-19 19:21:16 +04:00
$ ret - > { DC_SERVER_IPV6 } = $ s3dcvars - > { SERVER_IPV6 } ;
2011-04-18 09:28:40 +04:00
$ ret - > { DC_NETBIOSNAME } = $ s3dcvars - > { NETBIOSNAME } ;
$ ret - > { DC_USERNAME } = $ s3dcvars - > { USERNAME } ;
$ ret - > { DC_PASSWORD } = $ s3dcvars - > { PASSWORD } ;
2009-01-28 23:01:04 +03:00
return $ ret ;
}
2011-04-19 10:38:46 +04:00
sub setup_admember ($$$$)
{
2012-03-02 04:44:56 +04:00
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2011-04-19 10:38:46 +04:00
2012-02-14 02:04:16 +04:00
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2012-03-02 04:44:56 +04:00
print "PROVISIONING S3 AD MEMBER..." ;
2011-04-19 10:38:46 +04:00
my $ member_options = "
security = ads
server signing = on
workgroup = $ dcvars - > { DOMAIN }
realm = $ dcvars - > { REALM }
" ;
my $ ret = $ self - > provision ( $ prefix ,
2012-03-02 04:44:56 +04:00
"LOCALADMEMBER" ,
"loCalMemberPass" ,
2014-09-04 16:33:05 +04:00
$ member_options ,
$ dcvars - > { SERVER_IP } ,
$ dcvars - > { SERVER_IPV6 } ) ;
2011-04-19 10:38:46 +04:00
$ ret or return undef ;
close ( USERMAP ) ;
$ ret - > { DOMAIN } = $ dcvars - > { DOMAIN } ;
$ ret - > { REALM } = $ dcvars - > { REALM } ;
my $ ctx ;
my $ prefix_abs = abs_path ( $ prefix ) ;
$ ctx = { } ;
$ ctx - > { krb5_conf } = "$prefix_abs/lib/krb5.conf" ;
$ ctx - > { domain } = $ dcvars - > { DOMAIN } ;
$ ctx - > { realm } = $ dcvars - > { REALM } ;
$ ctx - > { dnsname } = lc ( $ dcvars - > { REALM } ) ;
$ ctx - > { kdc_ipv4 } = $ dcvars - > { SERVER_IP } ;
2014-09-04 16:33:05 +04:00
$ ctx - > { kdc_ipv6 } = $ dcvars - > { SERVER_IPV6 } ;
2011-08-26 10:02:01 +04:00
Samba:: mk_krb5_conf ( $ ctx , "" ) ;
2011-04-19 10:38:46 +04:00
$ ret - > { KRB5_CONFIG } = $ ctx - > { krb5_conf } ;
my $ net = Samba:: bindir_path ( $ self , "net" ) ;
my $ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
2014-09-04 16:33:05 +04:00
if ( defined ( $ ret - > { RESOLV_WRAPPER_CONF } ) ) {
$ cmd . = "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" " ;
} else {
$ cmd . = "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" " ;
}
2011-04-19 10:38:46 +04:00
$ cmd . = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" " ;
2013-02-21 23:33:23 +04:00
$ cmd . = "$net join $ret->{CONFIGURATION}" ;
$ cmd . = " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}" ;
if ( system ( $ cmd ) != 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
# We need world access to this share, as otherwise the domain
# administrator from the AD domain provided by Samba4 can't
# access the share for tests.
chmod 0777 , "$prefix/share" ;
if ( not $ self - > check_or_start ( $ ret , "yes" , "yes" , "yes" ) ) {
return undef ;
}
$ ret - > { DC_SERVER } = $ dcvars - > { SERVER } ;
$ ret - > { DC_SERVER_IP } = $ dcvars - > { SERVER_IP } ;
2014-06-19 19:21:16 +04:00
$ ret - > { DC_SERVER_IPV6 } = $ dcvars - > { SERVER_IPV6 } ;
2013-02-21 23:33:23 +04:00
$ ret - > { DC_NETBIOSNAME } = $ dcvars - > { NETBIOSNAME } ;
$ ret - > { DC_USERNAME } = $ dcvars - > { USERNAME } ;
$ ret - > { DC_PASSWORD } = $ dcvars - > { PASSWORD } ;
# Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
$ ret - > { target } = $ self ;
return $ ret ;
}
sub setup_admember_rfc2307 ($$$$)
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > have_ads ( ) ) {
return "UNKNOWN" ;
}
print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config..." ;
my $ member_options = "
security = ads
server signing = on
workgroup = $ dcvars - > { DOMAIN }
realm = $ dcvars - > { REALM }
idmap config $ dcvars - > { DOMAIN } : backend = rfc2307
idmap config $ dcvars - > { DOMAIN } : range = 2000000 - 2999999
idmap config $ dcvars - > { DOMAIN } : ldap_server = ad
idmap config $ dcvars - > { DOMAIN } : bind_path_user = ou = idmap , dc = samba , dc = example , dc = com
idmap config $ dcvars - > { DOMAIN } : bind_path_group = ou = idmap , dc = samba , dc = example , dc = com
" ;
my $ ret = $ self - > provision ( $ prefix ,
"RFC2307MEMBER" ,
"loCalMemberPass" ,
2014-09-04 16:33:05 +04:00
$ member_options ,
$ dcvars - > { SERVER_IP } ,
$ dcvars - > { SERVER_IPV6 } ) ;
2013-02-21 23:33:23 +04:00
$ ret or return undef ;
close ( USERMAP ) ;
$ ret - > { DOMAIN } = $ dcvars - > { DOMAIN } ;
$ ret - > { REALM } = $ dcvars - > { REALM } ;
my $ ctx ;
my $ prefix_abs = abs_path ( $ prefix ) ;
$ ctx = { } ;
$ ctx - > { krb5_conf } = "$prefix_abs/lib/krb5.conf" ;
$ ctx - > { domain } = $ dcvars - > { DOMAIN } ;
$ ctx - > { realm } = $ dcvars - > { REALM } ;
$ ctx - > { dnsname } = lc ( $ dcvars - > { REALM } ) ;
$ ctx - > { kdc_ipv4 } = $ dcvars - > { SERVER_IP } ;
2014-09-04 16:33:05 +04:00
$ ctx - > { kdc_ipv6 } = $ dcvars - > { SERVER_IPV6 } ;
2013-02-21 23:33:23 +04:00
Samba:: mk_krb5_conf ( $ ctx , "" ) ;
$ ret - > { KRB5_CONFIG } = $ ctx - > { krb5_conf } ;
my $ net = Samba:: bindir_path ( $ self , "net" ) ;
my $ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
2014-09-04 16:33:05 +04:00
if ( defined ( $ ret - > { RESOLV_WRAPPER_CONF } ) ) {
$ cmd . = "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" " ;
} else {
$ cmd . = "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" " ;
}
2013-02-21 23:33:23 +04:00
$ cmd . = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" " ;
2011-04-19 10:38:46 +04:00
$ cmd . = "$net join $ret->{CONFIGURATION}" ;
$ cmd . = " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}" ;
2011-04-27 16:18:18 +04:00
if ( system ( $ cmd ) != 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2011-04-19 10:38:46 +04:00
2011-04-29 09:54:20 +04:00
# We need world access to this share, as otherwise the domain
# administrator from the AD domain provided by Samba4 can't
# access the share for tests.
chmod 0777 , "$prefix/share" ;
2012-11-23 03:02:33 +04:00
if ( not $ self - > check_or_start ( $ ret , "yes" , "yes" , "yes" ) ) {
return undef ;
}
2011-04-19 10:38:46 +04:00
$ ret - > { DC_SERVER } = $ dcvars - > { SERVER } ;
$ ret - > { DC_SERVER_IP } = $ dcvars - > { SERVER_IP } ;
2014-06-19 19:21:16 +04:00
$ ret - > { DC_SERVER_IPV6 } = $ dcvars - > { SERVER_IPV6 } ;
2011-04-19 10:38:46 +04:00
$ ret - > { DC_NETBIOSNAME } = $ dcvars - > { NETBIOSNAME } ;
$ ret - > { DC_USERNAME } = $ dcvars - > { USERNAME } ;
$ ret - > { DC_PASSWORD } = $ dcvars - > { PASSWORD } ;
# Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
$ ret - > { target } = $ self ;
return $ ret ;
}
2012-09-26 04:40:17 +04:00
sub setup_simpleserver ($$)
2011-02-18 10:52:00 +03:00
{
my ( $ self , $ path ) = @ _ ;
print "PROVISIONING server with security=share..." ;
2012-08-21 13:22:54 +04:00
my $ prefix_abs = abs_path ( $ path ) ;
2012-09-26 04:40:17 +04:00
my $ simpleserver_options = "
2011-02-18 10:52:00 +03:00
lanman auth = yes
2013-05-22 10:13:21 +04:00
vfs objects = xattr_tdb streams_depot
2012-08-21 13:22:54 +04:00
[ vfs_aio_fork ]
path = $ prefix_abs / share
2013-05-22 10:13:21 +04:00
vfs objects = aio_fork
2012-08-21 13:22:54 +04:00
read only = no
vfs_aio_fork:erratic_testing_mode = yes
2011-02-18 10:52:00 +03:00
" ;
my $ vars = $ self - > provision ( $ path ,
"LOCALSHARE4" ,
"local4pass" ,
2012-09-26 04:40:17 +04:00
$ simpleserver_options ) ;
2011-02-18 10:52:00 +03:00
2011-04-12 03:05:34 +04:00
$ vars or return undef ;
2012-11-23 03:02:33 +04:00
if ( not $ self - > check_or_start ( $ vars , "yes" , "no" , "yes" ) ) {
2011-04-12 03:05:34 +04:00
return undef ;
}
2011-02-18 10:52:00 +03:00
2012-09-26 04:40:17 +04:00
$ self - > { vars } - > { simpleserver } = $ vars ;
2011-02-18 10:52:00 +03:00
return $ vars ;
}
2011-04-04 13:13:17 +04:00
sub setup_ktest ($$$)
{
2011-04-19 10:38:46 +04:00
my ( $ self , $ prefix ) = @ _ ;
2011-04-04 13:13:17 +04:00
2012-02-14 02:04:16 +04:00
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2011-04-04 13:13:17 +04:00
print "PROVISIONING server with security=ads..." ;
my $ ktest_options = "
workgroup = KTEST
realm = ktest . samba . example . com
security = ads
username map = $ prefix /lib/ username . map
2012-02-14 12:22:14 +04:00
server signing = required
2011-04-04 13:13:17 +04:00
" ;
my $ ret = $ self - > provision ( $ prefix ,
"LOCALKTEST6" ,
"localktest6pass" ,
$ ktest_options ) ;
2011-04-12 03:05:34 +04:00
$ ret or return undef ;
2011-04-04 13:13:17 +04:00
2011-04-19 10:38:46 +04:00
my $ ctx ;
my $ prefix_abs = abs_path ( $ prefix ) ;
$ ctx = { } ;
$ ctx - > { krb5_conf } = "$prefix_abs/lib/krb5.conf" ;
$ ctx - > { domain } = "KTEST" ;
$ ctx - > { realm } = "KTEST.SAMBA.EXAMPLE.COM" ;
$ ctx - > { dnsname } = lc ( $ ctx - > { realm } ) ;
$ ctx - > { kdc_ipv4 } = "0.0.0.0" ;
2014-09-04 16:33:05 +04:00
$ ctx - > { kdc_ipv6 } = "::" ;
2011-08-26 10:02:01 +04:00
Samba:: mk_krb5_conf ( $ ctx , "" ) ;
2011-04-19 10:38:46 +04:00
$ ret - > { KRB5_CONFIG } = $ ctx - > { krb5_conf } ;
2011-04-04 13:13:17 +04:00
open ( USERMAP , ">$prefix/lib/username.map" ) or die ( "Unable to open $prefix/lib/username.map" ) ;
print USERMAP "
$ ret - > { USERNAME } = KTEST \ \ Administrator
" ;
close ( USERMAP ) ;
#This is the secrets.tdb created by 'net ads join' from Samba3 to a
#Samba4 DC with the same parameters as are being used here. The
#domain SID is S-1-5-21-1071277805-689288055-3486227160
2011-12-10 18:31:46 +04:00
system ( "cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb" ) ;
2011-04-04 13:13:17 +04:00
chmod 0600 , "$prefix/private/secrets.tdb" ;
2013-02-20 08:29:42 +04:00
#Make sure there's no old ntdb file.
system ( "rm -f $prefix/private/secrets.ntdb" ) ;
2011-04-04 13:13:17 +04:00
#This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
# "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
#
#and having in krb5.conf:
# ticket_lifetime = 799718400
# renew_lifetime = 799718400
#
2011-04-06 03:12:15 +04:00
# The commands for the -2 keytab where were:
2011-04-04 13:13:17 +04:00
# kinit administrator@KTEST.SAMBA.EXAMPLE.COM
# kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
# kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
# kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
# kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
#
2011-04-06 03:12:15 +04:00
# and then for the -3 keytab, I did
#
# net changetrustpw; kdestroy and the same again.
#
# This creates a credential cache with a very long lifetime (2036 at
# at 2011-04), and shows that running 'net changetrustpw' does not
# break existing logins (for the secrets.tdb method at least).
#
2011-04-04 13:13:17 +04:00
$ ret - > { KRB5_CCACHE } = "FILE:$prefix/krb5_ccache" ;
2011-04-06 03:12:15 +04:00
system ( "cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2" ) ;
chmod 0600 , "$prefix/krb5_ccache-2" ;
system ( "cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3" ) ;
chmod 0600 , "$prefix/krb5_ccache-3" ;
2011-04-04 13:13:17 +04:00
2012-01-27 08:20:17 +04:00
# We need world access to this share, as otherwise the domain
# administrator from the AD domain provided by ktest can't
# access the share for tests.
chmod 0777 , "$prefix/share" ;
2012-11-23 03:02:33 +04:00
if ( not $ self - > check_or_start ( $ ret , "yes" , "no" , "yes" ) ) {
2011-04-12 03:05:34 +04:00
return undef ;
}
2011-04-04 13:13:17 +04:00
return $ ret ;
}
2011-07-22 07:00:21 +04:00
sub setup_maptoguest ($$)
{
my ( $ self , $ path ) = @ _ ;
print "PROVISIONING maptoguest..." ;
my $ options = "
map to guest = bad user
" ;
my $ vars = $ self - > provision ( $ path ,
"maptoguest" ,
"maptoguestpass" ,
$ options ) ;
$ vars or return undef ;
2012-11-23 03:02:33 +04:00
if ( not $ self - > check_or_start ( $ vars , "yes" , "no" , "yes" ) ) {
2011-07-22 07:00:21 +04:00
return undef ;
}
$ self - > { vars } - > { s3maptoguest } = $ vars ;
return $ vars ;
}
2007-09-02 21:47:35 +04:00
sub stop_sig_term ($$) {
my ( $ self , $ pid ) = @ _ ;
kill ( "USR1" , $ pid ) or kill ( "ALRM" , $ pid ) or warn ( "Unable to kill $pid: $!" ) ;
}
sub stop_sig_kill ($$) {
my ( $ self , $ pid ) = @ _ ;
2009-03-20 16:25:15 +03:00
kill ( "ALRM" , $ pid ) or warn ( "Unable to kill $pid: $!" ) ;
2007-09-02 21:47:35 +04:00
}
2007-04-18 04:12:39 +04:00
2007-09-02 21:47:35 +04:00
sub write_pid ($$$)
{
my ( $ env_vars , $ app , $ pid ) = @ _ ;
2007-04-18 04:12:39 +04:00
2007-09-02 21:47:35 +04:00
open ( PID , ">$env_vars->{PIDDIR}/timelimit.$app.pid" ) ;
print PID $ pid ;
close ( PID ) ;
2007-04-18 04:12:39 +04:00
}
2007-09-02 21:47:35 +04:00
sub read_pid ($$)
{
my ( $ env_vars , $ app ) = @ _ ;
open ( PID , "<$env_vars->{PIDDIR}/timelimit.$app.pid" ) ;
my $ pid = <PID> ;
close ( PID ) ;
return $ pid ;
2007-04-18 04:12:39 +04:00
}
2011-10-18 13:37:25 +04:00
sub check_or_start ($$$$$) {
2011-04-19 07:50:40 +04:00
my ( $ self , $ env_vars , $ nmbd , $ winbindd , $ smbd ) = @ _ ;
2007-04-18 04:12:39 +04:00
2012-01-03 09:48:29 +04:00
# use a pipe for stdin in the child processes. This allows
# those processes to monitor the pipe for EOF to ensure they
# exit when the test script exits
pipe ( STDIN_READER , $ env_vars - > { STDIN_PIPE } ) ;
2007-04-18 04:12:39 +04:00
unlink ( $ env_vars - > { NMBD_TEST_LOG } ) ;
print "STARTING NMBD..." ;
2007-03-21 18:57:07 +03:00
my $ pid = fork ( ) ;
if ( $ pid == 0 ) {
2007-04-18 04:12:39 +04:00
open STDOUT , ">$env_vars->{NMBD_TEST_LOG}" ;
2007-03-21 18:57:07 +03:00
open STDERR , '>&STDOUT' ;
2007-09-30 13:08:10 +04:00
2009-01-28 19:28:51 +03:00
SocketWrapper:: set_default_iface ( $ env_vars - > { SOCKET_WRAPPER_DEFAULT_IFACE } ) ;
2011-04-19 10:38:46 +04:00
$ ENV { KRB5_CONFIG } = $ env_vars - > { KRB5_CONFIG } ;
2014-02-20 13:34:49 +04:00
$ ENV { SELFTEST_WINBINDD_SOCKET_DIR } = $ env_vars - > { SELFTEST_WINBINDD_SOCKET_DIR } ;
2011-01-08 08:28:45 +03:00
$ ENV { NMBD_SOCKET_DIR } = $ env_vars - > { NMBD_SOCKET_DIR } ;
2007-09-30 13:08:10 +04:00
2009-01-28 19:28:51 +03:00
$ ENV { NSS_WRAPPER_PASSWD } = $ env_vars - > { NSS_WRAPPER_PASSWD } ;
$ ENV { NSS_WRAPPER_GROUP } = $ env_vars - > { NSS_WRAPPER_GROUP } ;
2013-06-27 18:12:47 +04:00
$ ENV { NSS_WRAPPER_HOSTS } = $ env_vars - > { NSS_WRAPPER_HOSTS } ;
2014-10-29 19:40:22 +03:00
$ ENV { NSS_WRAPPER_HOSTNAME } = $ env_vars - > { NSS_WRAPPER_HOSTNAME } ;
2013-06-12 17:42:01 +04:00
$ ENV { NSS_WRAPPER_MODULE_SO_PATH } = $ env_vars - > { NSS_WRAPPER_MODULE_SO_PATH } ;
$ ENV { NSS_WRAPPER_MODULE_FN_PREFIX } = $ env_vars - > { NSS_WRAPPER_MODULE_FN_PREFIX } ;
2009-01-28 19:28:51 +03:00
2013-03-19 18:43:12 +04:00
$ ENV { ENVNAME } = "$ENV{ENVNAME}.nmbd" ;
2009-03-20 18:18:47 +03:00
if ( $ nmbd ne "yes" ) {
2009-02-04 17:16:42 +03:00
$ SIG { USR1 } = $ SIG { ALRM } = $ SIG { INT } = $ SIG { QUIT } = $ SIG { TERM } = sub {
my $ signame = shift ;
print ( "Skip nmbd received signal $signame" ) ;
exit 0 ;
} ;
2011-04-19 07:50:40 +04:00
sleep ( $ self - > { server_maxtime } ) ;
2009-02-04 17:16:42 +03:00
exit 0 ;
}
2014-01-25 12:45:25 +04:00
$ ENV { MAKE_TEST_BINARY } = Samba:: bindir_path ( $ self , "nmbd" ) ;
2007-10-08 16:57:30 +04:00
my @ optargs = ( "-d0" ) ;
if ( defined ( $ ENV { NMBD_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { NMBD_OPTIONS } ) ;
}
2011-04-27 05:19:20 +04:00
my @ preargs = ( Samba:: bindir_path ( $ self , "timelimit" ) , $ self - > { server_maxtime } ) ;
2007-10-10 21:40:19 +04:00
if ( defined ( $ ENV { NMBD_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { NMBD_VALGRIND } ) ;
}
2014-01-25 12:45:25 +04:00
my @ args = ( "-F" , "--no-process-group" ,
"-s" , $ env_vars - > { SERVERCONFFILE } ,
"-l" , $ env_vars - > { LOGDIR } ) ;
if ( not defined ( $ ENV { NMBD_DONT_LOG_STDOUT } ) ) {
push ( @ args , "--log-stdout" ) ;
}
2007-10-10 21:40:19 +04:00
2012-01-03 09:48:29 +04:00
close ( $ env_vars - > { STDIN_PIPE } ) ;
open STDIN , ">&" , \ * STDIN_READER or die "can't dup STDIN_READER to STDIN: $!" ;
2014-01-25 12:45:25 +04:00
exec ( @ preargs , $ ENV { MAKE_TEST_BINARY } , @ args , @ optargs )
or die ( "Unable to start $ENV{MAKE_TEST_BINARY}: $!" ) ;
2007-03-21 18:57:07 +03:00
}
2012-03-04 11:34:34 +04:00
$ env_vars - > { NMBD_TL_PID } = $ pid ;
2007-09-02 21:47:35 +04:00
write_pid ( $ env_vars , "nmbd" , $ pid ) ;
2007-03-21 18:57:07 +03:00
print "DONE\n" ;
2009-01-28 11:35:44 +03:00
unlink ( $ env_vars - > { WINBINDD_TEST_LOG } ) ;
print "STARTING WINBINDD..." ;
$ pid = fork ( ) ;
if ( $ pid == 0 ) {
open STDOUT , ">$env_vars->{WINBINDD_TEST_LOG}" ;
open STDERR , '>&STDOUT' ;
2009-01-28 19:28:51 +03:00
SocketWrapper:: set_default_iface ( $ env_vars - > { SOCKET_WRAPPER_DEFAULT_IFACE } ) ;
2011-04-19 10:38:46 +04:00
$ ENV { KRB5_CONFIG } = $ env_vars - > { KRB5_CONFIG } ;
2014-02-20 13:34:49 +04:00
$ ENV { SELFTEST_WINBINDD_SOCKET_DIR } = $ env_vars - > { SELFTEST_WINBINDD_SOCKET_DIR } ;
2011-01-08 08:28:45 +03:00
$ ENV { NMBD_SOCKET_DIR } = $ env_vars - > { NMBD_SOCKET_DIR } ;
2009-01-28 11:35:44 +03:00
2009-01-28 19:28:51 +03:00
$ ENV { NSS_WRAPPER_PASSWD } = $ env_vars - > { NSS_WRAPPER_PASSWD } ;
$ ENV { NSS_WRAPPER_GROUP } = $ env_vars - > { NSS_WRAPPER_GROUP } ;
2013-06-27 18:12:47 +04:00
$ ENV { NSS_WRAPPER_HOSTS } = $ env_vars - > { NSS_WRAPPER_HOSTS } ;
2014-10-29 19:40:22 +03:00
$ ENV { NSS_WRAPPER_HOSTNAME } = $ env_vars - > { NSS_WRAPPER_HOSTNAME } ;
2013-06-12 17:42:01 +04:00
$ ENV { NSS_WRAPPER_MODULE_SO_PATH } = $ env_vars - > { NSS_WRAPPER_MODULE_SO_PATH } ;
$ ENV { NSS_WRAPPER_MODULE_FN_PREFIX } = $ env_vars - > { NSS_WRAPPER_MODULE_FN_PREFIX } ;
2014-09-04 16:33:05 +04:00
if ( defined ( $ env_vars - > { RESOLV_WRAPPER_CONF } ) ) {
$ ENV { RESOLV_WRAPPER_CONF } = $ env_vars - > { RESOLV_WRAPPER_CONF } ;
} else {
$ ENV { RESOLV_WRAPPER_HOSTS } = $ env_vars - > { RESOLV_WRAPPER_HOSTS } ;
}
2009-01-28 19:28:51 +03:00
2013-03-19 18:43:12 +04:00
$ ENV { ENVNAME } = "$ENV{ENVNAME}.winbindd" ;
2009-03-20 18:18:47 +03:00
if ( $ winbindd ne "yes" ) {
2009-02-04 17:16:42 +03:00
$ SIG { USR1 } = $ SIG { ALRM } = $ SIG { INT } = $ SIG { QUIT } = $ SIG { TERM } = sub {
my $ signame = shift ;
print ( "Skip winbindd received signal $signame" ) ;
exit 0 ;
} ;
2011-04-19 07:50:40 +04:00
sleep ( $ self - > { server_maxtime } ) ;
2009-02-04 17:16:42 +03:00
exit 0 ;
}
2014-01-25 12:45:25 +04:00
$ ENV { MAKE_TEST_BINARY } = Samba:: bindir_path ( $ self , "winbindd" ) ;
2009-01-28 11:35:44 +03:00
my @ optargs = ( "-d0" ) ;
if ( defined ( $ ENV { WINBINDD_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { WINBINDD_OPTIONS } ) ;
}
2011-04-27 05:19:20 +04:00
my @ preargs = ( Samba:: bindir_path ( $ self , "timelimit" ) , $ self - > { server_maxtime } ) ;
2009-01-28 19:28:51 +03:00
if ( defined ( $ ENV { WINBINDD_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { WINBINDD_VALGRIND } ) ;
}
2014-01-25 12:45:25 +04:00
my @ args = ( "-F" , "--no-process-group" ,
"-s" , $ env_vars - > { SERVERCONFFILE } ,
"-l" , $ env_vars - > { LOGDIR } ) ;
if ( not defined ( $ ENV { WINBINDD_DONT_LOG_STDOUT } ) ) {
push ( @ args , "--stdout" ) ;
}
2011-04-28 06:39:33 +04:00
2012-01-03 09:48:29 +04:00
close ( $ env_vars - > { STDIN_PIPE } ) ;
open STDIN , ">&" , \ * STDIN_READER or die "can't dup STDIN_READER to STDIN: $!" ;
2014-01-25 12:45:25 +04:00
exec ( @ preargs , $ ENV { MAKE_TEST_BINARY } , @ args , @ optargs )
or die ( "Unable to start $ENV{MAKE_TEST_BINARY}: $!" ) ;
2009-01-28 11:35:44 +03:00
}
2012-03-04 11:34:34 +04:00
$ env_vars - > { WINBINDD_TL_PID } = $ pid ;
2009-01-28 11:35:44 +03:00
write_pid ( $ env_vars , "winbindd" , $ pid ) ;
print "DONE\n" ;
2007-09-30 13:08:10 +04:00
2007-04-18 04:12:39 +04:00
unlink ( $ env_vars - > { SMBD_TEST_LOG } ) ;
print "STARTING SMBD..." ;
2007-04-18 18:43:05 +04:00
$ pid = fork ( ) ;
2007-04-18 04:12:39 +04:00
if ( $ pid == 0 ) {
open STDOUT , ">$env_vars->{SMBD_TEST_LOG}" ;
open STDERR , '>&STDOUT' ;
2007-09-30 13:08:10 +04:00
2009-01-28 19:28:51 +03:00
SocketWrapper:: set_default_iface ( $ env_vars - > { SOCKET_WRAPPER_DEFAULT_IFACE } ) ;
2011-04-19 10:38:46 +04:00
$ ENV { KRB5_CONFIG } = $ env_vars - > { KRB5_CONFIG } ;
2014-02-20 13:34:49 +04:00
$ ENV { SELFTEST_WINBINDD_SOCKET_DIR } = $ env_vars - > { SELFTEST_WINBINDD_SOCKET_DIR } ;
2011-01-08 08:28:45 +03:00
$ ENV { NMBD_SOCKET_DIR } = $ env_vars - > { NMBD_SOCKET_DIR } ;
2007-09-30 13:08:10 +04:00
2009-01-28 19:28:51 +03:00
$ ENV { NSS_WRAPPER_PASSWD } = $ env_vars - > { NSS_WRAPPER_PASSWD } ;
$ ENV { NSS_WRAPPER_GROUP } = $ env_vars - > { NSS_WRAPPER_GROUP } ;
2013-06-27 18:12:47 +04:00
$ ENV { NSS_WRAPPER_HOSTS } = $ env_vars - > { NSS_WRAPPER_HOSTS } ;
2014-10-29 19:40:22 +03:00
$ ENV { NSS_WRAPPER_HOSTNAME } = $ env_vars - > { NSS_WRAPPER_HOSTNAME } ;
2013-06-12 17:42:01 +04:00
$ ENV { NSS_WRAPPER_MODULE_SO_PATH } = $ env_vars - > { NSS_WRAPPER_MODULE_SO_PATH } ;
$ ENV { NSS_WRAPPER_MODULE_FN_PREFIX } = $ env_vars - > { NSS_WRAPPER_MODULE_FN_PREFIX } ;
2014-09-04 16:33:05 +04:00
if ( defined ( $ env_vars - > { RESOLV_WRAPPER_CONF } ) ) {
$ ENV { RESOLV_WRAPPER_CONF } = $ env_vars - > { RESOLV_WRAPPER_CONF } ;
} else {
$ ENV { RESOLV_WRAPPER_HOSTS } = $ env_vars - > { RESOLV_WRAPPER_HOSTS } ;
}
2009-01-28 19:28:51 +03:00
2013-03-19 18:43:12 +04:00
$ ENV { ENVNAME } = "$ENV{ENVNAME}.smbd" ;
2009-03-20 18:18:47 +03:00
if ( $ smbd ne "yes" ) {
2009-02-04 17:16:42 +03:00
$ SIG { USR1 } = $ SIG { ALRM } = $ SIG { INT } = $ SIG { QUIT } = $ SIG { TERM } = sub {
my $ signame = shift ;
print ( "Skip smbd received signal $signame" ) ;
exit 0 ;
} ;
2011-04-19 07:50:40 +04:00
sleep ( $ self - > { server_maxtime } ) ;
2009-02-04 17:16:42 +03:00
exit 0 ;
}
2011-04-27 05:19:20 +04:00
$ ENV { MAKE_TEST_BINARY } = Samba:: bindir_path ( $ self , "smbd" ) ;
2007-10-08 16:57:30 +04:00
my @ optargs = ( "-d0" ) ;
if ( defined ( $ ENV { SMBD_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { SMBD_OPTIONS } ) ;
}
2011-04-27 05:19:20 +04:00
my @ preargs = ( Samba:: bindir_path ( $ self , "timelimit" ) , $ self - > { server_maxtime } ) ;
2007-10-10 21:40:19 +04:00
if ( defined ( $ ENV { SMBD_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { SMBD_VALGRIND } ) ;
}
2014-01-25 12:45:25 +04:00
my @ args = ( "-F" , "--no-process-group" ,
"-s" , $ env_vars - > { SERVERCONFFILE } ,
"-l" , $ env_vars - > { LOGDIR } ) ;
if ( not defined ( $ ENV { SMBD_DONT_LOG_STDOUT } ) ) {
push ( @ args , "--log-stdout" ) ;
}
2012-01-03 09:48:29 +04:00
close ( $ env_vars - > { STDIN_PIPE } ) ;
open STDIN , ">&" , \ * STDIN_READER or die "can't dup STDIN_READER to STDIN: $!" ;
2014-01-25 12:45:25 +04:00
exec ( @ preargs , $ ENV { MAKE_TEST_BINARY } , @ args , @ optargs )
or die ( "Unable to start $ENV{MAKE_TEST_BINARY}: $!" ) ;
2007-04-18 04:12:39 +04:00
}
2012-03-04 11:34:34 +04:00
$ env_vars - > { SMBD_TL_PID } = $ pid ;
2007-09-02 21:47:35 +04:00
write_pid ( $ env_vars , "smbd" , $ pid ) ;
2007-04-18 04:12:39 +04:00
print "DONE\n" ;
2007-03-21 18:57:07 +03:00
2012-01-03 09:48:29 +04:00
close ( STDIN_READER ) ;
2012-11-23 03:09:43 +04:00
return $ self - > wait_for_start ( $ env_vars , $ nmbd , $ winbindd , $ smbd ) ;
2007-03-21 18:57:07 +03:00
}
2014-09-04 16:33:05 +04:00
sub provision ($$$$$$$$)
2007-03-21 18:57:07 +03:00
{
2014-09-04 16:33:05 +04:00
my ( $ self , $ prefix , $ server , $ password , $ extra_options , $ dc_server_ip , $ dc_server_ipv6 , $ no_delete_prefix ) = @ _ ;
2007-04-18 04:12:39 +04:00
##
## setup the various environment variables we need
##
2012-03-02 04:44:56 +04:00
my $ swiface = Samba:: get_interface ( $ server ) ;
2007-03-21 18:57:07 +03:00
my % ret = ( ) ;
2009-01-28 22:30:16 +03:00
my $ server_ip = "127.0.0.$swiface" ;
2014-06-19 19:21:16 +04:00
my $ server_ipv6 = sprintf ( "fd00:0000:0000:0000:0000:0000:5357:5f%02x" , $ swiface ) ;
2007-09-30 13:08:10 +04:00
my $ domain = "SAMBA-TEST" ;
2009-01-28 19:28:51 +03:00
my $ unix_name = ( $ ENV { USER } or $ ENV { LOGNAME } or `PATH=/usr/ucb:$ENV{PATH} whoami` ) ;
chomp $ unix_name ;
my $ unix_uid = $> ;
my $ unix_gids_str = $ ) ;
my @ unix_gids = split ( " " , $ unix_gids_str ) ;
2007-03-21 18:57:07 +03:00
2007-04-18 04:12:39 +04:00
my $ prefix_abs = abs_path ( $ prefix ) ;
2009-01-28 19:28:51 +03:00
my $ bindir_abs = abs_path ( $ self - > { bindir } ) ;
2007-09-30 13:08:10 +04:00
my @ dirs = ( ) ;
my $ shrdir = "$prefix_abs/share" ;
push ( @ dirs , $ shrdir ) ;
2007-04-18 04:12:39 +04:00
my $ libdir = "$prefix_abs/lib" ;
2007-09-30 13:08:10 +04:00
push ( @ dirs , $ libdir ) ;
2007-04-18 04:12:39 +04:00
my $ piddir = "$prefix_abs/pid" ;
2007-09-30 13:08:10 +04:00
push ( @ dirs , $ piddir ) ;
2007-04-18 04:12:39 +04:00
my $ privatedir = "$prefix_abs/private" ;
2007-09-30 13:08:10 +04:00
push ( @ dirs , $ privatedir ) ;
2007-04-18 04:12:39 +04:00
my $ lockdir = "$prefix_abs/lockdir" ;
2007-09-30 13:08:10 +04:00
push ( @ dirs , $ lockdir ) ;
2010-03-18 00:55:00 +03:00
my $ eventlogdir = "$prefix_abs/lockdir/eventlog" ;
push ( @ dirs , $ eventlogdir ) ;
2007-04-18 04:12:39 +04:00
my $ logdir = "$prefix_abs/logs" ;
2007-09-30 13:08:10 +04:00
push ( @ dirs , $ logdir ) ;
2010-04-23 15:51:02 +04:00
my $ driver32dir = "$shrdir/W32X86" ;
push ( @ dirs , $ driver32dir ) ;
my $ driver64dir = "$shrdir/x64" ;
push ( @ dirs , $ driver64dir ) ;
2010-11-29 17:17:41 +03:00
my $ driver40dir = "$shrdir/WIN40" ;
push ( @ dirs , $ driver40dir ) ;
2010-05-29 02:09:14 +04:00
my $ ro_shrdir = "$shrdir/root-tmp" ;
push ( @ dirs , $ ro_shrdir ) ;
my $ msdfs_shrdir = "$shrdir/msdfsshare" ;
push ( @ dirs , $ msdfs_shrdir ) ;
my $ msdfs_deeppath = "$msdfs_shrdir/deeppath" ;
push ( @ dirs , $ msdfs_deeppath ) ;
2014-08-28 00:15:29 +04:00
my $ badnames_shrdir = "$shrdir/badnames" ;
push ( @ dirs , $ badnames_shrdir ) ;
2014-11-18 01:17:34 +03:00
my $ lease1_shrdir = "$shrdir/SMB2_10" ;
push ( @ dirs , $ lease1_shrdir ) ;
my $ lease2_shrdir = "$shrdir/SMB3_00" ;
push ( @ dirs , $ lease2_shrdir ) ;
2007-09-30 13:08:10 +04:00
# this gets autocreated by winbindd
my $ wbsockdir = "$prefix_abs/winbindd" ;
2007-10-02 19:56:33 +04:00
my $ wbsockprivdir = "$lockdir/winbindd_privileged" ;
2007-03-21 18:57:07 +03:00
2011-01-08 08:28:45 +03:00
my $ nmbdsockdir = "$prefix_abs/nmbd" ;
2011-01-11 01:24:51 +03:00
unlink ( $ nmbdsockdir ) ;
2011-01-08 08:28:45 +03:00
2007-04-18 04:12:39 +04:00
##
## create the test directory layout
##
2009-02-04 13:26:46 +03:00
die ( "prefix_abs = ''" ) if $ prefix_abs eq "" ;
die ( "prefix_abs = '/'" ) if $ prefix_abs eq "/" ;
2007-04-20 15:40:44 +04:00
mkdir ( $ prefix_abs , 0777 ) ;
2007-04-18 04:12:39 +04:00
print "CREATE TEST ENVIRONMENT IN '$prefix'..." ;
2011-05-08 12:32:01 +04:00
if ( not defined ( $ no_delete_prefix ) or not $ no_delete_prefix ) {
system ( "rm -rf $prefix_abs/*" ) ;
}
2007-09-30 13:08:10 +04:00
mkdir ( $ _ , 0777 ) foreach ( @ dirs ) ;
2014-07-22 02:31:16 +04:00
my $ fs_specific_conf = $ self - > get_fs_specific_conf ( $ shrdir ) ;
2012-12-22 03:16:10 +04:00
##
## lockdir and piddir must be 0755
##
chmod 0755 , $ lockdir ;
chmod 0755 , $ piddir ;
2010-05-29 02:09:14 +04:00
##
## create ro and msdfs share layout
##
2010-05-29 02:38:21 +04:00
chmod 0755 , $ ro_shrdir ;
2010-05-29 02:09:14 +04:00
my $ unreadable_file = "$ro_shrdir/unreadable_file" ;
2011-05-08 08:54:50 +04:00
unless ( open ( UNREADABLE_FILE , ">$unreadable_file" ) ) {
warn ( "Unable to open $unreadable_file" ) ;
return undef ;
}
2010-05-29 02:09:14 +04:00
close ( UNREADABLE_FILE ) ;
2010-05-29 02:38:21 +04:00
chmod 0600 , $ unreadable_file ;
2010-05-29 02:09:14 +04:00
my $ msdfs_target = "$ro_shrdir/msdfs-target" ;
2011-05-08 08:54:50 +04:00
unless ( open ( MSDFS_TARGET , ">$msdfs_target" ) ) {
warn ( "Unable to open $msdfs_target" ) ;
return undef ;
}
2010-05-29 02:09:14 +04:00
close ( MSDFS_TARGET ) ;
2010-05-29 02:38:21 +04:00
chmod 0666 , $ msdfs_target ;
2010-05-29 02:09:14 +04:00
symlink "msdfs:$server_ip\\ro-tmp" , "$msdfs_shrdir/msdfs-src1" ;
2014-06-19 19:21:16 +04:00
symlink "msdfs:$server_ipv6\\ro-tmp" , "$msdfs_shrdir/deeppath/msdfs-src2" ;
2010-05-29 02:09:14 +04:00
2014-08-28 00:15:29 +04:00
##
## create bad names in $badnames_shrdir
##
## (An invalid name, would be mangled to 8.3).
my $ badname_target = "$badnames_shrdir/\340|\231\216\377\177" ;
unless ( open ( BADNAME_TARGET , ">$badname_target" ) ) {
warn ( "Unable to open $badname_target" ) ;
return undef ;
}
close ( BADNAME_TARGET ) ;
chmod 0666 , $ badname_target ;
## (A bad name, would not be mangled to 8.3).
my $ badname_target = "$badnames_shrdir/\240\276\346\327\377\177" ;
unless ( open ( BADNAME_TARGET , ">$badname_target" ) ) {
warn ( "Unable to open $badname_target" ) ;
return undef ;
}
close ( BADNAME_TARGET ) ;
chmod 0666 , $ badname_target ;
## (A bad good name).
my $ badname_target = "$badnames_shrdir/blank.txt" ;
unless ( open ( BADNAME_TARGET , ">$badname_target" ) ) {
warn ( "Unable to open $badname_target" ) ;
return undef ;
}
close ( BADNAME_TARGET ) ;
chmod 0666 , $ badname_target ;
2007-09-30 13:08:10 +04:00
my $ conffile = "$libdir/server.conf" ;
2007-03-21 18:57:07 +03:00
2011-02-22 03:56:18 +03:00
my $ nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl" ;
2009-01-28 19:28:51 +03:00
my $ nss_wrapper_passwd = "$privatedir/passwd" ;
my $ nss_wrapper_group = "$privatedir/group" ;
2013-06-27 18:12:47 +04:00
my $ nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts" ;
2014-09-04 16:33:05 +04:00
my $ resolv_conf = "$privatedir/resolv.conf" ;
2015-01-07 02:18:55 +03:00
my $ dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file" ;
2009-01-28 19:28:51 +03:00
2011-02-22 03:56:18 +03:00
my $ mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl" ;
2010-02-18 02:48:58 +03:00
2010-03-18 00:55:00 +03:00
my @ eventlog_list = ( "dns server" , "application" ) ;
2010-03-19 12:23:39 +03:00
##
## calculate uids and gids
##
my ( $ max_uid , $ max_gid ) ;
2014-05-16 06:30:43 +04:00
my ( $ uid_nobody , $ uid_root , $ uid_pdbtest , $ uid_pdbtest2 ) ;
2012-11-20 19:48:23 +04:00
my ( $ gid_nobody , $ gid_nogroup , $ gid_root , $ gid_domusers , $ gid_domadmins ) ;
2010-03-19 12:23:39 +03:00
2014-05-16 06:30:43 +04:00
if ( $ unix_uid < 0xffff - 4 ) {
2010-03-19 12:23:39 +03:00
$ max_uid = 0xffff ;
} else {
$ max_uid = $ unix_uid ;
}
$ uid_root = $ max_uid - 1 ;
$ uid_nobody = $ max_uid - 2 ;
2012-06-27 11:51:55 +04:00
$ uid_pdbtest = $ max_uid - 3 ;
2014-05-16 06:30:43 +04:00
$ uid_pdbtest2 = $ max_uid - 4 ;
2010-03-19 12:23:39 +03:00
2014-05-16 06:30:43 +04:00
if ( $ unix_gids [ 0 ] < 0xffff - 5 ) {
2010-03-19 12:23:39 +03:00
$ max_gid = 0xffff ;
} else {
$ max_gid = $ unix_gids [ 0 ] ;
}
$ gid_nobody = $ max_gid - 1 ;
$ gid_nogroup = $ max_gid - 2 ;
$ gid_root = $ max_gid - 3 ;
2010-11-09 00:39:51 +03:00
$ gid_domusers = $ max_gid - 4 ;
2012-11-20 19:48:23 +04:00
$ gid_domadmins = $ max_gid - 5 ;
2010-03-19 12:23:39 +03:00
##
## create conffile
##
2011-05-08 08:54:50 +04:00
unless ( open ( CONF , ">$conffile" ) ) {
warn ( "Unable to open $conffile" ) ;
return undef ;
}
2007-04-18 04:12:39 +04:00
print CONF "
[ global ]
2009-01-28 19:28:51 +03:00
netbios name = $ server
2014-06-19 19:21:16 +04:00
interfaces = $ server_ip /8 $server_ipv6/ 64
2009-01-28 19:28:51 +03:00
bind interfaces only = yes
2013-09-11 19:56:02 +04:00
panic action = cd $ self - > { srcdir } && $ self - > { srcdir } /selftest/g db_backtrace % d % \ $ ( MAKE_TEST_BINARY )
2012-05-17 03:06:29 +04:00
smbd:suicide mode = yes
2009-01-28 19:28:51 +03:00
2007-04-18 04:12:39 +04:00
workgroup = $ domain
2007-03-21 18:57:07 +03:00
2007-04-18 04:12:39 +04:00
private dir = $ privatedir
pid directory = $ piddir
lock directory = $ lockdir
log file = $ logdir / log . \ % m
2012-02-13 10:47:11 +04:00
log level = 1
2011-03-18 12:03:05 +03:00
debug pid = yes
2011-04-04 03:22:03 +04:00
max log size = 0
2007-03-21 18:57:07 +03:00
2009-01-28 19:28:51 +03:00
state directory = $ lockdir
cache directory = $ lockdir
2007-04-18 04:12:39 +04:00
passdb backend = tdbsam
2009-01-28 19:28:51 +03:00
time server = yes
2010-03-19 12:23:39 +03:00
add user script = $ nss_wrapper_pl - - passwd_path $ nss_wrapper_passwd - - type passwd - - action add - - name % u - - gid $ gid_nogroup
2009-05-28 12:40:22 +04:00
add group script = $ nss_wrapper_pl - - group_path $ nss_wrapper_group - - type group - - action add - - name % g
2010-03-19 12:23:39 +03:00
add machine script = $ nss_wrapper_pl - - passwd_path $ nss_wrapper_passwd - - type passwd - - action add - - name % u - - gid $ gid_nogroup
2009-05-28 12:40:22 +04:00
add user to group script = $ nss_wrapper_pl - - passwd_path $ nss_wrapper_passwd - - type member - - action add - - member % u - - name % g - - group_path $ nss_wrapper_group
delete user script = $ nss_wrapper_pl - - passwd_path $ nss_wrapper_passwd - - type passwd - - action delete - - name % u
delete group script = $ nss_wrapper_pl - - group_path $ nss_wrapper_group - - type group - - action delete - - name % g
delete user from group script = $ nss_wrapper_pl - - passwd_path $ nss_wrapper_passwd - - type member - - action delete - - member % u - - name % g - - group_path $ nss_wrapper_group
2009-01-28 19:28:51 +03:00
2010-02-18 02:48:58 +03:00
addprinter command = $ mod_printer_pl - a - s $ conffile - -
deleteprinter command = $ mod_printer_pl - d - s $ conffile - -
2010-03-18 00:55:00 +03:00
eventlog list = application \ " dns server \ "
2009-01-28 19:28:51 +03:00
kernel oplocks = no
kernel change notify = no
2014-10-14 21:34:53 +04:00
smb2 leases = yes
2009-01-28 19:28:51 +03:00
syslog = no
printing = bsd
printcap name = /dev/ null
2007-09-26 23:23:54 +04:00
2013-10-11 04:34:13 +04:00
winbindd socket directory = $ wbsockdir
2011-01-08 08:28:45 +03:00
nmbd:socket dir = $ nmbdsockdir
2011-03-10 17:58:05 +03:00
idmap config * : range = 100000 - 200000
2010-01-13 17:21:14 +03:00
winbind enum users = yes
winbind enum groups = yes
2014-03-31 11:47:18 +04:00
winbind separator = /
2009-01-28 19:28:51 +03:00
# min receivefile size = 4000
2007-09-30 13:08:10 +04:00
2007-04-18 04:12:39 +04:00
read only = no
2010-11-11 04:54:57 +03:00
server signing = auto
2007-04-18 04:12:39 +04:00
smbd:sharedelay = 100000
2012-03-15 20:28:38 +04:00
smbd:writetimeupdatedelay = 500000
2010-05-29 02:09:14 +04:00
map hidden = no
map system = no
map readonly = no
store dos attributes = yes
2013-03-10 13:25:53 +04:00
create mask = 755
2011-10-28 03:41:18 +04:00
dos filemode = yes
2014-10-25 00:57:04 +04:00
strict rename = yes
2013-05-22 10:13:21 +04:00
vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
2009-01-28 19:28:51 +03:00
2010-03-25 02:55:13 +03:00
printing = vlp
print command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb print % p % s
lpq command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb lpq % p
lp rm command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb lprm % p % j
lp pause command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb lppause % p % j
lp resume command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb lpresume % p % j
queue pause command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb queuepause % p
queue resume command = $ bindir_abs /vlp tdbfile=$lockdir/ vlp . tdb queueresume % p
2010-03-27 00:58:42 +03:00
lpq cache time = 0
2013-10-14 15:53:22 +04:00
print notify backchannel = yes
2010-03-25 02:55:13 +03:00
2011-05-08 12:32:01 +04:00
ncalrpc dir = $ prefix_abs / ncalrpc
2011-04-26 03:49:08 +04:00
2011-07-27 09:42:45 +04:00
# The samba3.blackbox.smbclient_s3 test uses this to test that
# sending messages works, and that the %m sub works.
2011-06-09 09:22:19 +04:00
message command = mv % s $ shrdir / message . % m
2009-01-28 22:30:16 +03:00
# Begin extra options
$ extra_options
# End extra options
2009-01-28 19:28:51 +03:00
#Include user defined custom parameters if set
2009-01-29 00:15:44 +03:00
" ;
if ( defined ( $ ENV { INCLUDE_CUSTOM_CONF } ) ) {
print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n" ;
}
2009-01-28 19:28:51 +03:00
2009-01-29 00:15:44 +03:00
print CONF "
2009-01-28 19:28:51 +03:00
[ tmp ]
path = $ shrdir
2011-07-29 06:12:36 +04:00
comment = smb username is [ % U ]
2014-02-11 22:39:04 +04:00
[ tmpsort ]
path = $ shrdir
comment = Load dirsort module
vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
2012-08-17 10:50:21 +04:00
[ tmpenc ]
path = $ shrdir
comment = encrypt smb username is [ % U ]
smb encrypt = required
2013-05-22 10:13:21 +04:00
vfs objects = dirsort
2011-02-18 10:52:00 +03:00
[ tmpguest ]
path = $ shrdir
guest ok = yes
[ guestonly ]
path = $ shrdir
guest only = yes
guest ok = yes
[ forceuser ]
path = $ shrdir
force user = $ unix_name
guest ok = yes
2015-01-14 00:49:58 +03:00
[ forceuser_unixonly ]
path = $ shrdir
force user = pdbtest
guest ok = yes
2011-02-18 10:52:00 +03:00
[ forcegroup ]
path = $ shrdir
force group = nogroup
guest ok = yes
2010-05-29 02:09:14 +04:00
[ ro - tmp ]
path = $ ro_shrdir
guest ok = yes
2012-12-20 16:05:55 +04:00
[ write - list - tmp ]
path = $ shrdir
read only = yes
write list = $ unix_name
[ valid - users - tmp ]
path = $ shrdir
valid users = $ unix_name
2010-05-29 02:09:14 +04:00
[ msdfs - share ]
path = $ msdfs_shrdir
msdfs root = yes
guest ok = yes
2007-04-18 04:12:39 +04:00
[ hideunread ]
copy = tmp
hide unreadable = yes
2010-05-29 02:09:14 +04:00
[ tmpcase ]
copy = tmp
case sensitive = yes
2007-04-18 04:12:39 +04:00
[ hideunwrite ]
copy = tmp
hide unwriteable files = yes
2012-08-09 17:27:50 +04:00
[ durable ]
copy = tmp
kernel share modes = no
kernel oplocks = no
posix locking = no
2013-11-18 17:54:26 +04:00
[ fs_specific ]
copy = tmp
$ fs_specific_conf
2007-04-18 04:12:39 +04:00
[ print1 ]
copy = tmp
printable = yes
2009-04-23 01:54:10 +04:00
2007-04-18 04:12:39 +04:00
[ print2 ]
copy = print1
[ print3 ]
copy = print1
2012-11-29 15:10:45 +04:00
default devmode = no
2010-09-02 15:39:12 +04:00
[ lp ]
2007-04-18 04:12:39 +04:00
copy = print1
2013-04-14 14:04:45 +04:00
2013-04-28 21:06:59 +04:00
[ nfs4acl_simple ]
2013-04-14 14:04:45 +04:00
path = $ shrdir
comment = smb username is [ % U ]
2013-04-28 21:06:59 +04:00
nfs4:mode = simple
2013-05-22 10:13:21 +04:00
vfs objects = nfs4acl_xattr xattr_tdb
2013-04-28 21:06:59 +04:00
[ nfs4acl_special ]
path = $ shrdir
comment = smb username is [ % U ]
nfs4:mode = special
2013-05-22 10:13:21 +04:00
vfs objects = nfs4acl_xattr xattr_tdb
2013-04-14 14:04:45 +04:00
2011-10-28 23:15:51 +04:00
[ xcopy_share ]
path = $ shrdir
comment = smb username is [ % U ]
create mask = 777
force create mode = 777
2012-06-05 07:43:09 +04:00
[ posix_share ]
path = $ shrdir
comment = smb username is [ % U ]
create mask = 0777
force create mode = 0
directory mask = 0777
force directory mode = 0
2013-05-22 10:13:21 +04:00
vfs objects = xattr_tdb
2013-12-06 02:20:06 +04:00
[ aio ]
copy = tmp
aio read size = 1
aio write size = 1
2012-06-05 07:43:09 +04:00
2010-04-23 15:51:02 +04:00
[ print \ $]
copy = tmp
2014-07-08 07:47:02 +04:00
[ vfs_fruit ]
path = $ shrdir
vfs objects = catia fruit streams_xattr
fruit:ressource = file
fruit:metadata = netatalk
fruit:locking = netatalk
fruit:encoding = native
2014-08-28 00:15:29 +04:00
[ badname - tmp ]
path = $ badnames_shrdir
guest ok = yes
2014-11-18 01:17:34 +03:00
[ dynamic_share ]
path = $ shrdir / % R
guest ok = yes
2007-04-18 04:12:39 +04:00
" ;
close ( CONF ) ;
2007-03-21 18:57:07 +03:00
2007-04-18 04:12:39 +04:00
##
## create a test account
##
2011-05-08 08:54:50 +04:00
unless ( open ( PASSWD , ">$nss_wrapper_passwd" ) ) {
warn ( "Unable to open $nss_wrapper_passwd" ) ;
return undef ;
}
2010-03-18 14:12:58 +03:00
print PASSWD " nobody:x: $ uid_nobody: $ gid_nobody:nobody gecos: $ prefix_abs: /bin/ false
2009-01-28 19:28:51 +03:00
$ unix_name:x: $ unix_uid: $ unix_gids [ 0 ] : $ unix_name gecos: $ prefix_abs: /bin/ false
2012-06-27 11:51:55 +04:00
pdbtest:x: $ uid_pdbtest: $ gid_nogroup:pdbtest gecos: $ prefix_abs: /bin/ false
2014-05-16 06:30:43 +04:00
pdbtest2:x: $ uid_pdbtest2: $ gid_nogroup:pdbtest gecos: $ prefix_abs: /bin/ false
2009-01-28 19:28:51 +03:00
" ;
2010-03-18 14:12:58 +03:00
if ( $ unix_uid != 0 ) {
2013-07-01 15:02:46 +04:00
print PASSWD " root:x: $ uid_root: $ gid_root:root gecos: $ prefix_abs: /bin/ false
" ;
2010-03-18 14:12:58 +03:00
}
2009-01-28 19:28:51 +03:00
close ( PASSWD ) ;
2011-05-08 08:54:50 +04:00
unless ( open ( GROUP , ">$nss_wrapper_group" ) ) {
warn ( "Unable to open $nss_wrapper_group" ) ;
return undef ;
}
2010-03-18 14:12:58 +03:00
print GROUP " nobody:x: $ gid_nobody:
nogroup:x: $ gid_nogroup:nobody
2009-01-28 19:28:51 +03:00
$ unix_name - group:x: $ unix_gids [ 0 ] :
2010-11-09 00:39:51 +03:00
domusers:X: $ gid_domusers:
2012-11-20 19:48:23 +04:00
domadmins:X: $ gid_domadmins:
2009-01-28 19:28:51 +03:00
" ;
2010-03-18 14:12:58 +03:00
if ( $ unix_gids [ 0 ] != 0 ) {
2013-07-01 15:02:46 +04:00
print GROUP " root:x: $ gid_root:
" ;
2010-03-18 14:12:58 +03:00
}
2009-01-28 19:28:51 +03:00
close ( GROUP ) ;
2013-06-27 18:12:47 +04:00
## hosts
my $ hostname = lc ( $ server ) ;
unless ( open ( HOSTS , ">>$nss_wrapper_hosts" ) ) {
warn ( "Unable to open $nss_wrapper_hosts" ) ;
return undef ;
}
2014-06-19 19:21:16 +04:00
print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n" ;
print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n" ;
2013-06-27 18:12:47 +04:00
close ( HOSTS ) ;
2014-09-04 16:33:05 +04:00
## hosts
unless ( open ( RESOLV_CONF , ">$resolv_conf" ) ) {
warn ( "Unable to open $resolv_conf" ) ;
return undef ;
}
if ( defined ( $ dc_server_ip ) or defined ( $ dc_server_ipv6 ) ) {
if ( defined ( $ dc_server_ip ) ) {
print RESOLV_CONF "nameserver $dc_server_ip\n" ;
}
if ( defined ( $ dc_server_ipv6 ) ) {
print RESOLV_CONF "nameserver $dc_server_ipv6\n" ;
}
} else {
print RESOLV_CONF "nameserver ${server_ip}\n" ;
print RESOLV_CONF "nameserver ${server_ipv6}\n" ;
}
close ( RESOLV_CONF ) ;
2013-06-27 18:12:47 +04:00
2010-03-18 00:55:00 +03:00
foreach my $ evlog ( @ eventlog_list ) {
my $ evlogtdb = "$eventlogdir/$evlog.tdb" ;
open ( EVENTLOG , ">$evlogtdb" ) or die ( "Unable to open $evlogtdb" ) ;
close ( EVENTLOG ) ;
}
2009-01-28 19:28:51 +03:00
$ ENV { NSS_WRAPPER_PASSWD } = $ nss_wrapper_passwd ;
$ ENV { NSS_WRAPPER_GROUP } = $ nss_wrapper_group ;
2013-06-27 18:12:47 +04:00
$ ENV { NSS_WRAPPER_HOSTS } = $ nss_wrapper_hosts ;
2014-10-29 19:40:22 +03:00
$ ENV { NSS_WRAPPER_HOSTNAME } = "${hostname}.samba.example.com" ;
2014-09-04 16:33:05 +04:00
if ( $ ENV { SAMBA_DNS_FAKING } ) {
$ ENV { RESOLV_WRAPPER_CONF } = $ resolv_conf ;
} else {
$ ENV { RESOLV_WRAPPER_HOSTS } = $ dns_host_file ;
}
2009-01-28 19:28:51 +03:00
2014-04-02 17:41:34 +04:00
my $ cmd = "UID_WRAPPER_ROOT=1 " . Samba:: bindir_path ( $ self , "smbpasswd" ) . " -c $conffile -L -s -a $unix_name > /dev/null" ;
2011-05-08 08:54:50 +04:00
unless ( open ( PWD , "|$cmd" ) ) {
warn ( "Unable to set password for test account\n$cmd" ) ;
return undef ;
}
2007-04-18 04:12:39 +04:00
print PWD "$password\n$password\n" ;
2011-05-08 08:54:50 +04:00
unless ( close ( PWD ) ) {
warn ( "Unable to set password for test account\n$cmd" ) ;
return undef ;
}
2007-04-18 04:12:39 +04:00
print "DONE\n" ;
2012-09-26 04:02:43 +04:00
open ( DNS_UPDATE_LIST , ">$prefix/dns_update_list" ) or die ( "Unable to open $$prefix/dns_update_list" ) ;
2014-06-19 19:21:16 +04:00
print DNS_UPDATE_LIST "A $server. $server_ip\n" ;
print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n" ;
2012-09-26 04:02:43 +04:00
close ( DNS_UPDATE_LIST ) ;
2007-04-18 04:12:39 +04:00
$ ret { SERVER_IP } = $ server_ip ;
2014-06-19 19:21:16 +04:00
$ ret { SERVER_IPV6 } = $ server_ipv6 ;
2007-04-18 04:12:39 +04:00
$ ret { NMBD_TEST_LOG } = "$prefix/nmbd_test.log" ;
2009-01-29 00:15:44 +03:00
$ ret { NMBD_TEST_LOG_POS } = 0 ;
2007-09-30 13:08:10 +04:00
$ ret { WINBINDD_TEST_LOG } = "$prefix/winbindd_test.log" ;
2009-01-29 00:15:44 +03:00
$ ret { WINBINDD_TEST_LOG_POS } = 0 ;
2007-04-18 04:12:39 +04:00
$ ret { SMBD_TEST_LOG } = "$prefix/smbd_test.log" ;
2009-01-29 00:15:44 +03:00
$ ret { SMBD_TEST_LOG_POS } = 0 ;
2007-04-18 04:12:39 +04:00
$ ret { SERVERCONFFILE } = $ conffile ;
$ ret { CONFIGURATION } = "-s $conffile" ;
$ ret { SERVER } = $ server ;
2009-01-28 19:28:51 +03:00
$ ret { USERNAME } = $ unix_name ;
2010-06-02 17:35:33 +04:00
$ ret { USERID } = $ unix_uid ;
2007-04-18 04:12:39 +04:00
$ ret { DOMAIN } = $ domain ;
$ ret { NETBIOSNAME } = $ server ;
$ ret { PASSWORD } = $ password ;
$ ret { PIDDIR } = $ piddir ;
2014-02-20 13:34:49 +04:00
$ ret { SELFTEST_WINBINDD_SOCKET_DIR } = $ wbsockdir ;
2007-10-02 19:56:33 +04:00
$ ret { WINBINDD_PRIV_PIPE_DIR } = $ wbsockprivdir ;
2011-01-08 08:28:45 +03:00
$ ret { NMBD_SOCKET_DIR } = $ nmbdsockdir ;
2009-01-29 00:15:44 +03:00
$ ret { SOCKET_WRAPPER_DEFAULT_IFACE } = $ swiface ;
2009-01-28 19:28:51 +03:00
$ ret { NSS_WRAPPER_PASSWD } = $ nss_wrapper_passwd ;
$ ret { NSS_WRAPPER_GROUP } = $ nss_wrapper_group ;
2013-06-27 18:12:47 +04:00
$ ret { NSS_WRAPPER_HOSTS } = $ nss_wrapper_hosts ;
2014-10-29 19:40:22 +03:00
$ ret { NSS_WRAPPER_HOSTNAME } = "${hostname}.samba.example.com" ;
2013-06-12 17:42:01 +04:00
$ ret { NSS_WRAPPER_MODULE_SO_PATH } = Samba:: nss_wrapper_winbind_so_path ( $ self ) ;
$ ret { NSS_WRAPPER_MODULE_FN_PREFIX } = "winbind" ;
2014-09-04 16:33:05 +04:00
if ( $ ENV { SAMBA_DNS_FAKING } ) {
$ ret { RESOLV_WRAPPER_HOSTS } = $ dns_host_file ;
} else {
$ ret { RESOLV_WRAPPER_CONF } = $ resolv_conf ;
}
2010-06-02 17:35:33 +04:00
$ ret { LOCAL_PATH } = "$shrdir" ;
2013-04-22 14:35:01 +04:00
$ ret { LOGDIR } = $ logdir ;
2009-01-28 19:28:51 +03:00
2007-04-18 04:12:39 +04:00
return \ % ret ;
2007-03-21 18:57:07 +03:00
}
2012-11-23 03:09:43 +04:00
sub wait_for_start ($$$$$)
2007-03-21 18:57:07 +03:00
{
2012-11-23 03:09:43 +04:00
my ( $ self , $ envvars , $ nmbd , $ winbindd , $ smbd ) = @ _ ;
2012-11-23 03:18:44 +04:00
my $ ret ;
2012-11-23 03:09:43 +04:00
if ( $ nmbd eq "yes" ) {
2014-07-25 18:45:29 +04:00
my $ count = 0 ;
# give time for nbt server to register its names
print "checking for nmbd\n" ;
# This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
my $ nmblookup = Samba:: bindir_path ( $ self , "nmblookup" ) ;
do {
$ ret = system ( "$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}" ) ;
if ( $ ret != 0 ) {
sleep ( 1 ) ;
} else {
system ( "$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__" ) ;
system ( "$nmblookup $envvars->{CONFIGURATION} __SAMBA__" ) ;
system ( "$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__" ) ;
system ( "$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}" ) ;
}
$ count + + ;
} while ( $ ret != 0 && $ count < 10 ) ;
if ( $ count == 10 ) {
print "NMBD not reachable after 10 retries\n" ;
teardown_env ( $ self , $ envvars ) ;
return 0 ;
}
2012-11-23 03:09:43 +04:00
}
2011-04-07 07:07:23 +04:00
2012-11-23 03:18:44 +04:00
if ( $ winbindd eq "yes" ) {
print "checking for winbindd\n" ;
my $ count = 0 ;
do {
2014-05-24 01:44:58 +04:00
$ ret = system ( "SELFTEST_WINBINDD_SOCKET_DIR=" . $ envvars - > { SELFTEST_WINBINDD_SOCKET_DIR } . " " . Samba:: bindir_path ( $ self , "wbinfo" ) . " --ping-dc" ) ;
2012-11-23 03:18:44 +04:00
if ( $ ret != 0 ) {
sleep ( 2 ) ;
}
$ count + + ;
} while ( $ ret != 0 && $ count < 10 ) ;
if ( $ count == 10 ) {
print "WINBINDD not reachable after 20 seconds\n" ;
teardown_env ( $ self , $ envvars ) ;
return 0 ;
}
}
2012-11-23 03:09:43 +04:00
if ( $ smbd eq "yes" ) {
# make sure smbd is also up set
print "wait for smbd\n" ;
2007-04-18 18:02:26 +04:00
2012-11-23 03:09:43 +04:00
my $ count = 0 ;
do {
$ ret = system ( Samba:: bindir_path ( $ self , "smbclient3" ) . " $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139" ) ;
if ( $ ret != 0 ) {
sleep ( 2 ) ;
}
$ count + +
} while ( $ ret != 0 && $ count < 10 ) ;
if ( $ count == 10 ) {
print "SMBD failed to start up in a reasonable time (20sec)\n" ;
teardown_env ( $ self , $ envvars ) ;
return 0 ;
2011-04-07 07:07:23 +04:00
}
}
2012-11-23 03:09:43 +04:00
2010-11-09 00:39:51 +03:00
# Ensure we have domain users mapped.
2011-04-27 05:19:20 +04:00
$ ret = system ( Samba:: bindir_path ( $ self , "net" ) . " $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain" ) ;
2011-04-12 03:05:34 +04:00
if ( $ ret != 0 ) {
return 1 ;
}
2012-11-20 19:48:23 +04:00
$ ret = system ( Samba:: bindir_path ( $ self , "net" ) . " $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain" ) ;
if ( $ ret != 0 ) {
return 1 ;
}
2010-11-09 00:39:51 +03:00
2012-11-23 04:35:30 +04:00
if ( $ winbindd eq "yes" ) {
# note: creating builtin groups requires winbindd for the
# unix id allocator
2014-02-20 13:34:49 +04:00
$ ret = system ( "SELFTEST_WINBINDD_SOCKET_DIR=" . $ envvars - > { SELFTEST_WINBINDD_SOCKET_DIR } . " " . Samba:: bindir_path ( $ self , "net" ) . " $envvars->{CONFIGURATION} sam createbuiltingroup Users" ) ;
2012-11-23 04:35:30 +04:00
if ( $ ret != 0 ) {
print "Failed to create BUILTIN\\Users group\n" ;
return 0 ;
}
my $ count = 0 ;
do {
system ( Samba:: bindir_path ( $ self , "net" ) . " $envvars->{CONFIGURATION} cache flush" ) ;
2014-02-20 13:34:49 +04:00
$ ret = system ( "SELFTEST_WINBINDD_SOCKET_DIR=" . $ envvars - > { SELFTEST_WINBINDD_SOCKET_DIR } . " " . Samba:: bindir_path ( $ self , "wbinfo" ) . " --sid-to-gid=S-1-5-32-545" ) ;
2012-11-23 04:35:30 +04:00
if ( $ ret != 0 ) {
sleep ( 2 ) ;
}
$ count + + ;
} while ( $ ret != 0 && $ count < 10 ) ;
if ( $ count == 10 ) {
print "WINBINDD not reachable after 20 seconds\n" ;
teardown_env ( $ self , $ envvars ) ;
return 0 ;
}
}
2007-04-18 18:02:26 +04:00
print $ self - > getlog_env ( $ envvars ) ;
2011-04-12 03:05:34 +04:00
return 1 ;
2007-03-21 18:57:07 +03:00
}
1 ;