s4-drs: torture test for DsGetReplInfo() (RPC-DSGETINFO test).
[Samba/gebeck_regimport.git] / source4 / torture / rpc / dsgetinfo.c
blob7aad7a16d048ddf34cab68340fafd612022afacb
1 /*
2 Unix SMB/CIFS implementation.
4 DsGetReplInfo test. Based on code from dssync.c
6 Copyright (C) Erick Nogueira do Nascimento 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "lib/cmdline/popt_common.h"
24 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
25 #include "librpc/gen_ndr/ndr_drsblobs.h"
26 #include "libcli/cldap/cldap.h"
27 #include "torture/torture.h"
28 #include "../libcli/drsuapi/drsuapi.h"
29 #include "auth/gensec/gensec.h"
30 #include "param/param.h"
31 #include "dsdb/samdb/samdb.h"
32 #include "lib/ldb_wrap.h"
33 #include "torture/rpc/rpc.h"
34 #include "torture/drs/proto.h"
37 struct DsGetinfoBindInfo {
38 struct dcerpc_pipe *drs_pipe;
39 struct drsuapi_DsBind req;
40 struct GUID bind_guid;
41 struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
42 struct drsuapi_DsBindInfo28 our_bind_info28;
43 struct drsuapi_DsBindInfo28 peer_bind_info28;
44 struct policy_handle bind_handle;
47 struct DsGetinfoTest {
48 struct dcerpc_binding *drsuapi_binding;
50 const char *ldap_url;
51 const char *site_name;
53 const char *domain_dn;
55 /* what we need to do as 'Administrator' */
56 struct {
57 struct cli_credentials *credentials;
58 struct DsGetinfoBindInfo drsuapi;
59 } admin;
62 static struct DsGetinfoTest *test_create_context(struct torture_context *tctx)
64 NTSTATUS status;
65 struct DsGetinfoTest *ctx;
66 struct drsuapi_DsBindInfo28 *our_bind_info28;
67 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
68 const char *binding = torture_setting_string(tctx, "binding", NULL);
69 ctx = talloc_zero(tctx, struct DsGetinfoTest);
70 if (!ctx) return NULL;
72 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
73 if (!NT_STATUS_IS_OK(status)) {
74 printf("Bad binding string %s\n", binding);
75 return NULL;
77 ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
79 /* ctx->admin ...*/
80 ctx->admin.credentials = cmdline_credentials;
82 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
83 our_bind_info28->supported_extensions = 0xFFFFFFFF;
84 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
85 our_bind_info28->site_guid = GUID_zero();
86 our_bind_info28->pid = 0;
87 our_bind_info28->repl_epoch = 1;
89 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
90 our_bind_info_ctr->length = 28;
91 our_bind_info_ctr->info.info28 = *our_bind_info28;
93 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
95 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
96 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
97 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
99 return ctx;
102 static bool _test_DsBind(struct torture_context *tctx,
103 struct DsGetinfoTest *ctx, struct cli_credentials *credentials, struct DsGetinfoBindInfo *b)
105 NTSTATUS status;
106 bool ret = true;
108 status = dcerpc_pipe_connect_b(ctx,
109 &b->drs_pipe, ctx->drsuapi_binding,
110 &ndr_table_drsuapi,
111 credentials, tctx->ev, tctx->lp_ctx);
113 if (!NT_STATUS_IS_OK(status)) {
114 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
115 return false;
118 status = dcerpc_drsuapi_DsBind(b->drs_pipe, ctx, &b->req);
119 if (!NT_STATUS_IS_OK(status)) {
120 const char *errstr = nt_errstr(status);
121 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
122 errstr = dcerpc_errstr(ctx, b->drs_pipe->last_fault_code);
124 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
125 ret = false;
126 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
127 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
128 ret = false;
131 ZERO_STRUCT(b->peer_bind_info28);
132 if (b->req.out.bind_info) {
133 switch (b->req.out.bind_info->length) {
134 case 24: {
135 struct drsuapi_DsBindInfo24 *info24;
136 info24 = &b->req.out.bind_info->info.info24;
137 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
138 b->peer_bind_info28.site_guid = info24->site_guid;
139 b->peer_bind_info28.pid = info24->pid;
140 b->peer_bind_info28.repl_epoch = 0;
141 break;
143 case 48: {
144 struct drsuapi_DsBindInfo48 *info48;
145 info48 = &b->req.out.bind_info->info.info48;
146 b->peer_bind_info28.supported_extensions= info48->supported_extensions;
147 b->peer_bind_info28.site_guid = info48->site_guid;
148 b->peer_bind_info28.pid = info48->pid;
149 b->peer_bind_info28.repl_epoch = info48->repl_epoch;
150 break;
152 case 28:
153 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
154 break;
155 default:
156 printf("DsBind - warning: unknown BindInfo length: %u\n",
157 b->req.out.bind_info->length);
161 return ret;
165 static bool test_getinfo(struct torture_context *tctx,
166 struct DsGetinfoTest *ctx)
168 NTSTATUS status;
169 struct dcerpc_pipe *p = ctx->admin.drsuapi.drs_pipe;
170 struct drsuapi_DsReplicaGetInfo r;
171 union drsuapi_DsReplicaGetInfoRequest req;
172 union drsuapi_DsReplicaInfo info;
173 enum drsuapi_DsReplicaInfoType info_type;
174 int i;
175 struct {
176 int32_t level;
177 int32_t infotype;
178 const char *obj_dn;
179 } array[] = {
181 DRSUAPI_DS_REPLICA_GET_INFO,
182 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS,
183 NULL
185 DRSUAPI_DS_REPLICA_GET_INFO,
186 DRSUAPI_DS_REPLICA_INFO_CURSORS,
187 NULL
189 DRSUAPI_DS_REPLICA_GET_INFO,
190 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA,
191 NULL
193 DRSUAPI_DS_REPLICA_GET_INFO,
194 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_CONNECT_FAILURES,
195 NULL
197 DRSUAPI_DS_REPLICA_GET_INFO,
198 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_LINK_FAILURES,
199 NULL
201 DRSUAPI_DS_REPLICA_GET_INFO,
202 DRSUAPI_DS_REPLICA_INFO_PENDING_OPS,
203 NULL
205 DRSUAPI_DS_REPLICA_GET_INFO2,
206 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA,
207 NULL
209 DRSUAPI_DS_REPLICA_GET_INFO2,
210 DRSUAPI_DS_REPLICA_INFO_CURSORS2,
211 NULL
213 DRSUAPI_DS_REPLICA_GET_INFO2,
214 DRSUAPI_DS_REPLICA_INFO_CURSORS3,
215 NULL
217 DRSUAPI_DS_REPLICA_GET_INFO2,
218 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA2,
219 NULL
221 DRSUAPI_DS_REPLICA_GET_INFO2,
222 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA2,
223 NULL
225 DRSUAPI_DS_REPLICA_GET_INFO2,
226 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS02,
227 NULL
229 DRSUAPI_DS_REPLICA_GET_INFO2,
230 DRSUAPI_DS_REPLICA_INFO_CONNECTIONS04,
231 "__IGNORED__"
233 DRSUAPI_DS_REPLICA_GET_INFO2,
234 DRSUAPI_DS_REPLICA_INFO_CURSORS05,
235 NULL
237 DRSUAPI_DS_REPLICA_GET_INFO2,
238 DRSUAPI_DS_REPLICA_INFO_06,
239 NULL
243 if (torture_setting_bool(tctx, "samba4", false)) {
244 torture_comment(tctx, "skipping DsReplicaGetInfo test against Samba4\n");
245 return true;
248 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
249 r.in.req = &req;
251 for (i=0; i < ARRAY_SIZE(array); i++) {
252 const char *object_dn;
254 torture_comment(tctx, "testing DsReplicaGetInfo level %d infotype %d\n",
255 array[i].level, array[i].infotype);
257 object_dn = (array[i].obj_dn ? array[i].obj_dn : ctx->domain_dn);
259 r.in.level = array[i].level;
260 switch(r.in.level) {
261 case DRSUAPI_DS_REPLICA_GET_INFO:
262 r.in.req->req1.info_type = array[i].infotype;
263 r.in.req->req1.object_dn = object_dn;
264 ZERO_STRUCT(r.in.req->req1.guid1);
265 break;
266 case DRSUAPI_DS_REPLICA_GET_INFO2:
267 r.in.req->req2.info_type = array[i].infotype;
268 r.in.req->req2.object_dn = object_dn;
269 ZERO_STRUCT(r.in.req->req2.guid1);
270 r.in.req->req2.unknown1 = 0;
271 r.in.req->req2.string1 = NULL;
272 r.in.req->req2.string2 = NULL;
273 r.in.req->req2.unknown2 = 0;
274 break;
277 r.out.info = &info;
278 r.out.info_type = &info_type;
280 status = dcerpc_drsuapi_DsReplicaGetInfo(p, tctx, &r);
281 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
282 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == DCERPC_FAULT_INVALID_TAG) {
283 torture_comment(tctx,
284 "DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
285 array[i].level, array[i].infotype);
286 } else {
287 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
291 return true;
295 * DSGETINFO test case setup
297 static bool torture_dsgetinfo_tcase_setup(struct torture_context *tctx, void **data)
299 bool bret;
300 struct DsGetinfoTest *ctx;
302 *data = ctx = test_create_context(tctx);
303 torture_assert(tctx, ctx, "test_create_context() failed");
305 bret = _test_DsBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
306 torture_assert(tctx, bret, "_test_DsBind() failed");
308 return true;
312 * DSGETINFO test case cleanup
314 static bool torture_dsgetinfo_tcase_teardown(struct torture_context *tctx, void *data)
316 struct DsGetinfoTest *ctx;
317 struct drsuapi_DsUnbind r;
318 struct policy_handle bind_handle;
320 ctx = talloc_get_type(data, struct DsGetinfoTest);
322 ZERO_STRUCT(r);
323 r.out.bind_handle = &bind_handle;
325 /* Unbing admin handle */
326 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
327 dcerpc_drsuapi_DsUnbind(ctx->admin.drsuapi.drs_pipe, ctx, &r);
329 talloc_free(ctx);
331 return true;
335 * DSGETINFO test case implementation
337 void torture_drs_rpc_dsgetinfo_tcase(struct torture_suite *suite)
339 typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
341 struct torture_test *test;
342 struct torture_tcase *tcase = torture_suite_add_tcase(suite, "DSGETINFO");
344 torture_tcase_set_fixture(tcase,
345 torture_dsgetinfo_tcase_setup,
346 torture_dsgetinfo_tcase_teardown);
348 test = torture_tcase_add_simple_test(tcase, "DsGetReplicaInfo", (run_func)test_getinfo);