s4-dsdb: pass parent request to dsdb_module_*() functions
[samba.git] / source4 / dsdb / samdb / ldb_modules / pdc_fsmo.c
index fefaef47551aef422e0ccb8c73167676e452b939..68f181581c9ca49766e15911a799387c8f808358 100644 (file)
@@ -27,6 +27,7 @@
 #include "librpc/gen_ndr/ndr_drsuapi.h"
 #include "librpc/gen_ndr/ndr_drsblobs.h"
 #include "../lib/util/dlinklist.h"
+#include "dsdb/samdb/ldb_modules/util.h"
 
 static int pdc_fsmo_init(struct ldb_module *module)
 {
@@ -45,52 +46,39 @@ static int pdc_fsmo_init(struct ldb_module *module)
 
        mem_ctx = talloc_new(module);
        if (!mem_ctx) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
-       pdc_dn = samdb_base_dn(ldb);
+       pdc_dn = ldb_get_default_basedn(ldb);
        if (!pdc_dn) {
-               ldb_debug(ldb, LDB_DEBUG_WARNING,
-                         "pdc_fsmo_init: no domain dn present: (skip loading of domain details)\n");
+               ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+                         "pdc_fsmo_init: could not determine default basedn");
                talloc_free(mem_ctx);
-               return ldb_next_init(module);
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
        pdc_fsmo = talloc_zero(mem_ctx, struct dsdb_pdc_fsmo);
        if (!pdc_fsmo) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
        ldb_module_set_private(module, pdc_fsmo);
 
-       ret = ldb_search(ldb, mem_ctx, &pdc_res,
-                        pdc_dn, LDB_SCOPE_BASE,
-                        pdc_attrs, NULL);
+       ret = dsdb_module_search_dn(module, mem_ctx, &pdc_res,
+                                   pdc_dn, 
+                                   pdc_attrs,
+                                   DSDB_FLAG_NEXT_MODULE, NULL);
        if (ret == LDB_ERR_NO_SUCH_OBJECT) {
-               ldb_debug(ldb, LDB_DEBUG_WARNING,
-                         "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n");
+               ldb_debug(ldb, LDB_DEBUG_TRACE,
+                         "pdc_fsmo_init: no domain object present: (skip loading of domain details)");
                talloc_free(mem_ctx);
                return ldb_next_init(module);
        } else if (ret != LDB_SUCCESS) {
                ldb_debug_set(ldb, LDB_DEBUG_FATAL,
-                             "pdc_fsmo_init: failed to search the domain object: %d:%s",
-                             ret, ldb_strerror(ret));
+                             "pdc_fsmo_init: failed to search the domain object: %d:%s: %s",
+                             ret, ldb_strerror(ret), ldb_errstring(ldb));
                talloc_free(mem_ctx);
                return ret;
        }
-       if (pdc_res->count == 0) {
-               ldb_debug(ldb, LDB_DEBUG_WARNING,
-                         "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n");
-               talloc_free(mem_ctx);
-               return ldb_next_init(module);
-       } else if (pdc_res->count > 1) {
-               ldb_debug_set(ldb, LDB_DEBUG_FATAL,
-                             "pdc_fsmo_init: [%u] domain objects found on a base search",
-                             pdc_res->count);
-               talloc_free(mem_ctx);
-               return LDB_ERR_CONSTRAINT_VIOLATION;
-       }
 
        pdc_fsmo->master_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, pdc_res->msgs[0], "fSMORoleOwner");
        if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc_fsmo->master_dn) == 0) {
@@ -100,8 +88,7 @@ static int pdc_fsmo_init(struct ldb_module *module)
        }
 
        if (ldb_set_opaque(ldb, "dsdb_pdc_fsmo", pdc_fsmo) != LDB_SUCCESS) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        talloc_steal(module, pdc_fsmo);
@@ -114,7 +101,13 @@ static int pdc_fsmo_init(struct ldb_module *module)
        return ldb_next_init(module);
 }
 
-_PUBLIC_ const struct ldb_module_ops ldb_pdc_fsmo_module_ops = {
+static const struct ldb_module_ops ldb_pdc_fsmo_module_ops = {
        .name           = "pdc_fsmo",
        .init_context   = pdc_fsmo_init
 };
+
+int ldb_pdc_fsmo_module_init(const char *version)
+{
+       LDB_MODULE_CHECK_VERSION(version);
+       return ldb_register_module(&ldb_pdc_fsmo_module_ops);
+}