[KERNEL32]: Improve RtlUnwind spec export.
[reactos.git] / rostests / winetests / rpcrt4 / server.c
1 /*
2 * Tests for WIDL and RPC server/clients.
3 *
4 * Copyright (C) Google 2007 (Dan Hipschman)
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 <windows.h>
22 #include <secext.h>
23 #include <rpcdce.h>
24 #include "wine/test.h"
25 #include "server_s.h"
26 #include "server_defines.h"
27
28 #include <stddef.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 #define PORT "4114"
33 #define PIPE "\\pipe\\wine_rpcrt4_test"
34
35 #define INT_CODE 4198
36
37 static const char *progname;
38 static BOOL old_windows_version;
39
40 static HANDLE stop_event;
41
42 static void (WINAPI *pNDRSContextMarshall2)(RPC_BINDING_HANDLE, NDR_SCONTEXT, void*, NDR_RUNDOWN, void*, ULONG);
43 static NDR_SCONTEXT (WINAPI *pNDRSContextUnmarshall2)(RPC_BINDING_HANDLE, void*, ULONG, void*, ULONG);
44 static RPC_STATUS (WINAPI *pRpcServerRegisterIfEx)(RPC_IF_HANDLE,UUID*, RPC_MGR_EPV*, unsigned int,
45 unsigned int,RPC_IF_CALLBACK_FN*);
46 static BOOLEAN (WINAPI *pGetUserNameExA)(EXTENDED_NAME_FORMAT, LPSTR, PULONG);
47 static RPC_STATUS (WINAPI *pRpcBindingSetAuthInfoExA)(RPC_BINDING_HANDLE, RPC_CSTR, ULONG, ULONG,
48 RPC_AUTH_IDENTITY_HANDLE, ULONG, RPC_SECURITY_QOS *);
49 static RPC_STATUS (WINAPI *pRpcServerRegisterAuthInfoA)(RPC_CSTR, ULONG, RPC_AUTH_KEY_RETRIEVAL_FN, LPVOID);
50
51 static char *domain_and_user;
52
53 /* type check statements generated in header file */
54 fnprintf *p_printf = printf;
55
56 static const WCHAR helloW[] = { 'H','e','l','l','o',0 };
57 static const WCHAR worldW[] = { 'W','o','r','l','d','!',0 };
58
59 static void InitFunctionPointers(void)
60 {
61 HMODULE hrpcrt4 = GetModuleHandleA("rpcrt4.dll");
62 HMODULE hsecur32 = LoadLibraryA("secur32.dll");
63
64 pNDRSContextMarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextMarshall2");
65 pNDRSContextUnmarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextUnmarshall2");
66 pRpcServerRegisterIfEx = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterIfEx");
67 pRpcBindingSetAuthInfoExA = (void *)GetProcAddress(hrpcrt4, "RpcBindingSetAuthInfoExA");
68 pRpcServerRegisterAuthInfoA = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterAuthInfoA");
69 pGetUserNameExA = (void *)GetProcAddress(hsecur32, "GetUserNameExA");
70
71 if (!pNDRSContextMarshall2) old_windows_version = TRUE;
72 }
73
74 void __RPC_FAR *__RPC_USER
75 midl_user_allocate(SIZE_T n)
76 {
77 return HeapAlloc(GetProcessHeap(), 0, n);
78 }
79
80 void __RPC_USER
81 midl_user_free(void __RPC_FAR *p)
82 {
83 HeapFree(GetProcessHeap(), 0, p);
84 }
85
86 static char *
87 xstrdup(const char *s)
88 {
89 char *d = HeapAlloc(GetProcessHeap(), 0, strlen(s) + 1);
90 strcpy(d, s);
91 return d;
92 }
93
94 int __cdecl s_int_return(void)
95 {
96 return INT_CODE;
97 }
98
99 int __cdecl s_square(int x)
100 {
101 return x * x;
102 }
103
104 int __cdecl s_sum(int x, int y)
105 {
106 return x + y;
107 }
108
109 signed char __cdecl s_sum_char(signed char x, signed char y)
110 {
111 return x + y;
112 }
113
114 short __cdecl s_sum_short(short x, short y)
115 {
116 return x + y;
117 }
118
119 int __cdecl s_sum_float(float x, float y)
120 {
121 return x + y;
122 }
123
124 int __cdecl s_sum_double_int(int x, double y)
125 {
126 return x + y;
127 }
128
129 hyper __cdecl s_sum_hyper(hyper x, hyper y)
130 {
131 return x + y;
132 }
133
134 int __cdecl s_sum_hyper_int(hyper x, hyper y)
135 {
136 return x + y;
137 }
138
139 int __cdecl s_sum_char_hyper(signed char x, hyper y)
140 {
141 return x + y;
142 }
143
144 void __cdecl s_square_out(int x, int *y)
145 {
146 *y = s_square(x);
147 }
148
149 void __cdecl s_square_ref(int *x)
150 {
151 *x = s_square(*x);
152 }
153
154 int __cdecl s_str_length(const char *s)
155 {
156 return strlen(s);
157 }
158
159 int __cdecl s_str_t_length(str_t s)
160 {
161 return strlen(s);
162 }
163
164 int __cdecl s_cstr_length(const char *s, int n)
165 {
166 int len = 0;
167 while (0 < n-- && *s++)
168 ++len;
169 return len;
170 }
171
172 int __cdecl s_dot_self(vector_t *v)
173 {
174 return s_square(v->x) + s_square(v->y) + s_square(v->z);
175 }
176
177 double __cdecl s_square_half(double x, double *y)
178 {
179 *y = x / 2.0;
180 return x * x;
181 }
182
183 float __cdecl s_square_half_float(float x, float *y)
184 {
185 *y = x / 2.0f;
186 return x * x;
187 }
188
189 LONG __cdecl s_square_half_long(LONG x, LONG *y)
190 {
191 *y = x / 2;
192 return x * x;
193 }
194
195 int __cdecl s_sum_fixed_array(int a[5])
196 {
197 return a[0] + a[1] + a[2] + a[3] + a[4];
198 }
199
200 int __cdecl s_pints_sum(pints_t *pints)
201 {
202 return *pints->pi + **pints->ppi + ***pints->pppi;
203 }
204
205 double __cdecl s_ptypes_sum(ptypes_t *pt)
206 {
207 return *pt->pc + *pt->ps + *pt->pl + *pt->pf + *pt->pd;
208 }
209
210 int __cdecl s_dot_pvectors(pvectors_t *p)
211 {
212 return p->pu->x * (*p->pv)->x + p->pu->y * (*p->pv)->y + p->pu->z * (*p->pv)->z;
213 }
214
215 int __cdecl s_sum_sp(sp_t *sp)
216 {
217 return sp->x + sp->s->x;
218 }
219
220 double __cdecl s_square_sun(sun_t *su)
221 {
222 switch (su->s)
223 {
224 case SUN_I: return su->u.i * su->u.i;
225 case SUN_F1:
226 case SUN_F2: return su->u.f * su->u.f;
227 case SUN_PI: return (*su->u.pi) * (*su->u.pi);
228 default:
229 return 0.0;
230 }
231 }
232
233 int __cdecl s_test_list_length(test_list_t *list)
234 {
235 return (list->t == TL_LIST
236 ? 1 + s_test_list_length(list->u.tail)
237 : 0);
238 }
239
240 int __cdecl s_sum_fixed_int_3d(int m[2][3][4])
241 {
242 int i, j, k;
243 int sum = 0;
244
245 for (i = 0; i < 2; ++i)
246 for (j = 0; j < 3; ++j)
247 for (k = 0; k < 4; ++k)
248 sum += m[i][j][k];
249
250 return sum;
251 }
252
253 int __cdecl s_sum_conf_array(int x[], int n)
254 {
255 int *p = x, *end = p + n;
256 int sum = 0;
257
258 while (p < end)
259 sum += *p++;
260
261 return sum;
262 }
263
264 int __cdecl s_sum_conf_ptr_by_conf_ptr(int n1, int *n2_then_x1, int *x2)
265 {
266 int i;
267 int sum = 0;
268 if(n1 == 0)
269 return 0;
270
271 for(i = 1; i < n1; ++i)
272 sum += n2_then_x1[i];
273
274 for(i = 0; i < *n2_then_x1; ++i)
275 sum += x2[i];
276
277 return sum;
278 }
279
280 int __cdecl s_sum_unique_conf_array(int x[], int n)
281 {
282 return s_sum_conf_array(x, n);
283 }
284
285 int __cdecl s_sum_unique_conf_ptr(int *x, int n)
286 {
287 return x ? s_sum_conf_array(x, n) : 0;
288 }
289
290 int __cdecl s_sum_var_array(int x[20], int n)
291 {
292 ok(0 <= n, "RPC sum_var_array\n");
293 ok(n <= 20, "RPC sum_var_array\n");
294
295 return s_sum_conf_array(x, n);
296 }
297
298 int __cdecl s_sum_complex_array(int n, refpint_t pi[])
299 {
300 int total = 0;
301 for (; n > 0; n--)
302 total += *pi[n - 1];
303 return total;
304 }
305
306 int __cdecl s_dot_two_vectors(vector_t vs[2])
307 {
308 return vs[0].x * vs[1].x + vs[0].y * vs[1].y + vs[0].z * vs[1].z;
309 }
310
311 void __cdecl s_get_number_array(int x[20], int *n)
312 {
313 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
314 memcpy(x, c, sizeof(c));
315 *n = sizeof(c)/sizeof(c[0]);
316 }
317
318 int __cdecl s_sum_cs(cs_t *cs)
319 {
320 return s_sum_conf_array(cs->ca, cs->n);
321 }
322
323 int __cdecl s_sum_cps(cps_t *cps)
324 {
325 int sum = 0;
326 int i;
327
328 for (i = 0; i < *cps->pn; ++i)
329 sum += cps->ca1[i];
330
331 for (i = 0; i < 2 * cps->n; ++i)
332 sum += cps->ca2[i];
333
334 return sum;
335 }
336
337 int __cdecl s_sum_cpsc(cpsc_t *cpsc)
338 {
339 int sum = 0;
340 int i;
341 for (i = 0; i < (cpsc->c ? cpsc->a : cpsc->b); ++i)
342 sum += cpsc->ca[i];
343 return sum;
344 }
345
346 int __cdecl s_get_cpsc(int n, cpsc_t *cpsc)
347 {
348 int i, ret;
349
350 cpsc->a = 2 * n;
351 cpsc->b = 2;
352 cpsc->c = 1;
353 cpsc->ca = MIDL_user_allocate( cpsc->a * sizeof(int) );
354 for (i = ret = 0; i < cpsc->a; i++) cpsc->ca[i] = i;
355 for (i = ret = 0; i < cpsc->a; i++) ret += cpsc->ca[i];
356 return ret;
357 }
358
359 int __cdecl s_square_puint(puint_t p)
360 {
361 int n = atoi(p);
362 return n * n;
363 }
364
365 int __cdecl s_sum_puints(puints_t *p)
366 {
367 int sum = 0;
368 int i;
369 for (i = 0; i < p->n; ++i)
370 sum += atoi(p->ps[i]);
371 return sum;
372 }
373
374 int __cdecl s_sum_cpuints(cpuints_t *p)
375 {
376 int sum = 0;
377 int i;
378 for (i = 0; i < p->n; ++i)
379 sum += atoi(p->ps[i]);
380 return sum;
381 }
382
383 int __cdecl s_dot_copy_vectors(vector_t u, vector_t v)
384 {
385 return u.x * v.x + u.y * v.y + u.z * v.z;
386 }
387
388 int __cdecl s_square_test_us(test_us_t *tus)
389 {
390 int n = atoi(tus->us.x);
391 return n * n;
392 }
393
394 double __cdecl s_square_encu(encu_t *eu)
395 {
396 switch (eu->t)
397 {
398 case ENCU_I: return eu->tagged_union.i * eu->tagged_union.i;
399 case ENCU_F: return eu->tagged_union.f * eu->tagged_union.f;
400 default:
401 return 0.0;
402 }
403 }
404
405 double __cdecl s_square_unencu(int t, unencu_t *eu)
406 {
407 switch (t)
408 {
409 case ENCU_I: return eu->i * eu->i;
410 case ENCU_F: return eu->f * eu->f;
411 default:
412 return 0.0;
413 }
414 }
415
416 void __cdecl s_check_se2(se_t *s)
417 {
418 ok(s->f == E2, "check_se2\n");
419 }
420
421 int __cdecl s_sum_parr(int *a[3])
422 {
423 return s_sum_pcarr(a, 3);
424 }
425
426 int __cdecl s_sum_pcarr(int *a[], int n)
427 {
428 int i, s = 0;
429 for (i = 0; i < n; ++i)
430 s += *a[i];
431 return s;
432 }
433
434 int __cdecl s_enum_ord(e_t e)
435 {
436 switch (e)
437 {
438 case E1: return 1;
439 case E2: return 2;
440 case E3: return 3;
441 case E4: return 4;
442 default:
443 return 0;
444 }
445 }
446
447 double __cdecl s_square_encue(encue_t *eue)
448 {
449 switch (eue->t)
450 {
451 case E1: return eue->tagged_union.i1 * eue->tagged_union.i1;
452 case E2: return eue->tagged_union.f2 * eue->tagged_union.f2;
453 default:
454 return 0.0;
455 }
456 }
457
458 int __cdecl s_sum_toplev_conf_2n(int *x, int n)
459 {
460 int sum = 0;
461 int i;
462 for (i = 0; i < 2 * n; ++i)
463 sum += x[i];
464 return sum;
465 }
466
467 int __cdecl s_sum_toplev_conf_cond(int *x, int a, int b, int c)
468 {
469 int sum = 0;
470 int n = c ? a : b;
471 int i;
472 for (i = 0; i < n; ++i)
473 sum += x[i];
474 return sum;
475 }
476
477 double __cdecl s_sum_aligns(aligns_t *a)
478 {
479 return a->c + a->i + a->s + a->d;
480 }
481
482 int __cdecl s_sum_padded(padded_t *p)
483 {
484 return p->i + p->c;
485 }
486
487 int __cdecl s_sum_padded2(padded_t ps[2])
488 {
489 return s_sum_padded(&ps[0]) + s_sum_padded(&ps[1]);
490 }
491
492 int __cdecl s_sum_padded_conf(padded_t *ps, int n)
493 {
494 int sum = 0;
495 int i;
496 for (i = 0; i < n; ++i)
497 sum += s_sum_padded(&ps[i]);
498 return sum;
499 }
500
501 int __cdecl s_sum_bogus(bogus_t *b)
502 {
503 return *b->h.p1 + *b->p2 + *b->p3 + b->c;
504 }
505
506 void __cdecl s_check_null(int *null)
507 {
508 ok(!null, "RPC check_null\n");
509 }
510
511 int __cdecl s_str_struct_len(str_struct_t *s)
512 {
513 return lstrlenA(s->s);
514 }
515
516 int __cdecl s_wstr_struct_len(wstr_struct_t *s)
517 {
518 return lstrlenW(s->s);
519 }
520
521 int __cdecl s_sum_doub_carr(doub_carr_t *dc)
522 {
523 int i, j;
524 int sum = 0;
525 for (i = 0; i < dc->n; ++i)
526 for (j = 0; j < dc->a[i]->n; ++j)
527 sum += dc->a[i]->a[j];
528 return sum;
529 }
530
531 void __cdecl s_make_pyramid_doub_carr(unsigned char n, doub_carr_t **dc)
532 {
533 doub_carr_t *t;
534 int i, j;
535 t = MIDL_user_allocate(FIELD_OFFSET(doub_carr_t, a[n]));
536 t->n = n;
537 for (i = 0; i < n; ++i)
538 {
539 int v = i + 1;
540 t->a[i] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t, a[v]));
541 t->a[i]->n = v;
542 for (j = 0; j < v; ++j)
543 t->a[i]->a[j] = j + 1;
544 }
545 *dc = t;
546 }
547
548 unsigned __cdecl s_hash_bstr(bstr_t b)
549 {
550 short n = b[-1];
551 short *s = b;
552 unsigned hash = 0;
553 short i;
554 for (i = 0; i < n; ++i)
555 hash = 5 * hash + (unsigned) s[i];
556 return hash;
557 }
558
559 void __cdecl s_get_a_bstr(bstr_t *b)
560 {
561 bstr_t bstr;
562 short str[] = {5, 'W', 'i', 'n', 'e', 0};
563 bstr = HeapAlloc(GetProcessHeap(), 0, sizeof(str));
564 memcpy(bstr, str, sizeof(str));
565 *b = bstr + 1;
566 }
567
568 void __cdecl s_get_name(name_t *name)
569 {
570 const char bossman[] = "Jeremy White";
571 memcpy(name->name, bossman, min(name->size, sizeof(bossman)));
572 /* ensure nul-termination */
573 if (name->size < sizeof(bossman))
574 name->name[name->size - 1] = 0;
575 }
576
577 void __cdecl s_get_names(int *n, str_array_t *names)
578 {
579 str_array_t list;
580
581 list = MIDL_user_allocate(2 * sizeof(list[0]));
582 list[0] = MIDL_user_allocate(6);
583 strcpy(list[0], "Hello");
584 list[1] = MIDL_user_allocate(7);
585 strcpy(list[1], "World!");
586
587 *names = list;
588 *n = 2;
589 }
590
591 void __cdecl s_get_namesw(int *n, wstr_array_t *names)
592 {
593 wstr_array_t list;
594
595 list = MIDL_user_allocate(2 * sizeof(list[0]));
596 list[0] = MIDL_user_allocate(sizeof(helloW));
597 lstrcpyW(list[0], helloW);
598 list[1] = MIDL_user_allocate(sizeof(worldW));
599 lstrcpyW(list[1], worldW);
600
601 *names = list;
602 *n = 2;
603 }
604
605 int __cdecl s_sum_pcarr2(int n, int **pa)
606 {
607 return s_sum_conf_array(*pa, n);
608 }
609
610 int __cdecl s_sum_L1_norms(int n, vector_t *vs)
611 {
612 int i;
613 int sum = 0;
614 for (i = 0; i < n; ++i)
615 sum += abs(vs[i].x) + abs(vs[i].y) + abs(vs[i].z);
616 return sum;
617 }
618
619 s123_t * __cdecl s_get_s123(void)
620 {
621 s123_t *s = MIDL_user_allocate(sizeof *s);
622 s->f1 = 1;
623 s->f2 = 2;
624 s->f3 = 3;
625 return s;
626 }
627
628 str_t __cdecl s_get_filename(void)
629 {
630 return (char *)__FILE__;
631 }
632
633 int __cdecl s_echo_ranged_int(int i, int j, int k)
634 {
635 return min( 100, i + j + k );
636 }
637
638 int __cdecl s_echo_ranged_int2(int i)
639 {
640 return i;
641 }
642
643 void __cdecl s_get_ranged_enum(renum_t *re)
644 {
645 *re = RE3;
646 }
647
648 void __cdecl s_context_handle_test(void)
649 {
650 NDR_SCONTEXT h;
651 RPC_BINDING_HANDLE binding;
652 RPC_STATUS status;
653 unsigned char buf[20];
654 static RPC_SERVER_INTERFACE server_if =
655 {
656 sizeof(RPC_SERVER_INTERFACE),
657 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
658 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
659 NULL,
660 0,
661 0,
662 0,
663 0,
664 0,
665 };
666
667 binding = I_RpcGetCurrentCallHandle();
668 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
669
670 if (!pNDRSContextMarshall2 || !pNDRSContextUnmarshall2)
671 {
672 win_skip("NDRSContextMarshall2 or NDRSContextUnmarshall2 not exported from rpcrt4.dll\n");
673 return;
674 }
675
676 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
677 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
678
679 /* marshal a context handle with NULL userContext */
680 memset(buf, 0xcc, sizeof(buf));
681 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
682 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
683 ok(UuidIsNil((UUID *)&buf[4], &status), "uuid should have been nil\n");
684
685 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
686 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
687
688 /* marshal a context handle with non-NULL userContext */
689 memset(buf, 0xcc, sizeof(buf));
690 h->userContext = (void *)0xdeadbeef;
691 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
692 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
693 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
694
695 /* raises ERROR_INVALID_HANDLE exception on Vista upwards */
696 if (0)
697 {
698 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
699 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
700 ok(h->userContext == (void *)0xdeadbeef, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
701
702 /* marshal a context handle with an interface specified */
703 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
704 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
705
706 memset(buf, 0xcc, sizeof(buf));
707 h->userContext = (void *)0xcafebabe;
708 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
709 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
710 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
711
712 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
713 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
714 ok(h->userContext == (void *)0xcafebabe, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
715 }
716
717 /* test same interface data, but different pointer */
718 /* raises ERROR_INVALID_HANDLE exception */
719 if (0)
720 {
721 RPC_SERVER_INTERFACE server_if_clone = server_if;
722
723 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if_clone.InterfaceId, 0);
724 }
725
726 /* test different interface data, but different pointer */
727 /* raises ERROR_INVALID_HANDLE exception */
728 if (0)
729 {
730 static RPC_SERVER_INTERFACE server_if2 =
731 {
732 sizeof(RPC_SERVER_INTERFACE),
733 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
734 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
735 NULL,
736 0,
737 0,
738 0,
739 0,
740 0,
741 };
742 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
743
744 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if2.InterfaceId, 0);
745 }
746 }
747
748 void __cdecl s_get_numbers(int length, int size, pints_t n[])
749 {
750 int i;
751 for (i = 0; i < length; i++)
752 {
753 n[i].pi = midl_user_allocate(sizeof(*n[i].pi));
754 *n[i].pi = i;
755 n[i].ppi = NULL;
756 n[i].pppi = NULL;
757 }
758 }
759
760 void __cdecl s_get_numbers_struct(numbers_struct_t **ns)
761 {
762 int i;
763 *ns = midl_user_allocate(FIELD_OFFSET(numbers_struct_t, numbers[5]));
764 if (!*ns) return;
765 (*ns)->length = 5;
766 (*ns)->size = 5;
767 for (i = 0; i < (*ns)->length; i++)
768 {
769 (*ns)->numbers[i].pi = NULL;
770 (*ns)->numbers[i].ppi = NULL;
771 (*ns)->numbers[i].pppi = NULL;
772 }
773 (*ns)->numbers[0].pi = midl_user_allocate(sizeof(*(*ns)->numbers[i].pi));
774 *(*ns)->numbers[0].pi = 5;
775 }
776
777 void __cdecl s_full_pointer_test(int *a, int *b)
778 {
779 ok(*a == 42, "Expected *a to be 42 instead of %d\n", *a);
780 ok(*b == 42, "Expected *b to be 42 instead of %d\n", *a);
781 ok(a == b, "Expected a (%p) to point to the same memory as b (%p)\n", a, b);
782 }
783
784 void __cdecl s_full_pointer_null_test(int *a, int *b)
785 {
786 ok(*a == 42, "Expected *a to be 42 instead of %d\n", *a);
787 ok(b == NULL, "Expected b to be NULL instead of %p\n", b);
788 }
789
790 void __cdecl s_stop(void)
791 {
792 ok(RPC_S_OK == RpcMgmtStopServerListening(NULL), "RpcMgmtStopServerListening\n");
793 ok(RPC_S_OK == RpcServerUnregisterIf(NULL, NULL, FALSE), "RpcServerUnregisterIf\n");
794 ok(SetEvent(stop_event), "SetEvent\n");
795 }
796
797 static void
798 make_cmdline(char buffer[MAX_PATH], const char *test)
799 {
800 sprintf(buffer, "%s server %s", progname, test);
801 }
802
803 static void
804 run_client(const char *test)
805 {
806 char cmdline[MAX_PATH];
807 PROCESS_INFORMATION info;
808 STARTUPINFOA startup;
809
810 memset(&startup, 0, sizeof startup);
811 startup.cb = sizeof startup;
812
813 make_cmdline(cmdline, test);
814 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
815 winetest_wait_child_process( info.hProcess );
816 ok(CloseHandle(info.hProcess), "CloseHandle\n");
817 ok(CloseHandle(info.hThread), "CloseHandle\n");
818 }
819
820 static void
821 basic_tests(void)
822 {
823 char string[] = "I am a string";
824 WCHAR wstring[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
825 int f[5] = {1, 3, 0, -2, -4};
826 vector_t a = {1, 3, 7};
827 vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2;
828 pvectors_t pvecs = {&vec1, &pvec2};
829 sp_inner_t spi = {42};
830 sp_t sp = {-13, &spi};
831 aligns_t aligns;
832 pints_t pints;
833 ptypes_t ptypes;
834 padded_t padded;
835 padded_t padded2[2];
836 bogus_t bogus;
837 int i1, i2, i3, *pi2, *pi3, **ppi3;
838 double u, v;
839 float s, t;
840 LONG q, r;
841 short h;
842 char c;
843 int x;
844 hyper y;
845 str_struct_t ss = {string};
846 wstr_struct_t ws = {wstring};
847 str_t str;
848 se_t se;
849 renum_t re;
850
851 ok(int_return() == INT_CODE, "RPC int_return\n");
852
853 ok(square(7) == 49, "RPC square\n");
854 x = sum(23, -4);
855 ok(x == 19, "RPC sum got %d\n", x);
856 c = sum_char(-23, 50);
857 ok(c == 27, "RPC sum_char got %d\n", (int)c);
858 h = sum_short(1122, -344);
859 ok(h == 778, "RPC sum_short got %d\n", (int)h);
860 x = sum_float(123.45, -32.2);
861 ok(x == 91, "RPC sum_float got %d\n", x);
862 x = sum_double_int(-78, 148.46);
863 ok(x == 70, "RPC sum_double_int got %d\n", x);
864 y = sum_hyper((hyper)0x12345678 << 16, (hyper)0x33557799 << 16);
865 ok(y == (hyper)0x4589ce11 << 16, "RPC hyper got %x%08x\n", (DWORD)(y >> 32), (DWORD)y);
866 x = sum_hyper_int((hyper)0x24242424 << 16, -((hyper)0x24241212 << 16));
867 ok(x == 0x12120000, "RPC hyper_int got 0x%x\n", x);
868 x = sum_char_hyper( 12, ((hyper)0x42424242 << 32) | 0x33334444 );
869 ok(x == 0x33334450, "RPC char_hyper got 0x%x\n", x);
870
871 x = 0;
872 square_out(11, &x);
873 ok(x == 121, "RPC square_out\n");
874
875 x = 5;
876 square_ref(&x);
877 ok(x == 25, "RPC square_ref\n");
878
879 ok(str_length(string) == strlen(string), "RPC str_length\n");
880 ok(str_t_length(string) == strlen(string), "RPC str_length\n");
881 ok(dot_self(&a) == 59, "RPC dot_self\n");
882
883 ok(str_struct_len(&ss) == lstrlenA(string), "RPC str_struct_len\n");
884 ok(wstr_struct_len(&ws) == lstrlenW(wstring), "RPC str_struct_len\n");
885
886 v = 0.0;
887 u = square_half(3.0, &v);
888 ok(u == 9.0, "RPC square_half\n");
889 ok(v == 1.5, "RPC square_half\n");
890
891 t = 0.0f;
892 s = square_half_float(3.0f, &t);
893 ok(s == 9.0f, "RPC square_half_float\n");
894 ok(t == 1.5f, "RPC square_half_float\n");
895
896 r = 0;
897 q = square_half_long(3, &r);
898 ok(q == 9, "RPC square_half_long\n");
899 ok(r == 1, "RPC square_half_long\n");
900
901 i1 = 19;
902 i2 = -3;
903 i3 = -29;
904 pi2 = &i2;
905 pi3 = &i3;
906 ppi3 = &pi3;
907 pints.pi = &i1;
908 pints.ppi = &pi2;
909 pints.pppi = &ppi3;
910 ok(pints_sum(&pints) == -13, "RPC pints_sum\n");
911
912 c = 10;
913 h = 3;
914 q = 14;
915 s = -5.0f;
916 u = 11.0;
917 ptypes.pc = &c;
918 ptypes.ps = &h;
919 ptypes.pl = &q;
920 ptypes.pf = &s;
921 ptypes.pd = &u;
922 ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n");
923
924 ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n");
925 ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n");
926 ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n");
927 ok(sum_sp(&sp) == 29, "RPC sum_sp\n");
928
929 ok(enum_ord(E1) == 1, "RPC enum_ord\n");
930 ok(enum_ord(E2) == 2, "RPC enum_ord\n");
931 ok(enum_ord(E3) == 3, "RPC enum_ord\n");
932 ok(enum_ord(E4) == 4, "RPC enum_ord\n");
933
934 se.f = E2;
935 check_se2(&se);
936
937 memset(&aligns, 0, sizeof(aligns));
938 aligns.c = 3;
939 aligns.i = 4;
940 aligns.s = 5;
941 aligns.d = 6.0;
942 ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
943
944 padded.i = -3;
945 padded.c = 8;
946 ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
947 padded2[0].i = -5;
948 padded2[0].c = 1;
949 padded2[1].i = 3;
950 padded2[1].c = 7;
951 ok(sum_padded2(padded2) == 6, "RPC sum_padded2\n");
952 padded2[0].i = -5;
953 padded2[0].c = 1;
954 padded2[1].i = 3;
955 padded2[1].c = 7;
956 ok(sum_padded_conf(padded2, 2) == 6, "RPC sum_padded_conf\n");
957
958 i1 = 14;
959 i2 = -7;
960 i3 = -4;
961 bogus.h.p1 = &i1;
962 bogus.p2 = &i2;
963 bogus.p3 = &i3;
964 bogus.c = 9;
965 ok(sum_bogus(&bogus) == 12, "RPC sum_bogus\n");
966
967 check_null(NULL);
968
969 str = get_filename();
970 ok(!strcmp(str, __FILE__), "get_filename() returned %s instead of %s\n", str, __FILE__);
971 midl_user_free(str);
972
973 x = echo_ranged_int(0,0,0);
974 ok(x == 0, "echo_ranged_int() returned %d instead of 0\n", x);
975 x = echo_ranged_int(10,20,100);
976 ok(x == 100, "echo_ranged_int() returned %d instead of 100\n", x);
977 x = echo_ranged_int2(40);
978 ok(x == 40, "echo_ranged_int() returned %d instead of 40\n", x);
979
980 if (!old_windows_version)
981 {
982 get_ranged_enum(&re);
983 ok(re == RE3, "get_ranged_enum() returned %d instead of RE3\n", re);
984 }
985 }
986
987 static void
988 union_tests(void)
989 {
990 encue_t eue;
991 encu_t eu;
992 unencu_t uneu;
993 sun_t su;
994 int i;
995
996 su.s = SUN_I;
997 su.u.i = 9;
998 ok(square_sun(&su) == 81.0, "RPC square_sun\n");
999
1000 su.s = SUN_F1;
1001 su.u.f = 5.0;
1002 ok(square_sun(&su) == 25.0, "RPC square_sun\n");
1003
1004 su.s = SUN_F2;
1005 su.u.f = -2.0;
1006 ok(square_sun(&su) == 4.0, "RPC square_sun\n");
1007
1008 su.s = SUN_PI;
1009 su.u.pi = &i;
1010 i = 11;
1011 ok(square_sun(&su) == 121.0, "RPC square_sun\n");
1012
1013 eu.t = ENCU_I;
1014 eu.tagged_union.i = 7;
1015 ok(square_encu(&eu) == 49.0, "RPC square_encu\n");
1016
1017 eu.t = ENCU_F;
1018 eu.tagged_union.f = 3.0;
1019 ok(square_encu(&eu) == 9.0, "RPC square_encu\n");
1020
1021 uneu.i = 4;
1022 ok(square_unencu(ENCU_I, &uneu) == 16.0, "RPC square_unencu\n");
1023
1024 uneu.f = 5.0;
1025 ok(square_unencu(ENCU_F, &uneu) == 25.0, "RPC square_unencu\n");
1026
1027 eue.t = E1;
1028 eue.tagged_union.i1 = 8;
1029 ok(square_encue(&eue) == 64.0, "RPC square_encue\n");
1030
1031 eue.t = E2;
1032 eue.tagged_union.f2 = 10.0;
1033 ok(square_encue(&eue) == 100.0, "RPC square_encue\n");
1034 }
1035
1036 static test_list_t *
1037 null_list(void)
1038 {
1039 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
1040 n->t = TL_NULL;
1041 n->u.x = 0;
1042 return n;
1043 }
1044
1045 static test_list_t *
1046 make_list(test_list_t *tail)
1047 {
1048 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
1049 n->t = TL_LIST;
1050 n->u.tail = tail;
1051 return n;
1052 }
1053
1054 static void
1055 free_list(test_list_t *list)
1056 {
1057 if (list->t == TL_LIST)
1058 free_list(list->u.tail);
1059 HeapFree(GetProcessHeap(), 0, list);
1060 }
1061
1062 ULONG __RPC_USER
1063 puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
1064 {
1065 return start + sizeof(int);
1066 }
1067
1068 unsigned char * __RPC_USER
1069 puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
1070 {
1071 int n = atoi(*p);
1072 memcpy(buffer, &n, sizeof n);
1073 return buffer + sizeof n;
1074 }
1075
1076 unsigned char * __RPC_USER
1077 puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
1078 {
1079 int n;
1080 memcpy(&n, buffer, sizeof n);
1081 *p = HeapAlloc(GetProcessHeap(), 0, 10);
1082 sprintf(*p, "%d", n);
1083 return buffer + sizeof n;
1084 }
1085
1086 void __RPC_USER
1087 puint_t_UserFree(ULONG *flags, puint_t *p)
1088 {
1089 HeapFree(GetProcessHeap(), 0, *p);
1090 }
1091
1092 ULONG __RPC_USER
1093 us_t_UserSize(ULONG *flags, ULONG start, us_t *pus)
1094 {
1095 return start + sizeof(struct wire_us);
1096 }
1097
1098 unsigned char * __RPC_USER
1099 us_t_UserMarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
1100 {
1101 struct wire_us wus;
1102 wus.x = atoi(pus->x);
1103 memcpy(buffer, &wus, sizeof wus);
1104 return buffer + sizeof wus;
1105 }
1106
1107 unsigned char * __RPC_USER
1108 us_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
1109 {
1110 struct wire_us wus;
1111 memcpy(&wus, buffer, sizeof wus);
1112 pus->x = HeapAlloc(GetProcessHeap(), 0, 10);
1113 sprintf(pus->x, "%d", wus.x);
1114 return buffer + sizeof wus;
1115 }
1116
1117 void __RPC_USER
1118 us_t_UserFree(ULONG *flags, us_t *pus)
1119 {
1120 HeapFree(GetProcessHeap(), 0, pus->x);
1121 }
1122
1123 ULONG __RPC_USER
1124 bstr_t_UserSize(ULONG *flags, ULONG start, bstr_t *b)
1125 {
1126 return start + FIELD_OFFSET(user_bstr_t, data[(*b)[-1]]);
1127 }
1128
1129 unsigned char * __RPC_USER
1130 bstr_t_UserMarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1131 {
1132 wire_bstr_t wb = (wire_bstr_t) buffer;
1133 wb->n = (*b)[-1];
1134 memcpy(&wb->data, *b, wb->n * sizeof wb->data[0]);
1135 return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1136 }
1137
1138 unsigned char * __RPC_USER
1139 bstr_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1140 {
1141 wire_bstr_t wb = (wire_bstr_t) buffer;
1142 short *data = HeapAlloc(GetProcessHeap(), 0, (wb->n + 1) * sizeof *data);
1143 data[0] = wb->n;
1144 memcpy(&data[1], wb->data, wb->n * sizeof data[1]);
1145 *b = &data[1];
1146 return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1147 }
1148
1149 void __RPC_USER
1150 bstr_t_UserFree(ULONG *flags, bstr_t *b)
1151 {
1152 HeapFree(GetProcessHeap(), 0, &((*b)[-1]));
1153 }
1154
1155 static void
1156 pointer_tests(void)
1157 {
1158 int a[] = {1, 2, 3, 4};
1159 char p1[] = "11";
1160 test_list_t *list = make_list(make_list(make_list(null_list())));
1161 test_us_t tus = {{p1}};
1162 int *pa[4];
1163 puints_t pus;
1164 cpuints_t cpus;
1165 short bstr_data[] = { 5, 'H', 'e', 'l', 'l', 'o' };
1166 bstr_t bstr = &bstr_data[1], bstr2;
1167 name_t name;
1168 void *buffer;
1169 int *pa2;
1170 s123_t *s123;
1171 int val = 42;
1172
1173 ok(test_list_length(list) == 3, "RPC test_list_length\n");
1174 ok(square_puint(p1) == 121, "RPC square_puint\n");
1175 pus.n = 4;
1176 pus.ps = HeapAlloc(GetProcessHeap(), 0, pus.n * sizeof pus.ps[0]);
1177 pus.ps[0] = xstrdup("5");
1178 pus.ps[1] = xstrdup("6");
1179 pus.ps[2] = xstrdup("7");
1180 pus.ps[3] = xstrdup("8");
1181 ok(sum_puints(&pus) == 26, "RPC sum_puints\n");
1182 HeapFree(GetProcessHeap(), 0, pus.ps[0]);
1183 HeapFree(GetProcessHeap(), 0, pus.ps[1]);
1184 HeapFree(GetProcessHeap(), 0, pus.ps[2]);
1185 HeapFree(GetProcessHeap(), 0, pus.ps[3]);
1186 HeapFree(GetProcessHeap(), 0, pus.ps);
1187 cpus.n = 4;
1188 cpus.ps = HeapAlloc(GetProcessHeap(), 0, cpus.n * sizeof cpus.ps[0]);
1189 cpus.ps[0] = xstrdup("5");
1190 cpus.ps[1] = xstrdup("6");
1191 cpus.ps[2] = xstrdup("7");
1192 cpus.ps[3] = xstrdup("8");
1193 ok(sum_cpuints(&cpus) == 26, "RPC sum_puints\n");
1194 HeapFree(GetProcessHeap(), 0, cpus.ps[0]);
1195 HeapFree(GetProcessHeap(), 0, cpus.ps[1]);
1196 HeapFree(GetProcessHeap(), 0, cpus.ps[2]);
1197 HeapFree(GetProcessHeap(), 0, cpus.ps[3]);
1198 HeapFree(GetProcessHeap(), 0, cpus.ps);
1199 ok(square_test_us(&tus) == 121, "RPC square_test_us\n");
1200
1201 pa[0] = &a[0];
1202 pa[1] = &a[1];
1203 pa[2] = &a[2];
1204 ok(sum_parr(pa) == 6, "RPC sum_parr\n");
1205
1206 pa[0] = &a[0];
1207 pa[1] = &a[1];
1208 pa[2] = &a[2];
1209 pa[3] = &a[3];
1210 ok(sum_pcarr(pa, 4) == 10, "RPC sum_pcarr\n");
1211
1212 ok(hash_bstr(bstr) == s_hash_bstr(bstr), "RPC hash_bstr_data\n");
1213
1214 get_a_bstr(&bstr);
1215 s_get_a_bstr(&bstr2);
1216 ok(!lstrcmpW((LPCWSTR)bstr, (LPCWSTR)bstr2), "bstr mismatch\n");
1217 HeapFree(GetProcessHeap(), 0, bstr - 1);
1218 HeapFree(GetProcessHeap(), 0, bstr2 - 1);
1219
1220 free_list(list);
1221
1222 if (!old_windows_version)
1223 {
1224 int n;
1225 str_array_t names;
1226 wstr_array_t namesw;
1227
1228 name.size = 10;
1229 name.name = buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, name.size);
1230 get_name(&name);
1231 ok(name.name == buffer, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name.name, buffer);
1232 ok(!strcmp(name.name, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name.name);
1233 HeapFree(GetProcessHeap(), 0, name.name);
1234
1235 n = -1;
1236 names = NULL;
1237 get_names(&n, &names);
1238 ok(n == 2, "expected 2, got %d\n", n);
1239 ok(!strcmp(names[0], "Hello"), "expected Hello, got %s\n", names[0]);
1240 ok(!strcmp(names[1], "World!"), "expected World!, got %s\n", names[1]);
1241 MIDL_user_free(names[0]);
1242 MIDL_user_free(names[1]);
1243 MIDL_user_free(names);
1244
1245 n = -1;
1246 namesw = NULL;
1247 get_namesw(&n, &namesw);
1248 ok(n == 2, "expected 2, got %d\n", n);
1249 ok(!lstrcmpW(namesw[0], helloW), "expected Hello, got %s\n", wine_dbgstr_w(namesw[0]));
1250 ok(!lstrcmpW(namesw[1], worldW), "expected World!, got %s\n", wine_dbgstr_w(namesw[1]));
1251 MIDL_user_free(namesw[0]);
1252 MIDL_user_free(namesw[1]);
1253 MIDL_user_free(namesw);
1254 }
1255
1256 pa2 = a;
1257 ok(sum_pcarr2(4, &pa2) == 10, "RPC sum_pcarr2\n");
1258
1259 s123 = get_s123();
1260 ok(s123->f1 == 1 && s123->f2 == 2 && s123->f3 == 3, "RPC get_s123\n");
1261 MIDL_user_free(s123);
1262
1263 full_pointer_test(&val, &val);
1264 full_pointer_null_test(&val, NULL);
1265 }
1266
1267 static int
1268 check_pyramid_doub_carr(doub_carr_t *dc)
1269 {
1270 int i, j;
1271 for (i = 0; i < dc->n; ++i)
1272 for (j = 0; j < dc->a[i]->n; ++j)
1273 if (dc->a[i]->a[j] != j + 1)
1274 return FALSE;
1275 return TRUE;
1276 }
1277
1278 static void
1279 free_pyramid_doub_carr(doub_carr_t *dc)
1280 {
1281 int i;
1282 for (i = 0; i < dc->n; ++i)
1283 MIDL_user_free(dc->a[i]);
1284 MIDL_user_free(dc);
1285 }
1286
1287 static void
1288 array_tests(void)
1289 {
1290 int m[2][3][4] =
1291 {
1292 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1293 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1294 };
1295 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1296 int c2[] = {10, 100, 200};
1297 int c3[20];
1298 vector_t vs[2] = {{1, -2, 3}, {4, -5, -6}};
1299 cps_t cps;
1300 cpsc_t cpsc;
1301 cs_t *cs;
1302 int n;
1303 int ca[5] = {1, -2, 3, -4, 5};
1304 int tmp[10];
1305 doub_carr_t *dc;
1306 int *pi;
1307 pints_t api[5];
1308 numbers_struct_t *ns;
1309 refpint_t rpi[5];
1310
1311 if (!old_windows_version)
1312 {
1313 const char str1[25] = "Hello";
1314 ok(cstr_length(str1, sizeof str1) == strlen(str1), "RPC cstr_length\n");
1315 }
1316
1317 ok(sum_fixed_int_3d(m) == 4116, "RPC sum_fixed_int_3d\n");
1318
1319 ok(sum_conf_array(c, 10) == 45, "RPC sum_conf_array\n");
1320 ok(sum_conf_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1321 ok(sum_conf_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1322 ok(sum_conf_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1323
1324 ok(sum_conf_ptr_by_conf_ptr(1, c2, c) == 45, "RPC sum_conf_ptr_by_conf_ptr\n");
1325 ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 345, "RPC sum_conf_ptr_by_conf_ptr\n");
1326 c2[0] = 0;
1327 ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 300, "RPC sum_conf_ptr_by_conf_ptr\n");
1328
1329 ok(sum_unique_conf_array(ca, 4) == -2, "RPC sum_unique_conf_array\n");
1330 ok(sum_unique_conf_ptr(ca, 5) == 3, "RPC sum_unique_conf_array\n");
1331 ok(sum_unique_conf_ptr(NULL, 10) == 0, "RPC sum_unique_conf_array\n");
1332
1333 get_number_array(c3, &n);
1334 ok(n == 10, "RPC get_num_array\n");
1335 for (; n > 0; n--)
1336 ok(c3[n-1] == c[n-1], "get_num_array returned wrong value %d @ %d\n",
1337 c3[n-1], n);
1338 ok(sum_var_array(c, 10) == 45, "RPC sum_conf_array\n");
1339 ok(sum_var_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1340 ok(sum_var_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1341 ok(sum_var_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1342
1343 ok(dot_two_vectors(vs) == -4, "RPC dot_two_vectors\n");
1344 cs = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t, ca[5]));
1345 cs->n = 5;
1346 cs->ca[0] = 3;
1347 cs->ca[1] = 5;
1348 cs->ca[2] = -2;
1349 cs->ca[3] = -1;
1350 cs->ca[4] = -4;
1351 ok(sum_cs(cs) == 1, "RPC sum_cs\n");
1352 HeapFree(GetProcessHeap(), 0, cs);
1353
1354 n = 5;
1355 cps.pn = &n;
1356 cps.ca1 = &c[2];
1357 cps.n = 3;
1358 cps.ca2 = &c[3];
1359 ok(sum_cps(&cps) == 53, "RPC sum_cps\n");
1360
1361 cpsc.a = 4;
1362 cpsc.b = 5;
1363 cpsc.c = 1;
1364 cpsc.ca = c;
1365 ok(sum_cpsc(&cpsc) == 6, "RPC sum_cpsc\n");
1366 cpsc.a = 4;
1367 cpsc.b = 5;
1368 cpsc.c = 0;
1369 cpsc.ca = c;
1370 ok(sum_cpsc(&cpsc) == 10, "RPC sum_cpsc\n");
1371
1372 cpsc.ca = NULL;
1373 ok(get_cpsc(5, &cpsc) == 45, "RPC sum_cpsc\n");
1374 ok( cpsc.a == 10, "RPC get_cpsc %u\n", cpsc.a );
1375 for (n = 0; n < 10; n++) ok( cpsc.ca[n] == n, "RPC get_cpsc[%d] = %d\n", n, cpsc.ca[n] );
1376
1377 memset( tmp, 0x33, sizeof(tmp) );
1378 cpsc.ca = tmp;
1379 ok(get_cpsc(4, &cpsc) == 28, "RPC sum_cpsc\n");
1380 ok( cpsc.a == 8, "RPC get_cpsc %u\n", cpsc.a );
1381 ok( cpsc.ca == tmp, "RPC get_cpsc %p/%p\n", cpsc.ca, tmp );
1382 for (n = 0; n < 8; n++) ok( cpsc.ca[n] == n, "RPC get_cpsc[%d] = %d\n", n, cpsc.ca[n] );
1383
1384 ok(sum_toplev_conf_2n(c, 3) == 15, "RPC sum_toplev_conf_2n\n");
1385 ok(sum_toplev_conf_cond(c, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1386 ok(sum_toplev_conf_cond(c, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1387
1388 dc = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_t, a[2]));
1389 dc->n = 2;
1390 dc->a[0] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t, a[3]));
1391 dc->a[0]->n = 3;
1392 dc->a[0]->a[0] = 5;
1393 dc->a[0]->a[1] = 1;
1394 dc->a[0]->a[2] = 8;
1395 dc->a[1] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t, a[2]));
1396 dc->a[1]->n = 2;
1397 dc->a[1]->a[0] = 2;
1398 dc->a[1]->a[1] = 3;
1399 ok(sum_doub_carr(dc) == 19, "RPC sum_doub_carr\n");
1400 HeapFree(GetProcessHeap(), 0, dc->a[0]);
1401 HeapFree(GetProcessHeap(), 0, dc->a[1]);
1402 HeapFree(GetProcessHeap(), 0, dc);
1403
1404 dc = NULL;
1405 make_pyramid_doub_carr(4, &dc);
1406 ok(check_pyramid_doub_carr(dc), "RPC make_pyramid_doub_carr\n");
1407 free_pyramid_doub_carr(dc);
1408
1409 ok(sum_L1_norms(2, vs) == 21, "RPC sum_L1_norms\n");
1410
1411 memset(api, 0, sizeof(api));
1412 pi = HeapAlloc(GetProcessHeap(), 0, sizeof(*pi));
1413 *pi = -1;
1414 api[0].pi = pi;
1415 get_numbers(1, 1, api);
1416 ok(api[0].pi == pi, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi, api[0].pi);
1417 ok(*api[0].pi == 0, "pi unmarshalled incorrectly %d\n", *api[0].pi);
1418
1419 if (!old_windows_version)
1420 {
1421 ns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(numbers_struct_t, numbers[5]));
1422 ns->length = 5;
1423 ns->size = 5;
1424 ns->numbers[0].pi = pi;
1425 get_numbers_struct(&ns);
1426 ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi);
1427 ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
1428 HeapFree(GetProcessHeap(), 0, ns);
1429 }
1430 HeapFree(GetProcessHeap(), 0, pi);
1431
1432 pi = HeapAlloc(GetProcessHeap(), 0, 5 * sizeof(*pi));
1433 pi[0] = 3; rpi[0] = &pi[0];
1434 pi[1] = 5; rpi[1] = &pi[1];
1435 pi[2] = -2; rpi[2] = &pi[2];
1436 pi[3] = -1; rpi[3] = &pi[3];
1437 pi[4] = -4; rpi[4] = &pi[4];
1438 ok(sum_complex_array(5, rpi) == 1, "RPC sum_complex_array\n");
1439 HeapFree(GetProcessHeap(), 0, pi);
1440 }
1441
1442 void __cdecl s_authinfo_test(unsigned int protseq, int secure)
1443 {
1444 RPC_BINDING_HANDLE binding;
1445 RPC_STATUS status;
1446 ULONG level, authnsvc;
1447 RPC_AUTHZ_HANDLE privs;
1448 unsigned char *principal;
1449
1450 binding = I_RpcGetCurrentCallHandle();
1451 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
1452
1453 level = authnsvc = 0xdeadbeef;
1454 privs = (RPC_AUTHZ_HANDLE)0xdeadbeef;
1455 principal = (unsigned char *)0xdeadbeef;
1456
1457 if (secure || protseq == RPC_PROTSEQ_LRPC)
1458 {
1459 status = RpcBindingInqAuthClientA(binding, &privs, &principal, &level, &authnsvc, NULL);
1460 if (status == RPC_S_CANNOT_SUPPORT)
1461 {
1462 win_skip("RpcBindingInqAuthClientA not supported\n");
1463 return;
1464 }
1465 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1466 ok(privs != (RPC_AUTHZ_HANDLE)0xdeadbeef, "privs unchanged\n");
1467 ok(principal != (unsigned char *)0xdeadbeef, "principal unchanged\n");
1468 if (protseq != RPC_PROTSEQ_LRPC)
1469 {
1470 todo_wine
1471 ok(principal != NULL, "NULL principal\n");
1472 }
1473 if (protseq == RPC_PROTSEQ_LRPC && principal && pGetUserNameExA)
1474 {
1475 int len;
1476 char *spn;
1477
1478 len = WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)privs, -1, NULL, 0, NULL, NULL);
1479 spn = HeapAlloc( GetProcessHeap(), 0, len );
1480 WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)privs, -1, spn, len, NULL, NULL);
1481
1482 ok(!strcmp(domain_and_user, spn), "expected %s got %s\n", domain_and_user, spn);
1483 HeapFree( GetProcessHeap(), 0, spn );
1484 }
1485 ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "level unchanged\n");
1486 ok(authnsvc == RPC_C_AUTHN_WINNT, "authnsvc unchanged\n");
1487
1488 status = RpcImpersonateClient(NULL);
1489 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1490 status = RpcRevertToSelf();
1491 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1492
1493 }
1494 else
1495 {
1496 status = RpcBindingInqAuthClientA(binding, &privs, &principal, &level, &authnsvc, NULL);
1497 ok(status == RPC_S_BINDING_HAS_NO_AUTH, "expected RPC_S_BINDING_HAS_NO_AUTH got %u\n", status);
1498 ok(privs == (RPC_AUTHZ_HANDLE)0xdeadbeef, "got %p\n", privs);
1499 ok(principal == (unsigned char *)0xdeadbeef, "got %s\n", principal);
1500 ok(level == 0xdeadbeef, "got %u\n", level);
1501 ok(authnsvc == 0xdeadbeef, "got %u\n", authnsvc);
1502 }
1503 }
1504
1505 static void
1506 run_tests(void)
1507 {
1508 basic_tests();
1509 union_tests();
1510 pointer_tests();
1511 array_tests();
1512 context_handle_test();
1513 }
1514
1515 static void
1516 set_auth_info(RPC_BINDING_HANDLE handle)
1517 {
1518 RPC_STATUS status;
1519 RPC_SECURITY_QOS qos;
1520
1521 if (!pGetUserNameExA)
1522 return;
1523
1524 qos.Version = 1;
1525 qos.Capabilities = RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH;
1526 qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
1527 qos.ImpersonationType = RPC_C_IMP_LEVEL_IMPERSONATE;
1528
1529 status = pRpcBindingSetAuthInfoExA(handle, (RPC_CSTR)domain_and_user, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
1530 RPC_C_AUTHN_WINNT, NULL, 0, &qos);
1531 ok(status == RPC_S_OK, "RpcBindingSetAuthInfoExA failed %d\n", status);
1532 }
1533
1534 #define test_is_server_listening(a,b) _test_is_server_listening(__LINE__,a,b)
1535 static void _test_is_server_listening(unsigned line, RPC_BINDING_HANDLE binding, RPC_STATUS expected_status)
1536 {
1537 RPC_STATUS status;
1538 status = RpcMgmtIsServerListening(binding);
1539 ok_(__FILE__,line)(status == expected_status, "RpcMgmtIsServerListening returned %u, expected %u\n",
1540 status, expected_status);
1541 }
1542
1543 #define test_is_server_listening2(a,b,c) _test_is_server_listening2(__LINE__,a,b,c)
1544 static void _test_is_server_listening2(unsigned line, RPC_BINDING_HANDLE binding, RPC_STATUS expected_status,
1545 RPC_STATUS expected_status2)
1546 {
1547 RPC_STATUS status;
1548 status = RpcMgmtIsServerListening(binding);
1549 ok_(__FILE__,line)(status == expected_status || status == expected_status2,
1550 "RpcMgmtIsServerListening returned %u, expected %u or %u\n",
1551 status, expected_status, expected_status2);
1552 }
1553
1554 static void
1555 client(const char *test)
1556 {
1557 static unsigned char iptcp[] = "ncacn_ip_tcp";
1558 static unsigned char np[] = "ncacn_np";
1559 static unsigned char ncalrpc[] = "ncalrpc";
1560 static unsigned char address[] = "127.0.0.1";
1561 static unsigned char address_np[] = "\\\\.";
1562 static unsigned char port[] = PORT;
1563 static unsigned char pipe[] = PIPE;
1564 static unsigned char guid[] = "00000000-4114-0704-2301-000000000000";
1565
1566 unsigned char *binding;
1567
1568 if (strcmp(test, "tcp_basic") == 0)
1569 {
1570 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1571 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1572
1573 run_tests();
1574 authinfo_test(RPC_PROTSEQ_TCP, 0);
1575 test_is_server_listening2(IServer_IfHandle, RPC_S_OK, RPC_S_ACCESS_DENIED);
1576
1577 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1578 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1579 }
1580 else if (strcmp(test, "tcp_secure") == 0)
1581 {
1582 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1583 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1584
1585 set_auth_info(IServer_IfHandle);
1586 authinfo_test(RPC_PROTSEQ_TCP, 1);
1587 test_is_server_listening(IServer_IfHandle, RPC_S_ACCESS_DENIED);
1588
1589 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1590 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1591 }
1592 else if (strcmp(test, "ncalrpc_basic") == 0)
1593 {
1594 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
1595 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1596
1597 run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */
1598 authinfo_test(RPC_PROTSEQ_LRPC, 0);
1599 test_is_server_listening(IServer_IfHandle, RPC_S_OK);
1600
1601 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1602 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1603 }
1604 else if (strcmp(test, "ncalrpc_secure") == 0)
1605 {
1606 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
1607 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1608
1609 set_auth_info(IServer_IfHandle);
1610 authinfo_test(RPC_PROTSEQ_LRPC, 1);
1611 test_is_server_listening(IServer_IfHandle, RPC_S_OK);
1612
1613 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1614 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1615 }
1616 else if (strcmp(test, "np_basic") == 0)
1617 {
1618 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, np, address_np, pipe, NULL, &binding), "RpcStringBindingCompose\n");
1619 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1620
1621 test_is_server_listening(IServer_IfHandle, RPC_S_OK);
1622 run_tests();
1623 authinfo_test(RPC_PROTSEQ_NMP, 0);
1624 test_is_server_listening(IServer_IfHandle, RPC_S_OK);
1625 stop();
1626 test_is_server_listening(IServer_IfHandle, RPC_S_NOT_LISTENING);
1627
1628 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1629 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1630 }
1631 }
1632
1633 static void
1634 server(void)
1635 {
1636 static unsigned char iptcp[] = "ncacn_ip_tcp";
1637 static unsigned char port[] = PORT;
1638 static unsigned char np[] = "ncacn_np";
1639 static unsigned char pipe[] = PIPE;
1640 static unsigned char ncalrpc[] = "ncalrpc";
1641 static unsigned char guid[] = "00000000-4114-0704-2301-000000000000";
1642 RPC_STATUS status, iptcp_status, np_status, ncalrpc_status;
1643 DWORD ret;
1644
1645 iptcp_status = RpcServerUseProtseqEpA(iptcp, 20, port, NULL);
1646 ok(iptcp_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status);
1647
1648 ncalrpc_status = RpcServerUseProtseqEpA(ncalrpc, 0, guid, NULL);
1649 ok(ncalrpc_status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", ncalrpc_status);
1650
1651 np_status = RpcServerUseProtseqEpA(np, 0, pipe, NULL);
1652 if (np_status == RPC_S_PROTSEQ_NOT_SUPPORTED)
1653 skip("Protocol sequence ncacn_np is not supported\n");
1654 else
1655 ok(np_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", np_status);
1656
1657 if (pRpcServerRegisterIfEx)
1658 {
1659 trace("Using RpcServerRegisterIfEx\n");
1660 status = pRpcServerRegisterIfEx(s_IServer_v0_0_s_ifspec, NULL, NULL,
1661 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,
1662 RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
1663 }
1664 else
1665 status = RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL);
1666 ok(status == RPC_S_OK, "RpcServerRegisterIf failed with status %d\n", status);
1667 test_is_server_listening(NULL, RPC_S_NOT_LISTENING);
1668 status = RpcServerListen(1, 20, TRUE);
1669 ok(status == RPC_S_OK, "RpcServerListen failed with status %d\n", status);
1670 test_is_server_listening(NULL, RPC_S_OK);
1671 stop_event = CreateEventW(NULL, FALSE, FALSE, NULL);
1672 ok(stop_event != NULL, "CreateEvent failed with error %d\n", GetLastError());
1673
1674 if (iptcp_status == RPC_S_OK)
1675 run_client("tcp_basic");
1676 else
1677 skip("tcp tests skipped due to earlier failure\n");
1678
1679 if (ncalrpc_status == RPC_S_OK)
1680 {
1681 run_client("ncalrpc_basic");
1682 if (pGetUserNameExA)
1683 {
1684 /* we don't need to register RPC_C_AUTHN_WINNT for ncalrpc */
1685 run_client("ncalrpc_secure");
1686 }
1687 }
1688 else
1689 skip("lrpc tests skipped due to earlier failure\n");
1690
1691 if (np_status == RPC_S_OK)
1692 run_client("np_basic");
1693 else
1694 {
1695 skip("np_basic tests skipped due to earlier failure\n");
1696 /* np client is what signals stop_event, so bail out if we didn't run do it */
1697 return;
1698 }
1699
1700 ret = WaitForSingleObject(stop_event, 1000);
1701 ok(WAIT_OBJECT_0 == ret, "WaitForSingleObject\n");
1702 /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
1703 * forever, so don't bother calling it in this case */
1704 if (ret == WAIT_OBJECT_0)
1705 {
1706 status = RpcMgmtWaitServerListen();
1707 todo_wine {
1708 ok(status == RPC_S_OK, "RpcMgmtWaitServerListening failed with status %d\n", status);
1709 }
1710 }
1711 }
1712
1713 START_TEST(server)
1714 {
1715 int argc;
1716 char **argv;
1717
1718 InitFunctionPointers();
1719
1720 if (pGetUserNameExA)
1721 {
1722 ULONG size = 0;
1723 ok(!pGetUserNameExA(NameSamCompatible, NULL, &size), "GetUserNameExA\n");
1724 domain_and_user = HeapAlloc(GetProcessHeap(), 0, size);
1725 ok(pGetUserNameExA(NameSamCompatible, domain_and_user, &size), "GetUserNameExA\n");
1726 }
1727 else
1728 win_skip("GetUserNameExA is needed for some authentication tests\n");
1729
1730 argc = winetest_get_mainargs(&argv);
1731 progname = argv[0];
1732
1733 if (argc == 3)
1734 {
1735 RpcTryExcept
1736 {
1737 client(argv[2]);
1738 }
1739 RpcExcept(TRUE)
1740 {
1741 trace("Exception %d\n", RpcExceptionCode());
1742 }
1743 RpcEndExcept
1744 }
1745 else
1746 server();
1747
1748 HeapFree(GetProcessHeap(), 0, domain_and_user);
1749 }