file_server: Move vfs objects initialisation into file_server.c smb.conf wrapper
[amitay/samba.git] / selftest / target / Samba4.pm
index 1ffb61c7a36e71ec2aa298d5d91c93b26745a3ae..bc94d7c86c20b588cdefe42e78b35f384b5cd287 100644 (file)
@@ -9,25 +9,29 @@ use strict;
 use Cwd qw(abs_path);
 use FindBin qw($RealBin);
 use POSIX;
+use SocketWrapper;
+use target::Samba;
+use target::Samba3;
 
 sub new($$$$$) {
-       my ($classname, $bindir, $ldap, $setupdir, $exeext) = @_;
-       $exeext = "" unless defined($exeext);
-       my $self = { 
-               vars => {}, 
-               ldap => $ldap, 
-               bindir => $bindir, 
-               setupdir => $setupdir,
-               exeext => $exeext
+       my ($classname, $bindir, $binary_mapping, $ldap, $srcdir, $server_maxtime) = @_;
+
+       my $self = {
+               vars => {},
+               ldap => $ldap,
+               bindir => $bindir,
+               binary_mapping => $binary_mapping,
+               srcdir => $srcdir,
+               server_maxtime => $server_maxtime,
+               target3 => new Samba3($bindir, $binary_mapping, $srcdir, $server_maxtime)
        };
        bless $self;
        return $self;
 }
 
-sub bindir_path($$) {
+sub scriptdir_path($$) {
        my ($self, $path) = @_;
-
-       return "$self->{bindir}/$path$self->{exeext}";
+       return "$self->{srcdir}/source4/scripting/$path";
 }
 
 sub openldap_start($$$) {
@@ -37,7 +41,7 @@ sub slapd_start($$)
 {
        my $count = 0;
        my ($self, $env_vars) = @_;
-       my $ldbsearch = $self->bindir_path("ldbsearch");
+       my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
 
        my $uri = $env_vars->{LDAP_URI};
 
@@ -53,10 +57,10 @@ sub slapd_start($$)
                system("$ENV{OPENLDAP_SLAPD} -d0 -F $env_vars->{SLAPD_CONF_D} -h $uri > $env_vars->{LDAPDIR}/logs 2>&1 &");
        }
        while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
-               $count++;
+               $count++;
                if ($count > 40) {
-                   $self->slapd_stop($env_vars);
-                   return 0;
+                       $self->slapd_stop($env_vars);
+                       return 0;
                }
                sleep(1);
        }
@@ -69,27 +73,30 @@ sub slapd_stop($$)
        if ($self->{ldap} eq "fedora-ds") {
                system("$envvars->{LDAPDIR}/slapd-$envvars->{LDAP_INSTANCE}/stop-slapd");
        } elsif ($self->{ldap} eq "openldap") {
-               open(IN, "<$envvars->{OPENLDAP_PIDFILE}") or 
-                       die("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
+               unless (open(IN, "<$envvars->{OPENLDAP_PIDFILE}")) {
+                       warn("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}");
+                       return 0;
+               }
                kill 9, <IN>;
                close(IN);
        }
        return 1;
 }
 
-sub check_or_start($$$) 
+sub check_or_start($$$)
 {
-       my ($self, $env_vars, $max_time) = @_;
-       return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
+        my ($self, $env_vars, $process_model) = @_;
 
-       unlink($env_vars->{SAMBA_TEST_FIFO});
-       POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
-       unlink($env_vars->{SAMBA_TEST_LOG});
-       
-       print "STARTING SAMBA... ";
+       return 0 if $self->check_env($env_vars);
+
+       # use a pipe for stdin in the child processes. This allows
+       # those processes to monitor the pipe for EOF to ensure they
+       # exit when the test script exits
+       pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
+
+       print "STARTING SAMBA...";
        my $pid = fork();
        if ($pid == 0) {
-               open STDIN, $env_vars->{SAMBA_TEST_FIFO};
                # we want out from samba to go to the log file, but also
                # to the users terminal when running 'make test' on the command
                # line. This puts it on stderr on the terminal
@@ -98,62 +105,35 @@ sub check_or_start($$$)
 
                SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
 
-               my $valgrind = "";
-               if (defined($ENV{SAMBA_VALGRIND})) {
-                   $valgrind = $ENV{SAMBA_VALGRIND};
-               } 
-
-               $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG}; 
+               $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
                $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
+               $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
 
                $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
                $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
+               $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
 
                $ENV{UID_WRAPPER} = "1";
 
-               # Start slapd before samba, but with the fifo on stdin
-               if (defined($self->{ldap})) {
-                   $self->slapd_start($env_vars) or 
-                       die("couldn't start slapd (main run)");
-               }
-
-               my $optarg = "";
-               if (defined($max_time)) {
-                       $optarg = "--maximum-runtime=$max_time ";
-               }
+               $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
+               my @preargs = ();
+               my @optargs = ();
                if (defined($ENV{SAMBA_OPTIONS})) {
-                       $optarg.= " $ENV{SAMBA_OPTIONS}";
-               }
-               my $samba = $self->bindir_path("samba");
-
-               # allow selection of the process model using
-               # the environment varibale SAMBA_PROCESS_MODEL
-               # that allows us to change the process model for 
-               # individual machines in the build farm
-               my $model = "single";
-               if (defined($ENV{SAMBA_PROCESS_MODEL})) {
-                       $model = $ENV{SAMBA_PROCESS_MODEL};
+                       @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
                }
-               my $ret = system("$valgrind $samba $optarg $env_vars->{CONFIGURATION} -M $model -i");
-               if ($? == -1) {
-                       print "Unable to start $samba: $ret: $!\n";
-                       exit 1;
+               if(defined($ENV{SAMBA_VALGRIND})) {
+                       @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
                }
-               unlink($env_vars->{SAMBA_TEST_FIFO});
-               my $exit = $? >> 8;
-               if ( $ret == 0 ) {
-                       print "$samba exits with status $exit\n";
-               } elsif ( $ret & 127 ) {
-                       print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
-               } else {
-                       $ret = $? >> 8;
-                       print "$samba failed with status $exit!\n";
-               }
-               exit $exit;
+
+               close($env_vars->{STDIN_PIPE});
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
+               exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
        }
+       $env_vars->{SAMBA_PID} = $pid;
        print "DONE\n";
 
-       open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
+       close(STDIN_READER);
 
        return $pid;
 }
@@ -165,21 +145,21 @@ sub wait_for_start($$)
        print "delaying for nbt name registration\n";
        sleep 2;
 
-       # This will return quickly when things are up, but be slow if we 
-       # need to wait for (eg) SSL init 
-       my $nmblookup = $self->bindir_path("nmblookup");
+       # This will return quickly when things are up, but be slow if we
+       # need to wait for (eg) SSL init
+       my $nmblookup =  Samba::bindir_path($self, "nmblookup");
        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->{NETBIOSALIAS}");
-       system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
+       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->{NETBIOSALIAS}");
-       system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}");
+       system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
+       system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
 
        print $self->getlog_env($testenv_vars);
 }
@@ -188,10 +168,10 @@ sub write_ldb_file($$$)
 {
        my ($self, $file, $ldif) = @_;
 
-       my $ldbadd = $self->bindir_path("ldbadd");
+       my $ldbadd =  Samba::bindir_path($self, "ldbadd");
        open(LDIF, "|$ldbadd -H $file >/dev/null");
        print LDIF $ldif;
-       return close(LDIF);
+       return(close(LDIF));
 }
 
 sub add_wins_config($$)
@@ -260,7 +240,7 @@ YX70obsCAQI=
 EOF
        close(DHFILE);
 
-       #Likewise, we pregenerate the key material.  This allows the 
+       #Likewise, we pregenerate the key material.  This allows the
        #other certificates to be pre-generated
        open(KEYFILE, ">$keyfile");
        print KEYFILE <<EOF;
@@ -302,7 +282,7 @@ yoZeAErTALjyZYZEPcECQQDlUi0N8DFxQ/lOwWyR3Hailft+mPqoPCa8QHlQZnlG
 -----END RSA PRIVATE KEY-----
 EOF
 
-       #generated with 
+       #generated with
        # hxtool issue-certificate --self-signed --issue-ca \
        # --ca-private-key="FILE:$KEYFILE" \
        # --subject="CN=CA,DC=samba,DC=example,DC=com" \
@@ -326,7 +306,7 @@ HTLk2sGigsWwrJ2N99sG/cqSJLJ1MFwLrs6koweBnYU0f/g=
 -----END CERTIFICATE-----
 EOF
 
-       #generated with GNUTLS internally in Samba.  
+       #generated with GNUTLS internally in Samba.
 
        open(CERTFILE, ">$certfile");
        print CERTFILE <<EOF;
@@ -440,23 +420,29 @@ Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
 EOF
 }
 
-#
-# provision_raw_prepare() is also used by Samba34.pm!
-#
-sub provision_raw_prepare($$$$$$$$$$)
+sub provision_raw_prepare($$$$$$$$$)
 {
-       my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, 
+       my ($self, $prefix, $server_role, $hostname,
            $domain, $realm, $functional_level,
-           $swiface, $password, $kdc_ipv4) = @_;
+           $password, $kdc_ipv4) = @_;
        my $ctx;
+       my $netbiosname = uc($hostname);
 
-       -d $prefix or mkdir($prefix, 0777) or die("Unable to create $prefix");
+       unless(-d $prefix or mkdir($prefix, 0777)) {
+               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 "/";
 
-       (system("rm -rf $prefix_abs/*") == 0) or die("Unable to clean up");
+       unless (system("rm -rf $prefix_abs/*") == 0) {
+               warn("Unable to clean up");
+       }
+
+       
+       my $swiface = Samba::get_interface($hostname);
 
        $ctx->{prefix} = $prefix;
        $ctx->{prefix_abs} = $prefix_abs;
@@ -464,13 +450,13 @@ sub provision_raw_prepare($$$$$$$$$$)
        $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
 
        $ctx->{server_role} = $server_role;
+       $ctx->{hostname} = $hostname;
        $ctx->{netbiosname} = $netbiosname;
-       $ctx->{netbiosalias} = $netbiosalias;
        $ctx->{swiface} = $swiface;
        $ctx->{password} = $password;
        $ctx->{kdc_ipv4} = $kdc_ipv4;
 
-       $ctx->{server_loglevel} = 1;
+       $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
        $ctx->{username} = "Administrator";
        $ctx->{domain} = $domain;
        $ctx->{realm} = uc($realm);
@@ -493,6 +479,8 @@ sub provision_raw_prepare($$$$$$$$$$)
        $ctx->{privatedir} = "$prefix_abs/private";
        $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
        $ctx->{lockdir} = "$prefix_abs/lockdir";
+       $ctx->{statedir} = "$prefix_abs/statedir";
+       $ctx->{cachedir} = "$prefix_abs/cachedir";
        $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
        $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
        $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
@@ -507,8 +495,9 @@ sub provision_raw_prepare($$$$$$$$$$)
        push(@{$ctx->{directories}}, $ctx->{privatedir});
        push(@{$ctx->{directories}}, $ctx->{etcdir});
        push(@{$ctx->{directories}}, $ctx->{piddir});
-       push(@{$ctx->{directories}}, $ctx->{ncalrpcdir});
        push(@{$ctx->{directories}}, $ctx->{lockdir});
+       push(@{$ctx->{directories}}, $ctx->{statedir});
+       push(@{$ctx->{directories}}, $ctx->{cachedir});
 
        $ctx->{smb_conf_extra_options} = "";
 
@@ -517,16 +506,24 @@ sub provision_raw_prepare($$$$$$$$$$)
        push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
        if (defined($ENV{GDB_PROVISION})) {
                push (@provision_options, "gdb --args");
+               if (!defined($ENV{PYTHON})) {
+                   push (@provision_options, "env");
+                   push (@provision_options, "python");
+               }
        }
        if (defined($ENV{VALGRIND_PROVISION})) {
                push (@provision_options, "valgrind");
+               if (!defined($ENV{PYTHON})) {
+                   push (@provision_options, "env");
+                   push (@provision_options, "python");
+               }
        }
        if (defined($ENV{PYTHON})) {
                push (@provision_options, $ENV{PYTHON});
        }
-       push (@provision_options, "$self->{setupdir}/provision");
+       push (@provision_options, "$self->{srcdir}/source4/setup/provision");
        push (@provision_options, "--configfile=$ctx->{smb_conf}");
-       push (@provision_options, "--host-name=$ctx->{netbiosname}");
+       push (@provision_options, "--host-name=$ctx->{hostname}");
        push (@provision_options, "--host-ip=$ctx->{ipv4}");
        push (@provision_options, "--quiet");
        push (@provision_options, "--domain=$ctx->{domain}");
@@ -537,14 +534,13 @@ sub provision_raw_prepare($$$$$$$$$$)
        push (@provision_options, "--root=$ctx->{unix_name}");
        push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
        push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
+       push (@provision_options, "--dns-backend=BIND9_DLZ");
 
        @{$ctx->{provision_options}} = @provision_options;
 
        return $ctx;
 }
 
