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 "torture/rpc/torture_rpc.h"
33 #include "torture/drs/proto.h"
36 struct DsGetinfoBindInfo
{
37 struct dcerpc_pipe
*drs_pipe
;
38 struct dcerpc_binding_handle
*drs_handle
;
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
;
65 return the default DN for a ldap server given a connected RPC pipe to the
68 static const char *torture_get_ldap_base_dn(struct torture_context
*tctx
, struct dcerpc_pipe
*p
)
70 const char *hostname
= p
->binding
->host
;
71 struct ldb_context
*ldb
;
72 const char *ldap_url
= talloc_asprintf(p
, "ldap://%s", hostname
);
73 const char *attrs
[] = { "defaultNamingContext", NULL
};
75 TALLOC_CTX
*tmp_ctx
= talloc_new(tctx
);
77 struct ldb_result
*res
;
79 ldb
= ldb_init(tmp_ctx
, tctx
->ev
);
85 if (ldb_set_opaque(ldb
, "loadparm", tctx
->lp_ctx
)) {
90 ldb_set_modules_dir(ldb
,
91 modules_path(ldb
, "ldb"));
93 ret
= ldb_connect(ldb
, ldap_url
, 0, NULL
);
94 if (ret
!= LDB_SUCCESS
) {
95 torture_comment(tctx
, "Failed to make LDB connection to target");
100 ret
= dsdb_search_dn(ldb
, tmp_ctx
, &res
, ldb_dn_new(tmp_ctx
, ldb
, ""),
102 if (ret
!= LDB_SUCCESS
) {
103 torture_comment(tctx
, "Failed to get defaultNamingContext");
104 talloc_free(tmp_ctx
);
108 dnstr
= ldb_msg_find_attr_as_string(res
->msgs
[0], "defaultNamingContext", NULL
);
109 dnstr
= talloc_strdup(tctx
, dnstr
);
110 talloc_free(tmp_ctx
);
115 static struct DsGetinfoTest
*test_create_context(struct torture_context
*tctx
)
118 struct DsGetinfoTest
*ctx
;
119 struct drsuapi_DsBindInfo28
*our_bind_info28
;
120 struct drsuapi_DsBindInfoCtr
*our_bind_info_ctr
;
121 const char *binding
= torture_setting_string(tctx
, "binding", NULL
);
122 ctx
= talloc_zero(tctx
, struct DsGetinfoTest
);
123 if (!ctx
) return NULL
;
125 status
= dcerpc_parse_binding(ctx
, binding
, &ctx
->drsuapi_binding
);
126 if (!NT_STATUS_IS_OK(status
)) {
127 printf("Bad binding string %s\n", binding
);
130 status
= dcerpc_binding_set_flags(ctx
->drsuapi_binding
, DCERPC_SIGN
| DCERPC_SEAL
, 0);
131 if (!NT_STATUS_IS_OK(status
)) {
132 printf("dcerpc_binding_set_flags - %s\n", nt_errstr(status
));
137 ctx
->admin
.credentials
= cmdline_credentials
;
139 our_bind_info28
= &ctx
->admin
.drsuapi
.our_bind_info28
;
140 our_bind_info28
->supported_extensions
= 0xFFFFFFFF;
141 our_bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
;
142 our_bind_info28
->site_guid
= GUID_zero();
143 our_bind_info28
->pid
= 0;
144 our_bind_info28
->repl_epoch
= 1;
146 our_bind_info_ctr
= &ctx
->admin
.drsuapi
.our_bind_info_ctr
;
147 our_bind_info_ctr
->length
= 28;
148 our_bind_info_ctr
->info
.info28
= *our_bind_info28
;
150 GUID_from_string(DRSUAPI_DS_BIND_GUID
, &ctx
->admin
.drsuapi
.bind_guid
);
152 ctx
->admin
.drsuapi
.req
.in
.bind_guid
= &ctx
->admin
.drsuapi
.bind_guid
;
153 ctx
->admin
.drsuapi
.req
.in
.bind_info
= our_bind_info_ctr
;
154 ctx
->admin
.drsuapi
.req
.out
.bind_handle
= &ctx
->admin
.drsuapi
.bind_handle
;
159 static bool _test_DsBind(struct torture_context
*tctx
,
160 struct DsGetinfoTest
*ctx
, struct cli_credentials
*credentials
, struct DsGetinfoBindInfo
*b
)
165 status
= dcerpc_pipe_connect_b(ctx
,
166 &b
->drs_pipe
, ctx
->drsuapi_binding
,
168 credentials
, tctx
->ev
, tctx
->lp_ctx
);
170 if (!NT_STATUS_IS_OK(status
)) {
171 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status
));
174 b
->drs_handle
= b
->drs_pipe
->binding_handle
;
176 status
= dcerpc_drsuapi_DsBind_r(b
->drs_handle
, ctx
, &b
->req
);
177 if (!NT_STATUS_IS_OK(status
)) {
178 const char *errstr
= nt_errstr(status
);
179 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr
);
181 } else if (!W_ERROR_IS_OK(b
->req
.out
.result
)) {
182 printf("DsBind failed - %s\n", win_errstr(b
->req
.out
.result
));
186 ZERO_STRUCT(b
->peer_bind_info28
);
187 if (b
->req
.out
.bind_info
) {
188 switch (b
->req
.out
.bind_info
->length
) {
190 struct drsuapi_DsBindInfo24
*info24
;
191 info24
= &b
->req
.out
.bind_info
->info
.info24
;
192 b
->peer_bind_info28
.supported_extensions
= info24
->supported_extensions
;
193 b
->peer_bind_info28
.site_guid
= info24
->site_guid
;
194 b
->peer_bind_info28
.pid
= info24
->pid
;
195 b
->peer_bind_info28
.repl_epoch
= 0;
199 struct drsuapi_DsBindInfo48
*info48
;
200 info48
= &b
->req
.out
.bind_info
->info
.info48
;
201 b
->peer_bind_info28
.supported_extensions
= info48
->supported_extensions
;
202 b
->peer_bind_info28
.site_guid
= info48
->site_guid
;
203 b
->peer_bind_info28
.pid
= info48
->pid
;
204 b
->peer_bind_info28
.repl_epoch
= info48
->repl_epoch
;
208 b
->peer_bind_info28
= b
->req
.out
.bind_info
->info
.info28
;
211 printf("DsBind - warning: unknown BindInfo length: %u\n",
212 b
->req
.out
.bind_info
->length
);
220 static bool test_getinfo(struct torture_context
*tctx
,
221 struct DsGetinfoTest
*ctx
)
224 struct dcerpc_pipe
*p
= ctx
->admin
.drsuapi
.drs_pipe
;
225 struct dcerpc_binding_handle
*b
= ctx
->admin
.drsuapi
.drs_handle
;
226 struct drsuapi_DsReplicaGetInfo r
;
227 union drsuapi_DsReplicaGetInfoRequest req
;
228 union drsuapi_DsReplicaInfo info
;
229 enum drsuapi_DsReplicaInfoType info_type
;
231 int invalid_levels
= 0;
236 const char *attribute_name
;
240 .level
= DRSUAPI_DS_REPLICA_GET_INFO
,
241 .infotype
= DRSUAPI_DS_REPLICA_INFO_NEIGHBORS
243 .level
= DRSUAPI_DS_REPLICA_GET_INFO
,
244 .infotype
= DRSUAPI_DS_REPLICA_INFO_CURSORS
246 .level
= DRSUAPI_DS_REPLICA_GET_INFO
,
247 .infotype
= DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA
249 .level
= DRSUAPI_DS_REPLICA_GET_INFO
,
250 .infotype
= DRSUAPI_DS_REPLICA_INFO_KCC_DSA_CONNECT_FAILURES
252 .level
= DRSUAPI_DS_REPLICA_GET_INFO
,
253 .infotype
= DRSUAPI_DS_REPLICA_INFO_KCC_DSA_LINK_FAILURES
255 .level
= DRSUAPI_DS_REPLICA_GET_INFO
,
256 .infotype
= DRSUAPI_DS_REPLICA_INFO_PENDING_OPS
258 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
259 .infotype
= DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA
261 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
262 .infotype
= DRSUAPI_DS_REPLICA_INFO_CURSORS2
264 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
265 .infotype
= DRSUAPI_DS_REPLICA_INFO_CURSORS3
267 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
268 .infotype
= DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA2
,
269 .obj_dn
= "CN=Domain Admins,CN=Users,",
272 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
273 .infotype
= DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA2
,
274 .obj_dn
= "CN=Domain Admins,CN=Users,",
275 .flags
= DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE
277 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
278 .infotype
= DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA2
280 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
281 .infotype
= DRSUAPI_DS_REPLICA_INFO_REPSTO
283 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
284 .infotype
= DRSUAPI_DS_REPLICA_INFO_CLIENT_CONTEXTS
286 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
287 .infotype
= DRSUAPI_DS_REPLICA_INFO_UPTODATE_VECTOR_V1
289 .level
= DRSUAPI_DS_REPLICA_GET_INFO2
,
290 .infotype
= DRSUAPI_DS_REPLICA_INFO_SERVER_OUTGOING_CALLS
294 ctx
->domain_dn
= torture_get_ldap_base_dn(tctx
, p
);
295 torture_assert(tctx
, ctx
->domain_dn
!= NULL
, "Cannot get domain_dn");
297 if (torture_setting_bool(tctx
, "samba4", false)) {
298 torture_comment(tctx
, "skipping DsReplicaGetInfo test against Samba4\n");
302 r
.in
.bind_handle
= &ctx
->admin
.drsuapi
.bind_handle
;
305 for (i
=0; i
< ARRAY_SIZE(array
); i
++) {
306 const char *object_dn
;
308 torture_comment(tctx
, "Testing DsReplicaGetInfo level %d infotype %d\n",
309 array
[i
].level
, array
[i
].infotype
);
311 if (array
[i
].obj_dn
) {
312 object_dn
= array
[i
].obj_dn
;
313 if (object_dn
[strlen(object_dn
)-1] == ',') {
314 /* add the domain DN on the end */
315 object_dn
= talloc_asprintf(tctx
, "%s%s", object_dn
, ctx
->domain_dn
);
318 object_dn
= ctx
->domain_dn
;
321 r
.in
.level
= array
[i
].level
;
323 case DRSUAPI_DS_REPLICA_GET_INFO
:
324 r
.in
.req
->req1
.info_type
= array
[i
].infotype
;
325 r
.in
.req
->req1
.object_dn
= object_dn
;
326 ZERO_STRUCT(r
.in
.req
->req1
.source_dsa_guid
);
328 case DRSUAPI_DS_REPLICA_GET_INFO2
:
329 r
.in
.req
->req2
.info_type
= array
[i
].infotype
;
330 r
.in
.req
->req2
.object_dn
= object_dn
;
331 ZERO_STRUCT(r
.in
.req
->req2
.source_dsa_guid
);
332 r
.in
.req
->req2
.flags
= 0;
333 r
.in
.req
->req2
.attribute_name
= NULL
;
334 r
.in
.req
->req2
.value_dn_str
= NULL
;
335 r
.in
.req
->req2
.enumeration_context
= 0;
339 /* Construct a different request for some of the infoTypes */
340 if (array
[i
].attribute_name
!= NULL
) {
341 r
.in
.req
->req2
.attribute_name
= array
[i
].attribute_name
;
343 if (array
[i
].flags
!= 0) {
344 r
.in
.req
->req2
.flags
|= array
[i
].flags
;
348 r
.out
.info_type
= &info_type
;
350 status
= dcerpc_drsuapi_DsReplicaGetInfo_r(b
, tctx
, &r
);
351 if (NT_STATUS_EQUAL(status
, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE
)) {
352 torture_comment(tctx
,
353 "DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
354 array
[i
].level
, array
[i
].infotype
);
357 torture_assert_ntstatus_ok(tctx
, status
, talloc_asprintf(tctx
,
358 "DsReplicaGetInfo level %d and/or infotype %d failed\n",
359 array
[i
].level
, array
[i
].infotype
));
360 if (W_ERROR_EQUAL(r
.out
.result
, WERR_INVALID_LEVEL
)) {
361 /* this is a not yet supported level */
362 torture_comment(tctx
,
363 "DsReplicaGetInfo level %d and/or infotype %d not yet supported by server\n",
364 array
[i
].level
, array
[i
].infotype
);
369 torture_drsuapi_assert_call(tctx
, p
, status
, &r
, "dcerpc_drsuapi_DsReplicaGetInfo");
372 if (invalid_levels
> 0) {
380 * DSGETINFO test case setup
382 static bool torture_dsgetinfo_tcase_setup(struct torture_context
*tctx
, void **data
)
385 struct DsGetinfoTest
*ctx
;
387 *data
= ctx
= test_create_context(tctx
);
388 torture_assert(tctx
, ctx
, "test_create_context() failed");
390 bret
= _test_DsBind(tctx
, ctx
, ctx
->admin
.credentials
, &ctx
->admin
.drsuapi
);
391 torture_assert(tctx
, bret
, "_test_DsBind() failed");
397 * DSGETINFO test case cleanup
399 static bool torture_dsgetinfo_tcase_teardown(struct torture_context
*tctx
, void *data
)
401 struct DsGetinfoTest
*ctx
;
402 struct drsuapi_DsUnbind r
;
403 struct policy_handle bind_handle
;
405 ctx
= talloc_get_type(data
, struct DsGetinfoTest
);
408 r
.out
.bind_handle
= &bind_handle
;
410 /* Unbing admin handle */
411 r
.in
.bind_handle
= &ctx
->admin
.drsuapi
.bind_handle
;
412 dcerpc_drsuapi_DsUnbind_r(ctx
->admin
.drsuapi
.drs_handle
, ctx
, &r
);
420 * DSGETINFO test case implementation
422 void torture_drs_rpc_dsgetinfo_tcase(struct torture_suite
*suite
)
424 typedef bool (*run_func
) (struct torture_context
*test
, void *tcase_data
);
425 struct torture_tcase
*tcase
= torture_suite_add_tcase(suite
, "dsgetinfo");
427 torture_tcase_set_fixture(tcase
,
428 torture_dsgetinfo_tcase_setup
,
429 torture_dsgetinfo_tcase_teardown
);
431 torture_tcase_add_simple_test(tcase
, "DsGetReplicaInfo", (run_func
)test_getinfo
);