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.

487 lines
11 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: manage.cpp
  7. //
  8. // Contents: Cert Server Policy & Exit manage module callouts
  9. //
  10. // History: 10-Sept-98 mattt created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include <pch.cpp>
  14. #pragma hdrstop
  15. #include "csdisp.h"
  16. #include "csprop.h"
  17. #define __dwFILE__ __dwFILE_CERTLIB_MANAGE_CPP__
  18. //+-------------------------------------------------------------------------
  19. // IManageModule dispatch support
  20. //+------------------------------------
  21. // GetProperty method:
  22. OLECHAR *managemodule_apszGetProperty[] = {
  23. TEXT("GetProperty"),
  24. TEXT("strConfig"),
  25. TEXT("strStorageLocation"),
  26. TEXT("strPropertyName"),
  27. TEXT("Flags"),
  28. };
  29. //+------------------------------------
  30. // SetProperty method:
  31. OLECHAR *managemodule_apszSetProperty[] = {
  32. TEXT("SetProperty"),
  33. TEXT("strConfig"),
  34. TEXT("strStorageLocation"),
  35. TEXT("strPropertyName"),
  36. TEXT("Flags"),
  37. TEXT("pvarProperty"),
  38. };
  39. //+------------------------------------
  40. // Configure method:
  41. OLECHAR *managemodule_apszConfigure[] = {
  42. TEXT("Configure"),
  43. TEXT("strConfig"),
  44. TEXT("strStorageLocation"),
  45. TEXT("Flags"),
  46. };
  47. //+------------------------------------
  48. // Dispatch Table:
  49. DISPATCHTABLE g_adtManageModule[] =
  50. {
  51. #define MANAGEMODULE_GETPROPERTY 0
  52. DECLARE_DISPATCH_ENTRY(managemodule_apszGetProperty)
  53. #define MANAGEMODULE_SETPROPERTY 1
  54. DECLARE_DISPATCH_ENTRY(managemodule_apszSetProperty)
  55. #define MANAGEMODULE_CONFIGURE 2
  56. DECLARE_DISPATCH_ENTRY(managemodule_apszConfigure)
  57. };
  58. #define CMANAGEMODULEDISPATCH (ARRAYSIZE(g_adtManageModule))
  59. HRESULT
  60. ManageModule_GetProperty(
  61. IN DISPATCHINTERFACE *pdiManage,
  62. IN WCHAR const *pwszConfig,
  63. IN WCHAR const *pwszStorageLocation,
  64. IN WCHAR const *pwszPropertyName,
  65. IN DWORD dwFlags,
  66. IN LONG ColumnType,
  67. OUT VOID *pProperty)
  68. {
  69. HRESULT hr;
  70. BSTR strConfig = NULL;
  71. BSTR strStorageLocation = NULL;
  72. BSTR strPropertyName = NULL;
  73. BOOL fException = FALSE;
  74. ULONG_PTR ExceptionAddress;
  75. LONG RetType;
  76. VARIANT varResult;
  77. VariantInit(&varResult);
  78. CSASSERT(NULL != pdiManage && NULL != pdiManage->pDispatchTable);
  79. hr = E_OUTOFMEMORY;
  80. strConfig = SysAllocString(pwszConfig);
  81. if (NULL == strConfig)
  82. {
  83. _JumpError(hr, error, "SysAllocString");
  84. }
  85. strStorageLocation = SysAllocString(pwszStorageLocation);
  86. if (NULL == strStorageLocation)
  87. {
  88. _JumpError(hr, error, "SysAllocString");
  89. }
  90. strPropertyName = SysAllocString(pwszPropertyName);
  91. if (NULL == strPropertyName)
  92. {
  93. _JumpError(hr, error, "SysAllocString");
  94. }
  95. switch (ColumnType)
  96. {
  97. case PROPTYPE_BINARY:
  98. case PROPTYPE_STRING:
  99. RetType = VT_BSTR;
  100. break;
  101. case PROPTYPE_DATE:
  102. RetType = VT_DATE;
  103. break;
  104. case PROPTYPE_LONG:
  105. RetType = VT_I4;
  106. break;
  107. default:
  108. hr = E_INVALIDARG;
  109. _JumpError(hr, error, "PropertyType");
  110. }
  111. __try
  112. {
  113. if (NULL != pdiManage->pDispatch)
  114. {
  115. VARIANT avar[4];
  116. avar[0].vt = VT_BSTR;
  117. avar[0].bstrVal = strConfig;
  118. avar[1].vt = VT_BSTR;
  119. avar[1].bstrVal = strStorageLocation;
  120. avar[2].vt = VT_BSTR;
  121. avar[2].bstrVal = strPropertyName;
  122. avar[3].vt = VT_I4;
  123. avar[3].lVal = dwFlags;
  124. hr = DispatchInvoke(
  125. pdiManage,
  126. MANAGEMODULE_GETPROPERTY,
  127. ARRAYSIZE(avar),
  128. avar,
  129. RetType,
  130. pProperty);
  131. _JumpIfError(hr, error, "Invoke(GetName)");
  132. }
  133. else
  134. {
  135. hr = ((ICertManageModule *) pdiManage->pUnknown)->GetProperty(
  136. strConfig,
  137. strStorageLocation,
  138. strPropertyName,
  139. dwFlags,
  140. &varResult);
  141. _JumpIfError(hr, error, "ICertManageModule::GetProperty");
  142. hr = DispatchGetReturnValue(&varResult, RetType, pProperty);
  143. _JumpIfError2(hr, error, "DispatchGetReturnValue", CERTSRV_E_PROPERTY_EMPTY);
  144. }
  145. }
  146. __except(
  147. ExceptionAddress = (ULONG_PTR) (GetExceptionInformation())->ExceptionRecord->ExceptionAddress,
  148. hr = myHEXCEPTIONCODE(),
  149. EXCEPTION_EXECUTE_HANDLER)
  150. {
  151. _PrintError(hr, "GetProperty: Exception");
  152. fException = TRUE;
  153. }
  154. error:
  155. if (NULL != strConfig)
  156. {
  157. SysFreeString(strConfig);
  158. }
  159. if (NULL != strStorageLocation)
  160. {
  161. SysFreeString(strStorageLocation);
  162. }
  163. if (NULL != strPropertyName)
  164. {
  165. SysFreeString(strPropertyName);
  166. }
  167. VariantClear(&varResult);
  168. return(hr);
  169. }
  170. HRESULT
  171. ManageModule_SetProperty(
  172. IN DISPATCHINTERFACE *pdiManage,
  173. IN WCHAR const *pwszConfig,
  174. IN WCHAR const *pwszStorageLocation,
  175. IN WCHAR const *pwszPropertyName,
  176. IN DWORD dwFlags,
  177. IN LONG ColumnType,
  178. IN VOID* pProperty)
  179. {
  180. HRESULT hr;
  181. BSTR strConfig = NULL;
  182. BSTR strStorageLocation = NULL;
  183. BSTR strPropertyName = NULL;
  184. BOOL fException = FALSE;
  185. ULONG_PTR ExceptionAddress;
  186. VARIANT varResult;
  187. CSASSERT(NULL != pdiManage && NULL != pdiManage->pDispatchTable);
  188. hr = E_OUTOFMEMORY;
  189. strConfig = SysAllocString(pwszConfig);
  190. if (NULL == strConfig)
  191. {
  192. _JumpError(hr, error, "SysAllocString");
  193. }
  194. strStorageLocation = SysAllocString(pwszStorageLocation);
  195. if (NULL == strStorageLocation)
  196. {
  197. _JumpError(hr, error, "SysAllocString");
  198. }
  199. strPropertyName = SysAllocString(pwszPropertyName);
  200. if (NULL == strPropertyName)
  201. {
  202. _JumpError(hr, error, "SysAllocString");
  203. }
  204. switch (ColumnType)
  205. {
  206. case PROPTYPE_BINARY:
  207. case PROPTYPE_STRING:
  208. varResult.vt = VT_BSTR;
  209. varResult.bstrVal = (BSTR) pProperty;
  210. break;
  211. case PROPTYPE_DATE:
  212. varResult.vt = VT_DATE;
  213. CopyMemory(&varResult.date, pProperty, sizeof(DATE));
  214. break;
  215. case PROPTYPE_LONG:
  216. varResult.vt = VT_I4;
  217. varResult.lVal = *(LONG *) pProperty;
  218. break;
  219. default:
  220. hr = E_INVALIDARG;
  221. _JumpError(hr, error, "PropertyType");
  222. }
  223. __try
  224. {
  225. if (NULL != pdiManage->pDispatch)
  226. {
  227. VARIANT avar[5];
  228. avar[0].vt = VT_BSTR;
  229. avar[0].bstrVal = strConfig;
  230. avar[1].vt = VT_BSTR;
  231. avar[1].bstrVal = strStorageLocation;
  232. avar[2].vt = VT_BSTR;
  233. avar[2].bstrVal = strPropertyName;
  234. avar[3].vt = VT_I4;
  235. avar[3].lVal = dwFlags;
  236. avar[4] = varResult;
  237. hr = DispatchInvoke(
  238. pdiManage,
  239. MANAGEMODULE_SETPROPERTY,
  240. ARRAYSIZE(avar),
  241. avar,
  242. 0,
  243. NULL);
  244. _JumpIfError(hr, error, "Invoke(GetName)");
  245. }
  246. else
  247. {
  248. hr = ((ICertManageModule *) pdiManage->pUnknown)->SetProperty(
  249. strConfig,
  250. strStorageLocation,
  251. strPropertyName,
  252. dwFlags,
  253. &varResult);
  254. _JumpIfError(hr, error, "ICertManageModule::SetProperty");
  255. }
  256. }
  257. __except(
  258. ExceptionAddress = (ULONG_PTR) (GetExceptionInformation())->ExceptionRecord->ExceptionAddress,
  259. hr = myHEXCEPTIONCODE(),
  260. EXCEPTION_EXECUTE_HANDLER)
  261. {
  262. _PrintError(hr, "SetProperty: Exception");
  263. fException = TRUE;
  264. }
  265. error:
  266. if (NULL != strConfig)
  267. {
  268. SysFreeString(strConfig);
  269. }
  270. if (NULL != strStorageLocation)
  271. {
  272. SysFreeString(strStorageLocation);
  273. }
  274. if (NULL != strPropertyName)
  275. {
  276. SysFreeString(strPropertyName);
  277. }
  278. //VariantInit(&varResult); // this owned no memory
  279. return(hr);
  280. }
  281. HRESULT
  282. ManageModule_Configure(
  283. IN DISPATCHINTERFACE *pdiManage,
  284. IN WCHAR const *pwszConfig,
  285. IN WCHAR const *pwszStorageLocation,
  286. IN DWORD dwFlags)
  287. {
  288. HRESULT hr;
  289. BOOL fException = FALSE;
  290. ULONG_PTR ExceptionAddress;
  291. BSTR strConfig = NULL;
  292. BSTR strStorageLocation = NULL;
  293. CSASSERT(NULL != pdiManage && NULL != pdiManage->pDispatchTable);
  294. hr = E_OUTOFMEMORY;
  295. strConfig = SysAllocString(pwszConfig);
  296. if (NULL == strConfig)
  297. {
  298. _JumpError(hr, error, "SysAllocString");
  299. }
  300. strStorageLocation = SysAllocString(pwszStorageLocation);
  301. if (NULL == strStorageLocation)
  302. {
  303. _JumpError(hr, error, "SysAllocString");
  304. }
  305. __try
  306. {
  307. if (NULL != pdiManage->pDispatch)
  308. {
  309. VARIANT avar[3];
  310. avar[0].vt = VT_BSTR;
  311. avar[0].bstrVal = strConfig;
  312. avar[1].vt = VT_BSTR;
  313. avar[1].bstrVal = strStorageLocation;
  314. avar[2].vt = VT_I4;
  315. avar[2].lVal = dwFlags;
  316. hr = DispatchInvoke(
  317. pdiManage,
  318. MANAGEMODULE_CONFIGURE,
  319. ARRAYSIZE(avar),
  320. avar,
  321. 0,
  322. NULL);
  323. _JumpIfError(hr, error, "Invoke(Configure)");
  324. }
  325. else
  326. {
  327. hr = ((ICertManageModule *) pdiManage->pUnknown)->Configure(
  328. strConfig,
  329. strStorageLocation,
  330. dwFlags);
  331. _JumpIfError(hr, error, "ICertManageModule::Configure");
  332. }
  333. }
  334. __except(
  335. ExceptionAddress = (ULONG_PTR) (GetExceptionInformation())->ExceptionRecord->ExceptionAddress,
  336. hr = myHEXCEPTIONCODE(),
  337. EXCEPTION_EXECUTE_HANDLER)
  338. {
  339. _PrintError(hr, "Configure: Exception");
  340. fException = TRUE;
  341. }
  342. error:
  343. if (NULL != strConfig)
  344. {
  345. SysFreeString(strConfig);
  346. }
  347. if (NULL != strStorageLocation)
  348. {
  349. SysFreeString(strStorageLocation);
  350. }
  351. return(hr);
  352. }
  353. HRESULT
  354. ManageModule_Init(
  355. IN DWORD Flags,
  356. IN TCHAR const *pszProgID, // morph for difft instances of this class
  357. IN CLSID const *pclsid,
  358. OUT DISPATCHINTERFACE *pdiManage)
  359. {
  360. HRESULT hr;
  361. hr = DispatchSetup(
  362. Flags,
  363. CLSCTX_INPROC_SERVER,
  364. pszProgID,
  365. pclsid,
  366. &IID_ICertManageModule,
  367. CMANAGEMODULEDISPATCH,
  368. g_adtManageModule,
  369. pdiManage);
  370. _JumpIfError(hr, error, "DispatchSetup");
  371. pdiManage->pDispatchTable = g_adtManageModule;
  372. error:
  373. return(hr);
  374. }
  375. HRESULT
  376. ManageModule_Init2(
  377. IN BOOL fIDispatch,
  378. IN ICertManageModule *pManage,
  379. OUT DISPATCHINTERFACE *pdiManage)
  380. {
  381. HRESULT hr;
  382. IDispatch *pDispatch = NULL;
  383. pdiManage->pDispatchTable = NULL;
  384. pdiManage->pDispatch = NULL;
  385. pdiManage->pUnknown = NULL;
  386. if (fIDispatch)
  387. {
  388. hr = pManage->QueryInterface(
  389. IID_IDispatch,
  390. (VOID **) &pDispatch);
  391. _JumpIfError(hr, error, "QueryInterface");
  392. hr = DispatchGetIds(
  393. pDispatch,
  394. CMANAGEMODULEDISPATCH,
  395. g_adtManageModule,
  396. pdiManage);
  397. _JumpIfError(hr, error, "DispatchGetIds");
  398. pdiManage->pDispatch = pDispatch;
  399. pDispatch = NULL;
  400. }
  401. else
  402. {
  403. pManage->AddRef();
  404. pdiManage->pUnknown = (IUnknown *) pManage;
  405. hr = S_OK;
  406. }
  407. pdiManage->pDispatchTable = g_adtManageModule;
  408. error:
  409. if (NULL != pDispatch)
  410. {
  411. pDispatch->Release();
  412. }
  413. return(hr);
  414. }
  415. VOID
  416. ManageModule_Release(
  417. IN OUT DISPATCHINTERFACE *pdiManage)
  418. {
  419. DispatchRelease(pdiManage);
  420. }