user32: Use a default name for winstations created or opened with no name.

The default is of the form "Service-0x<luid high>-<luid low>$" where the
luid in question is the logon session luid.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-06-23 12:56:39 +01:00 committed by Alexandre Julliard
parent e0b5edf896
commit 6e69e512d8
2 changed files with 53 additions and 5 deletions

View File

@ -118,9 +118,10 @@ static void test_handles(void)
HANDLE hthread;
DWORD id, flags, le;
ATOM atom;
char buffer[20];
char buffer[29], default_name[29] = "";
DWORD size;
BOOL ret;
TOKEN_STATISTICS token_stats;
/* win stations */
@ -215,7 +216,6 @@ static void test_handles(void)
SetLastError( 0xdeadbeef );
w2 = OpenWindowStationA( "", TRUE, WINSTA_ALL_ACCESS );
ok( !w2, "open station succeeded\n" );
todo_wine
ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError() );
SetLastError( 0xdeadbeef );
@ -225,16 +225,30 @@ static void test_handles(void)
memset( buffer, 0, sizeof(buffer) );
ret = GetUserObjectInformationA( w2, UOI_NAME, buffer, sizeof(buffer), &size );
ok( ret, "GetUserObjectInformationA failed with error %u\n", GetLastError() );
todo_wine ok( !memcmp(buffer, "Service-0x0-", 12), "unexpected window station name '%s'\n", buffer );
todo_wine ok( buffer[strlen(buffer) - 1] == '$', "unexpected window station name '%s'\n", buffer );
/* Get the logon session LUID */
ret = GetTokenInformation( GetCurrentProcessToken(), TokenStatistics, &token_stats, sizeof(token_stats), NULL );
if (ret)
sprintf( default_name, "Service-0x%x-%x$", token_stats.AuthenticationId.HighPart,
token_stats.AuthenticationId.LowPart );
if (*default_name)
ok( !strcmp( buffer, default_name ), "unexpected window station name '%s' expected '%s'\n", buffer, default_name );
SetLastError( 0xdeadbeef );
w3 = OpenWindowStationA( "", TRUE, WINSTA_ALL_ACCESS );
todo_wine
ok( w3 != 0, "open station failed err %u\n", GetLastError() );
CloseWindowStation( w3 );
CloseWindowStation( w2 );
w2 = CreateWindowStationA( NULL, 0, WINSTA_ALL_ACCESS, NULL );
ok( w2 != 0, "create station failed err %u\n", GetLastError() );
memset( buffer, 0, sizeof(buffer) );
ret = GetUserObjectInformationA( w2, UOI_NAME, buffer, sizeof(buffer), &size );
ok( ret, "GetUserObjectInformationA failed with error %u\n", GetLastError() );
if (*default_name)
ok( !strcmp( buffer, default_name ), "unexpected window station name '%s' expected '%s'\n", buffer, default_name );
CloseWindowStation( w2 );
SetLastError( 0xdeadbeef );
w2 = CreateWindowStationA( "foo\\bar", 0, WINSTA_ALL_ACCESS, NULL );
ok( !w2, "create station succeeded\n" );

View File

@ -80,6 +80,30 @@ static HANDLE get_winstations_dir_handle(void)
return handle;
}
static BOOL WINAPI winstation_default_name_once( INIT_ONCE *once, void *param, void **context )
{
static const WCHAR fmt[] = {'S','e','r','v','i','c','e','-','0','x','%','x','-','%','x','$',0};
WCHAR *name = (WCHAR *)param;
TOKEN_STATISTICS stats;
BOOL ret;
ret = GetTokenInformation( GetCurrentProcessToken(), TokenStatistics, &stats, sizeof(stats), NULL );
if (ret)
sprintfW( name, fmt, stats.AuthenticationId.HighPart, stats.AuthenticationId.LowPart );
return ret;
}
static const WCHAR *get_winstation_default_name( void )
{
static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
static WCHAR name[29];
BOOL ret;
ret = InitOnceExecuteOnce( &once, winstation_default_name_once, name, NULL );
return ret ? name : NULL;
}
/***********************************************************************
* CreateWindowStationA (USER32.@)
*/
@ -113,6 +137,11 @@ HWINSTA WINAPI CreateWindowStationW( LPCWSTR name, DWORD flags, ACCESS_MASK acce
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
if (!len)
{
name = get_winstation_default_name();
len = strlenW( name );
}
SERVER_START_REQ( create_winstation )
{
req->flags = 0;
@ -160,6 +189,11 @@ HWINSTA WINAPI OpenWindowStationW( LPCWSTR name, BOOL inherit, ACCESS_MASK acces
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
if (!len)
{
name = get_winstation_default_name();
len = strlenW( name );
}
SERVER_START_REQ( open_winstation )
{
req->access = access;