Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
6.2 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. // File: RSOPObject.cpp
  8. //
  9. // Contents: Implementation of CRSOPObject
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include <AutoEnr.h>
  14. #include <winsafer.h>
  15. #include <winsaferp.h>
  16. #include <gpedit.h>
  17. #include "RSOPObject.h"
  18. #include "SaferUtil.h"
  19. #ifdef _DEBUG
  20. #ifndef ALPHA
  21. #define new DEBUG_NEW
  22. #endif
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. CRSOPObject::CRSOPObject (
  27. const CString& szRegistryKey,
  28. const CString& szValueName,
  29. const CString& szPolicyName,
  30. UINT precedence,
  31. COleVariant& varValue)
  32. : CObject (),
  33. m_szRegistryKey (szRegistryKey),
  34. m_szValueName (szValueName),
  35. m_szPolicyName (szPolicyName),
  36. m_precedence (precedence),
  37. m_vtType (0),
  38. m_pbyBlob (0),
  39. m_sizeArray (0),
  40. m_bstr (0)
  41. {
  42. if ( szValueName.IsEmpty () )
  43. {
  44. // Do nothing, but avoid all the string comparisons
  45. }
  46. else if ( !_wcsicmp (SAFER_IDS_DESCRIPTION_REGVALUE, szValueName) ||
  47. !_wcsicmp (SAFER_IDS_FRIENDLYNAME_REGVALUE, szValueName) ||
  48. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_FULLY_TRUSTED, szValueName) ||
  49. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_NORMAL_USER, szValueName) ||
  50. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_CONSTRAINED, szValueName) ||
  51. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_UNTRUSTED, szValueName) ||
  52. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_DISALLOWED, szValueName) )
  53. {
  54. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  55. HRESULT hr = BstrFromVector(pArray, &m_bstr);
  56. if ( SUCCEEDED (hr) )
  57. {
  58. m_vtType = VT_BSTR;
  59. }
  60. }
  61. else if ( !_wcsicmp (SAFER_IDS_LASTMODIFIED_REGVALUE, szValueName) )
  62. {
  63. m_vtType = VT_ARRAY;
  64. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  65. if ( pArray )
  66. {
  67. BYTE HUGEP *pByte = 0;
  68. // Get a pointer to the elements of the array.
  69. HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pByte);
  70. if ( SUCCEEDED (hr) )
  71. {
  72. m_sizeArray = pArray->rgsabound->cElements;
  73. ASSERT (m_sizeArray == sizeof (FILETIME));
  74. if ( m_sizeArray == sizeof (FILETIME) )
  75. {
  76. memcpy (&m_fileTime, pByte, m_sizeArray);
  77. }
  78. SafeArrayUnaccessData (pArray);
  79. }
  80. }
  81. }
  82. else if ( !_wcsicmp (STR_BLOBCOUNT, szValueName) ||
  83. !_wcsicmp (STR_BLOBLENGTH, szValueName) ||
  84. !_wcsicmp (CERT_PROT_ROOT_FLAGS_VALUE_NAME, szValueName) ||
  85. !_wcsicmp (AUTO_ENROLLMENT_POLICY, szValueName) ||
  86. !_wcsicmp (SAFER_IDS_SAFERFLAGS_REGVALUE, szValueName) ||
  87. !_wcsicmp (CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME, szValueName) ||
  88. !_wcsicmp (SAFER_TRANSPARENTENABLED_REGVALUE, szValueName) ||
  89. !_wcsicmp (SAFER_VALUE_NAME_HASH_SIZE, szValueName) ||
  90. !_wcsicmp (SAFER_VALUE_NAME_DEFAULT_LEVEL, szValueName) ||
  91. !_wcsicmp (EFS_SETTINGS_REGVALUE, szValueName) ||
  92. !_wcsicmp (SAFER_POLICY_SCOPE, szValueName) )
  93. {
  94. m_vtType = VT_I4;
  95. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  96. if ( pArray )
  97. {
  98. BYTE HUGEP *pByte = 0;
  99. // Get a pointer to the elements of the array.
  100. HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pByte);
  101. if ( SUCCEEDED(hr) )
  102. {
  103. ASSERT (pArray->rgsabound->cElements == sizeof (m_dwValue));
  104. memcpy (&m_dwValue, pByte, pArray->rgsabound->cElements);
  105. SafeArrayUnaccessData (pArray);
  106. }
  107. }
  108. }
  109. else if ( !wcsncmp (STR_BLOB, szValueName, wcslen (STR_BLOB)) ||
  110. !_wcsicmp (SAFER_IDS_ITEMDATA_REGVALUE, szValueName) ||
  111. !_wcsicmp (SAFER_IDS_ITEMSIZE_REGVALUE, szValueName) ||
  112. !_wcsicmp (SAFER_IDS_HASHALG_REGVALUE, szValueName) ||
  113. !_wcsicmp (SAFER_EXETYPES_REGVALUE, szValueName) )
  114. {
  115. // Blob, Blob0, Blob1, etc.
  116. m_vtType = VT_ARRAY;
  117. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  118. if ( pArray )
  119. {
  120. BYTE HUGEP *pByte = 0;
  121. // Get a pointer to the elements of the array.
  122. HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pByte);
  123. if ( SUCCEEDED (hr) )
  124. {
  125. m_sizeArray = pArray->rgsabound->cElements;
  126. m_pbyBlob = new BYTE[m_sizeArray];
  127. if ( m_pbyBlob )
  128. {
  129. memcpy (m_pbyBlob, pByte, m_sizeArray);
  130. }
  131. SafeArrayUnaccessData (pArray);
  132. }
  133. }
  134. }
  135. else if ( !_wcsicmp (CERT_EFSBLOB_VALUE_NAME, szValueName) )
  136. {
  137. }
  138. else
  139. {
  140. ASSERT (0);
  141. }
  142. }
  143. CRSOPObject::CRSOPObject (const CRSOPObject& rObject)
  144. :
  145. m_szRegistryKey (rObject.m_szRegistryKey),
  146. m_szValueName (rObject.m_szValueName),
  147. m_szPolicyName (rObject.m_szPolicyName),
  148. m_precedence (rObject.m_precedence),
  149. m_vtType (rObject.m_vtType),
  150. m_pbyBlob (0),
  151. m_sizeArray (rObject.m_sizeArray),
  152. m_bstr (0)
  153. {
  154. if ( VT_ARRAY == m_vtType )
  155. {
  156. m_pbyBlob = new BYTE[m_sizeArray];
  157. if ( m_pbyBlob )
  158. {
  159. memcpy (m_pbyBlob, rObject.m_pbyBlob, m_sizeArray);
  160. }
  161. }
  162. else if ( VT_I4 == m_vtType )
  163. {
  164. m_dwValue = rObject.m_dwValue;
  165. }
  166. memcpy (&m_fileTime, &rObject.m_fileTime, sizeof (FILETIME));
  167. if ( rObject.m_bstr )
  168. m_bstr = SysAllocString (rObject.m_bstr);
  169. }
  170. CRSOPObject::~CRSOPObject ()
  171. {
  172. if ( VT_ARRAY == m_vtType && m_pbyBlob )
  173. delete [] m_pbyBlob;
  174. if ( m_bstr )
  175. SysFreeString (m_bstr);
  176. }
  177. HRESULT CRSOPObject::GetBSTR (BSTR* pBstr) const
  178. {
  179. HRESULT hr = S_OK;
  180. if ( pBstr )
  181. {
  182. if ( m_bstr )
  183. *pBstr = SysAllocString ((PCWSTR) m_bstr);
  184. else
  185. hr = E_NOTIMPL;
  186. }
  187. else
  188. hr = E_POINTER;
  189. return hr;
  190. }