r24557: rename 'dcerpc_table_' -> 'ndr_table_'
[gd/samba-autobuild/.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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_oxidresolver_c.h"
24 #include "librpc/gen_ndr/ndr_remact_c.h"
25 #include "librpc/gen_ndr/epmapper.h"
26 #include "torture/rpc/rpc.h"
27
28 #define CLSID_IMAGEDOC "02B01C80-E03D-101A-B294-00DD010F2BF9"
29
30 const struct GUID IUnknown_uuid = {
31         0x00000000,0x0000,0x0000,{0xc0,0x00},{0x00,0x00,0x00,0x00,0x00,0x46}
32 };
33
34 static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t *oxid, struct GUID *oid)
35 {
36         struct RemoteActivation r;
37         NTSTATUS status;
38         struct GUID iids[2];
39         uint16_t protseq[3] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_UUID };
40
41         ZERO_STRUCT(r.in);
42         r.in.this.version.MajorVersion = 5;
43         r.in.this.version.MinorVersion = 1;
44         r.in.this.cid = GUID_random();
45         GUID_from_string(CLSID_IMAGEDOC, &r.in.Clsid);
46         r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
47         r.in.num_protseqs = 3;
48         r.in.protseq = protseq;
49         r.in.Interfaces = 1;
50         iids[0] = IUnknown_uuid;
51         r.in.pIIDs = iids;
52         r.out.pOxid = oxid;
53         r.out.ipidRemUnknown = oid;
54
55         status = dcerpc_RemoteActivation(p, mem_ctx, &r);
56         if(NT_STATUS_IS_ERR(status)) {
57                 fprintf(stderr, "RemoteActivation: %s\n", nt_errstr(status));
58                 return 0;
59         }
60
61         if(!W_ERROR_IS_OK(r.out.result)) {
62                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.result));
63                 return 0;
64         }
65
66         if(!W_ERROR_IS_OK(*r.out.hr)) {
67                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(*r.out.hr));
68                 return 0;
69         }
70
71         if(!W_ERROR_IS_OK(r.out.results[0])) {
72                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.results[0]));
73                 return 0;
74         }
75
76
77         return 1;
78 }
79
80 static int test_SimplePing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t setid)
81 {
82         struct SimplePing r;
83         NTSTATUS status;
84
85         r.in.SetId = &setid;
86
87         status = dcerpc_SimplePing(p, mem_ctx, &r);
88         if(NT_STATUS_IS_ERR(status)) {
89                 fprintf(stderr, "SimplePing: %s\n", nt_errstr(status));
90                 return 0;
91         }
92
93         if(!W_ERROR_IS_OK(r.out.result)) {
94                 fprintf(stderr, "SimplePing: %s\n", win_errstr(r.out.result));
95                 return 0;
96         }
97
98         return 1;
99 }
100
101 static int test_ComplexPing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t *setid, struct GUID oid)
102 {
103         struct ComplexPing r;
104         NTSTATUS status;
105
106         *setid = 0;
107         ZERO_STRUCT(r.in);
108
109         r.in.SequenceNum = 0;
110         r.in.SetId = setid;
111         r.in.cAddToSet = 1;
112         r.in.AddToSet = &oid;
113
114         status = dcerpc_ComplexPing(p, mem_ctx, &r);
115         if(NT_STATUS_IS_ERR(status)) {
116                 fprintf(stderr, "ComplexPing: %s\n", nt_errstr(status));
117                 return 0;
118         }
119
120         if(!W_ERROR_IS_OK(r.out.result)) {
121                 fprintf(stderr, "ComplexPing: %s\n", win_errstr(r.out.result));
122                 return 0;
123         }
124
125         
126
127         return 1;
128 }
129
130 static int test_ServerAlive(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
131 {
132         struct ServerAlive r;
133         NTSTATUS status;
134
135         status = dcerpc_ServerAlive(p, mem_ctx, &r);
136         if(NT_STATUS_IS_ERR(status)) {
137                 fprintf(stderr, "ServerAlive: %s\n", nt_errstr(status));
138                 return 0;
139         }
140
141         if(!W_ERROR_IS_OK(r.out.result)) {
142                 fprintf(stderr, "ServerAlive: %s\n", win_errstr(r.out.result));
143                 return 0;
144         }
145
146         return 1;
147 }
148
149 static int test_ResolveOxid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t oxid)
150 {
151         struct ResolveOxid r;
152         NTSTATUS status;
153         uint16_t protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };   
154
155         r.in.pOxid = oxid;
156         r.in.cRequestedProtseqs = 2;
157         r.in.arRequestedProtseqs = protseq;
158
159         status = dcerpc_ResolveOxid(p, mem_ctx, &r);
160         if(NT_STATUS_IS_ERR(status)) {
161                 fprintf(stderr, "ResolveOxid: %s\n", nt_errstr(status));
162                 return 0;
163         }
164
165         if(!W_ERROR_IS_OK(r.out.result)) {
166                 fprintf(stderr, "ResolveOxid: %s\n", win_errstr(r.out.result));
167                 return 0;
168         }
169
170         return 1;
171 }
172
173 static int test_ResolveOxid2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t oxid)
174 {
175         struct ResolveOxid2 r;
176         NTSTATUS status;
177         uint16_t protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };   
178
179         r.in.pOxid = oxid;
180         r.in.cRequestedProtseqs = 2;
181         r.in.arRequestedProtseqs = protseq;
182
183         status = dcerpc_ResolveOxid2(p, mem_ctx, &r);
184         if(NT_STATUS_IS_ERR(status)) {
185                 fprintf(stderr, "ResolveOxid2: %s\n", nt_errstr(status));
186                 return 0;
187         }
188
189         if(!W_ERROR_IS_OK(r.out.result)) {
190                 fprintf(stderr, "ResolveOxid2: %s\n", win_errstr(r.out.result));
191                 return 0;
192         }
193         
194         printf("Remote server versions: %d, %d\n", r.out.ComVersion->MajorVersion, r.out.ComVersion->MinorVersion);
195
196         return 1;
197 }
198
199
200
201 static int test_ServerAlive2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
202 {
203         struct ServerAlive2 r;
204         NTSTATUS status;
205
206         status = dcerpc_ServerAlive2(p, mem_ctx, &r);
207         if(NT_STATUS_IS_ERR(status)) {
208                 fprintf(stderr, "ServerAlive2: %s\n", nt_errstr(status));
209                 return 0;
210         }
211
212         if(!W_ERROR_IS_OK(r.out.result)) {
213                 fprintf(stderr, "ServerAlive2: %s\n", win_errstr(r.out.result));
214                 return 0;
215         }
216
217         return 1;
218 }
219
220 BOOL torture_rpc_oxidresolve(struct torture_context *torture)
221 {
222         NTSTATUS status;
223        struct dcerpc_pipe *p, *premact;
224         TALLOC_CTX *mem_ctx;
225         BOOL ret = True;
226         uint64_t setid;
227         uint64_t oxid;
228         struct GUID oid;
229
230         mem_ctx = talloc_init("torture_rpc_oxidresolve");
231
232         status = torture_rpc_connection(mem_ctx, 
233                                         &premact, 
234                                         &ndr_table_IRemoteActivation);
235                         
236         if (!NT_STATUS_IS_OK(status)) {
237                 talloc_free(mem_ctx);
238                 return False;
239         }
240
241         status = torture_rpc_connection(mem_ctx, 
242                                         &p, 
243                                         &ndr_table_IOXIDResolver);
244
245         if (!NT_STATUS_IS_OK(status)) {
246                 talloc_free(mem_ctx);
247                 return False;
248         }
249
250         if(!test_ServerAlive(p, mem_ctx))
251                 ret = False;
252
253         if(!test_ServerAlive2(p, mem_ctx))
254                 ret = False;
255
256         if(!test_RemoteActivation(premact, mem_ctx, &oxid, &oid))
257                 return False;
258
259         if(!test_ComplexPing(p, mem_ctx, &setid, oid))
260                 ret = False;
261
262         if(!test_SimplePing(p, mem_ctx, setid))
263                 ret = False;
264
265         if(!test_ResolveOxid(p, mem_ctx, oxid))
266                 ret = False;
267
268         if(!test_ResolveOxid2(p, mem_ctx, oxid))
269                 ret = False;
270
271         talloc_free(mem_ctx);
272
273         return ret;
274 }