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
5.1 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: comtest.cpp
  7. //
  8. // Contents: Cert Server COM interface test driver
  9. //
  10. // History: 20-Jan-97 vich created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include <pch.cpp>
  14. #pragma hdrstop
  15. #include <stdio.h>
  16. #include "csdisp.h"
  17. #include "csprop.h"
  18. #if DBG_COMTEST
  19. BOOL
  20. comTestCIPolicy(
  21. IN LONG Context,
  22. IN DWORD Flags)
  23. {
  24. HRESULT hr;
  25. DISPATCHINTERFACE diCIPolicy;
  26. BSTR bstrReq = NULL;
  27. BSTR bstrCert = NULL;
  28. BOOL fMustRelease = FALSE;
  29. DATE Date;
  30. wprintf(L"\n");
  31. hr = CIPolicy_Init(Flags, &diCIPolicy);
  32. _JumpIfError(hr, error, "CIPolicy_Init");
  33. fMustRelease = TRUE;
  34. hr = CIPolicy_SetContext(&diCIPolicy, Context);
  35. _JumpIfError(hr, error, "CIPolicy_SetContext");
  36. hr = CIPolicy_GetRequestProperty(
  37. &diCIPolicy,
  38. g_wszPropSubjectCommonName,
  39. PROPTYPE_STRING,
  40. &bstrReq);
  41. _JumpIfError(hr, error, "CIPolicy_GetRequestProperty");
  42. wprintf(
  43. L"%d:CIPolicy_GetRequestProperty(%u, %ws) == `%ws'\n",
  44. Flags,
  45. Context,
  46. g_wszPropSubjectCommonName,
  47. bstrReq);
  48. hr = CIPolicy_GetCertificateProperty(
  49. &diCIPolicy,
  50. g_wszPropSubjectCommonName,
  51. PROPTYPE_STRING,
  52. &bstrCert);
  53. _JumpIfError(hr, error, "CIPolicy_GetCertificateProperty");
  54. wprintf(
  55. L"%d:CIPolicy_GetCertificateProperty(%u, %ws) == `%ws'\n",
  56. Flags,
  57. Context,
  58. g_wszPropSubjectCommonName,
  59. bstrCert);
  60. hr = CIPolicy_SetCertificateProperty(
  61. &diCIPolicy,
  62. g_wszPropSubjectLocality,
  63. PROPTYPE_STRING,
  64. L"coreSetPropPolicy_Locality");
  65. _JumpIfError(hr, error, "CIPolicy_SetCertificateProperty");
  66. wprintf(
  67. L"%d:CIPolicy_SetCertificateProperty(%u, %ws, %ws) == %x\n",
  68. Flags,
  69. Context,
  70. g_wszPropSubjectCommonName,
  71. L"CIPolicy_SetCertificateProperty_Locality",
  72. hr);
  73. hr = CIPolicy_GetCertificateProperty(
  74. &diCIPolicy,
  75. g_wszPropCertificateNotBeforeDate,
  76. PROPTYPE_DATE,
  77. (BSTR *) &Date);
  78. _JumpIfError(hr, error, "CIPolicy_GetCertificateProperty");
  79. wprintf(
  80. L"%d:CIPolicy_GetCertificateProperty(%u, %ws) == %x (%f)\n",
  81. Flags,
  82. Context,
  83. g_wszPropCertificateNotBeforeDate,
  84. hr,
  85. Date);
  86. hr = CIPolicy_SetCertificateProperty(
  87. &diCIPolicy,
  88. g_wszPropCertificateNotBeforeDate,
  89. PROPTYPE_DATE,
  90. (BSTR) &Date);
  91. _JumpIfError(hr, error, "CIPolicy_SetCertificateProperty");
  92. wprintf(
  93. L"%d:CIPolicy_SetCertificateProperty(%u, %ws) == %x (%f)\n",
  94. Flags,
  95. Context,
  96. g_wszPropCertificateNotBeforeDate,
  97. hr,
  98. Date);
  99. Date += 1.5; // Set validity period to 1.5 days.
  100. hr = CIPolicy_SetCertificateProperty(
  101. &diCIPolicy,
  102. g_wszPropCertificateNotAfterDate,
  103. PROPTYPE_DATE,
  104. (BSTR) &Date);
  105. _JumpIfError(hr, error, "CIPolicy_SetCertificateProperty");
  106. wprintf(
  107. L"%d:CIPolicy_SetCertificateProperty(%u, %ws) == %x (%f)\n",
  108. Flags,
  109. Context,
  110. g_wszPropCertificateNotAfterDate,
  111. hr,
  112. Date);
  113. error:
  114. if (NULL != bstrReq)
  115. {
  116. SysFreeString(bstrReq);
  117. }
  118. if (NULL != bstrCert)
  119. {
  120. SysFreeString(bstrCert);
  121. }
  122. if (fMustRelease)
  123. {
  124. CIPolicy_Release(&diCIPolicy);
  125. }
  126. return(S_OK == hr);
  127. }
  128. BOOL
  129. comTestCIExit(
  130. IN LONG Context,
  131. IN DWORD Flags)
  132. {
  133. HRESULT hr;
  134. DISPATCHINTERFACE diCIExit;
  135. BSTR bstrReq = NULL;
  136. BSTR bstrCert = NULL;
  137. BOOL fMustRelease = FALSE;
  138. wprintf(L"\n");
  139. hr = CIExit_Init(Flags, &diCIExit);
  140. _JumpIfError(hr, error, "CIExit_Init");
  141. fMustRelease = TRUE;
  142. hr = CIExit_SetContext(&diCIExit, Context);
  143. _JumpIfError(hr, error, "CIExit_SetContext");
  144. hr = CIExit_GetRequestProperty(
  145. &diCIExit,
  146. g_wszPropSubjectCommonName,
  147. PROPTYPE_STRING,
  148. &bstrReq);
  149. _JumpIfError(hr, error, "CIExit_GetRequestProperty");
  150. wprintf(
  151. L"%d:CIExit_GetRequestProperty(%u, %ws) == `%ws'\n",
  152. Flags,
  153. Context,
  154. g_wszPropSubjectCommonName,
  155. bstrReq);
  156. hr = CIExit_GetCertificateProperty(
  157. &diCIExit,
  158. g_wszPropSubjectCommonName,
  159. PROPTYPE_STRING,
  160. &bstrCert);
  161. _JumpIfError(hr, error, "CIExit_GetCertificateProperty");
  162. wprintf(
  163. L"%d:CIExit_GetCertificateProperty(%u, %ws) == `%ws'\n",
  164. Flags,
  165. Context,
  166. g_wszPropSubjectCommonName,
  167. bstrCert);
  168. error:
  169. if (NULL != bstrReq)
  170. {
  171. SysFreeString(bstrReq);
  172. }
  173. if (NULL != bstrCert)
  174. {
  175. SysFreeString(bstrCert);
  176. }
  177. if (fMustRelease)
  178. {
  179. CIExit_Release(&diCIExit);
  180. }
  181. return(S_OK == hr);
  182. }
  183. BOOL
  184. ComTest(
  185. IN LONG Context)
  186. {
  187. return(
  188. comTestCIPolicy(Context, DISPSETUP_COMFIRST) &&
  189. comTestCIPolicy(Context, DISPSETUP_COM) &&
  190. comTestCIPolicy(Context, DISPSETUP_IDISPATCH) &&
  191. comTestCIExit(Context, DISPSETUP_COMFIRST) &&
  192. comTestCIExit(Context, DISPSETUP_COM) &&
  193. comTestCIExit(Context, DISPSETUP_IDISPATCH));
  194. }
  195. #endif // DBG_COMTEST