884a19
From b67bc28be3e0ab40e14f698951c9ba057ea8321d Mon Sep 17 00:00:00 2001
884a19
From: Andreas Schneider <asn@samba.org>
884a19
Date: Thu, 15 Nov 2018 16:06:49 +0100
884a19
Subject: [PATCH 1/4] selftest: Add gooduser and eviluser to Samba3
884a19
MIME-Version: 1.0
884a19
Content-Type: text/plain; charset=UTF-8
884a19
Content-Transfer-Encoding: 8bit
884a19
884a19
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13699
884a19
884a19
Signed-off-by: Andreas Schneider <asn@samba.org>
884a19
Reviewed-by: Ralph Böhme <slow@samba.org>
884a19
Reviewed-by: Jeremy Allison <jra@samba.org>
884a19
(cherry picked from commit 3b38dddff2c1d1b51aed96368b358f349682bea0)
884a19
---
884a19
 selftest/target/Samba3.pm | 10 +++++++++-
884a19
 1 file changed, 9 insertions(+), 1 deletion(-)
884a19
884a19
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
884a19
index 438cb3409bb..373f8152ca3 100755
884a19
--- a/selftest/target/Samba3.pm
884a19
+++ b/selftest/target/Samba3.pm
884a19
@@ -1610,8 +1610,10 @@ sub provision($$$$$$$$$)
884a19
	my ($gid_force_user);
884a19
	my ($uid_user1);
884a19
	my ($uid_user2);
