s4-ldb: use TALLOC_CTX type instead of 'void'
[kamenim/samba.git] / source4 / lib / ldb / common / ldb.c
index f1b28b6819b7cb20152d44a232b5d4c3d2d1ea79..dbb0089db495ec6762dacdbef7b5562d7cc6abed 100644 (file)
@@ -32,6 +32,7 @@
  *  Author: Andrew Tridgell
  */
 
+#define TEVENT_DEPRECATED 1
 #include "ldb_private.h"
 
 static int ldb_context_destructor(void *ptr)
@@ -40,13 +41,47 @@ static int ldb_context_destructor(void *ptr)
 
        if (ldb->transaction_active) {
                ldb_debug(ldb, LDB_DEBUG_FATAL,
-                         "A transaction is still active in ldb context [%p]",
-                         ldb);
+                         "A transaction is still active in ldb context [%p] on %s",
+                         ldb, (const char *)ldb_get_opaque(ldb, "ldb_url"));
        }
 
        return 0;
 }
 
+/*
+  this is used to catch debug messages from events
+*/
+static void ldb_tevent_debug(void *context, enum tevent_debug_level level,
+                            const char *fmt, va_list ap)  PRINTF_ATTRIBUTE(3,0);
+
+static void ldb_tevent_debug(void *context, enum tevent_debug_level level,
+                            const char *fmt, va_list ap)
+{
+       struct ldb_context *ldb = talloc_get_type(context, struct ldb_context);
+       enum ldb_debug_level ldb_level = LDB_DEBUG_FATAL;
+       char *s = NULL;
+
+       switch (level) {
+       case TEVENT_DEBUG_FATAL:
+               ldb_level = LDB_DEBUG_FATAL;
+               break;
+       case TEVENT_DEBUG_ERROR:
+               ldb_level = LDB_DEBUG_ERROR;
+               break;
+       case TEVENT_DEBUG_WARNING:
+               ldb_level = LDB_DEBUG_WARNING;
+               break;
+       case TEVENT_DEBUG_TRACE:
+               ldb_level = LDB_DEBUG_TRACE;
+               break;
+       };
+
+       vasprintf(&s, fmt, ap);
+       if (!s) return;
+       ldb_debug(ldb, ldb_level, "tevent: %s", s);
+       free(s);
+}
+
 /*
    initialise a ldb context
    The mem_ctx is required
@@ -62,10 +97,12 @@ struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx)
         * until we have them all converted */
        if (ev_ctx == NULL) {
                ev_ctx = tevent_context_init(talloc_autofree_context());
+               tevent_set_debug(ev_ctx, ldb_tevent_debug, ldb);
+               tevent_loop_allow_nesting(ev_ctx);
        }
 
        ret = ldb_setup_wellknown_attributes(ldb);
-       if (ret != 0) {
+       if (ret != LDB_SUCCESS) {
                talloc_free(ldb);
                return NULL;
        }
@@ -180,7 +217,7 @@ int ldb_connect(struct ldb_context *ldb, const char *url,
                unsigned int flags, const char *options[])
 {
        int ret;
-       const char *url2;
+       char *url2;
        /* We seem to need to do this here, or else some utilities don't
         * get ldb backends */
 
@@ -191,7 +228,7 @@ int ldb_connect(struct ldb_context *ldb, const char *url,
                ldb_oom(ldb);
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       ret = ldb_set_opaque(ldb, "ldb_url", talloc_strdup(ldb, url2));
+       ret = ldb_set_opaque(ldb, "ldb_url", url2);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -203,7 +240,7 @@ int ldb_connect(struct ldb_context *ldb, const char *url,
 
        if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
                ldb_debug(ldb, LDB_DEBUG_FATAL,
-                         "Unable to load modules for %s: %s\n",
+                         "Unable to load modules for %s: %s",
                          url, ldb_errstring(ldb));
                return LDB_ERR_OTHER;
        }
@@ -220,6 +257,9 @@ void ldb_set_errstring(struct ldb_context *ldb, const char *err_string)
                talloc_free(ldb->err_string);
        }
        ldb->err_string = talloc_strdup(ldb, err_string);
+       if (ldb->flags & LDB_FLG_ENABLE_TRACING) {
+               ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_set_errstring: %s", ldb->err_string);
+       }
 }
 
 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...)
@@ -245,15 +285,40 @@ void ldb_reset_err_string(struct ldb_context *ldb)
        }
 }
 
