s3-winbindd: Remove undocumented winbindd:socket dir parameter
[mat/samba.git] / selftest / target / Samba3.pm
index 87763aadec119675ec705e590b9fcc009e4ad97d..c3a434558f7c65d9d4861874a85f39e3191aa0a2 100755 (executable)
@@ -25,6 +25,7 @@ sub have_ads($) {
        close IN;
 
        # If we were not built with ADS support, pretend we were never even available
+       print "smbd does not have ADS support\n" unless $found_ads;
        return $found_ads;
 }
 
@@ -54,9 +55,12 @@ sub teardown_env($$)
 
        # This should give it time to write out the gcov data
        until ($count > 20) {
-           if (Samba::cleanup_child($smbdpid, "smbd") == -1
-               && Samba::cleanup_child($nmbdpid, "nmbd") == -1
-               && Samba::cleanup_child($winbinddpid, "winbindd") == -1) {
+           my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
+           my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
+           my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
+           if ($smbdchild == -1
+               && $nmbdchild == -1
+               && $winbinddchild == -1) {
                last;
            }
            sleep(1);
@@ -73,9 +77,12 @@ sub teardown_env($$)
 
        $count = 0;
        until ($count > 10) {
-           if (Samba::cleanup_child($smbdpid, "smbd") == -1
-               && Samba::cleanup_child($nmbdpid, "nmbd") == -1
-               && Samba::cleanup_child($winbinddpid, "winbindd") == -1) {
+           my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
+           my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
+           my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
+           if ($smbdchild == -1
+               && $nmbdchild == -1
+               && $winbinddchild == -1) {
                last;
            }
            sleep(1);
@@ -147,19 +154,12 @@ sub setup_env($$$)
 
        if ($envname eq "s3dc") {
                return $self->setup_s3dc("$path/s3dc");
-       } elsif ($envname eq "secshare") {
-               return $self->setup_secshare("$path/secshare");
+       } elsif ($envname eq "simpleserver") {
+               return $self->setup_simpleserver("$path/simpleserver");
        } elsif ($envname eq "maptoguest") {
                return $self->setup_maptoguest("$path/maptoguest");
        } elsif ($envname eq "ktest") {
                return $self->setup_ktest("$path/ktest");
-       } elsif ($envname eq "secserver") {
-               if (not defined($self->{vars}->{s3dc})) {
-                       if (not defined($self->setup_s3dc("$path/s3dc"))) {
-                               return undef;
-                       }
-               }
-               return $self->setup_secserver("$path/secserver", $self->{vars}->{s3dc});
        } elsif ($envname eq "member") {
                if (not defined($self->{vars}->{s3dc})) {
                        if (not defined($self->setup_s3dc("$path/s3dc"))) {
@@ -182,6 +182,17 @@ sub setup_s3dc($$)
        domain master = yes
        domain logons = yes
        lanman auth = yes
+
+       rpc_server:epmapper = external
+       rpc_server:spoolss = external
+       rpc_server:lsarpc = external
+       rpc_server:samr = external
+       rpc_server:netlogon = external
+       rpc_server:register_embedded_np = yes
+
+       rpc_daemon:epmd = fork
+       rpc_daemon:spoolssd = fork
+       rpc_daemon:lsasd = fork
 ";
 
        my $vars = $self->provision($path,
@@ -191,10 +202,7 @@ sub setup_s3dc($$)
 
        $vars or return undef;
 
-       $self->check_or_start($vars,
-                              "yes", "yes", "yes");
-
-       if (not $self->wait_for_start($vars)) {
+       if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
               return undef;
        }
 
@@ -237,9 +245,7 @@ sub setup_member($$$)
            return undef;
        }
 
-       $self->check_or_start($ret, "yes", "yes", "yes");
-
-       if (not $self->wait_for_start($ret)) {
+       if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
               return undef;
        }
 
@@ -310,10 +316,9 @@ sub setup_admember($$$$)
        # access the share for tests.
        chmod 0777, "$prefix/share";
 
-       $self->check_or_start($ret,
-                             "yes", "yes", "yes");
-
-       $self->wait_for_start($ret);
+       if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
+               return undef;
+       }
 
        $ret->{DC_SERVER} = $dcvars->{SERVER};
        $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
@@ -327,66 +332,118 @@ sub setup_admember($$$$)
        return $ret;
 }
 
-sub setup_secshare($$)
+sub setup_admember_rfc2307($$$$)
 {
-       my ($self, $path) = @_;
+       my ($self, $prefix, $dcvars) = @_;
 
-       print "PROVISIONING server with security=share...";
+       # If we didn't build with ADS, pretend this env was never available
+       if (not $self->have_ads()) {
+               return "UNKNOWN";
+       }
 
-       my $secshare_options = "
-       security = share
-       lanman auth = yes
+       print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
+
+       my $member_options = "
+       security = ads
+       server signing = on
+        workgroup = $dcvars->{DOMAIN}
+        realm = $dcvars->{REALM}
+        idmap config $dcvars->{DOMAIN} : backend = rfc2307
+        idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
+        idmap config $dcvars->{DOMAIN} : ldap_server = ad
+        idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
+        idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
 ";
 
-       my $vars = $self->provision($path,
-                                   "LOCALSHARE4",
-                                   "local4pass",
-                                   $secshare_options);
+       my $ret = $self->provision($prefix,
+                                  "RFC2307MEMBER",
+                                  "loCalMemberPass",
+                                  $member_options);
 
-       $vars or return undef;
+       $ret or return undef;
 
-       $self->check_or_start($vars, "yes", "no", "yes");
+       close(USERMAP);
+       $ret->{DOMAIN} = $dcvars->{DOMAIN};
+       $ret->{REALM} = $dcvars->{REALM};
 
-       if (not $self->wait_for_start($vars)) {
-              return undef;
+       my $ctx;
+       my $prefix_abs = abs_path($prefix);
+       $ctx = {};
+       $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
+       $ctx->{domain} = $dcvars->{DOMAIN};
+       $ctx->{realm} = $dcvars->{REALM};
+       $ctx->{dnsname} = lc($dcvars->{REALM});
+       $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
+       Samba::mk_krb5_conf($ctx, "");
+
+       $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
+
+       my $net = Samba::bindir_path($self, "net");
+       my $cmd = "";
+       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
+       $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
+       $cmd .= "$net join $ret->{CONFIGURATION}";
+       $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
+
+       if (system($cmd) != 0) {
+           warn("Join failed\n$cmd");
+           return undef;
        }
 
-       $self->{vars}->{secshare} = $vars;
+       # We need world access to this share, as otherwise the domain
+       # administrator from the AD domain provided by Samba4 can't
+       # access the share for tests.
+       chmod 0777, "$prefix/share";
 
-       return $vars;
+       if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
+               return undef;
+       }
+
+       $ret->{DC_SERVER} = $dcvars->{SERVER};
+       $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
+       $ret->{DC_USERNAME} = $dcvars->{USERNAME};
+       $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
+
+       # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
+       $ret->{target} = $self;
+
+       return $ret;
 }
 
-sub setup_secserver($$$)
+sub setup_simpleserver($$)
 {
-       my ($self, $prefix, $s3dcvars) = @_;
+       my ($self, $path) = @_;
 
-       print "PROVISIONING server with security=server...";
+       print "PROVISIONING server with security=share...";
 
-       my $secserver_options = "
-       security = server
-        password server = $s3dcvars->{SERVER_IP}
-";
+       my $prefix_abs = abs_path($path);
 
-       my $ret = $self->provision($prefix,
-                                  "LOCALSERVER5",
-                                  "localserver5pass",
-                                  $secserver_options);
+       my $simpleserver_options = "
+       lanman auth = yes
+       vfs objects = xattr_tdb streams_depot
 
-       $ret or return undef;
+[vfs_aio_fork]
+       path = $prefix_abs/share
+        vfs objects = aio_fork
+        read only = no
+        vfs_aio_fork:erratic_testing_mode=yes
+";
 
-       $self->check_or_start($ret, "yes", "no", "yes");
+       my $vars = $self->provision($path,
+                                   "LOCALSHARE4",
+                                   "local4pass",
+                                   $simpleserver_options);
+
+       $vars or return undef;
 
-       if (not $self->wait_for_start($ret)) {
+       if (not $self->check_or_start($vars, "yes", "no", "yes")) {
               return undef;
        }
 
-       $ret->{DC_SERVER} = $s3dcvars->{SERVER};
-       $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
-       $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
-       $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
-       $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
+       $self->{vars}->{simpleserver} = $vars;
 
-       return $ret;
+       return $vars;
 }
 
 sub setup_ktest($$$)
@@ -440,6 +497,9 @@ $ret->{USERNAME} = KTEST\\Administrator
        system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
        chmod 0600, "$prefix/private/secrets.tdb";
 
+#Make sure there's no old ntdb file.
+       system("rm -f $prefix/private/secrets.ntdb");
+
 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
 #
@@ -476,9 +536,7 @@ $ret->{USERNAME} = KTEST\\Administrator
        # access the share for tests.
        chmod 0777, "$prefix/share";
 
-       $self->check_or_start($ret, "yes", "no", "yes");
-
-       if (not $self->wait_for_start($ret)) {
+       if (not $self->check_or_start($ret, "yes", "no", "yes")) {
               return undef;
        }
        return $ret;
@@ -501,10 +559,7 @@ map to guest = bad user
 
        $vars or return undef;
 
-       $self->check_or_start($vars,
-                              "yes", "no", "yes");
-
-       if (not $self->wait_for_start($vars)) {
+       if (not $self->check_or_start($vars, "yes", "no", "yes")) {
               return undef;
        }
 
@@ -702,7 +757,7 @@ sub check_or_start($$$$$) {
 
        close(STDIN_READER);
 
-       return 0;
+       return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
 }
 
 sub provision($$$$$$)
@@ -726,7 +781,6 @@ sub provision($$$$$$)
 
        my $prefix_abs = abs_path($prefix);
        my $bindir_abs = abs_path($self->{bindir});
-       my $vfs_modulesdir_abs = ($ENV{VFSLIBDIR} or $bindir_abs);
 
        my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
 
@@ -791,6 +845,13 @@ sub provision($$$$$$)
        }
        mkdir($_, 0777) foreach(@dirs);
 
+       ##
+       ## lockdir and piddir must be 0755
+       ##
+       chmod 0755, $lockdir;
+       chmod 0755, $piddir;
+
+
        ##
        ## create ro and msdfs share layout
        ##
@@ -829,8 +890,8 @@ sub provision($$$$$$)
        ##
 
        my ($max_uid, $max_gid);
-       my ($uid_nobody, $uid_root);
-       my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers);
+       my ($uid_nobody, $uid_root, $uid_pdbtest);
+       my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
 
        if ($unix_uid < 0xffff - 2) {
                $max_uid = 0xffff;
@@ -840,6 +901,7 @@ sub provision($$$$$$)
 
        $uid_root = $max_uid - 1;
        $uid_nobody = $max_uid - 2;
+       $uid_pdbtest = $max_uid - 3;
 
        if ($unix_gids[0] < 0xffff - 3) {
                $max_gid = 0xffff;
@@ -851,6 +913,7 @@ sub provision($$$$$$)
        $gid_nogroup = $max_gid - 2;
        $gid_root = $max_gid - 3;
        $gid_domusers = $max_gid - 4;
+       $gid_domadmins = $max_gid - 5;
 
        ##
        ## create conffile
@@ -865,7 +928,8 @@ sub provision($$$$$$)
        netbios name = $server
        interfaces = $server_ip/8
        bind interfaces only = yes
-       panic action = $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
+       panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
+       smbd:suicide mode = yes
 
        workgroup = $domain
 
@@ -904,7 +968,7 @@ sub provision($$$$$$)
        printing = bsd
        printcap name = /dev/null
 
-       winbindd:socket dir = $wbsockdir
+       winbindd socket directory = $wbsockdir
        nmbd:socket dir = $nmbdsockdir
        idmap config * : range = 100000-200000
        winbind enum users = yes
@@ -912,19 +976,18 @@ sub provision($$$$$$)
 
 #      min receivefile size = 4000
 
-       max protocol = SMB2
        read only = no
        server signing = auto
 
        smbd:sharedelay = 100000
-#      smbd:writetimeupdatedelay = 500000
+       smbd:writetimeupdatedelay = 500000
        map hidden = no
        map system = no
        map readonly = no
        store dos attributes = yes
        create mask = 755
        dos filemode = yes
-       vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
+       vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
 
        printing = vlp
        print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
@@ -935,19 +998,9 @@ sub provision($$$$$$)
        queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
        queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
        lpq cache time = 0
+       print notify backchannel = yes
 
        ncalrpc dir = $prefix_abs/ncalrpc
-       rpc_server:epmapper = external
-       rpc_server:spoolss = external
-       rpc_server:lsarpc = external
-       rpc_server:samr = external
-       rpc_server:netlogon = external
-       rpc_server:tcpip = yes
-
-       rpc_daemon:epmd = fork
-       rpc_daemon:spoolssd = fork
-       rpc_daemon:lsasd = fork
-
         resolv:host file = $dns_host_file
 
         # The samba3.blackbox.smbclient_s3 test uses this to test that
@@ -969,6 +1022,11 @@ sub provision($$$$$$)
 [tmp]
        path = $shrdir
         comment = smb username is [%U]
+[tmpenc]
+       path = $shrdir
+       comment = encrypt smb username is [%U]
+       smb encrypt = required
+       vfs objects = dirsort
 [tmpguest]
        path = $shrdir
         guest ok = yes
@@ -987,6 +1045,13 @@ sub provision($$$$$$)
 [ro-tmp]
        path = $ro_shrdir
        guest ok = yes
+[write-list-tmp]
+       path = $shrdir
+        read only = yes
+       write list = $unix_name
+[valid-users-tmp]
+       path = $shrdir
+       valid users = $unix_name
 [msdfs-share]
        path = $msdfs_shrdir
        msdfs root = yes
@@ -1000,6 +1065,11 @@ sub provision($$$$$$)
 [hideunwrite]
        copy = tmp
        hide unwriteable files = yes
+[durable]
+       copy = tmp
+       kernel share modes = no
+       kernel oplocks = no
+       posix locking = no
 [print1]
        copy = tmp
        printable = yes
@@ -1008,13 +1078,36 @@ sub provision($$$$$$)
        copy = print1
 [print3]
        copy = print1
+       default devmode = no
 [lp]
        copy = print1
+
+[nfs4acl_simple]
+       path = $shrdir
+       comment = smb username is [%U]
+       nfs4:mode = simple
+       vfs objects = nfs4acl_xattr xattr_tdb
+
+[nfs4acl_special]
+       path = $shrdir
+       comment = smb username is [%U]
+       nfs4:mode = special
+       vfs objects = nfs4acl_xattr xattr_tdb
+
 [xcopy_share]
        path = $shrdir
        comment = smb username is [%U]
        create mask = 777
        force create mode = 777
+[posix_share]
+       path = $shrdir
+       comment = smb username is [%U]
+       create mask = 0777
+       force create mode = 0
+       directory mask = 0777
+       force directory mode = 0
+       vfs objects = xattr_tdb
+
 [print\$]
        copy = tmp
        ";
@@ -1030,9 +1123,11 @@ sub provision($$$$$$)
         } 
        print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
+pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
 ";
        if ($unix_uid != 0) {
-               print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
+               print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
+";
        }
        close(PASSWD);
 
@@ -1044,9 +1139,11 @@ $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
 nogroup:x:$gid_nogroup:nobody
 $unix_name-group:x:$unix_gids[0]:
 domusers:X:$gid_domusers:
+domadmins:X:$gid_domadmins:
 ";
        if ($unix_gids[0] != 0) {
-               print GROUP "root:x:$gid_root:";
+               print GROUP "root:x:$gid_root:
+";
        }
 
        close(GROUP);
@@ -1072,10 +1169,13 @@ domusers:X:$gid_domusers:
         }
        print "DONE\n";
 
-       open(HOSTS, ">>$ENV{SELFTEST_PREFIX}/dns_host_file") or die("Unable to open $ENV{SELFTEST_PREFIX}/dns_host_file");
-       print HOSTS "A $server. $server_ip
-";
-       close(HOSTS);
+       open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
+       print DNS_UPDATE_LIST "A $server. $server_ip";
+       close(DNS_UPDATE_LIST);
+
+        if (system("$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$dns_host_file -s $conffile --update-list=$prefix/dns_update_list --no-substiutions --no-credentials") != 0) {
+                die "Unable to update hostname into $dns_host_file";
+        }
 
        $ret{SERVER_IP} = $server_ip;
        $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
@@ -1099,51 +1199,99 @@ domusers:X:$gid_domusers:
        $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
        $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
        $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
-       $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
-        if (not defined($ret{NSS_WRAPPER_WINBIND_SO_PATH})) {
-               $ret{NSS_WRAPPER_WINBIND_SO_PATH} = Samba::bindir_path($self, "default/nsswitch/libnss-winbind.so");
-        }
+       $ret{NSS_WRAPPER_WINBIND_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
        $ret{LOCAL_PATH} = "$shrdir";
 
        return \%ret;
 }
 
-sub wait_for_start($$)
+sub wait_for_start($$$$$)
 {
-       my ($self, $envvars) = @_;
+       my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
+       my $ret;
+
+       if ($nmbd eq "yes") {
+           # give time for nbt server to register its names
+           print "delaying for nbt name registration\n";
+           sleep(10);
+           # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
+           my $nmblookup = Samba::bindir_path($self, "nmblookup3");
+           system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
+           system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
+           system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
+           system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
+           system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
+       }
 
-       # give time for nbt server to register its names
-       print "delaying for nbt name registration\n";
-       sleep(10);
-       # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
-       system(Samba::bindir_path($self, "nmblookup3") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
-       system(Samba::bindir_path($self, "nmblookup3") ." $envvars->{CONFIGURATION} __SAMBA__");
-       system(Samba::bindir_path($self, "nmblookup3") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
-       system(Samba::bindir_path($self, "nmblookup3") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
-       system(Samba::bindir_path($self, "nmblookup3") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
+       if ($winbindd eq "yes") {
+           print "checking for winbindd\n";
+           my $count = 0;
+           do {
+               $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " -p");
+               if ($ret != 0) {
+                   sleep(2);
+               }
+               $count++;
+           } while ($ret != 0 && $count < 10);
+           if ($count == 10) {
+               print "WINBINDD not reachable after 20 seconds\n";
+               teardown_env($self, $envvars);
+               return 0;
+           }
+       }
 
-       # make sure smbd is also up set
-       print "wait for smbd\n";
+       if ($smbd eq "yes") {
+           # make sure smbd is also up set
+           print "wait for smbd\n";
 
-       my $count = 0;
-       my $ret;
-       do {
-           $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
-           if ($ret != 0) {
-               sleep(2);
+           my $count = 0;
+           do {
+               $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
+               if ($ret != 0) {
+                   sleep(2);
+               }
+               $count++
+           } while ($ret != 0 && $count < 10);
+           if ($count == 10) {
+               print "SMBD failed to start up in a reasonable time (20sec)\n";
+               teardown_env($self, $envvars);
+               return 0;
            }
-           $count++
-       } while ($ret != 0 && $count < 10);
-       if ($count == 10) {
-           print "SMBD failed to start up in a reasonable time (20sec)\n";
-           teardown_env($self, $envvars);
-           return 0;
        }
+
        # Ensure we have domain users mapped.
        $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
        if ($ret != 0) {
            return 1;
        }
+       $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
+       if ($ret != 0) {
+           return 1;
+       }
+
+       if ($winbindd eq "yes") {
+           # note: creating builtin groups requires winbindd for the
+           # unix id allocator
+           $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
+           if ($ret != 0) {
+               print "Failed to create BUILTIN\\Users group\n";
+               return 0;
+           }
+           my $count = 0;
+           do {
+               system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
+               $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
+               if ($ret != 0) {
+                   sleep(2);
+               }
+               $count++;
+           } while ($ret != 0 && $count < 10);
+           if ($count == 10) {
+               print "WINBINDD not reachable after 20 seconds\n";
+               teardown_env($self, $envvars);
+               return 0;
+           }
+       }
 
        print $self->getlog_env($envvars);