Fixed a severe bug in RtlQueryRegistryValues() and implemented support for REG_EXPAND_SZ.

Read the system environment from the registry.

svn path=/trunk/; revision=2977
This commit is contained in:
Eric Kohl 2002-05-24 18:08:39 +00:00
parent dffbf01285
commit 6ff87bd4f1
4 changed files with 165 additions and 146 deletions

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.11 2002/04/29 23:19:53 ekohl Exp $
/* $Id: registry.c,v 1.12 2002/05/24 18:07:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -21,6 +21,7 @@
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#include <ntdll/registry.h>
#include <ntos/minmax.h>
@ -167,6 +168,9 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
ULONG Index;
ULONG StringLen;
PWSTR StringPtr;
PWSTR ExpandBuffer;
UNICODE_STRING EnvValue;
UNICODE_STRING EnvExpandedValue;
DPRINT("RtlQueryRegistryValues() called\n");
@ -385,8 +389,40 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
else if ((ValueInfo->Type == REG_EXPAND_SZ) &&
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{
DPRINT1("FIXME: expand REG_EXPAND_SZ\n");
DPRINT("Expand REG_EXPAND_SZ type\n");
ExpandBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
ValueInfo->DataLength * 2);
if (ExpandBuffer == NULL)
{
Status = STATUS_NO_MEMORY;
break;
}
RtlInitUnicodeString(&EnvValue,
(PWSTR)ValueInfo->Data);
EnvExpandedValue.Length = 0;
EnvExpandedValue.MaximumLength = ValueInfo->DataLength * 2 * sizeof(WCHAR);
EnvExpandedValue.Buffer = ExpandBuffer;
*ExpandBuffer = 0;
RtlExpandEnvironmentStrings_U(Environment,
&EnvValue,
&EnvExpandedValue,
&StringLen);
StringLen = (wcslen(ExpandBuffer) + 1) * sizeof(WCHAR);
Status = QueryEntry->QueryRoutine(FullValueInfo->Name,
REG_SZ,
(PVOID)ExpandBuffer,
StringLen,
Context,
QueryEntry->EntryContext);
RtlFreeHeap(RtlGetProcessHeap(),
0,
ExpandBuffer);
}
else
{
@ -430,7 +466,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
FullValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
0,
BufferSize);
if (ValueInfo == NULL)
if (FullValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
@ -460,11 +496,12 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
break;
}
if ((ValueInfo->Type == REG_MULTI_SZ) &&
DPRINT("FullValueInfo->Type: %lu\n", FullValueInfo->Type);
if ((FullValueInfo->Type == REG_MULTI_SZ) &&
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{
DPRINT("Expand REG_MULTI_SZ type\n");
StringPtr = (PWSTR)ValueInfo->Data;
StringPtr = (PWSTR)((PVOID)FullValueInfo + FullValueInfo->DataOffset);
while (*StringPtr != 0)
{
StringLen = (wcslen(StringPtr) + 1) * sizeof(WCHAR);
@ -479,11 +516,44 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
StringPtr = (PWSTR)((PUCHAR)StringPtr + StringLen);
}
}
else if ((ValueInfo->Type == REG_EXPAND_SZ) &&
else if ((FullValueInfo->Type == REG_EXPAND_SZ) &&
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{
DPRINT1("FIXME: expand REG_EXPAND_SZ\n");
DPRINT("Expand REG_EXPAND_SZ type\n");
StringPtr = (PWSTR)((PVOID)FullValueInfo + FullValueInfo->DataOffset);
ExpandBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
FullValueInfo->DataLength * 2);
if (ExpandBuffer == NULL)
{
Status = STATUS_NO_MEMORY;
break;
}
RtlInitUnicodeString(&EnvValue,
StringPtr);
EnvExpandedValue.Length = 0;
EnvExpandedValue.MaximumLength = FullValueInfo->DataLength * 2 * sizeof(WCHAR);
EnvExpandedValue.Buffer = ExpandBuffer;
*ExpandBuffer = 0;
RtlExpandEnvironmentStrings_U(Environment,
&EnvValue,
&EnvExpandedValue,
&StringLen);
StringLen = (wcslen(ExpandBuffer) + 1) * sizeof(WCHAR);
Status = QueryEntry->QueryRoutine(FullValueInfo->Name,
REG_SZ,
(PVOID)ExpandBuffer,
StringLen,
Context,
QueryEntry->EntryContext);
RtlFreeHeap(RtlGetProcessHeap(),
0,
ExpandBuffer);
}
else
{
@ -505,7 +575,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
RtlFreeHeap(RtlGetProcessHeap(),
0,
ValueInfo);
FullValueInfo);
if (!NT_SUCCESS(Status))
break;

View file

@ -363,12 +363,6 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
StringPtr = (PWSTR)((PUCHAR)StringPtr + StringLen);
}
}
else if ((ValueInfo->Type == REG_EXPAND_SZ) &&
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{
DPRINT1("FIXME: expand REG_EXPAND_SZ\n");
}
else
{
Status = QueryEntry->QueryRoutine(QueryEntry->Name,
@ -409,7 +403,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
BufferSize = sizeof(KEY_VALUE_FULL_INFORMATION) + 4096;
FullValueInfo = ExAllocatePool(PagedPool,
BufferSize);
if (ValueInfo == NULL)
if (FullValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
@ -439,11 +433,11 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
break;
}
if ((ValueInfo->Type == REG_MULTI_SZ) &&
if ((FullValueInfo->Type == REG_MULTI_SZ) &&
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{
DPRINT("Expand REG_MULTI_SZ type\n");
StringPtr = (PWSTR)ValueInfo->Data;
StringPtr = (PWSTR)((PVOID)FullValueInfo + FullValueInfo->DataOffset);
while (*StringPtr != 0)
{
StringLen = (wcslen(StringPtr) + 1) * sizeof(WCHAR);
@ -458,12 +452,6 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
StringPtr = (PWSTR)((PUCHAR)StringPtr + StringLen);
}
}
else if ((ValueInfo->Type == REG_EXPAND_SZ) &&
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{
DPRINT1("FIXME: expand REG_EXPAND_SZ\n");
}
else
{
Status = QueryEntry->QueryRoutine(FullValueInfo->Name,
@ -482,7 +470,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
Index++;
}
ExFreePool(ValueInfo);
ExFreePool(FullValueInfo);
if (!NT_SUCCESS(Status))
break;

View file

@ -1,4 +1,4 @@
/* $Id: init.c,v 1.35 2002/05/24 07:49:41 ekohl Exp $
/* $Id: init.c,v 1.36 2002/05/24 18:07:56 ekohl Exp $
*
* init.c - Session Manager initialization
*
@ -441,7 +441,6 @@ SmCreatePagingFiles(VOID)
}
#if 0
static NTSTATUS STDCALL
SmEnvironmentQueryRoutine(PWSTR ValueName,
ULONG ValueType,
@ -450,68 +449,54 @@ SmEnvironmentQueryRoutine(PWSTR ValueName,
PVOID Context,
PVOID EntryContext)
{
// NTSTATUS Status;
UNICODE_STRING EnvVariable;
UNICODE_STRING EnvValue;
//#ifndef NDEBUG
#ifndef NDEBUG
PrintString("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
PrintString("ValueData '%S'\n", (PWSTR)ValueData);
//#endif
#endif
if (ValueType != REG_SZ)
{
return(STATUS_SUCCESS);
}
RtlInitUnicodeString(&EnvVariable,
ValueName);
RtlInitUnicodeString(&EnvValue,
(PWSTR)ValueData);
RtlSetEnvironmentVariable(Context,
&EnvVariable,
&EnvValue);
// return(Status);
return(STATUS_SUCCESS);
}
#endif
static NTSTATUS
SmSetEnvironmentVariables(VOID)
{
#if 0
RTL_QUERY_REGISTRY_TABLE QueryTable[2];
NTSTATUS Status;
RtlZeroMemory(&QueryTable,
sizeof(QueryTable));
QueryTable[0].QueryRoutine = SmEnvironmentQueryRoutine;
Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
L"\\Session Manager\\Environment",
QueryTable,
NULL,
NULL);
PrintString("*** System stopped ***\n");
for(;;);
return(Status);
#endif
//#if 0
UNICODE_STRING EnvVariable;
UNICODE_STRING EnvValue;
UNICODE_STRING EnvExpandedValue;
ULONG ExpandedLength;
WCHAR ExpandBuffer[512];
WCHAR ValueBuffer[MAX_PATH];
NTSTATUS Status;
/*
* The following environment variables are read from the registry.
* Because the registry does not work yet, the environment variables
* are set one by one, using information from the shared user page.
* The following environment variables must be set prior to reading
* other variables from the registry.
*
* Variables (example):
* SystemRoot = C:\reactos
* SystemDrive = C:
*
* OS = ReactOS
* Path = %SystemRoot%\system32;%SystemRoot%
* windir = %SystemRoot%
* SystemRoot = "C:\reactos"
* SystemDrive = "C:"
*/
/* copy system root into value buffer */
wcscpy (ValueBuffer, SharedUserData->NtSystemRoot);
/* Copy system root into value buffer */
wcscpy(ValueBuffer,
SharedUserData->NtSystemRoot);
/* set "SystemRoot = C:\reactos" */
/* Cet SystemRoot = "C:\reactos" */
RtlInitUnicodeString(&EnvVariable,
L"SystemRoot");
RtlInitUnicodeString(&EnvValue,
@ -520,10 +505,10 @@ SmSetEnvironmentVariables(VOID)
&EnvVariable,
&EnvValue);
/* cut off trailing path */
/* Cut off trailing path */
ValueBuffer[2] = 0;
/* Set "SystemDrive = C:" */
/* Set SystemDrive = "C:" */
RtlInitUnicodeString(&EnvVariable,
L"SystemDrive");
RtlInitUnicodeString(&EnvValue,
@ -532,53 +517,19 @@ SmSetEnvironmentVariables(VOID)
&EnvVariable,
&EnvValue);
/* Read system environment from the registry. */
RtlZeroMemory(&QueryTable,
sizeof(QueryTable));
/* Set "OS = ReactOS" */
RtlInitUnicodeString (&EnvVariable,
L"OS");
RtlInitUnicodeString (&EnvValue,
L"ReactOS");
RtlSetEnvironmentVariable (&SmSystemEnvironment,
&EnvVariable,
&EnvValue);
QueryTable[0].QueryRoutine = SmEnvironmentQueryRoutine;
Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
L"\\Session Manager\\Environment",
QueryTable,
&SmSystemEnvironment,
SmSystemEnvironment);
/* Set "Path = %SystemRoot%\system32;%SystemRoot%" */
RtlInitUnicodeString (&EnvVariable,
L"Path");
RtlInitUnicodeString (&EnvValue,
L"%SystemRoot%\\system32;%SystemRoot%");
EnvExpandedValue.Length = 0;
EnvExpandedValue.MaximumLength = 512 * sizeof(WCHAR);
EnvExpandedValue.Buffer = ExpandBuffer;
*ExpandBuffer = 0;
RtlExpandEnvironmentStrings_U (SmSystemEnvironment,
&EnvValue,
&EnvExpandedValue,
&ExpandedLength);
RtlSetEnvironmentVariable (&SmSystemEnvironment,
&EnvVariable,
&EnvExpandedValue);
/* Set "windir = %SystemRoot%" */
RtlInitUnicodeString (&EnvVariable,
L"windir");
RtlInitUnicodeString (&EnvValue,
L"%SystemRoot%");
EnvExpandedValue.Length = 0;
EnvExpandedValue.MaximumLength = 512 * sizeof(WCHAR);
EnvExpandedValue.Buffer = ExpandBuffer;
*ExpandBuffer = 0;
RtlExpandEnvironmentStrings_U (SmSystemEnvironment,
&EnvValue,
&EnvExpandedValue,
&ExpandedLength);
RtlSetEnvironmentVariable (&SmSystemEnvironment,
&EnvVariable,
&EnvExpandedValue);
return(STATUS_SUCCESS);
//#endif
return(Status);
}

