a3a04f
From 7417ea49cc998d07e0208736269b40f8ac3f2c48 Mon Sep 17 00:00:00 2001
a3a04f
From: Andreas Schneider <asn@samba.org>
a3a04f
Date: Mon, 19 Jun 2017 14:50:33 +0200
a3a04f
Subject: [PATCH 1/2] s3:popt_common: Reparse the username in
a3a04f
 popt_common_credentials_post()
a3a04f
a3a04f
When we parse the username in the options handling, the smb.conf file
a3a04f
has not been loaded yet. So we are not aware of a 'winbind separator'
a3a04f
set in the config file.
a3a04f
a3a04f
We need to read and set the username again in the post-processing of the
a3a04f
credentials.
a3a04f
a3a04f
https://bugzilla.samba.org/show_bug.cgi?id=12849
a3a04f
a3a04f
Signed-off-by: Andreas Schneider <asn@samba.org>
a3a04f
Reviewed-by: Stefan Metzmacher <metze@samba.org>
a3a04f
(cherry picked from commit 0caf40ec0196de0de016fda0d4aff0734d498d2b)
a3a04f
---
a3a04f
 source3/lib/popt_common.c | 15 +++++++++++++++
a3a04f
 1 file changed, 15 insertions(+)
a3a04f
a3a04f
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
a3a04f
index 3589a4fbd2b..9928c708e89 100644
a3a04f
--- a/source3/lib/popt_common.c
a3a04f
+++ b/source3/lib/popt_common.c
a3a04f
@@ -238,6 +238,7 @@ void popt_common_credentials_set_delay_post(void)
a3a04f
 void popt_common_credentials_post(void)
a3a04f
 {
a3a04f
 	struct user_auth_info *auth_info = cmdline_auth_info;
a3a04f
+	const char *username = NULL;
a3a04f
 
a3a04f
 	if (get_cmdline_auth_info_use_machine_account(auth_info) &&
a3a04f
 	    !set_cmdline_auth_info_machine_account_creds(auth_info))
a3a04f
@@ -248,6 +249,20 @@ void popt_common_credentials_post(void)
a3a04f
 	}
a3a04f
 
a3a04f
 	set_cmdline_auth_info_getpass(auth_info);
a3a04f
+
a3a04f
+	/*
a3a04f
+	 * When we set the username during the handling of the options passed to
a3a04f
+	 * the binary we haven't loaded the config yet. This means that we
a3a04f
+	 * didnn't take the 'winbind separator' into account.
a3a04f
+	 *
a3a04f
+	 * The username might contain the domain name and thus it hasn't been
a3a04f
+	 * correctly parsed yet. If we have a username we need to set it again
a3a04f
+	 * to run the string parser for the username correctly.
a3a04f
+	 */
a3a04f
+	username = get_cmdline_auth_info_username(auth_info);
a3a04f
+	if (username != NULL && username[0] != '\0') {
a3a04f
+		set_cmdline_auth_info_username(auth_info, username);
a3a04f
+	}
a3a04f
 }
a3a04f
 
