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