cryptdlg: Add Swedish translation.
[wine.git] / dlls / rpcrt4 / tests / server.c
blobf07fad4f7f31a366c30682b35dd032f683590616
1 /*
2 * Tests for WIDL and RPC server/clients.
4 * Copyright (C) Google 2007 (Dan Hipschman)
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.
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.
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
21 #include <windows.h>
22 #include <secext.h>
23 #include <rpcdce.h>
24 #include "wine/test.h"
25 #include "server.h"
26 #include "server_defines.h"
28 #include <stddef.h>
29 #include <stdio.h>
30 #include <stdlib.h>
32 #define PORT "4114"
33 #define PIPE "\\pipe\\wine_rpcrt4_test"
35 #define INT_CODE 4198
37 static const char *progname;
38 static BOOL old_windows_version;
40 static HANDLE stop_event;
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);
51 static char *domain_and_user;
53 /* type check statements generated in header file */
54 fnprintf *p_printf = printf;
56 static void InitFunctionPointers(void)
58 HMODULE hrpcrt4 = GetModuleHandleA("rpcrt4.dll");
59 HMODULE hsecur32 = LoadLibraryA("secur32.dll");
61 pNDRSContextMarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextMarshall2");
62 pNDRSContextUnmarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextUnmarshall2");
63 pRpcServerRegisterIfEx = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterIfEx");
64 pRpcBindingSetAuthInfoExA = (void *)GetProcAddress(hrpcrt4, "RpcBindingSetAuthInfoExA");
65 pRpcServerRegisterAuthInfoA = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterAuthInfoA");
66 pGetUserNameExA = (void *)GetProcAddress(hsecur32, "GetUserNameExA");
68 if (!pNDRSContextMarshall2) old_windows_version = TRUE;
71 void __RPC_FAR *__RPC_USER
72 midl_user_allocate(SIZE_T n)
74 return HeapAlloc(GetProcessHeap(), 0, n);
77 void __RPC_USER
78 midl_user_free(void __RPC_FAR *p)
80 HeapFree(GetProcessHeap(), 0, p);
83 static char *
84 xstrdup(const char *s)
86 char *d = HeapAlloc(GetProcessHeap(), 0, strlen(s) + 1);
87 strcpy(d, s);
88 return d;
91 int
92 s_int_return(void)
94 return INT_CODE;
97 int
98 s_square(int x)
100 return x * x;
104 s_sum(int x, int y)
106 return x + y;
109 void
110 s_square_out(int x, int *y)
112 *y = s_square(x);
115 void
116 s_square_ref(int *x)
118 *x = s_square(*x);
122 s_str_length(const char *s)
124 return strlen(s);
128 s_str_t_length(str_t s)
130 return strlen(s);
134 s_cstr_length(const char *s, int n)
136 int len = 0;
137 while (0 < n-- && *s++)
138 ++len;
139 return len;
143 s_dot_self(vector_t *v)
145 return s_square(v->x) + s_square(v->y) + s_square(v->z);
148 double
149 s_square_half(double x, double *y)
151 *y = x / 2.0;
152 return x * x;
155 float
156 s_square_half_float(float x, float *y)
158 *y = x / 2.0f;
159 return x * x;
162 LONG
163 s_square_half_long(LONG x, LONG *y)
165 *y = x / 2;
166 return x * x;
170 s_sum_fixed_array(int a[5])
172 return a[0] + a[1] + a[2] + a[3] + a[4];
176 s_pints_sum(pints_t *pints)
178 return *pints->pi + **pints->ppi + ***pints->pppi;
181 double
182 s_ptypes_sum(ptypes_t *pt)
184 return *pt->pc + *pt->ps + *pt->pl + *pt->pf + *pt->pd;
188 s_dot_pvectors(pvectors_t *p)
190 return p->pu->x * (*p->pv)->x + p->pu->y * (*p->pv)->y + p->pu->z * (*p->pv)->z;
194 s_sum_sp(sp_t *sp)
196 return sp->x + sp->s->x;
199 double
200 s_square_sun(sun_t *su)
202 switch (su->s)
204 case SUN_I: return su->u.i * su->u.i;
205 case SUN_F1:
206 case SUN_F2: return su->u.f * su->u.f;
207 case SUN_PI: return (*su->u.pi) * (*su->u.pi);
208 default:
209 return 0.0;
214 s_test_list_length(test_list_t *list)
216 return (list->t == TL_LIST
217 ? 1 + s_test_list_length(list->u.tail)
218 : 0);
222 s_sum_fixed_int_3d(int m[2][3][4])
224 int i, j, k;
225 int sum = 0;
227 for (i = 0; i < 2; ++i)
228 for (j = 0; j < 3; ++j)
229 for (k = 0; k < 4; ++k)
230 sum += m[i][j][k];
232 return sum;
236 s_sum_conf_array(int x[], int n)
238 int *p = x, *end = p + n;
239 int sum = 0;
241 while (p < end)
242 sum += *p++;
244 return sum;
248 s_sum_conf_ptr_by_conf_ptr(int n1, int *n2_then_x1, int *x2)
250 int i;
251 int sum = 0;
252 if(n1 == 0)
253 return 0;
255 for(i = 1; i < n1; ++i)
256 sum += n2_then_x1[i];
258 for(i = 0; i < *n2_then_x1; ++i)
259 sum += x2[i];
261 return sum;
265 s_sum_unique_conf_array(int x[], int n)
267 return s_sum_conf_array(x, n);
271 s_sum_unique_conf_ptr(int *x, int n)
273 return x ? s_sum_conf_array(x, n) : 0;
277 s_sum_var_array(int x[20], int n)
279 ok(0 <= n, "RPC sum_var_array\n");
280 ok(n <= 20, "RPC sum_var_array\n");
282 return s_sum_conf_array(x, n);
286 s_sum_complex_array(int n, refpint_t pi[])
288 int total = 0;
289 for (; n > 0; n--)
290 total += *pi[n - 1];
291 return total;
295 s_dot_two_vectors(vector_t vs[2])
297 return vs[0].x * vs[1].x + vs[0].y * vs[1].y + vs[0].z * vs[1].z;
300 void
301 s_get_number_array(int x[20], int *n)
303 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
304 memcpy(x, c, sizeof(c));
305 *n = sizeof(c)/sizeof(c[0]);
309 s_sum_cs(cs_t *cs)
311 return s_sum_conf_array(cs->ca, cs->n);
315 s_sum_cps(cps_t *cps)
317 int sum = 0;
318 int i;
320 for (i = 0; i < *cps->pn; ++i)
321 sum += cps->ca1[i];
323 for (i = 0; i < 2 * cps->n; ++i)
324 sum += cps->ca2[i];
326 return sum;
330 s_sum_cpsc(cpsc_t *cpsc)
332 int sum = 0;
333 int i;
334 for (i = 0; i < (cpsc->c ? cpsc->a : cpsc->b); ++i)
335 sum += cpsc->ca[i];
336 return sum;
340 s_square_puint(puint_t p)
342 int n = atoi(p);
343 return n * n;
347 s_sum_puints(puints_t *p)
349 int sum = 0;
350 int i;
351 for (i = 0; i < p->n; ++i)
352 sum += atoi(p->ps[i]);
353 return sum;
357 s_sum_cpuints(cpuints_t *p)
359 int sum = 0;
360 int i;
361 for (i = 0; i < p->n; ++i)
362 sum += atoi(p->ps[i]);
363 return sum;
367 s_dot_copy_vectors(vector_t u, vector_t v)
369 return u.x * v.x + u.y * v.y + u.z * v.z;
373 s_square_test_us(test_us_t *tus)
375 int n = atoi(tus->us.x);
376 return n * n;
379 double
380 s_square_encu(encu_t *eu)
382 switch (eu->t)
384 case ENCU_I: return eu->tagged_union.i * eu->tagged_union.i;
385 case ENCU_F: return eu->tagged_union.f * eu->tagged_union.f;
386 default:
387 return 0.0;
391 double
392 s_square_unencu(int t, unencu_t *eu)
394 switch (t)
396 case ENCU_I: return eu->i * eu->i;
397 case ENCU_F: return eu->f * eu->f;
398 default:
399 return 0.0;
403 void
404 s_check_se2(se_t *s)
406 ok(s->f == E2, "check_se2\n");
410 s_sum_parr(int *a[3])
412 return s_sum_pcarr(a, 3);
416 s_sum_pcarr(int *a[], int n)
418 int i, s = 0;
419 for (i = 0; i < n; ++i)
420 s += *a[i];
421 return s;
425 s_enum_ord(e_t e)
427 switch (e)
429 case E1: return 1;
430 case E2: return 2;
431 case E3: return 3;
432 case E4: return 4;
433 default:
434 return 0;
438 double
439 s_square_encue(encue_t *eue)
441 switch (eue->t)
443 case E1: return eue->tagged_union.i1 * eue->tagged_union.i1;
444 case E2: return eue->tagged_union.f2 * eue->tagged_union.f2;
445 default:
446 return 0.0;
451 s_sum_toplev_conf_2n(int *x, int n)
453 int sum = 0;
454 int i;
455 for (i = 0; i < 2 * n; ++i)
456 sum += x[i];
457 return sum;
461 s_sum_toplev_conf_cond(int *x, int a, int b, int c)
463 int sum = 0;
464 int n = c ? a : b;
465 int i;
466 for (i = 0; i < n; ++i)
467 sum += x[i];
468 return sum;
471 double
472 s_sum_aligns(aligns_t *a)
474 return a->c + a->i + a->s + a->d;
478 s_sum_padded(padded_t *p)
480 return p->i + p->c;
484 s_sum_padded2(padded_t ps[2])
486 return s_sum_padded(&ps[0]) + s_sum_padded(&ps[1]);
490 s_sum_padded_conf(padded_t *ps, int n)
492 int sum = 0;
493 int i;
494 for (i = 0; i < n; ++i)
495 sum += s_sum_padded(&ps[i]);
496 return sum;
500 s_sum_bogus(bogus_t *b)
502 return *b->h.p1 + *b->p2 + *b->p3 + b->c;
505 void
506 s_check_null(int *null)
508 ok(!null, "RPC check_null\n");
512 s_str_struct_len(str_struct_t *s)
514 return lstrlenA(s->s);
518 s_wstr_struct_len(wstr_struct_t *s)
520 return lstrlenW(s->s);
524 s_sum_doub_carr(doub_carr_t *dc)
526 int i, j;
527 int sum = 0;
528 for (i = 0; i < dc->n; ++i)
529 for (j = 0; j < dc->a[i]->n; ++j)
530 sum += dc->a[i]->a[j];
531 return sum;
534 void
535 s_make_pyramid_doub_carr(unsigned char n, doub_carr_t **dc)
537 doub_carr_t *t;
538 int i, j;
539 t = MIDL_user_allocate(FIELD_OFFSET(doub_carr_t, a[n]));
540 t->n = n;
541 for (i = 0; i < n; ++i)
543 int v = i + 1;
544 t->a[i] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t, a[v]));
545 t->a[i]->n = v;
546 for (j = 0; j < v; ++j)
547 t->a[i]->a[j] = j + 1;
549 *dc = t;
552 unsigned
553 s_hash_bstr(bstr_t b)
555 short n = b[-1];
556 short *s = b;
557 unsigned hash = 0;
558 short i;
559 for (i = 0; i < n; ++i)
560 hash = 5 * hash + (unsigned) s[i];
561 return hash;
564 void
565 s_get_name(name_t *name)
567 const char bossman[] = "Jeremy White";
568 memcpy(name->name, bossman, min(name->size, sizeof(bossman)));
569 /* ensure nul-termination */
570 if (name->size < sizeof(bossman))
571 name->name[name->size - 1] = 0;
575 s_sum_pcarr2(int n, int **pa)
577 return s_sum_conf_array(*pa, n);
581 s_sum_L1_norms(int n, vector_t *vs)
583 int i;
584 int sum = 0;
585 for (i = 0; i < n; ++i)
586 sum += abs(vs[i].x) + abs(vs[i].y) + abs(vs[i].z);
587 return sum;
590 s123_t *
591 s_get_s123(void)
593 s123_t *s = MIDL_user_allocate(sizeof *s);
594 s->f1 = 1;
595 s->f2 = 2;
596 s->f3 = 3;
597 return s;
600 str_t
601 s_get_filename(void)
603 return (char *)__FILE__;
606 int s_echo_ranged_int(int n)
608 return n;
611 void s_get_ranged_enum(renum_t *re)
613 *re = RE3;
616 void
617 s_context_handle_test(void)
619 NDR_SCONTEXT h;
620 RPC_BINDING_HANDLE binding;
621 RPC_STATUS status;
622 unsigned char buf[20];
623 static RPC_SERVER_INTERFACE server_if =
625 sizeof(RPC_SERVER_INTERFACE),
626 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
627 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
628 NULL,
636 binding = I_RpcGetCurrentCallHandle();
637 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
639 if (!pNDRSContextMarshall2 || !pNDRSContextUnmarshall2)
641 win_skip("NDRSContextMarshall2 or NDRSContextUnmarshall2 not exported from rpcrt4.dll\n");
642 return;
645 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
646 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
648 /* marshal a context handle with NULL userContext */
649 memset(buf, 0xcc, sizeof(buf));
650 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
651 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
652 ok(UuidIsNil((UUID *)&buf[4], &status), "uuid should have been nil\n");
654 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
655 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
657 /* marshal a context handle with non-NULL userContext */
658 memset(buf, 0xcc, sizeof(buf));
659 h->userContext = (void *)0xdeadbeef;
660 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
661 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
662 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
664 /* raises ERROR_INVALID_HANDLE exception on Vista upwards */
665 if (0)
667 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
668 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
669 ok(h->userContext == (void *)0xdeadbeef, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
671 /* marshal a context handle with an interface specified */
672 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
673 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
675 memset(buf, 0xcc, sizeof(buf));
676 h->userContext = (void *)0xcafebabe;
677 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
678 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
679 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
681 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
682 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
683 ok(h->userContext == (void *)0xcafebabe, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
686 /* test same interface data, but different pointer */
687 /* raises ERROR_INVALID_HANDLE exception */
688 if (0)
690 RPC_SERVER_INTERFACE server_if_clone = server_if;
692 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if_clone.InterfaceId, 0);
695 /* test different interface data, but different pointer */
696 /* raises ERROR_INVALID_HANDLE exception */
697 if (0)
699 static RPC_SERVER_INTERFACE server_if2 =
701 sizeof(RPC_SERVER_INTERFACE),
702 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
703 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
704 NULL,
711 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
713 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if2.InterfaceId, 0);
717 void
718 s_get_numbers(int length, int size, pints_t n[])
720 int i;
721 for (i = 0; i < length; i++)
723 n[i].pi = midl_user_allocate(sizeof(*n[i].pi));
724 *n[i].pi = i;
725 n[i].ppi = NULL;
726 n[i].pppi = NULL;
730 void
731 s_get_numbers_struct(numbers_struct_t **ns)
733 int i;
734 *ns = midl_user_allocate(FIELD_OFFSET(numbers_struct_t, numbers[5]));
735 if (!*ns) return;
736 (*ns)->length = 5;
737 (*ns)->size = 5;
738 for (i = 0; i < (*ns)->length; i++)
740 (*ns)->numbers[i].pi = NULL;
741 (*ns)->numbers[i].ppi = NULL;
742 (*ns)->numbers[i].pppi = NULL;
744 (*ns)->numbers[0].pi = midl_user_allocate(sizeof(*(*ns)->numbers[i].pi));
745 *(*ns)->numbers[0].pi = 5;
748 void
749 s_full_pointer_test(int *a, int *b)
751 ok(*a == 42, "Expected *a to be 42 instead of %d\n", *a);
752 ok(*b == 42, "Expected *b to be 42 instead of %d\n", *a);
753 ok(a == b, "Expected a (%p) to point to the same memory as b (%p)\n", a, b);
756 void
757 s_full_pointer_null_test(int *a, int *b)
759 ok(*a == 42, "Expected *a to be 42 instead of %d\n", *a);
760 ok(b == NULL, "Expected b to be NULL instead of %p\n", b);
763 void
764 s_stop(void)
766 ok(RPC_S_OK == RpcMgmtStopServerListening(NULL), "RpcMgmtStopServerListening\n");
767 ok(RPC_S_OK == RpcServerUnregisterIf(NULL, NULL, FALSE), "RpcServerUnregisterIf\n");
768 ok(SetEvent(stop_event), "SetEvent\n");
771 static void
772 make_cmdline(char buffer[MAX_PATH], const char *test)
774 sprintf(buffer, "%s server %s", progname, test);
777 static void
778 run_client(const char *test)
780 char cmdline[MAX_PATH];
781 PROCESS_INFORMATION info;
782 STARTUPINFOA startup;
784 memset(&startup, 0, sizeof startup);
785 startup.cb = sizeof startup;
787 make_cmdline(cmdline, test);
788 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
789 winetest_wait_child_process( info.hProcess );
790 ok(CloseHandle(info.hProcess), "CloseHandle\n");
791 ok(CloseHandle(info.hThread), "CloseHandle\n");
794 static void
795 basic_tests(void)
797 char string[] = "I am a string";
798 WCHAR wstring[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
799 int f[5] = {1, 3, 0, -2, -4};
800 vector_t a = {1, 3, 7};
801 vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2;
802 pvectors_t pvecs = {&vec1, &pvec2};
803 sp_inner_t spi = {42};
804 sp_t sp = {-13, &spi};
805 aligns_t aligns;
806 pints_t pints;
807 ptypes_t ptypes;
808 padded_t padded;
809 padded_t padded2[2];
810 bogus_t bogus;
811 int i1, i2, i3, *pi2, *pi3, **ppi3;
812 double u, v;
813 float s, t;
814 LONG q, r;
815 short h;
816 char c;
817 int x;
818 str_struct_t ss = {string};
819 wstr_struct_t ws = {wstring};
820 str_t str;
821 se_t se;
822 renum_t re;
824 ok(int_return() == INT_CODE, "RPC int_return\n");
826 ok(square(7) == 49, "RPC square\n");
827 ok(sum(23, -4) == 19, "RPC sum\n");
829 x = 0;
830 square_out(11, &x);
831 ok(x == 121, "RPC square_out\n");
833 x = 5;
834 square_ref(&x);
835 ok(x == 25, "RPC square_ref\n");
837 ok(str_length(string) == strlen(string), "RPC str_length\n");
838 ok(str_t_length(string) == strlen(string), "RPC str_length\n");
839 ok(dot_self(&a) == 59, "RPC dot_self\n");
841 ok(str_struct_len(&ss) == lstrlenA(string), "RPC str_struct_len\n");
842 ok(wstr_struct_len(&ws) == lstrlenW(wstring), "RPC str_struct_len\n");
844 v = 0.0;
845 u = square_half(3.0, &v);
846 ok(u == 9.0, "RPC square_half\n");
847 ok(v == 1.5, "RPC square_half\n");
849 t = 0.0f;
850 s = square_half_float(3.0f, &t);
851 ok(s == 9.0f, "RPC square_half_float\n");
852 ok(t == 1.5f, "RPC square_half_float\n");
854 r = 0;
855 q = square_half_long(3, &r);
856 ok(q == 9, "RPC square_half_long\n");
857 ok(r == 1, "RPC square_half_long\n");
859 i1 = 19;
860 i2 = -3;
861 i3 = -29;
862 pi2 = &i2;
863 pi3 = &i3;
864 ppi3 = &pi3;
865 pints.pi = &i1;
866 pints.ppi = &pi2;
867 pints.pppi = &ppi3;
868 ok(pints_sum(&pints) == -13, "RPC pints_sum\n");
870 c = 10;
871 h = 3;
872 q = 14;
873 s = -5.0f;
874 u = 11.0;
875 ptypes.pc = &c;
876 ptypes.ps = &h;
877 ptypes.pl = &q;
878 ptypes.pf = &s;
879 ptypes.pd = &u;
880 ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n");
882 ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n");
883 ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n");
884 ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n");
885 ok(sum_sp(&sp) == 29, "RPC sum_sp\n");
887 ok(enum_ord(E1) == 1, "RPC enum_ord\n");
888 ok(enum_ord(E2) == 2, "RPC enum_ord\n");
889 ok(enum_ord(E3) == 3, "RPC enum_ord\n");
890 ok(enum_ord(E4) == 4, "RPC enum_ord\n");
892 se.f = E2;
893 check_se2(&se);
895 memset(&aligns, 0, sizeof(aligns));
896 aligns.c = 3;
897 aligns.i = 4;
898 aligns.s = 5;
899 aligns.d = 6.0;
900 ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
902 padded.i = -3;
903 padded.c = 8;
904 ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
905 padded2[0].i = -5;
906 padded2[0].c = 1;
907 padded2[1].i = 3;
908 padded2[1].c = 7;
909 ok(sum_padded2(padded2) == 6, "RPC sum_padded2\n");
910 padded2[0].i = -5;
911 padded2[0].c = 1;
912 padded2[1].i = 3;
913 padded2[1].c = 7;
914 ok(sum_padded_conf(padded2, 2) == 6, "RPC sum_padded_conf\n");
916 i1 = 14;
917 i2 = -7;
918 i3 = -4;
919 bogus.h.p1 = &i1;
920 bogus.p2 = &i2;
921 bogus.p3 = &i3;
922 bogus.c = 9;
923 ok(sum_bogus(&bogus) == 12, "RPC sum_bogus\n");
925 check_null(NULL);
927 str = get_filename();
928 ok(!strcmp(str, __FILE__), "get_filename() returned %s instead of %s\n", str, __FILE__);
929 midl_user_free(str);
931 x = echo_ranged_int(0);
932 ok(x == 0, "echo_ranged_int() returned %d instead of 0\n", x);
933 x = echo_ranged_int(100);
934 ok(x == 100, "echo_ranged_int() returned %d instead of 100\n", x);
936 if (!old_windows_version)
938 get_ranged_enum(&re);
939 ok(re == RE3, "get_ranged_enum() returned %d instead of RE3\n", re);
943 static void
944 union_tests(void)
946 encue_t eue;
947 encu_t eu;
948 unencu_t uneu;
949 sun_t su;
950 int i;
952 su.s = SUN_I;
953 su.u.i = 9;
954 ok(square_sun(&su) == 81.0, "RPC square_sun\n");
956 su.s = SUN_F1;
957 su.u.f = 5.0;
958 ok(square_sun(&su) == 25.0, "RPC square_sun\n");
960 su.s = SUN_F2;
961 su.u.f = -2.0;
962 ok(square_sun(&su) == 4.0, "RPC square_sun\n");
964 su.s = SUN_PI;
965 su.u.pi = &i;
966 i = 11;
967 ok(square_sun(&su) == 121.0, "RPC square_sun\n");
969 eu.t = ENCU_I;
970 eu.tagged_union.i = 7;
971 ok(square_encu(&eu) == 49.0, "RPC square_encu\n");
973 eu.t = ENCU_F;
974 eu.tagged_union.f = 3.0;
975 ok(square_encu(&eu) == 9.0, "RPC square_encu\n");
977 uneu.i = 4;
978 ok(square_unencu(ENCU_I, &uneu) == 16.0, "RPC square_unencu\n");
980 uneu.f = 5.0;
981 ok(square_unencu(ENCU_F, &uneu) == 25.0, "RPC square_unencu\n");
983 eue.t = E1;
984 eue.tagged_union.i1 = 8;
985 ok(square_encue(&eue) == 64.0, "RPC square_encue\n");
987 eue.t = E2;
988 eue.tagged_union.f2 = 10.0;
989 ok(square_encue(&eue) == 100.0, "RPC square_encue\n");
992 static test_list_t *
993 null_list(void)
995 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
996 n->t = TL_NULL;
997 n->u.x = 0;
998 return n;
1001 static test_list_t *
1002 make_list(test_list_t *tail)
1004 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
1005 n->t = TL_LIST;
1006 n->u.tail = tail;
1007 return n;
1010 static void
1011 free_list(test_list_t *list)
1013 if (list->t == TL_LIST)
1014 free_list(list->u.tail);
1015 HeapFree(GetProcessHeap(), 0, list);
1018 ULONG __RPC_USER
1019 puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
1021 return start + sizeof(int);
1024 unsigned char * __RPC_USER
1025 puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
1027 int n = atoi(*p);
1028 memcpy(buffer, &n, sizeof n);
1029 return buffer + sizeof n;
1032 unsigned char * __RPC_USER
1033 puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
1035 int n;
1036 memcpy(&n, buffer, sizeof n);
1037 *p = HeapAlloc(GetProcessHeap(), 0, 10);
1038 sprintf(*p, "%d", n);
1039 return buffer + sizeof n;
1042 void __RPC_USER
1043 puint_t_UserFree(ULONG *flags, puint_t *p)
1045 HeapFree(GetProcessHeap(), 0, *p);
1048 ULONG __RPC_USER
1049 us_t_UserSize(ULONG *flags, ULONG start, us_t *pus)
1051 return start + sizeof(struct wire_us);
1054 unsigned char * __RPC_USER
1055 us_t_UserMarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
1057 struct wire_us wus;
1058 wus.x = atoi(pus->x);
1059 memcpy(buffer, &wus, sizeof wus);
1060 return buffer + sizeof wus;
1063 unsigned char * __RPC_USER
1064 us_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
1066 struct wire_us wus;
1067 memcpy(&wus, buffer, sizeof wus);
1068 pus->x = HeapAlloc(GetProcessHeap(), 0, 10);
1069 sprintf(pus->x, "%d", wus.x);
1070 return buffer + sizeof wus;
1073 void __RPC_USER
1074 us_t_UserFree(ULONG *flags, us_t *pus)
1076 HeapFree(GetProcessHeap(), 0, pus->x);
1079 ULONG __RPC_USER
1080 bstr_t_UserSize(ULONG *flags, ULONG start, bstr_t *b)
1082 return start + FIELD_OFFSET(user_bstr_t, data[(*b)[-1]]);
1085 unsigned char * __RPC_USER
1086 bstr_t_UserMarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1088 wire_bstr_t wb = (wire_bstr_t) buffer;
1089 wb->n = (*b)[-1];
1090 memcpy(&wb->data, *b, wb->n * sizeof wb->data[0]);
1091 return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1094 unsigned char * __RPC_USER
1095 bstr_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1097 wire_bstr_t wb = (wire_bstr_t) buffer;
1098 short *data = HeapAlloc(GetProcessHeap(), 0, (wb->n + 1) * sizeof *data);
1099 data[0] = wb->n;
1100 memcpy(&data[1], wb->data, wb->n * sizeof data[1]);
1101 *b = &data[1];
1102 return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1105 void __RPC_USER
1106 bstr_t_UserFree(ULONG *flags, bstr_t *b)
1108 HeapFree(GetProcessHeap(), 0, &((*b)[-1]));
1111 static void
1112 pointer_tests(void)
1114 int a[] = {1, 2, 3, 4};
1115 char p1[] = "11";
1116 test_list_t *list = make_list(make_list(make_list(null_list())));
1117 test_us_t tus = {{p1}};
1118 int *pa[4];
1119 puints_t pus;
1120 cpuints_t cpus;
1121 short bstr_data[] = { 5, 'H', 'e', 'l', 'l', 'o' };
1122 bstr_t bstr = &bstr_data[1];
1123 name_t name;
1124 void *buffer;
1125 int *pa2;
1126 s123_t *s123;
1127 int val = 42;
1129 ok(test_list_length(list) == 3, "RPC test_list_length\n");
1130 ok(square_puint(p1) == 121, "RPC square_puint\n");
1131 pus.n = 4;
1132 pus.ps = HeapAlloc(GetProcessHeap(), 0, pus.n * sizeof pus.ps[0]);
1133 pus.ps[0] = xstrdup("5");
1134 pus.ps[1] = xstrdup("6");
1135 pus.ps[2] = xstrdup("7");
1136 pus.ps[3] = xstrdup("8");
1137 ok(sum_puints(&pus) == 26, "RPC sum_puints\n");
1138 HeapFree(GetProcessHeap(), 0, pus.ps[0]);
1139 HeapFree(GetProcessHeap(), 0, pus.ps[1]);
1140 HeapFree(GetProcessHeap(), 0, pus.ps[2]);
1141 HeapFree(GetProcessHeap(), 0, pus.ps[3]);
1142 HeapFree(GetProcessHeap(), 0, pus.ps);
1143 cpus.n = 4;
1144 cpus.ps = HeapAlloc(GetProcessHeap(), 0, cpus.n * sizeof cpus.ps[0]);
1145 cpus.ps[0] = xstrdup("5");
1146 cpus.ps[1] = xstrdup("6");
1147 cpus.ps[2] = xstrdup("7");
1148 cpus.ps[3] = xstrdup("8");
1149 ok(sum_cpuints(&cpus) == 26, "RPC sum_puints\n");
1150 HeapFree(GetProcessHeap(), 0, cpus.ps[0]);
1151 HeapFree(GetProcessHeap(), 0, cpus.ps[1]);
1152 HeapFree(GetProcessHeap(), 0, cpus.ps[2]);
1153 HeapFree(GetProcessHeap(), 0, cpus.ps[3]);
1154 HeapFree(GetProcessHeap(), 0, cpus.ps);
1155 ok(square_test_us(&tus) == 121, "RPC square_test_us\n");
1157 pa[0] = &a[0];
1158 pa[1] = &a[1];
1159 pa[2] = &a[2];
1160 ok(sum_parr(pa) == 6, "RPC sum_parr\n");
1162 pa[0] = &a[0];
1163 pa[1] = &a[1];
1164 pa[2] = &a[2];
1165 pa[3] = &a[3];
1166 ok(sum_pcarr(pa, 4) == 10, "RPC sum_pcarr\n");
1168 ok(hash_bstr(bstr) == s_hash_bstr(bstr), "RPC hash_bstr_data\n");
1170 free_list(list);
1172 if (!old_windows_version)
1174 name.size = 10;
1175 name.name = buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, name.size);
1176 get_name(&name);
1177 ok(name.name == buffer, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name.name, buffer);
1178 ok(!strcmp(name.name, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name.name);
1179 HeapFree(GetProcessHeap(), 0, name.name);
1182 pa2 = a;
1183 ok(sum_pcarr2(4, &pa2) == 10, "RPC sum_pcarr2\n");
1185 s123 = get_s123();
1186 ok(s123->f1 == 1 && s123->f2 == 2 && s123->f3 == 3, "RPC get_s123\n");
1187 MIDL_user_free(s123);
1189 full_pointer_test(&val, &val);
1190 full_pointer_null_test(&val, NULL);
1193 static int
1194 check_pyramid_doub_carr(doub_carr_t *dc)
1196 int i, j;
1197 for (i = 0; i < dc->n; ++i)
1198 for (j = 0; j < dc->a[i]->n; ++j)
1199 if (dc->a[i]->a[j] != j + 1)
1200 return FALSE;
1201 return TRUE;
1204 static void
1205 free_pyramid_doub_carr(doub_carr_t *dc)
1207 int i;
1208 for (i = 0; i < dc->n; ++i)
1209 MIDL_user_free(dc->a[i]);
1210 MIDL_user_free(dc);
1213 static void
1214 array_tests(void)
1216 int m[2][3][4] =
1218 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1219 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1221 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1222 int c2[] = {10, 100, 200};
1223 int c3[20];
1224 vector_t vs[2] = {{1, -2, 3}, {4, -5, -6}};
1225 cps_t cps;
1226 cpsc_t cpsc;
1227 cs_t *cs;
1228 int n;
1229 int ca[5] = {1, -2, 3, -4, 5};
1230 doub_carr_t *dc;
1231 int *pi;
1232 pints_t api[5];
1233 numbers_struct_t *ns;
1234 refpint_t rpi[5];
1236 if (!old_windows_version)
1238 const char str1[25] = "Hello";
1239 ok(cstr_length(str1, sizeof str1) == strlen(str1), "RPC cstr_length\n");
1242 ok(sum_fixed_int_3d(m) == 4116, "RPC sum_fixed_int_3d\n");
1244 ok(sum_conf_array(c, 10) == 45, "RPC sum_conf_array\n");
1245 ok(sum_conf_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1246 ok(sum_conf_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1247 ok(sum_conf_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1249 ok(sum_conf_ptr_by_conf_ptr(1, c2, c) == 45, "RPC sum_conf_ptr_by_conf_ptr\n");
1250 ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 345, "RPC sum_conf_ptr_by_conf_ptr\n");
1251 c2[0] = 0;
1252 ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 300, "RPC sum_conf_ptr_by_conf_ptr\n");
1254 ok(sum_unique_conf_array(ca, 4) == -2, "RPC sum_unique_conf_array\n");
1255 ok(sum_unique_conf_ptr(ca, 5) == 3, "RPC sum_unique_conf_array\n");
1256 ok(sum_unique_conf_ptr(NULL, 10) == 0, "RPC sum_unique_conf_array\n");
1258 get_number_array(c3, &n);
1259 ok(n == 10, "RPC get_num_array\n");
1260 for (; n > 0; n--)
1261 ok(c3[n-1] == c[n-1], "get_num_array returned wrong value %d @ %d\n",
1262 c3[n-1], n);
1263 ok(sum_var_array(c, 10) == 45, "RPC sum_conf_array\n");
1264 ok(sum_var_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1265 ok(sum_var_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1266 ok(sum_var_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1268 ok(dot_two_vectors(vs) == -4, "RPC dot_two_vectors\n");
1269 cs = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t, ca[5]));
1270 cs->n = 5;
1271 cs->ca[0] = 3;
1272 cs->ca[1] = 5;
1273 cs->ca[2] = -2;
1274 cs->ca[3] = -1;
1275 cs->ca[4] = -4;
1276 ok(sum_cs(cs) == 1, "RPC sum_cs\n");
1277 HeapFree(GetProcessHeap(), 0, cs);
1279 n = 5;
1280 cps.pn = &n;
1281 cps.ca1 = &c[2];
1282 cps.n = 3;
1283 cps.ca2 = &c[3];
1284 ok(sum_cps(&cps) == 53, "RPC sum_cps\n");
1286 cpsc.a = 4;
1287 cpsc.b = 5;
1288 cpsc.c = 1;
1289 cpsc.ca = c;
1290 ok(sum_cpsc(&cpsc) == 6, "RPC sum_cpsc\n");
1291 cpsc.a = 4;
1292 cpsc.b = 5;
1293 cpsc.c = 0;
1294 cpsc.ca = c;
1295 ok(sum_cpsc(&cpsc) == 10, "RPC sum_cpsc\n");
1297 ok(sum_toplev_conf_2n(c, 3) == 15, "RPC sum_toplev_conf_2n\n");
1298 ok(sum_toplev_conf_cond(c, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1299 ok(sum_toplev_conf_cond(c, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1301 dc = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_t, a[2]));
1302 dc->n = 2;
1303 dc->a[0] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t, a[3]));
1304 dc->a[0]->n = 3;
1305 dc->a[0]->a[0] = 5;
1306 dc->a[0]->a[1] = 1;
1307 dc->a[0]->a[2] = 8;
1308 dc->a[1] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t, a[2]));
1309 dc->a[1]->n = 2;
1310 dc->a[1]->a[0] = 2;
1311 dc->a[1]->a[1] = 3;
1312 ok(sum_doub_carr(dc) == 19, "RPC sum_doub_carr\n");
1313 HeapFree(GetProcessHeap(), 0, dc->a[0]);
1314 HeapFree(GetProcessHeap(), 0, dc->a[1]);
1315 HeapFree(GetProcessHeap(), 0, dc);
1317 dc = NULL;
1318 make_pyramid_doub_carr(4, &dc);
1319 ok(check_pyramid_doub_carr(dc), "RPC make_pyramid_doub_carr\n");
1320 free_pyramid_doub_carr(dc);
1322 ok(sum_L1_norms(2, vs) == 21, "RPC sum_L1_norms\n");
1324 memset(api, 0, sizeof(api));
1325 pi = HeapAlloc(GetProcessHeap(), 0, sizeof(*pi));
1326 *pi = -1;
1327 api[0].pi = pi;
1328 get_numbers(1, 1, api);
1329 ok(api[0].pi == pi, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi, api[0].pi);
1330 ok(*api[0].pi == 0, "pi unmarshalled incorrectly %d\n", *api[0].pi);
1332 if (!old_windows_version)
1334 ns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(numbers_struct_t, numbers[5]));
1335 ns->length = 5;
1336 ns->size = 5;
1337 ns->numbers[0].pi = pi;
1338 get_numbers_struct(&ns);
1339 ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi);
1340 ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
1341 HeapFree(GetProcessHeap(), 0, ns);
1343 HeapFree(GetProcessHeap(), 0, pi);
1345 pi = HeapAlloc(GetProcessHeap(), 0, 5 * sizeof(*pi));
1346 pi[0] = 3; rpi[0] = &pi[0];
1347 pi[1] = 5; rpi[1] = &pi[1];
1348 pi[2] = -2; rpi[2] = &pi[2];
1349 pi[3] = -1; rpi[3] = &pi[3];
1350 pi[4] = -4; rpi[4] = &pi[4];
1351 ok(sum_complex_array(5, rpi) == 1, "RPC sum_complex_array\n");
1352 HeapFree(GetProcessHeap(), 0, pi);
1355 void
1356 s_authinfo_test(unsigned int protseq, int secure)
1358 RPC_BINDING_HANDLE binding;
1359 RPC_STATUS status;
1360 ULONG level, authnsvc;
1361 RPC_AUTHZ_HANDLE privs;
1362 unsigned char *principal;
1364 binding = I_RpcGetCurrentCallHandle();
1365 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
1367 level = authnsvc = 0xdeadbeef;
1368 privs = (RPC_AUTHZ_HANDLE)0xdeadbeef;
1369 principal = (unsigned char *)0xdeadbeef;
1371 if (secure || protseq == RPC_PROTSEQ_LRPC)
1373 status = RpcBindingInqAuthClientA(binding, &privs, &principal, &level, &authnsvc, NULL);
1374 if (status == RPC_S_CANNOT_SUPPORT)
1376 win_skip("RpcBindingInqAuthClientA not supported\n");
1377 return;
1379 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1380 ok(privs != (RPC_AUTHZ_HANDLE)0xdeadbeef, "privs unchanged\n");
1381 ok(principal != (unsigned char *)0xdeadbeef, "principal unchanged\n");
1382 if (protseq != RPC_PROTSEQ_LRPC)
1384 todo_wine
1385 ok(principal != NULL, "NULL principal\n");
1387 if (protseq == RPC_PROTSEQ_LRPC && principal && pGetUserNameExA)
1389 int len;
1390 char *spn;
1392 len = WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)privs, -1, NULL, 0, NULL, NULL);
1393 spn = HeapAlloc( GetProcessHeap(), 0, len );
1394 WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)privs, -1, spn, len, NULL, NULL);
1396 ok(!strcmp(domain_and_user, spn), "expected %s got %s\n", domain_and_user, spn);
1397 HeapFree( GetProcessHeap(), 0, spn );
1399 ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "level unchanged\n");
1400 ok(authnsvc == RPC_C_AUTHN_WINNT, "authnsvc unchanged\n");
1402 status = RpcImpersonateClient(NULL);
1403 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1404 status = RpcRevertToSelf();
1405 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1408 else
1410 status = RpcBindingInqAuthClientA(binding, &privs, &principal, &level, &authnsvc, NULL);
1411 ok(status == RPC_S_BINDING_HAS_NO_AUTH, "expected RPC_S_BINDING_HAS_NO_AUTH got %u\n", status);
1412 ok(privs == (RPC_AUTHZ_HANDLE)0xdeadbeef, "got %p\n", privs);
1413 ok(principal == (unsigned char *)0xdeadbeef, "got %s\n", principal);
1414 ok(level == 0xdeadbeef, "got %u\n", level);
1415 ok(authnsvc == 0xdeadbeef, "got %u\n", authnsvc);
1419 static void
1420 run_tests(void)
1422 basic_tests();
1423 union_tests();
1424 pointer_tests();
1425 array_tests();
1426 context_handle_test();
1429 static void
1430 set_auth_info(RPC_BINDING_HANDLE handle)
1432 RPC_STATUS status;
1433 RPC_SECURITY_QOS qos;
1435 if (!pGetUserNameExA)
1436 return;
1438 qos.Version = 1;
1439 qos.Capabilities = RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH;
1440 qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
1441 qos.ImpersonationType = RPC_C_IMP_LEVEL_IMPERSONATE;
1443 status = pRpcBindingSetAuthInfoExA(handle, (RPC_CSTR)domain_and_user, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
1444 RPC_C_AUTHN_WINNT, NULL, 0, &qos);
1445 ok(status == RPC_S_OK, "RpcBindingSetAuthInfoExA failed %d\n", status);
1448 static void
1449 client(const char *test)
1451 static unsigned char iptcp[] = "ncacn_ip_tcp";
1452 static unsigned char np[] = "ncacn_np";
1453 static unsigned char ncalrpc[] = "ncalrpc";
1454 static unsigned char address[] = "127.0.0.1";
1455 static unsigned char address_np[] = "\\\\.";
1456 static unsigned char port[] = PORT;
1457 static unsigned char pipe[] = PIPE;
1458 static unsigned char guid[] = "00000000-4114-0704-2301-000000000000";
1460 unsigned char *binding;
1462 if (strcmp(test, "tcp_basic") == 0)
1464 ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1465 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1467 run_tests();
1468 authinfo_test(RPC_PROTSEQ_TCP, 0);
1470 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1471 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1473 else if (strcmp(test, "tcp_secure") == 0)
1475 ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1476 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1478 set_auth_info(IServer_IfHandle);
1479 authinfo_test(RPC_PROTSEQ_TCP, 1);
1481 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1482 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1484 else if (strcmp(test, "ncalrpc_basic") == 0)
1486 ok(RPC_S_OK == RpcStringBindingCompose(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
1487 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1489 run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */
1490 authinfo_test(RPC_PROTSEQ_LRPC, 0);
1492 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1493 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1495 else if (strcmp(test, "ncalrpc_secure") == 0)
1497 ok(RPC_S_OK == RpcStringBindingCompose(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
1498 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1500 set_auth_info(IServer_IfHandle);
1501 authinfo_test(RPC_PROTSEQ_LRPC, 1);
1503 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1504 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1506 else if (strcmp(test, "np_basic") == 0)
1508 ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address_np, pipe, NULL, &binding), "RpcStringBindingCompose\n");
1509 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1511 run_tests();
1512 authinfo_test(RPC_PROTSEQ_NMP, 0);
1513 stop();
1515 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1516 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1520 static void
1521 server(void)
1523 static unsigned char iptcp[] = "ncacn_ip_tcp";
1524 static unsigned char port[] = PORT;
1525 static unsigned char np[] = "ncacn_np";
1526 static unsigned char pipe[] = PIPE;
1527 static unsigned char ncalrpc[] = "ncalrpc";
1528 static unsigned char guid[] = "00000000-4114-0704-2301-000000000000";
1529 RPC_STATUS status, iptcp_status, np_status, ncalrpc_status;
1530 DWORD ret;
1532 iptcp_status = RpcServerUseProtseqEp(iptcp, 20, port, NULL);
1533 ok(iptcp_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status);
1535 ncalrpc_status = RpcServerUseProtseqEp(ncalrpc, 0, guid, NULL);
1536 ok(ncalrpc_status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", ncalrpc_status);
1538 np_status = RpcServerUseProtseqEp(np, 0, pipe, NULL);
1539 if (np_status == RPC_S_PROTSEQ_NOT_SUPPORTED)
1540 skip("Protocol sequence ncacn_np is not supported\n");
1541 else
1542 ok(np_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", np_status);
1544 if (pRpcServerRegisterIfEx)
1546 trace("Using RpcServerRegisterIfEx\n");
1547 status = pRpcServerRegisterIfEx(s_IServer_v0_0_s_ifspec, NULL, NULL,
1548 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,
1549 RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
1551 else
1552 status = RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL);
1553 ok(status == RPC_S_OK, "RpcServerRegisterIf failed with status %d\n", status);
1554 status = RpcServerListen(1, 20, TRUE);
1555 ok(status == RPC_S_OK, "RpcServerListen failed with status %d\n", status);
1556 stop_event = CreateEvent(NULL, FALSE, FALSE, NULL);
1557 ok(stop_event != NULL, "CreateEvent failed with error %d\n", GetLastError());
1559 if (iptcp_status == RPC_S_OK)
1560 run_client("tcp_basic");
1561 else
1562 skip("tcp tests skipped due to earlier failure\n");
1564 if (ncalrpc_status == RPC_S_OK)
1566 run_client("ncalrpc_basic");
1567 if (pGetUserNameExA)
1569 /* we don't need to register RPC_C_AUTHN_WINNT for ncalrpc */
1570 run_client("ncalrpc_secure");
1573 else
1574 skip("lrpc tests skipped due to earlier failure\n");
1576 if (np_status == RPC_S_OK)
1577 run_client("np_basic");
1578 else
1580 skip("np_basic tests skipped due to earlier failure\n");
1581 /* np client is what signals stop_event, so bail out if we didn't run do it */
1582 return;
1585 ret = WaitForSingleObject(stop_event, 1000);
1586 ok(WAIT_OBJECT_0 == ret, "WaitForSingleObject\n");
1587 /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
1588 * forever, so don't bother calling it in this case */
1589 if (ret == WAIT_OBJECT_0)
1591 status = RpcMgmtWaitServerListen();
1592 todo_wine {
1593 ok(status == RPC_S_OK, "RpcMgmtWaitServerListening failed with status %d\n", status);
1598 START_TEST(server)
1600 int argc;
1601 char **argv;
1603 InitFunctionPointers();
1605 if (pGetUserNameExA)
1607 ULONG size = 0;
1608 ok(!pGetUserNameExA(NameSamCompatible, NULL, &size), "GetUserNameExA\n");
1609 domain_and_user = HeapAlloc(GetProcessHeap(), 0, size);
1610 ok(pGetUserNameExA(NameSamCompatible, domain_and_user, &size), "GetUserNameExA\n");
1612 else
1613 win_skip("GetUserNameExA is needed for some authentication tests\n");
1615 argc = winetest_get_mainargs(&argv);
1616 progname = argv[0];
1618 if (argc == 3)
1620 RpcTryExcept
1622 client(argv[2]);
1624 RpcExcept(TRUE)
1626 trace("Exception %d\n", RpcExceptionCode());
1628 RpcEndExcept
1630 else
1631 server();
1633 HeapFree(GetProcessHeap(), 0, domain_and_user);