70be2d
From 6dfc274ce5ae036a95ac2d7f6f9182c7f5a5b50f Mon Sep 17 00:00:00 2001
70be2d
From: Andreas Schneider <asn@samba.org>
70be2d
Date: Mon, 19 Sep 2016 13:59:54 +0200
70be2d
Subject: [PATCH] s3-lib: Fix %G substitution in AD member environment
70be2d
70be2d
If we are a domain member we should look up the user with the domain
70be2d
name specified else it will only work if we have
70be2d
'winbind use default domain' set.
70be2d
70be2d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12276
70be2d
70be2d
Signed-off-by: Andreas Schneider <asn@samba.org>
70be2d
Reviewed-by: Ralph Boehme <slow@samba.org>
70be2d
(cherry picked from commit 619ca5f63c47ff8b021692aaa756dcb0d883b8dd)
70be2d
---
70be2d
 source3/lib/substitute.c | 24 ++++++++++++++++++------
70be2d
 1 file changed, 18 insertions(+), 6 deletions(-)
70be2d
70be2d
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
70be2d
index 4e2ce9b..1f98327 100644
70be2d
--- a/source3/lib/substitute.c
70be2d
+++ b/source3/lib/substitute.c
70be2d
@@ -499,15 +499,18 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
70be2d
 			break;
70be2d
 		case 'G' : {
70be2d
 			struct passwd *pass;
70be2d
+			bool is_domain_name = false;
70be2d
+			const char *sep = lp_winbind_separator();
70be2d
 
70be2d
 			if (domain_name != NULL && domain_name[0] != '\0' &&
70be2d
-			    !strequal(domain_name, my_sam_name()))
70be2d
-			{
70be2d
+			    (lp_security() == SEC_ADS ||
70be2d
+			     lp_security() == SEC_DOMAIN)) {
70be2d
 				r = talloc_asprintf(tmp_ctx,
70be2d
 						    "%s%c%s",
70be2d
 						    domain_name,
70be2d
-						    *lp_winbind_separator(),
70be2d
+						    *sep,
70be2d
 						    smb_name);
70be2d
+				is_domain_name = true;
70be2d
 			} else {
70be2d
 				r = talloc_strdup(tmp_ctx, smb_name);
70be2d
 			}
70be2d
@@ -517,9 +520,18 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
70be2d
 
70be2d
 			pass = Get_Pwnam_alloc(tmp_ctx, r);
70be2d
 			if (pass != NULL) {
70be2d
-				a_string = realloc_string_sub(
70be2d
-					a_string, "%G",
70be2d
-					gidtoname(pass->pw_gid));
70be2d
+				char *group_name;
70be2d
+
70be2d
+				group_name = gidtoname(pass->pw_gid);
70be2d
+				if (is_domain_name) {
70be2d
+					p = strchr_m(group_name, *sep);
70be2d
+					if (p != NULL) {
70be2d
+						group_name = p + 1;
70be2d
+					}
70be2d
+				}
70be2d
+				a_string = realloc_string_sub(a_string,
70be2d
+							      "%G",
70be2d
+							      group_name);
70be2d
 			}
70be2d
 			TALLOC_FREE(pass);
70be2d
 			break;
70be2d
-- 
70be2d
2.10.1
70be2d
70be2d
From d851e487422808b6d3ba2738daa1c697e569bd27 Mon Sep 17 00:00:00 2001
70be2d
From: Volker Lendecke <vl@samba.org>
70be2d
Date: Wed, 12 Oct 2016 12:35:12 +0200
70be2d
Subject: [PATCH] lib: Fix CID 1373623 Dereference after null check
70be2d
MIME-Version: 1.0
70be2d
Content-Type: text/plain; charset=UTF-8
70be2d
Content-Transfer-Encoding: 8bit
70be2d
70be2d
We should not overload "p", this is used in the outer loop
70be2d
70be2d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12276
70be2d
Signed-off-by: Volker Lendecke <vl@samba.org>
70be2d
Reviewed-by: Ralph Böhme <slow@samba.org>
70be2d
Reviewed-by: Jeremy Allison <jra@samba.org>
70be2d
(cherry picked from commit 6ec81ca3c196f3c4659a4e1c473759b393708d12)
70be2d
---
70be2d
 source3/lib/substitute.c | 7 ++++---
70be2d
 1 file changed, 4 insertions(+), 3 deletions(-)
70be2d
70be2d
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
70be2d
index 1f98327..f56e2c4 100644
70be2d
--- a/source3/lib/substitute.c
70be2d
+++ b/source3/lib/substitute.c
70be2d
@@ -524,9 +524,10 @@ char *talloc_sub_basic(TALLOC_CTX *mem_ctx,
70be2d
 
70be2d
 				group_name = gidtoname(pass->pw_gid);
70be2d
 				if (is_domain_name) {
70be2d
-					p = strchr_m(group_name, *sep);
70be2d
-					if (p != NULL) {
70be2d
-						group_name = p + 1;
70be2d
+					char *group_sep;
70be2d
+					group_sep = strchr_m(group_name, *sep);
70be2d
+					if (group_sep != NULL) {
70be2d
+						group_name = group_sep + 1;
70be2d
 					}
70be2d
 				}
70be2d
 				a_string = realloc_string_sub(a_string,
70be2d
-- 
70be2d
2.10.1
70be2d