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.

368 lines
15 KiB

  1. #ifndef __USERCOPY_HPP__
  2. #define __USERCOPY_HPP__
  3. //#pragma title("usercopy.hpp- class definitions for usercopy")
  4. /*
  5. ================================================================================
  6. (c) Copyright 1995-1998, Mission Critical Software, Inc., All Rights Reserved
  7. Proprietary and confidential to Mission Critical Software, Inc.
  8. Program - usercopy
  9. Class - LAN Manager Utilities
  10. Author - Christy Boles
  11. Created - 09/04/97
  12. Description- class definitions to allow usercopy to process subsets of accounts.
  13. The list of accounts will be generated by the GUI, and will consist
  14. of a TNodeList of TAcctNodes. Users will be added from the front of
  15. the list, and groups will be added at the end.
  16. Updates - 01/30/98 CAB Added strong password generation
  17. ================================================================================
  18. */
  19. #include <lmcons.h>
  20. #include "TNode.hpp"
  21. #include <share.h> // for _SH_DENYNO
  22. #include "EaLen.hpp"
  23. #include "Common.hpp"
  24. #include "Err.hpp"
  25. #include "UString.hpp"
  26. #include "CommaLog.hpp"
  27. #include "TARNode.hpp"
  28. #include "WorkObj.h"
  29. #include "ProcExts.h"
  30. //#import "\bin\DBManager.tlb" no_namespace, named_guids
  31. //#import "\bin\McsDctWorkerObjects.tlb"
  32. #import "DBMgr.tlb" no_namespace, named_guids
  33. #import "WorkObj.tlb"
  34. #define AR_BUFSIZE ((size_t)16000)
  35. #define AR_NUM_IN_BUF 5000
  36. #define F_REPLACE 0x00000001 // replace account info
  37. #define F_GROUP 0x00000002 // copy global groups
  38. #define F_LGROUP 0x00000004 // copy local groups
  39. #define F_USERS 0x00000008 // copy users
  40. #define F_DISABLE_ALL 0x00000010 // disable all accounts
  41. #define F_DISABLE_SPECIAL 0x00000020 // disable Account Ops, Backup Ops, Administrators, Domain Admins
  42. #define F_STRONGPW_ALL 0x00000040 // generate strong passwords for all accounts
  43. #define F_STRONGPW_SPECIAL 0x00000080 // generate strong passwords for Account Ops, Backup Ops, Admins, and Domain Admins
  44. #define F_MACHINE 0x00000100 // copy computer accounts
  45. #define F_REMOVE_OLD_MEMBERS 0x00000200 // remove old members from replaced groups
  46. #define F_DISABLESOURCE 0x00000400 // disable copied user accounts on source domain
  47. #define F_AddToSrcGroupLocal 0x00000800 // indicates that the add-to group is on the target domain
  48. #define F_AddToGroupLocal 0x00001000 // add to group is a local group
  49. #define F_INTERACT 0x00002000 // use command-line parms to initiate interactive gui session
  50. #define F_WARN_FULLNAME 0x00004000 // warn before replacing accounts w/different fullname
  51. #define F_WARN_COMMENT 0x00008000 // warn before replacing accounts w/different comment
  52. #define F_CopyPasswords 0x00010000 // copy passwords
  53. #define F_RevokeOldRights 0x00020000 // removes old user rights from copied accounts
  54. #define F_AddSidHistory 0x00040000 // Add SID of source account to the SID history of the target account.
  55. #define F_TranslateProfiles 0x00080000 // Translate roaming profiles
  56. #define F_OUS 0x00100000 // Process the organizational units.
  57. #define F_COMPUTERS 0x00200000 // Process the computer accounts in Acct replication
  58. #define F_COPY_CONT_CONTENT 0x00400000 // Copy the container contents along with the container when copying accounts.
  59. #define F_COPY_MIGRATED_ACCT 0x00800000 // When expanding containers/membership include accounts that have already been migrated.
  60. #define F_MOVE_REPLACED_ACCT 0x01000000 // move a replaces account to the user-specified OU.
  61. #define AR_AccountComputer (0x80000000)
  62. #define AR_AccountComputerPdc (0x40000000)
  63. #define ADMINISTRATORS 1
  64. #define ACCOUNT_OPERATORS 2
  65. #define BACKUP_OPERATORS 3
  66. #define DOMAIN_ADMINS 4
  67. #define CREATOR_OWNER 5
  68. #define DOMAIN_USERS 6
  69. #define DOMAIN_CONTROLLERS 7
  70. #define DOMAIN_COMPUTERS 8
  71. struct AccountStats
  72. {
  73. long users;
  74. long globals;
  75. long locals;
  76. long computers;
  77. long generic;
  78. };
  79. class TANode:public TNode
  80. {
  81. BOOL bMarked;
  82. PSID pSid;
  83. WCHAR name[LEN_Account];
  84. public:
  85. TANode() { name[0] = 0; bMarked = FALSE; pSid = NULL;}
  86. TANode(WCHAR const * n)
  87. {
  88. safecopy(name,n);
  89. bMarked = FALSE;
  90. pSid = NULL;
  91. }
  92. ~TANode()
  93. {
  94. if ( pSid )
  95. delete pSid;
  96. }
  97. BOOL Marked() { return bMarked; }
  98. void Mark() { bMarked = TRUE; }
  99. void SetSid(PSID p) { pSid = p; }
  100. void SetName(WCHAR const * n){ safecopy(name,n); }
  101. WCHAR * GetName() { return name; }
  102. PSID GetSid() { return pSid;}
  103. };
  104. // Password generation service
  105. #define PWGEN_MIN_LENGTH 8 // enforced minimum password length
  106. #define PWGEN_MAX_LENGTH 14 // enforced maximum password length
  107. struct EaPwdFilterInfo
  108. {
  109. DWORD bEnforce;
  110. DWORD bAllowName;
  111. DWORD minLower;
  112. DWORD minUpper;
  113. DWORD minDigits;
  114. DWORD minSpecial;
  115. DWORD maxConsecutiveAlpha;
  116. };
  117. struct Options
  118. {
  119. WCHAR srcDomain[LEN_Domain];
  120. WCHAR srcDomainDns[LEN_Domain];
  121. WCHAR srcDomainFlat[LEN_Domain];
  122. WCHAR tgtDomain[LEN_Domain];
  123. WCHAR tgtDomainDns[LEN_Domain];
  124. WCHAR tgtDomainFlat[LEN_Domain];
  125. WCHAR srcComp[LEN_Account]; // source computername
  126. WCHAR srcCompDns[LEN_Account]; // DNS source computername
  127. WCHAR srcCompFlat[LEN_Account]; // flat source computername
  128. WCHAR tgtComp[LEN_Account]; // target computername
  129. WCHAR tgtCompDns[LEN_Account]; // DNS target computername
  130. WCHAR tgtCompFlat[LEN_Account]; // flat target computername
  131. PSID srcSid;
  132. PSID tgtSid;
  133. DWORD srcDomainVer;
  134. DWORD srcDomainVerMinor;
  135. DWORD tgtDomainVer;
  136. DWORD tgtDomainVerMinor;
  137. WCHAR prefix[UNLEN]; // prefix for added users
  138. WCHAR suffix[UNLEN]; // suffix for added users
  139. WCHAR globalPrefix[UNLEN];
  140. WCHAR globalSuffix[UNLEN];
  141. WCHAR addToGroup[GNLEN+1]; // optional group name to add new users to
  142. WCHAR addToGroupSource[GNLEN+1]; // optional group name to add source users to
  143. WCHAR logFile[MAX_PATH+1];
  144. EaPwdFilterInfo policyInfo;
  145. DWORD minPwdLength;
  146. CommaDelimitedLog passwordLog;
  147. DWORD flags; // operation flags
  148. BOOL nochange;
  149. WCHAR authUser[UNLEN+1]; //User name for source authentication
  150. WCHAR authPassword[UNLEN+1]; //Password for Authentication.
  151. WCHAR authDomain[LEN_Domain+1]; // Domain for the user passed for authentication
  152. HANDLE dsBindHandle; // Handle to the directory service. Should be init by DsBind.
  153. WCHAR srcNamingContext[LEN_Path]; // Naming context for the Adsi path
  154. WCHAR tgtNamingContext[LEN_Path]; // Naming context for the Target domain
  155. WCHAR tgtOUPath[LEN_Path]; // path for the OU container that is to be used to create objects in
  156. BOOL expandContainers; // Whether or not we want to expand the containers.
  157. BOOL expandMemberOf;
  158. BOOL fixMembership;
  159. IIManageDB * pDb;
  160. HRESULT openDBResult;
  161. BOOL bUndo;
  162. BOOL bSameForest;
  163. long lActionID;
  164. long lUndoActionID;
  165. MCSDCTWORKEROBJECTSLib::IStatusObjPtr pStatus;
  166. WCHAR sDomUsers[UNLEN+1]; // Name of the domain users group in the source domain
  167. _bstr_t sExcSystemProps; // system properties to exclude from migration
  168. _bstr_t sExcUserProps; // user properties to exclude from migration
  169. _bstr_t sExcInetOrgPersonProps; // InetOrgPerson properties to exclude from migration
  170. _bstr_t sExcGroupProps; // group properties to exclude from migration
  171. _bstr_t sExcCmpProps; // computer properties to exclude from migration
  172. BOOL bExcludeProps;
  173. _bstr_t sWizard;
  174. Options() {
  175. srcDomain[0] = 0;
  176. srcDomainDns[0] = 0;
  177. srcDomainFlat[0] = 0;
  178. tgtDomain[0] = 0;
  179. tgtDomainDns[0] = 0;
  180. tgtDomainFlat[0] = 0;
  181. srcComp[0] = 0;
  182. srcCompDns[0] = 0;
  183. srcCompFlat[0] = 0;
  184. tgtComp[0] = 0;
  185. tgtCompDns[0] = 0;
  186. tgtCompFlat[0] = 0;
  187. prefix[0] = 0;
  188. suffix[0] = 0;
  189. globalPrefix[0] = 0;
  190. globalSuffix[0] = 0;
  191. addToGroup[0] = 0;
  192. addToGroupSource[0] = 0;
  193. logFile[0] = 0;
  194. minPwdLength = 0;
  195. flags = 0;
  196. nochange = TRUE;
  197. authUser[0] = 0;
  198. authPassword[0] = 0;
  199. authDomain[0] = 0;
  200. srcNamingContext[0] = 0;
  201. tgtNamingContext[0] = 0;
  202. tgtOUPath[0] = 0;
  203. expandContainers = FALSE;
  204. fixMembership = TRUE;
  205. pDb = NULL;
  206. openDBResult = CoCreateInstance(CLSID_IManageDB,NULL,CLSCTX_ALL,IID_IIManageDB,(void**)&pDb);
  207. bUndo = FALSE;
  208. srcDomainVer = -1;
  209. srcDomainVerMinor = -1;
  210. tgtDomainVer = -1;
  211. tgtDomainVerMinor = -1;
  212. srcSid = NULL;
  213. tgtSid = NULL;
  214. lUndoActionID = 0;
  215. pStatus = NULL;
  216. bSameForest = FALSE;
  217. sDomUsers[0] = 0;
  218. bExcludeProps = FALSE;
  219. }
  220. ~Options()
  221. {
  222. if( pDb )
  223. {
  224. pDb->Release();
  225. }
  226. if ( srcSid )
  227. FreeSid(srcSid);
  228. if ( tgtSid )
  229. FreeSid(tgtSid);
  230. }
  231. };
  232. typedef void ProgressFn(WCHAR const * mesg);
  233. int
  234. UserCopy(
  235. Options * options, // in - options
  236. TNodeListSortable * acctlist, // in - list of accounts to process
  237. ProgressFn * progress, // in - function called to log current progress
  238. TError & error, // in - TError to write messages to
  239. IStatusObj * pStatus, // in -status object to support cancellation
  240. void fn (void ), // in - window update function
  241. CProcessExtensions * pExts // in - pointer to extensions
  242. );
  243. int
  244. UserRename(
  245. Options * options, // in -options
  246. TNodeListSortable * acctlist, // in -list of accounts to process
  247. ProgressFn * progress, // in -window to write progress messages to
  248. TError & error, // in -window to write error messages to
  249. IStatusObj * pStatus, // in -status object to support cancellation
  250. void WindowUpdate (void ) // in - window update function
  251. );
  252. bool AddSidHistory(
  253. const Options * pOptions,
  254. const WCHAR * strSrcPrincipal,
  255. const WCHAR * strDestPrincipal,
  256. IStatusObj * pStatus = NULL,
  257. BOOL isFatal = TRUE
  258. );
  259. bool BindToDS(
  260. Options * pOpt
  261. );
  262. bool AddToOU (
  263. Options * options, // in -options
  264. TNodeListSortable * acctlist // in -list of accounts to process
  265. );
  266. void MakeFullyQualifiedAdsPath(
  267. WCHAR * sPath, //out- Fully qulified LDAP path to the object
  268. DWORD nPathLen, //in - MAX size, in characters, of the sPath buffer
  269. WCHAR * sSubPath, //in- LDAP subpath of the object
  270. WCHAR * tgtDomain, //in- Domain name where object exists.
  271. WCHAR * sDN //in- Deafault naming context for the Domain
  272. );
  273. void FillupNamingContext(Options * options);
  274. bool IsAccountMigrated(
  275. TAcctReplNode * pNode, //in -Account node that contains the Account info
  276. Options * pOptions, //in -Options as specified by the user.
  277. IIManageDBPtr pDb, //in -Pointer to DB manager. We dont want to create this object for every account we process
  278. WCHAR * sTgtSam //in,out - Name of the target object that was copied if any.
  279. );
  280. bool CheckifAccountExists(
  281. Options const* options, //in-Options as set by the user
  282. WCHAR * acctName //in-Name of the account to look for
  283. );
  284. bool CallExtensions(
  285. CProcessExtensions * pExt, // in - Extension handler.
  286. Options * options, // in -options
  287. TNodeListSortable * acctlist, //in -Accounts to be copied.
  288. IStatusObj * pStatus, // in -status object to support cancellation
  289. ProgressFn * progress //in- Progress function.
  290. );
  291. void
  292. CopyGlobalGroupMembers(
  293. Options const * options ,// in -options
  294. TAcctReplNode * acct ,// in -account to copy
  295. TNodeListSortable * acctlist ,// in -list of accounts being copied
  296. void WindowUpdate (void ) // in - window update function
  297. );
  298. void
  299. CopyLocalGroupMembers(
  300. Options const * options ,// in -options
  301. TAcctReplNode * acct ,// in -account to copy
  302. TNodeListSortable * acctlist ,// in -list of accounts being copied
  303. void WindowUpdate (void ) // in - window update function
  304. );
  305. HRESULT
  306. CopySidHistoryProperty(
  307. Options * pOptions,
  308. TAcctReplNode * pNode,
  309. IStatusObj * pStatus
  310. );
  311. HRESULT
  312. __stdcall
  313. GetRidPoolAllocator(
  314. Options * pOptions
  315. );
  316. void Mark( _bstr_t sMark, _bstr_t sObj);
  317. void BatchMark(const EAMAccountStats& stats);
  318. DWORD GetName(PSID pObjectSID, WCHAR * sNameAccount, WCHAR * sDomain);
  319. typedef HRESULT (CALLBACK * ADSGETOBJECT)(LPWSTR, REFIID, void**);
  320. extern ADSGETOBJECT ADsGetObject;
  321. #endif //__USERCOPY_HPP__