svn commit: samba r10917 - in branches/SAMBA_4_0/source/lib/ldb: common include modules

tridge at samba.org tridge at samba.org
Wed Oct 12 08:11:46 GMT 2005


Author: tridge
Date: 2005-10-12 08:11:45 +0000 (Wed, 12 Oct 2005)
New Revision: 10917

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=10917

Log:

copy the element name in a ldb_msg_rename_attr() and ldb_msg_copy_attr() to ensure
that callers (like the ldap server) can talloc_steal the name

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/modules/operational.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c	2005-10-12 07:57:39 UTC (rev 10916)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c	2005-10-12 08:11:45 UTC (rev 10917)
@@ -587,12 +587,17 @@
 /*
   rename the specified attribute in a search result
 */
-void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace)
+int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace)
 {
 	struct ldb_message_element *el = ldb_msg_find_element(msg, attr);
-	if (el != NULL) {
-		el->name = replace;
+	if (el == NULL) {
+		return 0;
 	}
+	el->name = talloc_strdup(msg->elements, replace);
+	if (el->name == NULL) {
+		return -1;
+	}
+	return 0;
 }
 
 
@@ -608,8 +613,7 @@
 	if (ldb_msg_add(msg, el, 0) != 0) {
 		return -1;
 	}
-	ldb_msg_rename_attr(msg, attr, replace);
-	return 0;
+	return ldb_msg_rename_attr(msg, attr, replace);
 }
 
 

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2005-10-12 07:57:39 UTC (rev 10916)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2005-10-12 08:11:45 UTC (rev 10917)
@@ -497,7 +497,7 @@
 				 const char *attr, 
 				 const char *replace);
 
-void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
+int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
 int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace);
 
 char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t);

Modified: branches/SAMBA_4_0/source/lib/ldb/modules/operational.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/modules/operational.c	2005-10-12 07:57:39 UTC (rev 10916)
+++ branches/SAMBA_4_0/source/lib/ldb/modules/operational.c	2005-10-12 08:11:45 UTC (rev 10917)
@@ -113,6 +113,8 @@
 	int ret;
 	const char **search_attrs = NULL;
 
+	(*res) = NULL;
+
 	/* replace any attributes in the parse tree that are
 	   searchable, but are stored using a different name in the
 	   backend */
@@ -165,9 +167,11 @@
 						goto oom;
 					}
 				} else {
-					ldb_msg_rename_attr((*res)[r], 
-							    search_sub[i].replace,
-							    search_sub[i].attr);
+					if (ldb_msg_rename_attr((*res)[r], 
+							      search_sub[i].replace,
+							      search_sub[i].attr) != 0) {
+						goto oom;
+					}
 				}
 			}
 		}
@@ -179,6 +183,7 @@
 
 oom:
 	talloc_free(search_attrs);
+	talloc_free(*res);
 	ldb_oom(module->ldb);
 	return -1;
 }



More information about the samba-cvs mailing list