diff options
author | Simo Sorce <idra@samba.org> | 2005-11-08 00:11:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:45:53 -0500 |
commit | 5c9590587197dcb95007fdc54318187d5716c7c6 (patch) | |
tree | d5161aa628d8a4bc4f11bf849d76a451ff44522c /source4/lib/ldb/modules | |
parent | 14b59bcbec1a288810efee5c9442dff30f1a474a (diff) | |
download | samba-5c9590587197dcb95007fdc54318187d5716c7c6.tar.gz samba-5c9590587197dcb95007fdc54318187d5716c7c6.tar.bz2 samba-5c9590587197dcb95007fdc54318187d5716c7c6.zip |
r11567: Ldb API change patch.
This patch changes the way lsb_search is called and the meaning of the returned integer.
The last argument of ldb_search is changed from struct ldb_message to struct ldb_result
which contains a pointer to a struct ldb_message list and a count of the number of messages.
The return is not the count of messages anymore but instead it is an ldb error value.
I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good
amount of places. I also tried to double check all my changes being sure that the calling
functions would still behave as before. But this patch is big enough that I fear some bug
may have been introduced anyway even if it passes the test suite. So if you are currently
working on any file being touched please give it a deep look and blame me for any error.
Simo.
(This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780)
Diffstat (limited to 'source4/lib/ldb/modules')
-rw-r--r-- | source4/lib/ldb/modules/ldb_map.c | 198 | ||||
-rw-r--r-- | source4/lib/ldb/modules/operational.c | 84 | ||||
-rw-r--r-- | source4/lib/ldb/modules/rdn_name.c | 56 | ||||
-rw-r--r-- | source4/lib/ldb/modules/schema.c | 77 | ||||
-rw-r--r-- | source4/lib/ldb/modules/skel.c | 40 |
5 files changed, 291 insertions, 164 deletions
diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c index 48aa7e2ef5..49261d155c 100644 --- a/source4/lib/ldb/modules/ldb_map.c +++ b/source4/lib/ldb/modules/ldb_map.c @@ -24,6 +24,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #include "ldb/modules/ldb_map.h" @@ -687,8 +688,10 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c /* rename a record */ -static int map_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +static int map_rename(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_dn *olddn = req->op.rename.olddn; + const struct ldb_dn *newdn = req->op.rename.newdn; struct ldb_map_context *privdat = map_get_privdat(module); struct ldb_dn *n_olddn, *n_newdn; int ret; @@ -699,9 +702,9 @@ static int map_rename(struct ldb_module *module, const struct ldb_dn *olddn, con ret = ldb_rename(privdat->mapped_ldb, n_olddn, n_newdn); if (ret != -1) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Mapped record renamed"); - ldb_next_rename_record(module, olddn, newdn); + ldb_next_request(module, req); } else { - ret = ldb_next_rename_record(module, olddn, newdn); + ret = ldb_next_request(module, req); if (ret != -1) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Fallback record renamed"); @@ -718,8 +721,9 @@ static int map_rename(struct ldb_module *module, const struct ldb_dn *olddn, con /* delete a record */ -static int map_delete(struct ldb_module *module, const struct ldb_dn *dn) +static int map_delete(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_dn *dn = req->op.del.dn; struct ldb_map_context *privdat = map_get_privdat(module); struct ldb_dn *newdn; int ret; @@ -730,13 +734,15 @@ static int map_delete(struct ldb_module *module, const struct ldb_dn *dn) if (ret != -1) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Mapped record deleted"); } else { - ret = ldb_next_delete_record(module, dn); + ret = ldb_next_request(module, req); if (ret != -1) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Fallback record deleted"); } } - ldb_next_delete_record(module, newdn); + req->op.del.dn = newdn; + ret = ldb_next_request(module, req); + req->op.del.dn = dn; talloc_free(newdn); @@ -744,12 +750,11 @@ static int map_delete(struct ldb_module *module, const struct ldb_dn *dn) } /* search fallback database */ -static int map_search_fb(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) +static int map_search_fb(struct ldb_module *module, struct ldb_request *req) { - int ret; + struct ldb_parse_tree *tree = req->op.search.tree; struct ldb_parse_tree t_and, t_not, t_present, *childs[2]; + int ret; char *ismapped; t_present.operation = LDB_OP_PRESENT; @@ -764,8 +769,10 @@ static int map_search_fb(struct ldb_module *module, const struct ldb_dn *base, t_and.operation = LDB_OP_AND; t_and.u.list.num_elements = 2; t_and.u.list.elements = childs; - - ret = ldb_next_search_bytree(module, base, scope, &t_and, attrs, res); + + req->op.search.tree = &t_and; + ret = ldb_next_request(module, req); + req->op.search.tree = tree; talloc_free(ismapped); @@ -773,13 +780,17 @@ static int map_search_fb(struct ldb_module *module, const struct ldb_dn *base, } /* Search in the database against which we are mapping */ -static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) +static int map_search_mp(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_dn *base = req->op.search.base; + enum ldb_scope scope = req->op.search.scope; + struct ldb_parse_tree *tree = req->op.search.tree; + const char * const *attrs = req->op.search.attrs; + struct ldb_result **res = req->op.search.res; + struct ldb_request new_req; struct ldb_parse_tree *new_tree; struct ldb_dn *new_base; - struct ldb_message **newres; + struct ldb_result *newres; const char **newattrs; int mpret, ret; struct ldb_map_context *privdat = map_get_privdat(module); @@ -801,15 +812,22 @@ static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base, newattrs = ldb_map_attrs(module, attrs); new_base = map_local_dn(module, module, base); - mpret = ldb_search_bytree(privdat->mapped_ldb, new_base, scope, new_tree, newattrs, &newres); + memset((char *)&(new_req), 0, sizeof(new_req)); + new_req.operation = LDB_REQ_SEARCH; + new_req.op.search.base = new_base; + new_req.op.search.scope = scope; + new_req.op.search.tree = new_tree; + new_req.op.search.attrs = newattrs; + new_req.op.search.res = &newres; + mpret = ldb_request(privdat->mapped_ldb, req); talloc_free(new_base); talloc_free(new_tree); talloc_free(newattrs); - if (mpret == -1) { + if (mpret != LDB_SUCCESS) { ldb_set_errstring(module, talloc_strdup(module, ldb_errstring(privdat->mapped_ldb))); - return -1; + return mpret; } /* @@ -817,23 +835,34 @@ static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base, - test if (full expression) is now true */ - *res = talloc_array(module, struct ldb_message *, mpret); + *res = talloc(module, struct ldb_result); + (*res)->msgs = talloc_array(module, struct ldb_message *, newres->count); + (*res)->count = newres->count; ret = 0; for (i = 0; i < mpret; i++) { + struct ldb_request mergereq; struct ldb_message *merged; - struct ldb_message **extrares = NULL; + struct ldb_result *extrares = NULL; int extraret; /* Always get special DN's from the fallback database */ - if (ldb_dn_is_special(newres[i]->dn)) + if (ldb_dn_is_special(newres->msgs[i]->dn)) continue; - merged = ldb_map_message_incoming(module, attrs, newres[i]); + merged = ldb_map_message_incoming(module, attrs, newres->msgs[i]); /* Merge with additional data from fallback database */ - extraret = ldb_next_search(module, merged->dn, LDB_SCOPE_BASE, "", NULL, &extrares); + memset((char *)&(mergereq), 0, sizeof(mergereq)); /* zero off the request structure */ + mergereq.operation = LDB_REQ_SEARCH; + mergereq.op.search.base = merged->dn; + mergereq.op.search.scope = LDB_SCOPE_BASE; + mergereq.op.search.tree = ldb_parse_tree(module, ""); + mergereq.op.search.attrs = NULL; + mergereq.op.search.res = &extrares; + + extraret = ldb_next_request(module, &mergereq); if (extraret == -1) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Error searching for extra data!\n"); @@ -848,13 +877,13 @@ static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base, if (extraret == 1) { int j; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Extra data found for remote DN: %s", ldb_dn_linearize(merged, merged->dn)); - for (j = 0; j < extrares[0]->num_elements; j++) { - ldb_msg_add(merged, &(extrares[0]->elements[j]), extrares[0]->elements[j].flags); + for (j = 0; j < extrares->msgs[0]->num_elements; j++) { + ldb_msg_add(merged, &(extrares->msgs[0]->elements[j]), extrares->msgs[0]->elements[j].flags); } } if (ldb_match_msg(module->ldb, merged, tree, base, scope) != 0) { - (*res)[ret] = merged; + (*res)->msgs[ret] = merged; ret++; } else { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Discarded merged message because it did not match"); @@ -863,45 +892,51 @@ static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base, talloc_free(newres); - return ret; + (*res)->count = ret; + return LDB_SUCCESS; } /* search for matching records using a ldb_parse_tree */ -static int map_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) +static int map_search_bytree(struct ldb_module *module, struct ldb_request *req) { - struct ldb_message **fbres, **mpres = NULL; - int i; - int ret_fb, ret_mp; + const struct ldb_dn *base = req->op.search.base; + struct ldb_result **res = req->op.search.res; + struct ldb_result *fbres, *mpres = NULL; + int i, ret; - ret_fb = map_search_fb(module, base, scope, tree, attrs, &fbres); - if (ret_fb == -1) - return -1; + req->op.search.res = &fbres; + ret = map_search_fb(module, req); + req->op.search.res = res; + if (ret != LDB_SUCCESS) + return ret; /* special dn's are never mapped.. */ if (ldb_dn_is_special(base)) { *res = fbres; - return ret_fb; + return ret; } - ret_mp = map_search_mp(module, base, scope, tree, attrs, &mpres); - if (ret_mp == -1) { - return -1; + req->op.search.res = &mpres; + ret = map_search_mp(module, req); + req->op.search.res = res; + if (ret != LDB_SUCCESS) { + return ret; } /* Merge results */ - *res = talloc_array(module, struct ldb_message *, ret_fb + ret_mp); + *res = talloc(module, struct ldb_result); + (*res)->msgs = talloc_array(*res, struct ldb_message *, fbres->count + mpres->count); - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Merging %d mapped and %d fallback messages", ret_mp, ret_fb); + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Merging %d mapped and %d fallback messages", mpres->count, fbres->count); - for (i = 0; i < ret_fb; i++) (*res)[i] = fbres[i]; - for (i = 0; i < ret_mp; i++) (*res)[ret_fb+i] = mpres[i]; + for (i = 0; i < fbres->count; i++) (*res)->msgs[i] = fbres->msgs[i]; + for (i = 0; i < mpres->count; i++) (*res)->msgs[fbres->count + i] = mpres->msgs[i]; - return ret_fb + ret_mp; + (*res)->count = fbres->count + mpres->count; + return LDB_SUCCESS; } static int msg_contains_objectclass(const struct ldb_message *msg, const char *name) @@ -921,19 +956,20 @@ static int msg_contains_objectclass(const struct ldb_message *msg, const char *n /* add a record */ -static int map_add(struct ldb_module *module, const struct ldb_message *msg) +static int map_add(struct ldb_module *module, struct ldb_request *req) { - int ret; + const struct ldb_message *msg = req->op.add.message; struct ldb_map_context *privdat = map_get_privdat(module); struct ldb_message *fb, *mp; struct ldb_message_element *ocs; + int ret; int i; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add"); if (ldb_dn_is_special(msg->dn)) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added fallback record"); - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } mp = talloc_zero(module, struct ldb_message); @@ -981,7 +1017,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) ocs = ldb_msg_find_element(mp, "objectClass"); if (ocs->num_values == 1) { /* Only top */ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added fallback record"); - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* @@ -1098,7 +1134,10 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added mapped record"); ldb_msg_add_string(fb, "isMapped", "TRUE"); - ret = ldb_next_add_record(module, fb); + + req->op.add.message = fb; + ret = ldb_next_request(module, req); + req->op.add.message = msg; if (ret == -1) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Adding fallback record failed: %s", ldb_errstring(module->ldb)); return -1; @@ -1114,8 +1153,9 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) /* modify a record */ -static int map_modify(struct ldb_module *module, const struct ldb_message *msg) +static int map_modify(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.mod.message; struct ldb_map_context *privdat = map_get_privdat(module); struct ldb_message *fb, *mp; struct ldb_message_element *elm; @@ -1125,7 +1165,7 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_modify"); if (ldb_dn_is_special(msg->dn)) - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); fb = talloc_zero(module, struct ldb_message); fb->dn = talloc_reference(fb, msg->dn); @@ -1217,11 +1257,16 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) if (fb->num_elements > 0) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Modifying fallback record with %d elements", fb->num_elements); - fb_ret = ldb_next_modify_record(module, fb); + req->op.mod.message = fb; + fb_ret = ldb_next_request(module, req); if (fb_ret == -1) { ldb_msg_add_string(fb, "isMapped", "TRUE"); - fb_ret = ldb_next_add_record(module, fb); + req->operation = LDB_REQ_ADD; + req->op.add.message = fb; + fb_ret = ldb_next_request(module, req); + req->operation = LDB_REQ_MODIFY; } + req->op.mod.message = msg; } else fb_ret = 0; talloc_free(fb); @@ -1234,19 +1279,42 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) return (mp_ret == -1 || fb_ret == -1)?-1:0; } + +static int map_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return map_search_bytree(module, req); + + case LDB_REQ_ADD: + return map_add(module, req); + + case LDB_REQ_MODIFY: + return map_modify(module, req); + + case LDB_REQ_DELETE: + return map_delete(module, req); + + case LDB_REQ_RENAME: + return map_rename(module, req); + + default: + return ldb_next_request(module, req); + + } +} + + static const struct ldb_module_ops map_ops = { .name = "map", - .search_bytree = map_search_bytree, - .add_record = map_add, - .modify_record = map_modify, - .delete_record = map_delete, - .rename_record = map_rename + .request = map_request }; static char *map_find_url(struct ldb_context *ldb, const char *name) { const char * const attrs[] = { "@MAP_URL" , NULL}; - struct ldb_message **msg = NULL; + struct ldb_result *result = NULL; struct ldb_dn *mods; char *url; int ret; @@ -1257,16 +1325,16 @@ static char *map_find_url(struct ldb_context *ldb, const char *name) return NULL; } - ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &msg); + ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &result); talloc_free(mods); - if (ret < 1) { + if (ret != LDB_SUCCESS || result->count == 0) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Not enough results found looking for @MAP"); return NULL; } - url = talloc_strdup(ldb, ldb_msg_find_string(msg[0], "@MAP_URL", NULL)); + url = talloc_strdup(ldb, ldb_msg_find_string(result->msgs[0], "@MAP_URL", NULL)); - talloc_free(msg); + talloc_free(result); return url; } diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index 8a06e20c29..7c554e8541 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -76,6 +76,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #include <time.h> @@ -174,23 +175,20 @@ failed: /* hook search operations */ -static int operational_search_bytree(struct ldb_module *module, - const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_message ***res) +static int operational_search_bytree(struct ldb_module *module, struct ldb_request *req) { int i, r, a; int ret; + const char * const *attrs = req->op.search.attrs; const char **search_attrs = NULL; - (*res) = NULL; + *(req->op.search.res) = NULL; /* replace any attributes in the parse tree that are searchable, but are stored using a different name in the backend */ for (i=0;i<ARRAY_SIZE(parse_tree_sub);i++) { - ldb_parse_tree_attr_replace(tree, + ldb_parse_tree_attr_replace(req->op.search.tree, parse_tree_sub[i].attr, parse_tree_sub[i].replace); } @@ -213,18 +211,22 @@ static int operational_search_bytree(struct ldb_module *module, } } - + /* use new set of attrs if any */ + if (search_attrs) req->op.search.attrs = search_attrs; /* perform the search */ - ret = ldb_next_search_bytree(module, base, scope, tree, - search_attrs?search_attrs:attrs, res); - if (ret <= 0) { + ret = ldb_next_request(module, req); + /* set back saved attrs if needed */ + if (search_attrs) req->op.search.attrs = attrs; + + /* check operation result */ + if (ret != LDB_SUCCESS) { return ret; } /* for each record returned post-process to add any derived attributes that have been asked for */ - for (r=0;r<ret;r++) { - if (operational_search_post_process(module, (*res)[r], attrs) != 0) { + for (r = 0; r < (*(req->op.search.res))->count; r++) { + if (operational_search_post_process(module, (*(req->op.search.res))->msgs[r], attrs) != 0) { goto failed; } } @@ -235,9 +237,9 @@ static int operational_search_bytree(struct ldb_module *module, failed: talloc_free(search_attrs); - talloc_free(*res); + talloc_free(*(req->op.search.res)); ldb_oom(module->ldb); - return -1; + return LDB_ERR_OTHER; } /* @@ -273,15 +275,15 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t) /* hook add record ops */ -static int operational_add_record(struct ldb_module *module, - const struct ldb_message *msg) +static int operational_add(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.add.message; time_t t = time(NULL); struct ldb_message *msg2; int ret; if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* we have to copy the message as the caller might have it as a const */ @@ -294,7 +296,13 @@ static int operational_add_record(struct ldb_module *module, talloc_free(msg2); return -1; } - ret = ldb_next_add_record(module, msg2); + /* use the new structure for the call chain below this point */ + req->op.add.message = msg2; + /* go on with the call chain */ + ret = ldb_next_request(module, req); + /* put back saved message */ + req->op.add.message = msg; + /* free temproary compy */ talloc_free(msg2); return ret; } @@ -302,15 +310,15 @@ static int operational_add_record(struct ldb_module *module, /* hook modify record ops */ -static int operational_modify_record(struct ldb_module *module, - const struct ldb_message *msg) +static int operational_modify(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.mod.message; time_t t = time(NULL); struct ldb_message *msg2; int ret; if (ldb_dn_is_special(msg->dn)) { - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } /* we have to copy the message as the caller might have it as a const */ @@ -322,16 +330,40 @@ static int operational_modify_record(struct ldb_module *module, talloc_free(msg2); return -1; } - ret = ldb_next_modify_record(module, msg2); + /* use the new structure for the call chain below this point */ + req->op.mod.message = msg2; + /* go on with the call chain */ + ret = ldb_next_request(module, req); + /* put back saved message */ + req->op.mod.message = msg; + /* free temproary compy */ talloc_free(msg2); return ret; } + +static int operational_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return operational_search_bytree(module, req); + + case LDB_REQ_ADD: + return operational_add(module, req); + + case LDB_REQ_MODIFY: + return operational_modify(module, req); + + default: + return ldb_next_request(module, req); + + } +} + static const struct ldb_module_ops operational_ops = { .name = "operational", - .search_bytree = operational_search_bytree, - .add_record = operational_add_record, - .modify_record = operational_modify_record + .request = operational_request }; diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index c51aa74244..42faf6629c 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -37,14 +37,6 @@ #include "ldb/include/ldb_private.h" #include <time.h> -static int rdn_name_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n"); - return ldb_next_search_bytree(module, base, scope, tree, attrs, res); -} - static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name) { int i; @@ -58,9 +50,9 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess return NULL; } -/* add_record: add crateTimestamp/modifyTimestamp attributes */ -static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) +static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.add.message; struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; @@ -70,12 +62,12 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa /* do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* Perhaps someone above us knows better */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } msg2 = talloc(module, struct ldb_message); @@ -128,15 +120,18 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa } } - ret = ldb_next_add_record(module, msg2); + req->op.add.message = msg2; + ret = ldb_next_request(module, req); + req->op.add.message = msg; + talloc_free(msg2); return ret; } -/* modify_record: change modifyTimestamp as well */ -static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_message *msg) +static int rdn_name_modify(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.mod.message; struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; @@ -146,12 +141,12 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me /* do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } /* Perhaps someone above us knows better */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } msg2 = talloc(module, struct ldb_message); @@ -186,24 +181,35 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me attribute->flags = LDB_FLAG_MOD_REPLACE; - ret = ldb_next_modify_record(module, msg2); + req->op.add.message = msg2; + ret = ldb_next_request(module, req); + req->op.add.message = msg; + talloc_free(msg2); return ret; } -static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) { - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n"); - return ldb_next_rename_record(module, olddn, newdn); + switch (req->operation) { + + case LDB_REQ_ADD: + return rdn_name_add(module, req); + + case LDB_REQ_MODIFY: + return rdn_name_modify(module, req); + + + default: + return ldb_next_request(module, req); + + } } static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", - .search_bytree = rdn_name_search_bytree, - .add_record = rdn_name_add_record, - .modify_record = rdn_name_modify_record, - .rename_record = rdn_name_rename_record + .request = rdn_name_request }; diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c index 27177116c2..fd96a6cfba 100644 --- a/source4/lib/ldb/modules/schema.c +++ b/source4/lib/ldb/modules/schema.c @@ -128,7 +128,7 @@ static int get_msg_attributes(struct schema_structures *ss, const struct ldb_mes static int get_entry_attributes(struct ldb_context *ldb, const struct ldb_dn *dn, struct schema_structures *ss) { - struct ldb_message **srch; + struct ldb_result *srch; int ret; ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &srch); @@ -138,7 +138,7 @@ static int get_entry_attributes(struct ldb_context *ldb, const struct ldb_dn *dn talloc_steal(ss, srch); /* set flags to 0 as flags on search have undefined values */ - ret = get_msg_attributes(ss, *srch, 0); + ret = get_msg_attributes(ss, *(srch->msgs), 0); if (ret != 0) { talloc_free(srch); return ret; @@ -187,7 +187,7 @@ static int add_attribute_uniq(void *mem_ctx, struct schema_attribute_list *list, recursively get parent objectlasses attributes */ static int get_attr_list_recursive(struct ldb_module *module, struct schema_structures *schema_struct) { - struct ldb_message **srch; + struct ldb_result *srch; int i, j; int ret; @@ -226,20 +226,20 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru /* Add inherited classes eliminating duplicates */ /* fill in required_attrs and optional_attrs attribute lists */ - for (j = 0; j < (*srch)->num_elements; j++) { + for (j = 0; j < srch->msgs[0]->num_elements; j++) { int is_aux, is_class; is_aux = 0; is_class = 0; - if (ldb_attr_cmp((*srch)->elements[j].name, "systemAuxiliaryclass") == 0) { + if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "systemAuxiliaryclass") == 0) { is_aux = SCHEMA_FLAG_AUXILIARY; is_class = 1; } - if (ldb_attr_cmp((*srch)->elements[j].name, "auxiliaryClass") == 0) { + if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "auxiliaryClass") == 0) { is_aux = SCHEMA_FLAG_AUXILIARY; is_class = 1; } - if (ldb_attr_cmp((*srch)->elements[j].name, "subClassOf") == 0) { + if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "subClassOf") == 0) { is_class = 1; } @@ -247,28 +247,28 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru if (add_attribute_uniq(schema_struct, &schema_struct->objectclasses, is_aux, - &(*srch)->elements[j]) != 0) { + &srch->msgs[0]->elements[j]) != 0) { return -1; } } else { - if (ldb_attr_cmp((*srch)->elements[j].name, "mustContain") == 0 || - ldb_attr_cmp((*srch)->elements[j].name, "SystemMustContain") == 0) { + if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "mustContain") == 0 || + ldb_attr_cmp(srch->msgs[0]->elements[j].name, "SystemMustContain") == 0) { if (add_attribute_uniq(schema_struct, &schema_struct->required_attrs, SCHEMA_FLAG_RESET, - &(*srch)->elements[j]) != 0) { + &srch->msgs[0]->elements[j]) != 0) { return -1; } } - if (ldb_attr_cmp((*srch)->elements[j].name, "mayContain") == 0 || - ldb_attr_cmp((*srch)->elements[j].name, "SystemMayContain") == 0) { + if (ldb_attr_cmp(srch->msgs[0]->elements[j].name, "mayContain") == 0 || + ldb_attr_cmp(srch->msgs[0]->elements[j].name, "SystemMayContain") == 0) { if (add_attribute_uniq(schema_struct, &schema_struct->optional_attrs, SCHEMA_FLAG_RESET, - &(*srch)->elements[j]) != 0) { + &srch->msgs[0]->elements[j]) != 0) { return -1; } } @@ -279,17 +279,10 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru return 0; } -/* search */ -static int schema_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) -{ - return ldb_next_search_bytree(module, base, scope, tree, attrs, res); -} - /* add_record */ -static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg) +static int schema_add(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.add.message; struct schema_structures *entry_structs; unsigned int i; int ret; @@ -304,7 +297,7 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message /* do not check on our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* TODO: check parent exists */ @@ -366,12 +359,13 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message talloc_free(entry_structs); - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* modify_record */ -static int schema_modify_record(struct ldb_module *module, const struct ldb_message *msg) +static int schema_modify(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.mod.message; struct schema_structures *entry_structs; unsigned int i; int ret; @@ -387,7 +381,7 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess /* do not check on our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* allocate object structs */ @@ -466,29 +460,28 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess talloc_free(entry_structs); - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } -/* delete_record */ -static int schema_delete_record(struct ldb_module *module, const struct ldb_dn *dn) +static int schema_request(struct ldb_module *module, struct ldb_request *req) { -/* struct private_data *data = (struct private_data *)module->private_data; */ - return ldb_next_delete_record(module, dn); -} + switch (req->operation) { -/* rename_record */ -static int schema_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) -{ - return ldb_next_rename_record(module, olddn, newdn); + case LDB_REQ_ADD: + return schema_add(module, req); + + case LDB_REQ_MODIFY: + return schema_modify(module, req); + + default: + return ldb_next_request(module, req); + + } } static const struct ldb_module_ops schema_ops = { .name = "schema", - .search_bytree = schema_search_bytree, - .add_record = schema_add_record, - .modify_record = schema_modify_record, - .delete_record = schema_delete_record, - .rename_record = schema_rename_record + .request = schema_request }; #ifdef HAVE_DLOPEN_DISABLED diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c index f882a840e1..a3dcfc21bb 100644 --- a/source4/lib/ldb/modules/skel.c +++ b/source4/lib/ldb/modules/skel.c @@ -44,7 +44,7 @@ struct private_data { /* search */ static int skel_search(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) + const char * const *attrs, struct ldb_result **res) { return ldb_next_search(module, base, scope, tree, attrs, res); } @@ -100,13 +100,41 @@ static int skel_destructor(void *module_ctx) return 0; } +static int skel_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return skel_search_bytree(module, + req->op.search->base, + req->op.search->scope, + req->op.search->tree, + req->op.search->attrs, + req->op.search->res); + + case LDB_REQ_ADD: + return skel_add(module, req->op.add->message); + + case LDB_REQ_MODIFY: + return skel_modify(module, req->op.mod->message); + + case LDB_REQ_DELETE: + return skel_delete(module, req->op.del->dn); + + case LDB_REQ_RENAME: + return skel_rename(module, + req->op.rename->olddn, + req->op.rename->newdn); + + default: + return ldb_next_request(module, req); + + } +} + static const struct ldb_module_ops skel_ops = { .name = "skel", - .search_bytree = skel_search_bytree, - .add_record = skel_add_record, - .modify_record = skel_modify_record, - .delete_record = skel_delete_record, - .rename_record = skel_rename_record, + .request = skel_request, .start_transaction = skel_start_trans, .end_transaction = skel_end_trans, .del_transaction = skel_del_trans, |