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"
34 struct fsmo_role_state
{
35 struct irpc_message
*msg
;
36 struct drepl_takeFSMORole
*r
;
39 static void drepl_role_callback(struct dreplsrv_service
*service
,
41 enum drsuapi_DsExtendedError ext_err
,
44 struct fsmo_role_state
*fsmo
= talloc_get_type_abort(cb_data
, struct fsmo_role_state
);
45 if (!W_ERROR_IS_OK(werr
)) {
46 DEBUG(2,(__location__
": Failed role transfer - %s - extended_ret[0x%X]\n",
47 win_errstr(werr
), ext_err
));
49 DEBUG(2,(__location__
": Successful role transfer\n"));
51 fsmo
->r
->out
.result
= werr
;
52 irpc_send_reply(fsmo
->msg
, NT_STATUS_OK
);
55 static bool fsmo_master_equal(struct ldb_dn
*ntds_dn
, struct ldb_dn
*role_owner_dn
)
57 if (ldb_dn_compare(ntds_dn
, role_owner_dn
) == 0) {
58 DEBUG(0,("\nWe are the FSMO master.\n"));
65 see which role is we are asked to assume, initialize data and send request
67 NTSTATUS
drepl_take_FSMO_role(struct irpc_message
*msg
,
68 struct drepl_takeFSMORole
*r
)
70 struct dreplsrv_service
*service
= talloc_get_type(msg
->private_data
,
71 struct dreplsrv_service
);
72 struct ldb_dn
*role_owner_dn
, *fsmo_role_dn
, *ntds_dn
;
73 TALLOC_CTX
*tmp_ctx
= talloc_new(service
);
74 uint64_t fsmo_info
= 0;
75 enum drsuapi_DsExtendedOperation extended_op
= DRSUAPI_EXOP_NONE
;
77 enum drepl_role_master role
= r
->in
.role
;
78 struct fsmo_role_state
*fsmo
;
80 ntds_dn
= samdb_ntds_settings_dn(service
->samdb
);
82 r
->out
.result
= WERR_DS_DRA_INTERNAL_ERROR
;
86 werr
= dsdb_get_fsmo_role_info(tmp_ctx
, service
->samdb
, role
,
87 &fsmo_role_dn
, &role_owner_dn
);
88 if (!W_ERROR_IS_OK(werr
)) {
94 case DREPL_NAMING_MASTER
:
95 case DREPL_INFRASTRUCTURE_MASTER
:
96 case DREPL_SCHEMA_MASTER
:
97 extended_op
= DRSUAPI_EXOP_FSMO_REQ_ROLE
;
99 case DREPL_RID_MASTER
:
100 extended_op
= DRSUAPI_EXOP_FSMO_RID_REQ_ROLE
;
102 case DREPL_PDC_MASTER
:
103 extended_op
= DRSUAPI_EXOP_FSMO_REQ_PDC
;
106 DEBUG(2,("Unknown role %u in role transfer\n",
108 r
->out
.result
= WERR_DS_DRA_INTERNAL_ERROR
;
112 if (fsmo_master_equal(ntds_dn
, role_owner_dn
) ||
113 (extended_op
== DRSUAPI_EXOP_NONE
)) {
114 DEBUG(0,("FSMO role check failed for DN %s and owner %s \n",
115 ldb_dn_get_linearized(fsmo_role_dn
),
116 ldb_dn_get_linearized(role_owner_dn
)));
117 r
->out
.result
= WERR_OK
;
121 fsmo
= talloc(msg
, struct fsmo_role_state
);
122 NT_STATUS_HAVE_NO_MEMORY(fsmo
);
127 werr
= drepl_request_extended_op(service
,
135 if (!W_ERROR_IS_OK(werr
)) {
136 r
->out
.result
= werr
;
140 /* mark this message to be answered later */
141 msg
->defer_reply
= true;
142 dreplsrv_run_pending_ops(service
);