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(a)codeweavers.com>
---
dlls/user32/tests/winstation.c | 24 +++++++++++++++++++-----
dlls/user32/winstation.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/dlls/user32/tests/winstation.c b/dlls/user32/tests/winstation.c
index 4aa5565b96c..d239ead6e98 100644
--- a/dlls/user32/tests/winstation.c
+++ b/dlls/user32/tests/winstation.c
@@ -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" );
diff --git a/dlls/user32/winstation.c b/dlls/user32/winstation.c
index 4f53b43bd6c..b5d5a372faf 100644
--- a/dlls/user32/winstation.c
+++ b/dlls/user32/winstation.c
@@ -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;
--
2.23.0