1 | /*
|
---|
2 | Unix SMB/CIFS mplementation.
|
---|
3 | DSDB replication service
|
---|
4 |
|
---|
5 | Copyright (C) Stefan Metzmacher 2007
|
---|
6 | Copyright (C) Kamen Mazdrashki <kamenim@samba.org> 2010
|
---|
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 "dsdb/samdb/samdb.h"
|
---|
25 | #include "auth/auth.h"
|
---|
26 | #include "smbd/service.h"
|
---|
27 | #include "lib/events/events.h"
|
---|
28 | #include "dsdb/repl/drepl_service.h"
|
---|
29 | #include <ldb_errors.h>
|
---|
30 | #include "../lib/util/dlinklist.h"
|
---|
31 | #include "librpc/gen_ndr/ndr_misc.h"
|
---|
32 | #include "librpc/gen_ndr/ndr_drsuapi.h"
|
---|
33 | #include "librpc/gen_ndr/ndr_drsblobs.h"
|
---|
34 | #include "librpc/gen_ndr/ndr_irpc.h"
|
---|
35 | #include "param/param.h"
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Call-back data for _drepl_replica_sync_done_cb()
|
---|
39 | */
|
---|
40 | struct drepl_replica_sync_cb_data {
|
---|
41 | struct irpc_message *msg;
|
---|
42 | struct drsuapi_DsReplicaSync *r;
|
---|
43 |
|
---|
44 | /* number of ops left to be completed */
|
---|
45 | int ops_count;
|
---|
46 |
|
---|
47 | /* last failure error code */
|
---|
48 | WERROR werr_last_failure;
|
---|
49 | };
|
---|
50 |
|
---|
51 |
|
---|
52 | static WERROR dreplsrv_init_creds(struct dreplsrv_service *service)
|
---|
53 | {
|
---|
54 | service->system_session_info = system_session(service->task->lp_ctx);
|
---|
55 | if (service->system_session_info == NULL) {
|
---|
56 | return WERR_NOMEM;
|
---|
57 | }
|
---|
58 |
|
---|
59 | return WERR_OK;
|
---|
60 | }
|
---|
61 |
|
---|
62 | static WERROR dreplsrv_connect_samdb(struct dreplsrv_service *service, struct loadparm_context *lp_ctx)
|
---|
63 | {
|
---|
64 | const struct GUID *ntds_guid;
|
---|
65 | struct drsuapi_DsBindInfo28 *bind_info28;
|
---|
66 |
|
---|
67 | service->samdb = samdb_connect(service, service->task->event_ctx, lp_ctx, service->system_session_info, 0);
|
---|
68 | if (!service->samdb) {
|
---|
69 | return WERR_DS_UNAVAILABLE;
|
---|
70 | }
|
---|
71 |
|
---|
72 | ntds_guid = samdb_ntds_objectGUID(service->samdb);
|
---|
73 | if (!ntds_guid) {
|
---|
74 | return WERR_DS_UNAVAILABLE;
|
---|
75 | }
|
---|
76 | service->ntds_guid = *ntds_guid;
|
---|
77 |
|
---|
78 | if (samdb_rodc(service->samdb, &service->am_rodc) != LDB_SUCCESS) {
|
---|
79 | DEBUG(0,(__location__ ": Failed to determine RODC status\n"));
|
---|
80 | return WERR_DS_UNAVAILABLE;
|
---|
81 | }
|
---|
82 |
|
---|
83 | bind_info28 = &service->bind_info28;
|
---|
84 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
|
---|
85 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
|
---|
86 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
|
---|
87 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
|
---|
88 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
|
---|
89 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
|
---|
90 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
|
---|
91 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
|
---|
92 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
|
---|
93 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
|
---|
94 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
|
---|
95 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
|
---|
96 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
|
---|
97 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
|
---|
98 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
|
---|
99 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
|
---|
100 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
|
---|
101 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
|
---|
102 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
|
---|
103 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V5;
|
---|
104 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
|
---|
105 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
|
---|
106 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
|
---|
107 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
|
---|
108 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
|
---|
109 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
|
---|
110 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
|
---|
111 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
|
---|
112 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
|
---|
113 | #if 0 /* we don't support XPRESS compression yet */
|
---|
114 | bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
|
---|
115 | #endif
|
---|
116 | /* TODO: fill in site_guid */
|
---|
117 | bind_info28->site_guid = GUID_zero();
|
---|
118 | /* TODO: find out how this is really triggered! */
|
---|
119 | bind_info28->pid = 0;
|
---|
120 | bind_info28->repl_epoch = 0;
|
---|
121 |
|
---|
122 | return WERR_OK;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Callback for dreplsrv_out_operation operation completion.
|
---|
128 | *
|
---|
129 | * We just need to complete a waiting IRPC message here.
|
---|
130 | * In case pull operation has failed,
|
---|
131 | * caller of this callback will dump
|
---|
132 | * failure information.
|
---|
133 | *
|
---|
134 | * NOTE: cb_data is allocated in IRPC msg's context
|
---|
135 | * and will be freed during irpc_send_reply() call.
|
---|
136 | */
|
---|
137 | static void _drepl_replica_sync_done_cb(struct dreplsrv_service *service,
|
---|
138 | WERROR werr,
|
---|
139 | enum drsuapi_DsExtendedError ext_err,
|
---|
140 | void *cb_data)
|
---|
141 | {
|
---|
142 | struct drepl_replica_sync_cb_data *data = talloc_get_type(cb_data,
|
---|
143 | struct drepl_replica_sync_cb_data);
|
---|
144 | struct irpc_message *msg = data->msg;
|
---|
145 | struct drsuapi_DsReplicaSync *r = data->r;
|
---|
146 |
|
---|
147 | /* store last bad result */
|
---|
148 | if (!W_ERROR_IS_OK(werr)) {
|
---|
149 | data->werr_last_failure = werr;
|
---|
150 | }
|
---|
151 |
|
---|
152 | /* decrement pending ops count */
|
---|
153 | data->ops_count--;
|
---|
154 |
|
---|
155 | if (data->ops_count == 0) {
|
---|
156 | /* Return result to client */
|
---|
157 | r->out.result = data->werr_last_failure;
|
---|
158 |
|
---|
159 | /* complete IRPC message */
|
---|
160 | irpc_send_reply(msg, NT_STATUS_OK);
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Helper to schedule a replication operation with a source DSA.
|
---|
166 | * If 'data' is valid pointer, then a callback
|
---|
167 | * for the operation is passed and 'data->msg' is
|
---|
168 | * marked as 'deferred' - defer_reply = true
|
---|
169 | */
|
---|
170 | static WERROR _drepl_schedule_replication(struct dreplsrv_service *service,
|
---|
171 | struct dreplsrv_partition_source_dsa *dsa,
|
---|
172 | struct drsuapi_DsReplicaObjectIdentifier *nc,
|
---|
173 | uint32_t rep_options,
|
---|
174 | struct drepl_replica_sync_cb_data *data,
|
---|
175 | TALLOC_CTX *mem_ctx)
|
---|
176 | {
|
---|
177 | WERROR werr;
|
---|
178 | dreplsrv_extended_callback_t fn_callback = NULL;
|
---|
179 |
|
---|
180 | if (data) {
|
---|
181 | fn_callback = _drepl_replica_sync_done_cb;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /* schedule replication item */
|
---|
185 | werr = dreplsrv_schedule_partition_pull_source(service, dsa, rep_options,
|
---|
186 | DRSUAPI_EXOP_NONE, 0,
|
---|
187 | fn_callback, data);
|
---|
188 | if (!W_ERROR_IS_OK(werr)) {
|
---|
189 | DEBUG(0,("%s: failed setup of sync of partition (%s, %s, %s) - %s\n",
|
---|
190 | __FUNCTION__,
|
---|
191 | GUID_string(mem_ctx, &nc->guid),
|
---|
192 | nc->dn,
|
---|
193 | dsa->repsFrom1->other_info->dns_name,
|
---|
194 | win_errstr(werr)));
|
---|
195 | return werr;
|
---|
196 | }
|
---|
197 | /* log we've scheduled a replication item */
|
---|
198 | DEBUG(3,("%s: forcing sync of partition (%s, %s, %s)\n",
|
---|
199 | __FUNCTION__,
|
---|
200 | GUID_string(mem_ctx, &nc->guid),
|
---|
201 | nc->dn,
|
---|
202 | dsa->repsFrom1->other_info->dns_name));
|
---|
203 |
|
---|
204 | /* mark IRPC message as deferred if necessary */
|
---|
205 | if (data) {
|
---|
206 | data->ops_count++;
|
---|
207 | data->msg->defer_reply = true;
|
---|
208 | }
|
---|
209 |
|
---|
210 | return WERR_OK;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /*
|
---|
214 | DsReplicaSync messages from the DRSUAPI server are forwarded here
|
---|
215 | */
|
---|
216 | static NTSTATUS drepl_replica_sync(struct irpc_message *msg,
|
---|
217 | struct drsuapi_DsReplicaSync *r)
|
---|
218 | {
|
---|
219 | WERROR werr;
|
---|
220 | struct dreplsrv_partition *p;
|
---|
221 | struct drepl_replica_sync_cb_data *cb_data;
|
---|
222 | struct dreplsrv_partition_source_dsa *dsa;
|
---|
223 | struct drsuapi_DsReplicaSyncRequest1 *req1;
|
---|
224 | struct drsuapi_DsReplicaObjectIdentifier *nc;
|
---|
225 | struct dreplsrv_service *service = talloc_get_type(msg->private_data,
|
---|
226 | struct dreplsrv_service);
|
---|
227 |
|
---|
228 | #define REPLICA_SYNC_FAIL(_msg, _werr) do {\
|
---|
229 | if (!W_ERROR_IS_OK(_werr)) { \
|
---|
230 | DEBUG(0,(__location__ ": Failure - %s. werr = %s\n", \
|
---|
231 | _msg, win_errstr(_werr))); \
|
---|
232 | NDR_PRINT_IN_DEBUG(drsuapi_DsReplicaSync, r); \
|
---|
233 | } \
|
---|
234 | r->out.result = _werr; \
|
---|
235 | goto done;\
|
---|
236 | } while(0)
|
---|
237 |
|
---|
238 |
|
---|
239 | if (r->in.level != 1) {
|
---|
240 | REPLICA_SYNC_FAIL("Unsupported level",
|
---|
241 | WERR_DS_DRA_INVALID_PARAMETER);
|
---|
242 | }
|
---|
243 |
|
---|
244 | req1 = &r->in.req->req1;
|
---|
245 | nc = req1->naming_context;
|
---|
246 |
|
---|
247 | /* Check input parameters */
|
---|
248 | if (!nc) {
|
---|
249 | REPLICA_SYNC_FAIL("Invalid Naming Context",
|
---|
250 | WERR_DS_DRA_INVALID_PARAMETER);
|
---|
251 | }
|
---|
252 |
|
---|
253 | /* Find Naming context to be synchronized */
|
---|
254 | werr = dreplsrv_partition_find_for_nc(service,
|
---|
255 | &nc->guid, &nc->sid, nc->dn,
|
---|
256 | &p);
|
---|
257 | if (!W_ERROR_IS_OK(werr)) {
|
---|
258 | REPLICA_SYNC_FAIL("Failed to find requested Naming Context",
|
---|
259 | werr);
|
---|
260 | }
|
---|
261 |
|
---|
262 | /* should we process it asynchronously? */
|
---|
263 | if (req1->options & DRSUAPI_DRS_ASYNC_OP) {
|
---|
264 | cb_data = NULL;
|
---|
265 | } else {
|
---|
266 | cb_data = talloc_zero(msg, struct drepl_replica_sync_cb_data);
|
---|
267 | if (!cb_data) {
|
---|
268 | REPLICA_SYNC_FAIL("Not enought memory",
|
---|
269 | WERR_DS_DRA_INTERNAL_ERROR);
|
---|
270 | }
|
---|
271 |
|
---|
272 | cb_data->msg = msg;
|
---|
273 | cb_data->r = r;
|
---|
274 | cb_data->werr_last_failure = WERR_OK;
|
---|
275 | }
|
---|
276 |
|
---|
277 | /* collect source DSAs to sync with */
|
---|
278 | if (req1->options & DRSUAPI_DRS_SYNC_ALL) {
|
---|
279 | for (dsa = p->sources; dsa; dsa = dsa->next) {
|
---|
280 | /* schedule replication item */
|
---|
281 | werr = _drepl_schedule_replication(service, dsa, nc,
|
---|
282 | req1->options, cb_data, msg);
|
---|
283 | if (!W_ERROR_IS_OK(werr)) {
|
---|
284 | REPLICA_SYNC_FAIL("_drepl_schedule_replication() failed",
|
---|
285 | werr);
|
---|
286 | }
|
---|
287 | }
|
---|
288 | } else {
|
---|
289 | if (req1->options & DRSUAPI_DRS_SYNC_BYNAME) {
|
---|
290 | /* client should pass at least valid string */
|
---|
291 | if (!req1->source_dsa_dns) {
|
---|
292 | REPLICA_SYNC_FAIL("'source_dsa_dns' is not valid",
|
---|
293 | WERR_DS_DRA_INVALID_PARAMETER);
|
---|
294 | }
|
---|
295 |
|
---|
296 | werr = dreplsrv_partition_source_dsa_by_dns(p,
|
---|
297 | req1->source_dsa_dns,
|
---|
298 | &dsa);
|
---|
299 | } else {
|
---|
300 | /* client should pass at least some GUID */
|
---|
301 | if (GUID_all_zero(&req1->source_dsa_guid)) {
|
---|
302 | REPLICA_SYNC_FAIL("'source_dsa_guid' is not valid",
|
---|
303 | WERR_DS_DRA_INVALID_PARAMETER);
|
---|
304 | }
|
---|
305 |
|
---|
306 | werr = dreplsrv_partition_source_dsa_by_guid(p,
|
---|
307 | &req1->source_dsa_guid,
|
---|
308 | &dsa);
|
---|
309 | }
|
---|
310 | if (!W_ERROR_IS_OK(werr)) {
|
---|
311 | REPLICA_SYNC_FAIL("Failed to locate source DSA for given NC",
|
---|
312 | werr);
|
---|
313 | }
|
---|
314 |
|
---|
315 | /* schedule replication item */
|
---|
316 | werr = _drepl_schedule_replication(service, dsa, nc,
|
---|
317 | req1->options, cb_data, msg);
|
---|
318 | if (!W_ERROR_IS_OK(werr)) {
|
---|
319 | REPLICA_SYNC_FAIL("_drepl_schedule_replication() failed",
|
---|
320 | werr);
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* if we got here, everything is OK */
|
---|
325 | r->out.result = WERR_OK;
|
---|
326 |
|
---|
327 | /*
|
---|
328 | * schedule replication event to force
|
---|
329 | * replication as soon as possible
|
---|
330 | */
|
---|
331 | dreplsrv_periodic_schedule(service, 0);
|
---|
332 |
|
---|
333 | done:
|
---|
334 | return NT_STATUS_OK;
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Called when drplsrv should refresh its state.
|
---|
339 | * For example, when KCC change topology, dreplsrv
|
---|
340 | * should update its cache
|
---|
341 | *
|
---|
342 | * @param partition_dn If not empty/NULL, partition to update
|
---|
343 | */
|
---|
344 | static NTSTATUS dreplsrv_refresh(struct irpc_message *msg,
|
---|
345 | struct dreplsrv_refresh *r)
|
---|
346 | {
|
---|
347 | struct dreplsrv_service *s = talloc_get_type(msg->private_data,
|
---|
348 | struct dreplsrv_service);
|
---|
349 |
|
---|
350 | r->out.result = dreplsrv_refresh_partitions(s);
|
---|
351 |
|
---|
352 | return NT_STATUS_OK;
|
---|
353 | }
|
---|
354 |
|
---|
355 | static NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg,
|
---|
356 | struct drepl_takeFSMORole *r)
|
---|
357 | {
|
---|
358 | struct dreplsrv_service *service = talloc_get_type(msg->private_data,
|
---|
359 | struct dreplsrv_service);
|
---|
360 | r->out.result = dreplsrv_fsmo_role_check(service, r->in.role);
|
---|
361 | return NT_STATUS_OK;
|
---|
362 | }
|
---|
363 |
|
---|
364 | /**
|
---|
365 | * Called when the auth code wants us to try and replicate
|
---|
366 | * a users secrets
|
---|
367 | */
|
---|
368 | static NTSTATUS drepl_trigger_repl_secret(struct irpc_message *msg,
|
---|
369 | struct drepl_trigger_repl_secret *r)
|
---|
370 | {
|
---|
371 | struct dreplsrv_service *service = talloc_get_type(msg->private_data,
|
---|
372 | struct dreplsrv_service);
|
---|
373 |
|
---|
374 |
|
---|
375 | drepl_repl_secret(service, r->in.user_dn);
|
---|
376 |
|
---|
377 | /* we are not going to be sending a reply to this request */
|
---|
378 | msg->no_reply = true;
|
---|
379 |
|
---|
380 | return NT_STATUS_OK;
|
---|
381 | }
|
---|
382 |
|
---|
383 |
|
---|
384 | /*
|
---|
385 | DsReplicaAdd messages from the DRSUAPI server are forwarded here
|
---|
386 | */
|
---|
387 | static NTSTATUS dreplsrv_replica_add(struct irpc_message *msg,
|
---|
388 | struct drsuapi_DsReplicaAdd *r)
|
---|
389 | {
|
---|
390 | struct dreplsrv_service *service = talloc_get_type(msg->private_data,
|
---|
391 | struct dreplsrv_service);
|
---|
392 | return drepl_replica_add(service, r);
|
---|
393 | }
|
---|
394 |
|
---|
395 | /*
|
---|
396 | DsReplicaDel messages from the DRSUAPI server are forwarded here
|
---|
397 | */
|
---|
398 | static NTSTATUS dreplsrv_replica_del(struct irpc_message *msg,
|
---|
399 | struct drsuapi_DsReplicaDel *r)
|
---|
400 | {
|
---|
401 | struct dreplsrv_service *service = talloc_get_type(msg->private_data,
|
---|
402 | struct dreplsrv_service);
|
---|
403 | return drepl_replica_del(service, r);
|
---|
404 | }
|
---|
405 |
|
---|
406 | /*
|
---|
407 | DsReplicaMod messages from the DRSUAPI server are forwarded here
|
---|
408 | */
|
---|
409 | static NTSTATUS dreplsrv_replica_mod(struct irpc_message *msg,
|
---|
410 | struct drsuapi_DsReplicaMod *r)
|
---|
411 | {
|
---|
412 | struct dreplsrv_service *service = talloc_get_type(msg->private_data,
|
---|
413 | struct dreplsrv_service);
|
---|
414 | return drepl_replica_mod(service, r);
|
---|
415 | }
|
---|
416 |
|
---|
417 |
|
---|
418 | /*
|
---|
419 | startup the dsdb replicator service task
|
---|
420 | */
|
---|
421 | static void dreplsrv_task_init(struct task_server *task)
|
---|
422 | {
|
---|
423 | WERROR status;
|
---|
424 | struct dreplsrv_service *service;
|
---|
425 | uint32_t periodic_startup_interval;
|
---|
426 |
|
---|
427 | switch (lpcfg_server_role(task->lp_ctx)) {
|
---|
428 | case ROLE_STANDALONE:
|
---|
429 | task_server_terminate(task, "dreplsrv: no DSDB replication required in standalone configuration",
|
---|
430 | false);
|
---|
431 | return;
|
---|
432 | case ROLE_DOMAIN_MEMBER:
|
---|
433 | task_server_terminate(task, "dreplsrv: no DSDB replication required in domain member configuration",
|
---|
434 | false);
|
---|
435 | return;
|
---|
436 | case ROLE_DOMAIN_CONTROLLER:
|
---|
437 | /* Yes, we want DSDB replication */
|
---|
438 | break;
|
---|
439 | }
|
---|
440 |
|
---|
441 | task_server_set_title(task, "task[dreplsrv]");
|
---|
442 |
|
---|
443 | service = talloc_zero(task, struct dreplsrv_service);
|
---|
444 | if (!service) {
|
---|
445 | task_server_terminate(task, "dreplsrv_task_init: out of memory", true);
|
---|
446 | return;
|
---|
447 | }
|
---|
448 | service->task = task;
|
---|
449 | service->startup_time = timeval_current();
|
---|
450 | task->private_data = service;
|
---|
451 |
|
---|
452 | status = dreplsrv_init_creds(service);
|
---|
453 | if (!W_ERROR_IS_OK(status)) {
|
---|
454 | task_server_terminate(task, talloc_asprintf(task,
|
---|
455 | "dreplsrv: Failed to obtain server credentials: %s\n",
|
---|
456 | win_errstr(status)), true);
|
---|
457 | return;
|
---|
458 | }
|
---|
459 |
|
---|
460 | status = dreplsrv_connect_samdb(service, task->lp_ctx);
|
---|
461 | if (!W_ERROR_IS_OK(status)) {
|
---|
462 | task_server_terminate(task, talloc_asprintf(task,
|
---|
463 | "dreplsrv: Failed to connect to local samdb: %s\n",
|
---|
464 | win_errstr(status)), true);
|
---|
465 | return;
|
---|
466 | }
|
---|
467 |
|
---|
468 | status = dreplsrv_load_partitions(service);
|
---|
469 | if (!W_ERROR_IS_OK(status)) {
|
---|
470 | task_server_terminate(task, talloc_asprintf(task,
|
---|
471 | "dreplsrv: Failed to load partitions: %s\n",
|
---|
472 | win_errstr(status)), true);
|
---|
473 | return;
|
---|
474 | }
|
---|
475 |
|
---|
476 | periodic_startup_interval = lpcfg_parm_int(task->lp_ctx, NULL, "dreplsrv", "periodic_startup_interval", 15); /* in seconds */
|
---|
477 | service->periodic.interval = lpcfg_parm_int(task->lp_ctx, NULL, "dreplsrv", "periodic_interval", 300); /* in seconds */
|
---|
478 |
|
---|
479 | status = dreplsrv_periodic_schedule(service, periodic_startup_interval);
|
---|
480 | if (!W_ERROR_IS_OK(status)) {
|
---|
481 | task_server_terminate(task, talloc_asprintf(task,
|
---|
482 | "dreplsrv: Failed to periodic schedule: %s\n",
|
---|
483 | win_errstr(status)), true);
|
---|
484 | return;
|
---|
485 | }
|
---|
486 |
|
---|
487 | /* if we are a RODC then we do not send DSReplicaSync*/
|
---|
488 | if (!service->am_rodc) {
|
---|
489 | service->notify.interval = lpcfg_parm_int(task->lp_ctx, NULL, "dreplsrv",
|
---|
490 | "notify_interval", 5); /* in seconds */
|
---|
491 | status = dreplsrv_notify_schedule(service, service->notify.interval);
|
---|
492 | if (!W_ERROR_IS_OK(status)) {
|
---|
493 | task_server_terminate(task, talloc_asprintf(task,
|
---|
494 | "dreplsrv: Failed to setup notify schedule: %s\n",
|
---|
495 | win_errstr(status)), true);
|
---|
496 | return;
|
---|
497 | }
|
---|
498 | }
|
---|
499 |
|
---|
500 | irpc_add_name(task->msg_ctx, "dreplsrv");
|
---|
501 |
|
---|
502 | IRPC_REGISTER(task->msg_ctx, irpc, DREPLSRV_REFRESH, dreplsrv_refresh, service);
|
---|
503 | IRPC_REGISTER(task->msg_ctx, drsuapi, DRSUAPI_DSREPLICASYNC, drepl_replica_sync, service);
|
---|
504 | IRPC_REGISTER(task->msg_ctx, drsuapi, DRSUAPI_DSREPLICAADD, dreplsrv_replica_add, service);
|
---|
505 | IRPC_REGISTER(task->msg_ctx, drsuapi, DRSUAPI_DSREPLICADEL, dreplsrv_replica_del, service);
|
---|
506 | IRPC_REGISTER(task->msg_ctx, drsuapi, DRSUAPI_DSREPLICAMOD, dreplsrv_replica_mod, service);
|
---|
507 | IRPC_REGISTER(task->msg_ctx, irpc, DREPL_TAKEFSMOROLE, drepl_take_FSMO_role, service);
|
---|
508 | IRPC_REGISTER(task->msg_ctx, irpc, DREPL_TRIGGER_REPL_SECRET, drepl_trigger_repl_secret, service);
|
---|
509 | messaging_register(task->msg_ctx, service, MSG_DREPL_ALLOCATE_RID, dreplsrv_allocate_rid);
|
---|
510 | }
|
---|
511 |
|
---|
512 | /*
|
---|
513 | register ourselves as a available server
|
---|
514 | */
|
---|
515 | NTSTATUS server_service_drepl_init(void)
|
---|
516 | {
|
---|
517 | return register_server_service("drepl", dreplsrv_task_init);
|
---|
518 | }
|
---|