From 0fa924bb8f446e35a0fd543cda20b23c81e7dc9e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 13 Oct 2005 05:04:16 +0000 Subject: r10954: added support for canonicalName in the operational module, using the dn->canonicalName function abartlet just committed (This used to be commit 197e8a27f0557869eacd17b74e1b14e0665883b1) --- source4/lib/ldb/common/ldb_msg.c | 13 ++++ source4/lib/ldb/include/ldb.h | 1 + source4/lib/ldb/modules/operational.c | 112 ++++++++++++++++++++++++---------- 3 files changed, 94 insertions(+), 32 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 977f68144b..f4a49e47ce 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -617,6 +617,19 @@ int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *rep } +/* + remove the specified attribute in a search result +*/ +void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr) +{ + struct ldb_message_element *el = ldb_msg_find_element(msg, attr); + int n = (el - msg->elements); + if (n != msg->num_elements-1) { + memmove(el, el+1, ((msg->num_elements-1) - n)*sizeof(*el)); + } + msg->num_elements--; +} + /* return a LDAP formatted time string */ diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 27313613ab..c26229678e 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -498,6 +498,7 @@ void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree, int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace); int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace); +void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr); char *ldb_timestring(void *mem_ctx, time_t t); time_t ldb_string_to_time(const char *s); diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index c40936df07..8a06e20c29 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -79,6 +79,19 @@ #include "ldb/include/ldb_private.h" #include +/* + construct a canonical name from a message +*/ +static int construct_canonical_name(struct ldb_module *module, struct ldb_message *msg) +{ + char *canonicalName; + canonicalName = ldb_dn_canonical_string(msg, msg->dn); + if (canonicalName == NULL) { + return -1; + } + return ldb_msg_add_string(msg, "canonicalName", canonicalName); +} + /* a list of attribute names that should be substituted in the parse tree before the search is done @@ -91,6 +104,7 @@ static const struct { { "modifyTimestamp", "whenChanged" } }; + /* a list of attribute names that are hidden, but can be searched for using another (non-hidden) name to produce the correct result @@ -98,12 +112,65 @@ static const struct { static const struct { const char *attr; const char *replace; + int (*constructor)(struct ldb_module *, struct ldb_message *); } search_sub[] = { - { "createTimestamp", "whenCreated" }, - { "modifyTimestamp", "whenChanged" }, - { "structuralObjectClass", "objectClass" } + { "createTimestamp", "whenCreated", NULL }, + { "modifyTimestamp", "whenChanged", NULL }, + { "structuralObjectClass", "objectClass", NULL }, + { "canonicalName", "distinguishedName", construct_canonical_name } }; +/* + post process a search result record. For any search_sub[] attributes that were + asked for, we need to call the appropriate copy routine to copy the result + into the message, then remove any attributes that we added to the search but were + not asked for by the user +*/ +static int operational_search_post_process(struct ldb_module *module, + struct ldb_message *msg, + const char * const *attrs) +{ + int i, a=0; + + for (a=0;attrs && attrs[a];a++) { + for (i=0;ildb, LDB_DEBUG_WARNING, + "operational_search_post_process failed for attribute '%s'\n", + attrs[a]); + return -1; +} + /* hook search operations */ @@ -131,13 +198,14 @@ static int operational_search_bytree(struct ldb_module *module, /* in the list of attributes we are looking for, rename any attributes to the alias for any hidden attributes that can be fetched directly using non-hidden names */ - for (i=0;ildb); -- cgit