diff options
author | Matthias Dieter Wallnöfer <mdw@samba.org> | 2010-09-12 13:14:36 +0200 |
---|---|---|
committer | Matthias Dieter Wallnöfer <mdw@samba.org> | 2010-09-12 19:23:05 +0200 |
commit | dad7cdad2261b8b860a67ecfdcb027ff9a7985db (patch) | |
tree | 862b58b8671b65a635b22dc10dc0948f69d5a975 /source4/dsdb | |
parent | 6aca09b0b723d0116c0038e4e43a13a77b68deca (diff) | |
download | samba-dad7cdad2261b8b860a67ecfdcb027ff9a7985db.tar.gz samba-dad7cdad2261b8b860a67ecfdcb027ff9a7985db.tar.bz2 samba-dad7cdad2261b8b860a67ecfdcb027ff9a7985db.zip |
s4:samldb LDB module - refactor "samldb_find_for_defaultObjectCategory" to be again synchronous
Also to make it easier to comprehend
Diffstat (limited to 'source4/dsdb')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/samldb.c | 116 |
1 files changed, 22 insertions, 94 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c index 021be26300..dcf32c490f 100644 --- a/source4/dsdb/samdb/ldb_modules/samldb.c +++ b/source4/dsdb/samdb/ldb_modules/samldb.c @@ -59,11 +59,8 @@ struct samldb_ctx { /* the resulting message */ struct ldb_message *msg; - /* holds a generic dn */ - struct ldb_dn *dn; - /* used in "samldb_find_for_defaultObjectCategory" */ - struct ldb_dn *res_dn; + struct ldb_dn *dn, *res_dn; /* all the async steps necessary to complete the operation */ struct samldb_step *steps; @@ -400,106 +397,37 @@ found: return samldb_next_step(ac); } - -/* - * samldb_find_for_defaultObjectCategory (async) - */ - -static int samldb_find_for_defaultObjectCategory_callback(struct ldb_request *req, - struct ldb_reply *ares) -{ - struct ldb_context *ldb; - struct samldb_ctx *ac; - int ret; - - ac = talloc_get_type(req->context, struct samldb_ctx); - ldb = ldb_module_get_ctx(ac->module); - - if (!ares) { - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - if (ares->error != LDB_SUCCESS) { - if (ares->error == LDB_ERR_NO_SUCH_OBJECT) { - if (ldb_request_get_control(ac->req, - LDB_CONTROL_RELAX_OID) != NULL) { - /* Don't be pricky when the DN doesn't exist */ - /* if we have the RELAX control specified */ - ac->res_dn = req->op.search.base; - return samldb_next_step(ac); - } else { - ldb_set_errstring(ldb, - "samldb_find_defaultObjectCategory: " - "Invalid DN for 'defaultObjectCategory'!"); - ares->error = LDB_ERR_CONSTRAINT_VIOLATION; - } - } - - return ldb_module_done(ac->req, ares->controls, - ares->response, ares->error); - } - - switch (ares->type) { - case LDB_REPLY_ENTRY: - ac->res_dn = talloc_steal(ac, ares->message->dn); - - ret = LDB_SUCCESS; - break; - - case LDB_REPLY_REFERRAL: - /* ignore */ - talloc_free(ares); - ret = LDB_SUCCESS; - break; - - case LDB_REPLY_DONE: - talloc_free(ares); - - if (ac->res_dn != NULL) { - /* when found go on */ - ret = samldb_next_step(ac); - } else { - ret = LDB_ERR_OPERATIONS_ERROR; - } - break; - } - -done: - if (ret != LDB_SUCCESS) { - return ldb_module_done(ac->req, NULL, NULL, ret); - } - - return LDB_SUCCESS; -} - static int samldb_find_for_defaultObjectCategory(struct samldb_ctx *ac) { - struct ldb_context *ldb; - struct ldb_request *req; - static const char *no_attrs[] = { NULL }; + struct ldb_context *ldb = ldb_module_get_ctx(ac->module); + struct ldb_result *res; + const char *no_attrs[] = { NULL }; int ret; - ldb = ldb_module_get_ctx(ac->module); - ac->res_dn = NULL; - ret = ldb_build_search_req(&req, ldb, ac, - ac->dn, LDB_SCOPE_BASE, - "(objectClass=classSchema)", no_attrs, - NULL, ac, - samldb_find_for_defaultObjectCategory_callback, - ac->req); - if (ret != LDB_SUCCESS) { - return ret; + ret = dsdb_module_search(ac->module, ac, &res, + ac->dn, LDB_SCOPE_BASE, no_attrs, + DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT | DSDB_FLAG_NEXT_MODULE, + "(objectClass=classSchema)"); + if (ret == LDB_ERR_NO_SUCH_OBJECT) { + /* Don't be pricky when the DN doesn't exist if we have the */ + /* RELAX control specified */ + if (ldb_request_get_control(ac->req, + LDB_CONTROL_RELAX_OID) == NULL) { + ldb_set_errstring(ldb, + "samldb_find_defaultObjectCategory: " + "Invalid DN for 'defaultObjectCategory'!"); + return LDB_ERR_CONSTRAINT_VIOLATION; + } } - - ret = dsdb_request_add_controls(req, - DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT); - if (ret != LDB_SUCCESS) { + if ((ret != LDB_ERR_NO_SUCH_OBJECT) && (ret != LDB_SUCCESS)) { return ret; } - return ldb_next_request(ac->module, req); + ac->res_dn = ac->dn; + + return samldb_next_step(ac); } /** |