selftest: run smbtorture_s3 tests against the ntvfs file server
[kai/samba.git] / selftest / target / Samba4.pm
index 52c6d680d739de07301c8071984be4553e4a3e00..698cd127a054eb05ea9802f20c35d7ba4a131755 100644 (file)
@@ -85,18 +85,18 @@ sub slapd_stop($$)
 
 sub check_or_start($$$)
 {
-       my ($self, $env_vars, $process_model) = @_;
-       return 0 if ( -p $env_vars->{SAMBA_TEST_FIFO});
+        my ($self, $env_vars, $process_model) = @_;
 
-       unlink($env_vars->{SAMBA_TEST_FIFO});
-       POSIX::mkfifo($env_vars->{SAMBA_TEST_FIFO}, 0700);
-       unlink($env_vars->{SAMBA_TEST_LOG});
-       
-       my $pwd = `pwd`;
-       print "STARTING SAMBA for $ENV{ENVNAME}\n";
+       return 0 if $self->check_env($env_vars);
+
+       # 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});
+
+       print "STARTING SAMBA...";
        my $pid = fork();
        if ($pid == 0) {
-               open STDIN, $env_vars->{SAMBA_TEST_FIFO};
                # we want out from samba to go to the log file, but also
                # to the users terminal when running 'make test' on the command
                # line. This puts it on stderr on the terminal
@@ -105,59 +105,35 @@ sub check_or_start($$$)
 
                SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
 
-               my $valgrind = "";
-               if (defined($ENV{SAMBA_VALGRIND})) {
-                   $valgrind = $ENV{SAMBA_VALGRIND};
-               }
-
                $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};
 
                $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
                $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";
 
-               # Start slapd before samba, but with the fifo on stdin
-               if (defined($self->{ldap})) {
-                       unless($self->slapd_start($env_vars)) {
-                               warn("couldn't start slapd (main run)");
-                               return undef;
-                       }
-               }
-
-               my $optarg = "";
-               $optarg = "--maximum-runtime=$self->{server_maxtime}";
+               $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
+               my @preargs = ();
+               my @optargs = ();
                if (defined($ENV{SAMBA_OPTIONS})) {
-                       $optarg.= " $ENV{SAMBA_OPTIONS}";
-               }
-               my $samba =  Samba::bindir_path($self, "samba");
-
-               chomp($pwd);
-               my $cmdline = "$valgrind ${pwd}/$samba $optarg $env_vars->{CONFIGURATION} -M $process_model -i";
-               my $ret = system("$cmdline");
-               if ($ret == -1) {
-                       print "Unable to start $cmdline: $ret: $!\n";
-                       exit 1;
+                       @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
                }
-               my $exit = ($ret >> 8);
-               unlink($env_vars->{SAMBA_TEST_FIFO});
-               if ($ret == 0) {
-                       print "$samba exited with no error\n";
-                       exit 0;
-               } elsif ( $ret & 127 ) {
-                       print "$samba got signal ".($ret & 127)." and exits with $exit!\n";
-               } else {
-                       print "$samba failed with status $exit!\n";
+               if(defined($ENV{SAMBA_VALGRIND})) {
+                       @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
                }
-               if ($exit == 0) {
-                       $exit = -1;
-               }
-               exit $exit;
+
+               close($env_vars->{STDIN_PIPE});
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
+               exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
        }
+       $env_vars->{SAMBA_PID} = $pid;
        print "DONE\n";
 
-       open(DATA, ">$env_vars->{SAMBA_TEST_FIFO}");
+       close(STDIN_READER);
 
        return $pid;
 }
@@ -444,11 +420,11 @@ Wfz/8alZ5aMezCQzXJyIaJsCLeKABosSwHcpAFmxlQ==
 EOF
 }
 
