Emanuele Aliberti <ea@reactos.com>
[reactos.git] / reactos / lib / kernel32 / process / session.c
1 /* $Id: session.c,v 1.6 2004/09/23 21:01:23 ea Exp $
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
13 DWORD ActiveConsoleSessionId = 0;
14
15
16 /*
17 * @unimplemented
18 */
19 DWORD STDCALL
20 DosPathToSessionPathW (DWORD SessionID, LPWSTR InPath, LPWSTR * OutPath)
21 {
22 return 0;
23 }
24
25 /*
26 * From: ActiveVB.DE
27 *
28 * Declare Function DosPathToSessionPath _
29 * Lib "kernel32.dll" _
30 * Alias "DosPathToSessionPathA" ( _
31 * ByVal SessionId As Long, _
32 * ByVal pInPath As String, _
33 * ByVal ppOutPath As String ) _
34 * As Long
35 *
36 * @unimplemented
37 */
38 DWORD STDCALL
39 DosPathToSessionPathA (DWORD SessionId, LPSTR InPath, LPSTR * OutPath)
40 {
41 //DosPathToSessionPathW (SessionId,InPathW,OutPathW);
42 return 0;
43 }
44
45 /*
46 * @implemented
47 */
48 BOOL STDCALL ProcessIdToSessionId (IN DWORD dwProcessId,
49 OUT DWORD* pSessionId)
50 {
51 NTSTATUS Status = STATUS_SUCCESS;
52 HANDLE ProcessHandle = INVALID_HANDLE_VALUE;
53 OBJECT_ATTRIBUTES Oa = { sizeof (OBJECT_ATTRIBUTES), 0, };
54 DWORD SessionId = 0;
55
56 if (IsBadWritePtr(pSessionId, sizeof (DWORD)))
57 {
58 SetLastError (ERROR_INVALID_DATA); //FIXME
59 goto ProcessIdToSessionId_FAIL_EXIT;
60 }
61 Status = NtOpenProcess (
62 & ProcessHandle,
63 PROCESS_QUERY_INFORMATION,
64 & Oa,
65 NULL);
66 if (!NT_SUCCESS(Status))
67 {
68 goto ProcessIdToSessionId_FAIL;
69 }
70 Status = NtQueryInformationProcess (
71 ProcessHandle,
72 ProcessSessionInformation,
73 & SessionId,
74 sizeof SessionId,
75 NULL);
76 if (!NT_SUCCESS(Status))
77 {
78 NtClose (ProcessHandle);
79 goto ProcessIdToSessionId_FAIL;
80 }
81 NtClose (ProcessHandle);
82 *pSessionId = SessionId;
83 return TRUE;
84
85 ProcessIdToSessionId_FAIL:
86 SetLastErrorByStatus(Status);
87 ProcessIdToSessionId_FAIL_EXIT:
88 return FALSE;
89 }
90
91 /*
92 * @implemented
93 */
94 DWORD STDCALL
95 WTSGetActiveConsoleSessionId (VOID)
96 {
97 return ActiveConsoleSessionId;
98 }
99
100 /* EOF */