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;
86 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
88 case DREPL_INFRASTRUCTURE_MASTER:
89 fsmo_role_dn = samdb_infrastructure_dn(ldb, tmp_ctx);
90 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
91 if (ret != LDB_SUCCESS) {
92 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Schema Master object - %s",
95 return WERR_DS_DRA_INTERNAL_ERROR;
97 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
99 case DREPL_RID_MASTER:
100 ret = samdb_rid_manager_dn(ldb, tmp_ctx, &fsmo_role_dn);
101 if (ret != LDB_SUCCESS) {
102 DEBUG(0, (__location__ ": Failed to find RID Manager object - %s", ldb_errstring(ldb)));
103 talloc_free(tmp_ctx);
104 return WERR_DS_DRA_INTERNAL_ERROR;
107 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
108 if (ret != LDB_SUCCESS) {
109 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in RID Manager object - %s",
110 ldb_errstring(ldb)));
111 talloc_free(tmp_ctx);
112 return WERR_DS_DRA_INTERNAL_ERROR;
114 extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
116 case DREPL_SCHEMA_MASTER:
117 fsmo_role_dn = ldb_get_schema_basedn(ldb);
118 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
119 if (ret != LDB_SUCCESS) {
120 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Schema Master object - %s",
121 ldb_errstring(ldb)));
122 talloc_free(tmp_ctx);
123 return WERR_DS_DRA_INTERNAL_ERROR;
125 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
127 case DREPL_PDC_MASTER:
128 fsmo_role_dn = ldb_get_default_basedn(ldb);
129 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
130 if (ret != LDB_SUCCESS) {
131 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Pd Master object - %s",
132 ldb_errstring(ldb)));
133 talloc_free(tmp_ctx);
134 return WERR_DS_DRA_INTERNAL_ERROR;
136 extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
139 return WERR_DS_DRA_INTERNAL_ERROR;
142 if (fsmo_master_cmp(ntds_dn, role_owner_dn) ||
143 (extended_op == DRSUAPI_EXOP_NONE)) {
144 DEBUG(0,("FSMO role check failed for DN %s and owner %s ",
145 ldb_dn_get_linearized(fsmo_role_dn),
146 ldb_dn_get_linearized(role_owner_dn)));
150 werr = drepl_request_extended_op(service,
158 if (W_ERROR_IS_OK(werr)) {
159 dreplsrv_run_pending_ops(service);
161 DEBUG(0,("%s: drepl_request_extended_op() failed with %s",
162 __FUNCTION__, win_errstr(werr)));