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.

263 lines
5.9 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. namespace NAMECRACKER
  25. {
  26. extern const _TCHAR CANONICAL_DELIMITER;
  27. extern const _TCHAR RDN_DELIMITER;
  28. extern const _TCHAR SAM_DELIMITER;
  29. extern const _TCHAR SAM_INVALID_CHARACTERS[];
  30. extern const _TCHAR EXCLUDE_SAM_INVALID_CHARACTERS[];
  31. }
  32. //---------------------------------------------------------------------------
  33. // Name Cracker Class
  34. //---------------------------------------------------------------------------
  35. class CNameCracker
  36. {
  37. public:
  38. CNameCracker();
  39. ~CNameCracker();
  40. void SetDomainNames(LPCTSTR pszDnsName, LPCTSTR pszFlatName, LPCTSTR pszDomainController)
  41. {
  42. m_strDnsName = pszDnsName;
  43. m_strFlatName = pszFlatName;
  44. m_strDomainController = pszDomainController;
  45. }
  46. void SetDefaultContainer(IADsContainerPtr& spContainer)
  47. {
  48. m_spDefaultContainer = spContainer;
  49. }
  50. void CrackNames(const StringVector& vecNames);
  51. const CStringSet& GetResolvedNames() const
  52. {
  53. return m_setResolvedNames;
  54. }
  55. const StringVector& GetUnResolvedNames() const
  56. {
  57. return m_vecUnResolvedNames;
  58. }
  59. void SiftExcludeNames(const StringSet& setExcludeNames, const StringSet& setNamingAttributes, StringSet& setExcludeRDNs, StringSet& setExcludeSamAccountNames) const;
  60. protected:
  61. void Separate(
  62. const StringVector& vecNames,
  63. StringVector& vecCanonicalNames,
  64. StringVector& vecSamAccountNames,
  65. StringVector& vecRelativeDistinguishedNames
  66. );
  67. void CrackCanonicalNames(const StringVector& vecCanonicalNames, StringVector& vecUnResolvedNames);
  68. void CrackSamAccountNames(const StringVector& vecSamAccountNames, StringVector& vecUnResolvedNames);
  69. void CrackRelativeDistinguishedNames(const StringVector& vecRelativeDistinguishedNames, StringVector& vecUnResolvedNames);
  70. typedef enum
  71. {
  72. CANONICAL_NAME,
  73. NT4_ACCOUNT_NAME,
  74. }
  75. NAME_FORMAT;
  76. struct SName
  77. {
  78. SName(LPCTSTR pszPartial, LPCTSTR pszComplete) :
  79. strPartial(pszPartial),
  80. strComplete(pszComplete)
  81. {
  82. }
  83. SName(const SName& r) :
  84. strPartial(r.strPartial),
  85. strComplete(r.strComplete),
  86. strResolved(r.strResolved)
  87. {
  88. }
  89. SName& operator =(const SName& r)
  90. {
  91. strPartial = r.strPartial;
  92. strComplete = r.strComplete;
  93. strResolved = r.strResolved;
  94. return *this;
  95. }
  96. tstring strPartial;
  97. tstring strComplete;
  98. tstring strResolved;
  99. };
  100. typedef std::vector<SName> CNameVector;
  101. void CrackNames(NAME_FORMAT eFormat, CNameVector& vecNames);
  102. protected:
  103. tstring m_strDnsName;
  104. tstring m_strFlatName;
  105. tstring m_strDomainController;
  106. IADsContainerPtr m_spDefaultContainer;
  107. CStringSet m_setResolvedNames;
  108. StringVector m_vecUnResolvedNames;
  109. };
  110. //---------------------------------------------------------------------------
  111. // Ignore Case String Less
  112. //---------------------------------------------------------------------------
  113. struct IgnoreCaseStringLess :
  114. public std::binary_function<_bstr_t, _bstr_t, bool>
  115. {
  116. bool operator()(const _bstr_t& x, const _bstr_t& y) const;
  117. };
  118. //---------------------------------------------------------------------------
  119. // Domain To Path Map Class
  120. //---------------------------------------------------------------------------
  121. class CDomainToPathMap :
  122. public std::map<_bstr_t, StringSet, IgnoreCaseStringLess>
  123. {
  124. public:
  125. CDomainToPathMap()
  126. {
  127. }
  128. void Initialize(LPCTSTR pszDefaultDomainDns, LPCTSTR pszDefaultDomainFlat, const StringSet& setNames);
  129. protected:
  130. static bool GetValidDomainName(_bstr_t& strDomainName);
  131. };
  132. //---------------------------------------------------------------------------
  133. // Name To Path Map Class
  134. //---------------------------------------------------------------------------
  135. class CNameToPathMap :
  136. public std::map<_bstr_t, StringSet, IgnoreCaseStringLess>
  137. {
  138. public:
  139. CNameToPathMap();
  140. CNameToPathMap(StringSet& setNames);
  141. void Initialize(StringSet& setNames);
  142. void Add(_bstr_t& strName, _bstr_t& strPath);
  143. };
  144. //---------------------------------------------------------------------------
  145. // Compare Strings Class
  146. //---------------------------------------------------------------------------
  147. class CCompareStrings
  148. {
  149. public:
  150. CCompareStrings();
  151. CCompareStrings(StringSet& setNames);
  152. void Initialize(StringSet& setNames);
  153. bool IsMatch(LPCTSTR pszName);
  154. protected:
  155. class CCompareString
  156. {
  157. public:
  158. CCompareString(LPCTSTR pszCompare = NULL);
  159. CCompareString(const CCompareString& r);
  160. void Initialize(LPCTSTR pszCompare);
  161. bool IsMatch(LPCTSTR psz);
  162. protected:
  163. int m_nType;
  164. _bstr_t m_strCompare;
  165. };
  166. typedef std::vector<CCompareString> CompareStringVector;
  167. CompareStringVector m_vecCompareStrings;
  168. };
  169. //---------------------------------------------------------------------------
  170. // Compare RDNs Class
  171. //---------------------------------------------------------------------------
  172. class CCompareRDNs
  173. {
  174. public:
  175. CCompareRDNs();
  176. CCompareRDNs(StringSet& setNames);
  177. void Initialize(StringSet& setNames);
  178. bool IsMatch(LPCTSTR pszName);
  179. protected:
  180. class CCompareRDN
  181. {
  182. public:
  183. CCompareRDN(LPCTSTR pszCompare = NULL);
  184. CCompareRDN(const CCompareRDN& r);
  185. void Initialize(LPCTSTR pszCompare);
  186. bool IsMatch(LPCTSTR psz);
  187. protected:
  188. int m_nPatternType;
  189. _bstr_t m_strType;
  190. _bstr_t m_strValue;
  191. };
  192. typedef std::vector<CCompareRDN> CompareVector;
  193. CompareVector m_vecCompare;
  194. };