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