-#
-# provision_raw_step1() is also used by Samba34.pm!
 #
 # Step1 creates the basic configuration
 #
@@ -554,21 +550,25 @@ sub provision_raw_step1($$)
 
        mkdir($_, 0777) foreach (@{$ctx->{directories}});
 
-       open(CONFFILE, ">$ctx->{smb_conf}")
-               or die("can't open $ctx->{smb_conf}$?");
+       unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
+               warn("can't open $ctx->{smb_conf}$?");
+               return undef;
+       }
+       my $acl = "false";
+       $acl = "true" if (defined $ENV{WITH_ACL});
        print CONFFILE "
 [global]
+       acl:search = $acl
        netbios name = $ctx->{netbiosname}
-       netbios aliases = $ctx->{netbiosalias}
-       posix:eadb = $ctx->{lockdir}/eadb.tdb
+       posix:eadb = $ctx->{statedir}/eadb.tdb
        workgroup = $ctx->{domain}
        realm = $ctx->{realm}
        private dir = $ctx->{privatedir}
        pid directory = $ctx->{piddir}
        ncalrpc dir = $ctx->{ncalrpcdir}
        lock dir = $ctx->{lockdir}
-       setup directory = $self->{setupdir}
-       modules dir = $self->{bindir}/modules
+       state directory = $ctx->{statedir}
+       cache directory = $ctx->{cachedir}
        winbindd socket directory = $ctx->{winbindd_socket_dir}
        winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
        ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
@@ -576,9 +576,10 @@ sub provision_raw_step1($$)
        name resolve order = file bcast
        interfaces = $ctx->{interfaces}
        tls dh params file = $ctx->{tlsdir}/dhparms.pem
-       panic action = $RealBin/gdb_backtrace \%PID% \%PROG%
+       panic action = $RealBin/gdb_backtrace \%d
        wins support = yes
        server role = $ctx->{server_role}
+       server services = +echo +dns
        notify:inotify = false
        ldb:nosync = true
 #We don't want to pass our self-tests if the PAC code is wrong
@@ -586,16 +587,23 @@ sub provision_raw_step1($$)
        log level = $ctx->{server_loglevel}
        lanman auth = Yes
        rndc command = true
-        dns update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file}
-        spn update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_spnupdate
+        dns update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$ctx->{dns_host_file}
+        spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate
         resolv:host file = $ctx->{dns_host_file}
        dreplsrv:periodic_startup_interval = 0
+       dsdb:schema update allowed = yes
+
+        passdb backend = samba4
+
+        # remove this again, when our smb2 client library
+        # supports signin on compound related requests
+        server signing = on
 ";
 
        if (defined($ctx->{sid_generator}) && $ctx->{sid_generator} ne "internal") {
                print CONFFILE "
        sid generator = $ctx->{sid_generator}";
-        }
+       }
 
        print CONFFILE "
 
@@ -607,47 +615,12 @@ sub provision_raw_step1($$)
 
        $self->mk_keyblobs($ctx->{tlsdir});
 
-       open(KRB5CONF, ">$ctx->{krb5_conf}")
-               or die("can't open $ctx->{krb5_conf}$?");
-       print KRB5CONF "
-#Generated krb5.conf for $ctx->{realm}
-
-[libdefaults]
- default_realm = $ctx->{realm}
- dns_lookup_realm = false
- dns_lookup_kdc = false
- ticket_lifetime = 24h
- forwardable = yes
-
-[realms]
- $ctx->{realm} = {
-  kdc = $ctx->{kdc_ipv4}:88
-  admin_server = $ctx->{kdc_ipv4}:88
-  default_domain = $ctx->{dnsname}
- }
- $ctx->{dnsname} = {
-  kdc = $ctx->{kdc_ipv4}:88
-  admin_server = $ctx->{kdc_ipv4}:88
-  default_domain = $ctx->{dnsname}
- }
- $ctx->{domain} = {
-  kdc = $ctx->{kdc_ipv4}:88
-  admin_server = $ctx->{kdc_ipv4}:88
-  default_domain = $ctx->{dnsname}
- }
-
-[appdefaults]
-       pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
-
-[kdc]
-       enable-pkinit = true
-       pkinit_identity = FILE:$ctx->{tlsdir}/kdc.pem,$ctx->{tlsdir}/key.pem
-       pkinit_anchors = FILE:$ctx->{tlsdir}/ca.pem
-
-[domain_realm]
- .$ctx->{dnsname} = $ctx->{realm}
-";
-       close(KRB5CONF);
+        #Default the KDC IP to the server's IP
+       if (not defined($ctx->{kdc_ipv4})) {
+             $ctx->{kdc_ipv4} = $ctx->{ipv4};
+        }
+
+       Samba::mk_krb5_conf($ctx, "");
 
        open(PWD, ">$ctx->{nsswrap_passwd}");
        print PWD "
@@ -670,21 +643,23 @@ nogroup:x:65534:nobody
        my $configuration = "--configfile=$ctx->{smb_conf}";
 
 #Ensure the config file is valid before we start
-       my $testparm = $self->bindir_path("../scripting/bin/testparm");
+       my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
        if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
                system("$testparm -v --suppress-prompt $configuration >&2");
-               die("Failed to create a valid smb.conf configuration $testparm!");
+               warn("Failed to create a valid smb.conf configuration $testparm!");
+               return undef;
+       }
+       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;
        }
-
-       (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) or die("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
 
        my $ret = {
                KRB5_CONFIG => $ctx->{krb5_conf},
                PIDDIR => $ctx->{piddir},
-               SERVER => $ctx->{netbiosname},
+               SERVER => $ctx->{hostname},
                SERVER_IP => $ctx->{ipv4},
                NETBIOSNAME => $ctx->{netbiosname},
-               NETBIOSALIAS => $ctx->{netbiosalias},
                DOMAIN => $ctx->{domain},
                USERNAME => $ctx->{username},
                REALM => $ctx->{realm},
@@ -694,6 +669,8 @@ nogroup:x:65534:nobody
                WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
                NCALRPCDIR => $ctx->{ncalrpcdir},
                LOCKDIR => $ctx->{lockdir},
+               STATEDIR => $ctx->{statedir},
+               CACHEDIR => $ctx->{cachedir},
                SERVERCONFFILE => $ctx->{smb_conf},
                CONFIGURATION => $configuration,
                SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
@@ -702,13 +679,13 @@ nogroup:x:65534:nobody
                SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
                SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
                SAMBA_TEST_LOG_POS => 0,
+               NSS_WRAPPER_WINBIND_SO_PATH => Samba::bindir_path($self, "default/nsswitch/libnss-winbind.so"),
+                LOCAL_PATH => $ctx->{tmpdir}
        };
 
        return $ret;
 }
 
