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 505130f..9d74e7d
@@ -11,14 +11,29 @@ 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, $srcdir, $exeext, $server_maxtime) = @_;
-       $exeext = "" unless defined($exeext);
+       my ($classname, $bindir, $binary_mapping, $srcdir, $server_maxtime) = @_;
        my $self = { vars => {},
                     bindir => $bindir,
                     binary_mapping => $binary_mapping,
                     srcdir => $srcdir,
-                    exeext => $exeext,
                     server_maxtime => $server_maxtime
        };
        bless $self;
@@ -91,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") {
@@ -112,7 +133,7 @@ sub setup_env($$$)
                }
                return $self->setup_member("$path/member", $self->{vars}->{s3dc});
        } else {
-               return undef;
+               return "UNKNOWN";
        }
 }
 
@@ -202,6 +223,11 @@ 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 = "
@@ -231,7 +257,7 @@ sub setup_admember($$$$)
        $ctx->{realm} = $dcvars->{REALM};
        $ctx->{dnsname} = lc($dcvars->{REALM});
        $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
-       Samba::mk_krb5_conf($ctx);
+       Samba::mk_krb5_conf($ctx, "");
 
        $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
 
@@ -269,54 +295,6 @@ 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: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", "yes", "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) = @_;
@@ -385,6 +363,11 @@ sub setup_ktest($$$)
 {
        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...";
 
        my $ktest_options = "
@@ -392,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,
@@ -410,7 +394,7 @@ sub setup_ktest($$$)
        $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
        $ctx->{dnsname} = lc($ctx->{realm});
        $ctx->{kdc_ipv4} = "0.0.0.0";
-       Samba::mk_krb5_conf($ctx);
+       Samba::mk_krb5_conf($ctx, "");
 
        $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
 
@@ -424,11 +408,7 @@ $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
 
-       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");
-       }
+       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:
@@ -462,6 +442,11 @@ $ret->{USERNAME} = KTEST\\Administrator
        system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
        chmod 0600, "$prefix/krb5_ccache-3";
 
+       # 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)) {
@@ -470,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: $!");
@@ -499,9 +514,14 @@ sub read_pid($$)
        return $pid;
 }
 
-sub check_or_start($$$$) {
+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();
@@ -519,6 +539,8 @@ 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;
@@ -541,6 +563,9 @@ 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: $!");
        }
        write_pid($env_vars, "nmbd", $pid);
@@ -563,6 +588,8 @@ 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;
@@ -585,7 +612,10 @@ sub check_or_start($$$$) {
                        @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
                }
 
-               print "Starting winbindd with config $env_vars->{SERVERCONFFILE})\n";
+               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: $!");
        }
@@ -609,6 +639,8 @@ 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;
@@ -628,11 +660,17 @@ 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: $!");
        }
        write_pid($env_vars, "smbd", $pid);
        print "DONE\n";
 
+       close(STDIN_READER);
+
        return 0;
 }
 
@@ -803,7 +841,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
 
@@ -853,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
@@ -866,10 +905,21 @@ sub provision($$$$$$$)
        lpq cache time = 0
 
        ncalrpc dir = $prefix_abs/ncalrpc
-       rpc_server:epmapper = embedded
+       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
@@ -886,6 +936,7 @@ sub provision($$$$$$$)
        print CONF "
 [tmp]
        path = $shrdir
+        comment = smb username is [%U]
 [tmpguest]
        path = $shrdir
         guest ok = yes
@@ -927,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
        ";