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 */
|
||||
ULONG Flags;
|
||||
|
||||
/* Length of Name */
|
||||
USHORT NameSize;
|
||||
|
||||
/* Name of key */
|
||||
PCHAR Name;
|
||||
/* Key name */
|
||||
UNICODE_STRING Name;
|
||||
|
||||
/* Registry hive the key belongs to */
|
||||
PREGISTRY_HIVE RegistryHive;
|
||||
|
|
|
@ -46,6 +46,7 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
|||
NTSTATUS Status;
|
||||
PVOID Object;
|
||||
PWSTR End;
|
||||
PWSTR Start;
|
||||
|
||||
DPRINT("NtCreateKey (Name %wZ KeyHandle %x Root %x)\n",
|
||||
ObjectAttributes->ObjectName,
|
||||
|
@ -90,11 +91,11 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
|||
|
||||
/* If RemainingPath contains \ we must return error
|
||||
because NtCreateKey don't create trees */
|
||||
if (RemainingPath.Buffer[0] == '\\')
|
||||
End = wcschr(RemainingPath.Buffer + 1, '\\');
|
||||
else
|
||||
End = wcschr(RemainingPath.Buffer, '\\');
|
||||
Start = RemainingPath.Buffer;
|
||||
if (*Start == L'\\')
|
||||
Start++;
|
||||
|
||||
End = wcschr(Start, L'\\');
|
||||
if (End != NULL)
|
||||
{
|
||||
ObDereferenceObject(Object);
|
||||
|
@ -147,8 +148,8 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
|||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
KeyObject->Name = KeyObject->KeyCell->Name;
|
||||
KeyObject->NameSize = KeyObject->KeyCell->NameSize;
|
||||
RtlCreateUnicodeString(&KeyObject->Name,
|
||||
Start);
|
||||
|
||||
if (KeyObject->RegistryHive == KeyObject->ParentKey->RegistryHive)
|
||||
{
|
||||
|
@ -383,7 +384,6 @@ NtEnumerateKey(
|
|||
mbstowcs(BasicInformation->Name,
|
||||
SubKeyCell->Name,
|
||||
SubKeyCell->NameSize * 2);
|
||||
// BasicInformation->Name[SubKeyCell->NameSize] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -410,7 +410,6 @@ NtEnumerateKey(
|
|||
mbstowcs(NodeInformation->Name,
|
||||
SubKeyCell->Name,
|
||||
SubKeyCell->NameSize * 2);
|
||||
// NodeInformation->Name[SubKeyCell->NameSize] = 0;
|
||||
if (SubKeyCell->ClassSize != 0)
|
||||
{
|
||||
pClassData=CmiGetBlock(KeyObject->RegistryHive,
|
||||
|
@ -845,7 +844,7 @@ NtQueryKey(IN HANDLE KeyHandle,
|
|||
case KeyBasicInformation:
|
||||
/* Check size of buffer */
|
||||
if (Length < sizeof(KEY_BASIC_INFORMATION) +
|
||||
KeyObject->NameSize * sizeof(WCHAR))
|
||||
KeyObject->Name.Length)
|
||||
{
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
@ -856,19 +855,19 @@ NtQueryKey(IN HANDLE KeyHandle,
|
|||
BasicInformation->LastWriteTime.u.LowPart = KeyCell->LastWriteTime.dwLowDateTime;
|
||||
BasicInformation->LastWriteTime.u.HighPart = KeyCell->LastWriteTime.dwHighDateTime;
|
||||
BasicInformation->TitleIndex = 0;
|
||||
BasicInformation->NameLength = (KeyObject->NameSize) * sizeof(WCHAR);
|
||||
mbstowcs(BasicInformation->Name,
|
||||
KeyObject->Name,
|
||||
KeyObject->NameSize*sizeof(WCHAR));
|
||||
BasicInformation->NameLength = KeyObject->Name.Length;
|
||||
RtlCopyMemory(BasicInformation->Name,
|
||||
KeyObject->Name.Buffer,
|
||||
KeyObject->Name.Length);
|
||||
*ResultLength = sizeof(KEY_BASIC_INFORMATION) +
|
||||
KeyObject->NameSize * sizeof(WCHAR);
|
||||
KeyObject->Name.Length;
|
||||
}
|
||||
break;
|
||||
|
||||
case KeyNodeInformation:
|
||||
/* Check size of buffer */
|
||||
if (Length < sizeof(KEY_NODE_INFORMATION)
|
||||
+ KeyObject->NameSize * sizeof(WCHAR)
|
||||
+ KeyObject->Name.Length
|
||||
+ KeyCell->ClassSize)
|
||||
{
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
|
@ -881,24 +880,24 @@ NtQueryKey(IN HANDLE KeyHandle,
|
|||
NodeInformation->LastWriteTime.u.HighPart = KeyCell->LastWriteTime.dwHighDateTime;
|
||||
NodeInformation->TitleIndex = 0;
|
||||
NodeInformation->ClassOffset = sizeof(KEY_NODE_INFORMATION) +
|
||||
KeyObject->NameSize * sizeof(WCHAR);
|
||||
KeyObject->Name.Length;
|
||||
NodeInformation->ClassLength = KeyCell->ClassSize;
|
||||
NodeInformation->NameLength = KeyObject->NameSize * sizeof(WCHAR);
|
||||
mbstowcs(NodeInformation->Name,
|
||||
KeyObject->Name,
|
||||
KeyObject->NameSize * sizeof(WCHAR));
|
||||
NodeInformation->NameLength = KeyObject->Name.Length;
|
||||
RtlCopyMemory(NodeInformation->Name,
|
||||
KeyObject->Name.Buffer,
|
||||
KeyObject->Name.Length);
|
||||
|
||||
if (KeyCell->ClassSize != 0)
|
||||
{
|
||||
pClassData = CmiGetBlock(KeyObject->RegistryHive,
|
||||
KeyCell->ClassNameOffset,
|
||||
NULL);
|
||||
wcsncpy(NodeInformation->Name + KeyObject->NameSize * sizeof(WCHAR),
|
||||
wcsncpy(NodeInformation->Name + KeyObject->Name.Length,
|
||||
(PWCHAR)pClassData->Data,
|
||||
KeyCell->ClassSize);
|
||||
}
|
||||
*ResultLength = sizeof(KEY_NODE_INFORMATION)
|
||||
+ KeyObject->NameSize * sizeof(WCHAR)
|
||||
+ KeyObject->Name.Length
|
||||
+ KeyCell->ClassSize;
|
||||
}
|
||||
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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -311,9 +311,8 @@ CmInitializeRegistry(VOID)
|
|||
RootKey->NumberOfSubKeys = 0;
|
||||
RootKey->SubKeys = NULL;
|
||||
RootKey->SizeOfSubKeys = 0;
|
||||
RootKey->NameSize = strlen("Registry");
|
||||
RootKey->Name = ExAllocatePool(PagedPool, RootKey->NameSize);
|
||||
RtlCopyMemory(RootKey->Name, "Registry", RootKey->NameSize);
|
||||
Status = RtlCreateUnicodeString(&RootKey->Name, L"Registry");
|
||||
assert(NT_SUCCESS(Status));
|
||||
|
||||
KeInitializeSpinLock(&CmiKeyListLock);
|
||||
|
||||
|
@ -338,9 +337,8 @@ CmInitializeRegistry(VOID)
|
|||
MachineKey->NumberOfSubKeys = 0;
|
||||
MachineKey->SubKeys = NULL;
|
||||
MachineKey->SizeOfSubKeys = MachineKey->KeyCell->NumberOfSubKeys;
|
||||
MachineKey->NameSize = strlen("Machine");
|
||||
MachineKey->Name = ExAllocatePool(PagedPool, MachineKey->NameSize);
|
||||
RtlCopyMemory(MachineKey->Name, "Machine", MachineKey->NameSize);
|
||||
Status = RtlCreateUnicodeString(&MachineKey->Name, L"Machine");
|
||||
assert(NT_SUCCESS(Status));
|
||||
CmiAddKeyToList(RootKey, MachineKey);
|
||||
|
||||
/* Create '\Registry\User' key. */
|
||||
|
@ -364,9 +362,8 @@ CmInitializeRegistry(VOID)
|
|||
UserKey->NumberOfSubKeys = 0;
|
||||
UserKey->SubKeys = NULL;
|
||||
UserKey->SizeOfSubKeys = UserKey->KeyCell->NumberOfSubKeys;
|
||||
UserKey->NameSize = strlen("User");
|
||||
UserKey->Name = ExAllocatePool(PagedPool, UserKey->NameSize);
|
||||
RtlCopyMemory(UserKey->Name, "User", UserKey->NameSize);
|
||||
Status = RtlCreateUnicodeString(&UserKey->Name, L"User");
|
||||
assert(NT_SUCCESS(Status));
|
||||
CmiAddKeyToList(RootKey, UserKey);
|
||||
}
|
||||
|
||||
|
@ -598,24 +595,18 @@ CmiConnectHive(PREGISTRY_HIVE RegistryHive,
|
|||
return(STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
NewKey->SizeOfSubKeys = NewKey->KeyCell->NumberOfSubKeys;
|
||||
NewKey->NameSize = wcslen (SubName);
|
||||
NewKey->Name = ExAllocatePool(PagedPool, NewKey->NameSize);
|
||||
|
||||
if ((NewKey->Name == NULL) && (NewKey->NameSize != 0))
|
||||
Status = RtlCreateUnicodeString(&NewKey->Name,
|
||||
SubName);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("NewKey->NameSize %d\n", NewKey->NameSize);
|
||||
DPRINT1("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
|
||||
if (NewKey->SubKeys != NULL)
|
||||
ExFreePool(NewKey->SubKeys);
|
||||
NtClose(KeyHandle);
|
||||
ObDereferenceObject (ParentKey);
|
||||
return(STATUS_INSUFFICIENT_RESOURCES);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
wcstombs (NewKey->Name,
|
||||
SubName,
|
||||
NewKey->NameSize);
|
||||
|
||||
CmiAddKeyToList (ParentKey, NewKey);
|
||||
ObDereferenceObject (ParentKey);
|
||||
|
||||
|
|
|
@ -146,8 +146,13 @@ CmiObjectParse(PVOID ParsedObject,
|
|||
}
|
||||
|
||||
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->BlockOffset = BlockOffset;
|
||||
FoundObject->RegistryHive = ParsedKey->RegistryHive;
|
||||
|
@ -224,25 +229,22 @@ CmiObjectCreate(PVOID ObjectBody,
|
|||
PWSTR RemainingPath,
|
||||
POBJECT_ATTRIBUTES ObjectAttributes)
|
||||
{
|
||||
PKEY_OBJECT pKey = ObjectBody;
|
||||
PKEY_OBJECT KeyObject = ObjectBody;
|
||||
PWSTR Start;
|
||||
|
||||
pKey->ParentKey = Parent;
|
||||
KeyObject->ParentKey = Parent;
|
||||
if (RemainingPath)
|
||||
{
|
||||
if(RemainingPath[0]== L'\\')
|
||||
{
|
||||
pKey->Name = (PCHAR)(&RemainingPath[1]);
|
||||
pKey->NameSize = wcslen(RemainingPath) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pKey->Name = (PCHAR)RemainingPath;
|
||||
pKey->NameSize = wcslen(RemainingPath);
|
||||
}
|
||||
Start = RemainingPath;
|
||||
if(*Start == L'\\')
|
||||
Start++;
|
||||
RtlCreateUnicodeString(&KeyObject->Name,
|
||||
Start);
|
||||
}
|
||||
else
|
||||
{
|
||||
pKey->NameSize = 0;
|
||||
RtlInitUnicodeString(&KeyObject->Name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
@ -263,6 +265,8 @@ CmiObjectDelete(PVOID DeletedObject)
|
|||
DPRINT1("Key not found in parent list ???\n");
|
||||
}
|
||||
|
||||
RtlFreeUnicodeString(&KeyObject->Name);
|
||||
|
||||
if (KeyObject->Flags & KO_MARKED_FOR_DELETE)
|
||||
{
|
||||
DPRINT("delete really key\n");
|
||||
|
@ -376,13 +380,15 @@ CmiScanKeyList(PKEY_OBJECT Parent,
|
|||
{
|
||||
PKEY_OBJECT CurKey;
|
||||
KIRQL OldIrql;
|
||||
WORD NameSize;
|
||||
DWORD Index;
|
||||
ULONG Index;
|
||||
UNICODE_STRING UName;
|
||||
|
||||
DPRINT("Scanning key list for: %s (Parent: %s)\n",
|
||||
KeyName, Parent->Name);
|
||||
DPRINT("Scanning key list for: %s (Parent: %wZ)\n",
|
||||
KeyName, &Parent->Name);
|
||||
|
||||
RtlCreateUnicodeStringFromAsciiz(&UName,
|
||||
KeyName);
|
||||
|
||||
NameSize = strlen(KeyName);
|
||||
KeAcquireSpinLock(&CmiKeyListLock, &OldIrql);
|
||||
/* FIXME: if list maintained in alphabetic order, use dichotomic search */
|
||||
for (Index=0; Index < Parent->NumberOfSubKeys; Index++)
|
||||
|
@ -390,24 +396,27 @@ CmiScanKeyList(PKEY_OBJECT Parent,
|
|||
CurKey = Parent->SubKeys[Index];
|
||||
if (Attributes & OBJ_CASE_INSENSITIVE)
|
||||
{
|
||||
if ((NameSize == CurKey->NameSize)
|
||||
&& (_strnicmp(KeyName, CurKey->Name, NameSize) == 0))
|
||||
if ((UName.Length == CurKey->Name.Length)
|
||||
&& (_wcsicmp(UName.Buffer, CurKey->Name.Buffer) == 0))
|
||||
{
|
||||
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
||||
RtlFreeUnicodeString(&UName);
|
||||
return CurKey;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((NameSize == CurKey->NameSize)
|
||||
&& (strncmp(KeyName,CurKey->Name,NameSize) == 0))
|
||||
if ((UName.Length == CurKey->Name.Length)
|
||||
&& (wcscmp(UName.Buffer, CurKey->Name.Buffer) == 0))
|
||||
{
|
||||
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
||||
RtlFreeUnicodeString(&UName);
|
||||
return CurKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
KeReleaseSpinLock(&CmiKeyListLock, OldIrql);
|
||||
RtlFreeUnicodeString(&UName);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue