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 *****************************************************************/
@ -96,10 +99,31 @@ MapDefaultKey (PHKEY RealKey,
/* create/open the default handle */ /* create/open the default handle */
switch (Index) switch (Index)
{ {
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 */ 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;
@ -136,6 +161,29 @@ static VOID CloseDefaultKeys (VOID)
} }
static NTSTATUS
OpenClassesRootKey(PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName;
DPRINT("OpenClassesRootKey()\n");
RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine\\Software\\CLASSES");
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
return(NtOpenKey(KeyHandle,
KEY_ALL_ACCESS,
&Attributes));
}
static NTSTATUS static NTSTATUS
OpenLocalMachineKey(PHANDLE KeyHandle) OpenLocalMachineKey(PHANDLE KeyHandle)
{ {
@ -159,14 +207,56 @@ OpenLocalMachineKey (PHANDLE KeyHandle)
} }
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;
@ -190,13 +280,10 @@ RegCloseKey(
/************************************************************************ /************************************************************************
* RegConnectRegistryA * RegConnectRegistryA
*/ */
LONG LONG STDCALL
STDCALL RegConnectRegistryA(LPSTR lpMachineName,
RegConnectRegistryA(
LPSTR lpMachineName,
HKEY hKey, HKEY hKey,
PHKEY phkResult PHKEY phkResult)
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED; return ERROR_CALL_NOT_IMPLEMENTED;
@ -206,13 +293,10 @@ RegConnectRegistryA(
/************************************************************************ /************************************************************************
* RegConnectRegistryW * RegConnectRegistryW
*/ */
LONG LONG STDCALL
STDCALL RegConnectRegistryW(LPWSTR lpMachineName,
RegConnectRegistryW(
LPWSTR lpMachineName,
HKEY hKey, HKEY hKey,
PHKEY phkResult PHKEY phkResult)
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED; return ERROR_CALL_NOT_IMPLEMENTED;
@ -222,15 +306,12 @@ RegConnectRegistryW(
/************************************************************************ /************************************************************************
* RegCreateKeyA * RegCreateKeyA
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyA(HKEY hKey,
RegCreateKeyA(
HKEY hKey,
LPCSTR lpSubKey, LPCSTR lpSubKey,
PHKEY phkResult PHKEY phkResult)
)
{ {
return RegCreateKeyExA(hKey, return(RegCreateKeyExA(hKey,
lpSubKey, lpSubKey,
0, 0,
NULL, NULL,
@ -238,22 +319,19 @@ RegCreateKeyA(
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
NULL, NULL,
phkResult, phkResult,
NULL); NULL));
} }
/************************************************************************ /************************************************************************
* RegCreateKeyW * RegCreateKeyW
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyW(HKEY hKey,
RegCreateKeyW(
HKEY hKey,
LPCWSTR lpSubKey, LPCWSTR lpSubKey,
PHKEY phkResult PHKEY phkResult)
)
{ {
return RegCreateKeyExW(hKey, return(RegCreateKeyExW(hKey,
lpSubKey, lpSubKey,
0, 0,
NULL, NULL,
@ -261,17 +339,15 @@ RegCreateKeyW(
KEY_ALL_ACCESS, KEY_ALL_ACCESS,
NULL, NULL,
phkResult, phkResult,
NULL); NULL));
} }
/************************************************************************ /************************************************************************
* RegCreateKeyExA * RegCreateKeyExA
*/ */
LONG LONG STDCALL
STDCALL RegCreateKeyExA(HKEY hKey,
RegCreateKeyExA(
HKEY hKey,
LPCSTR lpSubKey, LPCSTR lpSubKey,
DWORD Reserved, DWORD Reserved,
LPSTR lpClass, LPSTR lpClass,
@ -279,21 +355,71 @@ RegCreateKeyExA(
REGSAM samDesired, REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult, PHKEY phkResult,
LPDWORD lpdwDisposition 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(
HKEY hKey,
LPCWSTR lpSubKey, LPCWSTR lpSubKey,
DWORD Reserved, DWORD Reserved,
LPWSTR lpClass, LPWSTR lpClass,
@ -301,8 +427,7 @@ RegCreateKeyExW(
REGSAM samDesired, REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult, PHKEY phkResult,
LPDWORD lpdwDisposition 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(
HKEY hKey,
LPCSTR lpSubKey, LPCSTR lpSubKey,
PHKEY phkResult 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,37 +1151,81 @@ RegOpenKeyW (
/************************************************************************ /************************************************************************
* RegOpenKeyExA * RegOpenKeyExA
*/ */
LONG LONG STDCALL
STDCALL RegOpenKeyExA(HKEY hKey,
RegOpenKeyExA(
HKEY hKey,
LPCSTR lpSubKey, LPCSTR lpSubKey,
DWORD ulOptions, DWORD ulOptions,
REGSAM samDesired, REGSAM samDesired,
PHKEY phkResult 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(
HKEY hKey,
LPCWSTR lpSubKey, LPCWSTR lpSubKey,
DWORD ulOptions, DWORD ulOptions,
REGSAM samDesired, REGSAM samDesired,
PHKEY phkResult PHKEY phkResult)
)
{ {
NTSTATUS errCode;
UNICODE_STRING SubKeyString;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyString;
HANDLE KeyHandle;
LONG ErrorCode;
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
hKey);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode);
return(ErrorCode);
}
RtlInitUnicodeString(&SubKeyString, RtlInitUnicodeString(&SubKeyString,
(LPWSTR)lpSubKey); (LPWSTR)lpSubKey);
@ -1008,22 +1233,20 @@ RegOpenKeyExW(
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&SubKeyString, &SubKeyString,
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
(HANDLE)hKey, KeyHandle,
NULL); NULL);
errCode = NtOpenKey( Status = NtOpenKey(phkResult,
phkResult,
samDesired, samDesired,
& ObjectAttributes &ObjectAttributes);
); if (!NT_SUCCESS(Status))
if ( !NT_SUCCESS(errCode) )
{ {
LONG LastError = RtlNtStatusToDosError(errCode); ErrorCode = RtlNtStatusToDosError(Status);
SetLastError(LastError); SetLastError(ErrorCode);
return LastError; return(ErrorCode);
} }
return ERROR_SUCCESS; return(ERROR_SUCCESS);
} }