selftest: s!addc.samba.example.com!addom.samba.example.com!
[samba.git] / selftest / target / Samba4.pm
index 32114c3a5ecb67970ef2fead028d8c08543464c4..0508027bba54312f891183c94406d5484f13dbd8 100755 (executable)
@@ -89,7 +89,10 @@ sub check_or_start($$$)
         my ($self, $env_vars, $process_model) = @_;
        my $STDIN_READER;
 
-       return 0 if $self->check_env($env_vars);
+       my $env_ok = $self->check_env($env_vars);
+       if ($env_ok) {
+           return $env_vars->{SAMBA_PID};
+       }
 
        # use a pipe for stdin in the child processes. This allows
        # those processes to monitor the pipe for EOF to ensure they
@@ -132,6 +135,7 @@ sub check_or_start($$$)
                }
 
                $ENV{UID_WRAPPER} = "1";
+               $ENV{UID_WRAPPER_ROOT} = "1";
 
                $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
                my @preargs = ();
@@ -149,17 +153,28 @@ sub check_or_start($$$)
                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";
+       print "DONE ($pid)\n";
 
        close($STDIN_READER);
 
+       if ($self->wait_for_start($env_vars) != 0) {
+           warn("Samba $pid failed to start up");
+           return undef;
+       }
+
        return $pid;
 }
 
 sub wait_for_start($$)
 {
        my ($self, $testenv_vars) = @_;
-       my $ret;
+       my $ret = 0;
+
+       if (not $self->check_env($testenv_vars)) {
+           warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
+           return -1;
+       }
+
        # give time for nbt server to register its names
        print "delaying for nbt name registration\n";
        sleep 2;
@@ -199,7 +214,7 @@ sub wait_for_start($$)
            while (system("$ldbsearch -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$rid_set_dn\" rIDAllocationPool > /dev/null") != 0) {
                $count++;
                if ($count > 40) {
-                   $ret = 1;
+                   $ret = -1;
                    last;
                }
                sleep(1);
@@ -470,6 +485,86 @@ EOF
        umask $oldumask;
 }
 
+sub setup_namespaces($$:$$)
+{
+       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");
+
+       my $cmd_env = "";
+       $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}\" ";
+       }
+       $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\"";
+
+       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");
+               return;
+       }
+
+       return;
+}
+
+sub setup_trust($$$$$)
+{
+       my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
+
+       $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
+       $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
+       $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
+       $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
+       $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
+       $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
+       $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
+       $localenv->{TRUST_REALM} = $remoteenv->{REALM};
+
+       my $samba_tool =  Samba::bindir_path($self, "samba-tool");
+       # setup the trust
+       my $cmd_env = "";
+       $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}\" ";
+       }
+       $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\"";
+
+       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;
+       }
+
+       return $localenv
+}
+
 sub provision_raw_prepare($$$$$$$$$$$)
 {
        my ($self, $prefix, $server_role, $hostname,
@@ -566,6 +661,7 @@ sub provision_raw_prepare($$$$$$$$$$$)
        $ctx->{smb_conf_extra_options} = "";
 
        my @provision_options = ();
+       push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_config}\"");
        push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
        push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
        push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
@@ -816,14 +912,18 @@ sub provision_raw_step2($$$)
        }
 
        my $testallowed_account = "testallowed";
-       my $samba_tool_cmd = Samba::bindir_path($self, "samba-tool") 
+       my $samba_tool_cmd = "";
+       $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
            . " user add --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
        unless (system($samba_tool_cmd) == 0) {
                warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
                return undef;
        }
 
