[SCM] Samba Shared Repository - branch master updated - tevent-0-9-8-913-g3f59705

Andrew Tridgell tridge at samba.org
Fri Oct 2 06:53:22 MDT 2009


The branch, master has been updated
       via  3f59705a7120df61effe054cfb21219637662b14 (commit)
       via  35ff1f6f1f7f37dbc20668232728b54249e3d256 (commit)
       via  a0c82f17f897fcdbbd968d9808484ac577f93e20 (commit)
       via  959eff92064d3d2224f4f232be63acbbe045ee8f (commit)
       via  52b10ff3c5b4291c2f99922016417b2c4ae215e8 (commit)
       via  dfafd58348278276e51f84fe0d9e04ad41c3ac3d (commit)
       via  81c193da0945ea2dd355590a121ec83d77a594bd (commit)
      from  83e9b1c325964a016b499ad124d161eb20f6c26c (commit)

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


- Log -----------------------------------------------------------------
commit 3f59705a7120df61effe054cfb21219637662b14
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:40:50 2009 +1000

    Revert "s4:ldb-samba Use temp talloc contexts and talloc_steal avoid leaks."
    
    This reverts commit 38f87f40bfd7892043d49009067ae28431279580.

commit 35ff1f6f1f7f37dbc20668232728b54249e3d256
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:40:31 2009 +1000

    Revert "s4:ldb Fix ldb_list_find() folowing the change from char * to TDB_DATA"
    
    This reverts commit f0c2c9854c7659221fe9480110a7d9b2b48afbf9.

commit a0c82f17f897fcdbbd968d9808484ac577f93e20
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:40:02 2009 +1000

    Revert "s4:ldb always talloc_free() the ldb_ldif_write context, even on success"
    
    This reverts commit a610843e9f21ee77fd29356313d2ef05fe25a1ed.

commit 959eff92064d3d2224f4f232be63acbbe045ee8f
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:39:44 2009 +1000

    Revert "s4:ldb Remove LTDB_PACKING_FORMAT_NODN"
    
    This reverts commit bcbf0ae1e707c2355824800dc213d364070f070a.

commit 52b10ff3c5b4291c2f99922016417b2c4ae215e8
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:39:19 2009 +1000

    Revert "s4-ldb: merged with master"
    
    This reverts commit 14c9070322d089dd96b389e8087c4f4bf1a6c7cc.

commit dfafd58348278276e51f84fe0d9e04ad41c3ac3d
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:39:10 2009 +1000

    Revert "s4-ldb: overallocate idxptr to reduce memory fragmentation"
    
    This reverts commit e7846f69cacdd0551fcd777a71bf833a2fc9ca2b.

commit 81c193da0945ea2dd355590a121ec83d77a594bd
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 22:38:58 2009 +1000

    Revert "s4-ldb: fixed a memory leak"
    
    This reverts commit c7358d989034c9d936c04f2a7e4f89db252b798e.

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

Summary of changes:
 source4/lib/ldb-samba/ldif_handlers.c |   59 +--
 source4/lib/ldb/common/ldb_ldif.c     |    1 -
 source4/lib/ldb/ldb_tdb/ldb_cache.c   |   84 +---
 source4/lib/ldb/ldb_tdb/ldb_index.c   |  801 +++++++++++++++++----------------
 source4/lib/ldb/ldb_tdb/ldb_pack.c    |    7 +
 source4/lib/ldb/ldb_tdb/ldb_search.c  |   52 +--
 source4/lib/ldb/ldb_tdb/ldb_tdb.c     |  187 ++++-----
 source4/lib/ldb/ldb_tdb/ldb_tdb.h     |   54 +--
 8 files changed, 562 insertions(+), 683 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb-samba/ldif_handlers.c b/source4/lib/ldb-samba/ldif_handlers.c
