ReactOS  0.4.12-dev-934-g9a4676f
registry.c File Reference
#include "mkhive.h"
Include dependency graph for registry.c:

Go to the source code of this file.

Classes

struct  _REPARSE_POINT
 
struct  _MEMKEY
 

Macros

#define NDEBUG
 
#define HKEY_TO_MEMKEY(hKey)   ((PMEMKEY)(hKey))
 
#define MEMKEY_TO_HKEY(memKey)   ((HKEY)(memKey))
 

Typedefs

typedef struct _REPARSE_POINT REPARSE_POINT
 
typedef struct _REPARSE_POINTPREPARSE_POINT
 
typedef struct _MEMKEY MEMKEY
 
typedef struct _MEMKEYPMEMKEY
 

Functions

 C_ASSERT (_countof(RegistryHives)==MAX_NUMBER_OF_REGISTRY_HIVES)
 
static PMEMKEY CreateInMemoryStructure (IN PCMHIVE RegistryHive, IN HCELL_INDEX KeyCellOffset)
 
static LONG RegpCreateOrOpenKey (IN HKEY hParentKey, IN PCWSTR KeyName, IN BOOL AllowCreation, IN BOOL Volatile, OUT PHKEY Key)
 
LONG WINAPI RegCloseKey (IN HKEY hKey)
 
