Trivial winbind clean-up patches

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Jan 11 06:58:33 MST 2013


Hi!

Attached find two trivial patches to winbind, I had to just
look at the winbind_tdc cache and found these small flaws.

Please someone review and push to master.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From f5165da916b22135c1d938a878ff67f48c83cc81 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 11 Jan 2013 14:02:52 +0100
Subject: [PATCH 1/2] winbind: Fix error check in unpack_tdc_domains

---
 source3/winbindd/winbindd_cache.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index 76970d6..fbfaa1d 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -4455,7 +4455,9 @@ static size_t unpack_tdc_domains( unsigned char *buf, int buflen,
 	}
 
 	for ( i=0; i<num_domains; i++ ) {
-		len += tdb_unpack( buf+len, buflen-len, "fffddd",
+		int this_len;
+
+		this_len = tdb_unpack( buf+len, buflen-len, "fffddd",
 				   domain_name,
 				   dns_name,
 				   sid_string,
@@ -4463,11 +4465,12 @@ static size_t unpack_tdc_domains( unsigned char *buf, int buflen,
 				   &attribs,
 				   &type );
 
-		if ( len == -1 ) {
+		if ( this_len == -1 ) {
 			DEBUG(5,("unpack_tdc_domains: Failed to unpack domain array\n"));
 			TALLOC_FREE( list );			
 			return 0;
 		}
+		len += this_len;
 
 		DEBUG(11,("unpack_tdc_domains: Unpacking domain %s (%s) "
 			  "SID %s, flags = 0x%x, attribs = 0x%x, type = 0x%x\n",
-- 
1.7.3.4


From 9cd931cfc607fd257e1265f2c29d292c4caa19fd Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 11 Jan 2013 14:51:42 +0100
Subject: [PATCH 2/2] winbind: Fix some missing NULL checks

---
 source3/winbindd/winbindd_cache.c |   53 ++++++++++++++++++++----------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index fbfaa1d..252cf4a 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -4605,6 +4605,33 @@ bool wcache_tdc_add_domain( struct winbindd_domain *domain )
 	return ret;	
 }
 
+static struct winbindd_tdc_domain *wcache_tdc_dup_domain(
+	TALLOC_CTX *mem_ctx, const struct winbindd_tdc_domain *src)
+{
+	struct winbindd_tdc_domain *dst;
+
+	dst = talloc(mem_ctx, struct winbindd_tdc_domain);
+	if (dst == NULL) {
+		goto fail;
+	}
+	dst->domain_name = talloc_strdup(dst, src->domain_name);
+	if (dst->domain_name == NULL) {
+		goto fail;
+	}
+	dst->dns_name = talloc_strdup(dst, src->dns_name);
+	if (dst->dns_name == NULL) {
+		goto fail;
+	}
+	sid_copy(&dst->sid, &src->sid);
+	dst->trust_flags = src->trust_flags;
+	dst->trust_type = src->trust_type;
+	dst->trust_attribs = src->trust_attribs;
+	return dst;
+fail:
+	TALLOC_FREE(dst);
+	return NULL;
+}
+
 /*********************************************************************
  ********************************************************************/
 
@@ -4632,17 +4659,7 @@ struct winbindd_tdc_domain * wcache_tdc_fetch_domain( TALLOC_CTX *ctx, const cha
 			DEBUG(10,("wcache_tdc_fetch_domain: Found domain %s\n",
 				  name));
 
-			d = talloc( ctx, struct winbindd_tdc_domain );
-			if ( !d )
-				break;			
-
-			d->domain_name = talloc_strdup( d, dom_list[i].domain_name );
-			d->dns_name = talloc_strdup( d, dom_list[i].dns_name );
-			sid_copy( &d->sid, &dom_list[i].sid );
-			d->trust_flags   = dom_list[i].trust_flags;
-			d->trust_type    = dom_list[i].trust_type;
-			d->trust_attribs = dom_list[i].trust_attribs;
-
+			d = wcache_tdc_dup_domain(ctx, &dom_list[i]);
 			break;
 		}
 	}
@@ -4682,19 +4699,7 @@ struct winbindd_tdc_domain*
 				   dom_list[i].domain_name,
 				   sid_string_dbg(sid)));
 
-			d = talloc(ctx, struct winbindd_tdc_domain);
-			if (!d)
-				break;
-
-			d->domain_name = talloc_strdup(d,
-						       dom_list[i].domain_name);
-
-			d->dns_name = talloc_strdup(d, dom_list[i].dns_name);
-			sid_copy(&d->sid, &dom_list[i].sid);
-			d->trust_flags = dom_list[i].trust_flags;
-			d->trust_type = dom_list[i].trust_type;
-			d->trust_attribs = dom_list[i].trust_attribs;
-
+			d = wcache_tdc_dup_domain(ctx, &dom_list[i]);
 			break;
 		}
 	}
-- 
1.7.3.4



More information about the samba-technical mailing list