index 839a8f2..43a1045 100644
--- a/source4/lib/ldb-samba/ldif_handlers.c
+++ b/source4/lib/ldb-samba/ldif_handlers.c
@@ -181,38 +181,28 @@ static int extended_dn_read_SID(struct ldb_context *ldb, void *mem_ctx,
 {
 	struct dom_sid sid;
 	enum ndr_err_code ndr_err;
-	TALLOC_CTX *tmp_ctx;
 	if (ldif_comparision_objectSid_isString(in)) {
 		if (ldif_read_objectSid(ldb, mem_ctx, in, out) == 0) {
 			return 0;
 		}
 	}
 	
-	tmp_ctx = talloc_new(mem_ctx);
-	if (!tmp_ctx) {
-		return -1;
-	}
-
 	/* Perhaps not a string after all */
-	*out = data_blob_talloc(tmp_ctx, NULL, in->length/2+1);
+	*out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
 
 	if (!out->data) {
-		talloc_free(tmp_ctx);
 		return -1;
 	}
 
-	out->length = strhex_to_str((char *)out->data, out->length,
-				    (const char *)in->data, in->length);
+	(*out).length = strhex_to_str((char *)out->data, out->length,
+				     (const char *)in->data, in->length);
 
 	/* Check it looks like a SID */
-	ndr_err = ndr_pull_struct_blob_all(out, tmp_ctx, NULL, &sid,
+	ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &sid,
 					   (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		talloc_free(tmp_ctx);
 		return -1;
 	}
-	talloc_steal(mem_ctx, out->data);
-	talloc_free(tmp_ctx);
 	return 0;
 }
 
@@ -225,24 +215,17 @@ static int ldif_read_objectGUID(struct ldb_context *ldb, void *mem_ctx,
 	struct GUID guid;
 	NTSTATUS status;
 	enum ndr_err_code ndr_err;
-	TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
-	if (!tmp_ctx) {
-		return -1;
-	}
 
 	status = GUID_from_data_blob(in, &guid);
 	if (!NT_STATUS_IS_OK(status)) {
 		return -1;
 	}
 
-	ndr_err = ndr_push_struct_blob(out, tmp_ctx, NULL, &guid,
+	ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, &guid,
 				       (ndr_push_flags_fn_t)ndr_push_GUID);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		talloc_free(tmp_ctx);
 		return -1;
 	}
-	talloc_steal(mem_ctx, out->data);
-	talloc_free(tmp_ctx);
 	return 0;
 }
 
@@ -254,18 +237,12 @@ static int ldif_write_objectGUID(struct ldb_context *ldb, void *mem_ctx,
 {
 	struct GUID guid;
 	enum ndr_err_code ndr_err;
-	TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
-	if (!tmp_ctx) {
-		return -1;
-	}
-	ndr_err = ndr_pull_struct_blob_all(in, tmp_ctx, NULL, &guid,
+	ndr_err = ndr_pull_struct_blob_all(in, mem_ctx, NULL, &guid,
 					   (ndr_pull_flags_fn_t)ndr_pull_GUID);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		talloc_free(tmp_ctx);
 		return -1;
 	}
 	out->data = (uint8_t *)GUID_string(mem_ctx, &guid);
-	talloc_free(tmp_ctx);
 	if (out->data == NULL) {
 		return -1;
 	}
@@ -286,7 +263,6 @@ static int extended_dn_read_GUID(struct ldb_context *ldb, void *mem_ctx,
 {
 	struct GUID guid;
 	enum ndr_err_code ndr_err;
-	TALLOC_CTX *tmp_ctx;
 	if (in->length == 36 && ldif_read_objectGUID(ldb, mem_ctx, in, out) == 0) {
 		return 0;
 	}
@@ -296,30 +272,21 @@ static int extended_dn_read_GUID(struct ldb_context *ldb, void *mem_ctx,
 		return -1;
 	}
 		
-	tmp_ctx = talloc_new(mem_ctx);
-	if (!tmp_ctx) {
-		return -1;
-	}
-
-	*out = data_blob_talloc(tmp_ctx, NULL, in->length/2+1);
+	*out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
 	
 	if (!out->data) {
-		talloc_free(tmp_ctx);
 		return -1;
 	}
 	
-	out->length = strhex_to_str((char *)out->data, out->length,
-				    (const char *)in->data, in->length);
+	(*out).length = strhex_to_str((char *)out->data, out->length,
+				      (const char *)in->data, in->length);
 	
 	/* Check it looks like a GUID */
-	ndr_err = ndr_pull_struct_blob_all(out, tmp_ctx, NULL, &guid,
+	ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &guid,
 					   (ndr_pull_flags_fn_t)ndr_pull_GUID);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		talloc_free(tmp_ctx);
 		return -1;
 	}
-	talloc_steal(mem_ctx, out->data);
-	talloc_free(tmp_ctx);
 	return 0;
 }
 
@@ -401,14 +368,12 @@ static int ldif_read_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx
 		}
 	}
 
-	ndr_err = ndr_push_struct_blob(out, sd, NULL, sd,
+	ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, sd,
 				       (ndr_push_flags_fn_t)ndr_push_security_descriptor);
+	talloc_free(sd);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		talloc_free(sd);
 		return -1;
 	}
