r24900: - if we use try to create a 3rd dcerpc_pipe then use a 3rd variable
[kai/samba.git] / source4 / torture / rpc / alter_context.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    test suite for dcerpc alter_context operations
5
6    Copyright (C) Andrew Tridgell 2005
7    
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.
12    
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.
17    
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/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa.h"
25 #include "librpc/gen_ndr/ndr_dssetup.h"
26 #include "librpc/rpc/dcerpc.h"
27 #include "torture/rpc/rpc.h"
28
29 bool torture_rpc_alter_context(struct torture_context *torture)
30 {
31         NTSTATUS status;
32         struct dcerpc_pipe *p, *p2, *p3;
33         struct policy_handle *handle;
34         struct ndr_interface_table tmptbl;
35         struct ndr_syntax_id syntax;
36         struct ndr_syntax_id transfer_syntax;
37         bool ret = true;
38
39         torture_comment(torture, "opening LSA connection\n");
40         status = torture_rpc_connection(torture, &p, &ndr_table_lsarpc);
41         torture_assert_ntstatus_ok(torture, status, "connecting");
42
43         if (!test_lsa_OpenPolicy2(p, torture, &handle)) {
44                 ret = false;
45         }
46
47         torture_comment(torture, "Opening secondary DSSETUP context\n");
48         status = dcerpc_secondary_context(p, &p2, &ndr_table_dssetup);
49         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
50
51         tmptbl = ndr_table_dssetup;
52         tmptbl.syntax_id.if_version += 100;
53         torture_comment(torture, "Opening bad secondary connection\n");
54         status = dcerpc_secondary_context(p, &p3, &tmptbl);
55         torture_assert_ntstatus_equal(torture, status, NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX,
56                                       "dcerpc_alter_context with wrong version should fail");
57
58         torture_comment(torture, "testing DSSETUP pipe operations\n");
59         ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
60
61         if (handle) {
62                 ret &= test_lsa_Close(p, torture, handle);
63         }
64
65         syntax = p->syntax;
66         transfer_syntax = p->transfer_syntax;
67
68         torture_comment(torture, "Testing change of primary context\n");
69         status = dcerpc_alter_context(p, torture, &p2->syntax, &p2->transfer_syntax);
70         torture_assert_ntstatus_ok(torture, status, "dcerpc_alter_context failed");
71
72         torture_comment(torture, "testing DSSETUP pipe operations - should fault\n");
73         ret &= test_DsRoleGetPrimaryDomainInformation_ext(torture, p, NT_STATUS_NET_WRITE_FAULT);
74
75         ret &= test_lsa_OpenPolicy2(p, torture, &handle);
76
77         if (handle) {
78                 ret &= test_lsa_Close(p, torture, handle);
79         }
80
81         torture_comment(torture, "testing DSSETUP pipe operations\n");
82
83         ret &= test_DsRoleGetPrimaryDomainInformation(torture, p2);
84
85         return ret;
86 }