selftest: move all winbind test rules to one place
[samba.git] / selftest / target / Samba4.pm
old mode 100644 (file)
new mode 100755 (executable)
index a4fabd3..5ce2e84
@@ -117,12 +117,14 @@ sub check_or_start($$$)
                SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
 
                $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
-               $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
+               $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_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{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
+               $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
+               $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
 
                $ENV{UID_WRAPPER} = "1";
 
@@ -175,6 +177,9 @@ sub wait_for_start($$)
 
        # Ensure we have the first RID Set before we start tests.  This makes the tests more reliable.
        if ($testenv_vars->{SERVER_ROLE} eq "domain controller" and not ($testenv_vars->{NETBIOS_NAME} eq "rodc")) {
+           # Add hosts file for name lookups
+           $ENV{NSS_WRAPPER_HOSTS} = $testenv_vars->{NSS_WRAPPER_HOSTS};
+
            print "waiting for working LDAP and a RID Set to be allocated\n";
            my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
            my $count = 0;
@@ -506,6 +511,8 @@ sub provision_raw_prepare($$$$$$$$$$)
        chomp $unix_name;
        $ctx->{unix_name} = $unix_name;
        $ctx->{unix_uid} = $>;
+       my @mygid = split(" ", $();
+       $ctx->{unix_gid} = $mygid[0];
        $ctx->{unix_gids_str} = $);
        @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
 
@@ -524,6 +531,7 @@ sub provision_raw_prepare($$$$$$$$$$)
        $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
        $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
        $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
+       $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
 
        $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
 
@@ -543,6 +551,7 @@ sub provision_raw_prepare($$$$$$$$$$)
        my @provision_options = ();
        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}\"");
        if (defined($ENV{GDB_PROVISION})) {
                push (@provision_options, "gdb --args");
                if (!defined($ENV{PYTHON})) {
@@ -645,6 +654,8 @@ sub provision_raw_step1($$)
        server signing = on
 
         idmap_ldb:use rfc2307=yes
+       winbind enum users = yes
+       winbind enum groups = yes
 ";
 
        print CONFFILE "
@@ -670,6 +681,9 @@ root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false
 $ctx->{unix_name}:x:$ctx->{unix_uid}:100:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false
 nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
+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
 ";
        close(PWD);
         my $uid_rfc2307test = 65533;
@@ -681,10 +695,17 @@ wheel:x:10:
 users:x:100:
 nobody:x:65533:
 nogroup:x:65534:nobody
+$ctx->{unix_name}:x:$ctx->{unix_gid}:
 ";
        close(GRP);
         my $gid_rfc2307test = 65532;
 
+       my $hostname = lc($ctx->{hostname});
+       open(HOSTS, ">>$ctx->{nsswrap_hosts}");
+       print HOSTS "$ctx->{ipv4} ${hostname}.samba.example.com ${hostname}
+";
+       close(HOSTS);
+
        my $configuration = "--configfile=$ctx->{smb_conf}";
 
 #Ensure the config file is valid before we start
@@ -711,7 +732,7 @@ nogroup:x:65534:nobody
                PASSWORD => $ctx->{password},
                LDAPDIR => $ctx->{ldapdir},
                LDAP_INSTANCE => $ctx->{ldap_instance},
-               WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
+               SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
                NCALRPCDIR => $ctx->{ncalrpcdir},
                LOCKDIR => $ctx->{lockdir},
                STATEDIR => $ctx->{statedir},
@@ -722,10 +743,12 @@ nogroup:x:65534:nobody
                SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
                NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
                NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
+               NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
                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::nss_wrapper_winbind_so_path($self),
+               NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
+               NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
                 LOCAL_PATH => $ctx->{share},
                 UID_RFC2307TEST => $uid_rfc2307test,
                 GID_RFC2307TEST => $gid_rfc2307test,
@@ -895,7 +918,7 @@ $extra_smbconf_shares
        return $self->provision_raw_step2($ctx, $ret);
 }
 
-sub provision_member($$$)
+sub provision_s4member($$$)
 {
        my ($self, $prefix, $dcvars) = @_;
        print "PROVISIONING MEMBER...";
@@ -1300,6 +1323,34 @@ sub provision_fl2003dc($$)
                                   "locDCpass6",
                                   undef, "allow dns updates = nonsecure and secure", "", undef);
 
+       unless (defined $ret) {
+               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};
+
+       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;
+       }
+
+        return $ret;
+
        unless($self->add_wins_config("$prefix/private")) {
                warn("Unable to add wins configuration");
                return undef;
@@ -1425,6 +1476,8 @@ sub provision_plugin_s4_dc($$)
         server services = -smb +s3fs
         xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
 
+       dbwrap_tdb_mutexes:* = yes
+
        kernel oplocks = no
        kernel change notify = no
 
@@ -1680,7 +1733,7 @@ sub setup_env($$$)
                if (not defined($self->{vars}->{dc})) {
                        $self->setup_dc("$path/dc");
                }
-               return $self->setup_member("$path/s4member", $self->{vars}->{dc});
+               return $self->setup_s4member("$path/s4member", $self->{vars}->{dc});
        } elsif ($envname eq "rodc") {
                if (not defined($self->{vars}->{dc})) {
                        $self->setup_dc("$path/dc");
@@ -1706,18 +1759,18 @@ sub setup_env($$$)
        }
 }
 
-sub setup_member($$$)
+sub setup_s4member($$$)
 {
        my ($self, $path, $dc_vars) = @_;
 
-       my $env = $self->provision_member($path, $dc_vars);
+       my $env = $self->provision_s4member($path, $dc_vars);
 
        if (defined $env) {
                $self->check_or_start($env, "single");
 
                $self->wait_for_start($env);
 
-               $self->{vars}->{member} = $env;
+               $self->{vars}->{s4member} = $env;
        }
 
        return $env;