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.

429 lines
9.7 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Extension.cpp
  4. Content: Implementation of CExtension.
  5. History: 06-15-2001 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #include "StdAfx.h"
  8. #include "CAPICOM.h"
  9. #include "Extension.h"
  10. #include "OID.h"
  11. #include "EncodedData.h"
  12. ////////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Exported functions.
  15. //
  16. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  17. Function : CreateExtensionObject
  18. Synopsis : Create an IExtension object.
  19. Parameter: PCERT_EXTENSION pCertExtension - Pointer to CERT_EXTENSION to be
  20. used to initialize the IExtension
  21. object.
  22. IExtension ** ppIExtension - Pointer to pointer IExtension object.
  23. Remark :
  24. ------------------------------------------------------------------------------*/
  25. HRESULT CreateExtensionObject (PCERT_EXTENSION pCertExtension,
  26. IExtension ** ppIExtension)
  27. {
  28. HRESULT hr = S_OK;
  29. CComObject<CExtension> * pCExtension = NULL;
  30. DebugTrace("Entering CreateExtensionObject().\n", hr);
  31. //
  32. // Sanity check.
  33. //
  34. ATLASSERT(pCertExtension);
  35. ATLASSERT(ppIExtension);
  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<CExtension>::CreateInstance(&pCExtension)))
  43. {
  44. DebugTrace("Error [%#x]: CComObject<CExtension>::CreateInstance() failed.\n", hr);
  45. goto ErrorExit;
  46. }
  47. //
  48. // Initialize object.
  49. //
  50. if (FAILED(hr = pCExtension->Init(pCertExtension)))
  51. {
  52. DebugTrace("Error [%#x]: pCExtension->Init() failed.\n", hr);
  53. goto ErrorExit;
  54. }
  55. //
  56. // Return interface pointer to caller.
  57. //
  58. if (FAILED(hr = pCExtension->QueryInterface(ppIExtension)))
  59. {
  60. DebugTrace("Error [%#x]: pCExtension->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 CreateExtensionObject().\n");
  72. return hr;
  73. ErrorExit:
  74. //
  75. // Sanity check.
  76. //
  77. ATLASSERT(FAILED(hr));
  78. if (pCExtension)
  79. {
  80. delete pCExtension;
  81. }
  82. goto CommonExit;
  83. }
  84. ////////////////////////////////////////////////////////////////////////////////
  85. //
  86. // CExtension
  87. //
  88. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  89. Function : CExtension::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 CExtension:: get_OID (IOID ** pVal)
  96. {
  97. HRESULT hr = S_OK;
  98. DebugTrace("Entering CExtension::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 CExtension::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 : CExtension::get_IsCritical
  150. Synopsis : Check to see if the extension is marked critical.
  151. Parameter: VARIANT_BOOL * pVal - Pointer to VARIANT_BOOL to receive result.
  152. Remark :
  153. ------------------------------------------------------------------------------*/
  154. STDMETHODIMP CExtension::get_IsCritical (VARIANT_BOOL * pVal)
  155. {
  156. HRESULT hr = S_OK;
  157. DebugTrace("Entering CExtension::get_IsCritical().\n");
  158. try
  159. {
  160. //
  161. // Lock access to this object.
  162. //
  163. m_Lock.Lock();
  164. //
  165. // Check parameters.
  166. //
  167. if (NULL == pVal)
  168. {
  169. hr = E_INVALIDARG;
  170. DebugTrace("Error [%#x]: Parameter pVal is NULL.\n", hr);
  171. goto ErrorExit;
  172. }
  173. //
  174. // Return result.
  175. //
  176. *pVal = m_bIsCritical;
  177. }
  178. catch(...)
  179. {
  180. hr = E_POINTER;
  181. DebugTrace("Exception: invalid parameter.\n");
  182. goto ErrorExit;
  183. }
  184. UnlockExit:
  185. //
  186. // Unlock access to this object.
  187. //
  188. m_Lock.Unlock();
  189. DebugTrace("Leaving CExtension::get_IsCritical().\n");
  190. return hr;
  191. ErrorExit:
  192. //
  193. // Sanity check.
  194. //
  195. ATLASSERT(FAILED(hr));
  196. ReportError(hr);
  197. goto UnlockExit;
  198. }
  199. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  200. Function : CExtension::get_EncodedData
  201. Synopsis : Return the encoded data object.
  202. Parameter: IEncodedData ** pVal - Pointer to pointer to IEncodedData to
  203. receive the interface pointer.
  204. Remark :
  205. ------------------------------------------------------------------------------*/
  206. STDMETHODIMP CExtension::get_EncodedData (IEncodedData ** pVal)
  207. {
  208. HRESULT hr = S_OK;
  209. DebugTrace("Entering CExtension::get_EncodedData().\n");
  210. try
  211. {
  212. //
  213. // Lock access to this object.
  214. //
  215. m_Lock.Lock();
  216. //
  217. // Check parameters.
  218. //
  219. if (NULL == pVal)
  220. {
  221. hr = E_INVALIDARG;
  222. DebugTrace("Error [%#x]: Parameter pVal is NULL.\n", hr);
  223. goto ErrorExit;
  224. }
  225. //
  226. // Sanity check.
  227. //
  228. ATLASSERT(m_pIEncodedData);
  229. //
  230. // Return result.
  231. //
  232. if (FAILED(hr = m_pIEncodedData->QueryInterface(pVal)))
  233. {
  234. DebugTrace("Error [%#x]: m_pIEncodedData->QueryInterface() failed.\n", hr);
  235. goto ErrorExit;
  236. }
  237. }
  238. catch(...)
  239. {
  240. hr = E_POINTER;
  241. DebugTrace("Exception: invalid parameter.\n");
  242. goto ErrorExit;
  243. }
  244. UnlockExit:
  245. //
  246. // Unlock access to this object.
  247. //
  248. m_Lock.Unlock();
  249. DebugTrace("Leaving CExtension::get_EncodedData().\n");
  250. return hr;
  251. ErrorExit:
  252. //
  253. // Sanity check.
  254. //
  255. ATLASSERT(FAILED(hr));
  256. ReportError(hr);
  257. goto UnlockExit;
  258. }
  259. ////////////////////////////////////////////////////////////////////////////////
  260. //
  261. // Private methods.
  262. //
  263. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  264. Function : CExtension::Init
  265. Synopsis : Initialize the object.
  266. Parameter: PCERT_EXTENSION pCertExtension - Pointer to CERT_EXTENSION.
  267. Remark : This method is not part of the COM interface (it is a normal C++
  268. member function). We need it to initialize the object created
  269. internally by us with CERT_EXTENSION.
  270. Since it is only a normal C++ member function, this function can
  271. only be called from a C++ class pointer, not an interface pointer.
  272. ------------------------------------------------------------------------------*/
  273. STDMETHODIMP CExtension::Init (PCERT_EXTENSION pCertExtension)
  274. {
  275. HRESULT hr = S_OK;
  276. CComPtr<IOID> pIOID = NULL;
  277. CComPtr<IEncodedData> pIEncodedData = NULL;
  278. DebugTrace("Entering CExtension::Init().\n");
  279. //
  280. // Sanity check.
  281. //
  282. ATLASSERT(pCertExtension);
  283. //
  284. // Create the embeded OID object.
  285. //
  286. if (FAILED(hr = ::CreateOIDObject(pCertExtension->pszObjId,
  287. TRUE,
  288. &pIOID.p)))
  289. {
  290. DebugTrace("Error [%#x]: CreateOIDObject() failed.\n", hr);
  291. goto ErrorExit;
  292. }
  293. //
  294. // Create the embeded EncodedData object.
  295. //
  296. if (FAILED(hr = ::CreateEncodedDataObject(pCertExtension->pszObjId,
  297. &pCertExtension->Value,
  298. &pIEncodedData)))
  299. {
  300. DebugTrace("Error [%#x]: CreateEncodedDataObject() failed.\n", hr);
  301. goto ErrorExit;
  302. }
  303. //
  304. // Reset.
  305. //
  306. m_bIsCritical = pCertExtension->fCritical ? VARIANT_TRUE : VARIANT_FALSE;
  307. m_pIOID = pIOID;
  308. m_pIEncodedData = pIEncodedData;
  309. CommonExit:
  310. DebugTrace("Leaving CExtension::Init().\n");
  311. return hr;
  312. ErrorExit:
  313. //
  314. // Sanity check.
  315. //
  316. ATLASSERT(FAILED(hr));
  317. goto CommonExit;
  318. }