mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
Use Unicode strings in key objects.
svn path=/trunk/; revision=4787
This commit is contained in:
parent
be3c31a2c2
commit
80344c77a6
4 changed files with 68 additions and 72 deletions
|
@ -302,11 +302,8 @@ typedef struct _KEY_OBJECT
|
||||||
/* Key flags */
|
/* Key flags */
|
||||||
ULONG Flags;
|
ULONG Flags;
|
||||||
|
|
||||||
/* Length of Name */
|
/* Key name */
|
||||||
USHORT NameSize;
|
UNICODE_STRING Name;
|
||||||
|
|
||||||
/* Name of key */
|
|
||||||
PCHAR Name;
|
|
||||||
|
|
||||||
/* Registry hive the key belongs to */
|
/* Registry hive the key belongs to */
|
||||||
PREGISTRY_HIVE RegistryHive;
|
PREGISTRY_HIVE RegistryHive;
|
||||||
|
|
|
@ -46,6 +46,7 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PVOID Object;
|
PVOID Object;
|
||||||
PWSTR End;
|
PWSTR End;
|
||||||
|
PWSTR Start;
|
||||||
|
|
||||||
DPRINT("NtCreateKey (Name %wZ KeyHandle %x Root %x)\n",
|
DPRINT("NtCreateKey (Name %wZ KeyHandle %x Root %x)\n",
|
||||||
ObjectAttributes->ObjectName,
|
ObjectAttributes->ObjectName,
|
||||||
|
@ -90,11 +91,11 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
||||||
|
|
||||||
/* If RemainingPath contains \ we must return error
|
/* If RemainingPath contains \ we must return error
|
||||||
because NtCreateKey don't create trees */
|
because NtCreateKey don't create trees */
|
||||||
if (RemainingPath.Buffer[0] == '\\')
|
Start = RemainingPath.Buffer;
|
||||||
End = wcschr(RemainingPath.Buffer + 1, '\\');
|
if (*Start == L'\\')
|
||||||
else
|
Start++;
|
||||||
End = wcschr(RemainingPath.Buffer, '\\');
|
|
||||||
|
|
||||||
|
End = wcschr(Start, L'\\');
|
||||||
if (End != NULL)
|
if (End != NULL)
|
||||||
{
|
{
|
||||||
ObDereferenceObject(Object);
|
ObDereferenceObject(Object);
|
||||||
|
@ -147,8 +148,8 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyObject->Name = KeyObject->KeyCell->Name;
|
RtlCreateUnicodeString(&KeyObject->Name,
|
||||||
KeyObject->NameSize = KeyObject->KeyCell->NameSize;
|
Start);
|
||||||
|
|
||||||
if (KeyObject->RegistryHive == KeyObject->ParentKey->RegistryHive)
|
if (KeyObject->RegistryHive == KeyObject->ParentKey->RegistryHive)
|
||||||
{
|
{
|
||||||
|
@ -383,7 +384,6 @@ NtEnumerateKey(
|
||||||
mbstowcs(BasicInformation->Name,
|
mbstowcs(BasicInformation->Name,
|
||||||
SubKeyCell->Name,
|
SubKeyCell->Name,
|
||||||
SubKeyCell->NameSize * 2);
|
SubKeyCell->NameSize * 2);
|
||||||
// BasicInformation->Name[SubKeyCell->NameSize] = 0;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -410,7 +410,6 @@ NtEnumerateKey(
|
||||||
mbstowcs(NodeInformation->Name,
|
mbstowcs(NodeInformation->Name,
|
||||||
SubKeyCell->Name,
|
SubKeyCell->Name,
|
||||||
SubKeyCell->NameSize * 2);
|
SubKeyCell->NameSize * 2);
|
||||||
// NodeInformation->Name[SubKeyCell->NameSize] = 0;
|
|
||||||
if (SubKeyCell->ClassSize != 0)
|
if (SubKeyCell->ClassSize != 0)
|
||||||
{
|
{
|
||||||
pClassData=CmiGetBlock(KeyObject->RegistryHive,
|
pClassData=CmiGetBlock(KeyObject->RegistryHive,
|
||||||
|
@ -845,7 +844,7 @@ NtQueryKey(IN HANDLE KeyHandle,
|
||||||
case KeyBasicInformation:
|
case KeyBasicInformation:
|
||||||
/* Check size of buffer */
|
/* Check size of buffer */
|
||||||
if (Length < sizeof(KEY_BASIC_INFORMATION) +
|
if (Length < sizeof(KEY_BASIC_INFORMATION) +
|
||||||
KeyObject->NameSize * sizeof(WCHAR))
|
KeyObject->Name.Length)
|
||||||
{
|
{
|
||||||
Status = STATUS_BUFFER_OVERFLOW;
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
@ -856,19 +855,19 @@ NtQueryKey(IN HANDLE KeyHandle,
|
||||||
BasicInformation->LastWriteTime.u.LowPart = KeyCell->LastWriteTime.dwLowDateTime;
|
BasicInformation->LastWriteTime.u.LowPart = KeyCell->LastWriteTime.dwLowDateTime;
|
||||||
BasicInformation->LastWriteTime.u.HighPart = KeyCell->LastWriteTime.dwHighDateTime;
|
BasicInformation->LastWriteTime.u.HighPart = KeyCell->LastWriteTime.dwHighDateTime;
|
||||||
BasicInformation->TitleIndex = 0;
|
BasicInformation->TitleIndex = 0;
|
||||||
BasicInformation->NameLength = (KeyObject->NameSize) * sizeof(WCHAR);
|
BasicInformation->NameLength = KeyObject->Name.Length;
|
||||||
mbstowcs(BasicInformation->Name,
|
RtlCopyMemory(BasicInformation->Name,
|
||||||
KeyObject->Name,
|
KeyObject->Name.Buffer,
|
||||||
KeyObject->NameSize*sizeof(WCHAR));
|
KeyObject->Name.Length);
|
||||||
*ResultLength = sizeof(KEY_BASIC_INFORMATION) +
|
*ResultLength = sizeof(KEY_BASIC_INFORMATION) +
|
||||||
KeyObject->NameSize * sizeof(WCHAR);
|
KeyObject->Name.Length;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyNodeInformation:
|
case KeyNodeInformation:
|
||||||
/* Check size of buffer */
|
/* Check size of buffer */
|
||||||
if (Length < sizeof(KEY_NODE_INFORMATION)
|
if (Length < sizeof(KEY_NODE_INFORMATION)
|
||||||
+ KeyObject->NameSize * sizeof(WCHAR)
|
+ KeyObject->Name.Length
|
||||||
+ KeyCell->ClassSize)
|
+ KeyCell->ClassSize)
|
||||||
{
|
{
|
||||||
Status = STATUS_BUFFER_OVERFLOW;
|
Status = STATUS_BUFFER_OVERFLOW;
|
||||||
|
@ -881,24 +880,24 @@ NtQueryKey(IN HANDLE KeyHandle,
|
||||||
NodeInformation->LastWriteTime.u.HighPart = KeyCell->LastWriteTime.dwHighDateTime;
|
NodeInformation->LastWriteTime.u.HighPart = KeyCell->LastWriteTime.dwHighDateTime;
|
||||||
NodeInformation->TitleIndex = 0;
|
NodeInformation->TitleIndex = 0;
|
||||||
NodeInformation->ClassOffset = sizeof(KEY_NODE_INFORMATION) +
|
NodeInformation->ClassOffset = sizeof(KEY_NODE_INFORMATION) +
|
||||||
KeyObject->NameSize * sizeof(WCHAR);
|
KeyObject->Name.Length;
|
||||||
NodeInformation->ClassLength = KeyCell->ClassSize;
|
NodeInformation->ClassLength = KeyCell->ClassSize;
|
||||||
NodeInformation->NameLength = KeyObject->NameSize * sizeof(WCHAR);
|
NodeInformation->NameLength = KeyObject->Name.Length;
|
||||||
mbstowcs(NodeInformation->Name,
|
RtlCopyMemory(NodeInformation->Name,
|
||||||
KeyObject->Name,
|
KeyObject->Name.Buffer,
|
||||||
KeyObject->NameSize * sizeof(WCHAR));
|
KeyObject->Name.Length);
|
||||||
|
|
||||||
if (KeyCell->ClassSize != 0)
|
if (KeyCell->ClassSize != 0)
|
||||||
{
|
{
|
||||||
pClassData = CmiGetBlock(KeyObject->RegistryHive,
|
pClassData = CmiGetBlock(KeyObject->RegistryHive,
|
||||||
KeyCell->ClassNameOffset,
|
KeyCell->ClassNameOffset,
|
||||||
NULL);
|
NULL);
|
||||||
wcsncpy(NodeInformation->Name + KeyObject->NameSize * sizeof(WCHAR),
|
wcsncpy(NodeInformation->Name + KeyObject->Name.Length,
|
||||||
(PWCHAR)pClassData->Data,
|
(PWCHAR)pClassData->Data,
|
||||||
KeyCell->ClassSize);
|
KeyCell->ClassSize);
|
||||||
}
|
}
|
||||||
*ResultLength = sizeof(KEY_NODE_INFORMATION)
|
*ResultLength = sizeof(KEY_NODE_INFORMATION)
|
||||||
+ KeyObject->NameSize * sizeof(WCHAR)
|
+ KeyObject->Name.Length
|
||||||
+ KeyCell->ClassSize;
|
+ KeyCell->ClassSize;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: registry.c,v 1.95 2003/05/13 21:28:26 chorns Exp $
|
/* $Id: registry.c,v 1.96 2003/05/28 12:04:17 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -311,9 +311,8 @@ CmInitializeRegistry(VOID)
|
||||||
RootKey->NumberOfSubKeys = 0;
|
RootKey->NumberOfSubKeys = 0;
|
||||||
RootKey->SubKeys = NULL;
|
RootKey->SubKeys = NULL;
|
||||||
RootKey->SizeOfSubKeys = 0;
|
RootKey->SizeOfSubKeys = 0;
|
||||||
RootKey->NameSize = strlen("Registry");
|
Status = RtlCreateUnicodeString(&RootKey->Name, L"Registry");
|
||||||
RootKey->Name = ExAllocatePool(PagedPool, RootKey->NameSize);
|
assert(NT_SUCCESS(Status));
|
||||||
RtlCopyMemory(RootKey->Name, "Registry", RootKey->NameSize);
|
|
||||||
|
|
||||||
KeInitializeSpinLock(&CmiKeyListLock);
|
KeInitializeSpinLock(&CmiKeyListLock);
|
||||||
|
|
||||||
|
@ -338,9 +337,8 @@ CmInitializeRegistry(VOID)
|
||||||
MachineKey->NumberOfSubKeys = 0;
|
MachineKey->NumberOfSubKeys = 0;
|
||||||
MachineKey->SubKeys = NULL;
|
MachineKey->SubKeys = NULL;
|
||||||
MachineKey->SizeOfSubKeys = MachineKey->KeyCell->NumberOfSubKeys;
|
MachineKey->SizeOfSubKeys = MachineKey->KeyCell->NumberOfSubKeys;
|
||||||
MachineKey->NameSize = strlen("Machine");
|
Status = RtlCreateUnicodeString(&MachineKey->Name, L"Machine");
|
||||||
MachineKey->Name = ExAllocatePool(PagedPool, MachineKey->NameSize);
|
assert(NT_SUCCESS(Status));
|
||||||
RtlCopyMemory(MachineKey->Name, "Machine", MachineKey->NameSize);
|
|
||||||
CmiAddKeyToList(RootKey, MachineKey);
|
CmiAddKeyToList(RootKey, MachineKey);
|
||||||
|
|
||||||
/* Create '\Registry\User' key. */
|
/* Create '\Registry\User' key. */
|
||||||
|
@ -364,9 +362,8 @@ CmInitializeRegistry(VOID)
|
||||||
UserKey->NumberOfSubKeys = 0;
|
UserKey->NumberOfSubKeys = 0;
|
||||||
UserKey->SubKeys = NULL;
|
UserKey->SubKeys = NULL;
|
||||||
UserKey->SizeOfSubKeys = UserKey->KeyCell->NumberOfSubKeys;
|
UserKey->SizeOfSubKeys = UserKey->KeyCell->NumberOfSubKeys;
|
||||||
UserKey->NameSize = strlen("User");
|
Status = RtlCreateUnicodeString(&UserKey->Name, L"User");
|
||||||
UserKey->Name = ExAllocatePool(PagedPool, UserKey->NameSize);
|
assert(NT_SUCCESS(Status));
|
||||||
RtlCopyMemory(UserKey->Name, "User", UserKey->NameSize);
|
|
||||||
CmiAddKeyToList(RootKey, UserKey);
|
CmiAddKeyToList(RootKey, UserKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,24 +595,18 @@ CmiConnectHive(PREGISTRY_HIVE RegistryHive,
|
||||||
return(STATUS_INSUFFICIENT_RESOURCES);
|
return(STATUS_INSUFFICIENT_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
NewKey->SizeOfSubKeys = NewKey->KeyCell->NumberOfSubKeys;
|
Status = RtlCreateUnicodeString(&NewKey->Name,
|
||||||
NewKey->NameSize = wcslen (SubName);
|
SubName);
|
||||||
NewKey->Name = ExAllocatePool(PagedPool, NewKey->NameSize);
|
if (!NT_SUCCESS(Status))
|
||||||
|
|
||||||
if ((NewKey->Name == NULL) && (NewKey->NameSize != 0))
|
|
||||||
{
|
{
|
||||||
DPRINT("NewKey->NameSize %d\n", NewKey->NameSize);
|
DPRINT1("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
|
||||||
if (NewKey->SubKeys != NULL)
|
if (NewKey->SubKeys != NULL)
|
||||||
ExFreePool(NewKey->SubKeys);
|
ExFreePool(NewKey->SubKeys);
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
ObDereferenceObject (ParentKey);
|
ObDereferenceObject (ParentKey);
|
||||||
return(STATUS_INSUFFICIENT_RESOURCES);
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcstombs (NewKey->Name,
|
|
||||||
SubName,
|
|
||||||
NewKey->NameSize);
|
|
||||||
|
|
||||||
CmiAddKeyToList (ParentKey, NewKey);
|
CmiAddKeyToList (ParentKey, NewKey);
|
||||||
ObDereferenceObject (ParentKey);
|
ObDereferenceObject (ParentKey);
|
||||||
|
|
||||||
|
|
|
@ -146,8 +146,13 @@ CmiObjectParse(PVOID ParsedObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
FoundObject->Flags = 0;
|
FoundObject->Flags = 0;
|
||||||
FoundObject->Name = SubKeyCell->Name;
|
|
||||||
FoundObject->NameSize = SubKeyCell->NameSize;
|
FoundObject->Name.Length = Length * sizeof(WCHAR);
|
||||||
|
FoundObject->Name.MaximumLength = FoundObject->Name.Length + sizeof(WCHAR);
|
||||||
|
FoundObject->Name.Buffer = ExAllocatePool(NonPagedPool, FoundObject->Name.MaximumLength);
|
||||||
|
RtlCopyMemory(FoundObject->Name.Buffer, StartPtr, FoundObject->Name.Length);
|
||||||
|
FoundObject->Name.Buffer[FoundObject->Name.Length / sizeof(WCHAR)] = 0;
|
||||||
|
|
||||||
FoundObject->KeyCell = SubKeyCell;
|
FoundObject->KeyCell = SubKeyCell;
|
||||||
FoundObject->BlockOffset = BlockOffset;
|
FoundObject->BlockOffset = BlockOffset;
|
||||||
FoundObject->RegistryHive = ParsedKey->RegistryHive;
|
FoundObject->RegistryHive = ParsedKey->RegistryHive;
|
||||||
|
@ -224,25 +229,22 @@ CmiObjectCreate(PVOID ObjectBody,
|
||||||
PWSTR RemainingPath,
|
PWSTR RemainingPath,
|
||||||
POBJECT_ATTRIBUTES ObjectAttributes)
|
POBJECT_ATTRIBUTES ObjectAttributes)
|
||||||
{
|
{
|
||||||
PKEY_OBJECT pKey = ObjectBody;
|
PKEY_OBJECT KeyObject = ObjectBody;
|
||||||
|
PWSTR Start;
|
||||||
|
|
||||||
pKey->ParentKey = Parent;
|
KeyObject->ParentKey = Parent;
|
||||||
if (RemainingPath)
|
if (RemainingPath)
|
||||||
{
|
{
|
||||||
if(RemainingPath[0]== L'\\')
|
Start = RemainingPath;
|
||||||
{
|
if(*Start == L'\\')
|
||||||
pKey->Name = (PCHAR)(&RemainingPath[1]);
|
Start++;
|
||||||
pKey->NameSize = wcslen(RemainingPath) - 1;
|
RtlCreateUnicodeString(&KeyObject->Name,
|
||||||
}
|
Start);
|
||||||
else
|
|
||||||
{
|
|
||||||
pKey->Name = (PCHAR)RemainingPath;
|
|
||||||
pKey->NameSize = wcslen(RemainingPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pKey->NameSize = 0;
|
RtlInitUnicodeString(&KeyObject->Name,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
@ -263,6 +265,8 @@ CmiObjectDelete(PVOID DeletedObject)
|
||||||
DPRINT1("Key not found in parent list ???\n");
|
DPRINT1("Key not found in parent list ???\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlFreeUnicodeString(&KeyObject->Name);
|
||||||
|
|
||||||
if (KeyObject->Flags & KO_MARKED_FOR_DELETE)
|
if (KeyObject->Flags & KO_MARKED_FOR_DELETE)
|
||||||
{
|
{
|
||||||
DPRINT("delete really key\n");
|
DPRINT("delete really key\n");
|
||||||
|
@ -376,13 +380,15 @@ CmiScanKeyList(PKEY_OBJECT Parent,
|
||||||
{
|
{
|
||||||
PKEY_OBJECT CurKey;
|
PKEY_OBJECT CurKey;
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
WORD NameSize;
|
ULONG Index;
|
||||||
DWORD Index;
|
UNICODE_STRING UName;
|
||||||
|
|
||||||
DPRINT("Scanning key list for: %s (Parent: %s)\n",
|
DPRINT("Scanning key list for: %s (Parent: %wZ)\n",
|
||||||
KeyName, Parent->Name);
|
KeyName, &Parent->Name);
|
||||||
|
|
||||||
|
RtlCreateUnicodeStringFromAsciiz(&UName,
|
||||||
|
KeyName);
|
||||||
|
|
||||||
NameSize = strlen(KeyName);
|
|
||||||
KeAcquireSpinLock(&CmiKeyListLock, &OldIrql);
|
KeAcquireSpinLock(&CmiKeyListLock, &OldIrql);
|
||||||
/* FIXME: if list maintained in alphabetic order, use dichotomic search */
|
/* FIXME: if list maintained in alphabetic order, use dichotomic search */
|
||||||
for (Index=0; Index < Parent->NumberOfSubKeys; Index++)
|
for (Index=0; Index < Parent->NumberOfSubKeys; Index++)
|
||||||
|
@ -390,24 +396,27 @@ CmiScanKeyList(PKEY_OBJECT Parent,
|
||||||
CurKey = Parent->SubKeys[Index];
|
CurKey = Parent->SubKeys[Index];
|
||||||
if (Attributes & OBJ_CASE_INSENSITIVE)
|
if (Attributes & OBJ_CASE_INSENSITIVE)
|
||||||
{
|
{
|
||||||
if ((NameSize == CurKey->NameSize)
|
if ((UName.Length == CurKey->Name.Length)
|
||||||
&& (_strnicmp(KeyName, CurKey->Name, NameSize) == 0))
|
&& (_wcsicmp(UName.Buffer, CurKey->Name.Buffer) == 0))
|
||||||
{
|
{
|
||||||
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
||||||
|
RtlFreeUnicodeString(&UName);
|
||||||
return CurKey;
|
return CurKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((NameSize == CurKey->NameSize)
|
if ((UName.Length == CurKey->Name.Length)
|
||||||
&& (strncmp(KeyName,CurKey->Name,NameSize) == 0))
|
&& (wcscmp(UName.Buffer, CurKey->Name.Buffer) == 0))
|
||||||
{
|
{
|
||||||
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
||||||
|
RtlFreeUnicodeString(&UName);
|
||||||
return CurKey;
|
return CurKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
||||||
|
RtlFreeUnicodeString(&UName);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue