r23792: convert Samba4 to GPLv3
[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;
33         TALLOC_CTX *mem_ctx;
34         BOOL ret = True;
35         struct policy_handle *handle;
36         struct dcerpc_interface_table tmptbl;
37         struct dcerpc_syntax_id syntax;
38         struct dcerpc_syntax_id transfer_syntax;
39
40         mem_ctx = talloc_init("torture_rpc_alter_context");
41
42         printf("opening LSA connection\n");
43         status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
44         if (!NT_STATUS_IS_OK(status)) {
45                 talloc_free(mem_ctx);
46                 return False;
47         }
48
49         if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
50                 ret = False;
51         }
52
53         printf("Opening secondary DSSETUP context\n");
54         status = dcerpc_secondary_context(p, &p2, &dcerpc_table_dssetup);
55         if (!NT_STATUS_IS_OK(status)) {
56                 talloc_free(mem_ctx);
57                 printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
58                 return False;
59         }
60
61         tmptbl = dcerpc_table_dssetup;
62         tmptbl.syntax_id.if_version += 100;
63         printf("Opening bad secondary connection\n");
64         status = dcerpc_secondary_context(p, &p2, &tmptbl);
65         if (NT_STATUS_IS_OK(status)) {
66                 talloc_free(mem_ctx);
67                 printf("dcerpc_alter_context with wrong version should fail\n");
68                 return False;
69         }
70
71         printf("testing DSSETUP pipe operations\n");
72         ret &= test_DsRoleGetPrimaryDomainInformation(p2, mem_ctx);
73
74         if (handle) {
75                 if (!test_lsa_Close(p, mem_ctx, handle)) {
76                         ret = False;
77                 }
78         }
79
80         syntax = p->syntax;
81         transfer_syntax = p->transfer_syntax;
82
83         printf("Testing change of primary context\n");
84         status = dcerpc_alter_context(p, mem_ctx, &p2->syntax, &p2->transfer_syntax);
85         if (!NT_STATUS_IS_OK(status)) {
86                 talloc_free(mem_ctx);
87                 printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
88                 return False;
89         }
90
91         printf("testing DSSETUP pipe operations - should fault\n");
92         if (test_DsRoleGetPrimaryDomainInformation(p, mem_ctx)) {
93                 ret = False;
94         }
95
96         if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
97                 ret = False;
98         }
99
100         if (handle) {
101                 if (!test_lsa_Close(p, mem_ctx, handle)) {
102                         ret = False;
103                 }
104         }
105
106         printf("testing DSSETUP pipe operations\n");
107         ret &= test_DsRoleGetPrimaryDomainInformation(p2, mem_ctx);
108
109         talloc_free(mem_ctx);
110
111         return ret;
112 }