8ee3e12595e728a06d4e5bd8d3d59111326dba30
[reactos.git] / rostests / winetests / rpcrt4 / rpc.c
1 /*
2 * Unit test suite for rpc functions
3 *
4 * Copyright 2002 Greg Turner
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include <ntstatus.h>
25 #define WIN32_NO_STATUS
26 #include "wine/test.h"
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winnt.h>
30 #include <winerror.h>
31
32 #include "rpc.h"
33 #include "rpcdce.h"
34 #include "secext.h"
35
36 typedef unsigned int unsigned32;
37 typedef struct twr_t
38 {
39 unsigned32 tower_length;
40 /* [size_is] */ byte tower_octet_string[ 1 ];
41 } twr_t;
42
43 RPC_STATUS WINAPI TowerExplode(const twr_t *tower, RPC_SYNTAX_IDENTIFIER *object, RPC_SYNTAX_IDENTIFIER *syntax, char **protseq, char **endpoint, char **address);
44 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);
45
46 static UUID Uuid_Table[10] = {
47 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 0 (null) */
48 { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8a} }, /* 1 */
49 { 0xabadfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 2 */
50 { 0x93da375c, 0x1324, 0x1355, {0x87, 0xff, 0x49, 0x44, 0x34, 0x44, 0x22, 0x19} }, /* 3 */
51 { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8b} }, /* 4 (~1) */
52 { 0x9badfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 5 (~2) */
53 { 0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 6 (~0) */
54 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} }, /* 7 (~0) */
55 { 0x12312312, 0x1231, 0x1231, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff} }, /* 8 */
56 { 0x11111111, 0x1111, 0x1111, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} } /* 9 */
57 };
58
59 /* index of "10" means "NULL" */
60 static BOOL Uuid_Comparison_Grid[11][11] = {
61 { TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE },
62 { FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
63 { FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
64 { FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
65 { FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
66 { FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE },
67 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE },
68 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE },
69 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE },
70 { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE },
71 { TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE }
72 };
73
74 static void UuidConversionAndComparison(void) {
75 CHAR strx[100], x;
76 LPSTR str = strx;
77 WCHAR wstrx[100], wx;
78 LPWSTR wstr = wstrx;
79
80 UUID Uuid1, Uuid2, *PUuid1, *PUuid2;
81 RPC_STATUS rslt;
82
83 int i1,i2;
84
85 /* Uuid Equality */
86 for (i1 = 0; i1 < 11; i1++)
87 for (i2 = 0; i2 < 11; i2++) {
88 if (i1 < 10) {
89 Uuid1 = Uuid_Table[i1];
90 PUuid1 = &Uuid1;
91 } else {
92 PUuid1 = NULL;
93 }
94 if (i2 < 10) {
95 Uuid2 = Uuid_Table[i2];
96 PUuid2 = &Uuid2;
97 } else {
98 PUuid2 = NULL;
99 }
100 ok( (UuidEqual(PUuid1, PUuid2, &rslt) == Uuid_Comparison_Grid[i1][i2]), "UUID Equality\n" );
101 }
102
103 /* Uuid to String to Uuid (char) */
104 for (i1 = 0; i1 < 10; i1++) {
105 Uuid1 = Uuid_Table[i1];
106 ok( (UuidToStringA(&Uuid1, (unsigned char**)&str) == RPC_S_OK), "Simple UUID->String copy\n" );
107 ok( (UuidFromStringA((unsigned char*)str, &Uuid2) == RPC_S_OK), "Simple String->UUID copy from generated UUID String\n" );
108 ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> String -> Uuid transform\n" );
109 /* invalid uuid tests -- size of valid UUID string=36 */
110 for (i2 = 0; i2 < 36; i2++) {
111 x = str[i2];
112 str[i2] = 'g'; /* whatever, but "g" is a good boundary condition */
113 ok( (UuidFromStringA((unsigned char*)str, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID String\n" );
114 str[i2] = x; /* change it back so remaining tests are interesting. */
115 }
116 RpcStringFreeA((unsigned char **)&str);
117 }
118
119 /* Uuid to String to Uuid (wchar) */
120 for (i1 = 0; i1 < 10; i1++) {
121 Uuid1 = Uuid_Table[i1];
122 rslt=UuidToStringW(&Uuid1, &wstr);
123 ok( (rslt == RPC_S_OK), "Simple UUID->WString copy\n" );
124 ok( (UuidFromStringW(wstr, &Uuid2) == RPC_S_OK), "Simple WString->UUID copy from generated UUID String\n" );
125 ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> WString -> Uuid transform\n" );
126 /* invalid uuid tests -- size of valid UUID string=36 */
127 for (i2 = 0; i2 < 36; i2++) {
128 wx = wstr[i2];
129 wstr[i2] = 'g'; /* whatever, but "g" is a good boundary condition */
130 ok( (UuidFromStringW(wstr, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID WString\n" );
131 wstr[i2] = wx; /* change it back so remaining tests are interesting. */
132 }
133 RpcStringFreeW(&wstr);
134 }
135 }
136
137 static void TestDceErrorInqText (void)
138 {
139 char bufferInvalid [1024];
140 char buffer [1024]; /* The required size is not documented but would
141 * appear to be 256.
142 */
143 DWORD dwCount;
144
145 dwCount = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
146 FORMAT_MESSAGE_IGNORE_INSERTS,
147 NULL, RPC_S_NOT_RPC_ERROR, 0, bufferInvalid,
148 sizeof(bufferInvalid)/sizeof(bufferInvalid[0]), NULL);
149
150 /* A random sample of DceErrorInqText */
151 /* 0 is success */
152 ok ((DceErrorInqTextA (0, (unsigned char*)buffer) == RPC_S_OK),
153 "DceErrorInqTextA(0...)\n");
154 /* A real RPC_S error */
155 ok ((DceErrorInqTextA (RPC_S_INVALID_STRING_UUID, (unsigned char*)buffer) == RPC_S_OK),
156 "DceErrorInqTextA(valid...)\n");
157
158 if (dwCount)
159 {
160 /* A message for which FormatMessage should fail
161 * which should return RPC_S_OK and the
162 * fixed "not valid" message
163 */
164 ok ((DceErrorInqTextA (35, (unsigned char*)buffer) == RPC_S_OK &&
165 strcmp (buffer, bufferInvalid) == 0),
166 "DceErrorInqTextA(unformattable...)\n");
167 /* One for which FormatMessage should succeed but
168 * DceErrorInqText should "fail"
169 * 3814 is generally quite a long message
170 */
171 ok ((DceErrorInqTextA (3814, (unsigned char*)buffer) == RPC_S_OK &&
172 strcmp (buffer, bufferInvalid) == 0),
173 "DceErrorInqTextA(deviation...)\n");
174 }
175 else
176 ok (0, "Cannot set up for DceErrorInqText\n");
177 }
178
179 static RPC_DISPATCH_FUNCTION IFoo_table[] =
180 {
181 0
182 };
183
184 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable =
185 {
186 0,
187 IFoo_table
188 };
189
190 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface =
191 {
192 sizeof(RPC_SERVER_INTERFACE),
193 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
194 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
195 &IFoo_v0_0_DispatchTable,
196 0,
197 0,
198 0,
199 0,
200 0,
201 };
202
203 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec = (RPC_IF_HANDLE)& IFoo___RpcServerInterface;
204
205 static void test_rpc_ncacn_ip_tcp(void)
206 {
207 RPC_STATUS status;
208 unsigned char *binding, *principal;
209 handle_t IFoo_IfHandle;
210 ULONG level, authnsvc, authzsvc;
211 RPC_AUTH_IDENTITY_HANDLE identity;
212 static unsigned char foo[] = "foo";
213 static unsigned char ncacn_ip_tcp[] = "ncacn_ip_tcp";
214 static unsigned char address[] = "127.0.0.1";
215 static unsigned char endpoint[] = "4114";
216 static unsigned char spn[] = "principal";
217
218 status = RpcNetworkIsProtseqValidA(foo);
219 ok(status == RPC_S_INVALID_RPC_PROTSEQ, "return wrong\n");
220
221 status = RpcNetworkIsProtseqValidA(ncacn_ip_tcp);
222 ok(status == RPC_S_OK, "return wrong\n");
223
224 status = RpcMgmtStopServerListening(NULL);
225 ok(status == RPC_S_NOT_LISTENING,
226 "wrong RpcMgmtStopServerListening error (%u)\n", status);
227
228 status = RpcMgmtWaitServerListen();
229 ok(status == RPC_S_NOT_LISTENING,
230 "wrong RpcMgmtWaitServerListen error status (%u)\n", status);
231
232 status = RpcServerListen(1, 20, FALSE);
233 ok(status == RPC_S_NO_PROTSEQS_REGISTERED,
234 "wrong RpcServerListen error (%u)\n", status);
235
236 status = RpcServerUseProtseqEpA(ncacn_ip_tcp, 20, endpoint, NULL);
237 ok(status == RPC_S_OK, "RpcServerUseProtseqEp failed (%u)\n", status);
238
239 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
240 ok(status == RPC_S_OK, "RpcServerRegisterIf failed (%u)\n", status);
241
242 status = RpcServerListen(1, 20, TRUE);
243 ok(status == RPC_S_OK, "RpcServerListen failed (%u)\n", status);
244
245 status = RpcServerListen(1, 20, TRUE);
246 todo_wine {
247 ok(status == RPC_S_ALREADY_LISTENING,
248 "wrong RpcServerListen error (%u)\n", status);
249 }
250
251 status = RpcStringBindingComposeA(NULL, ncacn_ip_tcp, address,
252 endpoint, NULL, &binding);
253 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);
254
255 status = RpcBindingFromStringBindingA(binding, &IFoo_IfHandle);
256 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n",
257 status);
258
259 status = RpcBindingSetAuthInfoA(IFoo_IfHandle, NULL, RPC_C_AUTHN_LEVEL_NONE,
260 RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME);
261 ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status);
262
263 status = RpcBindingInqAuthInfoA(IFoo_IfHandle, NULL, NULL, NULL, NULL, NULL);
264 ok(status == RPC_S_BINDING_HAS_NO_AUTH, "RpcBindingInqAuthInfo failed (%u)\n",
265 status);
266
267 status = RpcBindingSetAuthInfoA(IFoo_IfHandle, spn, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
268 RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NAME);
269 ok(status == RPC_S_OK, "RpcBindingSetAuthInfo failed (%u)\n", status);
270
271 level = authnsvc = authzsvc = 0;
272 principal = (unsigned char *)0xdeadbeef;
273 identity = (RPC_AUTH_IDENTITY_HANDLE *)0xdeadbeef;
274 status = RpcBindingInqAuthInfoA(IFoo_IfHandle, &principal, &level, &authnsvc,
275 &identity, &authzsvc);
276
277 ok(status == RPC_S_OK, "RpcBindingInqAuthInfo failed (%u)\n", status);
278 ok(identity == NULL, "expected NULL identity, got %p\n", identity);
279 ok(principal != (unsigned char *)0xdeadbeef, "expected valid principal, got %p\n", principal);
280 ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "expected RPC_C_AUTHN_LEVEL_PKT_PRIVACY, got %d\n", level);
281 ok(authnsvc == RPC_C_AUTHN_WINNT, "expected RPC_C_AUTHN_WINNT, got %d\n", authnsvc);
282 todo_wine ok(authzsvc == RPC_C_AUTHZ_NAME, "expected RPC_C_AUTHZ_NAME, got %d\n", authzsvc);
283 if (status == RPC_S_OK) RpcStringFreeA(&principal);
284
285 status = RpcMgmtStopServerListening(NULL);
286 ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n",
287 status);
288
289 status = RpcMgmtStopServerListening(NULL);
290 ok(status == RPC_S_OK, "RpcMgmtStopServerListening failed (%u)\n",
291 status);
292
293 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
294 ok(status == RPC_S_OK, "RpcServerUnregisterIf failed (%u)\n", status);
295
296 status = RpcMgmtWaitServerListen();
297 todo_wine {
298 ok(status == RPC_S_OK, "RpcMgmtWaitServerListen failed (%u)\n", status);
299 }
300
301 status = RpcStringFreeA(&binding);
302 ok(status == RPC_S_OK, "RpcStringFree failed (%u)\n", status);
303
304 status = RpcBindingFree(&IFoo_IfHandle);
305 ok(status == RPC_S_OK, "RpcBindingFree failed (%u)\n", status);
306 }
307
308 /* this is what's generated with MS/RPC - it includes an extra 2
309 * bytes in the protocol floor */
310 static const unsigned char tower_data_tcp_ip1[] =
311 {
312 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
313 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
314 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
315 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
316 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
317 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
318 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x02,
319 0x00,0x00,0x00,0x01,0x00,0x07,0x02,0x00,
320 0x00,0x87,0x01,0x00,0x09,0x04,0x00,0x0a,
321 0x00,0x00,0x01,
322 };
323 /* this is the optimal data that i think should be generated */
324 static const unsigned char tower_data_tcp_ip2[] =
325 {
326 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
327 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
328 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
329 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
330 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
331 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
332 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x00,
333 0x00,0x01,0x00,0x07,0x02,0x00,0x00,0x87,
334 0x01,0x00,0x09,0x04,0x00,0x0a,0x00,0x00,
335 0x01,
336 };
337
338 static void test_towers(void)
339 {
340 RPC_STATUS ret;
341 twr_t *tower;
342 static const RPC_SYNTAX_IDENTIFIER mapi_if_id = { { 0xa4f1db00, 0xca47, 0x1067, { 0xb3, 0x1f, 0x00, 0xdd, 0x01, 0x06, 0x62, 0xda } }, { 0, 0 } };
343 static const RPC_SYNTAX_IDENTIFIER ndr_syntax = { { 0x8a885d04, 0x1ceb, 0x11c9, { 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60 } }, { 2, 0 } };
344 RPC_SYNTAX_IDENTIFIER object, syntax;
345 char *protseq, *endpoint, *address;
346 BOOL same;
347
348 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_ip_tcp", "135", "10.0.0.1", &tower);
349 ok(ret == RPC_S_OK ||
350 broken(ret == RPC_S_INVALID_RPC_PROTSEQ), /* Vista */
351 "TowerConstruct failed with error %d\n", ret);
352 if (ret == RPC_S_INVALID_RPC_PROTSEQ)
353 {
354 /* Windows Vista fails with this error and crashes if we continue */
355 win_skip("TowerConstruct failed, we are most likely on Windows Vista\n");
356 return;
357 }
358
359 /* first check we have the right amount of data */
360 ok(tower->tower_length == sizeof(tower_data_tcp_ip1) ||
361 tower->tower_length == sizeof(tower_data_tcp_ip2),
362 "Wrong size of tower %d\n", tower->tower_length);
363
364 /* then do a byte-by-byte comparison */
365 same = ((tower->tower_length == sizeof(tower_data_tcp_ip1)) &&
366 !memcmp(&tower->tower_octet_string, tower_data_tcp_ip1, sizeof(tower_data_tcp_ip1))) ||
367 ((tower->tower_length == sizeof(tower_data_tcp_ip2)) &&
368 !memcmp(&tower->tower_octet_string, tower_data_tcp_ip2, sizeof(tower_data_tcp_ip2)));
369
370 ok(same, "Tower data differs\n");
371 if (!same)
372 {
373 unsigned32 i;
374 for (i = 0; i < tower->tower_length; i++)
375 {
376 if (i % 8 == 0) printf(" ");
377 printf("0x%02x,", tower->tower_octet_string[i]);
378 if (i % 8 == 7) printf("\n");
379 }
380 printf("\n");
381 }
382
383 ret = TowerExplode(tower, &object, &syntax, &protseq, &endpoint, &address);
384 ok(ret == RPC_S_OK, "TowerExplode failed with error %d\n", ret);
385 ok(!memcmp(&object, &mapi_if_id, sizeof(mapi_if_id)), "object id didn't match\n");
386 ok(!memcmp(&syntax, &ndr_syntax, sizeof(syntax)), "syntax id didn't match\n");
387 ok(!strcmp(protseq, "ncacn_ip_tcp"), "protseq was \"%s\" instead of \"ncacn_ip_tcp\"\n", protseq);
388 ok(!strcmp(endpoint, "135"), "endpoint was \"%s\" instead of \"135\"\n", endpoint);
389 ok(!strcmp(address, "10.0.0.1"), "address was \"%s\" instead of \"10.0.0.1\"\n", address);
390
391 I_RpcFree(protseq);
392 I_RpcFree(endpoint);
393 I_RpcFree(address);
394
395 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, NULL);
396 ok(ret == RPC_S_OK, "TowerExplode failed with error %d\n", ret);
397
398 I_RpcFree(tower);
399
400 /* test the behaviour for ip_tcp with name instead of dotted IP notation */
401 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_ip_tcp", "135", "localhost", &tower);
402 ok(ret == RPC_S_OK, "TowerConstruct failed with error %d\n", ret);
403 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, &address);
404 ok(ret == RPC_S_OK, "TowerExplode failed with error %d\n", ret);
405 ok(!strcmp(address, "0.0.0.0") ||
406 broken(!strcmp(address, "255.255.255.255")),
407 "address was \"%s\" instead of \"0.0.0.0\"\n", address);
408
409 I_RpcFree(address);
410 I_RpcFree(tower);
411
412 /* test the behaviour for np with no address */
413 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_np", "\\pipe\\test", NULL, &tower);
414 ok(ret == RPC_S_OK, "TowerConstruct failed with error %d\n", ret);
415 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, &address);
416 ok(ret == RPC_S_OK ||
417 broken(ret != RPC_S_OK), /* win2k, indeterminate */
418 "TowerExplode failed with error %d\n", ret);
419 /* Windows XP SP3 sets address to NULL */
420 ok(!address || !strcmp(address, ""), "address was \"%s\" instead of \"\" or NULL (XP SP3)\n", address);
421
422 I_RpcFree(address);
423 I_RpcFree(tower);
424 }
425
426 static void test_I_RpcMapWin32Status(void)
427 {
428 LONG win32status;
429 RPC_STATUS rpc_status;
430 BOOL w2k3_up = FALSE;
431
432 /* Windows 2003 and above return STATUS_UNSUCCESSFUL if given an unknown status */
433 win32status = I_RpcMapWin32Status(9999);
434 if (win32status == STATUS_UNSUCCESSFUL)
435 w2k3_up = TRUE;
436
437 /* On Windows XP-SP1 and below some statuses are not mapped and return
438 * the given status
439 */
440 for (rpc_status = 0; rpc_status < 10000; rpc_status++)
441 {
442 LONG expected_win32status;
443 BOOL missing = FALSE;
444
445 win32status = I_RpcMapWin32Status(rpc_status);
446 switch (rpc_status)
447 {
448 case ERROR_SUCCESS: expected_win32status = ERROR_SUCCESS; break;
449 case ERROR_ACCESS_DENIED: expected_win32status = STATUS_ACCESS_DENIED; break;
450 case ERROR_INVALID_HANDLE: expected_win32status = RPC_NT_SS_CONTEXT_MISMATCH; break;
451 case ERROR_OUTOFMEMORY: expected_win32status = STATUS_NO_MEMORY; break;
452 case ERROR_INVALID_PARAMETER: expected_win32status = STATUS_INVALID_PARAMETER; break;
453 case ERROR_INSUFFICIENT_BUFFER: expected_win32status = STATUS_BUFFER_TOO_SMALL; break;
454 case ERROR_MAX_THRDS_REACHED: expected_win32status = STATUS_NO_MEMORY; break;
455 case ERROR_NOACCESS: expected_win32status = STATUS_ACCESS_VIOLATION; break;
456 case ERROR_NOT_ENOUGH_SERVER_MEMORY: expected_win32status = STATUS_INSUFF_SERVER_RESOURCES; break;
457 case ERROR_WRONG_PASSWORD: expected_win32status = STATUS_WRONG_PASSWORD; missing = TRUE; break;
458 case ERROR_INVALID_LOGON_HOURS: expected_win32status = STATUS_INVALID_LOGON_HOURS; missing = TRUE; break;
459 case ERROR_PASSWORD_EXPIRED: expected_win32status = STATUS_PASSWORD_EXPIRED; missing = TRUE; break;
460 case ERROR_ACCOUNT_DISABLED: expected_win32status = STATUS_ACCOUNT_DISABLED; missing = TRUE; break;
461 case ERROR_INVALID_SECURITY_DESCR: expected_win32status = STATUS_INVALID_SECURITY_DESCR; break;
462 case RPC_S_INVALID_STRING_BINDING: expected_win32status = RPC_NT_INVALID_STRING_BINDING; break;
463 case RPC_S_WRONG_KIND_OF_BINDING: expected_win32status = RPC_NT_WRONG_KIND_OF_BINDING; break;
464 case RPC_S_INVALID_BINDING: expected_win32status = RPC_NT_INVALID_BINDING; break;
465 case RPC_S_PROTSEQ_NOT_SUPPORTED: expected_win32status = RPC_NT_PROTSEQ_NOT_SUPPORTED; break;
466 case RPC_S_INVALID_RPC_PROTSEQ: expected_win32status = RPC_NT_INVALID_RPC_PROTSEQ; break;
467 case RPC_S_INVALID_STRING_UUID: expected_win32status = RPC_NT_INVALID_STRING_UUID; break;
468 case RPC_S_INVALID_ENDPOINT_FORMAT: expected_win32status = RPC_NT_INVALID_ENDPOINT_FORMAT; break;
469 case RPC_S_INVALID_NET_ADDR: expected_win32status = RPC_NT_INVALID_NET_ADDR; break;
470 case RPC_S_NO_ENDPOINT_FOUND: expected_win32status = RPC_NT_NO_ENDPOINT_FOUND; break;
471 case RPC_S_INVALID_TIMEOUT: expected_win32status = RPC_NT_INVALID_TIMEOUT; break;
472 case RPC_S_OBJECT_NOT_FOUND: expected_win32status = RPC_NT_OBJECT_NOT_FOUND; break;
473 case RPC_S_ALREADY_REGISTERED: expected_win32status = RPC_NT_ALREADY_REGISTERED; break;
474 case RPC_S_TYPE_ALREADY_REGISTERED: expected_win32status = RPC_NT_TYPE_ALREADY_REGISTERED; break;
475 case RPC_S_ALREADY_LISTENING: expected_win32status = RPC_NT_ALREADY_LISTENING; break;
476 case RPC_S_NO_PROTSEQS_REGISTERED: expected_win32status = RPC_NT_NO_PROTSEQS_REGISTERED; break;
477 case RPC_S_NOT_LISTENING: expected_win32status = RPC_NT_NOT_LISTENING; break;
478 case RPC_S_UNKNOWN_MGR_TYPE: expected_win32status = RPC_NT_UNKNOWN_MGR_TYPE; break;
479 case RPC_S_UNKNOWN_IF: expected_win32status = RPC_NT_UNKNOWN_IF; break;
480 case RPC_S_NO_BINDINGS: expected_win32status = RPC_NT_NO_BINDINGS; break;
481 case RPC_S_NO_PROTSEQS: expected_win32status = RPC_NT_NO_PROTSEQS; break;
482 case RPC_S_CANT_CREATE_ENDPOINT: expected_win32status = RPC_NT_CANT_CREATE_ENDPOINT; break;
483 case RPC_S_OUT_OF_RESOURCES: expected_win32status = RPC_NT_OUT_OF_RESOURCES; break;
484 case RPC_S_SERVER_UNAVAILABLE: expected_win32status = RPC_NT_SERVER_UNAVAILABLE; break;
485 case RPC_S_SERVER_TOO_BUSY: expected_win32status = RPC_NT_SERVER_TOO_BUSY; break;
486 case RPC_S_INVALID_NETWORK_OPTIONS: expected_win32status = RPC_NT_INVALID_NETWORK_OPTIONS; break;
487 case RPC_S_NO_CALL_ACTIVE: expected_win32status = RPC_NT_NO_CALL_ACTIVE; break;
488 case RPC_S_CALL_FAILED: expected_win32status = RPC_NT_CALL_FAILED; break;
489 case RPC_S_CALL_FAILED_DNE: expected_win32status = RPC_NT_CALL_FAILED_DNE; break;
490 case RPC_S_PROTOCOL_ERROR: expected_win32status = RPC_NT_PROTOCOL_ERROR; break;
491 case RPC_S_UNSUPPORTED_TRANS_SYN: expected_win32status = RPC_NT_UNSUPPORTED_TRANS_SYN; break;
492 case RPC_S_UNSUPPORTED_TYPE: expected_win32status = RPC_NT_UNSUPPORTED_TYPE; break;
493 case RPC_S_INVALID_TAG: expected_win32status = RPC_NT_INVALID_TAG; break;
494 case RPC_S_INVALID_BOUND: expected_win32status = RPC_NT_INVALID_BOUND; break;
495 case RPC_S_NO_ENTRY_NAME: expected_win32status = RPC_NT_NO_ENTRY_NAME; break;
496 case RPC_S_INVALID_NAME_SYNTAX: expected_win32status = RPC_NT_INVALID_NAME_SYNTAX; break;
497 case RPC_S_UNSUPPORTED_NAME_SYNTAX: expected_win32status = RPC_NT_UNSUPPORTED_NAME_SYNTAX; break;
498 case RPC_S_UUID_NO_ADDRESS: expected_win32status = RPC_NT_UUID_NO_ADDRESS; break;
499 case RPC_S_DUPLICATE_ENDPOINT: expected_win32status = RPC_NT_DUPLICATE_ENDPOINT; break;
500 case RPC_S_UNKNOWN_AUTHN_TYPE: expected_win32status = RPC_NT_UNKNOWN_AUTHN_TYPE; break;
501 case RPC_S_MAX_CALLS_TOO_SMALL: expected_win32status = RPC_NT_MAX_CALLS_TOO_SMALL; break;
502 case RPC_S_STRING_TOO_LONG: expected_win32status = RPC_NT_STRING_TOO_LONG; break;
503 case RPC_S_PROTSEQ_NOT_FOUND: expected_win32status = RPC_NT_PROTSEQ_NOT_FOUND; break;
504 case RPC_S_PROCNUM_OUT_OF_RANGE: expected_win32status = RPC_NT_PROCNUM_OUT_OF_RANGE; break;
505 case RPC_S_BINDING_HAS_NO_AUTH: expected_win32status = RPC_NT_BINDING_HAS_NO_AUTH; break;
506 case RPC_S_UNKNOWN_AUTHN_SERVICE: expected_win32status = RPC_NT_UNKNOWN_AUTHN_SERVICE; break;
507 case RPC_S_UNKNOWN_AUTHN_LEVEL: expected_win32status = RPC_NT_UNKNOWN_AUTHN_LEVEL; break;
508 case RPC_S_INVALID_AUTH_IDENTITY: expected_win32status = RPC_NT_INVALID_AUTH_IDENTITY; break;
509 case RPC_S_UNKNOWN_AUTHZ_SERVICE: expected_win32status = RPC_NT_UNKNOWN_AUTHZ_SERVICE; break;
510 case EPT_S_INVALID_ENTRY: expected_win32status = EPT_NT_INVALID_ENTRY; break;
511 case EPT_S_CANT_PERFORM_OP: expected_win32status = EPT_NT_CANT_PERFORM_OP; break;
512 case EPT_S_NOT_REGISTERED: expected_win32status = EPT_NT_NOT_REGISTERED; break;
513 case EPT_S_CANT_CREATE: expected_win32status = EPT_NT_CANT_CREATE; break;
514 case RPC_S_NOTHING_TO_EXPORT: expected_win32status = RPC_NT_NOTHING_TO_EXPORT; break;
515 case RPC_S_INCOMPLETE_NAME: expected_win32status = RPC_NT_INCOMPLETE_NAME; break;
516 case RPC_S_INVALID_VERS_OPTION: expected_win32status = RPC_NT_INVALID_VERS_OPTION; break;
517 case RPC_S_NO_MORE_MEMBERS: expected_win32status = RPC_NT_NO_MORE_MEMBERS; break;
518 case RPC_S_NOT_ALL_OBJS_UNEXPORTED: expected_win32status = RPC_NT_NOT_ALL_OBJS_UNEXPORTED; break;
519 case RPC_S_INTERFACE_NOT_FOUND: expected_win32status = RPC_NT_INTERFACE_NOT_FOUND; break;
520 case RPC_S_ENTRY_ALREADY_EXISTS: expected_win32status = RPC_NT_ENTRY_ALREADY_EXISTS; break;
521 case RPC_S_ENTRY_NOT_FOUND: expected_win32status = RPC_NT_ENTRY_NOT_FOUND; break;
522 case RPC_S_NAME_SERVICE_UNAVAILABLE: expected_win32status = RPC_NT_NAME_SERVICE_UNAVAILABLE; break;
523 case RPC_S_INVALID_NAF_ID: expected_win32status = RPC_NT_INVALID_NAF_ID; break;
524 case RPC_S_CANNOT_SUPPORT: expected_win32status = RPC_NT_CANNOT_SUPPORT; break;
525 case RPC_S_NO_CONTEXT_AVAILABLE: expected_win32status = RPC_NT_NO_CONTEXT_AVAILABLE; break;
526 case RPC_S_INTERNAL_ERROR: expected_win32status = RPC_NT_INTERNAL_ERROR; break;
527 case RPC_S_ZERO_DIVIDE: expected_win32status = RPC_NT_ZERO_DIVIDE; break;
528 case RPC_S_ADDRESS_ERROR: expected_win32status = RPC_NT_ADDRESS_ERROR; break;
529 case RPC_S_FP_DIV_ZERO: expected_win32status = RPC_NT_FP_DIV_ZERO; break;
530 case RPC_S_FP_UNDERFLOW: expected_win32status = RPC_NT_FP_UNDERFLOW; break;
531 case RPC_S_FP_OVERFLOW: expected_win32status = RPC_NT_FP_OVERFLOW; break;
532 case RPC_S_CALL_IN_PROGRESS: expected_win32status = RPC_NT_CALL_IN_PROGRESS; break;
533 case RPC_S_NO_MORE_BINDINGS: expected_win32status = RPC_NT_NO_MORE_BINDINGS; break;
534 case RPC_S_CALL_CANCELLED: expected_win32status = RPC_NT_CALL_CANCELLED; missing = TRUE; break;
535 case RPC_S_INVALID_OBJECT: expected_win32status = RPC_NT_INVALID_OBJECT; break;
536 case RPC_S_INVALID_ASYNC_HANDLE: expected_win32status = RPC_NT_INVALID_ASYNC_HANDLE; missing = TRUE; break;
537 case RPC_S_INVALID_ASYNC_CALL: expected_win32status = RPC_NT_INVALID_ASYNC_CALL; missing = TRUE; break;
538 case RPC_S_GROUP_MEMBER_NOT_FOUND: expected_win32status = RPC_NT_GROUP_MEMBER_NOT_FOUND; break;
539 case RPC_X_NO_MORE_ENTRIES: expected_win32status = RPC_NT_NO_MORE_ENTRIES; break;
540 case RPC_X_SS_CHAR_TRANS_OPEN_FAIL: expected_win32status = RPC_NT_SS_CHAR_TRANS_OPEN_FAIL; break;
541 case RPC_X_SS_CHAR_TRANS_SHORT_FILE: expected_win32status = RPC_NT_SS_CHAR_TRANS_SHORT_FILE; break;
542 case RPC_X_SS_IN_NULL_CONTEXT: expected_win32status = RPC_NT_SS_IN_NULL_CONTEXT; break;
543 case RPC_X_SS_CONTEXT_DAMAGED: expected_win32status = RPC_NT_SS_CONTEXT_DAMAGED; break;
544 case RPC_X_SS_HANDLES_MISMATCH: expected_win32status = RPC_NT_SS_HANDLES_MISMATCH; break;
545 case RPC_X_SS_CANNOT_GET_CALL_HANDLE: expected_win32status = RPC_NT_SS_CANNOT_GET_CALL_HANDLE; break;
546 case RPC_X_NULL_REF_POINTER: expected_win32status = RPC_NT_NULL_REF_POINTER; break;
547 case RPC_X_ENUM_VALUE_OUT_OF_RANGE: expected_win32status = RPC_NT_ENUM_VALUE_OUT_OF_RANGE; break;
548 case RPC_X_BYTE_COUNT_TOO_SMALL: expected_win32status = RPC_NT_BYTE_COUNT_TOO_SMALL; break;
549 case RPC_X_BAD_STUB_DATA: expected_win32status = RPC_NT_BAD_STUB_DATA; break;
550 case RPC_X_PIPE_CLOSED: expected_win32status = RPC_NT_PIPE_CLOSED; missing = TRUE; break;
551 case RPC_X_PIPE_DISCIPLINE_ERROR: expected_win32status = RPC_NT_PIPE_DISCIPLINE_ERROR; missing = TRUE; break;
552 case RPC_X_PIPE_EMPTY: expected_win32status = RPC_NT_PIPE_EMPTY; missing = TRUE; break;
553 case ERROR_PASSWORD_MUST_CHANGE: expected_win32status = STATUS_PASSWORD_MUST_CHANGE; missing = TRUE; break;
554 case ERROR_ACCOUNT_LOCKED_OUT: expected_win32status = STATUS_ACCOUNT_LOCKED_OUT; missing = TRUE; break;
555 default:
556 if (w2k3_up)
557 expected_win32status = STATUS_UNSUCCESSFUL;
558 else
559 expected_win32status = rpc_status;
560 }
561
562 ok(win32status == expected_win32status ||
563 broken(missing && win32status == rpc_status),
564 "I_RpcMapWin32Status(%d) should have returned 0x%x instead of 0x%x%s\n",
565 rpc_status, expected_win32status, win32status,
566 broken(missing) ? " (or have returned with the given status)" : "");
567 }
568 }
569
570 static void test_RpcStringBindingParseA(void)
571 {
572 static unsigned char valid_binding[] = "00000000-0000-0000-c000-000000000046@ncacn_np:.[endpoint=\\pipe\\test]";
573 static unsigned char valid_binding2[] = "00000000-0000-0000-c000-000000000046@ncacn_np:.[\\pipe\\test]";
574 static unsigned char invalid_uuid_binding[] = "{00000000-0000-0000-c000-000000000046}@ncacn_np:.[endpoint=\\pipe\\test]";
575 static unsigned char invalid_ep_binding[] = "00000000-0000-0000-c000-000000000046@ncacn_np:.[endpoint=test]";
576 static unsigned char invalid_binding[] = "00000000-0000-0000-c000-000000000046@ncacn_np";
577 RPC_STATUS status;
578 unsigned char *uuid;
579 unsigned char *protseq;
580 unsigned char *network_addr;
581 unsigned char *endpoint;
582 unsigned char *options;
583
584 /* test all parameters */
585 status = RpcStringBindingParseA(valid_binding, &uuid, &protseq, &network_addr, &endpoint, &options);
586 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
587 ok(!strcmp((char *)uuid, "00000000-0000-0000-c000-000000000046"), "uuid should have been 00000000-0000-0000-C000-000000000046 instead of %s\n", uuid);
588 ok(!strcmp((char *)protseq, "ncacn_np"), "protseq should have been ncacn_np instead of %s\n", protseq);
589 ok(!strcmp((char *)network_addr, "."), "network_addr should have been . instead of %s\n", network_addr);
590 ok(!strcmp((char *)endpoint, "pipetest"), "endpoint should have been pipetest instead of %s\n", endpoint);
591 if (options)
592 ok(!strcmp((char *)options, ""), "options should have been \"\" of \"%s\"\n", options);
593 else
594 todo_wine ok(FALSE, "options is NULL\n");
595 RpcStringFreeA(&uuid);
596 RpcStringFreeA(&protseq);
597 RpcStringFreeA(&network_addr);
598 RpcStringFreeA(&endpoint);
599 RpcStringFreeA(&options);
600
601 /* test all parameters with different type of string binding */
602 status = RpcStringBindingParseA(valid_binding2, &uuid, &protseq, &network_addr, &endpoint, &options);
603 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
604 ok(!strcmp((char *)uuid, "00000000-0000-0000-c000-000000000046"), "uuid should have been 00000000-0000-0000-C000-000000000046 instead of %s\n", uuid);
605 ok(!strcmp((char *)protseq, "ncacn_np"), "protseq should have been ncacn_np instead of %s\n", protseq);
606 ok(!strcmp((char *)network_addr, "."), "network_addr should have been . instead of %s\n", network_addr);
607 ok(!strcmp((char *)endpoint, "pipetest"), "endpoint should have been pipetest instead of %s\n", endpoint);
608 if (options)
609 ok(!strcmp((char *)options, ""), "options should have been \"\" of \"%s\"\n", options);
610 else
611 todo_wine ok(FALSE, "options is NULL\n");
612 RpcStringFreeA(&uuid);
613 RpcStringFreeA(&protseq);
614 RpcStringFreeA(&network_addr);
615 RpcStringFreeA(&endpoint);
616 RpcStringFreeA(&options);
617
618 /* test with as many parameters NULL as possible */
619 status = RpcStringBindingParseA(valid_binding, NULL, &protseq, NULL, NULL, NULL);
620 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
621 ok(!strcmp((char *)protseq, "ncacn_np"), "protseq should have been ncacn_np instead of %s\n", protseq);
622 RpcStringFreeA(&protseq);
623
624 /* test with invalid uuid */
625 status = RpcStringBindingParseA(invalid_uuid_binding, NULL, &protseq, NULL, NULL, NULL);
626 ok(status == RPC_S_INVALID_STRING_UUID, "RpcStringBindingParseA should have returned RPC_S_INVALID_STRING_UUID instead of %d\n", status);
627 ok(protseq == NULL, "protseq was %p instead of NULL\n", protseq);
628
629 /* test with invalid endpoint */
630 status = RpcStringBindingParseA(invalid_ep_binding, NULL, &protseq, NULL, NULL, NULL);
631 ok(status == RPC_S_OK, "RpcStringBindingParseA failed with error %d\n", status);
632 RpcStringFreeA(&protseq);
633
634 /* test with invalid binding */
635 status = RpcStringBindingParseA(invalid_binding, &uuid, &protseq, &network_addr, &endpoint, &options);
636 todo_wine
637 ok(status == RPC_S_INVALID_STRING_BINDING, "RpcStringBindingParseA should have returned RPC_S_INVALID_STRING_BINDING instead of %d\n", status);
638 todo_wine
639 ok(uuid == NULL, "uuid was %p instead of NULL\n", uuid);
640 if (uuid)
641 RpcStringFreeA(&uuid);
642 ok(protseq == NULL, "protseq was %p instead of NULL\n", protseq);
643 todo_wine
644 ok(network_addr == NULL, "network_addr was %p instead of NULL\n", network_addr);
645 if (network_addr)
646 RpcStringFreeA(&network_addr);
647 ok(endpoint == NULL, "endpoint was %p instead of NULL\n", endpoint);
648 ok(options == NULL, "options was %p instead of NULL\n", options);
649 }
650
651 static void test_I_RpcExceptionFilter(void)
652 {
653 ULONG exception;
654 int retval;
655 int (WINAPI *pI_RpcExceptionFilter)(ULONG) = (void *)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "I_RpcExceptionFilter");
656
657 if (!pI_RpcExceptionFilter)
658 {
659 win_skip("I_RpcExceptionFilter not exported\n");
660 return;
661 }
662
663 for (exception = 0; exception < STATUS_REG_NAT_CONSUMPTION; exception++)
664 {
665 /* skip over uninteresting bits of the number space */
666 if (exception == 2000) exception = 0x40000000;
667 if (exception == 0x40000005) exception = 0x80000000;
668 if (exception == 0x80000005) exception = 0xc0000000;
669
670 retval = pI_RpcExceptionFilter(exception);
671 switch (exception)
672 {
673 case STATUS_DATATYPE_MISALIGNMENT:
674 case STATUS_BREAKPOINT:
675 case STATUS_ACCESS_VIOLATION:
676 case STATUS_ILLEGAL_INSTRUCTION:
677 case STATUS_PRIVILEGED_INSTRUCTION:
678 case STATUS_INSTRUCTION_MISALIGNMENT:
679 case STATUS_STACK_OVERFLOW:
680 case STATUS_POSSIBLE_DEADLOCK:
681 ok(retval == EXCEPTION_CONTINUE_SEARCH, "I_RpcExceptionFilter(0x%x) should have returned %d instead of %d\n",
682 exception, EXCEPTION_CONTINUE_SEARCH, retval);
683 break;
684 case STATUS_GUARD_PAGE_VIOLATION:
685 case STATUS_IN_PAGE_ERROR:
686 case STATUS_HANDLE_NOT_CLOSABLE:
687 trace("I_RpcExceptionFilter(0x%x) returned %d\n", exception, retval);
688 break;
689 default:
690 ok(retval == EXCEPTION_EXECUTE_HANDLER, "I_RpcExceptionFilter(0x%x) should have returned %d instead of %d\n",
691 exception, EXCEPTION_EXECUTE_HANDLER, retval);
692 }
693 }
694 }
695
696 static void test_RpcStringBindingFromBinding(void)
697 {
698 static unsigned char ncacn_np[] = "ncacn_np";
699 static unsigned char address[] = ".";
700 static unsigned char endpoint[] = "\\pipe\\wine_rpc_test";
701 RPC_STATUS status;
702 handle_t handle;
703 RPC_CSTR binding;
704
705 status = RpcStringBindingComposeA(NULL, ncacn_np, address,
706 endpoint, NULL, &binding);
707 ok(status == RPC_S_OK, "RpcStringBindingCompose failed (%u)\n", status);
708
709 status = RpcBindingFromStringBindingA(binding, &handle);
710 ok(status == RPC_S_OK, "RpcBindingFromStringBinding failed (%u)\n", status);
711 RpcStringFreeA(&binding);
712
713 status = RpcBindingToStringBindingA(handle, &binding);
714 ok(status == RPC_S_OK, "RpcStringBindingFromBinding failed with error %u\n", status);
715
716 ok(!strcmp((const char *)binding, "ncacn_np:.[\\\\pipe\\\\wine_rpc_test]"),
717 "binding string didn't match what was expected: \"%s\"\n", binding);
718 RpcStringFreeA(&binding);
719
720 status = RpcBindingFree(&handle);
721 ok(status == RPC_S_OK, "RpcBindingFree failed with error %u\n", status);
722 }
723
724 static void test_UuidCreate(void)
725 {
726 UUID guid;
727 BYTE version;
728
729 UuidCreate(&guid);
730 version = (guid.Data3 & 0xf000) >> 12;
731 ok(version == 4 || broken(version == 1), "unexpected version %d\n",
732 version);
733 if (version == 4)
734 {
735 static UUID v4and = { 0, 0, 0x4000, { 0x80,0,0,0,0,0,0,0 } };
736 static UUID v4or = { 0xffffffff, 0xffff, 0x4fff,
737 { 0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff } };
738 UUID and, or;
739 RPC_STATUS rslt;
740 int i;
741
742 and = guid;
743 or = guid;
744 /* Generate a bunch of UUIDs and mask them. By the end, we expect
745 * every randomly generated bit to have been zero at least once,
746 * resulting in no bits set in the and mask except those which are not
747 * randomly generated: the version number and the topmost bits of the
748 * Data4 field (treated as big-endian.) Similarly, we expect only
749 * the bits which are not randomly set to be cleared in the or mask.
750 */
751 for (i = 0; i < 1000; i++)
752 {
753 LPBYTE src, dst;
754
755 UuidCreate(&guid);
756 for (src = (LPBYTE)&guid, dst = (LPBYTE)&and;
757 src - (LPBYTE)&guid < sizeof(guid); src++, dst++)
758 *dst &= *src;
759 for (src = (LPBYTE)&guid, dst = (LPBYTE)&or;
760 src - (LPBYTE)&guid < sizeof(guid); src++, dst++)
761 *dst |= *src;
762 }
763 ok(UuidEqual(&and, &v4and, &rslt),
764 "unexpected bits set in V4 UUID: %s\n", wine_dbgstr_guid(&and));
765 ok(UuidEqual(&or, &v4or, &rslt),
766 "unexpected bits set in V4 UUID: %s\n", wine_dbgstr_guid(&or));
767 }
768 else
769 {
770 /* Older versions of Windows generate V1 UUIDs. For these, there are
771 * many stable bits, including at least the MAC address if one is
772 * present. Just check that Data4[0]'s most significant bits are
773 * set as expected.
774 */
775 ok((guid.Data4[0] & 0xc0) == 0x80,
776 "unexpected value in Data4[0]: %02x\n", guid.Data4[0] & 0xc0);
777 }
778 }
779
780 static void test_UuidCreateSequential(void)
781 {
782 UUID guid1;
783 BYTE version;
784 RPC_STATUS (WINAPI *pUuidCreateSequential)(UUID *) = (void *)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "UuidCreateSequential");
785 RPC_STATUS (WINAPI *pI_UuidCreate)(UUID *) = (void*)GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "I_UuidCreate");
786 RPC_STATUS ret;
787
788 if (!pUuidCreateSequential)
789 {
790 win_skip("UuidCreateSequential not exported\n");
791 return;
792 }
793
794 ok(pI_UuidCreate != pUuidCreateSequential, "got %p, %p\n", pI_UuidCreate, pUuidCreateSequential);
795
796 ret = pUuidCreateSequential(&guid1);
797 ok(!ret || ret == RPC_S_UUID_LOCAL_ONLY,
798 "expected RPC_S_OK or RPC_S_UUID_LOCAL_ONLY, got %08x\n", ret);
799 version = (guid1.Data3 & 0xf000) >> 12;
800 ok(version == 1, "unexpected version %d\n", version);
801 if (version == 1)
802 {
803 UUID guid2;
804
805 if (!ret)
806 {
807 /* If the call succeeded, there's a valid (non-multicast) MAC
808 * address in the uuid:
809 */
810 ok(!(guid1.Data4[2] & 0x01) || broken(guid1.Data4[2] & 0x01), /* Win 8.1 */
811 "GUID does not appear to contain a MAC address: %s\n",
812 wine_dbgstr_guid(&guid1));
813 }
814 else
815 {
816 /* Otherwise, there's a randomly generated multicast MAC address
817 * address in the uuid:
818 */
819 ok((guid1.Data4[2] & 0x01),
820 "GUID does not appear to contain a multicast MAC address: %s\n",
821 wine_dbgstr_guid(&guid1));
822 }
823 /* Generate another GUID, and make sure its MAC address matches the
824 * first.
825 */
826 ret = pUuidCreateSequential(&guid2);
827 ok(!ret || ret == RPC_S_UUID_LOCAL_ONLY,
828 "expected RPC_S_OK or RPC_S_UUID_LOCAL_ONLY, got %08x\n", ret);
829 version = (guid2.Data3 & 0xf000) >> 12;
830 ok(version == 1, "unexpected version %d\n", version);
831 ok(!memcmp(guid1.Data4, guid2.Data4, sizeof(guid2.Data4)),
832 "unexpected value in MAC address: %s\n",
833 wine_dbgstr_guid(&guid2));
834
835 /* I_UuidCreate does exactly the same */
836 pI_UuidCreate(&guid2);
837 version = (guid2.Data3 & 0xf000) >> 12;
838 ok(version == 1, "unexpected version %d\n", version);
839 ok(!memcmp(guid1.Data4, guid2.Data4, sizeof(guid2.Data4)),
840 "unexpected value in MAC address: %s\n",
841 wine_dbgstr_guid(&guid2));
842 }
843 }
844
845 static void test_RpcBindingFree(void)
846 {
847 RPC_BINDING_HANDLE binding = NULL;
848 RPC_STATUS status;
849
850 status = RpcBindingFree(&binding);
851 ok(status == RPC_S_INVALID_BINDING,
852 "RpcBindingFree should have returned RPC_S_INVALID_BINDING instead of %d\n",
853 status);
854 }
855
856 static void test_RpcServerInqDefaultPrincName(void)
857 {
858 RPC_STATUS ret;
859 RPC_CSTR principal, saved_principal;
860 char *username;
861 ULONG len = 0;
862
863 GetUserNameExA( NameSamCompatible, NULL, &len );
864 username = HeapAlloc( GetProcessHeap(), 0, len );
865 GetUserNameExA( NameSamCompatible, username, &len );
866
867 ret = RpcServerInqDefaultPrincNameA( 0, NULL );
868 ok( ret == RPC_S_UNKNOWN_AUTHN_SERVICE, "got %u\n", ret );
869
870 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_DEFAULT, NULL );
871 ok( ret == RPC_S_UNKNOWN_AUTHN_SERVICE, "got %u\n", ret );
872
873 principal = (RPC_CSTR)0xdeadbeef;
874 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_DEFAULT, &principal );
875 ok( ret == RPC_S_UNKNOWN_AUTHN_SERVICE, "got %u\n", ret );
876 ok( principal == (RPC_CSTR)0xdeadbeef, "got unexpected principal\n" );
877
878 saved_principal = (RPC_CSTR)0xdeadbeef;
879 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_WINNT, &saved_principal );
880 ok( ret == RPC_S_OK, "got %u\n", ret );
881 ok( saved_principal != (RPC_CSTR)0xdeadbeef, "expected valid principal\n" );
882 ok( !strcmp( (const char *)saved_principal, username ), "got \'%s\'\n", saved_principal );
883 trace("%s\n", saved_principal);
884
885 ret = RpcServerRegisterAuthInfoA( (RPC_CSTR)"wine\\test", RPC_C_AUTHN_WINNT, NULL, NULL );
886 ok( ret == RPC_S_OK, "got %u\n", ret );
887
888 principal = (RPC_CSTR)0xdeadbeef;
889 ret = RpcServerInqDefaultPrincNameA( RPC_C_AUTHN_WINNT, &principal );
890 ok( ret == RPC_S_OK, "got %u\n", ret );
891 ok( principal != (RPC_CSTR)0xdeadbeef, "expected valid principal\n" );
892 ok( !strcmp( (const char *)principal, username ), "got \'%s\'\n", principal );
893 RpcStringFreeA( &principal );
894
895 ret = RpcServerRegisterAuthInfoA( saved_principal, RPC_C_AUTHN_WINNT, NULL, NULL );
896 ok( ret == RPC_S_OK, "got %u\n", ret );
897
898 RpcStringFreeA( &saved_principal );
899 HeapFree( GetProcessHeap(), 0, username );
900 }
901
902 static void test_RpcServerRegisterAuthInfo(void)
903 {
904 RPC_STATUS status;
905
906 status = RpcServerRegisterAuthInfoW(NULL, 600, NULL, NULL);
907 ok(status == RPC_S_UNKNOWN_AUTHN_SERVICE, "status = %x\n", status);
908 }
909
910 START_TEST( rpc )
911 {
912 UuidConversionAndComparison();
913 TestDceErrorInqText();
914 test_rpc_ncacn_ip_tcp();
915 test_towers();
916 test_I_RpcMapWin32Status();
917 test_RpcStringBindingParseA();
918 test_I_RpcExceptionFilter();
919 test_RpcStringBindingFromBinding();
920 test_UuidCreate();
921 test_UuidCreateSequential();
922 test_RpcBindingFree();
923 test_RpcServerInqDefaultPrincName();
924 test_RpcServerRegisterAuthInfo();
925 }