return ret;
}
-/*
- add all elements from one message into another
- */
-static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *ret,
- const struct ldb_message *msg)
-{
- struct ldb_context *ldb;
- unsigned int i;
- int check_duplicates = (ret->num_elements != 0);
-
- ldb = ldb_module_get_ctx(module);
-
- if (msg_add_distinguished_name(ret) != 0) {
- return -1;
- }
-
- for (i=0;i<msg->num_elements;i++) {
- const struct ldb_schema_attribute *a;
- a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name);
- if (a->flags & LDB_ATTR_FLAG_HIDDEN) {
- continue;
- }
- if (msg_add_element(ret, &msg->elements[i],
- check_duplicates) != 0) {
- return -1;
- }
- }
-
- return 0;
-}
-
-
-/*
- pull the specified list of attributes from a message
- */
-static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module,
- TALLOC_CTX *mem_ctx,
- const struct ldb_message *msg,
- const char * const *attrs)
-{
- struct ldb_message *ret;
- unsigned int i;
-
- ret = talloc(mem_ctx, struct ldb_message);
- if (!ret) {
- return NULL;
- }
-
- ret->dn = ldb_dn_copy(ret, msg->dn);
- if (!ret->dn) {
- talloc_free(ret);
- return NULL;
- }
-
- ret->num_elements = 0;
- ret->elements = NULL;
-
- if (!attrs) {
- if (msg_add_all_elements(module, ret, msg) != 0) {
- talloc_free(ret);
- return NULL;
- }
- return ret;
- }
-
- for (i=0;attrs[i];i++) {
- struct ldb_message_element *el;
-
- if (strcmp(attrs[i], "*") == 0) {
- if (msg_add_all_elements(module, ret, msg) != 0) {
- talloc_free(ret);
- return NULL;
- }
- continue;
- }
-
- if (ldb_attr_cmp(attrs[i], "distinguishedName") == 0) {
- if (msg_add_distinguished_name(ret) != 0) {
- return NULL;
- }
- continue;
- }
-
- el = ldb_msg_find_element(msg, attrs[i]);
- if (!el) {
- continue;
- }
- if (msg_add_element(ret, el, 1) != 0) {
- talloc_free(ret);
- return NULL;
- }
- }
-
- return ret;
-}
-
/*
search the database for a single simple dn.
return LDB_ERR_NO_SUCH_OBJECT on record-not-found
return LDB_SUCCESS;
}
-/*
- add a set of attributes from a record to a set of results
- return 0 on success, -1 on failure
-*/
-int ltdb_add_attr_results(struct ldb_module *module,
- TALLOC_CTX *mem_ctx,
- struct ldb_message *msg,
- const char * const attrs[],
- unsigned int *count,
- struct ldb_message ***res)
-{
- struct ldb_message *msg2;
- struct ldb_message **res2;
-
- /* pull the attributes that the user wants */
- msg2 = ltdb_pull_attrs(module, mem_ctx, msg, attrs);
- if (!msg2) {
- return -1;
- }
-
- /* add to the results list */
- res2 = talloc_realloc(mem_ctx, *res, struct ldb_message *, (*count)+2);
- if (!res2) {
- talloc_free(msg2);
- return -1;
- }
-
- (*res) = res2;
-
- (*res)[*count] = talloc_move(*res, &msg2);
- (*res)[(*count)+1] = NULL;
- (*count)++;
-
- return 0;
-}
-
-
-
/*
filter the specified list of attributes from a message
removing not requested attrs from the new message constructed.
void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
unsigned int unpack_flags);
-int ltdb_add_attr_results(struct ldb_module *module,
- TALLOC_CTX *mem_ctx,
- struct ldb_message *msg,
- const char * const attrs[],
- unsigned int *count,
- struct ldb_message ***res);
int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
const struct ldb_message *msg, const char * const *attrs,
struct ldb_message **filtered_msg);