884a19
+	my ($uid_gooduser);
884a19
+	my ($uid_eviluser);
884a19
884a19
-	if ($unix_uid < 0xffff - 10) {
884a19
+	if ($unix_uid < 0xffff - 12) {
884a19
		$max_uid = 0xffff;
884a19
	} else {
884a19
		$max_uid = $unix_uid;
884a19
@@ -1627,6 +1629,8 @@ sub provision($$$$$$$$$)
884a19
	$uid_smbget = $max_uid - 8;
884a19
	$uid_user1 = $max_uid - 9;
884a19
	$uid_user2 = $max_uid - 10;
884a19
+	$uid_gooduser = $max_uid - 11;
884a19
+	$uid_eviluser = $max_uid - 12;
884a19
884a19
	if ($unix_gids[0] < 0xffff - 8) {
884a19
		$max_gid = 0xffff;
884a19
@@ -2248,6 +2252,8 @@ force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/f
884a19
 smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
884a19
 user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
884a19
 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
884a19
+gooduser:x:$uid_gooduser:$gid_domusers:gooduser gecos:$prefix_abs:/bin/false
884a19
+eviluser:x:$uid_eviluser:$gid_domusers:eviluser gecos::/bin/false
884a19
 ";
884a19
	if ($unix_uid != 0) {
884a19
		print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
884a19
@@ -2324,6 +2330,8 @@ force_user:x:$gid_force_user:
884a19
	createuser($self, "smbget_user", $password, $conffile, \%createuser_env) || die("Unable to create smbget_user");
884a19
	createuser($self, "user1", $password, $conffile, \%createuser_env) || die("Unable to create user1");
884a19
	createuser($self, "user2", $password, $conffile, \%createuser_env) || die("Unable to create user2");
884a19
+	createuser($self, "gooduser", $password, $conffile, \%createuser_env) || die("Unable to create gooduser");
884a19
+	createuser($self, "eviluser", $password, $conffile, \%createuser_env) || die("Unable to create eviluser");
884a19
884a19
	open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
884a19
	print DNS_UPDATE_LIST "A $server. $server_ip\n";
884a19
--
884a19
2.19.2
884a19
884a19
884a19
From ca57b6e4f02c725a3f47b8dde01d4b70dce42784 Mon Sep 17 00:00:00 2001
884a19
From: Andreas Schneider <asn@samba.org>
884a19
Date: Fri, 16 Nov 2018 15:40:59 +0100
884a19
Subject: [PATCH 2/4] s3:tests: Test for users connecting to their 'homes'
884a19
 share
884a19
MIME-Version: 1.0
884a19
Content-Type: text/plain; charset=UTF-8
884a19
Content-Transfer-Encoding: 8bit
884a19
884a19
This adds a test for CVE-2009-2813.
884a19
884a19
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13699
884a19
884a19
Signed-off-by: Andreas Schneider <asn@samba.org>
884a19
Reviewed-by: Ralph Böhme <slow@samba.org>
884a19
(cherry picked from commit cc471448df91c43fe38e2fcdf9b3874636ca51a6)
884a19
---
884a19
 selftest/target/Samba3.pm          |  4 ++
884a19
 source3/script/tests/test_homes.sh | 99 ++++++++++++++++++++++++++++++
884a19
 source3/selftest/tests.py          |  1 +
884a19
 3 files changed, 104 insertions(+)
884a19
 create mode 100755 source3/script/tests/test_homes.sh
884a19
884a19
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
884a19
index 373f8152ca3..2031003210c 100755
884a19
--- a/selftest/target/Samba3.pm
884a19
+++ b/selftest/target/Samba3.pm
884a19
@@ -921,6 +921,10 @@ sub setup_fileserver
884a19
	comment = inherit only unix owner
884a19
	inherit owner = unix only
884a19
	acl_xattr:ignore system acls = yes
884a19
+[homes]
884a19
+	comment = Home directories
884a19
+	browseable = No
884a19
+	read only = No
884a19
 ";
884a19
884a19
	my $vars = $self->provision($path, "WORKGROUP",
884a19
diff --git a/source3/script/tests/test_homes.sh b/source3/script/tests/test_homes.sh
884a19
new file mode 100755
884a19
index 00000000000..06de0a0c301
884a19
--- /dev/null
884a19
+++ b/source3/script/tests/test_homes.sh
884a19
@@ -0,0 +1,99 @@
884a19
+#!/bin/sh
884a19
+
884a19
+# Copyright (c) Andreas Schneider <asn@samba.org>
884a19
+# License: GPLv3
884a19
+
884a19
+if [ $# -lt 7 ]; then
884a19
+	echo "Usage: test_homes.sh SERVER USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT CONFIGURATION"
884a19
+	exit 1
884a19
+fi
884a19
+
884a19
+SERVER="${1}"
884a19
+USERNAME="${2}"
884a19
+PASSWORD="${3}"
884a19
+LOCAL_PATH="${4}"
884a19
+PREFIX="${5}"
884a19
+SMBCLIENT="${6}"
884a19
+CONFIGURATION="${7}"
884a19
+shift 7
884a19
+
884a19
+incdir=`dirname $0`/../../../testprogs/blackbox
884a19
+. $incdir/subunit.sh
884a19
+
884a19
+failed=0
884a19
+
884a19
+test_gooduser_home()
884a19
+{
884a19
+    tmpfile=$PREFIX/smbclient_homes_gooduser_commands
884a19
+    cat > $tmpfile <
884a19
+ls
884a19
+quit
884a19
+EOF
884a19
+
884a19
+    USERNAME=gooduser
884a19
+
884a19
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/$USERNAME $CONFIGURATION < $tmpfile 2>&1'
884a19
+    eval echo "$cmd"
884a19
+    out=$(eval $cmd)
884a19
+    ret=$?
884a19
+    rm -f $tmpfile
884a19
+
884a19
+    if [ $ret -ne 0 ] ; then
884a19
+       echo "$out"
884a19
+       echo "failed to connect error $ret"
884a19
+       return 1
884a19
+    fi
884a19
+
884a19
+    echo "$out" | grep 'Try "help" to get a list of possible commands.'
884a19
+    ret=$?
884a19
+    if [ $ret -ne 0 ] ; then
884a19
+       echo "$out"
884a19
+       echo 'failed - should get: Try "help" to get a list of possible commands.'
884a19
+       return 1
884a19
+    fi
884a19
+
884a19
+    return 0
884a19
+}
884a19
+
884a19
+test_eviluser_home()
884a19
+{
884a19
+    tmpfile=$PREFIX/smbclient_homes_eviluser_commands
884a19
+    cat > $tmpfile <
884a19
+ls
884a19
+quit
884a19
+EOF
884a19
+
884a19
+    USERNAME=eviluser
884a19
+
884a19
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/$USERNAME $CONFIGURATION < $tmpfile 2>&1'
884a19
+    eval echo "$cmd"
884a19
+    out=$(eval $cmd)
884a19
+    ret=$?
884a19
+    rm -f $tmpfile
884a19
+
884a19
+    if [ $ret -ne 1 ] ; then
884a19
+       echo "$out"
884a19
+       echo "The server should reject connecting ret=$ret"
884a19
+       return 1
884a19
+    fi
884a19
+
884a19
+    echo "$out" | grep 'NT_STATUS_BAD_NETWORK_NAME'
884a19
+    ret=$?
884a19
+    if [ $ret -ne 0 ] ; then
884a19
+       echo "$out"
884a19
+       echo 'failed - should get: NT_STATUS_BAD_NETWORK_NAME.'
884a19
+       return 1
884a19
+    fi
884a19
+
884a19
+    return 0
884a19
+}
884a19
+
884a19
+testit "test gooduser home" \
884a19
+    test_gooduser_home || \
884a19
+    failed=`expr $failed + 1`
884a19
+
884a19
+testit "test eviluser home reject" \
884a19
+    test_eviluser_home || \
884a19
+    failed=`expr $failed + 1`
884a19
+
884a19
+testok $0 $failed
884a19
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
884a19
index 09cd5159a0d..4aef7a4d596 100755
884a19
--- a/source3/selftest/tests.py
884a19
+++ b/source3/selftest/tests.py
884a19
@@ -290,6 +290,7 @@ for env in ["fileserver"]:
884a19
     plantestsuite("samba3.blackbox.large_acl.NT1", env, [os.path.join(samba3srcdir, "script/tests/test_large_acl.sh"), '$SERVER', '$USERNAME', '$PASSWORD', smbclient3, smbcacls, '-m', 'NT1'])
884a19
     plantestsuite("samba3.blackbox.large_acl.SMB3", env, [os.path.join(samba3srcdir, "script/tests/test_large_acl.sh"), '$SERVER', '$USERNAME', '$PASSWORD', smbclient3, smbcacls, '-m', 'SMB3'])
884a19
     plantestsuite("samba3.blackbox.give_owner", env, [os.path.join(samba3srcdir, "script/tests/test_give_owner.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$PREFIX', smbclient3, smbcacls, net, 'tmp'])
884a19
+    plantestsuite("samba3.blackbox.homes", env, [os.path.join(samba3srcdir, "script/tests/test_homes.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', '$PREFIX', smbclient3, configuration])
884a19
884a19
     #
884a19
     # tar command tests
884a19
--
884a19
2.19.2
884a19
884a19
884a19
From 274e960fde8e680a487fd7f3af57c824f9a5151b Mon Sep 17 00:00:00 2001
884a19
From: Andreas Schneider <asn@samba.org>
884a19
Date: Thu, 22 Nov 2018 18:23:24 +0100
884a19
Subject: [PATCH 3/4] s3:smbd: Make sure we do not export "/" (root) as home
884a19
 dir
884a19
MIME-Version: 1.0
884a19
Content-Type: text/plain; charset=UTF-8
884a19
Content-Transfer-Encoding: 8bit
884a19
884a19
If "/" (root) is returned as the home directory, prevent exporting it.
884a19
884a19
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13699
884a19
884a19
Signed-off-by: Andreas Schneider <asn@samba.org>
884a19
Reviewed-by: Ralph Böhme <slow@samba.org>
884a19
(cherry picked from commit 99695528f7453023446956d5f8f0656574e243af)
884a19
---
884a19
 source3/param/service.c | 6 +++++-
884a19
 source3/smbd/password.c | 7 +++++++
884a19
 2 files changed, 12 insertions(+), 1 deletion(-)
884a19
884a19
diff --git a/source3/param/service.c b/source3/param/service.c
884a19
index b21be6093d4..22f46f08894 100644
884a19
--- a/source3/param/service.c
884a19
+++ b/source3/param/service.c
884a19
@@ -149,7 +149,11 @@ int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out)
884a19
		DEBUG(3,("checking for home directory %s gave %s\n",*p_service_out,
884a19
			phome_dir?phome_dir:"(NULL)"));
884a19
884a19
-		iService = add_home_service(*p_service_out,*p_service_out /* 'username' */, phome_dir);
884a19
+		if (!strequal(phome_dir, "/")) {
884a19
+			iService = add_home_service(*p_service_out,
884a19
+						    *p_service_out, /* username */
884a19
+						    phome_dir);
884a19
+		}
884a19
	}
884a19
884a19
	/* If we still don't have a service, attempt to add it as a printer. */
884a19
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
884a19
index f472bda2c70..0576d2563eb 100644
884a19
--- a/source3/smbd/password.c
884a19
+++ b/source3/smbd/password.c
884a19
@@ -129,6 +129,13 @@ int register_homes_share(const char *username)
884a19
		return -1;
884a19
	}
884a19
884a19
+	if (strequal(pwd->pw_dir, "/")) {
884a19
+		DBG_NOTICE("Invalid home directory defined for user '%s'\n",
884a19
+			   username);
884a19
+		TALLOC_FREE(pwd);
884a19
+		return -1;
884a19
+	}
884a19
+
884a19
	DEBUG(3, ("Adding homes service for user '%s' using home directory: "
884a19
		  "'%s'\n", username, pwd->pw_dir));
884a19
884a19
--
884a19
2.19.2
884a19
884a19
884a19
From e26c6aa97e57432d2f2fee2eba870ba76c9b8d41 Mon Sep 17 00:00:00 2001
884a19
From: Andreas Schneider <asn@samba.org>
884a19
Date: Mon, 3 Dec 2018 11:05:46 +0100
884a19
Subject: [PATCH 4/4] s3:tests: Add test for checking that root is not allowed
884a19
 as home dir
884a19
MIME-Version: 1.0
884a19
Content-Type: text/plain; charset=UTF-8
884a19
Content-Transfer-Encoding: 8bit
884a19
884a19
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13699
884a19
884a19
Signed-off-by: Andreas Schneider <asn@samba.org>
884a19
Reviewed-by: Ralph Böhme <slow@samba.org>
884a19
Reviewed-by: Jeremy Allison <jra@samba.org>
884a19
884a19
Autobuild-User(master): Jeremy Allison <jra@samba.org>
884a19
Autobuild-Date(master): Wed Dec  5 05:22:43 CET 2018 on sn-devel-144
884a19
884a19
(cherry picked from commit a92f0ccce606be12e851a4100fbb44b069c5fe87)
884a19
---
884a19
 selftest/target/Samba3.pm          |  6 ++++-
884a19
 source3/script/tests/test_homes.sh | 37 ++++++++++++++++++++++++++++++
884a19
 2 files changed, 42 insertions(+), 1 deletion(-)
884a19
884a19
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
884a19
index 2031003210c..583396b3818 100755
884a19
--- a/selftest/target/Samba3.pm
884a19
+++ b/selftest/target/Samba3.pm
884a19
@@ -1616,8 +1616,9 @@ sub provision($$$$$$$$$)
884a19
	my ($uid_user2);
884a19
	my ($uid_gooduser);
884a19
	my ($uid_eviluser);
884a19
+	my ($uid_slashuser);
884a19
884a19
-	if ($unix_uid < 0xffff - 12) {
884a19
+	if ($unix_uid < 0xffff - 13) {
884a19
		$max_uid = 0xffff;
884a19
	} else {
884a19
		$max_uid = $unix_uid;
884a19
@@ -1635,6 +1636,7 @@ sub provision($$$$$$$$$)
884a19
	$uid_user2 = $max_uid - 10;
884a19
	$uid_gooduser = $max_uid - 11;
884a19
	$uid_eviluser = $max_uid - 12;
884a19
+	$uid_slashuser = $max_uid - 13;
884a19
884a19
	if ($unix_gids[0] < 0xffff - 8) {
884a19
		$max_gid = 0xffff;
884a19
@@ -2258,6 +2260,7 @@ user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
884a19
 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
884a19
 gooduser:x:$uid_gooduser:$gid_domusers:gooduser gecos:$prefix_abs:/bin/false
884a19
 eviluser:x:$uid_eviluser:$gid_domusers:eviluser gecos::/bin/false
884a19
+slashuser:x:$uid_slashuser:$gid_domusers:slashuser gecos:/:/bin/false
884a19
 ";
884a19
	if ($unix_uid != 0) {
884a19
		print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
884a19
@@ -2336,6 +2339,7 @@ force_user:x:$gid_force_user:
884a19
	createuser($self, "user2", $password, $conffile, \%createuser_env) || die("Unable to create user2");
884a19
	createuser($self, "gooduser", $password, $conffile, \%createuser_env) || die("Unable to create gooduser");
884a19
	createuser($self, "eviluser", $password, $conffile, \%createuser_env) || die("Unable to create eviluser");
884a19
+	createuser($self, "slashuser", $password, $conffile, \%createuser_env) || die("Unable to create slashuser");
884a19
884a19
	open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
884a19
	print DNS_UPDATE_LIST "A $server. $server_ip\n";
884a19
diff --git a/source3/script/tests/test_homes.sh b/source3/script/tests/test_homes.sh
884a19
index 06de0a0c301..90e84550dbc 100755
884a19
--- a/source3/script/tests/test_homes.sh
884a19
+++ b/source3/script/tests/test_homes.sh
884a19
@@ -88,6 +88,39 @@ EOF
884a19
     return 0
884a19
 }
884a19
884a19
+test_slashuser_home()
884a19
+{
884a19
+    tmpfile=$PREFIX/smbclient_homes_slashuser_commands
884a19
+    cat > $tmpfile <
884a19
+ls
884a19
+quit
884a19
+EOF
884a19
+
884a19
+    USERNAME=slashuser
884a19
+
884a19
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/$USERNAME $CONFIGURATION < $tmpfile 2>&1'
884a19
+    eval echo "$cmd"
884a19
+    out=$(eval $cmd)
884a19
+    ret=$?
884a19
+    rm -f $tmpfile
884a19
+
884a19
+    if [ $ret -ne 1 ] ; then
884a19
+       echo "$out"
884a19
+       echo "The server should reject connecting ret=$ret"
884a19
+       return 1
884a19
+    fi
884a19
+
884a19
+    echo "$out" | grep 'NT_STATUS_BAD_NETWORK_NAME'
884a19
+    ret=$?
884a19
+    if [ $ret -ne 0 ] ; then
884a19
+       echo "$out"
884a19
+       echo 'failed - should get: NT_STATUS_BAD_NETWORK_NAME.'
884a19
+       return 1
884a19
+    fi
884a19
+
884a19
+    return 0
884a19
+}
884a19
+
884a19
 testit "test gooduser home" \
884a19
     test_gooduser_home || \
884a19
     failed=`expr $failed + 1`
884a19
@@ -96,4 +129,8 @@ testit "test eviluser home reject" \
884a19
     test_eviluser_home || \
884a19
     failed=`expr $failed + 1`
884a19
884a19
+testit "test slashuser home reject" \
884a19
+    test_slashuser_home || \
884a19
+    failed=`expr $failed + 1`
884a19
+
884a19
 testok $0 $failed
884a19
--
884a19
2.19.2