ctdb-scripts: Support storing statd-callout state in cluster filesystem
[samba4-gss.git] / source4 / torture / rpc / alter_context.c
blobef2e3efc3348ff5a67f66f40c64424dfd91c4aa8
1 /*
2 Unix SMB/CIFS implementation.
4 test suite for dcerpc alter_context operations
6 Copyright (C) Andrew Tridgell 2005
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 "librpc/gen_ndr/ndr_lsa.h"
24 #include "librpc/gen_ndr/ndr_dssetup.h"
25 #include "torture/rpc/torture_rpc.h"
27 bool torture_rpc_alter_context(struct torture_context *torture)
29 NTSTATUS status;
30 struct dcerpc_pipe *p, *p2, *p3;
31 struct policy_handle *handle;
32 struct ndr_interface_table tmptbl;
33 const struct dcerpc_binding *bd = NULL;
34 const struct dcerpc_binding *bd2 = NULL;
35 struct ndr_syntax_id syntax = { .if_version = 0, };
36 struct ndr_syntax_id syntax2 = { .if_version = 0, };
37 const struct ndr_syntax_id *transfer_syntax = NULL;
38 const struct ndr_syntax_id *transfer_syntax2 = NULL;
39 uint32_t flags = 0;
40 uint32_t flags2 = 0;
41 bool ret = true;
43 torture_comment(torture, "opening LSA connection\n");
44 status = torture_rpc_connection(torture, &p, &ndr_table_lsarpc);
45 torture_assert_ntstatus_ok(torture, status, "connecting");
47 bd = dcerpc_binding_handle_get_binding(p->binding_handle);
48 syntax = dcerpc_binding_get_abstract_syntax(bd);
49 flags = dcerpc_binding_get_flags(bd);
50 if (flags & DCERPC_NDR64) {
51 transfer_syntax = &ndr_transfer_syntax_ndr64;
52 } else {
53 transfer_syntax = &ndr_transfer_syntax_ndr;
56 torture_comment(torture, "Testing change of primary context\n");
57 status = dcerpc_alter_context(p, torture, &syntax, transfer_syntax);
58 torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
60 if (!test_lsa_OpenPolicy2(p->binding_handle, torture, &handle)) {
61 ret = false;
64 torture_comment(torture, "Testing change of primary context\n");
65 status = dcerpc_alter_context(p, torture, &syntax, transfer_syntax);
66 torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
68 torture_comment(torture, "Opening secondary DSSETUP context\n");
69 status = dcerpc_secondary_context(p, &p2, &ndr_table_dssetup);
70 torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
72 bd2 = dcerpc_binding_handle_get_binding(p2->binding_handle);
73 syntax2 = dcerpc_binding_get_abstract_syntax(bd2);
74 flags2 = dcerpc_binding_get_flags(bd2);
75 if (flags2 & DCERPC_NDR64) {
76 transfer_syntax2 = &ndr_transfer_syntax_ndr64;
77 } else {
78 transfer_syntax2 = &ndr_transfer_syntax_ndr;
81 torture_comment(torture, "Testing change of primary context\n");
82 status = dcerpc_alter_context(p2, torture, &syntax2, transfer_syntax2);
83 torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
85 tmptbl = ndr_table_dssetup;
86 tmptbl.syntax_id.if_version += 100;
87 torture_comment(torture, "Opening bad secondary connection\n");
88 status = dcerpc_secondary_context(p, &p3, &tmptbl);
89 torture_assert_ntstatus_equal(torture, status, NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX,
90 "dcerpc_alter_context with wrong version should fail");
92 torture_comment(torture, "Testing DSSETUP pipe operations\n");
93 ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
95 if (handle) {
96 ret &= test_lsa_Close(p->binding_handle, torture, handle);
99 torture_comment(torture, "Testing change of primary context\n");
100 status = dcerpc_alter_context(p, torture, &syntax, transfer_syntax);
101 torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
103 ret &= test_lsa_OpenPolicy2(p->binding_handle, torture, &handle);
105 if (handle) {
106 ret &= test_lsa_Close(p->binding_handle, torture, handle);
109 torture_comment(torture, "Testing change of primary context\n");
110 status = dcerpc_alter_context(p, torture, &syntax2, transfer_syntax2);
111 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTOCOL_ERROR)) {
113 ret &= test_lsa_OpenPolicy2_ex(p->binding_handle, torture, &handle,
114 NT_STATUS_CONNECTION_DISCONNECTED,
115 NT_STATUS_CONNECTION_RESET);
117 torture_assert(torture, !dcerpc_binding_handle_is_connected(p->binding_handle),
118 "dcerpc disconnected");
120 return ret;
122 torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
124 torture_comment(torture, "Testing DSSETUP pipe operations - should fault\n");
125 ret &= test_DsRoleGetPrimaryDomainInformation_ext(torture, p, NT_STATUS_RPC_BAD_STUB_DATA);
127 ret &= test_lsa_OpenPolicy2(p->binding_handle, torture, &handle);
129 if (handle) {
130 ret &= test_lsa_Close(p->binding_handle, torture, handle);
133 torture_comment(torture, "Testing DSSETUP pipe operations\n");
135 ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
137 return ret;