2001-05-02 22:25:58 +00:00
|
|
|
/* $Id: registry.c,v 1.2 2001/05/02 22:23:21 ekohl Exp $
|
2000-08-11 12:46:47 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PURPOSE: Rtl registry functions
|
|
|
|
* FILE: lib/ntdll/rtl/registry.c
|
|
|
|
* PROGRAMER: Eric Kohl
|
|
|
|
* REVISION HISTORY:
|
|
|
|
* 2000/08/11: Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <ntdll/ntdll.h>
|
|
|
|
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
static NTSTATUS RtlpGetRegistryHandle(ULONG RelativeTo,
|
|
|
|
PWSTR Path,
|
|
|
|
BOOLEAN Create,
|
|
|
|
PHANDLE KeyHandle);
|
|
|
|
|
2000-08-11 12:46:47 +00:00
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlCheckRegistryKey(IN ULONG RelativeTo,
|
|
|
|
IN PWSTR Path)
|
2000-08-11 12:46:47 +00:00
|
|
|
{
|
2001-05-02 22:25:58 +00:00
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = RtlpGetRegistryHandle(RelativeTo,
|
|
|
|
Path,
|
|
|
|
FALSE,
|
|
|
|
&KeyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
NtClose(KeyHandle);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2000-08-11 12:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlCreateRegistryKey(IN ULONG RelativeTo,
|
|
|
|
IN PWSTR Path)
|
2000-08-11 12:46:47 +00:00
|
|
|
{
|
2001-05-02 22:25:58 +00:00
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = RtlpGetRegistryHandle(RelativeTo,
|
|
|
|
Path,
|
|
|
|
TRUE,
|
|
|
|
&KeyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
NtClose(KeyHandle);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2000-08-11 12:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlDeleteRegistryValue(IN ULONG RelativeTo,
|
|
|
|
IN PWSTR Path,
|
|
|
|
IN PWSTR ValueName)
|
2000-08-11 12:46:47 +00:00
|
|
|
{
|
2001-05-02 22:25:58 +00:00
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
|
|
|
|
Status = RtlpGetRegistryHandle(RelativeTo,
|
|
|
|
Path,
|
|
|
|
TRUE,
|
|
|
|
&KeyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&Name,
|
|
|
|
ValueName);
|
|
|
|
|
|
|
|
NtDeleteValueKey(KeyHandle,
|
|
|
|
&Name);
|
|
|
|
|
|
|
|
NtClose(KeyHandle);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2000-08-11 12:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlFormatCurrentUserKeyPath(PUNICODE_STRING KeyPath)
|
|
|
|
{
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlOpenCurrentUser(...)
|
|
|
|
*/
|
|
|
|
|
|
|
|
NTSTATUS STDCALL
|
2000-08-11 12:46:47 +00:00
|
|
|
RtlQueryRegistryValues (
|
|
|
|
IN ULONG RelativeTo,
|
|
|
|
IN PWSTR Path,
|
|
|
|
IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
|
|
|
|
IN PVOID Context,
|
|
|
|
IN PVOID Environment
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlWriteRegistryValue(IN ULONG RelativeTo,
|
|
|
|
IN PWSTR Path,
|
|
|
|
IN PWSTR ValueName,
|
|
|
|
IN ULONG ValueType,
|
|
|
|
IN PVOID ValueData,
|
|
|
|
IN ULONG ValueLength)
|
2000-08-11 12:46:47 +00:00
|
|
|
{
|
2001-05-02 22:25:58 +00:00
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
|
|
|
|
Status = RtlpGetRegistryHandle(RelativeTo,
|
|
|
|
Path,
|
|
|
|
TRUE,
|
|
|
|
&KeyHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&Name,
|
|
|
|
ValueName);
|
|
|
|
|
|
|
|
NtSetValueKey(KeyHandle,
|
|
|
|
&Name,
|
|
|
|
0,
|
|
|
|
ValueType,
|
|
|
|
ValueData,
|
|
|
|
ValueLength);
|
|
|
|
|
|
|
|
NtClose(KeyHandle);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2000-08-11 12:46:47 +00:00
|
|
|
}
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
|
2000-08-11 12:46:47 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
RtlpNtMakeTemporaryKey(HANDLE KeyHandle)
|
|
|
|
{
|
|
|
|
return NtDeleteKey(KeyHandle);
|
|
|
|
}
|
|
|
|
|
2001-05-02 22:25:58 +00:00
|
|
|
|
|
|
|
/* INTERNAL FUNCTIONS ******************************************************/
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
RtlpGetRegistryHandle(ULONG RelativeTo,
|
|
|
|
PWSTR Path,
|
|
|
|
BOOLEAN Create,
|
|
|
|
PHANDLE KeyHandle)
|
|
|
|
{
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
WCHAR KeyBuffer[MAX_PATH];
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
if (RelativeTo & RTL_REGISTRY_HANDLE)
|
|
|
|
{
|
|
|
|
*KeyHandle = (HANDLE)Path;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RelativeTo & RTL_REGISTRY_OPTIONAL)
|
|
|
|
RelativeTo &= ~RTL_REGISTRY_OPTIONAL;
|
|
|
|
|
|
|
|
if (RelativeTo >= RTL_REGISTRY_MAXIMUM)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
KeyName.Length = 0;
|
|
|
|
KeyName.MaximumLength = MAX_PATH;
|
|
|
|
KeyName.Buffer = KeyBuffer;
|
|
|
|
KeyBuffer[0] = 0;
|
|
|
|
|
|
|
|
switch (RelativeTo)
|
|
|
|
{
|
|
|
|
case RTL_REGISTRY_SERVICES:
|
|
|
|
RtlAppendUnicodeToString(&KeyName,
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTL_REGISTRY_CONTROL:
|
|
|
|
RtlAppendUnicodeToString(&KeyName,
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTL_REGISTRY_WINDOWS_NT:
|
|
|
|
RtlAppendUnicodeToString(&KeyName,
|
|
|
|
L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTL_REGISTRY_DEVICEMAP:
|
|
|
|
RtlAppendUnicodeToString(&KeyName,
|
|
|
|
L"\\Registry\\Machine\\Hardware\\DeviceMap\\");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTL_REGISTRY_USER:
|
|
|
|
Status = RtlFormatCurrentUserKeyPath(&KeyName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Path[0] != L'\\')
|
|
|
|
RtlAppendUnicodeToString(&KeyName,
|
|
|
|
L"\\");
|
|
|
|
|
|
|
|
RtlAppendUnicodeToString(&KeyName,
|
|
|
|
Path);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (Create == TRUE)
|
|
|
|
{
|
|
|
|
Status = NtCreateKey(KeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = NtOpenKey(KeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-11 12:46:47 +00:00
|
|
|
/* EOF */
|