summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb/ldb_modules/extended_dn.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules/extended_dn.c')
-rw-r--r--source4/dsdb/samdb/ldb_modules/extended_dn.c143
1 files changed, 69 insertions, 74 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn.c b/source4/dsdb/samdb/ldb_modules/extended_dn.c
index 84bf5e4843..e40190e86f 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn.c
@@ -1,7 +1,7 @@
/*
ldb database library
- Copyright (C) Simo Sorce 2005
+ Copyright (C) Simo Sorce 2005-2008
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
@@ -95,7 +95,7 @@ static bool add_attrs(void *mem_ctx, char ***attrs, const char *attr)
return true;
}
-static bool inject_extended_dn(struct ldb_message *msg,
+static int inject_extended_dn(struct ldb_message *msg,
struct ldb_context *ldb,
int type,
bool remove_guid,
@@ -113,8 +113,9 @@ static bool inject_extended_dn(struct ldb_message *msg,
guid_blob = ldb_msg_find_ldb_val(msg, "objectGUID");
sid_blob = ldb_msg_find_ldb_val(msg, "objectSID");
- if (!guid_blob)
- return false;
+ if (!guid_blob) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
switch (type) {
case 0:
@@ -123,7 +124,7 @@ static bool inject_extended_dn(struct ldb_message *msg,
const char *lower_guid_hex = strlower_talloc(msg, data_blob_hex_string(msg, guid_blob));
const char *lower_sid_hex = strlower_talloc(msg, data_blob_hex_string(msg, sid_blob));
if (!lower_guid_hex || !lower_sid_hex) {
- return false;
+ return LDB_ERR_OPERATIONS_ERROR;
}
new_dn = talloc_asprintf(msg, "<GUID=%s>;<SID=%s>;%s",
lower_guid_hex,
@@ -132,7 +133,7 @@ static bool inject_extended_dn(struct ldb_message *msg,
} else {
const char *lower_guid_hex = strlower_talloc(msg, data_blob_hex_string(msg, guid_blob));
if (!lower_guid_hex) {
- return false;
+ return LDB_ERR_OPERATIONS_ERROR;
}
new_dn = talloc_asprintf(msg, "<GUID=%s>;%s",
lower_guid_hex,
@@ -151,8 +152,8 @@ static bool inject_extended_dn(struct ldb_message *msg,
if (sid) {
object_sid = dom_sid_string(msg, sid);
if (!object_sid)
- return false;
-
+ return LDB_ERR_OPERATIONS_ERROR;
+
}
/* Normal, sane format */
@@ -167,11 +168,11 @@ static bool inject_extended_dn(struct ldb_message *msg,
}
break;
default:
- return false;
+ return LDB_ERR_OPERATIONS_ERROR;
}
if (!new_dn) {
- return false;
+ return LDB_ERR_OPERATIONS_ERROR;
}
if (remove_guid) {
@@ -184,52 +185,70 @@ static bool inject_extended_dn(struct ldb_message *msg,
msg->dn = ldb_dn_new(msg, ldb, new_dn);
if (! ldb_dn_validate(msg->dn))
- return false;
+ return LDB_ERR_OPERATIONS_ERROR;
val = ldb_msg_find_ldb_val(msg, "distinguishedName");
if (val) {
ldb_msg_remove_attr(msg, "distinguishedName");
if (ldb_msg_add_steal_string(msg, "distinguishedName", new_dn))
- return false;
+ return LDB_ERR_OPERATIONS_ERROR;
}
- return true;
+ return LDB_SUCCESS;
}
/* search */
struct extended_context {
struct ldb_module *module;
- void *up_context;
- int (*up_callback)(struct ldb_context *, void *, struct ldb_reply *);
+ struct ldb_request *req;
- const char * const *attrs;
bool remove_guid;
bool remove_sid;
int extended_type;
};
-static int extended_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
+static int extended_callback(struct ldb_request *req, struct ldb_reply *ares)
{
struct extended_context *ac;
+ int ret;
- ac = talloc_get_type(context, struct extended_context);
+ ac = talloc_get_type(req->context, struct extended_context);
- if (ares->type == LDB_REPLY_ENTRY) {
+ if (!ares) {
+ return ldb_module_done(ac->req, NULL, NULL,
+ LDB_ERR_OPERATIONS_ERROR);
+ }
+ if (ares->error != LDB_SUCCESS) {
+ return ldb_module_done(ac->req, ares->controls,
+ ares->response, ares->error);
+ }
+
+ switch (ares->type) {
+ case LDB_REPLY_ENTRY:
/* for each record returned post-process to add any derived
attributes that have been asked for */
- if (!inject_extended_dn(ares->message, ldb, ac->extended_type, ac->remove_guid, ac->remove_sid)) {
- goto error;
+ ret = inject_extended_dn(ares->message, ac->module->ldb,
+ ac->extended_type, ac->remove_guid,
+ ac->remove_sid);
+ if (ret != LDB_SUCCESS) {
+ return ldb_module_done(ac->req, NULL, NULL, ret);
}
- }
- return ac->up_callback(ldb, ac->up_context, ares);
+ return ldb_module_send_entry(ac->req, ares->message);
-error:
- talloc_free(ares);
- return LDB_ERR_OPERATIONS_ERROR;
+ case LDB_REPLY_REFERRAL:
+ return ldb_module_send_referral(ac->req, ares->referral);
+
+ case LDB_REPLY_DONE:
+ return ldb_module_done(ac->req, ares->controls,
+ ares->response, LDB_SUCCESS);
+
+ }
+ return LDB_SUCCESS;
}
+
static int extended_search(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_control *control;
@@ -237,6 +256,7 @@ static int extended_search(struct ldb_module *module, struct ldb_request *req)
struct ldb_control **saved_controls;
struct extended_context *ac;
struct ldb_request *down_req;
+ const char * const *cast_attrs = NULL;
char **new_attrs;
int ret;
@@ -261,9 +281,7 @@ static int extended_search(struct ldb_module *module, struct ldb_request *req)
}
ac->module = module;
- ac->up_context = req->context;
- ac->up_callback = req->callback;
- ac->attrs = req->op.search.attrs;
+ ac->req = req;
ac->remove_guid = false;
ac->remove_sid = false;
if (extended_ctrl) {
@@ -272,17 +290,6 @@ static int extended_search(struct ldb_module *module, struct ldb_request *req)
ac->extended_type = 0;
}
- down_req = talloc_zero(req, struct ldb_request);
- if (down_req == NULL) {
- ldb_oom(module->ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
- down_req->operation = req->operation;
- down_req->op.search.base = req->op.search.base;
- down_req->op.search.scope = req->op.search.scope;
- down_req->op.search.tree = req->op.search.tree;
-
/* check if attrs only is specified, in that case check wether we need to modify them */
if (req->op.search.attrs) {
if (! is_attr_in_list(req->op.search.attrs, "objectGUID")) {
@@ -292,26 +299,38 @@ static int extended_search(struct ldb_module *module, struct ldb_request *req)
ac->remove_sid = true;
}
if (ac->remove_guid || ac->remove_sid) {
- new_attrs = copy_attrs(down_req, req->op.search.attrs);
+ new_attrs = copy_attrs(ac, req->op.search.attrs);
if (new_attrs == NULL) {
ldb_oom(module->ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
if (ac->remove_guid) {
- if (!add_attrs(down_req, &new_attrs, "objectGUID"))
+ if (!add_attrs(ac, &new_attrs, "objectGUID"))
return LDB_ERR_OPERATIONS_ERROR;
}
if (ac->remove_sid) {
- if (!add_attrs(down_req, &new_attrs, "objectSID"))
+ if (!add_attrs(ac, &new_attrs, "objectSID"))
return LDB_ERR_OPERATIONS_ERROR;
}
-
- down_req->op.search.attrs = (const char * const *)new_attrs;
+ cast_attrs = (const char * const *)new_attrs;
+ } else {
+ cast_attrs = req->op.search.attrs;
}
}
- down_req->controls = req->controls;
+ ret = ldb_build_search_req_ex(&down_req,
+ module->ldb, ac,
+ req->op.search.base,
+ req->op.search.scope,
+ req->op.search.tree,
+ cast_attrs,
+ req->controls,
+ ac, extended_callback,
+ req);
+ if (ret != LDB_SUCCESS) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
/* save it locally and remove it from the list */
/* we do not need to replace them later as we
@@ -320,45 +339,21 @@ static int extended_search(struct ldb_module *module, struct ldb_request *req)
return LDB_ERR_OPERATIONS_ERROR;
}
- down_req->context = ac;
- down_req->callback = extended_callback;
- ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
-
/* perform the search */
- ret = ldb_next_request(module, down_req);
-
- /* do not free down_req as the call results may be linked to it,
- * it will be freed when the upper level request get freed */
- if (ret == LDB_SUCCESS) {
- req->handle = down_req->handle;
- }
-
- return ret;
+ return ldb_next_request(module, down_req);
}
static int extended_init(struct ldb_module *module)
{
- struct ldb_request *req;
int ret;
- req = talloc(module, struct ldb_request);
- if (req == NULL) {
- ldb_oom(module->ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
- req->operation = LDB_REQ_REGISTER_CONTROL;
- req->op.reg_control.oid = LDB_CONTROL_EXTENDED_DN_OID;
- req->controls = NULL;
-
- ret = ldb_request(module->ldb, req);
+ ret = ldb_mod_register_control(module, LDB_CONTROL_EXTENDED_DN_OID);
if (ret != LDB_SUCCESS) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "extended_dn: Unable to register control with rootdse!\n");
- talloc_free(req);
+ ldb_debug(module->ldb, LDB_DEBUG_ERROR,
+ "extended_dn: Unable to register control with rootdse!\n");
return LDB_ERR_OPERATIONS_ERROR;
}
- talloc_free(req);
return ldb_next_init(module);
}