483b06
From 376a1fbfe97624116d8fb10f26d97ef15fd3b917 Mon Sep 17 00:00:00 2001
483b06
From: Florence Blanc-Renaud <flo@redhat.com>
483b06
Date: Tue, 21 Mar 2017 17:33:20 +0100
483b06
Subject: [PATCH] ipa-sam: create the gidNumber attribute in the trusted domain
483b06
 entry
483b06
483b06
When a trusted domain entry is created, the uidNumber attribute is created
483b06
but not the gidNumber attribute. This causes samba to log
483b06
	Failed to find a Unix account for DOM-AD$
483b06
because the samu structure does not contain a group_sid and is not put
483b06
in the cache.
483b06
The fix creates the gidNumber attribute in the trusted domain entry,
483b06
and initialises the group_sid field in the samu structure returned
483b06
by ldapsam_getsampwnam. This ensures that the entry is put in the cache.
483b06
483b06
Note that this is only a partial fix for 6660 as it does not prevent
483b06
_netr_ServerAuthenticate3 from failing with the log
483b06
	_netr_ServerAuthenticate3: netlogon_creds_server_check failed. Rejecting auth request from client VM-AD machine account dom-ad.example.com.
483b06
483b06
https://pagure.io/freeipa/issue/6827
483b06
483b06
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
483b06
---
483b06
 daemons/ipa-sam/ipa_sam.c | 40 +++++++++++++++++++++++++++++++++++++---
483b06
 1 file changed, 37 insertions(+), 3 deletions(-)
