ReactOS  0.4.15-dev-344-g6808e40
winsta.c File Reference
#include <user32.h>
Include dependency graph for winsta.c:

Go to the source code of this file.

Classes

struct  tagENUMNAMESASCIICONTEXT
 

Typedefs

typedef struct tagENUMNAMESASCIICONTEXT ENUMNAMESASCIICONTEXT
 
typedef struct tagENUMNAMESASCIICONTEXTPENUMNAMESASCIICONTEXT
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winsta)
 
HWINSTA WINAPI CreateWindowStationA (IN LPCSTR lpwinsta OPTIONAL, IN DWORD dwReserved, IN ACCESS_MASK dwDesiredAccess, IN LPSECURITY_ATTRIBUTES lpsa OPTIONAL)
 
HWINSTA WINAPI CreateWindowStationW (IN LPCWSTR lpwinsta OPTIONAL, IN DWORD dwReserved, IN ACCESS_MASK dwDesiredAccess, IN LPSECURITY_ATTRIBUTES lpsa OPTIONAL)
 
BOOL FASTCALL EnumNamesW (HWINSTA WindowStation, NAMEENUMPROCW EnumFunc, LPARAM Context, BOOL Desktops)
 
BOOL CALLBACK EnumNamesCallback (LPWSTR Name, LPARAM Param)
 
BOOL FASTCALL EnumNamesA (HWINSTA WindowStation, NAMEENUMPROCA EnumFunc, LPARAM Context, BOOL Desktops)
 
BOOL WINAPI EnumWindowStationsA (IN WINSTAENUMPROCA EnumFunc, IN LPARAM Context)
 
BOOL WINAPI EnumWindowStationsW (IN WINSTAENUMPROCW EnumFunc, IN LPARAM Context)
 
BOOL WINAPI GetWinStationInfo (PVOID pUnknown)
 
HWINSTA WINAPI OpenWindowStationA (IN LPCSTR lpszWinSta, IN BOOL fInherit, IN ACCESS_MASK dwDesiredAccess)
 
HWINSTA WINAPI OpenWindowStationW (IN LPCWSTR lpszWinSta, IN BOOL fInherit, IN ACCESS_MASK dwDesiredAccess)
 
BOOL WINAPI SetWindowStationUser (IN HWINSTA hWindowStation, IN PLUID pluid, IN PSID psid OPTIONAL, IN DWORD size)
 

Typedef Documentation

◆ ENUMNAMESASCIICONTEXT

◆ PENUMNAMESASCIICONTEXT

Function Documentation

◆ CreateWindowStationA()

HWINSTA WINAPI CreateWindowStationA ( IN LPCSTR lpwinsta  OPTIONAL,
IN DWORD  dwReserved,
IN ACCESS_MASK  dwDesiredAccess,
IN LPSECURITY_ATTRIBUTES lpsa  OPTIONAL 
)

Definition at line 18 of file winsta.c.

23 {
24  HWINSTA hWinSta;
25  UNICODE_STRING WindowStationNameU;
26 
27  if (lpwinsta)
28  {
29  /* After conversion, the buffer is zero-terminated */
30  RtlCreateUnicodeStringFromAsciiz(&WindowStationNameU, lpwinsta);
31  }
32  else
33  {
34  RtlInitUnicodeString(&WindowStationNameU, NULL);
35  }
36 
37  hWinSta = CreateWindowStationW(WindowStationNameU.Buffer,
38  dwReserved,
39  dwDesiredAccess,
40  lpsa);
41 
42  /* Free the string if it was allocated */
43  if (lpwinsta) RtlFreeUnicodeString(&WindowStationNameU);
44 
45  return hWinSta;
46 }
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:90
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
HWINSTA WINAPI CreateWindowStationW(IN LPCWSTR lpwinsta OPTIONAL, IN DWORD dwReserved, IN ACCESS_MASK dwDesiredAccess, IN LPSECURITY_ATTRIBUTES lpsa OPTIONAL)
Definition: winsta.c:54
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

