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 3 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, see <http://www.gnu.org/licenses/>.
24 #include "ldb_module.h"
25 #include "dsdb/samdb/samdb.h"
26 #include "librpc/gen_ndr/ndr_misc.h"
27 #include "librpc/gen_ndr/ndr_drsuapi.h"
28 #include "librpc/gen_ndr/ndr_drsblobs.h"
29 #include "../lib/util/dlinklist.h"
30 #include "dsdb/samdb/ldb_modules/util.h"
32 static int pdc_fsmo_init(struct ldb_module *module)
34 struct ldb_context *ldb;
36 struct ldb_dn *pdc_dn;
37 struct dsdb_pdc_fsmo *pdc_fsmo;
38 struct ldb_result *pdc_res;
40 static const char *pdc_attrs[] = {
45 ldb = ldb_module_get_ctx(module);
47 mem_ctx = talloc_new(module);
50 return LDB_ERR_OPERATIONS_ERROR;
53 pdc_dn = samdb_base_dn(ldb);
55 ldb_debug(ldb, LDB_DEBUG_WARNING,
56 "pdc_fsmo_init: no domain dn present: (skip loading of domain details)\n");
58 return ldb_next_init(module);
61 pdc_fsmo = talloc_zero(mem_ctx, struct dsdb_pdc_fsmo);
64 return LDB_ERR_OPERATIONS_ERROR;
66 ldb_module_set_private(module, pdc_fsmo);
68 ret = dsdb_module_search_dn(module, mem_ctx, &pdc_res,
71 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
72 ldb_debug(ldb, LDB_DEBUG_WARNING,
73 "pdc_fsmo_init: no domain object present: (skip loading of domain details)\n");
75 return ldb_next_init(module);
76 } else if (ret != LDB_SUCCESS) {
77 ldb_debug_set(ldb, LDB_DEBUG_FATAL,
78 "pdc_fsmo_init: failed to search the domain object: %d:%s",
79 ret, ldb_strerror(ret));
84 pdc_fsmo->master_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, pdc_res->msgs[0], "fSMORoleOwner");
85 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc_fsmo->master_dn) == 0) {
86 pdc_fsmo->we_are_master = true;
88 pdc_fsmo->we_are_master = false;
91 if (ldb_set_opaque(ldb, "dsdb_pdc_fsmo", pdc_fsmo) != LDB_SUCCESS) {
93 return LDB_ERR_OPERATIONS_ERROR;
96 talloc_steal(module, pdc_fsmo);
98 ldb_debug(ldb, LDB_DEBUG_TRACE,
99 "pdc_fsmo_init: we are master: %s\n",
100 (pdc_fsmo->we_are_master?"yes":"no"));
102 talloc_free(mem_ctx);
103 return ldb_next_init(module);
106 _PUBLIC_ const struct ldb_module_ops ldb_pdc_fsmo_module_ops = {
108 .init_context = pdc_fsmo_init