summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_map
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2009-01-29 18:39:30 -0500
committerSimo Sorce <idra@samba.org>2009-01-30 01:02:03 -0500
commit380874ef863866c94c999ef53252b9d30df65e88 (patch)
treeaafdb720253d5a6013e2a23a0e81b0a9b90f054b /source4/lib/ldb/ldb_map
parenta5f0640bf99e6f7e38b0b1e7a7a56f8f58ec7e47 (diff)
downloadsamba-380874ef863866c94c999ef53252b9d30df65e88.tar.gz
samba-380874ef863866c94c999ef53252b9d30df65e88.tar.bz2
samba-380874ef863866c94c999ef53252b9d30df65e88.zip
Fix the mess with ldb includes.
Separate again the public from the private headers. Add a new header specific for modules. Also add service function for modules as now ldb_context and ldb_module are opaque structures for them.
Diffstat (limited to 'source4/lib/ldb/ldb_map')
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map.c83
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map_inbound.c72
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map_outbound.c33
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map_private.h2
4 files changed, 137 insertions, 53 deletions
diff --git a/source4/lib/ldb/ldb_map/ldb_map.c b/source4/lib/ldb/ldb_map/ldb_map.c
index 72d8378a07..ea2bfd1dc1 100644
--- a/source4/lib/ldb/ldb_map/ldb_map.c
+++ b/source4/lib/ldb/ldb_map/ldb_map.c
@@ -35,7 +35,7 @@
* Author: Jelmer Vernooij, Martin Kuehl
*/
-#include "ldb_includes.h"
+#include "ldb_module.h"
#include "ldb_map.h"
#include "ldb_map_private.h"
@@ -102,7 +102,7 @@
/* Extract mappings from private data. */
const struct ldb_map_context *map_get_context(struct ldb_module *module)
{
- const struct map_private *data = talloc_get_type(module->private_data, struct map_private);
+ const struct map_private *data = talloc_get_type(ldb_module_get_private(module), struct map_private);
return data->context;
}
@@ -110,11 +110,14 @@ const struct ldb_map_context *map_get_context(struct ldb_module *module)
struct map_context *map_init_context(struct ldb_module *module,
struct ldb_request *req)
{
+ struct ldb_context *ldb;
struct map_context *ac;
+ ldb = ldb_module_get_ctx(module);
+
ac = talloc_zero(req, struct map_context);
if (ac == NULL) {
- ldb_set_errstring(module->ldb, "Out of Memory");
+ ldb_set_errstring(ldb, "Out of Memory");
return NULL;
}
@@ -202,8 +205,11 @@ static struct ldb_dn *ldb_dn_rebase_remote(void *mem_ctx, const struct ldb_map_c
int ldb_next_remote_request(struct ldb_module *module, struct ldb_request *request)
{
const struct ldb_map_context *data = map_get_context(module);
+ struct ldb_context *ldb;
struct ldb_message *msg;
+ ldb = ldb_module_get_ctx(module);
+
switch (request->operation) {
case LDB_SEARCH:
if (request->op.search.base) {
@@ -236,7 +242,7 @@ int ldb_next_remote_request(struct ldb_module *module, struct ldb_request *reque
break;
default:
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"Invalid remote request!\n");
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -462,6 +468,7 @@ bool ldb_dn_check_local(struct ldb_module *module, struct ldb_dn *dn)
struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn)
{
const struct ldb_map_context *data = map_get_context(module);
+ struct ldb_context *ldb;
struct ldb_dn *newdn;
const struct ldb_map_attribute *map;
enum ldb_map_attr_type map_type;
@@ -473,6 +480,8 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct
return NULL;
}
+ ldb = ldb_module_get_ctx(module);
+
newdn = ldb_dn_copy(mem_ctx, dn);
if (newdn == NULL) {
map_oom(module);
@@ -493,14 +502,14 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct
switch (map_type) {
case MAP_IGNORE:
case MAP_GENERATE:
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
"used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
case MAP_CONVERT:
if (map->u.convert.convert_local == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"'convert_local' not set for attribute '%s' "
"used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
@@ -534,6 +543,7 @@ failed:
struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn)
{
const struct ldb_map_context *data = map_get_context(module);
+ struct ldb_context *ldb;
struct ldb_dn *newdn;
const struct ldb_map_attribute *map;
enum ldb_map_attr_type map_type;
@@ -545,6 +555,8 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struc
return NULL;
}
+ ldb = ldb_module_get_ctx(module);
+
newdn = ldb_dn_copy(mem_ctx, dn);
if (newdn == NULL) {
map_oom(module);
@@ -565,14 +577,14 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struc
switch (map_type) {
case MAP_IGNORE:
case MAP_GENERATE:
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
"used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
case MAP_CONVERT:
if (map->u.convert.convert_remote == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"'convert_remote' not set for attribute '%s' "
"used in DN!\n", ldb_dn_get_component_name(dn, i));
goto failed;
@@ -623,10 +635,13 @@ struct ldb_dn *ldb_dn_map_rebase_remote(struct ldb_module *module, void *mem_ctx
/* Map a DN contained in an ldb value into the remote partition. */
static struct ldb_val ldb_dn_convert_local(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val)
{
+ struct ldb_context *ldb;
struct ldb_dn *dn, *newdn;
struct ldb_val newval;
- dn = ldb_dn_from_ldb_val(mem_ctx, module->ldb, val);
+ ldb = ldb_module_get_ctx(module);
+
+ dn = ldb_dn_from_ldb_val(mem_ctx, ldb, val);
if (! ldb_dn_validate(dn)) {
newval.length = 0;
newval.data = NULL;
@@ -649,10 +664,13 @@ static struct ldb_val ldb_dn_convert_local(struct ldb_module *module, void *mem_
/* Map a DN contained in an ldb value into the local partition. */
static struct ldb_val ldb_dn_convert_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val)
{
+ struct ldb_context *ldb;
struct ldb_dn *dn, *newdn;
struct ldb_val newval;
- dn = ldb_dn_from_ldb_val(mem_ctx, module->ldb, val);
+ ldb = ldb_module_get_ctx(module);
+
+ dn = ldb_dn_from_ldb_val(mem_ctx, ldb, val);
if (! ldb_dn_validate(dn)) {
newval.length = 0;
newval.data = NULL;
@@ -693,11 +711,14 @@ static struct ldb_val map_objectclass_convert_local(struct ldb_module *module, v
static void map_objectclass_generate_remote(struct ldb_module *module, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local)
{
const struct ldb_map_context *data = map_get_context(module);
+ struct ldb_context *ldb;
struct ldb_message_element *el, *oc;
struct ldb_val val;
bool found_extensibleObject = false;
int i;
+ ldb = ldb_module_get_ctx(module);
+
/* Find old local objectClass */
oc = ldb_msg_find_element(old, "objectClass");
if (oc == NULL) {
@@ -707,7 +728,7 @@ static void map_objectclass_generate_remote(struct ldb_module *module, const cha
/* Prepare new element */
el = talloc_zero(remote, struct ldb_message_element);
if (el == NULL) {
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return; /* TODO: fail? */
}
@@ -716,7 +737,7 @@ static void map_objectclass_generate_remote(struct ldb_module *module, const cha
el->values = talloc_array(el, struct ldb_val, el->num_values);
if (el->values == NULL) {
talloc_free(el);
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return; /* TODO: fail? */
}
@@ -766,10 +787,13 @@ static struct ldb_val map_objectclass_convert_remote(struct ldb_module *module,
static struct ldb_message_element *map_objectclass_generate_local(struct ldb_module *module, void *mem_ctx, const char *local_attr, const struct ldb_message *remote)
{
const struct ldb_map_context *data = map_get_context(module);
+ struct ldb_context *ldb;
struct ldb_message_element *el, *oc;
struct ldb_val val;
int i;
+ ldb = ldb_module_get_ctx(module);
+
/* Find old remote objectClass */
oc = ldb_msg_find_element(remote, "objectClass");
if (oc == NULL) {
@@ -779,7 +803,7 @@ static struct ldb_message_element *map_objectclass_generate_local(struct ldb_mod
/* Prepare new element */
el = talloc_zero(mem_ctx, struct ldb_message_element);
if (el == NULL) {
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return NULL;
}
@@ -788,7 +812,7 @@ static struct ldb_message_element *map_objectclass_generate_local(struct ldb_mod
el->values = talloc_array(el, struct ldb_val, el->num_values);
if (el->values == NULL) {
talloc_free(el);
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return NULL;
}
@@ -809,7 +833,7 @@ static struct ldb_message_element *map_objectclass_generate_local(struct ldb_mod
el->values = talloc_realloc(el, el->values, struct ldb_val, el->num_values);
if (el->values == NULL) {
talloc_free(el);
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return NULL;
}
}
@@ -847,9 +871,12 @@ static int map_objectclass_convert_operator(struct ldb_module *module, void *mem
struct ldb_request *map_search_base_req(struct map_context *ac, struct ldb_dn *dn, const char * const *attrs, const struct ldb_parse_tree *tree, void *context, ldb_map_callback_t callback)
{
const struct ldb_parse_tree *search_tree;
+ struct ldb_context *ldb;
struct ldb_request *req;
int ret;
+ ldb = ldb_module_get_ctx(ac->module);
+
if (tree) {
search_tree = tree;
} else {
@@ -859,7 +886,7 @@ struct ldb_request *map_search_base_req(struct map_context *ac, struct ldb_dn *d
}
}
- ret = ldb_build_search_req_ex(&req, ac->module->ldb, ac,
+ ret = ldb_build_search_req_ex(&req, ldb, ac,
dn, LDB_SCOPE_BASE,
search_tree, attrs,
NULL,
@@ -879,11 +906,14 @@ struct ldb_request *map_build_fixup_req(struct map_context *ac,
void *context,
ldb_map_callback_t callback)
{
+ struct ldb_context *ldb;
struct ldb_request *req;
struct ldb_message *msg;
const char *dn;
int ret;
+ ldb = ldb_module_get_ctx(ac->module);
+
/* Prepare message */
msg = ldb_msg_new(ac);
if (msg == NULL) {
@@ -905,7 +935,7 @@ struct ldb_request *map_build_fixup_req(struct map_context *ac,
}
/* Prepare request */
- ret = ldb_build_mod_req(&req, ac->module->ldb,
+ ret = ldb_build_mod_req(&req, ldb,
ac, msg, NULL,
context, callback,
ac->req);
@@ -961,6 +991,7 @@ static const struct ldb_map_attribute objectclass_attribute_map = {
static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data, const char *name)
{
static const char * const attrs[] = { MAP_DN_FROM, MAP_DN_TO, NULL };
+ struct ldb_context *ldb;
struct ldb_dn *dn;
struct ldb_message *msg;
struct ldb_result *res;
@@ -972,34 +1003,36 @@ static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data,
return LDB_SUCCESS;
}
- dn = ldb_dn_new_fmt(data, module->ldb, "%s=%s", MAP_DN_NAME, name);
+ ldb = ldb_module_get_ctx(module);
+
+ dn = ldb_dn_new_fmt(data, ldb, "%s=%s", MAP_DN_NAME, name);
if ( ! ldb_dn_validate(dn)) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"Failed to construct '%s' DN!\n", MAP_DN_NAME);
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ldb_search(module->ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
+ ret = ldb_search(ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
talloc_free(dn);
if (ret != LDB_SUCCESS) {
return ret;
}
if (res->count == 0) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"No results for '%s=%s'!\n", MAP_DN_NAME, name);
talloc_free(res);
return LDB_ERR_CONSTRAINT_VIOLATION;
}
if (res->count > 1) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"Too many results for '%s=%s'!\n", MAP_DN_NAME, name);
talloc_free(res);
return LDB_ERR_CONSTRAINT_VIOLATION;
}
msg = res->msgs[0];
- data->local_base_dn = ldb_msg_find_attr_as_dn(module->ldb, data, msg, MAP_DN_FROM);
- data->remote_base_dn = ldb_msg_find_attr_as_dn(module->ldb, data, msg, MAP_DN_TO);
+ data->local_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_FROM);
+ data->remote_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_TO);
talloc_free(res);
return LDB_SUCCESS;
@@ -1075,7 +1108,7 @@ _PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attrib
return LDB_ERR_OPERATIONS_ERROR;
}
- module->private_data = data;
+ ldb_module_set_private(module, data);
data->context = talloc_zero(data, struct ldb_map_context);
if (!data->context) {
diff --git a/source4/lib/ldb/ldb_map/ldb_map_inbound.c b/source4/lib/ldb/ldb_map/ldb_map_inbound.c
index 96605f23eb..e915a5f46a 100644
--- a/source4/lib/ldb/ldb_map/ldb_map_inbound.c
+++ b/source4/lib/ldb/ldb_map/ldb_map_inbound.c
@@ -24,7 +24,7 @@
*/
-#include "ldb_includes.h"
+#include "ldb_module.h"
#include "ldb_map.h"
#include "ldb_map_private.h"
@@ -69,10 +69,11 @@ static int ldb_msg_el_partition(struct ldb_module *module, struct ldb_message *l
const struct ldb_map_context *data = map_get_context(module);
const struct ldb_map_attribute *map = map_attr_find_local(data, attr_name);
struct ldb_message_element *el=NULL;
+ struct ldb_context *ldb = ldb_module_get_ctx(module);
/* Unknown attribute: ignore */
if (map == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: "
"Not mapping attribute '%s': no mapping found\n",
old->name);
goto local;
@@ -84,7 +85,7 @@ static int ldb_msg_el_partition(struct ldb_module *module, struct ldb_message *l
case MAP_CONVERT:
if (map->u.convert.convert_local == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: "
"Not mapping attribute '%s': "
"'convert_local' not set\n",
map->local_name);
@@ -98,7 +99,7 @@ static int ldb_msg_el_partition(struct ldb_module *module, struct ldb_message *l
case MAP_GENERATE:
if (map->u.generate.generate_remote == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: "
"Not mapping attribute '%s': "
"'generate_remote' not set\n",
map->local_name);
@@ -158,12 +159,15 @@ static bool ldb_msg_check_remote(struct ldb_module *module, const struct ldb_mes
static int ldb_msg_partition(struct ldb_module *module, struct ldb_message *local, struct ldb_message *remote, const struct ldb_message *msg)
{
/* const char * const names[]; */
+ struct ldb_context *ldb;
int i, ret;
+ ldb = ldb_module_get_ctx(module);
+
for (i = 0; i < msg->num_elements; i++) {
/* Skip 'IS_MAPPED' */
if (ldb_attr_cmp(msg->elements[i].name, IS_MAPPED) == 0) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: "
"Skipping attribute '%s'\n",
msg->elements[i].name);
continue;
@@ -195,10 +199,12 @@ static int map_rename_local_callback(struct ldb_request *req,
/* Store the DN of a single search result in context. */
static int map_search_self_callback(struct ldb_request *req, struct ldb_reply *ares)
{
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
ac = talloc_get_type(req->context, struct map_context);
+ ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
@@ -214,7 +220,7 @@ static int map_search_self_callback(struct ldb_request *req, struct ldb_reply *a
case LDB_REPLY_ENTRY:
/* We have already found a remote DN */
if (ac->local_dn) {
- ldb_set_errstring(ac->module->ldb,
+ ldb_set_errstring(ldb,
"Too many results!");
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
@@ -284,10 +290,12 @@ static int map_search_self_req(struct ldb_request **req,
static int map_op_local_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
ac = talloc_get_type(req->context, struct map_context);
+ ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
@@ -299,7 +307,7 @@ static int map_op_local_callback(struct ldb_request *req,
}
if (ares->type != LDB_REPLY_DONE) {
- ldb_set_errstring(req->handle->ldb, "Invalid reply type!");
+ ldb_set_errstring(ldb, "Invalid reply type!");
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
@@ -317,9 +325,11 @@ static int map_op_local_callback(struct ldb_request *req,
static int map_op_remote_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
+ struct ldb_context *ldb;
struct map_context *ac;
ac = talloc_get_type(req->context, struct map_context);
+ ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
@@ -331,7 +341,7 @@ static int map_op_remote_callback(struct ldb_request *req,
}
if (ares->type != LDB_REPLY_DONE) {
- ldb_set_errstring(req->handle->ldb, "Invalid reply type!");
+ ldb_set_errstring(ldb, "Invalid reply type!");
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
@@ -350,11 +360,14 @@ static int map_op_remote_callback(struct ldb_request *req,
int map_add(struct ldb_module *module, struct ldb_request *req)
{
const struct ldb_message *msg = req->op.add.message;
+ struct ldb_context *ldb;
struct map_context *ac;
struct ldb_message *remote_msg;
const char *dn;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
/* Do not manipulate our control entries */
if (ldb_dn_is_special(msg->dn)) {
return ldb_next_request(module, req);
@@ -397,7 +410,7 @@ int map_add(struct ldb_module *module, struct ldb_request *req)
ldb_msg_partition(module, ac->local_msg, remote_msg, msg);
/* Prepare the remote operation */
- ret = ldb_build_add_req(&ac->remote_req, module->ldb,
+ ret = ldb_build_add_req(&ac->remote_req, ldb,
ac, remote_msg,
req->controls,
ac, map_op_remote_callback,
@@ -426,10 +439,13 @@ int map_add(struct ldb_module *module, struct ldb_request *req)
static int map_add_do_local(struct map_context *ac)
{
struct ldb_request *local_req;
+ struct ldb_context *ldb;
int ret;
+ ldb = ldb_module_get_ctx(ac->module);
+
/* Prepare the local operation */
- ret = ldb_build_add_req(&local_req, ac->module->ldb, ac,
+ ret = ldb_build_add_req(&local_req, ldb, ac,
ac->local_msg,
ac->req->controls,
ac,
@@ -451,9 +467,12 @@ int map_modify(struct ldb_module *module, struct ldb_request *req)
const struct ldb_message *msg = req->op.mod.message;
struct ldb_request *search_req;
struct ldb_message *remote_msg;
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
/* Do not manipulate our control entries */
if (ldb_dn_is_special(msg->dn)) {
return ldb_next_request(module, req);
@@ -498,7 +517,7 @@ int map_modify(struct ldb_module *module, struct ldb_request *req)
ldb_msg_partition(module, ac->local_msg, remote_msg, msg);
/* Prepare the remote operation */
- ret = ldb_build_mod_req(&ac->remote_req, module->ldb,
+ ret = ldb_build_mod_req(&ac->remote_req, ldb,
ac, remote_msg,
req->controls,
ac, map_op_remote_callback,
@@ -526,9 +545,12 @@ int map_modify(struct ldb_module *module, struct ldb_request *req)
static int map_modify_do_local(struct map_context *ac)
{
struct ldb_request *local_req;
+ struct ldb_context *ldb;
char *dn;
int ret;
+ ldb = ldb_module_get_ctx(ac->module);
+
if (ac->local_dn == NULL) {
/* No local record present, add it instead */
/* Add local 'IS_MAPPED' */
@@ -544,7 +566,7 @@ static int map_modify_do_local(struct map_context *ac)
}
/* Prepare the local operation */
- ret = ldb_build_add_req(&local_req, ac->module->ldb, ac,
+ ret = ldb_build_add_req(&local_req, ldb, ac,
ac->local_msg,
ac->req->controls,
ac,
@@ -555,7 +577,7 @@ static int map_modify_do_local(struct map_context *ac)
}
} else {
/* Prepare the local operation */
- ret = ldb_build_mod_req(&local_req, ac->module->ldb, ac,
+ ret = ldb_build_mod_req(&local_req, ldb, ac,
ac->local_msg,
ac->req->controls,
ac,
@@ -577,9 +599,12 @@ static int map_modify_do_local(struct map_context *ac)
int map_delete(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_request *search_req;
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
/* Do not manipulate our control entries */
if (ldb_dn_is_special(req->op.del.dn)) {
return ldb_next_request(module, req);
@@ -598,7 +623,7 @@ int map_delete(struct ldb_module *module, struct ldb_request *req)
}
/* Prepare the remote operation */
- ret = ldb_build_del_req(&ac->remote_req, module->ldb, ac,
+ ret = ldb_build_del_req(&ac->remote_req, ldb, ac,
ldb_dn_map_local(module, ac, req->op.del.dn),
req->controls,
ac,
@@ -628,8 +653,11 @@ int map_delete(struct ldb_module *module, struct ldb_request *req)
static int map_delete_do_local(struct map_context *ac)
{
struct ldb_request *local_req;
+ struct ldb_context *ldb;
int ret;
+ ldb = ldb_module_get_ctx(ac->module);
+
/* No local record, continue remotely */
if (ac->local_dn == NULL) {
/* Do the remote request. */
@@ -637,7 +665,7 @@ static int map_delete_do_local(struct map_context *ac)
}
/* Prepare the local operation */
- ret = ldb_build_del_req(&local_req, ac->module->ldb, ac,
+ ret = ldb_build_del_req(&local_req, ldb, ac,
ac->req->op.del.dn,
ac->req->controls,
ac,
@@ -657,9 +685,12 @@ static int map_delete_do_local(struct map_context *ac)
int map_rename(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_request *search_req;
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
/* Do not manipulate our control entries */
if (ldb_dn_is_special(req->op.rename.olddn)) {
return ldb_next_request(module, req);
@@ -685,7 +716,7 @@ int map_rename(struct ldb_module *module, struct ldb_request *req)
}
/* Prepare the remote operation */
- ret = ldb_build_rename_req(&ac->remote_req, module->ldb, ac,
+ ret = ldb_build_rename_req(&ac->remote_req, ldb, ac,
ldb_dn_map_local(module, ac, req->op.rename.olddn),
ldb_dn_map_local(module, ac, req->op.rename.newdn),
req->controls,
@@ -715,8 +746,11 @@ int map_rename(struct ldb_module *module, struct ldb_request *req)
static int map_rename_do_local(struct map_context *ac)
{
struct ldb_request *local_req;
+ struct ldb_context *ldb;
int ret;
+ ldb = ldb_module_get_ctx(ac->module);
+
/* No local record, continue remotely */
if (ac->local_dn == NULL) {
/* Do the remote request. */
@@ -724,7 +758,7 @@ static int map_rename_do_local(struct map_context *ac)
}
/* Prepare the local operation */
- ret = ldb_build_rename_req(&local_req, ac->module->ldb, ac,
+ ret = ldb_build_rename_req(&local_req, ldb, ac,
ac->req->op.rename.olddn,
ac->req->op.rename.newdn,
ac->req->controls,
@@ -741,10 +775,12 @@ static int map_rename_do_local(struct map_context *ac)
static int map_rename_local_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
ac = talloc_get_type(req->context, struct map_context);
+ ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
@@ -756,7 +792,7 @@ static int map_rename_local_callback(struct ldb_request *req,
}
if (ares->type != LDB_REPLY_DONE) {
- ldb_set_errstring(req->handle->ldb, "Invalid reply type!");
+ ldb_set_errstring(ldb, "Invalid reply type!");
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
diff --git a/source4/lib/ldb/ldb_map/ldb_map_outbound.c b/source4/lib/ldb/ldb_map/ldb_map_outbound.c
index 5588eaaf46..327fa92f8d 100644
--- a/source4/lib/ldb/ldb_map/ldb_map_outbound.c
+++ b/source4/lib/ldb/ldb_map/ldb_map_outbound.c
@@ -25,7 +25,7 @@
*/
-#include "ldb_includes.h"
+#include "ldb_module.h"
#include "ldb_map.h"
#include "ldb_map_private.h"
@@ -264,6 +264,9 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local
const struct ldb_map_attribute *map;
struct ldb_message_element *old, *el=NULL;
const char *remote_name = NULL;
+ struct ldb_context *ldb;
+
+ ldb = ldb_module_get_ctx(module);
/* We handle wildcards in ldb_msg_el_merge_wildcard */
if (ldb_attr_cmp(attr_name, "*") == 0) {
@@ -300,7 +303,7 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local
case MAP_CONVERT:
if (map->u.convert.convert_remote == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"Skipping attribute '%s': "
"'convert_remote' not set\n",
attr_name);
@@ -319,7 +322,7 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local
case MAP_GENERATE:
if (map->u.generate.generate_local == NULL) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
"Skipping attribute '%s': "
"'generate_local' not set\n",
attr_name);
@@ -869,6 +872,9 @@ static int map_subtree_collect_remote(struct ldb_module *module, void *mem_ctx,
{
const struct ldb_map_context *data = map_get_context(module);
const struct ldb_map_attribute *map;
+ struct ldb_context *ldb;
+
+ ldb = ldb_module_get_ctx(module);
if (tree == NULL) {
return 0;
@@ -893,7 +899,7 @@ static int map_subtree_collect_remote(struct ldb_module *module, void *mem_ctx,
}
if (map->type == MAP_GENERATE) {
- ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: "
"Skipping attribute '%s': "
"'convert_operator' not set\n",
tree->u.equality.attr);
@@ -1045,14 +1051,17 @@ int map_return_entry(struct map_context *ac, struct ldb_reply *ares)
{
struct ldb_message_element *el;
const char * const *attrs;
+ struct ldb_context *ldb;
int i;
+ ldb = ldb_module_get_ctx(ac->module);
+
/* Merged result doesn't match original query, skip */
- if (!ldb_match_msg(ac->module->ldb, ares->message,
+ if (!ldb_match_msg(ldb, ares->message,
ac->req->op.search.tree,
ac->req->op.search.base,
ac->req->op.search.scope)) {
- ldb_debug(ac->module->ldb, LDB_DEBUG_TRACE, "ldb_map: "
+ ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_map: "
"Skipping record '%s': "
"doesn't match original search\n",
ldb_dn_get_linearized(ares->message->dn));
@@ -1086,13 +1095,17 @@ int map_search(struct ldb_module *module, struct ldb_request *req)
struct ldb_parse_tree *remote_tree;
struct ldb_parse_tree *local_tree;
struct ldb_request *remote_req;
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
const char *wildcard[] = { "*", NULL };
const char * const *attrs;
- if (!module->private_data) /* if we're not yet initialized, go to the next module */
+ ldb = ldb_module_get_ctx(module);
+
+ /* if we're not yet initialized, go to the next module */
+ if (!ldb_module_get_private(module))
return ldb_next_request(module, req);
/* Do not manipulate our control entries */
@@ -1165,7 +1178,7 @@ int map_search(struct ldb_module *module, struct ldb_request *req)
ac->local_tree = local_tree;
/* Prepare the remote operation */
- ret = ldb_build_search_req_ex(&remote_req, module->ldb, ac,
+ ret = ldb_build_search_req_ex(&remote_req, ldb, ac,
req->op.search.base,
req->op.search.scope,
remote_tree,
@@ -1282,10 +1295,12 @@ static int map_search_local(struct map_context *ac)
/* Merge the remote and local parts of a search result. */
int map_local_merge_callback(struct ldb_request *req, struct ldb_reply *ares)
{
+ struct ldb_context *ldb;
struct map_context *ac;
int ret;
ac = talloc_get_type(req->context, struct map_context);
+ ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
@@ -1301,7 +1316,7 @@ int map_local_merge_callback(struct ldb_request *req, struct ldb_reply *ares)
/* We have already found a local record */
if (ac->r_current->local) {
talloc_free(ares);
- ldb_set_errstring(ac->module->ldb, "ldb_map: Too many results!");
+ ldb_set_errstring(ldb, "ldb_map: Too many results!");
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
diff --git a/source4/lib/ldb/ldb_map/ldb_map_private.h b/source4/lib/ldb/ldb_map/ldb_map_private.h
index 0543ba71b9..0c46443253 100644
--- a/source4/lib/ldb/ldb_map/ldb_map_private.h
+++ b/source4/lib/ldb/ldb_map/ldb_map_private.h
@@ -1,6 +1,6 @@
/* A handy macro to report Out of Memory conditions */
-#define map_oom(module) ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory"));
+#define map_oom(module) ldb_set_errstring(ldb_module_get_ctx(module), talloc_asprintf(module, "Out of Memory"));
/* The type of search callback functions */
typedef int (*ldb_map_callback_t)(struct ldb_request *, struct ldb_reply *);