selftest: change plugin_dc to test using s3fs
[nivanova/samba-autobuild/.git] / selftest / target / Samba3.pm
old mode 100644 (file)
new mode 100755 (executable)
index eff6145..9d74e7d
@@ -9,16 +9,32 @@ use strict;
 use Cwd qw(abs_path);
 use FindBin qw($RealBin);
 use POSIX;
+use target::Samba;
+
+sub have_ads($) {
+        my ($self) = @_;
+       my $found_ads = 0;
+        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;
+}
 
 sub new($$) {
-       my ($classname, $bindir, $binary_mapping, $bindir_path, $srcdir, $exeext) = @_;
-       $exeext = "" unless defined($exeext);
+       my ($classname, $bindir, $binary_mapping, $srcdir, $server_maxtime) = @_;
        my $self = { vars => {},
                     bindir => $bindir,
                     binary_mapping => $binary_mapping,
-                    bindir_path => $bindir_path,
                     srcdir => $srcdir,
-                    exeext => $exeext
+                    server_maxtime => $server_maxtime
        };
        bless $self;
        return $self;
@@ -90,10 +106,16 @@ sub setup_env($$$)
 {
        my ($self, $envname, $path) = @_;
        
+       if (defined($self->{vars}->{$envname})) {
+               return $self->{vars}->{$envname};
+       }
+
        if ($envname eq "s3dc") {
                return $self->setup_s3dc("$path/s3dc");
        } elsif ($envname eq "secshare") {
                return $self->setup_secshare("$path/secshare");
+       } elsif ($envname eq "maptoguest") {
+               return $self->setup_maptoguest("$path/maptoguest");
        } elsif ($envname eq "ktest") {
                return $self->setup_ktest("$path/ktest");
        } elsif ($envname eq "secserver") {
@@ -111,7 +133,7 @@ sub setup_env($$$)
                }
                return $self->setup_member("$path/member", $self->{vars}->{s3dc});
        } else {
-               return undef;
+               return "UNKNOWN";
        }
 }
 