-#define FIRST_OP(ldb, op) do { \
+
+
+/*
+  set an ldb error based on file:line
+*/
+int ldb_error_at(struct ldb_context *ldb, int ecode,
+                const char *reason, const char *file, int line)
+{
+       if (reason == NULL) {
+               reason = ldb_strerror(ecode);
+       }
+       ldb_asprintf_errstring(ldb, "%s at %s:%d", reason, file, line);
+       return ecode;
+}
+
+
+#define FIRST_OP_NOERR(ldb, op) do { \
        module = ldb->modules;                                  \
        while (module && module->ops->op == NULL) module = module->next; \
-       if (module == NULL) {                                           \
+       if ((ldb->flags & LDB_FLG_ENABLE_TRACING) && module) { \
+               ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_trace_request: (%s)->" #op, \
+                         module->ops->name);                           \
+       }                                                               \
+} while (0)
+
+#define FIRST_OP(ldb, op) do { \
+       FIRST_OP_NOERR(ldb, op); \
+       if (module == NULL) {                                   \
                ldb_asprintf_errstring(ldb, "unable to find module or backend to handle operation: " #op); \
                return LDB_ERR_OPERATIONS_ERROR;                        \
        } \
 } while (0)
 
+
 /*
   start a transaction
 */
@@ -274,6 +339,7 @@ int ldb_transaction_start(struct ldb_context *ldb)
 
        /* start a new transaction */
        ldb->transaction_active++;
+       ldb->prepare_commit_done = false;
 
        FIRST_OP(ldb, start_transaction);
 
@@ -289,9 +355,68 @@ int ldb_transaction_start(struct ldb_context *ldb)
                                status);
                }
        }
+       if ((module && module->ldb->flags & LDB_FLG_ENABLE_TRACING)) { 
+               ldb_debug(module->ldb, LDB_DEBUG_TRACE, "start ldb transaction error: %s", 
+                         ldb_errstring(module->ldb));                          
+       }
+       return status;
+}
+
+/*
+  prepare for transaction commit (first phase of two phase commit)
+*/
+int ldb_transaction_prepare_commit(struct ldb_context *ldb)
+{
+       struct ldb_module *module;
+       int status;
+
+       if (ldb->prepare_commit_done) {
+               return LDB_SUCCESS;
+       }
+
+       /* commit only when all nested transactions are complete */
+       if (ldb->transaction_active > 1) {
+               return LDB_SUCCESS;
+       }
+
+       ldb->prepare_commit_done = true;
+
+       if (ldb->transaction_active < 0) {
+               ldb_debug(ldb, LDB_DEBUG_FATAL,
+                         "prepare commit called but no ldb transactions are active!");
+               ldb->transaction_active = 0;
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       /* call prepare transaction if available */
+       FIRST_OP_NOERR(ldb, prepare_commit);
+       if (module == NULL) {
+               return LDB_SUCCESS;
+       }
+
+       status = module->ops->prepare_commit(module);
+       if (status != LDB_SUCCESS) {
+               /* if a module fails the prepare then we need
+                  to call the end transaction for everyone */
+               FIRST_OP(ldb, del_transaction);
+               module->ops->del_transaction(module);
+               if (ldb->err_string == NULL) {
+                       /* no error string was setup by the backend */
+                       ldb_asprintf_errstring(ldb,
+                                              "ldb transaction prepare commit: %s (%d)",
+                                              ldb_strerror(status),
+                                              status);
+               }
+               if ((module && module->ldb->flags & LDB_FLG_ENABLE_TRACING)) { 
+                       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "prepare commit transaction error: %s", 
+                                 ldb_errstring(module->ldb));                          
+               }
+       }
+
        return status;
 }
 
+
 /*
   commit a transaction
 */
@@ -300,6 +425,11 @@ int ldb_transaction_commit(struct ldb_context *ldb)
        struct ldb_module *module;
        int status;
 
+       status = ldb_transaction_prepare_commit(ldb);
+       if (status != LDB_SUCCESS) {
+               return status;
+       }
+
        ldb->transaction_active--;
 
        ldb_debug(ldb, LDB_DEBUG_TRACE,
@@ -318,10 +448,9 @@ int ldb_transaction_commit(struct ldb_context *ldb)
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       FIRST_OP(ldb, end_transaction);
-
        ldb_reset_err_string(ldb);
 
+       FIRST_OP(ldb, end_transaction);
        status = module->ops->end_transaction(module);
        if (status != LDB_SUCCESS) {
                if (ldb->err_string == NULL) {
@@ -331,10 +460,18 @@ int ldb_transaction_commit(struct ldb_context *ldb)
                                ldb_strerror(status),
                                status);
                }
+               if ((module && module->ldb->flags & LDB_FLG_ENABLE_TRACING)) { 
+                       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "commit ldb transaction error: %s", 
+                                 ldb_errstring(module->ldb));                          
+               }
+               /* cancel the transaction */
+               FIRST_OP(ldb, del_transaction);
+               module->ops->del_transaction(module);
        }
        return status;
 }
 
