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 ;
2007-03-21 18:57:07 +03:00
2007-04-18 04:12:39 +04:00
sub binpath ($$)
{
my ( $ self , $ binary ) = @ _ ;
if ( defined ( $ self - > { bindir } ) ) {
my $ path = "$self->{bindir}/$binary" ;
- f $ path or die ( "File $path doesn't exist" ) ;
return $ path ;
}
return $ binary ;
}
sub new ($$) {
2011-02-22 03:56:18 +03:00
my ( $ classname , $ bindir , $ srcdir ) = @ _ ;
my $ self = { bindir = > $ bindir ,
srcdir = > $ srcdir
} ;
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 ) = @ _ ;
2007-03-21 18:57:07 +03:00
2007-09-02 21:47:35 +04:00
my $ smbdpid = read_pid ( $ envvars , "smbd" ) ;
my $ nmbdpid = read_pid ( $ envvars , "nmbd" ) ;
2009-01-28 19:28:51 +03:00
my $ winbinddpid = read_pid ( $ envvars , "winbindd" ) ;
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
sleep ( 2 ) ;
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 ) = @ _ ;
# TODO ...
return 1 ;
}
2007-04-18 04:12:39 +04:00
sub setup_env ($$$)
{
my ( $ self , $ envname , $ path ) = @ _ ;
2007-03-21 18:57:07 +03:00
2007-04-18 04:12:39 +04:00
if ( $ envname eq "dc" ) {
return $ self - > setup_dc ( "$path/dc" ) ;
2011-02-18 10:52:00 +03:00
} elsif ( $ envname eq "secshare" ) {
return $ self - > setup_secshare ( "$path/secshare" ) ;
2011-03-28 13:42:55 +04:00
} elsif ( $ envname eq "secserver" ) {
if ( not defined ( $ self - > { vars } - > { dc } ) ) {
$ self - > setup_dc ( "$path/dc" ) ;
}
return $ self - > setup_secserver ( "$path/secserver" , $ self - > { vars } - > { dc } ) ;
2009-01-28 23:01:04 +03: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-18 04:12:39 +04:00
} else {
2007-09-02 03:11:48 +04:00
return undef ;
2007-04-18 04:12:39 +04:00
}
}
sub setup_dc ($$)
{
my ( $ self , $ path ) = @ _ ;
2007-03-21 18:57:07 +03:00
2009-01-28 22:30:16 +03:00
print "PROVISIONING DC..." ;
my $ dc_options = "
domain master = yes
domain logons = yes
2009-05-08 02:18:28 +04:00
lanman auth = yes
2009-01-28 22:30:16 +03:00
" ;
my $ vars = $ self - > provision ( $ path ,
"LOCALDC2" ,
2 ,
"localdc2pass" ,
$ dc_options ) ;
2007-04-18 04:12:39 +04:00
2007-09-30 13:08:10 +04:00
$ self - > check_or_start ( $ vars ,
2009-03-20 18:18:47 +03:00
( $ ENV { SMBD_MAXTIME } or 2700 ) ,
"yes" , "yes" , "yes" ) ;
2007-04-18 04:12:39 +04:00
$ self - > wait_for_start ( $ vars ) ;
2011-02-21 08:01:44 +03:00
$ vars - > { DC_SERVER } = $ vars - > { SERVER } ;
$ vars - > { DC_SERVER_IP } = $ vars - > { SERVER_IP } ;
$ vars - > { DC_NETBIOSNAME } = $ vars - > { NETBIOSNAME } ;
$ vars - > { DC_USERNAME } = $ vars - > { USERNAME } ;
$ vars - > { DC_PASSWORD } = $ vars - > { PASSWORD } ;
2009-01-28 23:01:04 +03:00
$ self - > { vars } - > { dc } = $ vars ;
2007-04-18 04:12:39 +04:00
return $ vars ;
}
2009-01-28 23:01:04 +03:00
sub setup_member ($$$)
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "PROVISIONING MEMBER..." ;
my $ member_options = "
security = domain
2009-03-06 18:35:34 +03:00
server signing = on
2009-01-28 23:01:04 +03:00
" ;
my $ ret = $ self - > provision ( $ prefix ,
"LOCALMEMBER3" ,
3 ,
"localmember3pass" ,
$ member_options ) ;
$ ret or die ( "Unable to provision" ) ;
my $ net = $ self - > binpath ( "net" ) ;
my $ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
$ cmd . = "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member" ;
$ cmd . = " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}" ;
system ( $ cmd ) == 0 or die ( "Join failed\n$cmd" ) ;
$ self - > check_or_start ( $ ret ,
2009-03-20 18:18:47 +03:00
( $ ENV { SMBD_MAXTIME } or 2700 ) ,
"yes" , "yes" , "yes" ) ;
2009-01-28 23:01:04 +03:00
$ self - > wait_for_start ( $ ret ) ;
$ ret - > { DC_SERVER } = $ dcvars - > { SERVER } ;
$ ret - > { DC_SERVER_IP } = $ dcvars - > { SERVER_IP } ;
$ ret - > { DC_NETBIOSNAME } = $ dcvars - > { NETBIOSNAME } ;
$ ret - > { DC_USERNAME } = $ dcvars - > { USERNAME } ;
$ ret - > { DC_PASSWORD } = $ dcvars - > { PASSWORD } ;
return $ ret ;
}
2011-02-18 10:52:00 +03:00
sub setup_secshare ($$)
{
my ( $ self , $ path ) = @ _ ;
print "PROVISIONING server with security=share..." ;
my $ secshare_options = "
security = share
lanman auth = yes
" ;
my $ vars = $ self - > provision ( $ path ,
"LOCALSHARE4" ,
4 ,
"local4pass" ,
$ secshare_options ) ;
$ self - > check_or_start ( $ vars ,
( $ ENV { SMBD_MAXTIME } or 2700 ) ,
"yes" , "no" , "yes" ) ;
$ self - > wait_for_start ( $ vars ) ;
$ self - > { vars } - > { secshare } = $ vars ;
return $ vars ;
}
2011-03-28 13:42:55 +04:00
sub setup_secserver ($$$)
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "PROVISIONING server with security=server..." ;
my $ secserver_options = "
security = server
password server = $ dcvars - > { SERVER_IP }
" ;
my $ ret = $ self - > provision ( $ prefix ,
"LOCALSERVER5" ,
5 ,
"localserver5pass" ,
$ secserver_options ) ;
$ ret or die ( "Unable to provision" ) ;
$ self - > check_or_start ( $ ret ,
( $ ENV { SMBD_MAXTIME } or 2700 ) ,
"yes" , "no" , "yes" ) ;
$ self - > wait_for_start ( $ ret ) ;
$ ret - > { DC_SERVER } = $ dcvars - > { SERVER } ;
$ ret - > { DC_SERVER_IP } = $ dcvars - > { SERVER_IP } ;
$ ret - > { DC_NETBIOSNAME } = $ dcvars - > { NETBIOSNAME } ;
$ ret - > { DC_USERNAME } = $ dcvars - > { USERNAME } ;
$ ret - > { DC_PASSWORD } = $ dcvars - > { PASSWORD } ;
return $ ret ;
}
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
}
2009-03-20 18:18:47 +03:00
sub check_or_start ($$$$$) {
my ( $ self , $ env_vars , $ maxtime , $ nmbd , $ winbindd , $ smbd ) = @ _ ;
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 } ) ;
2007-09-30 13:08:10 +04:00
$ ENV { WINBINDD_SOCKET_DIR } = $ env_vars - > { 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 } ;
2009-06-06 01:21:54 +04:00
$ ENV { NSS_WRAPPER_WINBIND_SO_PATH } = $ env_vars - > { NSS_WRAPPER_WINBIND_SO_PATH } ;
2009-01-28 19:28:51 +03:00
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 ;
} ;
2009-03-20 18:18:47 +03:00
sleep ( $ maxtime ) ;
2009-02-04 17:16:42 +03:00
exit 0 ;
}
2007-10-08 16:57:30 +04:00
my @ optargs = ( "-d0" ) ;
if ( defined ( $ ENV { NMBD_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { NMBD_OPTIONS } ) ;
}
2007-04-18 04:12:39 +04:00
$ ENV { MAKE_TEST_BINARY } = $ self - > binpath ( "nmbd" ) ;
2007-10-10 21:40:19 +04:00
2009-03-20 18:18:47 +03:00
my @ preargs = ( $ self - > binpath ( "timelimit" ) , $ maxtime ) ;
2007-10-10 21:40:19 +04:00
if ( defined ( $ ENV { NMBD_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { NMBD_VALGRIND } ) ;
}
2011-01-11 01:24:51 +03:00
exec ( @ preargs , $ self - > binpath ( "nmbd" ) , "-F" , "--no-process-group" , "-S" , "-s" , $ env_vars - > { SERVERCONFFILE } , @ optargs ) or die ( "Unable to start nmbd: $!" ) ;
2007-03-21 18:57:07 +03:00
}
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 } ) ;
2009-01-28 11:35:44 +03:00
$ ENV { WINBINDD_SOCKET_DIR } = $ env_vars - > { 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 } ;
2009-06-06 01:21:54 +04:00
$ ENV { NSS_WRAPPER_WINBIND_SO_PATH } = $ env_vars - > { NSS_WRAPPER_WINBIND_SO_PATH } ;
2009-01-28 19:28:51 +03:00
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 ;
} ;
2009-03-20 18:18:47 +03:00
sleep ( $ maxtime ) ;
2009-02-04 17:16:42 +03:00
exit 0 ;
}
2009-01-28 11:35:44 +03:00
my @ optargs = ( "-d0" ) ;
if ( defined ( $ ENV { WINBINDD_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { WINBINDD_OPTIONS } ) ;
}
$ ENV { MAKE_TEST_BINARY } = $ self - > binpath ( "winbindd" ) ;
2009-01-28 19:28:51 +03:00
2009-03-20 18:18:47 +03:00
my @ preargs = ( $ self - > binpath ( "timelimit" ) , $ maxtime ) ;
2009-01-28 19:28:51 +03:00
if ( defined ( $ ENV { WINBINDD_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { WINBINDD_VALGRIND } ) ;
}
2010-03-26 15:23:31 +03:00
exec ( @ preargs , $ self - > binpath ( "winbindd" ) , "-F" , "--no-process-group" , "-s" , $ env_vars - > { SERVERCONFFILE } , @ optargs ) or die ( "Unable to start winbindd: $!" ) ;
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 } ) ;
2007-09-30 13:08:10 +04:00
$ ENV { WINBINDD_SOCKET_DIR } = $ env_vars - > { 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 } ;
2009-06-06 01:21:54 +04:00
$ ENV { NSS_WRAPPER_WINBIND_SO_PATH } = $ env_vars - > { NSS_WRAPPER_WINBIND_SO_PATH } ;
2009-01-28 19:28:51 +03:00
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 ;
} ;
2009-03-20 18:18:47 +03:00
sleep ( $ maxtime ) ;
2009-02-04 17:16:42 +03:00
exit 0 ;
}
2007-04-18 04:12:39 +04:00
$ ENV { MAKE_TEST_BINARY } = $ self - > binpath ( "smbd" ) ;
2007-10-08 16:57:30 +04:00
my @ optargs = ( "-d0" ) ;
if ( defined ( $ ENV { SMBD_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { SMBD_OPTIONS } ) ;
}
2009-03-20 18:18:47 +03:00
my @ preargs = ( $ self - > binpath ( "timelimit" ) , $ maxtime ) ;
2007-10-10 21:40:19 +04:00
if ( defined ( $ ENV { SMBD_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { SMBD_VALGRIND } ) ;
}
2010-03-26 15:23:31 +03:00
exec ( @ preargs , $ self - > binpath ( "smbd" ) , "-F" , "--no-process-group" , "-s" , $ env_vars - > { SERVERCONFFILE } , @ optargs ) or die ( "Unable to start smbd: $!" ) ;
2007-04-18 04:12:39 +04:00
}
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
2007-04-18 04:12:39 +04:00
return 0 ;
2007-03-21 18:57:07 +03:00
}
2009-01-28 22:30:16 +03:00
sub provision ($$$$$$)
2007-03-21 18:57:07 +03:00
{
2009-01-28 22:30:16 +03:00
my ( $ self , $ prefix , $ server , $ swiface , $ password , $ extra_options ) = @ _ ;
2007-04-18 04:12:39 +04:00
##
## setup the various environment variables we need
##
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" ;
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 } ) ;
2010-12-10 19:15:18 +03:00
my $ vfs_modulesdir_abs = ( $ ENV { VFSLIBDIR } or $ bindir_abs ) ;
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 ) ;
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'..." ;
system ( "rm -rf $prefix_abs/*" ) ;
2007-09-30 13:08:10 +04:00
mkdir ( $ _ , 0777 ) foreach ( @ dirs ) ;
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" ;
open ( UNREADABLE_FILE , ">$unreadable_file" ) or die ( "Unable to open $unreadable_file" ) ;
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" ;
open ( MSDFS_TARGET , ">$msdfs_target" ) or die ( "Unable to open $msdfs_target" ) ;
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" ;
symlink "msdfs:$server_ip\\ro-tmp" , "$msdfs_shrdir/deeppath/msdfs-src2" ;
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" ;
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 ) ;
my ( $ uid_nobody , $ uid_root ) ;
2010-11-09 00:39:51 +03:00
my ( $ gid_nobody , $ gid_nogroup , $ gid_root , $ gid_domusers ) ;
2010-03-19 12:23:39 +03:00
if ( $ unix_uid < 0xffff - 2 ) {
$ max_uid = 0xffff ;
} else {
$ max_uid = $ unix_uid ;
}
$ uid_root = $ max_uid - 1 ;
$ uid_nobody = $ max_uid - 2 ;
if ( $ unix_gids [ 0 ] < 0xffff - 3 ) {
$ 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 ;
2010-03-19 12:23:39 +03:00
##
## create conffile
##
2007-04-18 04:12:39 +04:00
open ( CONF , ">$conffile" ) or die ( "Unable to open $conffile" ) ;
print CONF "
[ global ]
2009-01-28 19:28:51 +03:00
netbios name = $ server
interfaces = $ server_ip / 8
bind interfaces only = yes
2011-02-22 03:56:18 +03:00
panic action = $ self - > { srcdir } /selftest/g db_backtrace % d % \ $ ( MAKE_TEST_BINARY )
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
log level = 0
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
2007-04-18 04:12:39 +04:00
name resolve order = bcast
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
syslog = no
printing = bsd
printcap name = /dev/ null
2007-09-26 23:23:54 +04:00
2007-09-30 13:08:10 +04:00
winbindd:socket dir = $ 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
2009-01-28 19:28:51 +03:00
# min receivefile size = 4000
2007-09-30 13:08:10 +04:00
2010-10-05 14:19:58 +04:00
max protocol = SMB2
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
2010-05-29 02:09:14 +04:00
# smbd:writetimeupdatedelay = 500000
map hidden = no
map system = no
map readonly = no
store dos attributes = yes
2007-04-18 04:12:39 +04:00
create mask = 755
2010-10-26 17:26:17 +04:00
vfs objects = $ vfs_modulesdir_abs /xattr_tdb.so $vfs_modulesdir_abs/s treams_depot . so
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
2010-03-25 02:55:13 +03:00
2011-03-02 17:27:12 +03:00
ncalrpc dir = $ lockdir / ncalrpc
2011-01-20 17:37:46 +03:00
rpc_server:epmapper = embedded
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-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
[ 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
[ 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
[ 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
2010-09-02 15:39:12 +04:00
[ lp ]
2007-04-18 04:12:39 +04:00
copy = print1
2010-04-23 15:51:02 +04:00
[ print \ $]
copy = tmp
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
##
2009-01-28 19:28:51 +03:00
open ( PASSWD , ">$nss_wrapper_passwd" ) or die ( "Unable to open $nss_wrapper_passwd" ) ;
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
" ;
2010-03-18 14:12:58 +03:00
if ( $ unix_uid != 0 ) {
print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false" ;
}
2009-01-28 19:28:51 +03:00
close ( PASSWD ) ;
open ( GROUP , ">$nss_wrapper_group" ) or die ( "Unable to open $nss_wrapper_group" ) ;
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:
2009-01-28 19:28:51 +03:00
" ;
2010-03-18 14:12:58 +03:00
if ( $ unix_gids [ 0 ] != 0 ) {
print GROUP "root:x:$gid_root:" ;
}
2009-01-28 19:28:51 +03:00
close ( GROUP ) ;
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 ;
open ( PWD , "|" . $ self - > binpath ( "smbpasswd" ) . " -c $conffile -L -s -a $unix_name >/dev/null" ) ;
2007-04-18 04:12:39 +04:00
print PWD "$password\n$password\n" ;
close ( PWD ) or die ( "Unable to set password for test account" ) ;
print "DONE\n" ;
$ ret { SERVER_IP } = $ server_ip ;
$ 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 ;
2007-09-30 13:08:10 +04:00
$ ret { 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 ;
2009-06-06 01:21:54 +04:00
$ ret { NSS_WRAPPER_WINBIND_SO_PATH } = $ ENV { NSS_WRAPPER_WINBIND_SO_PATH } ;
2010-06-02 17:35:33 +04:00
$ ret { LOCAL_PATH } = "$shrdir" ;
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
}
2007-04-18 04:12:39 +04:00
sub wait_for_start ($$)
2007-03-21 18:57:07 +03:00
{
2007-04-18 04:12:39 +04:00
my ( $ self , $ envvars ) = @ _ ;
# give time for nbt server to register its names
print "delaying for nbt name registration\n" ;
sleep ( 10 ) ;
# This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
system ( $ self - > binpath ( "nmblookup" ) . " $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__" ) ;
system ( $ self - > binpath ( "nmblookup" ) . " $envvars->{CONFIGURATION} __SAMBA__" ) ;
system ( $ self - > binpath ( "nmblookup" ) . " $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__" ) ;
system ( $ self - > binpath ( "nmblookup" ) . " $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}" ) ;
system ( $ self - > binpath ( "nmblookup" ) . " $envvars->{CONFIGURATION} $envvars->{SERVER}" ) ;
# make sure smbd is also up set
print "wait for smbd\n" ;
system ( $ self - > binpath ( "smbclient" ) . " $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2" ) ;
system ( $ self - > binpath ( "smbclient" ) . " $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2" ) ;
2007-04-18 18:02:26 +04:00
2010-11-09 00:39:51 +03:00
# Ensure we have domain users mapped.
system ( $ self - > binpath ( "net" ) . " $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain" ) ;
2007-04-18 18:02:26 +04:00
print $ self - > getlog_env ( $ envvars ) ;
2007-03-21 18:57:07 +03:00
}
1 ;