-#
-# provision_raw_step2() is also used by Samba34.pm!
 #
 # Step2 runs the provision script
 #
@@ -717,21 +694,24 @@ sub provision_raw_step2($$$)
        my ($self, $ctx, $ret) = @_;
 
        my $provision_cmd = join(" ", @{$ctx->{provision_options}});
-       (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n");
+       unless (system($provision_cmd) == 0) {
+               warn("Unable to provision: \n$provision_cmd\n");
+               return undef;
+       }
 
        return $ret;
 }
 
-sub provision($$$$$$$$$)
+sub provision($$$$$$$$)
 {
-       my ($self, $prefix, $server_role, $netbiosname, $netbiosalias, 
-           $domain, $realm, $functional_level, 
-           $swiface, $password, $kdc_ipv4, $extra_smbconf_options) = @_;
+       my ($self, $prefix, $server_role, $hostname,
+           $domain, $realm, $functional_level,
+           $password, $kdc_ipv4, $extra_smbconf_options) = @_;
 
        my $ctx = $self->provision_raw_prepare($prefix, $server_role,
-                                              $netbiosname, $netbiosalias,
+                                              $hostname,
                                               $domain, $realm, $functional_level,
-                                              $swiface, $password, $kdc_ipv4);
+                                              $password, $kdc_ipv4);
 
        $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
        push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
@@ -743,16 +723,26 @@ sub provision($$$$$$$$$)
 
        max xmit = 32K
        server max protocol = SMB2
-        $extra_smbconf_options
        host msdfs = $msdfs
        lanman auth = yes
 
+       $extra_smbconf_options
+
 [tmp]
        path = $ctx->{tmpdir}
        read only = no
        posix:sharedelay = 10000
        posix:oplocktimeout = 3
-       posix:writetimeupdatedelay = 500000
+       posix:writetimeupdatedelay = 50000
+
+[xcopy_share]
+       path = $ctx->{tmpdir}
+       read only = no
+       posix:sharedelay = 10000
+       posix:oplocktimeout = 3
+       posix:writetimeupdatedelay = 50000
+       create mask = 777
+       force create mode = 777
 
 [test1]
        path = $ctx->{tmpdir}/test1
@@ -773,8 +763,10 @@ sub provision($$$$$$$$$)
        ntvfs handler = cifs
        cifs:server = $ctx->{netbiosname}
        cifs:share = tmp
-#There is no username specified here, instead the client is expected
-#to log in with kerberos, and the serverwill use delegated credentials.
+       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
 
 [simple]
        path = $ctx->{tmpdir}
@@ -782,11 +774,11 @@ sub provision($$$$$$$$$)
        ntvfs handler = simple
 
 [sysvol]
-       path = $ctx->{lockdir}/sysvol
+       path = $ctx->{statedir}/sysvol
        read only = yes
 
 [netlogon]
-       path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
+       path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
        read only = no
 
 [cifsposix]
@@ -802,8 +794,7 @@ sub provision($$$$$$$$$)
                $ldap_uri =~ s|/|%2F|g;
                $ldap_uri = "ldapi://$ldap_uri";
                $ctx->{ldap_uri} = $ldap_uri;
-
-                if ($self->{ldap} eq "fedora-ds") {
+               if ($self->{ldap} eq "fedora-ds") {
                        $ctx->{sid_generator} = "backend";
                }
 
@@ -811,13 +802,16 @@ sub provision($$$$$$$$$)
        }
 
        my $ret = $self->provision_raw_step1($ctx);
+       unless (defined $ret) {
+               return undef;
+       }
 
        if (defined($self->{ldap})) {
-                $ret->{LDAP_URI} = $ctx->{ldap_uri};
+               $ret->{LDAP_URI} = $ctx->{ldap_uri};
                push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
                push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
                if ($self->{ldap} eq "openldap") {
-                       push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
+                       push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
                        ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
 
                 } elsif ($self->{ldap} eq "fedora-ds") {
@@ -828,9 +822,7 @@ sub provision($$$$$$$$$)
 
        }
 
-       $ret = $self->provision_raw_step2($ctx, $ret);
-
-       return $ret;
+       return $self->provision_raw_step2($ctx, $ret);
 }
 
 sub provision_member($$$)
@@ -840,38 +832,39 @@ sub provision_member($$$)
 
        my $ret = $self->provision($prefix,
                                   "member server",
-                                  "localmember",
-                                  "member3",
-                                  "SAMBADOMAIN", 
-                                  "samba.example.com", 
+                                  "s4member",
+                                  "SAMBADOMAIN",
+                                  "samba.example.com",
                                   "2008",
-                                  3,
                                   "locMEMpass3",
                                   $dcvars->{SERVER_IP},
                                   "");
+       unless ($ret) {
+               return undef;
+       }
 
-       $ret or die("Unable to provision");
-
-       my $net = $self->bindir_path("net");
+       my $samba_tool =  Samba::bindir_path($self, "samba-tool");
        my $cmd = "";
        $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
        $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
-       $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
+       $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
        $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
+       $cmd .= " --machinepass=machine$ret->{password}";
 
-       system($cmd) == 0 or die("Join failed\n$cmd");
+       unless (system($cmd) == 0) {
+               warn("Join failed\n$cmd");
+               return undef;
+       }
 
        $ret->{MEMBER_SERVER} = $ret->{SERVER};
        $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
        $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
