Added some code to map more predefined keys (like HKCU).

Implemented some ansi functions

svn path=/trunk/; revision=2025
This commit is contained in:
Eric Kohl 2001-07-01 17:54:07 +00:00
parent a9be5303eb
commit 8cd4cde19c

View file

@ -1,4 +1,4 @@
/* $Id: reg.c,v 1.11 2000/09/27 01:21:27 ekohl Exp $ /* $Id: reg.c,v 1.12 2001/07/01 17:54:07 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -19,7 +19,7 @@
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
#define MAX_DEFAULT_HANDLES 7 #define MAX_DEFAULT_HANDLES 6
static CRITICAL_SECTION HandleTableCS; static CRITICAL_SECTION HandleTableCS;
static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES]; static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
@ -30,7 +30,10 @@ static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
static NTSTATUS MapDefaultKey (PHKEY ParentKey, HKEY Key); static NTSTATUS MapDefaultKey (PHKEY ParentKey, HKEY Key);
static VOID CloseDefaultKeys(VOID); static VOID CloseDefaultKeys(VOID);
static NTSTATUS OpenClassesRootKey(PHANDLE KeyHandle);
static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle); static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle);
static NTSTATUS OpenUsersKey (PHANDLE KeyHandle);
static NTSTATUS OpenCurrentConfigKey(PHANDLE KeyHandle);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -67,8 +70,8 @@ RegCleanup(VOID)
static NTSTATUS static NTSTATUS
MapDefaultKey (PHKEY RealKey, MapDefaultKey(PHKEY RealKey,
HKEY Key) HKEY Key)
{ {
PHANDLE Handle; PHANDLE Handle;
ULONG Index; ULONG Index;
@ -96,10 +99,31 @@ MapDefaultKey (PHKEY RealKey,
/* create/open the default handle */ /* create/open the default handle */
switch (Index) switch (Index)
{ {
case 2: /*HKEY_LOCAL_MACHINE */ case 0: /* HKEY_CLASSES_ROOT */
Status = OpenClassesRootKey(Handle);
break;
case 1: /* HKEY_CURRENT_USER */
Status = RtlOpenCurrentUser(KEY_ALL_ACCESS,
Handle);
break;
case 2: /* HKEY_LOCAL_MACHINE */
Status = OpenLocalMachineKey(Handle); Status = OpenLocalMachineKey(Handle);
break; break;
case 3: /* HKEY_USERS */
Status = OpenUsersKey(Handle);
break;
#if 0
case 4: /* HKEY_PERFORMANCE_DATA */
Status = OpenPerformanceDataKey(Handle);
break;
#endif
case 5: /* HKEY_CURRENT_CONFIG */
Status = OpenCurrentConfigKey(Handle);
break;
default: default:
DPRINT("MapDefaultHandle() no handle creator\n"); DPRINT("MapDefaultHandle() no handle creator\n");
Status = STATUS_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
@ -117,7 +141,8 @@ MapDefaultKey (PHKEY RealKey,
} }
static VOID CloseDefaultKeys (VOID) static VOID
CloseDefaultKeys(VOID)
{ {
ULONG i; ULONG i;
@ -137,172 +162,272 @@ static VOID CloseDefaultKeys (VOID)
static NTSTATUS static NTSTATUS
OpenLocalMachineKey (PHANDLE KeyHandle) OpenClassesRootKey(PHANDLE KeyHandle)
{ {
OBJECT_ATTRIBUTES Attributes; OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
DPRINT("OpenLocalMachineKey()\n"); DPRINT("OpenClassesRootKey()\n");
RtlInitUnicodeString(&KeyName, RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine"); L"\\Registry\\Machine\\Software\\CLASSES");
InitializeObjectAttributes(&Attributes, InitializeObjectAttributes(&Attributes,
&KeyName, &KeyName,
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
return (NtOpenKey (KeyHandle, return(NtOpenKey(KeyHandle,
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
&Attributes)); &Attributes));
} }
static NTSTATUS
OpenLocalMachineKey(PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName;
DPRINT("OpenLocalMachineKey()\n");
RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine");
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
return(NtOpenKey(KeyHandle,
KEY_ALL_ACCESS,
&Attributes));
}
static NTSTATUS
OpenUsersKey(PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName;
DPRINT("OpenUsersKey()\n");
RtlInitUnicodeString(&KeyName,
L"\\Registry\\User");
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
return(NtOpenKey(KeyHandle,
KEY_ALL_ACCESS,
&Attributes));
}
static NTSTATUS
OpenCurrentConfigKey(PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName;
DPRINT("OpenCurrentConfigKey()\n");
RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current");
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
return(NtOpenKey(KeyHandle,
KEY_ALL_ACCESS,
&Attributes));
}
/************************************************************************ /************************************************************************
* RegCloseKey * RegCloseKey
*/ */
LONG LONG STDCALL
STDCALL RegCloseKey(HKEY hKey)
RegCloseKey(
HKEY hKey
)
{ {
NTSTATUS Status; NTSTATUS Status;
/* don't close null handle or a pseudo handle */ /* don't close null handle or a pseudo handle */
if ((!hKey) || (((ULONG)hKey & 0xF0000000) == 0x80000000)) if ((!hKey) || (((ULONG)hKey & 0xF0000000) == 0x80000000))
return ERROR_INVALID_HANDLE; return ERROR_INVALID_HANDLE;
Status = NtClose (hKey); Status = NtClose (hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
LONG ErrorCode = RtlNtStatusToDosError(Status); LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode); SetLastError (ErrorCode);
return ErrorCode; return ErrorCode;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
/************************************************************************ /************************************************************************
* RegConnectRegistryA * RegConnectRegistryA
*/ */
LONG LONG STDCALL
STDCALL RegConnectRegistryA(LPSTR lpMachineName,
RegConnectRegistryA( HKEY hKey,
LPSTR lpMachineName, PHKEY phkResult)
HKEY hKey,
PHKEY phkResult
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED; return ERROR_CALL_NOT_IMPLEMENTED;
} }
/************************************************************************ /************************************************************************
* RegConnectRegistryW * RegConnectRegistryW
*/ */
LONG LONG STDCALL
STDCALL RegConnectRegistryW(LPWSTR lpMachineName,
RegConnectRegistryW( HKEY hKey,
LPWSTR lpMachineName, PHKEY phkResult)
HKEY hKey,
PHKEY phkResult
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED; return ERROR_CALL_NOT_IMPLEMENTED;
} }
/************************************************************************ /************************************************************************
* RegCreateKeyA * RegCreateKeyA
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyA(HKEY hKey,
RegCreateKeyA( LPCSTR lpSubKey,
HKEY hKey, PHKEY phkResult)
LPCSTR lpSubKey,
PHKEY phkResult
)
{ {
return RegCreateKeyExA(hKey, return(RegCreateKeyExA(hKey,
lpSubKey, lpSubKey,
0, 0,
NULL, NULL,
0, 0,
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
NULL, NULL,
phkResult, phkResult,
NULL); NULL));
} }
/************************************************************************ /************************************************************************
* RegCreateKeyW * RegCreateKeyW
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyW(HKEY hKey,
RegCreateKeyW( LPCWSTR lpSubKey,
HKEY hKey, PHKEY phkResult)
LPCWSTR lpSubKey,
PHKEY phkResult
)
{ {
return RegCreateKeyExW(hKey, return(RegCreateKeyExW(hKey,
lpSubKey, lpSubKey,
0, 0,
NULL, NULL,
0, 0,
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
NULL, NULL,
phkResult, phkResult,
NULL); NULL));
} }
/************************************************************************ /************************************************************************
* RegCreateKeyExA * RegCreateKeyExA
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyExA(HKEY hKey,
RegCreateKeyExA( LPCSTR lpSubKey,
HKEY hKey, DWORD Reserved,
LPCSTR lpSubKey, LPSTR lpClass,
DWORD Reserved, DWORD dwOptions,
LPSTR lpClass, REGSAM samDesired,
DWORD dwOptions, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
REGSAM samDesired, PHKEY phkResult,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, LPDWORD lpdwDisposition)
PHKEY phkResult,
LPDWORD lpdwDisposition
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); UNICODE_STRING SubKeyString;
return ERROR_CALL_NOT_IMPLEMENTED; UNICODE_STRING ClassString;
OBJECT_ATTRIBUTES Attributes;
NTSTATUS Status;
HKEY ParentKey;
DPRINT("RegCreateKeyExW() called\n");
/* get the real parent key */
Status = MapDefaultKey(&ParentKey,
hKey);
if (!NT_SUCCESS(Status))
{
LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
DPRINT("ParentKey %x\n", (ULONG)ParentKey);
if (lpClass != NULL)
RtlCreateUnicodeStringFromAsciiz(&ClassString,
lpClass);
RtlCreateUnicodeStringFromAsciiz(&SubKeyString,
(LPSTR)lpSubKey);
InitializeObjectAttributes(&Attributes,
&SubKeyString,
OBJ_CASE_INSENSITIVE,
(HANDLE)ParentKey,
(PSECURITY_DESCRIPTOR)lpSecurityAttributes);
Status = NtCreateKey(phkResult,
samDesired,
&Attributes,
0,
(lpClass == NULL)? NULL : &ClassString,
dwOptions,
(PULONG)lpdwDisposition);
RtlFreeUnicodeString(&SubKeyString);
if (lpClass != NULL)
RtlFreeUnicodeString(&ClassString);
DPRINT("Status %x\n", Status);
if (!NT_SUCCESS(Status))
{
LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode);
return ErrorCode;
}
return(ERROR_SUCCESS);
} }
/************************************************************************ /************************************************************************
* RegCreateKeyExW * RegCreateKeyExW
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyExW(HKEY hKey,
RegCreateKeyExW( LPCWSTR lpSubKey,
HKEY hKey, DWORD Reserved,
LPCWSTR lpSubKey, LPWSTR lpClass,
DWORD Reserved, DWORD dwOptions,
LPWSTR lpClass, REGSAM samDesired,
DWORD dwOptions, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
REGSAM samDesired, PHKEY phkResult,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, LPDWORD lpdwDisposition)
PHKEY phkResult,
LPDWORD lpdwDisposition
)
{ {
UNICODE_STRING SubKeyString; UNICODE_STRING SubKeyString;
UNICODE_STRING ClassString; UNICODE_STRING ClassString;
@ -817,14 +942,36 @@ RegEnumValueW(
/************************************************************************ /************************************************************************
* RegFlushKey * RegFlushKey
*/ */
LONG LONG STDCALL
STDCALL RegFlushKey(HKEY hKey)
RegFlushKey(
HKEY hKey
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); HANDLE KeyHandle;
return ERROR_CALL_NOT_IMPLEMENTED; NTSTATUS Status;
LONG ErrorCode;
if (hKey == HKEY_PERFORMANCE_DATA)
return(ERROR_SUCCESS);
Status = MapDefaultKey(&KeyHandle,
hKey);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
Status = NtFlushKey(KeyHandle);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
return(ERROR_SUCCESS);
} }
@ -899,16 +1046,50 @@ RegNotifyChangeKeyValue(
/************************************************************************ /************************************************************************
* RegOpenKeyA * RegOpenKeyA
*/ */
LONG LONG STDCALL
STDCALL RegOpenKeyA(HKEY hKey,
RegOpenKeyA( LPCSTR lpSubKey,
HKEY hKey, PHKEY phkResult)
LPCSTR lpSubKey,
PHKEY phkResult
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); OBJECT_ATTRIBUTES ObjectAttributes;
return ERROR_CALL_NOT_IMPLEMENTED; UNICODE_STRING SubKeyString;
HANDLE KeyHandle;
LONG ErrorCode;
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
hKey);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
RtlCreateUnicodeStringFromAsciiz(&SubKeyString,
(LPSTR)lpSubKey);
InitializeObjectAttributes(&ObjectAttributes,
&SubKeyString,
OBJ_CASE_INSENSITIVE,
KeyHandle,
NULL);
Status = NtOpenKey(phkResult,
KEY_ALL_ACCESS,
&ObjectAttributes);
RtlFreeUnicodeString(&SubKeyString);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
return(ERROR_SUCCESS);
} }
@ -970,60 +1151,102 @@ RegOpenKeyW (
/************************************************************************ /************************************************************************
* RegOpenKeyExA * RegOpenKeyExA
*/ */
LONG LONG STDCALL
STDCALL RegOpenKeyExA(HKEY hKey,
RegOpenKeyExA( LPCSTR lpSubKey,
HKEY hKey, DWORD ulOptions,
LPCSTR lpSubKey, REGSAM samDesired,
DWORD ulOptions, PHKEY phkResult)
REGSAM samDesired,
PHKEY phkResult
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); OBJECT_ATTRIBUTES ObjectAttributes;
return ERROR_CALL_NOT_IMPLEMENTED; UNICODE_STRING SubKeyString;
HANDLE KeyHandle;
LONG ErrorCode;
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
hKey);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
RtlCreateUnicodeStringFromAsciiz(&SubKeyString,
(LPSTR)lpSubKey);
InitializeObjectAttributes(&ObjectAttributes,
&SubKeyString,
OBJ_CASE_INSENSITIVE,
KeyHandle,
NULL);
Status = NtOpenKey(phkResult,
samDesired,
&ObjectAttributes);
RtlFreeUnicodeString(&SubKeyString);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
return(ERROR_SUCCESS);
} }
/************************************************************************ /************************************************************************
* RegOpenKeyExW * RegOpenKeyExW
*/ */
LONG LONG STDCALL
STDCALL RegOpenKeyExW(HKEY hKey,
RegOpenKeyExW( LPCWSTR lpSubKey,
HKEY hKey, DWORD ulOptions,
LPCWSTR lpSubKey, REGSAM samDesired,
DWORD ulOptions, PHKEY phkResult)
REGSAM samDesired,
PHKEY phkResult
)
{ {
NTSTATUS errCode; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyString; UNICODE_STRING SubKeyString;
OBJECT_ATTRIBUTES ObjectAttributes; HANDLE KeyHandle;
LONG ErrorCode;
NTSTATUS Status;
RtlInitUnicodeString(&SubKeyString, Status = MapDefaultKey(&KeyHandle,
(LPWSTR)lpSubKey); hKey);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
InitializeObjectAttributes(&ObjectAttributes, SetLastError (ErrorCode);
&SubKeyString, return(ErrorCode);
OBJ_CASE_INSENSITIVE, }
(HANDLE)hKey,
NULL);
errCode = NtOpenKey( RtlInitUnicodeString(&SubKeyString,
phkResult, (LPWSTR)lpSubKey);
samDesired,
& ObjectAttributes
);
if ( !NT_SUCCESS(errCode) )
{
LONG LastError = RtlNtStatusToDosError(errCode);
SetLastError(LastError); InitializeObjectAttributes(&ObjectAttributes,
return LastError; &SubKeyString,
} OBJ_CASE_INSENSITIVE,
return ERROR_SUCCESS; KeyHandle,
NULL);
Status = NtOpenKey(phkResult,
samDesired,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(ErrorCode);
return(ErrorCode);
}
return(ERROR_SUCCESS);
} }