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
24 #include "wine/test.h"
26 #include "server_defines.h"
33 #define PIPE "\\pipe\\wine_rpcrt4_test"
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 const WCHAR helloW
[] = { 'H','e','l','l','o',0 };
57 static const WCHAR worldW
[] = { 'W','o','r','l','d','!',0 };
59 static void InitFunctionPointers(void)
61 HMODULE hrpcrt4
= GetModuleHandleA("rpcrt4.dll");
62 HMODULE hsecur32
= LoadLibraryA("secur32.dll");
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");
71 if (!pNDRSContextMarshall2
) old_windows_version
= TRUE
;
74 void __RPC_FAR
*__RPC_USER
75 midl_user_allocate(SIZE_T n
)
77 return HeapAlloc(GetProcessHeap(), 0, n
);
81 midl_user_free(void __RPC_FAR
*p
)
83 HeapFree(GetProcessHeap(), 0, p
);
87 xstrdup(const char *s
)
89 char *d
= HeapAlloc(GetProcessHeap(), 0, strlen(s
) + 1);
94 int __cdecl
s_int_return(void)
99 int __cdecl
s_square(int x
)
104 int __cdecl
s_sum(int x
, int y
)
109 signed char __cdecl
s_sum_char(signed char x
, signed char y
)
114 short __cdecl
s_sum_short(short x
, short y
)
119 int __cdecl
s_sum_float(float x
, float y
)
124 int __cdecl
s_sum_double_int(int x
, double y
)
129 hyper __cdecl
s_sum_hyper(hyper x
, hyper y
)
134 int __cdecl
s_sum_hyper_int(hyper x
, hyper y
)
139 int __cdecl
s_sum_char_hyper(signed char x
, hyper y
)
144 void __cdecl
s_square_out(int x
, int *y
)
149 void __cdecl
s_square_ref(int *x
)
154 int __cdecl
s_str_length(const char *s
)
159 int __cdecl
s_str_t_length(str_t s
)
164 int __cdecl
s_cstr_length(const char *s
, int n
)
167 while (0 < n
-- && *s
++)
172 int __cdecl
s_dot_self(vector_t
*v
)
174 return s_square(v
->x
) + s_square(v
->y
) + s_square(v
->z
);
177 double __cdecl
s_square_half(double x
, double *y
)
183 float __cdecl
s_square_half_float(float x
, float *y
)
189 LONG __cdecl
s_square_half_long(LONG x
, LONG
*y
)
195 int __cdecl
s_sum_fixed_array(int a
[5])
197 return a
[0] + a
[1] + a
[2] + a
[3] + a
[4];
200 int __cdecl
s_pints_sum(pints_t
*pints
)
202 return *pints
->pi
+ **pints
->ppi
+ ***pints
->pppi
;
205 double __cdecl
s_ptypes_sum(ptypes_t
*pt
)
207 return *pt
->pc
+ *pt
->ps
+ *pt
->pl
+ *pt
->pf
+ *pt
->pd
;
210 int __cdecl
s_dot_pvectors(pvectors_t
*p
)
212 return p
->pu
->x
* (*p
->pv
)->x
+ p
->pu
->y
* (*p
->pv
)->y
+ p
->pu
->z
* (*p
->pv
)->z
;
215 int __cdecl
s_sum_sp(sp_t
*sp
)
217 return sp
->x
+ sp
->s
->x
;
220 double __cdecl
s_square_sun(sun_t
*su
)
224 case SUN_I
: return su
->u
.i
* su
->u
.i
;
226 case SUN_F2
: return su
->u
.f
* su
->u
.f
;
227 case SUN_PI
: return (*su
->u
.pi
) * (*su
->u
.pi
);
233 int __cdecl
s_test_list_length(test_list_t
*list
)
235 return (list
->t
== TL_LIST
236 ? 1 + s_test_list_length(list
->u
.tail
)
240 int __cdecl
s_sum_fixed_int_3d(int m
[2][3][4])
245 for (i
= 0; i
< 2; ++i
)
246 for (j
= 0; j
< 3; ++j
)
247 for (k
= 0; k
< 4; ++k
)
253 int __cdecl
s_sum_conf_array(int x
[], int n
)
255 int *p
= x
, *end
= p
+ n
;
264 int __cdecl
s_sum_conf_ptr_by_conf_ptr(int n1
, int *n2_then_x1
, int *x2
)
271 for(i
= 1; i
< n1
; ++i
)
272 sum
+= n2_then_x1
[i
];
274 for(i
= 0; i
< *n2_then_x1
; ++i
)
280 int __cdecl
s_sum_unique_conf_array(int x
[], int n
)
282 return s_sum_conf_array(x
, n
);
285 int __cdecl
s_sum_unique_conf_ptr(int *x
, int n
)
287 return x
? s_sum_conf_array(x
, n
) : 0;
290 int __cdecl
s_sum_var_array(int x
[20], int n
)
292 ok(0 <= n
, "RPC sum_var_array\n");
293 ok(n
<= 20, "RPC sum_var_array\n");
295 return s_sum_conf_array(x
, n
);
298 int __cdecl
s_sum_complex_array(int n
, refpint_t pi
[])
306 int __cdecl
s_dot_two_vectors(vector_t vs
[2])
308 return vs
[0].x
* vs
[1].x
+ vs
[0].y
* vs
[1].y
+ vs
[0].z
* vs
[1].z
;
311 void __cdecl
s_get_number_array(int x
[20], int *n
)
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]);
318 int __cdecl
s_sum_cs(cs_t
*cs
)
320 return s_sum_conf_array(cs
->ca
, cs
->n
);
323 int __cdecl
s_sum_cps(cps_t
*cps
)
328 for (i
= 0; i
< *cps
->pn
; ++i
)
331 for (i
= 0; i
< 2 * cps
->n
; ++i
)
337 int __cdecl
s_sum_cpsc(cpsc_t
*cpsc
)
341 for (i
= 0; i
< (cpsc
->c
? cpsc
->a
: cpsc
->b
); ++i
)
346 int __cdecl
s_get_cpsc(int n
, cpsc_t
*cpsc
)
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
];
359 int __cdecl
s_square_puint(puint_t p
)
365 int __cdecl
s_sum_puints(puints_t
*p
)
369 for (i
= 0; i
< p
->n
; ++i
)
370 sum
+= atoi(p
->ps
[i
]);
374 int __cdecl
s_sum_cpuints(cpuints_t
*p
)
378 for (i
= 0; i
< p
->n
; ++i
)
379 sum
+= atoi(p
->ps
[i
]);
383 int __cdecl
s_dot_copy_vectors(vector_t u
, vector_t v
)
385 return u
.x
* v
.x
+ u
.y
* v
.y
+ u
.z
* v
.z
;
388 int __cdecl
s_square_test_us(test_us_t
*tus
)
390 int n
= atoi(tus
->us
.x
);
394 double __cdecl
s_square_encu(encu_t
*eu
)
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
;
405 double __cdecl
s_square_unencu(int t
, unencu_t
*eu
)
409 case ENCU_I
: return eu
->i
* eu
->i
;
410 case ENCU_F
: return eu
->f
* eu
->f
;
416 void __cdecl
s_check_se2(se_t
*s
)
418 ok(s
->f
== E2
, "check_se2\n");
421 int __cdecl
s_sum_parr(int *a
[3])
423 return s_sum_pcarr(a
, 3);
426 int __cdecl
s_sum_pcarr(int *a
[], int n
)
429 for (i
= 0; i
< n
; ++i
)
434 int __cdecl
s_enum_ord(e_t e
)
447 double __cdecl
s_square_encue(encue_t
*eue
)
451 case E1
: return eue
->tagged_union
.i1
* eue
->tagged_union
.i1
;
452 case E2
: return eue
->tagged_union
.f2
* eue
->tagged_union
.f2
;
458 int __cdecl
s_sum_toplev_conf_2n(int *x
, int n
)
462 for (i
= 0; i
< 2 * n
; ++i
)
467 int __cdecl
s_sum_toplev_conf_cond(int *x
, int a
, int b
, int c
)
472 for (i
= 0; i
< n
; ++i
)
477 double __cdecl
s_sum_aligns(aligns_t
*a
)
479 return a
->c
+ a
->i
+ a
->s
+ a
->d
;
482 int __cdecl
s_sum_padded(padded_t
*p
)
487 int __cdecl
s_sum_padded2(padded_t ps
[2])
489 return s_sum_padded(&ps
[0]) + s_sum_padded(&ps
[1]);
492 int __cdecl
s_sum_padded_conf(padded_t
*ps
, int n
)
496 for (i
= 0; i
< n
; ++i
)
497 sum
+= s_sum_padded(&ps
[i
]);
501 int __cdecl
s_sum_bogus(bogus_t
*b
)
503 return *b
->h
.p1
+ *b
->p2
+ *b
->p3
+ b
->c
;
506 void __cdecl
s_check_null(int *null
)
508 ok(!null
, "RPC check_null\n");
511 int __cdecl
s_str_struct_len(str_struct_t
*s
)
513 return lstrlenA(s
->s
);
516 int __cdecl
s_wstr_struct_len(wstr_struct_t
*s
)
518 return lstrlenW(s
->s
);
521 int __cdecl
s_sum_doub_carr(doub_carr_t
*dc
)
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
];
531 void __cdecl
s_make_pyramid_doub_carr(unsigned char n
, doub_carr_t
**dc
)
535 t
= MIDL_user_allocate(FIELD_OFFSET(doub_carr_t
, a
[n
]));
537 for (i
= 0; i
< n
; ++i
)
540 t
->a
[i
] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t
, a
[v
]));
542 for (j
= 0; j
< v
; ++j
)
543 t
->a
[i
]->a
[j
] = j
+ 1;
548 unsigned __cdecl
s_hash_bstr(bstr_t b
)
554 for (i
= 0; i
< n
; ++i
)
555 hash
= 5 * hash
+ (unsigned) s
[i
];
559 void __cdecl
s_get_a_bstr(bstr_t
*b
)
562 short str
[] = {5, 'W', 'i', 'n', 'e', 0};
563 bstr
= HeapAlloc(GetProcessHeap(), 0, sizeof(str
));
564 memcpy(bstr
, str
, sizeof(str
));
568 void __cdecl
s_get_name(name_t
*name
)
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;
577 void __cdecl
s_get_names(int *n
, str_array_t
*names
)
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!");
591 void __cdecl
s_get_namesw(int *n
, wstr_array_t
*names
)
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
);
605 int __cdecl
s_sum_pcarr2(int n
, int **pa
)
607 return s_sum_conf_array(*pa
, n
);
610 int __cdecl
s_sum_L1_norms(int n
, vector_t
*vs
)
614 for (i
= 0; i
< n
; ++i
)
615 sum
+= abs(vs
[i
].x
) + abs(vs
[i
].y
) + abs(vs
[i
].z
);
619 s123_t
* __cdecl
s_get_s123(void)
621 s123_t
*s
= MIDL_user_allocate(sizeof *s
);
628 str_t __cdecl
s_get_filename(void)
630 return (char *)__FILE__
;
633 int __cdecl
s_echo_ranged_int(int i
, int j
, int k
)
635 return min( 100, i
+ j
+ k
);
638 int __cdecl
s_echo_ranged_int2(int i
)
643 void __cdecl
s_get_ranged_enum(renum_t
*re
)
648 void __cdecl
s_context_handle_test(void)
651 RPC_BINDING_HANDLE binding
;
653 unsigned char buf
[20];
654 static RPC_SERVER_INTERFACE server_if
=
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}},
667 binding
= I_RpcGetCurrentCallHandle();
668 ok(binding
!= NULL
, "I_RpcGetCurrentCallHandle returned NULL\n");
670 if (!pNDRSContextMarshall2
|| !pNDRSContextUnmarshall2
)
672 win_skip("NDRSContextMarshall2 or NDRSContextUnmarshall2 not exported from rpcrt4.dll\n");
676 h
= pNDRSContextUnmarshall2(binding
, NULL
, NDR_LOCAL_DATA_REPRESENTATION
, NULL
, 0);
677 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
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");
685 h
= pNDRSContextUnmarshall2(binding
, NULL
, NDR_LOCAL_DATA_REPRESENTATION
, NULL
, 0);
686 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
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");
695 /* raises ERROR_INVALID_HANDLE exception on Vista upwards */
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
);
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");
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");
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
);
717 /* test same interface data, but different pointer */
718 /* raises ERROR_INVALID_HANDLE exception */
721 RPC_SERVER_INTERFACE server_if_clone
= server_if
;
723 pNDRSContextUnmarshall2(binding
, buf
, NDR_LOCAL_DATA_REPRESENTATION
, &server_if_clone
.InterfaceId
, 0);
726 /* test different interface data, but different pointer */
727 /* raises ERROR_INVALID_HANDLE exception */
730 static RPC_SERVER_INTERFACE server_if2
=
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}},
742 pNDRSContextMarshall2(binding
, h
, buf
, NULL
, &server_if
.InterfaceId
, 0);
744 pNDRSContextUnmarshall2(binding
, buf
, NDR_LOCAL_DATA_REPRESENTATION
, &server_if2
.InterfaceId
, 0);
748 status
= RpcBindingServerFromClient(NULL
, &binding
);
750 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
751 ok(binding
!= NULL
, "binding is NULL\n");
753 if (status
== RPC_S_OK
&& binding
!= NULL
)
755 unsigned char* string_binding
= NULL
;
756 unsigned char* object_uuid
= NULL
;
757 unsigned char* protseq
= NULL
;
758 unsigned char* network_address
= NULL
;
759 unsigned char* endpoint
= NULL
;
760 unsigned char* network_options
= NULL
;
762 status
= RpcBindingToStringBindingA(binding
, &string_binding
);
763 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
764 ok(string_binding
!= NULL
, "string_binding is NULL\n");
766 status
= RpcStringBindingParseA(string_binding
, &object_uuid
, &protseq
, &network_address
, &endpoint
, &network_options
);
767 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
768 ok(protseq
!= NULL
&& *protseq
!= '\0', "protseq is %s\n", protseq
);
769 ok(network_address
!= NULL
&& *network_address
!= '\0', "network_address is %s\n", network_address
);
773 ok(object_uuid
!= NULL
&& *object_uuid
== '\0', "object_uuid is %s\n", object_uuid
);
774 ok(endpoint
!= NULL
&& *endpoint
== '\0', "endpoint is %s\n", endpoint
);
775 ok(network_options
!= NULL
&& *network_options
== '\0', "network_options is %s\n", network_options
);
778 RpcStringFreeA(&string_binding
);
779 RpcStringFreeA(&object_uuid
);
780 RpcStringFreeA(&protseq
);
781 RpcStringFreeA(&network_address
);
782 RpcStringFreeA(&endpoint
);
783 RpcStringFreeA(&network_options
);
784 RpcBindingFree(&binding
);
788 void __cdecl
s_get_numbers(int length
, int size
, pints_t n
[])
791 for (i
= 0; i
< length
; i
++)
793 n
[i
].pi
= midl_user_allocate(sizeof(*n
[i
].pi
));
800 void __cdecl
s_get_numbers_struct(numbers_struct_t
**ns
)
803 *ns
= midl_user_allocate(FIELD_OFFSET(numbers_struct_t
, numbers
[5]));
807 for (i
= 0; i
< (*ns
)->length
; i
++)
809 (*ns
)->numbers
[i
].pi
= NULL
;
810 (*ns
)->numbers
[i
].ppi
= NULL
;
811 (*ns
)->numbers
[i
].pppi
= NULL
;
813 (*ns
)->numbers
[0].pi
= midl_user_allocate(sizeof(*(*ns
)->numbers
[i
].pi
));
814 *(*ns
)->numbers
[0].pi
= 5;
817 void __cdecl
s_full_pointer_test(int *a
, int *b
)
819 ok(*a
== 42, "Expected *a to be 42 instead of %d\n", *a
);
820 ok(*b
== 42, "Expected *b to be 42 instead of %d\n", *a
);
821 ok(a
== b
, "Expected a (%p) to point to the same memory as b (%p)\n", a
, b
);
824 void __cdecl
s_full_pointer_null_test(int *a
, int *b
)
826 ok(*a
== 42, "Expected *a to be 42 instead of %d\n", *a
);
827 ok(b
== NULL
, "Expected b to be NULL instead of %p\n", b
);
830 void __cdecl
s_stop(void)
832 ok(RPC_S_OK
== RpcMgmtStopServerListening(NULL
), "RpcMgmtStopServerListening\n");
833 ok(RPC_S_OK
== RpcServerUnregisterIf(NULL
, NULL
, FALSE
), "RpcServerUnregisterIf\n");
834 ok(SetEvent(stop_event
), "SetEvent\n");
838 make_cmdline(char buffer
[MAX_PATH
], const char *test
)
840 sprintf(buffer
, "%s server %s", progname
, test
);
844 run_client(const char *test
)
846 char cmdline
[MAX_PATH
];
847 PROCESS_INFORMATION info
;
848 STARTUPINFOA startup
;
850 memset(&startup
, 0, sizeof startup
);
851 startup
.cb
= sizeof startup
;
853 make_cmdline(cmdline
, test
);
854 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
855 winetest_wait_child_process( info
.hProcess
);
856 ok(CloseHandle(info
.hProcess
), "CloseHandle\n");
857 ok(CloseHandle(info
.hThread
), "CloseHandle\n");
863 char string
[] = "I am a string";
864 WCHAR wstring
[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
865 int f
[5] = {1, 3, 0, -2, -4};
866 vector_t a
= {1, 3, 7};
867 vector_t vec1
= {4, -2, 1}, vec2
= {-5, 2, 3}, *pvec2
= &vec2
;
868 pvectors_t pvecs
= {&vec1
, &pvec2
};
869 sp_inner_t spi
= {42};
870 sp_t sp
= {-13, &spi
};
877 int i1
, i2
, i3
, *pi2
, *pi3
, **ppi3
;
885 str_struct_t ss
= {string
};
886 wstr_struct_t ws
= {wstring
};
891 ok(int_return() == INT_CODE
, "RPC int_return\n");
893 ok(square(7) == 49, "RPC square\n");
895 ok(x
== 19, "RPC sum got %d\n", x
);
896 c
= sum_char(-23, 50);
897 ok(c
== 27, "RPC sum_char got %d\n", (int)c
);
898 h
= sum_short(1122, -344);
899 ok(h
== 778, "RPC sum_short got %d\n", (int)h
);
900 x
= sum_float(123.45, -32.2);
901 ok(x
== 91, "RPC sum_float got %d\n", x
);
902 x
= sum_double_int(-78, 148.46);
903 ok(x
== 70, "RPC sum_double_int got %d\n", x
);
904 y
= sum_hyper((hyper
)0x12345678 << 16, (hyper
)0x33557799 << 16);
905 ok(y
== (hyper
)0x4589ce11 << 16, "RPC hyper got %x%08x\n", (DWORD
)(y
>> 32), (DWORD
)y
);
906 x
= sum_hyper_int((hyper
)0x24242424 << 16, -((hyper
)0x24241212 << 16));
907 ok(x
== 0x12120000, "RPC hyper_int got 0x%x\n", x
);
908 x
= sum_char_hyper( 12, ((hyper
)0x42424242 << 32) | 0x33334444 );
909 ok(x
== 0x33334450, "RPC char_hyper got 0x%x\n", x
);
913 ok(x
== 121, "RPC square_out\n");
917 ok(x
== 25, "RPC square_ref\n");
919 ok(str_length(string
) == strlen(string
), "RPC str_length\n");
920 ok(str_t_length(string
) == strlen(string
), "RPC str_length\n");
921 ok(dot_self(&a
) == 59, "RPC dot_self\n");
923 ok(str_struct_len(&ss
) == lstrlenA(string
), "RPC str_struct_len\n");
924 ok(wstr_struct_len(&ws
) == lstrlenW(wstring
), "RPC str_struct_len\n");
927 u
= square_half(3.0, &v
);
928 ok(u
== 9.0, "RPC square_half\n");
929 ok(v
== 1.5, "RPC square_half\n");
932 s
= square_half_float(3.0f
, &t
);
933 ok(s
== 9.0f
, "RPC square_half_float\n");
934 ok(t
== 1.5f
, "RPC square_half_float\n");
937 q
= square_half_long(3, &r
);
938 ok(q
== 9, "RPC square_half_long\n");
939 ok(r
== 1, "RPC square_half_long\n");
950 ok(pints_sum(&pints
) == -13, "RPC pints_sum\n");
962 ok(ptypes_sum(&ptypes
) == 33.0, "RPC ptypes_sum\n");
964 ok(dot_pvectors(&pvecs
) == -21, "RPC dot_pvectors\n");
965 ok(dot_copy_vectors(vec1
, vec2
) == -21, "RPC dot_copy_vectors\n");
966 ok(sum_fixed_array(f
) == -2, "RPC sum_fixed_array\n");
967 ok(sum_sp(&sp
) == 29, "RPC sum_sp\n");
969 ok(enum_ord(E1
) == 1, "RPC enum_ord\n");
970 ok(enum_ord(E2
) == 2, "RPC enum_ord\n");
971 ok(enum_ord(E3
) == 3, "RPC enum_ord\n");
972 ok(enum_ord(E4
) == 4, "RPC enum_ord\n");
977 memset(&aligns
, 0, sizeof(aligns
));
982 ok(sum_aligns(&aligns
) == 18.0, "RPC sum_aligns\n");
986 ok(sum_padded(&padded
) == 5, "RPC sum_padded\n");
991 ok(sum_padded2(padded2
) == 6, "RPC sum_padded2\n");
996 ok(sum_padded_conf(padded2
, 2) == 6, "RPC sum_padded_conf\n");
1005 ok(sum_bogus(&bogus
) == 12, "RPC sum_bogus\n");
1009 str
= get_filename();
1010 ok(!strcmp(str
, __FILE__
), "get_filename() returned %s instead of %s\n", str
, __FILE__
);
1011 midl_user_free(str
);
1013 x
= echo_ranged_int(0,0,0);
1014 ok(x
== 0, "echo_ranged_int() returned %d instead of 0\n", x
);
1015 x
= echo_ranged_int(10,20,100);
1016 ok(x
== 100, "echo_ranged_int() returned %d instead of 100\n", x
);
1017 x
= echo_ranged_int2(40);
1018 ok(x
== 40, "echo_ranged_int() returned %d instead of 40\n", x
);
1020 if (!old_windows_version
)
1022 get_ranged_enum(&re
);
1023 ok(re
== RE3
, "get_ranged_enum() returned %d instead of RE3\n", re
);
1038 ok(square_sun(&su
) == 81.0, "RPC square_sun\n");
1042 ok(square_sun(&su
) == 25.0, "RPC square_sun\n");
1046 ok(square_sun(&su
) == 4.0, "RPC square_sun\n");
1051 ok(square_sun(&su
) == 121.0, "RPC square_sun\n");
1054 eu
.tagged_union
.i
= 7;
1055 ok(square_encu(&eu
) == 49.0, "RPC square_encu\n");
1058 eu
.tagged_union
.f
= 3.0;
1059 ok(square_encu(&eu
) == 9.0, "RPC square_encu\n");
1062 ok(square_unencu(ENCU_I
, &uneu
) == 16.0, "RPC square_unencu\n");
1065 ok(square_unencu(ENCU_F
, &uneu
) == 25.0, "RPC square_unencu\n");
1068 eue
.tagged_union
.i1
= 8;
1069 ok(square_encue(&eue
) == 64.0, "RPC square_encue\n");
1072 eue
.tagged_union
.f2
= 10.0;
1073 ok(square_encue(&eue
) == 100.0, "RPC square_encue\n");
1076 static test_list_t
*
1079 test_list_t
*n
= HeapAlloc(GetProcessHeap(), 0, sizeof *n
);
1085 static test_list_t
*
1086 make_list(test_list_t
*tail
)
1088 test_list_t
*n
= HeapAlloc(GetProcessHeap(), 0, sizeof *n
);
1095 free_list(test_list_t
*list
)
1097 if (list
->t
== TL_LIST
)
1098 free_list(list
->u
.tail
);
1099 HeapFree(GetProcessHeap(), 0, list
);
1103 puint_t_UserSize(ULONG
*flags
, ULONG start
, puint_t
*p
)
1105 return start
+ sizeof(int);
1108 unsigned char * __RPC_USER
1109 puint_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, puint_t
*p
)
1112 memcpy(buffer
, &n
, sizeof n
);
1113 return buffer
+ sizeof n
;
1116 unsigned char * __RPC_USER
1117 puint_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, puint_t
*p
)
1120 memcpy(&n
, buffer
, sizeof n
);
1121 *p
= HeapAlloc(GetProcessHeap(), 0, 10);
1122 sprintf(*p
, "%d", n
);
1123 return buffer
+ sizeof n
;
1127 puint_t_UserFree(ULONG
*flags
, puint_t
*p
)
1129 HeapFree(GetProcessHeap(), 0, *p
);
1133 us_t_UserSize(ULONG
*flags
, ULONG start
, us_t
*pus
)
1135 return start
+ sizeof(struct wire_us
);
1138 unsigned char * __RPC_USER
1139 us_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, us_t
*pus
)
1142 wus
.x
= atoi(pus
->x
);
1143 memcpy(buffer
, &wus
, sizeof wus
);
1144 return buffer
+ sizeof wus
;
1147 unsigned char * __RPC_USER
1148 us_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, us_t
*pus
)
1151 memcpy(&wus
, buffer
, sizeof wus
);
1152 pus
->x
= HeapAlloc(GetProcessHeap(), 0, 10);
1153 sprintf(pus
->x
, "%d", wus
.x
);
1154 return buffer
+ sizeof wus
;
1158 us_t_UserFree(ULONG
*flags
, us_t
*pus
)
1160 HeapFree(GetProcessHeap(), 0, pus
->x
);
1164 bstr_t_UserSize(ULONG
*flags
, ULONG start
, bstr_t
*b
)
1166 return start
+ FIELD_OFFSET(user_bstr_t
, data
[(*b
)[-1]]);
1169 unsigned char * __RPC_USER
1170 bstr_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, bstr_t
*b
)
1172 wire_bstr_t wb
= (wire_bstr_t
) buffer
;
1174 memcpy(&wb
->data
, *b
, wb
->n
* sizeof wb
->data
[0]);
1175 return buffer
+ FIELD_OFFSET(user_bstr_t
, data
[wb
->n
]);
1178 unsigned char * __RPC_USER
1179 bstr_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, bstr_t
*b
)
1181 wire_bstr_t wb
= (wire_bstr_t
) buffer
;
1182 short *data
= HeapAlloc(GetProcessHeap(), 0, (wb
->n
+ 1) * sizeof *data
);
1184 memcpy(&data
[1], wb
->data
, wb
->n
* sizeof data
[1]);
1186 return buffer
+ FIELD_OFFSET(user_bstr_t
, data
[wb
->n
]);
1190 bstr_t_UserFree(ULONG
*flags
, bstr_t
*b
)
1192 HeapFree(GetProcessHeap(), 0, &((*b
)[-1]));
1198 int a
[] = {1, 2, 3, 4};
1200 test_list_t
*list
= make_list(make_list(make_list(null_list())));
1201 test_us_t tus
= {{p1
}};
1205 short bstr_data
[] = { 5, 'H', 'e', 'l', 'l', 'o' };
1206 bstr_t bstr
= &bstr_data
[1], bstr2
;
1213 ok(test_list_length(list
) == 3, "RPC test_list_length\n");
1214 ok(square_puint(p1
) == 121, "RPC square_puint\n");
1216 pus
.ps
= HeapAlloc(GetProcessHeap(), 0, pus
.n
* sizeof pus
.ps
[0]);
1217 pus
.ps
[0] = xstrdup("5");
1218 pus
.ps
[1] = xstrdup("6");
1219 pus
.ps
[2] = xstrdup("7");
1220 pus
.ps
[3] = xstrdup("8");
1221 ok(sum_puints(&pus
) == 26, "RPC sum_puints\n");
1222 HeapFree(GetProcessHeap(), 0, pus
.ps
[0]);
1223 HeapFree(GetProcessHeap(), 0, pus
.ps
[1]);
1224 HeapFree(GetProcessHeap(), 0, pus
.ps
[2]);
1225 HeapFree(GetProcessHeap(), 0, pus
.ps
[3]);
1226 HeapFree(GetProcessHeap(), 0, pus
.ps
);
1228 cpus
.ps
= HeapAlloc(GetProcessHeap(), 0, cpus
.n
* sizeof cpus
.ps
[0]);
1229 cpus
.ps
[0] = xstrdup("5");
1230 cpus
.ps
[1] = xstrdup("6");
1231 cpus
.ps
[2] = xstrdup("7");
1232 cpus
.ps
[3] = xstrdup("8");
1233 ok(sum_cpuints(&cpus
) == 26, "RPC sum_puints\n");
1234 HeapFree(GetProcessHeap(), 0, cpus
.ps
[0]);
1235 HeapFree(GetProcessHeap(), 0, cpus
.ps
[1]);
1236 HeapFree(GetProcessHeap(), 0, cpus
.ps
[2]);
1237 HeapFree(GetProcessHeap(), 0, cpus
.ps
[3]);
1238 HeapFree(GetProcessHeap(), 0, cpus
.ps
);
1239 ok(square_test_us(&tus
) == 121, "RPC square_test_us\n");
1244 ok(sum_parr(pa
) == 6, "RPC sum_parr\n");
1250 ok(sum_pcarr(pa
, 4) == 10, "RPC sum_pcarr\n");
1252 ok(hash_bstr(bstr
) == s_hash_bstr(bstr
), "RPC hash_bstr_data\n");
1255 s_get_a_bstr(&bstr2
);
1256 ok(!lstrcmpW((LPCWSTR
)bstr
, (LPCWSTR
)bstr2
), "bstr mismatch\n");
1257 HeapFree(GetProcessHeap(), 0, bstr
- 1);
1258 HeapFree(GetProcessHeap(), 0, bstr2
- 1);
1262 if (!old_windows_version
)
1266 wstr_array_t namesw
;
1269 name
.name
= buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, name
.size
);
1271 ok(name
.name
== buffer
, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name
.name
, buffer
);
1272 ok(!strcmp(name
.name
, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name
.name
);
1273 HeapFree(GetProcessHeap(), 0, name
.name
);
1277 get_names(&n
, &names
);
1278 ok(n
== 2, "expected 2, got %d\n", n
);
1279 ok(!strcmp(names
[0], "Hello"), "expected Hello, got %s\n", names
[0]);
1280 ok(!strcmp(names
[1], "World!"), "expected World!, got %s\n", names
[1]);
1281 MIDL_user_free(names
[0]);
1282 MIDL_user_free(names
[1]);
1283 MIDL_user_free(names
);
1287 get_namesw(&n
, &namesw
);
1288 ok(n
== 2, "expected 2, got %d\n", n
);
1289 ok(!lstrcmpW(namesw
[0], helloW
), "expected Hello, got %s\n", wine_dbgstr_w(namesw
[0]));
1290 ok(!lstrcmpW(namesw
[1], worldW
), "expected World!, got %s\n", wine_dbgstr_w(namesw
[1]));
1291 MIDL_user_free(namesw
[0]);
1292 MIDL_user_free(namesw
[1]);
1293 MIDL_user_free(namesw
);
1297 ok(sum_pcarr2(4, &pa2
) == 10, "RPC sum_pcarr2\n");
1300 ok(s123
->f1
== 1 && s123
->f2
== 2 && s123
->f3
== 3, "RPC get_s123\n");
1301 MIDL_user_free(s123
);
1303 full_pointer_test(&val
, &val
);
1304 full_pointer_null_test(&val
, NULL
);
1308 check_pyramid_doub_carr(doub_carr_t
*dc
)
1311 for (i
= 0; i
< dc
->n
; ++i
)
1312 for (j
= 0; j
< dc
->a
[i
]->n
; ++j
)
1313 if (dc
->a
[i
]->a
[j
] != j
+ 1)
1319 free_pyramid_doub_carr(doub_carr_t
*dc
)
1322 for (i
= 0; i
< dc
->n
; ++i
)
1323 MIDL_user_free(dc
->a
[i
]);
1332 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1333 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1335 int c
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1336 int c2
[] = {10, 100, 200};
1338 vector_t vs
[2] = {{1, -2, 3}, {4, -5, -6}};
1343 int ca
[5] = {1, -2, 3, -4, 5};
1348 numbers_struct_t
*ns
;
1351 if (!old_windows_version
)
1353 const char str1
[25] = "Hello";
1354 ok(cstr_length(str1
, sizeof str1
) == strlen(str1
), "RPC cstr_length\n");
1357 ok(sum_fixed_int_3d(m
) == 4116, "RPC sum_fixed_int_3d\n");
1359 ok(sum_conf_array(c
, 10) == 45, "RPC sum_conf_array\n");
1360 ok(sum_conf_array(&c
[5], 2) == 11, "RPC sum_conf_array\n");
1361 ok(sum_conf_array(&c
[7], 1) == 7, "RPC sum_conf_array\n");
1362 ok(sum_conf_array(&c
[2], 0) == 0, "RPC sum_conf_array\n");
1364 ok(sum_conf_ptr_by_conf_ptr(1, c2
, c
) == 45, "RPC sum_conf_ptr_by_conf_ptr\n");
1365 ok(sum_conf_ptr_by_conf_ptr(3, c2
, c
) == 345, "RPC sum_conf_ptr_by_conf_ptr\n");
1367 ok(sum_conf_ptr_by_conf_ptr(3, c2
, c
) == 300, "RPC sum_conf_ptr_by_conf_ptr\n");
1369 ok(sum_unique_conf_array(ca
, 4) == -2, "RPC sum_unique_conf_array\n");
1370 ok(sum_unique_conf_ptr(ca
, 5) == 3, "RPC sum_unique_conf_array\n");
1371 ok(sum_unique_conf_ptr(NULL
, 10) == 0, "RPC sum_unique_conf_array\n");
1373 get_number_array(c3
, &n
);
1374 ok(n
== 10, "RPC get_num_array\n");
1376 ok(c3
[n
-1] == c
[n
-1], "get_num_array returned wrong value %d @ %d\n",
1378 ok(sum_var_array(c
, 10) == 45, "RPC sum_conf_array\n");
1379 ok(sum_var_array(&c
[5], 2) == 11, "RPC sum_conf_array\n");
1380 ok(sum_var_array(&c
[7], 1) == 7, "RPC sum_conf_array\n");
1381 ok(sum_var_array(&c
[2], 0) == 0, "RPC sum_conf_array\n");
1383 ok(dot_two_vectors(vs
) == -4, "RPC dot_two_vectors\n");
1384 cs
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t
, ca
[5]));
1391 ok(sum_cs(cs
) == 1, "RPC sum_cs\n");
1392 HeapFree(GetProcessHeap(), 0, cs
);
1399 ok(sum_cps(&cps
) == 53, "RPC sum_cps\n");
1405 ok(sum_cpsc(&cpsc
) == 6, "RPC sum_cpsc\n");
1410 ok(sum_cpsc(&cpsc
) == 10, "RPC sum_cpsc\n");
1413 ok(get_cpsc(5, &cpsc
) == 45, "RPC sum_cpsc\n");
1414 ok( cpsc
.a
== 10, "RPC get_cpsc %u\n", cpsc
.a
);
1415 for (n
= 0; n
< 10; n
++) ok( cpsc
.ca
[n
] == n
, "RPC get_cpsc[%d] = %d\n", n
, cpsc
.ca
[n
] );
1417 memset( tmp
, 0x33, sizeof(tmp
) );
1419 ok(get_cpsc(4, &cpsc
) == 28, "RPC sum_cpsc\n");
1420 ok( cpsc
.a
== 8, "RPC get_cpsc %u\n", cpsc
.a
);
1421 ok( cpsc
.ca
== tmp
, "RPC get_cpsc %p/%p\n", cpsc
.ca
, tmp
);
1422 for (n
= 0; n
< 8; n
++) ok( cpsc
.ca
[n
] == n
, "RPC get_cpsc[%d] = %d\n", n
, cpsc
.ca
[n
] );
1424 ok(sum_toplev_conf_2n(c
, 3) == 15, "RPC sum_toplev_conf_2n\n");
1425 ok(sum_toplev_conf_cond(c
, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1426 ok(sum_toplev_conf_cond(c
, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1428 dc
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_t
, a
[2]));
1430 dc
->a
[0] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t
, a
[3]));
1435 dc
->a
[1] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t
, a
[2]));
1439 ok(sum_doub_carr(dc
) == 19, "RPC sum_doub_carr\n");
1440 HeapFree(GetProcessHeap(), 0, dc
->a
[0]);
1441 HeapFree(GetProcessHeap(), 0, dc
->a
[1]);
1442 HeapFree(GetProcessHeap(), 0, dc
);
1445 make_pyramid_doub_carr(4, &dc
);
1446 ok(check_pyramid_doub_carr(dc
), "RPC make_pyramid_doub_carr\n");
1447 free_pyramid_doub_carr(dc
);
1449 ok(sum_L1_norms(2, vs
) == 21, "RPC sum_L1_norms\n");
1451 memset(api
, 0, sizeof(api
));
1452 pi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pi
));
1455 get_numbers(1, 1, api
);
1456 ok(api
[0].pi
== pi
, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi
, api
[0].pi
);
1457 ok(*api
[0].pi
== 0, "pi unmarshalled incorrectly %d\n", *api
[0].pi
);
1459 if (!old_windows_version
)
1461 ns
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, FIELD_OFFSET(numbers_struct_t
, numbers
[5]));
1464 ns
->numbers
[0].pi
= pi
;
1465 get_numbers_struct(&ns
);
1466 ok(ns
->numbers
[0].pi
== pi
, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi
, ns
->numbers
[0].pi
);
1467 ok(*ns
->numbers
[0].pi
== 5, "pi unmarshalled incorrectly %d\n", *ns
->numbers
[0].pi
);
1468 HeapFree(GetProcessHeap(), 0, ns
);
1470 HeapFree(GetProcessHeap(), 0, pi
);
1472 pi
= HeapAlloc(GetProcessHeap(), 0, 5 * sizeof(*pi
));
1473 pi
[0] = 3; rpi
[0] = &pi
[0];
1474 pi
[1] = 5; rpi
[1] = &pi
[1];
1475 pi
[2] = -2; rpi
[2] = &pi
[2];
1476 pi
[3] = -1; rpi
[3] = &pi
[3];
1477 pi
[4] = -4; rpi
[4] = &pi
[4];
1478 ok(sum_complex_array(5, rpi
) == 1, "RPC sum_complex_array\n");
1479 HeapFree(GetProcessHeap(), 0, pi
);
1482 void __cdecl
s_authinfo_test(unsigned int protseq
, int secure
)
1484 RPC_BINDING_HANDLE binding
;
1486 ULONG level
, authnsvc
;
1487 RPC_AUTHZ_HANDLE privs
;
1488 unsigned char *principal
;
1490 binding
= I_RpcGetCurrentCallHandle();
1491 ok(binding
!= NULL
, "I_RpcGetCurrentCallHandle returned NULL\n");
1493 level
= authnsvc
= 0xdeadbeef;
1494 privs
= (RPC_AUTHZ_HANDLE
)0xdeadbeef;
1495 principal
= (unsigned char *)0xdeadbeef;
1497 if (secure
|| protseq
== RPC_PROTSEQ_LRPC
)
1499 status
= RpcBindingInqAuthClientA(binding
, &privs
, &principal
, &level
, &authnsvc
, NULL
);
1500 if (status
== RPC_S_CANNOT_SUPPORT
)
1502 win_skip("RpcBindingInqAuthClientA not supported\n");
1505 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1506 ok(privs
!= (RPC_AUTHZ_HANDLE
)0xdeadbeef, "privs unchanged\n");
1507 ok(principal
!= (unsigned char *)0xdeadbeef, "principal unchanged\n");
1508 if (protseq
!= RPC_PROTSEQ_LRPC
)
1511 ok(principal
!= NULL
, "NULL principal\n");
1513 if (protseq
== RPC_PROTSEQ_LRPC
&& principal
&& pGetUserNameExA
)
1518 len
= WideCharToMultiByte(CP_ACP
, 0, (const WCHAR
*)privs
, -1, NULL
, 0, NULL
, NULL
);
1519 spn
= HeapAlloc( GetProcessHeap(), 0, len
);
1520 WideCharToMultiByte(CP_ACP
, 0, (const WCHAR
*)privs
, -1, spn
, len
, NULL
, NULL
);
1522 ok(!strcmp(domain_and_user
, spn
), "expected %s got %s\n", domain_and_user
, spn
);
1523 HeapFree( GetProcessHeap(), 0, spn
);
1525 ok(level
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
, "level unchanged\n");
1526 ok(authnsvc
== RPC_C_AUTHN_WINNT
, "authnsvc unchanged\n");
1528 status
= RpcImpersonateClient(NULL
);
1529 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1530 status
= RpcRevertToSelf();
1531 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1536 status
= RpcBindingInqAuthClientA(binding
, &privs
, &principal
, &level
, &authnsvc
, NULL
);
1537 ok(status
== RPC_S_BINDING_HAS_NO_AUTH
, "expected RPC_S_BINDING_HAS_NO_AUTH got %u\n", status
);
1538 ok(privs
== (RPC_AUTHZ_HANDLE
)0xdeadbeef, "got %p\n", privs
);
1539 ok(principal
== (unsigned char *)0xdeadbeef, "got %s\n", principal
);
1540 ok(level
== 0xdeadbeef, "got %u\n", level
);
1541 ok(authnsvc
== 0xdeadbeef, "got %u\n", authnsvc
);
1552 context_handle_test();
1556 set_auth_info(RPC_BINDING_HANDLE handle
)
1559 RPC_SECURITY_QOS qos
;
1561 if (!pGetUserNameExA
)
1565 qos
.Capabilities
= RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH
;
1566 qos
.IdentityTracking
= RPC_C_QOS_IDENTITY_STATIC
;
1567 qos
.ImpersonationType
= RPC_C_IMP_LEVEL_IMPERSONATE
;
1569 status
= pRpcBindingSetAuthInfoExA(handle
, (RPC_CSTR
)domain_and_user
, RPC_C_AUTHN_LEVEL_PKT_PRIVACY
,
1570 RPC_C_AUTHN_WINNT
, NULL
, 0, &qos
);
1571 ok(status
== RPC_S_OK
, "RpcBindingSetAuthInfoExA failed %d\n", status
);
1574 #define test_is_server_listening(a,b) _test_is_server_listening(__LINE__,a,b)
1575 static void _test_is_server_listening(unsigned line
, RPC_BINDING_HANDLE binding
, RPC_STATUS expected_status
)
1578 status
= RpcMgmtIsServerListening(binding
);
1579 ok_(__FILE__
,line
)(status
== expected_status
, "RpcMgmtIsServerListening returned %u, expected %u\n",
1580 status
, expected_status
);
1583 #define test_is_server_listening2(a,b,c) _test_is_server_listening2(__LINE__,a,b,c)
1584 static void _test_is_server_listening2(unsigned line
, RPC_BINDING_HANDLE binding
, RPC_STATUS expected_status
,
1585 RPC_STATUS expected_status2
)
1588 status
= RpcMgmtIsServerListening(binding
);
1589 ok_(__FILE__
,line
)(status
== expected_status
|| status
== expected_status2
,
1590 "RpcMgmtIsServerListening returned %u, expected %u or %u\n",
1591 status
, expected_status
, expected_status2
);
1595 client(const char *test
)
1597 static unsigned char iptcp
[] = "ncacn_ip_tcp";
1598 static unsigned char np
[] = "ncacn_np";
1599 static unsigned char ncalrpc
[] = "ncalrpc";
1600 static unsigned char address
[] = "127.0.0.1";
1601 static unsigned char address_np
[] = "\\\\.";
1602 static unsigned char port
[] = PORT
;
1603 static unsigned char pipe
[] = PIPE
;
1604 static unsigned char guid
[] = "00000000-4114-0704-2301-000000000000";
1606 unsigned char *binding
;
1608 if (strcmp(test
, "tcp_basic") == 0)
1610 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, iptcp
, address
, port
, NULL
, &binding
), "RpcStringBindingCompose\n");
1611 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
1614 authinfo_test(RPC_PROTSEQ_TCP
, 0);
1615 test_is_server_listening2(IServer_IfHandle
, RPC_S_OK
, RPC_S_ACCESS_DENIED
);
1617 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1618 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
1620 else if (strcmp(test
, "tcp_secure") == 0)
1622 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, iptcp
, address
, port
, NULL
, &binding
), "RpcStringBindingCompose\n");
1623 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
1625 set_auth_info(IServer_IfHandle
);
1626 authinfo_test(RPC_PROTSEQ_TCP
, 1);
1627 test_is_server_listening(IServer_IfHandle
, RPC_S_ACCESS_DENIED
);
1629 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1630 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
1632 else if (strcmp(test
, "ncalrpc_basic") == 0)
1634 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, guid
, NULL
, &binding
), "RpcStringBindingCompose\n");
1635 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
1637 run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */
1638 authinfo_test(RPC_PROTSEQ_LRPC
, 0);
1639 test_is_server_listening(IServer_IfHandle
, RPC_S_OK
);
1641 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1642 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
1644 else if (strcmp(test
, "ncalrpc_secure") == 0)
1646 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, guid
, NULL
, &binding
), "RpcStringBindingCompose\n");
1647 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
1649 set_auth_info(IServer_IfHandle
);
1650 authinfo_test(RPC_PROTSEQ_LRPC
, 1);
1651 test_is_server_listening(IServer_IfHandle
, RPC_S_OK
);
1653 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1654 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
1656 else if (strcmp(test
, "np_basic") == 0)
1658 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, np
, address_np
, pipe
, NULL
, &binding
), "RpcStringBindingCompose\n");
1659 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
1661 test_is_server_listening(IServer_IfHandle
, RPC_S_OK
);
1663 authinfo_test(RPC_PROTSEQ_NMP
, 0);
1664 test_is_server_listening(IServer_IfHandle
, RPC_S_OK
);
1666 test_is_server_listening(IServer_IfHandle
, RPC_S_NOT_LISTENING
);
1668 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1669 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
1676 static unsigned char iptcp
[] = "ncacn_ip_tcp";
1677 static unsigned char port
[] = PORT
;
1678 static unsigned char np
[] = "ncacn_np";
1679 static unsigned char pipe
[] = PIPE
;
1680 static unsigned char ncalrpc
[] = "ncalrpc";
1681 static unsigned char guid
[] = "00000000-4114-0704-2301-000000000000";
1682 RPC_STATUS status
, iptcp_status
, np_status
, ncalrpc_status
;
1685 iptcp_status
= RpcServerUseProtseqEpA(iptcp
, 20, port
, NULL
);
1686 ok(iptcp_status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status
);
1688 ncalrpc_status
= RpcServerUseProtseqEpA(ncalrpc
, 0, guid
, NULL
);
1689 ok(ncalrpc_status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", ncalrpc_status
);
1691 np_status
= RpcServerUseProtseqEpA(np
, 0, pipe
, NULL
);
1692 if (np_status
== RPC_S_PROTSEQ_NOT_SUPPORTED
)
1693 skip("Protocol sequence ncacn_np is not supported\n");
1695 ok(np_status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", np_status
);
1697 if (pRpcServerRegisterIfEx
)
1699 trace("Using RpcServerRegisterIfEx\n");
1700 status
= pRpcServerRegisterIfEx(s_IServer_v0_0_s_ifspec
, NULL
, NULL
,
1701 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH
,
1702 RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
1705 status
= RpcServerRegisterIf(s_IServer_v0_0_s_ifspec
, NULL
, NULL
);
1706 ok(status
== RPC_S_OK
, "RpcServerRegisterIf failed with status %d\n", status
);
1707 test_is_server_listening(NULL
, RPC_S_NOT_LISTENING
);
1708 status
= RpcServerListen(1, 20, TRUE
);
1709 ok(status
== RPC_S_OK
, "RpcServerListen failed with status %d\n", status
);
1710 test_is_server_listening(NULL
, RPC_S_OK
);
1711 stop_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1712 ok(stop_event
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1714 if (iptcp_status
== RPC_S_OK
)
1715 run_client("tcp_basic");
1717 skip("tcp tests skipped due to earlier failure\n");
1719 if (ncalrpc_status
== RPC_S_OK
)
1721 run_client("ncalrpc_basic");
1722 if (pGetUserNameExA
)
1724 /* we don't need to register RPC_C_AUTHN_WINNT for ncalrpc */
1725 run_client("ncalrpc_secure");
1729 skip("lrpc tests skipped due to earlier failure\n");
1731 if (np_status
== RPC_S_OK
)
1732 run_client("np_basic");
1735 skip("np_basic tests skipped due to earlier failure\n");
1736 /* np client is what signals stop_event, so bail out if we didn't run do it */
1740 ret
= WaitForSingleObject(stop_event
, 1000);
1741 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
1742 /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
1743 * forever, so don't bother calling it in this case */
1744 if (ret
== WAIT_OBJECT_0
)
1746 status
= RpcMgmtWaitServerListen();
1748 ok(status
== RPC_S_OK
, "RpcMgmtWaitServerListening failed with status %d\n", status
);
1758 InitFunctionPointers();
1760 if (pGetUserNameExA
)
1763 ok(!pGetUserNameExA(NameSamCompatible
, NULL
, &size
), "GetUserNameExA\n");
1764 domain_and_user
= HeapAlloc(GetProcessHeap(), 0, size
);
1765 ok(pGetUserNameExA(NameSamCompatible
, domain_and_user
, &size
), "GetUserNameExA\n");
1768 win_skip("GetUserNameExA is needed for some authentication tests\n");
1770 argc
= winetest_get_mainargs(&argv
);
1781 trace("Exception %d\n", RpcExceptionCode());
1788 HeapFree(GetProcessHeap(), 0, domain_and_user
);