diff options
Diffstat (limited to 'source3/lib/ldb/common/ldb.c')
-rw-r--r-- | source3/lib/ldb/common/ldb.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/source3/lib/ldb/common/ldb.c b/source3/lib/ldb/common/ldb.c index 7648abf795..9e0ee6ebca 100644 --- a/source3/lib/ldb/common/ldb.c +++ b/source3/lib/ldb/common/ldb.c @@ -522,7 +522,7 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req) Use talloc_free to free the ldb_message returned in 'res', if successful */ -static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) +int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { struct ldb_result *res; int n; @@ -532,12 +532,13 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld return LDB_ERR_OPERATIONS_ERROR; } - res = *((struct ldb_result **)context); + res = talloc_get_type(context, struct ldb_result); if (!res || !ares) { + ldb_set_errstring(ldb, "NULL res or ares in callback"); goto error; } - + switch (ares->type) { case LDB_REPLY_ENTRY: res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2); @@ -564,19 +565,17 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld res->refs[n] = talloc_move(res->refs, &ares->referral); res->refs[n + 1] = NULL; + case LDB_REPLY_EXTENDED: case LDB_REPLY_DONE: - /* Should do something here to detect if this never - * happens */ + /* TODO: we should really support controls on entries and referrals too! */ + res->controls = talloc_move(res, &ares->controls); break; } - talloc_steal(res, ares->controls); talloc_free(ares); return LDB_SUCCESS; error: talloc_free(ares); - talloc_free(res); - *((struct ldb_result **)context) = NULL; return LDB_ERR_OPERATIONS_ERROR; } @@ -752,16 +751,19 @@ int ldb_search(struct ldb_context *ldb, enum ldb_scope scope, const char *expression, const char * const *attrs, - struct ldb_result **res) + struct ldb_result **_res) { struct ldb_request *req; int ret; + struct ldb_result *res; + + *_res = NULL; - *res = talloc_zero(ldb, struct ldb_result); - if (! *res) { + res = talloc_zero(ldb, struct ldb_result); + if (!res) { return LDB_ERR_OPERATIONS_ERROR; } - + ret = ldb_build_search_req(&req, ldb, ldb, base?base:ldb_get_default_basedn(ldb), scope, @@ -769,7 +771,7 @@ int ldb_search(struct ldb_context *ldb, attrs, NULL, res, - ldb_search_callback); + ldb_search_default_callback); if (ret != LDB_SUCCESS) goto done; @@ -785,10 +787,10 @@ int ldb_search(struct ldb_context *ldb, done: if (ret != LDB_SUCCESS) { - talloc_free(*res); - *res = NULL; + talloc_free(res); } + *_res = res; return ret; } |