summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb/ldb_modules
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-01-17 23:58:14 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:43:42 -0500
commitcc6c3eb38c267c7a1f0087bcfdccc01e2164134f (patch)
treed8679e9eeaba3cca94831ffec884ce9d9d98400d /source4/dsdb/samdb/ldb_modules
parentaa2439da359e966df819f5c142c9b1093420db70 (diff)
downloadsamba-cc6c3eb38c267c7a1f0087bcfdccc01e2164134f.tar.gz
samba-cc6c3eb38c267c7a1f0087bcfdccc01e2164134f.tar.bz2
samba-cc6c3eb38c267c7a1f0087bcfdccc01e2164134f.zip
r20867: add modules to handle the domain naming and the pdc FSMO Roles
metze (This used to be commit 341fae8e8465e67023ab0e82110835669a593577)
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules')
-rw-r--r--source4/dsdb/samdb/ldb_modules/config.mk22
-rw-r--r--source4/dsdb/samdb/ldb_modules/naming_fsmo.c121
-rw-r--r--source4/dsdb/samdb/ldb_modules/pdc_fsmo.c120
3 files changed, 263 insertions, 0 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/config.mk b/source4/dsdb/samdb/ldb_modules/config.mk
index 2c84ee0aef..0934b4ca6a 100644
--- a/source4/dsdb/samdb/ldb_modules/config.mk
+++ b/source4/dsdb/samdb/ldb_modules/config.mk
@@ -45,6 +45,28 @@ OBJ_FILES = \
################################################
################################################
+# Start MODULE ldb_naming_fsmo
+[MODULE::ldb_naming_fsmo]
+SUBSYSTEM = ldb
+PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC
+INIT_FUNCTION = naming_fsmo_module_init
+OBJ_FILES = \
+ naming_fsmo.o
+# End MODULE ldb_naming_fsmo
+################################################
+
+################################################
+# Start MODULE ldb_pdc_fsmo
+[MODULE::ldb_pdc_fsmo]
+SUBSYSTEM = ldb
+PRIVATE_DEPENDENCIES = SAMDB LIBTALLOC
+INIT_FUNCTION = pdc_fsmo_module_init
+OBJ_FILES = \
+ pdc_fsmo.o
+# End MODULE ldb_pdc_fsmo
+################################################
+
+################################################
# Start MODULE ldb_samldb
[MODULE::ldb_samldb]
SUBSYSTEM = ldb
diff --git a/source4/dsdb/samdb/ldb_modules/naming_fsmo.c b/source4/dsdb/samdb/ldb_modules/naming_fsmo.c
new file mode 100644
index 0000000000..9041c37ce7
--- /dev/null
+++ b/source4/dsdb/samdb/ldb_modules/naming_fsmo.c
@@ -0,0 +1,121 @@
+/*
+ Unix SMB/CIFS mplementation.
+
+ The module that handles the Domain Naming FSMO Role Owner
+ checkings
+
+ Copyright (C) Stefan Metzmacher 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "includes.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "lib/ldb/include/ldb_private.h"
+#include "dsdb/samdb/samdb.h"
+#include "librpc/gen_ndr/ndr_misc.h"
+#include "librpc/gen_ndr/ndr_drsuapi.h"
+#include "librpc/gen_ndr/ndr_drsblobs.h"
+#include "lib/util/dlinklist.h"
+
+struct dsdb_naming_fsmo {
+ bool we_are_master;
+};
+
+static int naming_fsmo_init(struct ldb_module *module)
+{
+ TALLOC_CTX *mem_ctx;
+ struct ldb_dn *naming_dn;
+ struct dsdb_naming_fsmo *naming_fsmo;
+ struct ldb_result *naming_res;
+ struct ldb_dn *naming_master_dn;
+ int ret;
+ static const char *naming_attrs[] = {
+ "fSMORoleOwner",
+ NULL
+ };
+
+ mem_ctx = talloc_new(module);
+ if (!mem_ctx) {
+ ldb_oom(module->ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ naming_dn = samdb_partitions_dn(module->ldb, mem_ctx);
+ if (!naming_dn) {
+ ldb_debug(module->ldb, LDB_DEBUG_WARNING,
+ "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)\n");
+ talloc_free(mem_ctx);
+ return ldb_next_init(module);
+ }
+
+ naming_fsmo = talloc_zero(mem_ctx, struct dsdb_naming_fsmo);
+ if (!naming_fsmo) {
+ ldb_oom(module->ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ module->private_data = naming_fsmo;
+
+ ret = ldb_search(module->ldb, naming_dn,
+ LDB_SCOPE_BASE,
+ NULL, naming_attrs,
+ &naming_res);
+ if (ret != LDB_SUCCESS) {
+ ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
+ "naming_fsmo_init: failed to search the cross-ref container: %d:%s\n",
+ ret, ldb_strerror(ret));
+ talloc_free(mem_ctx);
+ return ret;
+ }
+ talloc_steal(mem_ctx, naming_res);
+ if (naming_res->count == 0) {
+ ldb_debug(module->ldb, LDB_DEBUG_WARNING,
+ "naming_fsmo_init: no cross-ref container present: (skip loading of naming contexts details)\n");
+ talloc_free(mem_ctx);
+ return ldb_next_init(module);
+ } else if (naming_res->count > 1) {
+ ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
+ "naming_fsmo_init: [%u] cross-ref containers found on a base search\n",
+ naming_res->count);
+ talloc_free(mem_ctx);
+ return LDB_ERR_CONSTRAINT_VIOLATION;
+ }
+
+ naming_master_dn = ldb_msg_find_attr_as_dn(module->ldb, mem_ctx, naming_res->msgs[0], "fSMORoleOwner");
+ if (ldb_dn_compare(samdb_ntds_settings_dn(module->ldb), naming_master_dn) == 0) {
+ naming_fsmo->we_are_master = true;
+ } else {
+ naming_fsmo->we_are_master = false;
+ }
+
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE,
+ "naming_fsmo_init: we are master: %s\n",
+ (naming_fsmo->we_are_master?"yes":"no"));
+
+ talloc_free(mem_ctx);
+ return ldb_next_init(module);
+}
+
+static const struct ldb_module_ops naming_fsmo_ops = {
+ .name = "naming_fsmo",
+ .init_context = naming_fsmo_init
+};
+
+int naming_fsmo_module_init(void)
+{
+ return ldb_register_module(&naming_fsmo_ops);
+}
diff --git a/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c b/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c
new file mode 100644
index 0000000000..16b40ef8d9
--- /dev/null
+++ b/source4/dsdb/samdb/ldb_modules/pdc_fsmo.c
@@ -0,0 +1,120 @@
+/*
+ Unix SMB/CIFS mplementation.
+
+ The module that handles the PDC FSMO Role Owner checkings
+
+ Copyright (C) Stefan Metzmacher 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "includes.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "lib/ldb/include/ldb_private.h"
+#include "dsdb/samdb/samdb.h"
+#include "librpc/gen_ndr/ndr_misc.h"
+#include "librpc/gen_ndr/ndr_drsuapi.h"
+#include "librpc/gen_ndr/ndr_drsblobs.h"
+#include "lib/util/dlinklist.h"
+
+struct dsdb_pdc_fsmo {
+ bool we_are_master;
+};
+
+static int pdc_fsmo_init(struct ldb_module *module)
+{
+ TALLOC_CTX *mem_ctx;
+ struct ldb_dn *pdc_dn;
+ struct dsdb_pdc_fsmo *pdc_fsmo;
+ struct ldb_result *pdc_res;
+ struct ldb_dn *pdc_master_dn;
+ int ret;
+ static const char *pdc_attrs[] = {
+ "fSMORoleOwner",
+ NULL
+ };
+
+ mem_ctx = talloc_new(module);
+ if (!mem_ctx) {
+ ldb_oom(module->ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ pdc_dn = samdb_base_dn(module->ldb);
+ if (!pdc_dn) {
+ ldb_debug(module->ldb, LDB_DEBUG_WARNING,
+ "pdc_fsmo_init: no domain dn present: (skip loading of domain details)\n");
+ talloc_free(mem_ctx);
+ return ldb_next_init(module);
+ }
+
+ pdc_fsmo = talloc_zero(mem_ctx, struct dsdb_pdc_fsmo);
+ if (!pdc_fsmo) {
+ ldb_oom(module->ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ module->private_data = pdc_fsmo;
+
+ ret = ldb_search(module->ldb, pdc_dn,
+ LDB_SCOPE_BASE,
+ NULL, pdc_attrs,
+ &pdc_res);
+ if (ret != LDB_SUCCESS) {
+ ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
+ "pdc_fsmo_init: failed to search the domain object: %d:%s\n",
+ ret, ldb_strerror(ret));
+ talloc_free(mem_ctx);
+ return ret;
+ }
+ talloc_steal(mem_ctx, pdc_res);
+ if (pdc_res->count == 0) {
+ ldb_debug(module->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(module->ldb, LDB_DEBUG_FATAL,
+ "pdc_fsmo_init: [%u] domain objects found on a base search\n",
+ pdc_res->count);
+ talloc_free(mem_ctx);
+ return LDB_ERR_CONSTRAINT_VIOLATION;
+ }
+
+ pdc_master_dn = ldb_msg_find_attr_as_dn(module->ldb, mem_ctx, pdc_res->msgs[0], "fSMORoleOwner");
+ if (ldb_dn_compare(samdb_ntds_settings_dn(module->ldb), pdc_master_dn) == 0) {
+ pdc_fsmo->we_are_master = true;
+ } else {
+ pdc_fsmo->we_are_master = false;
+ }
+
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE,
+ "pdc_fsmo_init: we are master: %s\n",
+ (pdc_fsmo->we_are_master?"yes":"no"));
+
+ talloc_free(mem_ctx);
+ return ldb_next_init(module);
+}
+
+static const struct ldb_module_ops pdc_fsmo_ops = {
+ .name = "pdc_fsmo",
+ .init_context = pdc_fsmo_init
+};
+
+int pdc_fsmo_module_init(void)
+{
+ return ldb_register_module(&pdc_fsmo_ops);
+}