2 Unix SMB/CIFS mplementation.
4 DSDB replication service - FSMO role change
6 Copyright (C) Nadezhda Ivanova 2010
7 Copyright (C) Andrew Tridgell 2010
8 Copyright (C) Andrew Bartlett 2010
10 based on drepl_ridalloc.c
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "dsdb/samdb/samdb.h"
29 #include "smbd/service.h"
30 #include "dsdb/repl/drepl_service.h"
31 #include "param/param.h"
32 #include "lib/messaging/irpc.h"
33 #include "librpc/gen_ndr/ndr_irpc.h"
35 static void drepl_role_callback(struct dreplsrv_service *service,
37 enum drsuapi_DsExtendedError ext_err,
40 if (!W_ERROR_IS_OK(werr)) {
41 DEBUG(0,(__location__ ": Failed role transfer - %s - extended_ret[0x%X]\n",
42 win_errstr(werr), ext_err));
44 DEBUG(0,(__location__ ": Successful role transfer\n"));
48 static bool fsmo_master_cmp(struct ldb_dn *ntds_dn, struct ldb_dn *role_owner_dn)
50 if (ldb_dn_compare(ntds_dn, role_owner_dn) == 0) {
51 DEBUG(0,("\nWe are the FSMO master.\n"));
58 see which role is we are asked to assume, initialize data and send request
60 WERROR dreplsrv_fsmo_role_check(struct dreplsrv_service *service,
63 struct ldb_dn *role_owner_dn, *fsmo_role_dn, *ntds_dn;
64 TALLOC_CTX *tmp_ctx = talloc_new(service);
65 struct ldb_context *ldb = service->samdb;
67 uint64_t fsmo_info = 0;
68 enum drsuapi_DsExtendedOperation extended_op = DRSUAPI_EXOP_NONE;
71 ntds_dn = samdb_ntds_settings_dn(ldb);
73 return WERR_DS_DRA_INTERNAL_ERROR;
77 case DREPL_NAMING_MASTER:
78 fsmo_role_dn = samdb_partitions_dn(ldb, tmp_ctx),
79 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
80 if (ret != LDB_SUCCESS) {
81 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Naming Master object - %s",
84 return WERR_DS_DRA_INTERNAL_ERROR;
87 case DREPL_INFRASTRUCTURE_MASTER:
88 fsmo_role_dn = samdb_infrastructure_dn(ldb, tmp_ctx);
89 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
90 if (ret != LDB_SUCCESS) {
91 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Schema Master object - %s",
94 return WERR_DS_DRA_INTERNAL_ERROR;
96 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
98 case DREPL_RID_MASTER:
99 ret = samdb_rid_manager_dn(ldb, tmp_ctx, &fsmo_role_dn);
100 if (ret != LDB_SUCCESS) {
101 DEBUG(0, (__location__ ": Failed to find RID Manager object - %s", ldb_errstring(ldb)));
102 talloc_free(tmp_ctx);
103 return WERR_DS_DRA_INTERNAL_ERROR;
106 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
107 if (ret != LDB_SUCCESS) {
108 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in RID Manager object - %s",
109 ldb_errstring(ldb)));
110 talloc_free(tmp_ctx);
111 return WERR_DS_DRA_INTERNAL_ERROR;
113 extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
115 case DREPL_SCHEMA_MASTER:
116 fsmo_role_dn = ldb_get_schema_basedn(ldb);
117 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
118 if (ret != LDB_SUCCESS) {
119 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Schema Master object - %s",
120 ldb_errstring(ldb)));
121 talloc_free(tmp_ctx);
122 return WERR_DS_DRA_INTERNAL_ERROR;
124 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
126 case DREPL_PDC_MASTER:
127 fsmo_role_dn = ldb_get_default_basedn(ldb);
128 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
129 if (ret != LDB_SUCCESS) {
130 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Pd Master object - %s",
131 ldb_errstring(ldb)));
132 talloc_free(tmp_ctx);
133 return WERR_DS_DRA_INTERNAL_ERROR;
135 extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
138 return WERR_DS_DRA_INTERNAL_ERROR;
141 if (fsmo_master_cmp(ntds_dn, role_owner_dn) ||
142 (extended_op == DRSUAPI_EXOP_NONE)) {
143 DEBUG(0,("FSMO role check failed for DN %s and owner %s ",
144 ldb_dn_get_linearized(fsmo_role_dn),
145 ldb_dn_get_linearized(role_owner_dn)));
149 werr = drepl_request_extended_op(service,
154 drepl_role_callback);
155 if (W_ERROR_IS_OK(werr)) {
156 dreplsrv_run_pending_ops(service);
158 DEBUG(0,("%s: drepl_request_extended_op() failed with %s",
159 __FUNCTION__, win_errstr(werr)));