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