-       $ret->{MEMBER_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
        $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
        $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
 
        $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
        $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
        $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
-       $ret->{DC_NETBIOSALIAS} = $dcvars->{DC_NETBIOSALIAS};
        $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
        $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
 
@@ -883,41 +876,90 @@ sub provision_rpc_proxy($$$)
        my ($self, $prefix, $dcvars) = @_;
        print "PROVISIONING RPC PROXY...";
 
-       my $extra_smbconf_options = "dcerpc_remote:binding = ncacn_ip_tcp:localdc
-       dcerpc endpoint servers = epmapper, remote
-       dcerpc_remote:interfaces = rpcecho
+       my $extra_smbconf_options = "
+
+       # rpc_proxy
+       dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
+       dcerpc endpoint servers = epmapper, remote
+       dcerpc_remote:interfaces = rpcecho
+
+[cifs_to_dc]
+       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
+
 ";
 
        my $ret = $self->provision($prefix,
                                   "member server",
                                   "localrpcproxy",
-                                  "rpcproxy4",
-                                  "SAMBADOMAIN", 
-                                  "samba.example.com", 
+                                  "SAMBADOMAIN",
+                                  "samba.example.com",
                                   "2008",
-                                  4,
                                   "locRPCproxypass4",
                                   $dcvars->{SERVER_IP},
                                   $extra_smbconf_options);
 
-       $ret or die("Unable to provision");
+       unless ($ret) {
+               return undef;
+       }
 
-       my $net = $self->bindir_path("net");
+       my $samba_tool =  Samba::bindir_path($self, "samba-tool");
+
+       # The joind runs in the context of the rpc_proxy/member for now
        my $cmd = "";
        $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
        $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
-       $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
+       $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
        $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
+       $cmd .= " --machinepass=machine$ret->{password}";
+
+       unless (system($cmd) == 0) {
+               warn("Join failed\n$cmd");
+               return undef;
+       }
+
+       # Setting up delegation runs in the context of the DC for now
+       $cmd = "";
+       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
+       $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
+       $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
+       $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
+
+       unless (system($cmd) == 0) {
+               warn("Delegation failed\n$cmd");
+               return undef;
+       }
 
-       system($cmd) == 0 or die("Join failed\n$cmd");
+       # Setting up delegation runs in the context of the DC for now
+       $cmd = "";
+       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
+       $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
+       $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
+       $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} $dcvars->{CONFIGURATION}";
+
+       unless (system($cmd) == 0) {
+               warn("Delegation failed\n$cmd");
+               return undef;
+       }
 
        $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
        $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
        $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
-       $ret->{RPC_PROXY_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
        $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
        $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
 
+       $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
+       $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
+       $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
+       $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
+
        return $ret;
 }
 
@@ -929,11 +971,10 @@ sub provision_vampire_dc($$$)
        # 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",
                                               "localvampiredc",
-                                              "dc2",
-                                              "SAMBADOMAIN", 
-                                              "samba.example.com", 
+                                              "SAMBADOMAIN",
+                                              "samba.example.com",
                                               "2008",
-                                              2, $dcvars->{PASSWORD},
+                                              $dcvars->{PASSWORD},
                                               $dcvars->{SERVER_IP});
 
        $ctx->{smb_conf_extra_options} = "
@@ -941,37 +982,103 @@ sub provision_vampire_dc($$$)
        server max protocol = SMB2
 
 [sysvol]
-       path = $ctx->{lockdir}/sysvol
+       path = $ctx->{statedir}/sysvol
        read only = yes
 
 [netlogon]
-       path = $ctx->{lockdir}/sysvol/$ctx->{dnsname}/scripts
+       path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
        read only = no
 
 ";
 
        my $ret = $self->provision_raw_step1($ctx);
+       unless ($ret) {
+               return undef;
+       }
 
-       $ret or die("Unable to prepare test env");
-
-       my $net = $self->bindir_path("net");
+       my $samba_tool =  Samba::bindir_path($self, "samba-tool");
        my $cmd = "";
        $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
        $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
-       $cmd .= "$net vampire $ret->{CONFIGURATION} $dcvars->{DOMAIN} --realm=$dcvars->{REALM}";
-       $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
+       $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
+       $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
+       $cmd .= " --machinepass=machine$ret->{password}";
 
-       system($cmd) == 0 or die("Join failed\n$cmd");
+       unless (system($cmd) == 0) {
+               warn("Join failed\n$cmd");
+               return undef;
+       }
 
        $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
        $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
        $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
-       $ret->{VAMPIRE_DC_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
 
        $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
        $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
        $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
-       $ret->{DC_NETBIOSALIAS} = $dcvars->{DC_NETBIOSALIAS};
+       $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
+       $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
+
+       return $ret;
+}
+
+sub provision_subdom_dc($$$)
+{
+       my ($self, $prefix, $dcvars) = @_;
+       print "PROVISIONING SUBDOMAIN DC...";
+
+       # 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",
+                                              "localsubdc",
+                                              "SAMBASUBDOM",
+                                              "sub.samba.example.com",
+                                              "2008",
+                                              $dcvars->{PASSWORD},
+                                              undef);
+
+       $ctx->{smb_conf_extra_options} = "
+       max xmit = 32K
+       server max protocol = SMB2
+
+[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 $dc_realms = Samba::mk_realms_stanza($dcvars->{REALM}, lc($dcvars->{REALM}),
+                                                $dcvars->{DOMAIN}, $dcvars->{SERVER_IP});
+       Samba::mk_krb5_conf($ctx, $dc_realms);
+
+       my $samba_tool =  Samba::bindir_path($self, "samba-tool");
+       my $cmd = "";
+       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
+       $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{realm} subdomain ";
+       $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
+       $cmd .= " --machinepass=machine$ret->{password}";
+
+       unless (system($cmd) == 0) {
+               warn("Join failed\n$cmd");
+               return undef;
+       }
+
+       $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
+       $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
+       $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
+
+       $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
+       $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
        $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
        $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
 
@@ -983,24 +1090,26 @@ sub provision_dc($$)
        my ($self, $prefix) = @_;
 
        print "PROVISIONING DC...";
+        my $extra_conf_options = "netbios aliases = localDC1-a
+allow dns updates = True";
        my $ret = $self->provision($prefix,
                                   "domain controller",
                                   "localdc",
-                                  "dc1",
-                                  "SAMBADOMAIN", 
-                                  "samba.example.com", 
+                                  "SAMBADOMAIN",
+                                  "samba.example.com",
                                   "2008",
-                                  1,
                                   "locDCpass1",
-                                  "127.0.0.1", "");
-
-       $self->add_wins_config("$prefix/private") or 
-               die("Unable to add wins configuration");
+                                  undef, $extra_conf_options);
 
+       return undef unless(defined $ret);
+       unless($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
+       $ret->{NETBIOSALIAS} = "localdc1-a";
        $ret->{DC_SERVER} = $ret->{SERVER};
        $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
        $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
-       $ret->{DC_NETBIOSALIAS} = $ret->{NETBIOSALIAS};
        $ret->{DC_USERNAME} = $ret->{USERNAME};
        $ret->{DC_PASSWORD} = $ret->{PASSWORD};
 
@@ -1015,16 +1124,16 @@ sub provision_fl2000dc($$)
        my $ret = $self->provision($prefix,
                                   "domain controller",
                                   "dc5",
-                                  "localfl2000dc",
-                                  "SAMBA2000", 
-                                  "samba2000.example.com", 
+                                  "SAMBA2000",
+                                  "samba2000.example.com",
                                   "2000",
-                                  5,
                                   "locDCpass5",
-                                  "127.0.0.5", "");
+                                  undef, "");
 
-       $self->add_wins_config("$prefix/private") or 
-               die("Unable to add wins configuration");
+       unless($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
 
        return $ret;
 }
@@ -1037,16 +1146,16 @@ sub provision_fl2003dc($$)
        my $ret = $self->provision($prefix,
                                   "domain controller",
                                   "dc6",
-                                  "localfl2003dc",
                                   "SAMBA2003",
                                   "samba2003.example.com",
                                   "2003",
-                                  6,
                                   "locDCpass6",
-                                  "127.0.0.6", "");
+                                  undef, "");
 
-       $self->add_wins_config("$prefix/private") or
-               die("Unable to add wins configuration");
+       unless($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
 
        return $ret;
 }
@@ -1059,16 +1168,158 @@ sub provision_fl2008r2dc($$)
        my $ret = $self->provision($prefix,
                                   "domain controller",
                                   "dc7",
-                                  "localfl2000r2dc",
                                   "SAMBA2008R2",
                                   "samba2008R2.example.com",
                                   "2008_R2",
-                                  7,
                                   "locDCpass7",
-                                  "127.0.0.7", "");
+                                  undef, "");
 
-       $self->add_wins_config("$prefix/private") or
-               die("Unable to add wins configuration");
+       unless ($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
+
+       return $ret;
+}
+
+
+sub provision_rodc($$$)
+{
+       my ($self, $prefix, $dcvars) = @_;
+       print "PROVISIONING RODC...";
+
+       # 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",
+                                              "SAMBADOMAIN",
+                                              "samba.example.com",
+                                              "2008",
+                                              $dcvars->{PASSWORD},
+                                              $dcvars->{SERVER_IP});
+       unless ($ctx) {
+               return undef;
+       }
+
+       $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
+       push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
+
+       $ctx->{smb_conf_extra_options} = "
+       max xmit = 32K
+       server max protocol = SMB2
+
+[sysvol]
+       path = $ctx->{statedir}/sysvol
+       read only = yes
+
+[netlogon]
+       path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
+       read only = yes
+
+[tmp]
+       path = $ctx->{tmpdir}
+       read only = no
+       posix:sharedelay = 10000
+       posix:oplocktimeout = 3
+       posix:writetimeupdatedelay = 50000
+
+";
+
+       my $ret = $self->provision_raw_step1($ctx);
+       unless ($ret) {
+               return undef;
+       }
+
+       my $samba_tool =  Samba::bindir_path($self, "samba-tool");
+       my $cmd = "";
+       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
+       $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
+       $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
+       $cmd .= " --server=$dcvars->{DC_SERVER}";
+
+       unless (system($cmd) == 0) {
+               warn("RODC join failed\n$cmd");
+               return undef;
+       }
+
+       # 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};
+       Samba::mk_krb5_conf($ctx);
+
+       $ret->{RODC_DC_SERVER} = $ret->{SERVER};
+       $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
+       $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
+
+       $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
+       $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
+       $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
+       $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
+
+       return $ret;
+}
+
+sub provision_plugin_s4_dc($$)
+{
+       my ($self, $prefix) = @_;
+
+       my $extra_smbconf_options = "
+server services = -smb +s3fs
+dcerpc endpoint servers = -unixinfo -spoolss -winreg -wkssvc -srvsvc
+
+";
+
+       print "PROVISIONING PLUGIN S4 DC...";
+       my $ret = $self->provision($prefix,
+                                  "domain controller",
+                                  "plugindc",
+                                  "PLUGINDOMAIN",
+                                  "plugin.samba.example.com",
+                                  "2008",
+                                  "locDCpass1",
+                                  undef, $extra_smbconf_options);
+
+       return undef unless(defined $ret);
+       unless($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
+
+       $ret->{DC_SERVER} = $ret->{SERVER};
+       $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
+       $ret->{DC_USERNAME} = $ret->{USERNAME};
+       $ret->{DC_PASSWORD} = $ret->{PASSWORD};
+
+       return $ret;
+}
+
+sub provision_chgdcpass($$)
+{
+       my ($self, $prefix) = @_;
+
+       print "PROVISIONING CHGDCPASS...";
+       my $ret = $self->provision($prefix,
+                                  "domain controller",
+                                  "chgdcpass",
+                                  "CHDCDOMAIN",
+                                  "chgdcpassword.samba.example.com",
+                                  "2008",
+                                  "chgDCpass1",
+                                  undef);
+
+       return undef unless(defined $ret);
+       unless($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
+       $ret->{DC_SERVER} = $ret->{SERVER};
+       $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
+       $ret->{DC_USERNAME} = $ret->{USERNAME};
+       $ret->{DC_PASSWORD} = $ret->{PASSWORD};
 
        return $ret;
 }
@@ -1078,37 +1329,47 @@ sub teardown_env($$)
        my ($self, $envvars) = @_;
        my $pid;
 
-       close(DATA);
+       # This should cause samba to terminate gracefully
+       close($envvars->{STDIN_PIPE});
 
-       if (-f "$envvars->{PIDDIR}/samba.pid" ) {
-               open(IN, "<$envvars->{PIDDIR}/samba.pid") or die("unable to open server pid file");
-               $pid = <IN>;
-               close(IN);
+       $pid = $envvars->{SAMBA_PID};
+       my $count = 0;
+       my $childpid;
+
+       # This should give it time to write out the gcov data
+       until ($count > 20) {
+           if (Samba::cleanup_child($pid, "samba") == -1) {
+               last;
+           }
+           sleep(1);
+           $count++;
+       }
 
-               # Give the process 20 seconds to exit.  gcov needs
-               # this time to write out the covarge data
-               my $count = 0;
-               until (kill(0, $pid) == 0) {
-                   # if no process sucessfully signalled, then we are done
-                   sleep(1);
-                   $count++;
-                   last if $count > 20;
-               }
-               
-               # If it is still around, kill it
-               if ($count > 20) {
-                   print "server process $pid took more than $count seconds to exit, killing\n";
-                   kill 9, $pid;
-               }
+       if ($count <= 20 && kill(0, $pid) == 0) {
+           return;
        }
 
-       my $failed = $? >> 8;
+       kill "TERM", $pid;
+
+       until ($count > 20) {
+           if (Samba::cleanup_child($pid, "samba") == -1) {
+               last;
+           }
+           sleep(1);
+           $count++;
+       }
+
+       # If it is still around, kill it
+       if ($count > 20 && kill(0, $pid) == 0) {
+           warn "server process $pid took more than $count seconds to exit, killing\n";
+           kill 9, $pid;
+       }
 
        $self->slapd_stop($envvars) if ($self->{ldap});
 
        print $self->getlog_env($envvars);
 
-       return $failed;
+       return;
 }
 
 sub getlog_env($$)
@@ -1127,7 +1388,7 @@ sub getlog_env($$)
        close(LOG);
 
        return "" if $out eq $title;
+
        return $out;
 }
 
@@ -1135,16 +1396,21 @@ sub check_env($$)
 {
        my ($self, $envvars) = @_;
 
-       return 1 if (-p $envvars->{SAMBA_TEST_FIFO});
-
-       print $self->getlog_env($envvars);
+       my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
 
-       return 0;
+       return ($childpid == 0);
 }
 
 sub setup_env($$$)
 {
        my ($self, $envname, $path) = @_;
+       my $target3 = $self->{target3};
+
+       $ENV{ENVNAME} = $envname;
+
+       if (defined($self->{vars}->{$envname})) {
+               return $self->{vars}->{$envname};
+       }
 
        if ($envname eq "dc") {
                return $self->setup_dc("$path/dc");
@@ -1164,59 +1430,32 @@ sub setup_env($$$)
                        $self->setup_dc("$path/dc");
                }
                return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{dc});
-       } elsif ($envname eq "member") {
+       } elsif ($envname eq "subdom_dc") {
                if (not defined($self->{vars}->{dc})) {
                        $self->setup_dc("$path/dc");
                }
-               return $self->setup_member("$path/member", $self->{vars}->{dc});
-       } elsif ($envname eq "all") {
+               return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{dc});
+       } elsif ($envname eq "s4member") {
                if (not defined($self->{vars}->{dc})) {
                        $self->setup_dc("$path/dc");
                }
-               my $ret = $self->setup_member("$path/member", $self->{vars}->{dc});
-               if (not defined($self->{vars}->{rpc_proxy})) {
-                       my $rpc_proxy_ret = $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{dc});
-                       
-                       $ret->{RPC_PROXY_SERVER} = $rpc_proxy_ret->{SERVER};
-                       $ret->{RPC_PROXY_SERVER_IP} = $rpc_proxy_ret->{SERVER_IP};
-                       $ret->{RPC_PROXY_NETBIOSNAME} = $rpc_proxy_ret->{NETBIOSNAME};
-                       $ret->{RPC_PROXY_NETBIOSALIAS} = $rpc_proxy_ret->{NETBIOSALIAS};
-                       $ret->{RPC_PROXY_USERNAME} = $rpc_proxy_ret->{USERNAME};
-                       $ret->{RPC_PROXY_PASSWORD} = $rpc_proxy_ret->{PASSWORD};
-               }
-               if (not defined($self->{vars}->{fl2000dc})) {
-                       my $fl2000dc_ret = $self->setup_fl2000dc("$path/fl2000dc", $self->{vars}->{dc});
-                       
-                       $ret->{FL2000DC_SERVER} = $fl2000dc_ret->{SERVER};
-                       $ret->{FL2000DC_SERVER_IP} = $fl2000dc_ret->{SERVER_IP};
-                       $ret->{FL2000DC_NETBIOSNAME} = $fl2000dc_ret->{NETBIOSNAME};
-                       $ret->{FL2000DC_NETBIOSALIAS} = $fl2000dc_ret->{NETBIOSALIAS};
-                       $ret->{FL2000DC_USERNAME} = $fl2000dc_ret->{USERNAME};
-                       $ret->{FL2000DC_PASSWORD} = $fl2000dc_ret->{PASSWORD};
-               }
-               if (not defined($self->{vars}->{fl2003dc})) {
-                       my $fl2003dc_ret = $self->setup_fl2003dc("$path/fl2003dc", $self->{vars}->{dc});
-
-                       $ret->{FL2003DC_SERVER} = $fl2003dc_ret->{SERVER};
-                       $ret->{FL2003DC_SERVER_IP} = $fl2003dc_ret->{SERVER_IP};
-                       $ret->{FL2003DC_NETBIOSNAME} = $fl2003dc_ret->{NETBIOSNAME};
-                       $ret->{FL2003DC_NETBIOSALIAS} = $fl2003dc_ret->{NETBIOSALIAS};
-                       $ret->{FL2003DC_USERNAME} = $fl2003dc_ret->{USERNAME};
-                       $ret->{FL2003DC_PASSWORD} = $fl2003dc_ret->{PASSWORD};
+               return $self->setup_member("$path/s4member", $self->{vars}->{dc});
+       } elsif ($envname eq "rodc") {
+               if (not defined($self->{vars}->{dc})) {
+                       $self->setup_dc("$path/dc");
                }
-               if (not defined($self->{vars}->{fl2008r2dc})) {
-                       my $fl2008r2dc_ret = $self->setup_fl2008r2dc("$path/fl2008r2dc", $self->{vars}->{dc});
-
-                       $ret->{FL2008R2DC_SERVER} = $fl2008r2dc_ret->{SERVER};
-                       $ret->{FL2008R2DC_SERVER_IP} = $fl2008r2dc_ret->{SERVER_IP};
-                       $ret->{FL2008R2DC_NETBIOSNAME} = $fl2008r2dc_ret->{NETBIOSNAME};
-                       $ret->{FL2008R2DC_NETBIOSALIAS} = $fl2008r2dc_ret->{NETBIOSALIAS};
-                       $ret->{FL2008R2DC_USERNAME} = $fl2008r2dc_ret->{USERNAME};
-                       $ret->{FL2008R2DC_PASSWORD} = $fl2008r2dc_ret->{PASSWORD};
+               return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
+       } elsif ($envname eq "chgdcpass") {
+               return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
+       } elsif ($envname eq "s3member") {
+               if (not defined($self->{vars}->{dc})) {
+                       $self->setup_dc("$path/dc");
                }
-               return $ret;
+               return $target3->setup_admember("$path/s3member", $self->{vars}->{dc}, 29);
+       } elsif ($envname eq "plugin_s4_dc") {
+               return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
        } else {
-               die("Samba4 can't provide environment '$envname'");
+               return "UNKNOWN";
        }
 }
 
