2 * Copyright 2014 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define WIN32_LEAN_AND_MEAN
25 #include "wine/test.h"
27 #include "dpnet_test.h"
29 /* {CD0C3D4B-E15E-4CF2-9EA8-6E1D6548C5A5} */
30 static const GUID appguid
= { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
31 static WCHAR sessionname
[] = {'w','i','n','e','g','a','m','e','s','s','e','r','v','e','r',0};
33 static BOOL nCreatePlayer
;
34 static BOOL nDestroyPlayer
;
36 static HRESULT WINAPI
DirectPlayMessageHandler(PVOID pvUserContext
, DWORD dwMessageId
, PVOID pMsgBuffer
)
38 trace("msgid: 0x%08x\n", dwMessageId
);
42 case DPN_MSGID_CREATE_PLAYER
:
45 case DPN_MSGID_DESTROY_PLAYER
:
46 nDestroyPlayer
= TRUE
;
53 static void create_server(void)
56 IDirectPlay8Server
*server
= NULL
;
58 hr
= CoCreateInstance( &CLSID_DirectPlay8Server
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Server
, (LPVOID
*)&server
);
59 ok(hr
== S_OK
, "Failed to create IDirectPlay8Server object\n");
62 hr
= IDirectPlay8Server_Close(server
, 0);
63 todo_wine
ok(hr
== DPNERR_UNINITIALIZED
, "got 0x%08x\n", hr
);
65 hr
= IDirectPlay8Server_Initialize(server
, NULL
, NULL
, 0);
66 ok(hr
== DPNERR_INVALIDPARAM
, "got 0x%08x\n", hr
);
68 hr
= IDirectPlay8Server_Initialize(server
, NULL
, DirectPlayMessageHandler
, 0);
69 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
72 IDirectPlay8Address
*localaddr
= NULL
;
73 DPN_APPLICATION_DESC appdesc
;
75 hr
= CoCreateInstance( &CLSID_DirectPlay8Address
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Address
, (LPVOID
*)&localaddr
);
76 ok(hr
== S_OK
, "Failed to create IDirectPlay8Address object\n");
78 hr
= IDirectPlay8Address_SetSP(localaddr
, &CLSID_DP8SP_TCPIP
);
79 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
81 memset( &appdesc
, 0, sizeof(DPN_APPLICATION_DESC
) );
82 appdesc
.dwSize
= sizeof( DPN_APPLICATION_DESC
);
83 appdesc
.dwFlags
= DPNSESSION_CLIENT_SERVER
;
84 appdesc
.guidApplication
= appguid
;
85 appdesc
.pwszSessionName
= sessionname
;
87 hr
= IDirectPlay8Server_Host(server
, &appdesc
, &localaddr
, 1, NULL
, NULL
, NULL
, 0);
88 todo_wine
ok(hr
== S_OK
, "got 0x%08x\n", hr
);
90 todo_wine
ok(nCreatePlayer
, "No DPN_MSGID_CREATE_PLAYER Message\n");
91 ok(!nDestroyPlayer
, "Received DPN_MSGID_DESTROY_PLAYER Message\n");
93 hr
= IDirectPlay8Server_Close(server
, 0);
94 todo_wine
ok(hr
== S_OK
, "got 0x%08x\n", hr
);
96 todo_wine
ok(nDestroyPlayer
, "No DPN_MSGID_DESTROY_PLAYER Message\n");
98 IDirectPlay8Address_Release(localaddr
);
101 IDirectPlay8Server_Release(server
);
105 static void test_server_info(void)
108 DPN_PLAYER_INFO info
;
109 WCHAR name
[] = {'w','i','n','e',0};
110 WCHAR name2
[] = {'w','i','n','e','2',0};
111 WCHAR data
[] = {'X','X','X','X',0};
112 IDirectPlay8Server
*server
= NULL
;
114 hr
= CoCreateInstance( &CLSID_DirectPlay8Server
, NULL
, CLSCTX_ALL
, &IID_IDirectPlay8Server
, (LPVOID
*)&server
);
115 ok(hr
== S_OK
, "Failed to create IDirectPlay8Server object\n");
118 ZeroMemory( &info
, sizeof(DPN_PLAYER_INFO
) );
119 info
.dwSize
= sizeof(DPN_PLAYER_INFO
);
120 info
.dwInfoFlags
= DPNINFO_NAME
;
122 hr
= IDirectPlay8Server_SetServerInfo(server
, NULL
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
123 ok(hr
== E_POINTER
, "got %x\n", hr
);
125 info
.pwszName
= name
;
126 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
127 ok(hr
== DPNERR_UNINITIALIZED
, "got %x\n", hr
);
129 hr
= IDirectPlay8Server_Initialize(server
, NULL
, DirectPlayMessageHandler
, 0);
130 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
132 hr
= IDirectPlay8Server_SetServerInfo(server
, NULL
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
133 ok(hr
== E_POINTER
, "got %x\n", hr
);
135 info
.pwszName
= NULL
;
136 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
137 ok(hr
== S_OK
, "got %x\n", hr
);
139 info
.pwszName
= name
;
140 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
141 ok(hr
== S_OK
, "got %x\n", hr
);
143 info
.dwInfoFlags
= DPNINFO_NAME
;
144 info
.pwszName
= name2
;
145 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
146 ok(hr
== S_OK
, "got %x\n", hr
);
148 info
.dwInfoFlags
= DPNINFO_DATA
;
149 info
.pwszName
= NULL
;
151 info
.dwDataSize
= sizeof(data
);
152 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
153 ok(hr
== E_POINTER
, "got %x\n", hr
);
155 info
.dwInfoFlags
= DPNINFO_DATA
;
156 info
.pwszName
= NULL
;
159 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
160 ok(hr
== S_OK
, "got %x\n", hr
);
162 info
.dwInfoFlags
= DPNINFO_DATA
;
163 info
.pwszName
= NULL
;
165 info
.dwDataSize
= sizeof(data
);
166 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
167 ok(hr
== S_OK
, "got %x\n", hr
);
169 info
.dwInfoFlags
= DPNINFO_DATA
| DPNINFO_NAME
;
170 info
.pwszName
= name
;
172 info
.dwDataSize
= sizeof(data
);
173 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
174 ok(hr
== S_OK
, "got %x\n", hr
);
176 info
.dwInfoFlags
= DPNINFO_DATA
| DPNINFO_NAME
;
177 info
.pwszName
= name
;
180 hr
= IDirectPlay8Server_SetServerInfo(server
, &info
, NULL
, NULL
, DPNSETSERVERINFO_SYNC
);
181 ok(hr
== S_OK
, "got %x\n", hr
);
183 IDirectPlay8Server_Release(server
);
187 BOOL
is_process_elevated(void)
190 if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
))
192 TOKEN_ELEVATION_TYPE type
;
196 ret
= GetTokenInformation( token
, TokenElevationType
, &type
, sizeof(type
), &size
);
197 CloseHandle( token
);
198 return (ret
&& type
== TokenElevationTypeFull
);
203 BOOL
is_firewall_enabled(void)
206 INetFwMgr
*mgr
= NULL
;
207 INetFwPolicy
*policy
= NULL
;
208 INetFwProfile
*profile
= NULL
;
209 VARIANT_BOOL enabled
= VARIANT_FALSE
;
211 init
= CoInitializeEx( 0, COINIT_APARTMENTTHREADED
);
213 hr
= CoCreateInstance( &CLSID_NetFwMgr
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetFwMgr
,
215 ok( hr
== S_OK
, "got %08x\n", hr
);
216 if (hr
!= S_OK
) goto done
;
218 hr
= INetFwMgr_get_LocalPolicy( mgr
, &policy
);
219 ok( hr
== S_OK
, "got %08x\n", hr
);
220 if (hr
!= S_OK
) goto done
;
222 hr
= INetFwPolicy_get_CurrentProfile( policy
, &profile
);
223 if (hr
!= S_OK
) goto done
;
225 hr
= INetFwProfile_get_FirewallEnabled( profile
, &enabled
);
226 ok( hr
== S_OK
, "got %08x\n", hr
);
229 if (policy
) INetFwPolicy_Release( policy
);
230 if (profile
) INetFwProfile_Release( profile
);
231 if (mgr
) INetFwMgr_Release( mgr
);
232 if (SUCCEEDED( init
)) CoUninitialize();
233 return (enabled
== VARIANT_TRUE
);
236 HRESULT
set_firewall( enum firewall_op op
)
238 static const WCHAR dpnsvrW
[] =
239 {'d','p','n','s','v','r','.','e','x','e',0};
240 static const WCHAR separator
[] = {'\\',0};
241 static const WCHAR clientW
[] =
242 {'d','p','n','e','t','_','c','l','i','e','n','t',0};
243 static const WCHAR serverW
[] =
244 {'d','p','n','e','t','_','s','e','r','v','e','r',0};
246 INetFwMgr
*mgr
= NULL
;
247 INetFwPolicy
*policy
= NULL
;
248 INetFwProfile
*profile
= NULL
;
249 INetFwAuthorizedApplication
*app
= NULL
;
250 INetFwAuthorizedApplications
*apps
= NULL
;
251 BSTR name
, image
= SysAllocStringLen( NULL
, MAX_PATH
);
252 WCHAR path
[MAX_PATH
];
254 if (!GetModuleFileNameW( NULL
, image
, MAX_PATH
))
256 SysFreeString( image
);
260 if(!GetSystemDirectoryW(path
, MAX_PATH
))
262 SysFreeString( image
);
265 lstrcatW(path
, separator
);
266 lstrcatW(path
, dpnsvrW
);
268 init
= CoInitializeEx( 0, COINIT_APARTMENTTHREADED
);
270 hr
= CoCreateInstance( &CLSID_NetFwMgr
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetFwMgr
,
272 ok( hr
== S_OK
, "got %08x\n", hr
);
273 if (hr
!= S_OK
) goto done
;
275 hr
= INetFwMgr_get_LocalPolicy( mgr
, &policy
);
276 ok( hr
== S_OK
, "got %08x\n", hr
);
277 if (hr
!= S_OK
) goto done
;
279 hr
= INetFwPolicy_get_CurrentProfile( policy
, &profile
);
280 if (hr
!= S_OK
) goto done
;
282 hr
= INetFwProfile_get_AuthorizedApplications( profile
, &apps
);
283 ok( hr
== S_OK
, "got %08x\n", hr
);
284 if (hr
!= S_OK
) goto done
;
286 hr
= CoCreateInstance( &CLSID_NetFwAuthorizedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
287 &IID_INetFwAuthorizedApplication
, (void **)&app
);
288 ok( hr
== S_OK
, "got %08x\n", hr
);
289 if (hr
!= S_OK
) goto done
;
291 hr
= INetFwAuthorizedApplication_put_ProcessImageFileName( app
, image
);
292 if (hr
!= S_OK
) goto done
;
294 name
= SysAllocString( clientW
);
295 hr
= INetFwAuthorizedApplication_put_Name( app
, name
);
296 SysFreeString( name
);
297 ok( hr
== S_OK
, "got %08x\n", hr
);
298 if (hr
!= S_OK
) goto done
;
301 hr
= INetFwAuthorizedApplications_Add( apps
, app
);
302 else if (op
== APP_REMOVE
)
303 hr
= INetFwAuthorizedApplications_Remove( apps
, image
);
306 if (hr
!= S_OK
) goto done
;
308 INetFwAuthorizedApplication_Release( app
);
309 hr
= CoCreateInstance( &CLSID_NetFwAuthorizedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
310 &IID_INetFwAuthorizedApplication
, (void **)&app
);
311 ok( hr
== S_OK
, "got %08x\n", hr
);
312 if (hr
!= S_OK
) goto done
;
314 SysFreeString( image
);
315 image
= SysAllocString( path
);
316 hr
= INetFwAuthorizedApplication_put_ProcessImageFileName( app
, image
);
317 if (hr
!= S_OK
) goto done
;
319 name
= SysAllocString( serverW
);
320 hr
= INetFwAuthorizedApplication_put_Name( app
, name
);
321 SysFreeString( name
);
322 ok( hr
== S_OK
, "got %08x\n", hr
);
323 if (hr
!= S_OK
) goto done
;
326 hr
= INetFwAuthorizedApplications_Add( apps
, app
);
327 else if (op
== APP_REMOVE
)
328 hr
= INetFwAuthorizedApplications_Remove( apps
, image
);
333 if (app
) INetFwAuthorizedApplication_Release( app
);
334 if (apps
) INetFwAuthorizedApplications_Release( apps
);
335 if (policy
) INetFwPolicy_Release( policy
);
336 if (profile
) INetFwProfile_Release( profile
);
337 if (mgr
) INetFwMgr_Release( mgr
);
338 if (SUCCEEDED( init
)) CoUninitialize();
339 SysFreeString( image
);
343 /* taken from programs/winetest/main.c */
344 BOOL
is_stub_dll(const char *filename
)
350 size
= GetFileVersionInfoSizeA(filename
, &ver
);
351 if (!size
) return FALSE
;
353 data
= HeapAlloc(GetProcessHeap(), 0, size
);
354 if (!data
) return FALSE
;
356 if (GetFileVersionInfoA(filename
, ver
, size
, data
))
360 sprintf(buf
, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), 1200);
361 if (VerQueryValueA(data
, buf
, (void**)&p
, &size
))
362 isstub
= !lstrcmpiA("wcodstub.dll", p
);
364 HeapFree(GetProcessHeap(), 0, data
);
372 BOOL firewall_enabled
;
375 if(!GetSystemDirectoryA(path
, MAX_PATH
))
377 skip("Failed to get systems directory\n");
380 strcat(path
, "\\dpnet.dll");
382 if (!winetest_interactive
&& is_stub_dll(path
))
384 win_skip("dpnet is a stub dll, skipping tests\n");
388 if ((firewall_enabled
= is_firewall_enabled()) && !is_process_elevated())
390 skip("no privileges, skipping tests to avoid firewall dialog\n");
394 if (firewall_enabled
)
396 HRESULT hr
= set_firewall(APP_ADD
);
399 skip("can't authorize app in firewall %08x\n", hr
);
404 hr
= CoInitialize(0);
405 ok( hr
== S_OK
, "failed to init com\n");
415 if (firewall_enabled
) set_firewall(APP_REMOVE
);