diff options
author | Simo Sorce <idra@samba.org> | 2009-01-29 18:39:30 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2009-01-30 01:02:03 -0500 |
commit | 380874ef863866c94c999ef53252b9d30df65e88 (patch) | |
tree | aafdb720253d5a6013e2a23a0e81b0a9b90f054b /source4/dsdb/samdb | |
parent | a5f0640bf99e6f7e38b0b1e7a7a56f8f58ec7e47 (diff) | |
download | samba-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/dsdb/samdb')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/anr.c | 41 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/config.mk | 2 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/instancetype.c | 23 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/objectguid.c | 22 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/partition.c | 2 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/ranged_results.c | 27 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/subtree_delete.c | 16 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/subtree_rename.c | 21 | ||||
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/update_keytab.c | 67 |
9 files changed, 146 insertions, 75 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/anr.c b/source4/dsdb/samdb/ldb_modules/anr.c index 49e453ffa1..a04f5ebfa6 100644 --- a/source4/dsdb/samdb/ldb_modules/anr.c +++ b/source4/dsdb/samdb/ldb_modules/anr.c @@ -30,7 +30,7 @@ */ #include "includes.h" -#include "ldb_includes.h" +#include "ldb_module.h" #include "dsdb/samdb/samdb.h" /** @@ -40,11 +40,14 @@ static struct ldb_parse_tree *make_parse_list(struct ldb_module *module, TALLOC_CTX *mem_ctx, enum ldb_parse_op op, struct ldb_parse_tree *first_arm, struct ldb_parse_tree *second_arm) { + struct ldb_context *ldb; struct ldb_parse_tree *list; + ldb = ldb_module_get_ctx(module); + list = talloc(mem_ctx, struct ldb_parse_tree); if (list == NULL){ - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } list->operation = op; @@ -52,7 +55,7 @@ static struct ldb_parse_tree *make_parse_list(struct ldb_module *module, list->u.list.num_elements = 2; list->u.list.elements = talloc_array(list, struct ldb_parse_tree *, 2); if (!list->u.list.elements) { - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } list->u.list.elements[0] = talloc_steal(list, first_arm); @@ -67,8 +70,11 @@ static struct ldb_parse_tree *make_match_tree(struct ldb_module *module, TALLOC_CTX *mem_ctx, enum ldb_parse_op op, const char *attr, const DATA_BLOB *match) { + struct ldb_context *ldb; struct ldb_parse_tree *match_tree; + ldb = ldb_module_get_ctx(module); + match_tree = talloc(mem_ctx, struct ldb_parse_tree); /* Depending on what type of match was selected, fill in the right part of the union */ @@ -83,7 +89,7 @@ static struct ldb_parse_tree *make_match_tree(struct ldb_module *module, match_tree->u.substring.chunks = talloc_array(match_tree, struct ldb_val *, 2); if (match_tree->u.substring.chunks == NULL){ - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } match_tree->u.substring.chunks[0] = match; @@ -120,12 +126,16 @@ static int anr_replace_value(struct anr_context *ac, struct ldb_module *module = ac->module; struct ldb_parse_tree *match_tree; struct dsdb_attribute *cur; - const struct dsdb_schema *schema = dsdb_get_schema(module->ldb); + const struct dsdb_schema *schema; + struct ldb_context *ldb; uint8_t *p; enum ldb_parse_op op; + ldb = ldb_module_get_ctx(module); + + schema = dsdb_get_schema(ldb); if (!schema) { - ldb_asprintf_errstring(module->ldb, "no schema with which to construct anr filter"); + ldb_asprintf_errstring(ldb, "no schema with which to construct anr filter"); return LDB_ERR_OPERATIONS_ERROR; } @@ -135,7 +145,7 @@ static int anr_replace_value(struct anr_context *ac, DATA_BLOB *match2 = talloc(mem_ctx, DATA_BLOB); *match2 = data_blob_const(match->data+1, match->length - 1); if (match2 == NULL){ - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } match = match2; @@ -151,7 +161,7 @@ static int anr_replace_value(struct anr_context *ac, /* Inject an 'or' with the current tree */ tree = make_parse_list(module, mem_ctx, LDB_OP_OR, tree, match_tree); if (tree == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } } else { @@ -170,7 +180,7 @@ static int anr_replace_value(struct anr_context *ac, DATA_BLOB *first_match = talloc(tree, DATA_BLOB); DATA_BLOB *second_match = talloc(tree, DATA_BLOB); if (!first_match || !second_match) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } *first_match = data_blob_const(match->data, p-match->data); @@ -183,7 +193,7 @@ static int anr_replace_value(struct anr_context *ac, first_split_filter = make_parse_list(module, ac, LDB_OP_AND, match_tree_1, match_tree_2); if (first_split_filter == NULL){ - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -192,14 +202,14 @@ static int anr_replace_value(struct anr_context *ac, second_split_filter = make_parse_list(module, ac, LDB_OP_AND, match_tree_1, match_tree_2); if (second_split_filter == NULL){ - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } split_filters = make_parse_list(module, mem_ctx, LDB_OP_OR, first_split_filter, second_split_filter); if (split_filters == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -305,14 +315,17 @@ static int anr_search_callback(struct ldb_request *req, struct ldb_reply *ares) /* search */ static int anr_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_parse_tree *anr_tree; struct ldb_request *down_req; struct anr_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + ac = talloc(req, struct anr_context); if (!ac) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -335,7 +348,7 @@ static int anr_search(struct ldb_module *module, struct ldb_request *req) } ret = ldb_build_search_req_ex(&down_req, - module->ldb, ac, + ldb, ac, req->op.search.base, req->op.search.scope, anr_tree, diff --git a/source4/dsdb/samdb/ldb_modules/config.mk b/source4/dsdb/samdb/ldb_modules/config.mk index 1c50923eba..01f5188b6f 100644 --- a/source4/dsdb/samdb/ldb_modules/config.mk +++ b/source4/dsdb/samdb/ldb_modules/config.mk @@ -2,7 +2,7 @@ # Start MODULE ldb_objectguid [MODULE::ldb_objectguid] SUBSYSTEM = LIBLDB -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS LIBNDR +PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC LIBEVENTS LIBNDR INIT_FUNCTION = LDB_MODULE(objectguid) # End MODULE ldb_objectguid ################################################ diff --git a/source4/dsdb/samdb/ldb_modules/instancetype.c b/source4/dsdb/samdb/ldb_modules/instancetype.c index a8c45dee4c..8d648d6d82 100644 --- a/source4/dsdb/samdb/ldb_modules/instancetype.c +++ b/source4/dsdb/samdb/ldb_modules/instancetype.c @@ -35,7 +35,7 @@ */ #include "includes.h" -#include "ldb/include/ldb_includes.h" +#include "ldb_module.h" #include "librpc/gen_ndr/ndr_misc.h" #include "dsdb/samdb/samdb.h" #include "dsdb/common/flags.h" @@ -47,10 +47,11 @@ struct it_context { static int it_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct it_context *ac; ac = talloc_get_type(req->context, struct it_context); - + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -62,7 +63,7 @@ static int it_callback(struct ldb_request *req, struct ldb_reply *ares) } 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); } @@ -74,6 +75,7 @@ static int it_callback(struct ldb_request *req, struct ldb_reply *ares) /* add_record: add instancetype attribute */ static int instancetype_add(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_request *down_req; struct ldb_message *msg; struct it_context *ac; @@ -81,9 +83,10 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req) int ret; const struct ldb_control *partition_ctrl; const struct dsdb_control_current_partition *partition; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "instancetype_add_record\n"); + ldb = ldb_module_get_ctx(module); + + ldb_debug(ldb, LDB_DEBUG_TRACE, "instancetype_add_record\n"); /* do not manipulate our control entries */ if (ldb_dn_is_special(req->op.add.message->dn)) { @@ -92,7 +95,7 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req) partition_ctrl = ldb_request_get_control(req, DSDB_CONTROL_CURRENT_PARTITION_OID); if (!partition_ctrl) { - ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, + ldb_debug_set(ldb, LDB_DEBUG_FATAL, "instancetype_add: no current partition control found"); return LDB_ERR_CONSTRAINT_VIOLATION; } @@ -111,7 +114,7 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req) /* we have to copy the message as the caller might have it as a const */ msg = ldb_msg_copy_shallow(ac, req->op.add.message); if (msg == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -121,18 +124,18 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req) instance_type = INSTANCE_TYPE_WRITE; if (ldb_dn_compare(partition->dn, msg->dn) == 0) { instance_type |= INSTANCE_TYPE_IS_NC_HEAD; - if (ldb_dn_compare(msg->dn, samdb_base_dn(module->ldb)) != 0) { + if (ldb_dn_compare(msg->dn, samdb_base_dn(ldb)) != 0) { instance_type |= INSTANCE_TYPE_NC_ABOVE; } } ret = ldb_msg_add_fmt(msg, "instanceType", "%u", instance_type); if (ret != LDB_SUCCESS) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_build_add_req(&down_req, module->ldb, ac, + ret = ldb_build_add_req(&down_req, ldb, ac, msg, req->controls, ac, it_callback, diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c index 3d725686e7..46ba8ebdb3 100644 --- a/source4/dsdb/samdb/ldb_modules/objectguid.c +++ b/source4/dsdb/samdb/ldb_modules/objectguid.c @@ -34,7 +34,7 @@ */ #include "includes.h" -#include "ldb/include/ldb_includes.h" +#include "ldb_module.h" #include "librpc/gen_ndr/ndr_misc.h" #include "param/param.h" @@ -136,6 +136,7 @@ static int og_op_callback(struct ldb_request *req, struct ldb_reply *ares) /* add_record: add objectGUID attribute */ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_request *down_req; struct ldb_message_element *attribute; struct ldb_message *msg; @@ -147,7 +148,9 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) time_t t = time(NULL); struct og_context *ac; - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n"); + ldb = ldb_module_get_ctx(module); + + ldb_debug(ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n"); /* do not manipulate our control entries */ if (ldb_dn_is_special(req->op.add.message->dn)) { @@ -176,7 +179,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) guid = GUID_random(); ndr_err = ndr_push_struct_blob(&v, msg, - lp_iconv_convenience(ldb_get_opaque(module->ldb, "loadparm")), + lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), &guid, (ndr_push_flags_fn_t)ndr_push_GUID); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { @@ -196,7 +199,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) /* Get a sequence number from the backend */ /* FIXME: ldb_sequence_number is a semi-async call, * make sure this function is split and a callback is used */ - ret = ldb_sequence_number(module->ldb, LDB_SEQ_NEXT, &seq_num); + ret = ldb_sequence_number(ldb, LDB_SEQ_NEXT, &seq_num); if (ret == LDB_SUCCESS) { if (add_uint64_element(msg, "uSNCreated", seq_num) != 0 || add_uint64_element(msg, "uSNChanged", seq_num) != 0) { @@ -204,7 +207,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) } } - ret = ldb_build_add_req(&down_req, module->ldb, ac, + ret = ldb_build_add_req(&down_req, ldb, ac, msg, req->controls, ac, og_op_callback, @@ -220,6 +223,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) /* modify_record: update timestamps */ static int objectguid_modify(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_request *down_req; struct ldb_message *msg; int ret; @@ -227,7 +231,9 @@ static int objectguid_modify(struct ldb_module *module, struct ldb_request *req) uint64_t seq_num; struct og_context *ac; - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n"); + ldb = ldb_module_get_ctx(module); + + ldb_debug(ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n"); /* do not manipulate our control entries */ if (ldb_dn_is_special(req->op.add.message->dn)) { @@ -252,14 +258,14 @@ static int objectguid_modify(struct ldb_module *module, struct ldb_request *req) } /* Get a sequence number from the backend */ - ret = ldb_sequence_number(module->ldb, LDB_SEQ_NEXT, &seq_num); + ret = ldb_sequence_number(ldb, LDB_SEQ_NEXT, &seq_num); if (ret == LDB_SUCCESS) { if (add_uint64_element(msg, "uSNChanged", seq_num) != 0) { return LDB_ERR_OPERATIONS_ERROR; } } - ret = ldb_build_mod_req(&down_req, module->ldb, ac, + ret = ldb_build_mod_req(&down_req, ldb, ac, msg, req->controls, ac, og_op_callback, diff --git a/source4/dsdb/samdb/ldb_modules/partition.c b/source4/dsdb/samdb/ldb_modules/partition.c index 0000c87f72..71a1b8e942 100644 --- a/source4/dsdb/samdb/ldb_modules/partition.c +++ b/source4/dsdb/samdb/ldb_modules/partition.c @@ -34,7 +34,7 @@ */ #include "includes.h" -#include "ldb/include/ldb_includes.h" +#include "ldb_private.h" #include "dsdb/samdb/samdb.h" struct partition_private_data { diff --git a/source4/dsdb/samdb/ldb_modules/ranged_results.c b/source4/dsdb/samdb/ldb_modules/ranged_results.c index eeb161bdde..8f36baa7d6 100644 --- a/source4/dsdb/samdb/ldb_modules/ranged_results.c +++ b/source4/dsdb/samdb/ldb_modules/ranged_results.c @@ -29,7 +29,7 @@ * Author: Andrew Bartlett */ -#include "ldb_includes.h" +#include "ldb_module.h" struct rr_context { struct ldb_module *module; @@ -43,7 +43,7 @@ static struct rr_context *rr_init_context(struct ldb_module *module, ac = talloc_zero(req, struct rr_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb_module_get_ctx(module), "Out of Memory"); return NULL; } @@ -55,10 +55,12 @@ static struct rr_context *rr_init_context(struct ldb_module *module, static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct rr_context *ac; int i, j; ac = talloc_get_type(req->context, struct rr_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -106,7 +108,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) (size_t)(p - ac->req->op.search.attrs[i])); if (!new_attr) { - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -123,7 +125,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) } else { end_str = talloc_asprintf(el, "%u", end); if (!end_str) { - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -137,7 +139,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) orig_num_values = el->num_values; if ((start + end < start) || (start + end < end)) { - ldb_asprintf_errstring(ac->module->ldb, + ldb_asprintf_errstring(ldb, "range request error: start or end would overflow!"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_UNWILLING_TO_PERFORM); @@ -147,7 +149,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) el->values = talloc_array(el, struct ldb_val, (end - start) + 1); if (!el->values) { - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -158,7 +160,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) } el->name = talloc_asprintf(el, "%s;range=%u-%s", el->name, start, end_str); if (!el->name) { - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -170,6 +172,7 @@ static int rr_search_callback(struct ldb_request *req, struct ldb_reply *ares) /* search */ static int rr_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; int i; unsigned int start, end; const char **new_attrs = NULL; @@ -178,6 +181,8 @@ static int rr_search(struct ldb_module *module, struct ldb_request *req) struct rr_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + /* Strip the range request from the attribute */ for (i = 0; req->op.search.attrs && req->op.search.attrs[i]; i++) { char *p; @@ -194,14 +199,14 @@ static int rr_search(struct ldb_module *module, struct ldb_request *req) end = (unsigned int)-1; if (sscanf(p, ";range=%u-*", &start) != 1) { if (sscanf(p, ";range=%u-%u", &start, &end) != 2) { - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "range request error: " "range request malformed"); return LDB_ERR_UNWILLING_TO_PERFORM; } } if (start > end) { - ldb_asprintf_errstring(module->ldb, "range request error: start must not be greater than end"); + ldb_asprintf_errstring(ldb, "range request error: start must not be greater than end"); return LDB_ERR_UNWILLING_TO_PERFORM; } @@ -210,7 +215,7 @@ static int rr_search(struct ldb_module *module, struct ldb_request *req) (size_t)(p - new_attrs[i])); if (!new_attrs[i]) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } } @@ -221,7 +226,7 @@ static int rr_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_build_search_req_ex(&down_req, module->ldb, ac, + ret = ldb_build_search_req_ex(&down_req, ldb, ac, req->op.search.base, req->op.search.scope, req->op.search.tree, diff --git a/source4/dsdb/samdb/ldb_modules/subtree_delete.c b/source4/dsdb/samdb/ldb_modules/subtree_delete.c index 10e2dc25ce..55a24549dd 100644 --- a/source4/dsdb/samdb/ldb_modules/subtree_delete.c +++ b/source4/dsdb/samdb/ldb_modules/subtree_delete.c @@ -29,7 +29,7 @@ * Author: Andrew Bartlett */ -#include "ldb_includes.h" +#include "ldb_module.h" struct subtree_delete_context { struct ldb_module *module; @@ -41,11 +41,14 @@ struct subtree_delete_context { static struct subtree_delete_context *subdel_ctx_init(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct subtree_delete_context *ac; + ldb = ldb_module_get_ctx(module); + ac = talloc_zero(req, struct subtree_delete_context); if (ac == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } @@ -58,10 +61,12 @@ static struct subtree_delete_context *subdel_ctx_init(struct ldb_module *module, static int subtree_delete_search_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct subtree_delete_context *ac; int ret; ac = talloc_get_type(req->context, struct subtree_delete_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -89,7 +94,7 @@ static int subtree_delete_search_callback(struct ldb_request *req, if (ac->num_children > 0) { talloc_free(ares); - ldb_asprintf_errstring(ac->module->ldb, + ldb_asprintf_errstring(ldb, "Cannot delete %s, not a leaf node " "(has %d children)\n", ldb_dn_get_linearized(ac->req->op.del.dn), @@ -112,6 +117,7 @@ static int subtree_delete_search_callback(struct ldb_request *req, static int subtree_delete(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; static const char * const attrs[2] = { "distinguishedName", NULL }; struct ldb_request *search_req; struct subtree_delete_context *ac; @@ -120,6 +126,8 @@ static int subtree_delete(struct ldb_module *module, struct ldb_request *req) return ldb_next_request(module, req); } + ldb = ldb_module_get_ctx(module); + /* This gets complex: We need to: - Do a search for all entires under this entry - Wait for these results to appear @@ -135,7 +143,7 @@ static int subtree_delete(struct ldb_module *module, struct ldb_request *req) /* we do not really need to find all descendents, * if there is even one single direct child, that's * enough to bail out */ - ret = ldb_build_search_req(&search_req, module->ldb, ac, + ret = ldb_build_search_req(&search_req, ldb, ac, req->op.del.dn, LDB_SCOPE_ONELEVEL, "(objectClass=*)", attrs, req->controls, diff --git a/source4/dsdb/samdb/ldb_modules/subtree_rename.c b/source4/dsdb/samdb/ldb_modules/subtree_rename.c index d3ceb8ad97..e2f6b1d059 100644 --- a/source4/dsdb/samdb/ldb_modules/subtree_rename.c +++ b/source4/dsdb/samdb/ldb_modules/subtree_rename.c @@ -28,7 +28,7 @@ * Author: Andrew Bartlett */ -#include "ldb_includes.h" +#include "ldb_module.h" struct subren_msg_store { struct subren_msg_store *next; @@ -47,11 +47,14 @@ struct subtree_rename_context { static struct subtree_rename_context *subren_ctx_init(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct subtree_rename_context *ac; + ldb = ldb_module_get_ctx(module); + ac = talloc_zero(req, struct subtree_rename_context); if (ac == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } @@ -66,10 +69,12 @@ static int subtree_rename_next_request(struct subtree_rename_context *ac); static int subtree_rename_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct subtree_rename_context *ac; int ret; ac = talloc_get_type(req->context, struct subtree_rename_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -82,7 +87,7 @@ static int subtree_rename_callback(struct ldb_request *req, } if (ares->type != LDB_REPLY_DONE) { - ldb_set_errstring(ac->module->ldb, "Invalid reply type!\n"); + ldb_set_errstring(ldb, "Invalid reply type!\n"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -104,14 +109,17 @@ static int subtree_rename_callback(struct ldb_request *req, static int subtree_rename_next_request(struct subtree_rename_context *ac) { + struct ldb_context *ldb; struct ldb_request *req; int ret; + ldb = ldb_module_get_ctx(ac->module); + if (ac->current == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_build_rename_req(&req, ac->module->ldb, ac->current, + ret = ldb_build_rename_req(&req, ldb, ac->current, ac->current->olddn, ac->current->newdn, ac->req->controls, @@ -204,6 +212,7 @@ static int subtree_rename_search_callback(struct ldb_request *req, /* rename */ static int subtree_rename(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; static const char *attrs[2] = { "distinguishedName", NULL }; struct ldb_request *search_req; struct subtree_rename_context *ac; @@ -212,6 +221,8 @@ static int subtree_rename(struct ldb_module *module, struct ldb_request *req) return ldb_next_request(module, req); } + ldb = ldb_module_get_ctx(module); + /* This gets complex: We need to: - Do a search for all entires under this entry - Wait for these results to appear @@ -235,7 +246,7 @@ static int subtree_rename(struct ldb_module *module, struct ldb_request *req) ac->current->newdn = req->op.rename.newdn; ac->list = ac->current; - ret = ldb_build_search_req(&search_req, module->ldb, ac, + ret = ldb_build_search_req(&search_req, ldb, ac, req->op.rename.olddn, LDB_SCOPE_SUBTREE, "(objectClass=*)", diff --git a/source4/dsdb/samdb/ldb_modules/update_keytab.c b/source4/dsdb/samdb/ldb_modules/update_keytab.c index 7b82763403..e178ebb9dc 100644 --- a/source4/dsdb/samdb/ldb_modules/update_keytab.c +++ b/source4/dsdb/samdb/ldb_modules/update_keytab.c @@ -28,7 +28,7 @@ */ #include "includes.h" -#include "ldb/include/ldb_includes.h" +#include "ldb_module.h" #include "auth/credentials/credentials.h" #include "auth/credentials/credentials_krb5.h" #include "system/kerberos.h" @@ -60,7 +60,7 @@ static struct update_kt_ctx *update_kt_ctx_init(struct ldb_module *module, ac = talloc_zero(req, struct update_kt_ctx); if (ac == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb_module_get_ctx(module)); return NULL; } @@ -76,7 +76,8 @@ static struct update_kt_ctx *update_kt_ctx_init(struct ldb_module *module, * of async issues). -SSS */ static int add_modified(struct ldb_module *module, struct ldb_dn *dn, bool delete) { - struct update_kt_private *data = talloc_get_type(module->private_data, struct update_kt_private); + struct ldb_context *ldb = ldb_module_get_ctx(module); + struct update_kt_private *data = talloc_get_type(ldb_module_get_private(module), struct update_kt_private); struct dn_list *item; char *filter; struct ldb_result *res; @@ -87,11 +88,11 @@ static int add_modified(struct ldb_module *module, struct ldb_dn *dn, bool delet filter = talloc_asprintf(data, "(&(dn=%s)(&(objectClass=kerberosSecret)(privateKeytab=*)))", ldb_dn_get_linearized(dn)); if (!filter) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_search(module->ldb, data, &res, + ret = ldb_search(ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, "%s", filter); if (ret != LDB_SUCCESS) { talloc_free(filter); @@ -109,7 +110,7 @@ static int add_modified(struct ldb_module *module, struct ldb_dn *dn, bool delet item = talloc(data->changed_dns? (void *)data->changed_dns: (void *)data, struct dn_list); if (!item) { talloc_free(filter); - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -117,12 +118,12 @@ static int add_modified(struct ldb_module *module, struct ldb_dn *dn, bool delet if (!item->creds) { DEBUG(1, ("cli_credentials_init failed!")); talloc_free(filter); - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - cli_credentials_set_conf(item->creds, ldb_get_opaque(module->ldb, "loadparm")); - status = cli_credentials_set_secrets(item->creds, ldb_get_event_context(module->ldb), ldb_get_opaque(module->ldb, "loadparm"), module->ldb, NULL, filter); + cli_credentials_set_conf(item->creds, ldb_get_opaque(ldb, "loadparm")); + status = cli_credentials_set_secrets(item->creds, ldb_get_event_context(ldb), ldb_get_opaque(ldb, "loadparm"), ldb, NULL, filter); talloc_free(filter); if (NT_STATUS_IS_OK(status)) { if (delete) { @@ -142,10 +143,12 @@ static int ukt_search_modified(struct update_kt_ctx *ac); static int update_kt_op_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct update_kt_ctx *ac; int ret; ac = talloc_get_type(req->context, struct update_kt_ctx); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -157,7 +160,7 @@ static int update_kt_op_callback(struct ldb_request *req, } if (ares->type != LDB_REPLY_DONE) { - ldb_set_errstring(ac->module->ldb, "Invalid request type!\n"); + ldb_set_errstring(ldb, "Invalid request type!\n"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -179,10 +182,13 @@ static int update_kt_op_callback(struct ldb_request *req, static int ukt_del_op(struct update_kt_ctx *ac) { + struct ldb_context *ldb; struct ldb_request *down_req; int ret; - ret = ldb_build_del_req(&down_req, ac->module->ldb, ac, + ldb = ldb_module_get_ctx(ac->module); + + ret = ldb_build_del_req(&down_req, ldb, ac, ac->dn, ac->req->controls, ac, update_kt_op_callback, @@ -246,11 +252,14 @@ static int ukt_search_modified_callback(struct ldb_request *req, static int ukt_search_modified(struct update_kt_ctx *ac) { + struct ldb_context *ldb; static const char * const attrs[] = { "distinguishedName", NULL }; struct ldb_request *search_req; int ret; - ret = ldb_build_search_req(&search_req, ac->module->ldb, ac, + ldb = ldb_module_get_ctx(ac->module); + + ret = ldb_build_search_req(&search_req, ldb, ac, ac->dn, LDB_SCOPE_BASE, "(&(objectClass=kerberosSecret)" "(privateKeytab=*))", attrs, @@ -267,10 +276,13 @@ static int ukt_search_modified(struct update_kt_ctx *ac) /* add */ static int update_kt_add(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct update_kt_ctx *ac; struct ldb_request *down_req; int ret; + ldb = ldb_module_get_ctx(module); + ac = update_kt_ctx_init(module, req); if (ac == NULL) { return LDB_ERR_OPERATIONS_ERROR; @@ -278,7 +290,7 @@ static int update_kt_add(struct ldb_module *module, struct ldb_request *req) ac->dn = req->op.add.message->dn; - ret = ldb_build_add_req(&down_req, module->ldb, ac, + ret = ldb_build_add_req(&down_req, ldb, ac, req->op.add.message, req->controls, ac, update_kt_op_callback, @@ -293,10 +305,13 @@ static int update_kt_add(struct ldb_module *module, struct ldb_request *req) /* modify */ static int update_kt_modify(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct update_kt_ctx *ac; struct ldb_request *down_req; int ret; + ldb = ldb_module_get_ctx(module); + ac = update_kt_ctx_init(module, req); if (ac == NULL) { return LDB_ERR_OPERATIONS_ERROR; @@ -304,7 +319,7 @@ static int update_kt_modify(struct ldb_module *module, struct ldb_request *req) ac->dn = req->op.mod.message->dn; - ret = ldb_build_mod_req(&down_req, module->ldb, ac, + ret = ldb_build_mod_req(&down_req, ldb, ac, req->op.mod.message, req->controls, ac, update_kt_op_callback, @@ -335,10 +350,13 @@ static int update_kt_delete(struct ldb_module *module, struct ldb_request *req) /* rename */ static int update_kt_rename(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct update_kt_ctx *ac; struct ldb_request *down_req; int ret; + ldb = ldb_module_get_ctx(module); + ac = update_kt_ctx_init(module, req); if (ac == NULL) { return LDB_ERR_OPERATIONS_ERROR; @@ -346,7 +364,7 @@ static int update_kt_rename(struct ldb_module *module, struct ldb_request *req) ac->dn = req->op.rename.newdn; - ret = ldb_build_rename_req(&down_req, module->ldb, ac, + ret = ldb_build_rename_req(&down_req, ldb, ac, req->op.rename.olddn, req->op.rename.newdn, req->controls, @@ -362,16 +380,19 @@ static int update_kt_rename(struct ldb_module *module, struct ldb_request *req) /* end a transaction */ static int update_kt_end_trans(struct ldb_module *module) { - struct update_kt_private *data = talloc_get_type(module->private_data, struct update_kt_private); + struct ldb_context *ldb; + struct update_kt_private *data = talloc_get_type(ldb_module_get_private(module), struct update_kt_private); struct dn_list *p; + ldb = ldb_module_get_ctx(module); + for (p=data->changed_dns; p; p = p->next) { int kret; - kret = cli_credentials_update_keytab(p->creds, ldb_get_event_context(module->ldb), ldb_get_opaque(module->ldb, "loadparm")); + kret = cli_credentials_update_keytab(p->creds, ldb_get_event_context(ldb), ldb_get_opaque(ldb, "loadparm")); if (kret != 0) { talloc_free(data->changed_dns); data->changed_dns = NULL; - ldb_asprintf_errstring(module->ldb, "Failed to update keytab: %s", error_message(kret)); + ldb_asprintf_errstring(ldb, "Failed to update keytab: %s", error_message(kret)); return LDB_ERR_OPERATIONS_ERROR; } } @@ -385,7 +406,7 @@ static int update_kt_end_trans(struct ldb_module *module) /* end a transaction */ static int update_kt_del_trans(struct ldb_module *module) { - struct update_kt_private *data = talloc_get_type(module->private_data, struct update_kt_private); + struct update_kt_private *data = talloc_get_type(ldb_module_get_private(module), struct update_kt_private); talloc_free(data->changed_dns); data->changed_dns = NULL; @@ -395,17 +416,21 @@ static int update_kt_del_trans(struct ldb_module *module) static int update_kt_init(struct ldb_module *module) { + struct ldb_context *ldb; struct update_kt_private *data; + ldb = ldb_module_get_ctx(module); + data = talloc(module, struct update_kt_private); if (data == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - module->private_data = data; data->changed_dns = NULL; + ldb_module_set_private(module, data); + return ldb_next_init(module); } |