ReactOS 0.4.15-dev-7842-g558ab78
cmse.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/cmlib/cmse.c
5 * PURPOSE: Configuration Manager Library - Security Subsystem Interface
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "cmlib.h"
12#define NDEBUG
13#include <debug.h>
14
15/* FUNCTIONS *****************************************************************/
16
17VOID
20 IN HCELL_INDEX SecurityCell)
21{
22 PCM_KEY_SECURITY SecurityData, FlinkCell, BlinkCell;
23
24 PAGED_CODE();
25
26 // ASSERT( (((PCMHIVE)Hive)->HiveSecurityLockOwner == KeGetCurrentThread()) || (CmpTestRegistryLockExclusive() == TRUE) );
27
28 SecurityData = (PCM_KEY_SECURITY)HvGetCell(Hive, SecurityCell);
29 if (!SecurityData) return;
30
31 FlinkCell = (PCM_KEY_SECURITY)HvGetCell(Hive, SecurityData->Flink);
32 if (!FlinkCell)
33 {
34 HvReleaseCell(Hive, SecurityCell);
35 return;
36 }
37
38 BlinkCell = (PCM_KEY_SECURITY)HvGetCell(Hive, SecurityData->Blink);
39 if (!BlinkCell)
40 {
41 HvReleaseCell(Hive, SecurityData->Flink);
42 HvReleaseCell(Hive, SecurityCell);
43 return;
44 }
45
46 /* Sanity checks */
47 ASSERT(FlinkCell->Blink == SecurityCell);
48 ASSERT(BlinkCell->Flink == SecurityCell);
49
50 /* Unlink the security block and free it */
51 FlinkCell->Blink = SecurityData->Blink;
52 BlinkCell->Flink = SecurityData->Flink;
53#ifdef USE_CM_CACHE
54 CmpRemoveFromSecurityCache(Hive, SecurityCell);
55#endif
56
57 /* Release the cells */
58 HvReleaseCell(Hive, SecurityData->Blink);
59 HvReleaseCell(Hive, SecurityData->Flink);
60 HvReleaseCell(Hive, SecurityCell);
61}
62
63VOID
66 IN HCELL_INDEX Cell)
67{
68 PCM_KEY_NODE CellData;
69 PCM_KEY_SECURITY SecurityData;
70
71 PAGED_CODE();
72
73 // ASSERT( (((PCMHIVE)Hive)->HiveSecurityLockOwner == KeGetCurrentThread()) || (CmpTestRegistryLockExclusive() == TRUE) );
74
75 CellData = (PCM_KEY_NODE)HvGetCell(Hive, Cell);
76 if (!CellData) return;
77
79
80 // FIXME: ReactOS-specific: check whether this key has a security block.
81 // On Windows there is no such check, all keys seem to have a valid
82 // security block.
83 // If we remove this check on ReactOS (and continue running) then we get
84 // a BSOD at the end...
85 if (CellData->Security == HCELL_NIL)
86 {
87 DPRINT("Cell 0x%08x (data 0x%p) has no security block!\n", Cell, CellData);
88 HvReleaseCell(Hive, Cell);
89 return;
90 }
91
92 SecurityData = (PCM_KEY_SECURITY)HvGetCell(Hive, CellData->Security);
93 if (!SecurityData)
94 {
95 HvReleaseCell(Hive, Cell);
96 return;
97 }
98
100
101 if (SecurityData->ReferenceCount > 1)
102 {
103 SecurityData->ReferenceCount--;
104 }
105 else // if (SecurityData->ReferenceCount <= 1)
106 {
107 CmpRemoveSecurityCellList(Hive, CellData->Security);
108 HvFreeCell(Hive, CellData->Security);
109 }
110
111 CellData->Security = HCELL_NIL;
112 HvReleaseCell(Hive, CellData->Security);
113 HvReleaseCell(Hive, Cell);
114}
#define PAGED_CODE()
struct _CM_KEY_NODE * PCM_KEY_NODE
#define CM_KEY_SECURITY_SIGNATURE
Definition: cmdata.h:23
struct _CM_KEY_SECURITY * PCM_KEY_SECURITY
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:455
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:468
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:452
#define HCELL_NIL
Definition: hivedata.h:110
ULONG HCELL_INDEX
Definition: hivedata.h:105
#define ASSERT(a)
Definition: mode.c:44
VOID NTAPI CmpFreeSecurityDescriptor(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmse.c:65
VOID NTAPI CmpRemoveSecurityCellList(IN PHHIVE Hive, IN HCELL_INDEX SecurityCell)
Definition: cmse.c:19
#define DPRINT
Definition: sndvol32.h:71
USHORT Signature
Definition: cmdata.h:92
HCELL_INDEX Security
Definition: cmdata.h:107
HCELL_INDEX Flink
Definition: cmdata.h:141
ULONG ReferenceCount
Definition: cmdata.h:143
HCELL_INDEX Blink
Definition: cmdata.h:142
USHORT Signature
Definition: cmdata.h:139
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39