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
9 Copyright (C) Anatoliy Atanasov 2010
11 based on drepl_ridalloc.c
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "dsdb/samdb/samdb.h"
30 #include "smbd/service.h"
31 #include "dsdb/repl/drepl_service.h"
32 #include "param/param.h"
33 #include "librpc/gen_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,
61 enum drepl_role_master role)
63 struct ldb_dn *role_owner_dn, *fsmo_role_dn, *ntds_dn;
64 TALLOC_CTX *tmp_ctx = talloc_new(service);
65 uint64_t fsmo_info = 0;
66 enum drsuapi_DsExtendedOperation extended_op = DRSUAPI_EXOP_NONE;
69 ntds_dn = samdb_ntds_settings_dn(service->samdb);
71 return WERR_DS_DRA_INTERNAL_ERROR;
74 werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role,
75 &fsmo_role_dn, &role_owner_dn);
76 if (!W_ERROR_IS_OK(werr)) {
81 case DREPL_NAMING_MASTER:
82 case DREPL_INFRASTRUCTURE_MASTER:
83 case DREPL_SCHEMA_MASTER:
84 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
86 case DREPL_RID_MASTER:
87 extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
89 case DREPL_PDC_MASTER:
90 extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
93 return WERR_DS_DRA_INTERNAL_ERROR;
96 if (fsmo_master_cmp(ntds_dn, role_owner_dn) ||
97 (extended_op == DRSUAPI_EXOP_NONE)) {
98 DEBUG(0,("FSMO role check failed for DN %s and owner %s ",
99 ldb_dn_get_linearized(fsmo_role_dn),
100 ldb_dn_get_linearized(role_owner_dn)));
104 werr = drepl_request_extended_op(service,
112 if (W_ERROR_IS_OK(werr)) {
113 dreplsrv_run_pending_ops(service);
115 DEBUG(0,("%s: drepl_request_extended_op() failed with %s",
116 __FUNCTION__, win_errstr(werr)));