source: vendor/current/source4/dsdb/samdb/ldb_modules/pdc_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 The module that handles the PDC FSMO Role Owner checkings
5
6 Copyright (C) Stefan Metzmacher 2007
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "includes.h"
24#include "ldb_module.h"
25#include "dsdb/samdb/samdb.h"
26#include "librpc/gen_ndr/ndr_misc.h"
27#include "librpc/gen_ndr/ndr_drsuapi.h"
28#include "librpc/gen_ndr/ndr_drsblobs.h"
29#include "../lib/util/dlinklist.h"
30#include "dsdb/samdb/ldb_modules/util.h"
31
32static int pdc_fsmo_init(struct ldb_module *module)
33{
34 struct ldb_context *ldb;
35 TALLOC_CTX *mem_ctx;
36 struct ldb_dn *pdc_dn;
37 struct dsdb_pdc_fsmo *pdc_fsmo;
38 struct ldb_result *pdc_res;
39 int ret;
40 static const char *pdc_attrs[] = {
41 "fSMORoleOwner",
42 NULL
43 };
44
45 ldb = ldb_module_get_ctx(module);
46
47 mem_ctx = talloc_new(module);
48 if (!mem_ctx) {
49 return ldb_oom(ldb);
50 }
51
52 pdc_dn = ldb_get_default_basedn(ldb);
53 if (!pdc_dn) {
54 ldb_debug_set(ldb, LDB_DEBUG_FATAL,
55 "pdc_fsmo_init: could not determine default basedn");
56 talloc_free(mem_ctx);
57 return LDB_ERR_OPERATIONS_ERROR;
58 }
59
60 pdc_fsmo = talloc_zero(mem_ctx, struct dsdb_pdc_fsmo);
61 if (!pdc_fsmo) {
62 return ldb_oom(ldb);
63 }
64 ldb_module_set_private(module, pdc_fsmo);
65
66 ret = dsdb_module_search_dn(module, mem_ctx, &pdc_res,
67 pdc_dn,
68 pdc_attrs,
69 DSDB_FLAG_NEXT_MODULE, NULL);
70 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
71 ldb_debug(ldb, LDB_DEBUG_TRACE,
72 "pdc_fsmo_init: no domain object present: (skip loading of domain details)");
73 talloc_free(mem_ctx);
74 return ldb_next_init(module);
75 } else if (ret != LDB_SUCCESS) {
76 ldb_debug_set(ldb, LDB_DEBUG_FATAL,
77 "pdc_fsmo_init: failed to search the domain object: %d:%s: %s",
78 ret, ldb_strerror(ret), ldb_errstring(ldb));
79 talloc_free(mem_ctx);
80 return ret;
81 }
82
83 pdc_fsmo->master_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, pdc_res->msgs[0], "fSMORoleOwner");
84 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc_fsmo->master_dn) == 0) {
85 pdc_fsmo->we_are_master = true;
86 } else {
87 pdc_fsmo->we_are_master = false;
88 }
89
90 if (ldb_set_opaque(ldb, "dsdb_pdc_fsmo", pdc_fsmo) != LDB_SUCCESS) {
91 return ldb_oom(ldb);
92 }
93
94 talloc_steal(module, pdc_fsmo);
95
96 ldb_debug(ldb, LDB_DEBUG_TRACE,
97 "pdc_fsmo_init: we are master: %s\n",
98 (pdc_fsmo->we_are_master?"yes":"no"));
99
100 talloc_free(mem_ctx);
101 return ldb_next_init(module);
102}
103
104static const struct ldb_module_ops ldb_pdc_fsmo_module_ops = {
105 .name = "pdc_fsmo",
106 .init_context = pdc_fsmo_init
107};
108
109int ldb_pdc_fsmo_module_init(const char *version)
110{
111 LDB_MODULE_CHECK_VERSION(version);
112 return ldb_register_module(&ldb_pdc_fsmo_module_ops);
113}
Note: See TracBrowser for help on using the repository browser.