selftest: rename 'promoted_vampire_dc' to 'promoted_dc'
[samba.git] / selftest / target / Samba3.pm
index e8a03e71dc14982f7715658232a709e300478bcd..8546bd28951983010e5dc873bf4e1bbc91268cac 100755 (executable)
@@ -12,15 +12,17 @@ use POSIX;
 use target::Samba;
 
 sub have_ads($) {
-    my ($self);
+        my ($self) = @_;
        my $found_ads = 0;
-       my $smbd_build_options = Samba::bindir_path($self, "smbd") . " -b";
-       my @build_options = `$smbd_build_options`;
-       foreach my $option (@build_options) {
-               if ($option =~ "WITH_ADS") {
-                      $found_ads = 1;
-               }
-       }
+        my $smbd_build_options = Samba::bindir_path($self, "smbd") . " -b|";
+        open(IN, $smbd_build_options) or die("Unable to run $smbd_build_options: $!");
+
+        while (<IN>) {
+                if (/WITH_ADS/) {
+                       $found_ads = 1;
+                }
+        }
+       close IN;
 
        # If we were not built with ADS support, pretend we were never even available
        return $found_ads;
@@ -41,17 +43,56 @@ sub new($$) {
 sub teardown_env($$)
 {
        my ($self, $envvars) = @_;
+       my $count = 0;
+       
+       # This should cause smbd to terminate gracefully
+       close($envvars->{STDIN_PIPE});
+
+       my $smbdpid = $envvars->{SMBD_TL_PID};
+       my $nmbdpid = $envvars->{NMBD_TL_PID};
+       my $winbinddpid = $envvars->{WINBINDD_TL_PID};
+
+       # This should give it time to write out the gcov data
+       until ($count > 20) {
+           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);
+           $count++;
+       }
 
-       my $smbdpid = read_pid($envvars, "smbd");
-       my $nmbdpid = read_pid($envvars, "nmbd");
-       my $winbinddpid = read_pid($envvars, "winbindd");
+       if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
+           return;
+       }
 
        $self->stop_sig_term($smbdpid);
        $self->stop_sig_term($nmbdpid);
        $self->stop_sig_term($winbinddpid);
 
-       sleep(2);
+       $count = 0;
+       until ($count > 10) {
+           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);
+           $count++;
+       }
+
+       if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
+           return;
+       }
 
+       warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
        $self->stop_sig_kill($smbdpid);
        $self->stop_sig_kill($nmbdpid);
        $self->stop_sig_kill($winbinddpid);
@@ -96,6 +137,8 @@ sub check_env($$)
 {
        my ($self, $envvars) = @_;
 
+       my $childpid = waitpid(-1, WNOHANG);
+
        # TODO ...
        return 1;
 }
@@ -110,19 +153,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"))) {
@@ -145,20 +181,27 @@ 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,
                                    "LOCALS3DC2",
-                                   2,
                                    "locals3dc2pass",
                                    $s3dc_options);
 
        $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;
        }
 
@@ -185,7 +228,6 @@ sub setup_member($$$)
 ";
        my $ret = $self->provision($prefix,
                                   "LOCALMEMBER3",
-                                  3,
                                   "localmember3pass",
                                   $member_options);
 
@@ -202,9 +244,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;
        }
 
@@ -219,14 +259,14 @@ sub setup_member($$$)
 
 sub setup_admember($$$$)
 {
-       my ($self, $prefix, $dcvars, $iface) = @_;
+       my ($self, $prefix, $dcvars) = @_;
 
        # If we didn't build with ADS, pretend this env was never available
        if (not $self->have_ads()) {
                return "UNKNOWN";
        }
 
-       print "PROVISIONING S3 AD MEMBER$iface...";
+       print "PROVISIONING S3 AD MEMBER...";
 
        my $member_options = "
        security = ads
@@ -236,9 +276,8 @@ sub setup_admember($$$$)
 ";
 
        my $ret = $self->provision($prefix,
-                                  "LOCALADMEMBER$iface",
-                                  $iface,
-                                  "loCalMember${iface}Pass",
+                                  "LOCALADMEMBER",
+                                  "loCalMemberPass",
                                   $member_options);
 
        $ret or return undef;
@@ -276,10 +315,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};
@@ -293,143 +331,42 @@ sub setup_admember($$$$)
        return $ret;
 }
 
