svn commit: samba r20054 - in branches/SAMBA_3_0/source/lib/ldb/ldb_tdb: .

vlendec at samba.org vlendec at samba.org
Wed Dec 6 14:40:48 GMT 2006


Author: vlendec
Date: 2006-12-06 14:40:47 +0000 (Wed, 06 Dec 2006)
New Revision: 20054

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

Log:
Revert my changes, Simo promised to work on it :-)
Modified:
   branches/SAMBA_3_0/source/lib/ldb/ldb_tdb/ldb_index.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/ldb/ldb_tdb/ldb_index.c
===================================================================
--- branches/SAMBA_3_0/source/lib/ldb/ldb_tdb/ldb_index.c	2006-12-06 12:25:41 UTC (rev 20053)
+++ branches/SAMBA_3_0/source/lib/ldb/ldb_tdb/ldb_index.c	2006-12-06 14:40:47 UTC (rev 20054)
@@ -41,8 +41,7 @@
   find an element in a list, using the given comparison function and
   assuming that the list is already sorted using comp_fn
 
-  return -1 if not found, or the index of the first occurance of needle if
-  found
+  return -1 if not found, or the index of the first occurance of needle if found
 */
 static int ldb_list_find(const void *needle, 
 			 const void *base, size_t nmemb, size_t size, 
@@ -129,8 +128,7 @@
 	if (ldb_should_b64_encode(&v)) {
 		char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length);
 		if (!vstr) return NULL;
-		dn = talloc_asprintf(ldb, "%s:%s::%s", LTDB_INDEX, attr_folded,
-				     vstr);
+		dn = talloc_asprintf(ldb, "%s:%s::%s", LTDB_INDEX, attr_folded, vstr);
 		talloc_free(vstr);
 		if (v.data != value->data) {
 			talloc_free(v.data);
@@ -140,8 +138,8 @@
 		goto done;
 	}
 
-	dn = talloc_asprintf(ldb, "%s:%s:%.*s", LTDB_INDEX, attr_folded,
-			     (int)v.length, (char *)v.data);
+	dn = talloc_asprintf(ldb, "%s:%s:%.*s", 
+			      LTDB_INDEX, attr_folded, (int)v.length, (char *)v.data);
 
 	if (v.data != value->data) {
 		talloc_free(v.data);
@@ -166,8 +164,7 @@
 			const struct ldb_message_element *el = 
 				&msg->elements[i];
 			for (j=0;j<el->num_values;j++) {
-				if (ldb_attr_cmp((char *)el->values[j].data,
-						 attr) == 0) {
+				if (ldb_attr_cmp((char *)el->values[j].data, attr) == 0) {
 					if (v_idx) {
 						*v_idx = j;
 					}
@@ -204,8 +201,7 @@
 
 	/* if the attribute isn't in the list of indexed attributes then
 	   this node needs a full search */
-	if (ldb_msg_find_idx(index_list, tree->u.equality.attr, NULL,
-			     LTDB_IDXATTR) == -1) {
+	if (ldb_msg_find_idx(index_list, tree->u.equality.attr, NULL, LTDB_IDXATTR) == -1) {
 		return -1;
 	}
 
@@ -241,8 +237,8 @@
 		}
 
 		for (j=0;j<el->num_values;j++) {
-			list->dn[list->count] = talloc_strdup(
-				list->dn, (char *)el->values[j].data);
+			list->dn[list->count] = 
+				talloc_strdup(list->dn, (char *)el->values[j].data);
 			if (!list->dn[list->count]) {
 				talloc_free(msg);
 				return -1;
@@ -254,16 +250,14 @@
 	talloc_free(msg);
 
 	if (list->count > 1) {
-		qsort(list->dn, list->count, sizeof(char *),
-		      (comparison_fn_t) list_cmp);
+		qsort(list->dn, list->count, sizeof(char *), (comparison_fn_t) list_cmp);
 	}
 
 	return 1;
 }
 
 
-static int list_union(struct ldb_context *, struct dn_list *,
-		      const struct dn_list *);
+static int list_union(struct ldb_context *, struct dn_list *, const struct dn_list *);
 
 /*
   return a list of dn's that might match a simple indexed search on
@@ -296,6 +290,9 @@
 		struct dn_list *list2;
 		tree2.operation = LDB_OP_EQUALITY;
 		tree2.u.equality.attr = LTDB_OBJECTCLASS;
+		if (!tree2.u.equality.attr) {
+			return -1;
+		}
 		tree2.u.equality.value.data = 
 			(uint8_t *)talloc_strdup(list, subclasses[i]);
 		if (tree2.u.equality.value.data == NULL) {
@@ -332,8 +329,7 @@
 			      struct dn_list *list)
 {
 	if (ldb_attr_cmp(tree->u.equality.attr, LTDB_OBJECTCLASS) == 0) {
-		return ltdb_index_dn_objectclass(module, tree, index_list,
-						 list);
+		return ltdb_index_dn_objectclass(module, tree, index_list, list);
 	}
 	if (ldb_attr_dn(tree->u.equality.attr) == 0) {
 		list->dn = talloc_array(list, char *, 1);
@@ -341,8 +337,7 @@
 			ldb_oom(module->ldb);
 			return -1;
 		}
-		list->dn[0] = talloc_strdup(
-			list, (char *)tree->u.equality.value.data);
+		list->dn[0] = talloc_strdup(list, (char *)tree->u.equality.value.data);
 		if (list->dn[0] == NULL) {
 			ldb_oom(module->ldb);
 			return -1;
@@ -385,8 +380,7 @@
 	for (i=0;i<list->count;i++) {
 		if (ldb_list_find(list->dn[i], list2->dn, list2->count, 
 			      sizeof(char *), (comparison_fn_t)strcmp) != -1) {
-			list3->dn[list3->count] = talloc_move(
-				list3->dn, &list->dn[i]);
+			list3->dn[list3->count] = talloc_move(list3->dn, &list->dn[i]);
 			list3->count++;
 		} else {
 			talloc_free(list->dn[i]);
@@ -428,8 +422,7 @@
 	for (i=0;i<list2->count;i++) {
 		if (ldb_list_find(list2->dn[i], list->dn, count, 
 			      sizeof(char *), (comparison_fn_t)strcmp) == -1) {
-			list->dn[list->count] = talloc_strdup(
-				list->dn, list2->dn[i]);
+			list->dn[list->count] = talloc_strdup(list->dn, list2->dn[i]);
 			if (!list->dn[list->count]) {
 				return -1;
 			}
@@ -438,8 +431,7 @@
 	}
 
 	if (list->count != count) {
-		qsort(list->dn, list->count, sizeof(char *),
-		      (comparison_fn_t)list_cmp);
+		qsort(list->dn, list->count, sizeof(char *), (comparison_fn_t)list_cmp);
 	}
 
 	return 0;
@@ -476,8 +468,7 @@
 			return -1;
 		}
 
-		v = ltdb_index_dn(module, tree->u.list.elements[i],
-				  index_list, list2);
+		v = ltdb_index_dn(module, tree->u.list.elements[i], index_list, list2);
 
 		if (v == 0) {
 			/* 0 || X == X */
@@ -561,8 +552,7 @@
 			return -1;
 		}
 
-		v = ltdb_index_dn(module, tree->u.list.elements[i],
-				  index_list, list2);
+		v = ltdb_index_dn(module, tree->u.list.elements[i], index_list, list2);
 
 		if (v == 0) {
 			/* 0 && X == 0 */
@@ -648,8 +638,7 @@
 static int ltdb_index_filter(const struct dn_list *dn_list, 
 			     struct ldb_handle *handle)
 {
-	struct ltdb_context *ac = talloc_get_type(handle->private_data,
-						  struct ltdb_context);
+	struct ltdb_context *ac = talloc_get_type(handle->private_data, struct ltdb_context);
 	struct ldb_reply *ares = NULL;
 	unsigned int i;
 
@@ -697,8 +686,7 @@
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
-		if (!ldb_match_msg(ac->module->ldb, ares->message, ac->tree,
-				   ac->base, ac->scope)) {
+		if (!ldb_match_msg(ac->module->ldb, ares->message, ac->tree, ac->base, ac->scope)) {
 			talloc_free(ares);
 			continue;
 		}
@@ -715,8 +703,7 @@
 
 		ares->type = LDB_REPLY_ENTRY;
         	handle->state = LDB_ASYNC_PENDING;
-		handle->status = ac->callback(ac->module->ldb, ac->context,
-					      ares);
+		handle->status = ac->callback(ac->module->ldb, ac->context, ares);
 
 		if (handle->status != LDB_SUCCESS) {
 			handle->state = LDB_ASYNC_DONE;
@@ -772,8 +759,7 @@
 		dn_list->count = 1;
 		ret = 1;
 	} else {
-		ret = ltdb_index_dn(ac->module, ac->tree,
-				    ltdb->cache->indexlist, dn_list);
+		ret = ltdb_index_dn(ac->module, ac->tree, ltdb->cache->indexlist, dn_list);
 	}
 
 	if (ret == 1) {
@@ -801,26 +787,23 @@
 
 	/* add another entry */
 	el2 = talloc_realloc(msg, msg->elements, 
-			     struct ldb_message_element, msg->num_elements+1);
+			       struct ldb_message_element, msg->num_elements+1);
 	if (!el2) {
 		return -1;
 	}
 
 	msg->elements = el2;
-	msg->elements[msg->num_elements].name = talloc_strdup(msg->elements,
-							      LTDB_IDX);
+	msg->elements[msg->num_elements].name = talloc_strdup(msg->elements, LTDB_IDX);
 	if (!msg->elements[msg->num_elements].name) {
 		return -1;
 	}
 	msg->elements[msg->num_elements].num_values = 0;
-	msg->elements[msg->num_elements].values = talloc(msg->elements,
-							 struct ldb_val);
+	msg->elements[msg->num_elements].values = talloc(msg->elements, struct ldb_val);
 	if (!msg->elements[msg->num_elements].values) {
 		return -1;
 	}
 	msg->elements[msg->num_elements].values[0].length = strlen(dn);
-	msg->elements[msg->num_elements].values[0].data =
-		discard_const_p(uint8_t, dn);
+	msg->elements[msg->num_elements].values[0].data = discard_const_p(uint8_t, dn);
 	msg->elements[msg->num_elements].num_values = 1;
 	msg->num_elements++;
 
@@ -843,8 +826,7 @@
 
 	/* for multi-valued attributes we can end up with repeats */
 	for (i=0;i<msg->elements[idx].num_values;i++) {
-		if (strcmp(dn,
-			   (char *)msg->elements[idx].values[i].data) == 0) {
+		if (strcmp(dn, (char *)msg->elements[idx].values[i].data) == 0) {
 			return 0;
 		}
 	}
@@ -857,10 +839,8 @@
 	}
 	msg->elements[idx].values = v2;
 
-	msg->elements[idx].values[msg->elements[idx].num_values].length =
-		strlen(dn);
-	msg->elements[idx].values[msg->elements[idx].num_values].data =
-		discard_const_p(uint8_t, dn);
+	msg->elements[idx].values[msg->elements[idx].num_values].length = strlen(dn);
+	msg->elements[idx].values[msg->elements[idx].num_values].data = discard_const_p(uint8_t, dn);
 	msg->elements[idx].num_values++;
 
 	return 0;
@@ -943,8 +923,8 @@
 	}
 
 	for (i = 0; i < num_el; i++) {
-		ret = ldb_msg_find_idx(ltdb->cache->indexlist,
-				       elements[i].name, NULL, LTDB_IDXATTR);
+		ret = ldb_msg_find_idx(ltdb->cache->indexlist, elements[i].name, 
+				       NULL, LTDB_IDXATTR);
 		if (ret == -1) {
 			continue;
 		}
@@ -1017,8 +997,8 @@
 	}
 
 	if (ret == 0) {
-		/* it wasn't indexed. Did we have an earlier error? If we did
-		   then its gone now */
+		/* it wasn't indexed. Did we have an earlier error? If we did then
+		   its gone now */
 		talloc_free(dn_key);
 		return 0;
 	}
@@ -1080,15 +1060,13 @@
 	}
 
 	for (i = 0; i < msg->num_elements; i++) {
-		ret = ldb_msg_find_idx(ltdb->cache->indexlist,
-				       msg->elements[i].name, NULL,
-				       LTDB_IDXATTR);
+		ret = ldb_msg_find_idx(ltdb->cache->indexlist, msg->elements[i].name, 
+				       NULL, LTDB_IDXATTR);
 		if (ret == -1) {
 			continue;
 		}
 		for (j = 0; j < msg->elements[i].num_values; j++) {
-			ret = ltdb_index_del_value(module, dn,
-						   &msg->elements[i], j);
+			ret = ltdb_index_del_value(module, dn, &msg->elements[i], j);
 			if (ret == -1) {
 				talloc_free(dn);
 				return -1;
@@ -1104,8 +1082,7 @@
 /*
   traversal function that deletes all @INDEX records
 */
-static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
-			void *state)
+static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
 {
 	const char *dn = "DN=" LTDB_INDEX ":";
 	if (strncmp((char *)key.dptr, dn, strlen(dn)) == 0) {
@@ -1117,8 +1094,7 @@
 /*
   traversal function that adds @INDEX records during a re index
 */
-static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
-		    void *state)
+static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
 {
 	struct ldb_module *module = (struct ldb_module *)state;
 	struct ldb_message *msg;
@@ -1147,9 +1123,8 @@
 	key2 = ltdb_key(module, msg->dn);
 	if (key2.dptr == NULL) {
 		/* probably a corrupt record ... darn */
-		ldb_debug(module->ldb, LDB_DEBUG_ERROR,
-			  "Invalid DN in re_index: %s\n",
-			  ldb_dn_linearize(msg, msg->dn));
+		ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s\n",
+							ldb_dn_linearize(msg, msg->dn));
 		talloc_free(msg);
 		return 0;
 	}



More information about the samba-cvs mailing list