483b06
483b06
diff --git a/daemons/ipa-sam/ipa_sam.c b/daemons/ipa-sam/ipa_sam.c
483b06
index 4c1fda5f82b43f69929613f9938410b32cff31e7..6a29e8e10b4299356b9ead76276eecc8083791a3 100644
483b06
--- a/daemons/ipa-sam/ipa_sam.c
483b06
+++ b/daemons/ipa-sam/ipa_sam.c
483b06
@@ -195,6 +195,7 @@ struct ipasam_privates {
483b06
 	char *trust_dn;
483b06
 	char *flat_name;
483b06
 	struct dom_sid fallback_primary_group;
483b06
+	char *fallback_primary_group_gid_str;
483b06
 	char *server_princ;
483b06
 	char *client_princ;
483b06
 	struct sss_idmap_ctx *idmap_ctx;
483b06
@@ -2419,6 +2420,9 @@ static NTSTATUS ipasam_set_trusted_domain(struct pdb_methods *methods,
483b06
 	if (entry == NULL || sid == NULL) {
483b06
 		smbldap_make_mod(priv2ld(ldap_state), entry, &mods,
483b06
 				 LDAP_ATTRIBUTE_UIDNUMBER, IPA_MAGIC_ID_STR);
483b06
+		smbldap_make_mod(priv2ld(ldap_state), entry, &mods,
483b06
+		                 LDAP_ATTRIBUTE_GIDNUMBER,
483b06
+				 ldap_state->ipasam_privates->fallback_primary_group_gid_str);
483b06
 	}
483b06
 
483b06
 	if (td->netbios_name != NULL) {
483b06
@@ -2829,6 +2833,7 @@ static bool init_sam_from_td(struct samu *user, struct pdb_trusted_domain *td,
483b06
 {
483b06
 	NTSTATUS status;
483b06
 	struct dom_sid *u_sid;
483b06
+	struct dom_sid *g_sid;
483b06
 	char *name;
483b06
 	char *trustpw = NULL;
483b06
 	char *trustpw_utf8 = NULL;
483b06
@@ -2884,6 +2889,11 @@ static bool init_sam_from_td(struct samu *user, struct pdb_trusted_domain *td,
483b06
 	}
483b06
 	talloc_free(u_sid);
483b06
 
483b06
+	g_sid = &ldap_state->ipasam_privates->fallback_primary_group;
483b06
+	if (!pdb_set_group_sid(user, g_sid, PDB_SET)) {
483b06
+		return false;
483b06
+	}
483b06
+
483b06
 	status = get_trust_pwd(user, &td->trust_auth_incoming, &trustpw, NULL);
483b06
 	if (!NT_STATUS_IS_OK(status)) {
483b06
 		return false;
483b06
@@ -3594,14 +3604,17 @@ static void ipasam_free_private_data(void **vp)
483b06
 static struct dom_sid *get_fallback_group_sid(TALLOC_CTX *mem_ctx,
483b06
 					      struct smbldap_state *ldap_state,
483b06
 					      struct sss_idmap_ctx *idmap_ctx,
483b06
-					      LDAPMessage *dom_entry)
483b06
+					      LDAPMessage *dom_entry,
483b06
+					      char **fallback_group_gid_str)
483b06
 {
483b06
 	char *dn;
483b06
 	char *sid;
483b06
+	char *gidnumber;
483b06
 	int ret;
483b06
 	const char *filter = "objectClass=*";
483b06
 	const char *attr_list[] = {
483b06
 					LDAP_ATTRIBUTE_SID,
483b06
+					LDAP_ATTRIBUTE_GIDNUMBER,
483b06
 					NULL};
483b06
 	LDAPMessage *result;
483b06
 	LDAPMessage *entry;
483b06
@@ -3648,9 +3661,20 @@ static struct dom_sid *get_fallback_group_sid(TALLOC_CTX *mem_ctx,
483b06
 		talloc_free(sid);
483b06
 		return NULL;
483b06
 	}
483b06
+	talloc_free(sid);
483b06
+
483b06
+	gidnumber = get_single_attribute(mem_ctx, ldap_state->ldap_struct,
483b06
+					entry, LDAP_ATTRIBUTE_GIDNUMBER);
483b06
+	if (gidnumber == NULL) {
483b06
+		DEBUG(0, ("Missing mandatory attribute %s.\n",
483b06
+			  LDAP_ATTRIBUTE_GIDNUMBER));
483b06
+		ldap_msgfree(result);
483b06
+		return NULL;
483b06
+	}
483b06
+
483b06
+	*fallback_group_gid_str = gidnumber;
483b06
 
483b06
 	ldap_msgfree(result);
483b06
-	talloc_free(sid);
483b06
 
483b06
 	return fallback_group_sid;
483b06
 }
483b06
@@ -4443,6 +4467,7 @@ static NTSTATUS pdb_init_ipasam(struct pdb_methods **pdb_method,
483b06
 	char *domain_sid_string = NULL;
483b06
 	struct dom_sid *ldap_domain_sid = NULL;
483b06
 	struct dom_sid *fallback_group_sid = NULL;
483b06
+	char *fallback_group_gid_str = NULL;
483b06
 
483b06
 	LDAPMessage *result = NULL;
483b06
 	LDAPMessage *entry = NULL;
483b06
@@ -4586,7 +4611,8 @@ static NTSTATUS pdb_init_ipasam(struct pdb_methods **pdb_method,
483b06
 	fallback_group_sid = get_fallback_group_sid(ldap_state,
483b06
 					ldap_state->smbldap_state,
483b06
 					ldap_state->ipasam_privates->idmap_ctx,
483b06
-					result);
483b06
+					result,
483b06
+					&fallback_group_gid_str);
483b06
 	if (fallback_group_sid == NULL) {
483b06
 		DEBUG(0, ("Cannot find SID of fallback group.\n"));
483b06
 		ldap_msgfree(result);
483b06
@@ -4596,6 +4622,14 @@ static NTSTATUS pdb_init_ipasam(struct pdb_methods **pdb_method,
483b06
 		 fallback_group_sid);
483b06
 	talloc_free(fallback_group_sid);
483b06
 
483b06
+	if (fallback_group_gid_str == NULL) {
483b06
+		DEBUG(0, ("Cannot find gidNumber of fallback group.\n"));
483b06
+		ldap_msgfree(result);
483b06
+		return NT_STATUS_INVALID_PARAMETER;
483b06
+	}
483b06
+	ldap_state->ipasam_privates->fallback_primary_group_gid_str =
483b06
+		fallback_group_gid_str;
483b06
+
483b06
 	domain_sid_string = get_single_attribute(
483b06
 				ldap_state,
483b06
 				ldap_state->smbldap_state->ldap_struct,
483b06
-- 
483b06
2.9.3
483b06