return 0;
}
-static bool ldb_consume_element_data(uint8_t **pp, size_t *premaining)
-{
- unsigned int remaining = *premaining;
- uint8_t *p = *pp;
- uint32_t num_values = pull_uint32(p, 0);
- uint32_t j, len;
-
- p += 4;
- if (remaining < 4) {
- return false;
- }
- remaining -= 4;
- for (j = 0; j < num_values; j++) {
- len = pull_uint32(p, 0);
- if (remaining < 5) {
- return false;
- }
- remaining -= 5;
- if (len > remaining) {
- return false;
- }
- remaining -= len;
- p += len + 4 + 1;
- }
-
- *premaining = remaining;
- *pp = p;
- return true;
-}
-
-
/*
* 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.
*/
-int ldb_unpack_data_only_attr_list_flags(struct ldb_context *ldb,
- const struct ldb_val *data,
- struct ldb_message *message,
- const char * const *list,
- unsigned int list_size,
- unsigned int flags,
- unsigned int *nb_elements_in_db)
+int ldb_unpack_data_flags(struct ldb_context *ldb,
+ const struct ldb_val *data,
+ struct ldb_message *message,
+ unsigned int flags)
{
uint8_t *p;
size_t remaining;
unsigned format;
unsigned int nelem = 0;
size_t len;
- unsigned int found = 0;
struct ldb_val *ldb_val_single_array = NULL;
- if (list == NULL) {
- list_size = 0;
- }
-
message->elements = NULL;
p = data->data;
format = pull_uint32(p, 0);
message->num_elements = pull_uint32(p, 4);
p += 8;
- if (nb_elements_in_db) {
- *nb_elements_in_db = message->num_elements;
- }
remaining = data->length - 8;
}
attr = (char *)p;
- /*
- * The general idea is to reduce allocations by skipping over
- * attributes that we do not actually care about.
- *
- * This is a bit expensive but normally the list is pretty small
- * also the cost of freeing unused attributes is quite important
- * and can dwarf the cost of looping.
- */
- if (list_size != 0) {
- bool keep = false;
- unsigned int h;
-
- /*
- * We know that p has a \0 terminator before the
- * end of the buffer due to the check above.
- */
- for (h = 0; h < list_size && found < list_size; h++) {
- if (ldb_attr_cmp(attr, list[h]) == 0) {
- keep = true;
- found++;
- break;
- }
- }
-
- if (!keep) {
- if (remaining < (attr_len + 1)) {
- errno = EIO;
- goto failed;
- }
- remaining -= attr_len + 1;
- p += attr_len + 1;
- if (!ldb_consume_element_data(&p, &remaining)) {
- errno = EIO;
- goto failed;
- }
- continue;
- }
- }
element = &message->elements[nelem];
element->name = attr;
element->flags = 0;
if (remaining != 0) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
- "Error: %zu bytes unread in ldb_unpack_data_only_attr_list",
+ "Error: %zu bytes unread in ldb_unpack_data_flags",
remaining);
}
/*
* 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.
- *
* Free with ldb_unpack_data_free()
*/
-int ldb_unpack_data_only_attr_list(struct ldb_context *ldb,
- const struct ldb_val *data,
- struct ldb_message *message,
- const char * const *list,
- unsigned int list_size,
- unsigned int *nb_elements_in_db)
-{
- return ldb_unpack_data_only_attr_list_flags(ldb,
- data,
- message,
- list,
- list_size,
- 0,
- nb_elements_in_db);
-}
-
int ldb_unpack_data(struct ldb_context *ldb,
const struct ldb_val *data,
struct ldb_message *message)
{
- return ldb_unpack_data_only_attr_list(ldb, data, message, NULL, 0, NULL);
+ return ldb_unpack_data_flags(ldb, data, message, 0);
}
/*
struct ldb_val *data);
/*
* 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.
*/
-int ldb_unpack_data_only_attr_list(struct ldb_context *ldb,
- const struct ldb_val *data,
- struct ldb_message *message,
- const char* const * list,
- unsigned int list_size,
- unsigned int *nb_attributes_indb);
int ldb_unpack_data(struct ldb_context *ldb,
const struct ldb_val *data,
struct ldb_message *message);
* are unpacked or returned.
*
*/
-int ldb_unpack_data_only_attr_list_flags(struct ldb_context *ldb,
- const struct ldb_val *data,
- struct ldb_message *message,
- const char * const *list,
- unsigned int list_size,
- unsigned int flags,
- unsigned int *nb_elements_in_db);
+int ldb_unpack_data_flags(struct ldb_context *ldb,
+ const struct ldb_val *data,
+ struct ldb_message *message,
+ unsigned int flags);
/* currently unused (was NO_DATA_ALLOC) 0x0001 */
#define LDB_UNPACK_DATA_FLAG_NO_DN 0x0002
msg = ldb_msg_new(module);
- ctx->error = ldb_unpack_data_only_attr_list_flags(ldb, &data,
- msg,
- NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_DN,
- NULL);
+ ctx->error = ldb_unpack_data_flags(ldb, &data, msg,
+ LDB_UNPACK_DATA_FLAG_NO_DN);
if (ctx->error != LDB_SUCCESS) {
talloc_free(msg);
}
}
- ret = ldb_unpack_data_only_attr_list_flags(ldb, &data_parse,
- ctx->msg,
- NULL, 0,
- ctx->unpack_flags,
- NULL);
+ ret = ldb_unpack_data_flags(ldb, &data_parse,
+ ctx->msg, ctx->unpack_flags);
if (ret == -1) {
if (data_parse.data != data.data) {
talloc_free(data_parse.data);
struct ldb_message *msg, *filtered_msg;
int ret;
bool matched;
- unsigned int nb_elements_in_db;
ac = talloc_get_type(state, struct ldb_kv_context);
ldb = ldb_module_get_ctx(ac->module);
}
/* unpack the record */
- ret = ldb_unpack_data_only_attr_list_flags(ldb, &val,
- msg,
- NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC,
- &nb_elements_in_db);
+ ret = ldb_unpack_data_flags(ldb, &val, msg,
+ LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC);
if (ret == -1) {
talloc_free(msg);
ac->error = LDB_ERR_OPERATIONS_ERROR;
struct ldb_message *msg = ldb_msg_new(mem_ctx);
const char *ldif_text = dda1d01d_ldif;
struct ldb_ldif ldif;
- unsigned int nb_elements_in_db;
ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
torture_assert(torture,
"Failed to init ldb");
torture_assert_int_equal(torture,
- ldb_unpack_data_only_attr_list_flags(ldb, &data,
- msg,
- NULL, 0,
- LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC,
- &nb_elements_in_db),
+ ldb_unpack_data_flags(ldb, &data, msg,
+ LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC),
0,
"ldb_unpack_data failed");
"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_DN,
- &nb_elements_in_db),
+ ldb_unpack_data_flags(ldb, &data, msg,
+ LDB_UNPACK_DATA_FLAG_NO_DN),
0,
"ldb_unpack_data failed");