s3-lsasd: Listen on \PIPE\lsass.
[idra/samba.git] / selftest / target / Samba3.pm
old mode 100644 (file)
new mode 100755 (executable)
index 6312d65..bc8105a
@@ -95,6 +95,8 @@ sub setup_env($$$)
                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") {
@@ -247,24 +249,16 @@ sub setup_admember($$$$)
            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);
 
-       my $smbcacls = Samba::bindir_path($self, "smbcacls");
-       #Allow domain users to manipulate the share
-       $cmd = "";
-       $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
-       $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
-       $cmd .= "$smbcacls $ret->{CONFIGURATION} //127.0.0.29/tmp / -U$ret->{USERNAME}%$ret->{PASSWORD} ";
-       $cmd .= "-S ACL:$dcvars->{DOMAIN}\\\\Domain\\ Users:ALLOWED/0x0/FULL";
-
-       if (system($cmd) != 0) {
-           warn("smbcacls failed, your filesystem may not support ACLs.  Try mount $prefix_abs -oremount,acl\nThis support is required for S3 member in S4 tests\n$cmd");
-           return undef;
-       }
-
        $ret->{DC_SERVER} = $dcvars->{SERVER};
        $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
        $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
@@ -277,6 +271,59 @@ 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
+        passdb backend = samba4
+        auth methods = guest samba4
+        domain logons = yes
+        rpc_server:epmapper = external
+        rpc_daemon:epmd = disabled
+        rpc_daemon:lsasd = disabled
+        rpc_server:tcpip = no
+        rpc_server:lsass = external
+        rpc_server:lsarpc = external
+        rpc_server:netlogon = external
+        rpc_server:samr = external
+       server signing = on
+";
+
+       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($$)
 {
        my ($self, $path) = @_;
@@ -384,7 +431,11 @@ $ret->{USERNAME} = KTEST\\Administrator
 #Samba4 DC with the same parameters as are being used here.  The
 #domain SID is S-1-5-21-1071277805-689288055-3486227160
 
-       system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
+       if (defined($ENV{BUILD_TDB2})) {
+           system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb2 $prefix/private/secrets.tdb");
+       } else {
+           system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
+       }
        chmod 0600, "$prefix/private/secrets.tdb";
 
 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
@@ -426,6 +477,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: $!");
@@ -592,9 +673,9 @@ sub check_or_start($$$$) {
        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
@@ -672,7 +753,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);
 
        ##
@@ -681,12 +764,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";
@@ -734,7 +823,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
@@ -810,11 +902,25 @@ 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:lsass = 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
        # End extra options
@@ -829,6 +935,7 @@ sub provision($$$$$$)
        print CONF "
 [tmp]
        path = $shrdir
+        comment = smb username is [%U]
 [tmpguest]
        path = $shrdir
         guest ok = yes
@@ -879,7 +986,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
 ";
@@ -888,7 +998,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]:
@@ -909,10 +1022,16 @@ domusers:X:$gid_domusers:
        $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
        $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
 
-       open(PWD, "|".Samba::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");