-	talloc_steal(mem_ctx, out->data);
-	talloc_free(sd);
 
 	return 0;
 }
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index 9705179..b7ab730 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -373,7 +373,6 @@ int ldb_ldif_write(struct ldb_context *ldb,
 	ret = fprintf_fn(private_data,"\n");
 	CHECK_RET;
 
-	talloc_free(mem_ctx);
 	return total;
 }
 
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index f853023..2c39968 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -190,6 +190,8 @@ static int ltdb_baseinfo_init(struct ldb_module *module)
 	void *data = ldb_module_get_private(module);
 	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
 	struct ldb_message *msg;
+	struct ldb_message_element el;
+	struct ldb_val val;
 	int ret;
 	/* the initial sequence number must be different from the one
 	   set in ltdb_cache_free(). Thanks to Jon for pointing this
@@ -200,21 +202,31 @@ static int ltdb_baseinfo_init(struct ldb_module *module)
 
 	ltdb->sequence_number = atof(initial_sequence_number);
 
-	msg = ldb_msg_new(ltdb);
+	msg = talloc(ltdb, struct ldb_message);
+	if (msg == NULL) {
+		goto failed;
+	}
+
+	msg->num_elements = 1;
+	msg->elements = &el;
 	msg->dn = ldb_dn_new(msg, ldb, LTDB_BASEINFO);
 	if (!msg->dn) {
 		goto failed;
 	}
-
-	if (ldb_msg_add_string(msg, LTDB_SEQUENCE_NUMBER, initial_sequence_number) != 0) {
+	el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER);
+	if (!el.name) {
 		goto failed;
 	}
-
-	if (ldb_msg_add_string(msg, LTDB_INDEX_VERSION, "1") != 0) {
+	el.values = &val;
+	el.num_values = 1;
+	el.flags = 0;
+	val.data = (uint8_t *)talloc_strdup(msg, initial_sequence_number);
+	if (!val.data) {
 		goto failed;
 	}
-
-	ret = ltdb_store(module, msg, msg, TDB_INSERT);
+	val.length = 1;
+	
+	ret = ltdb_store(module, msg, TDB_INSERT);
 
 	talloc_free(msg);
 
@@ -313,16 +325,6 @@ int ltdb_cache_load(struct ldb_module *module)
 	}
 	ltdb->sequence_number = seq;
 
-	/* Determine what index format we are in (updated on reindex) */
-	ltdb->index_version = ldb_msg_find_attr_as_uint64(baseinfo, LTDB_INDEX_VERSION, 0);
-
-	if (ltdb->index_version > 1) {
-		ldb_debug(ldb, LDB_DEBUG_ERROR, 
-			  "Invalid index version %d on database.  This ldb supports only index version 0 and 1",
-			  ltdb->index_version);
-		goto failed;
-	}
-
 	/* Read an interpret database options */
 	options = talloc(ltdb->cache, struct ldb_message);
 	if (options == NULL) goto failed;
@@ -446,15 +448,13 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
 
 	s = ldb_timestring(msg, t);
 	if (s == NULL) {
-		talloc_free(msg);
-		errno = ENOMEM;
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
 	val_time.data = (uint8_t *)s;
 	val_time.length = strlen(s);
 
-	ret = ltdb_modify_internal(module, msg, msg);
+	ret = ltdb_modify_internal(module, msg);
 
 	talloc_free(msg);
 
@@ -469,50 +469,6 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
 	return ret;
 }
 
