Line data Source code
1 : /*
2 : Unix SMB/CIFS Implementation.
3 :
4 : DSDB replication service - FSMO role change
5 :
6 : Copyright (C) Nadezhda Ivanova 2010
7 : Copyright (C) Andrew Tridgell 2010
8 : Copyright (C) Andrew Bartlett 2010
9 : Copyright (C) Anatoliy Atanasov 2010
10 :
11 : based on drepl_ridalloc.c
12 :
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.
17 :
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.
22 :
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/>.
25 :
26 : */
27 :
28 : #include "includes.h"
29 : #include "dsdb/samdb/samdb.h"
30 : #include "samba/service.h"
31 : #include "dsdb/repl/drepl_service.h"
32 : #include "param/param.h"
33 :
34 : #undef DBGC_CLASS
35 : #define DBGC_CLASS DBGC_DRS_REPL
36 :
37 : struct fsmo_role_state {
38 : struct irpc_message *msg;
39 : struct drepl_takeFSMORole *r;
40 : };
41 :
42 22 : static void drepl_role_callback(struct dreplsrv_service *service,
43 : WERROR werr,
44 : enum drsuapi_DsExtendedError ext_err,
45 : void *cb_data)
46 : {
47 22 : struct fsmo_role_state *fsmo = talloc_get_type_abort(cb_data, struct fsmo_role_state);
48 22 : if (!W_ERROR_IS_OK(werr)) {
49 0 : DEBUG(2,(__location__ ": Failed role transfer - %s - extended_ret[0x%X]\n",
50 : win_errstr(werr), ext_err));
51 : } else {
52 22 : DEBUG(2,(__location__ ": Successful role transfer\n"));
53 : }
54 22 : fsmo->r->out.result = werr;
55 22 : irpc_send_reply(fsmo->msg, NT_STATUS_OK);
56 22 : }
57 :
58 : /*
59 : see which role is we are asked to assume, initialize data and send request
60 : */
61 22 : NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg,
62 : struct drepl_takeFSMORole *r)
63 : {
64 22 : struct dreplsrv_service *service = talloc_get_type(msg->private_data,
65 : struct dreplsrv_service);
66 0 : struct ldb_dn *role_owner_dn, *fsmo_role_dn;
67 22 : TALLOC_CTX *tmp_ctx = talloc_new(service);
68 22 : uint64_t fsmo_info = 0;
69 22 : enum drsuapi_DsExtendedOperation extended_op = DRSUAPI_EXOP_NONE;
70 0 : WERROR werr;
71 22 : enum drepl_role_master role = r->in.role;
72 0 : struct fsmo_role_state *fsmo;
73 0 : bool is_us;
74 0 : int ret;
75 :
76 22 : werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role,
77 : &fsmo_role_dn, &role_owner_dn);
78 22 : if (!W_ERROR_IS_OK(werr)) {
79 0 : talloc_free(tmp_ctx);
80 0 : r->out.result = werr;
81 0 : return NT_STATUS_OK;
82 : }
83 :
84 22 : switch (role) {
85 12 : case DREPL_NAMING_MASTER:
86 : case DREPL_INFRASTRUCTURE_MASTER:
87 : case DREPL_SCHEMA_MASTER:
88 12 : extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
89 12 : break;
90 6 : case DREPL_RID_MASTER:
91 6 : extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
92 6 : break;
93 4 : case DREPL_PDC_MASTER:
94 4 : extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
95 4 : break;
96 0 : default:
97 0 : DEBUG(0,("Unknown role %u in role transfer\n",
98 : (unsigned)role));
99 : /* IRPC messages are trusted, so this really should not happen */
100 0 : smb_panic("Unknown role despite dsdb_get_fsmo_role_info success");
101 : }
102 :
103 22 : ret = samdb_dn_is_our_ntdsa(service->samdb, role_owner_dn, &is_us);
104 22 : if (ret != LDB_SUCCESS) {
105 0 : DEBUG(0,("FSMO role check failed (failed to confirm if our ntdsDsa) for DN %s and owner %s \n",
106 : ldb_dn_get_linearized(fsmo_role_dn),
107 : ldb_dn_get_linearized(role_owner_dn)));
108 0 : talloc_free(tmp_ctx);
109 0 : r->out.result = WERR_DS_DRA_INTERNAL_ERROR;
110 0 : return NT_STATUS_OK;
111 : }
112 :
113 22 : if (is_us) {
114 0 : DEBUG(5,("FSMO role check failed, we already own DN %s with %s\n",
115 : ldb_dn_get_linearized(fsmo_role_dn),
116 : ldb_dn_get_linearized(role_owner_dn)));
117 0 : r->out.result = WERR_OK;
118 0 : talloc_free(tmp_ctx);
119 0 : return NT_STATUS_OK;
120 : }
121 :
122 22 : fsmo = talloc(msg, struct fsmo_role_state);
123 22 : NT_STATUS_HAVE_NO_MEMORY(fsmo);
124 :
125 22 : fsmo->msg = msg;
126 22 : fsmo->r = r;
127 :
128 22 : werr = drepl_request_extended_op(service,
129 : fsmo_role_dn,
130 : role_owner_dn,
131 : extended_op,
132 : fsmo_info,
133 : 0,
134 : drepl_role_callback,
135 : fsmo);
136 22 : if (!W_ERROR_IS_OK(werr)) {
137 0 : r->out.result = werr;
138 0 : talloc_free(tmp_ctx);
139 0 : return NT_STATUS_OK;
140 : }
141 :
142 : /* mark this message to be answered later */
143 22 : msg->defer_reply = true;
144 22 : dreplsrv_run_pending_ops(service);
145 22 : talloc_free(tmp_ctx);
146 22 : return NT_STATUS_OK;
147 : }
|