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.

150 lines
3.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999 - 2000
  5. //
  6. // File: tmpllist.h
  7. //
  8. // Contents: certificate template list class
  9. //
  10. //---------------------------------------------------------------------------
  11. #ifndef __TMPLLIST_H__
  12. #define __TMPLLIST_H__
  13. #include <tptrlist.h>
  14. namespace CertSrv
  15. {
  16. class CTemplateInfo
  17. {
  18. public:
  19. CTemplateInfo() :
  20. m_pwszTemplateName(NULL),
  21. m_pwszTemplateOID(NULL),
  22. m_hCertType(NULL){};
  23. ~CTemplateInfo()
  24. {
  25. if(m_pwszTemplateName)
  26. LocalFree(m_pwszTemplateName);
  27. if(m_pwszTemplateOID)
  28. LocalFree(m_pwszTemplateOID);
  29. // no free needed for m_hCertType
  30. };
  31. HRESULT SetInfo(
  32. LPCWSTR pcwszTemplateName,
  33. LPCWSTR pcwszTemplateOID);
  34. HRESULT SetInfo(HCERTTYPE hCertType)
  35. { m_hCertType = hCertType; return S_OK;}
  36. LPCWSTR GetName();
  37. LPCWSTR GetOID();
  38. HCERTTYPE GetCertType() { return m_hCertType; }
  39. DWORD GetMarshalBufferSize()
  40. {
  41. return sizeof(WCHAR)*
  42. (2 + // trailing separators
  43. (GetName()?wcslen(GetName()):0) +
  44. (GetOID() ?wcslen(GetOID()) :0));
  45. }
  46. void FillInfoFromProperty(LPWSTR& pwszProp, LPCWSTR pcwszPropName);
  47. bool operator==(CTemplateInfo& rh);
  48. protected:
  49. LPWSTR m_pwszTemplateName;
  50. LPWSTR m_pwszTemplateOID;
  51. HCERTTYPE m_hCertType;
  52. }; // class CTemplateInfo
  53. typedef LPCWSTR (CTemplateInfo::* GetIdentifierFunc) ();
  54. class CTemplateList : public TPtrList<CTemplateInfo>
  55. {
  56. public:
  57. static const WCHAR m_gcchSeparator = L'\n';
  58. HRESULT Marshal(BYTE*& rpBuffer, DWORD& rcBuffer) const;
  59. HRESULT Unmarshal(const BYTE *pBuffer, DWORD cBuffer);
  60. HRESULT LoadTemplatesFromDS();
  61. HRESULT ValidateMarshalBuffer(const BYTE *pBuffer, DWORD cBuffer) const;
  62. HRESULT AddTemplateInfo(
  63. IN LPCWSTR pcwszTemplateName,
  64. IN LPCWSTR pcwszTemplateOID);
  65. HRESULT AddTemplateInfo(
  66. IN HCERTTYPE hCertType,
  67. IN BOOL fTransientCertTypeHandle); // don't hang onto hCertType
  68. HRESULT RemoveTemplateInfo(HCERTTYPE hCertType);
  69. bool TemplateExistsOID(LPCWSTR pcwszOID) const
  70. {
  71. return TemplateExists(pcwszOID, &CTemplateInfo::GetOID);
  72. }
  73. bool TemplateExistsName(LPCWSTR pcwszName) const
  74. {
  75. return TemplateExists(pcwszName, &CTemplateInfo::GetName);
  76. }
  77. protected:
  78. DWORD GetMarshalBufferSize() const;
  79. bool TemplateExists(LPCWSTR pcwszOIDorName, GetIdentifierFunc func) const
  80. {
  81. TPtrListEnum<CTemplateInfo> listenum(*this);
  82. CTemplateInfo *pInfo;
  83. for(pInfo=listenum.Next();
  84. pInfo;
  85. pInfo=listenum.Next())
  86. {
  87. if(0 == _wcsicmp((pInfo->*func)(), pcwszOIDorName))
  88. return true;
  89. }
  90. return false;
  91. }
  92. }; // class CTemplateList
  93. typedef TPtrListEnum<CTemplateInfo> CTemplateListEnum;
  94. } // namespace CertSrv
  95. HRESULT
  96. myUpdateCATemplateListToCA(
  97. IN HCAINFO hCAInfo,
  98. IN const CTemplateList& list);
  99. HRESULT
  100. myUpdateCATemplateListToDS(
  101. IN HCAINFO hCAInfo);
  102. HRESULT
  103. myRetrieveCATemplateList(
  104. IN HCAINFO hCAInfo,
  105. IN BOOL fTransientCertTypeHandle, // don't hang onto hCertType
  106. OUT CTemplateList& list);
  107. HRESULT
  108. myAddToCATemplateList(
  109. IN HCAINFO hCAInfo,
  110. IN OUT CTemplateList& list,
  111. IN HCERTTYPE hCertType,
  112. IN BOOL fTransientCertTypeHandle); // don't hang onto hCertType
  113. HRESULT
  114. myRemoveFromCATemplateList(
  115. IN HCAINFO hCAInfo,
  116. IN OUT CTemplateList& list,
  117. IN HCERTTYPE hCertType);
  118. using namespace CertSrv;
  119. #endif //__TMPLLIST_H__