summaryrefslogtreecommitdiff
path: root/source4/script/tests/Samba4.pm
diff options
context:
space:
mode:
Diffstat (limited to 'source4/script/tests/Samba4.pm')
-rw-r--r--source4/script/tests/Samba4.pm100
1 files changed, 72 insertions, 28 deletions
diff --git a/source4/script/tests/Samba4.pm b/source4/script/tests/Samba4.pm
index c4c0598ff5..0a92f36dc8 100644
--- a/source4/script/tests/Samba4.pm
+++ b/source4/script/tests/Samba4.pm
@@ -5,18 +5,21 @@
package Samba4;
-use Exporter;
-@ISA = qw(Exporter);
-@EXPORT_OK = qw(slapd_start slapd_stop smbd_check_or_start provision);
-
use strict;
use FindBin qw($RealBin);
use POSIX;
+sub new($$$$) {
+ my ($classname, $bindir, $ldap, $setupdir) = @_;
+ my $self = { ldap => $ldap, bindir => $bindir, setupdir => $setupdir };
+ bless $self;
+ return $self;
+}
+
sub slapd_start($$$)
{
- my $count = 0;
- my ($bindir, $conf, $uri) = @_;
+ my $count = 0;
+ my ($self, $conf, $uri) = @_;
# running slapd in the background means it stays in the same process group, so it can be
# killed by timelimit
if (defined($ENV{FEDORA_DS_PREFIX})) {
@@ -27,10 +30,10 @@ sub slapd_start($$$)
system("slapd -d$ENV{OPENLDAP_LOGLEVEL} -f $conf -h $uri > $ENV{LDAPDIR}/logs 2>&1 &");
$ENV{PATH} = $oldpath;
}
- while (system("$bindir/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
+ while (system("$self->{bindir}/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
$count++;
if ($count > 10) {
- slapd_stop();
+ $self->slapd_stop();
return 0;
}
sleep(1);
@@ -38,8 +41,9 @@ sub slapd_start($$$)
return 1;
}
-sub slapd_stop()
+sub slapd_stop($)
{
+ my ($self) = @_;
if (defined($ENV{FEDORA_DS_PREFIX})) {
system("$ENV{LDAPDIR}/slapd-samba4/stop-slapd");
} else {
@@ -50,39 +54,48 @@ sub slapd_stop()
}
}
-sub smbd_check_or_start($$$$$$)
+sub check_or_start($$$$)
{
- my ($bindir, $test_fifo, $test_log, $socket_wrapper_dir, $max_time, $conffile) = @_;
- return 0 if ( -p $test_fifo );
+ my ($self, $env_vars, $socket_wrapper_dir, $max_time) = @_;
+ return 0 if ( -p $env_vars->{SMBD_TEST_FIFO});
+
+ # Start slapd before smbd
+ if ($self->{ldap}) {
+ $self->slapd_start($ENV{SLAPD_CONF}, $ENV{LDAP_URI}) or
+ die("couldn't start slapd");
+
+ print "LDAP PROVISIONING...";
+ $self->provision_ldap();
+ }
warn("Not using socket wrapper, but also not running as root. Will not be able to listen on proper ports") unless
defined($socket_wrapper_dir) or $< == 0;
- unlink($test_fifo);
- POSIX::mkfifo($test_fifo, 0700);
- unlink($test_log);
+ unlink($env_vars->{SMBD_TEST_FIFO});
+ POSIX::mkfifo($env_vars->{SMBD_TEST_FIFO}, 0700);
+ unlink($env_vars->{SMBD_TEST_LOG});
my $valgrind = "";
if (defined($ENV{SMBD_VALGRIND})) {
$valgrind = $ENV{SMBD_VALGRIND};
}
- print "STARTING SMBD...";
+ print "STARTING SMBD... ";
my $pid = fork();
if ($pid == 0) {
- open STDIN, $test_fifo;
- open STDOUT, ">$test_log";
+ open STDIN, $env_vars->{SMBD_TEST_FIFO};
+ open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
open STDERR, '>&STDOUT';
my $optarg = "";
if (defined($max_time)) {
$optarg = "--maximum-runtime=$max_time ";
}
- my $ret = system("$valgrind $bindir/smbd $optarg -s $conffile -M single -i --leak-report-full");
+ my $ret = system("$valgrind $self->{bindir}/smbd $optarg -s $env_vars->{CONFFILE} -M single -i --leak-report-full");
if ($? == -1) {
print "Unable to start smbd: $ret: $!\n";
exit 1;
}
- unlink($test_fifo);
+ unlink($env_vars->{SMBD_TEST_FIFO});
unlink(<$socket_wrapper_dir/*>) if (defined($socket_wrapper_dir) and -d $socket_wrapper_dir);
my $exit = $? >> 8;
if ( $ret == 0 ) {
@@ -97,10 +110,12 @@ sub smbd_check_or_start($$$$$$)
}
print "DONE\n";
+ open(DATA, ">$env_vars->{SMBD_TEST_FIFO}");
+
return $pid;
}
-sub wait_for_start()
+sub wait_for_start($)
{
# give time for nbt server to register its names
print "delaying for nbt name registration\n";
@@ -117,25 +132,54 @@ sub wait_for_start()
system("bin/nmblookup $ENV{CONFIGURATION} -U $ENV{SERVER} $ENV{NETBIOSNAME}");
}
-sub provision($)
+sub provision($$$)
{
- my ($prefix) = @_;
+ my ($self, $environment, $prefix) = @_;
my %ret = ();
print "PROVISIONING...";
- open(IN, "$RealBin/mktestsetup.sh $prefix|") or die("Unable to setup");
+ open(IN, "$RealBin/mktestdc.sh $prefix|") or die("Unable to setup");
while (<IN>) {
die ("Error parsing `$_'") unless (/^([A-Z0-9a-z_]+)=(.*)$/);
$ret{$1} = $2;
}
close(IN);
+
+ $ret{SMBD_TEST_FIFO} = "$prefix/smbd_test.fifo";
+ $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
return \%ret;
}
-sub provision_ldap($$)
+sub provision_ldap($)
+{
+ my ($self) = @_;
+ system("$self->{bindir}/smbscript $self->{setupdir}/provision $ENV{PROVISION_OPTIONS} \"$ENV{PROVISION_ACI}\" --ldap-backend=$ENV{LDAP_URI}") and
+ die("LDAP PROVISIONING failed: $self->{bindir}/smbscript $self->{setupdir}/provision $ENV{PROVISION_OPTIONS} \"$ENV{PROVISION_ACI}\" --ldap-backend=$ENV{LDAP_URI}");
+}
+
+sub stop($)
+{
+ my ($self) = @_;
+
+ close(DATA);
+
+ sleep(2);
+
+ my $failed = $? >> 8;
+
+ if (-f "$ENV{PIDDIR}/smbd.pid" ) {
+ open(IN, "<$ENV{PIDDIR}/smbd.pid") or die("unable to open smbd pid file");
+ kill 9, <IN>;
+ close(IN);
+ }
+
+ $self->slapd_stop() if ($self->{ldap});
+
+ return $failed;
+}
+
+sub setup_env($$)
{
- my ($bindir, $setupdir) = @_;
- system("$bindir/smbscript $setupdir/provision $ENV{PROVISION_OPTIONS} \"$ENV{PROVISION_ACI}\" --ldap-backend=$ENV{LDAP_URI}") and
- die("LDAP PROVISIONING failed: $bindir/smbscript $setupdir/provision $ENV{PROVISION_OPTIONS} \"$ENV{PROVISION_ACI}\" --ldap-backend=$ENV{LDAP_URI}");
+ my ($self, $name) = @_;
}
1;