[RPCRT4] Sync with Wine Staging 2.9. CORE-13362
[reactos.git] / rostests / winetests / rpcrt4 / rpc.c
1 /*
2 * Unit test suite for rpc functions
3 *
4 * Copyright 2002 Greg Turner
5 * Copyright 2008-2009 Robert Shearman
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #define COBJMACROS
26 #include <ntstatus.h>
27 #define WIN32_NO_STATUS
28 #include "wine/test.h"
29 #include <windef.h>
30 #include <winbase.h>
31 #include <winnt.h>
32 #include <winerror.h>
33 #include <ole2.h>
34 #include <oleauto.h>
35 #include <ntsecapi.h>
36 #include <initguid.h>
37 #include <netfw.h>
38
39 #include "rpc.h"
40 #include "rpcdce.h"
41 #include "secext.h"
42
43 typedef unsigned int unsigned32;
44 typedef struct twr_t
45 {
46 unsigned32 tower_length;
47 /* [size_is] */ byte tower_octet_string[ 1 ];
48 } twr_t;
49
50 RPC_STATUS WINAPI TowerExplode(const twr_t *tower, RPC_SYNTAX_IDENTIFIER *object, RPC_SYNTAX_IDENTIFIER *syntax, char **protseq, char **endpoint, char **address);
51 RPC_STATUS WINAPI TowerConstruct(const RPC_SYNTAX_IDENTIFIER *object, const RPC_SYNTAX_IDENTIFIER *syntax, const char *protseq, const char *endpoint, const char *address, twr_t **tower);
52
53 static UUID Uuid_Table[10] = {
54 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 0 (null) */
55 { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8a} }, /* 1 */
56 { 0xabadfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 2 */
57 { 0x93da375c, 0x1324, 0x1355, {0x87, 0xff, 0x49, 0x44, 0x34, 0x44, 0x22, 0x19} }, /* 3 */
58 { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8b} }, /* 4 (~1) */
59 { 0x9badfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 5 (~2) */
60 { 0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 6 (~0) */
61 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} }, /* 7 (~0) */
62 { 0x12312312, 0x1231, 0x1231, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff} }, /* 8 */
63 { 0x11111111, 0x1111, 0x1111, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} } /* 9 */
64 };
65
66 /* index of "10" means "NULL" */
67 static BOOL Uuid_Comparison_Grid[11][11] = {
68 { TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE },
69 { FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
70 { FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
71 { FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
72 { FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
73 { FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
74 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE },
75 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE },
76 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE },
77 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE },
78 { TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE }
79 };
80
81 static void UuidConversionAndComparison(void) {
82 CHAR strx[100], x;
83 LPSTR str = strx;
84 WCHAR wstrx[100], wx;
85 LPWSTR wstr = wstrx;
86
87 UUID Uuid1, Uuid2, *PUuid1, *PUuid2;
88 RPC_STATUS rslt;
89
90 int i1,i2;
91
92 /* Uuid Equality */
93 for (i1 = 0; i1 < 11; i1++)
94 for (i2 = 0; i2 < 11; i2++) {
95 if (i1 < 10) {
96 Uuid1 = Uuid_Table[i1];
97 PUuid1 = &Uuid1;
98 } else {
99 PUuid1 = NULL;
100 }
101 if (i2 < 10) {
102 Uuid2 = Uuid_Table[i2];
103 PUuid2 = &Uuid2;
104 } else {
105 PUuid2 = NULL;
106 }
107 ok( (UuidEqual(PUuid1, PUuid2, &rslt) == Uuid_Comparison_Grid[i1][i2]), "UUID Equality\n" );
108 }
109
110 /* Uuid to String to Uuid (char) */
111 for (i1 = 0; i1 < 10; i1++) {
112 Uuid1 = Uuid_Table[i1];
113 ok( (UuidToStringA(&Uuid1, (unsigned char**)&str) == RPC_S_OK), "Simple UUID->String copy\n" );
114 ok( (UuidFromStringA((unsigned char*)str, &Uuid2) == RPC_S_OK), "Simple String->UUID copy from generated UUID String\n" );
115 ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> String -> Uuid transform\n" );
116 /* invalid uuid tests -- size of valid UUID string=36 */
117 for (i2 = 0; i2 < 36; i2++) {
118 x = str[i2];
119 str[i2] = 'g'; /* whatever, but "g" is a good boundary condition */
120 ok( (UuidFromStringA((unsigned char*)str, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID String\n" );
121 str[i2] = x; /* change it back so remaining tests are interesting. */
122 }
123 RpcStringFreeA((unsigned char **)&str);
124 }
125
126 /* Uuid to String to Uuid (wchar) */
127 for (i1 = 0; i1 < 10; i1++) {
128 Uuid1 = Uuid_Table[i1];
129 rslt=UuidToStringW(&Uuid1, &wstr);
130 ok( (rslt == RPC_S_OK), "Simple UUID->WString copy\n" );
131 ok( (UuidFromStringW(wstr, &Uuid2) == RPC_S_OK), "Simple WString->UUID copy from generated UUID String\n" );
132 ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> WString -> Uuid transform\n" );
133 /* invalid uuid tests -- size of valid UUID string=36 */
134 for (i2 = 0; i2 < 36; i2++) {
135 wx = wstr[i2];
136 wstr[i2] = 'g'; /* whatever, but "g" is a good boundary condition */
137 ok( (UuidFromStringW(wstr, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID WString\n" );
138 wstr[i2] = wx; /* change it back so remaining tests are interesting. */
139 }
140 RpcStringFreeW(&wstr);
141 }
142 }
143
144 static void TestDceErrorInqText (void)
145 {
146 char bufferInvalid [1024];
147 char buffer [1024]; /* The required size is not documented but would
148 * appear to be 256.
149 */
150 DWORD dwCount;
151
152 dwCount = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
153 FORMAT_MESSAGE_IGNORE_INSERTS,
154 NULL, RPC_S_NOT_RPC_ERROR, 0, bufferInvalid,
155 sizeof(bufferInvalid)/sizeof(bufferInvalid[0]), NULL);
156
157 /* A random sample of DceErrorInqText */
158 /* 0 is success */
159 ok ((DceErrorInqTextA (0, (unsigned char*)buffer) == RPC_S_OK),
160 "DceErrorInqTextA(0...)\n");
161 /* A real RPC_S error */
162 ok ((DceErrorInqTextA (RPC_S_INVALID_STRING_UUID, (unsigned char*)buffer) == RPC_S_OK),
163 "DceErrorInqTextA(valid...)\n");
164
165 if (dwCount)
166 {
167 /* A message for which FormatMessage should fail
168 * which should return RPC_S_OK and the
169 * fixed "not valid" message
170 */
171 ok ((DceErrorInqTextA (35, (unsigned char*)buffer) == RPC_S_OK &&
172 strcmp (buffer, bufferInvalid) == 0),
173 "DceErrorInqTextA(unformattable...)\n");
174 /* One for which FormatMessage should succeed but
175 * DceErrorInqText should "fail"
176 * 3814 is generally quite a long message
177 */
178 ok ((DceErrorInqTextA (3814, (unsigned char*)buffer) == RPC_S_OK &&
179 strcmp (buffer, bufferInvalid) == 0),
180 "DceErrorInqTextA(deviation...)\n");
181 }
182 else
183 ok (0, "Cannot set up for DceErrorInqText\n");
184 }
185
186 static RPC_DISPATCH_FUNCTION IFoo_table[] =
187 {
188 0
189 };
190
191 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable =
192 {
193 0,
194 IFoo_table
195 };
196
197 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface =
198 {
199 sizeof(RPC_SERVER_INTERFACE),
200 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
201 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
202 &IFoo_v0_0_DispatchTable,
203 0,
204 0,
205 0,
206 0,
207 0,
208 };
209
210 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec = (RPC_IF_HANDLE)& IFoo___RpcServerInterface;
211
212 static void test_rpc_ncacn_ip_tcp(void)
213 {
214 RPC_STATUS status;
215 unsigned char *binding, *principal;
216 handle_t IFoo_IfHandle;
217 ULONG level, authnsvc, authzsvc;
218 RPC_AUTH_IDENTITY_HANDLE identity;
219 static unsigned char foo[] = "foo";
220 static unsigned char ncacn_ip_tcp[] = "ncacn_ip_tcp";
221 static unsigned char address[] = "127.0.0.1";
222 static unsigned char endpoint[] = "4114";
223 static unsigned char spn[] = "principal";
224
225 status = RpcNetworkIsProtseqValidA(foo);
226 ok(status == RPC_S_INVALID_RPC_PROTSEQ, "return wrong\n");
227
228 status = RpcNetworkIsProtseqValidA(ncacn_ip_tcp);
229 ok(status == RPC_S_OK, "return wrong\n");
230
231 status = RpcMgmtStopServerListening(NULL);
232 ok(status == RPC_S_NOT_LISTENING,
233 "wrong RpcMgmtStopServerListening error (%u)\n", status);
234
235 status = RpcMgmtWaitServerListen();
236 ok(status == RPC_S_NOT_LISTENING,
237 "wrong RpcMgmtWaitServerListen error status (%u)\n", status);
238
239 status = RpcServerListen(1, 20, FALSE);
240 ok(status == RPC_S_NO_PROTSEQS_REGISTERED,
241 "wrong RpcServerListen error (%u)\n", status);
242
243 status = RpcServerUseProtseqEpA(ncacn_ip_tcp, 20, endpoint, NULL);
244 ok(status == RPC_S_OK, "RpcServerUseProtseqEp failed (%u)\n", status);
245
246 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
247 ok(status == RPC_S_OK, "RpcServerRegisterIf failed (%u)\n", status);
248
249 status = RpcServerListen(1, 20, TRUE);
250 ok(status == RPC_S_OK, "RpcServerListen failed (%u)\n", status);
251
252 status = RpcServerListen(1, 20, TRUE);
253 todo_wine {
254 ok(status == RPC_S_ALREADY_LISTENING,
255 "wrong RpcServerListen error (%u)\n", status);
256 }
257
258 status = RpcStringBindingComposeA(NULL, ncacn_ip_tcp, address,
259 endpoint, NULL, &binding);
260 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);
261
262 status = RpcBindingFromStringBindingA(binding, &IFoo_IfHandle);
263 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n",
264 status);
265
266 status = RpcBindingSetAuthInfoA(IFoo_IfHandle, NULL, RPC_C_AUTHN_LEVEL_NONE,
267 RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME);
268 ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status);
269
270 status = RpcBindingInqAuthInfoA(IFoo_IfHandle, NULL, NULL, NULL, NULL, NULL);
271 ok(status == RPC_S_BINDING_HAS_NO_AUTH, "RpcBindingInqAuthInfo failed (%u)\n",
272 status);
273
274 status = RpcBindingSetAuthInfoA(IFoo_IfHandle, spn, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
275 RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME);
276 ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status);
277
278 level = authnsvc = authzsvc = 0;
279 principal = (unsigned char *)0xdeadbeef;
280 identity = (RPC_AUTH_IDENTITY_HANDLE *)0xdeadbeef;
281 status = RpcBindingInqAuthInfoA(IFoo_IfHandle, &principal, &level, &authnsvc,
282 &identity, &authzsvc);
283
284 ok(status == RPC_S_OK, "RpcBindingInqAuthInfo failed (%u)\n", status);
285 ok(identity == NULL, "expected NULL identity, got %p\n", identity);
286 ok(principal != (unsigned char *)0xdeadbeef, "expected valid principal, got %p\n", principal);
287 ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "expected RPC_C_AUTHN_LEVEL_PKT_PRIVACY, got %d\n", level);
288 ok(authnsvc == RPC_C_AUTHN_WINNT, "expected RPC_C_AUTHN_WINNT, got %d\n", authnsvc);
289 todo_wine ok(authzsvc == RPC_C_AUTHZ_NAME, "expected RPC_C_AUTHZ_NAME, got %d\n", authzsvc);
290 if (status == RPC_S_OK) RpcStringFreeA(&principal);
291
292 status = RpcMgmtStopServerListening(NULL);
293 ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n",
294 status);
295
296 status = RpcMgmtStopServerListening(NULL);
297 ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n",
298 status);
299
300 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
301 ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%u)\n", status);
302
303 status = RpcMgmtWaitServerListen();
304 todo_wine {
305 ok(status == RPC_S_OK, "RpcMgmtWaitServerListen failed (%u)\n", status);
306 }
307
308 status = RpcStringFreeA(&binding);
309 ok(status == RPC_S_OK, "RpcStringFree failed (%u)\n", status);
310
311 status = RpcBindingFree(&IFoo_IfHandle);
312 ok(status == RPC_S_OK, "RpcBindingFree failed (%u)\n", status);
313 }
314
315 /* this is what's generated with MS/RPC - it includes an extra 2
316 * bytes in the protocol floor */
317 static const unsigned char tower_data_tcp_ip1[] =
318 {
319 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
320 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
321 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
322 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
323 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
324 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
325 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x02,
326 0x00,0x00,0x00,0x01,0x00,0x07,0x02,0x00,
327 0x00,0x87,0x01,0x00,0x09,0x04,0x00,0x0a,
328 0x00,0x00,0x01,
329 };
330 /* this is the optimal data that i think should be generated */
331 static const unsigned char tower_data_tcp_ip2[] =
332 {
333 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
334 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
335 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
336 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
337 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
338 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
339 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x00,
340 0x00,0x01,0x00,0x07,0x02,0x00,0x00,0x87,
341 0x01,0x00,0x09,0x04,0x00,0x0a,0x00,0x00,
342 0x01,
343 };
344
345 static void test_towers(void)
346 {
347 RPC_STATUS ret;
348 twr_t *tower;
349 static const RPC_SYNTAX_IDENTIFIER mapi_if_id = { { 0xa4f1db00, 0xca47, 0x1067, { 0xb3, 0x1f, 0x00, 0xdd, 0x01, 0x06, 0x62, 0xda } }, { 0, 0 } };
350 static const RPC_SYNTAX_IDENTIFIER ndr_syntax = { { 0x8a885d04, 0x1ceb, 0x11c9, { 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60 } }, { 2, 0 } };
351 RPC_SYNTAX_IDENTIFIER object, syntax;
352 char *protseq, *endpoint, *address;
353 BOOL same;
354
355 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_ip_tcp", "135", "10.0.0.1", &tower);
356 ok(ret == RPC_S_OK ||
357 broken(ret == RPC_S_INVALID_RPC_PROTSEQ), /* Vista */
358 "TowerConstruct failed with error %d\n", ret);
359 if (ret == RPC_S_INVALID_RPC_PROTSEQ)
360 {
361 /* Windows Vista fails with this error and crashes if we continue */
362 win_skip("TowerConstruct failed, we are most likely on Windows Vista\n");
363 return;
364 }
365
366 /* first check we have the right amount of data */
367 ok(tower->tower_length == sizeof(tower_data_tcp_ip1) ||
368 tower->tower_length == sizeof(tower_data_tcp_ip2),
369 "Wrong size of tower %d\n", tower->tower_length);
370
371 /* then do a byte-by-byte comparison */
372 same = ((tower->tower_length == sizeof(tower_data_tcp_ip1)) &&
373 !memcmp(&tower->tower_octet_string, tower_data_tcp_ip1, sizeof(tower_data_tcp_ip1))) ||
374 ((tower->tower_length == sizeof(tower_data_tcp_ip2)) &&
375 !memcmp(&tower->tower_octet_string, tower_data_tcp_ip2, sizeof(tower_data_tcp_ip2)));
376
377 ok(same, "Tower data differs\n");
378 if (!same)
379 {
380 unsigned32 i;
381 for (i = 0; i < tower->tower_length; i++)
382 {
383 if (i % 8 == 0) printf(" ");
384 printf("0x%02x,", tower->tower_octet_string[i]);
385 if (i % 8 == 7) printf("\n");
386 }
387 printf("\n");
388 }
389
390 ret = TowerExplode(tower, &object, &syntax, &protseq, &endpoint, &address);
391 ok(ret == RPC_S_OK, "TowerExplode failed with error %d\n", ret);
392 ok(!memcmp(&object, &mapi_if_id, sizeof(mapi_if_id)), "object id didn't match\n");
393 ok(!memcmp(&syntax, &ndr_syntax, sizeof(syntax)), "syntax id didn't match\n");
394 ok(!strcmp(protseq, "ncacn_ip_tcp"), "protseq was \"%s\" instead of \"ncacn_ip_tcp\"\n", protseq);
395 ok(!strcmp(endpoint, "135"), "endpoint was \"%s\" instead of \"135\"\n", endpoint);
396 ok(!strcmp(address, "10.0.0.1"), "address was \"%s\" instead of \"10.0.0.1\"\n", address);
397
398 I_RpcFree(protseq);
399 I_RpcFree(endpoint);
400 I_RpcFree(address);
401
402 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, NULL);
403 ok(ret == RPC_S_OK, "TowerExplode failed with error %d\n", ret);
404
405 I_RpcFree(tower);
406
407 /* test the behaviour for ip_tcp with name instead of dotted IP notation */
408 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_ip_tcp", "135", "localhost", &tower);
409 ok(ret == RPC_S_OK, "TowerConstruct failed with error %d\n", ret);
410 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, &address);
411 ok(ret == RPC_S_OK, "TowerExplode failed with error %d\n", ret);
412 ok(!strcmp(address, "0.0.0.0") ||
413 broken(!strcmp(address, "255.255.255.255")),
414 "address was \"%s\" instead of \"0.0.0.0\"\n", address);
415
416 I_RpcFree(address);
417 I_RpcFree(tower);
418
419 /* test the behaviour for np with no address */
420 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_np", "\\pipe\\test", NULL, &tower);
421 ok(ret == RPC_S_OK, "TowerConstruct failed with error %d\n", ret);
422 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, &address);
423 ok(ret == RPC_S_OK ||
424 broken(ret != RPC_S_OK), /* win2k, indeterminate */
425 "TowerExplode failed with error %d\n", ret);
426 /* Windows XP SP3 sets address to NULL */
427 ok(!address || !strcmp(address, ""), "address was \"%s\" instead of \"\" or NULL (XP SP3)\n", address);
428
429 I_RpcFree(address);
430 I_RpcFree(tower);
431 }
432
433 static void test_I_RpcMapWin32Status(void)
434 {
435 LONG win32status;
436 RPC_STATUS rpc_status;
437 BOOL w2k3_up = FALSE;
438
439 /* Windows 2003 and above return STATUS_UNSUCCESSFUL if given an unknown status */
440 win32status = I_RpcMapWin32Status(9999);
441 if (win32status == STATUS_UNSUCCESSFUL)
442 w2k3_up = TRUE;
443
444 /* On Windows XP-SP1 and below some statuses are not mapped and return
445 * the given status
446 */
447 for (rpc_status = 0; rpc_status < 10000; rpc_status++)
448 {
449 LONG expected_win32status;
450 BOOL missing = FALSE;
451
452 win32status = I_RpcMapWin32Status(rpc_status);
453 switch (rpc_status)
454 {
455 case ERROR_SUCCESS: expected_win32status = ERROR_SUCCESS; break;
456 case ERROR_ACCESS_DENIED: expected_win32status = STATUS_ACCESS_DENIED; break;
457 case ERROR_INVALID_HANDLE: expected_win32status = RPC_NT_SS_CONTEXT_MISMATCH; break;
458 case ERROR_OUTOFMEMORY: expected_win32status = STATUS_NO_MEMORY; break;
459 case ERROR_INVALID_PARAMETER: expected_win32status = STATUS_INVALID_PARAMETER; break;
460 case ERROR_INSUFFICIENT_BUFFER: expected_win32status = STATUS_BUFFER_TOO_SMALL; break;
461 case ERROR_MAX_THRDS_REACHED: expected_win32status = STATUS_NO_MEMORY; break;
462 case ERROR_NOACCESS: expected_win32status = STATUS_ACCESS_VIOLATION; break;
463 case ERROR_NOT_ENOUGH_SERVER_MEMORY: expected_win32status = STATUS_INSUFF_SERVER_RESOURCES; break;
464 case ERROR_WRONG_PASSWORD: expected_win32status = STATUS_WRONG_PASSWORD; missing = TRUE; break;
465 case ERROR_INVALID_LOGON_HOURS: expected_win32status = STATUS_INVALID_LOGON_HOURS; missing = TRUE; break;
466 case ERROR_PASSWORD_EXPIRED: expected_win32status = STATUS_PASSWORD_EXPIRED; missing = TRUE; break;
467 case ERROR_ACCOUNT_DISABLED: expected_win32status = STATUS_ACCOUNT_DISABLED; missing = TRUE; break;
468 case ERROR_INVALID_SECURITY_DESCR: expected_win32status = STATUS_INVALID_SECURITY_DESCR; break;
469 case RPC_S_INVALID_STRING_BINDING: expected_win32status = RPC_NT_INVALID_STRING_BINDING; break;
470 case RPC_S_WRONG_KIND_OF_BINDING: expected_win32status = RPC_NT_WRONG_KIND_OF_BINDING; break;
471 case RPC_S_INVALID_BINDING: expected_win32status = RPC_NT_INVALID_BINDING; break;
472 case RPC_S_PROTSEQ_NOT_SUPPORTED: expected_win32status = RPC_NT_PROTSEQ_NOT_SUPPORTED; break;
473 case RPC_S_INVALID_RPC_PROTSEQ: expected_win32status = RPC_NT_INVALID_RPC_PROTSEQ; break;
474 case RPC_S_INVALID_STRING_UUID: expected_win32status = RPC_NT_INVALID_STRING_UUID; break;
475 case RPC_S_INVALID_ENDPOINT_FORMAT: expected_win32status = RPC_NT_INVALID_ENDPOINT_FORMAT; break;
476 case RPC_S_INVALID_NET_ADDR: expected_win32status = RPC_NT_INVALID_NET_ADDR; break;
477 case RPC_S_NO_ENDPOINT_FOUND: expected_win32status = RPC_NT_NO_ENDPOINT_FOUND; break;
478 case RPC_S_INVALID_TIMEOUT: expected_win32status = RPC_NT_INVALID_TIMEOUT; break;
479 case RPC_S_OBJECT_NOT_FOUND: expected_win32status = RPC_NT_OBJECT_NOT_FOUND; break;
480 case RPC_S_ALREADY_REGISTERED: expected_win32status = RPC_NT_ALREADY_REGISTERED; break;
481 case RPC_S_TYPE_ALREADY_REGISTERED: expected_win32status = RPC_NT_TYPE_ALREADY_REGISTERED; break;
482 case RPC_S_ALREADY_LISTENING: expected_win32status = RPC_NT_ALREADY_LISTENING; break;
483 case RPC_S_NO_PROTSEQS_REGISTERED: expected_win32status = RPC_NT_NO_PROTSEQS_REGISTERED; break;
484 case RPC_S_NOT_LISTENING: expected_win32status = RPC_NT_NOT_LISTENING; break;
485 case RPC_S_UNKNOWN_MGR_TYPE: expected_win32status = RPC_NT_UNKNOWN_MGR_TYPE; break;
486 case RPC_S_UNKNOWN_IF: expected_win32status = RPC_NT_UNKNOWN_IF; break;
487 case RPC_S_NO_BINDINGS: expected_win32status = RPC_NT_NO_BINDINGS; break;
488 case RPC_S_NO_PROTSEQS: expected_win32status = RPC_NT_NO_PROTSEQS; break;
489 case RPC_S_CANT_CREATE_ENDPOINT: expected_win32status = RPC_NT_CANT_CREATE_ENDPOINT; break;
490 case RPC_S_OUT_OF_RESOURCES: expected_win32status = RPC_NT_OUT_OF_RESOURCES; break;
491 case RPC_S_SERVER_UNAVAILABLE: expected_win32status = RPC_NT_SERVER_UNAVAILABLE; break;
492 case RPC_S_SERVER_TOO_BUSY: expected_win32status = RPC_NT_SERVER_TOO_BUSY; break;
493 case RPC_S_INVALID_NETWORK_OPTIONS: expected_win32status = RPC_NT_INVALID_NETWORK_OPTIONS; break;
494 case RPC_S_NO_CALL_ACTIVE: expected_win32status = RPC_NT_NO_CALL_ACTIVE; break;
495 case RPC_S_CALL_FAILED: expected_win32status = RPC_NT_CALL_FAILED; break;
496 case RPC_S_CALL_FAILED_DNE: expected_win32status = RPC_NT_CALL_FAILED_DNE; break;
497 case RPC_S_PROTOCOL_ERROR: expected_win32status = RPC_NT_PROTOCOL_ERROR; break;
498 case RPC_S_UNSUPPORTED_TRANS_SYN: expected_win32status = RPC_NT_UNSUPPORTED_TRANS_SYN; break;
499 case RPC_S_UNSUPPORTED_TYPE: expected_win32status = RPC_NT_UNSUPPORTED_TYPE; break;
500 case RPC_S_INVALID_TAG: expected_win32status = RPC_NT_INVALID_TAG; break;
501 case RPC_S_INVALID_BOUND: expected_win32status = RPC_NT_INVALID_BOUND; break;
502 case RPC_S_NO_ENTRY_NAME: expected_win32status = RPC_NT_NO_ENTRY_NAME; break;
503 case RPC_S_INVALID_NAME_SYNTAX: expected_win32status = RPC_NT_INVALID_NAME_SYNTAX; break;
504 case RPC_S_UNSUPPORTED_NAME_SYNTAX: expected_win32status = RPC_NT_UNSUPPORTED_NAME_SYNTAX; break;
505 case RPC_S_UUID_NO_ADDRESS: expected_win32status = RPC_NT_UUID_NO_ADDRESS; break;
506 case RPC_S_DUPLICATE_ENDPOINT: expected_win32status = RPC_NT_DUPLICATE_ENDPOINT; break;
507 case RPC_S_UNKNOWN_AUTHN_TYPE: expected_win32status = RPC_NT_UNKNOWN_AUTHN_TYPE; break;
508 case RPC_S_MAX_CALLS_TOO_SMALL: expected_win32status = RPC_NT_MAX_CALLS_TOO_SMALL; break;
509 case RPC_S_STRING_TOO_LONG: expected_win32status = RPC_NT_STRING_TOO_LONG; break;
510 case RPC_S_PROTSEQ_NOT_FOUND: expected_win32status = RPC_NT_PROTSEQ_NOT_FOUND; break;
511 case RPC_S_PROCNUM_OUT_OF_RANGE: expected_win32status = RPC_NT_PROCNUM_OUT_OF_RANGE; break;
512 case RPC_S_BINDING_HAS_NO_AUTH: expected_win32status = RPC_NT_BINDING_HAS_NO_AUTH; break;
513 case RPC_S_UNKNOWN_AUTHN_SERVICE: expected_win32status = RPC_NT_UNKNOWN_AUTHN_SERVICE; break;
514 case RPC_S_UNKNOWN_AUTHN_LEVEL: expected_win32status = RPC_NT_UNKNOWN_AUTHN_LEVEL; break;
515 case RPC_S_INVALID_AUTH_IDENTITY: expected_win32status = RPC_NT_INVALID_AUTH_IDENTITY; break;
516 case RPC_S_UNKNOWN_AUTHZ_SERVICE: expected_win32status = RPC_NT_UNKNOWN_AUTHZ_SERVICE; break;
517 case EPT_S_INVALID_ENTRY: expected_win32status = EPT_NT_INVALID_ENTRY; break;
518 case EPT_S_CANT_PERFORM_OP: expected_win32status = EPT_NT_CANT_PERFORM_OP; break;
519 case EPT_S_NOT_REGISTERED: expected_win32status = EPT_NT_NOT_REGISTERED; break;
520 case EPT_S_CANT_CREATE: expected_win32status = EPT_NT_CANT_CREATE; break;
521 case RPC_S_NOTHING_TO_EXPORT: expected_win32status = RPC_NT_NOTHING_TO_EXPORT; break;
522 case RPC_S_INCOMPLETE_NAME: expected_win32status = RPC_NT_INCOMPLETE_NAME; break;
523 case RPC_S_INVALID_VERS_OPTION: expected_win32status = RPC_NT_INVALID_VERS_OPTION; break;
524 case RPC_S_NO_MORE_MEMBERS: expected_win32status = RPC_NT_NO_MORE_MEMBERS; break;
525 case RPC_S_NOT_ALL_OBJS_UNEXPORTED: expected_win32status = RPC_NT_NOT_ALL_OBJS_UNEXPORTED; break;
526 case RPC_S_INTERFACE_NOT_FOUND: expected_win32status = RPC_NT_INTERFACE_NOT_FOUND; break;
527 case RPC_S_ENTRY_ALREADY_EXISTS: expected_win32status = RPC_NT_ENTRY_ALREADY_EXISTS; break;
528 case RPC_S_ENTRY_NOT_FOUND: expected_win32status = RPC_NT_ENTRY_NOT_FOUND; break;
529 case RPC_S_NAME_SERVICE_UNAVAILABLE: expected_win32status = RPC_NT_NAME_SERVICE_UNAVAILABLE; break;
530 case RPC_S_INVALID_NAF_ID: expected_win32status = RPC_NT_INVALID_NAF_ID; break;
531 case RPC_S_CANNOT_SUPPORT: expected_win32status = RPC_NT_CANNOT_SUPPORT; break;
532 case RPC_S_NO_CONTEXT_AVAILABLE: expected_win32status = RPC_NT_NO_CONTEXT_AVAILABLE; break;
533 case RPC_S_INTERNAL_ERROR: expected_win32status = RPC_NT_INTERNAL_ERROR; break;
534 case RPC_S_ZERO_DIVIDE: expected_win32status = RPC_NT_ZERO_DIVIDE; break;
535 case RPC_S_ADDRESS_ERROR: expected_win32status = RPC_NT_ADDRESS_ERROR; break;
536 case RPC_S_FP_DIV_ZERO: expected_win32status = RPC_NT_FP_DIV_ZERO; break;
537 case RPC_S_FP_UNDERFLOW: expected_win32status = RPC_NT_FP_UNDERFLOW; break;
538 case RPC_S_FP_OVERFLOW: expected_win32status = RPC_NT_FP_OVERFLOW; break;
539 case RPC_S_CALL_IN_PROGRESS: expected_win32status = RPC_NT_CALL_IN_PROGRESS; break;
540 case RPC_S_NO_MORE_BINDINGS: expected_win32status = RPC_NT_NO_MORE_BINDINGS; break;
541 case RPC_S_CALL_CANCELLED: expected_win32status = RPC_NT_CALL_CANCELLED; missing = TRUE; break;
542 case RPC_S_INVALID_OBJECT: expected_win32status = RPC_NT_INVALID_OBJECT; break;
543 case RPC_S_INVALID_ASYNC_HANDLE: expected_win32status = RPC_NT_INVALID_ASYNC_HANDLE; missing = TRUE; break;
544 case RPC_S_INVALID_ASYNC_CALL: expected_win32status = RPC_NT_INVALID_ASYNC_CALL; missing = TRUE; break;
545 case RPC_S_GROUP_MEMBER_NOT_FOUND: expected_win32status = RPC_NT_GROUP_MEMBER_NOT_FOUND; break;
546 case RPC_X_NO_MORE_ENTRIES: expected_win32status = RPC_NT_NO_MORE_ENTRIES; break;
547 case RPC_X_SS_CHAR_TRANS_OPEN_FAIL: expected_win32status = RPC_NT_SS_CHAR_TRANS_OPEN_FAIL; break;
548 case RPC_X_SS_CHAR_TRANS_SHORT_FILE: expected_win32status = RPC_NT_SS_CHAR_TRANS_SHORT_FILE; break;
549 case RPC_X_SS_IN_NULL_CONTEXT: expected_win32status = RPC_NT_SS_IN_NULL_CONTEXT; break;
550 case RPC_X_SS_CONTEXT_DAMAGED: expected_win32status = RPC_NT_SS_CONTEXT_DAMAGED; break;
551 case RPC_X_SS_HANDLES_MISMATCH: expected_win32status = RPC_NT_SS_HANDLES_MISMATCH; break;
552 case RPC_X_SS_CANNOT_GET_CALL_HANDLE: expected_win32status = RPC_NT_SS_CANNOT_GET_CALL_HANDLE; break;
553 case RPC_X_NULL_REF_POINTER: expected_win32status = RPC_NT_NULL_REF_POINTER; break;
554 case RPC_X_ENUM_VALUE_OUT_OF_RANGE: expected_win32status = RPC_NT_ENUM_VALUE_OUT_OF_RANGE; break;
555 case RPC_X_BYTE_COUNT_TOO_SMALL: expected_win32status = RPC_NT_BYTE_COUNT_TOO_SMALL; break;
556 case RPC_X_BAD_STUB_DATA: expected_win32status = RPC_NT_BAD_STUB_DATA; break;
557 case RPC_X_PIPE_CLOSED: expected_win32status = RPC_NT_PIPE_CLOSED; missing = TRUE; break;
558 case RPC_X_PIPE_DISCIPLINE_ERROR: expected_win32status = RPC_NT_PIPE_DISCIPLINE_ERROR; missing = TRUE; break;
559 case RPC_X_PIPE_EMPTY: expected_win32status = RPC_NT_PIPE_EMPTY; missing = TRUE; break;
560 case ERROR_PASSWORD_MUST_CHANGE: expected_win32status = STATUS_PASSWORD_MUST_CHANGE; missing = TRUE; break;
561 case ERROR_ACCOUNT_LOCKED_OUT: expected_win32status = STATUS_ACCOUNT_LOCKED_OUT; missing = TRUE; break;
562 default:
563 if (w2k3_up)
564 expected_win32status = STATUS_UNSUCCESSFUL;
565 else
566 expected_win32status = rpc_status;
567 }
568
569 ok(win32status == expected_win32status ||
570 broken(missing && win32status == rpc_status),
571 "I_RpcMapWin32Status(%d) should have returned 0x%x instead of 0x%x%s\n",
572 rpc_status, expected_win32status, win32status,
573 broken(missing) ? " (or have returned with the given status)" : "");
574 }
575 }
576
577 static void test_RpcStringBindingParseA(void)
578 {
579 static unsigned char valid_binding[] = "00000000-0000-0000-c000-000000000046@ncacn_np:.[endpoint=\\pipe\\test]";
580 static unsigned char valid_binding2[] = "00000000-0000-0000-c000-000000000046@ncacn_np:.[\\pipe\\test]";
581 static unsigned char invalid_uuid_binding[] = "{00000000-0000-0000-c000-000000000046}@ncacn_np:.[endpoint=\\pipe\\test]";
582 static unsigned char invalid_ep_binding[] = "00000000-0000-0000-c000-000000000046@ncacn_np:.[endpoint=test]";
583 static unsigned char invalid_binding[] = "00000000-0000-0000-c000-000000000046@ncacn_np";
584 RPC_STATUS status;
585 unsigned char *uuid;
586 unsigned char *protseq;
587 unsigned char *network_addr;
588 unsigned char *endpoint;
589 unsigned char *options;
590
591 /* test all parameters */
592 status = RpcStringBindingParseA(valid_binding, &uuid, &protseq, &network_addr, &endpoint, &options);
593 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
594 ok(!strcmp((char *)uuid, "00000000-0000-0000-c000-000000000046"), "uuid should have been 00000000-0000-0000-C000-000000000046 instead of %s\n", uuid);
595 ok(!strcmp((char *)protseq, "ncacn_np"), "protseq should have been ncacn_np instead of %s\n", protseq);
596 ok(!strcmp((char *)network_addr, "."), "network_addr should have been . instead of %s\n", network_addr);
597 ok(!strcmp((char *)endpoint, "pipetest"), "endpoint should have been pipetest instead of %s\n", endpoint);
598 if (options)
599 ok(!strcmp((char *)options, ""), "options should have been \"\" of \"%s\"\n", options);
600 else
601 todo_wine ok(FALSE, "options is NULL\n");
602 RpcStringFreeA(&uuid);
603 RpcStringFreeA(&protseq);
604 RpcStringFreeA(&network_addr);
605 RpcStringFreeA(&endpoint);
606 RpcStringFreeA(&options);
607
608 /* test all parameters with different type of string binding */
609 status = RpcStringBindingParseA(valid_binding2, &uuid, &protseq, &network_addr, &endpoint, &options);
610 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
611 ok(!strcmp((char *)uuid, "00000000-0000-0000-c000-000000000046"), "uuid should have been 00000000-0000-0000-C000-000000000046 instead of %s\n", uuid);
612 ok(!strcmp((char *)protseq, "ncacn_np"), "protseq should have been ncacn_np instead of %s\n", protseq);
613 ok(!strcmp((char *)network_addr, "."), "network_addr should have been . instead of %s\n", network_addr);
614 ok(!strcmp((char *)endpoint, "pipetest"), "endpoint should have been pipetest instead of %s\n", endpoint);
615 if (options)
616 ok(!strcmp((char *)options, ""), "options should have been \"\" of \"%s\"\n", options);
617 else
618 todo_wine ok(FALSE, "options is NULL\n");
619 RpcStringFreeA(&uuid);
620 RpcStringFreeA(&protseq);
621 RpcStringFreeA(&network_addr);
622 RpcStringFreeA(&endpoint);
623 RpcStringFreeA(&options);
624
625 /* test with as many parameters NULL as possible */
626 status = RpcStringBindingParseA(valid_binding, NULL, &protseq, NULL, NULL, NULL);
627 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
628 ok(!strcmp((char *)protseq, "ncacn_np"), "protseq should have been ncacn_np instead of %s\n", protseq);
629 RpcStringFreeA(&protseq);
630
631 /* test with invalid uuid */
632 status = RpcStringBindingParseA(invalid_uuid_binding, NULL, &protseq, NULL, NULL, NULL);
633 ok(status == RPC_S_INVALID_STRING_UUID, "RpcStringBindingParseA should have returned RPC_S_INVALID_STRING_UUID instead of %d\n", status);
634 ok(protseq == NULL, "protseq was %p instead of NULL\n", protseq);
635
636 /* test with invalid endpoint */
637 status = RpcStringBindingParseA(invalid_ep_binding, NULL, &protseq, NULL, NULL, NULL);
638 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
639 RpcStringFreeA(&protseq);
640
641 /* test with invalid binding */
642 status = RpcStringBindingParseA(invalid_binding, &uuid, &protseq, &network_addr, &endpoint, &options);
643 todo_wine
644 ok(status == RPC_S_INVALID_STRING_BINDING, "RpcStringBindingParseA should have returned RPC_S_INVALID_STRING_BINDING instead of %d\n", status);
645 todo_wine
646 ok(uuid == NULL, "uuid was %p instead of NULL\n", uuid);
647 if (uuid)
648 RpcStringFreeA(&uuid);
649 ok(protseq == NULL, "protseq was %p instead of NULL\n", protseq);
650 todo_wine
651 ok(network_addr == NULL, "network_addr was %p instead of NULL\n", network_addr);
652 if (network_addr)
653 RpcStringFreeA(&network_addr);
654 ok(endpoint == NULL, "endpoint was %p instead of NULL\n", endpoint);
655 ok(options == NULL, "options was %p instead of NULL\n", options);
656 }
657
658 static void test_I_RpcExceptionFilter(void)
659 {
660 ULONG exception;
661 int retval;
662 int (WINAPI *pI_RpcExceptionFilter)(ULONG) = (void *)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "I_RpcExceptionFilter");
663
664 if (!pI_RpcExceptionFilter)
665 {
666 win_skip("I_RpcExceptionFilter not exported\n");
667 return;
668 }
669
670 for (exception = 0; exception < STATUS_REG_NAT_CONSUMPTION; exception++)
671 {
672 /* skip over uninteresting bits of the number space */
673 if (exception == 2000) exception = 0x40000000;
674 if (exception == 0x40000005) exception = 0x80000000;
675 if (exception == 0x80000005) exception = 0xc0000000;
676
677 retval = pI_RpcExceptionFilter(exception);
678 switch (exception)
679 {
680 case STATUS_DATATYPE_MISALIGNMENT:
681 case STATUS_BREAKPOINT:
682 case STATUS_ACCESS_VIOLATION:
683 case STATUS_ILLEGAL_INSTRUCTION:
684 case STATUS_PRIVILEGED_INSTRUCTION:
685 case STATUS_INSTRUCTION_MISALIGNMENT:
686 case STATUS_STACK_OVERFLOW:
687 case STATUS_POSSIBLE_DEADLOCK:
688 ok(retval == EXCEPTION_CONTINUE_SEARCH, "I_RpcExceptionFilter(0x%x) should have returned %d instead of %d\n",
689 exception, EXCEPTION_CONTINUE_SEARCH, retval);
690 break;
691 case STATUS_GUARD_PAGE_VIOLATION:
692 case STATUS_IN_PAGE_ERROR:
693 case STATUS_HANDLE_NOT_CLOSABLE:
694 trace("I_RpcExceptionFilter(0x%x) returned %d\n", exception, retval);
695 break;
696 default:
697 ok(retval == EXCEPTION_EXECUTE_HANDLER, "I_RpcExceptionFilter(0x%x) should have returned %d instead of %d\n",
698 exception, EXCEPTION_EXECUTE_HANDLER, retval);
699 }
700 }
701 }
702
703 static void test_RpcStringBindingFromBinding(void)
704 {
705 static unsigned char ncacn_np[] = "ncacn_np";
706 static unsigned char address[] = ".";
707 static unsigned char endpoint[] = "\\pipe\\wine_rpc_test";
708 RPC_STATUS status;
709 handle_t handle;
710 RPC_CSTR binding;
711
712 status = RpcStringBindingComposeA(NULL, ncacn_np, address,
713 endpoint, NULL, &binding);
714 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);
715
716 status = RpcBindingFromStringBindingA(binding, &handle);
717 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n", status);
718 RpcStringFreeA(&binding);
719
720 status = RpcBindingToStringBindingA(handle, &binding);
721 ok(status == RPC_S_OK, "RpcStringBindingFromBinding failed with error %u\n", status);
722
723 ok(!strcmp((const char *)binding, "ncacn_np:.[\\\\pipe\\\\wine_rpc_test]"),
724 "binding string didn't match what was expected: \"%s\"\n", binding);
725 RpcStringFreeA(&binding);
726
727 status = RpcBindingFree(&handle);
728 ok(status == RPC_S_OK, "RpcBindingFree failed with error %u\n", status);
729 }
730
731 static void test_UuidCreate(void)
732 {
733 UUID guid;
734 BYTE version;
735
736 UuidCreate(&guid);
737 version = (guid.Data3 & 0xf000) >> 12;
738 ok(version == 4 || broken(version == 1), "unexpected version %d\n",
739 version);
740 if (version == 4)
741 {
742 static UUID v4and = { 0, 0, 0x4000, { 0x80,0,0,0,0,0,0,0 } };
743 static UUID v4or = { 0xffffffff, 0xffff, 0x4fff,
744 { 0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff } };
745 UUID and, or;
746 RPC_STATUS rslt;
747 int i;
748
749 and = guid;
750 or = guid;
751 /* Generate a bunch of UUIDs and mask them. By the end, we expect
752 * every randomly generated bit to have been zero at least once,
753 * resulting in no bits set in the and mask except those which are not
754 * randomly generated: the version number and the topmost bits of the
755 * Data4 field (treated as big-endian.) Similarly, we expect only
756 * the bits which are not randomly set to be cleared in the or mask.
757 */
758 for (i = 0; i < 1000; i++)
759 {
760 LPBYTE src, dst;
761
762 UuidCreate(&guid);
763 for (src = (LPBYTE)&guid, dst = (LPBYTE)&and;
764 src - (LPBYTE)&guid < sizeof(guid); src++, dst++)
765 *dst &= *src;
766 for (src = (LPBYTE)&guid, dst = (LPBYTE)&or;
767 src - (LPBYTE)&guid < sizeof(guid); src++, dst++)
768 *dst |= *src;
769 }
770 ok(UuidEqual(&and, &v4and, &rslt),
771 "unexpected bits set in V4 UUID: %s\n", wine_dbgstr_guid(&and));
772 ok(UuidEqual(&or, &v4or, &rslt),
773 "unexpected bits set in V4 UUID: %s\n", wine_dbgstr_guid(&or));
774 }
775 else
776 {
777 /* Older versions of Windows generate V1 UUIDs. For these, there are
778 * many stable bits, including at least the MAC address if one is
779 * present. Just check that Data4[0]'s most significant bits are
780 * set as expected.
781 */
782 ok((guid.Data4[0] & 0xc0) == 0x80,
783 "unexpected value in Data4[0]: %02x\n", guid.Data4[0] & 0xc0);
784 }
785 }
786
787 static void test_UuidCreateSequential(void)
788 {
789 UUID guid1;
790 BYTE version;
791 RPC_STATUS (WINAPI *pUuidCreateSequential)(UUID *) = (void *)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "UuidCreateSequential");
792 RPC_STATUS (WINAPI *pI_UuidCreate)(UUID *) = (void*)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "I_UuidCreate");
793 RPC_STATUS ret;
794
795 if (!pUuidCreateSequential)
796 {
797 win_skip("UuidCreateSequential not exported\n");
798 return;
799 }
800
801 ok(pI_UuidCreate != pUuidCreateSequential, "got %p, %p\n", pI_UuidCreate, pUuidCreateSequential);
802
803 ret = pUuidCreateSequential(&guid1);
804 ok(!ret || ret == RPC_S_UUID_LOCAL_ONLY,
805 "expected RPC_S_OK or RPC_S_UUID_LOCAL_ONLY, got %08x\n", ret);
806 version = (guid1.Data3 & 0xf000) >> 12;
807 ok(version == 1, "unexpected version %d\n", version);
808 if (version == 1)
809 {
810 UUID guid2;
811
812 if (!ret)
813 {
814 /* If the call succeeded, there's a valid (non-multicast) MAC
815 * address in the uuid:
816 */
817 ok(!(guid1.Data4[2] & 0x01) || broken(guid1.Data4[2] & 0x01), /* Win 8.1 */
818 "GUID does not appear to contain a MAC address: %s\n",
819 wine_dbgstr_guid(&guid1));
820 }
821 else
822 {
823 /* Otherwise, there's a randomly generated multicast MAC address
824 * address in the uuid:
825 */
826 ok((guid1.Data4[2] & 0x01),
827 "GUID does not appear to contain a multicast MAC address: %s\n",
828 wine_dbgstr_guid(&guid1));
829 }
830 /* Generate another GUID, and make sure its MAC address matches the
831 * first.
832 */
833 ret = pUuidCreateSequential(&guid2);
834 ok(!ret || ret == RPC_S_UUID_LOCAL_ONLY,
835 "expected RPC_S_OK or RPC_S_UUID_LOCAL_ONLY, got %08x\n", ret);
836 version = (guid2.Data3 & 0xf000) >> 12;
837 ok(version == 1, "unexpected version %d\n", version);
838 ok(!memcmp(guid1.Data4, guid2.Data4, sizeof(guid2.Data4)),
839 "unexpected value in MAC address: %s\n",
840 wine_dbgstr_guid(&guid2));
841
842 /* I_UuidCreate does exactly the same */
843 pI_UuidCreate(&guid2);
844 version = (guid2.Data3 & 0xf000) >> 12;
845 ok(version == 1, "unexpected version %d\n", version);
846 ok(!memcmp(guid1.Data4, guid2.Data4, sizeof(guid2.Data4)),
847 "unexpected value in MAC address: %s\n",
848 wine_dbgstr_guid(&guid2));
849 }
850 }
851
852 static void test_RpcBindingFree(void)
853 {
854 RPC_BINDING_HANDLE binding = NULL;
855 RPC_STATUS status;
856
857 status = RpcBindingFree(&binding);
858 ok(status == RPC_S_INVALID_BINDING,
859 "RpcBindingFree should have returned RPC_S_INVALID_BINDING instead of %d\n",
860 status);
861 }
862
863 static void test_RpcServerInqDefaultPrincName(void)
864 {
865 RPC_STATUS ret;
866 RPC_CSTR principal, saved_principal;
867 char *username;
868 ULONG len = 0;
869
870 GetUserNameExA( NameSamCompatible, NULL, &len );
871 username = HeapAlloc( GetProcessHeap(), 0, len );
872 GetUserNameExA( NameSamCompatible, username, &len );
873
874 ret = RpcServerInqDefaultPrincNameA( 0, NULL );
875 ok( ret == RPC_S_UNKNOWN_AUTHN_SERVICE, "got %u\n", ret );
876
877 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_DEFAULT, NULL );
878 ok( ret == RPC_S_UNKNOWN_AUTHN_SERVICE, "got %u\n", ret );
879
880 principal = (RPC_CSTR)0xdeadbeef;
881 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_DEFAULT, &principal );
882 ok( ret == RPC_S_UNKNOWN_AUTHN_SERVICE, "got %u\n", ret );
883 ok( principal == (RPC_CSTR)0xdeadbeef, "got unexpected principal\n" );
884
885 saved_principal = (RPC_CSTR)0xdeadbeef;
886 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_WINNT, &saved_principal );
887 ok( ret == RPC_S_OK, "got %u\n", ret );
888 ok( saved_principal != (RPC_CSTR)0xdeadbeef, "expected valid principal\n" );
889 ok( !strcmp( (const char *)saved_principal, username ), "got \'%s\'\n", saved_principal );
890 trace("%s\n", saved_principal);
891
892 ret = RpcServerRegisterAuthInfoA( (RPC_CSTR)"wine\\test", RPC_C_AUTHN_WINNT, NULL, NULL );
893 ok( ret == RPC_S_OK, "got %u\n", ret );
894
895 principal = (RPC_CSTR)0xdeadbeef;
896 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_WINNT, &principal );
897 ok( ret == RPC_S_OK, "got %u\n", ret );
898 ok( principal != (RPC_CSTR)0xdeadbeef, "expected valid principal\n" );
899 ok( !strcmp( (const char *)principal, username ), "got \'%s\'\n", principal );
900 RpcStringFreeA( &principal );
901
902 ret = RpcServerRegisterAuthInfoA( saved_principal, RPC_C_AUTHN_WINNT, NULL, NULL );
903 ok( ret == RPC_S_OK, "got %u\n", ret );
904
905 RpcStringFreeA( &saved_principal );
906 HeapFree( GetProcessHeap(), 0, username );
907 }
908
909 static void test_RpcServerRegisterAuthInfo(void)
910 {
911 RPC_STATUS status;
912
913 status = RpcServerRegisterAuthInfoW(NULL, 600, NULL, NULL);
914 ok(status == RPC_S_UNKNOWN_AUTHN_SERVICE, "status = %x\n", status);
915 }
916
917 static void test_RpcServerUseProtseq(void)
918 {
919 RPC_STATUS status;
920 RPC_BINDING_VECTOR *bindings;
921 ULONG i;
922 ULONG binding_count_before;
923 ULONG binding_count_after1;
924 ULONG binding_count_after2;
925 ULONG endpoints_registered = 0;
926 static unsigned char iptcp[] = "ncacn_ip_tcp";
927 static unsigned char np[] = "ncacn_np";
928 static unsigned char ncalrpc[] = "ncalrpc";
929 BOOL iptcp_registered = FALSE, np_registered = FALSE, ncalrpc_registered = FALSE;
930
931 status = RpcServerInqBindings(&bindings);
932 if (status == RPC_S_NO_BINDINGS)
933 binding_count_before = 0;
934 else
935 {
936 binding_count_before = bindings->Count;
937 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
938 for (i = 0; i < bindings->Count; i++)
939 {
940 RPC_CSTR str_bind;
941 status = RpcBindingToStringBindingA(bindings->BindingH[i], &str_bind);
942 ok(status == RPC_S_OK, "RpcBindingToStringBinding failed with status %d\n", status);
943 if (lstrlenA((const char *)str_bind) > 12 && !memcmp(str_bind, "ncacn_ip_tcp", 12))
944 iptcp_registered = TRUE;
945 if (lstrlenA((const char *)str_bind) > 8 && !memcmp(str_bind, "ncacn_np", 8))
946 np_registered = TRUE;
947 if (lstrlenA((const char *)str_bind) > 7 && !memcmp(str_bind, "ncalrpc", 7))
948 ncalrpc_registered = TRUE;
949 RpcStringFreeA(&str_bind);
950 }
951 RpcBindingVectorFree(&bindings);
952 }
953
954 /* show that RpcServerUseProtseqEp(..., NULL, ...) is the same as
955 * RpcServerUseProtseq(...) */
956 status = RpcServerUseProtseqEpA(ncalrpc, 0, NULL, NULL);
957 ok(status == RPC_S_OK || broken(status == RPC_S_INVALID_ENDPOINT_FORMAT),
958 "RpcServerUseProtseqEp with NULL endpoint failed with status %d\n",
959 status);
960
961 /* register protocol sequences without explicit endpoints */
962 status = RpcServerUseProtseqA(np, 0, NULL);
963 if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
964 win_skip("ncacn_np not supported\n");
965 else
966 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
967 if (status == RPC_S_OK && !np_registered) endpoints_registered++;
968
969 status = RpcServerUseProtseqA(iptcp, 0, NULL);
970 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);
971 if (status == RPC_S_OK && !iptcp_registered) endpoints_registered++;
972
973 status = RpcServerUseProtseqA(ncalrpc, 0, NULL);
974 ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);
975 if (status == RPC_S_OK && !ncalrpc_registered) endpoints_registered++;
976
977 status = RpcServerInqBindings(&bindings);
978 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
979 binding_count_after1 = bindings->Count;
980 ok(binding_count_after1 == binding_count_before + endpoints_registered,
981 "wrong binding count - before: %u, after %u, endpoints registered %u\n",
982 binding_count_before, binding_count_after1, endpoints_registered);
983 for (i = 0; i < bindings->Count; i++)
984 {
985 RPC_CSTR str_bind;
986 status = RpcBindingToStringBindingA(bindings->BindingH[i], &str_bind);
987 ok(status == RPC_S_OK, "RpcBindingToStringBinding failed with status %d\n", status);
988 trace("string binding: %s\n", str_bind);
989 RpcStringFreeA(&str_bind);
990 }
991 RpcBindingVectorFree(&bindings);
992
993 /* re-register - endpoints should be reused */
994 status = RpcServerUseProtseqA(np, 0, NULL);
995 if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
996 win_skip("ncacn_np not supported\n");
997 else
998 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
999
1000 status = RpcServerUseProtseqA(iptcp, 0, NULL);
1001 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);
1002
1003 status = RpcServerUseProtseqA(ncalrpc, 0, NULL);
1004 ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);
1005
1006 status = RpcServerInqBindings(&bindings);
1007 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
1008 binding_count_after2 = bindings->Count;
1009 ok(binding_count_after2 == binding_count_after1,
1010 "bindings should have been re-used - after1: %u after2: %u\n",
1011 binding_count_after1, binding_count_after2);
1012 RpcBindingVectorFree(&bindings);
1013 }
1014
1015 static void test_endpoint_mapper(RPC_CSTR protseq, RPC_CSTR address)
1016 {
1017 static unsigned char annotation[] = "Test annotation string.";
1018 RPC_STATUS status;
1019 RPC_BINDING_VECTOR *binding_vector;
1020 handle_t handle;
1021 unsigned char *binding;
1022
1023 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
1024 ok(status == RPC_S_OK, "%s: RpcServerRegisterIf failed (%u)\n", protseq, status);
1025
1026 status = RpcServerInqBindings(&binding_vector);
1027 ok(status == RPC_S_OK, "%s: RpcServerInqBindings failed with error %u\n", protseq, status);
1028
1029 /* register endpoints created in test_RpcServerUseProtseq */
1030 status = RpcEpRegisterA(IFoo_v0_0_s_ifspec, binding_vector, NULL, annotation);
1031 ok(status == RPC_S_OK, "%s: RpcEpRegisterA failed with error %u\n", protseq, status);
1032 /* reregister the same endpoint with no annotation */
1033 status = RpcEpRegisterA(IFoo_v0_0_s_ifspec, binding_vector, NULL, NULL);
1034 ok(status == RPC_S_OK, "%s: RpcEpRegisterA failed with error %u\n", protseq, status);
1035
1036 status = RpcStringBindingComposeA(NULL, protseq, address,
1037 NULL, NULL, &binding);
1038 ok(status == RPC_S_OK, "%s: RpcStringBindingCompose failed (%u)\n", protseq, status);
1039
1040 status = RpcBindingFromStringBindingA(binding, &handle);
1041 ok(status == RPC_S_OK, "%s: RpcBindingFromStringBinding failed (%u)\n", protseq, status);
1042
1043 RpcStringFreeA(&binding);
1044
1045 status = RpcBindingReset(handle);
1046 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
1047
1048 status = RpcEpResolveBinding(handle, IFoo_v0_0_s_ifspec);
1049 ok(status == RPC_S_OK || broken(status == RPC_S_SERVER_UNAVAILABLE), /* win9x */
1050 "%s: RpcEpResolveBinding failed with error %u\n", protseq, status);
1051
1052 status = RpcBindingReset(handle);
1053 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
1054
1055 status = RpcBindingFree(&handle);
1056 ok(status == RPC_S_OK, "%s: RpcBindingFree failed with error %u\n", protseq, status);
1057
1058 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
1059 ok(status == RPC_S_OK, "%s: RpcServerUnregisterIf failed (%u)\n", protseq, status);
1060
1061 status = RpcEpUnregister(IFoo_v0_0_s_ifspec, binding_vector, NULL);
1062 ok(status == RPC_S_OK, "%s: RpcEpUnregisterA failed with error %u\n", protseq, status);
1063
1064 status = RpcBindingVectorFree(&binding_vector);
1065 ok(status == RPC_S_OK, "%s: RpcBindingVectorFree failed with error %u\n", protseq, status);
1066 }
1067
1068 static BOOL is_process_elevated(void)
1069 {
1070 HANDLE token;
1071 if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token ))
1072 {
1073 TOKEN_ELEVATION_TYPE type;
1074 DWORD size;
1075 BOOL ret;
1076
1077 ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size );
1078 CloseHandle( token );
1079 return (ret && type == TokenElevationTypeFull);
1080 }
1081 return FALSE;
1082 }
1083
1084 static BOOL is_firewall_enabled(void)
1085 {
1086 HRESULT hr, init;
1087 INetFwMgr *mgr = NULL;
1088 INetFwPolicy *policy = NULL;
1089 INetFwProfile *profile = NULL;
1090 VARIANT_BOOL enabled = VARIANT_FALSE;
1091
1092 init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED );
1093
1094 hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr,
1095 (void **)&mgr );
1096 ok( hr == S_OK, "got %08x\n", hr );
1097 if (hr != S_OK) goto done;
1098
1099 hr = INetFwMgr_get_LocalPolicy( mgr, &policy );
1100 ok( hr == S_OK, "got %08x\n", hr );
1101 if (hr != S_OK) goto done;
1102
1103 hr = INetFwPolicy_get_CurrentProfile( policy, &profile );
1104 if (hr != S_OK) goto done;
1105
1106 hr = INetFwProfile_get_FirewallEnabled( profile, &enabled );
1107 ok( hr == S_OK, "got %08x\n", hr );
1108
1109 done:
1110 if (policy) INetFwPolicy_Release( policy );
1111 if (profile) INetFwProfile_Release( profile );
1112 if (mgr) INetFwMgr_Release( mgr );
1113 if (SUCCEEDED( init )) CoUninitialize();
1114 return (enabled == VARIANT_TRUE);
1115 }
1116
1117 enum firewall_op
1118 {
1119 APP_ADD,
1120 APP_REMOVE
1121 };
1122
1123 static HRESULT set_firewall( enum firewall_op op )
1124 {
1125 static const WCHAR testW[] = {'r','p','c','r','t','4','_','t','e','s','t',0};
1126 HRESULT hr, init;
1127 INetFwMgr *mgr = NULL;
1128 INetFwPolicy *policy = NULL;
1129 INetFwProfile *profile = NULL;
1130 INetFwAuthorizedApplication *app = NULL;
1131 INetFwAuthorizedApplications *apps = NULL;
1132 BSTR name, image = SysAllocStringLen( NULL, MAX_PATH );
1133
1134 if (!GetModuleFileNameW( NULL, image, MAX_PATH ))
1135 {
1136 SysFreeString( image );
1137 return E_FAIL;
1138 }
1139 init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED );
1140
1141 hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr,
1142 (void **)&mgr );
1143 ok( hr == S_OK, "got %08x\n", hr );
1144 if (hr != S_OK) goto done;
1145
1146 hr = INetFwMgr_get_LocalPolicy( mgr, &policy );
1147 ok( hr == S_OK, "got %08x\n", hr );
1148 if (hr != S_OK) goto done;
1149
1150 hr = INetFwPolicy_get_CurrentProfile( policy, &profile );
1151 if (hr != S_OK) goto done;
1152
1153 INetFwProfile_get_AuthorizedApplications( profile, &apps );
1154 ok( hr == S_OK, "got %08x\n", hr );
1155 if (hr != S_OK) goto done;
1156
1157 hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER,
1158 &IID_INetFwAuthorizedApplication, (void **)&app );
1159 ok( hr == S_OK, "got %08x\n", hr );
1160 if (hr != S_OK) goto done;
1161
1162 hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image );
1163 if (hr != S_OK) goto done;
1164
1165 name = SysAllocString( testW );
1166 hr = INetFwAuthorizedApplication_put_Name( app, name );
1167 SysFreeString( name );
1168 ok( hr == S_OK, "got %08x\n", hr );
1169 if (hr != S_OK) goto done;
1170
1171 if (op == APP_ADD)
1172 hr = INetFwAuthorizedApplications_Add( apps, app );
1173 else if (op == APP_REMOVE)
1174 hr = INetFwAuthorizedApplications_Remove( apps, image );
1175 else
1176 hr = E_INVALIDARG;
1177
1178 done:
1179 if (app) INetFwAuthorizedApplication_Release( app );
1180 if (apps) INetFwAuthorizedApplications_Release( apps );
1181 if (policy) INetFwPolicy_Release( policy );
1182 if (profile) INetFwProfile_Release( profile );
1183 if (mgr) INetFwMgr_Release( mgr );
1184 if (SUCCEEDED( init )) CoUninitialize();
1185 SysFreeString( image );
1186 return hr;
1187 }
1188
1189 START_TEST( rpc )
1190 {
1191 static unsigned char ncacn_np[] = "ncacn_np";
1192 static unsigned char ncalrpc[] = "ncalrpc";
1193 static unsigned char np_address[] = ".";
1194 BOOL firewall_enabled = is_firewall_enabled();
1195
1196 if (firewall_enabled && !is_process_elevated())
1197 {
1198 skip("no privileges, skipping tests to avoid firewall dialog\n");
1199 return;
1200 }
1201
1202 UuidConversionAndComparison();
1203 TestDceErrorInqText();
1204 test_towers();
1205 test_I_RpcMapWin32Status();
1206 test_RpcStringBindingParseA();
1207 test_I_RpcExceptionFilter();
1208 test_RpcStringBindingFromBinding();
1209 test_UuidCreate();
1210 test_UuidCreateSequential();
1211 test_RpcBindingFree();
1212 test_RpcServerInqDefaultPrincName();
1213 test_RpcServerRegisterAuthInfo();
1214
1215 if (firewall_enabled)
1216 {
1217 HRESULT hr = set_firewall(APP_ADD);
1218 if (hr != S_OK)
1219 {
1220 skip("can't authorize app in firewall %08x\n", hr);
1221 return;
1222 }
1223 }
1224
1225 test_rpc_ncacn_ip_tcp();
1226 test_RpcServerUseProtseq();
1227 test_endpoint_mapper(ncacn_np, np_address);
1228 test_endpoint_mapper(ncalrpc, NULL);
1229
1230 if (firewall_enabled) set_firewall(APP_REMOVE);
1231 }