dsdb: Fix dsdb_next_callback to correctly use ldb_module_done() etc
[kai/samba-autobuild/.git] / source4 / dsdb / samdb / ldb_modules / util.c
index 36d35b7094a0c60c68d86a753bf9a082f6332ebb..9e37c085bbadd72c181526847f0ac3aac61cb88c 100644 (file)
@@ -832,8 +832,29 @@ int dsdb_next_callback(struct ldb_request *req, struct ldb_reply *ares)
 {
        struct ldb_request *up_req = talloc_get_type(req->context, struct ldb_request);
 
-       talloc_steal(up_req, req);
-       return up_req->callback(up_req, ares);
+       if (!ares) {
+               return ldb_module_done(up_req, NULL, NULL,
+                                      LDB_ERR_OPERATIONS_ERROR);
+       }
+
+       if (ares->error != LDB_SUCCESS || ares->type == LDB_REPLY_DONE) {
+               return ldb_module_done(up_req, ares->controls,
+                                      ares->response, ares->error);
+       }
+
+       /* Otherwise pass on the callback */
+       switch (ares->type) {
+       case LDB_REPLY_ENTRY:
+               return ldb_module_send_entry(up_req, ares->message,
+                                            ares->controls);
+
+       case LDB_REPLY_REFERRAL:
+               return ldb_module_send_referral(up_req,
+                                               ares->referral);
+       default:
+               /* Can't happen */
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
 }
 
 /*