From c370237f44f91f98e4e5cce81fafeea442573bad Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@samba.org>
Date: Wed, 19 Aug 2015 16:24:08 +0200
Subject: [PATCH 1/2] PATCHSET32: s3-auth: Pass nt_username to check_account()

We set nt_username above but do not use it in this function.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=9862

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit e8c76932e4ac192a00afa3b9731f5921c4b37da6)
---
 source3/auth/auth_util.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c
index a548b7b..aa269d6 100644
--- a/source3/auth/auth_util.c
+++ b/source3/auth/auth_util.c
@@ -1251,9 +1251,12 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
 
 	/* this call will try to create the user if necessary */
 
-	nt_status = check_account(mem_ctx, nt_domain, sent_nt_username,
-				     &found_username, &pwd,
-				     &username_was_mapped);
+	nt_status = check_account(mem_ctx,
+				  nt_domain,
+				  nt_username,
+				  &found_username,
+				  &pwd,
+				  &username_was_mapped);
 
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		return nt_status;
-- 
2.5.0


From 1ab3cd252942b4fa5637d3f98b48ac3ba098de30 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@samba.org>
Date: Wed, 19 Aug 2015 16:11:47 +0200
Subject: [PATCH 2/2] PATCHSET32: s3-auth: Fix 'map to guest = Bad Uid' support

BUG: https://bugzilla.samba.org/show_bug.cgi?id=9862

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit 34965d4d98d172e848e2b96fad8a9e0b99288ba7)
---
 source3/auth/auth_util.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c
index aa269d6..cfda8b7 100644
--- a/source3/auth/auth_util.c
+++ b/source3/auth/auth_util.c
@@ -1259,6 +1259,14 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
 				  &username_was_mapped);
 
 	if (!NT_STATUS_IS_OK(nt_status)) {
+		/* Handle 'map to guest = Bad Uid */
+		if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_SUCH_USER) &&
+		    (lp_security() == SEC_ADS || lp_security() == SEC_DOMAIN) &&
+		    lp_map_to_guest() == MAP_TO_GUEST_ON_BAD_UID) {
+			DEBUG(2, ("Try to map %s to guest account\n",
+				   nt_username));
+			return make_server_info_guest(mem_ctx, server_info);
+		}
 		return nt_status;
 	}
 
-- 
2.5.0

