ReactOS 0.4.17-dev-301-g9127a53
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)
 

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 77 of file policy.cpp.

Constructor & Destructor Documentation

◆ ~CPolicyCache()

CPolicyCache::~CPolicyCache ( )
inline

Definition at line 80 of file policy.cpp.

81 {
83
86 }
HANDLE m_hGlobalCounter
Definition: policy.cpp:111
PSHPOLICY_RESULT m_pResults
Definition: policy.cpp:115
#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 223 of file policy.cpp.

228{
229 UNREFERENCED_PARAMETER(pcbValue); // Reserved for future use
230
231 // Use caching only when dealing with DWORD value
232 if (pConstraint->wFlags == SRRF_RT_DWORD)
233 {
234 pResult->dwValue = *(PDWORD)pvValue;
235 pResult->state = POLICY_STATE_CACHED;
236 }
237}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
DWORD * PDWORD
Definition: pedump.c:68
@ POLICY_STATE_CACHED
Definition: policy.cpp:25
#define SRRF_RT_DWORD
Definition: shlwapi.h:705
POLICY_STATE state
Definition: policy.cpp:31

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 183 of file policy.cpp.

190{
191 CStringW szFullKey = CStringW(m_pszRootKey) + L"\\" + pszSubKey;
192
193 DWORD cbDataSaved = pcbData ? *pcbData : 0;
194 WORD wFlags = pConstraint->wFlags;
195
196 LSTATUS error = RegGetValueW(HKEY_LOCAL_MACHINE, szFullKey, pszValueName, wFlags, pdwType,
197 pvData, pcbData);
199 {
200 if (pcbData)
201 *pcbData = cbDataSaved;
202 error = RegGetValueW(HKEY_CURRENT_USER, szFullKey, pszValueName, wFlags, pdwType,
203 pvData, pcbData);
204 }
205
206 if (error)
208
209 if (!pvData)
210 return S_OK;
211
212 if (pConstraint->wFlags == SRRF_RT_DWORD && pConstraint->wMinSize == sizeof(DWORD))
213 {
214 DWORD dwValue = *(PDWORD)pvData;
215 if (dwValue < pConstraint->dwMin || pConstraint->dwMax < dwValue)
216 return E_DATATYPE_MISMATCH;
217 }
218
219 return S_OK;
220}
LPCWSTR m_pszRootKey
Definition: policy.cpp:110
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 117 of file policy.cpp.

118 {
120 if (m_nCounterValue != Value)
121 {
124 }
125 }
DWORD m_cItems
Definition: policy.cpp:113
LONG m_nCounterValue
Definition: policy.cpp:112
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 143 of file policy.cpp.

144{
146
147 if (m_cItems == 0)
148 return E_UNEXPECTED;
149
150 UINT iItem;
151 for (iItem = 0; iItem < m_cItems; ++iItem)
152 {
153 if (IsEqualGUID(m_pItems[iItem].rpolid, rpolid))
154 break;
155 }
156
157 if (iItem >= m_cItems)
158 return E_UNEXPECTED;
159
160 const SHPOLICY_ITEM *pItem = &m_pItems[iItem];
161 PSHPOLICY_RESULT pResult = &m_pResults[iItem];
162
163 if (pResult->state == POLICY_STATE_NOT_FOUND)
165
166 // Use caching only when dealing with DWORD value
167 if (pvValue && pcbValue && *pcbValue == sizeof(DWORD) && pResult->state == POLICY_STATE_CACHED)
168 {
169 *(PDWORD)pvValue = pResult->dwValue;
170 return S_OK;
171 }
172
173 HRESULT hr = _GetValue(pItem->pszKeyName, pItem->pszValueName, pItem->pConstraint, NULL,
174 pvValue, pcbValue);
176 pResult->state = POLICY_STATE_NOT_FOUND;
177 else if (SUCCEEDED(hr) && pvValue)
178 _CacheResult(pItem->pConstraint, pvValue, pcbValue, pResult);
179
180 return hr;
181}
void _ValidateCachedResults()
Definition: policy.cpp:117
const SHPOLICY_ITEM * m_pItems
Definition: policy.cpp:114
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:183
static void _CacheResult(const SHPOLICY_CONSTRAINT *pConstraint, PVOID pvValue, PDWORD pcbValue, PSHPOLICY_RESULT pResult)
Definition: policy.cpp:223
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:24
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
PCWSTR pszValueName
Definition: policy.cpp:54
const SHPOLICY_CONSTRAINT * pConstraint
Definition: policy.cpp:55
PCWSTR pszKeyName
Definition: policy.cpp:53
#define E_UNEXPECTED
Definition: winerror.h:3528

Referenced by SHWindowsPolicyGetValue().

◆ Initialize()

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

Definition at line 88 of file policy.cpp.

89 {
91 m_pszRootKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies";
93 m_cItems = cItems;
95 if (!m_pResults)
96 return FALSE;
97 m_hGlobalCounter = SHGlobalCounterCreate(GUID_Restrictions);
99 {
102 return FALSE;
103 }
104 return TRUE;
105 }
#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().

Member Data Documentation

◆ m_cItems

DWORD CPolicyCache::m_cItems
protected

Definition at line 113 of file policy.cpp.

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

◆ m_hGlobalCounter

HANDLE CPolicyCache::m_hGlobalCounter
protected

Definition at line 111 of file policy.cpp.

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

◆ m_nCounterValue

LONG CPolicyCache::m_nCounterValue
protected

Definition at line 112 of file policy.cpp.

Referenced by _ValidateCachedResults(), and Initialize().

◆ m_pItems

const SHPOLICY_ITEM* CPolicyCache::m_pItems
protected

Definition at line 114 of file policy.cpp.

Referenced by GetValue(), and Initialize().

◆ m_pResults

PSHPOLICY_RESULT CPolicyCache::m_pResults
protected

Definition at line 115 of file policy.cpp.

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

◆ m_pszRootKey

LPCWSTR CPolicyCache::m_pszRootKey
protected

Definition at line 110 of file policy.cpp.

Referenced by _GetValue(), and Initialize().


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