a3a04f
 static void popt_common_credentials_callback(poptContext con,
a3a04f
-- 
a3a04f
2.13.1
a3a04f
a3a04f
a3a04f
From 5143e70481e5b47f37a2eb16a8b74bf74d8ec639 Mon Sep 17 00:00:00 2001
a3a04f
From: Andreas Schneider <asn@samba.org>
a3a04f
Date: Mon, 19 Jun 2017 15:52:23 +0200
a3a04f
Subject: [PATCH 2/2] s3:tests: Add test for smbclient -UDOMAIN+username
a3a04f
a3a04f
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12849
a3a04f
a3a04f
Signed-off-by: Andreas Schneider <asn@samba.org>
a3a04f
Reviewed-by: Stefan Metzmacher <metze@samba.org>
a3a04f
a3a04f
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
a3a04f
Autobuild-Date(master): Tue Jun 20 14:48:33 CEST 2017 on sn-devel-144
a3a04f
a3a04f
(cherry picked from commit e60aeb6f56a26019788442247361ed516bf965af)
a3a04f
---
a3a04f
 source3/script/tests/test_smbclient_basic.sh | 62 ++++++++++++++++++++++++++++
a3a04f
 source3/selftest/tests.py                    |  1 +
a3a04f
 2 files changed, 63 insertions(+)
a3a04f
 create mode 100755 source3/script/tests/test_smbclient_basic.sh
a3a04f
a3a04f
diff --git a/source3/script/tests/test_smbclient_basic.sh b/source3/script/tests/test_smbclient_basic.sh
a3a04f
new file mode 100755
a3a04f
index 00000000000..90e579b68e9
a3a04f
--- /dev/null
a3a04f
+++ b/source3/script/tests/test_smbclient_basic.sh
a3a04f
@@ -0,0 +1,62 @@
a3a04f
+#!/bin/sh
a3a04f
+
a3a04f
+# this runs the file serving tests that are expected to pass with samba3 against shares with various options
a3a04f
+
a3a04f
+if [ $# -lt 5 ]; then
a3a04f
+cat <
a3a04f
+Usage: test_smbclient_basic.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD SMBCLIENT <smbclient arguments>
a3a04f
+EOF
a3a04f
+exit 1;
a3a04f
+fi
a3a04f
+
a3a04f
+SERVER="$1"
a3a04f
+SERVER_IP="$2"
a3a04f
+USERNAME="$3"
a3a04f
+PASSWORD="$4"
a3a04f
+smbclient="$5"
a3a04f
+CONFIGURATION="$6"
a3a04f
+shift 6
a3a04f
+ADDARGS="$@"
a3a04f
+
a3a04f
+incdir=`dirname $0`/../../../testprogs/blackbox
a3a04f
+. $incdir/subunit.sh
a3a04f
+
a3a04f
+test_smbclient() {
a3a04f
+	name="$1"
a3a04f
+	cmd="$2"
a3a04f
+	shift
a3a04f
+	shift
a3a04f
+	echo "test: $name"
a3a04f
+	$VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" $@
a3a04f
+	status=$?
a3a04f
+	if [ x$status = x0 ]; then
a3a04f
+		echo "success: $name"
a3a04f
+	else
a3a04f
+		echo "failure: $name"
a3a04f
+	fi
a3a04f
+	return $status
a3a04f
+}
a3a04f
+
a3a04f
+# TEST using \ as the separator (default)
a3a04f
+test_smbclient "smbclient as $DOMAIN\\$USERNAME" 'ls' -U$DOMAIN\\$USERNAME%$PASSWORD $CONFIGURATION || failed=`expr $failed + 1`
a3a04f
+# TEST using / as the separator (default)
a3a04f
+test_smbclient "smbclient as $DOMAIN/$USERNAME" 'ls' -U$DOMAIN/$USERNAME%$PASSWORD $CONFIGURATION || failed=`expr $failed + 1`
a3a04f
+
a3a04f
+# TEST using 'winbind separator = +'
a3a04f
+test_smbclient "smbclient as $DOMAIN+$USERNAME" 'ls' -U$DOMAIN+$USERNAME%$PASSWORD $CONFIGURATION --option=winbindseparator=+ || failed=`expr $failed + 1`
a3a04f
+
a3a04f
+# TEST using 'winbind separator = +' set in a config file
a3a04f
+smbclient_config="$PREFIX/tmpsmbconf"
a3a04f
+cat > $smbclient_config <
a3a04f
+[global]
a3a04f
+    include = $(echo $CONFIGURATION | cut -d= -f2)
a3a04f
+    winbind separator = +
a3a04f
+EOF
a3a04f
+
a3a04f
+SAVE_CONFIGURATION="$CONFIGURATION"
a3a04f
+CONFIGURATION="--configfile=$smbclient_config"
a3a04f
+test_smbclient "smbclient as $DOMAIN+$USERNAME" 'ls' -U$DOMAIN+$USERNAME%$PASSWORD || failed=`expr $failed + 1`
a3a04f
+CONFIGURATION="$SAVE_CONFIGURATION"
a3a04f
+rm -rf $smbclient_config
a3a04f
+
a3a04f
+exit $failed
a3a04f
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
a3a04f
index dfe7866b283..d3cb071b903 100755
a3a04f
--- a/source3/selftest/tests.py
a3a04f
+++ b/source3/selftest/tests.py
a3a04f
@@ -152,6 +152,7 @@ plantestsuite("samba.vfstest.xattr-tdb-1", "nt4_dc:local", [os.path.join(samba3s
a3a04f
 plantestsuite("samba.vfstest.acl", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/vfstest-acl/run.sh"), binpath("vfstest"), "$PREFIX", configuration])
a3a04f
 plantestsuite("samba.vfstest.catia", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/vfstest-catia/run.sh"), binpath("vfstest"), "$PREFIX", configuration])
a3a04f
 
a3a04f
+plantestsuite("samba3.blackbox.smbclient_basic", "ad_member", [os.path.join(samba3srcdir, "script/tests/test_smbclient_basic.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD', smbclient3, configuration])
a3a04f
 for options in ["", "--option=clientntlmv2auth=no", "--option=clientusespnego=no", "--option=clientusespnego=no --option=clientntlmv2auth=no", "--option=clientntlmv2auth=no --option=clientlanmanauth=yes --max-protocol=LANMAN2", "--option=clientntlmv2auth=no --option=clientlanmanauth=yes --option=clientmaxprotocol=NT1"]:
a3a04f
     env = "nt4_dc"
a3a04f
     plantestsuite("samba3.blackbox.smbclient_auth.plain (%s) %s" % (env, options), env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_auth.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD', smbclient3, configuration, options])
a3a04f
-- 
a3a04f
2.13.1
a3a04f