From ad5bb10f707dddc0cea159af09393520128157d7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 23:04:57 +0100 Subject: python: Build shared python modules for generic use. (This used to be commit 502424955237ace5a276d4c91c62e95233ecd978) --- source4/build/smb_build/input.pm | 2 +- source4/build/smb_build/makefile.pm | 6 ++++-- source4/scripting/python/config.mk | 10 ++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source4/build/smb_build/input.pm b/source4/build/smb_build/input.pm index 6d5c4f4a1e..0b26aee65e 100644 --- a/source4/build/smb_build/input.pm +++ b/source4/build/smb_build/input.pm @@ -182,7 +182,7 @@ sub check_python($$$) $python->{SUBSYSTEM} = "LIBPYTHON"; - check_module($INPUT, $python, $default_ot); + check_module($INPUT, $python, ["SHARED_LIBRARY", "STATIC_LIBRARY"]); } sub check_binary($$) diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 0e7771c3f2..ce1e757c61 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -27,6 +27,7 @@ sub new($$$) $self->{torture_progs} = []; $self->{static_libs} = []; $self->{python_dsos} = []; + $self->{python_pys} = []; $self->{shared_libs} = []; $self->{installable_shared_libs} = []; $self->{headers} = []; @@ -345,7 +346,7 @@ sub SharedModule($$) push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)"); - if (defined($ctx->{INIT_FUNCTION})) { + if (defined($ctx->{INIT_FUNCTION}) and $ctx->{TYPE} ne "PYTHON") { my $init_fn = $ctx->{INIT_FUNCTION_TYPE}; $init_fn =~ s/\(\*\)/init_module/; my $proto_fn = $ctx->{INIT_FUNCTION_TYPE}; @@ -539,7 +540,7 @@ sub PythonFiles($$) $self->output("$target: $source\n" . "\tmkdir -p \$(builddir)/bin/python\n" . "\tcp $source \$@\n\n"); - push (@{$self->{python_dsos}}, $target); + push (@{$self->{python_pys}}, $target); } } @@ -714,6 +715,7 @@ sub write($$) $self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n"); $self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n"); $self->output("PYTHON_DSOS = " . array2oneperline($self->{python_dsos}) . "\n"); + $self->output("PYTHON_PYS = " . array2oneperline($self->{python_pys}) . "\n"); $self->output("INSTALLABLE_SHARED_LIBS = " . array2oneperline($self->{installable_shared_libs}) . "\n"); $self->output("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n"); $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n"); diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk index f00b477919..450da0e90a 100644 --- a/source4/scripting/python/config.mk +++ b/source4/scripting/python/config.mk @@ -16,7 +16,7 @@ PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS SWIG_FILE = misc.i # Swig extensions -swig: pythonmods +swig:: pythonmods .SUFFIXES: _wrap.c .i @@ -28,13 +28,19 @@ realdistclean:: @-rm -f bin/python/* # FIXME: Remove _wrap.c files -pythonmods: $(PYTHON_DSOS) +pythonmods:: $(PYTHON_DSOS) $(PYTHON_PYS) PYDOCTOR_MODULES=bin/python/ldb.py bin/python/auth.py bin/python/credentials.py bin/python/registry.py bin/python/tdb.py bin/python/security.py bin/python/events.py bin/python/net.py pydoctor:: pythonmods LD_LIBRARY_PATH=bin/shared PYTHONPATH=bin/python pydoctor --make-html --docformat=restructuredtext --add-package scripting/python/samba/ $(addprefix --add-module , $(PYDOCTOR_MODULES)) +installpython:: pythonmods + @$(SHELL) $(srcdir)/script/installpython.sh \ + $(INSTALLPERMS) \ + $(DESTDIR)$(PYTHONDIR) \ + scripting/python bin/python + clean:: @echo "Removing python modules" @rm -f bin/python/* -- cgit From 39cc507d1b7b0454d8f380fc3127fa966a0f972c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 14:54:29 +0100 Subject: pidl: Fix imported function for ServerNDR and add test to make sure it doesn't regress again. (This used to be commit 0e036948307c8ca5013e20a17a10d109830e4df1) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 2 +- source4/pidl/tests/samba3-srv.pl | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 source4/pidl/tests/samba3-srv.pl diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 47312bc83d..ecc43ab896 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -12,7 +12,7 @@ use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(ElementStars DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionOutEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionOutEnv); use vars qw($VERSION); $VERSION = '0.01'; diff --git a/source4/pidl/tests/samba3-srv.pl b/source4/pidl/tests/samba3-srv.pl new file mode 100644 index 0000000000..dc96518fd0 --- /dev/null +++ b/source4/pidl/tests/samba3-srv.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +# (C) 2008 Jelmer Vernooij +# Published under the GNU General Public License +use strict; +use warnings; + +use Test::More tests => 0; +use FindBin qw($RealBin); +use lib "$RealBin"; +use Util; +use Parse::Pidl::Util qw(MyDumper); +use Parse::Pidl::Samba3::ServerNDR; + + -- cgit From af163d258cfeee2a908e297256570a2bfcc8b651 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 15:06:46 +0100 Subject: pidl: Fix missing import for fatal(). (This used to be commit 6a9827454aaf4279ee85dc5d99d10f14e4c09eae) --- source4/pidl/lib/Parse/Pidl/Samba4.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4.pm b/source4/pidl/lib/Parse/Pidl/Samba4.pm index 5848543a60..d42e01cdb0 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4.pm @@ -12,6 +12,7 @@ require Exporter; use Parse::Pidl::Util qw(has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); +use Parse::Pidl qw(fatal); use strict; use vars qw($VERSION); -- cgit From 3e53ad6f4a5767fd1a26a35a0060b03a6e77161c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 15:07:00 +0100 Subject: pidl: Add simple test for ServerNDR. (This used to be commit 5b2ea43ed8613ac10ebe7feda0cf070c8079137a) --- source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 4 ++++ source4/pidl/tests/samba3-srv.pl | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index ecc43ab896..ca9e7d15db 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -6,6 +6,10 @@ package Parse::Pidl::Samba3::ServerNDR; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(DeclLevel); + use strict; use Parse::Pidl qw(warning fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); diff --git a/source4/pidl/tests/samba3-srv.pl b/source4/pidl/tests/samba3-srv.pl index dc96518fd0..d1e2bc9545 100644 --- a/source4/pidl/tests/samba3-srv.pl +++ b/source4/pidl/tests/samba3-srv.pl @@ -4,11 +4,15 @@ use strict; use warnings; -use Test::More tests => 0; +use Test::More tests => 1; use FindBin qw($RealBin); use lib "$RealBin"; use Util; -use Parse::Pidl::Util qw(MyDumper); -use Parse::Pidl::Samba3::ServerNDR; +use Parse::Pidl::Util qw(MyDumper has_property); +use Parse::Pidl::Samba3::ServerNDR qw(DeclLevel); +my $l = { TYPE => "DATA", DATA_TYPE => "uint32" }; +my $e = { FILE => "foo", LINE => 0, PROPERTIES => { }, TYPE => "uint32", + LEVELS => [ $l ] }; +is("uint32_t", DeclLevel($e, 0)); -- cgit From e3fb56d183c03a93c2f2bfed1df17cfe8be4f47f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 16 Jan 2008 16:01:50 +0100 Subject: Add lsa_PolicyAuditEventType and lsa_PolicyAuditPolicy enums from samba3 to IDL. Guenther (This used to be commit 1b5706e413f1c6aa1ede15a625929f785ce37272) --- source4/librpc/idl/lsa.idl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source4/librpc/idl/lsa.idl b/source4/librpc/idl/lsa.idl index 705c86e39b..8d26ec0aad 100644 --- a/source4/librpc/idl/lsa.idl +++ b/source4/librpc/idl/lsa.idl @@ -138,9 +138,29 @@ import "security.idl"; uint32 unknown; } lsa_AuditLogInfo; + typedef [v1_enum] enum { + LSA_AUDIT_POLICY_NONE=0, + LSA_AUDIT_POLICY_SUCCESS=1, + LSA_AUDIT_POLICY_FAILURE=2, + LSA_AUDIT_POLICY_ALL=(LSA_AUDIT_POLICY_SUCCESS|LSA_AUDIT_POLICY_FAILURE), + LSA_AUDIT_POLICY_CLEAR=4 + } lsa_PolicyAuditPolicy; + + typedef enum { + LSA_AUDIT_CATEGORY_SYSTEM = 0, + LSA_AUDIT_CATEGORY_LOGON = 1, + LSA_AUDIT_CATEGORY_FILE_AND_OBJECT_ACCESS = 2, + LSA_AUDIT_CATEGORY_USE_OF_USER_RIGHTS = 3, + LSA_AUDIT_CATEGORY_PROCCESS_TRACKING = 4, + LSA_AUDIT_CATEGORY_SECURITY_POLICY_CHANGES = 5, + LSA_AUDIT_CATEGORY_ACCOUNT_MANAGEMENT = 6, + LSA_AUDIT_CATEGORY_DIRECTORY_SERVICE_ACCESS = 7, /* only in win2k/2k3 */ + LSA_AUDIT_CATEGORY_ACCOUNT_LOGON = 8 /* only in win2k/2k3 */ + } lsa_PolicyAuditEventType; + typedef struct { uint32 auditing_mode; - [size_is(count)] uint32 *settings; + [size_is(count)] lsa_PolicyAuditPolicy *settings; uint32 count; } lsa_AuditEventsInfo; -- cgit From fa6ce1e4a9d285c82faed49a09bb2bd297bbea39 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 16:53:21 +0100 Subject: Ignore newly generated proto header. (This used to be commit caa0da310da47a48a9add6de3d309984ae14f59c) --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ccc12650c1..9ed0334ea1 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ source/lib/util/pidfile.h source/lib/util/unix_privs.h source/lib/util/util_proto.h source/lib/util/wrap_xattr.h +source/lib/util/asn1_proto.h source/libcli/finddcs.h source/libcli/libcli_proto.h source/libcli/auth/proto.h @@ -79,7 +80,6 @@ source/libcli/resolve/proto.h source/libcli/security/proto.h source/libcli/smb2/smb2_proto.h source/libcli/smb_composite/proto.h -source/libcli/util/asn1_proto.h source/libcli/util/clilsa.h source/libcli/util/proto.h source/libcli/wrepl/winsrepl_proto.h -- cgit From a760146e73ea0f6bb30f01276f3756d97644722c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 17:40:25 +0100 Subject: selftest: Add some more documentation. Rename env => target to avoid confusion. (This used to be commit 50b8a16d0cb5e1c4352e73900d1e98a812340cca) --- source4/selftest/README | 17 + source4/selftest/env/Samba3.pm | 434 ------------------ source4/selftest/env/Samba4.pm | 915 ------------------------------------- source4/selftest/env/Windows.pm | 40 -- source4/selftest/selftest.pl | 9 +- source4/selftest/target/Samba3.pm | 434 ++++++++++++++++++ source4/selftest/target/Samba4.pm | 915 +++++++++++++++++++++++++++++++++++++ source4/selftest/target/Windows.pm | 40 ++ 8 files changed, 1410 insertions(+), 1394 deletions(-) delete mode 100644 source4/selftest/env/Samba3.pm delete mode 100644 source4/selftest/env/Samba4.pm delete mode 100644 source4/selftest/env/Windows.pm create mode 100644 source4/selftest/target/Samba3.pm create mode 100644 source4/selftest/target/Samba4.pm create mode 100644 source4/selftest/target/Windows.pm diff --git a/source4/selftest/README b/source4/selftest/README index a0afda3d19..3250f32ec7 100644 --- a/source4/selftest/README +++ b/source4/selftest/README @@ -1,6 +1,23 @@ +# vim: ft=rst + This directory contains test scripts that are useful for running a bunch of tests all at once. +=============== +Available tests +=============== +The available tests are obtained from a script, usually +selftest/samba{3,4}_tests.sh. This script should for each test output +the name of the test, the command to run and the environment that should be +provided. + +============ +Environments +============ +Tests often need to run against a server with particular things set up, +a "environment". This environment is provided by the test "target": Samba 3, +Samba 4 or Windows. + The following environments are currently available: - none: No server set up, no variables set. diff --git a/source4/selftest/env/Samba3.pm b/source4/selftest/env/Samba3.pm deleted file mode 100644 index b0c4eb22bd..0000000000 --- a/source4/selftest/env/Samba3.pm +++ /dev/null @@ -1,434 +0,0 @@ -#!/usr/bin/perl -# Bootstrap Samba and run a number of tests against it. -# Copyright (C) 2005-2007 Jelmer Vernooij -# Published under the GNU GPL, v3 or later. - -package Samba3; - -use strict; -use Cwd qw(abs_path); -use FindBin qw($RealBin); -use POSIX; - -sub binpath($$) -{ - my ($self, $binary) = @_; - - if (defined($self->{bindir})) { - my $path = "$self->{bindir}/$binary"; - -f $path or die("File $path doesn't exist"); - return $path; - } - - return $binary; -} - -sub new($$) { - my ($classname, $bindir) = @_; - my $self = { bindir => $bindir }; - bless $self; - return $self; -} - -sub teardown_env($$) -{ - my ($self, $envvars) = @_; - - my $smbdpid = read_pid($envvars, "smbd"); - my $nmbdpid = read_pid($envvars, "nmbd"); -# my $winbinddpid = read_pid($envvars, "winbindd"); - - $self->stop_sig_term($smbdpid); - $self->stop_sig_term($nmbdpid); -# $self->stop_sig_term($winbinddpid); - $self->stop_sig_kill($smbdpid); - $self->stop_sig_kill($nmbdpid); -# $self->stop_sig_kill($winbinddpid); - - return 0; -} - -sub getlog_env_app($$$) -{ - my ($self, $envvars, $name) = @_; - - my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n"; - my $out = $title; - - open(LOG, "<".$envvars->{$name."_TEST_LOG"}); - - seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET); - while () { - $out .= $_; - } - $envvars->{$name."_TEST_LOG_POS"} = tell(LOG); - close(LOG); - - return "" if $out eq $title; - - return $out; -} - -sub getlog_env($$) -{ - my ($self, $envvars) = @_; - my $ret = ""; - - $ret .= $self->getlog_env_app($envvars, "SMBD"); - $ret .= $self->getlog_env_app($envvars, "NMBD"); -# $ret .= $self->getlog_env_app($envvars, "WINBINDD"); - - return $ret; -} - -sub check_env($$) -{ - my ($self, $envvars) = @_; - - # TODO ... - return 1; -} - -sub setup_env($$$) -{ - my ($self, $envname, $path) = @_; - - if ($envname eq "dc") { - return $self->setup_dc("$path/dc"); - } else { - return undef; - } -} - -sub setup_dc($$) -{ - my ($self, $path) = @_; - - my $vars = $self->provision($path, "dc"); - - $self->check_or_start($vars, - ($ENV{NMBD_MAXTIME} or 2700), - ($ENV{WINBINDD_MAXTIME} or 2700), - ($ENV{SMBD_MAXTIME} or 2700)); - - $self->wait_for_start($vars); - - return $vars; -} - -sub stop($) -{ - my ($self) = @_; -} - -sub stop_sig_term($$) { - my ($self, $pid) = @_; - kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!"); -} - -sub stop_sig_kill($$) { - my ($self, $pid) = @_; - kill("ALRM", $pid) or warn("Unable to kill $pid: $!"); -} - -sub write_pid($$$) -{ - my ($env_vars, $app, $pid) = @_; - - open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid"); - print PID $pid; - close(PID); -} - -sub read_pid($$) -{ - my ($env_vars, $app) = @_; - - open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid"); - my $pid = ; - close(PID); - return $pid; -} - -sub check_or_start($$$$) { - my ($self, $env_vars, $nmbd_maxtime, $winbindd_maxtime, $smbd_maxtime) = @_; - - unlink($env_vars->{NMBD_TEST_LOG}); - print "STARTING NMBD..."; - my $pid = fork(); - if ($pid == 0) { - open STDOUT, ">$env_vars->{NMBD_TEST_LOG}"; - open STDERR, '>&STDOUT'; - - $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR}; - - my @optargs = ("-d0"); - if (defined($ENV{NMBD_OPTIONS})) { - @optargs = split(/ /, $ENV{NMBD_OPTIONS}); - } - - $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd"); - - my @preargs = ($self->binpath("timelimit"), $nmbd_maxtime); - if(defined($ENV{NMBD_VALGRIND})) { - @preargs = split(/ /, $ENV{NMBD_VALGRIND}); - } - - exec(@preargs, $self->binpath("nmbd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!"); - } - write_pid($env_vars, "nmbd", $pid); - print "DONE\n"; - -# disable winbindd until the build-farm faked_users work with it -# unlink($env_vars->{WINBINDD_TEST_LOG}); -# print "STARTING WINBINDD..."; -# $pid = fork(); -# if ($pid == 0) { -# open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}"; -# open STDERR, '>&STDOUT'; -# -# $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR}; -# -# my @optargs = ("-d0"); -# if (defined($ENV{WINBINDD_OPTIONS})) { -# @optargs = split(/ /, $ENV{WINBINDD_OPTIONS}); -# } -# -# $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd"); -# exec($self->binpath("timelimit"), $winbindd_maxtime, $ENV{WINBINDD_VALGRIND}, $self->binpath("winbindd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!"); -# } -# write_pid($env_vars, "winbindd", $pid); -# print "DONE\n"; - - unlink($env_vars->{SMBD_TEST_LOG}); - print "STARTING SMBD..."; - $pid = fork(); - if ($pid == 0) { - open STDOUT, ">$env_vars->{SMBD_TEST_LOG}"; - open STDERR, '>&STDOUT'; - - $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR}; - - $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd"); - my @optargs = ("-d0"); - if (defined($ENV{SMBD_OPTIONS})) { - @optargs = split(/ /, $ENV{SMBD_OPTIONS}); - } - my @preargs = ($self->binpath("timelimit"), $smbd_maxtime); - if(defined($ENV{SMBD_VALGRIND})) { - @preargs = split(/ /,$ENV{SMBD_VALGRIND}); - } - exec(@preargs, $self->binpath("smbd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!"); - } - write_pid($env_vars, "smbd", $pid); - print "DONE\n"; - - return 0; -} - -sub create_clientconf($$$) -{ - my ($self, $prefix, $domain) = @_; - - my $lockdir = "$prefix/locks"; - my $logdir = "$prefix/logs"; - my $piddir = "$prefix/pid"; - my $privatedir = "$prefix/private"; - my $scriptdir = "$RealBin/.."; - my $conffile = "$prefix/smb.conf"; - - my $torture_interfaces='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8'; - open(CONF, ">$conffile"); - print CONF " -[global] - workgroup = $domain - - private dir = $privatedir - pid directory = $piddir - lock directory = $lockdir - log file = $logdir/log.\%m - log level = 0 - - name resolve order = bcast - - netbios name = TORTURE_6 - interfaces = $torture_interfaces - panic action = $scriptdir/gdb_backtrace \%d %\$(MAKE_TEST_BINARY) - - passdb backend = tdbsam - "; - close(CONF); -} - -sub provision($$$) -{ - my ($self, $prefix, $role) = @_; - - ## - ## setup the various environment variables we need - ## - - my %ret = (); - my $server = "LOCALHOST2"; - my $server_ip = "127.0.0.2"; - my $domain = "SAMBA-TEST"; - - my $username = `PATH=/usr/ucb:$ENV{PATH} whoami`; - chomp $username; - my $password = "test"; - - my $srcdir="$RealBin/.."; - my $scriptdir="$srcdir/selftest"; - my $prefix_abs = abs_path($prefix); - - my @dirs = (); - - my $shrdir="$prefix_abs/share"; - push(@dirs,$shrdir); - - my $libdir="$prefix_abs/lib"; - push(@dirs,$libdir); - - my $piddir="$prefix_abs/pid"; - push(@dirs,$piddir); - - my $privatedir="$prefix_abs/private"; - push(@dirs,$privatedir); - - my $lockdir="$prefix_abs/lockdir"; - push(@dirs,$lockdir); - - my $logdir="$prefix_abs/logs"; - push(@dirs,$logdir); - - # this gets autocreated by winbindd - my $wbsockdir="$prefix_abs/winbindd"; - my $wbsockprivdir="$lockdir/winbindd_privileged"; - - ## - ## create the test directory layout - ## - mkdir($prefix_abs, 0777); - print "CREATE TEST ENVIRONMENT IN '$prefix'..."; - system("rm -rf $prefix_abs/*"); - mkdir($_, 0777) foreach(@dirs); - - my $conffile="$libdir/server.conf"; - - open(CONF, ">$conffile") or die("Unable to open $conffile"); - print CONF " -[global] - workgroup = $domain - - private dir = $privatedir - pid directory = $piddir - lock directory = $lockdir - log file = $logdir/log.\%m - log level = 0 - - name resolve order = bcast - - netbios name = $server - interfaces = $server_ip/8 - bind interfaces only = yes - panic action = $scriptdir/gdb_backtrace %d %\$(MAKE_TEST_BINARY) - - passdb backend = tdbsam - - ; Necessary to add the build farm hacks - add user script = /bin/false - add machine script = /bin/false - - kernel oplocks = no - kernel change notify = no - - syslog = no - printing = bsd - printcap name = /dev/null - -"; - - if ($role eq "dc") { - print CONF "\tdomain logons = yes\n"; - print CONF "\tdomain master = yes\n"; - } - -print CONF " - - winbindd:socket dir = $wbsockdir - -[tmp] - path = $shrdir - read only = no - smbd:sharedelay = 100000 - map hidden = yes - map system = yes - create mask = 755 -[hideunread] - copy = tmp - hide unreadable = yes -[hideunwrite] - copy = tmp - hide unwriteable files = yes -[print1] - copy = tmp - printable = yes - printing = test -[print2] - copy = print1 -[print3] - copy = print1 -[print4] - copy = print1 - "; - close(CONF); - - ## - ## create a test account - ## - - open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $username"); - print PWD "$password\n$password\n"; - close(PWD) or die("Unable to set password for test account"); - - print "DONE\n"; - - $ret{SERVER_IP} = $server_ip; - $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log"; - $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log"; - $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; - $ret{SERVERCONFFILE} = $conffile; - $ret{CONFIGURATION} ="-s $conffile"; - $ret{SERVER} = $server; - $ret{USERNAME} = $username; - $ret{DOMAIN} = $domain; - $ret{NETBIOSNAME} = $server; - $ret{PASSWORD} = $password; - $ret{PIDDIR} = $piddir; - $ret{WINBINDD_SOCKET_DIR} = $wbsockdir; - $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir; - return \%ret; -} - -sub wait_for_start($$) -{ - my ($self, $envvars) = @_; - - # 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($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__"); - system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__"); - system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__"); - system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}"); - system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}"); - # make sure smbd is also up set - print "wait for smbd\n"; - system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2"); - system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2"); - - print $self->getlog_env($envvars); -} - -1; diff --git a/source4/selftest/env/Samba4.pm b/source4/selftest/env/Samba4.pm deleted file mode 100644 index 87a86ef06f..0000000000 --- a/source4/selftest/env/Samba4.pm +++ /dev/null @@ -1,915 +0,0 @@ -#!/usr/bin/perl -# Bootstrap Samba and run a number of tests against it. -# Copyright (C) 2005-2007 Jelmer Vernooij -# Published under the GNU GPL, v3 or later. - -package Samba4; - -use strict; -use Cwd qw(abs_path); -use FindBin qw($RealBin); -use POSIX; - -sub new($$$$) { - my ($classname, $bindir, $ldap, $setupdir) = @_; - my $self = { - vars => {}, - ldap => $ldap, - bindir => $bindir, - setupdir => $setupdir - }; - bless $self; - return $self; -} - -sub openldap_start($$$) { - my ($slapd_conf, $uri, $logs) = @_; - my $oldpath = $ENV{PATH}; - my $olroot = ""; - my $olpath = ""; - if (defined $ENV{OPENLDAP_ROOT}) { - $olroot = "$ENV{OPENLDAP_ROOT}"; - $olpath = "$olroot/libexec:$olroot/sbin:"; - } - $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}"; - system("slapd -d63 -f $slapd_conf -h $uri > $logs 2>&1 &"); - $ENV{PATH} = $oldpath; -} - -sub slapd_start($$) -{ - my $count = 0; - my ($self, $env_vars) = @_; - - my $uri = $env_vars->{LDAP_URI}; - - # running slapd in the background means it stays in the same process group, so it can be - # killed by timelimit - if ($self->{ldap} eq "fedora-ds") { - system("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd -D $env_vars->{FEDORA_DS_DIR} -d0 -i $env_vars->{FEDORA_DS_PIDFILE}> $env_vars->{LDAPDIR}/logs 2>&1 &"); - } elsif ($self->{ldap} eq "openldap") { - openldap_start($env_vars->{SLAPD_CONF}, $uri, "$env_vars->{LDAPDIR}/logs"); - } - while (system("$self->{bindir}/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) { - $count++; - if ($count > 40) { - $self->slapd_stop($env_vars); - return 0; - } - sleep(1); - } - return 1; -} - -sub slapd_stop($$) -{ - my ($self, $envvars) = @_; - if ($self->{ldap} eq "fedora-ds") { - system("$envvars->{LDAPDIR}/slapd-samba4/stop-slapd"); - } elsif ($self->{ldap} eq "openldap") { - open(IN, "<$envvars->{OPENLDAP_PIDFILE}") or - die("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}"); - kill 9, ; - close(IN); - } - return 1; -} - -sub check_or_start($$$) -{ - my ($self, $env_vars, $max_time) = @_; - return 0 if ( -p $env_vars->{SMBD_TEST_FIFO}); - - unlink($env_vars->{SMBD_TEST_FIFO}); - POSIX::mkfifo($env_vars->{SMBD_TEST_FIFO}, 0700); - unlink($env_vars->{SMBD_TEST_LOG}); - - print "STARTING SMBD... "; - my $pid = fork(); - if ($pid == 0) { - open STDIN, $env_vars->{SMBD_TEST_FIFO}; - open STDOUT, ">$env_vars->{SMBD_TEST_LOG}"; - open STDERR, '>&STDOUT'; - - SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE}); - - my $valgrind = ""; - if (defined($ENV{SMBD_VALGRIND})) { - $valgrind = $ENV{SMBD_VALGRIND}; - } - - $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG}; - - $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD}; - $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP}; - - # Start slapd before smbd, but with the fifo on stdin - if (defined($self->{ldap})) { - $self->slapd_start($env_vars) or - die("couldn't start slapd (2nd time)"); - } - - my $optarg = ""; - if (defined($max_time)) { - $optarg = "--maximum-runtime=$max_time "; - } - if (defined($ENV{SMBD_OPTIONS})) { - $optarg.= " $ENV{SMBD_OPTIONS}"; - } - my $ret = system("$valgrind $self->{bindir}/smbd $optarg $env_vars->{CONFIGURATION} -M single -i --leak-report-full"); - if ($? == -1) { - print "Unable to start smbd: $ret: $!\n"; - exit 1; - } - unlink($env_vars->{SMBD_TEST_FIFO}); - my $exit = $? >> 8; - if ( $ret == 0 ) { - print "smbd exits with status $exit\n"; - } elsif ( $ret & 127 ) { - print "smbd got signal ".($ret & 127)." and exits with $exit!\n"; - } else { - $ret = $? >> 8; - print "smbd failed with status $exit!\n"; - } - exit $exit; - } - print "DONE\n"; - - open(DATA, ">$env_vars->{SMBD_TEST_FIFO}"); - - return $pid; -} - -sub wait_for_start($$) -{ - my ($self, $testenv_vars) = @_; - # give time for nbt server to register its names - print "delaying for nbt name registration\n"; - sleep 2; - - # This will return quickly when things are up, but be slow if we - # need to wait for (eg) SSL init - system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}"); - system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}"); - - print $self->getlog_env($testenv_vars); -} - -sub write_ldb_file($$$) -{ - my ($self, $file, $ldif) = @_; - - open(LDIF, "|$self->{bindir}/ldbadd -H $file >/dev/null"); - print LDIF $ldif; - return close(LDIF); -} - -sub add_wins_config($$) -{ - my ($self, $privatedir) = @_; - - return $self->write_ldb_file("$privatedir/wins_config.ldb", " -dn: name=TORTURE_6,CN=PARTNERS -objectClass: wreplPartner -name: TORTURE_6 -address: 127.0.0.6 -pullInterval: 0 -pushChangeCount: 0 -type: 0x3 -"); -} - -sub mk_fedora_ds($$$) -{ - my ($self, $ldapdir, $configuration) = @_; - - my $fedora_ds_inf = "$ldapdir/fedorads.inf"; - my $fedora_ds_extra_ldif = "$ldapdir/fedorads-partitions.ldif"; - - #Make the subdirectory be as fedora DS would expect - my $fedora_ds_dir = "$ldapdir/slapd-samba4"; - - my $pidfile = "$fedora_ds_dir/logs/slapd-samba4.pid"; - - system("$self->{bindir}/ad2oLschema $configuration -H $ldapdir/schema-tmp.ldb --option=convert:target=fedora-ds -I $self->{setupdir}/schema-map-fedora-ds-1.0 -O $ldapdir/99_ad.ldif >&2") == 0 or die("schema conversion for Fedora DS failed"); - -my $dir = getcwd(); -chdir "$ENV{FEDORA_DS_ROOT}/bin" || die; - if (system("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf >&2") != 0) { - chdir $dir; - die("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf FAILED: $?"); - } - chdir $dir || die; - - return ($fedora_ds_dir, $pidfile); -} - -sub mk_openldap($$$) -{ - my ($self, $ldapdir, $configuration) = @_; - - my $slapd_conf = "$ldapdir/slapd.conf"; - my $pidfile = "$ldapdir/slapd.pid"; - my $modconf = "$ldapdir/modules.conf"; - - #This uses the backend provision we just did, to read out the schema - system("$self->{bindir}/ad2oLschema $configuration --option=convert:target=openldap -H $ldapdir/schema-tmp.ldb -I $self->{setupdir}/schema-map-openldap-2.3 -O $ldapdir/backend-schema.schema >&2") == 0 or die("schema conversion for OpenLDAP failed"); - - my $oldpath = $ENV{PATH}; - my $olpath = ""; - my $olroot = ""; - if (defined $ENV{OPENLDAP_ROOT}) { - $olroot = "$ENV{OPENLDAP_ROOT}"; - $olpath = "$olroot/libexec:$olroot/sbin:"; - } - $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}"; - - unlink($modconf); - open(CONF, ">$modconf"); close(CONF); - - if (system("slaptest -u -f $slapd_conf >&2") != 0) { - open(CONF, ">$modconf"); - # enable slapd modules - print CONF " -modulepath $olroot/libexec/openldap -moduleload syncprov -moduleload memberof -moduleload refint -"; - close(CONF); - } - if (system("slaptest -u -f $slapd_conf >&2") != 0) { - open(CONF, ">$modconf"); - # enable slapd modules - print CONF " -modulepath $olroot/libexec/openldap -moduleload back_hdb -moduleload syncprov -moduleload memberof -moduleload refint -"; - close(CONF); - } - - if (system("slaptest -u -f $slapd_conf >&2") != 0) { - open(CONF, ">$modconf"); - # enable slapd modules - print CONF " -moduleload back_hdb -moduleload syncprov -moduleload memberof -moduleload refint -"; - close(CONF); - } - - if (system("slaptest -u -f $slapd_conf >&2") != 0) { - open(CONF, ">$modconf"); - # enable slapd modules - print CONF " -modulepath /usr/lib/ldap -moduleload back_hdb -moduleload syncprov -moduleload memberof -moduleload refint -"; - close(CONF); - } - - if (system("slaptest -u -f $slapd_conf >&2") != 0) { - open(CONF, ">$modconf"); - # enable slapd modules (Fedora layout) - print CONF " -modulepath /usr/lib/openldap -moduleload syncprov -moduleload memberof -moduleload refint -"; - close(CONF); - } - - if (system("slaptest -u -f $slapd_conf >&2") != 0) { - open(CONF, ">$modconf"); - # enable slapd modules (Fedora x86_64 layout) - print CONF " -modulepath /usr/lib64/openldap -moduleload syncprov -moduleload memberof -moduleload refint -"; - close(CONF); - } - - system("slaptest -u -f $slapd_conf") == 0 or die("slaptest still fails after adding modules"); - - - $ENV{PATH} = $oldpath; - - return ($slapd_conf, $pidfile); -} - -sub mk_keyblobs($$) -{ - my ($self, $tlsdir) = @_; - - #TLS and PKINIT crypto blobs - my $dhfile = "$tlsdir/dhparms.pem"; - my $cafile = "$tlsdir/ca.pem"; - my $certfile = "$tlsdir/cert.pem"; - my $reqkdc = "$tlsdir/req-kdc.der"; - my $kdccertfile = "$tlsdir/kdc.pem"; - my $keyfile = "$tlsdir/key.pem"; - my $adminkeyfile = "$tlsdir/adminkey.pem"; - my $reqadmin = "$tlsdir/req-admin.der"; - my $admincertfile = "$tlsdir/admincert.pem"; - - mkdir($tlsdir, 0777); - - #This is specified here to avoid draining entropy on every run - open(DHFILE, ">$dhfile"); - print DHFILE <$keyfile"); - print KEYFILE <$adminkeyfile"); - - print ADMINKEYFILE <$cafile"); - print CAFILE <$certfile"); - print CERTFILE <$kdccertfile"); - print KDCCERTFILE <$admincertfile"); - print ADMINCERTFILE <; - my $unix_gids_str = $); - my @unix_gids = split(" ", $unix_gids_str); - my $srcdir="$RealBin/.."; - -d $prefix or mkdir($prefix, 0777) or die("Unable to create $prefix"); - my $prefix_abs = abs_path($prefix); - my $tmpdir = "$prefix_abs/tmp"; - my $etcdir = "$prefix_abs/etc"; - my $piddir = "$prefix_abs/pid"; - my $conffile = "$etcdir/smb.conf"; - my $krb5_config = "$etcdir/krb5.conf"; - my $privatedir = "$prefix_abs/private"; - my $ncalrpcdir = "$prefix_abs/ncalrpc"; - my $lockdir = "$prefix_abs/lockdir"; - my $winbindd_socket_dir = "$prefix_abs/winbind_socket"; - my $winbindd_priv_pipe_dir = "$piddir/smbd.tmp/winbind_pipe"; - my $nsswrap_passwd = "$etcdir/passwd"; - my $nsswrap_group = "$etcdir/group"; - - my $configuration = "--configfile=$conffile"; - my $ldapdir = "$privatedir/ldap"; - - my $tlsdir = "$privatedir/tls"; - - my $ifaceipv4 = "127.0.0.$swiface"; - my $interfaces = "$ifaceipv4/8"; - - (system("rm -rf $prefix/*") == 0) or die("Unable to clean up"); - mkdir($_, 0777) foreach ($privatedir, $etcdir, $piddir, $ncalrpcdir, $lockdir, - $tmpdir); - - - my $localbasedn = $basedn; - $localbasedn = "DC=$netbiosname" if $server_role eq "member server"; - - open(CONFFILE, ">$conffile"); - print CONFFILE " -[global] - netbios name = $netbiosname - netbios aliases = $netbiosalias - workgroup = $domain - realm = $realm - private dir = $privatedir - pid directory = $piddir - ncalrpc dir = $ncalrpcdir - lock dir = $lockdir - setup directory = $self->{setupdir} - modules dir = $self->{bindir}/modules - js include = $srcdir/scripting/libjs - winbindd socket directory = $winbindd_socket_dir - winbind separator = / - name resolve order = bcast - interfaces = $interfaces - tls dh params file = $tlsdir/dhparms.pem - panic action = $srcdir/script/gdb_backtrace \%PID% \%PROG% - wins support = yes - server role = $server_role - max xmit = 32K - server max protocol = SMB2 - notify:inotify = false - ldb:nosync = true - system:anonymous = true -#We don't want to pass our self-tests if the PAC code is wrong - gensec:require_pac = true - log level = $smbd_loglevel - -[tmp] - path = $tmpdir - read only = no - ntvfs handler = posix - posix:sharedelay = 100000 - posix:eadb = $lockdir/eadb.tdb - -[cifs] - read only = no - ntvfs handler = cifs - cifs:server = $netbiosname - cifs:share = tmp -#There is no username specified here, instead the client is expected -#to log in with kerberos, and smbd will used delegated credentials. - -[simple] - path = $tmpdir - read only = no - ntvfs handler = simple - -[cifsposix] - copy = simple - ntvfs handler = cifsposix -"; - close(CONFFILE); - - $self->mk_keyblobs($tlsdir); - - open(KRB5CONF, ">$krb5_config"); - print KRB5CONF " -#Generated krb5.conf for $realm - -[libdefaults] - default_realm = $realm - dns_lookup_realm = false - dns_lookup_kdc = false - ticket_lifetime = 24h - forwardable = yes - -[realms] - $realm = { - kdc = 127.0.0.1:88 - admin_server = 127.0.0.1:88 - default_domain = $dnsname - } - $dnsname = { - kdc = 127.0.0.1:88 - admin_server = 127.0.0.1:88 - default_domain = $dnsname - } - $domain = { - kdc = 127.0.0.1:88 - admin_server = 127.0.0.1:88 - default_domain = $dnsname - } - -[appdefaults] - pkinit_anchors = FILE:$tlsdir/ca.pem - -[kdc] - enable-pkinit = true - pkinit_identity = FILE:$tlsdir/kdc.pem,$tlsdir/key.pem - pkinit_anchors = FILE:$tlsdir/ca.pem - -[domain_realm] - .$dnsname = $realm -"; - close(KRB5CONF); - - open(PWD, ">$nsswrap_passwd"); - print PWD " -root:x:0:0:root gecos:$prefix_abs:/bin/false -$unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false -nobody:x:65534:65533:nobody gecos:$prefix_abs:/bin/false -"; - close(PWD); - - open(GRP, ">$nsswrap_group"); - print GRP " -root:x:0: -wheel:x:10: -users:x:100: -nobody:x:65533: -nogroup:x:65534:nobody -"; - close(GRP); - -#Ensure the config file is valid before we start - if (system("$self->{bindir}/testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) { - system("$self->{bindir}/testparm -v --suppress-prompt $configuration >&2"); - die("Failed to create a valid smb.conf configuration!"); - } - - (system("($self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$netbiosname\" ) >/dev/null 2>&1") == 0) or die("Failed to create a valid smb.conf configuration! $self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global"); - - my @provision_options = (); - push (@provision_options, "NSS_WRAPPER_PASSWD=\"$nsswrap_passwd\""); - push (@provision_options, "NSS_WRAPPER_GROUP=\"$nsswrap_group\""); - if (defined($ENV{PROVISION_PYTHON})) { - push (@provision_options, "$self->{bindir}/smbpython"); - push (@provision_options, "$self->{setupdir}/provision.py"); - } else { - push (@provision_options, "$self->{bindir}/smbscript"); - push (@provision_options, "$self->{setupdir}/provision"); - } - push (@provision_options, split(' ', $configuration)); - push (@provision_options, "--host-name=$netbiosname"); - push (@provision_options, "--host-ip=$ifaceipv4"); - push (@provision_options, "--quiet"); - push (@provision_options, "--domain=$domain"); - push (@provision_options, "--realm=$realm"); - push (@provision_options, "--adminpass=$password"); - push (@provision_options, "--krbtgtpass=krbtgt$password"); - push (@provision_options, "--machinepass=machine$password"); - push (@provision_options, "--root=$unix_name"); - push (@provision_options, "--simple-bind-dn=cn=Manager,$localbasedn"); - push (@provision_options, "--password=$password"); - push (@provision_options, "--server-role=\"$server_role\""); - - my $ldap_uri= "$ldapdir/ldapi"; - $ldap_uri =~ s|/|%2F|g; - $ldap_uri = "ldapi://$ldap_uri"; - - my $ret = { - KRB5_CONFIG => $krb5_config, - PIDDIR => $piddir, - SERVER => $netbiosname, - SERVER_IP => $ifaceipv4, - NETBIOSNAME => $netbiosname, - NETBIOSALIAS => $netbiosalias, - LDAP_URI => $ldap_uri, - DOMAIN => $domain, - USERNAME => $username, - REALM => $realm, - PASSWORD => $password, - LDAPDIR => $ldapdir, - WINBINDD_SOCKET_DIR => $winbindd_socket_dir, - WINBINDD_PRIV_PIPE_DIR => $winbindd_priv_pipe_dir, - NCALRPCDIR => $ncalrpcdir, - LOCKDIR => $lockdir, - CONFIGURATION => $configuration, - SOCKET_WRAPPER_DEFAULT_IFACE => $swiface, - NSS_WRAPPER_PASSWD => $nsswrap_passwd, - NSS_WRAPPER_GROUP => $nsswrap_group, - }; - - if (defined($self->{ldap})) { - - push (@provision_options, "--ldap-backend=$ldap_uri"); - system("$self->{bindir}/smbscript $self->{setupdir}/provision-backend $configuration --ldap-manager-pass=$password --root=$unix_name --realm=$realm --host-name=$netbiosname --ldap-backend-type=$self->{ldap}>&2") == 0 or die("backend provision failed"); - - if ($self->{ldap} eq "openldap") { - ($ret->{SLAPD_CONF}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ldapdir, $configuration) or die("Unable to create openldap directories"); - } elsif ($self->{ldap} eq "fedora-ds") { - ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ldapdir, $configuration) or die("Unable to create fedora ds directories"); - push (@provision_options, "--ldap-module=nsuniqueid"); - push (@provision_options, "'--aci=aci:: KHRhcmdldGF0dHIgPSAiKiIpICh2ZXJzaW9uIDMuMDthY2wgImZ1bGwgYWNjZXNzIHRvIGFsbCBieSBhbGwiO2FsbG93IChhbGwpKHVzZXJkbiA9ICJsZGFwOi8vL2FueW9uZSIpOykK'"); - } - - $self->slapd_start($ret) or - die("couldn't start slapd"); - } - - my $provision_cmd = join(" ", @provision_options); - (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n"); - - if (defined($self->{ldap})) { - $self->slapd_stop($ret) or - die("couldn't stop slapd"); - } - - return $ret; -} - -sub provision_member($$$) -{ - my ($self, $prefix, $dcvars) = @_; - print "PROVISIONING MEMBER..."; - - my $ret = $self->provision($prefix, - "member server", - "localmember3", - "localmember", - 3, - "localmemberpass"); - - $ret or die("Unable to provision"); - - my $cmd = ""; - $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; - $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" "; - $cmd .= "$self->{bindir}/net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member"; - $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}"; - - system($cmd) == 0 or die("Join failed\n$cmd"); - - $ret->{SMBD_TEST_FIFO} = "$prefix/smbd_test.fifo"; - $ret->{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; - $ret->{SMBD_TEST_LOG_POS} = 0; - - $ret->{DC_SERVER} = $dcvars->{SERVER}; - $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP}; - $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME}; - $ret->{DC_NETBIOSALIAS} = $dcvars->{NETBIOSALIAS}; - $ret->{DC_USERNAME} = $dcvars->{USERNAME}; - $ret->{DC_PASSWORD} = $dcvars->{PASSWORD}; - - return $ret; -} - -sub provision_dc($$) -{ - my ($self, $prefix) = @_; - - print "PROVISIONING DC..."; - my $ret = $self->provision($prefix, - "domain controller", - "localdc1", - "localdc", - 1, - "localdcpass"); - - $self->add_wins_config("$prefix/private") or - die("Unable to add wins configuration"); - - $ret->{SMBD_TEST_FIFO} = "$prefix/smbd_test.fifo"; - $ret->{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; - $ret->{SMBD_TEST_LOG_POS} = 0; - return $ret; -} - -sub teardown_env($$) -{ - my ($self, $envvars) = @_; - my $pid; - - close(DATA); - - if (-f "$envvars->{PIDDIR}/smbd.pid" ) { - open(IN, "<$envvars->{PIDDIR}/smbd.pid") or die("unable to open smbd pid file"); - $pid = ; - close(IN); - - # 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 it is still around, kill it - if ($count > 20) { - print "smbd process $pid took more than $count seconds to exit, killing\n"; - kill 9, $pid; - } - } - - my $failed = $? >> 8; - - $self->slapd_stop($envvars) if ($self->{ldap}); - - print $self->getlog_env($envvars); - - return $failed; -} - -sub getlog_env($$) -{ - my ($self, $envvars) = @_; - my $title = "SMBD LOG of: $envvars->{NETBIOSNAME}\n"; - my $out = $title; - - open(LOG, "<$envvars->{SMBD_TEST_LOG}"); - - seek(LOG, $envvars->{SMBD_TEST_LOG_POS}, SEEK_SET); - while () { - $out .= $_; - } - $envvars->{SMBD_TEST_LOG_POS} = tell(LOG); - close(LOG); - - return "" if $out eq $title; - - return $out; -} - -sub check_env($$) -{ - my ($self, $envvars) = @_; - - return 1 if (-p $envvars->{SMBD_TEST_FIFO}); - - print $self->getlog_env($envvars); - - return 0; -} - -sub setup_env($$$) -{ - my ($self, $envname, $path) = @_; - - if ($envname eq "dc") { - return $self->setup_dc("$path/dc"); - } elsif ($envname eq "member") { - if (not defined($self->{vars}->{dc})) { - $self->setup_dc("$path/dc"); - } - return $self->setup_member("$path/member", $self->{vars}->{dc}); - } else { - die("Samba4 can't provide environment '$envname'"); - } -} - -sub setup_member($$$$) -{ - my ($self, $path, $dc_vars) = @_; - - my $env = $self->provision_member($path, $dc_vars); - - $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500)); - - $self->wait_for_start($env); - - return $env; -} - -sub setup_dc($$) -{ - my ($self, $path) = @_; - - my $env = $self->provision_dc($path); - - $self->check_or_start($env, - ($ENV{SMBD_MAXTIME} or 7500)); - - $self->wait_for_start($env); - - $self->{vars}->{dc} = $env; - - return $env; -} - -sub stop($) -{ - my ($self) = @_; -} - -1; diff --git a/source4/selftest/env/Windows.pm b/source4/selftest/env/Windows.pm deleted file mode 100644 index d0c90d7f7b..0000000000 --- a/source4/selftest/env/Windows.pm +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/perl -# Bootstrap Samba and run a number of tests against it. -# Copyright (C) 2005-2007 Jelmer Vernooij -# Published under the GNU GPL, v3 or later. - -package Windows; - -use strict; -use FindBin qw($RealBin); -use POSIX; - -sub new($) -{ - my ($classname) = @_; - my $self = { }; - bless $self; - return $self; -} - -sub provision($$$) -{ - my ($self, $environment, $prefix) = @_; - - die ("Windows tests will not run without root privileges.") - if (`whoami` ne "root"); - - die("Environment variable WINTESTCONF has not been defined.\n". - "Windows tests will not run unconfigured.") if (not defined($ENV{WINTESTCONF})); - - die ("$ENV{WINTESTCONF} could not be read.") if (! -r $ENV{WINTESTCONF}); - - $ENV{WINTEST_DIR}="$ENV{SRCDIR}/selftest/win"; -} - -sub setup_env($$) -{ - my ($self, $name) = @_; -} - -1; diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl index 96409558b1..46c3846b54 100755 --- a/source4/selftest/selftest.pl +++ b/source4/selftest/selftest.pl @@ -67,7 +67,7 @@ these tests will be counted as successes, successes will be counted as failures. The format for the file is, one entry per line: -TESTSUITE-NAME/TEST-NAME +TESTSUITE-NAME.TEST-NAME The reason for a test can also be specified, by adding a hash sign (#) and the reason after the test name. @@ -130,9 +130,6 @@ use POSIX; use Cwd qw(abs_path); use lib "$RealBin"; use Subunit qw(parse_results); -use env::Samba3; -use env::Samba4; -use env::Windows; use SocketWrapper; my $opt_help = 0; @@ -429,17 +426,20 @@ my $testenv_default = "none"; if ($opt_target eq "samba4") { $testenv_default = "member"; + use target::Samba4; $target = new Samba4($opt_bindir or "$srcdir/bin", $ldap, "$srcdir/setup"); } elsif ($opt_target eq "samba3") { if ($opt_socket_wrapper and `$opt_bindir/smbd -b | grep SOCKET_WRAPPER` eq "") { die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting...."); } $testenv_default = "dc"; + use target::Samba3; $target = new Samba3($opt_bindir); } elsif ($opt_target eq "win") { die("Windows tests will not run with socket wrapper enabled.") if ($opt_socket_wrapper); $testenv_default = "dc"; + use target::Windows; $target = new Windows(); } @@ -741,7 +741,6 @@ sub teardown_env($) delete $running_envs{$envname}; } - if ($opt_no_lazy_setup) { setup_env($_) foreach (keys %required_envs); } diff --git a/source4/selftest/target/Samba3.pm b/source4/selftest/target/Samba3.pm new file mode 100644 index 0000000000..b0c4eb22bd --- /dev/null +++ b/source4/selftest/target/Samba3.pm @@ -0,0 +1,434 @@ +#!/usr/bin/perl +# Bootstrap Samba and run a number of tests against it. +# Copyright (C) 2005-2007 Jelmer Vernooij +# Published under the GNU GPL, v3 or later. + +package Samba3; + +use strict; +use Cwd qw(abs_path); +use FindBin qw($RealBin); +use POSIX; + +sub binpath($$) +{ + my ($self, $binary) = @_; + + if (defined($self->{bindir})) { + my $path = "$self->{bindir}/$binary"; + -f $path or die("File $path doesn't exist"); + return $path; + } + + return $binary; +} + +sub new($$) { + my ($classname, $bindir) = @_; + my $self = { bindir => $bindir }; + bless $self; + return $self; +} + +sub teardown_env($$) +{ + my ($self, $envvars) = @_; + + my $smbdpid = read_pid($envvars, "smbd"); + my $nmbdpid = read_pid($envvars, "nmbd"); +# my $winbinddpid = read_pid($envvars, "winbindd"); + + $self->stop_sig_term($smbdpid); + $self->stop_sig_term($nmbdpid); +# $self->stop_sig_term($winbinddpid); + $self->stop_sig_kill($smbdpid); + $self->stop_sig_kill($nmbdpid); +# $self->stop_sig_kill($winbinddpid); + + return 0; +} + +sub getlog_env_app($$$) +{ + my ($self, $envvars, $name) = @_; + + my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n"; + my $out = $title; + + open(LOG, "<".$envvars->{$name."_TEST_LOG"}); + + seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET); + while () { + $out .= $_; + } + $envvars->{$name."_TEST_LOG_POS"} = tell(LOG); + close(LOG); + + return "" if $out eq $title; + + return $out; +} + +sub getlog_env($$) +{ + my ($self, $envvars) = @_; + my $ret = ""; + + $ret .= $self->getlog_env_app($envvars, "SMBD"); + $ret .= $self->getlog_env_app($envvars, "NMBD"); +# $ret .= $self->getlog_env_app($envvars, "WINBINDD"); + + return $ret; +} + +sub check_env($$) +{ + my ($self, $envvars) = @_; + + # TODO ... + return 1; +} + +sub setup_env($$$) +{ + my ($self, $envname, $path) = @_; + + if ($envname eq "dc") { + return $self->setup_dc("$path/dc"); + } else { + return undef; + } +} + +sub setup_dc($$) +{ + my ($self, $path) = @_; + + my $vars = $self->provision($path, "dc"); + + $self->check_or_start($vars, + ($ENV{NMBD_MAXTIME} or 2700), + ($ENV{WINBINDD_MAXTIME} or 2700), + ($ENV{SMBD_MAXTIME} or 2700)); + + $self->wait_for_start($vars); + + return $vars; +} + +sub stop($) +{ + my ($self) = @_; +} + +sub stop_sig_term($$) { + my ($self, $pid) = @_; + kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!"); +} + +sub stop_sig_kill($$) { + my ($self, $pid) = @_; + kill("ALRM", $pid) or warn("Unable to kill $pid: $!"); +} + +sub write_pid($$$) +{ + my ($env_vars, $app, $pid) = @_; + + open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid"); + print PID $pid; + close(PID); +} + +sub read_pid($$) +{ + my ($env_vars, $app) = @_; + + open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid"); + my $pid = ; + close(PID); + return $pid; +} + +sub check_or_start($$$$) { + my ($self, $env_vars, $nmbd_maxtime, $winbindd_maxtime, $smbd_maxtime) = @_; + + unlink($env_vars->{NMBD_TEST_LOG}); + print "STARTING NMBD..."; + my $pid = fork(); + if ($pid == 0) { + open STDOUT, ">$env_vars->{NMBD_TEST_LOG}"; + open STDERR, '>&STDOUT'; + + $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR}; + + my @optargs = ("-d0"); + if (defined($ENV{NMBD_OPTIONS})) { + @optargs = split(/ /, $ENV{NMBD_OPTIONS}); + } + + $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd"); + + my @preargs = ($self->binpath("timelimit"), $nmbd_maxtime); + if(defined($ENV{NMBD_VALGRIND})) { + @preargs = split(/ /, $ENV{NMBD_VALGRIND}); + } + + exec(@preargs, $self->binpath("nmbd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!"); + } + write_pid($env_vars, "nmbd", $pid); + print "DONE\n"; + +# disable winbindd until the build-farm faked_users work with it +# unlink($env_vars->{WINBINDD_TEST_LOG}); +# print "STARTING WINBINDD..."; +# $pid = fork(); +# if ($pid == 0) { +# open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}"; +# open STDERR, '>&STDOUT'; +# +# $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR}; +# +# my @optargs = ("-d0"); +# if (defined($ENV{WINBINDD_OPTIONS})) { +# @optargs = split(/ /, $ENV{WINBINDD_OPTIONS}); +# } +# +# $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd"); +# exec($self->binpath("timelimit"), $winbindd_maxtime, $ENV{WINBINDD_VALGRIND}, $self->binpath("winbindd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!"); +# } +# write_pid($env_vars, "winbindd", $pid); +# print "DONE\n"; + + unlink($env_vars->{SMBD_TEST_LOG}); + print "STARTING SMBD..."; + $pid = fork(); + if ($pid == 0) { + open STDOUT, ">$env_vars->{SMBD_TEST_LOG}"; + open STDERR, '>&STDOUT'; + + $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR}; + + $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd"); + my @optargs = ("-d0"); + if (defined($ENV{SMBD_OPTIONS})) { + @optargs = split(/ /, $ENV{SMBD_OPTIONS}); + } + my @preargs = ($self->binpath("timelimit"), $smbd_maxtime); + if(defined($ENV{SMBD_VALGRIND})) { + @preargs = split(/ /,$ENV{SMBD_VALGRIND}); + } + exec(@preargs, $self->binpath("smbd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!"); + } + write_pid($env_vars, "smbd", $pid); + print "DONE\n"; + + return 0; +} + +sub create_clientconf($$$) +{ + my ($self, $prefix, $domain) = @_; + + my $lockdir = "$prefix/locks"; + my $logdir = "$prefix/logs"; + my $piddir = "$prefix/pid"; + my $privatedir = "$prefix/private"; + my $scriptdir = "$RealBin/.."; + my $conffile = "$prefix/smb.conf"; + + my $torture_interfaces='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8'; + open(CONF, ">$conffile"); + print CONF " +[global] + workgroup = $domain + + private dir = $privatedir + pid directory = $piddir + lock directory = $lockdir + log file = $logdir/log.\%m + log level = 0 + + name resolve order = bcast + + netbios name = TORTURE_6 + interfaces = $torture_interfaces + panic action = $scriptdir/gdb_backtrace \%d %\$(MAKE_TEST_BINARY) + + passdb backend = tdbsam + "; + close(CONF); +} + +sub provision($$$) +{ + my ($self, $prefix, $role) = @_; + + ## + ## setup the various environment variables we need + ## + + my %ret = (); + my $server = "LOCALHOST2"; + my $server_ip = "127.0.0.2"; + my $domain = "SAMBA-TEST"; + + my $username = `PATH=/usr/ucb:$ENV{PATH} whoami`; + chomp $username; + my $password = "test"; + + my $srcdir="$RealBin/.."; + my $scriptdir="$srcdir/selftest"; + my $prefix_abs = abs_path($prefix); + + my @dirs = (); + + my $shrdir="$prefix_abs/share"; + push(@dirs,$shrdir); + + my $libdir="$prefix_abs/lib"; + push(@dirs,$libdir); + + my $piddir="$prefix_abs/pid"; + push(@dirs,$piddir); + + my $privatedir="$prefix_abs/private"; + push(@dirs,$privatedir); + + my $lockdir="$prefix_abs/lockdir"; + push(@dirs,$lockdir); + + my $logdir="$prefix_abs/logs"; + push(@dirs,$logdir); + + # this gets autocreated by winbindd + my $wbsockdir="$prefix_abs/winbindd"; + my $wbsockprivdir="$lockdir/winbindd_privileged"; + + ## + ## create the test directory layout + ## + mkdir($prefix_abs, 0777); + print "CREATE TEST ENVIRONMENT IN '$prefix'..."; + system("rm -rf $prefix_abs/*"); + mkdir($_, 0777) foreach(@dirs); + + my $conffile="$libdir/server.conf"; + + open(CONF, ">$conffile") or die("Unable to open $conffile"); + print CONF " +[global] + workgroup = $domain + + private dir = $privatedir + pid directory = $piddir + lock directory = $lockdir + log file = $logdir/log.\%m + log level = 0 + + name resolve order = bcast + + netbios name = $server + interfaces = $server_ip/8 + bind interfaces only = yes + panic action = $scriptdir/gdb_backtrace %d %\$(MAKE_TEST_BINARY) + + passdb backend = tdbsam + + ; Necessary to add the build farm hacks + add user script = /bin/false + add machine script = /bin/false + + kernel oplocks = no + kernel change notify = no + + syslog = no + printing = bsd + printcap name = /dev/null + +"; + + if ($role eq "dc") { + print CONF "\tdomain logons = yes\n"; + print CONF "\tdomain master = yes\n"; + } + +print CONF " + + winbindd:socket dir = $wbsockdir + +[tmp] + path = $shrdir + read only = no + smbd:sharedelay = 100000 + map hidden = yes + map system = yes + create mask = 755 +[hideunread] + copy = tmp + hide unreadable = yes +[hideunwrite] + copy = tmp + hide unwriteable files = yes +[print1] + copy = tmp + printable = yes + printing = test +[print2] + copy = print1 +[print3] + copy = print1 +[print4] + copy = print1 + "; + close(CONF); + + ## + ## create a test account + ## + + open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $username"); + print PWD "$password\n$password\n"; + close(PWD) or die("Unable to set password for test account"); + + print "DONE\n"; + + $ret{SERVER_IP} = $server_ip; + $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log"; + $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log"; + $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; + $ret{SERVERCONFFILE} = $conffile; + $ret{CONFIGURATION} ="-s $conffile"; + $ret{SERVER} = $server; + $ret{USERNAME} = $username; + $ret{DOMAIN} = $domain; + $ret{NETBIOSNAME} = $server; + $ret{PASSWORD} = $password; + $ret{PIDDIR} = $piddir; + $ret{WINBINDD_SOCKET_DIR} = $wbsockdir; + $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir; + return \%ret; +} + +sub wait_for_start($$) +{ + my ($self, $envvars) = @_; + + # 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($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}"); + # make sure smbd is also up set + print "wait for smbd\n"; + system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2"); + system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2"); + + print $self->getlog_env($envvars); +} + +1; diff --git a/source4/selftest/target/Samba4.pm b/source4/selftest/target/Samba4.pm new file mode 100644 index 0000000000..87a86ef06f --- /dev/null +++ b/source4/selftest/target/Samba4.pm @@ -0,0 +1,915 @@ +#!/usr/bin/perl +# Bootstrap Samba and run a number of tests against it. +# Copyright (C) 2005-2007 Jelmer Vernooij +# Published under the GNU GPL, v3 or later. + +package Samba4; + +use strict; +use Cwd qw(abs_path); +use FindBin qw($RealBin); +use POSIX; + +sub new($$$$) { + my ($classname, $bindir, $ldap, $setupdir) = @_; + my $self = { + vars => {}, + ldap => $ldap, + bindir => $bindir, + setupdir => $setupdir + }; + bless $self; + return $self; +} + +sub openldap_start($$$) { + my ($slapd_conf, $uri, $logs) = @_; + my $oldpath = $ENV{PATH}; + my $olroot = ""; + my $olpath = ""; + if (defined $ENV{OPENLDAP_ROOT}) { + $olroot = "$ENV{OPENLDAP_ROOT}"; + $olpath = "$olroot/libexec:$olroot/sbin:"; + } + $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}"; + system("slapd -d63 -f $slapd_conf -h $uri > $logs 2>&1 &"); + $ENV{PATH} = $oldpath; +} + +sub slapd_start($$) +{ + my $count = 0; + my ($self, $env_vars) = @_; + + my $uri = $env_vars->{LDAP_URI}; + + # running slapd in the background means it stays in the same process group, so it can be + # killed by timelimit + if ($self->{ldap} eq "fedora-ds") { + system("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd -D $env_vars->{FEDORA_DS_DIR} -d0 -i $env_vars->{FEDORA_DS_PIDFILE}> $env_vars->{LDAPDIR}/logs 2>&1 &"); + } elsif ($self->{ldap} eq "openldap") { + openldap_start($env_vars->{SLAPD_CONF}, $uri, "$env_vars->{LDAPDIR}/logs"); + } + while (system("$self->{bindir}/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) { + $count++; + if ($count > 40) { + $self->slapd_stop($env_vars); + return 0; + } + sleep(1); + } + return 1; +} + +sub slapd_stop($$) +{ + my ($self, $envvars) = @_; + if ($self->{ldap} eq "fedora-ds") { + system("$envvars->{LDAPDIR}/slapd-samba4/stop-slapd"); + } elsif ($self->{ldap} eq "openldap") { + open(IN, "<$envvars->{OPENLDAP_PIDFILE}") or + die("unable to open slapd pid file: $envvars->{OPENLDAP_PIDFILE}"); + kill 9, ; + close(IN); + } + return 1; +} + +sub check_or_start($$$) +{ + my ($self, $env_vars, $max_time) = @_; + return 0 if ( -p $env_vars->{SMBD_TEST_FIFO}); + + unlink($env_vars->{SMBD_TEST_FIFO}); + POSIX::mkfifo($env_vars->{SMBD_TEST_FIFO}, 0700); + unlink($env_vars->{SMBD_TEST_LOG}); + + print "STARTING SMBD... "; + my $pid = fork(); + if ($pid == 0) { + open STDIN, $env_vars->{SMBD_TEST_FIFO}; + open STDOUT, ">$env_vars->{SMBD_TEST_LOG}"; + open STDERR, '>&STDOUT'; + + SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE}); + + my $valgrind = ""; + if (defined($ENV{SMBD_VALGRIND})) { + $valgrind = $ENV{SMBD_VALGRIND}; + } + + $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG}; + + $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD}; + $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP}; + + # Start slapd before smbd, but with the fifo on stdin + if (defined($self->{ldap})) { + $self->slapd_start($env_vars) or + die("couldn't start slapd (2nd time)"); + } + + my $optarg = ""; + if (defined($max_time)) { + $optarg = "--maximum-runtime=$max_time "; + } + if (defined($ENV{SMBD_OPTIONS})) { + $optarg.= " $ENV{SMBD_OPTIONS}"; + } + my $ret = system("$valgrind $self->{bindir}/smbd $optarg $env_vars->{CONFIGURATION} -M single -i --leak-report-full"); + if ($? == -1) { + print "Unable to start smbd: $ret: $!\n"; + exit 1; + } + unlink($env_vars->{SMBD_TEST_FIFO}); + my $exit = $? >> 8; + if ( $ret == 0 ) { + print "smbd exits with status $exit\n"; + } elsif ( $ret & 127 ) { + print "smbd got signal ".($ret & 127)." and exits with $exit!\n"; + } else { + $ret = $? >> 8; + print "smbd failed with status $exit!\n"; + } + exit $exit; + } + print "DONE\n"; + + open(DATA, ">$env_vars->{SMBD_TEST_FIFO}"); + + return $pid; +} + +sub wait_for_start($$) +{ + my ($self, $testenv_vars) = @_; + # give time for nbt server to register its names + print "delaying for nbt name registration\n"; + sleep 2; + + # This will return quickly when things are up, but be slow if we + # need to wait for (eg) SSL init + system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSALIAS}"); + system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSALIAS}"); + + print $self->getlog_env($testenv_vars); +} + +sub write_ldb_file($$$) +{ + my ($self, $file, $ldif) = @_; + + open(LDIF, "|$self->{bindir}/ldbadd -H $file >/dev/null"); + print LDIF $ldif; + return close(LDIF); +} + +sub add_wins_config($$) +{ + my ($self, $privatedir) = @_; + + return $self->write_ldb_file("$privatedir/wins_config.ldb", " +dn: name=TORTURE_6,CN=PARTNERS +objectClass: wreplPartner +name: TORTURE_6 +address: 127.0.0.6 +pullInterval: 0 +pushChangeCount: 0 +type: 0x3 +"); +} + +sub mk_fedora_ds($$$) +{ + my ($self, $ldapdir, $configuration) = @_; + + my $fedora_ds_inf = "$ldapdir/fedorads.inf"; + my $fedora_ds_extra_ldif = "$ldapdir/fedorads-partitions.ldif"; + + #Make the subdirectory be as fedora DS would expect + my $fedora_ds_dir = "$ldapdir/slapd-samba4"; + + my $pidfile = "$fedora_ds_dir/logs/slapd-samba4.pid"; + + system("$self->{bindir}/ad2oLschema $configuration -H $ldapdir/schema-tmp.ldb --option=convert:target=fedora-ds -I $self->{setupdir}/schema-map-fedora-ds-1.0 -O $ldapdir/99_ad.ldif >&2") == 0 or die("schema conversion for Fedora DS failed"); + +my $dir = getcwd(); +chdir "$ENV{FEDORA_DS_ROOT}/bin" || die; + if (system("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf >&2") != 0) { + chdir $dir; + die("perl $ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl --silent --file=$fedora_ds_inf FAILED: $?"); + } + chdir $dir || die; + + return ($fedora_ds_dir, $pidfile); +} + +sub mk_openldap($$$) +{ + my ($self, $ldapdir, $configuration) = @_; + + my $slapd_conf = "$ldapdir/slapd.conf"; + my $pidfile = "$ldapdir/slapd.pid"; + my $modconf = "$ldapdir/modules.conf"; + + #This uses the backend provision we just did, to read out the schema + system("$self->{bindir}/ad2oLschema $configuration --option=convert:target=openldap -H $ldapdir/schema-tmp.ldb -I $self->{setupdir}/schema-map-openldap-2.3 -O $ldapdir/backend-schema.schema >&2") == 0 or die("schema conversion for OpenLDAP failed"); + + my $oldpath = $ENV{PATH}; + my $olpath = ""; + my $olroot = ""; + if (defined $ENV{OPENLDAP_ROOT}) { + $olroot = "$ENV{OPENLDAP_ROOT}"; + $olpath = "$olroot/libexec:$olroot/sbin:"; + } + $ENV{PATH} = "$olpath/usr/local/sbin:/usr/sbin:/sbin:$ENV{PATH}"; + + unlink($modconf); + open(CONF, ">$modconf"); close(CONF); + + if (system("slaptest -u -f $slapd_conf >&2") != 0) { + open(CONF, ">$modconf"); + # enable slapd modules + print CONF " +modulepath $olroot/libexec/openldap +moduleload syncprov +moduleload memberof +moduleload refint +"; + close(CONF); + } + if (system("slaptest -u -f $slapd_conf >&2") != 0) { + open(CONF, ">$modconf"); + # enable slapd modules + print CONF " +modulepath $olroot/libexec/openldap +moduleload back_hdb +moduleload syncprov +moduleload memberof +moduleload refint +"; + close(CONF); + } + + if (system("slaptest -u -f $slapd_conf >&2") != 0) { + open(CONF, ">$modconf"); + # enable slapd modules + print CONF " +moduleload back_hdb +moduleload syncprov +moduleload memberof +moduleload refint +"; + close(CONF); + } + + if (system("slaptest -u -f $slapd_conf >&2") != 0) { + open(CONF, ">$modconf"); + # enable slapd modules + print CONF " +modulepath /usr/lib/ldap +moduleload back_hdb +moduleload syncprov +moduleload memberof +moduleload refint +"; + close(CONF); + } + + if (system("slaptest -u -f $slapd_conf >&2") != 0) { + open(CONF, ">$modconf"); + # enable slapd modules (Fedora layout) + print CONF " +modulepath /usr/lib/openldap +moduleload syncprov +moduleload memberof +moduleload refint +"; + close(CONF); + } + + if (system("slaptest -u -f $slapd_conf >&2") != 0) { + open(CONF, ">$modconf"); + # enable slapd modules (Fedora x86_64 layout) + print CONF " +modulepath /usr/lib64/openldap +moduleload syncprov +moduleload memberof +moduleload refint +"; + close(CONF); + } + + system("slaptest -u -f $slapd_conf") == 0 or die("slaptest still fails after adding modules"); + + + $ENV{PATH} = $oldpath; + + return ($slapd_conf, $pidfile); +} + +sub mk_keyblobs($$) +{ + my ($self, $tlsdir) = @_; + + #TLS and PKINIT crypto blobs + my $dhfile = "$tlsdir/dhparms.pem"; + my $cafile = "$tlsdir/ca.pem"; + my $certfile = "$tlsdir/cert.pem"; + my $reqkdc = "$tlsdir/req-kdc.der"; + my $kdccertfile = "$tlsdir/kdc.pem"; + my $keyfile = "$tlsdir/key.pem"; + my $adminkeyfile = "$tlsdir/adminkey.pem"; + my $reqadmin = "$tlsdir/req-admin.der"; + my $admincertfile = "$tlsdir/admincert.pem"; + + mkdir($tlsdir, 0777); + + #This is specified here to avoid draining entropy on every run + open(DHFILE, ">$dhfile"); + print DHFILE <$keyfile"); + print KEYFILE <$adminkeyfile"); + + print ADMINKEYFILE <$cafile"); + print CAFILE <$certfile"); + print CERTFILE <$kdccertfile"); + print KDCCERTFILE <$admincertfile"); + print ADMINCERTFILE <; + my $unix_gids_str = $); + my @unix_gids = split(" ", $unix_gids_str); + my $srcdir="$RealBin/.."; + -d $prefix or mkdir($prefix, 0777) or die("Unable to create $prefix"); + my $prefix_abs = abs_path($prefix); + my $tmpdir = "$prefix_abs/tmp"; + my $etcdir = "$prefix_abs/etc"; + my $piddir = "$prefix_abs/pid"; + my $conffile = "$etcdir/smb.conf"; + my $krb5_config = "$etcdir/krb5.conf"; + my $privatedir = "$prefix_abs/private"; + my $ncalrpcdir = "$prefix_abs/ncalrpc"; + my $lockdir = "$prefix_abs/lockdir"; + my $winbindd_socket_dir = "$prefix_abs/winbind_socket"; + my $winbindd_priv_pipe_dir = "$piddir/smbd.tmp/winbind_pipe"; + my $nsswrap_passwd = "$etcdir/passwd"; + my $nsswrap_group = "$etcdir/group"; + + my $configuration = "--configfile=$conffile"; + my $ldapdir = "$privatedir/ldap"; + + my $tlsdir = "$privatedir/tls"; + + my $ifaceipv4 = "127.0.0.$swiface"; + my $interfaces = "$ifaceipv4/8"; + + (system("rm -rf $prefix/*") == 0) or die("Unable to clean up"); + mkdir($_, 0777) foreach ($privatedir, $etcdir, $piddir, $ncalrpcdir, $lockdir, + $tmpdir); + + + my $localbasedn = $basedn; + $localbasedn = "DC=$netbiosname" if $server_role eq "member server"; + + open(CONFFILE, ">$conffile"); + print CONFFILE " +[global] + netbios name = $netbiosname + netbios aliases = $netbiosalias + workgroup = $domain + realm = $realm + private dir = $privatedir + pid directory = $piddir + ncalrpc dir = $ncalrpcdir + lock dir = $lockdir + setup directory = $self->{setupdir} + modules dir = $self->{bindir}/modules + js include = $srcdir/scripting/libjs + winbindd socket directory = $winbindd_socket_dir + winbind separator = / + name resolve order = bcast + interfaces = $interfaces + tls dh params file = $tlsdir/dhparms.pem + panic action = $srcdir/script/gdb_backtrace \%PID% \%PROG% + wins support = yes + server role = $server_role + max xmit = 32K + server max protocol = SMB2 + notify:inotify = false + ldb:nosync = true + system:anonymous = true +#We don't want to pass our self-tests if the PAC code is wrong + gensec:require_pac = true + log level = $smbd_loglevel + +[tmp] + path = $tmpdir + read only = no + ntvfs handler = posix + posix:sharedelay = 100000 + posix:eadb = $lockdir/eadb.tdb + +[cifs] + read only = no + ntvfs handler = cifs + cifs:server = $netbiosname + cifs:share = tmp +#There is no username specified here, instead the client is expected +#to log in with kerberos, and smbd will used delegated credentials. + +[simple] + path = $tmpdir + read only = no + ntvfs handler = simple + +[cifsposix] + copy = simple + ntvfs handler = cifsposix +"; + close(CONFFILE); + + $self->mk_keyblobs($tlsdir); + + open(KRB5CONF, ">$krb5_config"); + print KRB5CONF " +#Generated krb5.conf for $realm + +[libdefaults] + default_realm = $realm + dns_lookup_realm = false + dns_lookup_kdc = false + ticket_lifetime = 24h + forwardable = yes + +[realms] + $realm = { + kdc = 127.0.0.1:88 + admin_server = 127.0.0.1:88 + default_domain = $dnsname + } + $dnsname = { + kdc = 127.0.0.1:88 + admin_server = 127.0.0.1:88 + default_domain = $dnsname + } + $domain = { + kdc = 127.0.0.1:88 + admin_server = 127.0.0.1:88 + default_domain = $dnsname + } + +[appdefaults] + pkinit_anchors = FILE:$tlsdir/ca.pem + +[kdc] + enable-pkinit = true + pkinit_identity = FILE:$tlsdir/kdc.pem,$tlsdir/key.pem + pkinit_anchors = FILE:$tlsdir/ca.pem + +[domain_realm] + .$dnsname = $realm +"; + close(KRB5CONF); + + open(PWD, ">$nsswrap_passwd"); + print PWD " +root:x:0:0:root gecos:$prefix_abs:/bin/false +$unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false +nobody:x:65534:65533:nobody gecos:$prefix_abs:/bin/false +"; + close(PWD); + + open(GRP, ">$nsswrap_group"); + print GRP " +root:x:0: +wheel:x:10: +users:x:100: +nobody:x:65533: +nogroup:x:65534:nobody +"; + close(GRP); + +#Ensure the config file is valid before we start + if (system("$self->{bindir}/testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) { + system("$self->{bindir}/testparm -v --suppress-prompt $configuration >&2"); + die("Failed to create a valid smb.conf configuration!"); + } + + (system("($self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$netbiosname\" ) >/dev/null 2>&1") == 0) or die("Failed to create a valid smb.conf configuration! $self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global"); + + my @provision_options = (); + push (@provision_options, "NSS_WRAPPER_PASSWD=\"$nsswrap_passwd\""); + push (@provision_options, "NSS_WRAPPER_GROUP=\"$nsswrap_group\""); + if (defined($ENV{PROVISION_PYTHON})) { + push (@provision_options, "$self->{bindir}/smbpython"); + push (@provision_options, "$self->{setupdir}/provision.py"); + } else { + push (@provision_options, "$self->{bindir}/smbscript"); + push (@provision_options, "$self->{setupdir}/provision"); + } + push (@provision_options, split(' ', $configuration)); + push (@provision_options, "--host-name=$netbiosname"); + push (@provision_options, "--host-ip=$ifaceipv4"); + push (@provision_options, "--quiet"); + push (@provision_options, "--domain=$domain"); + push (@provision_options, "--realm=$realm"); + push (@provision_options, "--adminpass=$password"); + push (@provision_options, "--krbtgtpass=krbtgt$password"); + push (@provision_options, "--machinepass=machine$password"); + push (@provision_options, "--root=$unix_name"); + push (@provision_options, "--simple-bind-dn=cn=Manager,$localbasedn"); + push (@provision_options, "--password=$password"); + push (@provision_options, "--server-role=\"$server_role\""); + + my $ldap_uri= "$ldapdir/ldapi"; + $ldap_uri =~ s|/|%2F|g; + $ldap_uri = "ldapi://$ldap_uri"; + + my $ret = { + KRB5_CONFIG => $krb5_config, + PIDDIR => $piddir, + SERVER => $netbiosname, + SERVER_IP => $ifaceipv4, + NETBIOSNAME => $netbiosname, + NETBIOSALIAS => $netbiosalias, + LDAP_URI => $ldap_uri, + DOMAIN => $domain, + USERNAME => $username, + REALM => $realm, + PASSWORD => $password, + LDAPDIR => $ldapdir, + WINBINDD_SOCKET_DIR => $winbindd_socket_dir, + WINBINDD_PRIV_PIPE_DIR => $winbindd_priv_pipe_dir, + NCALRPCDIR => $ncalrpcdir, + LOCKDIR => $lockdir, + CONFIGURATION => $configuration, + SOCKET_WRAPPER_DEFAULT_IFACE => $swiface, + NSS_WRAPPER_PASSWD => $nsswrap_passwd, + NSS_WRAPPER_GROUP => $nsswrap_group, + }; + + if (defined($self->{ldap})) { + + push (@provision_options, "--ldap-backend=$ldap_uri"); + system("$self->{bindir}/smbscript $self->{setupdir}/provision-backend $configuration --ldap-manager-pass=$password --root=$unix_name --realm=$realm --host-name=$netbiosname --ldap-backend-type=$self->{ldap}>&2") == 0 or die("backend provision failed"); + + if ($self->{ldap} eq "openldap") { + ($ret->{SLAPD_CONF}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ldapdir, $configuration) or die("Unable to create openldap directories"); + } elsif ($self->{ldap} eq "fedora-ds") { + ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ldapdir, $configuration) or die("Unable to create fedora ds directories"); + push (@provision_options, "--ldap-module=nsuniqueid"); + push (@provision_options, "'--aci=aci:: KHRhcmdldGF0dHIgPSAiKiIpICh2ZXJzaW9uIDMuMDthY2wgImZ1bGwgYWNjZXNzIHRvIGFsbCBieSBhbGwiO2FsbG93IChhbGwpKHVzZXJkbiA9ICJsZGFwOi8vL2FueW9uZSIpOykK'"); + } + + $self->slapd_start($ret) or + die("couldn't start slapd"); + } + + my $provision_cmd = join(" ", @provision_options); + (system($provision_cmd) == 0) or die("Unable to provision: \n$provision_cmd\n"); + + if (defined($self->{ldap})) { + $self->slapd_stop($ret) or + die("couldn't stop slapd"); + } + + return $ret; +} + +sub provision_member($$$) +{ + my ($self, $prefix, $dcvars) = @_; + print "PROVISIONING MEMBER..."; + + my $ret = $self->provision($prefix, + "member server", + "localmember3", + "localmember", + 3, + "localmemberpass"); + + $ret or die("Unable to provision"); + + my $cmd = ""; + $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; + $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" "; + $cmd .= "$self->{bindir}/net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member"; + $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}"; + + system($cmd) == 0 or die("Join failed\n$cmd"); + + $ret->{SMBD_TEST_FIFO} = "$prefix/smbd_test.fifo"; + $ret->{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; + $ret->{SMBD_TEST_LOG_POS} = 0; + + $ret->{DC_SERVER} = $dcvars->{SERVER}; + $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP}; + $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME}; + $ret->{DC_NETBIOSALIAS} = $dcvars->{NETBIOSALIAS}; + $ret->{DC_USERNAME} = $dcvars->{USERNAME}; + $ret->{DC_PASSWORD} = $dcvars->{PASSWORD}; + + return $ret; +} + +sub provision_dc($$) +{ + my ($self, $prefix) = @_; + + print "PROVISIONING DC..."; + my $ret = $self->provision($prefix, + "domain controller", + "localdc1", + "localdc", + 1, + "localdcpass"); + + $self->add_wins_config("$prefix/private") or + die("Unable to add wins configuration"); + + $ret->{SMBD_TEST_FIFO} = "$prefix/smbd_test.fifo"; + $ret->{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; + $ret->{SMBD_TEST_LOG_POS} = 0; + return $ret; +} + +sub teardown_env($$) +{ + my ($self, $envvars) = @_; + my $pid; + + close(DATA); + + if (-f "$envvars->{PIDDIR}/smbd.pid" ) { + open(IN, "<$envvars->{PIDDIR}/smbd.pid") or die("unable to open smbd pid file"); + $pid = ; + close(IN); + + # 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 it is still around, kill it + if ($count > 20) { + print "smbd process $pid took more than $count seconds to exit, killing\n"; + kill 9, $pid; + } + } + + my $failed = $? >> 8; + + $self->slapd_stop($envvars) if ($self->{ldap}); + + print $self->getlog_env($envvars); + + return $failed; +} + +sub getlog_env($$) +{ + my ($self, $envvars) = @_; + my $title = "SMBD LOG of: $envvars->{NETBIOSNAME}\n"; + my $out = $title; + + open(LOG, "<$envvars->{SMBD_TEST_LOG}"); + + seek(LOG, $envvars->{SMBD_TEST_LOG_POS}, SEEK_SET); + while () { + $out .= $_; + } + $envvars->{SMBD_TEST_LOG_POS} = tell(LOG); + close(LOG); + + return "" if $out eq $title; + + return $out; +} + +sub check_env($$) +{ + my ($self, $envvars) = @_; + + return 1 if (-p $envvars->{SMBD_TEST_FIFO}); + + print $self->getlog_env($envvars); + + return 0; +} + +sub setup_env($$$) +{ + my ($self, $envname, $path) = @_; + + if ($envname eq "dc") { + return $self->setup_dc("$path/dc"); + } elsif ($envname eq "member") { + if (not defined($self->{vars}->{dc})) { + $self->setup_dc("$path/dc"); + } + return $self->setup_member("$path/member", $self->{vars}->{dc}); + } else { + die("Samba4 can't provide environment '$envname'"); + } +} + +sub setup_member($$$$) +{ + my ($self, $path, $dc_vars) = @_; + + my $env = $self->provision_member($path, $dc_vars); + + $self->check_or_start($env, ($ENV{SMBD_MAXTIME} or 7500)); + + $self->wait_for_start($env); + + return $env; +} + +sub setup_dc($$) +{ + my ($self, $path) = @_; + + my $env = $self->provision_dc($path); + + $self->check_or_start($env, + ($ENV{SMBD_MAXTIME} or 7500)); + + $self->wait_for_start($env); + + $self->{vars}->{dc} = $env; + + return $env; +} + +sub stop($) +{ + my ($self) = @_; +} + +1; diff --git a/source4/selftest/target/Windows.pm b/source4/selftest/target/Windows.pm new file mode 100644 index 0000000000..d0c90d7f7b --- /dev/null +++ b/source4/selftest/target/Windows.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# Bootstrap Samba and run a number of tests against it. +# Copyright (C) 2005-2007 Jelmer Vernooij +# Published under the GNU GPL, v3 or later. + +package Windows; + +use strict; +use FindBin qw($RealBin); +use POSIX; + +sub new($) +{ + my ($classname) = @_; + my $self = { }; + bless $self; + return $self; +} + +sub provision($$$) +{ + my ($self, $environment, $prefix) = @_; + + die ("Windows tests will not run without root privileges.") + if (`whoami` ne "root"); + + die("Environment variable WINTESTCONF has not been defined.\n". + "Windows tests will not run unconfigured.") if (not defined($ENV{WINTESTCONF})); + + die ("$ENV{WINTESTCONF} could not be read.") if (! -r $ENV{WINTESTCONF}); + + $ENV{WINTEST_DIR}="$ENV{SRCDIR}/selftest/win"; +} + +sub setup_env($$) +{ + my ($self, $name) = @_; +} + +1; -- cgit From 6508824f394ceac5cd16b3e620bffd18fe577fc1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 17:50:29 +0100 Subject: python: Don't attempt to build shared and static versions of modules, because it's just not going to work with the current build system. (This used to be commit d9b4a5bb172be74db3c16b50426810f1bdedd00e) --- source4/build/smb_build/input.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/build/smb_build/input.pm b/source4/build/smb_build/input.pm index 0b26aee65e..6d5c4f4a1e 100644 --- a/source4/build/smb_build/input.pm +++ b/source4/build/smb_build/input.pm @@ -182,7 +182,7 @@ sub check_python($$$) $python->{SUBSYSTEM} = "LIBPYTHON"; - check_module($INPUT, $python, ["SHARED_LIBRARY", "STATIC_LIBRARY"]); + check_module($INPUT, $python, $default_ot); } sub check_binary($$) -- cgit From 797e8db3ba1e0038db553af6f564e221479ac381 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Jan 2008 21:30:58 +0100 Subject: selftest: Use "require" rather than "use" keyword so .pm files don't have to be provided until used. (This used to be commit 95872d7db8c9bb1914ab4c9860fd8b09e6695cc7) --- source4/selftest/selftest.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl index 46c3846b54..004332a1fc 100755 --- a/source4/selftest/selftest.pl +++ b/source4/selftest/selftest.pl @@ -426,20 +426,20 @@ my $testenv_default = "none"; if ($opt_target eq "samba4") { $testenv_default = "member"; - use target::Samba4; + require target::Samba4; $target = new Samba4($opt_bindir or "$srcdir/bin", $ldap, "$srcdir/setup"); } elsif ($opt_target eq "samba3") { if ($opt_socket_wrapper and `$opt_bindir/smbd -b | grep SOCKET_WRAPPER` eq "") { die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting...."); } $testenv_default = "dc"; - use target::Samba3; + require target::Samba3; $target = new Samba3($opt_bindir); } elsif ($opt_target eq "win") { die("Windows tests will not run with socket wrapper enabled.") if ($opt_socket_wrapper); $testenv_default = "dc"; - use target::Windows; + require target::Windows; $target = new Windows(); } -- cgit