libnet: Add NULL checks to py_net_finddc
[Samba.git] / source3 / libnet / libnet_dssync.c
blobe593ae8536cfd28d0ff741b80534a34df79139a4
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan (metze) Metzmacher 2005
5 Copyright (C) Guenther Deschner 2008
6 Copyright (C) Michael Adam 2008
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.
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.
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/>.
23 #include "includes.h"
24 #include "libnet/libnet_dssync.h"
25 #include "rpc_client/cli_pipe.h"
26 #include "../libcli/drsuapi/drsuapi.h"
27 #include "../librpc/gen_ndr/ndr_drsuapi_c.h"
29 /****************************************************************
30 ****************************************************************/
32 static int libnet_dssync_free_context(struct dssync_context *ctx)
34 WERROR result;
35 struct dcerpc_binding_handle *b;
37 if (!ctx) {
38 return 0;
41 if (is_valid_policy_hnd(&ctx->bind_handle) && ctx->cli) {
42 b = ctx->cli->binding_handle;
43 dcerpc_drsuapi_DsUnbind(b, ctx, &ctx->bind_handle, &result);
46 return 0;
49 /****************************************************************
50 ****************************************************************/
52 NTSTATUS libnet_dssync_init_context(TALLOC_CTX *mem_ctx,
53 struct dssync_context **ctx_p)
55 struct dssync_context *ctx;
57 ctx = talloc_zero(mem_ctx, struct dssync_context);
58 NT_STATUS_HAVE_NO_MEMORY(ctx);
60 talloc_set_destructor(ctx, libnet_dssync_free_context);
61 ctx->clean_old_entries = false;
63 *ctx_p = ctx;
65 return NT_STATUS_OK;
68 /****************************************************************
69 ****************************************************************/
71 static void parse_obj_identifier(struct drsuapi_DsReplicaObjectIdentifier *id,
72 uint32_t *rid)
74 if (!id || !rid) {
75 return;
78 *rid = 0;
80 if (id->sid.num_auths > 0) {
81 *rid = id->sid.sub_auths[id->sid.num_auths - 1];
85 /****************************************************************
86 ****************************************************************/
88 static void libnet_dssync_decrypt_attributes(TALLOC_CTX *mem_ctx,
89 DATA_BLOB *session_key,
90 struct drsuapi_DsReplicaObjectListItemEx *cur)
92 for (; cur; cur = cur->next_object) {
94 uint32_t i;
95 uint32_t rid = 0;
97 parse_obj_identifier(cur->object.identifier, &rid);
99 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
101 struct drsuapi_DsReplicaAttribute *attr;
103 attr = &cur->object.attribute_ctr.attributes[i];
105 if (attr->value_ctr.num_values < 1) {
106 continue;
109 if (!attr->value_ctr.values[0].blob) {
110 continue;
113 drsuapi_decrypt_attribute(mem_ctx,
114 session_key,
115 rid,
117 attr);
121 /****************************************************************
122 ****************************************************************/
124 static NTSTATUS libnet_dssync_bind(TALLOC_CTX *mem_ctx,
125 struct dssync_context *ctx)
127 NTSTATUS status;
128 WERROR werr;
130 struct GUID bind_guid;
131 struct drsuapi_DsBindInfoCtr bind_info;
132 struct drsuapi_DsBindInfo28 info28;
133 struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
135 ZERO_STRUCT(info28);
137 GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
139 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
140 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
141 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
142 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
143 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
144 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
145 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
146 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
147 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
148 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
149 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
150 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
151 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
152 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
153 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
154 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
155 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
156 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
157 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
158 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
159 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
160 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
161 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
162 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
163 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
164 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
165 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
166 info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
167 info28.site_guid = GUID_zero();
168 info28.pid = 508;
169 info28.repl_epoch = 0;
171 bind_info.length = 28;
172 bind_info.info.info28 = info28;
174 status = dcerpc_drsuapi_DsBind(b, mem_ctx,
175 &bind_guid,
176 &bind_info,
177 &ctx->bind_handle,
178 &werr);
180 if (!NT_STATUS_IS_OK(status)) {
181 return status;
184 if (!W_ERROR_IS_OK(werr)) {
185 return werror_to_ntstatus(werr);
188 ZERO_STRUCT(ctx->remote_info28);
189 switch (bind_info.length) {
190 case 24: {
191 struct drsuapi_DsBindInfo24 *info24;
192 info24 = &bind_info.info.info24;
193 ctx->remote_info28.site_guid = info24->site_guid;
194 ctx->remote_info28.supported_extensions = info24->supported_extensions;
195 ctx->remote_info28.pid = info24->pid;
196 ctx->remote_info28.repl_epoch = 0;
197 break;
199 case 28: {
200 ctx->remote_info28 = bind_info.info.info28;
201 break;
203 case 32: {
204 struct drsuapi_DsBindInfo32 *info32;
205 info32 = &bind_info.info.info32;
206 ctx->remote_info28.site_guid = info32->site_guid;
207 ctx->remote_info28.supported_extensions = info32->supported_extensions;
208 ctx->remote_info28.pid = info32->pid;
209 ctx->remote_info28.repl_epoch = info32->repl_epoch;
210 break;
212 case 48: {
213 struct drsuapi_DsBindInfo48 *info48;
214 info48 = &bind_info.info.info48;
215 ctx->remote_info28.site_guid = info48->site_guid;
216 ctx->remote_info28.supported_extensions = info48->supported_extensions;
217 ctx->remote_info28.pid = info48->pid;
218 ctx->remote_info28.repl_epoch = info48->repl_epoch;
219 break;
221 case 52: {
222 struct drsuapi_DsBindInfo52 *info52;
223 info52 = &bind_info.info.info52;
224 ctx->remote_info28.site_guid = info52->site_guid;
225 ctx->remote_info28.supported_extensions = info52->supported_extensions;
226 ctx->remote_info28.pid = info52->pid;
227 ctx->remote_info28.repl_epoch = info52->repl_epoch;
228 break;
230 default:
231 DEBUG(1, ("Warning: invalid info length in bind info: %d\n",
232 bind_info.length));
233 break;
236 return status;
239 /****************************************************************
240 ****************************************************************/
242 static NTSTATUS libnet_dssync_lookup_nc(TALLOC_CTX *mem_ctx,
243 struct dssync_context *ctx)
245 NTSTATUS status;
246 WERROR werr;
247 uint32_t level = 1;
248 union drsuapi_DsNameRequest req;
249 uint32_t level_out;
250 struct drsuapi_DsNameString names[1];
251 union drsuapi_DsNameCtr ctr;
252 struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
254 names[0].str = talloc_asprintf(mem_ctx, "%s\\", ctx->domain_name);
255 NT_STATUS_HAVE_NO_MEMORY(names[0].str);
257 req.req1.codepage = 1252; /* german */
258 req.req1.language = 0x00000407; /* german */
259 req.req1.count = 1;
260 req.req1.names = names;
261 req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
262 req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_UNKNOWN;
263 req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
265 status = dcerpc_drsuapi_DsCrackNames(b, mem_ctx,
266 &ctx->bind_handle,
267 level,
268 &req,
269 &level_out,
270 &ctr,
271 &werr);
272 if (!NT_STATUS_IS_OK(status)) {
273 ctx->error_message = talloc_asprintf(ctx,
274 "Failed to lookup DN for domain name: %s",
275 get_friendly_nt_error_msg(status));
276 return status;
279 if (!W_ERROR_IS_OK(werr)) {
280 ctx->error_message = talloc_asprintf(ctx,
281 "Failed to lookup DN for domain name: %s",
282 get_friendly_werror_msg(werr));
283 return werror_to_ntstatus(werr);
286 if (ctr.ctr1->count != 1) {
287 return NT_STATUS_UNSUCCESSFUL;
290 if (ctr.ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
291 return NT_STATUS_UNSUCCESSFUL;
294 ctx->nc_dn = talloc_strdup(mem_ctx, ctr.ctr1->array[0].result_name);
295 NT_STATUS_HAVE_NO_MEMORY(ctx->nc_dn);
297 if (!ctx->dns_domain_name) {
298 ctx->dns_domain_name = talloc_strdup_upper(mem_ctx,
299 ctr.ctr1->array[0].dns_domain_name);
300 NT_STATUS_HAVE_NO_MEMORY(ctx->dns_domain_name);
303 return NT_STATUS_OK;
306 /****************************************************************
307 ****************************************************************/
309 static NTSTATUS libnet_dssync_init(TALLOC_CTX *mem_ctx,
310 struct dssync_context *ctx)
312 NTSTATUS status;
314 status = libnet_dssync_bind(mem_ctx, ctx);
315 if (!NT_STATUS_IS_OK(status)) {
316 return status;
319 if (!ctx->nc_dn) {
320 status = libnet_dssync_lookup_nc(mem_ctx, ctx);
323 return status;
326 /****************************************************************
327 ****************************************************************/
329 static NTSTATUS libnet_dssync_build_request(TALLOC_CTX *mem_ctx,
330 struct dssync_context *ctx,
331 const char *dn,
332 struct replUpToDateVectorBlob *utdv,
333 uint32_t *plevel,
334 union drsuapi_DsGetNCChangesRequest *preq)
336 NTSTATUS status;
337 uint32_t count;
338 uint32_t level;
339 union drsuapi_DsGetNCChangesRequest req;
340 enum drsuapi_DsExtendedOperation extended_op;
341 struct drsuapi_DsReplicaObjectIdentifier *nc = NULL;
342 struct drsuapi_DsReplicaCursorCtrEx *cursors = NULL;
344 uint32_t replica_flags = DRSUAPI_DRS_WRIT_REP |
345 DRSUAPI_DRS_INIT_SYNC |
346 DRSUAPI_DRS_PER_SYNC |
347 DRSUAPI_DRS_GET_ANC |
348 DRSUAPI_DRS_NEVER_SYNCED;
350 ZERO_STRUCT(req);
352 if (ctx->remote_info28.supported_extensions
353 & DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8)
355 level = 8;
356 } else {
357 level = 5;
360 nc = talloc_zero(mem_ctx, struct drsuapi_DsReplicaObjectIdentifier);
361 if (!nc) {
362 status = NT_STATUS_NO_MEMORY;
363 goto fail;
365 nc->dn = dn;
366 nc->guid = GUID_zero();
367 nc->sid = (struct dom_sid) {0};
369 if (!ctx->single_object_replication &&
370 !ctx->force_full_replication && utdv)
372 cursors = talloc_zero(mem_ctx,
373 struct drsuapi_DsReplicaCursorCtrEx);
374 if (!cursors) {
375 status = NT_STATUS_NO_MEMORY;
376 goto fail;
379 switch (utdv->version) {
380 case 1:
381 cursors->count = utdv->ctr.ctr1.count;
382 cursors->cursors = utdv->ctr.ctr1.cursors;
383 break;
384 case 2:
385 cursors->count = utdv->ctr.ctr2.count;
386 cursors->cursors = talloc_array(cursors,
387 struct drsuapi_DsReplicaCursor,
388 cursors->count);
389 if (!cursors->cursors) {
390 status = NT_STATUS_NO_MEMORY;
391 goto fail;
393 for (count = 0; count < cursors->count; count++) {
394 cursors->cursors[count].source_dsa_invocation_id =
395 utdv->ctr.ctr2.cursors[count].source_dsa_invocation_id;
396 cursors->cursors[count].highest_usn =
397 utdv->ctr.ctr2.cursors[count].highest_usn;
399 break;
403 if (ctx->single_object_replication) {
404 extended_op = DRSUAPI_EXOP_REPL_OBJ;
405 } else {
406 extended_op = DRSUAPI_EXOP_NONE;
409 if (level == 8) {
410 req.req8.naming_context = nc;
411 req.req8.replica_flags = replica_flags;
412 req.req8.max_object_count = 402;
413 req.req8.max_ndr_size = 402116;
414 req.req8.uptodateness_vector = cursors;
415 req.req8.extended_op = extended_op;
416 } else if (level == 5) {
417 req.req5.naming_context = nc;
418 req.req5.replica_flags = replica_flags;
419 req.req5.max_object_count = 402;
420 req.req5.max_ndr_size = 402116;
421 req.req5.uptodateness_vector = cursors;
422 req.req5.extended_op = extended_op;
423 } else {
424 status = NT_STATUS_INVALID_PARAMETER;
425 goto fail;
428 if (plevel) {
429 *plevel = level;
432 if (preq) {
433 *preq = req;
436 return NT_STATUS_OK;
438 fail:
439 TALLOC_FREE(nc);
440 TALLOC_FREE(cursors);
441 return status;
444 static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
445 struct dssync_context *ctx,
446 uint32_t level,
447 union drsuapi_DsGetNCChangesRequest *req,
448 struct replUpToDateVectorBlob **pnew_utdv)
450 NTSTATUS status;
451 WERROR werr;
452 union drsuapi_DsGetNCChangesCtr ctr;
453 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
454 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
455 struct replUpToDateVectorBlob *new_utdv = NULL;
456 uint32_t level_out = 0;
457 uint32_t out_level = 0;
458 int y;
459 bool last_query;
460 struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
462 if (!ctx->single_object_replication) {
463 new_utdv = talloc_zero(mem_ctx, struct replUpToDateVectorBlob);
464 if (!new_utdv) {
465 status = NT_STATUS_NO_MEMORY;
466 goto out;
470 for (y=0, last_query = false; !last_query; y++) {
471 struct drsuapi_DsReplicaObjectListItemEx *first_object = NULL;
472 struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr = NULL;
473 uint32_t linked_attributes_count = 0;
474 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes = NULL;
476 if (level == 8) {
477 DEBUG(1,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
478 (long long)req->req8.highwatermark.tmp_highest_usn,
479 (long long)req->req8.highwatermark.highest_usn));
480 } else if (level == 5) {
481 DEBUG(1,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
482 (long long)req->req5.highwatermark.tmp_highest_usn,
483 (long long)req->req5.highwatermark.highest_usn));
486 status = dcerpc_drsuapi_DsGetNCChanges(b, mem_ctx,
487 &ctx->bind_handle,
488 level,
489 req,
490 &level_out,
491 &ctr,
492 &werr);
493 if (!NT_STATUS_IS_OK(status)) {
494 ctx->error_message = talloc_asprintf(ctx,
495 "Failed to get NC Changes: %s",
496 get_friendly_nt_error_msg(status));
497 goto out;
500 if (!W_ERROR_IS_OK(werr)) {
501 status = werror_to_ntstatus(werr);
502 ctx->error_message = talloc_asprintf(ctx,
503 "Failed to get NC Changes: %s",
504 get_friendly_werror_msg(werr));
505 goto out;
508 if (level_out == 1) {
509 out_level = 1;
510 ctr1 = &ctr.ctr1;
511 } else if (level_out == 2 && ctr.ctr2.mszip1.ts) {
512 out_level = 1;
513 ctr1 = &ctr.ctr2.mszip1.ts->ctr1;
514 } else if (level_out == 6) {
515 out_level = 6;
516 ctr6 = &ctr.ctr6;
517 } else if (level_out == 7
518 && ctr.ctr7.level == 6
519 && ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
520 && ctr.ctr7.ctr.mszip6.ts) {
521 out_level = 6;
522 ctr6 = &ctr.ctr7.ctr.mszip6.ts->ctr6;
523 } else if (level_out == 7
524 && ctr.ctr7.level == 6
525 && ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS
526 && ctr.ctr7.ctr.xpress6.ts) {
527 out_level = 6;
528 ctr6 = &ctr.ctr7.ctr.xpress6.ts->ctr6;
531 if (out_level == 1) {
532 DEBUG(1,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
533 (long long)ctr1->new_highwatermark.tmp_highest_usn,
534 (long long)ctr1->new_highwatermark.highest_usn));
536 first_object = ctr1->first_object;
537 mapping_ctr = &ctr1->mapping_ctr;
539 if (ctr1->more_data) {
540 req->req5.highwatermark = ctr1->new_highwatermark;
541 } else {
542 last_query = true;
543 if (ctr1->uptodateness_vector &&
544 !ctx->single_object_replication)
546 new_utdv->version = 1;
547 new_utdv->ctr.ctr1.count =
548 ctr1->uptodateness_vector->count;
549 new_utdv->ctr.ctr1.cursors =
550 ctr1->uptodateness_vector->cursors;
553 } else if (out_level == 6) {
554 DEBUG(1,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
555 (long long)ctr6->new_highwatermark.tmp_highest_usn,
556 (long long)ctr6->new_highwatermark.highest_usn));
558 first_object = ctr6->first_object;
559 mapping_ctr = &ctr6->mapping_ctr;
561 linked_attributes = ctr6->linked_attributes;
562 linked_attributes_count = ctr6->linked_attributes_count;
564 if (ctr6->more_data) {
565 req->req8.highwatermark = ctr6->new_highwatermark;
566 } else {
567 last_query = true;
568 if (ctr6->uptodateness_vector &&
569 !ctx->single_object_replication)
571 new_utdv->version = 2;
572 new_utdv->ctr.ctr2.count =
573 ctr6->uptodateness_vector->count;
574 new_utdv->ctr.ctr2.cursors =
575 ctr6->uptodateness_vector->cursors;
580 status = cli_get_session_key(mem_ctx, ctx->cli, &ctx->session_key);
581 if (!NT_STATUS_IS_OK(status)) {
582 ctx->error_message = talloc_asprintf(ctx,
583 "Failed to get Session Key: %s",
584 nt_errstr(status));
585 goto out;
588 libnet_dssync_decrypt_attributes(mem_ctx,
589 &ctx->session_key,
590 first_object);
592 if (ctx->ops->process_objects) {
593 status = ctx->ops->process_objects(ctx, mem_ctx,
594 first_object,
595 mapping_ctr);
596 if (!NT_STATUS_IS_OK(status)) {
597 ctx->error_message = talloc_asprintf(ctx,
598 "Failed to call processing function: %s",
599 nt_errstr(status));
600 goto out;
604 if (linked_attributes_count == 0) {
605 continue;
608 if (ctx->ops->process_links) {
609 status = ctx->ops->process_links(ctx, mem_ctx,
610 linked_attributes_count,
611 linked_attributes,
612 mapping_ctr);
613 if (!NT_STATUS_IS_OK(status)) {
614 ctx->error_message = talloc_asprintf(ctx,
615 "Failed to call processing function: %s",
616 nt_errstr(status));
617 goto out;
622 *pnew_utdv = new_utdv;
624 out:
625 return status;
628 static NTSTATUS libnet_dssync_process(TALLOC_CTX *mem_ctx,
629 struct dssync_context *ctx)
631 NTSTATUS status;
633 uint32_t level = 0;
634 union drsuapi_DsGetNCChangesRequest req;
635 struct replUpToDateVectorBlob *old_utdv = NULL;
636 struct replUpToDateVectorBlob *pnew_utdv = NULL;
637 const char **dns;
638 uint32_t dn_count;
639 uint32_t count;
641 if (ctx->ops->startup) {
642 status = ctx->ops->startup(ctx, mem_ctx, &old_utdv);
643 if (!NT_STATUS_IS_OK(status)) {
644 ctx->error_message = talloc_asprintf(ctx,
645 "Failed to call startup operation: %s",
646 nt_errstr(status));
647 goto out;
651 if (ctx->single_object_replication && ctx->object_dns) {
652 dns = ctx->object_dns;
653 dn_count = ctx->object_count;
654 } else {
655 dns = &ctx->nc_dn;
656 dn_count = 1;
659 status = NT_STATUS_OK;
661 for (count=0; count < dn_count; count++) {
662 status = libnet_dssync_build_request(mem_ctx, ctx,
663 dns[count],
664 old_utdv, &level,
665 &req);
666 if (!NT_STATUS_IS_OK(status)) {
667 goto out;
670 status = libnet_dssync_getncchanges(mem_ctx, ctx, level, &req,
671 &pnew_utdv);
672 if (!NT_STATUS_IS_OK(status)) {
673 if (!ctx->error_message) {
674 ctx->error_message = talloc_asprintf(ctx,
675 "Failed to call DsGetNCCHanges: %s",
676 nt_errstr(status));
678 goto out;
682 if (ctx->ops->finish) {
683 status = ctx->ops->finish(ctx, mem_ctx, pnew_utdv);
684 if (!NT_STATUS_IS_OK(status)) {
685 ctx->error_message = talloc_asprintf(ctx,
686 "Failed to call finishing operation: %s",
687 nt_errstr(status));
688 goto out;
692 out:
693 return status;
696 /****************************************************************
697 ****************************************************************/
699 NTSTATUS libnet_dssync(TALLOC_CTX *mem_ctx,
700 struct dssync_context *ctx)
702 NTSTATUS status;
703 TALLOC_CTX *tmp_ctx;
705 tmp_ctx = talloc_new(mem_ctx);
706 if (!tmp_ctx) {
707 return NT_STATUS_NO_MEMORY;
710 status = libnet_dssync_init(tmp_ctx, ctx);
711 if (!NT_STATUS_IS_OK(status)) {
712 goto out;
715 status = libnet_dssync_process(tmp_ctx, ctx);
716 if (!NT_STATUS_IS_OK(status)) {
717 goto out;
720 out:
721 TALLOC_FREE(tmp_ctx);
722 return status;