◆ CreateWindowStationW()

HWINSTA WINAPI CreateWindowStationW ( IN LPCWSTR lpwinsta  OPTIONAL,
IN DWORD  dwReserved,
IN ACCESS_MASK  dwDesiredAccess,
IN LPSECURITY_ATTRIBUTES lpsa  OPTIONAL 
)

Definition at line 54 of file winsta.c.

59 {
61  HWINSTA hWinSta;
62  UNICODE_STRING WindowStationName;
63  // FIXME: We should cache a per-session directory (see ntuser\winsta.c!UserCreateWinstaDirectory).
64  UNICODE_STRING WindowStationsDir = RTL_CONSTANT_STRING(L"\\Windows\\WindowStations");
66  HANDLE hWindowStationsDir;
67 
68  /*
69  * If provided, the window station name is always relative to the
70  * current user session's WindowStations directory.
71  * Otherwise (the window station name is NULL or an empty string),
72  * pass both an empty string and no WindowStations directory handle
73  * to win32k, so that it will create a window station whose name
74  * is based on the logon session identifier for the calling process.
75  */
76  if (lpwinsta && *lpwinsta)
77  {
78  /* Open WindowStations directory */
80  &WindowStationsDir,
82  NULL,
83  NULL);
84 
85  Status = NtOpenDirectoryObject(&hWindowStationsDir,
88  if (!NT_SUCCESS(Status))
89  {
90  ERR("Failed to open WindowStations directory\n");
91  return NULL;
92  }
93 
94  RtlInitUnicodeString(&WindowStationName, lpwinsta);
95  }
96  else
97  {
98  lpwinsta = NULL;
99  hWindowStationsDir = NULL;
100  }
101 
102  /* Create the window station object */
104  lpwinsta ? &WindowStationName : NULL,
106  hWindowStationsDir,
107  NULL);
108 
109  /* Check if the handle should be inheritable */
110  if (lpsa && lpsa->bInheritHandle)
111  {
112  ObjectAttributes.Attributes |= OBJ_INHERIT;
113  }
114 
116  dwDesiredAccess,
117  0, 0, 0, 0, 0);
118 
119  if (hWindowStationsDir)
120  NtClose(hWindowStationsDir);
121 
122  return hWinSta;
123 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
NTSTATUS NTAPI NtOpenDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:401
HWINSTA APIENTRY NtUserCreateWindowStation(IN POBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK dwDesiredAccess, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4, DWORD Unknown5, DWORD Unknown6)
Definition: winsta.c:695
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_OPENIF
Definition: winternl.h:229
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_INHERIT
Definition: winternl.h:225
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:110
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by CreateWindowStationA().

◆ EnumNamesA()

BOOL FASTCALL EnumNamesA ( HWINSTA  WindowStation,
NAMEENUMPROCA  EnumFunc,
LPARAM  Context,
BOOL  Desktops 
)

Definition at line 273 of file winsta.c.

277 {
278  ENUMNAMESASCIICONTEXT PrivateContext;
279 
280  PrivateContext.UserEnumFunc = EnumFunc;
281  PrivateContext.UserContext = Context;
282 
283  return EnumNamesW(WindowStation, EnumNamesCallback, (LPARAM) &PrivateContext, Desktops);
284 }
BOOL CALLBACK EnumNamesCallback(LPWSTR Name, LPARAM Param)
Definition: winsta.c:211
LONG_PTR LPARAM
Definition: windef.h:208
static BOOL CALLBACK EnumFunc(_In_ HWND hWnd, _In_ PCWSTR lpszString, _In_ HANDLE hData)
Definition: SetProp.c:15
BOOL FASTCALL EnumNamesW(HWINSTA WindowStation, NAMEENUMPROCW EnumFunc, LPARAM Context, BOOL Desktops)
Definition: winsta.c:130
struct tagContext Context
Definition: acpixf.h:1034
NAMEENUMPROCA UserEnumFunc
Definition: winsta.c:201