+
 /*
   cancel a transaction
 */
@@ -356,7 +493,7 @@ int ldb_transaction_cancel(struct ldb_context *ldb)
 
        if (ldb->transaction_active < 0) {
                ldb_debug(ldb, LDB_DEBUG_FATAL,
-                         "commit called but no ldb transactions are active!");
+                         "cancel called but no ldb transactions are active!");
                ldb->transaction_active = 0;
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -372,10 +509,27 @@ int ldb_transaction_cancel(struct ldb_context *ldb)
                                ldb_strerror(status),
                                status);
                }
+               if ((module && module->ldb->flags & LDB_FLG_ENABLE_TRACING)) { 
+                       ldb_debug(module->ldb, LDB_DEBUG_TRACE, "cancel ldb transaction error: %s", 
+                                 ldb_errstring(module->ldb));                          
+               }
        }
        return status;
 }
 
+/*
+  cancel a transaction with no error if no transaction is pending
+  used when we fork() to clear any parent transactions
+*/
+int ldb_transaction_cancel_noerr(struct ldb_context *ldb)
+{
+       if (ldb->transaction_active > 0) {
+               return ldb_transaction_cancel(ldb);
+       }
+       return LDB_SUCCESS;
+}
+
+
 /* autostarts a transacion if none active */
 static int ldb_autotransaction_request(struct ldb_context *ldb,
                                       struct ldb_request *req)
@@ -520,6 +674,99 @@ int ldb_request_get_status(struct ldb_request *req)
        return req->handle->status;
 }
 