LONG WINAPI RegCreateKeyW (IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
 
LONG WINAPI RegCreateKeyExW (IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD Reserved, IN LPWSTR lpClass OPTIONAL, IN DWORD dwOptions, IN REGSAM samDesired, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes OPTIONAL, OUT PHKEY phkResult, OUT LPDWORD lpdwDisposition OPTIONAL)
 
LONG WINAPI RegDeleteKeyW (IN HKEY hKey, IN LPCWSTR lpSubKey)
 
LONG WINAPI RegOpenKeyW (IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
 
LONG WINAPI RegSetValueExW (IN HKEY hKey, IN LPCWSTR lpValueName OPTIONAL, IN ULONG Reserved, IN ULONG dwType, IN const UCHAR *lpData, IN ULONG cbData)
 
static VOID RepGetValueData (IN PHHIVE Hive, IN PCM_KEY_VALUE ValueCell, OUT PULONG Type OPTIONAL, OUT PUCHAR Data OPTIONAL, IN OUT PULONG DataSize OPTIONAL)
 
LONG WINAPI RegQueryValueExW (IN HKEY hKey, IN LPCWSTR lpValueName, IN PULONG lpReserved, OUT PULONG lpType OPTIONAL, OUT PUCHAR lpData OPTIONAL, IN OUT PULONG lpcbData OPTIONAL)
 
LONG WINAPI RegDeleteValueW (IN HKEY hKey, IN LPCWSTR lpValueName OPTIONAL)
 
static BOOL ConnectRegistry (IN HKEY RootKey, IN PCWSTR Path, IN PCMHIVE HiveToConnect, IN PUCHAR SecurityDescriptor, IN ULONG SecurityDescriptorLength)
 
static BOOL CreateSymLink (IN PCWSTR LinkKeyPath OPTIONAL, IN OUT PHKEY LinkKeyHandle OPTIONAL, IN HKEY TargetKeyHandle)
 
VOID RegInitializeRegistry (IN PCSTR HiveList)
 
VOID RegShutdownRegistry (VOID)
 

Variables

static CMHIVE RootHive
 
static PMEMKEY RootKey
 
static CMHIVE SystemHive
 
static CMHIVE SoftwareHive
 
static CMHIVE DefaultHive
 
static CMHIVE SamHive
 
static CMHIVE SecurityHive
 
static CMHIVE BcdHive
 
static UCHAR BcdSecurity []
 
static UCHAR SoftwareSecurity []
 
static UCHAR SystemSecurity []
 
HIVE_LIST_ENTRY RegistryHives []
 
LIST_ENTRY CmiHiveListHead
 
LIST_ENTRY CmiReparsePointsHead
 

Macro Definition Documentation

◆ HKEY_TO_MEMKEY

#define HKEY_TO_MEMKEY (   hKey)    ((PMEMKEY)(hKey))

Definition at line 51 of file registry.c.

◆ MEMKEY_TO_HKEY

#define MEMKEY_TO_HKEY (   memKey)    ((HKEY)(memKey))

Definition at line 52 of file registry.c.

◆ NDEBUG

#define NDEBUG

Definition at line 30 of file registry.c.

Typedef Documentation

◆ MEMKEY

◆ PMEMKEY

typedef struct _MEMKEY * PMEMKEY

◆ PREPARSE_POINT

◆ REPARSE_POINT

Function Documentation

◆ C_ASSERT()

◆ ConnectRegistry()

static BOOL ConnectRegistry ( IN HKEY RootKey  ,
IN PCWSTR  Path,
IN PCMHIVE  HiveToConnect,
IN PUCHAR  SecurityDescriptor,
IN ULONG  SecurityDescriptorLength 
)
static

Definition at line 1011 of file registry.c.

1017 {
1018  NTSTATUS Status;
1019  LONG rc;
1020  PREPARSE_POINT ReparsePoint;
1021  PMEMKEY NewKey;
1022 
1023  ReparsePoint = (PREPARSE_POINT)malloc(sizeof(*ReparsePoint));
1024  if (!ReparsePoint)
1025  return FALSE;
1026 
1027  /*
1028  * Use a dummy root key name:
1029  * - On 2k/XP/2k3, this is "$$$PROTO.HIV"
1030  * - On Vista+, this is "CMI-CreateHive{guid}"
1031  * See https://github.com/libyal/winreg-kb/blob/master/documentation/Registry%20files.asciidoc
1032  * for more information.
1033  */
1034  Status = CmiInitializeHive(HiveToConnect, L"$$$PROTO.HIV");
1035  if (!NT_SUCCESS(Status))
1036  {
1037  DPRINT1("CmiInitializeHive() failed with status 0x%08x\n", Status);
1038  free(ReparsePoint);
1039  return FALSE;
1040  }
1041 
1042  /*
1043  * Add security to the root key.
1044  * NOTE: One can implement this using the lpSecurityAttributes
1045  * parameter of RegCreateKeyExW.
1046  */
1047  Status = CmiCreateSecurityKey(&HiveToConnect->Hive,
1048  HiveToConnect->Hive.BaseBlock->RootCell,
1050  if (!NT_SUCCESS(Status))
1051  DPRINT1("Failed to add security for root key '%S'\n", Path);
1052 
1053  /* Create the key */
1054  rc = RegCreateKeyExW(RootKey,
1055  Path,
1056  0,
1057  NULL,
1059  0,
1060  NULL,
1061  (PHKEY)&NewKey,
1062  NULL);
1063  if (rc != ERROR_SUCCESS)
1064  {
1065  free(ReparsePoint);
1066  return FALSE;
1067  }
1068 
1069  ReparsePoint->SourceHive = NewKey->RegistryHive;
1070  ReparsePoint->SourceKeyCellOffset = NewKey->KeyCellOffset;
1071  NewKey->RegistryHive = HiveToConnect;
1072  NewKey->KeyCellOffset = HiveToConnect->Hive.BaseBlock->RootCell;
1073  ReparsePoint->DestinationHive = NewKey->RegistryHive;
1074  ReparsePoint->DestinationKeyCellOffset = NewKey->KeyCellOffset;
1075  InsertTailList(&CmiReparsePointsHead, &ReparsePoint->ListEntry);
1076 
1077  return TRUE;
1078 }
LIST_ENTRY CmiReparsePointsHead
Definition: registry.c:386
#define TRUE
Definition: types.h:120
static PMEMKEY RootKey
Definition: registry.c:55
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExW(IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD Reserved, IN LPWSTR lpClass OPTIONAL, IN DWORD dwOptions, IN REGSAM samDesired, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes OPTIONAL, OUT PHKEY phkResult, OUT LPDWORD lpdwDisposition OPTIONAL)
Definition: registry.c:533
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
HCELL_INDEX DestinationKeyCellOffset
Definition: registry.c:41
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
_In_ ULONG SecurityDescriptorLength
Definition: rtlfuncs.h:1674
HCELL_INDEX SourceKeyCellOffset
Definition: registry.c:39
HCELL_INDEX KeyCellOffset
Definition: registry.c:47
NTSTATUS CmiCreateSecurityKey(IN PHHIVE Hive, IN HCELL_INDEX Cell, IN PUCHAR Descriptor, IN ULONG DescriptorLength)
Definition: cmi.c:157
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
struct _REPARSE_POINT * PREPARSE_POINT
LIST_ENTRY ListEntry
Definition: registry.c:37
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCMHIVE DestinationHive
Definition: registry.c:40
PCMHIVE RegistryHive
Definition: registry.c:48
PCMHIVE SourceHive
Definition: registry.c:38
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
PRTL_UNICODE_STRING_BUFFER Path
NTSTATUS CmiInitializeHive(IN OUT PCMHIVE Hive, IN PCWSTR Name)
Definition: cmi.c:114
#define DPRINT1
Definition: precomp.h:8
#define malloc
Definition: debug_ros.c:4
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060

Referenced by RegInitializeRegistry().

◆ CreateInMemoryStructure()

static PMEMKEY CreateInMemoryStructure ( IN PCMHIVE  RegistryHive,
IN HCELL_INDEX  KeyCellOffset 
)
static

Definition at line 370 of file registry.c.

373 {
374  PMEMKEY Key;
375 
376  Key = (PMEMKEY)malloc(sizeof(MEMKEY));
377  if (!Key)
378  return NULL;
379 
380  Key->RegistryHive = RegistryHive;
381  Key->KeyCellOffset = KeyCellOffset;
382  return Key;
383 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
smooth NULL
Definition: ftsmooth.c:416
#define malloc
Definition: debug_ros.c:4
struct _MEMKEY * PMEMKEY

Referenced by RegInitializeRegistry(), and RegpCreateOrOpenKey().

◆ CreateSymLink()

static BOOL CreateSymLink ( IN PCWSTR LinkKeyPath  OPTIONAL,
IN OUT PHKEY LinkKeyHandle  OPTIONAL,
IN HKEY  TargetKeyHandle 
)
static

Definition at line 1081 of file registry.c.

1086 {
1087  LONG rc;
1088  PMEMKEY LinkKey, TargetKey;
1089  PREPARSE_POINT ReparsePoint;
1090 
1091  ReparsePoint = (PREPARSE_POINT)malloc(sizeof(*ReparsePoint));
1092  if (!ReparsePoint)
1093  return FALSE;
1094 
1095  if (LinkKeyPath && !(LinkKeyHandle && *LinkKeyHandle))
1096  {
1097  /* Create the link key */
1098  rc = RegCreateKeyExW(NULL,
1099  LinkKeyPath,
1100  0,
1101  NULL,
1103  0,
1104  NULL,
1105  (PHKEY)&LinkKey,
1106  NULL);
1107  if (rc != ERROR_SUCCESS)
1108  {
1109  free(ReparsePoint);
1110  return FALSE;
1111  }
1112  }
1113  else if (LinkKeyHandle)
1114  {
1115  /* Use the user-provided link key handle */
1116  LinkKey = HKEY_TO_MEMKEY(*LinkKeyHandle);
1117  }
1118 
1119  if (LinkKeyHandle)
1120  *LinkKeyHandle = MEMKEY_TO_HKEY(LinkKey);
1121 
1122  TargetKey = HKEY_TO_MEMKEY(TargetKeyHandle);
1123 
1124  ReparsePoint->SourceHive = LinkKey->RegistryHive;
1125  ReparsePoint->SourceKeyCellOffset = LinkKey->KeyCellOffset;
1126  ReparsePoint->DestinationHive = TargetKey->RegistryHive;
1127  ReparsePoint->DestinationKeyCellOffset = TargetKey->KeyCellOffset;
1128  InsertTailList(&CmiReparsePointsHead, &ReparsePoint->ListEntry);
1129 
1130  return TRUE;
1131 }
LIST_ENTRY CmiReparsePointsHead
Definition: registry.c:386
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExW(IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD Reserved, IN LPWSTR lpClass OPTIONAL, IN DWORD dwOptions, IN REGSAM samDesired, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes OPTIONAL, OUT PHKEY phkResult, OUT LPDWORD lpdwDisposition OPTIONAL)
Definition: registry.c:533
HCELL_INDEX DestinationKeyCellOffset
Definition: registry.c:41
#define free
Definition: debug_ros.c:5
#define InsertTailList(ListHead, Entry)
HCELL_INDEX SourceKeyCellOffset
Definition: registry.c:39
HCELL_INDEX KeyCellOffset
Definition: registry.c:47
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
struct _REPARSE_POINT * PREPARSE_POINT
LIST_ENTRY ListEntry
Definition: registry.c:37
PCMHIVE DestinationHive
Definition: registry.c:40
PCMHIVE RegistryHive
Definition: registry.c:48
PCMHIVE SourceHive
Definition: registry.c:38
#define malloc
Definition: debug_ros.c:4
#define MEMKEY_TO_HKEY(memKey)
Definition: registry.c:52
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by RegInitializeRegistry().

◆ RegCloseKey()

LONG WINAPI RegCloseKey ( IN HKEY  hKey)

Definition at line 512 of file registry.c.

514 {
515  PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
516 
517  /* Free the object */
518  free(Key);
519 
520  return ERROR_SUCCESS;
521 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define free
Definition: debug_ros.c:5
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by check_user_privs(), CopyKey(), CreateUserHive(), delete_key(), fetch_machine_component(), fetch_machine_product(), fetch_user_component(), fetch_user_product(), get_key_value(), msi_check_product_patches(), MSI_EnumComponentQualifiers(), msi_get_patch_state(), msi_reg_set_subkey_val(), MsiEnumClientsW(), MsiEnumFeaturesW(), MsiEnumPatchesW(), MsiEnumRelatedProductsW(), MSIREG_DeleteClassesUpgradeCodesKey(), MSIREG_DeleteLocalClassesFeaturesKey(), MSIREG_DeleteLocalClassesProductKey(), MSIREG_DeleteProductKey(), MSIREG_DeleteUpgradeCodesKey(), MSIREG_DeleteUserDataComponentKey(), MSIREG_DeleteUserDataPatchKey(), MSIREG_DeleteUserDataProductKey(), RegDeleteKeyW(), RegInitializeRegistry(), registry_read_filelist(), registry_read_formatopts(), registry_read_maximized(), registry_read_options(), registry_read_winrect(), registry_set_filelist(), registry_set_formatopts(), registry_set_options(), test_classesroot(), test_classesroot_enum(), test_classesroot_mask(), test_delete_key_value(), test_deleted_key(), test_enum_value(), test_perflib_key(), test_redirection(), test_reg_close_key(), test_reg_copy_tree(), test_reg_create_key(), test_reg_delete_key(), test_reg_delete_tree(), test_reg_load_key(), test_reg_open_key(), test_reg_query_info(), test_reg_query_value(), test_regconnectregistry(), test_RegNotifyChangeKeyValue(), test_RegOpenCurrentUser(), test_RegQueryValueExPerformanceData(), test_set_value(), test_string_termination(), and test_symlinks().

◆ RegCreateKeyExW()

LONG WINAPI RegCreateKeyExW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey,
IN DWORD  Reserved,
IN LPWSTR lpClass  OPTIONAL,
IN DWORD  dwOptions,
IN REGSAM  samDesired,
IN LPSECURITY_ATTRIBUTES lpSecurityAttributes  OPTIONAL,
OUT PHKEY  phkResult,
OUT LPDWORD lpdwDisposition  OPTIONAL 
)

◆ RegCreateKeyW()

LONG WINAPI RegCreateKeyW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey,
OUT PHKEY  phkResult 
)

Definition at line 524 of file registry.c.

528 {
529  return RegpCreateOrOpenKey(hKey, lpSubKey, TRUE, FALSE, phkResult);
530 }
#define TRUE
Definition: types.h:120
static LONG RegpCreateOrOpenKey(IN HKEY hParentKey, IN PCWSTR KeyName, IN BOOL AllowCreation, IN BOOL Volatile, OUT PHKEY Key)
Definition: registry.c:389

Referenced by msi_reg_set_subkey_val(), MSIREG_OpenUserComponentsKey(), MSIREG_OpenUserPatchesKey(), MSIREG_OpenUserUpgradeCodesKey(), and RegInitializeRegistry().

◆ RegDeleteKeyW()

LONG WINAPI RegDeleteKeyW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey 
)

Definition at line 552 of file registry.c.

555 {
556  LONG rc;
558  HKEY hTargetKey;
559  PMEMKEY Key; // ParentKey
560  PHHIVE Hive;
561  PCM_KEY_NODE KeyNode; // ParentNode
563  HCELL_INDEX ParentCell;
564 
565  if (lpSubKey)
566  {
567  rc = RegOpenKeyW(hKey, lpSubKey, &hTargetKey);
568  if (rc != ERROR_SUCCESS)
569  return rc;
570  }
571  else
572  {
573  hTargetKey = hKey;
574  rc = ERROR_SUCCESS;
575  }
576 
577  /* Don't allow deleting the root */
578  if (hTargetKey == RootKey)
579  {
580  /* Fail */
581  rc = ERROR_ACCESS_DENIED; // STATUS_CANNOT_DELETE;
582  goto Quit;
583  }
584 
585  /* Get the hive and node */
586  Key = HKEY_TO_MEMKEY(hTargetKey);
587  Hive = &Key->RegistryHive->Hive;
588 
589  /* Get the key node */
590  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
591  if (!KeyNode)
592  {
593  rc = ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
594  goto Quit;
595  }
596 
598 
599  /* Check if we don't have any children */
600  if (!(KeyNode->SubKeyCounts[Stable] + KeyNode->SubKeyCounts[Volatile]) &&
601  !(KeyNode->Flags & KEY_NO_DELETE))
602  {
603  /* Get the parent and free the cell */
604  ParentCell = KeyNode->Parent;
605  Status = CmpFreeKeyByCell(Hive, Key->KeyCellOffset, TRUE);
606  if (NT_SUCCESS(Status))
607  {
608  /* Get the parent node */
609  Parent = (PCM_KEY_NODE)HvGetCell(Hive, ParentCell);
610  if (Parent)
611  {
612  /* Make sure we're dirty */
613  ASSERT(HvIsCellDirty(Hive, ParentCell));
614 
615  /* Update the write time */
616  KeQuerySystemTime(&Parent->LastWriteTime);
617 
618  /* Release the cell */
619  HvReleaseCell(Hive, ParentCell);
620  }
621 
622  rc = ERROR_SUCCESS;
623  }
624  else
625  {
626  /* Fail */
627  rc = ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
628  }
629  }
630  else
631  {
632  /* Fail */
633  rc = ERROR_ACCESS_DENIED; // STATUS_CANNOT_DELETE;
634  }
635 
636  /* Release the cell */
637  HvReleaseCell(Hive, Key->KeyCellOffset);
638 
639 Quit:
640  if (lpSubKey)
641  RegCloseKey(hTargetKey);
642 
643  return rc;
644 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
static PMEMKEY RootKey
Definition: registry.c:55
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
LONG NTSTATUS
Definition: precomp.h:26
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:716
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
LONG WINAPI RegOpenKeyW(IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
Definition: registry.c:647
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG HCELL_INDEX
Definition: hivedata.h:80
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
USHORT Signature
Definition: cmdata.h:92
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KEY_NO_DELETE
Definition: cmdata.h:33
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI CmpFreeKeyByCell(IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN Unlink)
Definition: cmkeydel.c:159
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
USHORT Flags
Definition: cmdata.h:93
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by do_reg_operation().

◆ RegDeleteValueW()

LONG WINAPI RegDeleteValueW ( IN HKEY  hKey,
IN LPCWSTR lpValueName  OPTIONAL 
)

Definition at line 901 of file registry.c.

904 {
905  LONG rc;
907  PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
908  PHHIVE Hive = &Key->RegistryHive->Hive;
909  PCM_KEY_NODE KeyNode; // ParentNode
910  PCM_KEY_VALUE ValueCell;
911  HCELL_INDEX CellIndex;
912  ULONG ChildIndex;
913  UNICODE_STRING ValueNameString;
914 
915  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
916  if (!KeyNode)
917  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
918 
920 
921  /* Initialize value name string */
922  RtlInitUnicodeString(&ValueNameString, lpValueName);
923  if (!CmpFindNameInList(Hive,
924  &KeyNode->ValueList,
925  &ValueNameString,
926  &ChildIndex,
927  &CellIndex))
928  {
929  /* Sanity check */
930  ASSERT(CellIndex == HCELL_NIL);
931  }
932  if (CellIndex == HCELL_NIL)
933  {
934  rc = ERROR_FILE_NOT_FOUND; // STATUS_OBJECT_NAME_NOT_FOUND;
935  goto Quit;
936  }
937 
938  /* We found the value, mark all relevant cells dirty */
939  HvMarkCellDirty(Hive, Key->KeyCellOffset, FALSE);
940  HvMarkCellDirty(Hive, KeyNode->ValueList.List, FALSE);
941  HvMarkCellDirty(Hive, CellIndex, FALSE);
942 
943  /* Get the key value */
944  ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
945  ASSERT(ValueCell);
946 
947  /* Mark it and all related data as dirty */
948  if (!CmpMarkValueDataDirty(Hive, ValueCell))
949  {
950  /* Not enough log space, fail */
951  rc = ERROR_NO_LOG_SPACE; // STATUS_NO_LOG_SPACE;
952  goto Quit;
953  }
954 
955  /* Sanity checks */
956  ASSERT(HvIsCellDirty(Hive, KeyNode->ValueList.List));
957  ASSERT(HvIsCellDirty(Hive, CellIndex));
958 
959  /* Remove the value from the child list */
960  Status = CmpRemoveValueFromList(Hive, ChildIndex, &KeyNode->ValueList);
961  if (!NT_SUCCESS(Status))
962  {
963  /* Set known error */
964  rc = ERROR_NO_SYSTEM_RESOURCES; // STATUS_INSUFFICIENT_RESOURCES;
965  goto Quit;
966  }
967 
968  /* Remove the value and its data itself */
969  if (!CmpFreeValue(Hive, CellIndex))
970  {
971  /* Failed to free the value, fail */
972  rc = ERROR_NO_SYSTEM_RESOURCES; // STATUS_INSUFFICIENT_RESOURCES;
973  goto Quit;
974  }
975 
976  /* Set the last write time */
977  KeQuerySystemTime(&KeyNode->LastWriteTime);
978 
979  /* Sanity check */
980  ASSERT(HvIsCellDirty(Hive, Key->KeyCellOffset));
981 
982  /* Check if the value list is empty now */
983  if (!KeyNode->ValueList.Count)
984  {
985  /* Then clear key node data */
986  KeyNode->MaxValueNameLen = 0;
987  KeyNode->MaxValueDataLen = 0;
988  }
989 
990  /* Change default Status to success */
991  rc = ERROR_SUCCESS;
992 
993 Quit:
994  /* Check if we had a value */
995  if (ValueCell)
996  {
997  /* Release the child cell */
998  ASSERT(CellIndex != HCELL_NIL);
999  HvReleaseCell(Hive, CellIndex);
1000  }
1001 
1002  /* Release the parent cell, if any */
1003  if (KeyNode)
1004  HvReleaseCell(Hive, Key->KeyCellOffset);
1005 
1006  return rc;
1007 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
HCELL_INDEX List
Definition: cmdata.h:75
#define ERROR_SUCCESS
Definition: deptool.c:10
ULONG MaxValueNameLen
Definition: cmdata.h:111
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931
NTSTATUS NTAPI CmpRemoveValueFromList(IN PHHIVE Hive, IN ULONG Index, IN OUT PCHILD_LIST ChildList)
Definition: cmvalue.c:320
BOOLEAN NTAPI CmpFreeValue(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmvalue.c:73
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
#define ERROR_NO_LOG_SPACE
Definition: winerror.h:598
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
CHILD_LIST ValueList
Definition: cmdata.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:100
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
ULONG Count
Definition: cmdata.h:74
Status
Definition: gdiplustypes.h:24
struct _CM_KEY_VALUE * PCM_KEY_VALUE
ULONG MaxValueDataLen
Definition: cmdata.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51
BOOLEAN NTAPI CmpMarkValueDataDirty(IN PHHIVE Hive, IN PCM_KEY_VALUE Value)
Definition: cmvalue.c:19

Referenced by do_reg_operation().

◆ RegInitializeRegistry()

VOID RegInitializeRegistry ( IN PCSTR  HiveList)

Definition at line 1134 of file registry.c.

1136 {
1137  NTSTATUS Status;
1138  UINT i;
1139  HKEY ControlSetKey;
1140 
1143 
1145  if (!NT_SUCCESS(Status))
1146  {
1147  DPRINT1("CmiInitializeHive() failed with status 0x%08x\n", Status);
1148  return;
1149  }
1150 
1153 
1154  for (i = 0; i < _countof(RegistryHives); ++i)
1155  {
1156  /* Skip this registry hive if it's not in the list */
1157  if (!strstr(HiveList, RegistryHives[i].HiveName))
1158  continue;
1159 
1160  /* Create the registry key */
1162  RegistryHives[i].HiveRegistryPath,
1166 
1167  /* If we happen to deal with the special setup registry hive, stop there */
1168  // if (strcmp(RegistryHives[i].HiveName, "SETUPREG") == 0)
1169  if (i == 0)
1170  break;
1171  }
1172 
1173  /* Create the 'ControlSet001' key */
1175  L"Registry\\Machine\\SYSTEM\\ControlSet001",
1176  &ControlSetKey);
1177 
1178  /* Create the 'CurrentControlSet' key as a symlink to 'ControlSet001' */
1179  CreateSymLink(L"Registry\\Machine\\SYSTEM\\CurrentControlSet",
1180  NULL, ControlSetKey);
1181 
1182  RegCloseKey(ControlSetKey);
1183 
1184 #if 0
1185  /* Link SECURITY to SAM */
1186  CmpLinkKeyToHive(L"\\Registry\\Machine\\Security\\SAM", L"\\Registry\\Machine\\SAM\\SAM");
1187  /* Link S-1-5-18 to .Default */
1188  CmpLinkKeyToHive(L"\\Registry\\User\\S-1-5-18", L"\\Registry\\User\\.Default");
1189 #endif
1190 }
LIST_ENTRY CmiReparsePointsHead
Definition: registry.c:386
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
static PMEMKEY RootKey
Definition: registry.c:55
LIST_ENTRY CmiHiveListHead
Definition: registry.c:385
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define _countof(array)
Definition: fontsub.cpp:30
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
LONG NTSTATUS
Definition: precomp.h:26
LONG WINAPI RegCreateKeyW(IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
Definition: registry.c:524
static BOOL ConnectRegistry(IN HKEY RootKey, IN PCWSTR Path, IN PCMHIVE HiveToConnect, IN PUCHAR SecurityDescriptor, IN ULONG SecurityDescriptorLength)
Definition: registry.c:1011
_In_ ULONG SecurityDescriptorLength
Definition: rtlfuncs.h:1674
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static CMHIVE RootHive
Definition: registry.c:54
smooth NULL
Definition: ftsmooth.c:416
HHIVE Hive
Definition: cm.h:393
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PMEMKEY CreateInMemoryStructure(IN PCMHIVE RegistryHive, IN HCELL_INDEX KeyCellOffset)
Definition: registry.c:370
static const WCHAR L[]
Definition: oid.c:1250
HCELL_INDEX RootCell
Definition: hivedata.h:143
Status
Definition: gdiplustypes.h:24
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static PCMHIVE CmHive
Definition: registry.c:28
unsigned int UINT
Definition: ndis.h:50
NTSTATUS CmiInitializeHive(IN OUT PCMHIVE Hive, IN PCWSTR Name)
Definition: cmi.c:114
HIVE_LIST_ENTRY RegistryHives[]
Definition: registry.c:581
#define DPRINT1
Definition: precomp.h:8
BOOLEAN NTAPI CmpLinkKeyToHive(_In_z_ PCWSTR LinkKeyName, _In_z_ PCWSTR TargetKeyName)
Definition: cmsysini.c:42
static BOOL CreateSymLink(IN PCWSTR LinkKeyPath OPTIONAL, IN OUT PHKEY LinkKeyHandle OPTIONAL, IN HKEY TargetKeyHandle)
Definition: registry.c:1081

◆ RegOpenKeyW()

LONG WINAPI RegOpenKeyW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey,
OUT PHKEY  phkResult 
)

Definition at line 647 of file registry.c.

651 {
652  return RegpCreateOrOpenKey(hKey, lpSubKey, FALSE, FALSE, phkResult);
653 }
static LONG RegpCreateOrOpenKey(IN HKEY hParentKey, IN PCWSTR KeyName, IN BOOL AllowCreation, IN BOOL Volatile, OUT PHKEY Key)
Definition: registry.c:389

Referenced by MSIREG_OpenUserComponentsKey(), MSIREG_OpenUserPatchesKey(), MSIREG_OpenUserUpgradeCodesKey(), and RegDeleteKeyW().

◆ RegpCreateOrOpenKey()

static LONG RegpCreateOrOpenKey ( IN HKEY  hParentKey,
IN PCWSTR  KeyName,
IN BOOL  AllowCreation,
IN BOOL  Volatile,
OUT PHKEY  Key 
)
static

Definition at line 389 of file registry.c.

395 {
397  PWSTR LocalKeyName;
398  PWSTR End;
399  UNICODE_STRING KeyString;
400  PREPARSE_POINT CurrentReparsePoint;
401  PMEMKEY CurrentKey;
402  PCMHIVE ParentRegistryHive;
403  HCELL_INDEX ParentCellOffset;
404  PCM_KEY_NODE ParentKeyCell;
407 
408  DPRINT("RegpCreateOrOpenKey('%S')\n", KeyName);
409 
411  {
412  KeyName++;
413  ParentRegistryHive = RootKey->RegistryHive;
414  ParentCellOffset = RootKey->KeyCellOffset;
415  }
416  else if (hParentKey == NULL)
417  {
418  ParentRegistryHive = RootKey->RegistryHive;
419  ParentCellOffset = RootKey->KeyCellOffset;
420  }
421  else
422  {
423  ParentRegistryHive = HKEY_TO_MEMKEY(hParentKey)->RegistryHive;
424  ParentCellOffset = HKEY_TO_MEMKEY(hParentKey)->KeyCellOffset;
425  }
426 
427  LocalKeyName = (PWSTR)KeyName;
428  for (;;)
429  {
430  End = (PWSTR)strchrW(LocalKeyName, OBJ_NAME_PATH_SEPARATOR);
431  if (End)
432  {
433  KeyString.Buffer = LocalKeyName;
434  KeyString.Length = KeyString.MaximumLength =
435  (USHORT)((ULONG_PTR)End - (ULONG_PTR)LocalKeyName);
436  }
437  else
438  {
439  RtlInitUnicodeString(&KeyString, LocalKeyName);
440  if (KeyString.Length == 0)
441  {
442  /* Trailing path separator: we're done */
443  break;
444  }
445  }
446 
447  ParentKeyCell = (PCM_KEY_NODE)HvGetCell(&ParentRegistryHive->Hive, ParentCellOffset);
448  if (!ParentKeyCell)
449  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
450 
451  VERIFY_KEY_CELL(ParentKeyCell);
452 
453  BlockOffset = CmpFindSubKeyByName(&ParentRegistryHive->Hive, ParentKeyCell, &KeyString);
454  if (BlockOffset != HCELL_NIL)
455  {
457 
458  /* Search for a possible reparse point */
460  while (Ptr != &CmiReparsePointsHead)
461  {
462  CurrentReparsePoint = CONTAINING_RECORD(Ptr, REPARSE_POINT, ListEntry);
463  if (CurrentReparsePoint->SourceHive == ParentRegistryHive &&
464  CurrentReparsePoint->SourceKeyCellOffset == BlockOffset)
465  {
466  ParentRegistryHive = CurrentReparsePoint->DestinationHive;
467  BlockOffset = CurrentReparsePoint->DestinationKeyCellOffset;
468  break;
469  }
470  Ptr = Ptr->Flink;
471  }
472  }
473  else if (AllowCreation) // && (BlockOffset == HCELL_NIL)
474  {
475  Status = CmiAddSubKey(ParentRegistryHive,
476  ParentCellOffset,
477  &KeyString,
478  Volatile,
479  &BlockOffset);
480  }
481  else // if (BlockOffset == HCELL_NIL)
482  {
484  }
485 
486  HvReleaseCell(&ParentRegistryHive->Hive, ParentCellOffset);
487 
488  if (!NT_SUCCESS(Status))
489  {
490  DPRINT("RegpCreateOrOpenKey('%S'): Could not create or open subkey '%.*S', Status 0x%08x\n",
491  KeyName, (int)(KeyString.Length / sizeof(WCHAR)), KeyString.Buffer, Status);
492  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
493  }
494 
495  ParentCellOffset = BlockOffset;
496  if (End)
497  LocalKeyName = End + 1;
498  else
499  break;
500  }
501 
502  CurrentKey = CreateInMemoryStructure(ParentRegistryHive, ParentCellOffset);
503  if (!CurrentKey)
504  return ERROR_NOT_ENOUGH_MEMORY; // STATUS_NO_MEMORY;
505 
506  *Key = MEMKEY_TO_HKEY(CurrentKey);
507 
508  return ERROR_SUCCESS;
509 }
LIST_ENTRY CmiReparsePointsHead
Definition: registry.c:386
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4693
static PMEMKEY RootKey
Definition: registry.c:55
#define ERROR_SUCCESS
Definition: deptool.c:10
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:54
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
HCELL_INDEX DestinationKeyCellOffset
Definition: registry.c:41
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
#define VERIFY_KEY_CELL(key)
Definition: cmi.h:29
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
HCELL_INDEX SourceKeyCellOffset
Definition: registry.c:39
uint32_t ULONG_PTR
Definition: typedefs.h:63
HCELL_INDEX KeyCellOffset
Definition: registry.c:47
#define BlockOffset(V, L)
Definition: cdprocs.h:1660
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
PCMHIVE DestinationHive
Definition: registry.c:40
PCMHIVE RegistryHive
Definition: registry.c:48
PCMHIVE SourceHive
Definition: registry.c:38
static PMEMKEY CreateInMemoryStructure(IN PCMHIVE RegistryHive, IN HCELL_INDEX KeyCellOffset)
Definition: registry.c:370
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ULONG_PTR
Definition: config.h:101
#define MEMKEY_TO_HKEY(memKey)
Definition: registry.c:52
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
return STATUS_SUCCESS
Definition: btrfs.c:2725
HCELL_INDEX NTAPI CmpFindSubKeyByName(IN PHHIVE Hive, IN PCM_KEY_NODE Parent, IN PCUNICODE_STRING SearchName)
Definition: cmindex.c:683
NTSTATUS CmiAddSubKey(IN PCMHIVE RegistryHive, IN HCELL_INDEX ParentKeyCellOffset, IN PCUNICODE_STRING SubKeyName, IN BOOLEAN VolatileKey, OUT HCELL_INDEX *pBlockOffset)
Definition: cmi.c:297
Definition: cm.h:391
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by RegCreateKeyExW(), RegCreateKeyW(), and RegOpenKeyW().

◆ RegQueryValueExW()

LONG WINAPI RegQueryValueExW ( IN HKEY  hKey,
IN LPCWSTR  lpValueName,
IN PULONG  lpReserved,
OUT PULONG lpType  OPTIONAL,
OUT PUCHAR lpData  OPTIONAL,
IN OUT PULONG lpcbData  OPTIONAL 
)

Definition at line 862 of file registry.c.

869 {
870  PMEMKEY ParentKey = HKEY_TO_MEMKEY(hKey);
871  PHHIVE Hive = &ParentKey->RegistryHive->Hive;
872  PCM_KEY_NODE KeyNode;
873  PCM_KEY_VALUE ValueCell;
874  HCELL_INDEX CellIndex;
875  UNICODE_STRING ValueNameString;
876 
877  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, ParentKey->KeyCellOffset);
878  if (!KeyNode)
879  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
880 
882 
883  /* Initialize value name string */
884  RtlInitUnicodeString(&ValueNameString, lpValueName);
885  CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
886  if (CellIndex == HCELL_NIL)
887  return ERROR_FILE_NOT_FOUND; // STATUS_OBJECT_NAME_NOT_FOUND;
888 
889  /* Get the value cell */
890  ValueCell = HvGetCell(Hive, CellIndex);
891  ASSERT(ValueCell != NULL);
892 
893  RepGetValueData(Hive, ValueCell, lpType, lpData, lpcbData);
894 
895  HvReleaseCell(Hive, CellIndex);
896 
897  return ERROR_SUCCESS;
898 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
HCELL_INDEX KeyCellOffset
Definition: registry.c:47
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
static VOID RepGetValueData(IN PHHIVE Hive, IN PCM_KEY_VALUE ValueCell, OUT PULONG Type OPTIONAL, OUT PUCHAR Data OPTIONAL, IN OUT PULONG DataSize OPTIONAL)
Definition: registry.c:824
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PUNICODE_STRING Name)
Definition: cmvalue.c:99
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
PCMHIVE RegistryHive
Definition: registry.c:48
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by _test_hkey_main_Value_W(), do_reg_operation(), msi_reg_get_val_dword(), msi_reg_get_val_str(), QueryRegistryValue(), registry_read_filelist(), registry_read_formatopts(), registry_read_maximized(), registry_read_winrect(), RegQueryDword(), RegQueryValueWithAlloc(), test_RegQueryValueExPerformanceData(), and test_set_value().

◆ RegSetValueExW()

LONG WINAPI RegSetValueExW ( IN HKEY  hKey,
IN LPCWSTR lpValueName  OPTIONAL,
IN ULONG  Reserved,
IN ULONG  dwType,
IN const UCHAR lpData,
IN ULONG  cbData 
)

Definition at line 656 of file registry.c.

663 {
664  PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
665  PHHIVE Hive;
666  PCM_KEY_NODE KeyNode; // ParentNode
667  PCM_KEY_VALUE ValueCell;
668  ULONG ChildIndex;
669  HCELL_INDEX CellIndex;
670  UNICODE_STRING ValueNameString;
671 
672  PVOID DataCell;
673  ULONG DataCellSize;
675 
676  if (dwType == REG_LINK)
677  {
678  PMEMKEY DestKey;
679 
680  /* Special handling of registry links */
681  if (cbData != sizeof(PVOID))
682  return ERROR_INVALID_PARAMETER; // STATUS_INVALID_PARAMETER;
683 
684  DestKey = HKEY_TO_MEMKEY(*(PHKEY)lpData);
685 
686  // FIXME: Add additional checks for the validity of DestKey
687 
688  /* Create the link in registry hive (if applicable) */
689  if (Key->RegistryHive != DestKey->RegistryHive)
690  return ERROR_SUCCESS;
691 
692  DPRINT1("Save link to registry\n");
693  return ERROR_INVALID_FUNCTION; // STATUS_NOT_IMPLEMENTED;
694  }
695 
696  if ((cbData & ~CM_KEY_VALUE_SPECIAL_SIZE) != cbData)
697  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
698 
699  Hive = &Key->RegistryHive->Hive;
700 
701  KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
702  if (!KeyNode)
703  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
704 
706 
707  /* Mark the parent as dirty since we are going to create a new value in it */
708  HvMarkCellDirty(Hive, Key->KeyCellOffset, FALSE);
709 
710  /* Initialize value name string */
711  RtlInitUnicodeString(&ValueNameString, lpValueName);
712  if (!CmpFindNameInList(Hive,
713  &KeyNode->ValueList,
714  &ValueNameString,
715  &ChildIndex,
716  &CellIndex))
717  {
718  /* Sanity check */
719  ASSERT(CellIndex == HCELL_NIL);
720  /* Fail */
722  }
723  if (CellIndex == HCELL_NIL)
724  {
725  /* The value doesn't exist, create a new one */
726  Status = CmiAddValueKey(Key->RegistryHive,
727  KeyNode,
728  ChildIndex,
729  &ValueNameString,
730  &ValueCell,
731  &CellIndex);
732  }
733  else
734  {
735  /* The value already exists, use it. Get the value cell. */
736  ValueCell = HvGetCell(&Key->RegistryHive->Hive, CellIndex);
737  ASSERT(ValueCell != NULL);
739  }
740 
741  // /**/HvReleaseCell(Hive, CellIndex);/**/
742 
743  if (!NT_SUCCESS(Status))
744  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
745 
746  /* Get size of the allocated cell (if any) */
747  if (!(ValueCell->DataLength & CM_KEY_VALUE_SPECIAL_SIZE) &&
748  (ValueCell->DataLength & ~CM_KEY_VALUE_SPECIAL_SIZE) != 0)
749  {
750  DataCell = HvGetCell(Hive, ValueCell->Data);
751  if (!DataCell)
752  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
753 
754  DataCellSize = (ULONG)(-HvGetCellSize(Hive, DataCell));
755  }
756  else
757  {
758  DataCell = NULL;
759  DataCellSize = 0;
760  }
761 
762  if (cbData <= sizeof(HCELL_INDEX))
763  {
764  /* If data size <= sizeof(HCELL_INDEX) then store data in the data offset */
765  DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength);
766  if (DataCell)
767  HvFreeCell(Hive, ValueCell->Data);
768 
769  RtlCopyMemory(&ValueCell->Data, lpData, cbData);
770  ValueCell->DataLength = (cbData | CM_KEY_VALUE_SPECIAL_SIZE);
771  ValueCell->Type = dwType;
772  }
773  else
774  {
775  if (cbData > DataCellSize)
776  {
777  /* New data size is larger than the current, destroy current
778  * data block and allocate a new one. */
779  HCELL_INDEX NewOffset;
780 
781  DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength);
782 
783  NewOffset = HvAllocateCell(Hive, cbData, Stable, HCELL_NIL);
784  if (NewOffset == HCELL_NIL)
785  {
786  DPRINT("HvAllocateCell() has failed!\n");
787  return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
788  }
789 
790  if (DataCell)
791  HvFreeCell(Hive, ValueCell->Data);
792 
793  ValueCell->Data = NewOffset;
794  DataCell = (PVOID)HvGetCell(Hive, NewOffset);
795  }
796 
797  /* Copy new contents to cell */
798  RtlCopyMemory(DataCell, lpData, cbData);
799  ValueCell->DataLength = (cbData & ~CM_KEY_VALUE_SPECIAL_SIZE);
800  ValueCell->Type = dwType;
801  HvMarkCellDirty(Hive, ValueCell->Data, FALSE);
802  }
803 
804  HvMarkCellDirty(Hive, CellIndex, FALSE);
805 
806  /* Check if the maximum value name length changed, update it if so */
807  if (KeyNode->MaxValueNameLen < ValueNameString.Length)
808  KeyNode->MaxValueNameLen = ValueNameString.Length;
809 
810  /* Check if the maximum data length changed, update it if so */
811  if (KeyNode->MaxValueDataLen < cbData)
812  KeyNode->MaxValueDataLen = cbData;
813 
814  /* Save the write time */
815  KeQuerySystemTime(&KeyNode->LastWriteTime);
816 
817  return ERROR_SUCCESS;
818 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
HCELL_INDEX Data
Definition: cmdata.h:127
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
ULONG MaxValueNameLen
Definition: cmdata.h:111
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
static PVOID
Definition: registry.c:44
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
#define CM_KEY_VALUE_SPECIAL_SIZE
Definition: cm.h:73
ULONG DataLength
Definition: cmdata.h:126
NTSTATUS CmiAddValueKey(IN PCMHIVE RegistryHive, IN PCM_KEY_NODE Parent, IN ULONG ChildIndex, IN PCUNICODE_STRING ValueName, OUT PCM_KEY_VALUE *pValueCell, OUT HCELL_INDEX *pValueCellOffset)
Definition: cmi.c:348
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
void DPRINT(...)
Definition: polytest.cpp:61
CHILD_LIST ValueList
Definition: cmdata.h:103
#define REG_LINK
Definition: nt_native.h:1500
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
PCMHIVE RegistryHive
Definition: registry.c:48
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:100
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
LONG CMAPI HvGetCellSize(PHHIVE RegistryHive, PVOID Cell)
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
Status
Definition: gdiplustypes.h:24
ULONG Type
Definition: cmdata.h:128
ULONG MaxValueDataLen
Definition: cmdata.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by CopyKey(), msi_reg_set_val_dword(), msi_reg_set_val_multi_str(), msi_reg_set_val_str(), registry_set_filelist(), registry_set_formatopts(), registry_set_options(), test_enum_value(), and test_set_value().

◆ RegShutdownRegistry()

VOID RegShutdownRegistry ( VOID  )

Definition at line 1193 of file registry.c.

1194 {
1196  PREPARSE_POINT ReparsePoint;
1197 
1198  /* Clean up the reparse points list */
1200  {
1202  ReparsePoint = CONTAINING_RECORD(Entry, REPARSE_POINT, ListEntry);
1203  free(ReparsePoint);
1204  }
1205 
1206  /* FIXME: clean up the complete hive */
1207 
1208  free(RootKey);
1209 }
LIST_ENTRY CmiReparsePointsHead
Definition: registry.c:386
static PMEMKEY RootKey
Definition: registry.c:55
struct _Entry Entry
Definition: kefuncs.h:640
#define free
Definition: debug_ros.c:5
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: typedefs.h:117
base of all file and directory entries
Definition: entries.h:82

Referenced by main().

◆ RepGetValueData()

static VOID RepGetValueData ( IN PHHIVE  Hive,
IN PCM_KEY_VALUE  ValueCell,
OUT PULONG Type  OPTIONAL,
OUT PUCHAR Data  OPTIONAL,
IN OUT PULONG DataSize  OPTIONAL 
)
static

Definition at line 824 of file registry.c.

830 {
832  PVOID DataCell;
833 
834  /* Does the caller want the type? */
835  if (Type != NULL)
836  *Type = ValueCell->Type;
837 
838  /* Does the caller provide DataSize? */
839  if (DataSize != NULL)
840  {
841  // NOTE: CmpValueToData doesn't support big data (the function will
842  // bugcheck if so), FreeLdr is not supposed to read such data.
843  // If big data is needed, use instead CmpGetValueData.
844  // CmpGetValueData(Hive, ValueCell, DataSize, &DataCell, ...);
845  DataCell = CmpValueToData(Hive, ValueCell, &DataLength);
846 
847  /* Does the caller want the data? */
848  if ((Data != NULL) && (*DataSize != 0))
849  {
851  DataCell,
852  min(*DataSize, DataLength));
853  }
854 
855  /* Return the actual data length */
856  *DataSize = DataLength;
857  }
858 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
Type
Definition: Type.h:6
smooth NULL
Definition: ftsmooth.c:416
PCELL_DATA NTAPI CmpValueToData(IN PHHIVE Hive, IN PCM_KEY_VALUE Value, OUT PULONG Length)
Definition: cmvalue.c:167
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4733

Referenced by RegQueryValueExW().

Variable Documentation

◆ BcdHive

CMHIVE BcdHive
static

Definition at line 62 of file registry.c.

Referenced by BiLoadHive().

◆ BcdSecurity

UCHAR BcdSecurity[]
static

Definition at line 75 of file registry.c.

◆ CmiHiveListHead

LIST_ENTRY CmiHiveListHead

Definition at line 385 of file registry.c.

Referenced by CmiInitializeHive(), and RegInitializeRegistry().

◆ CmiReparsePointsHead

LIST_ENTRY CmiReparsePointsHead

◆ DefaultHive

CMHIVE DefaultHive
static

Definition at line 59 of file registry.c.

◆ RegistryHives

HIVE_LIST_ENTRY RegistryHives[]
Initial value:
=
{
{ "SETUPREG", L"Registry\\Machine\\SYSTEM" , &SystemHive , SystemSecurity , sizeof(SystemSecurity) },
{ "SYSTEM" , L"Registry\\Machine\\SYSTEM" , &SystemHive , SystemSecurity , sizeof(SystemSecurity) },
{ "SOFTWARE", L"Registry\\Machine\\SOFTWARE" , &SoftwareHive, SoftwareSecurity, sizeof(SoftwareSecurity) },
{ "DEFAULT" , L"Registry\\User\\.DEFAULT" , &DefaultHive , SystemSecurity , sizeof(SystemSecurity) },
{ "SAM" , L"Registry\\Machine\\SAM" , &SamHive , SystemSecurity , sizeof(SystemSecurity) },
{ "SECURITY", L"Registry\\Machine\\SECURITY" , &SecurityHive, NULL , 0 },
{ "BCD" , L"Registry\\Machine\\BCD00000000", &BcdHive , BcdSecurity , sizeof(BcdSecurity) },
}
static CMHIVE SamHive
Definition: registry.c:60
static UCHAR SoftwareSecurity[]
Definition: registry.c:137
static CMHIVE DefaultHive
Definition: registry.c:59
static CMHIVE SoftwareHive
Definition: registry.c:58
static CMHIVE BcdHive
Definition: registry.c:62
smooth NULL
Definition: ftsmooth.c:416
static CMHIVE SecurityHive
Definition: registry.c:61
static UCHAR BcdSecurity[]
Definition: registry.c:75
static const WCHAR L[]
Definition: oid.c:1250
static UCHAR SystemSecurity[]
Definition: registry.c:253
static CMHIVE SystemHive
Definition: registry.c:57

Definition at line 351 of file registry.c.

◆ RootHive

CMHIVE RootHive
static

Definition at line 54 of file registry.c.

Referenced by RegInitializeRegistry().

◆ RootKey

◆ SamHive

CMHIVE SamHive
static

Definition at line 60 of file registry.c.

◆ SecurityHive

CMHIVE SecurityHive
static

Definition at line 61 of file registry.c.

◆ SoftwareHive

CMHIVE SoftwareHive
static

Definition at line 58 of file registry.c.

◆ SoftwareSecurity

UCHAR SoftwareSecurity[]
static

Definition at line 137 of file registry.c.

◆ SystemHive

CMHIVE SystemHive
static

◆ SystemSecurity

UCHAR SystemSecurity[]
static

Definition at line 253 of file registry.c.