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