r14720: Add torture_context argument to all torture tests
[samba.git] / source4 / torture / rpc / oxidresolve.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for oxidresolve operations
4
5    Copyright (C) Jelmer Vernooij 2004
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_oxidresolver_c.h"
25 #include "librpc/gen_ndr/ndr_remact_c.h"
26 #include "librpc/gen_ndr/epmapper.h"
27 #include "torture/rpc/rpc.h"
28 #include "librpc/gen_ndr/ndr_dcom.h"
29
30 #define CLSID_IMAGEDOC "02B01C80-E03D-101A-B294-00DD010F2BF9"
31
32 static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t *oxid, struct GUID *oid)
33 {
34         struct RemoteActivation r;
35         NTSTATUS status;
36         struct GUID iids[2];
37         uint16_t protseq[3] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_UUID };
38
39         ZERO_STRUCT(r.in);
40         r.in.this.version.MajorVersion = 5;
41         r.in.this.version.MinorVersion = 1;
42         r.in.this.cid = GUID_random();
43         GUID_from_string(CLSID_IMAGEDOC, &r.in.Clsid);
44         r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
45         r.in.num_protseqs = 3;
46         r.in.protseq = protseq;
47         r.in.Interfaces = 1;
48         iids[0] = dcerpc_table_IUnknown.uuid;
49         r.in.pIIDs = iids;
50
51         status = dcerpc_RemoteActivation(p, mem_ctx, &r);
52         if(NT_STATUS_IS_ERR(status)) {
53                 fprintf(stderr, "RemoteActivation: %s\n", nt_errstr(status));
54                 return 0;
55         }
56
57         if(!W_ERROR_IS_OK(r.out.result)) {
58                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.result));
59                 return 0;
60         }
61
62         if(!W_ERROR_IS_OK(r.out.hr)) {
63                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.hr));
64                 return 0;
65         }
66
67         if(!W_ERROR_IS_OK(r.out.results[0])) {
68                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.results[0]));
69                 return 0;
70         }
71
72         *oid = r.out.ipidRemUnknown;
73         *oxid = r.out.pOxid;
74
75         return 1;
76 }
77
78 static int test_SimplePing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t setid)
79 {
80         struct SimplePing r;
81         NTSTATUS status;
82
83         r.in.SetId = &setid;
84
85         status = dcerpc_SimplePing(p, mem_ctx, &r);
86         if(NT_STATUS_IS_ERR(status)) {
87                 fprintf(stderr, "SimplePing: %s\n", nt_errstr(status));
88                 return 0;
89         }
90
91         if(!W_ERROR_IS_OK(r.out.result)) {
92                 fprintf(stderr, "SimplePing: %s\n", win_errstr(r.out.result));
93                 return 0;
94         }
95
96         return 1;
97 }
98
99 static int test_ComplexPing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t *setid, struct GUID oid)
100 {
101         struct ComplexPing r;
102         NTSTATUS status;
103
104         *setid = 0;
105         ZERO_STRUCT(r.in);
106
107         r.in.SequenceNum = 0;
108         r.in.SetId = setid;
109         r.in.cAddToSet = 1;
110         r.in.AddToSet = &oid;
111
112         status = dcerpc_ComplexPing(p, mem_ctx, &r);
113         if(NT_STATUS_IS_ERR(status)) {
114                 fprintf(stderr, "ComplexPing: %s\n", nt_errstr(status));
115                 return 0;
116         }
117
118         if(!W_ERROR_IS_OK(r.out.result)) {
119                 fprintf(stderr, "ComplexPing: %s\n", win_errstr(r.out.result));
120                 return 0;
121         }
122
123         
124
125         return 1;
126 }
127
128 static int test_ServerAlive(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
129 {
130         struct ServerAlive r;
131         NTSTATUS status;
132
133         status = dcerpc_ServerAlive(p, mem_ctx, &r);
134         if(NT_STATUS_IS_ERR(status)) {
135                 fprintf(stderr, "ServerAlive: %s\n", nt_errstr(status));
136                 return 0;
137         }
138
139         if(!W_ERROR_IS_OK(r.out.result)) {
140                 fprintf(stderr, "ServerAlive: %s\n", win_errstr(r.out.result));
141                 return 0;
142         }
143
144         return 1;
145 }
146
147 static int test_ResolveOxid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t oxid)
148 {
149         struct ResolveOxid r;
150         NTSTATUS status;
151         uint16_t protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };   
152
153         r.in.pOxid = oxid;
154         r.in.cRequestedProtseqs = 2;
155         r.in.arRequestedProtseqs = protseq;
156
157         status = dcerpc_ResolveOxid(p, mem_ctx, &r);
158         if(NT_STATUS_IS_ERR(status)) {
159                 fprintf(stderr, "ResolveOxid: %s\n", nt_errstr(status));
160                 return 0;
161         }
162
163         if(!W_ERROR_IS_OK(r.out.result)) {
164                 fprintf(stderr, "ResolveOxid: %s\n", win_errstr(r.out.result));
165                 return 0;
166         }
167
168         return 1;
169 }
170
171 static int test_ResolveOxid2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t oxid)
172 {
173         struct ResolveOxid2 r;
174         NTSTATUS status;
175         uint16_t protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };   
176
177         r.in.pOxid = oxid;
178         r.in.cRequestedProtseqs = 2;
179         r.in.arRequestedProtseqs = protseq;
180
181         status = dcerpc_ResolveOxid2(p, mem_ctx, &r);
182         if(NT_STATUS_IS_ERR(status)) {
183                 fprintf(stderr, "ResolveOxid2: %s\n", nt_errstr(status));
184                 return 0;
185         }
186
187         if(!W_ERROR_IS_OK(r.out.result)) {
188                 fprintf(stderr, "ResolveOxid2: %s\n", win_errstr(r.out.result));
189                 return 0;
190         }
191         
192         printf("Remote server versions: %d, %d\n", r.out.ComVersion.MajorVersion, r.out.ComVersion.MinorVersion);
193
194         return 1;
195 }
196
197
198
199 static int test_ServerAlive2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
200 {
201         struct ServerAlive2 r;
202         NTSTATUS status;
203
204         status = dcerpc_ServerAlive2(p, mem_ctx, &r);
205         if(NT_STATUS_IS_ERR(status)) {
206                 fprintf(stderr, "ServerAlive2: %s\n", nt_errstr(status));
207                 return 0;
208         }
209
210         if(!W_ERROR_IS_OK(r.out.result)) {
211                 fprintf(stderr, "ServerAlive2: %s\n", win_errstr(r.out.result));
212                 return 0;
213         }
214
215         return 1;
216 }
217
218 BOOL torture_rpc_oxidresolve(struct torture_context *torture)
219 {
220         NTSTATUS status;
221        struct dcerpc_pipe *p, *premact;
222         TALLOC_CTX *mem_ctx;
223         BOOL ret = True;
224         uint64_t setid;
225         uint64_t oxid;
226         struct GUID oid;
227
228         mem_ctx = talloc_init("torture_rpc_oxidresolve");
229
230         status = torture_rpc_connection(mem_ctx, 
231                                         &premact, 
232                                         &dcerpc_table_IRemoteActivation);
233                         
234         if (!NT_STATUS_IS_OK(status)) {
235                 talloc_free(mem_ctx);
236                 return False;
237         }
238
239         status = torture_rpc_connection(mem_ctx, 
240                                         &p, 
241                                         &dcerpc_table_IOXIDResolver);
242
243         if (!NT_STATUS_IS_OK(status)) {
244                 talloc_free(mem_ctx);
245                 return False;
246         }
247
248         if(!test_ServerAlive(p, mem_ctx))
249                 ret = False;
250
251         if(!test_ServerAlive2(p, mem_ctx))
252                 ret = False;
253
254         if(!test_RemoteActivation(premact, mem_ctx, &oxid, &oid))
255                 return False;
256
257         if(!test_ComplexPing(p, mem_ctx, &setid, oid))
258                 ret = False;
259
260         if(!test_SimplePing(p, mem_ctx, setid))
261                 ret = False;
262
263         if(!test_ResolveOxid(p, mem_ctx, oxid))
264                 ret = False;
265
266         if(!test_ResolveOxid2(p, mem_ctx, oxid))
267                 ret = False;
268
269         talloc_free(mem_ctx);
270
271         return ret;
272 }