Referenced by EnumDesktopsA(), and EnumWindowStationsA().

◆ EnumNamesCallback()

BOOL CALLBACK EnumNamesCallback ( LPWSTR  Name,
LPARAM  Param 
)

Definition at line 211 of file winsta.c.

212 {
214  CHAR FixedNameA[32];
215  LPSTR NameA;
216  INT Len;
217  BOOL Ret;
218 
219  /*
220  * Determine required size of Ascii string and see
221  * if we can use fixed buffer.
222  */
223  Len = WideCharToMultiByte(CP_ACP, 0, Name, -1, NULL, 0, NULL, NULL);
224  if (Len <= 0)
225  {
226  /* Some strange error occured */
227  return FALSE;
228  }
229  else if (Len <= sizeof(FixedNameA))
230  {
231  /* Fixed-size buffer is large enough */
232  NameA = FixedNameA;
233  }
234  else
235  {
236  /* Allocate a larger buffer */
237  NameA = HeapAlloc(GetProcessHeap(), 0, Len);
238  if (NULL == NameA)
239  {
241  return FALSE;
242  }
243  }
244 
245  /* Do the Unicode ->Ascii conversion */
246  if (0 == WideCharToMultiByte(CP_ACP, 0, Name, -1, NameA, Len, NULL, NULL))
247  {
248  /* Something went wrong, clean up */
249  if (NameA != FixedNameA)
250  {
251  HeapFree(GetProcessHeap(), 0, NameA);
252  }
253  return FALSE;
254  }
255 
256  /* Call user callback */
257  Ret = Context->UserEnumFunc(NameA, Context->UserContext);
258 
259  /* Cleanup */
260  if (NameA != FixedNameA)
261  {
262  HeapFree(GetProcessHeap(), 0, NameA);
263  }
264 
265  return Ret;
266 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
char * LPSTR
Definition: xmlstorage.h:182
int32_t INT
Definition: typedefs.h:57
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define Len
Definition: deflate.h:82
#define SetLastError(x)
Definition: compat.h:418
struct tagENUMNAMESASCIICONTEXT * PENUMNAMESASCIICONTEXT
#define HeapFree(x, y, z)
Definition: compat.h:403

Referenced by EnumNamesA().

◆ EnumNamesW()

BOOL FASTCALL EnumNamesW ( HWINSTA  WindowStation,
NAMEENUMPROCW  EnumFunc,
LPARAM  Context,
BOOL  Desktops 
)

Definition at line 130 of file winsta.c.

134 {
135  CHAR Buffer[256];
136  PVOID NameList;
137  PWCHAR Name;
140  ULONG CurrentEntry, EntryCount;
141  BOOL Ret;
142 
143  /* Check parameters */
144  if (WindowStation == NULL && Desktops)
145  {
146  WindowStation = GetProcessWindowStation();
147  }
148 
149  /* Try with fixed-size buffer */
150  Status = NtUserBuildNameList(WindowStation, sizeof(Buffer), Buffer, &RequiredSize);
151  if (NT_SUCCESS(Status))
152  {
153  /* Fixed-size buffer is large enough */
154  NameList = (PWCHAR) Buffer;
155  }
156  else if (Status == STATUS_BUFFER_TOO_SMALL)
157  {
158  /* Allocate a larger buffer */
159  NameList = HeapAlloc(GetProcessHeap(), 0, RequiredSize);
160  if (NameList == NULL)
161  return FALSE;
162 
163  /* Try again */
164  Status = NtUserBuildNameList(WindowStation, RequiredSize, NameList, NULL);
165  if (!NT_SUCCESS(Status))
166  {
167  HeapFree(GetProcessHeap(), 0, NameList);
169  return FALSE;
170  }
171  }
172  else
173  {
174  /* Some unrecognized error occured */
176  return FALSE;
177  }
178 
179  /* Enum the names one by one */
180  EntryCount = *((DWORD *) NameList);
181  Name = (PWCHAR) ((PCHAR) NameList + sizeof(DWORD));
182  Ret = TRUE;
183  for (CurrentEntry = 0; CurrentEntry < EntryCount && Ret; ++CurrentEntry)
184  {
185  Ret = (*EnumFunc)(Name, Context);
186  Name += wcslen(Name) + 1;
187  }
188 
189  /* Cleanup */
190  if (NameList != Buffer)
191  {
192  HeapFree(GetProcessHeap(), 0, NameList);
193  }
194 
195  return Ret;
196 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
NTSTATUS APIENTRY NtUserBuildNameList(HWINSTA hWindowStation, ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
Definition: winsta.c:1901
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:55
#define DWORD
Definition: nt_native.h:44
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
unsigned int BOOL
Definition: ntddk_ex.h:94
struct NameRec_ * Name
Definition: cdprocs.h:464
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_Inout_ PRTL_BUFFER _In_ SIZE_T RequiredSize
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:418
Status
Definition: gdiplustypes.h:24
HWINSTA WINAPI GetProcessWindowStation(void)
Definition: ntwrapper.h:124
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:403

Referenced by EnumDesktopsW(), EnumNamesA(), and EnumWindowStationsW().

◆ EnumWindowStationsA()

BOOL WINAPI EnumWindowStationsA ( IN WINSTAENUMPROCA  EnumFunc,
IN LPARAM  Context 
)

Definition at line 291 of file winsta.c.

294 {
295  return EnumNamesA(NULL, EnumFunc, Context, FALSE);
296 }
smooth NULL
Definition: ftsmooth.c:416
static BOOL CALLBACK EnumFunc(_In_ HWND hWnd, _In_ PCWSTR lpszString, _In_ HANDLE hData)
Definition: SetProp.c:15
BOOL FASTCALL EnumNamesA(HWINSTA WindowStation, NAMEENUMPROCA EnumFunc, LPARAM Context, BOOL Desktops)
Definition: winsta.c:273

◆ EnumWindowStationsW()

BOOL WINAPI EnumWindowStationsW ( IN WINSTAENUMPROCW  EnumFunc,
IN LPARAM  Context 
)

Definition at line 304 of file winsta.c.

307 {
308  return EnumNamesW(NULL, EnumFunc, Context, FALSE);
309 }
smooth NULL
Definition: ftsmooth.c:416
static BOOL CALLBACK EnumFunc(_In_ HWND hWnd, _In_ PCWSTR lpszString, _In_ HANDLE hData)
Definition: SetProp.c:15
BOOL FASTCALL EnumNamesW(HWINSTA WindowStation, NAMEENUMPROCW EnumFunc, LPARAM Context, BOOL Desktops)
Definition: winsta.c:130

◆ GetWinStationInfo()

BOOL WINAPI GetWinStationInfo ( PVOID  pUnknown)

Definition at line 317 of file winsta.c.

318 {
320 }
DWORD_PTR NTAPI NtUserCallOneParam(DWORD_PTR Param, DWORD Routine)
Definition: simplecall.c:145
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ PUNKNOWN pUnknown
Definition: drmk.h:76
uint32_t DWORD_PTR
Definition: typedefs.h:64

◆ OpenWindowStationA()

HWINSTA WINAPI OpenWindowStationA ( IN LPCSTR  lpszWinSta,
IN BOOL  fInherit,
IN ACCESS_MASK  dwDesiredAccess 
)

Definition at line 328 of file winsta.c.

332 {
333  HWINSTA hWinSta;
334  UNICODE_STRING WindowStationNameU;
335 
336  if (lpszWinSta)
337  {
338  /* After conversion, the buffer is zero-terminated */
339  RtlCreateUnicodeStringFromAsciiz(&WindowStationNameU, lpszWinSta);
340  }
341  else
342  {
343  RtlInitUnicodeString(&WindowStationNameU, NULL);
344  }
345 
346  hWinSta = OpenWindowStationW(WindowStationNameU.Buffer,
347  fInherit,
348  dwDesiredAccess);
349 
350  /* Free the string if it was allocated */
351  if (lpszWinSta) RtlFreeUnicodeString(&WindowStationNameU);
352 
353  return hWinSta;
354 }
HWINSTA WINAPI OpenWindowStationW(IN LPCWSTR lpszWinSta, IN BOOL fInherit, IN ACCESS_MASK dwDesiredAccess)
Definition: winsta.c:362
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

◆ OpenWindowStationW()

HWINSTA WINAPI OpenWindowStationW ( IN LPCWSTR  lpszWinSta,
IN BOOL  fInherit,
IN ACCESS_MASK  dwDesiredAccess 
)

Definition at line 362 of file winsta.c.

366 {
368  HWINSTA hWinSta;
369  UNICODE_STRING WindowStationName;
370  // FIXME: We should cache a per-session directory (see ntuser\winsta.c!UserCreateWinstaDirectory).
371  UNICODE_STRING WindowStationsDir = RTL_CONSTANT_STRING(L"\\Windows\\WindowStations");
373  HANDLE hWindowStationsDir;
374 
375  /* Open WindowStations directory */
377  &WindowStationsDir,
379  NULL,
380  NULL);
381 
382  Status = NtOpenDirectoryObject(&hWindowStationsDir,
385  if(!NT_SUCCESS(Status))
386  {
387  ERR("Failed to open WindowStations directory\n");
388  return NULL;
389  }
390 
391  /* Open the window station object */
392  RtlInitUnicodeString(&WindowStationName, lpszWinSta);
393 
395  &WindowStationName,
397  hWindowStationsDir,
398  NULL);
399 
400  /* Check if the handle should be inheritable */
401  if (fInherit)
402  {
403  ObjectAttributes.Attributes |= OBJ_INHERIT;
404  }
405 
406  hWinSta = NtUserOpenWindowStation(&ObjectAttributes, dwDesiredAccess);
407 
408  NtClose(hWindowStationsDir);
409 
410  return hWinSta;
411 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS NTAPI NtOpenDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:401
LONG NTSTATUS
Definition: precomp.h:26
HWINSTA APIENTRY NtUserOpenWindowStation(IN POBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK dwDesiredAccess)
Definition: winsta.c:836
smooth NULL
Definition: ftsmooth.c:416
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_INHERIT
Definition: winternl.h:225
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:110
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by OpenWindowStationA().

◆ SetWindowStationUser()

BOOL WINAPI SetWindowStationUser ( IN HWINSTA  hWindowStation,
IN PLUID  pluid,
IN PSID psid  OPTIONAL,
IN DWORD  size 
)

Definition at line 419 of file winsta.c.

424 {
425  BOOL Success;
426 
427  Success = NtUserSetWindowStationUser(hWindowStation, pluid, psid, size);
428  if (Success)
429  {
430  /* Signal log-on/off to WINSRV */
431 
432  /* User is logging on if *pluid != LuidNone, otherwise it is a log-off */
433  LUID LuidNone = {0, 0};
434  BOOL IsLogon = (pluid && !RtlEqualLuid(pluid, &LuidNone));
435 
436  Logon(IsLogon);
437  }
438 
439  return Success;
440 }
LUID LuidNone
Definition: sas.c:46
unsigned int BOOL
Definition: ntddk_ex.h:94
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:301
GLsizeiptr size
Definition: glext.h:5919
VOID FASTCALL Logon(BOOL IsLogon)
Definition: logon.c:74
BOOL NTAPI NtUserSetWindowStationUser(IN HWINSTA hWindowStation, IN PLUID pluid, IN PSID psid OPTIONAL, IN DWORD size)
Definition: winsta.c:1959

Referenced by AllowWinstaAccess(), CreateWindowStationAndDesktops(), HandleLogoff(), and HandleLogon().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winsta  )