Make RtlpGetRegistryHandle() a local helper function.

svn path=/trunk/; revision=6331
This commit is contained in:
Eric Kohl 2003-10-15 21:15:45 +00:00
parent ba15abe412
commit 194a827c38
4 changed files with 132 additions and 174 deletions

View file

@ -1,6 +0,0 @@
NTSTATUS
RtlpGetRegistryHandle(ULONG RelativeTo,
PWSTR Path,
BOOLEAN Create,
PHANDLE KeyHandle);

View file

@ -1,6 +1,6 @@
#ifndef _NTOS_H
#define _NTOS_H
/* $Id: ntos.h,v 1.16 2003/08/27 21:21:59 dwelch Exp $ */
/* $Id: ntos.h,v 1.17 2003/10/15 21:15:18 ekohl Exp $ */
#if defined(NTOS_MODE_USER)
/*
@ -45,7 +45,6 @@
#include "ntdll/csr.h"
#include "ntdll/dbg.h"
#include "ntdll/ldr.h"
#include "ntdll/registry.h"
#include "ntdll/rtl.h"
#include "ntdll/trace.h"
#include "rosrtl/thread.h"

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.24 2003/08/30 14:47:36 hbirr Exp $
/* $Id: registry.c,v 1.25 2003/10/15 21:14:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -21,7 +21,6 @@
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#include <ntdll/registry.h>
#include <ntos/minmax.h>
#define NDEBUG
@ -30,6 +29,120 @@
/* FUNCTIONS ***************************************************************/
static NTSTATUS
RtlpGetRegistryHandle(ULONG RelativeTo,
PWSTR Path,
BOOLEAN Create,
PHANDLE KeyHandle)
{
UNICODE_STRING KeyName;
WCHAR KeyBuffer[MAX_PATH];
OBJECT_ATTRIBUTES ObjectAttributes;
NTSTATUS Status;
DPRINT("RtlpGetRegistryHandle()\n");
if (RelativeTo & RTL_REGISTRY_HANDLE)
{
Status = NtDuplicateObject(NtCurrentProcess(),
(HANDLE)Path,
NtCurrentProcess(),
KeyHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
return(Status);
}
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_ABSOLUTE:
RtlAppendUnicodeToString(&KeyName,
L"\\");
break;
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;
/* ReactOS specific */
case RTL_REGISTRY_ENUM:
RtlAppendUnicodeToString(&KeyName,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
break;
}
DPRINT("KeyName %wZ\n", &KeyName);
if (Path[0] == L'\\' && RelativeTo != RTL_REGISTRY_ABSOLUTE)
{
Path++;
}
RtlAppendUnicodeToString(&KeyName,
Path);
DPRINT("KeyName %wZ\n", &KeyName);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
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);
}
/*
* @implemented
*/
@ -927,120 +1040,4 @@ RtlpNtSetValueKey(IN HANDLE KeyHandle,
DataLength));
}
/* INTERNAL FUNCTIONS ******************************************************/
NTSTATUS
RtlpGetRegistryHandle(ULONG RelativeTo,
PWSTR Path,
BOOLEAN Create,
PHANDLE KeyHandle)
{
UNICODE_STRING KeyName;
WCHAR KeyBuffer[MAX_PATH];
OBJECT_ATTRIBUTES ObjectAttributes;
NTSTATUS Status;
DPRINT("RtlpGetRegistryHandle()\n");
if (RelativeTo & RTL_REGISTRY_HANDLE)
{
Status = NtDuplicateObject(NtCurrentProcess(),
(HANDLE)Path,
NtCurrentProcess(),
KeyHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
return(Status);
}
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_ABSOLUTE:
RtlAppendUnicodeToString(&KeyName,
L"\\");
break;
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;
/* ReactOS specific */
case RTL_REGISTRY_ENUM:
RtlAppendUnicodeToString(&KeyName,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
break;
}
DPRINT("KeyName %wZ\n", &KeyName);
if (Path[0] == L'\\' && RelativeTo != RTL_REGISTRY_ABSOLUTE)
{
Path++;
}
RtlAppendUnicodeToString(&KeyName,
Path);
DPRINT("KeyName %wZ\n", &KeyName);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
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);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: timezone.c,v 1.6 2003/09/12 17:51:48 vizzini Exp $
/* $Id: timezone.c,v 1.7 2003/10/15 21:14:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -17,7 +17,6 @@
#define NDEBUG
#include <ntdll/ntdll.h>
#include <ntdll/registry.h>
/* FUNCTIONS *****************************************************************/
@ -28,7 +27,6 @@
NTSTATUS STDCALL
RtlQueryTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
{
HANDLE KeyHandle;
RTL_QUERY_REGISTRY_TABLE QueryTable[8];
UNICODE_STRING StandardName;
UNICODE_STRING DaylightName;
@ -36,16 +34,6 @@ RtlQueryTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
DPRINT("RtlQueryTimeZoneInformation()\n");
Status = RtlpGetRegistryHandle(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
TRUE,
&KeyHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle failed (Status %x)\n", Status);
return Status;
}
RtlZeroMemory(QueryTable,
sizeof(QueryTable));
@ -85,12 +73,11 @@ RtlQueryTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
QueryTable[6].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[6].EntryContext = &TimeZoneInformation->DaylightDate;
Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
QueryTable,
NULL,
NULL);
NtClose(KeyHandle);
return Status;
}
@ -102,105 +89,86 @@ RtlQueryTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
NTSTATUS STDCALL
RtlSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation)
{
HANDLE KeyHandle;
ULONG Length;
NTSTATUS Status;
DPRINT("RtlSetTimeZoneInformation()\n");
Status = RtlpGetRegistryHandle(RTL_REGISTRY_CONTROL,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
TRUE,
&KeyHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle failed (Status %x)\n", Status);
return Status;
}
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
L"Bias",
REG_DWORD,
&TimeZoneInformation->Bias,
sizeof(LONG));
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
return Status;
}
Length = (wcslen(TimeZoneInformation->StandardName) + 1) * sizeof(WCHAR);
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
L"Standard Name",
REG_SZ,
TimeZoneInformation->StandardName,
Length);
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
return Status;
}
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
L"Standard Bias",
REG_DWORD,
&TimeZoneInformation->StandardBias,
sizeof(LONG));
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
return Status;
}
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
L"Standard Start",
REG_BINARY,
&TimeZoneInformation->StandardDate,
sizeof(SYSTEMTIME));
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
return Status;
}
Length = (wcslen(TimeZoneInformation->DaylightName) + 1) * sizeof(WCHAR);
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
L"Daylight Name",
REG_SZ,
TimeZoneInformation->DaylightName,
Length);
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
return Status;
}
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
L"Daylight Bias",
REG_DWORD,
&TimeZoneInformation->DaylightBias,
sizeof(LONG));
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
return Status;
}
Status = RtlWriteRegistryValue(RTL_REGISTRY_HANDLE,
(PWSTR)KeyHandle,
Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
L"TimeZoneInformation",
L"Daylight Start",
REG_BINARY,
&TimeZoneInformation->DaylightDate,
sizeof(SYSTEMTIME));
NtClose(KeyHandle);
return Status;
}