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