* In typical use, most values are single-valued. This makes
* it quite expensive to allocate an array of ldb_val for each
* of these, just to then hold the pointer to the data buffer
- * (in the LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC we don't
- * allocate the data). So with
- * LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC we allocate this ahead
- * of time and use it for the single values where possible.
+ * So with LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC we allocate this
+ * ahead of time and use it for the single values where possible.
* (This is used the the normal search case, but not in the
* index case because of caller requirements).
*/
}
}
element = &message->elements[nelem];
- if (flags & LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC) {
- element->name = attr;
- } else {
- element->name = talloc_memdup(message->elements, attr, attr_len+1);
-
- if (element->name == NULL) {
- errno = ENOMEM;
- goto failed;
- }
- }
+ element->name = attr;
element->flags = 0;
if (remaining < (attr_len + 1)) {
}
element->values[j].length = len;
- if (flags & LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC) {
- element->values[j].data = p + 4;
- } else {
- element->values[j].data = talloc_size(element->values, len+1);
- if (element->values[j].data == NULL) {
- errno = ENOMEM;
- goto failed;
- }
- memcpy(element->values[j].data, p + 4,
- len);
- element->values[j].data[len] = 0;
- }
+ element->values[j].data = p + 4;
remaining -= len;
p += len+4+1;
}
/*
* Unpack a ldb message from a linear buffer in ldb_val
*
- * Providing a list of attributes to this function allows selective unpacking.
- * Giving a NULL list (or a list_size of 0) unpacks all the attributes.
- *
- * Flags allow control of allocation, so that if
- * LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC is specified, then data in values are
- * not allocated, instead they point into the supplier constant buffer.
- *
* If LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC is specified, then values
* array are not allocated individually (for single-valued
* attributes), instead they point into a single buffer per message.
*
- * LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC is only valid when
- * LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC is also specified.
- *
* Likewise if LDB_UNPACK_DATA_FLAG_NO_DN is specified, the DN is omitted.
*
* If LDB_UNPACK_DATA_FLAG_NO_ATTRS is specified, then no attributes
unsigned int flags,
unsigned int *nb_elements_in_db);
-#define LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC 0x0001
+/* currently unused (was NO_DATA_ALLOC) 0x0001 */
#define LDB_UNPACK_DATA_FLAG_NO_DN 0x0002
#define LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC 0x0004
#define LDB_UNPACK_DATA_FLAG_NO_ATTRS 0x0008
/* in case any attribute of the message was indexed, we need
to fetch the old record */
- ret = ldb_kv_search_dn1(
- module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
+ ret = ldb_kv_search_dn1(module, dn, msg, 0);
if (ret != LDB_SUCCESS) {
/* not finding the old record is an error */
goto done;
goto done;
}
- ret = ldb_kv_search_dn1(
- module, msg->dn, msg2, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
+ ret = ldb_kv_search_dn1(module, msg->dn, msg2, 0);
if (ret != LDB_SUCCESS) {
goto done;
}
}
/* we need to fetch the old record to re-add under the new name */
- ret = ldb_kv_search_dn1(module,
- req->op.rename.olddn,
- msg,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
+ ret = ldb_kv_search_dn1(module, req->op.rename.olddn, msg, 0);
if (ret == LDB_ERR_INVALID_DN_SYNTAX) {
ldb_asprintf_errstring(ldb_module_get_ctx(module),
"Invalid Old DN: %s",
r = ldb_kv_search_dn1(module,
dn,
attrs_msg,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
- LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
+ LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
LDB_UNPACK_DATA_FLAG_NO_DN);
talloc_free(dn);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
r = ldb_kv_search_dn1(module,
indexlist_dn,
ldb_kv->cache->indexlist,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
- LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
+ LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
LDB_UNPACK_DATA_FLAG_NO_DN);
TALLOC_FREE(indexlist_dn);
ret = ldb_kv_search_dn1(module,
dn,
msg,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
LDB_UNPACK_DATA_FLAG_NO_DN |
/*
* The entry point ldb_kv_search_indexed is
/*
* we avoid copying the strings by stealing the list. We have
- * to steal msg onto el->values (which looks odd) because we
- * asked for the memory to be allocated on msg, not on each
- * value with LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC above
+ * to steal msg onto el->values (which looks odd) because
+ * the memory is allocated on msg, not on each value.
*/
if (ldb_kv->cache->GUID_index_attribute == NULL) {
/* check indexing version number */
}
/*
- * The actual data is on msg, due to
- * LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC
+ * The actual data is on msg.
*/
talloc_steal(list->dn, msg);
for (i = 0; i < list->count; i++) {
ctx->error = ldb_unpack_data_only_attr_list_flags(ldb, &data,
msg,
NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
LDB_UNPACK_DATA_FLAG_NO_DN,
NULL);
/*
* we avoid copying the strings by stealing the list. We have
- * to steal msg onto el->values (which looks odd) because we
- * asked for the memory to be allocated on msg, not on each
- * value with LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC above
+ * to steal msg onto el->values (which looks odd) because
+ * the memory is allocated on msg, not on each value.
*/
if (version != LDB_KV_GUID_INDEXING_VERSION) {
/* This is quite likely during the DB startup
}
/*
- * The actual data is on msg, due to
- * LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC
+ * The actual data is on msg.
*/
talloc_steal(ctx->dn_list->dn, msg);
for (i = 0; i < additional_length; i++) {
ldb_kv,
keys[i],
msg,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
/*
* The entry point ldb_kv_search_indexed is
(struct ldb_kv_reindex_context *)state;
struct ldb_module *module = ctx->module;
struct ldb_message *msg;
- unsigned int nb_elements_in_db;
int ret;
struct ldb_val key2;
bool is_record;
return -1;
}
- ret = ldb_unpack_data_only_attr_list_flags(ldb, &val,
- msg,
- NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC,
- &nb_elements_in_db);
+ ret = ldb_unpack_data(ldb, &val, msg);
if (ret != 0) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %s\n",
ldb_dn_get_linearized(msg->dn));
(struct ldb_kv_reindex_context *)state;
struct ldb_module *module = ctx->module;
struct ldb_message *msg;
- unsigned int nb_elements_in_db;
int ret;
bool is_record;
return -1;
}
- ret = ldb_unpack_data_only_attr_list_flags(ldb, &val,
- msg,
- NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC,
- &nb_elements_in_db);
+ ret = ldb_unpack_data(ldb, &val, msg);
if (ret != 0) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %s\n",
ldb_dn_get_linearized(msg->dn));
void *private_data)
{
struct ldb_kv_parse_data_unpack_ctx *ctx = private_data;
- unsigned int nb_elements_in_db;
int ret;
struct ldb_context *ldb = ldb_module_get_ctx(ctx->module);
struct ldb_val data_parse = data;
struct ldb_kv_private *ldb_kv = ctx->ldb_kv;
- if ((ctx->unpack_flags & LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC)) {
- if ((ldb_kv->kv_ops->options & LDB_KV_OPTION_STABLE_READ_LOCK) &&
- (ctx->unpack_flags & LDB_UNPACK_DATA_FLAG_READ_LOCKED) &&
- !ldb_kv->kv_ops->transaction_active(ldb_kv)) {
- /*
- * In the case where no transactions are active and
- * we're in a read-lock, we can point directly into
- * database memory.
- *
- * The database can't be changed underneath us and we
- * will duplicate this data in the call to filter.
- *
- * This is seen in:
- * - ldb_kv_index_filter
- * - ldb_kv_search_and_return_base
- */
- } else {
- /*
- * In every other case, if we got
- * LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC we need at least
- * do a memdup on the whole data buffer as that may
- * change later and the caller needs a stable result.
- *
- * During transactions, pointers could change and in
- * TDB, there just aren't the same guarantees.
- */
- data_parse.data = talloc_memdup(ctx->msg,
- data.data,
- data.length);
- if (data_parse.data == NULL) {
- ldb_debug(ldb, LDB_DEBUG_ERROR,
- "Unable to allocate data(%d) for %*.*s\n",
- (int)data.length,
- (int)key.length, (int)key.length, key.data);
- return LDB_ERR_OPERATIONS_ERROR;
- }
+ if ((ldb_kv->kv_ops->options & LDB_KV_OPTION_STABLE_READ_LOCK) &&
+ (ctx->unpack_flags & LDB_UNPACK_DATA_FLAG_READ_LOCKED) &&
+ !ldb_kv->kv_ops->transaction_active(ldb_kv)) {
+ /*
+ * In the case where no transactions are active and
+ * we're in a read-lock, we can point directly into
+ * database memory.
+ *
+ * The database can't be changed underneath us and we
+ * will duplicate this data in the call to filter.
+ *
+ * This is seen in:
+ * - ldb_kv_index_filter
+ * - ldb_kv_search_and_return_base
+ */
+ } else {
+ /*
+ * In every other case, since unpack doesn't memdup, we need
+ * to at least do a memdup on the whole data buffer as that
+ * may change later and the caller needs a stable result.
+ *
+ * During transactions, pointers could change and in
+ * TDB, there just aren't the same guarantees.
+ */
+ data_parse.data = talloc_memdup(ctx->msg,
+ data.data,
+ data.length);
+ if (data_parse.data == NULL) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Unable to allocate data(%d) for %*.*s\n",
+ (int)data.length,
+ (int)key.length, (int)key.length, key.data);
+ return LDB_ERR_OPERATIONS_ERROR;
}
}
ctx->msg,
NULL, 0,
ctx->unpack_flags,
- &nb_elements_in_db);
+ NULL);
if (ret == -1) {
if (data_parse.data != data.data) {
talloc_free(data_parse.data);
ret = ldb_unpack_data_only_attr_list_flags(ldb, &val,
msg,
NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC|
LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC,
&nb_elements_in_db);
if (ret == -1) {
ret = ldb_kv_search_dn1(ctx->module,
ctx->base,
msg,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
LDB_UNPACK_DATA_FLAG_READ_LOCKED);
ldb_unpack_data_only_attr_list_flags(ldb, &data,
msg,
NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC,
- &nb_elements_in_db),
- 0,
- "ldb_unpack_data failed");
-
- ldif.changetype = LDB_CHANGETYPE_NONE;
- ldif.msg = msg;
- ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
-
- torture_assert_int_equal(torture,
- strcmp(ldif_text, dda1d01d_ldif), 0,
- "ldif form differs from binary form");
-
- torture_assert_int_equal(torture,
- ldb_unpack_data_only_attr_list_flags(ldb, &data,
- msg,
- NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC|
LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC,
&nb_elements_in_db),
0,