[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Mon Jun 28 06:07:24 MDT 2010


The branch, master has been updated
       via  8707be6... s3: Fix a valgrind error
       via  09a9cc3... s3: Re-arrange winbindd_ads.c:query_user
       via  a670804... s3: free -> SAFE_FREE
       via  c79e0c0... s3: Do an early TALLOC_FREE
      from  658048e... s3-registry: fix printing keyname delimiter.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 8707be6d7587217a62abdedf2b4294e31c261260
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 28 13:51:51 2010 +0200

    s3: Fix a valgrind error
    
    nss_get_info_cached does not necessarily fill in gid

commit 09a9cc32ee611c20c0e3384c404dd39f615b89ed
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 28 11:52:26 2010 +0200

    s3: Re-arrange winbindd_ads.c:query_user
    
    We can't access the LDAP message after nss_get_info_cached has potentially
    destroyed the ads_struct

commit a67080457926baa044265d46b7286737f4f5913a
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 28 11:21:03 2010 +0200

    s3: free -> SAFE_FREE

commit c79e0c0ce4a6689a6cd8ded7cb273d17b6be6211
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Jun 28 11:20:23 2010 +0200

    s3: Do an early TALLOC_FREE

-----------------------------------------------------------------------

Summary of changes:
 source3/winbindd/winbindd_ads.c |   59 ++++++++++++++++++++------------------
 1 files changed, 31 insertions(+), 28 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c
index 00b53a2..96c60a5 100644
--- a/source3/winbindd/winbindd_ads.c
+++ b/source3/winbindd/winbindd_ads.c
@@ -463,13 +463,14 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
 	uint32 group_rid;
 	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 	struct netr_SamInfo3 *user = NULL;
-	gid_t gid;
+	gid_t gid = -1;
+	int ret;
+	char *ads_name;
 
 	DEBUG(3,("ads: query_user\n"));
 
 	info->homedir = NULL;
 	info->shell = NULL;
-	info->primary_gid = (gid_t)-1;
 
 	/* try netsamlogon cache first */
 
@@ -527,13 +528,15 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
 	}
 
 	sidstr = sid_binstring(talloc_tos(), sid);
-	if (asprintf(&ldap_exp, "(objectSid=%s)", sidstr) == -1) {
+
+	ret = asprintf(&ldap_exp, "(objectSid=%s)", sidstr);
+	TALLOC_FREE(sidstr);
+	if (ret == -1) {
 		status = NT_STATUS_NO_MEMORY;
 		goto done;
 	}
 	rc = ads_search_retry(ads, &msg, ldap_exp, attrs);
-	free(ldap_exp);
-	TALLOC_FREE(sidstr);
+	SAFE_FREE(ldap_exp);
 	if (!ADS_ERR_OK(rc) || !msg) {
 		DEBUG(1,("query_user(sid=%s) ads_search: %s\n",
 			 sid_string_dbg(sid), ads_errstr(rc)));
@@ -549,6 +552,26 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
 
 	info->acct_name = ads_pull_username(ads, mem_ctx, msg);
 
+	if (!ads_pull_uint32(ads, msg, "primaryGroupID", &group_rid)) {
+		DEBUG(1,("No primary group for %s !?\n",
+			 sid_string_dbg(sid)));
+		goto done;
+	}
+
+	sid_copy(&info->user_sid, sid);
+	sid_compose(&info->group_sid, &domain->sid, group_rid);
+
+	/*
+	 * We have to fetch the "name" attribute before doing the
+	 * nss_get_info_cached call. nss_get_info_cached might destroy
+	 * the ads struct, potentially invalidating the ldap message.
+	 */
+
+	ads_name = ads_pull_string(ads, mem_ctx, msg, "name");
+
+	ads_msgfree(ads, msg);
+	msg = NULL;
+
 	status = nss_get_info_cached( domain, sid, mem_ctx, ads, msg,
 		      &info->homedir, &info->shell, &info->full_name, 
 		      &gid);
@@ -560,35 +583,15 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
 	}
 
 	if (info->full_name == NULL) {
-		info->full_name = ads_pull_string(ads, mem_ctx, msg, "name");
-	}
-
-	/*
-	 * We have to re-fetch ads from the domain,
-	 * nss_get_info_cached might have invalidated it.
-	 */
-	ads = ads_cached_connection(domain);
-	if (ads == NULL) {
-		domain->last_status = NT_STATUS_SERVER_DISABLED;
-		goto done;
-	}
-
-	if (!ads_pull_uint32(ads, msg, "primaryGroupID", &group_rid)) {
-		DEBUG(1,("No primary group for %s !?\n",
-			 sid_string_dbg(sid)));
-		goto done;
+		info->full_name = ads_name;
+	} else {
+		TALLOC_FREE(ads_name);
 	}
 
-	sid_copy(&info->user_sid, sid);
-	sid_compose(&info->group_sid, &domain->sid, group_rid);
-
 	status = NT_STATUS_OK;
 
 	DEBUG(3,("ads query_user gave %s\n", info->acct_name));
 done:
-	if (msg) 
-		ads_msgfree(ads, msg);
-
 	return status;
 }
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list