+
+/*
+  trace a ldb request
+*/
+static void ldb_trace_request(struct ldb_context *ldb, struct ldb_request *req)
+{
+       TALLOC_CTX *tmp_ctx = talloc_new(req);
+       unsigned int i;
+
+       switch (req->operation) {
+       case LDB_SEARCH:
+               ldb_debug_add(ldb, "ldb_trace_request: SEARCH\n");
+               ldb_debug_add(ldb, " dn: %s\n",
+                             ldb_dn_is_null(req->op.search.base)?"<rootDSE>":
+                             ldb_dn_get_linearized(req->op.search.base));
+               ldb_debug_add(ldb, " scope: %s\n", 
+                         req->op.search.scope==LDB_SCOPE_BASE?"base":
+                         req->op.search.scope==LDB_SCOPE_ONELEVEL?"one":
+                         req->op.search.scope==LDB_SCOPE_SUBTREE?"sub":"UNKNOWN");
+               ldb_debug_add(ldb, " expr: %s\n", 
+                         ldb_filter_from_tree(tmp_ctx, req->op.search.tree));
+               if (req->op.search.attrs == NULL) {
+                       ldb_debug_add(ldb, " attr: <ALL>\n");
+               } else {
+                       for (i=0; req->op.search.attrs[i]; i++) {
+                               ldb_debug_add(ldb, " attr: %s\n", req->op.search.attrs[i]);
+                       }
+               }
+               break;
+       case LDB_DELETE:
+               ldb_debug_add(ldb, "ldb_trace_request: DELETE\n");
+               ldb_debug_add(ldb, " dn: %s\n", 
+                             ldb_dn_get_linearized(req->op.del.dn));
+               break;
+       case LDB_RENAME:
+               ldb_debug_add(ldb, "ldb_trace_request: RENAME\n");
+               ldb_debug_add(ldb, " olddn: %s\n", 
+                             ldb_dn_get_linearized(req->op.rename.olddn));
+               ldb_debug_add(ldb, " newdn: %s\n", 
+                             ldb_dn_get_linearized(req->op.rename.newdn));
+               break;
+       case LDB_EXTENDED:
+               ldb_debug_add(ldb, "ldb_trace_request: EXTENDED\n");
+               ldb_debug_add(ldb, " oid: %s\n", req->op.extended.oid);
+               ldb_debug_add(ldb, " data: %s\n", req->op.extended.data?"yes":"no");
+               break;
+       case LDB_ADD:
+               ldb_debug_add(ldb, "ldb_trace_request: ADD\n");
+               ldb_debug_add(req->handle->ldb, "%s\n", 
+                             ldb_ldif_message_string(req->handle->ldb, tmp_ctx, 
+                                                     LDB_CHANGETYPE_ADD, 
+                                                     req->op.add.message));
+               break;
+       case LDB_MODIFY:
+               ldb_debug_add(ldb, "ldb_trace_request: MODIFY\n");
+               ldb_debug_add(req->handle->ldb, "%s\n", 
+                             ldb_ldif_message_string(req->handle->ldb, tmp_ctx, 
+                                                     LDB_CHANGETYPE_ADD, 
+                                                     req->op.mod.message));
+               break;
+       case LDB_REQ_REGISTER_CONTROL:
+               ldb_debug_add(ldb, "ldb_trace_request: REGISTER_CONTROL\n");
+               ldb_debug_add(req->handle->ldb, "%s\n", 
+                             req->op.reg_control.oid);
+               break;
+       case LDB_REQ_REGISTER_PARTITION:
+               ldb_debug_add(ldb, "ldb_trace_request: REGISTER_PARTITION\n");
+               ldb_debug_add(req->handle->ldb, "%s\n", 
+                             ldb_dn_get_linearized(req->op.reg_partition.dn));
+               break;
+       default:
+               ldb_debug_add(ldb, "ldb_trace_request: UNKNOWN(%u)\n", 
+                             req->operation);
+               break;
+       }
+
+       if (req->controls == NULL) {
+               ldb_debug_add(ldb, " control: <NONE>\n");
+       } else {
+               for (i=0; req->controls && req->controls[i]; i++) {
+                       ldb_debug_add(ldb, " control: %s  crit:%u  data:%s\n", 
+                                     req->controls[i]->oid, 
+                                     req->controls[i]->critical, 
+                                     req->controls[i]->data?"yes":"no");
+               }
+       }
+       
+       ldb_debug_end(ldb, LDB_DEBUG_TRACE);
+
+       talloc_free(tmp_ctx);
+}
+
+
 /*
   start an ldb request
   NOTE: the request must be a talloc context.
@@ -537,6 +784,10 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
 
        ldb_reset_err_string(ldb);
 
+       if (ldb->flags & LDB_FLG_ENABLE_TRACING) {
+               ldb_trace_request(ldb, req);
+       }
+
        /* call the first module in the chain */
        switch (req->operation) {
        case LDB_SEARCH:
@@ -544,6 +795,15 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
                ret = module->ops->search(module, req);
                break;
        case LDB_ADD:
+               /* we have to canonicalise here, as so many places
+                * in modules and backends assume we don't have two
+                * elements with the same name */
+               req->op.add.message = ldb_msg_canonicalize(ldb, req->op.add.message);
+               if (!req->op.add.message) {
+                       ldb_oom(ldb);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+               talloc_steal(req, req->op.add.message);
                FIRST_OP(ldb, add);
                ret = module->ops->add(module, req);
                break;
@@ -556,6 +816,16 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
                ret = module->ops->del(module, req);
                break;
        case LDB_RENAME:
+               if (!ldb_dn_validate(req->op.rename.olddn)) {
+                       ldb_asprintf_errstring(ldb, "ldb_rename: invalid olddn '%s'",
+                                              ldb_dn_get_linearized(req->op.rename.olddn));
+                       return LDB_ERR_INVALID_DN_SYNTAX;
+               }
+               if (!ldb_dn_validate(req->op.rename.newdn)) {
+                       ldb_asprintf_errstring(ldb, "ldb_rename: invalid newdn '%s'",
+                                              ldb_dn_get_linearized(req->op.rename.newdn));
+                       return LDB_ERR_INVALID_DN_SYNTAX;
+               }
                FIRST_OP(ldb, rename);
                ret = module->ops->rename(module, req);
                break;
@@ -591,7 +861,7 @@ int ldb_search_default_callback(struct ldb_request *req,
                                struct ldb_reply *ares)
 {
        struct ldb_result *res;
-       int n;
+       unsigned int n;
 
        res = talloc_get_type(req->context, struct ldb_result);
 
@@ -640,13 +910,63 @@ int ldb_search_default_callback(struct ldb_request *req,
                /* this is the last message, and means the request is done */
                /* we have to signal and eventual ldb_wait() waiting that the
                 * async request operation was completed */
+               talloc_free(ares);
                return ldb_request_done(req, LDB_SUCCESS);
        }
 
        talloc_free(ares);
+
        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;
@@ -673,7 +993,7 @@ int ldb_op_default_callback(struct ldb_request *req, struct ldb_reply *ares)
 
 int ldb_build_search_req_ex(struct ldb_request **ret_req,
                        struct ldb_context *ldb,
-                       void *mem_ctx,
+                       TALLOC_CTX *mem_ctx,
                        struct ldb_dn *base,
                        enum ldb_scope scope,
                        struct ldb_parse_tree *tree,
@@ -721,13 +1041,17 @@ int ldb_build_search_req_ex(struct ldb_request **ret_req,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (parent) {
+               req->handle->nesting++;
+       }
+
        *ret_req = req;
        return LDB_SUCCESS;
 }
 
 int ldb_build_search_req(struct ldb_request **ret_req,
                        struct ldb_context *ldb,
-                       void *mem_ctx,
+                       TALLOC_CTX *mem_ctx,
                        struct ldb_dn *base,
                        enum ldb_scope scope,
                        const char *expression,
@@ -757,7 +1081,7 @@ int ldb_build_search_req(struct ldb_request **ret_req,
 
 int ldb_build_add_req(struct ldb_request **ret_req,
                        struct ldb_context *ldb,
-                       void *mem_ctx,
+                       TALLOC_CTX *mem_ctx,
                        const struct ldb_message *message,
                        struct ldb_control **controls,
                        void *context,
@@ -788,6 +1112,10 @@ int ldb_build_add_req(struct ldb_request **ret_req,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (parent) {
+               req->handle->nesting++;
+       }
+
        *ret_req = req;
 
        return LDB_SUCCESS;
@@ -795,7 +1123,7 @@ int ldb_build_add_req(struct ldb_request **ret_req,
 
 int ldb_build_mod_req(struct ldb_request **ret_req,
                        struct ldb_context *ldb,
-                       void *mem_ctx,
+                       TALLOC_CTX *mem_ctx,
                        const struct ldb_message *message,
                        struct ldb_control **controls,
                        void *context,
@@ -826,6 +1154,10 @@ int ldb_build_mod_req(struct ldb_request **ret_req,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (parent) {
+               req->handle->nesting++;
+       }
+
        *ret_req = req;
 
        return LDB_SUCCESS;
@@ -833,7 +1165,7 @@ int ldb_build_mod_req(struct ldb_request **ret_req,
 
 int ldb_build_del_req(struct ldb_request **ret_req,
                        struct ldb_context *ldb,
-                       void *mem_ctx,
+                       TALLOC_CTX *mem_ctx,
                        struct ldb_dn *dn,
                        struct ldb_control **controls,
                        void *context,
@@ -864,6 +1196,10 @@ int ldb_build_del_req(struct ldb_request **ret_req,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (parent) {
+               req->handle->nesting++;
+       }
+
        *ret_req = req;
 
        return LDB_SUCCESS;
@@ -871,7 +1207,7 @@ int ldb_build_del_req(struct ldb_request **ret_req,
 
 int ldb_build_rename_req(struct ldb_request **ret_req,
                        struct ldb_context *ldb,
-                       void *mem_ctx,
+                       TALLOC_CTX *mem_ctx,
                        struct ldb_dn *olddn,
                        struct ldb_dn *newdn,
                        struct ldb_control **controls,
@@ -904,6 +1240,10 @@ int ldb_build_rename_req(struct ldb_request **ret_req,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (parent) {
+               req->handle->nesting++;
+       }
+
        *ret_req = req;
 
        return LDB_SUCCESS;
@@ -940,7 +1280,7 @@ int ldb_extended_default_callback(struct ldb_request *req,
 
 int ldb_build_extended_req(struct ldb_request **ret_req,
                           struct ldb_context *ldb,
-                          void *mem_ctx,
+                          TALLOC_CTX *mem_ctx,
                           const char *oid,
                           void *data,
                           struct ldb_control **controls,
@@ -973,6 +1313,10 @@ int ldb_build_extended_req(struct ldb_request **ret_req,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (parent) {
+               req->handle->nesting++;
+       }
+
        *ret_req = req;
 
        return LDB_SUCCESS;
@@ -1393,3 +1737,21 @@ void *ldb_get_opaque(struct ldb_context *ldb, const char *name)
        }
        return NULL;
 }
+
+int ldb_global_init(void)
+{
+       /* Provided for compatibility with some older versions of ldb */
+       return 0;
+}
+
+/* return the ldb flags */
+unsigned int ldb_get_flags(struct ldb_context *ldb)
+{
+       return ldb->flags;
+}
+
+/* set the ldb flags */
+void ldb_set_flags(struct ldb_context *ldb, unsigned flags)
+{
+       ldb->flags = flags;
+}