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.

253 lines
5.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: prop2.cpp
  8. //
  9. // Contents: ICertAdmin2 & ICertRequest2 IDispatch helper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #if defined(CCERTADMIN)
  13. # define CAPropWrapper(IFAdmin, IFRequest, Method) IFAdmin##_##Method
  14. # define ICertProp2 ICertAdmin2
  15. # define szICertProp2 "ICertAdmin2"
  16. #elif defined(CCERTREQUEST)
  17. # define CAPropWrapper(IFAdmin, IFRequest, Method) IFRequest##_##Method
  18. # define ICertProp2 ICertRequest2
  19. # define szICertProp2 "ICertRequest2"
  20. #else
  21. # error -- CCERTADMIN or CCERTREQUEST must be defined
  22. #endif
  23. #define szInvokeICertProp2(szMethod) "Invoke(" szICertProp2 "::" szMethod ")"
  24. HRESULT
  25. CAPropWrapper(Admin2, Request2, GetCAProperty)(
  26. IN DISPATCHINTERFACE *pdiProp,
  27. IN WCHAR const *pwszConfig,
  28. IN LONG PropId,
  29. IN LONG PropIndex,
  30. IN LONG PropType,
  31. IN LONG Flags, // CR_OUT_*
  32. OUT VOID *pPropertyValue)
  33. {
  34. HRESULT hr;
  35. BSTR strConfig = NULL;
  36. LONG RetType;
  37. VARIANT varResult;
  38. VariantInit(&varResult);
  39. CSASSERT(NULL != pdiProp && NULL != pdiProp->pDispatchTable);
  40. switch (PropType)
  41. {
  42. case PROPTYPE_BINARY:
  43. case PROPTYPE_STRING:
  44. RetType = VT_BSTR;
  45. break;
  46. case PROPTYPE_DATE:
  47. RetType = VT_DATE;
  48. break;
  49. case PROPTYPE_LONG:
  50. RetType = VT_I4;
  51. break;
  52. default:
  53. hr = E_INVALIDARG;
  54. _JumpError(hr, error, "PropType");
  55. }
  56. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  57. {
  58. hr = E_OUTOFMEMORY;
  59. _JumpError(hr, error, "ConvertWszToBstr");
  60. }
  61. if (NULL != pdiProp->pDispatch)
  62. {
  63. VARIANT avar[5];
  64. avar[0].vt = VT_BSTR;
  65. avar[0].bstrVal = strConfig;
  66. avar[1].vt = VT_I4;
  67. avar[1].lVal = PropId;
  68. avar[2].vt = VT_I4;
  69. avar[2].lVal = PropIndex;
  70. avar[3].vt = VT_I4;
  71. avar[3].lVal = PropType;
  72. avar[4].vt = VT_I4;
  73. avar[4].lVal = Flags;
  74. hr = DispatchInvoke(
  75. pdiProp,
  76. CAPropWrapper(ADMIN2, REQUEST2, GETCAPROPERTY),
  77. ARRAYSIZE(avar),
  78. avar,
  79. RetType,
  80. pPropertyValue);
  81. if (S_OK != hr)
  82. {
  83. DBGPRINT((
  84. DBG_SS_CERTLIB,
  85. "%hs: Config=%ws PropId=%x Index=%x Type=%x Flags=%x\n",
  86. szInvokeICertProp2("GetCAProperty"),
  87. pwszConfig,
  88. PropId,
  89. PropIndex,
  90. PropType,
  91. Flags));
  92. }
  93. _JumpIfError(hr, error, szInvokeICertProp2("GetCAProperty"));
  94. }
  95. else
  96. {
  97. hr = ((ICertProp2 *) pdiProp->pUnknown)->GetCAProperty(
  98. strConfig,
  99. PropId,
  100. PropIndex,
  101. PropType,
  102. Flags,
  103. &varResult);
  104. _JumpIfError3(
  105. hr,
  106. error,
  107. szICertProp2 "::GetCAProperty",
  108. HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
  109. E_INVALIDARG);
  110. hr = DispatchGetReturnValue(&varResult, RetType, pPropertyValue);
  111. _JumpIfError(hr, error, "DispatchGetReturnValue");
  112. }
  113. error:
  114. if (NULL != strConfig)
  115. {
  116. SysFreeString(strConfig);
  117. }
  118. VariantClear(&varResult);
  119. return(hr);
  120. }
  121. HRESULT
  122. CAPropWrapper(Admin2, Request2, GetCAPropertyFlags)(
  123. IN DISPATCHINTERFACE *pdiProp,
  124. IN WCHAR const *pwszConfig,
  125. IN LONG PropId,
  126. OUT LONG *pPropFlags)
  127. {
  128. HRESULT hr;
  129. BSTR strConfig = NULL;
  130. CSASSERT(NULL != pdiProp && NULL != pdiProp->pDispatchTable);
  131. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  132. {
  133. hr = E_OUTOFMEMORY;
  134. _JumpError(hr, error, "ConvertWszToBstr");
  135. }
  136. if (NULL != pdiProp->pDispatch)
  137. {
  138. VARIANT avar[2];
  139. avar[0].vt = VT_BSTR;
  140. avar[0].bstrVal = strConfig;
  141. avar[1].vt = VT_I4;
  142. avar[1].lVal = PropId;
  143. hr = DispatchInvoke(
  144. pdiProp,
  145. CAPropWrapper(ADMIN2, REQUEST2, GETCAPROPERTYFLAGS),
  146. ARRAYSIZE(avar),
  147. avar,
  148. VT_I4,
  149. pPropFlags);
  150. _JumpIfError(hr, error, szInvokeICertProp2("GetCAPropertyFlags"));
  151. }
  152. else
  153. {
  154. hr = ((ICertProp2 *) pdiProp->pUnknown)->GetCAPropertyFlags(
  155. strConfig,
  156. PropId,
  157. pPropFlags);
  158. _JumpIfError(hr, error, szICertProp2 "::GetCAPropertyFlags");
  159. }
  160. error:
  161. if (NULL != strConfig)
  162. {
  163. SysFreeString(strConfig);
  164. }
  165. return(hr);
  166. }
  167. HRESULT
  168. CAPropWrapper(Admin2, Request2, GetCAPropertyDisplayName)(
  169. IN DISPATCHINTERFACE *pdiProp,
  170. IN WCHAR const *pwszConfig,
  171. IN LONG PropId,
  172. OUT BSTR *pstrDisplayName)
  173. {
  174. HRESULT hr;
  175. BSTR strConfig = NULL;
  176. CSASSERT(NULL != pdiProp && NULL != pdiProp->pDispatchTable);
  177. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  178. {
  179. hr = E_OUTOFMEMORY;
  180. _JumpError(hr, error, "ConvertWszToBstr");
  181. }
  182. if (NULL != pdiProp->pDispatch)
  183. {
  184. VARIANT avar[2];
  185. avar[0].vt = VT_BSTR;
  186. avar[0].bstrVal = strConfig;
  187. avar[1].vt = VT_I4;
  188. avar[1].lVal = PropId;
  189. hr = DispatchInvoke(
  190. pdiProp,
  191. CAPropWrapper(ADMIN2, REQUEST2, GETCAPROPERTYDISPLAYNAME),
  192. ARRAYSIZE(avar),
  193. avar,
  194. VT_BSTR,
  195. pstrDisplayName);
  196. _JumpIfError(hr, error, szInvokeICertProp2("GetCAPropertyDisplayName"));
  197. }
  198. else
  199. {
  200. hr = ((ICertProp2 *) pdiProp->pUnknown)->GetCAPropertyDisplayName(
  201. strConfig,
  202. PropId,
  203. pstrDisplayName);
  204. _JumpIfError(hr, error, szICertProp2 "::GetCAPropertyDisplayName");
  205. }
  206. error:
  207. if (NULL != strConfig)
  208. {
  209. SysFreeString(strConfig);
  210. }
  211. return(hr);
  212. }