ReactOS 0.4.17-dev-218-g5635d24
CPolicyCache Class Reference
Collaboration diagram for CPolicyCache:

Public Member Functions

 ~CPolicyCache ()
 
BOOL Initialize (const SHPOLICY_ITEM *pItems, UINT cItems)
 
HRESULT GetValue (_In_ REFGUID rpolid, _Out_opt_ PVOID pvValue, _Out_opt_ PDWORD pcbValue)
 

Static Public Member Functions

static voidoperator new (size_t size)
 
static void operator delete (void *ptr)
 

Protected Member Functions

void _ValidateCachedResults ()
 
HRESULT _GetValue (_In_ LPCWSTR pszSubKey, _In_ LPCWSTR pszValueName, _In_ const SHPOLICY_CONSTRAINT *pConstraint, _Out_opt_ PDWORD pdwType, _Out_opt_ PVOID pvData, _Inout_opt_ PDWORD pcbData)
 

Static Protected Member Functions

static void _CacheResult (const SHPOLICY_CONSTRAINT *pConstraint, PVOID pvValue, PDWORD pcbValue, PSHPOLICY_RESULT pResult)
 

Protected Attributes

LPCWSTR m_pszRootKey
 
HANDLE m_hGlobalCounter
 
LONG m_nCounterValue
 
DWORD m_cItems
 
const SHPOLICY_ITEMm_pItems
 
PSHPOLICY_RESULT m_pResults
 

Detailed Description

Definition at line 76 of file policy.cpp.

Constructor & Destructor Documentation

◆ ~CPolicyCache()

CPolicyCache::~CPolicyCache ( )
inline

Definition at line 79 of file policy.cpp.

80 {
82
85 }
HANDLE m_hGlobalCounter
Definition: policy.cpp:121
PSHPOLICY_RESULT m_pResults
Definition: policy.cpp:125
#define CloseHandle
Definition: compat.h:739
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594

Member Function Documentation

◆ _CacheResult()

void CPolicyCache::_CacheResult ( const SHPOLICY_CONSTRAINT pConstraint,
PVOID  pvValue,
PDWORD  pcbValue,
PSHPOLICY_RESULT  pResult 
)
staticprotected

Definition at line 233 of file policy.cpp.

238{
239 UNREFERENCED_PARAMETER(pcbValue); // Reserved for future use
240
241 // Use caching only when dealing with DWORD value
242 if (pConstraint->wFlags == SRRF_RT_DWORD)
243 {
244 pResult->dwValue = *(PDWORD)pvValue;
245 pResult->state = POLICY_STATE_CACHED;
246 }
247}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
DWORD * PDWORD
Definition: pedump.c:68
@ POLICY_STATE_CACHED
Definition: policy.cpp:24
#define SRRF_RT_DWORD
Definition: shlwapi.h:705
POLICY_STATE state
Definition: policy.cpp:30

Referenced by GetValue().

◆ _GetValue()

HRESULT CPolicyCache::_GetValue ( _In_ LPCWSTR  pszSubKey,
_In_ LPCWSTR  pszValueName,
_In_ const SHPOLICY_CONSTRAINT pConstraint,
_Out_opt_ PDWORD  pdwType,
_Out_opt_ PVOID  pvData,
_Inout_opt_ PDWORD  pcbData 
)
protected

Definition at line 193 of file policy.cpp.

