Source code of Windows XP (NT5)
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.

213 lines
4.5 KiB

  1. #pragma once
  2. #include <map>
  3. #ifndef tstring
  4. #include <string>
  5. typedef std::basic_string<_TCHAR> tstring;
  6. #endif
  7. #ifndef StringVector
  8. #include <vector>
  9. typedef std::vector<tstring> StringVector;
  10. #endif
  11. #ifndef CStringSet
  12. #include <set>
  13. typedef std::set<tstring> CStringSet;
  14. #endif
  15. #ifndef IADsContainerPtr
  16. #include <ComDef.h>
  17. #include <ActiveDS.h>
  18. _COM_SMARTPTR_TYPEDEF(IADsContainer, IID_IADsContainer);
  19. #endif
  20. #ifndef StringSet
  21. #include <set>
  22. typedef std::set<_bstr_t> StringSet;
  23. #endif
  24. //---------------------------------------------------------------------------
  25. // Name Cracker Class
  26. //---------------------------------------------------------------------------
  27. class CNameCracker
  28. {
  29. public:
  30. CNameCracker();
  31. ~CNameCracker();
  32. void SetDomainNames(LPCTSTR pszDnsName, LPCTSTR pszFlatName, LPCTSTR pszDomainController)
  33. {
  34. m_strDnsName = pszDnsName;
  35. m_strFlatName = pszFlatName;
  36. m_strDomainController = pszDomainController;
  37. }
  38. void SetDefaultContainer(IADsContainerPtr& spContainer)
  39. {
  40. m_spDefaultContainer = spContainer;
  41. }
  42. void CrackNames(const StringVector& vecNames);
  43. const CStringSet& GetResolvedNames() const
  44. {
  45. return m_setResolvedNames;
  46. }
  47. const StringVector& GetUnResolvedNames() const
  48. {
  49. return m_vecUnResolvedNames;
  50. }
  51. protected:
  52. void Separate(
  53. const StringVector& vecNames,
  54. StringVector& vecCanonicalNames,
  55. StringVector& vecSamAccountNames,
  56. StringVector& vecRelativeDistinguishedNames
  57. );
  58. void CrackCanonicalNames(const StringVector& vecCanonicalNames, StringVector& vecUnResolvedNames);
  59. void CrackSamAccountNames(const StringVector& vecSamAccountNames, StringVector& vecUnResolvedNames);
  60. void CrackRelativeDistinguishedNames(const StringVector& vecRelativeDistinguishedNames, StringVector& vecUnResolvedNames);
  61. typedef enum
  62. {
  63. CANONICAL_NAME,
  64. NT4_ACCOUNT_NAME,
  65. }
  66. NAME_FORMAT;
  67. struct SName
  68. {
  69. SName(LPCTSTR pszPartial, LPCTSTR pszComplete) :
  70. strPartial(pszPartial),
  71. strComplete(pszComplete)
  72. {
  73. }
  74. SName(const SName& r) :
  75. strPartial(r.strPartial),
  76. strComplete(r.strComplete),
  77. strResolved(r.strResolved)
  78. {
  79. }
  80. SName& operator =(const SName& r)
  81. {
  82. strPartial = r.strPartial;
  83. strComplete = r.strComplete;
  84. strResolved = r.strResolved;
  85. return *this;
  86. }
  87. tstring strPartial;
  88. tstring strComplete;
  89. tstring strResolved;
  90. };
  91. typedef std::vector<SName> CNameVector;
  92. void CrackNames(NAME_FORMAT eFormat, CNameVector& vecNames);
  93. static tstring GetEscapedFilterName(LPCTSTR pszName);
  94. protected:
  95. tstring m_strDnsName;
  96. tstring m_strFlatName;
  97. tstring m_strDomainController;
  98. IADsContainerPtr m_spDefaultContainer;
  99. CStringSet m_setResolvedNames;
  100. StringVector m_vecUnResolvedNames;
  101. };
  102. //---------------------------------------------------------------------------
  103. // Ignore Case String Less
  104. //---------------------------------------------------------------------------
  105. struct IgnoreCaseStringLess :
  106. public std::binary_function<_bstr_t, _bstr_t, bool>
  107. {
  108. bool operator()(const _bstr_t& x, const _bstr_t& y) const;
  109. };
  110. //---------------------------------------------------------------------------
  111. // Domain To Path Map Class
  112. //---------------------------------------------------------------------------
  113. class CDomainToPathMap :
  114. public std::map<_bstr_t, StringSet, IgnoreCaseStringLess>
  115. {
  116. public:
  117. CDomainToPathMap()
  118. {
  119. }
  120. void Initialize(LPCTSTR pszDefaultDomainDns, LPCTSTR pszDefaultDomainFlat, const StringSet& setNames);
  121. protected:
  122. static bool GetValidDomainName(_bstr_t& strDomainName);
  123. };
  124. //---------------------------------------------------------------------------
  125. // Name To Path Map Class
  126. //---------------------------------------------------------------------------
  127. class CNameToPathMap :
  128. public std::map<_bstr_t, StringSet, IgnoreCaseStringLess>
  129. {
  130. public:
  131. CNameToPathMap();
  132. CNameToPathMap(StringSet& setNames);
  133. void Initialize(StringSet& setNames);
  134. void Add(_bstr_t& strName, _bstr_t& strPath);
  135. };
  136. //---------------------------------------------------------------------------
  137. // Compare Strings Class
  138. //---------------------------------------------------------------------------
  139. class CCompareStrings
  140. {
  141. public:
  142. CCompareStrings();
  143. CCompareStrings(StringSet& setNames);
  144. void Initialize(StringSet& setNames);
  145. bool IsMatch(LPCTSTR pszName);
  146. protected:
  147. class CCompareString
  148. {
  149. public:
  150. CCompareString(LPCTSTR pszCompare = NULL);
  151. CCompareString(const CCompareString& r);
  152. void Initialize(LPCTSTR pszCompare);
  153. bool IsMatch(LPCTSTR psz);
  154. protected:
  155. int m_nType;
  156. _bstr_t m_strCompare;
  157. };
  158. typedef std::vector<CCompareString> CompareStringVector;
  159. CompareStringVector m_vecCompareStrings;
  160. };