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.
2018-11-09 01:44:18 +03:00
# NOTE: Refer to the README for more details about the various testenvs,
# and tips about adding new testenvs.
2007-03-06 00:28:55 +03:00
package Samba4 ;
use strict ;
2019-12-07 12:37:00 +03:00
use warnings ;
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 ;
2010-11-27 05:03:50 +03:00
use SocketWrapper ;
2011-04-27 05:19:20 +04:00
use target::Samba ;
2011-04-19 10:38:46 +04:00
use target::Samba3 ;
2018-10-26 01:08:54 +03:00
use Archive::Tar ;
2007-03-06 00:28:55 +03:00
2009-01-21 12:14:29 +03:00
sub new ($$$$$) {
2022-11-22 12:31:19 +03:00
my ( $ classname , $ SambaCtx , $ bindir , $ srcdir , $ server_maxtime , $ default_ldb_backend ) = @ _ ;
2011-04-15 06:27:30 +04:00
2010-11-01 01:05:03 +03:00
my $ self = {
vars = > { } ,
2019-10-30 23:53:39 +03:00
SambaCtx = > $ SambaCtx ,
2010-11-01 01:05:03 +03:00
bindir = > $ bindir ,
2011-02-03 07:14:31 +03:00
srcdir = > $ srcdir ,
2011-04-19 10:38:46 +04:00
server_maxtime = > $ server_maxtime ,
2022-11-22 12:31:19 +03:00
target3 = > new Samba3 ( $ SambaCtx , $ bindir , $ srcdir , $ server_maxtime ) ,
default_ldb_backend = > $ default_ldb_backend ,
2007-04-17 04:30:01 +04:00
} ;
2007-03-21 18:57:07 +03:00
bless $ self ;
return $ self ;
}
2011-02-03 07:14:31 +03:00
sub scriptdir_path ($$) {
my ( $ self , $ path ) = @ _ ;
return "$self->{srcdir}/source4/scripting/$path" ;
}
2011-08-12 08:37:04 +04:00
sub check_or_start ($$$)
2007-03-06 00:28:55 +03:00
{
2012-03-04 10:30:45 +04:00
my ( $ self , $ env_vars , $ process_model ) = @ _ ;
2013-09-19 16:52:59 +04:00
my $ STDIN_READER ;
2007-03-21 18:57:07 +03:00
2015-12-07 03:18:38 +03:00
my $ env_ok = $ self - > check_env ( $ env_vars ) ;
if ( $ env_ok ) {
2016-05-05 02:35:46 +03:00
return $ env_vars - > { SAMBA_PID } ;
} elsif ( defined ( $ env_vars - > { SAMBA_PID } ) ) {
warn ( "SAMBA PID $env_vars->{SAMBA_PID} is not running (died)" ) ;
return undef ;
2015-12-07 03:18:38 +03:00
}
2012-03-04 10:30:45 +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
2013-09-19 16:52:59 +04:00
pipe ( $ STDIN_READER , $ env_vars - > { STDIN_PIPE } ) ;
2019-05-23 04:45:49 +03:00
# build up the command to run samba
2019-05-23 03:12:44 +03:00
my @ preargs = ( ) ;
my @ optargs = ( ) ;
if ( defined ( $ ENV { SAMBA_OPTIONS } ) ) {
@ optargs = split ( / / , $ ENV { SAMBA_OPTIONS } ) ;
}
if ( defined ( $ ENV { SAMBA_VALGRIND } ) ) {
@ preargs = split ( / / , $ ENV { SAMBA_VALGRIND } ) ;
}
if ( defined ( $ process_model ) ) {
push @ optargs , ( "-M" , $ process_model ) ;
}
2019-05-23 04:45:49 +03:00
my $ binary = Samba:: bindir_path ( $ self , "samba" ) ;
my @ full_cmd = ( @ preargs , $ binary , "-i" ,
2019-05-23 03:12:44 +03:00
"--no-process-group" , "--maximum-runtime=$self->{server_maxtime}" ,
$ env_vars - > { CONFIGURATION } , @ optargs ) ;
2019-05-23 06:47:46 +03:00
# the samba process takes some additional env variables (compared to s3)
my $ samba_envs = Samba:: get_env_for_process ( "samba" , $ env_vars ) ;
if ( defined ( $ ENV { MITKRB5 } ) ) {
$ samba_envs - > { KRB5_KDC_PROFILE } = $ env_vars - > { MITKDC_CONFIG } ;
}
2019-05-23 07:35:07 +03:00
# fork a child process and exec() samba
2019-05-23 07:58:20 +03:00
my $ daemon_ctx = {
2019-05-23 04:45:49 +03:00
NAME = > "samba" ,
BINARY_PATH = > $ binary ,
FULL_CMD = > [ @ full_cmd ] ,
LOG_FILE = > $ env_vars - > { SAMBA_TEST_LOG } ,
TEE_STDOUT = > 1 ,
2019-10-30 23:53:39 +03:00
PCAP_FILE = > "env-$ENV{ENVNAME}-samba" ,
2019-05-23 06:47:46 +03:00
ENV_VARS = > $ samba_envs ,
2019-05-23 07:58:20 +03:00
} ;
my $ pid = Samba:: fork_and_exec ( $ self , $ env_vars , $ daemon_ctx , $ STDIN_READER ) ;
2019-05-23 03:12:44 +03:00
2012-03-04 10:30:45 +04:00
$ env_vars - > { SAMBA_PID } = $ pid ;
2007-03-06 00:28:55 +03:00
2019-05-23 07:35:07 +03:00
# close the parent's read-end of the pipe
2013-09-19 16:52:59 +04:00
close ( $ STDIN_READER ) ;
2007-03-21 18:57:07 +03:00
2015-12-07 03:18:38 +03:00
if ( $ self - > wait_for_start ( $ env_vars ) != 0 ) {
warn ( "Samba $pid failed to start up" ) ;
return undef ;
}
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 ) = @ _ ;
2016-06-17 11:01:19 +03:00
my $ count = 0 ;
2015-12-07 03:18:38 +03:00
my $ ret = 0 ;
if ( not $ self - > check_env ( $ testenv_vars ) ) {
warn ( "unable to confirm Samba $testenv_vars->{SAMBA_PID} is running" ) ;
return - 1 ;
}
2010-11-01 01:05:03 +03:00
# This will return quickly when things are up, but be slow if we
# need to wait for (eg) SSL init
2012-05-25 03:44:17 +04:00
my $ nmblookup = Samba:: bindir_path ( $ self , "nmblookup4" ) ;
2016-06-17 11:01:19 +03:00
do {
$ ret = system ( "$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}" ) ;
if ( $ ret != 0 ) {
sleep ( 1 ) ;
} else {
system ( "$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}" ) ;
system ( "$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}" ) ;
}
$ count + + ;
} while ( $ ret != 0 && $ count < 20 ) ;
2017-06-15 07:19:17 +03:00
if ( $ count == 20 ) {
2016-06-17 11:01:19 +03:00
teardown_env ( $ self , $ testenv_vars ) ;
2019-01-30 15:44:04 +03:00
warn ( "nbt not reachable after 20 retries\n" ) ;
return - 1 ;
2016-06-17 11:01:19 +03:00
}
2007-04-18 18:02:26 +04:00
2013-06-19 05:33:36 +04:00
# Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
2017-03-27 05:26:48 +03:00
if ( $ testenv_vars - > { SERVER_ROLE } eq "domain controller" ) {
print "waiting for working LDAP and a RID Set to be allocated\n" ;
my $ ldbsearch = Samba:: bindir_path ( $ self , "ldbsearch" ) ;
my $ count = 0 ;
my $ base_dn = "DC=" . join ( ",DC=" , split ( /\./ , $ testenv_vars - > { REALM } ) ) ;
my $ search_dn = $ base_dn ;
if ( $ testenv_vars - > { NETBIOSNAME } ne "RODC" ) {
# TODO currently no check for actual rIDAllocationPool
$ search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn" ;
}
my $ max_wait = 60 ;
2018-01-10 03:28:13 +03:00
# Add hosts file for name lookups
2020-11-23 13:35:33 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ testenv_vars ) ;
2018-01-10 03:28:13 +03:00
$ cmd . = "$ldbsearch " ;
$ cmd . = "$testenv_vars->{CONFIGURATION} " ;
$ cmd . = "-H ldap://$testenv_vars->{SERVER} " ;
$ cmd . = "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} " ;
2020-12-17 14:25:15 +03:00
$ cmd . = "--scope base " ;
2018-01-10 03:28:13 +03:00
$ cmd . = "-b '$search_dn' " ;
2017-03-27 05:26:48 +03:00
while ( system ( "$cmd >/dev/null" ) != 0 ) {
$ count + + ;
if ( $ count > $ max_wait ) {
2019-01-30 15:44:04 +03:00
teardown_env ( $ self , $ testenv_vars ) ;
2017-03-27 05:26:48 +03:00
warn ( "Timed out ($max_wait sec) waiting for working LDAP and a RID Set to be allocated by $testenv_vars->{NETBIOSNAME} PID $testenv_vars->{SAMBA_PID}" ) ;
2019-01-30 15:44:04 +03:00
return - 1 ;
2017-03-27 05:26:48 +03:00
}
2019-01-30 15:44:04 +03:00
print "Waiting for working LDAP...\n" ;
2017-03-27 05:26:48 +03:00
sleep ( 1 ) ;
2013-06-19 05:33:36 +04:00
}
}
2017-06-15 07:20:11 +03:00
my $ wbinfo = Samba:: bindir_path ( $ self , "wbinfo" ) ;
$ count = 0 ;
do {
my $ cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} " ;
$ cmd . = "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} " ;
$ cmd . = "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} " ;
2018-08-20 01:14:16 +03:00
$ cmd . = "$wbinfo -P" ;
2017-06-15 07:20:11 +03:00
$ ret = system ( $ cmd ) ;
if ( $ ret != 0 ) {
sleep ( 1 ) ;
}
$ count + + ;
} while ( $ ret != 0 && $ count < 20 ) ;
if ( $ count == 20 ) {
teardown_env ( $ self , $ testenv_vars ) ;
2019-01-30 15:44:04 +03:00
warn ( "winbind not reachable after 20 retries\n" ) ;
return - 1 ;
2017-06-15 07:20:11 +03:00
}
2019-01-29 15:57:04 +03:00
# Ensure we registered all our names
if ( $ testenv_vars - > { SERVER_ROLE } eq "domain controller" ) {
2019-05-07 02:20:55 +03:00
my $ max_wait = 120 ;
2020-11-23 10:54:29 +03:00
my $ dns_update_cache = "$testenv_vars->{PRIVATEDIR}/dns_update_cache" ;
print "Waiting for $dns_update_cache to be created.\n" ;
2019-01-29 15:57:04 +03:00
$ count = 0 ;
2020-11-23 10:54:29 +03:00
while ( not - e $ dns_update_cache ) {
2019-01-29 15:57:04 +03:00
$ count + + ;
if ( $ count > $ max_wait ) {
teardown_env ( $ self , $ testenv_vars ) ;
2020-11-23 10:54:29 +03:00
warn ( "Timed out ($max_wait sec) waiting for $dns_update_cache PID $testenv_vars->{SAMBA_PID}" ) ;
2019-01-29 15:57:04 +03:00
return - 1 ;
}
2020-11-23 10:54:29 +03:00
print "Waiting for $dns_update_cache to be created...\n" ;
2019-01-29 15:57:04 +03:00
sleep ( 1 ) ;
}
2020-11-23 10:54:29 +03:00
print "Waiting for $dns_update_cache to be filled.\n" ;
2019-01-29 15:57:04 +03:00
$ count = 0 ;
2020-11-23 10:54:29 +03:00
while ( ( - s "$dns_update_cache" ) == 0 ) {
2019-01-29 15:57:04 +03:00
$ count + + ;
if ( $ count > $ max_wait ) {
teardown_env ( $ self , $ testenv_vars ) ;
2020-11-23 10:54:29 +03:00
warn ( "Timed out ($max_wait sec) waiting for $dns_update_cache PID $testenv_vars->{SAMBA_PID}" ) ;
2019-01-29 15:57:04 +03:00
return - 1 ;
}
2020-11-23 10:54:29 +03:00
print "Waiting for $dns_update_cache to be filled...\n" ;
2019-01-29 15:57:04 +03:00
sleep ( 1 ) ;
}
}
2007-04-18 18:02:26 +04:00
print $ self - > getlog_env ( $ testenv_vars ) ;
2013-06-19 05:33:36 +04:00
2019-01-30 15:44:04 +03:00
print "READY ($testenv_vars->{SAMBA_PID})\n" ;
return 0
2007-03-06 00:28:55 +03:00
}
2007-04-17 04:30:01 +04:00
sub write_ldb_file ($$$)
{
2021-10-18 01:55:14 +03:00
my ( $ self , $ file , $ ldif_in ) = @ _ ;
2007-04-17 04:30:01 +04:00
2011-04-27 05:19:20 +04:00
my $ ldbadd = Samba:: bindir_path ( $ self , "ldbadd" ) ;
2021-10-18 01:55:14 +03:00
open ( my $ ldif , "|$ldbadd -H $file > /dev/null" )
or die "Failed to run $ldbadd: $!" ;
print $ ldif $ ldif_in ;
close ( $ ldif ) ;
unless ( $? == 0 ) {
warn ( "$ldbadd failed: $?" ) ;
return undef ;
}
return 1 ;
2007-04-17 04:30:01 +04:00
}
sub add_wins_config ($$)
{
my ( $ self , $ privatedir ) = @ _ ;
2019-02-14 04:37:16 +03:00
my $ client_ip = Samba:: get_ipv4_addr ( "client" ) ;
2007-04-17 04:30:01 +04:00
return $ self - > write_ldb_file ( "$privatedir/wins_config.ldb" , "
2010-06-16 13:02:48 +04:00
dn: name = TORTURE_11 , CN = PARTNERS
2007-04-17 04:30:01 +04:00
objectClass: wreplPartner
2010-06-16 13:02:48 +04:00
name: TORTURE_11
2019-02-14 04:37:16 +03:00
address: $ client_ip
2007-04-17 04:30:01 +04:00
pullInterval: 0
pushChangeCount: 0
type: 0x3
" ) ;
}
2018-02-06 11:46:41 +03:00
sub setup_dns_hub_internal ($$$)
{
my ( $ self , $ hostname , $ prefix ) = @ _ ;
my $ STDIN_READER ;
2020-12-17 12:42:03 +03:00
unless ( - d $ prefix or mkdir ( $ prefix , 0777 ) ) {
2018-02-06 11:46:41 +03:00
warn ( "Unable to create $prefix" ) ;
return undef ;
}
my $ prefix_abs = abs_path ( $ prefix ) ;
die ( "prefix=''" ) if $ prefix_abs eq "" ;
die ( "prefix='/'" ) if $ prefix_abs eq "/" ;
unless ( system ( "rm -rf $prefix_abs/*" ) == 0 ) {
warn ( "Unable to clean up" ) ;
}
my $ env = undef ;
2019-03-12 07:39:50 +03:00
$ env - > { NETBIOSNAME } = $ hostname ;
2018-02-06 11:46:41 +03:00
2019-03-12 07:39:50 +03:00
$ env - > { SERVER_IP } = Samba:: get_ipv4_addr ( $ hostname ) ;
$ env - > { SERVER_IPV6 } = Samba:: get_ipv6_addr ( $ hostname ) ;
2019-05-23 04:45:49 +03:00
$ env - > { SOCKET_WRAPPER_DEFAULT_IFACE } = Samba:: get_interface ( $ hostname ) ;
2018-02-06 11:46:41 +03:00
$ env - > { DNS_HUB_LOG } = "$prefix_abs/dns_hub.log" ;
$ env - > { RESOLV_CONF } = "$prefix_abs/resolv.conf" ;
2019-03-14 07:38:22 +03:00
$ env - > { TESTENV_DIR } = $ prefix_abs ;
2018-02-06 11:46:41 +03:00
2019-10-31 17:37:40 +03:00
my $ ctx = undef ;
$ ctx - > { resolv_conf } = $ env - > { RESOLV_CONF } ;
$ ctx - > { dns_ipv4 } = $ env - > { SERVER_IP } ;
$ ctx - > { dns_ipv6 } = $ env - > { SERVER_IPV6 } ;
Samba:: mk_resolv_conf ( $ ctx ) ;
2018-02-06 11:46:41 +03:00
2019-05-23 03:12:44 +03:00
my @ preargs = ( ) ;
my @ args = ( ) ;
if ( ! defined ( $ ENV { PYTHON } ) ) {
push ( @ preargs , "env" ) ;
push ( @ preargs , "python" ) ;
} else {
push ( @ preargs , $ ENV { PYTHON } ) ;
}
my $ binary = "$self->{srcdir}/selftest/target/dns_hub.py" ;
push ( @ args , "$self->{server_maxtime}" ) ;
2020-03-11 19:03:01 +03:00
push ( @ args , "$env->{SERVER_IP},$env->{SERVER_IPV6}" ) ;
2019-05-23 03:12:44 +03:00
push ( @ args , Samba:: realm_to_ip_mappings ( ) ) ;
my @ full_cmd = ( @ preargs , $ binary , @ args ) ;
2019-05-23 07:35:07 +03:00
2019-05-23 07:58:20 +03:00
my $ daemon_ctx = {
2019-05-23 04:45:49 +03:00
NAME = > "dnshub" ,
BINARY_PATH = > $ binary ,
FULL_CMD = > [ @ full_cmd ] ,
LOG_FILE = > $ env - > { DNS_HUB_LOG } ,
TEE_STDOUT = > 1 ,
2019-10-30 23:53:39 +03:00
PCAP_FILE = > "env-$ENV{ENVNAME}-dns_hub" ,
2019-05-23 06:47:46 +03:00
ENV_VARS = > { } ,
2019-05-23 07:58:20 +03:00
} ;
2019-05-23 03:12:44 +03:00
2018-02-06 11:46:41 +03: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 - > { STDIN_PIPE } ) ;
2019-05-23 07:58:20 +03:00
my $ pid = Samba:: fork_and_exec ( $ self , $ env , $ daemon_ctx , $ STDIN_READER ) ;
2019-05-23 06:47:46 +03:00
2018-02-06 11:46:41 +03:00
$ env - > { SAMBA_PID } = $ pid ;
2019-03-13 00:30:25 +03:00
$ env - > { KRB5_CONFIG } = "$prefix_abs/no_krb5.conf" ;
2019-05-23 07:35:07 +03:00
# close the parent's read-end of the pipe
2018-02-06 11:46:41 +03:00
close ( $ STDIN_READER ) ;
return $ env ;
}
sub setup_dns_hub
{
my ( $ self , $ prefix ) = @ _ ;
my $ hostname = "rootdnsforwarder" ;
2020-12-17 12:42:03 +03:00
unless ( - d $ prefix or mkdir ( $ prefix , 0777 ) ) {
warn ( "Unable to create $prefix" ) ;
return undef ;
}
2018-02-06 11:46:41 +03:00
my $ env = $ self - > setup_dns_hub_internal ( "$hostname" , "$prefix/$hostname" ) ;
$ self - > { dns_hub_env } = $ env ;
return $ env ;
}
sub get_dns_hub_env ($)
{
my ( $ self , $ prefix ) = @ _ ;
if ( defined ( $ self - > { dns_hub_env } ) ) {
return $ self - > { dns_hub_env } ;
}
die ( "get_dns_hub_env() not setup 'dns_hub_env'" ) ;
return undef ;
}
2020-11-23 13:35:33 +03:00
sub return_env_value
{
my ( $ env , $ overwrite , $ key ) = @ _ ;
if ( defined ( $ overwrite ) and defined ( $ overwrite - > { $ key } ) ) {
return $ overwrite - > { $ key } ;
}
if ( defined ( $ env - > { $ key } ) ) {
return $ env - > { $ key } ;
}
return undef ;
}
2019-01-30 06:31:40 +03:00
# Returns the environmental variables that we pass to samba-tool commands
sub get_cmd_env_vars
{
2020-11-23 13:35:33 +03:00
my ( $ self , $ givenenv , $ overwrite ) = @ _ ;
my @ keys = (
"NSS_WRAPPER_HOSTS" ,
"SOCKET_WRAPPER_DEFAULT_IFACE" ,
"RESOLV_CONF" ,
"RESOLV_WRAPPER_CONF" ,
"RESOLV_WRAPPER_HOSTS" ,
"GNUTLS_FORCE_FIPS_MODE" ,
"OPENSSL_FORCE_FIPS_MODE" ,
"KRB5_CONFIG" ,
"KRB5_CCACHE" ,
2020-11-23 01:28:31 +03:00
"GNUPGHOME" ,
2020-11-23 13:35:33 +03:00
) ;
my $ localenv = undef ;
foreach my $ key ( @ keys ) {
my $ v = return_env_value ( $ givenenv , $ overwrite , $ key ) ;
$ localenv - > { $ key } = $ v if defined ( $ v ) ;
}
2019-01-30 06:31:40 +03:00
my $ cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' " ;
$ cmd_env . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
if ( defined ( $ localenv - > { RESOLV_WRAPPER_CONF } ) ) {
$ cmd_env . = "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" " ;
} else {
$ cmd_env . = "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" " ;
}
2020-03-13 16:36:18 +03:00
if ( defined ( $ localenv - > { GNUTLS_FORCE_FIPS_MODE } ) ) {
$ cmd_env . = "GNUTLS_FORCE_FIPS_MODE=$localenv->{GNUTLS_FORCE_FIPS_MODE} " ;
}
2020-03-16 11:39:48 +03:00
if ( defined ( $ localenv - > { OPENSSL_FORCE_FIPS_MODE } ) ) {
$ cmd_env . = "OPENSSL_FORCE_FIPS_MODE=$localenv->{OPENSSL_FORCE_FIPS_MODE} " ;
}
2020-11-23 13:35:33 +03:00
$ cmd_env . = "KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" " ;
2019-01-30 06:31:40 +03:00
$ cmd_env . = "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" " ;
$ cmd_env . = "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" " ;
2020-11-23 01:28:31 +03:00
$ cmd_env . = "GNUPGHOME=\"$localenv->{GNUPGHOME}\" " ;
2019-01-30 06:31:40 +03:00
return $ cmd_env ;
}
2019-05-23 08:44:37 +03:00
# Sets up a forest trust namespace.
# (Note this is different to kernel namespaces, setup by the
# USE_NAMESPACES=1 option)
2019-12-07 12:56:00 +03:00
sub setup_namespaces
2015-05-11 14:45:59 +03:00
{
my ( $ self , $ localenv , $ upn_array , $ spn_array ) = @ _ ;
@ { $ upn_array } = [] unless defined ( $ upn_array ) ;
my $ upn_args = "" ;
foreach my $ upn ( @ { $ upn_array } ) {
$ upn_args . = " --add-upn-suffix=$upn" ;
}
@ { $ spn_array } = [] unless defined ( $ spn_array ) ;
my $ spn_args = "" ;
foreach my $ spn ( @ { $ spn_array } ) {
$ spn_args . = " --add-spn-suffix=$spn" ;
}
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2019-01-30 06:31:40 +03:00
my $ cmd_env = $ self - > get_cmd_env_vars ( $ localenv ) ;
2015-05-11 14:45:59 +03:00
my $ cmd_config = " $localenv->{CONFIGURATION}" ;
my $ namespaces = $ cmd_env ;
$ namespaces . = " $samba_tool domain trust namespaces $upn_args $spn_args" ;
$ namespaces . = $ cmd_config ;
unless ( system ( $ namespaces ) == 0 ) {
warn ( "Failed to add namespaces \n$namespaces" ) ;
2021-04-08 16:54:18 +03:00
return - 1 ;
2015-05-11 14:45:59 +03:00
}
2021-04-08 16:54:18 +03:00
return 0 ;
2015-05-11 14:45:59 +03:00
}
2015-02-11 11:58:07 +03:00
sub setup_trust ($$$$$)
{
my ( $ self , $ localenv , $ remoteenv , $ type , $ extra_args ) = @ _ ;
$ localenv - > { TRUST_SERVER } = $ remoteenv - > { SERVER } ;
2021-06-18 14:40:59 +03:00
$ localenv - > { TRUST_SERVER_IP } = $ remoteenv - > { SERVER_IP } ;
$ localenv - > { TRUST_DNSNAME } = $ remoteenv - > { DNSNAME } ;
2019-02-13 04:50:12 +03:00
2015-02-11 11:58:07 +03:00
$ localenv - > { TRUST_USERNAME } = $ remoteenv - > { USERNAME } ;
$ localenv - > { TRUST_PASSWORD } = $ remoteenv - > { PASSWORD } ;
$ localenv - > { TRUST_DOMAIN } = $ remoteenv - > { DOMAIN } ;
$ localenv - > { TRUST_REALM } = $ remoteenv - > { REALM } ;
2018-02-26 16:56:27 +03:00
$ localenv - > { TRUST_DOMSID } = $ remoteenv - > { DOMSID } ;
2015-02-11 11:58:07 +03:00
2021-06-18 14:40:59 +03:00
# Add trusted domain realms to krb5.conf
Samba:: append_krb5_conf_trust_realms ( $ localenv ) ;
2015-02-11 11:58:07 +03:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2018-09-27 11:30:40 +03:00
2015-02-11 11:58:07 +03:00
# setup the trust
2019-01-30 06:31:40 +03:00
my $ cmd_env = $ self - > get_cmd_env_vars ( $ localenv ) ;
2015-02-11 11:58:07 +03:00
my $ cmd_config = " $localenv->{CONFIGURATION}" ;
my $ cmd_creds = $ cmd_config ;
$ cmd_creds . = " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}" ;
my $ create = $ cmd_env ;
$ create . = " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}" ;
$ create . = " $extra_args" ;
$ create . = $ cmd_creds ;
unless ( system ( $ create ) == 0 ) {
warn ( "Failed to create trust \n$create" ) ;
return undef ;
}
2018-02-26 19:05:49 +03:00
my $ groupname = "g_$localenv->{TRUST_DOMAIN}" ;
my $ groupadd = $ cmd_env ;
$ groupadd . = " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config" ;
unless ( system ( $ groupadd ) == 0 ) {
warn ( "Failed to create group \n$groupadd" ) ;
return undef ;
}
my $ groupmem = $ cmd_env ;
$ groupmem . = " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config" ;
unless ( system ( $ groupmem ) == 0 ) {
warn ( "Failed to add group member \n$groupmem" ) ;
return undef ;
}
2015-02-11 11:58:07 +03:00
return $ localenv
}
2020-03-13 16:33:08 +03:00
sub provision_raw_prepare ($$$$$$$$$$$$$$)
2007-04-17 04:30:01 +04:00
{
2020-03-13 15:58:57 +03:00
my ( $ self ,
$ prefix ,
$ server_role ,
$ hostname ,
$ domain ,
$ realm ,
$ samsid ,
$ functional_level ,
$ password ,
$ kdc_ipv4 ,
$ kdc_ipv6 ,
2020-03-13 16:33:08 +03:00
$ force_fips_mode ,
2020-03-13 15:58:57 +03:00
$ extra_provision_options ) = @ _ ;
2009-02-04 13:18:32 +03:00
my $ ctx ;
2018-09-27 11:30:40 +03:00
my $ python_cmd = "" ;
if ( defined $ ENV { PYTHON } ) {
$ python_cmd = $ ENV { PYTHON } . " " ;
}
$ ctx - > { python } = $ python_cmd ;
2011-06-24 20:50:51 +04:00
my $ netbiosname = uc ( $ hostname ) ;
2007-04-17 04:30:01 +04:00
2010-09-14 16:41:42 +04:00
unless ( - d $ prefix or mkdir ( $ prefix , 0777 ) ) {
warn ( "Unable to create $prefix" ) ;
return undef ;
}
2007-04-17 17:06:00 +04:00
my $ prefix_abs = abs_path ( $ prefix ) ;
2007-04-17 19:33:50 +04:00
2009-02-04 13:18:32 +03:00
die ( "prefix=''" ) if $ prefix_abs eq "" ;
die ( "prefix='/'" ) if $ prefix_abs eq "/" ;
2007-04-17 04:30:01 +04:00
2010-09-14 16:41:42 +04:00
unless ( system ( "rm -rf $prefix_abs/*" ) == 0 ) {
warn ( "Unable to clean up" ) ;
}
2007-04-17 04:30:01 +04:00
2023-12-08 15:06:27 +03:00
2012-03-02 04:44:56 +04:00
my $ swiface = Samba:: get_interface ( $ hostname ) ;
2009-02-04 13:18:32 +03:00
$ ctx - > { prefix } = $ prefix ;
$ ctx - > { prefix_abs } = $ prefix_abs ;
2010-02-24 07:09:28 +03:00
2009-02-04 13:18:32 +03:00
$ ctx - > { server_role } = $ server_role ;
2011-06-24 20:50:51 +04:00
$ ctx - > { hostname } = $ hostname ;
2009-02-04 13:18:32 +03:00
$ ctx - > { netbiosname } = $ netbiosname ;
$ ctx - > { swiface } = $ swiface ;
$ ctx - > { password } = $ password ;
2009-02-10 20:00:48 +03:00
$ ctx - > { kdc_ipv4 } = $ kdc_ipv4 ;
2014-09-10 12:59:39 +04:00
$ ctx - > { kdc_ipv6 } = $ kdc_ipv6 ;
2020-03-13 16:33:08 +03:00
$ ctx - > { force_fips_mode } = $ force_fips_mode ;
2016-09-22 19:46:28 +03:00
$ ctx - > { krb5_ccname } = "$prefix_abs/krb5cc_%{uid}" ;
2016-04-27 02:00:14 +03:00
if ( $ functional_level eq "2000" ) {
2020-04-21 12:07:45 +03:00
$ ctx - > { supported_enctypes } = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc" ;
2016-04-27 02:00:14 +03:00
}
2007-04-17 19:33:50 +04:00
2012-08-31 23:41:48 +04:00
#
# Set smbd log level here.
#
2010-11-23 23:47:36 +03:00
$ ctx - > { server_loglevel } = $ ENV { SERVER_LOG_LEVEL } || 1 ;
2009-07-27 16:39:10 +04:00
$ ctx - > { username } = "Administrator" ;
2010-06-15 16:24:36 +04:00
$ ctx - > { domain } = $ domain ;
$ ctx - > { realm } = uc ( $ realm ) ;
$ ctx - > { dnsname } = lc ( $ realm ) ;
2018-02-26 16:56:27 +03:00
$ ctx - > { samsid } = $ samsid ;
2023-12-08 15:07:19 +03:00
$ ctx - > { domain_admin } = "Administrator" ;
$ ctx - > { domain_admin_password } = $ password ;
$ ctx - > { domain_user } = "alice" ;
$ ctx - > { domain_user_password } = "Secret007" ;
2009-02-04 13:18:32 +03:00
2010-06-15 16:24:36 +04:00
$ ctx - > { functional_level } = $ functional_level ;
2009-02-04 13:18:32 +03:00
my $ unix_name = ( $ ENV { USER } or $ ENV { LOGNAME } or `whoami` ) ;
chomp $ unix_name ;
$ ctx - > { unix_name } = $ unix_name ;
$ ctx - > { unix_uid } = $> ;
2014-05-13 14:57:10 +04:00
my @ mygid = split ( " " , $( ) ;
$ ctx - > { unix_gid } = $ mygid [ 0 ] ;
2009-02-04 13:18:32 +03:00
$ ctx - > { unix_gids_str } = $ ) ;
@ { $ ctx - > { unix_gids } } = split ( " " , $ ctx - > { unix_gids_str } ) ;
$ ctx - > { etcdir } = "$prefix_abs/etc" ;
$ ctx - > { piddir } = "$prefix_abs/pid" ;
$ ctx - > { smb_conf } = "$ctx->{etcdir}/smb.conf" ;
$ ctx - > { krb5_conf } = "$ctx->{etcdir}/krb5.conf" ;
2016-09-22 19:46:28 +03:00
$ ctx - > { krb5_ccache } = "$prefix_abs/krb5_ccache" ;
2014-04-30 11:32:49 +04:00
$ ctx - > { mitkdc_conf } = "$ctx->{etcdir}/mitkdc.conf" ;
2020-11-23 01:28:31 +03:00
$ ctx - > { gnupghome } = "$prefix_abs/gnupg" ;
2009-02-04 13:18:32 +03:00
$ ctx - > { privatedir } = "$prefix_abs/private" ;
2017-08-22 18:10:01 +03:00
$ ctx - > { binddnsdir } = "$prefix_abs/bind-dns" ;
2009-02-04 13:18:32 +03:00
$ ctx - > { ncalrpcdir } = "$prefix_abs/ncalrpc" ;
$ ctx - > { lockdir } = "$prefix_abs/lockdir" ;
2012-08-30 16:09:10 +04:00
$ ctx - > { logdir } = "$prefix_abs/logs" ;
2011-07-12 15:12:50 +04:00
$ ctx - > { statedir } = "$prefix_abs/statedir" ;
$ ctx - > { cachedir } = "$prefix_abs/cachedir" ;
2021-05-19 04:57:21 +03:00
$ ctx - > { winbindd_socket_dir } = "$prefix_abs/wbsock" ;
2024-02-14 14:34:48 +03:00
$ ctx - > { nmbd_socket_dir } = "$prefix_abs/nmbsock" ;
2009-02-04 13:18:32 +03:00
$ ctx - > { ntp_signd_socket_dir } = "$prefix_abs/ntp_signd_socket" ;
$ ctx - > { nsswrap_passwd } = "$ctx->{etcdir}/passwd" ;
$ ctx - > { nsswrap_group } = "$ctx->{etcdir}/group" ;
2013-06-27 18:12:47 +04:00
$ ctx - > { nsswrap_hosts } = "$ENV{SELFTEST_PREFIX}/hosts" ;
2016-06-07 11:23:59 +03:00
$ ctx - > { nsswrap_hostname } = "$ctx->{hostname}.$ctx->{dnsname}" ;
2014-09-10 13:00:28 +04:00
if ( $ ENV { SAMBA_DNS_FAKING } ) {
$ ctx - > { dns_host_file } = "$ENV{SELFTEST_PREFIX}/dns_host_file" ;
2021-04-14 12:44:51 +03:00
$ ctx - > { samba_dnsupdate } = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --configfile=$ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}" ;
2018-09-27 11:30:40 +03:00
$ ctx - > { samba_dnsupdate } = $ python_cmd . $ ctx - > { samba_dnsupdate } ;
2014-09-10 13:00:28 +04:00
} else {
2021-04-14 12:44:51 +03:00
$ ctx - > { samba_dnsupdate } = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --configfile=$ctx->{smb_conf} --all-interfaces" ;
2018-09-27 11:30:40 +03:00
$ ctx - > { samba_dnsupdate } = $ python_cmd . $ ctx - > { samba_dnsupdate } ;
2016-06-10 06:43:37 +03:00
$ ctx - > { use_resolv_wrapper } = 1 ;
2014-09-10 13:00:28 +04:00
}
2019-01-02 23:24:34 +03:00
my $ dns_hub = $ self - > get_dns_hub_env ( ) ;
$ ctx - > { resolv_conf } = $ dns_hub - > { RESOLV_CONF } ;
2009-02-04 13:18:32 +03:00
$ ctx - > { tlsdir } = "$ctx->{privatedir}/tls" ;
2019-02-19 06:18:11 +03:00
$ ctx - > { ipv4 } = Samba:: get_ipv4_addr ( $ hostname ) ;
$ ctx - > { ipv6 } = Samba:: get_ipv6_addr ( $ hostname ) ;
2009-02-04 13:18:32 +03:00
push ( @ { $ ctx - > { directories } } , $ ctx - > { privatedir } ) ;
2017-08-22 18:10:01 +03:00
push ( @ { $ ctx - > { directories } } , $ ctx - > { binddnsdir } ) ;
2009-02-04 13:18:32 +03:00
push ( @ { $ ctx - > { directories } } , $ ctx - > { etcdir } ) ;
push ( @ { $ ctx - > { directories } } , $ ctx - > { piddir } ) ;
push ( @ { $ ctx - > { directories } } , $ ctx - > { lockdir } ) ;
2012-08-30 16:09:10 +04:00
push ( @ { $ ctx - > { directories } } , $ ctx - > { logdir } ) ;
2011-07-12 15:12:50 +04:00
push ( @ { $ ctx - > { directories } } , $ ctx - > { statedir } ) ;
push ( @ { $ ctx - > { directories } } , $ ctx - > { cachedir } ) ;
2009-02-04 13:18:32 +03:00
2009-02-10 19:01:51 +03:00
$ ctx - > { smb_conf_extra_options } = "" ;
2009-02-04 13:18:32 +03:00
2009-02-10 19:55:54 +03:00
my @ provision_options = ( ) ;
2020-11-23 01:28:31 +03:00
push ( @ provision_options , "GNUPGHOME=\"$ctx->{gnupghome}\"" ) ;
2016-09-23 07:14:45 +03:00
push ( @ provision_options , "KRB5_CONFIG=\"$ctx->{krb5_conf}\"" ) ;
2020-11-23 13:35:33 +03:00
push ( @ provision_options , "KRB5CCNAME=\"$ctx->{krb5_ccache}\"" ) ;
2009-02-10 19:55:54 +03:00
push ( @ provision_options , "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"" ) ;
push ( @ provision_options , "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"" ) ;
2013-06-27 18:12:47 +04:00
push ( @ provision_options , "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"" ) ;
2016-06-07 11:23:59 +03:00
push ( @ provision_options , "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"" ) ;
2016-06-10 06:43:37 +03:00
if ( defined ( $ ctx - > { use_resolv_wrapper } ) ) {
2014-09-10 13:00:28 +04:00
push ( @ provision_options , "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"" ) ;
2019-01-02 23:24:34 +03:00
push ( @ provision_options , "RESOLV_CONF=\"$ctx->{resolv_conf}\"" ) ;
2014-09-10 13:00:28 +04:00
} else {
push ( @ provision_options , "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"" ) ;
}
2020-03-13 16:36:18 +03:00
if ( defined ( $ ctx - > { force_fips_mode } ) ) {
push ( @ provision_options , "GNUTLS_FORCE_FIPS_MODE=1" ) ;
2020-03-16 11:39:48 +03:00
push ( @ provision_options , "OPENSSL_FORCE_FIPS_MODE=1" ) ;
2020-03-13 16:36:18 +03:00
}
2009-02-10 19:55:54 +03:00
if ( defined ( $ ENV { GDB_PROVISION } ) ) {
2009-02-23 21:33:39 +03:00
push ( @ provision_options , "gdb --args" ) ;
2010-10-18 15:11:40 +04:00
if ( ! defined ( $ ENV { PYTHON } ) ) {
push ( @ provision_options , "env" ) ;
push ( @ provision_options , "python" ) ;
}
2009-02-10 19:55:54 +03:00
}
if ( defined ( $ ENV { VALGRIND_PROVISION } ) ) {
push ( @ provision_options , "valgrind" ) ;
2010-10-18 15:11:40 +04:00
if ( ! defined ( $ ENV { PYTHON } ) ) {
push ( @ provision_options , "env" ) ;
push ( @ provision_options , "python" ) ;
}
2009-02-10 19:55:54 +03:00
}
2018-09-27 11:30:40 +03:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
push ( @ provision_options , $ samba_tool ) ;
2012-09-10 16:47:21 +04:00
push ( @ provision_options , "domain" ) ;
push ( @ provision_options , "provision" ) ;
2009-02-10 19:55:54 +03:00
push ( @ provision_options , "--configfile=$ctx->{smb_conf}" ) ;
2011-06-24 20:50:51 +04:00
push ( @ provision_options , "--host-name=$ctx->{hostname}" ) ;
2009-02-10 19:55:54 +03:00
push ( @ provision_options , "--host-ip=$ctx->{ipv4}" ) ;
push ( @ provision_options , "--quiet" ) ;
push ( @ provision_options , "--domain=$ctx->{domain}" ) ;
push ( @ provision_options , "--realm=$ctx->{realm}" ) ;
2018-02-26 16:56:27 +03:00
if ( defined ( $ ctx - > { samsid } ) ) {
push ( @ provision_options , "--domain-sid=$ctx->{samsid}" ) ;
}
2009-02-10 19:55:54 +03:00
push ( @ provision_options , "--adminpass=$ctx->{password}" ) ;
push ( @ provision_options , "--krbtgtpass=krbtgt$ctx->{password}" ) ;
push ( @ provision_options , "--machinepass=machine$ctx->{password}" ) ;
push ( @ provision_options , "--root=$ctx->{unix_name}" ) ;
push ( @ provision_options , "--server-role=\"$ctx->{server_role}\"" ) ;
2010-06-15 16:24:36 +04:00
push ( @ provision_options , "--function-level=\"$ctx->{functional_level}\"" ) ;
2009-02-10 19:55:54 +03:00
@ { $ ctx - > { provision_options } } = @ provision_options ;
2020-03-13 15:58:57 +03:00
if ( defined ( $ extra_provision_options ) ) {
push ( @ { $ ctx - > { provision_options } } , @ { $ extra_provision_options } ) ;
}
2009-02-04 13:18:32 +03:00
return $ ctx ;
}
2007-04-17 04:30:01 +04:00
2018-11-26 04:28:59 +03:00
sub has_option
{
my ( $ self , $ keyword , @ options_list ) = @ _ ;
# convert the options-list to a hash-map for easy keyword lookup
my % options_dict = map { $ _ = > 1 } @ options_list ;
return exists $ options_dict { $ keyword } ;
}
2009-02-04 13:18:32 +03:00
#
2009-02-10 19:55:54 +03:00
# Step1 creates the basic configuration
#
sub provision_raw_step1 ($$)
2009-02-04 13:18:32 +03:00
{
my ( $ self , $ ctx ) = @ _ ;
2007-05-01 07:28:12 +04:00
2009-02-04 13:18:32 +03:00
mkdir ( $ _ , 0777 ) foreach ( @ { $ ctx - > { directories } } ) ;
2007-05-01 07:28:12 +04:00
2012-12-22 03:16:10 +04:00
##
## lockdir and piddir must be 0755
##
chmod 0755 , $ ctx - > { lockdir } ;
chmod 0755 , $ ctx - > { piddir } ;
2010-09-14 16:41:42 +04:00
unless ( open ( CONFFILE , ">$ctx->{smb_conf}" ) ) {
warn ( "can't open $ctx->{smb_conf}$?" ) ;
return undef ;
}
2016-01-09 23:21:25 +03:00
2020-11-23 01:28:31 +03:00
Samba:: copy_gnupg_home ( $ ctx ) ;
2016-01-09 23:21:25 +03:00
Samba:: prepare_keyblobs ( $ ctx ) ;
2016-01-09 23:21:25 +03:00
my $ crlfile = "$ctx->{tlsdir}/crl.pem" ;
$ crlfile = "" unless - e $ { crlfile } ;
2016-01-09 23:21:25 +03:00
2018-11-26 04:28:59 +03:00
# work out which file server to use. Default to source3 smbd (s3fs),
# unless the source4 NTVFS (smb) file server has been specified
my $ services = "-smb +s3fs" ;
if ( $ self - > has_option ( "--use-ntvfs" , @ { $ ctx - > { provision_options } } ) ) {
$ services = "+smb -s3fs" ;
}
2019-03-12 04:00:55 +03:00
my $ interfaces = Samba:: get_interfaces_config ( $ ctx - > { netbiosname } ) ;
2007-04-17 04:30:01 +04:00
print CONFFILE "
[ global ]
2009-02-04 13:18:32 +03:00
netbios name = $ ctx - > { netbiosname }
2011-07-12 15:14:41 +04:00
posix:eadb = $ ctx - > { statedir } / eadb . tdb
2009-02-04 13:18:32 +03:00
workgroup = $ ctx - > { domain }
realm = $ ctx - > { realm }
private dir = $ ctx - > { privatedir }
2017-08-22 18:10:01 +03:00
binddns dir = $ ctx - > { binddnsdir }
2009-02-04 13:18:32 +03:00
pid directory = $ ctx - > { piddir }
ncalrpc dir = $ ctx - > { ncalrpcdir }
lock dir = $ ctx - > { lockdir }
2011-07-20 15:02:22 +04:00
state directory = $ ctx - > { statedir }
cache directory = $ ctx - > { cachedir }
2009-02-04 13:18:32 +03:00
winbindd socket directory = $ ctx - > { winbindd_socket_dir }
2024-02-14 14:34:48 +03:00
nmbd:socket dir = $ ctx - > { nmbd_socket_dir }
2009-02-04 13:18:32 +03:00
ntp signd socket directory = $ ctx - > { ntp_signd_socket_dir }
winbind separator = /
2019-03-12 04:00:55 +03:00
interfaces = $ interfaces
2009-02-04 13:18:32 +03:00
tls dh params file = $ ctx - > { tlsdir } / dhparms . pem
2016-01-09 23:21:25 +03:00
tls crlfile = $ { crlfile }
2016-03-26 10:38:46 +03:00
tls verify peer = no_check
2011-07-13 11:26:31 +04:00
panic action = $ RealBin / gdb_backtrace \ % d
2020-06-19 13:32:59 +03:00
smbd:suicide mode = yes
smbd:FSCTL_SMBTORTURE = yes
s3:smbd: only run validate_oplock_types() with smbd:validate_oplock_types = yes
This is really expensive as share_mode_forall_entries() is currently
doing a talloc_memdup() of the whole record...
This is mainly used to avoid regressions, so only
use smbd:validate_oplock_types = yes in make test,
but skip it for production.
This improves the following test:
time smbtorture //127.0.0.1/m -Uroot%test \
smb2.create.bench-path-contention-shared \
--option='torture:bench_path=file.dat' \
--option="torture:timelimit=60" \
--option="torture:nprocs=256" \
--option="torture:qdepth=1"
From:
open[num/s=8852,avslat=0.014999,minlat=0.000042,maxlat=0.054600]
close[num/s=8850,avslat=0.014136,minlat=0.000025,maxlat=0.054537]
to:
open[num/s=11377,avslat=0.012075,minlat=0.000041,maxlat=0.054107]
close[num/s=11375,avslat=0.010594,minlat=0.000023,maxlat=0.053620]
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2022-08-19 18:17:41 +03:00
smbd:validate_oplock_types = yes
2007-04-17 04:30:01 +04:00
wins support = yes
2009-02-04 13:18:32 +03:00
server role = $ ctx - > { server_role }
2018-11-26 04:28:59 +03:00
server services = + echo $ services
2023-09-12 09:59:44 +03:00
dcerpc endpoint servers = + winreg + srvsvc + rpcecho
2007-04-17 04:30:01 +04:00
notify:inotify = false
ldb:nosync = true
2015-12-21 12:27:33 +03:00
ldap server require strong auth = yes
2012-08-30 16:09:10 +04:00
log file = $ ctx - > { logdir } / log . \ % m
2009-02-04 13:18:32 +03:00
log level = $ ctx - > { server_loglevel }
2010-02-11 12:48:47 +03:00
lanman auth = Yes
2016-07-21 10:26:27 +03:00
ntlm auth = Yes
2019-09-27 17:24:25 +03:00
client min protocol = SMB2_02
server min protocol = SMB2_02
2019-07-08 16:26:25 +03:00
mangled names = yes
2014-09-10 13:00:28 +04:00
dns update command = $ ctx - > { samba_dnsupdate }
2021-04-14 12:44:51 +03:00
spn update command = $ ctx - > { python } $ ENV { SRCDIR_ABS } /source4/sc ripting /bin/s amba_spnupdate - - configfile $ ctx - > { smb_conf }
gpo update command = $ ctx - > { python } $ ENV { SRCDIR_ABS } /source4/sc ripting /bin/s amba - gpupdate - - configfile $ ctx - > { smb_conf } - - target = Computer
2018-09-27 11:30:40 +03:00
samba kcc command = $ ctx - > { python } $ ENV { SRCDIR_ABS } /source4/sc ripting /bin/s amba_kcc
2010-07-09 11:23:04 +04:00
dreplsrv:periodic_startup_interval = 0
2011-11-12 14:03:05 +04:00
dsdb:schema update allowed = yes
2011-08-22 04:05:02 +04:00
2012-08-23 14:13:45 +04:00
vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
2012-12-28 05:36:06 +04:00
idmap_ldb:use rfc2307 = yes
2014-05-20 03:16:07 +04:00
winbind enum users = yes
winbind enum groups = yes
2016-11-14 00:15:39 +03:00
rpc server port:netlogon = 1026
2019-03-22 14:04:49 +03:00
include system krb5 conf = no
2016-11-14 00:15:39 +03:00
2023-04-06 03:28:12 +03:00
debug syslog format = always
debug hires timestamp = yes
2010-02-11 12:48:47 +03:00
" ;
2009-10-28 23:28:31 +03:00
print CONFFILE "
2007-04-17 04:30:01 +04:00
2009-02-10 19:01:51 +03:00
# Begin extra options
$ ctx - > { smb_conf_extra_options }
# End extra options
2007-04-17 04:30:01 +04:00
" ;
close ( CONFFILE ) ;
2011-04-18 10:09:30 +04:00
#Default the KDC IP to the server's IP
if ( not defined ( $ ctx - > { kdc_ipv4 } ) ) {
2014-09-10 12:59:39 +04:00
$ ctx - > { kdc_ipv4 } = $ ctx - > { ipv4 } ;
}
if ( not defined ( $ ctx - > { kdc_ipv6 } ) ) {
$ ctx - > { kdc_ipv6 } = $ ctx - > { ipv6 } ;
}
2011-04-18 10:09:30 +04:00
2015-03-24 21:05:10 +03:00
Samba:: mk_krb5_conf ( $ ctx ) ;
2014-04-30 11:32:49 +04:00
Samba:: mk_mitkdc_conf ( $ ctx , abs_path ( Samba:: bindir_path ( $ self , "shared" ) ) ) ;
2007-04-17 04:30:01 +04:00
2009-02-04 13:18:32 +03:00
open ( PWD , ">$ctx->{nsswrap_passwd}" ) ;
2015-02-02 18:05:17 +03:00
if ( $ ctx - > { unix_uid } != 0 ) {
print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n" ;
}
2015-02-05 18:07:35 +03:00
print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n" ;
2015-02-02 18:05:17 +03:00
print PWD " nobody:x:65534:65533:nobody gecos: $ ctx - > { prefix_abs } : /bin/ false
2012-06-27 11:51:55 +04:00
pdbtest:x:65533:65533:pdbtest gecos: $ ctx - > { prefix_abs } : /bin/ false
2014-05-16 06:30:43 +04:00
pdbtest2:x:65532:65533:pdbtest gecos: $ ctx - > { prefix_abs } : /bin/ false
pdbtest3:x:65531:65533:pdbtest gecos: $ ctx - > { prefix_abs } : /bin/ false
pdbtest4:x:65530:65533:pdbtest gecos: $ ctx - > { prefix_abs } : /bin/ false
2007-11-05 17:49:40 +03:00
" ;
close ( PWD ) ;
2012-12-28 05:36:06 +04:00
my $ uid_rfc2307test = 65533 ;
2007-11-05 17:49:40 +03:00
2009-02-04 13:18:32 +03:00
open ( GRP , ">$ctx->{nsswrap_group}" ) ;
2015-02-03 16:59:06 +03:00
if ( $ ctx - > { unix_gid } != 0 ) {
print GRP "root:x:0:\n" ;
}
print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n" ;
print GRP " wheel:x:10:
2015-02-05 18:07:35 +03:00
users:x:65531:
2007-11-05 17:49:40 +03:00
nobody:x:65533:
nogroup:x:65534:nobody
" ;
close ( GRP ) ;
2012-12-28 05:36:06 +04:00
my $ gid_rfc2307test = 65532 ;
2007-11-05 17:49:40 +03:00
2013-06-27 18:12:47 +04:00
my $ hostname = lc ( $ ctx - > { hostname } ) ;
open ( HOSTS , ">>$ctx->{nsswrap_hosts}" ) ;
2014-12-03 17:44:57 +03:00
if ( $ hostname eq "localdc" ) {
print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n" ;
print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n" ;
} else {
print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n" ;
print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n" ;
}
2013-06-27 18:12:47 +04:00
close ( HOSTS ) ;
2009-02-04 13:18:32 +03:00
my $ configuration = "--configfile=$ctx->{smb_conf}" ;
2007-04-17 04:30:01 +04:00
#Ensure the config file is valid before we start
2011-06-04 02:20:54 +04:00
my $ testparm = Samba:: bindir_path ( $ self , "samba-tool" ) . " testparm" ;
2009-01-21 12:09:30 +03:00
if ( system ( "$testparm $configuration -v --suppress-prompt >/dev/null 2>&1" ) != 0 ) {
system ( "$testparm -v --suppress-prompt $configuration >&2" ) ;
2010-09-14 16:41:42 +04:00
warn ( "Failed to create a valid smb.conf configuration $testparm!" ) ;
return undef ;
2007-04-17 04:30:01 +04:00
}
2010-09-14 16:41:42 +04:00
unless ( system ( "($testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$ctx->{netbiosname}\" ) >/dev/null 2>&1" ) == 0 ) {
warn ( "Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global" ) ;
return undef ;
}
2007-04-17 04:30:01 +04:00
2019-02-17 23:28:37 +03:00
# Return the environment variables for the new testenv DC.
# Note that we have SERVER_X and DC_SERVER_X variables (which have the same
# value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
2007-04-17 04:30:01 +04:00
my $ ret = {
2020-11-23 01:28:31 +03:00
GNUPGHOME = > $ ctx - > { gnupghome } ,
2009-02-04 13:18:32 +03:00
KRB5_CONFIG = > $ ctx - > { krb5_conf } ,
2016-09-22 19:46:28 +03:00
KRB5_CCACHE = > $ ctx - > { krb5_ccache } ,
2014-04-30 11:32:49 +04:00
MITKDC_CONFIG = > $ ctx - > { mitkdc_conf } ,
2009-02-04 13:18:32 +03:00
PIDDIR = > $ ctx - > { piddir } ,
2011-06-24 20:50:51 +04:00
SERVER = > $ ctx - > { hostname } ,
2019-02-17 23:28:37 +03:00
DC_SERVER = > $ ctx - > { hostname } ,
2009-02-04 13:18:32 +03:00
SERVER_IP = > $ ctx - > { ipv4 } ,
2019-02-17 23:28:37 +03:00
DC_SERVER_IP = > $ ctx - > { ipv4 } ,
2014-06-19 19:21:16 +04:00
SERVER_IPV6 = > $ ctx - > { ipv6 } ,
2019-02-17 23:28:37 +03:00
DC_SERVER_IPV6 = > $ ctx - > { ipv6 } ,
2009-02-04 13:18:32 +03:00
NETBIOSNAME = > $ ctx - > { netbiosname } ,
2019-02-17 23:28:37 +03:00
DC_NETBIOSNAME = > $ ctx - > { netbiosname } ,
2009-02-04 13:18:32 +03:00
DOMAIN = > $ ctx - > { domain } ,
USERNAME = > $ ctx - > { username } ,
2019-02-17 23:28:37 +03:00
DC_USERNAME = > $ ctx - > { username } ,
2023-12-08 15:07:19 +03:00
DOMAIN_ADMIN = > $ ctx - > { domain_admin } ,
DOMAIN_ADMIN_PASSWORD = > $ ctx - > { domain_admin_password } ,
DOMAIN_USER = > $ ctx - > { domain_user } ,
DOMAIN_USER_PASSWORD = > $ ctx - > { domain_user_password } ,
2009-02-04 13:18:32 +03:00
REALM = > $ ctx - > { realm } ,
2018-08-27 06:00:12 +03:00
DNSNAME = > $ ctx - > { dnsname } ,
2018-02-26 16:56:27 +03:00
SAMSID = > $ ctx - > { samsid } ,
2009-02-04 13:18:32 +03:00
PASSWORD = > $ ctx - > { password } ,
2019-02-17 23:28:37 +03:00
DC_PASSWORD = > $ ctx - > { password } ,
2009-02-04 13:18:32 +03:00
LDAPDIR = > $ ctx - > { ldapdir } ,
2010-01-29 04:35:29 +03:00
LDAP_INSTANCE = > $ ctx - > { ldap_instance } ,
2014-02-20 13:34:49 +04:00
SELFTEST_WINBINDD_SOCKET_DIR = > $ ctx - > { winbindd_socket_dir } ,
2009-02-04 13:18:32 +03:00
NCALRPCDIR = > $ ctx - > { ncalrpcdir } ,
LOCKDIR = > $ ctx - > { lockdir } ,
2011-07-12 15:12:50 +04:00
STATEDIR = > $ ctx - > { statedir } ,
CACHEDIR = > $ ctx - > { cachedir } ,
2012-08-29 03:10:40 +04:00
PRIVATEDIR = > $ ctx - > { privatedir } ,
2017-08-22 18:10:01 +03:00
BINDDNSDIR = > $ ctx - > { binddnsdir } ,
2009-02-04 13:18:32 +03:00
SERVERCONFFILE = > $ ctx - > { smb_conf } ,
2019-03-14 07:38:22 +03:00
TESTENV_DIR = > $ ctx - > { prefix_abs } ,
2007-04-17 19:33:50 +04:00
CONFIGURATION = > $ configuration ,
2009-02-04 13:18:32 +03:00
SOCKET_WRAPPER_DEFAULT_IFACE = > $ ctx - > { swiface } ,
NSS_WRAPPER_PASSWD = > $ ctx - > { nsswrap_passwd } ,
NSS_WRAPPER_GROUP = > $ ctx - > { nsswrap_group } ,
2013-06-27 18:12:47 +04:00
NSS_WRAPPER_HOSTS = > $ ctx - > { nsswrap_hosts } ,
2016-06-07 11:23:59 +03:00
NSS_WRAPPER_HOSTNAME = > $ ctx - > { nsswrap_hostname } ,
2009-02-04 13:18:32 +03:00
SAMBA_TEST_FIFO = > "$ctx->{prefix}/samba_test.fifo" ,
SAMBA_TEST_LOG = > "$ctx->{prefix}/samba_test.log" ,
2009-02-04 17:17:14 +03:00
SAMBA_TEST_LOG_POS = > 0 ,
2013-06-12 17:42:01 +04:00
NSS_WRAPPER_MODULE_SO_PATH = > Samba:: nss_wrapper_winbind_so_path ( $ self ) ,
NSS_WRAPPER_MODULE_FN_PREFIX = > "winbind" ,
2012-12-28 05:36:06 +04:00
LOCAL_PATH = > $ ctx - > { share } ,
UID_RFC2307TEST = > $ uid_rfc2307test ,
2013-06-19 05:33:36 +04:00
GID_RFC2307TEST = > $ gid_rfc2307test ,
2016-06-10 06:43:37 +03:00
SERVER_ROLE = > $ ctx - > { server_role } ,
2020-03-13 16:36:18 +03:00
RESOLV_CONF = > $ ctx - > { resolv_conf } ,
2023-07-03 05:31:03 +03:00
KRB5_CRL_FILE = > $ crlfile ,
2007-04-17 04:30:01 +04:00
} ;
2016-06-10 06:43:37 +03:00
if ( defined ( $ ctx - > { use_resolv_wrapper } ) ) {
$ ret - > { RESOLV_WRAPPER_CONF } = $ ctx - > { resolv_conf } ;
2014-09-10 13:00:28 +04:00
} else {
$ ret - > { RESOLV_WRAPPER_HOSTS } = $ ctx - > { dns_host_file } ;
}
2020-03-13 16:36:18 +03:00
if ( defined ( $ ctx - > { force_fips_mode } ) ) {
$ ret - > { GNUTLS_FORCE_FIPS_MODE } = "1" ,
2020-03-16 11:39:48 +03:00
$ ret - > { OPENSSL_FORCE_FIPS_MODE } = "1" ,
2020-03-13 16:36:18 +03:00
}
2014-09-10 13:00:28 +04:00
2018-02-26 16:56:27 +03:00
if ( $ ctx - > { server_role } eq "domain controller" ) {
$ ret - > { DOMSID } = $ ret - > { SAMSID } ;
}
2009-02-10 19:55:54 +03:00
return $ ret ;
}
2007-04-23 11:33:15 +04:00
2009-02-10 19:55:54 +03:00
#
# Step2 runs the provision script
#
sub provision_raw_step2 ($$$)
{
my ( $ self , $ ctx , $ ret ) = @ _ ;
2007-04-24 01:56:23 +04:00
2021-10-18 01:55:14 +03:00
my $ ldif ;
2009-02-10 19:55:54 +03:00
my $ provision_cmd = join ( " " , @ { $ ctx - > { provision_options } } ) ;
2010-09-14 16:41:42 +04:00
unless ( system ( $ provision_cmd ) == 0 ) {
warn ( "Unable to provision: \n$provision_cmd\n" ) ;
return undef ;
}
2007-04-23 11:33:15 +04:00
2020-11-23 13:35:33 +03:00
my $ cmd_env = $ self - > get_cmd_env_vars ( $ ret ) ;
2015-03-29 12:15:29 +03:00
my $ testallowed_account = "testallowed" ;
2020-11-23 13:35:33 +03:00
my $ samba_tool_cmd = $ { cmd_env } ;
2015-10-24 00:41:23 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
2016-07-05 11:53:08 +03:00
. " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}" ;
2015-01-05 06:32:23 +03:00
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to add testallowed user: \n$samba_tool_cmd\n" ) ;
return undef ;
}
2020-05-04 19:09:53 +03:00
my $ srv_account = "srv_account" ;
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2020-05-04 19:09:53 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " user create --configfile=$ctx->{smb_conf} $srv_account $ctx->{password}" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to add $srv_account user: \n$samba_tool_cmd\n" ) ;
return undef ;
}
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2020-05-04 19:09:53 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " spn add HOST/$srv_account --configfile=$ctx->{smb_conf} $srv_account" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to add spn for $srv_account: \n$samba_tool_cmd\n" ) ;
return undef ;
}
2020-11-23 13:35:33 +03:00
my $ ldbmodify = $ { cmd_env } ;
2015-10-24 00:41:23 +03:00
$ ldbmodify . = Samba:: bindir_path ( $ self , "ldbmodify" ) ;
2019-03-29 04:12:49 +03:00
$ ldbmodify . = " --configfile=$ctx->{smb_conf}" ;
2015-01-23 07:19:41 +03:00
my $ base_dn = "DC=" . join ( ",DC=" , split ( /\./ , $ ctx - > { realm } ) ) ;
2015-03-12 12:43:57 +03:00
if ( $ ctx - > { server_role } ne "domain controller" ) {
$ base_dn = "DC=$ctx->{netbiosname}" ;
}
2015-03-29 12:15:29 +03:00
my $ user_dn = "cn=$testallowed_account,cn=users,$base_dn" ;
$ testallowed_account = "testallowed account" ;
2021-10-18 01:55:14 +03:00
open ( $ ldif , "|$ldbmodify -H $ctx->{privatedir}/sam.ldb" )
or die "Failed to run $ldbmodify: $!" ;
print $ ldif " dn: $ user_dn
2015-01-23 07:19:41 +03:00
changetype: modify
2015-03-12 03:43:49 +03:00
replace: samAccountName
2015-03-29 12:15:29 +03:00
samAccountName: $ testallowed_account
2015-03-12 03:43:49 +03:00
-
" ;
2021-10-18 01:55:14 +03:00
close ( $ ldif ) ;
unless ( $? == 0 ) {
warn ( "$ldbmodify failed: $?" ) ;
return undef ;
}
2015-03-12 03:43:49 +03:00
2021-10-18 01:55:14 +03:00
open ( $ ldif , "|$ldbmodify -H $ctx->{privatedir}/sam.ldb" )
or die "Failed to run $ldbmodify: $!" ;
print $ ldif " dn: $ user_dn
2015-03-12 03:43:49 +03:00
changetype: modify
2015-01-23 07:19:41 +03:00
replace: userPrincipalName
2015-03-12 02:56:56 +03:00
userPrincipalName: testallowed upn \ @$ ctx - > { realm }
2015-02-03 01:36:49 +03:00
replace: servicePrincipalName
servicePrincipalName: host / testallowed
2023-12-08 15:06:27 +03:00
-
2015-01-23 07:19:41 +03:00
" ;
2021-10-18 01:55:14 +03:00
close ( $ ldif ) ;
unless ( $? == 0 ) {
warn ( "$ldbmodify failed: $?" ) ;
return undef ;
}
2015-01-23 07:19:41 +03:00
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2015-10-24 00:41:23 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
2016-07-05 11:53:08 +03:00
. " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}" ;
2015-01-05 06:32:23 +03:00
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to add testdenied user: \n$samba_tool_cmd\n" ) ;
return undef ;
}
2019-12-07 12:38:30 +03:00
$ user_dn = "cn=testdenied,cn=users,$base_dn" ;
2021-10-18 01:55:14 +03:00
open ( $ ldif , "|$ldbmodify -H $ctx->{privatedir}/sam.ldb" )
or die "Failed to run $ldbmodify: $!" ;
print $ ldif " dn: $ user_dn
2015-01-23 07:19:41 +03:00
changetype: modify
replace: userPrincipalName
userPrincipalName: testdenied_upn \ @$ ctx - > { realm } . upn
2023-12-08 15:06:27 +03:00
-
2015-01-23 07:19:41 +03:00
" ;
2021-10-18 01:55:14 +03:00
close ( $ ldif ) ;
unless ( $? == 0 ) {
warn ( "$ldbmodify failed: $?" ) ;
return undef ;
}
2015-01-23 07:19:41 +03:00
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2018-08-27 06:00:12 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to add testupnspn user: \n$samba_tool_cmd\n" ) ;
return undef ;
}
2019-12-07 12:38:30 +03:00
$ user_dn = "cn=testupnspn,cn=users,$base_dn" ;
2021-10-18 01:55:14 +03:00
open ( $ ldif , "|$ldbmodify -H $ctx->{privatedir}/sam.ldb" )
or die "Failed to run $ldbmodify: $!" ;
print $ ldif " dn: $ user_dn
2018-08-27 06:00:12 +03:00
changetype: modify
replace: userPrincipalName
userPrincipalName: http / testupnspn . $ ctx - > { dnsname } \ @$ ctx - > { realm }
replace: servicePrincipalName
servicePrincipalName: http / testupnspn . $ ctx - > { dnsname }
-
" ;
2021-10-18 01:55:14 +03:00
close ( $ ldif ) ;
unless ( $? == 0 ) {
warn ( "$ldbmodify failed: $?" ) ;
return undef ;
}
2018-08-27 06:00:12 +03:00
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2015-10-24 00:41:23 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
2021-06-18 14:49:13 +03:00
. " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'" ;
2015-01-05 06:32:23 +03:00
unless ( system ( $ samba_tool_cmd ) == 0 ) {
2015-03-29 12:15:29 +03:00
warn ( "Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n" ) ;
2015-01-05 06:32:23 +03:00
return undef ;
}
2023-06-08 07:17:30 +03:00
# Create two users alice and bob!
2020-01-15 16:39:56 +03:00
my $ user_account_array = [ "alice" , "bob" , "jane" , "joe" ] ;
2016-09-25 19:41:50 +03:00
foreach my $ user_account ( @ { $ user_account_array } ) {
2020-11-23 13:35:33 +03:00
my $ samba_tool_cmd = $ { cmd_env } ;
2016-09-25 19:41:50 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " user create --configfile=$ctx->{smb_conf} $user_account Secret007" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to create user: $user_account\n$samba_tool_cmd\n" ) ;
return undef ;
}
}
2020-01-15 16:41:13 +03:00
my $ group_array = [ "Samba Users" ] ;
foreach my $ group ( @ { $ group_array } ) {
2020-11-23 13:35:33 +03:00
my $ samba_tool_cmd = $ { cmd_env } ;
2020-01-15 16:41:13 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " group add --configfile=$ctx->{smb_conf} \"$group\"" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to create group: $group\n$samba_tool_cmd\n" ) ;
return undef ;
}
}
2020-01-15 16:41:37 +03:00
# Add user joe to group "Samba Users"
my $ group = "Samba Users" ;
my $ user_account = "joe" ;
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2020-01-15 16:41:37 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " group addmembers --configfile=$ctx->{smb_conf} \"$group\" $user_account" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to add " . $ user_account . "to group group : $group\n$samba_tool_cmd\n" ) ;
return undef ;
}
2019-12-07 12:38:30 +03:00
$ group = "Samba Users" ;
$ user_account = "joe" ;
2020-01-15 16:41:37 +03:00
2020-11-23 13:35:33 +03:00
$ samba_tool_cmd = $ { cmd_env } ;
2020-01-15 16:41:37 +03:00
$ samba_tool_cmd . = Samba:: bindir_path ( $ self , "samba-tool" )
. " user setprimarygroup --configfile=$ctx->{smb_conf} $user_account \"$group\"" ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to set primary group of user: $user_account\n$samba_tool_cmd\n" ) ;
return undef ;
}
# Change the userPrincipalName for jane
2019-12-07 12:38:30 +03:00
$ user_dn = "cn=jane,cn=users,$base_dn" ;
2018-04-20 10:38:24 +03:00
2021-10-18 01:55:14 +03:00
open ( $ ldif , "|$ldbmodify -H $ctx->{privatedir}/sam.ldb" )
or die "Failed to run $ldbmodify: $!" ;
print $ ldif " dn: $ user_dn
2018-04-20 10:38:24 +03:00
changetype: modify
replace: userPrincipalName
userPrincipalName: jane . doe \ @$ ctx - > { realm }
-
" ;
2021-10-18 01:55:14 +03:00
close ( $ ldif ) ;
unless ( $? == 0 ) {
warn ( "$ldbmodify failed: $?" ) ;
return undef ;
}
2018-04-20 10:38:24 +03:00
2009-02-04 13:18:32 +03:00
return $ ret ;
}
2020-03-13 16:29:48 +03:00
sub provision ($$$$$$$$$$$)
2009-02-04 13:18:32 +03:00
{
2020-03-13 16:29:48 +03:00
my ( $ self ,
$ prefix ,
$ server_role ,
$ hostname ,
$ domain ,
$ realm ,
$ functional_level ,
$ password ,
$ kdc_ipv4 ,
$ kdc_ipv6 ,
$ force_fips_mode ,
$ extra_smbconf_options ,
$ extra_smbconf_shares ,
2012-09-12 10:52:15 +04:00
$ extra_provision_options ) = @ _ ;
2009-02-04 13:18:32 +03:00
2018-02-26 16:56:27 +03:00
my $ samsid = Samba:: random_domain_sid ( ) ;
2009-02-04 13:18:32 +03:00
my $ ctx = $ self - > provision_raw_prepare ( $ prefix , $ server_role ,
2011-06-24 20:50:51 +04:00
$ hostname ,
2018-02-26 16:56:27 +03:00
$ domain , $ realm ,
$ samsid ,
$ functional_level ,
2020-03-13 15:58:57 +03:00
$ password ,
$ kdc_ipv4 ,
$ kdc_ipv6 ,
2020-03-13 16:33:08 +03:00
$ force_fips_mode ,
2020-03-13 15:58:57 +03:00
$ extra_provision_options ) ;
2009-02-04 13:18:32 +03:00
2012-04-30 09:08:38 +04:00
$ ctx - > { share } = "$ctx->{prefix_abs}/share" ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}" ) ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}/test1" ) ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}/test2" ) ;
2012-08-30 16:09:49 +04:00
# precreate directories for printer drivers
push ( @ { $ ctx - > { directories } } , "$ctx->{share}/W32X86" ) ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}/x64" ) ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}/WIN40" ) ;
2010-05-11 21:22:24 +04:00
my $ msdfs = "no" ;
$ msdfs = "yes" if ( $ server_role eq "domain controller" ) ;
2009-02-10 19:01:51 +03:00
$ ctx - > { smb_conf_extra_options } = "
max xmit = 32 K
server max protocol = SMB2
2010-05-11 21:22:24 +04:00
host msdfs = $ msdfs
2010-06-23 00:11:00 +04:00
lanman auth = yes
2009-02-10 19:01:51 +03:00
2015-06-10 16:30:04 +03:00
# fruit:copyfile is a global option
fruit:copyfile = yes
2011-03-18 21:13:43 +03:00
$ extra_smbconf_options
2009-02-10 19:01:51 +03:00
[ tmp ]
2012-04-30 09:08:38 +04:00
path = $ ctx - > { share }
2009-02-10 19:01:51 +03:00
read only = no
2015-06-19 07:49:41 +03:00
posix:sharedelay = 100000
2009-02-10 19:01:51 +03:00
posix:oplocktimeout = 3
2015-06-19 07:49:41 +03:00
posix:writetimeupdatedelay = 500000
2009-02-10 19:01:51 +03:00
2011-10-28 23:15:51 +04:00
[ xcopy_share ]
2012-04-30 09:08:38 +04:00
path = $ ctx - > { share }
2011-10-28 23:15:51 +04:00
read only = no
2015-06-19 07:49:41 +03:00
posix:sharedelay = 100000
2011-10-28 23:15:51 +04:00
posix:oplocktimeout = 3
2015-06-19 07:49:41 +03:00
posix:writetimeupdatedelay = 500000
2011-09-09 03:03:23 +04:00
create mask = 777
force create mode = 777
2011-10-28 23:15:51 +04:00
2012-06-05 07:44:08 +04:00
[ posix_share ]
path = $ ctx - > { share }
read only = no
create mask = 0777
force create mode = 0
directory mask = 0777
force directory mode = 0
2009-02-10 19:01:51 +03:00
[ test1 ]
2012-04-30 09:08:38 +04:00
path = $ ctx - > { share } / test1
2009-02-10 19:01:51 +03:00
read only = no
2015-06-19 07:49:41 +03:00
posix:sharedelay = 100000
2009-02-10 19:01:51 +03:00
posix:oplocktimeout = 3
2015-06-19 07:49:41 +03:00
posix:writetimeupdatedelay = 500000
2009-02-10 19:01:51 +03:00
[ test2 ]
2012-04-30 09:08:38 +04:00
path = $ ctx - > { share } / test2
2009-02-10 19:01:51 +03:00
read only = no
2015-06-19 07:49:41 +03:00
posix:sharedelay = 100000
2009-02-10 19:01:51 +03:00
posix:oplocktimeout = 3
2015-06-19 07:49:41 +03:00
posix:writetimeupdatedelay = 500000
2009-02-10 19:01:51 +03:00
[ cifs ]
2014-08-06 18:54:43 +04:00
path = $ ctx - > { share } / _ignore_cifs_
2009-02-10 19:01:51 +03:00
read only = no
ntvfs handler = cifs
cifs:server = $ ctx - > { netbiosname }
cifs:share = tmp
2011-03-18 21:13:43 +03:00
cifs:use - s4u2proxy = yes
# There is no username specified here, instead the client is expected
# to log in with kerberos, and the serverwill use delegated credentials.
# Or the server tries s4u2self/s4u2proxy to impersonate the client
2009-02-10 19:01:51 +03:00
[ simple ]
2012-04-30 09:08:38 +04:00
path = $ ctx - > { share }
2009-02-10 19:01:51 +03:00
read only = no
ntvfs handler = simple
[ sysvol ]
2011-07-12 15:14:41 +04:00
path = $ ctx - > { statedir } / sysvol
2012-11-05 05:57:17 +04:00
read only = no
2009-02-10 19:01:51 +03:00
[ netlogon ]
2011-07-12 15:14:41 +04:00
path = $ ctx - > { statedir } /sysvol/ $ ctx - > { dnsname } / scripts
2009-02-10 19:01:51 +03:00
read only = no
[ cifsposix ]
copy = simple
ntvfs handler = cifsposix
2012-04-26 09:20:02 +04:00
2014-07-08 07:47:02 +04:00
[ vfs_fruit ]
path = $ ctx - > { share }
2015-05-10 12:58:32 +03:00
vfs objects = catia fruit streams_xattr acl_xattr
ea support = yes
2016-11-08 14:35:12 +03:00
fruit:resource = file
2014-07-08 07:47:02 +04:00
fruit:metadata = netatalk
fruit:locking = netatalk
fruit:encoding = native
2019-06-27 10:38:57 +03:00
[ xattr ]
path = $ ctx - > { share }
# This can be used for testing real fs xattr stuff
vfs objects = streams_xattr acl_xattr
2012-04-26 09:20:02 +04:00
$ extra_smbconf_shares
2009-02-10 19:01:51 +03:00
" ;
2009-02-10 19:55:54 +03:00
my $ ret = $ self - > provision_raw_step1 ( $ ctx ) ;
2010-11-01 01:00:46 +03:00
unless ( defined $ ret ) {
2010-09-14 16:41:42 +04:00
return undef ;
}
2009-02-10 19:55:54 +03:00
2010-09-14 16:41:42 +04:00
return $ self - > provision_raw_step2 ( $ ctx , $ ret ) ;
2007-04-17 04:30:01 +04:00
}
2019-02-13 05:52:00 +03:00
# For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
# original DC) in the testenv. $SERVER is always the joined DC that we are
# actually running the test against
sub set_pdc_env_vars
{
my ( $ self , $ env , $ dcvars ) = @ _ ;
$ env - > { DC_SERVER } = $ dcvars - > { DC_SERVER } ;
$ env - > { DC_SERVER_IP } = $ dcvars - > { DC_SERVER_IP } ;
$ env - > { DC_SERVER_IPV6 } = $ dcvars - > { DC_SERVER_IPV6 } ;
$ env - > { DC_SERVERCONFFILE } = $ dcvars - > { SERVERCONFFILE } ;
$ env - > { DC_NETBIOSNAME } = $ dcvars - > { DC_NETBIOSNAME } ;
$ env - > { DC_USERNAME } = $ dcvars - > { DC_USERNAME } ;
$ env - > { DC_PASSWORD } = $ dcvars - > { DC_PASSWORD } ;
}
2016-09-29 18:50:58 +03:00
sub provision_s4member ($$$$$)
2007-04-12 12:33:35 +04:00
{
2016-09-29 18:50:58 +03:00
my ( $ self , $ prefix , $ dcvars , $ hostname , $ more_conf ) = @ _ ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING MEMBER...\n" ;
2014-05-20 03:10:22 +04:00
my $ extra_smb_conf = "
passdb backend = samba_dsdb
winbindd:use external pipes = true
2015-07-15 12:10:24 +03:00
# the source4 smb server doesn't allow signing by default
server signing = enabled
2017-12-07 15:00:10 +03:00
raw NTLMv2 auth = yes
2015-07-15 12:10:24 +03:00
2019-12-04 14:06:44 +03:00
# override the new SMB2 only default
client min protocol = CORE
server min protocol = LANMAN1
2014-05-20 03:10:22 +04:00
" ;
2016-09-29 18:50:58 +03:00
if ( $ more_conf ) {
$ extra_smb_conf = $ extra_smb_conf . $ more_conf . "\n" ;
}
2018-11-26 03:32:03 +03:00
my $ extra_provision_options = [ "--use-ntvfs" ] ;
2007-04-29 17:54:51 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"member server" ,
2016-09-29 18:50:58 +03:00
$ hostname ,
2018-02-26 16:19:39 +03:00
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2010-06-15 16:24:36 +04:00
"2008" ,
2010-06-16 13:22:30 +04:00
"locMEMpass3" ,
2010-02-19 07:56:30 +03:00
$ dcvars - > { SERVER_IP } ,
2014-09-10 12:59:39 +04:00
$ dcvars - > { SERVER_IPV6 } ,
2020-03-13 16:29:48 +03:00
undef ,
2018-11-26 03:32:03 +03:00
$ extra_smb_conf , "" ,
$ extra_provision_options ) ;
2010-09-14 16:41:42 +04:00
unless ( $ ret ) {
return undef ;
}
2007-04-12 12:33:35 +04:00
2011-04-27 05:19:20 +04:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2019-01-30 06:31:40 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2020-10-27 17:28:06 +03:00
$ cmd . = "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} --experimental-s4-member member" ;
2010-02-19 07:56:30 +03:00
$ cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
2013-02-28 15:57:45 +04:00
$ cmd . = " --machinepass=machine$ret->{PASSWORD}" ;
2007-04-30 15:16:50 +04:00
2010-09-14 16:41:42 +04:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2007-04-16 14:44:26 +04:00
2018-02-26 16:56:27 +03:00
$ ret - > { DOMSID } = $ dcvars - > { DOMSID } ;
2019-02-13 05:52:00 +03:00
$ self - > set_pdc_env_vars ( $ ret , $ dcvars ) ;
2010-02-19 07:56:30 +03:00
return $ ret ;
}
sub provision_rpc_proxy ($$$)
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING RPC PROXY...\n" ;
2010-02-19 07:56:30 +03:00
2011-03-18 21:13:43 +03:00
my $ extra_smbconf_options = "
2014-04-09 07:54:07 +04:00
passdb backend = samba_dsdb
2011-03-18 21:13:43 +03:00
# rpc_proxy
dcerpc_remote:binding = ncacn_ip_tcp: $ dcvars - > { SERVER }
dcerpc endpoint servers = epmapper , remote
dcerpc_remote:interfaces = rpcecho
2018-11-23 15:15:10 +03:00
dcerpc_remote:allow_anonymous_fallback = yes
2019-12-04 14:06:44 +03:00
# override the new SMB2 only default
client min protocol = CORE
server min protocol = LANMAN1
2011-03-18 21:13:43 +03:00
[ cifs_to_dc ]
2014-08-06 18:54:43 +04:00
path = /tmp/ _ignore_cifs_to_dc_ / _none_
2011-03-18 21:13:43 +03:00
read only = no
ntvfs handler = cifs
cifs:server = $ dcvars - > { SERVER }
cifs:share = cifs
cifs:use - s4u2proxy = yes
# There is no username specified here, instead the client is expected
# to log in with kerberos, and the serverwill use delegated credentials.
# Or the server tries s4u2self/s4u2proxy to impersonate the client
2010-02-19 07:56:30 +03:00
" ;
2018-11-26 03:32:03 +03:00
my $ extra_provision_options = [ "--use-ntvfs" ] ;
2010-02-19 07:56:30 +03:00
my $ ret = $ self - > provision ( $ prefix ,
"member server" ,
"localrpcproxy" ,
2018-02-26 16:19:39 +03:00
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2010-06-15 16:24:36 +04:00
"2008" ,
2010-06-16 13:22:30 +04:00
"locRPCproxypass4" ,
2010-02-19 07:56:30 +03:00
$ dcvars - > { SERVER_IP } ,
2014-09-10 12:59:39 +04:00
$ dcvars - > { SERVER_IPV6 } ,
2020-03-13 16:29:48 +03:00
undef ,
2018-11-26 03:32:03 +03:00
$ extra_smbconf_options , "" ,
$ extra_provision_options ) ;
2010-09-14 16:41:42 +04:00
unless ( $ ret ) {
return undef ;
}
2010-02-19 07:56:30 +03:00
2011-04-27 05:19:20 +04:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2011-03-18 21:13:43 +03:00
# The joind runs in the context of the rpc_proxy/member for now
2019-01-30 06:31:40 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2020-10-27 17:28:06 +03:00
$ cmd . = "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} --experimental-s4-member member" ;
2010-02-19 07:56:30 +03:00
$ cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
2013-02-28 15:57:45 +04:00
$ cmd . = " --machinepass=machine$ret->{PASSWORD}" ;
2010-02-19 07:56:30 +03:00
2010-09-14 16:41:42 +04:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2010-02-19 07:56:30 +03:00
2020-11-23 13:35:33 +03:00
# Prepare a context of the DC, but using the local CCACHE.
my $ overwrite = undef ;
$ overwrite - > { KRB5_CCACHE } = $ ret - > { KRB5_CCACHE } ;
my $ dc_cmd_env = $ self - > get_cmd_env_vars ( $ dcvars , $ overwrite ) ;
2011-03-18 21:13:43 +03:00
# Setting up delegation runs in the context of the DC for now
2020-11-23 13:35:33 +03:00
$ cmd = $ dc_cmd_env ;
2011-03-18 21:13:43 +03:00
$ cmd . = "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on" ;
2013-09-22 22:24:57 +04:00
$ cmd . = " $dcvars->{CONFIGURATION}" ;
print $ cmd ;
2011-03-18 21:13:43 +03:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Delegation failed\n$cmd" ) ;
return undef ;
}
# Setting up delegation runs in the context of the DC for now
2020-11-23 13:35:33 +03:00
$ cmd = $ dc_cmd_env ;
2011-03-18 21:13:43 +03:00
$ cmd . = "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}" ;
2013-09-22 22:24:57 +04:00
$ cmd . = " $dcvars->{CONFIGURATION}" ;
2011-03-18 21:13:43 +03:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Delegation failed\n$cmd" ) ;
return undef ;
}
2018-02-26 16:56:27 +03:00
$ ret - > { DOMSID } = $ dcvars - > { DOMSID } ;
2019-02-13 05:52:00 +03:00
$ self - > set_pdc_env_vars ( $ ret , $ dcvars ) ;
2011-03-25 14:33:33 +03:00
2007-04-17 04:30:01 +04:00
return $ ret ;
2007-04-12 12:33:35 +04:00
}
2013-01-27 15:15:50 +04:00
sub provision_promoted_dc ($$$)
2012-07-06 09:39:09 +04:00
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING PROMOTED DC...\n" ;
2012-07-06 09:39:09 +04:00
2015-02-17 05:47:47 +03:00
# We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
2012-07-06 09:39:09 +04:00
my $ ctx = $ self - > provision_raw_prepare ( $ prefix , "domain controller" ,
"promotedvdc" ,
2018-02-26 16:19:39 +03:00
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2018-02-26 16:56:27 +03:00
$ dcvars - > { SAMSID } ,
2012-07-06 09:39:09 +04:00
"2008" ,
$ dcvars - > { PASSWORD } ,
2014-09-10 12:59:39 +04:00
$ dcvars - > { SERVER_IP } ,
$ dcvars - > { SERVER_IPV6 } ) ;
2012-09-12 10:52:15 +04:00
2012-07-06 09:39:09 +04:00
$ ctx - > { smb_conf_extra_options } = "
max xmit = 32 K
server max protocol = SMB2
2017-07-04 01:31:40 +03:00
ntlm auth = ntlmv2 - only
2022-11-18 02:11:39 +03:00
kdc force enable rc4 weak session keys = yes
2012-07-06 09:39:09 +04:00
[ sysvol ]
path = $ ctx - > { statedir } / sysvol
read only = yes
[ netlogon ]
path = $ ctx - > { statedir } /sysvol/ $ ctx - > { dnsname } / scripts
read only = no
" ;
my $ ret = $ self - > provision_raw_step1 ( $ ctx ) ;
unless ( $ ret ) {
return undef ;
}
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2019-01-30 06:31:40 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2020-10-27 17:28:06 +03:00
$ cmd . = "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} --experimental-s4-member MEMBER --realm=$dcvars->{REALM}" ;
2012-07-06 09:39:09 +04:00
$ cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
2013-02-28 15:57:45 +04:00
$ cmd . = " --machinepass=machine$ret->{PASSWORD}" ;
2012-07-06 09:39:09 +04:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2019-12-07 12:38:30 +03:00
$ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
$ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2012-07-06 09:39:09 +04:00
$ cmd . = "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}" ;
$ cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
2019-11-26 11:50:48 +03:00
$ cmd . = " --machinepass=machine$ret->{PASSWORD} --dns-backend=BIND9_DLZ" ;
2012-07-06 09:39:09 +04:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2019-02-13 05:52:00 +03:00
$ self - > set_pdc_env_vars ( $ ret , $ dcvars ) ;
2012-07-06 09:39:09 +04:00
return $ ret ;
}
2010-03-12 02:36:12 +03:00
sub provision_vampire_dc ($$$)
{
2017-02-07 23:16:41 +03:00
my ( $ self , $ prefix , $ dcvars , $ fl ) = @ _ ;
print "PROVISIONING VAMPIRE DC @ FL $fl...\n" ;
my $ name = "localvampiredc" ;
getncchanges.c: Send linked attributes in each chunk
Instead of sending all the linked attributes at the end, add a
configurable option to send the links in each replication chunk.
The benefits of this approach are:
- it can reduce memory overhead, as we don't have to keep all the links
in memory over the entire replication cycle.
- the client should never end up knowing about objects but not their
links. (Although we're not sure that this has actually resulted in
replication problems, i.e. missing links).
Note that until we support GET_TGT, this approach can mean we now send
a link where the client doesn't know about the target object, causing
the client to siliently drop that linked attribute. Hence, this option
is switched off by default.
Implementation-wise, this code works fairly the same as before. Instead
of sorting the entire getnc_state->la_sorted array at the end and then
splitting it up over chunks, we now split the links up over chunks and
then sort them when we copy them into the message. This should be OK, as
I believe the MS-DRSR Doc says the links in the message should be sorted
(rather than sorting *all* the links overall). Windows behaviour seems
to chunk the links based on USN and then sort them.
getnc_state->la_idx now tracks which links in getnc_state->la_list[]
have already been sent (instead of tracking getnc_state->la_sorted).
This means the la_sorted array no longer needs to be stored in
getnc_state and we can free the array's memory once we've copied the
links into the message. Unfortunately, the link_given/link_total debug
no longer reports the correct information, so I've moved these into
getncchanges_state struct (and now free the struct a bit later so it's
safe to reference in the debug).
The vampire_dc testenv has been updated to use this new behaviour.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
Autobuild-Date(master): Fri Sep 15 10:07:33 CEST 2017 on sn-devel-144
2017-06-07 01:46:47 +03:00
my $ extra_conf = "" ;
2017-02-07 23:16:41 +03:00
if ( $ fl == "2000" ) {
getncchanges.c: Send linked attributes in each chunk
Instead of sending all the linked attributes at the end, add a
configurable option to send the links in each replication chunk.
The benefits of this approach are:
- it can reduce memory overhead, as we don't have to keep all the links
in memory over the entire replication cycle.
- the client should never end up knowing about objects but not their
links. (Although we're not sure that this has actually resulted in
replication problems, i.e. missing links).
Note that until we support GET_TGT, this approach can mean we now send
a link where the client doesn't know about the target object, causing
the client to siliently drop that linked attribute. Hence, this option
is switched off by default.
Implementation-wise, this code works fairly the same as before. Instead
of sorting the entire getnc_state->la_sorted array at the end and then
splitting it up over chunks, we now split the links up over chunks and
then sort them when we copy them into the message. This should be OK, as
I believe the MS-DRSR Doc says the links in the message should be sorted
(rather than sorting *all* the links overall). Windows behaviour seems
to chunk the links based on USN and then sort them.
getnc_state->la_idx now tracks which links in getnc_state->la_list[]
have already been sent (instead of tracking getnc_state->la_sorted).
This means the la_sorted array no longer needs to be stored in
getnc_state and we can free the array's memory once we've copied the
links into the message. Unfortunately, the link_given/link_total debug
no longer reports the correct information, so I've moved these into
getncchanges_state struct (and now free the struct a bit later so it's
safe to reference in the debug).
The vampire_dc testenv has been updated to use this new behaviour.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
Autobuild-Date(master): Fri Sep 15 10:07:33 CEST 2017 on sn-devel-144
2017-06-07 01:46:47 +03:00
$ name = "vampire2000dc" ;
} else {
2017-08-15 03:18:02 +03:00
$ extra_conf = " drs: immediate link sync = yes
drs: max link sync = 250 " ;
2017-02-07 23:16:41 +03:00
}
2010-03-12 02:36:12 +03:00
# We do this so that we don't run the provision. That's the job of 'net vampire'.
my $ ctx = $ self - > provision_raw_prepare ( $ prefix , "domain controller" ,
2017-02-07 23:16:41 +03:00
$ name ,
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2018-02-26 16:56:27 +03:00
$ dcvars - > { DOMSID } ,
2017-02-07 23:16:41 +03:00
$ fl ,
2012-03-02 04:44:56 +04:00
$ dcvars - > { PASSWORD } ,
2014-09-10 12:59:39 +04:00
$ dcvars - > { SERVER_IP } ,
$ dcvars - > { SERVER_IPV6 } ) ;
2012-09-12 10:52:15 +04:00
2010-03-12 02:36:12 +03:00
$ ctx - > { smb_conf_extra_options } = "
max xmit = 32 K
server max protocol = SMB2
2017-07-04 01:31:40 +03:00
ntlm auth = mschapv2 - and - ntlmv2 - only
getncchanges.c: Send linked attributes in each chunk
Instead of sending all the linked attributes at the end, add a
configurable option to send the links in each replication chunk.
The benefits of this approach are:
- it can reduce memory overhead, as we don't have to keep all the links
in memory over the entire replication cycle.
- the client should never end up knowing about objects but not their
links. (Although we're not sure that this has actually resulted in
replication problems, i.e. missing links).
Note that until we support GET_TGT, this approach can mean we now send
a link where the client doesn't know about the target object, causing
the client to siliently drop that linked attribute. Hence, this option
is switched off by default.
Implementation-wise, this code works fairly the same as before. Instead
of sorting the entire getnc_state->la_sorted array at the end and then
splitting it up over chunks, we now split the links up over chunks and
then sort them when we copy them into the message. This should be OK, as
I believe the MS-DRSR Doc says the links in the message should be sorted
(rather than sorting *all* the links overall). Windows behaviour seems
to chunk the links based on USN and then sort them.
getnc_state->la_idx now tracks which links in getnc_state->la_list[]
have already been sent (instead of tracking getnc_state->la_sorted).
This means the la_sorted array no longer needs to be stored in
getnc_state and we can free the array's memory once we've copied the
links into the message. Unfortunately, the link_given/link_total debug
no longer reports the correct information, so I've moved these into
getncchanges_state struct (and now free the struct a bit later so it's
safe to reference in the debug).
The vampire_dc testenv has been updated to use this new behaviour.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Autobuild-User(master): Douglas Bagnall <dbagnall@samba.org>
Autobuild-Date(master): Fri Sep 15 10:07:33 CEST 2017 on sn-devel-144
2017-06-07 01:46:47 +03:00
$ extra_conf
2017-07-04 01:31:40 +03:00
2010-03-12 02:36:12 +03:00
[ sysvol ]
2011-07-12 15:14:41 +04:00
path = $ ctx - > { statedir } / sysvol
2010-03-12 02:36:12 +03:00
read only = yes
[ netlogon ]
2011-07-12 15:14:41 +04:00
path = $ ctx - > { statedir } /sysvol/ $ ctx - > { dnsname } / scripts
2010-03-12 02:36:12 +03:00
read only = no
" ;
my $ ret = $ self - > provision_raw_step1 ( $ ctx ) ;
2010-09-14 16:41:42 +04:00
unless ( $ ret ) {
return undef ;
}
2010-03-12 02:36:12 +03:00
2011-04-27 05:19:20 +04:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2019-01-30 06:31:40 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2011-07-19 06:54:37 +04:00
$ cmd . = "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}" ;
2011-08-12 01:07:35 +04:00
$ cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only" ;
2019-11-26 11:50:48 +03:00
$ cmd . = " --machinepass=machine$ret->{PASSWORD}" ;
2022-11-22 12:31:19 +03:00
$ cmd . = " --backend-store=$self->{default_ldb_backend}" ;
2010-03-12 02:36:12 +03:00
2010-09-14 16:41:42 +04:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Join failed\n$cmd" ) ;
return undef ;
}
2010-03-12 02:36:12 +03:00
2019-02-13 05:52:00 +03:00
$ self - > set_pdc_env_vars ( $ ret , $ dcvars ) ;
2013-09-09 09:14:45 +04:00
$ ret - > { DC_REALM } = $ dcvars - > { DC_REALM } ;
2010-03-12 02:36:12 +03:00
return $ ret ;
}
2019-01-15 06:30:51 +03:00
sub provision_ad_dc_ntvfs ($$$)
2007-03-06 00:28:55 +03:00
{
2019-01-15 06:30:51 +03:00
my ( $ self , $ prefix , $ extra_provision_options ) = @ _ ;
2007-03-21 18:57:07 +03:00
2015-06-12 05:41:20 +03:00
# We keep the old 'winbind' name here in server services to
# ensure upgrades which used that name still work with the now
# alias.
2016-06-17 11:47:06 +03:00
print "PROVISIONING AD DC (NTVFS)...\n" ;
2014-05-20 02:15:31 +04:00
my $ extra_conf_options = " netbios aliases = localDC1 - a
2015-12-21 12:27:33 +03:00
server services = + winbind - winbindd
2024-01-23 16:20:24 +03:00
ldap server require strong auth = allow_sasl_without_tls_channel_bindings
2017-12-07 15:00:10 +03:00
raw NTLMv2 auth = yes
2016-12-13 02:25:12 +03:00
lsa over netlogon = yes
2016-11-14 00:15:39 +03:00
rpc server port = 1027
2017-03-24 05:19:32 +03:00
auth event notification = true
2018-04-04 02:59:41 +03:00
dsdb event notification = true
dsdb password event notification = true
2018-04-16 05:03:14 +03:00
dsdb group change notification = true
2019-11-27 11:30:06 +03:00
# override the new SMB2 only default
client min protocol = CORE
server min protocol = LANMAN1
2022-11-30 14:26:01 +03:00
CVE_2020_1472:warn_about_unused_debug_level = 3
2022-11-30 16:57:20 +03:00
CVE_2022_38023:warn_about_unused_debug_level = 3
allow nt4 crypto:torturetest \ $ = yes
server reject md5 schannel:schannel2 \ $ = no
server reject md5 schannel:schannel3 \ $ = no
server reject md5 schannel:schannel8 \ $ = no
server reject md5 schannel:schannel9 \ $ = no
server reject md5 schannel:torturetest \ $ = no
server reject md5 schannel:tests4u2proxywk \ $ = no
server reject md5 schannel:tests4u2selfbdc \ $ = no
server reject md5 schannel:tests4u2selfwk \ $ = no
server reject md5 schannel:torturepacbdc \ $ = no
server reject md5 schannel:torturepacwksta \ $ = no
2022-11-30 14:26:01 +03:00
server require schannel : schannel0 \ $ = no
server require schannel : schannel1 \ $ = no
server require schannel : schannel2 \ $ = no
server require schannel : schannel3 \ $ = no
server require schannel : schannel4 \ $ = no
server require schannel : schannel5 \ $ = no
server require schannel : schannel6 \ $ = no
server require schannel : schannel7 \ $ = no
server require schannel : schannel8 \ $ = no
server require schannel : schannel9 \ $ = no
server require schannel : schannel10 \ $ = no
server require schannel : schannel11 \ $ = no
server require schannel : torturetest \ $ = no
2022-11-25 16:05:30 +03:00
server schannel require seal : schannel0 \ $ = no
server schannel require seal : schannel1 \ $ = no
server schannel require seal : schannel2 \ $ = no
server schannel require seal : schannel3 \ $ = no
server schannel require seal : schannel4 \ $ = no
server schannel require seal : schannel5 \ $ = no
server schannel require seal : schannel6 \ $ = no
server schannel require seal : schannel7 \ $ = no
server schannel require seal : schannel8 \ $ = no
server schannel require seal : schannel9 \ $ = no
server schannel require seal : schannel10 \ $ = no
server schannel require seal : schannel11 \ $ = no
server schannel require seal : torturetest \ $ = no
2022-11-30 14:26:01 +03:00
# needed for 'samba.tests.auth_log' tests
server require schannel : LOCALDC \ $ = no
2022-11-25 16:05:30 +03:00
server schannel require seal : LOCALDC \ $ = no
2015-12-21 12:27:33 +03:00
" ;
2023-05-11 01:03:30 +03:00
push ( @ { $ extra_provision_options } ,
"--base-schema=2008_R2" ,
"--use-ntvfs" ) ;
2007-04-29 17:54:51 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
"localdc" ,
2010-11-01 01:05:03 +03:00
"SAMBADOMAIN" ,
"samba.example.com" ,
2010-06-15 16:24:36 +04:00
"2008" ,
2010-06-16 13:22:30 +04:00
"locDCpass1" ,
2014-09-10 12:59:39 +04:00
undef ,
undef ,
2020-03-13 16:29:48 +03:00
undef ,
2014-09-10 12:59:39 +04:00
$ extra_conf_options ,
"" ,
2018-11-26 03:32:03 +03:00
$ extra_provision_options ) ;
2016-06-17 10:23:49 +03:00
unless ( $ ret ) {
return undef ;
}
2007-04-17 04:30:01 +04:00
2010-09-14 16:41:42 +04:00
unless ( $ self - > add_wins_config ( "$prefix/private" ) ) {
warn ( "Unable to add wins configuration" ) ;
return undef ;
}
2011-12-13 08:43:35 +04:00
$ ret - > { NETBIOSALIAS } = "localdc1-a" ;
2013-09-09 09:14:45 +04:00
$ ret - > { DC_REALM } = $ ret - > { REALM } ;
2010-02-19 07:56:30 +03:00
2007-04-17 04:30:01 +04:00
return $ ret ;
2007-03-06 00:28:55 +03:00
}
2010-06-15 16:24:36 +04:00
sub provision_fl2000dc ($$)
{
my ( $ self , $ prefix ) = @ _ ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING DC WITH FOREST LEVEL 2000...\n" ;
2016-04-25 17:02:22 +03:00
my $ extra_conf_options = "
2022-03-09 14:53:18 +03:00
kdc enable fast = no
2016-04-25 17:02:22 +03:00
spnego:simulate_w2k = yes
ntlmssp_server:force_old_spnego = yes
2022-11-30 16:57:20 +03:00
CVE_2022_38023:warn_about_unused_debug_level = 3
server reject md5 schannel:tests4u2proxywk \ $ = no
server reject md5 schannel:tests4u2selfbdc \ $ = no
server reject md5 schannel:tests4u2selfwk \ $ = no
server reject md5 schannel:torturepacbdc \ $ = no
server reject md5 schannel:torturepacwksta \ $ = no
2016-04-25 17:02:22 +03:00
" ;
2019-11-26 11:50:48 +03:00
my $ extra_provision_options = [ "--base-schema=2008_R2" ] ;
2017-12-14 21:27:10 +03:00
# This environment uses plain text secrets
# i.e. secret attributes are not encrypted on disk.
# This allows testing of the --plaintext-secrets option for
# provision
push ( @ { $ extra_provision_options } , "--plaintext-secrets" ) ;
2010-06-15 16:24:36 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
2010-06-23 03:53:20 +04:00
"dc5" ,
2010-11-01 01:05:03 +03:00
"SAMBA2000" ,
"samba2000.example.com" ,
2010-06-15 16:24:36 +04:00
"2000" ,
2010-06-16 13:14:46 +04:00
"locDCpass5" ,
2014-09-10 12:59:39 +04:00
undef ,
undef ,
2020-03-13 16:29:48 +03:00
undef ,
2016-04-25 17:02:22 +03:00
$ extra_conf_options ,
2014-09-10 12:59:39 +04:00
"" ,
2017-12-14 21:27:10 +03:00
$ extra_provision_options ) ;
2016-06-17 10:23:49 +03:00
unless ( $ ret ) {
return undef ;
}
2010-06-15 16:24:36 +04:00
2010-09-14 16:41:42 +04:00
unless ( $ self - > add_wins_config ( "$prefix/private" ) ) {
warn ( "Unable to add wins configuration" ) ;
return undef ;
}
2016-04-26 09:50:00 +03:00
$ ret - > { DC_REALM } = $ ret - > { REALM } ;
2010-06-15 16:24:36 +04:00
return $ ret ;
}
2015-02-11 11:58:07 +03:00
sub provision_fl2003dc ($$$)
2010-06-21 16:17:40 +04:00
{
2015-02-11 11:58:07 +03:00
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2019-02-19 06:18:11 +03:00
my $ ip_addr1 = Samba:: get_ipv4_addr ( "fakednsforwarder1" ) ;
2021-09-18 01:05:24 +03:00
my $ ip_addr2 = Samba:: get_ipv6_addr ( "fakednsforwarder2" ) ;
2010-06-21 16:17:40 +04:00
2016-06-17 11:47:06 +03:00
print "PROVISIONING DC WITH FOREST LEVEL 2003...\n" ;
2022-11-30 16:57:20 +03:00
my $ extra_conf_options = "
allow dns updates = nonsecure and secure
2022-03-09 14:53:18 +03:00
kdc enable fast = no
2017-05-13 09:37:05 +03:00
dcesrv:header signing = no
2018-12-14 15:36:39 +03:00
dcesrv:max auth states = 0
2022-11-30 16:57:20 +03:00
dns forwarder = $ ip_addr1 [ $ ip_addr2 ] : 54
CVE_2022_38023:warn_about_unused_debug_level = 3
server reject md5 schannel:tests4u2proxywk \ $ = no
server reject md5 schannel:tests4u2selfbdc \ $ = no
server reject md5 schannel:tests4u2selfwk \ $ = no
server reject md5 schannel:torturepacbdc \ $ = no
server reject md5 schannel:torturepacwksta \ $ = no
" ;
2019-11-26 11:50:48 +03:00
my $ extra_provision_options = [ "--base-schema=2008_R2" ] ;
2010-06-21 16:17:40 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
2010-06-23 03:53:20 +04:00
"dc6" ,
2010-06-21 16:17:40 +04:00
"SAMBA2003" ,
"samba2003.example.com" ,
"2003" ,
"locDCpass6" ,
2014-09-10 12:59:39 +04:00
undef ,
undef ,
2020-03-13 16:29:48 +03:00
undef ,
2014-09-10 12:59:39 +04:00
$ extra_conf_options ,
"" ,
2018-11-26 03:32:03 +03:00
$ extra_provision_options ) ;
2014-05-19 09:32:56 +04:00
unless ( defined $ ret ) {
return undef ;
}
2019-02-19 06:18:11 +03:00
$ ret - > { DNS_FORWARDER1 } = $ ip_addr1 ;
$ ret - > { DNS_FORWARDER2 } = $ ip_addr2 ;
2014-05-19 09:32:56 +04:00
my @ samba_tool_options ;
push ( @ samba_tool_options , Samba:: bindir_path ( $ self , "samba-tool" ) ) ;
push ( @ samba_tool_options , "domain" ) ;
push ( @ samba_tool_options , "passwordsettings" ) ;
push ( @ samba_tool_options , "set" ) ;
push ( @ samba_tool_options , "--configfile=$ret->{SERVERCONFFILE}" ) ;
push ( @ samba_tool_options , "--min-pwd-age=0" ) ;
push ( @ samba_tool_options , "--history-length=1" ) ;
my $ samba_tool_cmd = join ( " " , @ samba_tool_options ) ;
unless ( system ( $ samba_tool_cmd ) == 0 ) {
warn ( "Unable to set min password age to 0: \n$samba_tool_cmd\n" ) ;
return undef ;
}
2010-09-14 16:41:42 +04:00
unless ( $ self - > add_wins_config ( "$prefix/private" ) ) {
warn ( "Unable to add wins configuration" ) ;
return undef ;
}
2010-06-21 16:17:40 +04:00
return $ ret ;
}
2015-02-11 11:58:07 +03:00
sub provision_fl2008r2dc ($$$)
2010-06-21 16:17:40 +04:00
{
2015-02-11 11:58:07 +03:00
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2010-06-21 16:17:40 +04:00
2016-06-17 11:47:06 +03:00
print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n" ;
2020-08-13 15:59:58 +03:00
my $ extra_conf_options = "
ldap server require strong auth = no
# delay by 10 seconds, 10^7 usecs
ldap_server:delay_expire_disconnect = 10000
2022-11-30 16:57:20 +03:00
CVE_2022_38023:warn_about_unused_debug_level = 3
server reject md5 schannel:tests4u2proxywk \ $ = no
server reject md5 schannel:tests4u2selfbdc \ $ = no
server reject md5 schannel:tests4u2selfwk \ $ = no
server reject md5 schannel:torturepacbdc \ $ = no
server reject md5 schannel:torturepacwksta \ $ = no
2020-08-13 15:59:58 +03:00
" ;
2019-11-26 11:50:48 +03:00
my $ extra_provision_options = [ "--base-schema=2008_R2" ] ;
2010-06-21 16:17:40 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
2010-06-23 03:53:20 +04:00
"dc7" ,
2010-06-21 16:17:40 +04:00
"SAMBA2008R2" ,
"samba2008R2.example.com" ,
2010-06-23 04:24:14 +04:00
"2008_R2" ,
2010-06-21 16:17:40 +04:00
"locDCpass7" ,
2014-09-10 12:59:39 +04:00
undef ,
undef ,
2020-03-13 16:29:48 +03:00
undef ,
2015-12-21 12:27:33 +03:00
$ extra_conf_options ,
2014-09-10 12:59:39 +04:00
"" ,
2018-11-26 03:32:03 +03:00
$ extra_provision_options ) ;
2016-06-17 10:23:49 +03:00
unless ( defined $ ret ) {
return undef ;
}
2010-06-21 16:17:40 +04:00
2010-09-14 16:41:42 +04:00
unless ( $ self - > add_wins_config ( "$prefix/private" ) ) {
warn ( "Unable to add wins configuration" ) ;
return undef ;
}
2016-04-26 09:50:00 +03:00
$ ret - > { DC_REALM } = $ ret - > { REALM } ;
2010-06-21 16:17:40 +04:00
return $ ret ;
}
2010-09-09 12:02:31 +04:00
sub provision_rodc ($$$)
{
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING RODC...\n" ;
2010-09-09 12:02:31 +04:00
# We do this so that we don't run the provision. That's the job of 'net join RODC'.
my $ ctx = $ self - > provision_raw_prepare ( $ prefix , "domain controller" ,
"rodc" ,
2018-02-26 16:19:39 +03:00
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2018-02-26 16:56:27 +03:00
$ dcvars - > { DOMSID } ,
2010-09-09 12:02:31 +04:00
"2008" ,
2012-03-02 04:44:56 +04:00
$ dcvars - > { PASSWORD } ,
2014-09-10 12:59:39 +04:00
$ dcvars - > { SERVER_IP } ,
$ dcvars - > { SERVER_IPV6 } ) ;
2010-09-14 16:41:42 +04:00
unless ( $ ctx ) {
return undef ;
}
2010-09-09 12:02:31 +04:00
2012-04-30 09:08:38 +04:00
$ ctx - > { share } = "$ctx->{prefix_abs}/share" ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}" ) ;
2010-09-09 12:02:31 +04:00
$ ctx - > { smb_conf_extra_options } = "
max xmit = 32 K
server max protocol = SMB2
2017-04-26 07:11:28 +03:00
password server = $ dcvars - > { DC_SERVER }
2010-09-09 12:02:31 +04:00
[ sysvol ]
2011-07-12 15:14:41 +04:00
path = $ ctx - > { statedir } / sysvol
2010-09-09 12:02:31 +04:00
read only = yes
[ netlogon ]
2011-07-12 15:14:41 +04:00
path = $ ctx - > { statedir } /sysvol/ $ ctx - > { dnsname } / scripts
2010-09-09 12:02:31 +04:00
read only = yes
[ tmp ]
2012-04-30 09:08:38 +04:00
path = $ ctx - > { share }
2010-09-09 12:02:31 +04:00
read only = no
posix:sharedelay = 10000
posix:oplocktimeout = 3
2012-03-15 20:32:51 +04:00
posix:writetimeupdatedelay = 50000
2010-09-09 12:02:31 +04:00
" ;
my $ ret = $ self - > provision_raw_step1 ( $ ctx ) ;
2010-09-14 16:41:42 +04:00
unless ( $ ret ) {
return undef ;
}
2010-09-09 12:02:31 +04:00
2011-04-27 05:19:20 +04:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2019-01-30 06:31:40 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2011-07-19 06:54:37 +04:00
$ cmd . = "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC" ;
2010-09-09 12:02:31 +04:00
$ cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
2019-11-26 11:50:48 +03:00
$ cmd . = " --server=$dcvars->{DC_SERVER}" ;
2010-09-09 12:02:31 +04:00
2015-01-21 05:57:40 +03:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "RODC join failed\n$cmd" ) ;
return undef ;
}
2015-03-29 12:15:29 +03:00
# This ensures deterministic behaviour for tests that want to have the 'testallowed account'
2015-01-21 05:57:40 +03:00
# user password verified on the RODC
2015-03-29 12:15:29 +03:00
my $ testallowed_account = "testallowed account" ;
2020-11-23 13:35:33 +03:00
$ cmd = $ self - > get_cmd_env_vars ( $ ret ) ;
2015-03-29 12:15:29 +03:00
$ cmd . = "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}" ;
2015-01-21 05:57:40 +03:00
$ cmd . = " --server=$dcvars->{DC_SERVER}" ;
2010-09-14 16:41:42 +04:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "RODC join failed\n$cmd" ) ;
return undef ;
}
2010-09-09 12:02:31 +04:00
2011-03-04 12:05:51 +03:00
# we overwrite the kdc after the RODC join
# so that use the RODC as kdc and test
# the proxy code
$ ctx - > { kdc_ipv4 } = $ ret - > { SERVER_IP } ;
2014-09-10 12:59:39 +04:00
$ ctx - > { kdc_ipv6 } = $ ret - > { SERVER_IPV6 } ;
2011-04-19 10:38:46 +04:00
Samba:: mk_krb5_conf ( $ ctx ) ;
2014-04-30 11:32:49 +04:00
Samba:: mk_mitkdc_conf ( $ ctx , abs_path ( Samba:: bindir_path ( $ self , "shared" ) ) ) ;
2011-03-04 12:05:51 +03:00
2019-02-13 05:52:00 +03:00
$ self - > set_pdc_env_vars ( $ ret , $ dcvars ) ;
2010-09-09 12:02:31 +04:00
return $ ret ;
}
2016-01-12 15:51:00 +03:00
sub read_config_h ($)
{
my ( $ name ) = @ _ ;
2019-12-07 12:45:47 +03:00
my % ret ;
2016-01-12 15:51:00 +03:00
open ( LF , "<$name" ) or die ( "unable to read $name: $!" ) ;
while ( <LF> ) {
chomp ;
next if not ( /^#define / ) ;
if ( /^#define (.*?)[ \t]+(.*?)$/ ) {
$ ret { $ 1 } = $ 2 ;
next ;
}
if ( /^#define (.*?)[ \t]+$/ ) {
$ ret { $ 1 } = 1 ; ;
next ;
}
}
close ( LF ) ;
return \ % ret ;
}
2023-05-11 01:38:20 +03:00
sub provision_ad_dc ()
2011-05-08 08:55:33 +04:00
{
2020-03-13 16:26:33 +03:00
my ( $ self ,
$ prefix ,
$ hostname ,
$ domain ,
$ realm ,
$ force_fips_mode ,
$ smbconf_args ,
2023-05-11 01:38:20 +03:00
$ extra_provision_options ,
$ functional_level ) = @ _ ;
2011-05-08 08:55:33 +04:00
2012-04-26 09:20:02 +04:00
my $ prefix_abs = abs_path ( $ prefix ) ;
2012-04-30 17:39:27 +04:00
my $ bindir_abs = abs_path ( $ self - > { bindir } ) ;
my $ lockdir = "$prefix_abs/lockdir" ;
2012-08-30 16:09:49 +04:00
my $ conffile = "$prefix_abs/etc/smb.conf" ;
2012-04-30 17:39:27 +04:00
2016-01-16 12:20:32 +03:00
my $ require_mutexes = "dbwrap_tdb_require_mutexes:* = yes" ;
2020-02-02 10:57:17 +03:00
if ( $ ENV { SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT } // '' eq "1" ) {
$ require_mutexes = "" ;
}
2016-01-16 12:20:32 +03:00
2016-01-12 15:51:00 +03:00
my $ config_h = { } ;
2023-05-11 01:38:20 +03:00
if ( ! defined ( $ functional_level ) ) {
2023-05-11 05:25:31 +03:00
$ functional_level = "2016" ;
2023-05-11 01:38:20 +03:00
}
2023-05-11 05:25:31 +03:00
# If we choose to have distinct environments for experimental
# 2012 as well as the experimental 2016 support, we should
# extend what we match here.
if ( $ functional_level eq "2016" ) {
$ smbconf_args = " $ smbconf_args
[ global ]
ad dc functional level = 2016
" ;
}
2016-01-12 15:51:00 +03:00
if ( defined ( $ ENV { CONFIG_H } ) ) {
$ config_h = read_config_h ( $ ENV { CONFIG_H } ) ;
}
my $ password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A" ;
$ password_hash_gpg_key_ids = "" unless defined ( $ config_h - > { HAVE_GPGME } ) ;
2011-05-08 08:55:33 +04:00
my $ extra_smbconf_options = "
2012-04-26 09:20:02 +04:00
xattr_tdb:file = $ prefix_abs /statedir/x attr . tdb
2013-05-13 13:14:26 +04:00
dbwrap_tdb_mutexes: * = yes
2016-01-16 12:20:32 +03:00
$ { require_mutexes }
2013-05-13 13:14:26 +04:00
2016-01-12 15:51:00 +03:00
$ { password_hash_gpg_key_ids }
2012-04-26 09:20:02 +04:00
kernel oplocks = no
kernel change notify = no
2016-07-20 13:32:58 +03:00
smb2 leases = no
2020-06-19 13:32:59 +03:00
smb2 disable oplock break retry = yes
server multi channel support = yes
2012-04-26 09:20:02 +04:00
2015-03-24 02:16:36 +03:00
logging = file
2012-04-26 09:20:02 +04:00
printing = bsd
printcap name = /dev/ null
2012-09-12 16:10:55 +04:00
max protocol = SMB3
2012-04-26 09:20:02 +04:00
read only = no
smbd:sharedelay = 100000
smbd:writetimeupdatedelay = 500000
2013-03-10 13:25:53 +04:00
create mask = 755
2012-04-26 09:20:02 +04:00
dos filemode = yes
2018-01-11 19:52:06 +03:00
check parent directory delete on close = yes
2012-04-26 09:20:02 +04:00
2012-05-01 10:06:39 +04:00
dcerpc endpoint servers = - winreg - srvsvc
2012-04-30 17:39:27 +04:00
printcap name = /dev/ null
2012-08-30 16:09:49 +04:00
addprinter command = $ ENV { SRCDIR_ABS } /source3/sc ript /tests/ printing / modprinter . pl - a - s $ conffile - -
deleteprinter command = $ ENV { SRCDIR_ABS } /source3/sc ript /tests/ printing / modprinter . pl - d - s $ conffile - -
2012-04-30 17:39:27 +04: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
lpq cache time = 0
2013-10-14 15:53:22 +04:00
print notify backchannel = yes
2017-03-24 05:19:32 +03:00
2022-11-30 14:26:01 +03:00
CVE_2020_1472:warn_about_unused_debug_level = 3
2022-11-30 16:57:20 +03:00
CVE_2022_38023:warn_about_unused_debug_level = 3
CVE_2022_38023:error_debug_level = 2
server reject md5 schannel:schannel2 \ $ = no
server reject md5 schannel:schannel3 \ $ = no
server reject md5 schannel:schannel8 \ $ = no
server reject md5 schannel:schannel9 \ $ = no
server reject md5 schannel:torturetest \ $ = no
server reject md5 schannel:tests4u2proxywk \ $ = no
server reject md5 schannel:tests4u2selfbdc \ $ = no
server reject md5 schannel:tests4u2selfwk \ $ = no
server reject md5 schannel:torturepacbdc \ $ = no
server reject md5 schannel:torturepacwksta \ $ = no
server reject md5 schannel:samlogontest \ $ = no
2022-11-30 14:26:01 +03:00
server require schannel : schannel0 \ $ = no
server require schannel : schannel1 \ $ = no
server require schannel : schannel2 \ $ = no
server require schannel : schannel3 \ $ = no
server require schannel : schannel4 \ $ = no
server require schannel : schannel5 \ $ = no
server require schannel : schannel6 \ $ = no
server require schannel : schannel7 \ $ = no
server require schannel : schannel8 \ $ = no
server require schannel : schannel9 \ $ = no
server require schannel : schannel10 \ $ = no
server require schannel : schannel11 \ $ = no
server require schannel : torturetest \ $ = no
2022-11-25 16:05:30 +03:00
server schannel require seal : schannel0 \ $ = no
server schannel require seal : schannel1 \ $ = no
server schannel require seal : schannel2 \ $ = no
server schannel require seal : schannel3 \ $ = no
server schannel require seal : schannel4 \ $ = no
server schannel require seal : schannel5 \ $ = no
server schannel require seal : schannel6 \ $ = no
server schannel require seal : schannel7 \ $ = no
server schannel require seal : schannel8 \ $ = no
server schannel require seal : schannel9 \ $ = no
server schannel require seal : schannel10 \ $ = no
server schannel require seal : schannel11 \ $ = no
server schannel require seal : torturetest \ $ = no
2022-11-30 14:26:01 +03:00
auth event notification = true
2018-04-04 02:59:41 +03:00
dsdb event notification = true
dsdb password event notification = true
2018-04-16 05:03:14 +03:00
dsdb group change notification = true
2017-07-05 05:03:17 +03:00
$ smbconf_args
2012-04-26 09:20:02 +04:00
" ;
my $ extra_smbconf_shares = "
2012-08-17 10:50:21 +04:00
[ tmpenc ]
copy = tmp
smb encrypt = required
2012-04-26 09:20:02 +04:00
[ tmpcase ]
copy = tmp
case sensitive = yes
[ tmpguest ]
copy = tmp
guest ok = yes
2012-04-30 09:17:54 +04:00
[ hideunread ]
copy = tmp
hide unreadable = yes
2012-08-30 16:09:49 +04:00
2012-08-09 17:27:50 +04:00
[ durable ]
copy = tmp
kernel share modes = no
kernel oplocks = no
posix locking = no
2012-08-30 16:09:49 +04:00
[ print \ $]
copy = tmp
[ print1 ]
copy = tmp
printable = yes
[ print2 ]
copy = print1
[ print3 ]
copy = print1
2019-10-28 11:38:08 +03:00
[ print4 ]
copy = print1
guest ok = yes
2012-08-30 16:09:49 +04:00
[ lp ]
copy = print1
2011-05-08 08:55:33 +04:00
" ;
2022-11-22 12:31:19 +03:00
push ( @ { $ extra_provision_options } , "--backend-store=$self->{default_ldb_backend}" ) ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING AD DC...\n" ;
2011-05-08 08:55:33 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
2017-07-05 05:03:17 +03:00
$ hostname ,
$ domain ,
$ realm ,
2023-05-11 01:38:20 +03:00
$ functional_level ,
2011-05-08 08:55:33 +04:00
"locDCpass1" ,
2014-09-10 12:59:39 +04:00
undef ,
undef ,
2020-03-13 16:29:48 +03:00
$ force_fips_mode ,
2014-09-10 12:59:39 +04:00
$ extra_smbconf_options ,
$ extra_smbconf_shares ,
2018-05-14 03:14:06 +03:00
$ extra_provision_options ) ;
2016-06-17 10:23:49 +03:00
unless ( defined $ ret ) {
return undef ;
}
2011-05-08 08:55:33 +04:00
unless ( $ self - > add_wins_config ( "$prefix/private" ) ) {
warn ( "Unable to add wins configuration" ) ;
return undef ;
}
return $ ret ;
}
2012-02-29 05:48:21 +04:00
sub provision_chgdcpass ($$)
{
my ( $ self , $ prefix ) = @ _ ;
2016-06-17 11:47:06 +03:00
print "PROVISIONING CHGDCPASS...\n" ;
2016-06-13 06:42:46 +03:00
# This environment disallows the use of this password
# (and also removes the default AD complexity checks)
2019-09-19 02:50:01 +03:00
my $ unacceptable_password = "Paßßword-widk3Dsle32jxdBdskldsk55klASKQ" ;
2022-09-29 04:54:14 +03:00
# This environment also sets some settings that are unusual,
# to test specific behaviours. In particular, this
# environment fails to correctly support DRSUAPI_DRS_GET_ANC
# like Samba before 4.5 and DRSUAPI_DRS_GET_TGT before 4.8
#
# Additionally, disabling DRSUAPI_DRS_GET_TGT causes all links
# to be sent last (in the final chunk), which is like Samba
# before 4.8.
2018-11-23 02:23:23 +03:00
my $ extra_smb_conf = "
2019-02-05 17:30:36 +03:00
check password script = $ self - > { srcdir } /selftest/c heckpassword_arg1 . sh $ { unacceptable_password }
2018-12-14 15:51:27 +03:00
dcesrv:max auth states = 8
2022-09-29 04:54:14 +03:00
drs:broken_samba_4 .5_ get_anc_emulation = true
drs:get_tgt_support = false
2018-11-23 02:23:23 +03:00
" ;
2019-11-26 11:50:48 +03:00
my $ extra_provision_options = [ "--dns-backend=BIND9_DLZ" ] ;
2012-02-29 05:48:21 +04:00
my $ ret = $ self - > provision ( $ prefix ,
"domain controller" ,
"chgdcpass" ,
"CHDCDOMAIN" ,
"chgdcpassword.samba.example.com" ,
"2008" ,
"chgDCpass1" ,
2014-09-10 12:59:39 +04:00
undef ,
undef ,
2020-03-13 16:29:48 +03:00
undef ,
2018-11-23 02:23:23 +03:00
$ extra_smb_conf ,
2014-09-10 12:59:39 +04:00
"" ,
2012-09-12 10:52:15 +04:00
$ extra_provision_options ) ;
2016-06-17 10:23:49 +03:00
unless ( defined $ ret ) {
return undef ;
}
2012-02-29 05:48:21 +04:00
unless ( $ self - > add_wins_config ( "$prefix/private" ) ) {
warn ( "Unable to add wins configuration" ) ;
return undef ;
}
2023-12-08 15:06:27 +03:00
2014-05-20 02:15:31 +04:00
# Remove secrets.tdb from this environment to test that we
# still start up on systems without the new matching
2015-06-17 02:59:49 +03:00
# secrets.tdb records.
2013-02-20 08:29:42 +04:00
unless ( unlink ( "$ret->{PRIVATEDIR}/secrets.tdb" ) || unlink ( "$ret->{PRIVATEDIR}/secrets.ntdb" ) ) {
2012-08-29 03:10:40 +04:00
warn ( "Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision" ) ;
return undef ;
}
2019-02-17 23:28:37 +03:00
2016-06-13 06:42:46 +03:00
$ ret - > { UNACCEPTABLE_PASSWORD } = $ unacceptable_password ;
2012-02-29 05:48:21 +04:00
return $ ret ;
}
2016-11-30 04:18:46 +03:00
sub teardown_env_terminate ($$)
2007-03-21 18:57:07 +03:00
{
2007-04-11 00:19:31 +04:00
my ( $ self , $ envvars ) = @ _ ;
2007-07-04 04:34:16 +04:00
my $ pid ;
2007-03-21 18:57:07 +03:00
2019-01-18 01:50:45 +03:00
# This should cause samba to terminate gracefully
my $ smbcontrol = Samba:: bindir_path ( $ self , "smbcontrol" ) ;
my $ cmd = "" ;
$ cmd . = "$smbcontrol samba shutdown $envvars->{CONFIGURATION}" ;
my $ ret = system ( $ cmd ) ;
if ( $ ret != 0 ) {
warn "'$cmd' failed with '$ret'\n" ;
}
2012-03-02 11:01:13 +04:00
# This should cause samba to terminate gracefully
close ( $ envvars - > { STDIN_PIPE } ) ;
2007-03-21 18:57:07 +03:00
2012-03-04 10:30:45 +04:00
$ pid = $ envvars - > { SAMBA_PID } ;
my $ count = 0 ;
my $ childpid ;
2012-03-04 11:32:44 +04:00
# This should give it time to write out the gcov data
2016-11-30 04:18:46 +03:00
until ( $ count > 15 ) {
if ( Samba:: cleanup_child ( $ pid , "samba" ) != 0 ) {
return ;
}
sleep ( 1 ) ;
$ count + + ;
}
# After 15 Seconds, work out why this thing is still alive
warn "server process $pid took more than $count seconds to exit, showing backtrace:\n" ;
system ( "$self->{srcdir}/selftest/gdb_backtrace $pid" ) ;
2012-06-29 07:38:11 +04:00
until ( $ count > 30 ) {
2016-11-30 04:18:46 +03:00
if ( Samba:: cleanup_child ( $ pid , "samba" ) != 0 ) {
return ;
2012-03-04 11:32:44 +04:00
}
2012-03-04 10:30:45 +04:00
sleep ( 1 ) ;
$ count + + ;
}
2012-03-04 11:32:44 +04:00
2016-11-30 04:18:46 +03:00
if ( kill ( 0 , $ pid ) ) {
warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n" ;
2013-09-19 16:52:59 +04:00
kill "TERM" , $ pid ;
2016-11-30 04:18:46 +03:00
}
2012-03-04 11:32:44 +04:00
2016-11-30 04:18:46 +03:00
until ( $ count > 40 ) {
if ( Samba:: cleanup_child ( $ pid , "samba" ) != 0 ) {
return ;
2012-03-04 11:32:44 +04:00
}
2016-11-30 04:18:46 +03:00
sleep ( 1 ) ;
$ count + + ;
}
# If it is still around, kill it
if ( kill ( 0 , $ pid ) ) {
warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n" ;
2012-03-04 10:30:45 +04:00
kill 9 , $ pid ;
2007-03-21 18:57:07 +03:00
}
2016-11-30 04:18:46 +03:00
return ;
}
sub teardown_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
teardown_env_terminate ( $ self , $ envvars ) ;
2007-03-21 18:57:07 +03:00
2007-04-19 20:37:11 +04:00
print $ self - > getlog_env ( $ envvars ) ;
2012-03-04 10:30:45 +04:00
return ;
2007-03-21 18:57:07 +03:00
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
2016-05-05 02:35:46 +03:00
my $ title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n" ;
2007-04-18 18:02:26 +04:00
my $ out = $ title ;
2009-02-04 17:17:14 +03:00
open ( LOG , "<$envvars->{SAMBA_TEST_LOG}" ) ;
2007-04-18 18:02:26 +04:00
2009-02-04 17:17:14 +03:00
seek ( LOG , $ envvars - > { SAMBA_TEST_LOG_POS } , SEEK_SET ) ;
2007-04-18 18:02:26 +04:00
while ( <LOG> ) {
$ out . = $ _ ;
}
2009-02-04 17:17:14 +03:00
$ envvars - > { SAMBA_TEST_LOG_POS } = tell ( LOG ) ;
2007-04-18 18:02:26 +04:00
close ( LOG ) ;
return "" if $ out eq $ title ;
2010-11-01 01:05:03 +03:00
2007-04-18 18:02:26 +04:00
return $ out ;
}
2007-04-19 18:54:09 +04:00
sub check_env ($$)
{
my ( $ self , $ envvars ) = @ _ ;
2015-10-26 08:38:08 +03:00
my $ samba_pid = $ envvars - > { SAMBA_PID } ;
2007-04-19 18:54:09 +04:00
2015-12-07 03:32:25 +03:00
if ( not defined ( $ samba_pid ) ) {
return 0 ;
} elsif ( $ samba_pid > 0 ) {
my $ childpid = Samba:: cleanup_child ( $ samba_pid , "samba" ) ;
2015-10-26 08:38:08 +03:00
2015-12-07 03:32:25 +03:00
if ( $ childpid == 0 ) {
return 1 ;
}
return 0 ;
} else {
2015-12-07 03:18:38 +03:00
return 1 ;
}
2007-04-19 18:54:09 +04:00
}
2018-02-21 03:33:49 +03:00
# Declare the environments Samba4 makes available.
# To be set up, they will be called as
# samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2019-01-30 00:04:28 +03:00
# The interdependencies between the testenvs are declared below. Some testenvs
# are dependent on another testenv running first, e.g. vampire_dc is dependent
# on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
# dependent on dns_hub, which handles resolving DNS queries for the realm.
2018-02-21 03:33:49 +03:00
% Samba4:: ENV_DEPS = (
# name => [dep_1, dep_2, ...],
2019-01-02 16:18:44 +03:00
dns_hub = > [] ,
ad_dc_ntvfs = > [ "dns_hub" ] ,
2020-03-13 14:39:54 +03:00
ad_dc_fips = > [ "dns_hub" ] ,
2019-01-02 16:18:44 +03:00
ad_dc = > [ "dns_hub" ] ,
2019-12-04 18:27:04 +03:00
ad_dc_smb1 = > [ "dns_hub" ] ,
2019-12-17 18:31:27 +03:00
ad_dc_smb1_done = > [ "ad_dc_smb1" ] ,
2019-01-02 16:18:44 +03:00
ad_dc_no_nss = > [ "dns_hub" ] ,
ad_dc_no_ntlm = > [ "dns_hub" ] ,
2007-04-18 18:02:26 +04:00
2024-01-13 10:48:54 +03:00
fl2008r2dc = > [ "ad_dc" , "nt4_dc" ] ,
2018-02-21 03:33:49 +03:00
fl2003dc = > [ "ad_dc" ] ,
2017-06-09 16:03:29 +03:00
fl2000dc = > [ "ad_dc" ] ,
2010-10-02 23:42:00 +04:00
2018-02-21 03:33:49 +03:00
vampire_2000_dc = > [ "fl2000dc" ] ,
vampire_dc = > [ "ad_dc_ntvfs" ] ,
promoted_dc = > [ "ad_dc_ntvfs" ] ,
2012-02-15 01:55:05 +04:00
2018-02-21 03:33:49 +03:00
rodc = > [ "ad_dc_ntvfs" ] ,
rpc_proxy = > [ "ad_dc_ntvfs" ] ,
2019-01-02 16:18:44 +03:00
chgdcpass = > [ "dns_hub" ] ,
2018-02-21 03:33:49 +03:00
s4member_dflt_domain = > [ "ad_dc_ntvfs" ] ,
s4member = > [ "ad_dc_ntvfs" ] ,
2019-01-29 23:57:29 +03:00
# envs that test the server process model
proclimitdc = > [ "dns_hub" ] ,
preforkrestartdc = > [ "dns_hub" ] ,
# backup/restore testenvs
backupfromdc = > [ "dns_hub" ] ,
customdc = > [ "dns_hub" ] ,
2018-05-29 07:05:02 +03:00
restoredc = > [ "backupfromdc" ] ,
2018-06-11 02:02:11 +03:00
renamedc = > [ "backupfromdc" ] ,
2018-07-23 06:20:03 +03:00
offlinebackupdc = > [ "backupfromdc" ] ,
2018-07-06 06:59:31 +03:00
labdc = > [ "backupfromdc" ] ,
2018-05-29 07:05:02 +03:00
2023-04-11 11:04:23 +03:00
# aliases in order to split autobuild tasks
2023-05-11 00:49:34 +03:00
fl2008dc = > [ "ad_dc_ntvfs" ] ,
2019-11-26 15:32:04 +03:00
ad_dc_default = > [ "ad_dc" ] ,
2019-12-16 20:39:04 +03:00
ad_dc_default_smb1 = > [ "ad_dc_smb1" ] ,
2019-12-17 18:39:47 +03:00
ad_dc_default_smb1_done = > [ "ad_dc_default_smb1" ] ,
2019-11-25 15:03:28 +03:00
ad_dc_slowtests = > [ "ad_dc" ] ,
2019-02-26 16:03:29 +03:00
ad_dc_backup = > [ "ad_dc" ] ,
2019-02-26 16:01:10 +03:00
2019-04-12 04:31:29 +03:00
schema_dc = > [ "dns_hub" ] ,
schema_pair_dc = > [ "schema_dc" ] ,
2019-01-17 07:18:48 +03:00
2018-02-21 03:33:49 +03:00
none = > [] ,
) ;
2007-04-11 00:19:31 +04:00
2019-01-17 07:18:48 +03:00
% Samba4:: ENV_DEPS_POST = (
2019-04-12 04:31:29 +03:00
schema_dc = > [ "schema_pair_dc" ] ,
2019-01-17 07:18:48 +03:00
) ;
2019-02-26 16:01:10 +03:00
sub return_alias_env
{
my ( $ self , $ path , $ env ) = @ _ ;
# just an alias
return $ env ;
}
sub setup_fl2008dc
{
2023-05-11 00:49:34 +03:00
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env )
2019-02-26 16:01:10 +03:00
}
2019-02-26 16:03:29 +03:00
sub setup_ad_dc_default
{
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env )
}
2019-12-16 20:39:04 +03:00
sub setup_ad_dc_default_smb1
{
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env )
}
2019-12-17 18:39:47 +03:00
sub setup_ad_dc_default_smb1_done
{
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env )
}
2019-02-26 16:03:29 +03:00
sub setup_ad_dc_slowtests
{
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env )
}
2019-02-26 16:03:29 +03:00
sub setup_ad_dc_backup
{
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env )
}
2018-02-08 06:51:23 +03:00
sub setup_s4member
2007-04-12 12:33:35 +04:00
{
my ( $ self , $ path , $ dc_vars ) = @ _ ;
2016-09-29 18:50:58 +03:00
my $ env = $ self - > provision_s4member ( $ path , $ dc_vars , "s4member" ) ;
2007-04-12 12:33:35 +04:00
2010-11-01 01:00:46 +03:00
if ( defined $ env ) {
2016-02-17 13:58:43 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
2015-12-07 03:18:38 +03:00
return undef ;
}
2010-11-01 01:00:46 +03:00
}
2010-02-19 07:56:30 +03:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_s4member_dflt_domain
2016-09-29 18:50:58 +03:00
{
my ( $ self , $ path , $ dc_vars ) = @ _ ;
my $ env = $ self - > provision_s4member ( $ path , $ dc_vars , "s4member_dflt" ,
"winbind use default domain = yes" ) ;
if ( defined $ env ) {
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
return undef ;
}
}
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_rpc_proxy
2010-02-19 07:56:30 +03:00
{
my ( $ self , $ path , $ dc_vars ) = @ _ ;
my $ env = $ self - > provision_rpc_proxy ( $ path , $ dc_vars ) ;
2010-11-01 01:00:46 +03:00
if ( defined $ env ) {
2016-02-17 13:58:43 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
2015-12-07 03:18:38 +03:00
return undef ;
}
2010-11-01 01:00:46 +03:00
}
2007-04-12 12:33:35 +04:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_ad_dc_ntvfs
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
2019-01-15 06:30:51 +03:00
my $ env = $ self - > provision_ad_dc_ntvfs ( $ path , undef ) ;
2010-11-01 01:00:46 +03:00
if ( defined $ env ) {
2015-12-07 03:18:38 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
warn ( "Failed to start ad_dc_ntvfs" ) ;
return undef ;
}
2010-11-01 01:00:46 +03:00
}
2007-04-04 16:23:10 +04:00
return $ env ;
2007-03-06 00:28:55 +03:00
}
2018-02-08 06:51:23 +03:00
sub setup_chgdcpass
2012-02-29 05:48:21 +04:00
{
my ( $ self , $ path ) = @ _ ;
my $ env = $ self - > provision_chgdcpass ( $ path ) ;
if ( defined $ env ) {
2016-02-17 13:58:43 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
2015-12-07 03:18:38 +03:00
return undef ;
}
2012-02-29 05:48:21 +04:00
}
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_fl2000dc
2010-06-15 16:24:36 +04:00
{
2017-06-09 16:03:29 +03:00
my ( $ self , $ path , $ dc_vars ) = @ _ ;
2010-06-15 16:24:36 +04:00
my $ env = $ self - > provision_fl2000dc ( $ path ) ;
2010-11-01 01:00:46 +03:00
if ( defined $ env ) {
2016-02-17 13:58:43 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
2015-12-07 03:18:38 +03:00
return undef ;
}
2017-06-09 16:03:29 +03:00
$ env = $ self - > setup_trust ( $ env , $ dc_vars , "external" , "--no-aes-keys --direction=outgoing" ) ;
2010-11-01 01:00:46 +03:00
}
2010-06-15 16:24:36 +04:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_fl2003dc
2010-06-21 16:17:40 +04:00
{
2015-02-11 11:58:07 +03:00
my ( $ self , $ path , $ dc_vars ) = @ _ ;
2010-06-21 16:17:40 +04:00
my $ env = $ self - > provision_fl2003dc ( $ path ) ;
2010-11-01 01:00:46 +03:00
if ( defined $ env ) {
2016-02-17 13:58:43 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
2015-12-07 03:18:38 +03:00
return undef ;
}
2010-06-21 16:17:40 +04:00
2015-02-11 11:58:07 +03:00
$ env = $ self - > setup_trust ( $ env , $ dc_vars , "external" , "--no-aes-keys" ) ;
2010-11-01 01:00:46 +03:00
}
2010-06-21 16:17:40 +04:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_fl2008r2dc
2010-06-21 16:17:40 +04:00
{
2024-01-13 10:48:54 +03:00
my ( $ self , $ path , $ ad_dc_vars , $ nt4_dc_vars ) = @ _ ;
2010-06-21 16:17:40 +04:00
my $ env = $ self - > provision_fl2008r2dc ( $ path ) ;
2024-01-11 14:02:43 +03:00
if ( ! defined $ env ) {
return $ env ;
}
2010-06-21 16:17:40 +04:00
2024-01-11 14:02:43 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
return undef ;
}
2015-05-11 14:45:59 +03:00
2024-01-11 14:02:43 +03:00
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2015-05-11 14:45:59 +03:00
2024-01-11 14:02:43 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
2010-11-01 01:00:46 +03:00
}
2010-06-21 16:17:40 +04:00
2024-01-13 10:48:54 +03:00
$ env = $ self - > setup_trust ( $ env , $ ad_dc_vars , "forest" , "" ) ;
if ( ! defined $ env ) {
return undef ;
}
my $ net = Samba:: bindir_path ( $ self , "net" ) ;
my $ smbcontrol = Samba:: bindir_path ( $ self , "smbcontrol" ) ;
my $ trustpw = "TrUsTpW" ;
$ trustpw . = "$env->{SOCKET_WRAPPER_DEFAULT_IFACE}" ;
$ trustpw . = "$nt4_dc_vars->{SOCKET_WRAPPER_DEFAULT_IFACE}" ;
my $ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
$ cmd . = "SELFTEST_WINBINDD_SOCKET_DIR=\"$env->{SELFTEST_WINBINDD_SOCKET_DIR}\" " ;
$ cmd . = "$net rpc trust create " ;
$ cmd . = "otherdomainsid=$nt4_dc_vars->{SAMSID} " ;
$ cmd . = "otherdomain=$nt4_dc_vars->{DOMAIN} " ;
$ cmd . = "other_netbios_domain=$nt4_dc_vars->{DOMAIN} " ;
$ cmd . = "trustpw=$trustpw " ;
$ cmd . = "$env->{CONFIGURATION} " ;
$ cmd . = "-U $env->{DOMAIN}/$env->{USERNAME}\%$env->{PASSWORD} " ;
if ( system ( $ cmd ) != 0 ) {
warn ( "net rpc trust create failed\n$cmd" ) ;
return undef ;
}
$ cmd = "" ;
$ cmd . = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$nt4_dc_vars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" " ;
$ cmd . = "SELFTEST_WINBINDD_SOCKET_DIR=\"$nt4_dc_vars->{SELFTEST_WINBINDD_SOCKET_DIR}\" " ;
$ cmd . = "$net rpc trustdom establish $env->{DOMAIN} -U/%$trustpw $nt4_dc_vars->{CONFIGURATION}" ;
if ( system ( $ cmd ) != 0 ) {
warn ( "add failed\n$cmd" ) ;
return undef ;
}
# Reload trusts
$ cmd = "$smbcontrol winbindd reload-config $nt4_dc_vars->{CONFIGURATION}" ;
if ( system ( $ cmd ) != 0 ) {
warn ( "add failed\n$cmd" ) ;
return undef ;
}
$ env - > { NT4_TRUST_SERVER } = $ nt4_dc_vars - > { SERVER } ;
$ env - > { NT4_TRUST_SERVER_IP } = $ nt4_dc_vars - > { SERVER_IP } ;
$ env - > { NT4_TRUST_DOMAIN } = $ nt4_dc_vars - > { DOMAIN } ;
$ env - > { NT4_TRUST_DOMSID } = $ nt4_dc_vars - > { DOMSID } ;
return $ env ;
2010-06-21 16:17:40 +04:00
}
2018-02-08 06:51:23 +03:00
sub setup_vampire_dc
2018-02-21 03:33:49 +03:00
{
return setup_generic_vampire_dc ( @ _ , "2008" ) ;
}
sub setup_vampire_2000_dc
{
return setup_generic_vampire_dc ( @ _ , "2000" ) ;
}
sub setup_generic_vampire_dc
2010-03-12 02:36:12 +03:00
{
2017-02-07 23:16:41 +03:00
my ( $ self , $ path , $ dc_vars , $ fl ) = @ _ ;
2010-03-12 02:36:12 +03:00
2017-02-07 23:16:41 +03:00
my $ env = $ self - > provision_vampire_dc ( $ path , $ dc_vars , $ fl ) ;
2010-03-12 02:36:12 +03:00
2010-11-01 01:00:46 +03:00
if ( defined $ env ) {
2015-12-07 03:18:38 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "single" ) ) ) {
return undef ;
}
2010-11-01 01:00:46 +03:00
# force replicated DC to update repsTo/repsFrom
# for vampired partitions
2011-04-27 05:19:20 +04:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2010-08-28 02:30:09 +04:00
2010-11-01 01:00:46 +03:00
# as 'vampired' dc may add data in its local replica
# we need to synchronize data between DCs
my $ base_dn = "DC=" . join ( ",DC=" , split ( /\./ , $ dc_vars - > { REALM } ) ) ;
2019-01-30 06:31:40 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ env ) ;
2012-07-06 09:39:09 +04:00
$ cmd . = " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}" ;
$ cmd . = " $dc_vars->{CONFIGURATION}" ;
$ cmd . = " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}" ;
# replicate Configuration NC
my $ cmd_repl = "$cmd \"CN=Configuration,$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
# replicate Default NC
$ cmd_repl = "$cmd \"$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
2016-11-30 07:09:44 +03:00
# Pull in a full set of changes from the main DC
2019-12-07 12:38:30 +03:00
$ base_dn = "DC=" . join ( ",DC=" , split ( /\./ , $ dc_vars - > { REALM } ) ) ;
2019-01-30 06:31:40 +03:00
$ cmd = $ self - > get_cmd_env_vars ( $ env ) ;
2016-11-30 07:09:44 +03:00
$ cmd . = " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}" ;
$ cmd . = " $dc_vars->{CONFIGURATION}" ;
$ cmd . = " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}" ;
# replicate Configuration NC
2019-12-07 12:38:30 +03:00
$ cmd_repl = "$cmd \"CN=Configuration,$base_dn\"" ;
2016-11-30 07:09:44 +03:00
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
# replicate Default NC
$ cmd_repl = "$cmd \"$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
2012-07-06 09:39:09 +04:00
}
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_promoted_dc
2012-07-06 09:39:09 +04:00
{
my ( $ self , $ path , $ dc_vars ) = @ _ ;
2013-01-27 15:15:50 +04:00
my $ env = $ self - > provision_promoted_dc ( $ path , $ dc_vars ) ;
2012-07-06 09:39:09 +04:00
if ( defined $ env ) {
2015-12-07 03:18:38 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "single" ) ) ) {
return undef ;
}
2012-07-06 09:39:09 +04:00
2015-02-20 07:56:39 +03:00
# force source and replicated DC to update repsTo/repsFrom
2012-07-06 09:39:09 +04:00
# for vampired partitions
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2020-11-23 13:35:33 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ env ) ;
2012-07-06 09:39:09 +04:00
# as 'vampired' dc may add data in its local replica
# we need to synchronize data between DCs
my $ base_dn = "DC=" . join ( ",DC=" , split ( /\./ , $ dc_vars - > { REALM } ) ) ;
$ cmd . = " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}" ;
2011-08-09 14:20:54 +04:00
$ cmd . = " $dc_vars->{CONFIGURATION}" ;
2010-11-01 01:00:46 +03:00
$ cmd . = " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}" ;
# replicate Configuration NC
my $ cmd_repl = "$cmd \"CN=Configuration,$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
# replicate Default NC
$ cmd_repl = "$cmd \"$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
2010-09-14 16:41:42 +04:00
}
2010-08-28 02:30:09 +04:00
2010-03-12 02:36:12 +03:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_rodc
2010-09-09 12:02:31 +04:00
{
my ( $ self , $ path , $ dc_vars ) = @ _ ;
my $ env = $ self - > provision_rodc ( $ path , $ dc_vars ) ;
2010-09-14 16:41:42 +04:00
unless ( $ env ) {
return undef ;
}
2017-03-15 06:40:16 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
2015-12-07 03:18:38 +03:00
return undef ;
}
2010-09-09 12:02:31 +04:00
2015-02-20 07:56:39 +03:00
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2020-11-23 13:35:33 +03:00
my $ cmd = $ self - > get_cmd_env_vars ( $ env ) ;
2015-02-20 07:56:39 +03:00
my $ base_dn = "DC=" . join ( ",DC=" , split ( /\./ , $ dc_vars - > { REALM } ) ) ;
$ cmd . = " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}" ;
$ cmd . = " $dc_vars->{CONFIGURATION}" ;
$ cmd . = " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}" ;
# replicate Configuration NC
my $ cmd_repl = "$cmd \"CN=Configuration,$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
# replicate Default NC
$ cmd_repl = "$cmd \"$base_dn\"" ;
unless ( system ( $ cmd_repl ) == 0 ) {
warn ( "Failed to replicate\n$cmd_repl" ) ;
return undef ;
}
2010-09-09 12:02:31 +04:00
return $ env ;
}
2020-07-03 23:23:20 +03:00
sub _setup_ad_dc
2011-05-08 08:55:33 +04:00
{
2023-05-11 01:38:20 +03:00
my ( $ self , $ path , $ conf_opts , $ server , $ dom , $ functional_level ) = @ _ ;
2011-05-08 08:55:33 +04:00
2012-02-16 08:12:49 +04:00
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2019-12-04 18:27:04 +03:00
if ( ! defined ( $ conf_opts ) ) {
$ conf_opts = "" ;
}
if ( ! defined ( $ server ) ) {
$ server = "addc" ;
}
if ( ! defined ( $ dom ) ) {
$ dom = "addom.samba.example.com" ;
}
my $ env = $ self - > provision_ad_dc ( $ path , $ server , "ADDOMAIN" ,
$ dom ,
2020-03-13 16:26:33 +03:00
undef ,
2019-12-04 18:27:04 +03:00
$ conf_opts ,
2023-05-11 01:38:20 +03:00
undef ,
$ functional_level ) ;
2012-02-15 09:08:05 +04:00
unless ( $ env ) {
return undef ;
}
2011-05-08 08:55:33 +04:00
2018-08-28 06:26:03 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "prefork" ) ) ) {
2017-08-01 08:18:45 +03:00
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2017-08-01 08:18:45 +03:00
return $ env ;
}
2020-07-03 23:23:20 +03:00
sub setup_ad_dc
{
my ( $ self , $ path ) = @ _ ;
return _setup_ad_dc ( $ self , $ path , undef , undef , undef ) ;
}
2019-12-04 18:27:04 +03:00
sub setup_ad_dc_smb1
{
my ( $ self , $ path ) = @ _ ;
my $ conf_opts = "
[ global ]
client min protocol = CORE
server min protocol = LANMAN1
2022-11-30 14:26:01 +03:00
# needed for 'samba.tests.auth_log' tests
server require schannel : ADDCSMB1 \ $ = no
2022-11-25 16:05:30 +03:00
server schannel require seal : ADDCSMB1 \ $ = no
2019-12-04 18:27:04 +03:00
" ;
2020-07-03 23:23:20 +03:00
return _setup_ad_dc ( $ self , $ path , $ conf_opts , "addcsmb1" , "addom2.samba.example.com" ) ;
2019-12-04 18:27:04 +03:00
}
2019-12-17 18:31:27 +03:00
sub setup_ad_dc_smb1_done
{
my ( $ self , $ path , $ dep_env ) = @ _ ;
return $ self - > return_alias_env ( $ path , $ dep_env ) ;
}
2018-02-08 06:51:23 +03:00
sub setup_ad_dc_no_nss
2017-08-01 08:18:45 +03:00
{
my ( $ self , $ path ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2020-03-13 16:26:33 +03:00
my $ env = $ self - > provision_ad_dc ( $ path ,
"addc_no_nss" ,
"ADNONSSDOMAIN" ,
"adnonssdom.samba.example.com" ,
undef ,
"" ,
undef ) ;
2017-08-01 08:18:45 +03:00
unless ( $ env ) {
return undef ;
2015-03-05 15:22:07 +03:00
}
2017-08-01 08:18:45 +03:00
$ env - > { NSS_WRAPPER_MODULE_SO_PATH } = undef ;
$ env - > { NSS_WRAPPER_MODULE_FN_PREFIX } = undef ;
2015-12-07 03:18:38 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "single" ) ) ) {
return undef ;
}
2015-05-11 14:45:59 +03:00
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2015-05-11 14:45:59 +03:00
2011-05-08 08:55:33 +04:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_ad_dc_no_ntlm
2017-07-05 05:03:17 +03:00
{
my ( $ self , $ path ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2020-03-13 16:26:33 +03:00
my $ env = $ self - > provision_ad_dc ( $ path ,
"addc_no_ntlm" ,
"ADNONTLMDOMAIN" ,
2017-07-05 05:03:17 +03:00
"adnontlmdom.samba.example.com" ,
2020-03-13 16:26:33 +03:00
undef ,
2022-01-31 04:08:13 +03:00
"ntlm auth = disabled\nnt hash store = never" ,
2020-03-13 16:26:33 +03:00
undef ) ;
2017-07-05 05:03:17 +03:00
unless ( $ env ) {
return undef ;
}
2018-09-17 23:37:02 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "prefork" ) ) ) {
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2018-09-17 23:37:02 +03:00
return $ env ;
}
2020-03-13 14:39:54 +03:00
sub setup_ad_dc_fips
{
my ( $ self , $ path ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
my $ env = $ self - > provision_ad_dc ( $ path ,
"fipsdc" ,
"FIPSDOMAIN" ,
"fips.samba.example.com" ,
2020-03-13 16:26:33 +03:00
1 ,
2020-03-13 14:39:54 +03:00
"" ,
undef ) ;
unless ( $ env ) {
return undef ;
}
if ( not defined ( $ self - > check_or_start ( $ env , "prefork" ) ) ) {
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2020-03-13 14:39:54 +03:00
return $ env ;
}
2018-09-17 23:37:02 +03:00
#
# AD DC test environment used solely to test pre-fork process restarts.
# As processes get killed off and restarted it should not be used for other
sub setup_preforkrestartdc
{
my ( $ self , $ path ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
# note DC name must be <= 15 chars so we use 'prockill' instead of
# 'preforkrestart'
2020-03-13 16:26:33 +03:00
my $ env = $ self - > provision_ad_dc ( $ path ,
"prockilldc" ,
"PROCKILLDOMAIN" ,
"prockilldom.samba.example.com" ,
undef ,
"prefork backoff increment = 5\nprefork maximum backoff=10" ,
undef ) ;
2018-09-17 23:37:02 +03:00
unless ( $ env ) {
return undef ;
}
2021-02-11 12:19:31 +03:00
# We treat processes in this environment cruelly, sometimes
# sending them SIGSEGV signals. We don't need gdb_backtrace
# dissecting these fake crashes in precise detail.
$ env - > { PLEASE_NO_GDB_BACKTRACE } = '1' ;
2018-09-17 23:37:02 +03:00
$ env - > { NSS_WRAPPER_MODULE_SO_PATH } = undef ;
$ env - > { NSS_WRAPPER_MODULE_FN_PREFIX } = undef ;
2017-09-05 03:31:52 +03:00
if ( not defined ( $ self - > check_or_start ( $ env , "prefork" ) ) ) {
2017-07-05 05:03:17 +03:00
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2017-07-05 05:03:17 +03:00
return $ env ;
}
2018-09-18 02:21:40 +03:00
#
# ad_dc test environment used solely to test standard process model connection
# process limits. As the limit is set artificially low it should not be used
# for other tests.
sub setup_proclimitdc
{
my ( $ self , $ path ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2020-03-13 16:26:33 +03:00
my $ env = $ self - > provision_ad_dc ( $ path ,
"proclimitdc" ,
"PROCLIMITDOM" ,
"proclimit.samba.example.com" ,
undef ,
"max smbd processes = 20" ,
undef ) ;
2018-09-18 02:21:40 +03:00
unless ( $ env ) {
return undef ;
}
$ env - > { NSS_WRAPPER_MODULE_SO_PATH } = undef ;
$ env - > { NSS_WRAPPER_MODULE_FN_PREFIX } = undef ;
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2018-09-18 02:21:40 +03:00
return $ env ;
}
2019-01-17 07:18:48 +03:00
# Used to test a live upgrade of the schema on a 2 DC network.
2019-04-12 04:31:29 +03:00
sub setup_schema_dc
2019-01-17 07:18:48 +03:00
{
my ( $ self , $ path ) = @ _ ;
# provision the PDC using an older base schema
2022-11-22 12:31:19 +03:00
my $ provision_args = [ "--base-schema=2008_R2" , "--backend-store=$self->{default_ldb_backend}" ] ;
2019-01-17 07:18:48 +03:00
2023-05-11 05:25:31 +03:00
# We set the functional level to 2008_R2 to match the older
# base-schema (to allow schema upgrade to be tested)
2020-03-13 16:26:33 +03:00
my $ env = $ self - > provision_ad_dc ( $ path ,
"liveupgrade1dc" ,
"SCHEMADOMAIN" ,
2019-01-17 07:18:48 +03:00
"schema.samba.example.com" ,
2020-03-13 16:26:33 +03:00
undef ,
2019-01-17 07:18:48 +03:00
"drs: max link sync = 2" ,
2023-05-11 05:25:31 +03:00
$ provision_args ,
"2008_R2" ) ;
2019-01-17 07:18:48 +03:00
unless ( $ env ) {
return undef ;
}
if ( not defined ( $ self - > check_or_start ( $ env , "prefork" ) ) ) {
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2019-01-17 07:18:48 +03:00
return $ env ;
}
# the second DC in the live schema upgrade pair
2019-04-12 04:31:29 +03:00
sub setup_schema_pair_dc
2019-01-17 07:18:48 +03:00
{
2019-04-12 04:31:29 +03:00
# note: dcvars contains the env info for the dependent testenv ('schema_dc')
2019-01-17 07:18:48 +03:00
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "Preparing SCHEMA UPGRADE PAIR DC...\n" ;
my ( $ env , $ ctx ) = $ self - > prepare_dc_testenv ( $ prefix , "liveupgrade2dc" ,
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
$ dcvars - > { PASSWORD } ,
"" ) ;
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2020-11-23 13:35:33 +03:00
my $ cmd_vars = $ self - > get_cmd_env_vars ( $ env ) ;
2019-01-17 07:18:48 +03:00
my $ join_cmd = $ cmd_vars ;
$ join_cmd . = "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}" ;
$ join_cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} " ;
2022-11-22 12:31:19 +03:00
$ join_cmd . = " --backend-store=$self->{default_ldb_backend}" ;
2019-01-17 07:18:48 +03:00
my $ upgrade_cmd = $ cmd_vars ;
$ upgrade_cmd . = "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}" ;
$ upgrade_cmd . = " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}" ;
my $ repl_cmd = $ cmd_vars ;
$ repl_cmd . = "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}" ;
$ repl_cmd . = " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com" ;
$ repl_cmd . = " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
unless ( system ( $ join_cmd ) == 0 ) {
warn ( "Join failed\n$join_cmd" ) ;
return undef ;
}
$ env - > { DC_SERVER } = $ dcvars - > { SERVER } ;
$ env - > { DC_SERVER_IP } = $ dcvars - > { SERVER_IP } ;
$ env - > { DC_SERVER_IPV6 } = $ dcvars - > { SERVER_IPV6 } ;
$ env - > { DC_NETBIOSNAME } = $ dcvars - > { NETBIOSNAME } ;
# start samba for the new DC
if ( not defined ( $ self - > check_or_start ( $ env , "standard" ) ) ) {
return undef ;
}
unless ( system ( $ upgrade_cmd ) == 0 ) {
warn ( "Schema upgrade failed\n$upgrade_cmd" ) ;
return undef ;
}
unless ( system ( $ repl_cmd ) == 0 ) {
warn ( "Post-update schema replication failed\n$repl_cmd" ) ;
return undef ;
}
return $ env ;
}
2018-05-29 07:05:02 +03:00
# Sets up a DC that's solely used to do a domain backup from. We then use the
# backupfrom-DC to create the restore-DC - this proves that the backup/restore
# process will create a Samba DC that will actually start up.
# We don't use the backup-DC for anything else because its domain will conflict
# with the restore DC.
sub setup_backupfromdc
{
my ( $ self , $ path ) = @ _ ;
# If we didn't build with ADS, pretend this env was never available
if ( not $ self - > { target3 } - > have_ads ( ) ) {
return "UNKNOWN" ;
}
2018-09-18 07:30:15 +03:00
my $ provision_args = [ "--site=Backup-Site" ] ;
2020-03-13 16:26:33 +03:00
my $ env = $ self - > provision_ad_dc ( $ path ,
"backupfromdc" ,
"BACKUPDOMAIN" ,
2018-12-05 05:14:46 +03:00
"backupdom.samba.example.com" ,
2020-03-13 16:26:33 +03:00
undef ,
2018-12-05 05:14:46 +03:00
"samba kcc command = /bin/true" ,
2018-09-18 07:30:15 +03:00
$ provision_args ) ;
2018-05-29 07:05:02 +03:00
unless ( $ env ) {
return undef ;
}
2019-01-31 02:45:31 +03:00
if ( not defined ( $ self - > check_or_start ( $ env ) ) ) {
2018-05-29 07:05:02 +03:00
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2018-05-29 07:05:02 +03:00
2020-07-27 02:37:29 +03:00
# Set up a dangling forward link to an expunged object
#
# We need this to ensure that the "samba-tool domain backup rename"
# that is part of the creation of the labdc environment can
# cope with this situation on the source DC.
if ( not $ self - > write_ldb_file ( "$env->{PRIVATEDIR}/sam.ldb" , "
dn: ou = linktest , dc = backupdom , dc = samba , dc = example , dc = com
objectclass: organizationalUnit
-
dn: cn = linkto , ou = linktest , dc = backupdom , dc = samba , dc = example , dc = com
objectclass: msExchConfigurationContainer
-
dn: cn = linkfrom , ou = linktest , dc = backupdom , dc = samba , dc = example , dc = com
objectclass: msExchConfigurationContainer
addressBookRoots: cn = linkto , ou = linktest , dc = backupdom , dc = samba , dc = example , dc = com
-
" ) ) {
return undef ;
}
my $ ldbdel = Samba:: bindir_path ( $ self , "ldbdel" ) ;
my $ cmd = "$ldbdel -H $env->{PRIVATEDIR}/sam.ldb cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com" ;
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to delete link target: \n$cmd" ) ;
return undef ;
}
# Expunge will ensure that linkto is totally wiped from the DB
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
$ cmd = "$samba_tool domain tombstones expunge --tombstone-lifetime=0 $env->{CONFIGURATION}" ;
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to expunge link target: \n$cmd" ) ;
return undef ;
}
2018-05-29 07:05:02 +03:00
return $ env ;
}
2018-07-23 06:20:03 +03:00
# returns the server/user-auth params needed to run an online backup cmd
sub get_backup_server_args
{
# dcvars contains the env info for the backup DC testenv
my ( $ self , $ dcvars ) = @ _ ;
my $ server = $ dcvars - > { DC_SERVER_IP } ;
my $ server_args = "--server=$server " ;
$ server_args . = "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}" ;
selftest: Fix backup testenv creation on certain host machines
When we created the backup-file for the restoredc/renamedc/labdc
testenvs we weren't explicitly a --configfile on the samba-tool command.
This meant the command tried to use the smb.conf form the default
install location, i.e. /usr/local/samba/etc/smb.conf. On the gitlab CI
runner, there's no samba installed, so it ends up using the default
settings, which is fine. However, if the host machine had an invalid
smb.conf installed there, creating the testenv would fail with an error
like:
ERROR(runtime): uncaught exception - Unable to load default file
File "bin/python/samba/netcmd/__init__.py", line 184, in _run
return self.run(*args, **kwargs)
File "bin/python/samba/netcmd/domain_backup.py", line 222, in run
lp = sambaopts.get_loadparm()
File "bin/python/samba/getopt.py", line 94, in get_loadparm
self._lp.load_default()
We can avoid this by always explictly specifying the backupfromdc's
smb.conf when creating the backup file.
Likewise, labdc/customdc also need the config specified when the admin
password is reset.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2018-11-09 01:49:12 +03:00
$ server_args . = " $dcvars->{CONFIGURATION}" ;
2018-07-23 06:20:03 +03:00
return $ server_args ;
}
2018-05-29 07:05:02 +03:00
# Creates a backup of a running testenv DC
sub create_backup
{
# note: dcvars contains the env info for the backup DC testenv
my ( $ self , $ env , $ dcvars , $ backupdir , $ backup_cmd ) = @ _ ;
# get all the env variables we pass in with the samba-tool command
# Note: use the backupfrom-DC's krb5.conf to do the backup
2020-11-23 13:35:33 +03:00
my $ overwrite = undef ;
$ overwrite - > { KRB5_CONFIG } = $ dcvars - > { KRB5_CONFIG } ;
my $ cmd_env = $ self - > get_cmd_env_vars ( $ env , $ overwrite ) ;
2018-05-29 07:05:02 +03:00
# use samba-tool to create a backup from the 'backupfromdc' DC
my $ cmd = "" ;
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
2018-07-23 06:20:03 +03:00
$ cmd . = "$cmd_env $samba_tool domain backup $backup_cmd" ;
$ cmd . = " --targetdir=$backupdir" ;
2018-05-29 07:05:02 +03:00
print "Executing: $cmd\n" ;
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to create backup using: \n$cmd" ) ;
return undef ;
}
# get the name of the backup file created
opendir ( DIR , $ backupdir ) ;
my @ files = grep ( /\.tar/ , readdir ( DIR ) ) ;
closedir ( DIR ) ;
if ( scalar @ files != 1 ) {
warn ( "Backup file not found in directory $backupdir\n" ) ;
return undef ;
}
my $ backup_file = "$backupdir/$files[0]" ;
print "Using backup file $backup_file...\n" ;
return $ backup_file ;
}
# Restores a backup-file to populate a testenv for a new DC
sub restore_backup_file
{
my ( $ self , $ backup_file , $ restore_opts , $ restoredir , $ smbconf ) = @ _ ;
# pass the restore command the testenv's smb.conf that we've already
# generated. But move it to a temp-dir first, so that the restore doesn't
# overwrite it
my $ tmpdir = File::Temp - > newdir ( ) ;
my $ tmpconf = "$tmpdir/smb.conf" ;
my $ cmd = "cp $smbconf $tmpconf" ;
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to backup smb.conf using: \n$cmd" ) ;
return - 1 ;
}
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
$ cmd = "$samba_tool domain backup restore --backup-file=$backup_file" ;
$ cmd . = " --targetdir=$restoredir $restore_opts --configfile=$tmpconf" ;
print "Executing: $cmd\n" ;
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to restore backup using: \n$cmd" ) ;
return - 1 ;
}
print "Restore complete\n" ;
return 0
}
# sets up the initial directory and returns the new testenv's env info
# (without actually doing a 'domain join')
sub prepare_dc_testenv
{
2018-11-22 03:22:19 +03:00
my ( $ self , $ prefix , $ dcname , $ domain , $ realm ,
2019-10-31 17:39:53 +03:00
$ password , $ conf_options , $ dnsupdate_options ) = @ _ ;
2018-05-29 07:05:02 +03:00
my $ ctx = $ self - > provision_raw_prepare ( $ prefix , "domain controller" ,
$ dcname ,
$ domain ,
$ realm ,
undef ,
"2008" ,
$ password ,
undef ,
undef ) ;
# the restore uses a slightly different state-dir location to other testenvs
$ ctx - > { statedir } = "$ctx->{prefix_abs}/state" ;
push ( @ { $ ctx - > { directories } } , "$ctx->{statedir}" ) ;
# add support for sysvol/netlogon/tmp shares
$ ctx - > { share } = "$ctx->{prefix_abs}/share" ;
push ( @ { $ ctx - > { directories } } , "$ctx->{share}" ) ;
2018-12-13 06:29:33 +03:00
push ( @ { $ ctx - > { directories } } , "$ctx->{share}/test1" ) ;
2018-05-29 07:05:02 +03:00
2019-10-31 17:39:53 +03:00
if ( defined ( $ dnsupdate_options ) ) {
$ ctx - > { samba_dnsupdate } . = $ dnsupdate_options ;
}
2018-05-29 07:05:02 +03:00
$ ctx - > { smb_conf_extra_options } = "
2018-11-22 03:22:19 +03:00
$ conf_options
2023-06-13 04:33:10 +03:00
# Some of the DCs based on this will be in FL 2016 domains, so
# claim FL 2016 DC capability
ad dc functional level = 2016
2018-05-29 07:05:02 +03:00
max xmit = 32 K
server max protocol = SMB2
2018-12-05 05:14:46 +03:00
samba kcc command = /bin/ true
2018-12-13 06:29:33 +03:00
xattr_tdb:file = $ ctx - > { statedir } / xattr . tdb
2018-05-29 07:05:02 +03:00
[ sysvol ]
path = $ ctx - > { statedir } / sysvol
read only = no
[ netlogon ]
path = $ ctx - > { statedir } /sysvol/ $ ctx - > { dnsname } / scripts
read only = no
[ tmp ]
path = $ ctx - > { share }
read only = no
posix:sharedelay = 10000
posix:oplocktimeout = 3
posix:writetimeupdatedelay = 50000
2018-12-13 06:29:33 +03:00
[ test1 ]
path = $ ctx - > { share } / test1
read only = no
posix:sharedelay = 100000
posix:oplocktimeout = 3
posix:writetimeupdatedelay = 500000
2018-05-29 07:05:02 +03:00
" ;
my $ env = $ self - > provision_raw_step1 ( $ ctx ) ;
2018-07-23 06:20:03 +03:00
return ( $ env , $ ctx ) ;
2018-05-29 07:05:02 +03:00
}
# Set up a DC testenv solely by using the samba-tool domain backup/restore
# commands. This proves that we can backup an online DC ('backupfromdc') and
# use the backup file to create a valid, working samba DC.
sub setup_restoredc
{
# note: dcvars contains the env info for the dependent testenv ('backupfromdc')
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "Preparing RESTORE DC...\n" ;
2018-11-22 03:22:19 +03:00
# we arbitrarily designate the restored DC as having SMBv1 disabled
my $ extra_conf = "
server min protocol = SMB2
2019-02-05 02:23:43 +03:00
client min protocol = SMB2
prefork children = 1 " ;
2019-10-31 17:39:53 +03:00
my $ dnsupdate_options = " --use-samba-tool --no-credentials" ;
2018-11-22 03:22:19 +03:00
2018-07-23 06:20:03 +03:00
my ( $ env , $ ctx ) = $ self - > prepare_dc_testenv ( $ prefix , "restoredc" ,
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2018-11-22 03:22:19 +03:00
$ dcvars - > { PASSWORD } ,
2019-10-31 17:39:53 +03:00
$ extra_conf ,
$ dnsupdate_options ) ;
2018-05-29 07:05:02 +03:00
# create a backup of the 'backupfromdc'
my $ backupdir = File::Temp - > newdir ( ) ;
2018-07-23 06:20:03 +03:00
my $ server_args = $ self - > get_backup_server_args ( $ dcvars ) ;
my $ backup_args = "online $server_args" ;
my $ backup_file = $ self - > create_backup ( $ env , $ dcvars , $ backupdir ,
$ backup_args ) ;
2018-05-29 07:05:02 +03:00
unless ( $ backup_file ) {
return undef ;
}
# restore the backup file to populate the restore-DC testenv
my $ restore_dir = abs_path ( $ prefix ) ;
my $ ret = $ self - > restore_backup_file ( $ backup_file ,
"--newservername=$env->{SERVER}" ,
$ restore_dir , $ env - > { SERVERCONFFILE } ) ;
unless ( $ ret == 0 ) {
return undef ;
}
2019-10-31 17:39:53 +03:00
#
2023-09-07 07:04:41 +03:00
# As we create the same domain as a clone
2019-10-31 17:39:53 +03:00
# we need a separate resolv.conf!
#
$ ctx - > { resolv_conf } = "$ctx->{etcdir}/resolv.conf" ;
$ ctx - > { dns_ipv4 } = $ ctx - > { ipv4 } ;
$ ctx - > { dns_ipv6 } = $ ctx - > { ipv6 } ;
Samba:: mk_resolv_conf ( $ ctx ) ;
$ env - > { RESOLV_CONF } = $ ctx - > { resolv_conf } ;
2018-05-29 07:05:02 +03:00
# start samba for the restored DC
2019-01-31 02:45:31 +03:00
if ( not defined ( $ self - > check_or_start ( $ env ) ) ) {
2018-05-29 07:05:02 +03:00
return undef ;
}
return $ env ;
}
2018-06-11 02:02:11 +03:00
# Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
# restore commands. This proves that we can backup and rename an online DC
# ('backupfromdc') and use the backup file to create a valid, working samba DC.
sub setup_renamedc
{
# note: dcvars contains the env info for the dependent testenv ('backupfromdc')
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "Preparing RENAME DC...\n" ;
2019-02-05 02:23:43 +03:00
my $ extra_conf = "prefork children = 1" ;
2018-06-11 02:02:11 +03:00
2018-07-23 06:20:03 +03:00
my $ realm = "renamedom.samba.example.com" ;
my ( $ env , $ ctx ) = $ self - > prepare_dc_testenv ( $ prefix , "renamedc" ,
"RENAMEDOMAIN" , $ realm ,
2019-02-05 02:23:43 +03:00
$ dcvars - > { PASSWORD } , $ extra_conf ) ;
2018-06-11 02:02:11 +03:00
# create a backup of the 'backupfromdc' which renames the domain
my $ backupdir = File::Temp - > newdir ( ) ;
2018-07-23 06:20:03 +03:00
my $ server_args = $ self - > get_backup_server_args ( $ dcvars ) ;
my $ backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args" ;
2018-10-26 03:21:48 +03:00
$ backup_args . = " --backend-store=tdb" ;
2018-06-11 02:02:11 +03:00
my $ backup_file = $ self - > create_backup ( $ env , $ dcvars , $ backupdir ,
$ backup_args ) ;
unless ( $ backup_file ) {
return undef ;
}
# restore the backup file to populate the rename-DC testenv
my $ restore_dir = abs_path ( $ prefix ) ;
my $ restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}" ;
my $ ret = $ self - > restore_backup_file ( $ backup_file , $ restore_opts ,
$ restore_dir , $ env - > { SERVERCONFFILE } ) ;
unless ( $ ret == 0 ) {
return undef ;
}
# start samba for the restored DC
2019-01-31 02:45:31 +03:00
if ( not defined ( $ self - > check_or_start ( $ env ) ) ) {
2018-06-11 02:02:11 +03:00
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2018-06-11 02:02:11 +03:00
return $ env ;
}
2018-07-23 06:20:03 +03:00
# Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
# restore commands. This proves that we do an offline backup of a local DC
# ('backupfromdc') and use the backup file to create a valid, working samba DC.
sub setup_offlinebackupdc
{
# note: dcvars contains the env info for the dependent testenv ('backupfromdc')
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "Preparing OFFLINE BACKUP DC...\n" ;
2019-02-05 02:23:43 +03:00
my $ extra_conf = "prefork children = 1" ;
2019-10-31 17:39:53 +03:00
my $ dnsupdate_options = " --use-samba-tool --no-credentials" ;
2018-07-23 06:20:03 +03:00
my ( $ env , $ ctx ) = $ self - > prepare_dc_testenv ( $ prefix , "offlinebackupdc" ,
$ dcvars - > { DOMAIN } ,
$ dcvars - > { REALM } ,
2019-10-31 17:39:53 +03:00
$ dcvars - > { PASSWORD } ,
$ extra_conf ,
$ dnsupdate_options ) ;
2018-07-23 06:20:03 +03:00
# create an offline backup of the 'backupfromdc' target
my $ backupdir = File::Temp - > newdir ( ) ;
2021-04-14 12:44:51 +03:00
my $ cmd = "offline --configfile $dcvars->{SERVERCONFFILE}" ;
2018-07-23 06:20:03 +03:00
my $ backup_file = $ self - > create_backup ( $ env , $ dcvars ,
$ backupdir , $ cmd ) ;
unless ( $ backup_file ) {
return undef ;
}
# restore the backup file to populate the rename-DC testenv
my $ restore_dir = abs_path ( $ prefix ) ;
my $ restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}" ;
my $ ret = $ self - > restore_backup_file ( $ backup_file , $ restore_opts ,
$ restore_dir , $ env - > { SERVERCONFFILE } ) ;
unless ( $ ret == 0 ) {
return undef ;
}
2019-10-31 17:39:53 +03:00
#
2023-09-07 07:04:41 +03:00
# As we create the same domain as a clone
2019-10-31 17:39:53 +03:00
# we need a separate resolv.conf!
#
$ ctx - > { resolv_conf } = "$ctx->{etcdir}/resolv.conf" ;
$ ctx - > { dns_ipv4 } = $ ctx - > { ipv4 } ;
$ ctx - > { dns_ipv6 } = $ ctx - > { ipv6 } ;
Samba:: mk_resolv_conf ( $ ctx ) ;
$ env - > { RESOLV_CONF } = $ ctx - > { resolv_conf } ;
2018-07-23 06:20:03 +03:00
# re-create the testenv's krb5.conf (the restore may have overwritten it)
Samba:: mk_krb5_conf ( $ ctx ) ;
# start samba for the restored DC
2019-01-31 02:45:31 +03:00
if ( not defined ( $ self - > check_or_start ( $ env ) ) ) {
2018-07-23 06:20:03 +03:00
return undef ;
}
return $ env ;
}
2018-07-06 06:59:31 +03:00
# Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
# restore commands, using the --no-secrets option. This proves that we can
# create a realistic lab environment from an online DC ('backupfromdc').
sub setup_labdc
{
# note: dcvars contains the env info for the dependent testenv ('backupfromdc')
my ( $ self , $ prefix , $ dcvars ) = @ _ ;
print "Preparing LAB-DOMAIN DC...\n" ;
2019-02-05 02:23:43 +03:00
my $ extra_conf = "prefork children = 1" ;
2018-07-06 06:59:31 +03:00
2018-07-23 06:20:03 +03:00
my ( $ env , $ ctx ) = $ self - > prepare_dc_testenv ( $ prefix , "labdc" ,
"LABDOMAIN" ,
"labdom.samba.example.com" ,
2019-02-05 02:23:43 +03:00
$ dcvars - > { PASSWORD } , $ extra_conf ) ;
2018-07-06 06:59:31 +03:00
# create a backup of the 'backupfromdc' which renames the domain and uses
# the --no-secrets option to scrub any sensitive info
my $ backupdir = File::Temp - > newdir ( ) ;
2018-07-23 06:20:03 +03:00
my $ server_args = $ self - > get_backup_server_args ( $ dcvars ) ;
my $ backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args" ;
2022-11-22 12:31:19 +03:00
$ backup_args . = " --no-secrets --backend-store=$self->{default_ldb_backend}" ;
2018-07-06 06:59:31 +03:00
my $ backup_file = $ self - > create_backup ( $ env , $ dcvars , $ backupdir ,
$ backup_args ) ;
unless ( $ backup_file ) {
return undef ;
}
# restore the backup file to populate the lab-DC testenv
my $ restore_dir = abs_path ( $ prefix ) ;
my $ restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}" ;
my $ ret = $ self - > restore_backup_file ( $ backup_file , $ restore_opts ,
$ restore_dir , $ env - > { SERVERCONFFILE } ) ;
unless ( $ ret == 0 ) {
return undef ;
}
# because we don't include any secrets in the backup, we need to reset the
# admin user's password back to what the testenv expects
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
my $ cmd = "$samba_tool user setpassword $env->{USERNAME} " ;
$ cmd . = "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb" ;
selftest: Fix backup testenv creation on certain host machines
When we created the backup-file for the restoredc/renamedc/labdc
testenvs we weren't explicitly a --configfile on the samba-tool command.
This meant the command tried to use the smb.conf form the default
install location, i.e. /usr/local/samba/etc/smb.conf. On the gitlab CI
runner, there's no samba installed, so it ends up using the default
settings, which is fine. However, if the host machine had an invalid
smb.conf installed there, creating the testenv would fail with an error
like:
ERROR(runtime): uncaught exception - Unable to load default file
File "bin/python/samba/netcmd/__init__.py", line 184, in _run
return self.run(*args, **kwargs)
File "bin/python/samba/netcmd/domain_backup.py", line 222, in run
lp = sambaopts.get_loadparm()
File "bin/python/samba/getopt.py", line 94, in get_loadparm
self._lp.load_default()
We can avoid this by always explictly specifying the backupfromdc's
smb.conf when creating the backup file.
Likewise, labdc/customdc also need the config specified when the admin
password is reset.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2018-11-09 01:49:12 +03:00
$ cmd . = " $env->{CONFIGURATION}" ;
2018-07-06 06:59:31 +03:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to reset admin's password: \n$cmd" ) ;
selftest: Fix backup testenv creation on certain host machines
When we created the backup-file for the restoredc/renamedc/labdc
testenvs we weren't explicitly a --configfile on the samba-tool command.
This meant the command tried to use the smb.conf form the default
install location, i.e. /usr/local/samba/etc/smb.conf. On the gitlab CI
runner, there's no samba installed, so it ends up using the default
settings, which is fine. However, if the host machine had an invalid
smb.conf installed there, creating the testenv would fail with an error
like:
ERROR(runtime): uncaught exception - Unable to load default file
File "bin/python/samba/netcmd/__init__.py", line 184, in _run
return self.run(*args, **kwargs)
File "bin/python/samba/netcmd/domain_backup.py", line 222, in run
lp = sambaopts.get_loadparm()
File "bin/python/samba/getopt.py", line 94, in get_loadparm
self._lp.load_default()
We can avoid this by always explictly specifying the backupfromdc's
smb.conf when creating the backup file.
Likewise, labdc/customdc also need the config specified when the admin
password is reset.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2018-11-09 01:49:12 +03:00
return undef ;
2018-07-06 06:59:31 +03:00
}
# start samba for the restored DC
2019-01-31 02:45:31 +03:00
if ( not defined ( $ self - > check_or_start ( $ env ) ) ) {
2018-07-06 06:59:31 +03:00
return undef ;
}
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2018-07-06 06:59:31 +03:00
return $ env ;
}
2018-10-26 01:08:54 +03:00
# Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
sub get_backup_domain_realm
{
my ( $ self , $ backup_file ) = @ _ ;
print "Determining REALM/DOMAIN values in backup...\n" ;
# The backup will have the correct domain/realm values in the smb.conf.
# So we can work out the env variables the testenv should use based on
# that. Let's start by extracting the smb.conf
my $ tar = Archive::Tar - > new ( $ backup_file ) ;
my $ tmpdir = File::Temp - > newdir ( ) ;
my $ smbconf = "$tmpdir/smb.conf" ;
# note that the filepaths within the tar-file differ slightly for online
# and offline backups
if ( $ tar - > contains_file ( "etc/smb.conf" ) ) {
$ tar - > extract_file ( "etc/smb.conf" , $ smbconf ) ;
} elsif ( $ tar - > contains_file ( "./etc/smb.conf" ) ) {
$ tar - > extract_file ( "./etc/smb.conf" , $ smbconf ) ;
} else {
warn ( "Could not find smb.conf in $backup_file" ) ;
return undef , undef ;
}
2019-05-30 05:55:52 +03:00
# make sure we don't try to create locks/sockets in the default install
# location (i.e. /usr/local/samba/)
my $ options = "--option=\"private dir = $tmpdir\"" ;
$ options . = " --option=\"lock dir = $tmpdir\"" ;
2018-10-26 01:08:54 +03:00
# now use testparm to read the values we're interested in
my $ testparm = Samba:: bindir_path ( $ self , "testparm" ) ;
2019-05-30 05:55:52 +03:00
my $ domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options` ;
my $ realm = `$testparm $smbconf -sl --parameter-name=REALM $options` ;
2018-10-26 01:08:54 +03:00
chomp $ realm ;
chomp $ domain ;
print "Backup-file REALM is $realm, DOMAIN is $domain\n" ;
return ( $ domain , $ realm ) ;
}
# This spins up a custom testenv that can be based on any backup-file you want.
# This is just intended for manual testing (rather than automated test-cases)
sub setup_customdc
{
my ( $ self , $ prefix ) = @ _ ;
print "Preparing CUSTOM RESTORE DC...\n" ;
my $ dc_name = "customdc" ;
my $ password = "locDCpass1" ;
my $ backup_file = $ ENV { 'BACKUP_FILE' } ;
2019-10-31 17:39:53 +03:00
my $ dnsupdate_options = " --use-samba-tool --no-credentials" ;
2018-10-26 01:08:54 +03:00
# user must specify a backup file to restore via an ENV variable, i.e.
# BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
if ( not defined ( $ backup_file ) ) {
warn ( "Please specify BACKUP_FILE" ) ;
return undef ;
}
# work out the correct domain/realm env values from the backup-file
my ( $ domain , $ realm ) = $ self - > get_backup_domain_realm ( $ backup_file ) ;
2019-05-30 05:46:35 +03:00
if ( $ domain eq '' or $ realm eq '' ) {
warn ( "Could not determine domain or realm" ) ;
return undef ;
}
2018-10-26 01:08:54 +03:00
# create a placeholder directory and smb.conf, as well as the env vars.
my ( $ env , $ ctx ) = $ self - > prepare_dc_testenv ( $ prefix , $ dc_name ,
2019-10-31 17:39:53 +03:00
$ domain , $ realm , $ password , "" ,
$ dnsupdate_options ) ;
2018-10-26 01:08:54 +03:00
# restore the specified backup file to populate the testenv
my $ restore_dir = abs_path ( $ prefix ) ;
my $ ret = $ self - > restore_backup_file ( $ backup_file ,
"--newservername=$env->{SERVER}" ,
$ restore_dir , $ env - > { SERVERCONFFILE } ) ;
unless ( $ ret == 0 ) {
return undef ;
}
2019-10-31 17:39:53 +03:00
#
2023-09-07 07:04:41 +03:00
# As we create the same domain as a clone
2019-10-31 17:39:53 +03:00
# we need a separate resolv.conf!
#
$ ctx - > { resolv_conf } = "$ctx->{etcdir}/resolv.conf" ;
$ ctx - > { dns_ipv4 } = $ ctx - > { ipv4 } ;
$ ctx - > { dns_ipv6 } = $ ctx - > { ipv6 } ;
Samba:: mk_resolv_conf ( $ ctx ) ;
$ env - > { RESOLV_CONF } = $ ctx - > { resolv_conf } ;
2018-10-26 01:08:54 +03:00
# Change the admin password to the testenv default, just in case it's
# different, or in case this was a --no-secrets backup
my $ samba_tool = Samba:: bindir_path ( $ self , "samba-tool" ) ;
my $ cmd = "$samba_tool user setpassword $env->{USERNAME} " ;
$ cmd . = "--newpassword=$password -H $restore_dir/private/sam.ldb" ;
selftest: Fix backup testenv creation on certain host machines
When we created the backup-file for the restoredc/renamedc/labdc
testenvs we weren't explicitly a --configfile on the samba-tool command.
This meant the command tried to use the smb.conf form the default
install location, i.e. /usr/local/samba/etc/smb.conf. On the gitlab CI
runner, there's no samba installed, so it ends up using the default
settings, which is fine. However, if the host machine had an invalid
smb.conf installed there, creating the testenv would fail with an error
like:
ERROR(runtime): uncaught exception - Unable to load default file
File "bin/python/samba/netcmd/__init__.py", line 184, in _run
return self.run(*args, **kwargs)
File "bin/python/samba/netcmd/domain_backup.py", line 222, in run
lp = sambaopts.get_loadparm()
File "bin/python/samba/getopt.py", line 94, in get_loadparm
self._lp.load_default()
We can avoid this by always explictly specifying the backupfromdc's
smb.conf when creating the backup file.
Likewise, labdc/customdc also need the config specified when the admin
password is reset.
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2018-11-09 01:49:12 +03:00
$ cmd . = " $env->{CONFIGURATION}" ;
2018-10-26 01:08:54 +03:00
unless ( system ( $ cmd ) == 0 ) {
warn ( "Failed to reset admin's password: \n$cmd" ) ;
return undef ;
}
# re-create the testenv's krb5.conf (the restore may have overwritten it,
# if the backup-file was an offline backup)
Samba:: mk_krb5_conf ( $ ctx ) ;
# start samba for the restored DC
2019-01-31 02:45:31 +03:00
if ( not defined ( $ self - > check_or_start ( $ env ) ) ) {
2018-10-26 01:08:54 +03:00
return undef ;
}
# if this was a backup-rename, then we may need to setup namespaces
my $ upn_array = [ "$env->{REALM}.upn" ] ;
my $ spn_array = [ "$env->{REALM}.spn" ] ;
2021-04-08 16:54:18 +03:00
if ( $ self - > setup_namespaces ( $ env , $ upn_array , $ spn_array ) != 0 ) {
return undef ;
}
2018-10-26 01:08:54 +03:00
return $ env ;
}
2018-02-08 06:51:23 +03:00
sub setup_none
2015-10-26 08:38:08 +03:00
{
my ( $ self , $ path ) = @ _ ;
my $ ret = {
KRB5_CONFIG = > abs_path ( $ path ) . "/no_krb5.conf" ,
SAMBA_PID = > - 1 ,
}
}
2007-03-06 00:28:55 +03:00
1 ;