-sub setup_plugin_s4_dc($$$$)
-{
-       my ($self, $prefix, $dcvars, $iface) = @_;
-
-       print "PROVISIONING S4 PLUGIN AD DC$iface...";
-
-       my $plugin_s4_dc_options = "
-        workgroup = $dcvars->{DOMAIN}
-        realm = $dcvars->{REALM}
-
-        security = ads
-        domain logons = yes
-        passdb backend = samba4
-        auth methods = guest samba4
-        server signing = on
-
-        rpc_server:epmapper = disabled
-        rpc_server:rpcecho = disabled
-        rpc_server:dssetup = disabled
-        rpc_server:svctl = disabled
-        rpc_server:ntsvcs = disabled
-        rpc_server:eventlog = disabled
-        rpc_server:initshutdown = disabled
-
-        rpc_server:winreg = embedded
-        rpc_server:srvsvc = embedded
-        rpc_server:netdfs = embedded
-        rpc_server:wkssvc = embedded
-        rpc_server:spoolss = embedded
-
-        rpc_server:lsarpc = external
-        rpc_server:netlogon = external
-        rpc_server:samr = external
-
-        rpc_daemon:epmd = disabled
-        rpc_daemon:lsasd = disabled
-        rpc_daemon:spoolssd = disabled
-
-        rpc_server:tcpip = no
-
-[IPC\$]
-       vfs objects = dfs_samba4
-";
-
-       my $ret = $self->provision($prefix,
-                                  "plugindc",
-                                  $iface,
-                                  "pluGin${iface}Pass",
-                                  $plugin_s4_dc_options, 1);
-
-       $ret or return undef;
-
-       close(USERMAP);
-       $ret->{DOMAIN} = $dcvars->{DOMAIN};
-       $ret->{REALM} = $dcvars->{REALM};
-       $ret->{KRB5_CONFIG} = $dcvars->{KRB5_CONFIG};
-
-       # 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";
-
-       $self->check_or_start($ret,
-                             "no", "no", "yes");
-
-       $self->wait_for_start($ret);
-
-       # 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_secshare($$)
+sub setup_simpleserver($$)
 {
        my ($self, $path) = @_;
+       my $vfs_modulesdir_abs = $ENV{VFSLIBDIR};
 
        print "PROVISIONING server with security=share...";
 
-       my $secshare_options = "
-       security = share
+       my $prefix_abs = abs_path($path);
+
+       my $simpleserver_options = "
        lanman auth = yes
+       vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
+
+[vfs_aio_fork]
+       path = $prefix_abs/share
+        vfs objects = $vfs_modulesdir_abs/aio_fork.so
+        read only = no
+        vfs_aio_fork:erratic_testing_mode=yes
 ";
 
        my $vars = $self->provision($path,
                                    "LOCALSHARE4",
-                                   4,
                                    "local4pass",
-                                   $secshare_options);
+                                   $simpleserver_options);
 
        $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;
        }
 
-       $self->{vars}->{secshare} = $vars;
+       $self->{vars}->{simpleserver} = $vars;
 
        return $vars;
 }
 
-sub setup_secserver($$$)
-{
-       my ($self, $prefix, $s3dcvars) = @_;
-
-       print "PROVISIONING server with security=server...";
-
-       my $secserver_options = "
-       security = server
-        password server = $s3dcvars->{SERVER_IP}
-";
-
-       my $ret = $self->provision($prefix,
-                                  "LOCALSERVER5",
-                                  5,
-                                  "localserver5pass",
-                                  $secserver_options);
-
-       $ret or return undef;
-
-       $self->check_or_start($ret, "yes", "no", "yes");
-
-       if (not $self->wait_for_start($ret)) {
-              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};
-
-       return $ret;
-}
-
 sub setup_ktest($$$)
 {
        my ($self, $prefix) = @_;
@@ -451,7 +388,6 @@ sub setup_ktest($$$)
 
        my $ret = $self->provision($prefix,
                                   "LOCALKTEST6",
-                                  6,
                                   "localktest6pass",
                                   $ktest_options);
 
@@ -518,9 +454,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;
@@ -538,16 +472,12 @@ map to guest = bad user
 
        my $vars = $self->provision($path,
                                    "maptoguest",
-                                   7,
                                    "maptoguestpass",
                                    $options);
 
        $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;
        }
 
