2 Unix SMB/CIFS mplementation.
4 The module that handles the Domain Naming FSMO Role Owner
7 Copyright (C) Stefan Metzmacher 2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "ldb_module.h"
26 #include "dsdb/samdb/samdb.h"
27 #include "librpc/gen_ndr/ndr_misc.h"
28 #include "librpc/gen_ndr/ndr_drsuapi.h"
29 #include "librpc/gen_ndr/ndr_drsblobs.h"
30 #include "../lib/util/dlinklist.h"
31 #include "dsdb/samdb/ldb_modules/util.h"
33 static int naming_fsmo_init(struct ldb_module
*module
)
35 struct ldb_context
*ldb
;
37 struct ldb_dn
*naming_dn
;
38 struct dsdb_naming_fsmo
*naming_fsmo
;
39 struct ldb_result
*naming_res
;
41 static const char *naming_attrs
[] = {
46 ldb
= ldb_module_get_ctx(module
);
48 mem_ctx
= talloc_new(module
);
51 return LDB_ERR_OPERATIONS_ERROR
;
54 naming_dn
= samdb_partitions_dn(ldb
, mem_ctx
);
56 ldb_debug(ldb
, LDB_DEBUG_WARNING
,
57 "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)\n");
59 return ldb_next_init(module
);
62 naming_fsmo
= talloc_zero(mem_ctx
, struct dsdb_naming_fsmo
);
65 return LDB_ERR_OPERATIONS_ERROR
;
67 ldb_module_set_private(module
, naming_fsmo
);
69 ret
= dsdb_module_search_dn(module
, mem_ctx
, &naming_res
,
72 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
73 ldb_debug(ldb
, LDB_DEBUG_WARNING
,
74 "naming_fsmo_init: no partitions dn present: (skip loading of naming contexts details)\n");
76 return ldb_next_init(module
);
79 naming_fsmo
->master_dn
= ldb_msg_find_attr_as_dn(ldb
, naming_fsmo
, naming_res
->msgs
[0], "fSMORoleOwner");
80 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb
), naming_fsmo
->master_dn
) == 0) {
81 naming_fsmo
->we_are_master
= true;
83 naming_fsmo
->we_are_master
= false;
86 if (ldb_set_opaque(ldb
, "dsdb_naming_fsmo", naming_fsmo
) != LDB_SUCCESS
) {
88 return LDB_ERR_OPERATIONS_ERROR
;
91 talloc_steal(module
, naming_fsmo
);
93 ldb_debug(ldb
, LDB_DEBUG_TRACE
,
94 "naming_fsmo_init: we are master: %s\n",
95 (naming_fsmo
->we_are_master
?"yes":"no"));
98 return ldb_next_init(module
);
101 _PUBLIC_
const struct ldb_module_ops ldb_naming_fsmo_module_ops
= {
102 .name
= "naming_fsmo",
103 .init_context
= naming_fsmo_init