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.

148 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: cryptuiapi.cpp
  8. //
  9. // Contents: Public Cryptographic UI APIs
  10. //
  11. //--------------------------------------------------------------------------
  12. #include "global.hxx"
  13. #include <dbgdef.h>
  14. #include <cryptuiapi.h>
  15. //+-------------------------------------------------------------------------
  16. // Dialog viewer of a certificate, CTL or CRL context.
  17. //
  18. // dwContextType and associated pvContext's
  19. // CERT_STORE_CERTIFICATE_CONTEXT PCCERT_CONTEXT
  20. // CERT_STORE_CRL_CONTEXT PCCRL_CONTEXT
  21. // CERT_STORE_CTL_CONTEXT PCCTL_CONTEXT
  22. //
  23. // dwFlags currently isn't used and should be set to 0.
  24. //--------------------------------------------------------------------------
  25. BOOL
  26. WINAPI
  27. CryptUIDlgViewContext(
  28. IN DWORD dwContextType,
  29. IN const void *pvContext,
  30. IN OPTIONAL HWND hwnd, // Defaults to the desktop window
  31. IN OPTIONAL LPCWSTR pwszTitle, // Defaults to the context type title
  32. IN DWORD dwFlags,
  33. IN void *pvReserved
  34. )
  35. {
  36. BOOL fResult;
  37. switch (dwContextType) {
  38. case CERT_STORE_CERTIFICATE_CONTEXT:
  39. {
  40. CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo;
  41. memset(&ViewInfo, 0, sizeof(ViewInfo));
  42. ViewInfo.dwSize = sizeof(ViewInfo);
  43. ViewInfo.hwndParent = hwnd;
  44. ViewInfo.szTitle = pwszTitle;
  45. ViewInfo.pCertContext = (PCCERT_CONTEXT) pvContext;
  46. fResult = CryptUIDlgViewCertificateW(
  47. &ViewInfo,
  48. NULL // pfPropertiesChanged
  49. );
  50. }
  51. break;
  52. case CERT_STORE_CRL_CONTEXT:
  53. {
  54. CRYPTUI_VIEWCRL_STRUCTW ViewInfo;
  55. memset(&ViewInfo, 0, sizeof(ViewInfo));
  56. ViewInfo.dwSize = sizeof(ViewInfo);
  57. ViewInfo.hwndParent = hwnd;
  58. ViewInfo.szTitle = pwszTitle;
  59. ViewInfo.pCRLContext = (PCCRL_CONTEXT) pvContext;
  60. fResult = CryptUIDlgViewCRLW(
  61. &ViewInfo
  62. );
  63. }
  64. break;
  65. case CERT_STORE_CTL_CONTEXT:
  66. {
  67. CRYPTUI_VIEWCTL_STRUCTW ViewInfo;
  68. memset(&ViewInfo, 0, sizeof(ViewInfo));
  69. ViewInfo.dwSize = sizeof(ViewInfo);
  70. ViewInfo.hwndParent = hwnd;
  71. ViewInfo.szTitle = pwszTitle;
  72. ViewInfo.pCTLContext = (PCCTL_CONTEXT) pvContext;
  73. fResult = CryptUIDlgViewCTLW(
  74. &ViewInfo
  75. );
  76. }
  77. break;
  78. default:
  79. fResult = FALSE;
  80. SetLastError(E_INVALIDARG);
  81. }
  82. return fResult;
  83. }
  84. //+-------------------------------------------------------------------------
  85. // Dialog to select a certificate from the specified store.
  86. //
  87. // Returns the selected certificate context. If no certificate was
  88. // selected, NULL is returned.
  89. //
  90. // pwszTitle is either NULL or the title to be used for the dialog.
  91. // If NULL, the default title is used. The default title is
  92. // "Select Certificate".
  93. //
  94. // pwszDisplayString is either NULL or the text statement in the selection
  95. // dialog. If NULL, the default phrase
  96. // "Select a certificate you wish to use" is used in the dialog.
  97. //
  98. // dwDontUseColumn can be set to exclude columns from the selection
  99. // dialog. See the CRYPTDLG_SELECTCERT_*_COLUMN definitions below.
  100. //
  101. // dwFlags currently isn't used and should be set to 0.
  102. //--------------------------------------------------------------------------
  103. PCCERT_CONTEXT
  104. WINAPI
  105. CryptUIDlgSelectCertificateFromStore(
  106. IN HCERTSTORE hCertStore,
  107. IN OPTIONAL HWND hwnd, // Defaults to the desktop window
  108. IN OPTIONAL LPCWSTR pwszTitle,
  109. IN OPTIONAL LPCWSTR pwszDisplayString,
  110. IN DWORD dwDontUseColumn,
  111. IN DWORD dwFlags,
  112. IN void *pvReserved
  113. )
  114. {
  115. CRYPTUI_SELECTCERTIFICATE_STRUCTW SelectInfo;
  116. if (NULL == hCertStore) {
  117. SetLastError(E_INVALIDARG);
  118. return FALSE;
  119. }
  120. memset(&SelectInfo, 0, sizeof(SelectInfo));
  121. SelectInfo.dwSize = sizeof(SelectInfo);
  122. SelectInfo.hwndParent = hwnd;
  123. SelectInfo.szTitle = pwszTitle;
  124. SelectInfo.szDisplayString = pwszDisplayString;
  125. SelectInfo.dwDontUseColumn = dwDontUseColumn;
  126. SelectInfo.cDisplayStores = 1;
  127. SelectInfo.rghDisplayStores = &hCertStore;
  128. return CryptUIDlgSelectCertificateW(&SelectInfo);
  129. }