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.

121 lines
4.7 KiB

  1. #ifndef __CERT_DS_MANAGER_H__
  2. #define __CERT_DS_MANAGER_H__ 1
  3. #include <winldap.h>
  4. //--------------------------------------------------------------------------------
  5. //
  6. // CertDSManager interface.
  7. //
  8. // The CertDSManager provides a wrapper around the certcli API to allow
  9. // any DS caching/optimization to be localized within a simple class.
  10. //
  11. //--------------------------------------------------------------------------------
  12. class CertDSManager {
  13. public:
  14. virtual HRESULT CloseCA (IN HCAINFO hCAInfo) = 0;
  15. virtual HRESULT CloseCertType (IN HCERTTYPE hCertType) = 0;
  16. virtual HRESULT CountCAs (IN HCAINFO hCAInfo) = 0;
  17. virtual HRESULT EnumCertTypesForCA (IN HCAINFO hCAInfo, IN DWORD dsFlags, OUT HCERTTYPE *phCertType) = 0;
  18. virtual HRESULT EnumFirstCA (IN LPCWSTR wszScope, IN DWORD fFlags, OUT HCAINFO *phCAInfo) = 0;
  19. virtual HRESULT EnumNextCA (IN HCAINFO hPrevCA, OUT HCAINFO *phCAInfo) = 0;
  20. virtual HRESULT EnumNextCertType (IN HCERTTYPE hPrevCertType, OUT HCERTTYPE *phCertType) = 0;
  21. virtual HRESULT FindCertTypeByName (IN LPCWSTR pwszCertType, IN HCAINFO hCAInfo, IN DWORD dwFlags, OUT HCERTTYPE *phCertType) = 0;
  22. virtual HRESULT FindCAByName (IN LPCWSTR wszCAName,IN LPCWSTR wszScope,IN DWORD dwFlags,OUT HCAINFO *phCAInfo) = 0;
  23. virtual HRESULT GetCACertificate (IN HCAINFO hCAInfo, OUT PCCERT_CONTEXT *ppCert) = 0;
  24. HRESULT static MakeDSManager(OUT CertDSManager **ppDSManager);
  25. protected:
  26. virtual HRESULT Initialize() = 0;
  27. };
  28. //--------------------------------------------------------------------------------
  29. //
  30. // DefaultDSManager.
  31. //
  32. // Other DS manager classes should extend this class, and implement only those
  33. // methods which they wish to modify.
  34. //
  35. //--------------------------------------------------------------------------------
  36. class DefaultDSManager : public CertDSManager {
  37. public:
  38. virtual HRESULT CloseCA(IN HCAINFO hCAInfo) {
  39. return ::CACloseCA(hCAInfo);
  40. }
  41. virtual HRESULT CloseCertType(IN HCERTTYPE hCertType) {
  42. return ::CACloseCertType(hCertType);
  43. }
  44. virtual HRESULT CountCAs(IN HCAINFO hCAInfo) {
  45. return ::CACountCAs(hCAInfo);
  46. }
  47. virtual HRESULT EnumCertTypesForCA(IN HCAINFO hCAInfo, IN DWORD dwFlags, OUT HCERTTYPE *phCertType) {
  48. return ::CAEnumCertTypesForCA(hCAInfo, dwFlags, phCertType);
  49. }
  50. virtual HRESULT EnumFirstCA(IN LPCWSTR wszScope, IN DWORD dwFlags, OUT HCAINFO *phCAInfo) {
  51. return ::CAEnumFirstCA(wszScope, dwFlags, phCAInfo);
  52. }
  53. virtual HRESULT EnumNextCA(IN HCAINFO hPrevCA, OUT HCAINFO *phCAInfo) {
  54. return ::CAEnumNextCA(hPrevCA, phCAInfo);
  55. }
  56. virtual HRESULT EnumNextCertType(IN HCERTTYPE hPrevCertType, OUT HCERTTYPE *phCertType) {
  57. return ::CAEnumNextCertType(hPrevCertType, phCertType);
  58. }
  59. virtual HRESULT FindCertTypeByName(IN LPCWSTR pwszCertType, IN HCAINFO hCAInfo, IN DWORD dwFlags, OUT HCERTTYPE *phCertType) {
  60. return ::CAFindCertTypeByName(pwszCertType, hCAInfo, dwFlags, phCertType);
  61. }
  62. virtual HRESULT FindCAByName(IN LPCWSTR wszCAName, IN LPCWSTR wszScope, IN DWORD dwFlags, OUT HCAINFO *phCAInfo) {
  63. return ::CAFindByName(wszCAName, wszScope, dwFlags, phCAInfo);
  64. }
  65. virtual HRESULT GetCACertificate(IN HCAINFO hCAInfo, OUT PCCERT_CONTEXT *ppCert) {
  66. return ::CAGetCACertificate(hCAInfo, ppCert);
  67. }
  68. protected:
  69. virtual HRESULT Initialize() { return S_OK; }
  70. };
  71. //--------------------------------------------------------------------------------
  72. //
  73. // CachingDSManager
  74. //
  75. // This DS manager caches the LDAP binding handle (where possible) to prevent
  76. // unnecessary binds and unbinds. It uses an enhanced version of certcli which
  77. // allows you to pass an LDAP binding handle.
  78. //
  79. //--------------------------------------------------------------------------------
  80. class CachingDSManager : public DefaultDSManager {
  81. friend class CertDSManager;
  82. public:
  83. virtual ~CachingDSManager();
  84. // Extend those routines which allow you to use a cached binding handle
  85. HRESULT EnumCertTypesForCA(IN HCAINFO hCAInfo, IN DWORD dwFlags, OUT HCERTTYPE * phCertType);
  86. HRESULT EnumFirstCA(IN LPCWSTR wszScope, IN DWORD dwFlags, OUT HCAINFO *phCAInfo);
  87. HRESULT FindCAByName(IN LPCWSTR wszCAName, IN LPCWSTR wszScope, IN DWORD dwFlags,OUT HCAINFO *phCAInfo);
  88. HRESULT FindCertTypeByName(IN LPCWSTR pwszCertType, IN HCAINFO hCAInfo, IN DWORD dwFlags, OUT HCERTTYPE *phCertType);
  89. protected:
  90. HRESULT Initialize();
  91. private:
  92. CachingDSManager() : m_ldBindingHandle(NULL) { }
  93. LDAP *m_ldBindingHandle;
  94. };
  95. #endif // #ifndef __CERT_DS_MANAGER_H__