@@ -1226,11 +1465,13 @@ sub setup_member($$$)
 
        my $env = $self->provision_member($path, $dc_vars);
 
-       $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
+       if (defined $env) {
+               $self->check_or_start($env, "single");
 
-       $self->wait_for_start($env);
+               $self->wait_for_start($env);
 
-       $self->{vars}->{member} = $env;
+               $self->{vars}->{member} = $env;
+       }
 
        return $env;
 }
@@ -1241,12 +1482,13 @@ sub setup_rpc_proxy($$$)
 
        my $env = $self->provision_rpc_proxy($path, $dc_vars);
 
-       $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500));
-
-       $self->wait_for_start($env);
+       if (defined $env) {
+               $self->check_or_start($env, "single");
 
-       $self->{vars}->{rpc_proxy} = $env;
+               $self->wait_for_start($env);
 
+               $self->{vars}->{rpc_proxy} = $env;
+       }
        return $env;
 }
 
@@ -1255,14 +1497,28 @@ sub setup_dc($$)
        my ($self, $path) = @_;
 
        my $env = $self->provision_dc($path);
+       if (defined $env) {
+               $self->check_or_start($env, "standard");
 
-       $self->check_or_start($env, 
-               ($ENV{SMBD_MAXTIME} or 7500));
+               $self->wait_for_start($env);
 
-       $self->wait_for_start($env);
+               $self->{vars}->{dc} = $env;
+       }
+       return $env;
+}
 
-       $self->{vars}->{dc} = $env;
+sub setup_chgdcpass($$)
+{
+       my ($self, $path) = @_;
+
+       my $env = $self->provision_chgdcpass($path);
+       if (defined $env) {
+               $self->check_or_start($env, "single");
+
+               $self->wait_for_start($env);
 
+               $self->{vars}->{chgdcpass} = $env;
+       }
        return $env;
 }
 
@@ -1271,13 +1527,13 @@ sub setup_fl2000dc($$)
        my ($self, $path) = @_;
 
        my $env = $self->provision_fl2000dc($path);
+       if (defined $env) {
+               $self->check_or_start($env, "single");
 
-       $self->check_or_start($env, 
-               ($ENV{SMBD_MAXTIME} or 7500));
+               $self->wait_for_start($env);
 
-       $self->wait_for_start($env);
-
-       $self->{vars}->{fl2000dc} = $env;
+               $self->{vars}->{fl2000dc} = $env;
+       }
 
        return $env;
 }
@@ -1288,13 +1544,13 @@ sub setup_fl2003dc($$)
 
        my $env = $self->provision_fl2003dc($path);
 
-       $self->check_or_start($env,
-               ($ENV{SMBD_MAXTIME} or 7500));
-
-       $self->wait_for_start($env);
+       if (defined $env) {
+               $self->check_or_start($env, "single");
 
-       $self->{vars}->{fl2003dc} = $env;
+               $self->wait_for_start($env);
 
+               $self->{vars}->{fl2003dc} = $env;
+       }
        return $env;
 }
 
@@ -1304,12 +1560,13 @@ sub setup_fl2008r2dc($$)
 
        my $env = $self->provision_fl2008r2dc($path);
 
-       $self->check_or_start($env,
-               ($ENV{SMBD_MAXTIME} or 7500));
+       if (defined $env) {
+               $self->check_or_start($env, "single");
 
-       $self->wait_for_start($env);
+               $self->wait_for_start($env);
 
-       $self->{vars}->{fl2008r2dc} = $env;
+               $self->{vars}->{fl2008r2dc} = $env;
+       }
 
        return $env;
 }
@@ -1320,43 +1577,144 @@ sub setup_vampire_dc($$$)
 
        my $env = $self->provision_vampire_dc($path, $dc_vars);
 
-       $self->check_or_start($env,
-               ($ENV{SMBD_MAXTIME} or 7500));
+       if (defined $env) {
+               $self->check_or_start($env, "single");
+
+               $self->wait_for_start($env);
+
+               $self->{vars}->{vampire_dc} = $env;
+
+               # force replicated DC to update repsTo/repsFrom
+               # for vampired partitions
+               my $samba_tool =  Samba::bindir_path($self, "samba-tool");
+               my $cmd = "";
+               $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
+               $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
+               $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
+               $cmd .= " $env->{CONFIGURATION}";
+               $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
+               unless (system($cmd) == 0) {
+                       warn("Failed to exec kcc\n$cmd");
+                       return undef;
+               }
 
-       $self->wait_for_start($env);
+               # 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 = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
+               $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
+               $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{VAMPIRE_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;
+               }
+       }
+
+       return $env;
+}
 
-       $self->{vars}->{vampire_dc} = $env;
+sub setup_subdom_dc($$$)
+{
+       my ($self, $path, $dc_vars) = @_;
 
-       # force replicated DC to update repsTo/repsFrom
-       # for vampired partitions
-       my $net = $self->bindir_path("net");
-       my $cmd = "";
-       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
-       $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
-       $cmd .= " $net drs kcc $env->{DC_SERVER}";
-       $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
-       system($cmd) == 0 or die("Failed to exec kcc\n$cmd");
-
-       # 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 = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
-       $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
-       $cmd .= " $net drs replicate $env->{DC_SERVER} $env->{VAMPIRE_DC_SERVER}";
-       $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
-       # replicate Configuration NC
-       my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
-       system($cmd_repl) == 0 or die("Failed to replicate\n$cmd_repl");
-       # replicate Default NC
-       $cmd_repl = "$cmd \"$base_dn\"";
-       system($cmd_repl) == 0 or die("Failed to replicate\n$cmd_repl");
+       my $env = $self->provision_subdom_dc($path, $dc_vars);
+
+       if (defined $env) {
+               $self->check_or_start($env, "single");
+
+               $self->wait_for_start($env);
+
+               $self->{vars}->{subdom_dc} = $env;
+
+               # force replicated DC to update repsTo/repsFrom
+               # for primary domain partitions
+               my $samba_tool =  Samba::bindir_path($self, "samba-tool");
+               my $cmd = "";
+               $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
+               $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
+               $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
+               $cmd .= " $env->{CONFIGURATION}";
+               $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
+               unless (system($cmd) == 0) {
+                       warn("Failed to exec kcc\n$cmd");
+                       return undef;
+               }
+
+               # as 'subdomain' dc may add data in its local replica
+               # we need to synchronize data between DCs
+               my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
+               my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
+               $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
+               $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
+               $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
+               $cmd .= " $dc_vars->{CONFIGURATION}";
+               $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
+               # replicate Configuration NC
+               my $cmd_repl = "$cmd \"$config_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;
+               }
+       }
 
        return $env;
 }
 
-sub stop($)
+sub setup_rodc($$$)
 {
-       my ($self) = @_;
+       my ($self, $path, $dc_vars) = @_;
+
+       my $env = $self->provision_rodc($path, $dc_vars);
+
+       unless ($env) {
+               return undef;
+       }
+
+       $self->check_or_start($env, "single");
+
+       $self->wait_for_start($env);
+
+       $self->{vars}->{rodc} = $env;
+
+       return $env;
+}
+
+sub setup_plugin_s4_dc($$)
+{
+       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_plugin_s4_dc($path);
+       unless ($env) {
+               return undef;
+       }
+
+       $self->check_or_start($env, "single");
+       
+       $self->wait_for_start($env);
+       
+       $self->{vars}->{plugin_s4_dc} = $env;
+       return $env;
 }
 
 1;