From 0a4b0580d8f5de1733ea065553992edfcb793de5 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 17 May 2011 10:20:04 +0200 Subject: Generic dereference data structures and utilities These will be shared by both dereference methods in a later patch. --- src/providers/ldap/sdap.h | 10 ++++++++++ src/providers/ldap/sdap_async.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h index c00b3d3e6..cef2d23ae 100644 --- a/src/providers/ldap/sdap.h +++ b/src/providers/ldap/sdap.h @@ -305,6 +305,16 @@ struct sdap_server_opts { struct sdap_id_ctx; +struct sdap_attr_map_info { + struct sdap_attr_map *map; + int num_attrs; +}; + +struct sdap_deref_attrs { + struct sdap_attr_map *map; + struct sysdb_attrs *attrs; +}; + int sdap_get_map(TALLOC_CTX *memctx, struct confdb_ctx *cdb, const char *conf_path, diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c index 7c7e2699a..94ffcc392 100644 --- a/src/providers/ldap/sdap_async.c +++ b/src/providers/ldap/sdap_async.c @@ -821,6 +821,41 @@ static errno_t add_to_reply(TALLOC_CTX *mem_ctx, return EOK; } +struct sdap_deref_reply { + size_t reply_max; + size_t reply_count; + struct sdap_deref_attrs **reply; +}; + +static errno_t add_to_deref_reply(TALLOC_CTX *mem_ctx, + int num_maps, + struct sdap_deref_reply *dreply, + struct sdap_deref_attrs **res) +{ + int i; + + for (i=0; i < num_maps; i++) { + if (res[i]->attrs == NULL) continue; /* Nothing in this map */ + + if (dreply->reply == NULL || + dreply->reply_max == dreply->reply_count) { + dreply->reply_max += REPLY_REALLOC_INCREMENT; + dreply->reply = talloc_realloc(mem_ctx, dreply->reply, + struct sdap_deref_attrs *, + dreply->reply_max); + if (dreply->reply == NULL) { + DEBUG(1, ("talloc_realloc failed.\n")); + return ENOMEM; + } + } + + dreply->reply[dreply->reply_count++] = + talloc_steal(dreply->reply, res[i]); + } + + return EOK; +} + /* ==Generic Search exposing all options======================= */ typedef errno_t (*sdap_parse_cb)(struct sdap_handle *sh, struct sdap_msg *msg, -- cgit