summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-20 13:25:06 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:53:50 -0500
commitf0a8f718ff474009300af6746fa0fbb61c649ea9 (patch)
tree47c1c29215336691e96c2d2526883455f108d585 /source4/lib/ldb/ldb_tdb
parent0a083d1e08a7f7dfcf8abf5866ceb0eee52509e7 (diff)
downloadsamba-f0a8f718ff474009300af6746fa0fbb61c649ea9.tar.gz
samba-f0a8f718ff474009300af6746fa0fbb61c649ea9.tar.bz2
samba-f0a8f718ff474009300af6746fa0fbb61c649ea9.zip
r792: - changed the ldb ldif_* functions to be in the ldb_ namespace
- added better error reporting in ldbdel - fixed a bug in handling packing of records which contain elements with no values (it caused db corruption) - allow search with "dn" as target attribute (This used to be commit 36575396234e3d35dbd442c8f1ff54a17ae64e64)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c1
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_match.c1
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_pack.c20
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c28
4 files changed, 46 insertions, 4 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 3febdaa711..b4ca666287 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb/include/ldb_parse.h"
struct dn_list {
unsigned int count;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_match.c b/source4/lib/ldb/ldb_tdb/ldb_match.c
index 80d147cb43..05a2826d4d 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_match.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_match.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb/include/ldb_parse.h"
/*
diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c
index 8d1051be94..e71679646e 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_pack.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c
@@ -69,11 +69,17 @@ int ltdb_pack_data(struct ldb_context *ldb,
const struct ldb_message *message,
struct TDB_DATA *data)
{
- int i, j;
+ int i, j, real_elements=0;
size_t size;
char *p;
size_t len;
+ for (i=0;i<message->num_elements;i++) {
+ if (message->elements[i].num_values != 0) {
+ real_elements++;
+ }
+ }
+
/* work out how big it needs to be */
size = 8;
@@ -99,7 +105,7 @@ int ltdb_pack_data(struct ldb_context *ldb,
p = data->dptr;
put_uint32(p, 0, LTDB_PACKING_FORMAT);
- put_uint32(p, 4, message->num_elements);
+ put_uint32(p, 4, real_elements);
p += 8;
/* the dn needs to be packed so we can be case preserving
@@ -211,12 +217,14 @@ int ltdb_unpack_data(struct ldb_context *ldb,
message->elements = ldb_malloc_array_p(ldb, struct ldb_message_element,
message->num_elements);
-
if (!message->elements) {
errno = ENOMEM;
goto failed;
}
+ memset(message->elements, 0,
+ message->num_elements * sizeof(struct ldb_message_element));
+
for (i=0;i<message->num_elements;i++) {
if (remaining < 10) {
errno = EIO;
@@ -243,6 +251,7 @@ int ltdb_unpack_data(struct ldb_context *ldb,
}
}
p += 4;
+ remaining -= 4;
for (j=0;j<message->elements[i].num_values;j++) {
len = pull_uint32(p, 0);
if (len > remaining-5) {
@@ -257,6 +266,11 @@ int ltdb_unpack_data(struct ldb_context *ldb,
}
}
+ if (remaining != 0) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Error: %d bytes unread in ltdb_unpack_data\n", remaining);
+ }
+
return 0;
failed:
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index 6b38a28296..d97444a6e8 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb/include/ldb_parse.h"
/*
free a message that has all parts separately allocated
@@ -192,6 +193,31 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
continue;
}
+ if (ldb_attr_cmp(attrs[i], "dn") == 0) {
+ struct ldb_message_element el2;
+ struct ldb_val val;
+
+ el2.flags = 0;
+ el2.name = ldb_strdup(ldb, "dn");
+ if (!el2.name) {
+ msg_free_all_parts(ldb, ret);
+ ldb_free(ldb, el2.name);
+ return NULL;
+ }
+ el2.num_values = 1;
+ el2.values = &val;
+ val.data = ret->dn;
+ val.length = strlen(ret->dn);
+
+ if (msg_add_element(ldb, ret, &el2) != 0) {
+ msg_free_all_parts(ldb, ret);
+ ldb_free(ldb, el2.name);
+ return NULL;
+ }
+ ldb_free(ldb, el2.name);
+ continue;
+ }
+
el = ldb_msg_find_element(msg, attrs[i]);
if (!el) {
continue;
@@ -290,7 +316,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message
ret = ltdb_unpack_data(ldb, &tdb_data2, msg);
if (ret == -1) {
- free(tdb_data2.dptr);
+ ldb_free(ldb, tdb_data2.dptr);
return -1;
}