From 7fd416bd3e0d9cf602f441c9d4a1750544cba8e5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 31 Aug 2007 22:34:52 +0000 Subject: r24855: Convert RPC-DRSUAPI, RPC-SCHANNEL to use the torture API. (This used to be commit dadcc4708e1813c0b657f1d357c2ae202ea4ec5a) --- source4/torture/rpc/drsuapi.c | 262 +++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 144 deletions(-) (limited to 'source4/torture/rpc/drsuapi.c') diff --git a/source4/torture/rpc/drsuapi.c b/source4/torture/rpc/drsuapi.c index a9c7adc70b..08420d0d17 100644 --- a/source4/torture/rpc/drsuapi.c +++ b/source4/torture/rpc/drsuapi.c @@ -25,6 +25,7 @@ #include "torture/torture.h" #include "librpc/gen_ndr/ndr_drsuapi_c.h" #include "torture/rpc/rpc.h" +#include "dlinklist.h" #define TEST_MACHINE_NAME "torturetest" @@ -33,6 +34,7 @@ bool test_DsBind(struct dcerpc_pipe *p, struct torture_context *tctx, { NTSTATUS status; struct drsuapi_DsBind r; + struct torture_rpc_tcase_data *rpc_tcase; GUID_from_string(DRSUAPI_DS_BIND_GUID, &priv->bind_guid); @@ -40,29 +42,87 @@ bool test_DsBind(struct dcerpc_pipe *p, struct torture_context *tctx, r.in.bind_info = NULL; r.out.bind_handle = &priv->bind_handle; - torture_comment(tctx, "testing DsBind\n"); - status = dcerpc_drsuapi_DsBind(p, tctx, &r); - if (!NT_STATUS_IS_OK(status)) { - const char *errstr = nt_errstr(status); - if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { - errstr = dcerpc_errstr(tctx, p->last_fault_code); - } - torture_fail(tctx, "dcerpc_drsuapi_DsBind failed"); - } else if (!W_ERROR_IS_OK(r.out.result)) { - torture_fail(tctx, "DsBind failed"); - } + torture_assert_ntstatus_ok(tctx, status, "DsBind"); + torture_assert_werr_ok(tctx, r.out.result, "DsBind"); + + rpc_tcase = (struct torture_rpc_tcase_data *)tctx->active_tcase->data; + + priv->join = rpc_tcase->join_ctx; + + return true; +} + +bool test_DsUnbind(struct dcerpc_pipe *p, struct torture_context *tctx, + struct DsPrivate *priv) +{ + NTSTATUS status; + struct drsuapi_DsUnbind r; + + r.in.bind_handle = &priv->bind_handle; + r.out.bind_handle = &priv->bind_handle; + + status = dcerpc_drsuapi_DsUnbind(p, tctx, &r); + torture_assert_ntstatus_ok(tctx, status, + "dcerpc_drsuapi_DsUnbind failed"); + torture_assert_werr_ok(tctx, r.out.result, "DsBind failed"); return true; } -static bool test_DsGetDomainControllerInfo(struct dcerpc_pipe *p, - struct torture_context *torture, +static bool wrap_test_drsuapi(struct torture_context *tctx, + struct torture_tcase *tcase, + struct torture_test *test) +{ + bool (*fn) (struct torture_context *, struct dcerpc_pipe *, struct DsPrivate *); + struct torture_rpc_tcase_data *tcase_data = + (struct torture_rpc_tcase_data *)tcase->data; + bool ret; + struct DsPrivate priv; + + ZERO_STRUCT(priv); + + fn = test->fn; + + if (!test_DsBind(tcase_data->pipe, tctx, &priv)) + return false; + + ret = fn(tctx, tcase_data->pipe, &priv); + + if (!test_DsUnbind(tcase_data->pipe, tctx, &priv)) + return false; + + return ret; +} + +static struct torture_test *torture_rpc_tcase_add_drsuapi_test( + struct torture_rpc_tcase *tcase, + const char *name, + bool (*fn) (struct torture_context *, struct dcerpc_pipe *, struct DsPrivate *priv)) +{ + struct torture_test *test; + + test = talloc(tcase, struct torture_test); + + test->name = talloc_strdup(test, name); + test->description = NULL; + test->run = wrap_test_drsuapi; + test->dangerous = false; + test->data = NULL; + test->fn = fn; + + DLIST_ADD(tcase->tcase.tests, test); + + return test; +} + +static bool test_DsGetDomainControllerInfo(struct torture_context *torture, + struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; struct drsuapi_DsGetDomainControllerInfo r; - BOOL found = False; + bool found = false; int i, j, k; struct { @@ -123,7 +183,7 @@ static bool test_DsGetDomainControllerInfo(struct dcerpc_pipe *p, for (k=0; k < r.out.ctr.ctr1.count; k++) { if (strcasecmp_m(r.out.ctr.ctr1.array[k].netbios_name, torture_join_netbios_name(priv->join)) == 0) { - found = True; + found = true; break; } } @@ -132,7 +192,7 @@ static bool test_DsGetDomainControllerInfo(struct dcerpc_pipe *p, for (k=0; k < r.out.ctr.ctr2.count; k++) { if (strcasecmp_m(r.out.ctr.ctr2.array[k].netbios_name, torture_join_netbios_name(priv->join)) == 0) { - found = True; + found = true; priv->dcinfo = r.out.ctr.ctr2.array[k]; break; } @@ -168,7 +228,7 @@ static bool test_DsGetDomainControllerInfo(struct dcerpc_pipe *p, for (k=0; k < r.out.ctr.ctr01.count; k++) { if (strcasecmp_m(r.out.ctr.ctr01.array[k].client_account, dc_account)) { - found = True; + found = true; break; } } @@ -180,8 +240,8 @@ static bool test_DsGetDomainControllerInfo(struct dcerpc_pipe *p, return true; } -static bool test_DsWriteAccountSpn(struct dcerpc_pipe *p, - struct torture_context *tctx, +static bool test_DsWriteAccountSpn(struct torture_context *tctx, + struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; @@ -191,8 +251,6 @@ static bool test_DsWriteAccountSpn(struct dcerpc_pipe *p, r.in.bind_handle = &priv->bind_handle; r.in.level = 1; - torture_comment(tctx, "testing DsWriteAccountSpn\n"); - r.in.req.req1.operation = DRSUAPI_DS_SPN_OPERATION_ADD; r.in.req.req1.unknown1 = 0; r.in.req.req1.object_dn = priv->dcinfo.computer_dn; @@ -217,8 +275,8 @@ static bool test_DsWriteAccountSpn(struct dcerpc_pipe *p, return true; } -static bool test_DsReplicaGetInfo(struct dcerpc_pipe *p, - struct torture_context *tctx, +static bool test_DsReplicaGetInfo(struct torture_context *tctx, + struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; @@ -331,8 +389,8 @@ static bool test_DsReplicaGetInfo(struct dcerpc_pipe *p, return true; } -static bool test_DsReplicaSync(struct dcerpc_pipe *p, - struct torture_context *tctx, +static bool test_DsReplicaSync(struct torture_context *tctx, + struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; @@ -349,9 +407,6 @@ static bool test_DsReplicaSync(struct dcerpc_pipe *p, } }; - if (torture_setting_bool(tctx, "dangerous", false)) - torture_skip(tctx, "DsReplicaSync disabled - enable dangerous tests to use"); - ZERO_STRUCT(null_guid); ZERO_STRUCT(null_sid); @@ -385,8 +440,8 @@ static bool test_DsReplicaSync(struct dcerpc_pipe *p, return true; } -static bool test_DsReplicaUpdateRefs(struct dcerpc_pipe *p, - struct torture_context *tctx, +static bool test_DsReplicaUpdateRefs(struct torture_context *tctx, + struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; @@ -403,18 +458,13 @@ static bool test_DsReplicaUpdateRefs(struct dcerpc_pipe *p, } }; - if (lp_parm_bool(-1, "torture", "samba4", False)) { - printf("skipping DsReplicaUpdateRefs test against Samba4\n"); - return True; - } - ZERO_STRUCT(null_guid); ZERO_STRUCT(null_sid); r.in.bind_handle = &priv->bind_handle; for (i=0; i < ARRAY_SIZE(array); i++) { - printf("testing DsReplicaUpdateRefs level %d\n", + torture_comment(tctx, "testing DsReplicaUpdateRefs level %d\n", array[i].level); r.in.level = array[i].level; @@ -442,8 +492,8 @@ static bool test_DsReplicaUpdateRefs(struct dcerpc_pipe *p, return true; } -static bool test_DsGetNCChanges(struct dcerpc_pipe *p, - struct torture_context *tctx, +static bool test_DsGetNCChanges(struct torture_context *tctx, + struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; @@ -487,7 +537,7 @@ static bool test_DsGetNCChanges(struct dcerpc_pipe *p, r.in.req.req5.highwatermark.highest_usn = 0; r.in.req.req5.uptodateness_vector = NULL; r.in.req.req5.replica_flags = 0; - if (lp_parm_bool(-1, "drsuapi", "compression", False)) { + if (lp_parm_bool(-1, "drsuapi", "compression", false)) { r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES; } r.in.req.req5.max_object_count = 0; @@ -542,7 +592,7 @@ static bool test_DsGetNCChanges(struct dcerpc_pipe *p, return true; } -bool test_QuerySitesByCost(struct dcerpc_pipe *p, struct torture_context *tctx, +bool test_QuerySitesByCost(struct torture_context *tctx, struct dcerpc_pipe *p, struct DsPrivate *priv) { NTSTATUS status; @@ -565,8 +615,10 @@ bool test_QuerySitesByCost(struct dcerpc_pipe *p, struct torture_context *tctx, torture_assert_ntstatus_ok(tctx, status, "drsuapi_QuerySitesByCost"); torture_assert_werr_ok(tctx, r.out.result, "QuerySitesByCost failed"); - torture_assert_werr_equal(tctx, r.out.ctr.ctr1.info[0].error_code, WERR_DS_OBJ_NOT_FOUND, "expected not found error"); - torture_assert_werr_equal(tctx, r.out.ctr.ctr1.info[1].error_code, WERR_DS_OBJ_NOT_FOUND, "expected not found error"); + torture_assert_werr_equal(tctx, r.out.ctr.ctr1.info[0].error_code, + WERR_DS_OBJ_NOT_FOUND, "expected not found error"); + torture_assert_werr_equal(tctx, r.out.ctr.ctr1.info[1].error_code, + WERR_DS_OBJ_NOT_FOUND, "expected not found error"); torture_assert_int_equal(tctx, r.out.ctr.ctr1.info[0].site_cost, (uint32_t) -1, "unexpected site cost"); @@ -577,113 +629,35 @@ bool test_QuerySitesByCost(struct dcerpc_pipe *p, struct torture_context *tctx, return true; } -bool test_DsUnbind(struct dcerpc_pipe *p, struct torture_context *tctx, - struct DsPrivate *priv) -{ - NTSTATUS status; - struct drsuapi_DsUnbind r; - - r.in.bind_handle = &priv->bind_handle; - r.out.bind_handle = &priv->bind_handle; - - torture_comment(tctx, "testing DsUnbind\n"); - - status = dcerpc_drsuapi_DsUnbind(p, tctx, &r); - torture_assert_ntstatus_ok(tctx, status, - "dcerpc_drsuapi_DsUnbind failed"); - torture_assert_werr_ok(tctx, r.out.result, "DsBind failed"); - - return true; -} - -bool torture_rpc_drsuapi(struct torture_context *torture) +struct torture_suite *torture_rpc_drsuapi(TALLOC_CTX *mem_ctx) { - NTSTATUS status; - struct dcerpc_pipe *p; - bool ret = true; - struct DsPrivate priv; - struct cli_credentials *machine_credentials; - - ZERO_STRUCT(priv); - - priv.join = torture_join_domain(TEST_MACHINE_NAME, ACB_SVRTRUST, - &machine_credentials); - if (!priv.join) { - torture_fail(torture, "Failed to join as BDC"); - } - - status = torture_rpc_connection(torture, - &p, - &ndr_table_drsuapi); - if (!NT_STATUS_IS_OK(status)) { - torture_leave_domain(priv.join); - torture_fail(torture, "Unable to connect to DRSUAPI pipe"); - } - - ret &= test_DsBind(p, torture, &priv); -#if 0 - ret &= test_QuerySitesByCost(p, torture, &priv); -#endif - ret &= test_DsGetDomainControllerInfo(p, torture, &priv); - - ret &= test_DsCrackNames(p, torture, &priv); - - ret &= test_DsWriteAccountSpn(p, torture, &priv); - - ret &= test_DsReplicaGetInfo(p, torture, &priv); - - ret &= test_DsReplicaSync(p, torture, &priv); - - ret &= test_DsReplicaUpdateRefs(p, torture, &priv); - - ret &= test_DsGetNCChanges(p, torture, &priv); - - ret &= test_DsUnbind(p, torture, &priv); - - torture_leave_domain(priv.join); - - return ret; + struct torture_suite *suite = torture_suite_create(mem_ctx, "DRSUAPI"); + struct torture_test *test; + struct torture_rpc_tcase *tcase = torture_suite_add_machine_rpc_iface_tcase(suite, "drsuapi", + &ndr_table_drsuapi, TEST_MACHINE_NAME); + + torture_rpc_tcase_add_drsuapi_test(tcase, "QuerySitesByCost", test_QuerySitesByCost); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsGetDomainControllerInfo", test_DsGetDomainControllerInfo); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsCrackNames", test_DsCrackNames); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsWriteAccountSpn", test_DsWriteAccountSpn); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsReplicaGetInfo", test_DsReplicaGetInfo); + test = torture_rpc_tcase_add_drsuapi_test(tcase, "DsReplicaSync", test_DsReplicaSync); + test->dangerous = true; + torture_rpc_tcase_add_drsuapi_test(tcase, "DsReplicaUpdateRefs", test_DsReplicaUpdateRefs); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsGetNCChange", test_DsGetNCChanges); + + return suite; } -bool torture_rpc_drsuapi_cracknames(struct torture_context *torture) +struct torture_suite *torture_rpc_drsuapi_cracknames(TALLOC_CTX *mem_ctx) { - NTSTATUS status; - struct dcerpc_pipe *p; - bool ret = true; - struct DsPrivate priv; - struct cli_credentials *machine_credentials; - - torture_comment(torture, "Connected to DRSUAPI pipe\n"); + struct torture_suite *suite = torture_suite_create(mem_ctx, "CRACKNAMES"); + struct torture_rpc_tcase *tcase = torture_suite_add_machine_rpc_iface_tcase(suite, "drsuapi", + &ndr_table_drsuapi, TEST_MACHINE_NAME); - ZERO_STRUCT(priv); - - priv.join = torture_join_domain(TEST_MACHINE_NAME, ACB_SVRTRUST, - &machine_credentials); - if (!priv.join) { - torture_fail(torture, "Failed to join as BDC\n"); - } - - status = torture_rpc_connection(torture, - &p, - &ndr_table_drsuapi); - if (!NT_STATUS_IS_OK(status)) { - torture_leave_domain(priv.join); - torture_fail(torture, "Unable to connect to DRSUAPI pipe"); - } - - ret &= test_DsBind(p, torture, &priv); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsGetDomainControllerInfo", test_DsGetDomainControllerInfo); + torture_rpc_tcase_add_drsuapi_test(tcase, "DsCrackNames", test_DsCrackNames); - if (ret) { - /* We don't care if this fails, we just need some info from it */ - test_DsGetDomainControllerInfo(p, torture, &priv); - - ret &= test_DsCrackNames(p, torture, &priv); - - ret &= test_DsUnbind(p, torture, &priv); - } - - torture_leave_domain(priv.join); - - return ret; + return suite; } -- cgit