Leaked source code of windows server 2003
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.

222 lines
7.1 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  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. const CString& szPolicyOID)
  33. : CObject (),
  34. m_szRegistryKey (szRegistryKey),
  35. m_szValueName (szValueName),
  36. m_szPolicyName (szPolicyName),
  37. m_precedence (precedence),
  38. m_vtType (0),
  39. m_pbyBlob (0),
  40. m_sizeArray (0),
  41. m_bstr (0),
  42. m_szPolicyOID (szPolicyOID)
  43. {
  44. if ( szValueName.IsEmpty () )
  45. {
  46. // Do nothing, but avoid all the string comparisons
  47. }
  48. // security review 2/22/2002 BryanWal ok
  49. else if ( !_wcsicmp (SAFER_IDS_DESCRIPTION_REGVALUE, szValueName) ||
  50. !_wcsicmp (SAFER_IDS_FRIENDLYNAME_REGVALUE, szValueName) ||
  51. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_FULLY_TRUSTED, szValueName) ||
  52. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_NORMAL_USER, szValueName) ||
  53. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_CONSTRAINED, szValueName) ||
  54. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_UNTRUSTED, szValueName) ||
  55. !_wcsicmp (SAFER_IDS_LEVEL_DESCRIPTION_DISALLOWED, szValueName) )
  56. {
  57. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  58. HRESULT hr = BstrFromVector(pArray, &m_bstr);
  59. if ( SUCCEEDED (hr) )
  60. {
  61. m_vtType = VT_BSTR;
  62. }
  63. }
  64. else if ( !_wcsicmp (SAFER_IDS_LASTMODIFIED_REGVALUE, szValueName) )
  65. {
  66. m_vtType = VT_ARRAY;
  67. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  68. if ( pArray )
  69. {
  70. BYTE HUGEP *pByte = 0;
  71. // Get a pointer to the elements of the array.
  72. HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pByte);
  73. if ( SUCCEEDED (hr) )
  74. {
  75. m_sizeArray = pArray->rgsabound->cElements;
  76. ASSERT (m_sizeArray == sizeof (FILETIME));
  77. if ( m_sizeArray == sizeof (FILETIME) )
  78. {
  79. memcpy (&m_fileTime, pByte, sizeof (m_fileTime));
  80. }
  81. SafeArrayUnaccessData (pArray);
  82. }
  83. }
  84. }
  85. else if ( !_wcsicmp (STR_BLOBCOUNT, szValueName) ||
  86. !_wcsicmp (STR_BLOBLENGTH, szValueName) ||
  87. !_wcsicmp (CERT_PROT_ROOT_FLAGS_VALUE_NAME, szValueName) ||
  88. !_wcsicmp (AUTO_ENROLLMENT_POLICY, szValueName) ||
  89. !_wcsicmp (SAFER_IDS_SAFERFLAGS_REGVALUE, szValueName) ||
  90. !_wcsicmp (CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME, szValueName) ||
  91. !_wcsicmp (SAFER_TRANSPARENTENABLED_REGVALUE, szValueName) ||
  92. !_wcsicmp (SAFER_VALUE_NAME_HASH_SIZE, szValueName) ||
  93. !_wcsicmp (SAFER_VALUE_NAME_DEFAULT_LEVEL, szValueName) ||
  94. !_wcsicmp (EFS_SETTINGS_REGVALUE, szValueName) ||
  95. !_wcsicmp (SAFER_POLICY_SCOPE, szValueName) )
  96. {
  97. m_vtType = VT_I4;
  98. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  99. if ( pArray )
  100. {
  101. BYTE HUGEP *pByte = 0;
  102. // Get a pointer to the elements of the array.
  103. HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pByte);
  104. if ( SUCCEEDED(hr) )
  105. {
  106. ASSERT (pArray->rgsabound->cElements == sizeof (m_dwValue));
  107. if ( pArray->rgsabound->cElements == sizeof (m_dwValue) )
  108. {
  109. // security review 2/22/2002 BryanWal ok
  110. memcpy (&m_dwValue, pByte, sizeof (m_dwValue));
  111. }
  112. SafeArrayUnaccessData (pArray);
  113. }
  114. }
  115. }
  116. else if ( !wcsncmp (STR_BLOB, szValueName, wcslen (STR_BLOB)) ||
  117. !_wcsicmp (SAFER_IDS_ITEMDATA_REGVALUE, szValueName) ||
  118. !_wcsicmp (SAFER_IDS_ITEMSIZE_REGVALUE, szValueName) ||
  119. !_wcsicmp (SAFER_IDS_HASHALG_REGVALUE, szValueName) ||
  120. !_wcsicmp (SAFER_EXETYPES_REGVALUE, szValueName) )
  121. {
  122. // Blob, Blob0, Blob1, etc.
  123. m_vtType = VT_ARRAY;
  124. SAFEARRAY* pArray = (SAFEARRAY*) varValue.parray;
  125. if ( pArray )
  126. {
  127. BYTE HUGEP *pByte = 0;
  128. // Get a pointer to the elements of the array.
  129. HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pByte);
  130. if ( SUCCEEDED (hr) )
  131. {
  132. m_sizeArray = pArray->rgsabound->cElements;
  133. m_pbyBlob = new BYTE[m_sizeArray];
  134. if ( m_pbyBlob )
  135. {
  136. // security review 2/22/2002 BryanWal ok
  137. memcpy (m_pbyBlob, pByte, m_sizeArray);
  138. }
  139. SafeArrayUnaccessData (pArray);
  140. }
  141. }
  142. }
  143. else if ( !_wcsicmp (CERT_EFSBLOB_VALUE_NAME, szValueName) )
  144. {
  145. }
  146. else
  147. {
  148. _TRACE (0, L"CRSOPObject::CRSOPObject (): Value unaccounted for: %s\n",
  149. szValueName);
  150. }
  151. }
  152. CRSOPObject::CRSOPObject (const CRSOPObject& rObject)
  153. :
  154. m_szRegistryKey (rObject.m_szRegistryKey),
  155. m_szValueName (rObject.m_szValueName),
  156. m_szPolicyName (rObject.m_szPolicyName),
  157. m_precedence (rObject.m_precedence),
  158. m_vtType (rObject.m_vtType),
  159. m_pbyBlob (0),
  160. m_sizeArray (rObject.m_sizeArray),
  161. m_bstr (0),
  162. m_szPolicyOID (rObject.m_szPolicyOID)
  163. {
  164. ASSERT (!m_szRegistryKey.IsEmpty ());
  165. ASSERT (!m_szPolicyName.IsEmpty ());
  166. ASSERT (!m_szPolicyOID.IsEmpty ());
  167. if ( VT_ARRAY == m_vtType )
  168. {
  169. m_pbyBlob = new BYTE[m_sizeArray];
  170. if ( m_pbyBlob )
  171. {
  172. // security review 2/22/2002 BryanWal ok
  173. memcpy (m_pbyBlob, rObject.m_pbyBlob, m_sizeArray);
  174. }
  175. }
  176. else if ( VT_I4 == m_vtType )
  177. {
  178. m_dwValue = rObject.m_dwValue;
  179. }
  180. // security review 2/22/2002 BryanWal ok
  181. memcpy (&m_fileTime, &rObject.m_fileTime, sizeof (m_fileTime));
  182. if ( rObject.m_bstr )
  183. m_bstr = SysAllocString (rObject.m_bstr);
  184. }
  185. CRSOPObject::~CRSOPObject ()
  186. {
  187. if ( VT_ARRAY == m_vtType && m_pbyBlob )
  188. delete [] m_pbyBlob;
  189. if ( m_bstr )
  190. SysFreeString (m_bstr);
  191. }
  192. HRESULT CRSOPObject::GetBSTR (BSTR* pBstr) const
  193. {
  194. HRESULT hr = S_OK;
  195. if ( pBstr )
  196. {
  197. if ( m_bstr )
  198. *pBstr = SysAllocString ((PCWSTR) m_bstr);
  199. else
  200. hr = E_NOTIMPL;
  201. }
  202. else
  203. hr = E_POINTER;
  204. return hr;
  205. }