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.

228 lines
5.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: attribute.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _ATTR_H
  11. #define _ATTR_H
  12. #include "common.h"
  13. ////////////////////////////////////////////////////////////////////////
  14. // Forward Declarations
  15. //
  16. class CAttrList2;
  17. ////////////////////////////////////////////////////////////////////////
  18. // CADSIAttribute
  19. class CADSIAttribute
  20. {
  21. public:
  22. // Constructors
  23. //
  24. CADSIAttribute(ADS_ATTR_INFO* pInfo, BOOL bMulti, PCWSTR pszSyntax, BOOL bReadOnly = TRUE);
  25. CADSIAttribute(PADS_ATTR_INFO pInfo);
  26. CADSIAttribute(const CString& attributeName);
  27. CADSIAttribute(CADSIAttribute* pAttr);
  28. // Destructor
  29. //
  30. ~CADSIAttribute();
  31. // Data accessor functions
  32. //
  33. void GetProperty(CString& sProp) { sProp = m_pAttrInfo->pszAttrName; }
  34. DWORD GetNumValues() { return m_pAttrInfo->dwNumValues; }
  35. HRESULT SetValues(PADSVALUE pADsValue, DWORD dwNumValues);
  36. HRESULT SetValues(const CStringList& sValues);
  37. HRESULT AppendValues(PADSVALUE pADsValue, DWORD dwNumValues);
  38. void GetValues(CStringList& psValues, DWORD dwMaxCharCount = 1024);
  39. BOOL GetMultivalued() { return m_bMulti; }
  40. void SetMultivalued(BOOL bMulti) { m_bMulti = bMulti; }
  41. void SetDirty(const BOOL bDirty) { m_bDirty = bDirty; }
  42. BOOL IsDirty() { return m_bDirty; }
  43. void SetMandatory(const BOOL bMandatory) { m_bMandatory = bMandatory; }
  44. BOOL IsMandatory() { return m_bMandatory; }
  45. BOOL IsValueSet() { return m_bSet; }
  46. void SetValueSet(const BOOL bSet) { m_bSet = bSet; }
  47. ADSTYPE GetADsType() { return m_pAttrInfo->dwADsType; }
  48. void SetADsType(ADSTYPE dwType) { m_pAttrInfo->dwADsType = dwType; }
  49. CString GetSyntax() { return m_szSyntax; }
  50. void SetSyntax(PCWSTR pszSyntax) { m_szSyntax = pszSyntax; }
  51. ADS_ATTR_INFO* GetAttrInfo();
  52. void SetAttrInfo(PADS_ATTR_INFO pAttrInfo)
  53. {
  54. if (m_pAttrInfo != NULL)
  55. {
  56. _FreeADsAttrInfo(&m_pAttrInfo, FALSE);
  57. }
  58. m_pAttrInfo = pAttrInfo;
  59. m_bReadOnly = TRUE;
  60. }
  61. ADSVALUE* GetADsValues() { return m_pAttrInfo->pADsValues; }
  62. static HRESULT SetValuesInDS(CAttrList2* ptouchAttr, IDirectoryObject* pDirObject);
  63. private:
  64. // Functions
  65. //
  66. ADSVALUE* GetADSVALUE(int idx);
  67. static BOOL _AllocOctetString(const ADS_OCTET_STRING& rOldOctetString, ADS_OCTET_STRING& rNew);
  68. static void _FreeOctetString(BYTE*& lpValue);
  69. static BOOL _AllocString(LPCWSTR lpsz, LPWSTR* lppszNew);
  70. static void _FreeString(LPWSTR* lppsz);
  71. static BOOL _CopyADsAttrInfo(ADS_ATTR_INFO* pAttrInfo, ADS_ATTR_INFO** ppNewAttrInfo);
  72. static BOOL _CopyADsAttrInfo(ADS_ATTR_INFO* pAttrInfo, ADS_ATTR_INFO* pNewAttrInfo);
  73. static void _FreeADsAttrInfo(ADS_ATTR_INFO** ppAttrInfo, BOOL bReadOnly);
  74. static void _FreeADsAttrInfo(ADS_ATTR_INFO* pAttrInfo);
  75. static BOOL _AllocValues(ADSVALUE** ppValues, DWORD dwLength);
  76. static BOOL _CopyADsValues(ADS_ATTR_INFO* pOldAttrInfo, ADS_ATTR_INFO* ppNewAttrInfo);
  77. static void _FreeADsValues(ADSVALUE** ppADsValues, DWORD dwLength);
  78. static HRESULT _SetADsFromString(LPCWSTR lpszValue, ADSTYPE adsType, ADSVALUE* pADsValue);
  79. static
  80. HRESULT
  81. _CloneADsValue(const ADSVALUE& original, ADSVALUE& clone);
  82. static
  83. void
  84. _FreeADsValue(ADSVALUE& value);
  85. static
  86. bool
  87. _CloneBlob(const BYTE* src, DWORD srcSize, BYTE*& dest, DWORD& destSize);
  88. static
  89. void
  90. _FreeBlob(BYTE*& blob, DWORD& blobSize);
  91. static
  92. bool
  93. _CloneProviderSpecificBlob(
  94. const ADS_PROV_SPECIFIC& src,
  95. ADS_PROV_SPECIFIC& dest);
  96. static
  97. void
  98. _FreeProviderSpecificBlob(ADS_PROV_SPECIFIC& blob);
  99. static
  100. bool
  101. _CloneNtSecurityDescriptor(
  102. const ADS_NT_SECURITY_DESCRIPTOR& src,
  103. ADS_NT_SECURITY_DESCRIPTOR& dest);
  104. static
  105. void
  106. _FreeNtSecurityDescriptor(ADS_NT_SECURITY_DESCRIPTOR& sd);
  107. static
  108. bool
  109. _CloneDNWithBinary(
  110. const PADS_DN_WITH_BINARY& src,
  111. PADS_DN_WITH_BINARY& dest);
  112. static
  113. void
  114. _FreeDNWithBinary(PADS_DN_WITH_BINARY& dn);
  115. static
  116. bool
  117. _CloneDNWithString(
  118. const PADS_DN_WITH_STRING& src,
  119. PADS_DN_WITH_STRING& dest);
  120. static
  121. void
  122. _FreeDNWithString(PADS_DN_WITH_STRING& dn);
  123. // Member data
  124. //
  125. ADS_ATTR_INFO* m_pAttrInfo;
  126. BOOL m_bDirty;
  127. BOOL m_bMulti;
  128. BOOL m_bReadOnly;
  129. BOOL m_bMandatory;
  130. BOOL m_bSet;
  131. CString m_szSyntax;
  132. };
  133. ////////////////////////////////////////////////////////////////////////////////
  134. //
  135. //
  136. typedef CList<CADSIAttribute*,CADSIAttribute*> CAttrListBase2;
  137. class CAttrList2 : public CAttrListBase2
  138. {
  139. public:
  140. CAttrList2() : m_pMandatorySavedValues(NULL), m_pOptionalSavedValues(NULL)
  141. {
  142. }
  143. virtual ~CAttrList2()
  144. {
  145. if (m_pMandatorySavedValues != NULL)
  146. {
  147. FreeADsMem(m_pMandatorySavedValues);
  148. }
  149. if (m_pOptionalSavedValues != NULL)
  150. {
  151. FreeADsMem(m_pOptionalSavedValues);
  152. }
  153. RemoveAllAttr();
  154. }
  155. void RemoveAllAttr()
  156. {
  157. while (!IsEmpty())
  158. delete RemoveTail();
  159. }
  160. POSITION FindProperty(LPCWSTR lpszAttr);
  161. BOOL HasProperty(LPCWSTR lpszAttr);
  162. void GetNextDirty(POSITION& pos, CADSIAttribute** ppAttr);
  163. BOOL HasDirty();
  164. int GetDirtyCount()
  165. {
  166. int nCount = 0;
  167. POSITION pos = GetHeadPosition();
  168. while (pos != NULL)
  169. {
  170. if (GetNext(pos)->IsDirty())
  171. nCount++;
  172. }
  173. return nCount;
  174. }
  175. void SaveMandatoryValuesPointer(PADS_ATTR_INFO pAttrInfo) { m_pMandatorySavedValues = pAttrInfo; }
  176. void SaveOptionalValuesPointer(PADS_ATTR_INFO pAttrInfo) { m_pOptionalSavedValues = pAttrInfo; }
  177. private:
  178. PADS_ATTR_INFO m_pMandatorySavedValues;
  179. PADS_ATTR_INFO m_pOptionalSavedValues;
  180. };
  181. #ifndef OLD_ATTRIBUTE_CLASS
  182. typedef CAttrList2 CAttrList;
  183. typedef CADSIAttribute CADSIAttr;
  184. #endif
  185. #endif //_ATTR_H