-sub provision_raw_prepare($$$$$$$$$$)
+sub provision_raw_prepare($$$$$$$$$)
 {
        my ($self, $prefix, $server_role, $hostname,
            $domain, $realm, $functional_level,
-           $swiface, $password, $kdc_ipv4) = @_;
+           $password, $kdc_ipv4) = @_;
        my $ctx;
        my $netbiosname = uc($hostname);
 
@@ -465,6 +441,9 @@ sub provision_raw_prepare($$$$$$$$$$)
                warn("Unable to clean up");
        }
 
+       
+       my $swiface = Samba::get_interface($hostname);
+
        $ctx->{prefix} = $prefix;
        $ctx->{prefix_abs} = $prefix_abs;
        
@@ -700,6 +679,8 @@ nogroup:x:65534:nobody
                SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
                SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
                SAMBA_TEST_LOG_POS => 0,
+               NSS_WRAPPER_WINBIND_SO_PATH => Samba::bindir_path($self, "default/nsswitch/libnss-winbind.so"),
+                LOCAL_PATH => $ctx->{tmpdir}
        };
 
        return $ret;
@@ -721,16 +702,16 @@ sub provision_raw_step2($$$)
        return $ret;
 }
 
-sub provision($$$$$$$$$)
+sub provision($$$$$$$$)
 {
        my ($self, $prefix, $server_role, $hostname,
            $domain, $realm, $functional_level,
-           $swiface, $password, $kdc_ipv4, $extra_smbconf_options) = @_;
+           $password, $kdc_ipv4, $extra_smbconf_options) = @_;
 
        my $ctx = $self->provision_raw_prepare($prefix, $server_role,
                                               $hostname,
                                               $domain, $realm, $functional_level,
-                                              $swiface, $password, $kdc_ipv4);
+                                              $password, $kdc_ipv4);
 
        $ctx->{tmpdir} = "$ctx->{prefix_abs}/tmp";
        push(@{$ctx->{directories}}, "$ctx->{tmpdir}");
@@ -760,6 +741,8 @@ sub provision($$$$$$$$$)
        posix:sharedelay = 10000
        posix:oplocktimeout = 3
        posix:writetimeupdatedelay = 500000
+       create mask = 777
+       force create mode = 777
 
 [test1]
        path = $ctx->{tmpdir}/test1
@@ -853,7 +836,6 @@ sub provision_member($$$)
                                   "SAMBADOMAIN",
                                   "samba.example.com",
                                   "2008",
-                                  23,
                                   "locMEMpass3",
                                   $dcvars->{SERVER_IP},
                                   "");
@@ -919,7 +901,6 @@ sub provision_rpc_proxy($$$)
                                   "SAMBADOMAIN",
                                   "samba.example.com",
                                   "2008",
-                                  24,
                                   "locRPCproxypass4",
                                   $dcvars->{SERVER_IP},
                                   $extra_smbconf_options);
@@ -993,7 +974,7 @@ sub provision_vampire_dc($$$)
                                               "SAMBADOMAIN",
                                               "samba.example.com",
                                               "2008",
-                                              22, $dcvars->{PASSWORD},
+                                              $dcvars->{PASSWORD},
                                               $dcvars->{SERVER_IP});
 
        $ctx->{smb_conf_extra_options} = "
@@ -1052,7 +1033,7 @@ sub provision_subdom_dc($$$)
                                               "SAMBASUBDOM",
                                               "sub.samba.example.com",
                                               "2008",
-                                              31, $dcvars->{PASSWORD},
+                                              $dcvars->{PASSWORD},
                                               undef);
 
        $ctx->{smb_conf_extra_options} = "
@@ -1115,7 +1096,6 @@ sub provision_dc($$)
                                   "SAMBADOMAIN",
                                   "samba.example.com",
                                   "2008",
-                                  21,
                                   "locDCpass1",
                                   undef, "netbios aliases = localDC1-a");
 
@@ -1145,7 +1125,6 @@ sub provision_fl2000dc($$)
                                   "SAMBA2000",
                                   "samba2000.example.com",
                                   "2000",
-                                  25,
                                   "locDCpass5",
                                   undef, "");
 
