2 Unix SMB/CIFS implementation.
4 implement the DSGetNCChanges call
6 Copyright (C) Anatoliy Atanasov 2009
7 Copyright (C) Andrew Tridgell 2009
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "rpc_server/dcerpc_server.h"
25 #include "dsdb/samdb/samdb.h"
26 #include "param/param.h"
27 #include "librpc/gen_ndr/ndr_drsblobs.h"
28 #include "librpc/gen_ndr/ndr_drsuapi.h"
29 #include "librpc/gen_ndr/ndr_security.h"
30 #include "libcli/security/security.h"
31 #include "libcli/security/session.h"
32 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
33 #include "rpc_server/dcerpc_server_proto.h"
34 #include "../libcli/drsuapi/drsuapi.h"
35 #include "lib/util/binsearch.h"
36 #include "lib/util/tsort.h"
37 #include "auth/session.h"
38 #include "dsdb/common/util.h"
41 build a DsReplicaObjectIdentifier from a ldb msg
43 static struct drsuapi_DsReplicaObjectIdentifier *get_object_identifier(TALLOC_CTX *mem_ctx,
44 struct ldb_message *msg)
46 struct drsuapi_DsReplicaObjectIdentifier *identifier;
49 identifier = talloc(mem_ctx, struct drsuapi_DsReplicaObjectIdentifier);
50 if (identifier == NULL) {
54 identifier->dn = ldb_dn_alloc_linearized(identifier, msg->dn);
55 identifier->guid = samdb_result_guid(msg, "objectGUID");
57 sid = samdb_result_dom_sid(identifier, msg, "objectSid");
59 identifier->sid = *sid;
61 ZERO_STRUCT(identifier->sid);
66 static int udv_compare(const struct GUID *guid1, struct GUID guid2)
68 return GUID_compare(guid1, &guid2);
72 see if we can filter an attribute using the uptodateness_vector
74 static bool udv_filter(const struct drsuapi_DsReplicaCursorCtrEx *udv,
75 const struct GUID *originating_invocation_id,
76 uint64_t originating_usn)
78 const struct drsuapi_DsReplicaCursor *c;
79 if (udv == NULL) return false;
80 BINARY_ARRAY_SEARCH(udv->cursors, udv->count, source_dsa_invocation_id,
81 originating_invocation_id, udv_compare, c);
82 if (c && originating_usn <= c->highest_usn) {
89 static int attid_cmp(enum drsuapi_DsAttributeId a1, enum drsuapi_DsAttributeId a2)
91 if (a1 == a2) return 0;
92 return ((uint32_t)a1) > ((uint32_t)a2) ? 1 : -1;
96 check if an attribute is in a partial_attribute_set
98 static bool check_partial_attribute_set(const struct dsdb_attribute *sa,
99 struct drsuapi_DsPartialAttributeSet *pas)
101 enum drsuapi_DsAttributeId *result;
102 BINARY_ARRAY_SEARCH_V(pas->attids, pas->num_attids, (enum drsuapi_DsAttributeId)sa->attributeID_id,
104 return result != NULL;
109 drsuapi_DsGetNCChanges for one object
111 static WERROR get_nc_changes_build_object(struct drsuapi_DsReplicaObjectListItemEx *obj,
112 struct ldb_message *msg,
113 struct ldb_context *sam_ctx,
114 struct ldb_dn *ncRoot_dn,
116 struct dsdb_schema *schema,
117 DATA_BLOB *session_key,
118 uint64_t highest_usn,
119 uint32_t replica_flags,
120 struct drsuapi_DsPartialAttributeSet *partial_attribute_set,
121 struct drsuapi_DsReplicaCursorCtrEx *uptodateness_vector,
122 enum drsuapi_DsExtendedOperation extended_op)
124 const struct ldb_val *md_value;
126 struct replPropertyMetaDataBlob md;
128 enum ndr_err_code ndr_err;
131 const struct dsdb_attribute *rdn_sa;
132 unsigned int instanceType;
133 struct dsdb_syntax_ctx syntax_ctx;
135 /* make dsdb sytanx context for conversions */
136 dsdb_syntax_ctx_init(&syntax_ctx, sam_ctx, schema);
137 syntax_ctx.is_schema_nc = is_schema_nc;
139 instanceType = ldb_msg_find_attr_as_uint(msg, "instanceType", 0);
140 if (instanceType & INSTANCE_TYPE_IS_NC_HEAD) {
141 obj->is_nc_prefix = true;
142 obj->parent_object_guid = NULL;
144 obj->is_nc_prefix = false;
145 obj->parent_object_guid = talloc(obj, struct GUID);
146 if (obj->parent_object_guid == NULL) {
147 return WERR_DS_DRA_INTERNAL_ERROR;
149 *obj->parent_object_guid = samdb_result_guid(msg, "parentGUID");
150 if (GUID_all_zero(obj->parent_object_guid)) {
151 DEBUG(0,(__location__ ": missing parentGUID for %s\n",
152 ldb_dn_get_linearized(msg->dn)));
153 return WERR_DS_DRA_INTERNAL_ERROR;
156 obj->next_object = NULL;
158 md_value = ldb_msg_find_ldb_val(msg, "replPropertyMetaData");
160 /* nothing to send */
164 if (instanceType & INSTANCE_TYPE_UNINSTANT) {
165 /* don't send uninstantiated objects */
169 ndr_err = ndr_pull_struct_blob(md_value, obj, &md,
170 (ndr_pull_flags_fn_t)ndr_pull_replPropertyMetaDataBlob);
171 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
172 return WERR_DS_DRA_INTERNAL_ERROR;
175 if (md.version != 1) {
176 return WERR_DS_DRA_INTERNAL_ERROR;
179 rdn = ldb_dn_get_rdn_name(msg->dn);
181 DEBUG(0,(__location__ ": No rDN for %s\n", ldb_dn_get_linearized(msg->dn)));
182 return WERR_DS_DRA_INTERNAL_ERROR;
185 rdn_sa = dsdb_attribute_by_lDAPDisplayName(schema, rdn);
186 if (rdn_sa == NULL) {
187 DEBUG(0,(__location__ ": Can't find dsds_attribute for rDN %s in %s\n",
188 rdn, ldb_dn_get_linearized(msg->dn)));
189 return WERR_DS_DRA_INTERNAL_ERROR;
192 obj->meta_data_ctr = talloc(obj, struct drsuapi_DsReplicaMetaDataCtr);
193 attids = talloc_array(obj, uint32_t, md.ctr.ctr1.count);
195 obj->object.identifier = get_object_identifier(obj, msg);
196 if (obj->object.identifier == NULL) {
199 dom_sid_split_rid(NULL, &obj->object.identifier->sid, NULL, &rid);
201 obj->meta_data_ctr->meta_data = talloc_array(obj, struct drsuapi_DsReplicaMetaData, md.ctr.ctr1.count);
202 for (n=i=0; i<md.ctr.ctr1.count; i++) {
203 const struct dsdb_attribute *sa;
204 bool force_attribute = false;
206 /* if the attribute has not changed, and it is not the
207 instanceType then don't include it */
208 if (md.ctr.ctr1.array[i].local_usn < highest_usn &&
209 extended_op != DRSUAPI_EXOP_REPL_SECRET &&
210 md.ctr.ctr1.array[i].attid != DRSUAPI_ATTID_instanceType) continue;
212 /* don't include the rDN */
213 if (md.ctr.ctr1.array[i].attid == rdn_sa->attributeID_id) continue;
215 sa = dsdb_attribute_by_attributeID_id(schema, md.ctr.ctr1.array[i].attid);
217 DEBUG(0,(__location__ ": Failed to find attribute in schema for attrid %u mentioned in replPropertyMetaData of %s\n",
218 (unsigned int)md.ctr.ctr1.array[i].attid,
219 ldb_dn_get_linearized(msg->dn)));
220 return WERR_DS_DRA_INTERNAL_ERROR;
224 struct ldb_message_element *el;
225 el = ldb_msg_find_element(msg, sa->lDAPDisplayName);
226 if (el && el->num_values && dsdb_dn_is_upgraded_link_val(&el->values[0])) {
227 /* don't send upgraded links inline */
232 if (extended_op == DRSUAPI_EXOP_REPL_SECRET &&
233 !dsdb_attr_in_rodc_fas(sa)) {
234 force_attribute = true;
235 DEBUG(4,("Forcing attribute %s in %s\n",
236 sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
239 /* filter by uptodateness_vector */
240 if (md.ctr.ctr1.array[i].attid != DRSUAPI_ATTID_instanceType &&
242 udv_filter(uptodateness_vector,
243 &md.ctr.ctr1.array[i].originating_invocation_id,
244 md.ctr.ctr1.array[i].originating_usn)) {
248 /* filter by partial_attribute_set */
249 if (partial_attribute_set && !check_partial_attribute_set(sa, partial_attribute_set)) {
253 obj->meta_data_ctr->meta_data[n].originating_change_time = md.ctr.ctr1.array[i].originating_change_time;
254 obj->meta_data_ctr->meta_data[n].version = md.ctr.ctr1.array[i].version;
255 obj->meta_data_ctr->meta_data[n].originating_invocation_id = md.ctr.ctr1.array[i].originating_invocation_id;
256 obj->meta_data_ctr->meta_data[n].originating_usn = md.ctr.ctr1.array[i].originating_usn;
257 attids[n] = md.ctr.ctr1.array[i].attid;
261 /* ignore it if its an empty change. Note that renames always
262 * change the 'name' attribute, so they won't be ignored by
265 (n == 1 && attids[0] == DRSUAPI_ATTID_instanceType)) {
266 talloc_free(obj->meta_data_ctr);
267 obj->meta_data_ctr = NULL;
271 obj->meta_data_ctr->count = n;
273 obj->object.flags = DRSUAPI_DS_REPLICA_OBJECT_FROM_MASTER;
274 obj->object.attribute_ctr.num_attributes = obj->meta_data_ctr->count;
275 obj->object.attribute_ctr.attributes = talloc_array(obj, struct drsuapi_DsReplicaAttribute,
276 obj->object.attribute_ctr.num_attributes);
279 * Note that the meta_data array and the attributes array must
280 * be the same size and in the same order
282 for (i=0; i<obj->object.attribute_ctr.num_attributes; i++) {
283 struct ldb_message_element *el;
285 const struct dsdb_attribute *sa;
287 sa = dsdb_attribute_by_attributeID_id(schema, attids[i]);
289 DEBUG(0,("Unable to find attributeID %u in schema\n", attids[i]));
290 return WERR_DS_DRA_INTERNAL_ERROR;
293 el = ldb_msg_find_element(msg, sa->lDAPDisplayName);
295 /* this happens for attributes that have been removed */
296 DEBUG(5,("No element '%s' for attributeID %u in message\n",
297 sa->lDAPDisplayName, attids[i]));
298 ZERO_STRUCT(obj->object.attribute_ctr.attributes[i]);
299 obj->object.attribute_ctr.attributes[i].attid =
300 dsdb_attribute_get_attid(sa, syntax_ctx.is_schema_nc);
302 werr = sa->syntax->ldb_to_drsuapi(&syntax_ctx, sa, el, obj,
303 &obj->object.attribute_ctr.attributes[i]);
304 if (!W_ERROR_IS_OK(werr)) {
305 DEBUG(0,("Unable to convert %s to DRS object - %s\n",
306 sa->lDAPDisplayName, win_errstr(werr)));
309 /* if DRSUAPI_DRS_SPECIAL_SECRET_PROCESSING is set
310 * check if attribute is secret and send a null value
312 if (replica_flags & DRSUAPI_DRS_SPECIAL_SECRET_PROCESSING) {
313 drsuapi_process_secret_attribute(&obj->object.attribute_ctr.attributes[i],
314 &obj->meta_data_ctr->meta_data[i]);
316 /* some attributes needs to be encrypted
318 werr = drsuapi_encrypt_attribute(obj, session_key, rid,
319 &obj->object.attribute_ctr.attributes[i]);
320 if (!W_ERROR_IS_OK(werr)) {
321 DEBUG(0,("Unable to encrypt %s in DRS object - %s\n",
322 sa->lDAPDisplayName, win_errstr(werr)));
333 add one linked attribute from an object to the list of linked
334 attributes in a getncchanges request
336 static WERROR get_nc_changes_add_la(TALLOC_CTX *mem_ctx,
337 struct ldb_context *sam_ctx,
338 const struct dsdb_schema *schema,
339 const struct dsdb_attribute *sa,
340 struct ldb_message *msg,
341 struct dsdb_dn *dsdb_dn,
342 struct drsuapi_DsReplicaLinkedAttribute **la_list,
345 struct drsuapi_DsReplicaLinkedAttribute *la;
350 (*la_list) = talloc_realloc(mem_ctx, *la_list, struct drsuapi_DsReplicaLinkedAttribute, (*la_count)+1);
351 W_ERROR_HAVE_NO_MEMORY(*la_list);
353 la = &(*la_list)[*la_count];
355 la->identifier = get_object_identifier(*la_list, msg);
356 W_ERROR_HAVE_NO_MEMORY(la->identifier);
358 active = (dsdb_dn_rmd_flags(dsdb_dn->dn) & DSDB_RMD_FLAG_DELETED) == 0;
361 /* We have to check that the inactive link still point to an existing object */
367 v = ldb_msg_find_attr_as_string(msg, "isDeleted", "false");
368 if (strncasecmp(v, "true", 4) == 0) {
369 v = ldb_msg_find_attr_as_string(msg, "isRecycled", "false");
371 * Do not skip link when the object is just deleted (isRecycled not present)
372 * Do it for tomstones or recycled ones
374 if (strncasecmp(v, "true", 4) == 0) {
375 DEBUG(2, (" object %s is deleted, not returning linked attribute !\n",
376 ldb_dn_get_linearized(msg->dn)));
380 status = dsdb_get_extended_dn_guid(dsdb_dn->dn, &guid, "GUID");
381 if (!NT_STATUS_IS_OK(status)) {
382 DEBUG(0,(__location__ " Unable to extract GUID in linked attribute '%s' in '%s'\n",
383 sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
384 return ntstatus_to_werror(status);
386 ret = dsdb_find_dn_by_guid(sam_ctx, mem_ctx, &guid, &tdn);
387 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
388 DEBUG(2, (" Search of guid %s returned 0 objects, skipping it !\n",
389 GUID_string(mem_ctx, &guid)));
391 } else if (ret != LDB_SUCCESS) {
392 DEBUG(0, (__location__ " Search of guid %s failed with error code %d\n",
393 GUID_string(mem_ctx, &guid),
398 la->attid = sa->attributeID_id;
399 la->flags = active?DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE:0;
401 status = dsdb_get_extended_dn_uint32(dsdb_dn->dn, &la->meta_data.version, "RMD_VERSION");
402 if (!NT_STATUS_IS_OK(status)) {
403 DEBUG(0,(__location__ " No RMD_VERSION in linked attribute '%s' in '%s'\n",
404 sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
405 return ntstatus_to_werror(status);
407 status = dsdb_get_extended_dn_nttime(dsdb_dn->dn, &la->meta_data.originating_change_time, "RMD_CHANGETIME");
408 if (!NT_STATUS_IS_OK(status)) {
409 DEBUG(0,(__location__ " No RMD_CHANGETIME in linked attribute '%s' in '%s'\n",
410 sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
411 return ntstatus_to_werror(status);
413 status = dsdb_get_extended_dn_guid(dsdb_dn->dn, &la->meta_data.originating_invocation_id, "RMD_INVOCID");
414 if (!NT_STATUS_IS_OK(status)) {
415 DEBUG(0,(__location__ " No RMD_INVOCID in linked attribute '%s' in '%s'\n",
416 sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
417 return ntstatus_to_werror(status);
419 status = dsdb_get_extended_dn_uint64(dsdb_dn->dn, &la->meta_data.originating_usn, "RMD_ORIGINATING_USN");
420 if (!NT_STATUS_IS_OK(status)) {
421 DEBUG(0,(__location__ " No RMD_ORIGINATING_USN in linked attribute '%s' in '%s'\n",
422 sa->lDAPDisplayName, ldb_dn_get_linearized(msg->dn)));
423 return ntstatus_to_werror(status);
426 status = dsdb_get_extended_dn_nttime(dsdb_dn->dn, &la->originating_add_time, "RMD_ADDTIME");
427 if (!NT_STATUS_IS_OK(status)) {
428 /* this is possible for upgraded links */
429 la->originating_add_time = la->meta_data.originating_change_time;
432 werr = dsdb_dn_la_to_blob(sam_ctx, sa, schema, *la_list, dsdb_dn, &la->value.blob);
433 W_ERROR_NOT_OK_RETURN(werr);
441 add linked attributes from an object to the list of linked
442 attributes in a getncchanges request
444 static WERROR get_nc_changes_add_links(struct ldb_context *sam_ctx,
446 struct ldb_dn *ncRoot_dn,
447 struct dsdb_schema *schema,
448 uint64_t highest_usn,
449 uint32_t replica_flags,
450 struct ldb_message *msg,
451 struct drsuapi_DsReplicaLinkedAttribute **la_list,
453 struct drsuapi_DsReplicaCursorCtrEx *uptodateness_vector)
456 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
457 uint64_t uSNChanged = ldb_msg_find_attr_as_int(msg, "uSNChanged", -1);
459 for (i=0; i<msg->num_elements; i++) {
460 struct ldb_message_element *el = &msg->elements[i];
461 const struct dsdb_attribute *sa;
464 sa = dsdb_attribute_by_lDAPDisplayName(schema, el->name);
466 if (!sa || sa->linkID == 0 || (sa->linkID & 1)) {
467 /* we only want forward links */
471 if (el->num_values && !dsdb_dn_is_upgraded_link_val(&el->values[0])) {
472 /* its an old style link, it will have been
473 * sent in the main replication data */
477 for (j=0; j<el->num_values; j++) {
478 struct dsdb_dn *dsdb_dn;
483 dsdb_dn = dsdb_dn_parse(tmp_ctx, sam_ctx, &el->values[j], sa->syntax->ldap_oid);
484 if (dsdb_dn == NULL) {
485 DEBUG(1,(__location__ ": Failed to parse DN for %s in %s\n",
486 el->name, ldb_dn_get_linearized(msg->dn)));
487 talloc_free(tmp_ctx);
488 return WERR_DS_DRA_INTERNAL_ERROR;
491 status = dsdb_get_extended_dn_uint64(dsdb_dn->dn, &local_usn, "RMD_LOCAL_USN");
492 if (!NT_STATUS_IS_OK(status)) {
493 /* this can happen for attributes
494 given to us with old style meta
499 if (local_usn > uSNChanged) {
500 DEBUG(1,(__location__ ": uSNChanged less than RMD_LOCAL_USN for %s on %s\n",
501 el->name, ldb_dn_get_linearized(msg->dn)));
502 talloc_free(tmp_ctx);
503 return WERR_DS_DRA_INTERNAL_ERROR;
506 if (local_usn < highest_usn) {
510 werr = get_nc_changes_add_la(mem_ctx, sam_ctx, schema, sa, msg,
511 dsdb_dn, la_list, la_count);
512 if (!W_ERROR_IS_OK(werr)) {
513 talloc_free(tmp_ctx);
519 talloc_free(tmp_ctx);
524 fill in the cursors return based on the replUpToDateVector for the ncRoot_dn
526 static WERROR get_nc_changes_udv(struct ldb_context *sam_ctx,
527 struct ldb_dn *ncRoot_dn,
528 struct drsuapi_DsReplicaCursor2CtrEx *udv)
536 ret = dsdb_load_udv_v2(sam_ctx, ncRoot_dn, udv, &udv->cursors, &udv->count);
537 if (ret != LDB_SUCCESS) {
538 DEBUG(0,(__location__ ": Failed to load UDV for %s - %s\n",
539 ldb_dn_get_linearized(ncRoot_dn), ldb_errstring(sam_ctx)));
540 return WERR_DS_DRA_INTERNAL_ERROR;
547 /* comparison function for linked attributes - see CompareLinks() in
548 * MS-DRSR section 4.1.10.5.17 */
549 static int linked_attribute_compare(const struct drsuapi_DsReplicaLinkedAttribute *la1,
550 const struct drsuapi_DsReplicaLinkedAttribute *la2,
551 struct ldb_context *sam_ctx)
556 const struct dsdb_schema *schema;
557 const struct dsdb_attribute *schema_attrib;
558 struct dsdb_dn *dn1, *dn2;
559 struct GUID guid1, guid2;
562 c = GUID_compare(&la1->identifier->guid,
563 &la2->identifier->guid);
564 if (c != 0) return c;
566 if (la1->attid != la2->attid) {
567 return la1->attid < la2->attid? -1:1;
570 if ((la1->flags & DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE) !=
571 (la2->flags & DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE)) {
572 return (la1->flags & DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE)? 1:-1;
575 /* we need to get the target GUIDs to compare */
576 tmp_ctx = talloc_new(sam_ctx);
578 schema = dsdb_get_schema(sam_ctx, tmp_ctx);
579 schema_attrib = dsdb_attribute_by_attributeID_id(schema, la1->attid);
581 werr = dsdb_dn_la_from_blob(sam_ctx, schema_attrib, schema, tmp_ctx, la1->value.blob, &dn1);
582 if (!W_ERROR_IS_OK(werr)) {
583 DEBUG(0,(__location__ ": Bad la1 blob in sort\n"));
584 talloc_free(tmp_ctx);
588 werr = dsdb_dn_la_from_blob(sam_ctx, schema_attrib, schema, tmp_ctx, la2->value.blob, &dn2);
589 if (!W_ERROR_IS_OK(werr)) {
590 DEBUG(0,(__location__ ": Bad la2 blob in sort\n"));
591 talloc_free(tmp_ctx);
595 status = dsdb_get_extended_dn_guid(dn1->dn, &guid1, "GUID");
596 if (!NT_STATUS_IS_OK(status)) {
597 DEBUG(0,(__location__ ": Bad la1 guid in sort\n"));
598 talloc_free(tmp_ctx);
601 status = dsdb_get_extended_dn_guid(dn2->dn, &guid2, "GUID");
602 if (!NT_STATUS_IS_OK(status)) {
603 DEBUG(0,(__location__ ": Bad la2 guid in sort\n"));
604 talloc_free(tmp_ctx);
608 talloc_free(tmp_ctx);
610 return GUID_compare(&guid1, &guid2);
615 sort the objects we send by tree order
617 static int site_res_cmp_parent_order(struct ldb_message **m1, struct ldb_message **m2)
619 return ldb_dn_compare((*m2)->dn, (*m1)->dn);
623 sort the objects we send first by uSNChanged
625 static int site_res_cmp_usn_order(struct ldb_message **m1, struct ldb_message **m2)
627 unsigned usnchanged1, usnchanged2;
629 cn1 = ldb_dn_get_comp_num((*m1)->dn);
630 cn2 = ldb_dn_get_comp_num((*m2)->dn);
632 return cn1 > cn2 ? 1 : -1;
634 usnchanged1 = ldb_msg_find_attr_as_uint(*m1, "uSNChanged", 0);
635 usnchanged2 = ldb_msg_find_attr_as_uint(*m2, "uSNChanged", 0);
636 if (usnchanged1 == usnchanged2) {
639 return usnchanged1 > usnchanged2 ? 1 : -1;
644 handle a DRSUAPI_EXOP_FSMO_RID_ALLOC call
646 static WERROR getncchanges_rid_alloc(struct drsuapi_bind_state *b_state,
648 struct drsuapi_DsGetNCChangesRequest10 *req10,
649 struct drsuapi_DsGetNCChangesCtr6 *ctr6)
651 struct ldb_dn *rid_manager_dn, *fsmo_role_dn, *req_dn;
653 struct ldb_context *ldb = b_state->sam_ctx;
654 struct ldb_result *ext_res;
655 struct ldb_dn *base_dn;
656 struct dsdb_fsmo_extended_op *exop;
660 - verify that the DN being asked for is the RID Manager DN
661 - verify that we are the RID Manager
664 /* work out who is the RID Manager */
665 ret = samdb_rid_manager_dn(ldb, mem_ctx, &rid_manager_dn);
666 if (ret != LDB_SUCCESS) {
667 DEBUG(0, (__location__ ": Failed to find RID Manager object - %s\n", ldb_errstring(ldb)));
668 return WERR_DS_DRA_INTERNAL_ERROR;
671 req_dn = drs_ObjectIdentifier_to_dn(mem_ctx, ldb, req10->naming_context);
672 if (!ldb_dn_validate(req_dn) ||
673 ldb_dn_compare(req_dn, rid_manager_dn) != 0) {
674 /* that isn't the RID Manager DN */
675 DEBUG(0,(__location__ ": RID Alloc request for wrong DN %s\n",
676 drs_ObjectIdentifier_to_string(mem_ctx, req10->naming_context)));
677 ctr6->extended_ret = DRSUAPI_EXOP_ERR_MISMATCH;
681 /* find the DN of the RID Manager */
682 ret = samdb_reference_dn(ldb, mem_ctx, rid_manager_dn, "fSMORoleOwner", &fsmo_role_dn);
683 if (ret != LDB_SUCCESS) {
684 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in RID Manager object - %s\n",
685 ldb_errstring(ldb)));
686 ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
687 return WERR_DS_DRA_INTERNAL_ERROR;
690 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) != 0) {
691 /* we're not the RID Manager - go away */
692 DEBUG(0,(__location__ ": RID Alloc request when not RID Manager\n"));
693 ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
697 exop = talloc(mem_ctx, struct dsdb_fsmo_extended_op);
698 W_ERROR_HAVE_NO_MEMORY(exop);
700 exop->fsmo_info = req10->fsmo_info;
701 exop->destination_dsa_guid = req10->destination_dsa_guid;
703 ret = ldb_transaction_start(ldb);
704 if (ret != LDB_SUCCESS) {
705 DEBUG(0,(__location__ ": Failed transaction start - %s\n",
706 ldb_errstring(ldb)));
707 return WERR_DS_DRA_INTERNAL_ERROR;
711 * FIXME (kim): this is a temp hack to return just few object,
712 * but not the whole domain NC.
713 * We should remove this hack and implement a 'scope'
714 * building function to return just the set of object
715 * documented for DRSUAPI_EXOP_FSMO_RID_ALLOC extended_op
717 ldb_sequence_number(ldb, LDB_SEQ_HIGHEST_SEQ, &req10->highwatermark.highest_usn);
719 ret = ldb_extended(ldb, DSDB_EXTENDED_ALLOCATE_RID_POOL, exop, &ext_res);
720 if (ret != LDB_SUCCESS) {
721 DEBUG(0,(__location__ ": Failed extended allocation RID pool operation - %s\n",
722 ldb_errstring(ldb)));
723 ldb_transaction_cancel(ldb);
724 return WERR_DS_DRA_INTERNAL_ERROR;
727 ret = ldb_transaction_commit(ldb);
728 if (ret != LDB_SUCCESS) {
729 DEBUG(0,(__location__ ": Failed transaction commit - %s\n",
730 ldb_errstring(ldb)));
731 return WERR_DS_DRA_INTERNAL_ERROR;
734 talloc_free(ext_res);
736 base_dn = ldb_get_default_basedn(ldb);
738 DEBUG(2,("Allocated RID pool for server %s\n",
739 GUID_string(mem_ctx, &req10->destination_dsa_guid)));
741 ctr6->extended_ret = DRSUAPI_EXOP_ERR_SUCCESS;
747 return an array of SIDs from a ldb_message given an attribute name
748 assumes the SIDs are in extended DN format
750 static WERROR samdb_result_sid_array_dn(struct ldb_context *sam_ctx,
751 struct ldb_message *msg,
754 const struct dom_sid ***sids)
756 struct ldb_message_element *el;
759 el = ldb_msg_find_element(msg, attr);
765 (*sids) = talloc_array(mem_ctx, const struct dom_sid *, el->num_values + 1);
766 W_ERROR_HAVE_NO_MEMORY(*sids);
768 for (i=0; i<el->num_values; i++) {
769 struct ldb_dn *dn = ldb_dn_from_ldb_val(mem_ctx, sam_ctx, &el->values[i]);
773 sid = talloc(*sids, struct dom_sid);
774 W_ERROR_HAVE_NO_MEMORY(sid);
775 status = dsdb_get_extended_dn_sid(dn, sid, "SID");
776 if (!NT_STATUS_IS_OK(status)) {
777 return WERR_INTERNAL_DB_CORRUPTION;
788 return an array of SIDs from a ldb_message given an attribute name
789 assumes the SIDs are in NDR form
791 static WERROR samdb_result_sid_array_ndr(struct ldb_context *sam_ctx,
792 struct ldb_message *msg,
795 const struct dom_sid ***sids)
797 struct ldb_message_element *el;
800 el = ldb_msg_find_element(msg, attr);
806 (*sids) = talloc_array(mem_ctx, const struct dom_sid *, el->num_values + 1);
807 W_ERROR_HAVE_NO_MEMORY(*sids);
809 for (i=0; i<el->num_values; i++) {
810 enum ndr_err_code ndr_err;
813 sid = talloc(*sids, struct dom_sid);
814 W_ERROR_HAVE_NO_MEMORY(sid);
816 ndr_err = ndr_pull_struct_blob(&el->values[i], sid, sid,
817 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
818 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
819 return WERR_INTERNAL_DB_CORRUPTION;
829 see if any SIDs in list1 are in list2
831 static bool sid_list_match(const struct dom_sid **list1, const struct dom_sid **list2)
834 /* do we ever have enough SIDs here to worry about O(n^2) ? */
835 for (i=0; list1[i]; i++) {
836 for (j=0; list2[j]; j++) {
837 if (dom_sid_equal(list1[i], list2[j])) {
846 handle a DRSUAPI_EXOP_REPL_SECRET call
848 static WERROR getncchanges_repl_secret(struct drsuapi_bind_state *b_state,
850 struct drsuapi_DsGetNCChangesRequest10 *req10,
851 struct dom_sid *user_sid,
852 struct drsuapi_DsGetNCChangesCtr6 *ctr6)
854 struct drsuapi_DsReplicaObjectIdentifier *ncRoot = req10->naming_context;
855 struct ldb_dn *obj_dn, *rodc_dn, *krbtgt_link_dn;
857 const char *rodc_attrs[] = { "msDS-KrbTgtLink", "msDS-NeverRevealGroup", "msDS-RevealOnDemandGroup", NULL };
858 const char *obj_attrs[] = { "tokenGroups", "objectSid", "UserAccountControl", "msDS-KrbTgtLinkBL", NULL };
859 struct ldb_result *rodc_res, *obj_res;
860 const struct dom_sid **never_reveal_sids, **reveal_sids, **token_sids;
863 DEBUG(3,(__location__ ": DRSUAPI_EXOP_REPL_SECRET extended op on %s\n",
864 drs_ObjectIdentifier_to_string(mem_ctx, ncRoot)));
867 * we need to work out if we will allow this RODC to
868 * replicate the secrets for this object
870 * see 4.1.10.5.14 GetRevealSecretsPolicyForUser for details
874 if (b_state->sam_ctx_system == NULL) {
875 /* this operation needs system level access */
876 ctr6->extended_ret = DRSUAPI_EXOP_ERR_ACCESS_DENIED;
877 return WERR_DS_DRA_SOURCE_DISABLED;
880 obj_dn = drs_ObjectIdentifier_to_dn(mem_ctx, b_state->sam_ctx_system, ncRoot);
881 if (!ldb_dn_validate(obj_dn)) goto failed;
883 rodc_dn = ldb_dn_new_fmt(mem_ctx, b_state->sam_ctx_system, "<SID=%s>",
884 dom_sid_string(mem_ctx, user_sid));
885 if (!ldb_dn_validate(rodc_dn)) goto failed;
887 /* do the two searches we need */
888 ret = dsdb_search_dn(b_state->sam_ctx_system, mem_ctx, &rodc_res, rodc_dn, rodc_attrs,
889 DSDB_SEARCH_SHOW_EXTENDED_DN);
890 if (ret != LDB_SUCCESS || rodc_res->count != 1) goto failed;
892 ret = dsdb_search_dn(b_state->sam_ctx_system, mem_ctx, &obj_res, obj_dn, obj_attrs, 0);
893 if (ret != LDB_SUCCESS || obj_res->count != 1) goto failed;
895 /* if the object SID is equal to the user_sid, allow */
896 if (dom_sid_equal(user_sid,
897 samdb_result_dom_sid(mem_ctx, obj_res->msgs[0], "objectSid"))) {
901 /* an RODC is allowed to get its own krbtgt account secrets */
902 krbtgt_link_dn = samdb_result_dn(b_state->sam_ctx_system, mem_ctx,
903 rodc_res->msgs[0], "msDS-KrbTgtLink", NULL);
904 if (krbtgt_link_dn != NULL &&
905 ldb_dn_compare(obj_dn, krbtgt_link_dn) == 0) {
909 /* but it isn't allowed to get anyone elses krbtgt secrets */
910 if (samdb_result_dn(b_state->sam_ctx_system, mem_ctx,
911 obj_res->msgs[0], "msDS-KrbTgtLinkBL", NULL)) {
915 if (ldb_msg_find_attr_as_uint(obj_res->msgs[0],
916 "userAccountControl", 0) &
917 UF_INTERDOMAIN_TRUST_ACCOUNT) {
921 werr = samdb_result_sid_array_dn(b_state->sam_ctx_system, rodc_res->msgs[0],
922 mem_ctx, "msDS-NeverRevealGroup", &never_reveal_sids);
923 if (!W_ERROR_IS_OK(werr)) {
927 werr = samdb_result_sid_array_dn(b_state->sam_ctx_system, rodc_res->msgs[0],
928 mem_ctx, "msDS-RevealOnDemandGroup", &reveal_sids);
929 if (!W_ERROR_IS_OK(werr)) {
933 werr = samdb_result_sid_array_ndr(b_state->sam_ctx_system, obj_res->msgs[0],
934 mem_ctx, "tokenGroups", &token_sids);
935 if (!W_ERROR_IS_OK(werr) || token_sids==NULL) {
939 if (never_reveal_sids &&
940 sid_list_match(token_sids, never_reveal_sids)) {
945 sid_list_match(token_sids, reveal_sids)) {
951 DEBUG(2,(__location__ ": Denied RODC secret replication for %s by RODC %s\n",
952 ldb_dn_get_linearized(obj_dn), ldb_dn_get_linearized(rodc_res->msgs[0]->dn)));
953 ctr6->extended_ret = DRSUAPI_EXOP_ERR_NONE;
954 return WERR_DS_DRA_ACCESS_DENIED;
957 DEBUG(2,(__location__ ": Allowed RODC secret replication for %s by RODC %s\n",
958 ldb_dn_get_linearized(obj_dn), ldb_dn_get_linearized(rodc_res->msgs[0]->dn)));
959 ctr6->extended_ret = DRSUAPI_EXOP_ERR_SUCCESS;
960 req10->highwatermark.highest_usn = 0;
964 DEBUG(2,(__location__ ": Failed RODC secret replication for %s by RODC %s\n",
965 ldb_dn_get_linearized(obj_dn), dom_sid_string(mem_ctx, user_sid)));
966 ctr6->extended_ret = DRSUAPI_EXOP_ERR_NONE;
967 return WERR_DS_DRA_BAD_DN;
972 handle a DRSUAPI_EXOP_REPL_OBJ call
974 static WERROR getncchanges_repl_obj(struct drsuapi_bind_state *b_state,
976 struct drsuapi_DsGetNCChangesRequest10 *req10,
977 struct dom_sid *user_sid,
978 struct drsuapi_DsGetNCChangesCtr6 *ctr6)
980 struct drsuapi_DsReplicaObjectIdentifier *ncRoot = req10->naming_context;
982 DEBUG(3,(__location__ ": DRSUAPI_EXOP_REPL_OBJ extended op on %s\n",
983 drs_ObjectIdentifier_to_string(mem_ctx, ncRoot)));
985 ctr6->extended_ret = DRSUAPI_EXOP_ERR_SUCCESS;
986 req10->highwatermark.highest_usn = 0;
992 handle DRSUAPI_EXOP_FSMO_REQ_ROLE,
993 DRSUAPI_EXOP_FSMO_RID_REQ_ROLE,
994 and DRSUAPI_EXOP_FSMO_REQ_PDC calls
996 static WERROR getncchanges_change_master(struct drsuapi_bind_state *b_state,
998 struct drsuapi_DsGetNCChangesRequest10 *req10,
999 struct drsuapi_DsGetNCChangesCtr6 *ctr6)
1001 struct ldb_dn *fsmo_role_dn, *req_dn, *ntds_dn;
1004 struct ldb_context *ldb = b_state->sam_ctx;
1005 struct ldb_message *msg;
1009 - verify that the client dn exists
1010 - verify that we are the current master
1013 req_dn = drs_ObjectIdentifier_to_dn(mem_ctx, ldb, req10->naming_context);
1014 if (!ldb_dn_validate(req_dn)) {
1015 /* that is not a valid dn */
1016 DEBUG(0,(__location__ ": FSMO role transfer request for invalid DN %s\n",
1017 drs_ObjectIdentifier_to_string(mem_ctx, req10->naming_context)));
1018 ctr6->extended_ret = DRSUAPI_EXOP_ERR_MISMATCH;
1022 /* retrieve the current role owner */
1023 ret = samdb_reference_dn(ldb, mem_ctx, req_dn, "fSMORoleOwner", &fsmo_role_dn);
1024 if (ret != LDB_SUCCESS) {
1025 DEBUG(0,(__location__ ": Failed to find fSMORoleOwner in context - %s\n",
1026 ldb_errstring(ldb)));
1027 ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
1028 return WERR_DS_DRA_INTERNAL_ERROR;
1031 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) != 0) {
1032 /* we're not the current owner - go away */
1033 DEBUG(0,(__location__ ": FSMO transfer request when not owner\n"));
1034 ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
1038 /* change the current master */
1039 msg = ldb_msg_new(ldb);
1040 W_ERROR_HAVE_NO_MEMORY(msg);
1041 msg->dn = drs_ObjectIdentifier_to_dn(msg, ldb, req10->naming_context);
1042 W_ERROR_HAVE_NO_MEMORY(msg->dn);
1044 /* TODO: make sure ntds_dn is a valid nTDSDSA object */
1045 ret = dsdb_find_dn_by_guid(ldb, msg, &req10->destination_dsa_guid, &ntds_dn);
1046 if (ret != LDB_SUCCESS) {
1047 DEBUG(0, (__location__ ": Unable to find NTDS object for guid %s - %s\n",
1048 GUID_string(mem_ctx, &req10->destination_dsa_guid), ldb_errstring(ldb)));
1050 ctr6->extended_ret = DRSUAPI_EXOP_ERR_UNKNOWN_CALLER;
1054 ret = ldb_msg_add_string(msg, "fSMORoleOwner", ldb_dn_get_linearized(ntds_dn));
1057 return WERR_DS_DRA_INTERNAL_ERROR;
1060 for (i=0;i<msg->num_elements;i++) {
1061 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
1064 ret = ldb_transaction_start(ldb);
1065 if (ret != LDB_SUCCESS) {
1066 DEBUG(0,(__location__ ": Failed transaction start - %s\n",
1067 ldb_errstring(ldb)));
1068 return WERR_DS_DRA_INTERNAL_ERROR;
1071 ret = ldb_modify(ldb, msg);
1072 if (ret != LDB_SUCCESS) {
1073 DEBUG(0,(__location__ ": Failed to change current owner - %s\n",
1074 ldb_errstring(ldb)));
1075 ldb_transaction_cancel(ldb);
1076 return WERR_DS_DRA_INTERNAL_ERROR;
1079 ret = ldb_transaction_commit(ldb);
1080 if (ret != LDB_SUCCESS) {
1081 DEBUG(0,(__location__ ": Failed transaction commit - %s\n",
1082 ldb_errstring(ldb)));
1083 return WERR_DS_DRA_INTERNAL_ERROR;
1086 ctr6->extended_ret = DRSUAPI_EXOP_ERR_SUCCESS;
1091 /* state of a partially completed getncchanges call */
1092 struct drsuapi_getncchanges_state {
1094 uint32_t num_records;
1095 uint32_t num_processed;
1096 struct ldb_dn *ncRoot_dn;
1099 uint64_t highest_usn;
1100 struct ldb_dn *last_dn;
1101 struct drsuapi_DsReplicaLinkedAttribute *la_list;
1105 struct drsuapi_DsReplicaCursorCtrEx *uptodateness_vector;
1109 see if this getncchanges request includes a request to reveal secret information
1111 static WERROR dcesrv_drsuapi_is_reveal_secrets_request(struct drsuapi_bind_state *b_state,
1112 struct drsuapi_DsGetNCChangesRequest10 *req10,
1113 bool *is_secret_request)
1115 enum drsuapi_DsExtendedOperation exop;
1117 struct dsdb_schema *schema;
1119 *is_secret_request = true;
1121 exop = req10->extended_op;
1124 case DRSUAPI_EXOP_FSMO_REQ_ROLE:
1125 case DRSUAPI_EXOP_FSMO_RID_ALLOC:
1126 case DRSUAPI_EXOP_FSMO_RID_REQ_ROLE:
1127 case DRSUAPI_EXOP_FSMO_REQ_PDC:
1128 case DRSUAPI_EXOP_FSMO_ABANDON_ROLE:
1129 /* FSMO exops can reveal secrets */
1130 *is_secret_request = true;
1132 case DRSUAPI_EXOP_REPL_SECRET:
1133 case DRSUAPI_EXOP_REPL_OBJ:
1134 case DRSUAPI_EXOP_NONE:
1138 if (req10->replica_flags & DRSUAPI_DRS_SPECIAL_SECRET_PROCESSING) {
1139 *is_secret_request = false;
1143 if (exop == DRSUAPI_EXOP_REPL_SECRET ||
1144 req10->partial_attribute_set == NULL) {
1145 /* they want secrets */
1146 *is_secret_request = true;
1150 schema = dsdb_get_schema(b_state->sam_ctx, NULL);
1152 /* check the attributes they asked for */
1153 for (i=0; i<req10->partial_attribute_set->num_attids; i++) {
1154 const struct dsdb_attribute *sa;
1155 sa = dsdb_attribute_by_attributeID_id(schema, req10->partial_attribute_set->attids[i]);
1157 return WERR_DS_DRA_SCHEMA_MISMATCH;
1159 if (!dsdb_attr_in_rodc_fas(sa)) {
1160 *is_secret_request = true;
1165 if (req10->partial_attribute_set_ex) {
1166 /* check the extended attributes they asked for */
1167 for (i=0; i<req10->partial_attribute_set_ex->num_attids; i++) {
1168 const struct dsdb_attribute *sa;
1169 sa = dsdb_attribute_by_attributeID_id(schema, req10->partial_attribute_set_ex->attids[i]);
1171 return WERR_DS_DRA_SCHEMA_MISMATCH;
1173 if (!dsdb_attr_in_rodc_fas(sa)) {
1174 *is_secret_request = true;
1180 *is_secret_request = false;
1185 see if this getncchanges request is only for attributes in the GC
1186 partial attribute set
1188 static WERROR dcesrv_drsuapi_is_gc_pas_request(struct drsuapi_bind_state *b_state,
1189 struct drsuapi_DsGetNCChangesRequest10 *req10,
1190 bool *is_gc_pas_request)
1192 enum drsuapi_DsExtendedOperation exop;
1194 struct dsdb_schema *schema;
1196 exop = req10->extended_op;
1199 case DRSUAPI_EXOP_FSMO_REQ_ROLE:
1200 case DRSUAPI_EXOP_FSMO_RID_ALLOC:
1201 case DRSUAPI_EXOP_FSMO_RID_REQ_ROLE:
1202 case DRSUAPI_EXOP_FSMO_REQ_PDC:
1203 case DRSUAPI_EXOP_FSMO_ABANDON_ROLE:
1204 case DRSUAPI_EXOP_REPL_SECRET:
1205 *is_gc_pas_request = false;
1207 case DRSUAPI_EXOP_REPL_OBJ:
1208 case DRSUAPI_EXOP_NONE:
1212 if (req10->partial_attribute_set == NULL) {
1213 /* they want it all */
1214 *is_gc_pas_request = false;
1218 schema = dsdb_get_schema(b_state->sam_ctx, NULL);
1220 /* check the attributes they asked for */
1221 for (i=0; i<req10->partial_attribute_set->num_attids; i++) {
1222 const struct dsdb_attribute *sa;
1223 sa = dsdb_attribute_by_attributeID_id(schema, req10->partial_attribute_set->attids[i]);
1225 return WERR_DS_DRA_SCHEMA_MISMATCH;
1227 if (!sa->isMemberOfPartialAttributeSet) {
1228 *is_gc_pas_request = false;
1233 if (req10->partial_attribute_set_ex) {
1234 /* check the extended attributes they asked for */
1235 for (i=0; i<req10->partial_attribute_set_ex->num_attids; i++) {
1236 const struct dsdb_attribute *sa;
1237 sa = dsdb_attribute_by_attributeID_id(schema, req10->partial_attribute_set_ex->attids[i]);
1239 return WERR_DS_DRA_SCHEMA_MISMATCH;
1241 if (!sa->isMemberOfPartialAttributeSet) {
1242 *is_gc_pas_request = false;
1248 *is_gc_pas_request = true;
1254 map from req8 to req10
1256 static struct drsuapi_DsGetNCChangesRequest10 *
1257 getncchanges_map_req8(TALLOC_CTX *mem_ctx,
1258 struct drsuapi_DsGetNCChangesRequest8 *req8)
1260 struct drsuapi_DsGetNCChangesRequest10 *req10 = talloc_zero(mem_ctx,
1261 struct drsuapi_DsGetNCChangesRequest10);
1262 if (req10 == NULL) {
1266 req10->destination_dsa_guid = req8->destination_dsa_guid;
1267 req10->source_dsa_invocation_id = req8->source_dsa_invocation_id;
1268 req10->naming_context = req8->naming_context;
1269 req10->highwatermark = req8->highwatermark;
1270 req10->uptodateness_vector = req8->uptodateness_vector;
1271 req10->replica_flags = req8->replica_flags;
1272 req10->max_object_count = req8->max_object_count;
1273 req10->max_ndr_size = req8->max_ndr_size;
1274 req10->extended_op = req8->extended_op;
1275 req10->fsmo_info = req8->fsmo_info;
1276 req10->partial_attribute_set = req8->partial_attribute_set;
1277 req10->partial_attribute_set_ex = req8->partial_attribute_set_ex;
1278 req10->mapping_ctr = req8->mapping_ctr;
1285 * Collects object for normal replication cycle.
1287 static WERROR getncchanges_collect_objects(struct drsuapi_bind_state *b_state,
1288 TALLOC_CTX *mem_ctx,
1289 struct drsuapi_DsGetNCChangesRequest10 *req10,
1290 struct ldb_dn *search_dn,
1291 const char *extra_filter,
1292 struct ldb_result **search_res)
1295 char* search_filter;
1296 enum ldb_scope scope = LDB_SCOPE_SUBTREE;
1297 //const char *extra_filter;
1298 struct drsuapi_getncchanges_state *getnc_state = b_state->getncchanges_state;
1299 const char *attrs[] = { "uSNChanged",
1303 if (req10->extended_op == DRSUAPI_EXOP_REPL_OBJ ||
1304 req10->extended_op == DRSUAPI_EXOP_REPL_SECRET) {
1305 scope = LDB_SCOPE_BASE;
1308 //extra_filter = lpcfg_parm_string(dce_call->conn->dce_ctx->lp_ctx, NULL, "drs", "object filter");
1310 //getnc_state->min_usn = req10->highwatermark.highest_usn;
1312 /* Construct response. */
1313 search_filter = talloc_asprintf(mem_ctx,
1314 "(uSNChanged>=%llu)",
1315 (unsigned long long)(getnc_state->min_usn+1));
1318 search_filter = talloc_asprintf(mem_ctx, "(&%s(%s))", search_filter, extra_filter);
1321 if (req10->replica_flags & DRSUAPI_DRS_CRITICAL_ONLY) {
1322 search_filter = talloc_asprintf(mem_ctx,
1323 "(&%s(isCriticalSystemObject=TRUE))",
1327 if (req10->replica_flags & DRSUAPI_DRS_ASYNC_REP) {
1328 scope = LDB_SCOPE_BASE;
1332 search_dn = getnc_state->ncRoot_dn;
1335 DEBUG(2,(__location__ ": getncchanges on %s using filter %s\n",
1336 ldb_dn_get_linearized(getnc_state->ncRoot_dn), search_filter));
1337 ret = drsuapi_search_with_extended_dn(b_state->sam_ctx, getnc_state, search_res,
1338 search_dn, scope, attrs,
1340 if (ret != LDB_SUCCESS) {
1341 return WERR_DS_DRA_INTERNAL_ERROR;
1348 * Collects object for normal replication cycle.
1350 static WERROR getncchanges_collect_objects_exop(struct drsuapi_bind_state *b_state,
1351 TALLOC_CTX *mem_ctx,
1352 struct drsuapi_DsGetNCChangesRequest10 *req10,
1353 struct drsuapi_DsGetNCChangesCtr6 *ctr6,
1354 struct ldb_dn *search_dn,
1355 const char *extra_filter,
1356 struct ldb_result **search_res)
1358 /* we have nothing to do in case of ex-op failure */
1359 if (ctr6->extended_ret != DRSUAPI_EXOP_ERR_SUCCESS) {
1363 /* TODO: implement extended op specific collection
1364 * of objects. Right now we just normal procedure
1365 * for collecting objects */
1366 return getncchanges_collect_objects(b_state, mem_ctx, req10, search_dn, extra_filter, search_res);
1370 drsuapi_DsGetNCChanges
1372 see MS-DRSR 4.1.10.5.2 for basic logic of this function
1374 WERROR dcesrv_drsuapi_DsGetNCChanges(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1375 struct drsuapi_DsGetNCChanges *r)
1377 struct drsuapi_DsReplicaObjectIdentifier *ncRoot;
1380 struct dsdb_schema *schema;
1381 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
1382 struct drsuapi_DsReplicaObjectListItemEx **currentObject;
1384 DATA_BLOB session_key;
1386 struct dcesrv_handle *h;
1387 struct drsuapi_bind_state *b_state;
1388 struct drsuapi_getncchanges_state *getnc_state;
1389 struct drsuapi_DsGetNCChangesRequest10 *req10;
1391 uint32_t max_objects;
1393 uint32_t link_count = 0;
1394 uint32_t link_total = 0;
1395 uint32_t link_given = 0;
1396 struct ldb_dn *search_dn = NULL;
1397 bool am_rodc, null_scope=false;
1398 enum security_user_level security_level;
1399 struct ldb_context *sam_ctx;
1400 struct dom_sid *user_sid;
1401 bool is_secret_request;
1402 bool is_gc_pas_request;
1404 DCESRV_PULL_HANDLE_WERR(h, r->in.bind_handle, DRSUAPI_BIND_HANDLE);
1407 sam_ctx = b_state->sam_ctx_system?b_state->sam_ctx_system:b_state->sam_ctx;
1409 *r->out.level_out = 6;
1410 /* TODO: linked attributes*/
1411 r->out.ctr->ctr6.linked_attributes_count = 0;
1412 r->out.ctr->ctr6.linked_attributes = NULL;
1414 r->out.ctr->ctr6.object_count = 0;
1415 r->out.ctr->ctr6.nc_object_count = 0;
1416 r->out.ctr->ctr6.more_data = false;
1417 r->out.ctr->ctr6.uptodateness_vector = NULL;
1419 /* a RODC doesn't allow for any replication */
1420 ret = samdb_rodc(sam_ctx, &am_rodc);
1421 if (ret == LDB_SUCCESS && am_rodc) {
1422 DEBUG(0,(__location__ ": DsGetNCChanges attempt on RODC\n"));
1423 return WERR_DS_DRA_SOURCE_DISABLED;
1426 /* Check request revision.
1428 switch (r->in.level) {
1430 req10 = getncchanges_map_req8(mem_ctx, &r->in.req->req8);
1431 if (req10 == NULL) {
1436 req10 = &r->in.req->req10;
1439 DEBUG(0,(__location__ ": Request for DsGetNCChanges with unsupported level %u\n",
1441 return WERR_REVISION_MISMATCH;
1445 /* Perform access checks. */
1446 /* TODO: we need to support a sync on a specific non-root
1447 * DN. We'll need to find the real partition root here */
1448 ncRoot = req10->naming_context;
1449 if (ncRoot == NULL) {
1450 DEBUG(0,(__location__ ": Request for DsGetNCChanges with no NC\n"));
1451 return WERR_DS_DRA_INVALID_PARAMETER;
1454 if (samdb_ntds_options(sam_ctx, &options) != LDB_SUCCESS) {
1455 return WERR_DS_DRA_INTERNAL_ERROR;
1458 if ((options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) &&
1459 !(req10->replica_flags & DRSUAPI_DRS_SYNC_FORCED)) {
1460 return WERR_DS_DRA_SOURCE_DISABLED;
1463 user_sid = &dce_call->conn->auth_state.session_info->security_token->sids[PRIMARY_USER_SID_INDEX];
1465 /* all clients must have GUID_DRS_GET_CHANGES */
1466 werr = drs_security_access_check_nc_root(b_state->sam_ctx,
1468 dce_call->conn->auth_state.session_info->security_token,
1469 req10->naming_context,
1470 GUID_DRS_GET_CHANGES);
1471 if (!W_ERROR_IS_OK(werr)) {
1475 /* allowed if the GC PAS and client has
1476 GUID_DRS_GET_FILTERED_ATTRIBUTES */
1477 werr = dcesrv_drsuapi_is_gc_pas_request(b_state, req10, &is_gc_pas_request);
1478 if (!W_ERROR_IS_OK(werr)) {
1481 if (is_gc_pas_request) {
1482 werr = drs_security_access_check_nc_root(b_state->sam_ctx,
1484 dce_call->conn->auth_state.session_info->security_token,
1485 req10->naming_context,
1486 GUID_DRS_GET_FILTERED_ATTRIBUTES);
1487 if (W_ERROR_IS_OK(werr)) {
1492 werr = dcesrv_drsuapi_is_reveal_secrets_request(b_state, req10, &is_secret_request);
1493 if (!W_ERROR_IS_OK(werr)) {
1496 if (is_secret_request && req10->extended_op != DRSUAPI_EXOP_REPL_SECRET) {
1497 werr = drs_security_access_check_nc_root(b_state->sam_ctx,
1499 dce_call->conn->auth_state.session_info->security_token,
1500 req10->naming_context,
1501 GUID_DRS_GET_ALL_CHANGES);
1502 if (!W_ERROR_IS_OK(werr)) {
1508 /* for non-administrator replications, check that they have
1509 given the correct source_dsa_invocation_id */
1510 security_level = security_session_user_level(dce_call->conn->auth_state.session_info,
1511 samdb_domain_sid(sam_ctx));
1512 if (security_level == SECURITY_RO_DOMAIN_CONTROLLER) {
1513 if (req10->replica_flags & DRSUAPI_DRS_WRIT_REP) {
1514 /* we rely on this flag being unset for RODC requests */
1515 req10->replica_flags &= ~DRSUAPI_DRS_WRIT_REP;
1519 if (req10->replica_flags & DRSUAPI_DRS_FULL_SYNC_PACKET) {
1520 /* Ignore the _in_ uptpdateness vector*/
1521 req10->uptodateness_vector = NULL;
1524 getnc_state = b_state->getncchanges_state;
1526 /* see if a previous replication has been abandoned */
1528 struct ldb_dn *new_dn = drs_ObjectIdentifier_to_dn(getnc_state, sam_ctx, ncRoot);
1529 if (ldb_dn_compare(new_dn, getnc_state->ncRoot_dn) != 0) {
1530 DEBUG(0,(__location__ ": DsGetNCChanges 2nd replication on different DN %s %s (last_dn %s)\n",
1531 ldb_dn_get_linearized(new_dn),
1532 ldb_dn_get_linearized(getnc_state->ncRoot_dn),
1533 ldb_dn_get_linearized(getnc_state->last_dn)));
1534 talloc_free(getnc_state);
1539 if (getnc_state == NULL) {
1540 getnc_state = talloc_zero(b_state, struct drsuapi_getncchanges_state);
1541 if (getnc_state == NULL) {
1544 b_state->getncchanges_state = getnc_state;
1545 getnc_state->ncRoot_dn = drs_ObjectIdentifier_to_dn(getnc_state, sam_ctx, ncRoot);
1547 /* find out if we are to replicate Schema NC */
1548 ret = ldb_dn_compare(getnc_state->ncRoot_dn,
1549 ldb_get_schema_basedn(b_state->sam_ctx));
1550 getnc_state->is_schema_nc = (0 == ret);
1552 if (req10->extended_op != DRSUAPI_EXOP_NONE) {
1553 r->out.ctr->ctr6.extended_ret = DRSUAPI_EXOP_ERR_SUCCESS;
1557 * This is the first replication cycle and it is
1558 * a good place to handle extended operations
1560 * FIXME: we don't fully support extended operations yet
1562 switch (req10->extended_op) {
1563 case DRSUAPI_EXOP_NONE:
1565 case DRSUAPI_EXOP_FSMO_RID_ALLOC:
1566 werr = getncchanges_rid_alloc(b_state, mem_ctx, req10, &r->out.ctr->ctr6);
1567 W_ERROR_NOT_OK_RETURN(werr);
1568 search_dn = ldb_get_default_basedn(sam_ctx);
1570 case DRSUAPI_EXOP_REPL_SECRET:
1571 werr = getncchanges_repl_secret(b_state, mem_ctx, req10, user_sid, &r->out.ctr->ctr6);
1572 r->out.result = werr;
1573 W_ERROR_NOT_OK_RETURN(werr);
1575 case DRSUAPI_EXOP_FSMO_REQ_ROLE:
1576 werr = getncchanges_change_master(b_state, mem_ctx, req10, &r->out.ctr->ctr6);
1577 W_ERROR_NOT_OK_RETURN(werr);
1579 case DRSUAPI_EXOP_FSMO_RID_REQ_ROLE:
1580 werr = getncchanges_change_master(b_state, mem_ctx, req10, &r->out.ctr->ctr6);
1581 W_ERROR_NOT_OK_RETURN(werr);
1583 case DRSUAPI_EXOP_FSMO_REQ_PDC:
1584 werr = getncchanges_change_master(b_state, mem_ctx, req10, &r->out.ctr->ctr6);
1585 W_ERROR_NOT_OK_RETURN(werr);
1587 case DRSUAPI_EXOP_REPL_OBJ:
1588 werr = getncchanges_repl_obj(b_state, mem_ctx, req10, user_sid, &r->out.ctr->ctr6);
1589 r->out.result = werr;
1590 W_ERROR_NOT_OK_RETURN(werr);
1593 case DRSUAPI_EXOP_FSMO_ABANDON_ROLE:
1595 DEBUG(0,(__location__ ": Request for DsGetNCChanges unsupported extended op 0x%x\n",
1596 (unsigned)req10->extended_op));
1597 return WERR_DS_DRA_NOT_SUPPORTED;
1601 if (!ldb_dn_validate(getnc_state->ncRoot_dn) ||
1602 ldb_dn_is_null(getnc_state->ncRoot_dn)) {
1603 DEBUG(0,(__location__ ": Bad DN '%s'\n",
1604 drs_ObjectIdentifier_to_string(mem_ctx, ncRoot)));
1605 return WERR_DS_DRA_INVALID_PARAMETER;
1608 /* we need the session key for encrypting password attributes */
1609 status = dcesrv_inherited_session_key(dce_call->conn, &session_key);
1610 if (!NT_STATUS_IS_OK(status)) {
1611 DEBUG(0,(__location__ ": Failed to get session key\n"));
1612 return WERR_DS_DRA_INTERNAL_ERROR;
1616 TODO: MS-DRSR section 4.1.10.1.1
1617 Work out if this is the start of a new cycle */
1619 if (getnc_state->guids == NULL) {
1620 const char *extra_filter;
1621 struct ldb_result *search_res = NULL;
1623 extra_filter = lpcfg_parm_string(dce_call->conn->dce_ctx->lp_ctx, NULL, "drs", "object filter");
1625 getnc_state->min_usn = req10->highwatermark.highest_usn;
1627 if (req10->extended_op == DRSUAPI_EXOP_NONE) {
1628 werr = getncchanges_collect_objects(b_state, mem_ctx, req10,
1629 search_dn, extra_filter,
1632 werr = getncchanges_collect_objects_exop(b_state, mem_ctx, req10,
1634 search_dn, extra_filter,
1637 W_ERROR_NOT_OK_RETURN(werr);
1640 if (req10->replica_flags & DRSUAPI_DRS_GET_ANC) {
1641 TYPESAFE_QSORT(search_res->msgs,
1643 site_res_cmp_parent_order);
1645 TYPESAFE_QSORT(search_res->msgs,
1647 site_res_cmp_usn_order);
1651 /* extract out the GUIDs list */
1652 getnc_state->num_records = search_res ? search_res->count : 0;
1653 getnc_state->guids = talloc_array(getnc_state, struct GUID, getnc_state->num_records);
1654 W_ERROR_HAVE_NO_MEMORY(getnc_state->guids);
1656 for (i=0; i<getnc_state->num_records; i++) {
1657 getnc_state->guids[i] = samdb_result_guid(search_res->msgs[i], "objectGUID");
1658 if (GUID_all_zero(&getnc_state->guids[i])) {
1659 DEBUG(2,("getncchanges: bad objectGUID from %s\n", ldb_dn_get_linearized(search_res->msgs[i]->dn)));
1660 return WERR_DS_DRA_INTERNAL_ERROR;
1665 talloc_free(search_res);
1667 getnc_state->uptodateness_vector = talloc_steal(getnc_state, req10->uptodateness_vector);
1668 if (getnc_state->uptodateness_vector) {
1669 /* make sure its sorted */
1670 TYPESAFE_QSORT(getnc_state->uptodateness_vector->cursors,
1671 getnc_state->uptodateness_vector->count,
1672 drsuapi_DsReplicaCursor_compare);
1676 /* Prefix mapping */
1677 schema = dsdb_get_schema(sam_ctx, mem_ctx);
1679 DEBUG(0,("No schema in sam_ctx\n"));
1680 return WERR_DS_DRA_INTERNAL_ERROR;
1683 r->out.ctr->ctr6.naming_context = talloc(mem_ctx, struct drsuapi_DsReplicaObjectIdentifier);
1684 *r->out.ctr->ctr6.naming_context = *ncRoot;
1686 if (dsdb_find_guid_by_dn(sam_ctx, getnc_state->ncRoot_dn,
1687 &r->out.ctr->ctr6.naming_context->guid) != LDB_SUCCESS) {
1688 DEBUG(0,(__location__ ": Failed to find GUID of ncRoot_dn %s\n",
1689 ldb_dn_get_linearized(getnc_state->ncRoot_dn)));
1690 return WERR_DS_DRA_INTERNAL_ERROR;
1693 /* find the SID if there is one */
1694 dsdb_find_sid_by_dn(sam_ctx, getnc_state->ncRoot_dn, &r->out.ctr->ctr6.naming_context->sid);
1696 dsdb_get_oid_mappings_drsuapi(schema, true, mem_ctx, &ctr);
1697 r->out.ctr->ctr6.mapping_ctr = *ctr;
1699 r->out.ctr->ctr6.source_dsa_guid = *(samdb_ntds_objectGUID(sam_ctx));
1700 r->out.ctr->ctr6.source_dsa_invocation_id = *(samdb_ntds_invocation_id(sam_ctx));
1702 r->out.ctr->ctr6.old_highwatermark = req10->highwatermark;
1703 r->out.ctr->ctr6.new_highwatermark = req10->highwatermark;
1705 r->out.ctr->ctr6.first_object = NULL;
1706 currentObject = &r->out.ctr->ctr6.first_object;
1708 /* use this to force single objects at a time, which is useful
1709 * for working out what object is giving problems
1711 max_objects = lpcfg_parm_int(dce_call->conn->dce_ctx->lp_ctx, NULL, "drs", "max object sync", 1000);
1712 if (req10->max_object_count < max_objects) {
1713 max_objects = req10->max_object_count;
1716 * TODO: work out how the maximum should be calculated
1718 max_links = lpcfg_parm_int(dce_call->conn->dce_ctx->lp_ctx, NULL, "drs", "max link sync", 1500);
1720 for (i=getnc_state->num_processed;
1721 i<getnc_state->num_records &&
1723 (r->out.ctr->ctr6.object_count < max_objects);
1726 struct drsuapi_DsReplicaObjectListItemEx *obj;
1727 struct ldb_message *msg;
1728 static const char * const msg_attrs[] = {
1730 "nTSecurityDescriptor",
1732 "replPropertyMetaData",
1733 DSDB_SECRET_ATTRIBUTES,
1735 struct ldb_result *msg_res;
1736 struct ldb_dn *msg_dn;
1738 obj = talloc_zero(mem_ctx, struct drsuapi_DsReplicaObjectListItemEx);
1739 W_ERROR_HAVE_NO_MEMORY(obj);
1741 msg_dn = ldb_dn_new_fmt(obj, sam_ctx, "<GUID=%s>", GUID_string(obj, &getnc_state->guids[i]));
1742 W_ERROR_HAVE_NO_MEMORY(msg_dn);
1745 /* by re-searching here we avoid having a lot of full
1746 * records in memory between calls to getncchanges
1748 ret = drsuapi_search_with_extended_dn(sam_ctx, obj, &msg_res,
1750 LDB_SCOPE_BASE, msg_attrs, NULL);
1751 if (ret != LDB_SUCCESS) {
1752 if (ret != LDB_ERR_NO_SUCH_OBJECT) {
1753 DEBUG(1,("getncchanges: failed to fetch DN %s - %s\n",
1754 ldb_dn_get_extended_linearized(obj, msg_dn, 1), ldb_errstring(sam_ctx)));
1760 msg = msg_res->msgs[0];
1762 werr = get_nc_changes_build_object(obj, msg,
1763 sam_ctx, getnc_state->ncRoot_dn,
1764 getnc_state->is_schema_nc,
1765 schema, &session_key, getnc_state->min_usn,
1766 req10->replica_flags,
1767 req10->partial_attribute_set,
1768 getnc_state->uptodateness_vector,
1769 req10->extended_op);
1770 if (!W_ERROR_IS_OK(werr)) {
1774 werr = get_nc_changes_add_links(sam_ctx, getnc_state,
1775 getnc_state->ncRoot_dn,
1776 schema, getnc_state->min_usn,
1777 req10->replica_flags,
1779 &getnc_state->la_list,
1780 &getnc_state->la_count,
1781 getnc_state->uptodateness_vector);
1782 if (!W_ERROR_IS_OK(werr)) {
1786 uSN = ldb_msg_find_attr_as_int(msg, "uSNChanged", -1);
1787 if (uSN > r->out.ctr->ctr6.new_highwatermark.tmp_highest_usn) {
1788 r->out.ctr->ctr6.new_highwatermark.tmp_highest_usn = uSN;
1790 if (uSN > getnc_state->highest_usn) {
1791 getnc_state->highest_usn = uSN;
1794 if (obj->meta_data_ctr == NULL) {
1795 DEBUG(8,(__location__ ": getncchanges skipping send of object %s\n",
1796 ldb_dn_get_linearized(msg->dn)));
1797 /* no attributes to send */
1802 r->out.ctr->ctr6.object_count++;
1804 *currentObject = obj;
1805 currentObject = &obj->next_object;
1807 talloc_free(getnc_state->last_dn);
1808 getnc_state->last_dn = ldb_dn_copy(getnc_state, msg->dn);
1810 DEBUG(8,(__location__ ": replicating object %s\n", ldb_dn_get_linearized(msg->dn)));
1812 talloc_free(msg_res);
1813 talloc_free(msg_dn);
1816 getnc_state->num_processed = i;
1818 r->out.ctr->ctr6.nc_object_count = getnc_state->num_records;
1820 /* the client can us to call UpdateRefs on its behalf to
1821 re-establish monitoring of the NC */
1822 if ((req10->replica_flags & (DRSUAPI_DRS_ADD_REF | DRSUAPI_DRS_REF_GCSPN)) &&
1823 !GUID_all_zero(&req10->destination_dsa_guid)) {
1824 struct drsuapi_DsReplicaUpdateRefsRequest1 ureq;
1825 DEBUG(3,("UpdateRefs on getncchanges for %s\n",
1826 GUID_string(mem_ctx, &req10->destination_dsa_guid)));
1827 ureq.naming_context = ncRoot;
1828 ureq.dest_dsa_dns_name = samdb_ntds_msdcs_dns_name(b_state->sam_ctx, mem_ctx,
1829 &req10->destination_dsa_guid);
1830 if (!ureq.dest_dsa_dns_name) {
1833 ureq.dest_dsa_guid = req10->destination_dsa_guid;
1834 ureq.options = DRSUAPI_DRS_ADD_REF |
1835 DRSUAPI_DRS_ASYNC_OP |
1836 DRSUAPI_DRS_GETCHG_CHECK;
1838 /* we also need to pass through the
1839 DRSUAPI_DRS_REF_GCSPN bit so that repsTo gets flagged
1840 to send notifies using the GC SPN */
1841 ureq.options |= (req10->replica_flags & DRSUAPI_DRS_REF_GCSPN);
1843 werr = drsuapi_UpdateRefs(b_state, mem_ctx, &ureq);
1844 if (!W_ERROR_IS_OK(werr)) {
1845 DEBUG(0,(__location__ ": Failed UpdateRefs in DsGetNCChanges - %s\n",
1852 * This is just a guess, how to calculate the
1853 * number of linked attributes to send, we need to
1854 * find out how to do this right.
1856 if (r->out.ctr->ctr6.object_count >= max_links) {
1859 max_links -= r->out.ctr->ctr6.object_count;
1862 link_total = getnc_state->la_count;
1864 if (i < getnc_state->num_records) {
1865 r->out.ctr->ctr6.more_data = true;
1867 /* sort the whole array the first time */
1868 if (!getnc_state->la_sorted) {
1869 LDB_TYPESAFE_QSORT(getnc_state->la_list, getnc_state->la_count,
1870 sam_ctx, linked_attribute_compare);
1871 getnc_state->la_sorted = true;
1874 link_count = getnc_state->la_count - getnc_state->la_idx;
1875 link_count = MIN(max_links, link_count);
1877 r->out.ctr->ctr6.linked_attributes_count = link_count;
1878 r->out.ctr->ctr6.linked_attributes = getnc_state->la_list + getnc_state->la_idx;
1880 getnc_state->la_idx += link_count;
1881 link_given = getnc_state->la_idx;
1883 if (getnc_state->la_idx < getnc_state->la_count) {
1884 r->out.ctr->ctr6.more_data = true;
1888 if (!r->out.ctr->ctr6.more_data) {
1889 talloc_steal(mem_ctx, getnc_state->la_list);
1891 r->out.ctr->ctr6.uptodateness_vector = talloc(mem_ctx, struct drsuapi_DsReplicaCursor2CtrEx);
1892 r->out.ctr->ctr6.new_highwatermark.highest_usn = r->out.ctr->ctr6.new_highwatermark.tmp_highest_usn;
1894 werr = get_nc_changes_udv(sam_ctx, getnc_state->ncRoot_dn,
1895 r->out.ctr->ctr6.uptodateness_vector);
1896 if (!W_ERROR_IS_OK(werr)) {
1900 talloc_free(getnc_state);
1901 b_state->getncchanges_state = NULL;
1904 if (req10->extended_op != DRSUAPI_EXOP_NONE) {
1905 r->out.ctr->ctr6.uptodateness_vector = NULL;
1906 r->out.ctr->ctr6.nc_object_count = 0;
1907 ZERO_STRUCT(r->out.ctr->ctr6.new_highwatermark);
1910 DEBUG(r->out.ctr->ctr6.more_data?4:2,
1911 ("DsGetNCChanges with uSNChanged >= %llu flags 0x%08x on %s gave %u objects (done %u/%u) %u links (done %u/%u (as %s))\n",
1912 (unsigned long long)(req10->highwatermark.highest_usn+1),
1913 req10->replica_flags, drs_ObjectIdentifier_to_string(mem_ctx, ncRoot),
1914 r->out.ctr->ctr6.object_count,
1915 i, r->out.ctr->ctr6.more_data?getnc_state->num_records:i,
1916 r->out.ctr->ctr6.linked_attributes_count,
1917 link_given, link_total,
1918 dom_sid_string(mem_ctx, user_sid)));
1921 if (!r->out.ctr->ctr6.more_data && req10->extended_op != DRSUAPI_EXOP_NONE) {
1922 NDR_PRINT_FUNCTION_DEBUG(drsuapi_DsGetNCChanges, NDR_BOTH, r);