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"));
46 service->role_transfer_in_progress = false;
49 static bool fsmo_master_cmp(struct ldb_dn *ntds_dn, struct ldb_dn *role_owner_dn)
51 if (ldb_dn_compare(ntds_dn, role_owner_dn) == 0) {
52 DEBUG(0,("\nWe are the FSMO master.\n"));
59 see which role is we are asked to assume, initialize data and send request
61 WERROR dreplsrv_fsmo_role_check(struct dreplsrv_service *service,
64 struct ldb_dn *role_owner_dn, *fsmo_role_dn, *ntds_dn;
65 TALLOC_CTX *tmp_ctx = talloc_new(service);
66 struct ldb_context *ldb = service->samdb;
68 uint64_t fsmo_info = 0;
69 enum drsuapi_DsExtendedOperation extended_op = DRSUAPI_EXOP_NONE;
72 if (service->role_transfer_in_progress) {
74 /* should we allow these in parallel? */
75 return WERR_DS_DRA_REPL_PENDING;
78 ntds_dn = samdb_ntds_settings_dn(ldb);
80 return WERR_DS_DRA_INTERNAL_ERROR;
84 case DREPL_NAMING_MASTER:
85 fsmo_role_dn = samdb_partitions_dn(ldb, tmp_ctx),
86 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
87 if (ret != LDB_SUCCESS) {
88 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Naming Master object - %s",
91 return WERR_DS_DRA_INTERNAL_ERROR;
94 case DREPL_INFRASTRUCTURE_MASTER:
95 fsmo_role_dn = samdb_infrastructure_dn(ldb, tmp_ctx);
96 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
97 if (ret != LDB_SUCCESS) {
98 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Schema Master object - %s",
100 talloc_free(tmp_ctx);
101 return WERR_DS_DRA_INTERNAL_ERROR;
103 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
105 case DREPL_RID_MASTER:
106 ret = samdb_rid_manager_dn(ldb, tmp_ctx, &fsmo_role_dn);
107 if (ret != LDB_SUCCESS) {
108 DEBUG(0, (__location__ ": Failed to find RID Manager object - %s", ldb_errstring(ldb)));
109 talloc_free(tmp_ctx);
110 return WERR_DS_DRA_INTERNAL_ERROR;
113 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
114 if (ret != LDB_SUCCESS) {
115 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in RID Manager object - %s",
116 ldb_errstring(ldb)));
117 talloc_free(tmp_ctx);
118 return WERR_DS_DRA_INTERNAL_ERROR;
120 extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
122 case DREPL_SCHEMA_MASTER:
123 fsmo_role_dn = ldb_get_schema_basedn(ldb);
124 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
125 if (ret != LDB_SUCCESS) {
126 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Schema Master object - %s",
127 ldb_errstring(ldb)));
128 talloc_free(tmp_ctx);
129 return WERR_DS_DRA_INTERNAL_ERROR;
131 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
133 case DREPL_PDC_MASTER:
134 fsmo_role_dn = ldb_get_default_basedn(ldb);
135 ret = samdb_reference_dn(ldb, tmp_ctx, fsmo_role_dn, "fSMORoleOwner", &role_owner_dn);
136 if (ret != LDB_SUCCESS) {
137 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in Pd Master object - %s",
138 ldb_errstring(ldb)));
139 talloc_free(tmp_ctx);
140 return WERR_DS_DRA_INTERNAL_ERROR;
142 extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
145 return WERR_DS_DRA_INTERNAL_ERROR;
148 if (fsmo_master_cmp(ntds_dn, role_owner_dn) ||
149 (extended_op == DRSUAPI_EXOP_NONE)) {
150 DEBUG(0,("FSMO role check failed for DN %s and owner %s ",
151 ldb_dn_get_linearized(fsmo_role_dn),
152 ldb_dn_get_linearized(role_owner_dn)));
156 werr = drepl_request_extended_op(service,
161 drepl_role_callback);
162 if (W_ERROR_IS_OK(werr)) {
163 dreplsrv_run_pending_ops(service);
165 DEBUG(0,("%s: drepl_request_extended_op() failed with %s",
166 __FUNCTION__, win_errstr(werr)));