-       my $ldbmodify = Samba::bindir_path($self, "ldbmodify");
+       my $ldbmodify = "";
+       $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
        my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
 
        if ($ctx->{server_role} ne "domain controller") {
@@ -852,7 +952,9 @@ servicePrincipalName: host/testallowed
 ";
        close(LDIF);
 
-       $samba_tool_cmd = Samba::bindir_path($self, "samba-tool") 
+       $samba_tool_cmd = "";
+       $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
            . " user add --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
        unless (system($samba_tool_cmd) == 0) {
                warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
@@ -869,7 +971,9 @@ userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
 ";
        close(LDIF);
 
-       $samba_tool_cmd = Samba::bindir_path($self, "samba-tool") 
+       $samba_tool_cmd = "";
+       $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
            . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
        unless (system($samba_tool_cmd) == 0) {
                warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
@@ -925,16 +1029,16 @@ sub provision($$$$$$$$$$)
 [tmp]
        path = $ctx->{share}
        read only = no
-       posix:sharedelay = 10000
+       posix:sharedelay = 100000
        posix:oplocktimeout = 3
-       posix:writetimeupdatedelay = 50000
+       posix:writetimeupdatedelay = 500000
 
 [xcopy_share]
        path = $ctx->{share}
        read only = no
-       posix:sharedelay = 10000
+       posix:sharedelay = 100000
        posix:oplocktimeout = 3
-       posix:writetimeupdatedelay = 50000
+       posix:writetimeupdatedelay = 500000
        create mask = 777
        force create mode = 777
 
@@ -949,16 +1053,16 @@ sub provision($$$$$$$$$$)
 [test1]
        path = $ctx->{share}/test1
        read only = no
-       posix:sharedelay = 10000
+       posix:sharedelay = 100000
        posix:oplocktimeout = 3
-       posix:writetimeupdatedelay = 50000
+       posix:writetimeupdatedelay = 500000
 
 [test2]
        path = $ctx->{share}/test2
        read only = no
-       posix:sharedelay = 10000
+       posix:sharedelay = 100000
        posix:oplocktimeout = 3
-       posix:writetimeupdatedelay = 50000
+       posix:writetimeupdatedelay = 500000
 
 [cifs]
        path = $ctx->{share}/_ignore_cifs_
@@ -990,7 +1094,8 @@ sub provision($$$$$$$$$$)
 
 [vfs_fruit]
        path = $ctx->{share}
-       vfs objects = catia fruit streams_xattr
+       vfs objects = catia fruit streams_xattr acl_xattr
+       ea support = yes
        fruit:ressource = file
        fruit:metadata = netatalk
        fruit:locking = netatalk
@@ -1432,6 +1537,10 @@ sub provision_ad_dc_ntvfs($$)
 {
        my ($self, $prefix) = @_;
 
+       # We keep the old 'winbind' name here in server services to
+       # ensure upgrades which used that name still work with the now
+       # alias.
+
        print "PROVISIONING AD DC (NTVFS)...";
         my $extra_conf_options = "netbios aliases = localDC1-a
         server services = +winbind -winbindd";
@@ -1491,9 +1600,9 @@ sub provision_fl2000dc($$)
        return $ret;
 }
 
-sub provision_fl2003dc($$)
+sub provision_fl2003dc($$$)
 {
-       my ($self, $prefix) = @_;
+       my ($self, $prefix, $dcvars) = @_;
 
        print "PROVISIONING DC WITH FOREST LEVEL 2003...";
         my $extra_conf_options = "allow dns updates = nonsecure and secure";
@@ -1547,9 +1656,9 @@ sub provision_fl2003dc($$)
        return $ret;
 }
 
-sub provision_fl2008r2dc($$)
+sub provision_fl2008r2dc($$$)
 {
-       my ($self, $prefix) = @_;
+       my ($self, $prefix, $dcvars) = @_;
 
        print "PROVISIONING DC WITH FOREST LEVEL 2008r2...";
        my $ret = $self->provision($prefix,
@@ -1685,11 +1794,15 @@ sub provision_ad_dc($$)
        my $lockdir="$prefix_abs/lockdir";
         my $conffile="$prefix_abs/etc/smb.conf";
 
+       my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
+       $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
+
        my $extra_smbconf_options = "
         server services = -smb +s3fs
         xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
 
        dbwrap_tdb_mutexes:* = yes
+       ${require_mutexes}
 
        kernel oplocks = no
        kernel change notify = no
@@ -1770,7 +1883,7 @@ sub provision_ad_dc($$)
                                   "domain controller",
                                   "addc",
                                   "ADDOMAIN",
-                                  "addc.samba.example.com",
+                                  "addom.samba.example.com",
                                   "2008",
                                   "locDCpass1",
                                   undef,
@@ -1905,10 +2018,21 @@ sub getlog_env($$)
 sub check_env($$)
 {
        my ($self, $envvars) = @_;
+       my $samba_pid = $envvars->{SAMBA_PID};
 
-       my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
+       if (not defined($samba_pid)) {
+           return 0;
+       } elsif ($samba_pid > 0) {
+           my $childpid = Samba::cleanup_child($samba_pid, "samba");
+
+           if ($childpid == 0) {
+               return 1;
+           }
+           return 0;
+       } else {
+           return 1;
+       }
 
-       return ($childpid == 0);
 }
 
 sub setup_env($$$)
@@ -1927,9 +2051,15 @@ sub setup_env($$$)
        } elsif ($envname eq "fl2000dc") {
                return $self->setup_fl2000dc("$path/fl2000dc");
        } elsif ($envname eq "fl2003dc") {
-               return $self->setup_fl2003dc("$path/fl2003dc");
+               if (not defined($self->{vars}->{ad_dc})) {
+                       $self->setup_ad_dc("$path/ad_dc");
+               }
+               return $self->setup_fl2003dc("$path/fl2003dc", $self->{vars}->{ad_dc});
        } elsif ($envname eq "fl2008r2dc") {
-               return $self->setup_fl2008r2dc("$path/fl2008r2dc");
+               if (not defined($self->{vars}->{ad_dc})) {
+                       $self->setup_ad_dc("$path/ad_dc");
+               }
+               return $self->setup_fl2008r2dc("$path/fl2008r2dc", $self->{vars}->{ad_dc});
        } elsif ($envname eq "rpc_proxy") {
                if (not defined($self->{vars}->{ad_dc_ntvfs})) {
                        $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
@@ -1977,6 +2107,8 @@ sub setup_env($$$)
                }
                return $target3->setup_admember_rfc2307("$path/ad_member_rfc2307",
                                                        $self->{vars}->{ad_dc_ntvfs}, 34);
+       } elsif ($envname eq "none") {
+               return $self->setup_none("$path/none");
        } else {
                return "UNKNOWN";
        }
@@ -1989,9 +2121,9 @@ sub setup_s4member($$$)
        my $env = $self->provision_s4member($path, $dc_vars);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "standard"))) {
+                       return undef;
+               }
 
                $self->{vars}->{s4member} = $env;
        }
