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.

287 lines
12 KiB

  1. /*---------------------------------------------------------------------------
  2. File: AcctRepl.h
  3. Comments: Definition of account replicator COM object.
  4. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 02/15/99 11:18:21
  9. ---------------------------------------------------------------------------
  10. */
  11. // AcctRepl.h : Declaration of the CAcctRepl
  12. #ifndef __ACCTREPL_H_
  13. #define __ACCTREPL_H_
  14. #include "resource.h" // main symbols
  15. #include "ProcExts.h"
  16. #import "MoveObj.tlb" no_namespace
  17. #include "UserCopy.hpp"
  18. #include "TNode.hpp"
  19. #include "Err.hpp"
  20. #include "ResStr.h"
  21. #include <map>
  22. #include <set>
  23. #include <string>
  24. using namespace std;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAcctRepl
  27. class ATL_NO_VTABLE CAcctRepl :
  28. public CComObjectRootEx<CComMultiThreadModel>,
  29. public CComCoClass<CAcctRepl, &CLSID_AcctRepl>,
  30. public IAcctRepl
  31. {
  32. public:
  33. CAcctRepl()
  34. {
  35. m_pUnkMarshaler = NULL;
  36. m_UpdateUserRights = FALSE;
  37. m_ChangeDomain = FALSE;
  38. m_Reboot = FALSE;
  39. m_RenameOnly = FALSE;
  40. m_pExt = NULL;
  41. m_bIgnorePathConflict = false;
  42. m_pUserRights = NULL;
  43. }
  44. DECLARE_REGISTRY_RESOURCEID(IDR_ACCTREPL)
  45. DECLARE_NOT_AGGREGATABLE(CAcctRepl)
  46. DECLARE_GET_CONTROLLING_UNKNOWN()
  47. DECLARE_PROTECT_FINAL_CONSTRUCT()
  48. BEGIN_COM_MAP(CAcctRepl)
  49. COM_INTERFACE_ENTRY(IAcctRepl)
  50. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  51. END_COM_MAP()
  52. HRESULT FinalConstruct()
  53. {
  54. if (FAILED(opt.openDBResult))
  55. return opt.openDBResult;
  56. return CoCreateFreeThreadedMarshaler(
  57. GetControllingUnknown(), &m_pUnkMarshaler.p);
  58. }
  59. void FinalRelease()
  60. {
  61. if (m_pUserRights)
  62. {
  63. m_pUserRights->Release();
  64. }
  65. m_pUnkMarshaler.Release();
  66. }
  67. CComPtr<IUnknown> m_pUnkMarshaler;
  68. // IAcctRepl
  69. public:
  70. STDMETHOD(Process)(IUnknown * pWorkItemIn);
  71. protected:
  72. HRESULT ResetMembersForUnivGlobGroups(Options * pOptions, TAcctReplNode * pAcct);
  73. HRESULT FillNodeFromPath( TAcctReplNode * pAcct, Options * pOptions, TNodeListSortable * acctList );
  74. Options opt;
  75. TNodeListSortable acctList;
  76. BOOL m_UpdateUserRights;
  77. BOOL m_ChangeDomain;
  78. BOOL m_Reboot;
  79. BOOL m_RenameOnly;
  80. struct SNamingAttribute
  81. {
  82. SNamingAttribute() :
  83. nMinRange(0),
  84. nMaxRange(0)
  85. {
  86. }
  87. SNamingAttribute(int nMinRange, int nMaxRange, wstring strName) :
  88. nMinRange(nMinRange),
  89. nMaxRange(nMaxRange),
  90. strName(strName)
  91. {
  92. }
  93. SNamingAttribute(const SNamingAttribute& r) :
  94. nMinRange(r.nMinRange),
  95. nMaxRange(r.nMaxRange),
  96. strName(r.strName)
  97. {
  98. }
  99. SNamingAttribute& operator =(const SNamingAttribute& r)
  100. {
  101. nMinRange = r.nMinRange;
  102. nMaxRange = r.nMaxRange;
  103. strName = r.strName;
  104. return *this;
  105. }
  106. int nMinRange;
  107. int nMaxRange;
  108. wstring strName;
  109. };
  110. typedef map<wstring, SNamingAttribute> CNamingAttributeMap;
  111. CNamingAttributeMap m_mapNamingAttribute;
  112. HRESULT GetNamingAttribute(LPCTSTR pszServer, LPCTSTR pszClass, SNamingAttribute& rNamingAttribute);
  113. //
  114. // Target Path Set
  115. // Maintains set of account node pointers sorted by target path.
  116. // Used to determine if target path already has been used.
  117. //
  118. struct lessTargetPath
  119. {
  120. bool operator()(const TAcctReplNode* pNodeA, const TAcctReplNode* pNodeB) const
  121. {
  122. const WCHAR PATH_SEPARATOR = L'/';
  123. const size_t PROVIDER_PREFIX_LENGTH = 7;
  124. PCWSTR pszPathA = pNodeA->GetTargetPath();
  125. PCWSTR pszPathB = pNodeB->GetTargetPath();
  126. if (pszPathA && (wcslen(pszPathA) > PROVIDER_PREFIX_LENGTH))
  127. {
  128. PCWSTR pch = wcschr(pszPathA + PROVIDER_PREFIX_LENGTH, PATH_SEPARATOR);
  129. if (pch)
  130. {
  131. pszPathA = pch + 1;
  132. }
  133. }
  134. if (pszPathB && (wcslen(pszPathB) > PROVIDER_PREFIX_LENGTH))
  135. {
  136. PCWSTR pch = wcschr(pszPathB + PROVIDER_PREFIX_LENGTH, PATH_SEPARATOR);
  137. if (pch)
  138. {
  139. pszPathB = pch + 1;
  140. }
  141. }
  142. return UStrICmp(pszPathA, pszPathB) < 0;
  143. }
  144. };
  145. typedef set<TAcctReplNode*, lessTargetPath> CTargetPathSet;
  146. bool m_bIgnorePathConflict;
  147. HRESULT Create2KObj( TAcctReplNode * pAcct, Options * pOptions, CTargetPathSet& setTargetPath);
  148. bool DoTargetPathConflict(CTargetPathSet& setTargetPath, TAcctReplNode* pAcct);
  149. void LoadOptionsFromVarSet(IVarSet * pVarSet);
  150. void LoadResultsToVarSet(IVarSet * pVarSet);
  151. DWORD PopulateAccountListFromVarSet(IVarSet * pVarSet);
  152. HRESULT UpdateUserRights(IStatusObj* pStatus);
  153. void WriteOptionsToLog();
  154. int CopyObj(
  155. Options * options, // in -options
  156. TNodeListSortable * acctlist, // in -list of accounts to process
  157. ProgressFn * progress, // in -window to write progress messages to
  158. TError & error, // in -window to write error messages to
  159. IStatusObj * pStatus, // in -status object to support cancellation
  160. void WindowUpdate (void ) // in - window update function
  161. );
  162. int UndoCopy(
  163. Options * options, // in -options
  164. TNodeListSortable * acctlist, // in -list of accounts to process
  165. ProgressFn * progress, // in -window to write progress messages to
  166. TError & error, // in -window to write error messages to
  167. IStatusObj * pStatus, // in -status object to support cancellation
  168. void WindowUpdate (void ) // in - window update function
  169. );
  170. bool BothWin2K( Options * pOptions );
  171. int CopyObj2K( Options * pOptions, TNodeListSortable * acctList, ProgressFn * progress, IStatusObj * pStatus );
  172. int DeleteObject( Options * pOptions, TNodeListSortable * acctList, ProgressFn * progress, IStatusObj * pStatus );
  173. HRESULT UpdateGroupMembership(Options * pOptions, TNodeListSortable * acctlist,ProgressFn * progress, IStatusObj * pStatus );
  174. private:
  175. HRESULT UpdateMemberToGroups(TNodeListSortable * acctList, Options * pOptions, BOOL bGrpsOnly);
  176. BOOL StuffComputerNameinLdapPath(WCHAR * sAdsPath, DWORD nPathLen, WCHAR * sSubPath, Options * pOptions, BOOL bTarget = TRUE);
  177. BOOL CheckBuiltInWithNTApi( PSID pSid, WCHAR * pNode, Options * pOptions );
  178. BOOL GetNt4Type( WCHAR const * sComp, WCHAR const * sAcct, WCHAR * sType);
  179. BOOL GetSamFromPath(_bstr_t sPath, _bstr_t& sSam, _bstr_t& sType, _bstr_t& sSrcName, _bstr_t& sTgtName, long& grpType, Options * pOptions);
  180. BOOL IsContainer( TAcctReplNode * pNode, IADsContainer ** ppCont);
  181. BOOL ExpandContainers( TNodeListSortable * acctlist, Options *pOptions, ProgressFn * progress );
  182. CProcessExtensions * m_pExt;
  183. HRESULT CAcctRepl::RemoveMembers(TAcctReplNode * pAcct, Options * pOptions);
  184. bool FillPathInfo(TAcctReplNode * pAcct,Options * pOptions);
  185. bool AcctReplFullPath(TAcctReplNode * pAcct, Options * pOptions);
  186. BOOL NeedToProcessAccount(TAcctReplNode * pAcct, Options * pOptions);
  187. BOOL ExpandMembership(TNodeListSortable *acctlist, Options *pOptions, TNodeListSortable *pNewAccts, ProgressFn * progress, BOOL bGrpsOnly, BOOL bAnySourceDomain = FALSE);
  188. int MoveObj2K(Options * options, TNodeListSortable * acctlist, ProgressFn * progress, IStatusObj * pStatus);
  189. HRESULT ResetObjectsMembership(Options * pOptions, TNodeListSortable * pMember, IIManageDBPtr pDb);
  190. HRESULT RecordAndRemoveMemberOf ( Options * pOptions, TAcctReplNode * pAcct, TNodeListSortable * pMember);
  191. HRESULT RecordAndRemoveMember (Options * pOptions,TAcctReplNode * pAcct,TNodeListSortable * pMember);
  192. HRESULT MoveObject( TAcctReplNode * pAcct,Options * pOptions,IMoverPtr pMover);
  193. HRESULT ResetGroupsMembers( Options * pOptions, TAcctReplNode * pAcct, TNodeListSortable * pMember, IIManageDBPtr pDb );
  194. void ResetTypeOfPreviouslyMigratedGroups(Options* pOptions);
  195. HRESULT ADsPathFromDN( Options * pOptions,_bstr_t sDN,WCHAR * sPath, bool bWantLDAP = true);
  196. void SimpleADsPathFromDN( Options * pOptions,WCHAR const * sDN,WCHAR * sPath);
  197. BOOL FillNamingContext(Options * pOptions);
  198. HRESULT MakeAcctListFromMigratedObjects(Options * pOptions, long lUndoActionID, TNodeListSortable *& pAcctList,BOOL bReverseDomains);
  199. void AddPrefixSuffix( TAcctReplNode * pNode, Options * pOptions );
  200. HRESULT LookupAccountInTarget(Options * pOptions, WCHAR * sSam, WCHAR * sPath);
  201. void UpdateMemberList(TNodeListSortable * pMemberList,TNodeListSortable * acctlist);
  202. void BuildTargetPath(WCHAR const * sCN, WCHAR const * tgtOU, WCHAR * stgtPath);
  203. HRESULT BetterHR(HRESULT hr);
  204. HRESULT BuildSidPath(
  205. IADs * pAds, //in- pointer to the object whose sid we are retrieving.
  206. WCHAR * sSidPath, //out-path to the LDAP://<SID=###> object
  207. WCHAR * sSam, //out-Sam name of the object
  208. WCHAR * sDomain, //out-Domain name where this object resides.
  209. Options * pOptions, //in- Options
  210. PSID * ppSid //out-Pointer to the binary sid
  211. );
  212. HRESULT CheckClosedSetGroups(
  213. Options * pOptions, // in - options for the migration
  214. TNodeListSortable * pAcctList, // in - list of accounts to migrate
  215. ProgressFn * progress, // in - progress function to display progress messages
  216. IStatusObj * pStatus // in - status object to support cancellation
  217. );
  218. BOOL CanMoveInMixedMode(TAcctReplNode *pAcct,TNodeListSortable * acctlist,Options * pOptions);
  219. HRESULT QueryPrimaryGroupMembers(BSTR cols, Options * pOptions, DWORD rid, IEnumVARIANT** pEnum);
  220. bool GetRidForGroup(Options * pOptions, WCHAR * sGroupSam, DWORD& rid);
  221. HRESULT AddPrimaryGroupMembers(Options * pOptions, SAFEARRAY * multiVals, WCHAR * sGroupSam);
  222. HRESULT GetThePrimaryGroupMembers(Options * pOptions, WCHAR * sGroupSam, IEnumVARIANT ** pVar);
  223. BOOL TruncateSam(WCHAR * tgtname, TAcctReplNode * acct, Options * options, TNodeListSortable * acctList);
  224. BOOL DoesTargetObjectAlreadyExist(TAcctReplNode * pAcct, Options * pOptions);
  225. void GetAccountUPN(Options * pOptions, _bstr_t sSName, _bstr_t& sSUPN);
  226. HRESULT UpdateManagement(TNodeListSortable * acctList, Options * pOptions);
  227. _bstr_t GetUnEscapedNameWithFwdSlash(_bstr_t strName);
  228. _bstr_t GetCNFromPath(_bstr_t sPath);
  229. BOOL ReplaceSourceInLocalGroup(TNodeListSortable * acctList, Options * pOptions, IStatusObj *pStatus);
  230. _bstr_t GetDomainOfMigratedForeignSecPrincipal(IADs * pAds, _bstr_t sPath);
  231. void RemoveSourceAccountFromGroup(IADsGroup * pGroup, IVarSetPtr pMOTVarSet, Options * pOptions);
  232. void VerifyAndUpdateMigratedTarget(Options* pOptions, IVarSetPtr spAccountVarSet);
  233. typedef std::map<_bstr_t,_bstr_t> CGroupNameMap;
  234. CGroupNameMap m_IgnoredGrpMap;
  235. IUserRights* m_pUserRights;
  236. HRESULT EnumerateAccountRights(BOOL bTarget, TAcctReplNode* pAcct);
  237. HRESULT AddAccountRights(BOOL bTarget, TAcctReplNode* pAcct);
  238. HRESULT RemoveAccountRights(BOOL bTarget, TAcctReplNode* pAcct);
  239. IVarSetPtr GenerateSourceToTargetDnMap(TNodeListSortable* acctlist);
  240. };
  241. typedef void ProgressFn(WCHAR const * mesg);
  242. typedef HRESULT (CALLBACK * ADSGETOBJECT)(LPWSTR, REFIID, void**);
  243. extern ADSGETOBJECT ADsGetObject;
  244. #endif //__ACCTREPL_H_