@@ -588,6 +518,11 @@ sub read_pid($$)
 sub check_or_start($$$$$) {
        my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
 
+       # 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});
+
        unlink($env_vars->{NMBD_TEST_LOG});
        print "STARTING NMBD...";
        my $pid = fork();
@@ -629,8 +564,12 @@ sub check_or_start($$$$$) {
                        @preargs = split(/ /, $ENV{NMBD_VALGRIND});
                }
 
+               close($env_vars->{STDIN_PIPE});
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
                exec(@preargs, Samba::bindir_path($self, "nmbd"), "-F", "--no-process-group", "--log-stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
        }
+       $env_vars->{NMBD_TL_PID} = $pid;
        write_pid($env_vars, "nmbd", $pid);
        print "DONE\n";
 
@@ -677,8 +616,12 @@ sub check_or_start($$$$$) {
 
                print "Starting winbindd with config $env_vars->{SERVERCONFFILE}\n";
 
+               close($env_vars->{STDIN_PIPE});
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
                exec(@preargs, Samba::bindir_path($self, "winbindd"), "-F", "--no-process-group", "--stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
        }
+       $env_vars->{WINBINDD_TL_PID} = $pid;
        write_pid($env_vars, "winbindd", $pid);
        print "DONE\n";
 
@@ -720,22 +663,30 @@ sub check_or_start($$$$$) {
                if(defined($ENV{SMBD_VALGRIND})) {
                        @preargs = split(/ /,$ENV{SMBD_VALGRIND});
                }
+
+               close($env_vars->{STDIN_PIPE});
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
                exec(@preargs, Samba::bindir_path($self, "smbd"), "-F", "--no-process-group", "--log-stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
        }
+       $env_vars->{SMBD_TL_PID} = $pid;
        write_pid($env_vars, "smbd", $pid);
        print "DONE\n";
 
-       return 0;
+       close(STDIN_READER);
+
+       return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
 }
 
-sub provision($$$$$$$)
+sub provision($$$$$$)
 {
-       my ($self, $prefix, $server, $swiface, $password, $extra_options, $no_delete_prefix) = @_;
+       my ($self, $prefix, $server, $password, $extra_options, $no_delete_prefix) = @_;
 
        ##
        ## setup the various environment variables we need
        ##
 
+       my $swiface = Samba::get_interface($server);
        my %ret = ();
        my $server_ip = "127.0.0.$swiface";
        my $domain = "SAMBA-TEST";
@@ -813,6 +764,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
        ##
@@ -851,8 +809,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;
@@ -862,6 +820,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;
@@ -873,6 +832,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
@@ -888,6 +848,7 @@ sub provision($$$$$$$)
        interfaces = $server_ip/8
        bind interfaces only = yes
        panic action = $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
+       smbd:suicide mode = yes
 
        workgroup = $domain
 
@@ -895,7 +856,7 @@ sub provision($$$$$$$)
        pid directory = $piddir
        lock directory = $lockdir
        log file = $logdir/log.\%m
-       log level = 0
+       log level = 1
        debug pid = yes
         max log size = 0
 
@@ -934,19 +895,19 @@ 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
+       create mask = 0777
+       directory mask = 0777
        dos filemode = yes
-       vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
+       vfs objects = $vfs_modulesdir_abs/acl_xattr.so $vfs_modulesdir_abs/fake_acls.so $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
 
        printing = vlp
        print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
@@ -959,17 +920,6 @@ sub provision($$$$$$$)
        lpq cache time = 0
 
        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
@@ -991,6 +941,10 @@ sub provision($$$$$$$)
 [tmp]
        path = $shrdir
         comment = smb username is [%U]
+[tmpenc]
+       path = $shrdir
+       comment = encrypt smb username is [%U]
+       smb encrypt = required
 [tmpguest]
        path = $shrdir
         guest ok = yes
@@ -1009,6 +963,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
@@ -1022,6 +983,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
@@ -1030,6 +996,7 @@ sub provision($$$$$$$)
        copy = print1
 [print3]
        copy = print1
+       default devmode = no
 [lp]
        copy = print1
 [xcopy_share]
@@ -1037,6 +1004,15 @@ sub provision($$$$$$$)
        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 = $vfs_modulesdir_abs/xattr_tdb.so
+
 [print\$]
        copy = tmp
        ";
@@ -1052,6 +1028,7 @@ 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";
@@ -1066,6 +1043,7 @@ $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:";
@@ -1094,10 +1072,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";
@@ -1121,51 +1102,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);