From 86a137b6ccefc2c2206843f31c9377beb711e3d3 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze@samba.org>
Date: Tue, 17 Apr 2007 13:06:00 +0000
Subject: [PATCH] r22305: fix make test using a absolute path for
 --with-selftest-prefix

metze
(This used to be commit b9dc78c3ad4c636bd8356978c18313ab4277cd64)
---
 source4/script/tests/Samba4.pm   |  4 ++--
 source4/script/tests/selftest.pl | 26 +++++++++++++++++---------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/source4/script/tests/Samba4.pm b/source4/script/tests/Samba4.pm
index 28d8b91aa55..cc8f619c797 100644
--- a/source4/script/tests/Samba4.pm
+++ b/source4/script/tests/Samba4.pm
@@ -6,6 +6,7 @@
 package Samba4;
 
 use strict;
+use Cwd qw(abs_path);
 use FindBin qw($RealBin);
 use POSIX;
 
@@ -403,8 +404,7 @@ sub provision($$$$$)
 	my $server = "localhost";
 	my $srcdir="$RealBin/../..";
 	-d $prefix or mkdir($prefix) or die("Unable to create $prefix");
-	my $prefix_abs = getcwd()."/".$prefix;
-
+	my $prefix_abs = abs_path($prefix);
 	my $tmpdir = "$prefix_abs/tmp";
 	my $etcdir = "$prefix_abs/etc";
 	my $piddir = "$prefix_abs/pid";
diff --git a/source4/script/tests/selftest.pl b/source4/script/tests/selftest.pl
index 0f7b29c258e..f834918b8eb 100755
--- a/source4/script/tests/selftest.pl
+++ b/source4/script/tests/selftest.pl
@@ -113,7 +113,7 @@ use FindBin qw($RealBin $Script);
 use File::Spec;
 use Getopt::Long;
 use POSIX;
-use Cwd;
+use Cwd qw(abs_path);
 use lib "$RealBin";
 use Samba3;
 use Samba4;
@@ -136,7 +136,7 @@ my $opt_resetup_env = undef;
 
 my $srcdir = ".";
 my $builddir = ".";
-my $prefix = "st";
+my $prefix = "./st";
 
 my $suitesfailed = [];
 my $start = time();
@@ -370,6 +370,16 @@ if ($ldap) {
 }
 
 $prefix =~ s+//+/+;
+$prefix =~ s+/./+/+;
+$prefix =~ s+/$++;
+
+my $prefix_abs = abs_path($prefix);
+my $srcdir_abs = abs_path($srcdir);
+
+die("using an empty prefix isn't allowed") unless $prefix ne "";
+die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
+die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
+
 $ENV{PREFIX} = $prefix;
 $ENV{SRCDIR} = $srcdir;
 
@@ -442,14 +452,12 @@ my $interfaces = join(',', ("127.0.0.6/8",
 			    "127.0.0.10/8",
 			    "127.0.0.11/8"));
 
-my $conffile = "$prefix/client.conf";
+my $conffile = "$prefix_abs/client/client.conf";
 
 sub write_clientconf($$)
 {
 	my ($conffile, $vars) = @_;
 
-	my $abs_srcdir = cwd();
-
 	mkdir "$prefix/client" unless -d "$prefix/client";
 	
 	if ( -d "$prefix/client/private" ) {
@@ -482,16 +490,16 @@ sub write_clientconf($$)
 		print CF "\twinbindd socket directory = $vars->{WINBINDD_SOCKET_DIR}\n";
 	}
 	print CF "
-        private dir = $abs_srcdir/$prefix/client/private
-	js include = $abs_srcdir/scripting/libjs
+	private dir = $srcdir_abs/$prefix/client/private
+	js include = $srcdir_abs/scripting/libjs
 	name resolve order = bcast
 	interfaces = $interfaces
-	panic action = $abs_srcdir/script/gdb_backtrace \%PID\% \%PROG\%
+	panic action = $srcdir_abs/script/gdb_backtrace \%PID\% \%PROG\%
 	max xmit = 32K
 	notify:inotify = false
 	ldb:nosync = true
 	system:anonymous = true
-	torture:basedir = ./st
+	torture:basedir = $prefix_abs
 #We don't want to pass our self-tests if the PAC code is wrong
 	gensec:require_pac = true
 ";