200{
201 CStringW szFullKey = CStringW(m_pszRootKey) + L"\\" + pszSubKey;
202
203 DWORD cbDataSaved = pcbData ? *pcbData : 0;
204 WORD wFlags = pConstraint->wFlags;
205
206 LSTATUS error = RegGetValueW(HKEY_LOCAL_MACHINE, szFullKey, pszValueName, wFlags, pdwType,
207 pvData, pcbData);
209 {
210 if (pcbData)
211 *pcbData = cbDataSaved;
212 error = RegGetValueW(HKEY_CURRENT_USER, szFullKey, pszValueName, wFlags, pdwType,
213 pvData, pcbData);
214 }
215
216 if (error)
218
219 if (!pvData)
220 return S_OK;
221
222 if (pConstraint->wFlags == SRRF_RT_DWORD && pConstraint->wMinSize == sizeof(DWORD))
223 {
224 DWORD dwValue = *(PDWORD)pvData;
225 if (dwValue < pConstraint->dwMin || pConstraint->dwMax < dwValue)
226 return E_DATATYPE_MISMATCH;
227 }
228
229 return S_OK;
230}
LPCWSTR m_pszRootKey
Definition: policy.cpp:120
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
#define L(x)
Definition: resources.c:13
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define error(str)
Definition: mkdosfs.c:1605
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
CAtlStringW CStringW
Definition: atlstr.h:130
_In_ LPWSTR _In_ DWORD _In_ LPCVOID pvData
Definition: netsh.h:116
_In_opt_ LPCSTR _In_opt_ LPCSTR _In_ SRRF _Out_opt_ LPDWORD pdwType
Definition: shlwapi.h:783
_In_ _Out_writes_opt_ pcchValueName _Inout_opt_ LPDWORD _Out_opt_ _Out_writes_bytes_to_opt_ pcbData _Inout_opt_ LPDWORD pcbData
Definition: shlwapi.h:757
_In_opt_ LPCSTR pszSubKey
Definition: shlwapi.h:783
#define E_DATATYPE_MISMATCH
WINBASEAPI _In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon_undoc.h:337
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by GetValue().

◆ _ValidateCachedResults()

void CPolicyCache::_ValidateCachedResults ( )
inlineprotected

Definition at line 127 of file policy.cpp.

128 {
130 if (m_nCounterValue != Value)
131 {
134 }
135 }
DWORD m_cItems
Definition: policy.cpp:123
LONG m_nCounterValue
Definition: policy.cpp:122
LONG WINAPI SHGlobalCounterGetValue(HANDLE hSem)
Definition: thread.c:432
#define ZeroMemory
Definition: minwinbase.h:31
long LONG
Definition: pedump.c:60
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by GetValue().

◆ GetValue()

HRESULT CPolicyCache::GetValue ( _In_ REFGUID  rpolid,
_Out_opt_ PVOID  pvValue,
_Out_opt_ PDWORD  pcbValue 
)

Definition at line 153 of file policy.cpp.

154{
156
157 if (m_cItems == 0)
158 return E_UNEXPECTED;
159
160 UINT iItem;
161 for (iItem = 0; iItem < m_cItems; ++iItem)
162 {
163 if (IsEqualGUID(m_pItems[iItem].rpolid, rpolid))
164 break;
165 }
166
167 if (iItem >= m_cItems)
168 return E_UNEXPECTED;
169
170 const SHPOLICY_ITEM *pItem = &m_pItems[iItem];
171 PSHPOLICY_RESULT pResult = &m_pResults[iItem];
172
173 if (pResult->state == POLICY_STATE_NOT_FOUND)
175
176 // Use caching only when dealing with DWORD value
177 if (pvValue && pcbValue && *pcbValue == sizeof(DWORD) && pResult->state == POLICY_STATE_CACHED)
178 {
179 *(PDWORD)pvValue = pResult->dwValue;
180 return S_OK;
181 }
182
183 HRESULT hr = _GetValue(pItem->pszKeyName, pItem->pszValueName, pItem->pConstraint, NULL,
184 pvValue, pcbValue);
186 pResult->state = POLICY_STATE_NOT_FOUND;
187 else if (SUCCEEDED(hr) && pvValue)
188 _CacheResult(pItem->pConstraint, pvValue, pcbValue, pResult);
189
190 return hr;
191}
void _ValidateCachedResults()
Definition: policy.cpp:127
const SHPOLICY_ITEM * m_pItems
Definition: policy.cpp:124
HRESULT _GetValue(_In_ LPCWSTR pszSubKey, _In_ LPCWSTR pszValueName, _In_ const SHPOLICY_CONSTRAINT *pConstraint, _Out_opt_ PDWORD pdwType, _Out_opt_ PVOID pvData, _Inout_opt_ PDWORD pcbData)
Definition: policy.cpp:193
static void _CacheResult(const SHPOLICY_CONSTRAINT *pConstraint, PVOID pvValue, PDWORD pcbValue, PSHPOLICY_RESULT pResult)
Definition: policy.cpp:233
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define SUCCEEDED(hr)
Definition: intsafe.h:50
unsigned int UINT
Definition: ndis.h:50
@ POLICY_STATE_NOT_FOUND
Definition: policy.cpp:23
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
PCWSTR pszValueName
Definition: policy.cpp:53
const SHPOLICY_CONSTRAINT * pConstraint
Definition: policy.cpp:54
PCWSTR pszKeyName
Definition: policy.cpp:52
#define E_UNEXPECTED
Definition: winerror.h:3528