@@ -1168,7 +1147,6 @@ sub provision_fl2003dc($$)
                                   "SAMBA2003",
                                   "samba2003.example.com",
                                   "2003",
-                                  26,
                                   "locDCpass6",
                                   undef, "");
 
@@ -1191,7 +1169,6 @@ sub provision_fl2008r2dc($$)
                                   "SAMBA2008R2",
                                   "samba2008R2.example.com",
                                   "2008_R2",
-                                  27,
                                   "locDCpass7",
                                   undef, "");
 
@@ -1215,7 +1192,7 @@ sub provision_rodc($$$)
                                               "SAMBADOMAIN",
                                               "samba.example.com",
                                               "2008",
-                                              28, $dcvars->{PASSWORD},
+                                              $dcvars->{PASSWORD},
                                               $dcvars->{SERVER_IP});
        unless ($ctx) {
                return undef;
@@ -1287,8 +1264,12 @@ sub provision_plugin_s4_dc($$)
        my ($self, $prefix) = @_;
 
        my $extra_smbconf_options = "
-server services = -smb
-dcerpc endpoint servers = -unixinfo -rpcecho -spoolss -winreg -wkssvc -srvsvc
+server services = -smb +s3fs
+dcerpc endpoint servers = -unixinfo -spoolss -winreg -wkssvc -srvsvc
+
+[IPC\$]
+       vfs objects = dfs_samba4
+
 ";
 
        print "PROVISIONING PLUGIN S4 DC...";
@@ -1298,7 +1279,6 @@ dcerpc endpoint servers = -unixinfo -rpcecho -spoolss -winreg -wkssvc -srvsvc
                                   "PLUGINDOMAIN",
                                   "plugin.samba.example.com",
                                   "2008",
-                                  30,
                                   "locDCpass1",
                                   undef, $extra_smbconf_options);
 
@@ -1317,41 +1297,80 @@ dcerpc endpoint servers = -unixinfo -rpcecho -spoolss -winreg -wkssvc -srvsvc
        return $ret;
 }
 
