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