summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb/ldb_pack.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-01 09:45:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:38 -0500
commit0dad5a34273bf5cadcfd4a36d69bdffbf69eb073 (patch)
tree78ddbe4e053287a0e7a0300e945627ce4b24bc29 /source4/lib/ldb/ldb_tdb/ldb_pack.c
parenta2b6d47390a07f0d2a737d17144f825a9733d5bf (diff)
downloadsamba-0dad5a34273bf5cadcfd4a36d69bdffbf69eb073.tar.gz
samba-0dad5a34273bf5cadcfd4a36d69bdffbf69eb073.tar.bz2
samba-0dad5a34273bf5cadcfd4a36d69bdffbf69eb073.zip
r435: a major upgrade for ldb
- added the ability to mark record attributes as being CASE_INSENSITIVE, WILDCARD or INTEGER. - added the ability to support objectclass subclasses, and to search by a parent class - added internal support for case insensitive versus case sensitive indexing (not UTF8 compliant yet) - cleaned up a number of const warnings - added a number of helper functions for fetching integers, strings and doubles - added a in-memory cache for important database properties, supported by a database sequence number - changed some variable names to avoid conflicts with C++ (This used to be commit f2bf06f25c2e6c744817711c7bedbd1d3b52f994)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb/ldb_pack.c')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_pack.c56
1 files changed, 43 insertions, 13 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c
index 1196e561a2..3ded595259 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_pack.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c
@@ -36,7 +36,10 @@
#include "ldb/ldb_tdb/ldb_tdb.h"
/* change this if the data format ever changes */
-#define LTDB_PACKING_FORMAT 0x26011966
+#define LTDB_PACKING_FORMAT 0x26011967
+
+/* old packing formats */
+#define LTDB_PACKING_FORMAT_NODN 0x26011966
/*
pack a ldb message into a linear buffer in a TDB_DATA
@@ -53,10 +56,13 @@ int ltdb_pack_data(struct ldb_context *ctx,
int i, j;
size_t size;
char *p;
+ size_t len;
/* work out how big it needs to be */
size = 8;
+ size += 1 + strlen(message->dn);
+
for (i=0;i<message->num_elements;i++) {
if (message->elements[i].num_values == 0) {
continue;
@@ -79,9 +85,14 @@ int ltdb_pack_data(struct ldb_context *ctx,
SIVAL(p, 0, LTDB_PACKING_FORMAT);
SIVAL(p, 4, message->num_elements);
p += 8;
+
+ /* the dn needs to be packed so we can be case preserving
+ while hashing on a case folded dn */
+ len = strlen(message->dn);
+ memcpy(p, message->dn, len+1);
+ p += len + 1;
for (i=0;i<message->num_elements;i++) {
- size_t len;
if (message->elements[i].num_values == 0) {
continue;
}
@@ -133,33 +144,49 @@ int ltdb_unpack_data(struct ldb_context *ctx,
char *p;
unsigned int remaining;
int i, j;
+ unsigned format;
+ size_t len;
message->elements = NULL;
p = data->dptr;
- if (data->dsize < 4) {
+ if (data->dsize < 8) {
errno = EIO;
goto failed;
}
- if (IVAL(p, 0) != LTDB_PACKING_FORMAT) {
- /* this is where we will cope with upgrading the
- format if/when the format is ever changed */
+ format = IVAL(p, 0);
+ message->num_elements = IVAL(p, 4);
+ p += 8;
+
+ remaining = data->dsize - 8;
+
+ switch (format) {
+ case LTDB_PACKING_FORMAT_NODN:
+ message->dn = NULL;
+ break;
+
+ case LTDB_PACKING_FORMAT:
+ len = strnlen(p, remaining);
+ if (len == remaining) {
+ errno = EIO;
+ goto failed;
+ }
+ message->dn = p;
+ remaining -= len + 1;
+ p += len + 1;
+ break;
+
+ default:
errno = EIO;
goto failed;
}
- message->num_elements = IVAL(p, 4);
- p += 8;
-
if (message->num_elements == 0) {
message->elements = NULL;
return 0;
}
- /* basic sanity check */
- remaining = data->dsize - 8;
-
if (message->num_elements > remaining / 6) {
errno = EIO;
goto failed;
@@ -174,12 +201,15 @@ int ltdb_unpack_data(struct ldb_context *ctx,
}
for (i=0;i<message->num_elements;i++) {
- size_t len;
if (remaining < 10) {
errno = EIO;
goto failed;
}
len = strnlen(p, remaining-6);
+ if (len == remaining-6) {
+ errno = EIO;
+ goto failed;
+ }
message->elements[i].flags = 0;
message->elements[i].name = p;
remaining -= len + 1;