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.

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