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.

231 lines
6.2 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Qualifiers.cpp
  4. Content: Implementation of CQualifiers.
  5. History: 11-17-2001 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #include "StdAfx.h"
  8. #include "CAPICOM.h"
  9. #include "Qualifiers.h"
  10. ////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Exported functions.
  13. //
  14. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15. Function : CreateQualifiersObject
  16. Synopsis : Create a qualifiers collection object and populate the collection
  17. with qualifiers from the specified certificate policies.
  18. Parameter: PCERT_POLICY_INFO pCertPolicyInfo - Pointer to CERT_POLICY_INFO.
  19. IQualifiers ** ppIQualifiers - Pointer to pointer IQualifiers
  20. object.
  21. Remark :
  22. ------------------------------------------------------------------------------*/
  23. HRESULT CreateQualifiersObject (PCERT_POLICY_INFO pCertPolicyInfo,
  24. IQualifiers ** ppIQualifiers)
  25. {
  26. HRESULT hr = S_OK;
  27. CComObject<CQualifiers> * pCQualifiers = NULL;
  28. DebugTrace("Entering CreateQualifiersObject().\n");
  29. //
  30. // Sanity check.
  31. //
  32. ATLASSERT(pCertPolicyInfo);
  33. ATLASSERT(ppIQualifiers);
  34. try
  35. {
  36. //
  37. // Create the object. Note that the ref count will still be 0
  38. // after the object is created.
  39. //
  40. if (FAILED(hr = CComObject<CQualifiers>::CreateInstance(&pCQualifiers)))
  41. {
  42. DebugTrace("Error [%#x]: CComObject<CQualifiers>::CreateInstance() failed.\n", hr);
  43. goto ErrorExit;
  44. }
  45. //
  46. // Initialize object.
  47. //
  48. if (FAILED(hr = pCQualifiers->Init(pCertPolicyInfo)))
  49. {
  50. DebugTrace("Error [%#x]: pCQualifiers->Init() failed.\n", hr);
  51. goto ErrorExit;
  52. }
  53. //
  54. // Return interface pointer to caller.
  55. //
  56. if (FAILED(hr = pCQualifiers->QueryInterface(ppIQualifiers)))
  57. {
  58. DebugTrace("Unexpected error [%#x]: pCQualifiers->QueryInterface() failed.\n", hr);
  59. goto ErrorExit;
  60. }
  61. }
  62. catch(...)
  63. {
  64. hr = E_POINTER;
  65. DebugTrace("Exception: invalid parameter.\n");
  66. goto ErrorExit;
  67. }
  68. CommonExit:
  69. DebugTrace("Leaving CreateQualifiersObject().\n");
  70. return hr;
  71. ErrorExit:
  72. //
  73. // Sanity check.
  74. //
  75. ATLASSERT(FAILED(hr));
  76. if (pCQualifiers)
  77. {
  78. delete pCQualifiers;
  79. }
  80. goto CommonExit;
  81. }
  82. ////////////////////////////////////////////////////////////////////////////////
  83. //
  84. // CQualifiers
  85. //
  86. ////////////////////////////////////////////////////////////////////////////////
  87. //
  88. // Non COM functions.
  89. //
  90. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  91. Function : CQualifiers::Init
  92. Synopsis : Initialize the qualifiers collection object by adding all
  93. individual qualifier object to the collection.
  94. Parameter: PCERT_POLICY_INFO pCertPolicyInfo - Pointer to CERT_POLICY_INFO.
  95. Remark : This method is not part of the COM interface (it is a normal C++
  96. member function). We need it to initialize the object created
  97. internally by us.
  98. Since it is only a normal C++ member function, this function can
  99. only be called from a C++ class pointer, not an interface pointer.
  100. ------------------------------------------------------------------------------*/
  101. STDMETHODIMP CQualifiers::Init (PCERT_POLICY_INFO pCertPolicyInfo)
  102. {
  103. HRESULT hr = S_OK;
  104. DebugTrace("Entering CQualifiers::Init().\n");
  105. //
  106. // Sanity check.
  107. //
  108. ATLASSERT(pCertPolicyInfo);
  109. try
  110. {
  111. //
  112. // Make sure we have room to add.
  113. //
  114. if ((m_coll.size() + pCertPolicyInfo->cPolicyQualifier) > m_coll.max_size())
  115. {
  116. hr = CAPICOM_E_OUT_OF_RESOURCE;
  117. DebugTrace("Error [%#x]: Maximum entries (%#x) reached for Qualifierss collection.\n",
  118. hr, pCertPolicyInfo->cPolicyQualifier);
  119. goto ErrorExit;
  120. }
  121. //
  122. // Add all qualifiers to the map.
  123. //
  124. for (DWORD i = 0; i < pCertPolicyInfo->cPolicyQualifier; i++)
  125. {
  126. CComBSTR bstrIndex;
  127. CComPtr<IQualifier> pIQualifier = NULL;
  128. //
  129. // Create the qualifier object.
  130. //
  131. if (FAILED(hr = ::CreateQualifierObject(&pCertPolicyInfo->rgPolicyQualifier[i],
  132. &pIQualifier)))
  133. {
  134. DebugTrace("Error [%#x]: CreateQualifierObject() failed.\n", hr);
  135. goto ErrorExit;
  136. }
  137. //
  138. // BSTR index of OID.
  139. //
  140. if (!(bstrIndex = pCertPolicyInfo->rgPolicyQualifier[i].pszPolicyQualifierId))
  141. {
  142. hr = E_OUTOFMEMORY;
  143. DebugTrace("Error [%#x]: bstrIndex = pCertPolicyInfo->rgPolicyQualifier[i].pszPolicyQualifierId failed.\n", hr);
  144. goto ErrorExit;
  145. }
  146. //
  147. // Now add object to collection map.
  148. //
  149. // Note that the overloaded = operator for CComPtr will
  150. // automatically AddRef to the object. Also, when the CComPtr
  151. // is deleted (happens when the Remove or map destructor is called),
  152. // the CComPtr destructor will automatically Release the object.
  153. //
  154. m_coll[bstrIndex] = pIQualifier;
  155. }
  156. }
  157. catch(...)
  158. {
  159. hr = E_POINTER;
  160. DebugTrace("Exception: invalid parameter.\n");
  161. goto ErrorExit;
  162. }
  163. CommonExit:
  164. DebugTrace("Leaving CQualifiers::Init().\n");
  165. return hr;
  166. ErrorExit:
  167. //
  168. // Sanity check.
  169. //
  170. ATLASSERT(FAILED(hr));
  171. //
  172. // Free resource.
  173. //
  174. m_coll.clear();
  175. goto CommonExit;
  176. }