+sub provision_chgdcpass($$)
+{
+       my ($self, $prefix) = @_;
+
+       print "PROVISIONING CHGDCPASS...";
+       my $ret = $self->provision($prefix,
+                                  "domain controller",
+                                  "chgdcpass",
+                                  "CHDCDOMAIN",
+                                  "chgdcpassword.samba.example.com",
+                                  "2008",
+                                  "chgDCpass1",
+                                  undef);
+
+       return undef unless(defined $ret);
+       unless($self->add_wins_config("$prefix/private")) {
+               warn("Unable to add wins configuration");
+               return undef;
+       }
+       $ret->{DC_SERVER} = $ret->{SERVER};
+       $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
+       $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
+       $ret->{DC_USERNAME} = $ret->{USERNAME};
+       $ret->{DC_PASSWORD} = $ret->{PASSWORD};
+
+       return $ret;
+}
+
 sub teardown_env($$)
 {
        my ($self, $envvars) = @_;
        my $pid;
 
-       close(DATA);
+       # This should cause samba to terminate gracefully
+       close($envvars->{STDIN_PIPE});
 
-       if (open(IN, "<$envvars->{PIDDIR}/samba.pid")) {
-               $pid = <IN>;
-               close(IN);
+       $pid = $envvars->{SAMBA_PID};
+       my $count = 0;
+       my $childpid;
+
+       # This should give it time to write out the gcov data
+       until ($count > 20) {
+           if (Samba::cleanup_child($pid, "samba") == -1) {
+               last;
+           }
+           sleep(1);
+           $count++;
+       }
 
-               # Give the process 20 seconds to exit.  gcov needs
-               # this time to write out the covarge data
-               my $count = 0;
-               until (kill(0, $pid) == 0) {
-                       # if no process sucessfully signalled, then we are done
-                       sleep(1);
-                       $count++;
-                       last if $count > 20;
-               }
+       if ($count <= 20 && kill(0, $pid) == 0) {
+           return;
+       }
 
-               # If it is still around, kill it
-               if ($count > 20) {
-                       print "server process $pid took more than $count seconds to exit, killing\n";
-                       kill 9, $pid;
-               }
+       kill "TERM", $pid;
+
+       until ($count > 20) {
+           if (Samba::cleanup_child($pid, "samba") == -1) {
+               last;
+           }
+           sleep(1);
+           $count++;
        }
 
-       my $failed = $? >> 8;
+       # If it is still around, kill it
+       if ($count > 20 && kill(0, $pid) == 0) {
+           warn "server process $pid took more than $count seconds to exit, killing\n";
+           kill 9, $pid;
+       }
 
        $self->slapd_stop($envvars) if ($self->{ldap});
 
        print $self->getlog_env($envvars);
 
-       return $failed;
+       return;
 }
 
 sub getlog_env($$)
@@ -1378,7 +1397,9 @@ sub check_env($$)
 {
        my ($self, $envvars) = @_;
 
-       return (-p $envvars->{SAMBA_TEST_FIFO});
+       my $childpid = Samba::cleanup_child($envvars->{SAMBA_PID}, "samba");
+
+       return ($childpid == 0);
 }
 
 sub setup_env($$$)
@@ -1388,6 +1409,10 @@ sub setup_env($$$)
 
        $ENV{ENVNAME} = $envname;
 
+       if (defined($self->{vars}->{$envname})) {
+               return $self->{vars}->{$envname};
+       }
+
        if ($envname eq "dc") {
                return $self->setup_dc("$path/dc");
        } elsif ($envname eq "fl2000dc") {
@@ -1421,6 +1446,8 @@ sub setup_env($$$)
                        $self->setup_dc("$path/dc");
                }
                return $self->setup_rodc("$path/rodc", $self->{vars}->{dc});
+       } elsif ($envname eq "chgdcpass") {
+               return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
        } elsif ($envname eq "s3member") {
                if (not defined($self->{vars}->{dc})) {
                        $self->setup_dc("$path/dc");
@@ -1429,7 +1456,7 @@ sub setup_env($$$)
        } elsif ($envname eq "plugin_s4_dc") {
                return $self->setup_plugin_s4_dc("$path/plugin_s4_dc");
        } else {
-               return undef;
+               return "UNKNOWN";
        }
 }
 
@@ -1481,6 +1508,21 @@ sub setup_dc($$)
        return $env;
 }
 
+sub setup_chgdcpass($$)
+{
+       my ($self, $path) = @_;
+
+       my $env = $self->provision_chgdcpass($path);
+       if (defined $env) {
+               $self->check_or_start($env, "single");
+
+               $self->wait_for_start($env);
+
+               $self->{vars}->{chgdcpass} = $env;
+       }
+       return $env;
+}
+
 sub setup_fl2000dc($$)
 {
        my ($self, $path) = @_;
@@ -1658,19 +1700,21 @@ sub setup_plugin_s4_dc($$)
 {
        my ($self, $path) = @_;
 
-       my $env = $self->provision_plugin_s4_dc($path);
-       if (defined $env) {
-               $self->check_or_start($env, "single");
-
-               $self->wait_for_start($env);
-
-               my $s3_part_env = $self->{target3}->setup_plugin_s4_dc($path, $env, 30);
-               if (not defined($s3_part_env)) {
-                   return undef;
-               }
+       # If we didn't build with ADS, pretend this env was never available
+       if (not $self->{target3}->have_ads()) {
+              return "UNKNOWN";
+       }
 
-               $self->{vars}->{plugin_s4_dc} = $s3_part_env;
+       my $env = $self->provision_plugin_s4_dc($path);
+       unless ($env) {
+               return undef;
        }
+
+       $self->check_or_start($env, "single");
+       
+       $self->wait_for_start($env);
+       
+       $self->{vars}->{plugin_s4_dc} = $env;
        return $env;
 }