ReactOS 0.4.16-dev-306-g647d351
cmkeydel.c File Reference
#include "cmlib.h"
#include <debug.h>
Include dependency graph for cmkeydel.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI CmpMarkKeyDirty (IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN CheckNoSubkeys)
 
BOOLEAN NTAPI CmpFreeKeyBody (IN PHHIVE Hive, IN HCELL_INDEX Cell)
 
NTSTATUS NTAPI CmpFreeKeyByCell (IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN Unlink)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmkeydel.c.

Function Documentation

◆ CmpFreeKeyBody()

BOOLEAN NTAPI CmpFreeKeyBody ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell 
)

Definition at line 124 of file cmkeydel.c.

126{
127 PCM_KEY_NODE CellData;
128
129 /* Get the key node */
130 CellData = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
131 ASSERT(CellData);
132
133 /* Check if we can delete the child cells */
134 if (!(CellData->Flags & KEY_HIVE_EXIT))
135 {
136 /* Check if we have a security cell */
137 if (CellData->Security != HCELL_NIL)
138 {
139 /* Free the security cell */
140 HvFreeCell(Hive, CellData->Security);
141 }
142
143 /* Check if we have a class */
144 if (CellData->ClassLength > 0)
145 {
146 /* Free it */
147 HvFreeCell(Hive, CellData->Class);
148 }
149 }
150
151 /* Release and free the cell */
152 HvReleaseCell(Hive, Cell);
153 HvFreeCell(Hive, Cell);
154 return TRUE;
155}
struct _CM_KEY_NODE * PCM_KEY_NODE
#define KEY_HIVE_EXIT
Definition: cmdata.h:31
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:460
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:468
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:457
#define TRUE
Definition: types.h:120
#define HCELL_NIL
Definition: hivedata.h:110
#define ASSERT(a)
Definition: mode.c:44
HCELL_INDEX Security
Definition: cmdata.h:107
USHORT ClassLength
Definition: cmdata.h:115
HCELL_INDEX Class
Definition: cmdata.h:108
USHORT Flags
Definition: cmdata.h:93

Referenced by CmpFreeKeyByCell().

◆ CmpFreeKeyByCell()

NTSTATUS NTAPI CmpFreeKeyByCell ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell,
IN BOOLEAN  Unlink 
)

Definition at line 159 of file cmkeydel.c.

