a85a8504721894678c274b02912387b29cd1988e
[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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_lsa.h"
25 #include "librpc/gen_ndr/ndr_dssetup.h"
26
27
28 BOOL torture_rpc_alter_context(void)
29 {
30         NTSTATUS status;
31         struct dcerpc_pipe *p, *p2;
32         TALLOC_CTX *mem_ctx;
33         BOOL ret = True;
34         struct policy_handle *handle;
35         struct dcerpc_interface_table tmptbl;
36         struct dcerpc_syntax_id syntax;
37         struct dcerpc_syntax_id transfer_syntax;
38
39         mem_ctx = talloc_init("torture_rpc_alter_context");
40
41         printf("opening LSA connection\n");
42         status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
43         if (!NT_STATUS_IS_OK(status)) {
44                 talloc_free(mem_ctx);
45                 return False;
46         }
47
48         if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
49                 ret = False;
50         }
51
52         printf("Opening secondary DSSETUP context\n");
53         status = dcerpc_secondary_context(p, &p2, &dcerpc_table_dssetup);
54         if (!NT_STATUS_IS_OK(status)) {
55                 talloc_free(mem_ctx);
56                 printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
57                 return False;
58         }
59
60         tmptbl = dcerpc_table_dssetup;
61         tmptbl.if_version += 100;
62         printf("Opening bad secondary connection\n");
63         status = dcerpc_secondary_context(p, &p2, &tmptbl);
64         if (NT_STATUS_IS_OK(status)) {
65                 talloc_free(mem_ctx);
66                 printf("dcerpc_alter_context with wrong version should fail\n");
67                 return False;
68         }
69
70         printf("testing DSSETUP pipe operations\n");
71         ret &= test_DsRoleGetPrimaryDomainInformation(p2, mem_ctx);
72
73         if (handle) {
74                 if (!test_lsa_Close(p, mem_ctx, handle)) {
75                         ret = False;
76                 }
77         }
78
79         syntax = p->syntax;
80         transfer_syntax = p->transfer_syntax;
81
82         printf("Testing change of primary context\n");
83         status = dcerpc_alter_context(p, mem_ctx, &p2->syntax, &p2->transfer_syntax);
84         if (!NT_STATUS_IS_OK(status)) {
85                 talloc_free(mem_ctx);
86                 printf("dcerpc_alter_context failed - %s\n", nt_errstr(status));
87                 return False;
88         }
89
90         printf("testing DSSETUP pipe operations - should fault\n");
91         if (test_DsRoleGetPrimaryDomainInformation(p, mem_ctx)) {
92                 ret = False;
93         }
94
95         if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
96                 ret = False;
97         }
98
99         if (handle) {
100                 if (!test_lsa_Close(p, mem_ctx, handle)) {
101                         ret = False;
102                 }
103         }
104
105         printf("testing DSSETUP pipe operations\n");
106         ret &= test_DsRoleGetPrimaryDomainInformation(p2, mem_ctx);
107
108         talloc_free(mem_ctx);
109
110         return ret;
111 }