r3490: All tests work against NT4 now
[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 "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, HYPER_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         uuid_generate_random(&r.in.this.cid);
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, HYPER_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, HYPER_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.out.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, HYPER_T oxid)
148 {
149         struct ResolveOxid r;
150         NTSTATUS status;
151         uint16 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, HYPER_T oxid)
172 {
173         struct ResolveOxid2 r;
174         NTSTATUS status;
175         uint16 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(void)
219 {
220         NTSTATUS status;
221        struct dcerpc_pipe *p, *premact;
222         TALLOC_CTX *mem_ctx;
223         BOOL ret = True;
224         HYPER_T setid;
225         HYPER_T oxid;
226         struct GUID oid;
227
228         mem_ctx = talloc_init("torture_rpc_oxidresolve");
229
230         status = torture_rpc_connection(&premact, 
231                                         DCERPC_IREMOTEACTIVATION_NAME, 
232                                         DCERPC_IREMOTEACTIVATION_UUID, 
233                                         DCERPC_IREMOTEACTIVATION_VERSION);                                                              
234                         
235         if (!NT_STATUS_IS_OK(status)) {
236                 return False;
237         }
238
239         status = dcerpc_secondary_connection(premact, &p, 
240                                         DCERPC_IOXIDRESOLVER_NAME, 
241                                         DCERPC_IOXIDRESOLVER_UUID, 
242                                         DCERPC_IOXIDRESOLVER_VERSION);
243
244         if(!test_RemoteActivation(premact, mem_ctx, &oxid, &oid))
245                 return False;
246
247         if(!test_ServerAlive(p, mem_ctx))
248                 ret = False;
249
250         if(!test_ComplexPing(p, mem_ctx, &setid, oid))
251                 ret = False;
252
253         if(!test_SimplePing(p, mem_ctx, setid))
254                 ret = False;
255
256         if(!test_ServerAlive2(p, mem_ctx))
257                 ret = False;
258
259         if(!test_ResolveOxid(p, mem_ctx, oxid))
260                 ret = False;
261
262         if(!test_ResolveOxid2(p, mem_ctx, oxid))
263                 ret = False;
264
265         talloc_destroy(mem_ctx);
266
267     torture_rpc_close(p);
268
269         return ret;
270 }