162{
163 PCM_KEY_NODE CellData, ParentData;
164 PCELL_DATA ListData;
165 ULONG i;
167
168 /* Mark the entire key dirty */
169 CmpMarkKeyDirty(Hive, Cell, TRUE);
170
171 /* Get the target node and release it */
172 CellData = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
173 ASSERT(CellData);
174 HvReleaseCell(Hive, Cell);
175
176 /* Make sure we don't have subkeys */
177 ASSERT(CellData->SubKeyCounts[Stable] + CellData->SubKeyCounts[Volatile] == 0);
178
179 /* Check if we have to unlink */
180 if (Unlink)
181 {
182 /* Remove the subkey */
183 Result = CmpRemoveSubKey(Hive, CellData->Parent, Cell);
185
186 /* Get the parent node and release it */
187 ParentData = (PCM_KEY_NODE)HvGetCell(Hive, CellData->Parent);
188 ASSERT(ParentData);
189 HvReleaseCell(Hive, CellData->Parent);
190
191 /* Check if the parent node has no more subkeys */
192 if (ParentData->SubKeyCounts[Stable] + ParentData->SubKeyCounts[Volatile] == 0)
193 {
194 /* Then free the cached name/class lengths */
195 ParentData->MaxNameLen = 0;
196 ParentData->MaxClassLen = 0;
197 }
198 }
199
200 // TODO: Handle predefined keys (Flags: KEY_PREDEF_HANDLE)
201 /* If this is an exit node, we don't have values */
202 if (!(CellData->Flags & KEY_HIVE_EXIT))
203 {
204 /* Check if we have any values */
205 if (CellData->ValueList.Count > 0)
206 {
207 /* Get the value list and release it */
208 ListData = HvGetCell(Hive, CellData->ValueList.List);
209 ASSERT(ListData);
210 HvReleaseCell(Hive, CellData->ValueList.List);
211
212 /* Loop every value */
213 for (i = 0; i < CellData->ValueList.Count; i++)
214 {
215 /* Free it */
216 Result = CmpFreeValue(Hive, ListData->u.KeyList[i]);
217 ASSERT(Result);
218 }
219
220 /* Free the value list */
221 HvFreeCell(Hive, CellData->ValueList.List);
222 }
223
224 /* Free the key security descriptor */
225 CmpFreeSecurityDescriptor(Hive, Cell);
226 }
227
228 /* Free the key body itself, and then return our status */
229 if (!CmpFreeKeyBody(Hive, Cell)) return STATUS_INSUFFICIENT_RESOURCES;
230 return STATUS_SUCCESS;
231}
unsigned char BOOLEAN
BOOLEAN NTAPI CmpRemoveSubKey(IN PHHIVE Hive, IN HCELL_INDEX ParentKey, IN HCELL_INDEX TargetKey)
Definition: cmindex.c:1694
BOOLEAN NTAPI CmpFreeKeyBody(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmkeydel.c:124
BOOLEAN NTAPI CmpMarkKeyDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN CheckNoSubkeys)
Definition: cmkeydel.c:19
BOOLEAN NTAPI CmpFreeValue(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmvalue.c:73
VOID NTAPI CmpFreeSecurityDescriptor(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmse.c:65
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
@ Volatile
Definition: hivedata.h:128
@ Stable
Definition: hivedata.h:127
#define STATUS_SUCCESS
Definition: shellext.h:65
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
union _CELL_DATA::@4304 u
HCELL_INDEX List
Definition: cmdata.h:75
ULONG Count
Definition: cmdata.h:74
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG MaxNameLen
Definition: cmdata.h:109
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
ULONG MaxClassLen
Definition: cmdata.h:110
CHILD_LIST ValueList
Definition: cmdata.h:103
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static int Unlink(const char **args)
Definition: vfdcmd.c:2549
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by BiDeleteKey(), CmDeleteKey(), CmpDoCreate(), CmpUnlinkHiveFromMaster(), and RegDeleteKeyW().

◆ CmpMarkKeyDirty()

BOOLEAN NTAPI CmpMarkKeyDirty ( IN PHHIVE  Hive,
IN HCELL_INDEX  Cell,
IN BOOLEAN  CheckNoSubkeys 
)

Definition at line 19 of file cmkeydel.c.

22{
23 PCM_KEY_NODE CellData;
24 PCM_KEY_SECURITY SecurityData;
25 PCELL_DATA ListData, ValueData;
26 ULONG i;
27
28 /* Get the cell data for our target */
29 CellData = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
30 if (!CellData) return FALSE;
31
32 /* Check if sanity checks requested */
33 if (CheckNoSubkeys)
34 {
35 /* Do them */
36 ASSERT(CellData->SubKeyCounts[Stable] == 0);
37 ASSERT(CellData->SubKeyCounts[Volatile] == 0);
38 }
39
40 /* If this is an exit node, there's nothing to do */
41 if (CellData->Flags & KEY_HIVE_EXIT)
42 {
43 /* Release the cell and get out */
44 HvReleaseCell(Hive, Cell);
45 return TRUE;
46 }
47
48 /* Otherwise, mark it dirty and release it */
49 HvMarkCellDirty(Hive, Cell, FALSE);
50 HvReleaseCell(Hive, Cell);
51
52 /* Check if we have a class */
53 if (CellData->Class != HCELL_NIL)
54 {
55 /* Mark it dirty */
56 HvMarkCellDirty(Hive, CellData->Class, FALSE);
57 }
58
59 /* Check if we have security */
60 if (CellData->Security != HCELL_NIL)
61 {
62 /* Mark it dirty */
63 HvMarkCellDirty(Hive, CellData->Security, FALSE);
64
65 /* Get the security data and release it */
66 SecurityData = (PCM_KEY_SECURITY)HvGetCell(Hive, CellData->Security);
67 ASSERT(SecurityData);
68 HvReleaseCell(Hive, CellData->Security);
69
70 /* Mark the security links dirty too */
71 HvMarkCellDirty(Hive, SecurityData->Flink, FALSE);
72 HvMarkCellDirty(Hive, SecurityData->Blink, FALSE);
73 }
74
75 // TODO: Handle predefined keys (Flags: KEY_PREDEF_HANDLE)
76 /* Check if we have any values */
77 if (CellData->ValueList.Count > 0)
78 {
79 /* Dirty the value list */
80 HvMarkCellDirty(Hive, CellData->ValueList.List, FALSE);
81
82 /* Get the list data itself, and release it */
83 ListData = HvGetCell(Hive, CellData->ValueList.List);
84 ASSERT(ListData);
85 HvReleaseCell(Hive, CellData->ValueList.List);
86
87 /* Loop all values */
88 for (i = 0; i < CellData->ValueList.Count; i++)
89 {
90 /* Dirty each value */
91 HvMarkCellDirty(Hive, ListData->u.KeyList[i], FALSE);
92
93 /* Get the value data and release it */
94 ValueData = HvGetCell(Hive, ListData->u.KeyList[i]);
96 HvReleaseCell(Hive,ListData->u.KeyList[i]);
97
98 /* Mark the value data dirty too */
99 if (!CmpMarkValueDataDirty(Hive, &ValueData->u.KeyValue))
100 {
101 /* Failure */
102 return FALSE;
103 }
104 }
105 }
106
107 /* If this is an entry node, we're done */
108 if (CellData->Flags & KEY_HIVE_ENTRY) return TRUE;
109
110 /* Otherwise mark the index dirty too */
111 if (!CmpMarkIndexDirty(Hive, CellData->Parent, Cell))
112 {
113 /* Failure */
114 return FALSE;
115 }
116
117 /* Finally, mark the parent dirty */
118 HvMarkCellDirty(Hive, CellData->Parent, FALSE);
119 return TRUE;
120}
struct _CM_KEY_SECURITY * PCM_KEY_SECURITY
#define KEY_HIVE_ENTRY
Definition: cmdata.h:32
BOOLEAN NTAPI CmpMarkIndexDirty(IN PHHIVE Hive, IN HCELL_INDEX ParentKey, IN HCELL_INDEX TargetKey)
Definition: cmindex.c:771
BOOLEAN NTAPI CmpMarkValueDataDirty(IN PHHIVE Hive, IN PCM_KEY_VALUE Value)
Definition: cmvalue.c:19
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:109
#define FALSE
Definition: types.h:117
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
HCELL_INDEX Flink
Definition: cmdata.h:141
HCELL_INDEX Blink
Definition: cmdata.h:142

Referenced by CmpFreeKeyByCell().