fixed ProcessIdToSessionId()

svn path=/trunk/; revision=11161
This commit is contained in:
Thomas Bluemel 2004-10-02 21:14:08 +00:00
parent 3f75c451d1
commit b26683b0b3
2 changed files with 48 additions and 40 deletions

View file

@ -1,4 +1,4 @@
/* $Id: proc.c,v 1.68 2004/09/23 19:01:38 weiden Exp $ /* $Id: proc.c,v 1.69 2004/10/02 21:14:08 weiden Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -356,7 +356,7 @@ OpenProcess(DWORD dwDesiredAccess,
NTSTATUS errCode; NTSTATUS errCode;
HANDLE ProcessHandle; HANDLE ProcessHandle;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId ; CLIENT_ID ClientId;
ClientId.UniqueProcess = (HANDLE)dwProcessId; ClientId.UniqueProcess = (HANDLE)dwProcessId;
ClientId.UniqueThread = INVALID_HANDLE_VALUE; ClientId.UniqueThread = INVALID_HANDLE_VALUE;

View file

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.6 2004/09/23 21:01:23 ea Exp $ /* $Id: session.c,v 1.7 2004/10/02 21:14:08 weiden Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -48,43 +48,51 @@ DosPathToSessionPathA (DWORD SessionId, LPSTR InPath, LPSTR * OutPath)
BOOL STDCALL ProcessIdToSessionId (IN DWORD dwProcessId, BOOL STDCALL ProcessIdToSessionId (IN DWORD dwProcessId,
OUT DWORD* pSessionId) OUT DWORD* pSessionId)
{ {
NTSTATUS Status = STATUS_SUCCESS; PROCESS_SESSION_INFORMATION SessionInformation;
HANDLE ProcessHandle = INVALID_HANDLE_VALUE; OBJECT_ATTRIBUTES ObjectAttributes;
OBJECT_ATTRIBUTES Oa = { sizeof (OBJECT_ATTRIBUTES), 0, }; CLIENT_ID ClientId;
DWORD SessionId = 0; HANDLE ProcessHandle;
NTSTATUS Status;
if (IsBadWritePtr(pSessionId, sizeof (DWORD))) if(IsBadWritePtr(pSessionId, sizeof(DWORD)))
{ {
SetLastError (ERROR_INVALID_DATA); //FIXME SetLastError(ERROR_INVALID_PARAMETER);
goto ProcessIdToSessionId_FAIL_EXIT; return FALSE;
} }
Status = NtOpenProcess (
& ProcessHandle, ClientId.UniqueProcess = (HANDLE)dwProcessId;
ClientId.UniqueThread = INVALID_HANDLE_VALUE;
InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
Status = NtOpenProcess(&ProcessHandle,
PROCESS_QUERY_INFORMATION, PROCESS_QUERY_INFORMATION,
& Oa, &ObjectAttributes,
NULL); &ClientId);
if (!NT_SUCCESS(Status)) if(NT_SUCCESS(Status))
{ {
goto ProcessIdToSessionId_FAIL; Status = NtQueryInformationProcess(ProcessHandle,
}
Status = NtQueryInformationProcess (
ProcessHandle,
ProcessSessionInformation, ProcessSessionInformation,
& SessionId, &SessionInformation,
sizeof SessionId, sizeof(SessionInformation),
NULL); NULL);
if (!NT_SUCCESS(Status)) NtClose(ProcessHandle);
{
NtClose (ProcessHandle);
goto ProcessIdToSessionId_FAIL;
}
NtClose (ProcessHandle);
*pSessionId = SessionId;
return TRUE;
ProcessIdToSessionId_FAIL: if(NT_SUCCESS(Status))
{
*pSessionId = SessionInformation.SessionId;
return TRUE;
}
else
{
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
ProcessIdToSessionId_FAIL_EXIT: }
}
else
{
SetLastErrorByStatus(Status);
}
return FALSE; return FALSE;
} }