Release alpha15.
[nivanova/samba-autobuild/.git] / source4 / torture / drs / rpc / dssync.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    DsGetNCChanges replication test
5
6    Copyright (C) Stefan (metze) Metzmacher 2005
7    Copyright (C) Brad Henry 2005
8
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.
13
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.
18
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/>.
21 */
22
23 #include "includes.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "libcli/cldap/cldap.h"
28 #include "torture/torture.h"
29 #include "../libcli/drsuapi/drsuapi.h"
30 #include "auth/gensec/gensec.h"
31 #include "param/param.h"
32 #include "dsdb/samdb/samdb.h"
33 #include "torture/rpc/torture_rpc.h"
34 #include "torture/drs/proto.h"
35 #include "lib/tsocket/tsocket.h"
36 #include "libcli/resolve/resolve.h"
37
38 struct DsSyncBindInfo {
39         struct dcerpc_pipe *drs_pipe;
40         struct dcerpc_binding_handle *drs_handle;
41         struct drsuapi_DsBind req;
42         struct GUID bind_guid;
43         struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
44         struct drsuapi_DsBindInfo28 our_bind_info28;
45         struct drsuapi_DsBindInfo28 peer_bind_info28;
46         struct policy_handle bind_handle;
47 };
48
49 struct DsSyncLDAPInfo {
50         struct ldb_context *ldb;
51 };
52
53 struct DsSyncTest {
54         struct dcerpc_binding *drsuapi_binding;
55
56         const char *ldap_url;
57         const char *dest_address;
58         const char *domain_dn;
59         const char *config_dn;
60         const char *schema_dn;
61
62         /* what we need to do as 'Administrator' */
63         struct {
64                 struct cli_credentials *credentials;
65                 struct DsSyncBindInfo drsuapi;
66                 struct DsSyncLDAPInfo ldap;
67         } admin;
68
69         /* what we need to do as the new dc machine account */
70         struct {
71                 struct cli_credentials *credentials;
72                 struct DsSyncBindInfo drsuapi;
73                 struct drsuapi_DsGetDCInfo2 dc_info2;
74                 struct GUID invocation_id;
75                 struct GUID object_guid;
76         } new_dc;
77
78         /* info about the old dc */
79         struct {
80                 struct drsuapi_DsGetDomainControllerInfo dc_info;
81         } old_dc;
82 };
83
84 static struct DsSyncTest *test_create_context(struct torture_context *tctx)
85 {
86         NTSTATUS status;
87         struct DsSyncTest *ctx;
88         struct drsuapi_DsBindInfo28 *our_bind_info28;
89         struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
90         const char *binding = torture_setting_string(tctx, "binding", NULL);
91         struct nbt_name name;
92
93         ctx = talloc_zero(tctx, struct DsSyncTest);
94         if (!ctx) return NULL;
95
96         status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
97         if (!NT_STATUS_IS_OK(status)) {
98                 printf("Bad binding string %s\n", binding);
99                 return NULL;
100         }
101         ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
102
103         ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s", ctx->drsuapi_binding->host);
104
105         make_nbt_name_server(&name, ctx->drsuapi_binding->host);
106
107         /* do an initial name resolution to find its IP */
108         status = resolve_name(lpcfg_resolve_context(tctx->lp_ctx), &name, tctx,
109                               &ctx->dest_address, tctx->ev);
110         if (!NT_STATUS_IS_OK(status)) {
111                 printf("Failed to resolve %s - %s\n",
112                        name.name, nt_errstr(status));
113                 return NULL;
114         }
115
116         /* ctx->admin ...*/
117         ctx->admin.credentials                          = cmdline_credentials;
118
119         our_bind_info28                         = &ctx->admin.drsuapi.our_bind_info28;
120         our_bind_info28->supported_extensions   = 0xFFFFFFFF;
121         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
122         our_bind_info28->site_guid              = GUID_zero();
123         our_bind_info28->pid                    = 0;
124         our_bind_info28->repl_epoch             = 1;
125
126         our_bind_info_ctr                       = &ctx->admin.drsuapi.our_bind_info_ctr;
127         our_bind_info_ctr->length               = 28;
128         our_bind_info_ctr->info.info28          = *our_bind_info28;
129
130         GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
131
132         ctx->admin.drsuapi.req.in.bind_guid             = &ctx->admin.drsuapi.bind_guid;
133         ctx->admin.drsuapi.req.in.bind_info             = our_bind_info_ctr;
134         ctx->admin.drsuapi.req.out.bind_handle          = &ctx->admin.drsuapi.bind_handle;
135
136         /* ctx->new_dc ...*/
137         ctx->new_dc.credentials                 = cmdline_credentials;
138
139         our_bind_info28                         = &ctx->new_dc.drsuapi.our_bind_info28;
140         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
141         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
142         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
143         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
144         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
145         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
146         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
147         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
148         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
149         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
150         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
151         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
152         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
153         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
154         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
155         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
156         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
157         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
158         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
159         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
160         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
161         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
162         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
163         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
164         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
165         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
166         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
167         our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
168         if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
169                 our_bind_info28->supported_extensions   |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
170         }
171         our_bind_info28->site_guid              = GUID_zero();
172         our_bind_info28->pid                    = 0;
173         our_bind_info28->repl_epoch             = 0;
174
175         our_bind_info_ctr                       = &ctx->new_dc.drsuapi.our_bind_info_ctr;
176         our_bind_info_ctr->length               = 28;
177         our_bind_info_ctr->info.info28          = *our_bind_info28;
178
179         GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
180
181         ctx->new_dc.drsuapi.req.in.bind_guid            = &ctx->new_dc.drsuapi.bind_guid;
182         ctx->new_dc.drsuapi.req.in.bind_info            = our_bind_info_ctr;
183         ctx->new_dc.drsuapi.req.out.bind_handle         = &ctx->new_dc.drsuapi.bind_handle;
184
185         ctx->new_dc.invocation_id                       = ctx->new_dc.drsuapi.bind_guid;
186
187         /* ctx->old_dc ...*/
188
189         return ctx;
190 }
191
192 static bool _test_DsBind(struct torture_context *tctx,
193                          struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
194 {
195         NTSTATUS status;
196         bool ret = true;
197
198         status = dcerpc_pipe_connect_b(ctx,
199                                        &b->drs_pipe, ctx->drsuapi_binding,
200                                        &ndr_table_drsuapi,
201                                        credentials, tctx->ev, tctx->lp_ctx);
202
203         if (!NT_STATUS_IS_OK(status)) {
204                 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
205                 return false;
206         }
207         b->drs_handle = b->drs_pipe->binding_handle;
208
209         status = dcerpc_drsuapi_DsBind_r(b->drs_handle, ctx, &b->req);
210         if (!NT_STATUS_IS_OK(status)) {
211                 const char *errstr = nt_errstr(status);
212                 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
213                 ret = false;
214         } else if (!W_ERROR_IS_OK(b->req.out.result)) {
215                 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
216                 ret = false;
217         }
218
219         ZERO_STRUCT(b->peer_bind_info28);
220         if (b->req.out.bind_info) {
221                 switch (b->req.out.bind_info->length) {
222                 case 24: {
223                         struct drsuapi_DsBindInfo24 *info24;
224                         info24 = &b->req.out.bind_info->info.info24;
225                         b->peer_bind_info28.supported_extensions= info24->supported_extensions;
226                         b->peer_bind_info28.site_guid           = info24->site_guid;
227                         b->peer_bind_info28.pid                 = info24->pid;
228                         b->peer_bind_info28.repl_epoch          = 0;
229                         break;
230                 }
231                 case 48: {
232                         struct drsuapi_DsBindInfo48 *info48;
233                         info48 = &b->req.out.bind_info->info.info48;
234                         b->peer_bind_info28.supported_extensions= info48->supported_extensions;
235                         b->peer_bind_info28.site_guid           = info48->site_guid;
236                         b->peer_bind_info28.pid                 = info48->pid;
237                         b->peer_bind_info28.repl_epoch          = info48->repl_epoch;
238                         break;
239                 }
240                 case 28:
241                         b->peer_bind_info28 = b->req.out.bind_info->info.info28;
242                         break;
243                 default:
244                         printf("DsBind - warning: unknown BindInfo length: %u\n",
245                                b->req.out.bind_info->length);
246                 }
247         }
248
249         return ret;
250 }
251
252 static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx,
253                           struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
254 {
255         bool ret = true;
256
257         struct ldb_context *ldb;
258
259         const char *modules_option[] = { "modules:paged_searches", NULL };
260         ctx->admin.ldap.ldb = ldb = ldb_init(ctx, tctx->ev);
261         if (ldb == NULL) {
262                 return false;
263         }
264
265         /* Despite us loading the schema from the AD server, we need
266          * the samba handlers to get the extended DN syntax stuff */
267         ret = ldb_register_samba_handlers(ldb);
268         if (ret != LDB_SUCCESS) {
269                 talloc_free(ldb);
270                 return NULL;
271         }
272
273         ldb_set_modules_dir(ldb,
274                             talloc_asprintf(ldb,
275                                             "%s/ldb",
276                                             lpcfg_modulesdir(tctx->lp_ctx)));
277
278         if (ldb_set_opaque(ldb, "credentials", credentials)) {
279                 talloc_free(ldb);
280                 return NULL;
281         }
282
283         if (ldb_set_opaque(ldb, "loadparm", tctx->lp_ctx)) {
284                 talloc_free(ldb);
285                 return NULL;
286         }
287
288         ret = ldb_connect(ldb, ctx->ldap_url, 0, modules_option);
289         if (ret != LDB_SUCCESS) {
290                 talloc_free(ldb);
291                 torture_assert_int_equal(tctx, ret, LDB_SUCCESS, "Failed to make LDB connection to target");
292         }
293
294         printf("connected to LDAP: %s\n", ctx->ldap_url);
295
296         return true;
297 }
298
299 static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
300 {
301         struct ldb_context *ldb = ctx->admin.ldap.ldb;
302
303         /* We must have LDB connection ready by this time */
304         SMB_ASSERT(ldb != NULL);
305
306         ctx->domain_dn = ldb_dn_get_linearized(ldb_get_default_basedn(ldb));
307         torture_assert(tctx, ctx->domain_dn != NULL, "Failed to get Domain DN");
308
309         ctx->config_dn = ldb_dn_get_linearized(ldb_get_config_basedn(ldb));
310         torture_assert(tctx, ctx->config_dn != NULL, "Failed to get Domain DN");
311
312         ctx->schema_dn = ldb_dn_get_linearized(ldb_get_schema_basedn(ldb));
313         torture_assert(tctx, ctx->schema_dn != NULL, "Failed to get Domain DN");
314
315         return true;
316 }
317
318 static bool test_analyse_objects(struct torture_context *tctx,
319                                  struct DsSyncTest *ctx,
320                                  const char *partition,
321                                  const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
322                                  uint32_t object_count,
323                                  const struct drsuapi_DsReplicaObjectListItemEx *first_object,
324                                  const DATA_BLOB *gensec_skey)
325 {
326         static uint32_t object_id;
327         const char *save_values_dir;
328         const struct drsuapi_DsReplicaObjectListItemEx *cur;
329         struct ldb_context *ldb = ctx->admin.ldap.ldb;
330         struct ldb_dn *deleted_dn;
331         WERROR status;
332         int i, j, ret;
333         struct dsdb_extended_replicated_objects *objs;
334         struct ldb_extended_dn_control *extended_dn_ctrl;
335         struct dsdb_schema *ldap_schema;
336
337         /* load dsdb_schema using remote prefixMap */
338         torture_assert(tctx,
339                        drs_util_dsdb_schema_load_ldb(tctx, ldb, mapping_ctr, false),
340                        "drs_util_dsdb_schema_load_ldb() failed");
341         ldap_schema = dsdb_get_schema(ldb, NULL);
342
343         status = dsdb_replicated_objects_convert(ldb,
344                                                  ldap_schema,
345                                                  partition,
346                                                  mapping_ctr,
347                                                  object_count,
348                                                  first_object,
349                                                  0, NULL,
350                                                  NULL, NULL,
351                                                  gensec_skey,
352                                                  ctx, &objs);
353         torture_assert_werr_ok(tctx, status, "dsdb_extended_replicated_objects_convert() failed!");
354
355         extended_dn_ctrl = talloc(objs, struct ldb_extended_dn_control);
356         extended_dn_ctrl->type = 1;
357
358         deleted_dn = ldb_dn_new(objs, ldb, partition);
359         ldb_dn_add_child_fmt(deleted_dn, "CN=Deleted Objects");
360
361         for (i=0; i < object_count; i++) {
362                 struct ldb_request *search_req;
363                 struct ldb_result *res;
364                 struct ldb_message *new_msg, *drs_msg, *ldap_msg;
365                 const char **attrs = talloc_array(objs, const char *, objs->objects[i].msg->num_elements+1);
366                 for (j=0; j < objs->objects[i].msg->num_elements; j++) {
367                         attrs[j] = objs->objects[i].msg->elements[j].name;
368                 }
369                 attrs[j] = NULL;
370                 res = talloc_zero(objs, struct ldb_result);
371                 if (!res) {
372                         return LDB_ERR_OPERATIONS_ERROR;
373                 }
374                 ret = ldb_build_search_req(&search_req, ldb, objs,
375                                            objs->objects[i].msg->dn,
376                                            LDB_SCOPE_BASE,
377                                            NULL,
378                                            attrs,
379                                            NULL,
380                                            res,
381                                            ldb_search_default_callback,
382                                            NULL);
383                 if (ret != LDB_SUCCESS) {
384                         return false;
385                 }
386                 talloc_steal(search_req, res);
387                 ret = ldb_request_add_control(search_req, LDB_CONTROL_SHOW_DELETED_OID, true, NULL);
388                 if (ret != LDB_SUCCESS) {
389                         return false;
390                 }
391
392                 ret = ldb_request_add_control(search_req, LDB_CONTROL_EXTENDED_DN_OID, true, extended_dn_ctrl);
393                 if (ret != LDB_SUCCESS) {
394                         return false;
395                 }
396
397                 ret = ldb_request(ldb, search_req);
398                 if (ret == LDB_SUCCESS) {
399                         ret = ldb_wait(search_req->handle, LDB_WAIT_ALL);
400                 }
401
402                 torture_assert_int_equal(tctx, ret, LDB_SUCCESS,
403                                          talloc_asprintf(tctx,
404                                                          "Could not re-fetch object just delivered over DRS: %s",
405                                                          ldb_errstring(ldb)));
406                 torture_assert_int_equal(tctx, res->count, 1, "Could not re-fetch object just delivered over DRS");
407                 ldap_msg = res->msgs[0];
408                 for (j=0; j < ldap_msg->num_elements; j++) {
409                         ldap_msg->elements[j].flags = LDB_FLAG_MOD_ADD;
410                         /* For unknown reasons, there is no nTSecurityDescriptor on cn=deleted objects over LDAP, but there is over DRS!  Skip it on both transports for now here so */
411                         if ((ldb_attr_cmp(ldap_msg->elements[j].name, "nTSecurityDescriptor") == 0) &&
412                             (ldb_dn_compare(ldap_msg->dn, deleted_dn) == 0)) {
413                                 ldb_msg_remove_element(ldap_msg, &ldap_msg->elements[j]);
414                                 /* Don't skip one */
415                                 j--;
416                         }
417                 }
418
419                 ret = ldb_msg_normalize(ldb, search_req,
420                                         objs->objects[i].msg, &drs_msg);
421                 torture_assert(tctx, ret == LDB_SUCCESS,
422                                "ldb_msg_normalize() has failed");
423
424                 for (j=0; j < drs_msg->num_elements; j++) {
425                         if (drs_msg->elements[j].num_values == 0) {
426                                 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
427                                 /* Don't skip one */
428                                 j--;
429
430                                 /* For unknown reasons, there is no nTSecurityDescriptor on cn=deleted objects over LDAP, but there is over DRS! */
431                         } else if ((ldb_attr_cmp(drs_msg->elements[j].name, "nTSecurityDescriptor") == 0) &&
432                                    (ldb_dn_compare(drs_msg->dn, deleted_dn) == 0)) {
433                                 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
434                                 /* Don't skip one */
435                                 j--;
436                         } else if (ldb_attr_cmp(drs_msg->elements[j].name, "unicodePwd") == 0 ||
437                                    ldb_attr_cmp(drs_msg->elements[j].name, "dBCSPwd") == 0 ||
438                                    ldb_attr_cmp(drs_msg->elements[j].name, "ntPwdHistory") == 0 ||
439                                    ldb_attr_cmp(drs_msg->elements[j].name, "lmPwdHistory") == 0 ||
440                                    ldb_attr_cmp(drs_msg->elements[j].name, "supplementalCredentials") == 0 ||
441                                    ldb_attr_cmp(drs_msg->elements[j].name, "priorValue") == 0 ||
442                                    ldb_attr_cmp(drs_msg->elements[j].name, "currentValue") == 0 ||
443                                    ldb_attr_cmp(drs_msg->elements[j].name, "trustAuthOutgoing") == 0 ||
444                                    ldb_attr_cmp(drs_msg->elements[j].name, "trustAuthIncoming") == 0 ||
445                                    ldb_attr_cmp(drs_msg->elements[j].name, "initialAuthOutgoing") == 0 ||
446                                    ldb_attr_cmp(drs_msg->elements[j].name, "initialAuthIncoming") == 0) {
447
448                                 /* These are not shown over LDAP, so we need to skip them for the comparison */
449                                 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
450                                 /* Don't skip one */
451                                 j--;
452                         } else {
453                                 drs_msg->elements[j].flags = LDB_FLAG_MOD_ADD;
454                         }
455                 }
456
457
458                 ret = ldb_msg_difference(ldb, search_req,
459                                          drs_msg, ldap_msg, &new_msg);
460                 torture_assert(tctx, ret == LDB_SUCCESS, "ldb_msg_difference() has failed");
461                 if (new_msg->num_elements != 0) {
462                         char *s;
463                         bool is_warning = true;
464                         unsigned int idx;
465                         struct ldb_message_element *el;
466                         const struct dsdb_attribute * a;
467                         struct ldb_ldif ldif;
468                         ldif.changetype = LDB_CHANGETYPE_MODIFY;
469                         ldif.msg = new_msg;
470                         s = ldb_ldif_write_string(ldb, new_msg, &ldif);
471                         s = talloc_asprintf(tctx, "\n# Difference in between DRS and LDAP objects: \n%s", s);
472
473                         ret = ldb_msg_difference(ldb, search_req,
474                                                  ldap_msg, drs_msg, &ldif.msg);
475                         torture_assert(tctx, ret == LDB_SUCCESS, "ldb_msg_difference() has failed");
476                         s = talloc_asprintf_append(s,
477                                                    "\n# Difference in between LDAP and DRS objects: \n%s",
478                                                    ldb_ldif_write_string(ldb, new_msg, &ldif));
479
480                         s = talloc_asprintf_append(s,
481                                                    "# Should have no objects in 'difference' message. Diff elements: %d",
482                                                    new_msg->num_elements);
483
484                         /*
485                          * In case differences in messages are:
486                          * 1. Attributes with different values, i.e. 'replace'
487                          * 2. Those attributes are forward-link attributes
488                          * then we just warn about those differences.
489                          * It turns out windows doesn't send all of those values
490                          * in replicated_object but in linked_attributes.
491                          */
492                         for (idx = 0; idx < new_msg->num_elements && is_warning; idx++) {
493                                 el = &new_msg->elements[idx];
494                                 a = dsdb_attribute_by_lDAPDisplayName(ldap_schema,
495                                                                       el->name);
496                                 if (!(el->flags & (LDB_FLAG_MOD_ADD|LDB_FLAG_MOD_REPLACE))) {
497                                         /* DRS only value */
498                                         is_warning = false;
499                                 } else if (a->linkID & 1) {
500                                         is_warning = false;
501                                 }
502                         }
503                         if (is_warning) {
504                                 torture_warning(tctx, "%s", s);
505                         } else {
506                                 torture_fail(tctx, s);
507                         }
508                 }
509
510                 /* search_req is used as a tmp talloc context in the above */
511                 talloc_free(search_req);
512         }
513
514         if (!lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
515                 talloc_free(objs);
516                 return true;
517         }
518
519         save_values_dir = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
520
521         for (cur = first_object; cur; cur = cur->next_object) {
522                 const char *dn;
523                 struct dom_sid *sid = NULL;
524                 uint32_t rid = 0;
525                 bool dn_printed = false;
526
527                 if (!cur->object.identifier) continue;
528
529                 dn = cur->object.identifier->dn;
530                 if (cur->object.identifier->sid.num_auths > 0) {
531                         sid = &cur->object.identifier->sid;
532                         rid = sid->sub_auths[sid->num_auths - 1];
533                 }
534
535                 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
536                         const char *name = NULL;
537                         DATA_BLOB plain_data;
538                         struct drsuapi_DsReplicaAttribute *attr;
539                         ndr_pull_flags_fn_t pull_fn = NULL;
540                         ndr_print_fn_t print_fn = NULL;
541                         void *ptr = NULL;
542                         attr = &cur->object.attribute_ctr.attributes[i];
543
544                         switch (attr->attid) {
545                         case DRSUAPI_ATTID_dBCSPwd:
546                                 name    = "dBCSPwd";
547                                 break;
548                         case DRSUAPI_ATTID_unicodePwd:
549                                 name    = "unicodePwd";
550                                 break;
551                         case DRSUAPI_ATTID_ntPwdHistory:
552                                 name    = "ntPwdHistory";
553                                 break;
554                         case DRSUAPI_ATTID_lmPwdHistory:
555                                 name    = "lmPwdHistory";
556                                 break;
557                         case DRSUAPI_ATTID_supplementalCredentials:
558                                 name    = "supplementalCredentials";
559                                 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_supplementalCredentialsBlob;
560                                 print_fn = (ndr_print_fn_t)ndr_print_supplementalCredentialsBlob;
561                                 ptr = talloc(ctx, struct supplementalCredentialsBlob);
562                                 break;
563                         case DRSUAPI_ATTID_priorValue:
564                                 name    = "priorValue";
565                                 break;
566                         case DRSUAPI_ATTID_currentValue:
567                                 name    = "currentValue";
568                                 break;
569                         case DRSUAPI_ATTID_trustAuthOutgoing:
570                                 name    = "trustAuthOutgoing";
571                                 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
572                                 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
573                                 ptr = talloc(ctx, struct trustAuthInOutBlob);
574                                 break;
575                         case DRSUAPI_ATTID_trustAuthIncoming:
576                                 name    = "trustAuthIncoming";
577                                 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
578                                 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
579                                 ptr = talloc(ctx, struct trustAuthInOutBlob);
580                                 break;
581                         case DRSUAPI_ATTID_initialAuthOutgoing:
582                                 name    = "initialAuthOutgoing";
583                                 break;
584                         case DRSUAPI_ATTID_initialAuthIncoming:
585                                 name    = "initialAuthIncoming";
586                                 break;
587                         default:
588                                 continue;
589                         }
590
591                         if (attr->value_ctr.num_values != 1) continue;
592
593                         if (!attr->value_ctr.values[0].blob) continue;
594
595                         plain_data = *attr->value_ctr.values[0].blob;
596
597                         if (!dn_printed) {
598                                 object_id++;
599                                 DEBUG(0,("DN[%u] %s\n", object_id, dn));
600                                 dn_printed = true;
601                         }
602                         DEBUGADD(0,("ATTR: %s plain.length=%lu\n",
603                                     name, (long)plain_data.length));
604                         if (plain_data.length) {
605                                 enum ndr_err_code ndr_err;
606                                 dump_data(0, plain_data.data, plain_data.length);
607                                 if (save_values_dir) {
608                                         char *fname;
609                                         fname = talloc_asprintf(ctx, "%s/%s%02d",
610                                                                 save_values_dir,
611                                                                 name, object_id);
612                                         if (fname) {
613                                                 bool ok;
614                                                 ok = file_save(fname, plain_data.data, plain_data.length);
615                                                 if (!ok) {
616                                                         DEBUGADD(0,("Failed to save '%s'\n", fname));
617                                                 }
618                                         }
619                                         talloc_free(fname);
620                                 }
621
622                                 if (pull_fn) {
623                                         /* Can't use '_all' because of PIDL bugs with relative pointers */
624                                         ndr_err = ndr_pull_struct_blob(&plain_data, ptr,
625                                                                        ptr, pull_fn);
626                                         if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
627                                                 ndr_print_debug(print_fn, name, ptr);
628                                         } else {
629                                                 DEBUG(0, ("Failed to decode %s\n", name));
630                                         }
631                                 }
632                         }
633                         talloc_free(ptr);
634                 }
635         }
636         talloc_free(objs);
637         return true;
638 }
639
640 static bool test_GetNCChanges(struct torture_context *tctx,
641                               struct DsSyncTest *ctx,
642                               const char *nc_dn_str)
643 {
644         NTSTATUS status;
645         bool ret = true;
646         int i, y = 0;
647         uint64_t highest_usn = 0;
648         struct drsuapi_DsGetNCChanges r;
649         union drsuapi_DsGetNCChangesRequest req;
650         struct drsuapi_DsReplicaObjectIdentifier nc;
651         struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
652         struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
653         uint32_t out_level = 0;
654         struct GUID null_guid;
655         struct dom_sid null_sid;
656         DATA_BLOB gensec_skey;
657         struct {
658                 uint32_t level;
659         } array[] = {
660 /*              {
661                         5
662                 },
663 */              {
664                         8
665                 }
666         };
667
668         ZERO_STRUCT(null_guid);
669         ZERO_STRUCT(null_sid);
670
671         highest_usn = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
672
673         array[0].level = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
674
675         if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
676                 const struct samr_Password *nthash;
677                 nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
678                 if (nthash) {
679                         dump_data_pw("CREDENTIALS nthash:", nthash->hash, sizeof(nthash->hash));
680                 }
681         }
682         status = gensec_session_key(ctx->new_dc.drsuapi.drs_pipe->conn->security_state.generic_state,
683                                     &gensec_skey);
684         if (!NT_STATUS_IS_OK(status)) {
685                 printf("failed to get gensec session key: %s\n", nt_errstr(status));
686                 return false;
687         }
688
689         for (i=0; i < ARRAY_SIZE(array); i++) {
690                 printf("Testing DsGetNCChanges level %d\n",
691                         array[i].level);
692
693                 r.in.bind_handle        = &ctx->new_dc.drsuapi.bind_handle;
694                 r.in.level              = array[i].level;
695
696                 switch (r.in.level) {
697                 case 5:
698                         nc.guid = null_guid;
699                         nc.sid  = null_sid;
700                         nc.dn   = nc_dn_str;
701
702                         r.in.req                                        = &req;
703                         r.in.req->req5.destination_dsa_guid             = ctx->new_dc.invocation_id;
704                         r.in.req->req5.source_dsa_invocation_id         = null_guid;
705                         r.in.req->req5.naming_context                   = &nc;
706                         r.in.req->req5.highwatermark.tmp_highest_usn    = highest_usn;
707                         r.in.req->req5.highwatermark.reserved_usn       = 0;
708                         r.in.req->req5.highwatermark.highest_usn        = highest_usn;
709                         r.in.req->req5.uptodateness_vector              = NULL;
710                         r.in.req->req5.replica_flags                    = 0;
711                         if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
712                                 r.in.req->req5.replica_flags            |= DRSUAPI_DRS_USE_COMPRESSION;
713                         }
714                         if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
715                                 r.in.req->req5.replica_flags            |= DRSUAPI_DRS_WRIT_REP;
716                         }
717                         r.in.req->req5.replica_flags                    |= DRSUAPI_DRS_INIT_SYNC
718                                                                         | DRSUAPI_DRS_PER_SYNC
719                                                                         | DRSUAPI_DRS_GET_ANC
720                                                                         | DRSUAPI_DRS_NEVER_SYNCED
721                                                                         ;
722                         r.in.req->req5.max_object_count                 = 133;
723                         r.in.req->req5.max_ndr_size                     = 1336770;
724                         r.in.req->req5.extended_op                      = DRSUAPI_EXOP_NONE;
725                         r.in.req->req5.fsmo_info                        = 0;
726
727                         break;
728                 case 8:
729                         nc.guid = null_guid;
730                         nc.sid  = null_sid;
731                         nc.dn   = nc_dn_str;
732                         /* nc.dn can be set to any other ad partition */
733
734                         r.in.req                                        = &req;
735                         r.in.req->req8.destination_dsa_guid             = ctx->new_dc.invocation_id;
736                         r.in.req->req8.source_dsa_invocation_id         = null_guid;
737                         r.in.req->req8.naming_context                   = &nc;
738                         r.in.req->req8.highwatermark.tmp_highest_usn    = highest_usn;
739                         r.in.req->req8.highwatermark.reserved_usn       = 0;
740                         r.in.req->req8.highwatermark.highest_usn        = highest_usn;
741                         r.in.req->req8.uptodateness_vector              = NULL;
742                         r.in.req->req8.replica_flags                    = 0;
743                         if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
744                                 r.in.req->req8.replica_flags            |= DRSUAPI_DRS_USE_COMPRESSION;
745                         }
746                         if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
747                                 r.in.req->req8.replica_flags            |= DRSUAPI_DRS_WRIT_REP;
748                         }
749                         r.in.req->req8.replica_flags                    |= DRSUAPI_DRS_INIT_SYNC
750                                                                         | DRSUAPI_DRS_PER_SYNC
751                                                                         | DRSUAPI_DRS_GET_ANC
752                                                                         | DRSUAPI_DRS_NEVER_SYNCED
753                                                                         ;
754                         r.in.req->req8.max_object_count                 = 402;
755                         r.in.req->req8.max_ndr_size                     = 402116;
756
757                         r.in.req->req8.extended_op                      = DRSUAPI_EXOP_NONE;
758                         r.in.req->req8.fsmo_info                        = 0;
759                         r.in.req->req8.partial_attribute_set            = NULL;
760                         r.in.req->req8.partial_attribute_set_ex         = NULL;
761                         r.in.req->req8.mapping_ctr.num_mappings         = 0;
762                         r.in.req->req8.mapping_ctr.mappings             = NULL;
763
764                         break;
765                 }
766
767                 for (y=0; ;y++) {
768                         uint32_t _level = 0;
769                         union drsuapi_DsGetNCChangesCtr ctr;
770
771                         ZERO_STRUCT(r.out);
772
773                         r.out.level_out = &_level;
774                         r.out.ctr       = &ctr;
775
776                         if (r.in.level == 5) {
777                                 torture_comment(tctx,
778                                                 "start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",
779                                                 y,
780                                                 (unsigned long long) r.in.req->req5.highwatermark.tmp_highest_usn,
781                                                 (unsigned long long) r.in.req->req5.highwatermark.highest_usn);
782                         }
783
784                         if (r.in.level == 8) {
785                                 torture_comment(tctx,
786                                                 "start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",
787                                                 y,
788                                                 (unsigned long long) r.in.req->req8.highwatermark.tmp_highest_usn,
789                                                 (unsigned long long) r.in.req->req8.highwatermark.highest_usn);
790                         }
791
792                         status = dcerpc_drsuapi_DsGetNCChanges_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
793                         torture_drsuapi_assert_call(tctx, ctx->new_dc.drsuapi.drs_pipe, status,
794                                                     &r, "dcerpc_drsuapi_DsGetNCChanges");
795
796                         if (ret == true && *r.out.level_out == 1) {
797                                 out_level = 1;
798                                 ctr1 = &r.out.ctr->ctr1;
799                         } else if (ret == true && *r.out.level_out == 2 &&
800                                    r.out.ctr->ctr2.mszip1.ts) {
801                                 out_level = 1;
802                                 ctr1 = &r.out.ctr->ctr2.mszip1.ts->ctr1;
803                         }
804
805                         if (out_level == 1) {
806                                 torture_comment(tctx,
807                                                 "end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",
808                                                 y,
809                                                 (unsigned long long) ctr1->new_highwatermark.tmp_highest_usn,
810                                                 (unsigned long long) ctr1->new_highwatermark.highest_usn);
811
812                                 if (!test_analyse_objects(tctx, ctx, nc_dn_str, &ctr1->mapping_ctr,  ctr1->object_count,
813                                                           ctr1->first_object, &gensec_skey)) {
814                                         return false;
815                                 }
816
817                                 if (ctr1->more_data) {
818                                         r.in.req->req5.highwatermark = ctr1->new_highwatermark;
819                                         continue;
820                                 }
821                         }
822
823                         if (ret == true && *r.out.level_out == 6) {
824                                 out_level = 6;
825                                 ctr6 = &r.out.ctr->ctr6;
826                         } else if (ret == true && *r.out.level_out == 7
827                                    && r.out.ctr->ctr7.level == 6
828                                    && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
829                                    && r.out.ctr->ctr7.ctr.mszip6.ts) {
830                                 out_level = 6;
831                                 ctr6 = &r.out.ctr->ctr7.ctr.mszip6.ts->ctr6;
832                         } else if (ret == true && *r.out.level_out == 7
833                                    && r.out.ctr->ctr7.level == 6
834                                    && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS
835                                    && r.out.ctr->ctr7.ctr.xpress6.ts) {
836                                 out_level = 6;
837                                 ctr6 = &r.out.ctr->ctr7.ctr.xpress6.ts->ctr6;
838                         }
839
840                         if (out_level == 6) {
841                                 torture_comment(tctx,
842                                                 "end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",
843                                                 y,
844                                                 (unsigned long long) ctr6->new_highwatermark.tmp_highest_usn,
845                                                 (unsigned long long) ctr6->new_highwatermark.highest_usn);
846
847                                 if (!test_analyse_objects(tctx, ctx, nc_dn_str, &ctr6->mapping_ctr,  ctr6->object_count,
848                                                           ctr6->first_object, &gensec_skey)) {
849                                         return false;
850                                 }
851
852                                 if (ctr6->more_data) {
853                                         r.in.req->req8.highwatermark = ctr6->new_highwatermark;
854                                         continue;
855                                 }
856                         }
857
858                         break;
859                 }
860         }
861
862         return ret;
863 }
864
865 /**
866  * Test DsGetNCChanges() DRSUAPI call against one
867  * or more Naming Contexts.
868  * Specific NC to test with may be supplied
869  * in lp_ctx configuration. If no NC is specified,
870  * it will test DsGetNCChanges() on all NCs on remote DC
871  */
872 static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
873 {
874         bool ret = true;
875         size_t i, count;
876         const char *nc_dn_str;
877         const char **nc_list;
878
879         nc_list = const_str_list(str_list_make_empty(ctx));
880         torture_assert(tctx, nc_list, "Not enough memory!");
881
882         /* make a list of partitions to test with */
883         nc_dn_str = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
884         if (nc_dn_str == NULL) {
885                 nc_list = str_list_add_const(nc_list, ctx->domain_dn);
886                 nc_list = str_list_add_const(nc_list, ctx->config_dn);
887                 nc_list = str_list_add_const(nc_list, ctx->schema_dn);
888         } else {
889                 nc_list = str_list_add_const(nc_list, nc_dn_str);
890         }
891
892         count = str_list_length(nc_list);
893         for (i = 0; i < count && ret; i++) {
894                 torture_comment(tctx, "\nNaming Context: %s\n", nc_list[i]);
895                 ret = test_GetNCChanges(tctx, ctx, nc_list[i]);
896         }
897
898         talloc_free(nc_list);
899         return ret;
900 }
901
902
903 static bool test_FetchNT4Data(struct torture_context *tctx,
904                               struct DsSyncTest *ctx)
905 {
906         NTSTATUS status;
907         struct drsuapi_DsGetNT4ChangeLog r;
908         union drsuapi_DsGetNT4ChangeLogRequest req;
909         union drsuapi_DsGetNT4ChangeLogInfo info;
910         uint32_t level_out = 0;
911         struct GUID null_guid;
912         struct dom_sid null_sid;
913         DATA_BLOB cookie;
914
915         ZERO_STRUCT(null_guid);
916         ZERO_STRUCT(null_sid);
917         ZERO_STRUCT(cookie);
918
919         ZERO_STRUCT(r);
920         r.in.bind_handle        = &ctx->new_dc.drsuapi.bind_handle;
921         r.in.level              = 1;
922         r.out.info              = &info;
923         r.out.level_out         = &level_out;
924
925         req.req1.flags = lpcfg_parm_int(tctx->lp_ctx, NULL,
926                                      "dssync", "nt4changelog_flags",
927                                      DRSUAPI_NT4_CHANGELOG_GET_CHANGELOG |
928                                      DRSUAPI_NT4_CHANGELOG_GET_SERIAL_NUMBERS);
929         req.req1.preferred_maximum_length = lpcfg_parm_int(tctx->lp_ctx, NULL,
930                                         "dssync", "nt4changelog_preferred_len",
931                                         0x00004000);
932
933         while (1) {
934                 req.req1.restart_length = cookie.length;
935                 req.req1.restart_data = cookie.data;
936
937                 r.in.req = &req;
938
939                 status = dcerpc_drsuapi_DsGetNT4ChangeLog_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
940                 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
941                         torture_skip(tctx,
942                                      "DsGetNT4ChangeLog not supported: NT_STATUS_NOT_IMPLEMENTED");
943                 } else if (!NT_STATUS_IS_OK(status)) {
944                         const char *errstr = nt_errstr(status);
945                         if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
946                                 torture_skip(tctx,
947                                              "DsGetNT4ChangeLog not supported: NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE");
948                         }
949                         torture_fail(tctx,
950                                      talloc_asprintf(tctx, "dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n",
951                                                      errstr));
952                 } else if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_DOMAIN_ROLE)) {
953                         torture_skip(tctx,
954                                      "DsGetNT4ChangeLog not supported: WERR_INVALID_DOMAIN_ROLE");
955                 } else if (!W_ERROR_IS_OK(r.out.result)) {
956                         torture_fail(tctx,
957                                      talloc_asprintf(tctx, "DsGetNT4ChangeLog failed - %s\n",
958                                                      win_errstr(r.out.result)));
959                 } else if (*r.out.level_out != 1) {
960                         torture_fail(tctx,
961                                      talloc_asprintf(tctx, "DsGetNT4ChangeLog unknown level - %u\n",
962                                                      *r.out.level_out));
963                 } else if (NT_STATUS_IS_OK(r.out.info->info1.status)) {
964                 } else if (NT_STATUS_EQUAL(r.out.info->info1.status, STATUS_MORE_ENTRIES)) {
965                         cookie.length   = r.out.info->info1.restart_length;
966                         cookie.data     = r.out.info->info1.restart_data;
967                         continue;
968                 } else {
969                         torture_fail(tctx,
970                                      talloc_asprintf(tctx, "DsGetNT4ChangeLog failed - %s\n",
971                                                      nt_errstr(r.out.info->info1.status)));
972                 }
973
974                 break;
975         }
976
977         return true;
978 }
979
980 /**
981  * DSSYNC test case setup
982  */
983 static bool torture_dssync_tcase_setup(struct torture_context *tctx, void **data)
984 {
985         bool bret;
986         struct DsSyncTest *ctx;
987
988         *data = ctx = test_create_context(tctx);
989         torture_assert(tctx, ctx, "test_create_context() failed");
990
991         bret = _test_DsBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
992         torture_assert(tctx, bret, "_test_DsBind() failed");
993
994         bret = test_LDAPBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.ldap);
995         torture_assert(tctx, bret, "test_LDAPBind() failed");
996
997         bret = test_GetInfo(tctx, ctx);
998         torture_assert(tctx, bret, "test_GetInfo() failed");
999
1000         bret = _test_DsBind(tctx, ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
1001         torture_assert(tctx, bret, "_test_DsBind() failed");
1002
1003         return true;
1004 }
1005
1006 /**
1007  * DSSYNC test case cleanup
1008  */
1009 static bool torture_dssync_tcase_teardown(struct torture_context *tctx, void *data)
1010 {
1011         struct DsSyncTest *ctx;
1012         struct drsuapi_DsUnbind r;
1013         struct policy_handle bind_handle;
1014
1015         ctx = talloc_get_type(data, struct DsSyncTest);
1016
1017         ZERO_STRUCT(r);
1018         r.out.bind_handle = &bind_handle;
1019
1020         /* Unbing admin handle */
1021         r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
1022         dcerpc_drsuapi_DsUnbind_r(ctx->admin.drsuapi.drs_handle, ctx, &r);
1023
1024         /* Unbing new_dc handle */
1025         r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
1026         dcerpc_drsuapi_DsUnbind_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
1027
1028         talloc_free(ctx);
1029
1030         return true;
1031 }
1032
1033 /**
1034  * DSSYNC test case implementation
1035  */
1036 void torture_drs_rpc_dssync_tcase(struct torture_suite *suite)
1037 {
1038         typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
1039
1040         struct torture_test *test;
1041         struct torture_tcase *tcase = torture_suite_add_tcase(suite, "dssync");
1042
1043         torture_tcase_set_fixture(tcase,
1044                                   torture_dssync_tcase_setup,
1045                                   torture_dssync_tcase_teardown);
1046
1047         test = torture_tcase_add_simple_test(tcase, "DC_FetchData", (run_func)test_FetchData);
1048         test = torture_tcase_add_simple_test(tcase, "FetchNT4Data", (run_func)test_FetchNT4Data);
1049 }
1050