source: vendor/current/source4/dsdb/repl/drepl_fsmo.c@ 740

Last change on this file since 740 was 740, checked in by Silvan Scherrer, 12 years ago

Samba Server: update vendor to 3.6.0

File size: 3.3 KB
Line 
1/*
2 Unix SMB/CIFS mplementation.
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 "smbd/service.h"
31#include "dsdb/repl/drepl_service.h"
32#include "param/param.h"
33
34static void drepl_role_callback(struct dreplsrv_service *service,
35 WERROR werr,
36 enum drsuapi_DsExtendedError ext_err,
37 void *cb_data)
38{
39 if (!W_ERROR_IS_OK(werr)) {
40 DEBUG(0,(__location__ ": Failed role transfer - %s - extended_ret[0x%X]\n",
41 win_errstr(werr), ext_err));
42 } else {
43 DEBUG(0,(__location__ ": Successful role transfer\n"));
44 }
45}
46
47static bool fsmo_master_cmp(struct ldb_dn *ntds_dn, struct ldb_dn *role_owner_dn)
48{
49 if (ldb_dn_compare(ntds_dn, role_owner_dn) == 0) {
50 DEBUG(0,("\nWe are the FSMO master.\n"));
51 return true;
52 }
53 return false;
54}
55
56/*
57 see which role is we are asked to assume, initialize data and send request
58 */
59WERROR dreplsrv_fsmo_role_check(struct dreplsrv_service *service,
60 enum drepl_role_master role)
61{
62 struct ldb_dn *role_owner_dn, *fsmo_role_dn, *ntds_dn;
63 TALLOC_CTX *tmp_ctx = talloc_new(service);
64 uint64_t fsmo_info = 0;
65 enum drsuapi_DsExtendedOperation extended_op = DRSUAPI_EXOP_NONE;
66 WERROR werr;
67
68 ntds_dn = samdb_ntds_settings_dn(service->samdb);
69 if (!ntds_dn) {
70 return WERR_DS_DRA_INTERNAL_ERROR;
71 }
72
73 werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role,
74 &fsmo_role_dn, &role_owner_dn);
75 if (!W_ERROR_IS_OK(werr)) {
76 return werr;
77 }
78
79 switch (role) {
80 case DREPL_NAMING_MASTER:
81 case DREPL_INFRASTRUCTURE_MASTER:
82 case DREPL_SCHEMA_MASTER:
83 extended_op = DRSUAPI_EXOP_FSMO_REQ_ROLE;
84 break;
85 case DREPL_RID_MASTER:
86 extended_op = DRSUAPI_EXOP_FSMO_RID_REQ_ROLE;
87 break;
88 case DREPL_PDC_MASTER:
89 extended_op = DRSUAPI_EXOP_FSMO_REQ_PDC;
90 break;
91 default:
92 return WERR_DS_DRA_INTERNAL_ERROR;
93 }
94
95 if (fsmo_master_cmp(ntds_dn, role_owner_dn) ||
96 (extended_op == DRSUAPI_EXOP_NONE)) {
97 DEBUG(0,("FSMO role check failed for DN %s and owner %s ",
98 ldb_dn_get_linearized(fsmo_role_dn),
99 ldb_dn_get_linearized(role_owner_dn)));
100 return WERR_OK;
101 }
102
103 werr = drepl_request_extended_op(service,
104 fsmo_role_dn,
105 role_owner_dn,
106 extended_op,
107 fsmo_info,
108 0,
109 drepl_role_callback,
110 NULL);
111 if (W_ERROR_IS_OK(werr)) {
112 dreplsrv_run_pending_ops(service);
113 } else {
114 DEBUG(0,("%s: drepl_request_extended_op() failed with %s",
115 __FUNCTION__, win_errstr(werr)));
116 }
117 return werr;
118}
Note: See TracBrowser for help on using the repository browser.