@@ -136,7 +158,6 @@ sub setup_s3dc($$)
        $vars or return undef;
 
        $self->check_or_start($vars,
-                             ($ENV{SMBD_MAXTIME} or 2700),
                               "yes", "yes", "yes");
 
        if (not $self->wait_for_start($vars)) {
@@ -172,17 +193,18 @@ sub setup_member($$$)
 
        $ret or return undef;
 
-       my $net = $self->{bindir_path}->($self, "net");
+       my $net = Samba::bindir_path($self, "net");
        my $cmd = "";
        $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
        $cmd .= "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member";
        $cmd .= " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}";
 
-       system($cmd) == 0 or die("Join failed\n$cmd");
+       if (system($cmd) != 0) {
+           warn("Join failed\n$cmd");
+           return undef;
+       }
 
-       $self->check_or_start($ret,
-                             ($ENV{SMBD_MAXTIME} or 2700),
-                              "yes", "yes", "yes");
+       $self->check_or_start($ret, "yes", "yes", "yes");
 
        if (not $self->wait_for_start($ret)) {
               return undef;
@@ -197,6 +219,82 @@ sub setup_member($$$)
        return $ret;
 }
 
+sub setup_admember($$$$)
+{
+       my ($self, $prefix, $dcvars, $iface) = @_;
+
+       # 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...";
+
+       my $member_options = "
+       security = ads
+       server signing = on
+        workgroup = $dcvars->{DOMAIN}
+        realm = $dcvars->{REALM}
+";
+
+       my $ret = $self->provision($prefix,
+                                  "LOCALADMEMBER$iface",
+                                  $iface,
+                                  "loCalMember${iface}Pass",
+                                  $member_options);
+
+       $ret or return undef;
+
+       close(USERMAP);
+       $ret->{DOMAIN} = $dcvars->{DOMAIN};
+       $ret->{REALM} = $dcvars->{REALM};
+
+       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;
+       }
+
+       # 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,
+                             "yes", "yes", "yes");
+
+       $self->wait_for_start($ret);
+
+       $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_secshare($$)
 {
        my ($self, $path) = @_;
@@ -216,9 +314,7 @@ sub setup_secshare($$)
 
        $vars or return undef;
 
-       $self->check_or_start($vars,
-                             ($ENV{SMBD_MAXTIME} or 2700),
-                              "yes", "no", "yes");
+       $self->check_or_start($vars, "yes", "no", "yes");
 
        if (not $self->wait_for_start($vars)) {
               return undef;
@@ -248,9 +344,7 @@ sub setup_secserver($$$)
 
        $ret or return undef;
 
-       $self->check_or_start($ret,
-                             ($ENV{SMBD_MAXTIME} or 2700),
-                              "yes", "no", "yes");
+       $self->check_or_start($ret, "yes", "no", "yes");
 
        if (not $self->wait_for_start($ret)) {
               return undef;
@@ -267,7 +361,12 @@ sub setup_secserver($$$)
 
 sub setup_ktest($$$)
 {
-       my ($self, $prefix, $s3dcvars) = @_;
+       my ($self, $prefix) = @_;
+
+       # If we didn't build with ADS, pretend this env was never available
+       if (not $self->have_ads()) {
+               return "UNKNOWN";
+       }
 
        print "PROVISIONING server with security=ads...";
 
@@ -276,6 +375,7 @@ sub setup_ktest($$$)
         realm = ktest.samba.example.com
        security = ads
         username map = $prefix/lib/username.map
+        server signing = required
 ";
 
        my $ret = $self->provision($prefix,
@@ -286,6 +386,18 @@ sub setup_ktest($$$)
 
        $ret or return undef;
 
+       my $ctx;
+       my $prefix_abs = abs_path($prefix);
+       $ctx = {};
+       $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
+       $ctx->{domain} = "KTEST";
+       $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
+       $ctx->{dnsname} = lc($ctx->{realm});
+       $ctx->{kdc_ipv4} = "0.0.0.0";
+       Samba::mk_krb5_conf($ctx, "");
+
+       $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
+
        open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
        print USERMAP "
 $ret->{USERNAME} = KTEST\\Administrator
@@ -330,9 +442,12 @@ $ret->{USERNAME} = KTEST\\Administrator
        system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
        chmod 0600, "$prefix/krb5_ccache-3";
 
-       $self->check_or_start($ret,
-                             ($ENV{SMBD_MAXTIME} or 2700),
-                              "yes", "no", "yes");
+       # We need world access to this share, as otherwise the domain
+       # administrator from the AD domain provided by ktest can't
+       # access the share for tests.
+       chmod 0777, "$prefix/share";
+
+       $self->check_or_start($ret, "yes", "no", "yes");
 
        if (not $self->wait_for_start($ret)) {
               return undef;
@@ -340,6 +455,36 @@ $ret->{USERNAME} = KTEST\\Administrator
        return $ret;
 }
 
+sub setup_maptoguest($$)
+{
+       my ($self, $path) = @_;
+
+       print "PROVISIONING maptoguest...";
+
+       my $options = "
+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)) {
+              return undef;
+       }
+
+       $self->{vars}->{s3maptoguest} = $vars;
+
+       return $vars;
+}
+
 sub stop_sig_term($$) {
        my ($self, $pid) = @_;
        kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
@@ -370,7 +515,12 @@ sub read_pid($$)
 }
 
 sub check_or_start($$$$$) {
-       my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
+       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...";
@@ -381,6 +531,7 @@ 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{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
 
@@ -388,13 +539,15 @@ sub check_or_start($$$$$) {
                $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";
+
                if ($nmbd ne "yes") {
                        $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
                                my $signame = shift;
                                print("Skip nmbd received signal $signame");
                                exit 0;
                        };
-                       sleep($maxtime);
+                       sleep($self->{server_maxtime});
                        exit 0;
                }
 
@@ -403,14 +556,17 @@ sub check_or_start($$$$$) {
                        @optargs = split(/ /, $ENV{NMBD_OPTIONS});
                }
 
-               $ENV{MAKE_TEST_BINARY} = $self->{bindir_path}->($self, "nmbd");
+               $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
 
-               my @preargs = ($self->{bindir_path}->($self, "timelimit"), $maxtime);
+               my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
                if(defined($ENV{NMBD_VALGRIND})) { 
                        @preargs = split(/ /, $ENV{NMBD_VALGRIND});
                }
 
-               exec(@preargs, $self->{bindir_path}->($self, "nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
+               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: $!");
        }
        write_pid($env_vars, "nmbd", $pid);
        print "DONE\n";
@@ -424,6 +580,7 @@ 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{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
 
@@ -431,13 +588,15 @@ sub check_or_start($$$$$) {
                $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";
+
                if ($winbindd ne "yes") {
                        $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
                                my $signame = shift;
                                print("Skip winbindd received signal $signame");
                                exit 0;
                        };
-                       sleep($maxtime);
+                       sleep($self->{server_maxtime});
                        exit 0;
                }
 
@@ -446,14 +605,19 @@ sub check_or_start($$$$$) {
                        @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
                }
 
-               $ENV{MAKE_TEST_BINARY} = $self->{bindir_path}->($self, "winbindd");
+               $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
 
-               my @preargs = ($self->{bindir_path}->($self, "timelimit"), $maxtime);
+               my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
                if(defined($ENV{WINBINDD_VALGRIND})) {
                        @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
                }
 
-               exec(@preargs, $self->{bindir_path}->($self, "winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
+               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: $!");
        }
        write_pid($env_vars, "winbindd", $pid);
        print "DONE\n";
@@ -467,6 +631,7 @@ 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{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
 
@@ -474,36 +639,44 @@ sub check_or_start($$$$$) {
                $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";
+
                if ($smbd ne "yes") {
                        $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
                                my $signame = shift;
                                print("Skip smbd received signal $signame");
                                exit 0;
                        };
-                       sleep($maxtime);
+                       sleep($self->{server_maxtime});
                        exit 0;
                }
 
-               $ENV{MAKE_TEST_BINARY} = $self->{bindir_path}->($self, "smbd");
+               $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
                my @optargs = ("-d0");
                if (defined($ENV{SMBD_OPTIONS})) {
                        @optargs = split(/ /, $ENV{SMBD_OPTIONS});
                }
-               my @preargs = ($self->{bindir_path}->($self, "timelimit"), $maxtime);
+               my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
                if(defined($ENV{SMBD_VALGRIND})) {
                        @preargs = split(/ /,$ENV{SMBD_VALGRIND});
                }
-               exec(@preargs, $self->{bindir_path}->($self, "smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
+
+               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: $!");
        }
        write_pid($env_vars, "smbd", $pid);
        print "DONE\n";
 
+       close(STDIN_READER);
+
        return 0;
 }
 
-sub provision($$$$$$)
+sub provision($$$$$$$)
 {
-       my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
+       my ($self, $prefix, $server, $swiface, $password, $extra_options, $no_delete_prefix) = @_;
 
        ##
        ## setup the various environment variables we need
@@ -523,6 +696,8 @@ sub provision($$$$$$)
        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";
+
        my @dirs = ();
 
        my $shrdir="$prefix_abs/share";
@@ -579,7 +754,9 @@ sub provision($$$$$$)
 
        mkdir($prefix_abs, 0777);
        print "CREATE TEST ENVIRONMENT IN '$prefix'...";
-       system("rm -rf $prefix_abs/*");
+       if (not defined($no_delete_prefix) or not $no_delete_prefix) {
+           system("rm -rf $prefix_abs/*");
+       }
        mkdir($_, 0777) foreach(@dirs);
 
        ##
@@ -588,12 +765,18 @@ sub provision($$$$$$)
 
        chmod 0755, $ro_shrdir;
        my $unreadable_file = "$ro_shrdir/unreadable_file";
-       open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
+       unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
+               warn("Unable to open $unreadable_file");
+               return undef;
+       }
        close(UNREADABLE_FILE);
        chmod 0600, $unreadable_file;
 
        my $msdfs_target = "$ro_shrdir/msdfs-target";
-       open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
+       unless (open(MSDFS_TARGET, ">$msdfs_target")) {
+               warn("Unable to open $msdfs_target");
+               return undef;
+       }
        close(MSDFS_TARGET);
        chmod 0666, $msdfs_target;
        symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
@@ -641,7 +824,10 @@ sub provision($$$$$$)
        ## create conffile
        ##
 
-       open(CONF, ">$conffile") or die("Unable to open $conffile");
+       unless (open(CONF, ">$conffile")) {
+               warn("Unable to open $conffile");
+               return undef;
+       }
        print CONF "
 [global]
        netbios name = $server
@@ -655,12 +841,10 @@ 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
 
-       name resolve order = bcast
-
        state directory = $lockdir
        cache directory = $lockdir
 
@@ -707,6 +891,7 @@ sub provision($$$$$$)
        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
 
        printing = vlp
@@ -719,8 +904,23 @@ sub provision($$$$$$)
        queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
        lpq cache time = 0
 
-       ncalrpc dir = $lockdir/ncalrpc
-       rpc_server:epmapper = embedded
+       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
+        # sending messages works, and that the %m sub works.
+        message command = mv %s $shrdir/message.%m
 
        # Begin extra options
        $extra_options
@@ -736,6 +936,7 @@ sub provision($$$$$$)
        print CONF "
 [tmp]
        path = $shrdir
+        comment = smb username is [%U]
 [tmpguest]
        path = $shrdir
         guest ok = yes
@@ -777,6 +978,11 @@ sub provision($$$$$$)
        copy = print1
 [lp]
        copy = print1
+[xcopy_share]
+       path = $shrdir
+       comment = smb username is [%U]
+       create mask = 777
+       force create mode = 777
 [print\$]
        copy = tmp
        ";
@@ -786,7 +992,10 @@ sub provision($$$$$$)
        ## create a test account
        ##
 
-       open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
+       unless (open(PASSWD, ">$nss_wrapper_passwd")) {
+           warn("Unable to open $nss_wrapper_passwd");
+           return undef;
+        } 
        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
 ";
@@ -795,7 +1004,10 @@ $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
        }
        close(PASSWD);
 
-       open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
+       unless (open(GROUP, ">$nss_wrapper_group")) {
+             warn("Unable to open $nss_wrapper_group");
+             return undef;
+        }
        print GROUP "nobody:x:$gid_nobody:
 nogroup:x:$gid_nogroup:nobody
 $unix_name-group:x:$unix_gids[0]:
@@ -816,10 +1028,16 @@ domusers:X:$gid_domusers:
        $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
        $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
 
-       open(PWD, "|".$self->{bindir_path}->($self, "smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
+        my $cmd = Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
+       unless (open(PWD, "|$cmd")) {
+             warn("Unable to set password for test account\n$cmd");
+             return undef;
+        }
        print PWD "$password\n$password\n";
-       close(PWD) or die("Unable to set password for test account");
-
+       unless (close(PWD)) {
+             warn("Unable to set password for test account\n$cmd");
+             return undef; 
+        }
        print "DONE\n";
 
        open(HOSTS, ">>$ENV{SELFTEST_PREFIX}/dns_host_file") or die("Unable to open $ENV{SELFTEST_PREFIX}/dns_host_file");
@@ -851,7 +1069,7 @@ domusers:X:$gid_domusers:
        $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} = $self->{bindir_path}->($self, "default/nsswitch/libnss-winbind.so");
+               $ret{NSS_WRAPPER_WINBIND_SO_PATH} = Samba::bindir_path($self, "default/nsswitch/libnss-winbind.so");
         }
        $ret{LOCAL_PATH} = "$shrdir";
 
@@ -866,11 +1084,11 @@ sub wait_for_start($$)
        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($self->{bindir_path}->($self, "nmblookup3") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
-       system($self->{bindir_path}->($self, "nmblookup3") ." $envvars->{CONFIGURATION} __SAMBA__");
-       system($self->{bindir_path}->($self, "nmblookup3") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
-       system($self->{bindir_path}->($self, "nmblookup3") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
-       system($self->{bindir_path}->($self, "nmblookup3") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
+       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}");
 
        # make sure smbd is also up set
        print "wait for smbd\n";
@@ -878,7 +1096,7 @@ sub wait_for_start($$)
        my $count = 0;
        my $ret;
        do {
-           $ret = system($self->{bindir_path}->($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
+           $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
            if ($ret != 0) {
                sleep(2);
            }
@@ -890,7 +1108,7 @@ sub wait_for_start($$)
            return 0;
        }
        # Ensure we have domain users mapped.
-       $ret = system($self->{bindir_path}->($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
+       $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
        if ($ret != 0) {
            return 1;
        }