r5034: - added a type mapping function in pidl, so the type names in our IDL
[kai/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 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 "librpc/gen_ndr/ndr_oxidresolver.h"
24 #include "librpc/gen_ndr/ndr_remact.h"
25 #include "librpc/gen_ndr/ndr_epmapper.h"
26
27 #define CLSID_TEST "00000316-0000-0000-C000-000000000046"
28 #define CLSID_SIMPLE "5e9ddec7-5767-11cf-beab-00aa006c3606"
29 #define CLSID_COFFEEMACHINE "DB7C21F8-FE33-4C11-AEA5-CEB56F076FBB"
30
31 static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t *oxid, struct GUID *oid)
32 {
33         struct RemoteActivation r;
34         NTSTATUS status;
35         struct GUID iids[2];
36         uint16 protseq[3] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_UUID };
37
38         ZERO_STRUCT(r.in);
39         r.in.this.version.MajorVersion = 5;
40         r.in.this.version.MinorVersion = 1;
41         r.in.this.cid = GUID_random();
42         GUID_from_string(CLSID_SIMPLE, &r.in.Clsid);
43         r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
44         r.in.num_protseqs = 3;
45         r.in.protseq = protseq;
46         r.in.Interfaces = 1;
47         GUID_from_string(DCERPC_IUNKNOWN_UUID, &iids[0]);
48         r.in.pIIDs = iids;
49
50         status = dcerpc_RemoteActivation(p, mem_ctx, &r);
51         if(NT_STATUS_IS_ERR(status)) {
52                 fprintf(stderr, "RemoteActivation: %s\n", nt_errstr(status));
53                 return 0;
54         }
55
56         if(!W_ERROR_IS_OK(r.out.result)) {
57                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.result));
58                 return 0;
59         }
60
61         if(!W_ERROR_IS_OK(r.out.hr)) {
62                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.hr));
63                 return 0;
64         }
65
66         if(!W_ERROR_IS_OK(r.out.results[0])) {
67                 fprintf(stderr, "RemoteActivation: %s\n", win_errstr(r.out.results[0]));
68                 return 0;
69         }
70
71         *oid = r.out.ipidRemUnknown;
72         *oxid = r.out.pOxid;
73
74         return 1;
75 }
76
77 static int test_SimplePing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t setid)
78 {
79         struct SimplePing r;
80         NTSTATUS status;
81
82         r.in.SetId = &setid;
83
84         status = dcerpc_SimplePing(p, mem_ctx, &r);
85         if(NT_STATUS_IS_ERR(status)) {
86                 fprintf(stderr, "SimplePing: %s\n", nt_errstr(status));
87                 return 0;
88         }
89
90         if(!W_ERROR_IS_OK(r.out.result)) {
91                 fprintf(stderr, "SimplePing: %s\n", win_errstr(r.out.result));
92                 return 0;
93         }
94
95         return 1;
96 }
97
98 static int test_ComplexPing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t *setid, struct GUID oid)
99 {
100         struct ComplexPing r;
101         NTSTATUS status;
102
103         *setid = 0;
104         ZERO_STRUCT(r.in);
105
106         r.in.SequenceNum = 0;
107         r.in.SetId = setid;
108         r.in.cAddToSet = 1;
109         r.in.AddToSet = &oid;
110
111         status = dcerpc_ComplexPing(p, mem_ctx, &r);
112         if(NT_STATUS_IS_ERR(status)) {
113                 fprintf(stderr, "ComplexPing: %s\n", nt_errstr(status));
114                 return 0;
115         }
116
117         if(!W_ERROR_IS_OK(r.out.result)) {
118                 fprintf(stderr, "ComplexPing: %s\n", win_errstr(r.out.result));
119                 return 0;
120         }
121
122         
123
124         return 1;
125 }
126
127 static int test_ServerAlive(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
128 {
129         struct ServerAlive r;
130         NTSTATUS status;
131
132         status = dcerpc_ServerAlive(p, mem_ctx, &r);
133         if(NT_STATUS_IS_ERR(status)) {
134                 fprintf(stderr, "ServerAlive: %s\n", nt_errstr(status));
135                 return 0;
136         }
137
138         if(!W_ERROR_IS_OK(r.out.result)) {
139                 fprintf(stderr, "ServerAlive: %s\n", win_errstr(r.out.result));
140                 return 0;
141         }
142
143         return 1;
144 }
145
146 static int test_ResolveOxid(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t oxid)
147 {
148         struct ResolveOxid r;
149         NTSTATUS status;
150         uint16 protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };     
151
152         r.in.pOxid = oxid;
153         r.in.cRequestedProtseqs = 2;
154         r.in.arRequestedProtseqs = protseq;
155
156         status = dcerpc_ResolveOxid(p, mem_ctx, &r);
157         if(NT_STATUS_IS_ERR(status)) {
158                 fprintf(stderr, "ResolveOxid: %s\n", nt_errstr(status));
159                 return 0;
160         }
161
162         if(!W_ERROR_IS_OK(r.out.result)) {
163                 fprintf(stderr, "ResolveOxid: %s\n", win_errstr(r.out.result));
164                 return 0;
165         }
166
167         return 1;
168 }
169
170 static int test_ResolveOxid2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint64_t oxid)
171 {
172         struct ResolveOxid2 r;
173         NTSTATUS status;
174         uint16 protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };     
175
176         r.in.pOxid = oxid;
177         r.in.cRequestedProtseqs = 2;
178         r.in.arRequestedProtseqs = protseq;
179
180         status = dcerpc_ResolveOxid2(p, mem_ctx, &r);
181         if(NT_STATUS_IS_ERR(status)) {
182                 fprintf(stderr, "ResolveOxid2: %s\n", nt_errstr(status));
183                 return 0;
184         }
185
186         if(!W_ERROR_IS_OK(r.out.result)) {
187                 fprintf(stderr, "ResolveOxid2: %s\n", win_errstr(r.out.result));
188                 return 0;
189         }
190         
191         printf("Remote server versions: %d, %d\n", r.out.ComVersion.MajorVersion, r.out.ComVersion.MinorVersion);
192
193         return 1;
194 }
195
196
197
198 static int test_ServerAlive2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
199 {
200         struct ServerAlive2 r;
201         NTSTATUS status;
202
203         status = dcerpc_ServerAlive2(p, mem_ctx, &r);
204         if(NT_STATUS_IS_ERR(status)) {
205                 fprintf(stderr, "ServerAlive2: %s\n", nt_errstr(status));
206                 return 0;
207         }
208
209         if(!W_ERROR_IS_OK(r.out.result)) {
210                 fprintf(stderr, "ServerAlive2: %s\n", win_errstr(r.out.result));
211                 return 0;
212         }
213
214         return 1;
215 }
216
217 BOOL torture_rpc_oxidresolve(void)
218 {
219         NTSTATUS status;
220        struct dcerpc_pipe *p, *premact;
221         TALLOC_CTX *mem_ctx;
222         BOOL ret = True;
223         uint64_t setid;
224         uint64_t oxid;
225         struct GUID oid;
226
227         mem_ctx = talloc_init("torture_rpc_oxidresolve");
228
229         status = torture_rpc_connection(&premact, 
230                                         DCERPC_IREMOTEACTIVATION_NAME, 
231                                         DCERPC_IREMOTEACTIVATION_UUID, 
232                                         DCERPC_IREMOTEACTIVATION_VERSION);                                                              
233                         
234         if (!NT_STATUS_IS_OK(status)) {
235                 return False;
236         }
237
238         status = dcerpc_secondary_connection(premact, &p, 
239                                         DCERPC_IOXIDRESOLVER_NAME, 
240                                         DCERPC_IOXIDRESOLVER_UUID, 
241                                         DCERPC_IOXIDRESOLVER_VERSION);
242
243         if(!test_RemoteActivation(premact, mem_ctx, &oxid, &oid))
244                 return False;
245
246         if(!test_ServerAlive(p, mem_ctx))
247                 ret = False;
248
249         if(!test_ComplexPing(p, mem_ctx, &setid, oid))
250                 ret = False;
251
252         if(!test_SimplePing(p, mem_ctx, setid))
253                 ret = False;
254
255         if(!test_ServerAlive2(p, mem_ctx))
256                 ret = False;
257
258         if(!test_ResolveOxid(p, mem_ctx, oxid))
259                 ret = False;
260
261         if(!test_ResolveOxid2(p, mem_ctx, oxid))
262                 ret = False;
263
264         talloc_destroy(mem_ctx);
265
266     torture_rpc_close(p);
267
268         return ret;
269 }