-/*
-  increase the index version number to indicate a database change
-*/
-int ltdb_set_casefold_index(struct ldb_module *module)
-{
-	struct ldb_context *ldb;
-	void *data = ldb_module_get_private(module);
-	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
-	struct ldb_message *msg;
-	struct ldb_message_element *el;
-
-	int ret;
-		
-	ldb = ldb_module_get_ctx(module);
-
-	msg = ldb_msg_new(ltdb);
-	if (msg == NULL) {
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-	msg->dn = ldb_dn_new(msg, ldb, LTDB_BASEINFO);
-	if (msg->dn == NULL) {
-		talloc_free(msg);
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-
-	if (ldb_msg_add_string(msg, LTDB_INDEX_VERSION, "1") != 0) {
-		talloc_free(msg);
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-
-	el = ldb_msg_find_element(msg, LTDB_INDEX_VERSION);
-	if (!el) {
-		talloc_free(msg);
-		return LDB_ERR_OPERATIONS_ERROR;
-	}
-	el->flags = LDB_FLAG_MOD_REPLACE;
-
-	ret = ltdb_modify_internal(module, msg, msg);
-
-	talloc_free(msg);
-
-	return ret;
-}
-
 int ltdb_check_at_attributes_values(const struct ldb_val *value)
 {
 	int i;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 66d70a9..b959471 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -33,7 +33,6 @@
 
 #include "ldb_tdb.h"
 #include "dlinklist.h"
-#include "ldb_handlers.h"
 
 /*
   the idxptr code is a bit unusual. The way it works is to replace
@@ -54,12 +53,13 @@
   @INDEX records many times during indexing.
  */
 struct ldb_index_pointer {
-	struct ldb_message_element el;
+	struct ldb_index_pointer *next, *prev;
+	struct ldb_val value;
 };
 
 struct ltdb_idxptr {
 	int num_dns;
-	struct TDB_DATA *dn_list;
+	const char **dn_list;
 	bool repack;
 };
 
@@ -70,56 +70,58 @@ static int ltdb_idxptr_add(struct ldb_module *module, const struct ldb_message *
 {
 	void *data = ldb_module_get_private(module);
 	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
-	/* we overallocate a bit to save on memory fragmentation */
-	unsigned alloc_length = ((ltdb->idxptr->num_dns+1) + 16) & ~15;
 	ltdb->idxptr->dn_list = talloc_realloc(ltdb->idxptr, ltdb->idxptr->dn_list, 
-					       struct TDB_DATA, alloc_length);
+					       const char *, ltdb->idxptr->num_dns+1);
 	if (ltdb->idxptr->dn_list == NULL) {
 		ltdb->idxptr->num_dns = 0;
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 	ltdb->idxptr->dn_list[ltdb->idxptr->num_dns] =
-		ltdb_key(ltdb->idxptr->dn_list, msg->dn);
-	if (ltdb->idxptr->dn_list[ltdb->idxptr->num_dns].dptr == NULL) {
+		talloc_strdup(ltdb->idxptr->dn_list, ldb_dn_get_linearized(msg->dn));
+	if (ltdb->idxptr->dn_list[ltdb->idxptr->num_dns] == NULL) {
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 	ltdb->idxptr->num_dns++;
 	return LDB_SUCCESS;
 }
 
-/* return an idxptr record */
-static struct ldb_index_pointer *ltdb_return_idxptr(struct ldb_module *module, struct ldb_message_element *el)
+/* free an idxptr record */
+static int ltdb_free_idxptr(struct ldb_module *module, struct ldb_message_element *el)
 {
 	struct ldb_val val;
 	struct ldb_index_pointer *ptr;
 
 	if (el->num_values != 1) {
-		return NULL;
+		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
 	val = el->values[0];
 	if (val.length != sizeof(void *)) {
-		return NULL;
+		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
 	ptr = *(struct ldb_index_pointer **)val.data;
 	if (talloc_get_type(ptr, struct ldb_index_pointer) != ptr) {
-		return NULL;
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
+
+	while (ptr) {
+		struct ldb_index_pointer *tmp = ptr;
+		DLIST_REMOVE(ptr, ptr);
+		talloc_free(tmp);
 	}
 
-	return ptr;
+	return LDB_SUCCESS;
 }
 
+
 /* convert from the IDXPTR format to a ldb_message_element format */
-static int ltdb_convert_from_idxptr(struct ldb_module *module, struct ldb_message *msg, struct ldb_index_pointer **ptr_out)
+static int ltdb_convert_from_idxptr(struct ldb_module *module, struct ldb_message_element *el)
 {
 	struct ldb_val val;
-	struct ldb_index_pointer *ptr;
-
-	struct ldb_message_element *el = ldb_msg_find_element(msg, LTDB_IDXPTR);
-	if (!el) {
-		return LDB_SUCCESS;
-	}
+	struct ldb_index_pointer *ptr, *tmp;
+	int i;
+	struct ldb_val *val2;
 
 	if (el->num_values != 1) {
 		return LDB_ERR_OPERATIONS_ERROR;
@@ -135,40 +137,72 @@ static int ltdb_convert_from_idxptr(struct ldb_module *module, struct ldb_messag
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
-	talloc_free(el->values);
-	*el = ptr->el;
+	/* count the length of the list */
+	for (i=0, tmp = ptr; tmp; tmp=tmp->next) {
+		i++;
+	}
 
-	if (ptr_out) {
-		*ptr_out = ptr;
+	/* allocate the new values array */
+	val2 = talloc_realloc(NULL, el->values, struct ldb_val, i);
+	if (val2 == NULL) {
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
+	el->values = val2;
+	el->num_values = i;
+
+	/* populate the values array */
+	for (i=0, tmp = ptr; tmp; tmp=tmp->next, i++) {
+		el->values[i].length = tmp->value.length;
+		/* we need to over-allocate here as there are still some places
+		   in ldb that rely on null termination. */
+		el->values[i].data = talloc_size(el->values, tmp->value.length+1);
+		if (el->values[i].data == NULL) {
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		memcpy(el->values[i].data, tmp->value.data, tmp->value.length);
+		el->values[i].data[tmp->value.length] = 0;
 	}
 
+	/* update the name */
+	el->name = LTDB_IDX;
+
        	return LDB_SUCCESS;
 }
 
 
 /* convert to the IDXPTR format from a ldb_message_element format */
-static int ltdb_update_idxptr(struct ldb_module *module, TALLOC_CTX *mem_ctx, 
-			      struct ldb_index_pointer *ptr, 
-			      struct ldb_message_element *el)
+static int ltdb_convert_to_idxptr(struct ldb_module *module, struct ldb_message_element *el)
 {
+	struct ldb_index_pointer *ptr, *tmp;
+	int i;
 	struct ldb_val *val2;
-	ptr->el = *el;
-	talloc_steal(ptr, el->values);
-	talloc_steal(ptr, el->name);
+	void *data = ldb_module_get_private(module);
+	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+
+	ptr = NULL;
+
+	for (i=0;i<el->num_values;i++) {
+		tmp = talloc(ltdb->idxptr, struct ldb_index_pointer);
+		if (tmp == NULL) {
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		tmp->value = el->values[i];
+		tmp->value.data = talloc_memdup(tmp, tmp->value.data, tmp->value.length);
+		if (tmp->value.data == NULL) {
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		DLIST_ADD(ptr, tmp);
+	}
 
 	/* allocate the new values array */
-	val2 = talloc_array(mem_ctx, struct ldb_val, 1);
+	val2 = talloc_realloc(NULL, el->values, struct ldb_val, 1);
 	if (val2 == NULL) {
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 	el->values = val2;
 	el->num_values = 1;
 
-	if (strcmp(el->name, LTDB_IDXPTR) == 0) {
-		abort();
-	}
-
-	el->values[0].data = talloc_memdup(val2, &ptr, sizeof(ptr));
+	el->values[0].data = talloc_memdup(el->values, &ptr, sizeof(ptr));
 	el->values[0].length = sizeof(ptr);
 
 	/* update the name */
@@ -177,21 +211,6 @@ static int ltdb_update_idxptr(struct ldb_module *module, TALLOC_CTX *mem_ctx,
        	return LDB_SUCCESS;
 }
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list