From f84aeea7399eec38f7906dedaf3652af48c3d184 Mon Sep 17 00:00:00 2001 From: Anatoliy Atanasov Date: Tue, 4 May 2010 11:49:18 +0200 Subject: s4/rodc: Support read-only database Check on modify if we are RODC and return referral. On the ldap backend side now we pass context and ldb_modify_default_callback to propagate the referral error to the client. --- source4/lib/ldb/common/ldb.c | 48 +++++++++++++++++++++++++++++++++++++++++++ source4/lib/ldb/include/ldb.h | 1 + 2 files changed, 49 insertions(+) (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index bbb3b79e6c..07aa6d0985 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -903,6 +903,54 @@ int ldb_search_default_callback(struct ldb_request *req, return LDB_SUCCESS; } +int ldb_modify_default_callback(struct ldb_request *req, struct ldb_reply *ares) +{ + struct ldb_result *res; + unsigned int n; + int ret; + + res = talloc_get_type(req->context, struct ldb_result); + + if (!ares) { + return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); + } + + if (ares->error != LDB_SUCCESS) { + ret = ares->error; + talloc_free(ares); + return ldb_request_done(req, ret); + } + + switch (ares->type) { + case LDB_REPLY_REFERRAL: + if (res->refs) { + for (n = 0; res->refs[n]; n++) /*noop*/ ; + } else { + n = 0; + } + + res->refs = talloc_realloc(res, res->refs, char *, n + 2); + if (! res->refs) { + return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); + } + + res->refs[n] = talloc_move(res->refs, &ares->referral); + res->refs[n + 1] = NULL; + break; + + case LDB_REPLY_DONE: + talloc_free(ares); + return ldb_request_done(req, LDB_SUCCESS); + default: + talloc_free(ares); + ldb_set_errstring(req->handle->ldb, "Invalid reply type!"); + return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); + } + + talloc_free(ares); + return ldb_request_done(req, LDB_SUCCESS); +} + int ldb_op_default_callback(struct ldb_request *req, struct ldb_reply *ares) { int ret; diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index fc5d47ac32..b644b995ac 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -1017,6 +1017,7 @@ int ldb_search_default_callback(struct ldb_request *req, struct ldb_reply *ares) */ int ldb_op_default_callback(struct ldb_request *req, struct ldb_reply *ares); +int ldb_modify_default_callback(struct ldb_request *req, struct ldb_reply *ares); /** Helper function to build a search request -- cgit