s4-torture: fix ResolveOxid test, filling in missing ref,out pointers.
[obnox/samba/samba-obnox.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 "librpc/gen_ndr/ndr_oxidresolver_c.h"
23 #include "librpc/gen_ndr/ndr_remact_c.h"
24 #include "librpc/gen_ndr/epmapper.h"
25 #include "torture/rpc/torture_rpc.h"
26
27 #define CLSID_IMAGEDOC "02B01C80-E03D-101A-B294-00DD010F2BF9"
28
29 const struct GUID IUnknown_uuid = {
30         0x00000000,0x0000,0x0000,{0xc0,0x00},{0x00,0x00,0x00,0x00,0x00,0x46}
31 };
32
33 static bool test_RemoteActivation(struct torture_context *tctx,
34                                  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         struct dcerpc_pipe *p;
41         struct dcerpc_binding_handle *b;
42         struct ORPCTHAT that;
43         struct DUALSTRINGARRAY *pdsaOxidBindings;
44         uint32_t AuthnHint;
45         struct COMVERSION ServerVersion;
46         HRESULT hr;
47         struct MInterfacePointer *ifaces;
48
49         status = torture_rpc_connection(tctx, &p,
50                                         &ndr_table_IRemoteActivation);
51
52         if (!NT_STATUS_IS_OK(status)) {
53                 return false;
54         }
55         b = p->binding_handle;
56
57         ZERO_STRUCT(r);
58
59         r.in.this_object.version.MajorVersion = 5;
60         r.in.this_object.version.MinorVersion = 1;
61         r.in.this_object.cid = GUID_random();
62         GUID_from_string(CLSID_IMAGEDOC, &r.in.Clsid);
63         r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
64         r.in.num_protseqs = 3;
65         r.in.protseq = protseq;
66         r.in.Interfaces = 1;
67         iids[0] = IUnknown_uuid;
68         r.in.pIIDs = iids;
69
70         r.out.that = &that;
71         r.out.pOxid = oxid;
72         r.out.pdsaOxidBindings = &pdsaOxidBindings;
73         r.out.ipidRemUnknown = oid;
74         r.out.AuthnHint = &AuthnHint;
75         r.out.ServerVersion = &ServerVersion;
76         r.out.hr = &hr;
77         r.out.ifaces = &ifaces;
78
79         status = dcerpc_RemoteActivation_r(b, tctx, &r);
80         torture_assert_ntstatus_ok(tctx, status, "RemoteActivation failed");
81         torture_assert_werr_ok(tctx, r.out.result, "RemoteActivation failed");
82         torture_assert_hresult_ok(tctx, *r.out.hr, "RemoteActivation failed");
83         torture_assert_hresult_ok(tctx, r.out.results[0], "RemoteActivation failed");
84
85         return true;
86 }
87
88 static bool test_SimplePing(struct torture_context *tctx,
89                            struct dcerpc_pipe *p)
90 {
91         struct SimplePing r;
92         NTSTATUS status;
93         uint64_t setid;
94         struct dcerpc_binding_handle *b = p->binding_handle;
95
96         r.in.SetId = &setid;
97
98         status = dcerpc_SimplePing_r(b, tctx, &r);
99         torture_assert_ntstatus_ok(tctx, status, "SimplePing");
100         torture_assert_werr_ok(tctx, r.out.result, "SimplePing");
101
102         return true;
103 }
104
105 static bool test_ComplexPing(struct torture_context *tctx,
106                              struct dcerpc_pipe *p)
107 {
108         struct ComplexPing r;
109         NTSTATUS status;
110         uint64_t setid;
111         struct GUID oid;
112         uint64_t oxid;
113         struct dcerpc_binding_handle *b = p->binding_handle;
114
115         if (!test_RemoteActivation(tctx, &oxid, &oid))
116                 return false;
117
118         setid = 0;
119         ZERO_STRUCT(r.in);
120
121         r.in.SequenceNum = 0;
122         r.in.SetId = &setid;
123         r.in.cAddToSet = 1;
124         r.in.AddToSet = &oid;
125
126         status = dcerpc_ComplexPing_r(b, tctx, &r);
127         if(NT_STATUS_IS_ERR(status)) {
128                 fprintf(stderr, "ComplexPing: %s\n", nt_errstr(status));
129                 return 0;
130         }
131
132         if(!W_ERROR_IS_OK(r.out.result)) {
133                 fprintf(stderr, "ComplexPing: %s\n", win_errstr(r.out.result));
134                 return 0;
135         }
136
137
138
139         return 1;
140 }
141
142 static bool test_ServerAlive(struct torture_context *tctx,
143                             struct dcerpc_pipe *p)
144 {
145         struct ServerAlive r;
146         NTSTATUS status;
147         struct dcerpc_binding_handle *b = p->binding_handle;
148
149         status = dcerpc_ServerAlive_r(b, tctx, &r);
150         torture_assert_ntstatus_ok(tctx, status, "ServerAlive");
151         torture_assert_werr_ok(tctx, r.out.result, "ServerAlive");
152
153         return true;
154 }
155
156 static bool test_ResolveOxid(struct torture_context *tctx,
157                              struct dcerpc_pipe *p)
158 {
159         struct ResolveOxid r;
160         NTSTATUS status;
161         uint16_t protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };
162         uint64_t oxid;
163         struct GUID oid;
164         struct dcerpc_binding_handle *b = p->binding_handle;
165         struct DUALSTRINGARRAY *ppdsaOxidBindings;
166         struct GUID pipidRemUnknown;
167         uint32_t pAuthnHint;
168
169         if (!test_RemoteActivation(tctx, &oxid, &oid))
170                 return false;
171
172         r.in.pOxid = oxid;
173         r.in.cRequestedProtseqs = 2;
174         r.in.arRequestedProtseqs = protseq;
175         r.out.ppdsaOxidBindings = &ppdsaOxidBindings;
176         r.out.pipidRemUnknown = &pipidRemUnknown;
177         r.out.pAuthnHint = &pAuthnHint;
178
179         status = dcerpc_ResolveOxid_r(b, tctx, &r);
180         torture_assert_ntstatus_ok(tctx, status, "ResolveOxid");
181         torture_assert_werr_ok(tctx, r.out.result, "ResolveOxid");
182
183         return true;
184 }
185
186 static bool test_ResolveOxid2(struct torture_context *tctx,
187                               struct dcerpc_pipe *p)
188 {
189         struct ResolveOxid2 r;
190         NTSTATUS status;
191         uint16_t protseq[2] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_SMB };
192         uint64_t oxid;
193         struct GUID oid;
194         struct dcerpc_binding_handle *b = p->binding_handle;
195
196         if (!test_RemoteActivation(tctx, &oxid, &oid))
197                 return false;
198
199         r.in.pOxid = oxid;
200         r.in.cRequestedProtseqs = 2;
201         r.in.arRequestedProtseqs = protseq;
202
203         status = dcerpc_ResolveOxid2_r(b, tctx, &r);
204         torture_assert_ntstatus_ok(tctx, status, "ResolveOxid2");
205
206         torture_assert_werr_ok(tctx, r.out.result, "ResolveOxid2");
207
208         torture_comment(tctx, "Remote server versions: %d, %d\n", r.out.ComVersion->MajorVersion, r.out.ComVersion->MinorVersion);
209
210         return true;
211 }
212
213 static bool test_ServerAlive2(struct torture_context *tctx,
214                              struct dcerpc_pipe *p)
215 {
216         struct ServerAlive2 r;
217         NTSTATUS status;
218         struct dcerpc_binding_handle *b = p->binding_handle;
219         struct COMINFO info;
220         struct DUALSTRINGARRAY *dualstring;
221         uint8_t pReserved;
222
223         r.out.info = &info;
224         r.out.dualstring = &dualstring;
225         r.out.pReserved = &pReserved;
226
227         status = dcerpc_ServerAlive2_r(b, tctx, &r);
228         torture_assert_ntstatus_ok(tctx, status, "ServerAlive2");
229         torture_assert_werr_ok(tctx, r.out.result, "ServerAlive2");
230
231         return true;
232 }
233
234 struct torture_suite *torture_rpc_oxidresolve(TALLOC_CTX *mem_ctx)
235 {
236         struct torture_suite *suite = torture_suite_create(mem_ctx, "oxidresolve");
237         struct torture_rpc_tcase *tcase;
238
239         tcase = torture_suite_add_rpc_iface_tcase(suite, "oxidresolver",
240                                           &ndr_table_IOXIDResolver);
241
242         torture_rpc_tcase_add_test(tcase, "ServerAlive", test_ServerAlive);
243
244         torture_rpc_tcase_add_test(tcase, "ServerAlive2", test_ServerAlive2);
245
246         torture_rpc_tcase_add_test(tcase, "ComplexPing", test_ComplexPing);
247
248         torture_rpc_tcase_add_test(tcase, "SimplePing", test_SimplePing);
249
250         torture_rpc_tcase_add_test(tcase, "ResolveOxid", test_ResolveOxid);
251
252         torture_rpc_tcase_add_test(tcase, "ResolveOxid2", test_ResolveOxid2);
253
254         return suite;
255 }