@@ -2006,9 +2138,9 @@ sub setup_rpc_proxy($$$)
        my $env = $self->provision_rpc_proxy($path, $dc_vars);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "standard"))) {
+                       return undef;
+               }
 
                $self->{vars}->{rpc_proxy} = $env;
        }
@@ -2021,9 +2153,10 @@ sub setup_ad_dc_ntvfs($$)
 
        my $env = $self->provision_ad_dc_ntvfs($path);
        if (defined $env) {
-               $self->check_or_start($env, "standard");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "standard"))) {
+                   warn("Failed to start ad_dc_ntvfs");
+                       return undef;
+               }
 
                $self->{vars}->{ad_dc_ntvfs} = $env;
        }
@@ -2036,9 +2169,9 @@ sub setup_chgdcpass($$)
 
        my $env = $self->provision_chgdcpass($path);
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "standard"))) {
+                       return undef;
+               }
 
                $self->{vars}->{chgdcpass} = $env;
        }
@@ -2051,9 +2184,9 @@ sub setup_fl2000dc($$)
 
        my $env = $self->provision_fl2000dc($path);
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "standard"))) {
+                       return undef;
+               }
 
                $self->{vars}->{fl2000dc} = $env;
        }
@@ -2061,32 +2194,41 @@ sub setup_fl2000dc($$)
        return $env;
 }
 
-sub setup_fl2003dc($$)
+sub setup_fl2003dc($$$)
 {
-       my ($self, $path) = @_;
+       my ($self, $path, $dc_vars) = @_;
 
        my $env = $self->provision_fl2003dc($path);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
+               if (not defined($self->check_or_start($env, "standard"))) {
+                       return undef;
+               }
 
-               $self->wait_for_start($env);
+               $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
 
                $self->{vars}->{fl2003dc} = $env;
        }
        return $env;
 }
 
-sub setup_fl2008r2dc($$)
+sub setup_fl2008r2dc($$$)
 {
-       my ($self, $path) = @_;
+       my ($self, $path, $dc_vars) = @_;
 
        my $env = $self->provision_fl2008r2dc($path);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
+               if (not defined($self->check_or_start($env, "standard"))) {
+                       return undef;
+               }
+
+               my $upn_array = ["$env->{REALM}.upn"];
+               my $spn_array = ["$env->{REALM}.spn"];
 
-               $self->wait_for_start($env);
+               $self->setup_namespaces($env, $upn_array, $spn_array);
+
+               $env = $self->setup_trust($env, $dc_vars, "forest", "");
 
                $self->{vars}->{fl2008r2dc} = $env;
        }
@@ -2101,9 +2243,9 @@ sub setup_vampire_dc($$$)
        my $env = $self->provision_vampire_dc($path, $dc_vars);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "single"))) {
+                       return undef;
+               }
 
                $self->{vars}->{vampire_dc} = $env;
 
@@ -2164,9 +2306,9 @@ sub setup_promoted_dc($$$)
        my $env = $self->provision_promoted_dc($path, $dc_vars);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "single"))) {
+                       return undef;
+               }
 
                $self->{vars}->{promoted_dc} = $env;
 
@@ -2228,9 +2370,9 @@ sub setup_subdom_dc($$$)
        my $env = $self->provision_subdom_dc($path, $dc_vars);
 
        if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
+               if (not defined($self->check_or_start($env, "single"))) {
+                       return undef;
+               }
 
                $self->{vars}->{subdom_dc} = $env;
 
@@ -2284,9 +2426,9 @@ sub setup_rodc($$$)
                return undef;
        }
 
-       $self->check_or_start($env, "single");
-
-       $self->wait_for_start($env);
+       if (not defined($self->check_or_start($env, "single"))) {
+           return undef;
+       }
 
        # force source and replicated DC to update repsTo/repsFrom
        # for vampired partitions
@@ -2357,12 +2499,27 @@ sub setup_ad_dc($$)
                $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
        }
 
-       $self->check_or_start($env, "single");
-       
-       $self->wait_for_start($env);
-       
+       if (not defined($self->check_or_start($env, "single"))) {
+           return undef;
+       }
+
+       my $upn_array = ["$env->{REALM}.upn"];
+       my $spn_array = ["$env->{REALM}.spn"];
+
+       $self->setup_namespaces($env, $upn_array, $spn_array);
+
        $self->{vars}->{ad_dc} = $env;
        return $env;
 }
 
+sub setup_none($$)
+{
+       my ($self, $path) = @_;
+
+       my $ret = {
+               KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
+               SAMBA_PID => -1,
+       }
+}
+
 1;