diff options
author | Andrew Tridgell <tridge@samba.org> | 2012-10-31 16:06:03 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2012-11-01 15:40:41 +1100 |
commit | 30ffdda45bd3ae602b453c9c1bbdb77ea3de8a8d (patch) | |
tree | 2859583eec07abce06678d464aea79501dd3e554 /lib/ldb/common | |
parent | fc47b0d03c577730ce0ef9e09092f80c0712d5d0 (diff) | |
download | samba-30ffdda45bd3ae602b453c9c1bbdb77ea3de8a8d.tar.gz samba-30ffdda45bd3ae602b453c9c1bbdb77ea3de8a8d.tar.bz2 samba-30ffdda45bd3ae602b453c9c1bbdb77ea3de8a8d.zip |
ldb: fixed callers for ldb_pack_data() and ldb_unpack_data()
with ltdb_pack_data() and ltdb_unpack_data() now moved into common, we
need to increase the minor version and fixup callers of the API
Note that this relies on struct ldb_val being the same shape as
TDB_DATA, in much the same way as we rely on ldb_val and DATA_BLOB
being the same shape.
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/ldb/common')
-rw-r--r-- | lib/ldb/common/ldb_pack.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c index 03e0ec1ddf..4382d5b1be 100644 --- a/lib/ldb/common/ldb_pack.c +++ b/lib/ldb/common/ldb_pack.c @@ -31,13 +31,13 @@ * Author: Andrew Tridgell */ -#include "ldb_tdb.h" +#include "ldb_private.h" /* change this if the data format ever changes */ -#define LTDB_PACKING_FORMAT 0x26011967 +#define LDB_PACKING_FORMAT 0x26011967 /* old packing formats */ -#define LTDB_PACKING_FORMAT_NODN 0x26011966 +#define LDB_PACKING_FORMAT_NODN 0x26011966 /* use a portable integer format */ static void put_uint32(uint8_t *p, int ofs, unsigned int val) @@ -65,26 +65,23 @@ static int attribute_storable_values(const struct ldb_message_element *el) } /* - pack a ldb message into a linear buffer in a TDB_DATA + pack a ldb message into a linear buffer in a ldb_val note that this routine avoids saving elements with zero values, as these are equivalent to having no element caller frees the data buffer after use */ -int ltdb_pack_data(struct ldb_module *module, - const struct ldb_message *message, - TDB_DATA *data) +int ldb_pack_data(struct ldb_context *ldb, + const struct ldb_message *message, + struct ldb_val *data) { - struct ldb_context *ldb; unsigned int i, j, real_elements=0; size_t size; const char *dn; uint8_t *p; size_t len; - ldb = ldb_module_get_ctx(module); - dn = ldb_dn_get_linearized(message->dn); if (dn == NULL) { errno = ENOMEM; @@ -110,15 +107,15 @@ int ltdb_pack_data(struct ldb_module *module, } /* allocate it */ - data->dptr = talloc_array(ldb, uint8_t, size); - if (!data->dptr) { + data->data = talloc_array(ldb, uint8_t, size); + if (!data->data) { errno = ENOMEM; return -1; } - data->dsize = size; + data->length = size; - p = data->dptr; - put_uint32(p, 0, LTDB_PACKING_FORMAT); + p = data->data; + put_uint32(p, 0, LDB_PACKING_FORMAT); put_uint32(p, 4, real_elements); p += 8; @@ -150,13 +147,13 @@ int ltdb_pack_data(struct ldb_module *module, } /* - unpack a ldb message from a linear buffer in TDB_DATA + unpack a ldb message from a linear buffer in ldb_val - Free with ltdb_unpack_data_free() + Free with ldb_unpack_data_free() */ -int ltdb_unpack_data(struct ldb_context *ldb, - const TDB_DATA *data, - struct ldb_message *message) +int ldb_unpack_data(struct ldb_context *ldb, + const struct ldb_val *data, + struct ldb_message *message) { uint8_t *p; unsigned int remaining; @@ -166,8 +163,8 @@ int ltdb_unpack_data(struct ldb_context *ldb, message->elements = NULL; - p = data->dptr; - if (data->dsize < 8) { + p = data->data; + if (data->length < 8) { errno = EIO; goto failed; } @@ -176,14 +173,14 @@ int ltdb_unpack_data(struct ldb_context *ldb, message->num_elements = pull_uint32(p, 4); p += 8; - remaining = data->dsize - 8; + remaining = data->length - 8; switch (format) { - case LTDB_PACKING_FORMAT_NODN: + case LDB_PACKING_FORMAT_NODN: message->dn = NULL; break; - case LTDB_PACKING_FORMAT: + case LDB_PACKING_FORMAT: len = strnlen((char *)p, remaining); if (len == remaining) { errno = EIO; @@ -279,7 +276,7 @@ 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", remaining); + "Error: %d bytes unread in ldb_unpack_data", remaining); } return 0; |