2 Unix SMB/CIFS mplementation.
4 The module that handles the PDC FSMO Role Owner checkings
6 Copyright (C) Stefan Metzmacher 2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "lib/ldb/include/ldb.h"
26 #include "lib/ldb/include/ldb_errors.h"
27 #include "lib/ldb/include/ldb_private.h"
28 #include "dsdb/samdb/samdb.h"
29 #include "librpc/gen_ndr/ndr_misc.h"
30 #include "librpc/gen_ndr/ndr_drsuapi.h"
31 #include "librpc/gen_ndr/ndr_drsblobs.h"
32 #include "lib/util/dlinklist.h"
34 static int pdc_fsmo_init(struct ldb_module *module)
37 struct ldb_dn *pdc_dn;
38 struct dsdb_pdc_fsmo *pdc_fsmo;
39 struct ldb_result *pdc_res;
41 static const char *pdc_attrs[] = {
46 mem_ctx = talloc_new(module);
49 return LDB_ERR_OPERATIONS_ERROR;
52 pdc_dn = samdb_base_dn(module->ldb);
54 ldb_debug(module->ldb, LDB_DEBUG_WARNING,
55 "pdc_fsmo_init: no domain dn present: (skip loading of domain details)\n");
57 return ldb_next_init(module);
60 pdc_fsmo = talloc_zero(mem_ctx, struct dsdb_pdc_fsmo);
63 return LDB_ERR_OPERATIONS_ERROR;
65 module->private_data = pdc_fsmo;
67 ret = ldb_search(module->ldb, pdc_dn,
71 if (ret != LDB_SUCCESS) {
72 ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
73 "pdc_fsmo_init: failed to search the domain object: %d:%s\n",
74 ret, ldb_strerror(ret));
78 talloc_steal(mem_ctx, pdc_res);
79 if (pdc_res->count == 0) {
80 ldb_debug(module->ldb, LDB_DEBUG_WARNING,
81 "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n");
83 return ldb_next_init(module);
84 } else if (pdc_res->count > 1) {
85 ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
86 "pdc_fsmo_init: [%u] domain objects found on a base search\n",
89 return LDB_ERR_CONSTRAINT_VIOLATION;
92 pdc_fsmo->master_dn = ldb_msg_find_attr_as_dn(module->ldb, mem_ctx, pdc_res->msgs[0], "fSMORoleOwner");
93 if (ldb_dn_compare(samdb_ntds_settings_dn(module->ldb), pdc_fsmo->master_dn) == 0) {
94 pdc_fsmo->we_are_master = true;
96 pdc_fsmo->we_are_master = false;
99 if (ldb_set_opaque(module->ldb, "dsdb_pdc_fsmo", pdc_fsmo) != LDB_SUCCESS) {
100 ldb_oom(module->ldb);
101 return LDB_ERR_OPERATIONS_ERROR;
104 talloc_steal(module, pdc_fsmo);
106 ldb_debug(module->ldb, LDB_DEBUG_TRACE,
107 "pdc_fsmo_init: we are master: %s\n",
108 (pdc_fsmo->we_are_master?"yes":"no"));
110 talloc_free(mem_ctx);
111 return ldb_next_init(module);
114 static const struct ldb_module_ops pdc_fsmo_ops = {
116 .init_context = pdc_fsmo_init
119 int pdc_fsmo_module_init(void)
121 return ldb_register_module(&pdc_fsmo_ops);