Referenced by SHWindowsPolicyGetValue().

◆ Initialize()

BOOL CPolicyCache::Initialize ( const SHPOLICY_ITEM pItems,
UINT  cItems 
)
inline

Definition at line 98 of file policy.cpp.

99 {
101 m_pszRootKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies";
103 m_cItems = cItems;
105 if (!m_pResults)
106 return FALSE;
107 m_hGlobalCounter = SHGlobalCounterCreate(GUID_Restrictions);
108 if (!m_hGlobalCounter)
109 {
112 return FALSE;
113 }
114 return TRUE;
115 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HANDLE WINAPI SHGlobalCounterCreate(REFGUID guid)
Definition: thread.c:551
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
#define LPTR
Definition: minwinbase.h:93
static int int const SCRIPT_CONTROL const SCRIPT_STATE SCRIPT_ITEM * pItems
Definition: usp10.c:62
struct tagSHPOLICY_RESULT * PSHPOLICY_RESULT
#define MINLONG
Definition: umtypes.h:115

Referenced by SHPolicyCache_Create().

◆ operator delete()

static void CPolicyCache::operator delete ( void ptr)
inlinestatic

Definition at line 93 of file policy.cpp.

94 {
96 }
static PVOID ptr
Definition: dispmode.c:27

◆ operator new()

static void * CPolicyCache::operator new ( size_t  size)
inlinestatic

Definition at line 87 of file policy.cpp.

88 {
89 // Returns NULL on failure; caller must check before use.
90 // NOTE: C++ UB if constructor runs on NULL, but ReactOS convention.
91 return LocalAlloc(LPTR, size);
92 }
GLsizeiptr size
Definition: glext.h:5919

Member Data Documentation

◆ m_cItems

DWORD CPolicyCache::m_cItems
protected

Definition at line 123 of file policy.cpp.

Referenced by _ValidateCachedResults(), GetValue(), and Initialize().

◆ m_hGlobalCounter

HANDLE CPolicyCache::m_hGlobalCounter
protected

Definition at line 121 of file policy.cpp.

Referenced by _ValidateCachedResults(), Initialize(), and ~CPolicyCache().

◆ m_nCounterValue

LONG CPolicyCache::m_nCounterValue
protected

Definition at line 122 of file policy.cpp.

Referenced by _ValidateCachedResults(), and Initialize().

◆ m_pItems

const SHPOLICY_ITEM* CPolicyCache::m_pItems
protected

Definition at line 124 of file policy.cpp.

Referenced by GetValue(), and Initialize().

◆ m_pResults

PSHPOLICY_RESULT CPolicyCache::m_pResults
protected

Definition at line 125 of file policy.cpp.

Referenced by _ValidateCachedResults(), GetValue(), Initialize(), and ~CPolicyCache().

◆ m_pszRootKey

LPCWSTR CPolicyCache::m_pszRootKey
protected

Definition at line 120 of file policy.cpp.

Referenced by _GetValue(), and Initialize().


The documentation for this class was generated from the following file: