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/>.
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
;
51 const char *site_name
;
53 const char *domain_dn
;
55 /* what we need to do as 'Administrator' */
57 struct cli_credentials
*credentials
;
58 struct DsGetinfoBindInfo drsuapi
;
62 static struct DsGetinfoTest
*test_create_context(struct torture_context
*tctx
)
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
);
77 ctx
->drsuapi_binding
->flags
|= DCERPC_SIGN
| DCERPC_SEAL
;
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
;
102 static bool _test_DsBind(struct torture_context
*tctx
,
103 struct DsGetinfoTest
*ctx
, struct cli_credentials
*credentials
, struct DsGetinfoBindInfo
*b
)
108 status
= dcerpc_pipe_connect_b(ctx
,
109 &b
->drs_pipe
, ctx
->drsuapi_binding
,
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
));
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
);
126 } else if (!W_ERROR_IS_OK(b
->req
.out
.result
)) {
127 printf("DsBind failed - %s\n", win_errstr(b
->req
.out
.result
));
131 ZERO_STRUCT(b
->peer_bind_info28
);
132 if (b
->req
.out
.bind_info
) {
133 switch (b
->req
.out
.bind_info
->length
) {
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;
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
;
153 b
->peer_bind_info28
= b
->req
.out
.bind_info
->info
.info28
;
156 printf("DsBind - warning: unknown BindInfo length: %u\n",
157 b
->req
.out
.bind_info
->length
);
165 static bool test_getinfo(struct torture_context
*tctx
,
166 struct DsGetinfoTest
*ctx
)
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
;
175 int invalid_levels
= 0;
182 DRSUAPI_DS_REPLICA_GET_INFO
,
183 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS
,
186 DRSUAPI_DS_REPLICA_GET_INFO
,
187 DRSUAPI_DS_REPLICA_INFO_CURSORS
,
190 DRSUAPI_DS_REPLICA_GET_INFO
,
191 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA
,
194 DRSUAPI_DS_REPLICA_GET_INFO
,
195 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_CONNECT_FAILURES
,
198 DRSUAPI_DS_REPLICA_GET_INFO
,
199 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_LINK_FAILURES
,
202 DRSUAPI_DS_REPLICA_GET_INFO
,
203 DRSUAPI_DS_REPLICA_INFO_PENDING_OPS
,
206 DRSUAPI_DS_REPLICA_GET_INFO2
,
207 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA
,
210 DRSUAPI_DS_REPLICA_GET_INFO2
,
211 DRSUAPI_DS_REPLICA_INFO_CURSORS2
,
214 DRSUAPI_DS_REPLICA_GET_INFO2
,
215 DRSUAPI_DS_REPLICA_INFO_CURSORS3
,
218 DRSUAPI_DS_REPLICA_GET_INFO2
,
219 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA2
,
222 DRSUAPI_DS_REPLICA_GET_INFO2
,
223 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA2
,
226 DRSUAPI_DS_REPLICA_GET_INFO2
,
227 DRSUAPI_DS_REPLICA_INFO_REPSTO
,
230 DRSUAPI_DS_REPLICA_GET_INFO2
,
231 DRSUAPI_DS_REPLICA_INFO_CLIENT_CONTEXTS
,
234 DRSUAPI_DS_REPLICA_GET_INFO2
,
235 DRSUAPI_DS_REPLICA_INFO_UPTODATE_VECTOR_V1
,
238 DRSUAPI_DS_REPLICA_GET_INFO2
,
239 DRSUAPI_DS_REPLICA_INFO_SERVER_OUTGOING_CALLS
,
244 if (torture_setting_bool(tctx
, "samba4", false)) {
245 torture_comment(tctx
, "skipping DsReplicaGetInfo test against Samba4\n");
249 r
.in
.bind_handle
= &ctx
->admin
.drsuapi
.bind_handle
;
252 for (i
=0; i
< ARRAY_SIZE(array
); i
++) {
253 const char *object_dn
;
255 torture_comment(tctx
, "testing DsReplicaGetInfo level %d infotype %d\n",
256 array
[i
].level
, array
[i
].infotype
);
258 object_dn
= (array
[i
].obj_dn
? array
[i
].obj_dn
: ctx
->domain_dn
);
260 r
.in
.level
= array
[i
].level
;
262 case DRSUAPI_DS_REPLICA_GET_INFO
:
263 r
.in
.req
->req1
.info_type
= array
[i
].infotype
;
264 r
.in
.req
->req1
.object_dn
= object_dn
;
265 ZERO_STRUCT(r
.in
.req
->req1
.source_dsa_guid
);
267 case DRSUAPI_DS_REPLICA_GET_INFO2
:
268 r
.in
.req
->req2
.info_type
= array
[i
].infotype
;
269 r
.in
.req
->req2
.object_dn
= object_dn
;
270 ZERO_STRUCT(r
.in
.req
->req2
.source_dsa_guid
);
271 r
.in
.req
->req2
.flags
= 0;
272 r
.in
.req
->req2
.string1
= NULL
;
273 r
.in
.req
->req2
.string2
= NULL
;
274 r
.in
.req
->req2
.enumeration_context
= 0;
279 r
.out
.info_type
= &info_type
;
281 status
= dcerpc_drsuapi_DsReplicaGetInfo(p
, tctx
, &r
);
283 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INVALID_LEVEL
)) {
284 /* this is a not yet supported level */
285 torture_comment(tctx
,
286 "DsReplicaGetInfo level %d and/or infotype %d not yet supported by server\n",
287 array
[i
].level
, array
[i
].infotype
);
289 } else if (!NT_STATUS_IS_OK(status
) && p
->last_fault_code
== DCERPC_FAULT_INVALID_TAG
) {
290 torture_comment(tctx
,
291 "DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
292 array
[i
].level
, array
[i
].infotype
);
294 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
298 if (invalid_levels
> 0) {
306 * DSGETINFO test case setup
308 static bool torture_dsgetinfo_tcase_setup(struct torture_context
*tctx
, void **data
)
311 struct DsGetinfoTest
*ctx
;
313 *data
= ctx
= test_create_context(tctx
);
314 torture_assert(tctx
, ctx
, "test_create_context() failed");
316 bret
= _test_DsBind(tctx
, ctx
, ctx
->admin
.credentials
, &ctx
->admin
.drsuapi
);
317 torture_assert(tctx
, bret
, "_test_DsBind() failed");
323 * DSGETINFO test case cleanup
325 static bool torture_dsgetinfo_tcase_teardown(struct torture_context
*tctx
, void *data
)
327 struct DsGetinfoTest
*ctx
;
328 struct drsuapi_DsUnbind r
;
329 struct policy_handle bind_handle
;
331 ctx
= talloc_get_type(data
, struct DsGetinfoTest
);
334 r
.out
.bind_handle
= &bind_handle
;
336 /* Unbing admin handle */
337 r
.in
.bind_handle
= &ctx
->admin
.drsuapi
.bind_handle
;
338 dcerpc_drsuapi_DsUnbind(ctx
->admin
.drsuapi
.drs_pipe
, ctx
, &r
);
346 * DSGETINFO test case implementation
348 void torture_drs_rpc_dsgetinfo_tcase(struct torture_suite
*suite
)
350 typedef bool (*run_func
) (struct torture_context
*test
, void *tcase_data
);
352 struct torture_test
*test
;
353 struct torture_tcase
*tcase
= torture_suite_add_tcase(suite
, "DSGETINFO");
355 torture_tcase_set_fixture(tcase
,
356 torture_dsgetinfo_tcase_setup
,
357 torture_dsgetinfo_tcase_teardown
);
359 test
= torture_tcase_add_simple_test(tcase
, "DsGetReplicaInfo", (run_func
)test_getinfo
);