1. don't allow the ProcessImageFileName information class for NtSetInformationProcess() anymore

2. implemented the ProcessImageFileName class for NtQueryInformationProcess
3. changed NtCreateProcess to obtain the file name of the loaded image

svn path=/trunk/; revision=11768
This commit is contained in:
Thomas Bluemel 2004-11-21 21:09:43 +00:00
parent 19f47c9b4f
commit ad45691d40
5 changed files with 185 additions and 101 deletions

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.88 2004/11/07 15:58:41 blight Exp $
/* $Id: create.c,v 1.89 2004/11/21 21:09:42 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -765,7 +765,6 @@ CreateProcessW
UNICODE_STRING CommandLine_U;
CSRSS_API_REQUEST CsrRequest;
CSRSS_API_REPLY CsrReply;
CHAR ImageFileName[8];
PWCHAR s, e;
ULONG i;
UNICODE_STRING CurrentDirectory_U;
@ -780,7 +779,11 @@ CreateProcessW
WCHAR Name[MAX_PATH];
WCHAR *TidyCmdLine;
BOOL IsBatchFile = FALSE;
PROCESS_PRIORITY_CLASS PriorityClass;
OBJECT_ATTRIBUTES ProcObjectAttributes;
ULONG ProcAttributes = 0;
PVOID ProcSecurity = NULL;
DPRINT("CreateProcessW(lpApplicationName '%S', lpCommandLine '%S')\n",
lpApplicationName, lpCommandLine);
@ -876,23 +879,6 @@ CreateProcessW
return FALSE;
}
}
/*
* Store the image file name for the process
*/
e = wcschr(s, L'.');
if (e != NULL)
{
*e = 0;
}
for (i = 0; i < 8; i++)
{
ImageFileName[i] = (CHAR)(s[i]);
}
if (e != NULL)
{
*e = '.';
}
/*
* Process the application name and command line
@ -1012,17 +998,80 @@ CreateProcessW
lpProcessInformation);
}
/////////////////////////////////////////
/*
* Initialize the process object attributes
*/
if(lpProcessAttributes != NULL)
{
if(lpProcessAttributes->bInheritHandle)
{
ProcAttributes |= OBJ_INHERIT;
}
ProcSecurity = lpProcessAttributes->lpSecurityDescriptor;
}
InitializeObjectAttributes(&ProcObjectAttributes,
NULL,
ProcAttributes,
NULL,
ProcSecurity);
/*
* initialize the process priority class structure
*/
PriorityClass.Foreground = FALSE;
if(dwCreationFlags & IDLE_PRIORITY_CLASS)
{
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_IDLE;
}
else if(dwCreationFlags & BELOW_NORMAL_PRIORITY_CLASS)
{
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_BELOW_NORMAL;
}
else if(dwCreationFlags & NORMAL_PRIORITY_CLASS)
{
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL;
}
else if(dwCreationFlags & ABOVE_NORMAL_PRIORITY_CLASS)
{
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_ABOVE_NORMAL;
}
else if(dwCreationFlags & HIGH_PRIORITY_CLASS)
{
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_HIGH;
}
else if(dwCreationFlags & REALTIME_PRIORITY_CLASS)
{
/* FIXME - This is a privileged operation. If we don't have the privilege we should
rather use PROCESS_PRIORITY_CLASS_HIGH. */
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_REALTIME;
}
else
{
/* FIXME - what to do in this case? */
PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL;
}
/*
* Create a new process
*/
Status = NtCreateProcess(&hProcess,
PROCESS_ALL_ACCESS,
NULL,
&ProcObjectAttributes,
NtCurrentProcess(),
bInheritHandles,
hSection,
NULL,
NULL);
/* FIXME - handle failure!!!!! */
Status = NtSetInformationProcess(hProcess,
ProcessPriorityClass,
&PriorityClass,
sizeof(PROCESS_PRIORITY_CLASS));
/* FIXME - handle failure!!!!! */
if (lpStartupInfo)
{
if (lpStartupInfo->lpReserved2)
@ -1069,6 +1118,7 @@ CreateProcessW
0,
TRUE,
DUPLICATE_SAME_ACCESS);
/* FIXME - handle failure!!!!! */
}
/*
@ -1079,6 +1129,8 @@ CreateProcessW
&Sii,
sizeof(Sii),
&i);
/* FIXME - handle failure!!!!! */
/*
* Close the section
*/
@ -1316,11 +1368,7 @@ CreateProcessW
KlInitPeb(hProcess, Ppb, &ImageBaseAddress, Sii.Subsystem);
RtlDestroyProcessParameters (Ppb);
Status = NtSetInformationProcess(hProcess,
ProcessImageFileName,
ImageFileName,
8);
/*
* Create the thread for the kernel
*/

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.58 2004/10/05 10:38:57 ekohl Exp $
/* $Id: startup.c,v 1.59 2004/11/21 21:09:42 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -263,7 +263,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
PEDosHeader->e_lfanew == 0L ||
*(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC)
{
DbgPrint("Image has bad header\n");
DPRINT1("Image has bad header\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
}
@ -289,7 +289,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
NULL);
if (Peb->ProcessHeap == 0)
{
DbgPrint("Failed to create process heap\n");
DPRINT1("Failed to create process heap\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
@ -322,7 +322,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
sizeof(PEB_LDR_DATA));
if (Peb->Ldr == NULL)
{
DbgPrint("Failed to create loader data\n");
DPRINT1("Failed to create loader data\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
Peb->Ldr->Length = sizeof(PEB_LDR_DATA);
@ -348,7 +348,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
sizeof(LDR_MODULE));
if (NtModule == NULL)
{
DbgPrint("Failed to create loader module entry (NTDLL)\n");
DPRINT1("Failed to create loader module entry (NTDLL)\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
memset(NtModule, 0, sizeof(LDR_MODULE));
@ -387,7 +387,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
sizeof(LDR_MODULE));
if (ExeModule == NULL)
{
DbgPrint("Failed to create loader module infomation\n");
DPRINT1("Failed to create loader module infomation\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
ExeModule->BaseAddress = Peb->ImageBaseAddress;
@ -395,7 +395,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
if ((Peb->ProcessParameters == NULL) ||
(Peb->ProcessParameters->ImagePathName.Length == 0))
{
DbgPrint("Failed to access the process parameter block\n");
DPRINT1("Failed to access the process parameter block\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
@ -438,7 +438,7 @@ __true_LdrInitializeThunk (ULONG Unknown1,
/* Check before returning that we can run the image safely. */
if (EntryPoint == NULL)
{
DbgPrint("Failed to initialize image\n");
DPRINT1("Failed to initialize image\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
}
}

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.36 2004/11/19 01:30:35 weiden Exp $
/* $Id: process.c,v 1.37 2004/11/21 21:09:42 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -49,19 +49,16 @@ static NTSTATUS RtlpCreateFirstThread
}
static NTSTATUS
RtlpMapFile(PRTL_USER_PROCESS_PARAMETERS Ppb,
RtlpMapFile(PUNICODE_STRING ImageFileName,
PRTL_USER_PROCESS_PARAMETERS Ppb,
ULONG Attributes,
PHANDLE Section,
PCHAR ImageFileName)
PHANDLE Section)
{
HANDLE hFile;
IO_STATUS_BLOCK IoStatusBlock;
OBJECT_ATTRIBUTES ObjectAttributes;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
NTSTATUS Status;
PWCHAR s;
PWCHAR e;
ULONG i;
hFile = NULL;
@ -70,41 +67,13 @@ RtlpMapFile(PRTL_USER_PROCESS_PARAMETERS Ppb,
// DbgPrint("ImagePathName %x\n", Ppb->ImagePathName.Buffer);
InitializeObjectAttributes(&ObjectAttributes,
&(Ppb->ImagePathName),
ImageFileName,
Attributes & (OBJ_CASE_INSENSITIVE | OBJ_INHERIT),
NULL,
SecurityDescriptor);
RtlNormalizeProcessParams (Ppb);
/*
*
*/
// DbgPrint("ImagePathName %x\n", Ppb->ImagePathName.Buffer);
// DbgPrint("ImagePathName %S\n", Ppb->ImagePathName.Buffer);
s = wcsrchr(Ppb->ImagePathName.Buffer, '\\');
if (s == NULL)
{
s = Ppb->ImagePathName.Buffer;
}
else
{
s++;
}
e = wcschr(s, '.');
if (e != NULL)
{
*e = 0;
}
for (i = 0; i < 8; i++)
{
ImageFileName[i] = (CHAR)(s[i]);
}
if (e != NULL)
{
*e = '.';
}
/*
* Try to open the executable
*/
@ -264,17 +233,16 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
NTSTATUS Status;
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
ULONG retlen;
CHAR FileName[8];
SECTION_IMAGE_INFORMATION Sii;
ULONG ResultLength;
PVOID ImageBaseAddress;
DPRINT("RtlCreateUserProcess\n");
Status = RtlpMapFile(ProcessParameters,
Status = RtlpMapFile(ImageFileName,
ProcessParameters,
Attributes,
&hSection,
FileName);
&hSection);
if( !NT_SUCCESS( Status ) )
return Status;
@ -309,11 +277,6 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
DPRINT("ProcessBasicInfo.UniqueProcessId %d\n",
ProcessBasicInfo.UniqueProcessId);
ProcessInfo->ClientId.UniqueProcess = (HANDLE)ProcessBasicInfo.UniqueProcessId;
Status = NtSetInformationProcess(ProcessInfo->ProcessHandle,
ProcessImageFileName,
FileName,
8);
/*
* Create Process Environment Block
@ -342,13 +305,15 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
ImageBaseAddress + (ULONG)Sii.EntryPoint,
&ProcessInfo->ClientId,
&ProcessInfo->ThreadHandle);
NtClose(hSection);
if (!NT_SUCCESS(Status))
{
DPRINT("Failed to create thread\n");
NtClose(hSection);
return(Status);
}
NtClose(hSection);
return(STATUS_SUCCESS);
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: init.c,v 1.48 2004/10/24 20:37:26 weiden Exp $
/* $Id: init.c,v 1.49 2004/11/21 21:09:42 weiden Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ldr/init.c
@ -146,7 +146,7 @@ LdrpCreateProcessEnvironment(HANDLE ProcessHandle,
RtlCopyMemory(LocalPpb->ImagePathName.Buffer,
ImagePath->Buffer,
ImagePath->Length);
LocalPpb->ImagePathName.Buffer[ImagePath->Length / sizeof(WCHAR)] = (WCHAR)0;
LocalPpb->ImagePathName.Buffer[ImagePath->Length / sizeof(WCHAR)] = L'\0';
/* Denormalize the process parameter block */
DENORMALIZE(LocalPpb->ImagePathName.Buffer, LocalPpb);
@ -195,17 +195,6 @@ LdrpCreateProcessEnvironment(HANDLE ProcessHandle,
&RegionSize,
MEM_RELEASE);
/* Set image file name */
Status = NtSetInformationProcess(ProcessHandle,
ProcessImageFileName,
"SMSS",
5);
if (!NT_SUCCESS(Status))
{
DPRINT("NtSetInformationProcess() failed (Status %lx)\n", Status);
return(Status);
}
/* Read image base address. */
Offset = FIELD_OFFSET(PEB, ImageBaseAddress);
NtReadVirtualMemory(ProcessHandle,

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.155 2004/11/21 13:18:19 weiden Exp $
/* $Id: process.c,v 1.156 2004/11/21 21:09:43 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -849,6 +849,65 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
KEBUGCHECK(0);
}
if (SectionHandle != NULL)
{
PSECTION_OBJECT SectionObject;
UNICODE_STRING FileName;
PWCHAR szSrc;
PCHAR szDest;
USHORT lnFName = 0;
/*
* Determine the image file name and save it to the EPROCESS structure
*/
Status = ObReferenceObjectByHandle(SectionHandle,
0,
MmSectionObjectType,
UserMode,
(PVOID*)&SectionObject,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("Failed to reference section object\n", Status);
ObDereferenceObject(Process);
ObDereferenceObject(pParentProcess);
return(Status);
}
FileName = SectionObject->FileObject->FileName;
szSrc = (PWCHAR)(FileName.Buffer + FileName.Length - 1);
while(szSrc >= FileName.Buffer)
{
if(*szSrc == L'\\')
{
szSrc++;
break;
}
else
{
szSrc--;
lnFName++;
}
}
/* copy the image file name to the process and truncate it to 15 characters
if necessary */
szDest = Process->ImageFileName;
lnFName = min(lnFName, sizeof(Process->ImageFileName) - 1);
while(lnFName-- > 0)
{
*(szDest++) = (UCHAR)*(szSrc++);
}
*szDest = '\0';
ObDereferenceObject(SectionObject);
}
else
{
Process->ImageFileName[0] = '\0';
}
/*
* Map ntdll
*/
@ -867,7 +926,7 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
*/
if (SectionHandle != NULL)
{
DPRINT("Mapping process image\n");
DPRINT("Mapping process image\n");
Status = LdrpMapImage(*ProcessHandle,
SectionHandle,
&ImageBase);
@ -1255,6 +1314,34 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
}
break;
case ProcessImageFileName:
{
/*
* We DO NOT return the file name stored in the EPROCESS structure.
* Propably if we can't find a PEB or ProcessParameters structure for the
* process!
*/
PRTL_USER_PROCESS_PARAMETERS ProcParams;
ASSERT(Process->Peb);
ASSERT(Process->Peb->ProcessParameters);
ProcParams = Process->Peb->ProcessParameters;
if(ProcessInformationLength < sizeof(UNICODE_STRING) + ProcParams->ImagePathName.Length + sizeof(WCHAR))
{
Status = STATUS_INFO_LENGTH_MISMATCH;
}
else
{
PUNICODE_STRING DstPath = (PUNICODE_STRING)ProcessInformation;
DstPath->Length = ProcParams->ImagePathName.Length;
DstPath->MaximumLength = DstPath->Length + sizeof(WCHAR);
DstPath->Buffer = (PWSTR)(DstPath + 1);
RtlCopyMemory(DstPath->Buffer, ProcParams->ImagePathName.Buffer, ProcParams->ImagePathName.Length);
DstPath->Buffer[DstPath->Length / sizeof(WCHAR)] = L'\0';
}
break;
}
/*
* Note: The following 10 information classes are verified to not be
* implemented on NT, and do indeed return STATUS_INVALID_INFO_CLASS;
@ -1343,11 +1430,6 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
Status = PspAssignPrimaryToken(Process, *ProcessAccessTokenP);
break;
case ProcessImageFileName:
memcpy(Process->ImageFileName, ProcessInformation, 8);
Status = STATUS_SUCCESS;
break;
case ProcessLdtInformation:
case ProcessLdtSize:
case ProcessDefaultHardErrorMode: