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.

370 lines
8.6 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: PolicyInformation.cpp
  4. Content: Implementation of CPolicyInformation.
  5. History: 11-17-2001 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #include "StdAfx.h"
  8. #include "CAPICOM.h"
  9. #include "PolicyInformation.h"
  10. #include "OID.h"
  11. #include "Qualifiers.h"
  12. ////////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Exported functions.
  15. //
  16. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  17. Function : CreatePolicyInformationObject
  18. Synopsis : Create a policy information object.
  19. Parameter: PCERT_POLICY_INFO pCertPolicyInfo - Pointer to CERT_POLICY_INFO.
  20. IPolicyInformation ** ppIPolicyInformation - Pointer to pointer
  21. IPolicyInformation
  22. object.
  23. Remark :
  24. ------------------------------------------------------------------------------*/
  25. HRESULT CreatePolicyInformationObject (PCERT_POLICY_INFO pCertPolicyInfo,
  26. IPolicyInformation ** ppIPolicyInformation)
  27. {
  28. HRESULT hr = S_OK;
  29. CComObject<CPolicyInformation> * pCPolicyInformation = NULL;
  30. DebugTrace("Entering CreatePolicyInformationObject().\n");
  31. //
  32. // Sanity check.
  33. //
  34. ATLASSERT(pCertPolicyInfo);
  35. ATLASSERT(ppIPolicyInformation);
  36. try
  37. {
  38. //
  39. // Create the object. Note that the ref count will still be 0
  40. // after the object is created.
  41. //
  42. if (FAILED(hr = CComObject<CPolicyInformation>::CreateInstance(&pCPolicyInformation)))
  43. {
  44. DebugTrace("Error [%#x]: CComObject<CPolicyInformation>::CreateInstance() failed.\n", hr);
  45. goto ErrorExit;
  46. }
  47. //
  48. // Initialize object.
  49. //
  50. if (FAILED(hr = pCPolicyInformation->Init(pCertPolicyInfo)))
  51. {
  52. DebugTrace("Error [%#x]: pCPolicyInformation->Init() failed.\n", hr);
  53. goto ErrorExit;
  54. }
  55. //
  56. // Return interface pointer to caller.
  57. //
  58. if (FAILED(hr = pCPolicyInformation->QueryInterface(ppIPolicyInformation)))
  59. {
  60. DebugTrace("Unexpected error [%#x]: pCPolicyInformation->QueryInterface() failed.\n", hr);
  61. goto ErrorExit;
  62. }
  63. }
  64. catch(...)
  65. {
  66. hr = E_POINTER;
  67. DebugTrace("Exception: invalid parameter.\n");
  68. goto ErrorExit;
  69. }
  70. CommonExit:
  71. DebugTrace("Leaving CreatePolicyInformationObject().\n");
  72. return hr;
  73. ErrorExit:
  74. //
  75. // Sanity check.
  76. //
  77. ATLASSERT(FAILED(hr));
  78. if (pCPolicyInformation)
  79. {
  80. delete pCPolicyInformation;
  81. }
  82. goto CommonExit;
  83. }
  84. ////////////////////////////////////////////////////////////////////////////////
  85. //
  86. // CPolicyInformation
  87. //
  88. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  89. Function : CPolicyInformation::get_OID
  90. Synopsis :Return the OID object.
  91. Parameter: IOID ** pVal - Pointer to pointer to IOID to receive the interface
  92. pointer.
  93. Remark :
  94. ------------------------------------------------------------------------------*/
  95. STDMETHODIMP CPolicyInformation:: get_OID (IOID ** pVal)
  96. {
  97. HRESULT hr = S_OK;
  98. DebugTrace("Entering CPolicyInformation::get_OID().\n");
  99. try
  100. {
  101. //
  102. // Lock access to this object.
  103. //
  104. m_Lock.Lock();
  105. //
  106. // Check parameters.
  107. //
  108. if (NULL == pVal)
  109. {
  110. hr = E_INVALIDARG;
  111. DebugTrace("Error [%#x]: Parameter pVal is NULL.\n", hr);
  112. goto ErrorExit;
  113. }
  114. //
  115. // Sanity check.
  116. //
  117. ATLASSERT(m_pIOID);
  118. //
  119. // Return result.
  120. //
  121. if (FAILED(hr = m_pIOID->QueryInterface(pVal)))
  122. {
  123. DebugTrace("Error [%#x]: m_pIOID->QueryInterface() failed.\n", hr);
  124. goto ErrorExit;
  125. }
  126. }
  127. catch(...)
  128. {
  129. hr = E_POINTER;
  130. DebugTrace("Exception: invalid parameter.\n");
  131. goto ErrorExit;
  132. }
  133. UnlockExit:
  134. //
  135. // Unlock access to this object.
  136. //
  137. m_Lock.Unlock();
  138. DebugTrace("Leaving CPolicyInformation::get_OID().\n");
  139. return hr;
  140. ErrorExit:
  141. //
  142. // Sanity check.
  143. //
  144. ATLASSERT(FAILED(hr));
  145. ReportError(hr);
  146. goto UnlockExit;
  147. }
  148. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  149. Function : CPolicyInformation::get_Qualifiers
  150. Synopsis :Return the Qualifiers object.
  151. Parameter: IQualifiers ** pVal - Pointer to pointer to IQualifiers to receive
  152. the interface pointer.
  153. Remark :
  154. ------------------------------------------------------------------------------*/
  155. STDMETHODIMP CPolicyInformation:: get_Qualifiers (IQualifiers ** pVal)
  156. {
  157. HRESULT hr = S_OK;
  158. DebugTrace("Entering CPolicyInformation::get_Qualifiers().\n");
  159. try
  160. {
  161. //
  162. // Lock access to this object.
  163. //
  164. m_Lock.Lock();
  165. //
  166. // Check parameters.
  167. //
  168. if (NULL == pVal)
  169. {
  170. hr = E_INVALIDARG;
  171. DebugTrace("Error [%#x]: Parameter pVal is NULL.\n", hr);
  172. goto ErrorExit;
  173. }
  174. //
  175. // Sanity check.
  176. //
  177. ATLASSERT(m_pIQualifiers);
  178. //
  179. // Return result.
  180. //
  181. if (FAILED(hr = m_pIQualifiers->QueryInterface(pVal)))
  182. {
  183. DebugTrace("Error [%#x]: m_pIQualifiers->QueryInterface() failed.\n", hr);
  184. goto ErrorExit;
  185. }
  186. }
  187. catch(...)
  188. {
  189. hr = E_POINTER;
  190. DebugTrace("Exception: invalid parameter.\n");
  191. goto ErrorExit;
  192. }
  193. UnlockExit:
  194. //
  195. // Unlock access to this object.
  196. //
  197. m_Lock.Unlock();
  198. DebugTrace("Leaving CPolicyInformation::get_Qualifiers().\n");
  199. return hr;
  200. ErrorExit:
  201. //
  202. // Sanity check.
  203. //
  204. ATLASSERT(FAILED(hr));
  205. ReportError(hr);
  206. goto UnlockExit;
  207. }
  208. ////////////////////////////////////////////////////////////////////////////////
  209. //
  210. // Non COM functions.
  211. //
  212. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  213. Function : CPolicyInformation::Init
  214. Synopsis : Initialize the PolicyInformation object.
  215. Parameter: PCERT_POLICY_INFO pCertPolicyInfo - Pointer to CERT_POLICY_INFO.
  216. Remark : This method is not part of the COM interface (it is a normal C++
  217. member function). We need it to initialize the object created
  218. internally by us.
  219. Since it is only a normal C++ member function, this function can
  220. only be called from a C++ class pointer, not an interface pointer.
  221. ------------------------------------------------------------------------------*/
  222. STDMETHODIMP CPolicyInformation::Init (PCERT_POLICY_INFO pCertPolicyInfo)
  223. {
  224. HRESULT hr = S_OK;
  225. DebugTrace("Entering CPolicyInformation::Init().\n");
  226. //
  227. // Sanity check.
  228. //
  229. ATLASSERT(pCertPolicyInfo);
  230. try
  231. {
  232. //
  233. // Create the embeded OID object.
  234. //
  235. if (FAILED(hr = ::CreateOIDObject(pCertPolicyInfo->pszPolicyIdentifier, TRUE, &m_pIOID)))
  236. {
  237. DebugTrace("Error [%#x]: CreateOIDObject() failed.\n", hr);
  238. goto ErrorExit;
  239. }
  240. //
  241. // Create the qualifiers object.
  242. //
  243. if (FAILED(hr = ::CreateQualifiersObject(pCertPolicyInfo, &m_pIQualifiers)))
  244. {
  245. DebugTrace("Error [%#x]: CreateQualifiersObject() failed.\n", hr);
  246. goto ErrorExit;
  247. }
  248. }
  249. catch(...)
  250. {
  251. hr = CAPICOM_E_INTERNAL;
  252. DebugTrace("Exception: internal error.\n");
  253. goto ErrorExit;
  254. }
  255. CommonExit:
  256. DebugTrace("Leaving CPolicyInformation::Init().\n");
  257. return hr;
  258. ErrorExit:
  259. //
  260. // Sanity check.
  261. //
  262. ATLASSERT(FAILED(hr));
  263. //
  264. // Free resource.
  265. //
  266. if (m_pIOID)
  267. {
  268. m_pIOID.Release();
  269. }
  270. if (m_pIQualifiers)
  271. {
  272. m_pIQualifiers.Release();
  273. }
  274. goto CommonExit;
  275. }