View file

@ -53,6 +53,10 @@ REGEDIT4
"UNC"="\Device\Mup"
[\Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"ComSpec"=expand:"%SystemRoot%\system32\shell.exe"
"OS"=expand:"ReactOS"
"Path"=expand:"%SystemRoot%\system32;%SystemRoot%"
"windir"=expand:"%SystemRoot%"
[\Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]
"PagingFiles"=multi:"C:\reactos\pagefile.sys"
@ -60,85 +64,91 @@ REGEDIT4
[\Registry\Machine\SYSTEM\CurrentControlSet\Services]
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Atapi]
"ImagePath"="system32\drivers\atapi.sys"
"Group"="SCSI Miniport"
"ImagePath"="system32\drivers\atapi.sys"
"Start"=dword:00000000
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Beep]
"ImagePath"="system32\drivers\beep.sys"
"Group"="Base"
"ImagePath"="system32\drivers\beep.sys"
"Start"=dword:00000001
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Cdfs]
"ImagePath"="system32\drivers\cdfs.sys"
"Group"="File System"
"ImagePath"="system32\drivers\cdfs.sys"
"Start"=dword:00000004
"Type"=dword:00000002
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Cdrom]
"ImagePath"="system32\drivers\cdrom.sys"
"Group"="SCSI Class"
"ImagePath"="system32\drivers\cdrom.sys"
"Start"=dword:00000000
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Class2]
"ImagePath"="system32\drivers\class2.sys"
"Group"="SCSI Class Helper"
"ImagePath"="system32\drivers\class2.sys"
"Start"=dword:00000000
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Disk]
"ImagePath"="system32\drivers\disk.sys"
"Group"="SCSI Class"
"ImagePath"="system32\drivers\disk.sys"
"Start"=dword:00000000
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\EventLog]
"Group"="Error log"
"ImagePath"="%SystemRoot%\system32\services.exe"
"Start"=dword:00000004
"Type"=dword:00000020
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Floppy]
"ImagePath"="system32\drivers\floppy.sys"
"Group"="Primary Disk"
"ImagePath"="system32\drivers\floppy.sys"
"Start"=dword:00000001
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Fs_Rec]
"ImagePath"="system32\drivers\fs_rec.sys"
"Group"="Boot file system"
"ImagePath"="system32\drivers\fs_rec.sys"
"Start"=dword:00000000
"Type"=dword:00000008
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Ide]
"ImagePath"="system32\drivers\ide.sys"
"Group"="Primary Disk"
"ImagePath"="system32\drivers\ide.sys"
"Start"=dword:00000004
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Msfs]
"ImagePath"="system32\drivers\msfs.sys"
"Group"="File System"
"ImagePath"="system32\drivers\msfs.sys"
"Start"=dword:00000001
"Type"=dword:00000002
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Npfs]
"ImagePath"="system32\drivers\npfs.sys"
"Group"="File System"
"ImagePath"="system32\drivers\npfs.sys"
"Start"=dword:00000001
"Type"=dword:00000002
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Null]
"ImagePath"="system32\drivers\null.sys"
"Group"="Base"
"ImagePath"="system32\drivers\null.sys"
"Start"=dword:00000001
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Scsiport]
"ImagePath"="system32\drivers\scsiport.sys"
"Group"="SCSI Port"
"ImagePath"="system32\drivers\scsiport.sys"
"Start"=dword:00000000
"Type"=dword:00000001
[\Registry\Machine\SYSTEM\CurrentControlSet\Services\Vfatfs]
"ImagePath"="system32\drivers\vfatfs.sys"
"Group"="Boot File System"
"ImagePath"="system32\drivers\vfatfs.sys"
"Start"=dword:00000000
"Type"=dword:00000002