ReactOS  0.4.13-dev-961-g238ea69
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 
17 VOID
18 NTAPI
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 = HvGetCell(Hive, SecurityCell);
29  if (!SecurityData) return;
30 
31  FlinkCell = HvGetCell(Hive, SecurityData->Flink);
32  if (!FlinkCell)
33  {
34  HvReleaseCell(Hive, SecurityCell);
35  return;
36  }
37 
38  BlinkCell = 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 
63 VOID
64 NTAPI
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 = 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 = HvGetCell(Hive, CellData->Security);
93  if (!SecurityData)
94  {
95  HvReleaseCell(Hive, Cell);
96  return;
97  }
98 
99  ASSERT(SecurityData->Signature == CM_KEY_SECURITY_SIGNATURE);
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 IN
Definition: typedefs.h:38
#define CM_KEY_SECURITY_SIGNATURE
Definition: cmdata.h:23
#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 Flink
Definition: cmdata.h:141
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
void DPRINT(...)
Definition: polytest.cpp:61
ULONG ReferenceCount
Definition: cmdata.h:143
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
Definition: bzip2.c:1694
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
VOID NTAPI CmpFreeSecurityDescriptor(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmse.c:65
HCELL_INDEX Security
Definition: cmdata.h:107
VOID NTAPI CmpRemoveSecurityCellList(IN PHHIVE Hive, IN HCELL_INDEX SecurityCell)
Definition: cmse.c:19
USHORT Signature
Definition: cmdata.h:139
HCELL_INDEX Blink
Definition: cmdata.h:142