- Merge from trunk up to r45543
[reactos.git] / dll / win32 / kernel32 / process / session.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/proc/session.c
6 * PURPOSE: Win32 session (TS) functions
7 * PROGRAMMER: Emanuele Aliberti
8 * UPDATE HISTORY:
9 * 2001-12-07 created
10 */
11 #include <k32.h>
12 #include <wine/debug.h>
13
14 WINE_DEFAULT_DEBUG_CHANNEL(kernel32session);
15
16 DWORD ActiveConsoleSessionId = 0;
17
18
19 /*
20 * @unimplemented
21 */
22 DWORD
23 WINAPI
24 DosPathToSessionPathW(DWORD SessionID,
25 LPWSTR InPath,
26 LPWSTR *OutPath)
27 {
28 UNIMPLEMENTED;
29 return 0;
30 }
31
32 /*
33 * From: ActiveVB.DE
34 *
35 * Declare Function DosPathToSessionPath _
36 * Lib "kernel32.dll" _
37 * Alias "DosPathToSessionPathA" ( _
38 * ByVal SessionId As Long, _
39 * ByVal pInPath As String, _
40 * ByVal ppOutPath As String ) _
41 * As Long
42 *
43 * @unimplemented
44 */
45 DWORD
46 WINAPI
47 DosPathToSessionPathA(DWORD SessionId,
48 LPSTR InPath,
49 LPSTR *OutPath)
50 {
51 //DosPathToSessionPathW (SessionId,InPathW,OutPathW);
52 UNIMPLEMENTED;
53 return 0;
54 }
55
56 /*
57 * @implemented
58 */
59 BOOL
60 WINAPI
61 ProcessIdToSessionId(IN DWORD dwProcessId,
62 OUT DWORD *pSessionId)
63 {
64 PROCESS_SESSION_INFORMATION SessionInformation;
65 OBJECT_ATTRIBUTES ObjectAttributes;
66 CLIENT_ID ClientId;
67 HANDLE ProcessHandle;
68 NTSTATUS Status;
69
70 if (IsBadWritePtr(pSessionId, sizeof(DWORD)))
71 {
72 SetLastError(ERROR_INVALID_PARAMETER);
73 return FALSE;
74 }
75
76 ClientId.UniqueProcess = (HANDLE)dwProcessId;
77 ClientId.UniqueThread = 0;
78
79 InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
80
81 Status = NtOpenProcess(&ProcessHandle,
82 PROCESS_QUERY_INFORMATION,
83 &ObjectAttributes,
84 &ClientId);
85 if (NT_SUCCESS(Status))
86 {
87 Status = NtQueryInformationProcess(ProcessHandle,
88 ProcessSessionInformation,
89 &SessionInformation,
90 sizeof(SessionInformation),
91 NULL);
92 NtClose(ProcessHandle);
93
94 if (NT_SUCCESS(Status))
95 {
96 *pSessionId = SessionInformation.SessionId;
97 return TRUE;
98 }
99 }
100
101 SetLastErrorByStatus(Status);
102 return FALSE;
103 }
104
105 /*
106 * @implemented
107 */
108 DWORD
109 WINAPI
110 WTSGetActiveConsoleSessionId(VOID)
111 {
112 return ActiveConsoleSessionId;
113 }
114
115 /* EOF */