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.

354 lines
14 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 srcComp[LEN_Account]; // source computername
  120. WCHAR srcDomain[LEN_Domain+1];
  121. WCHAR tgtDomain[LEN_Domain+1];
  122. WCHAR srcDomainDns[LEN_Path];
  123. WCHAR tgtDomainDns[LEN_Path];
  124. WCHAR tgtComp[LEN_Account]; // target computername
  125. PSID srcSid;
  126. PSID tgtSid;
  127. DWORD srcDomainVer;
  128. DWORD tgtDomainVer;
  129. WCHAR prefix[UNLEN]; // prefix for added users
  130. WCHAR suffix[UNLEN]; // suffix for added users
  131. WCHAR globalPrefix[UNLEN];
  132. WCHAR globalSuffix[UNLEN];
  133. WCHAR addToGroup[GNLEN+1]; // optional group name to add new users to
  134. WCHAR addToGroupSource[GNLEN+1]; // optional group name to add source users to
  135. WCHAR logFile[MAX_PATH+1];
  136. EaPwdFilterInfo policyInfo;
  137. DWORD minPwdLength;
  138. CommaDelimitedLog passwordLog;
  139. DWORD flags; // operation flags
  140. BOOL nochange;
  141. WCHAR authUser[UNLEN+1]; //User name for source authentication
  142. WCHAR authPassword[UNLEN+1]; //Password for Authentication.
  143. WCHAR authDomain[LEN_Domain+1]; // Domain for the user passed for authentication
  144. HANDLE dsBindHandle; // Handle to the directory service. Should be init by DsBind.
  145. WCHAR srcNamingContext[LEN_Path]; // Naming context for the Adsi path
  146. WCHAR tgtNamingContext[LEN_Path]; // Naming context for the Target domain
  147. WCHAR tgtOUPath[LEN_Path]; // path for the OU container that is to be used to create objects in
  148. BOOL expandContainers; // Whether or not we want to expand the containers.
  149. BOOL expandMemberOf;
  150. BOOL fixMembership;
  151. IIManageDB * pDb;
  152. BOOL bUndo;
  153. BOOL bSameForest;
  154. long lActionID;
  155. long lUndoActionID;
  156. MCSDCTWORKEROBJECTSLib::IStatusObjPtr pStatus;
  157. WCHAR sDomUsers[UNLEN+1]; // Name of the domain users group in the source domain
  158. _bstr_t sExcUserProps; // user properties to exclude from migration
  159. _bstr_t sExcGroupProps; // group properties to exclude from migration
  160. _bstr_t sExcCmpProps; // computer properties to exclude from migration
  161. BOOL bExcludeProps;
  162. _bstr_t sWizard;
  163. Options() {
  164. srcComp[0] = 0;
  165. srcDomain[0] = 0;
  166. tgtDomain[0] = 0;
  167. srcDomainDns[0] = 0;
  168. tgtDomainDns[0] = 0;
  169. tgtComp[0] = 0;
  170. prefix[0] = 0;
  171. suffix[0] = 0;
  172. globalPrefix[0] = 0;
  173. globalSuffix[0] = 0;
  174. addToGroup[0] = 0;
  175. addToGroupSource[0] = 0;
  176. logFile[0] = 0;
  177. minPwdLength = 0;
  178. flags = 0;
  179. nochange = TRUE;
  180. authUser[0] = 0;
  181. authPassword[0] = 0;
  182. authDomain[0] = 0;
  183. srcNamingContext[0] = 0;
  184. tgtNamingContext[0] = 0;
  185. tgtOUPath[0] = 0;
  186. expandContainers = FALSE;
  187. fixMembership = TRUE;
  188. pDb = NULL;
  189. CoCreateInstance(CLSID_IManageDB,NULL,CLSCTX_ALL,IID_IIManageDB,(void**)&pDb);
  190. bUndo = FALSE;
  191. srcDomainVer = -1;
  192. tgtDomainVer = -1;
  193. srcSid = NULL;
  194. tgtSid = NULL;
  195. lUndoActionID = 0;
  196. pStatus = NULL;
  197. bSameForest = FALSE;
  198. sDomUsers[0] = 0;
  199. bExcludeProps = FALSE;
  200. }
  201. ~Options()
  202. {
  203. if( pDb )
  204. {
  205. pDb->Release();
  206. }
  207. if ( srcSid )
  208. FreeSid(srcSid);
  209. if ( tgtSid )
  210. FreeSid(tgtSid);
  211. }
  212. };
  213. typedef void ProgressFn(WCHAR const * mesg);
  214. int
  215. UserCopy(
  216. Options * options, // in - options
  217. TNodeListSortable * acctlist, // in - list of accounts to process
  218. ProgressFn * progress, // in - function called to log current progress
  219. TError & error, // in - TError to write messages to
  220. IStatusObj * pStatus, // in -status object to support cancellation
  221. void fn (void ), // in - window update function
  222. CProcessExtensions * pExts // in - pointer to extensions
  223. );
  224. int
  225. UserRename(
  226. Options * options, // in -options
  227. TNodeListSortable * acctlist, // in -list of accounts to process
  228. ProgressFn * progress, // in -window to write progress messages to
  229. TError & error, // in -window to write error messages to
  230. IStatusObj * pStatus, // in -status object to support cancellation
  231. void WindowUpdate (void ) // in - window update function
  232. );
  233. DWORD
  234. CopyServerName(
  235. WCHAR * uncServ ,// out-UNC server name
  236. TCHAR const * server // in -\\server or domain name
  237. );
  238. bool AddSidHistory(
  239. const Options * pOptions,
  240. const WCHAR * strSrcPrincipal,
  241. const WCHAR * strDestPrincipal,
  242. IStatusObj * pStatus = NULL,
  243. BOOL isFatal = TRUE
  244. );
  245. bool BindToDS(
  246. WCHAR * strDestDC,
  247. Options * pOpt
  248. );
  249. bool AddToOU (
  250. Options * options, // in -options
  251. TNodeListSortable * acctlist // in -list of accounts to process
  252. );
  253. void MakeFullyQualifiedAdsPath(
  254. WCHAR * sPath, //out- Fully qulified LDAP path to the object
  255. DWORD nPathLen, //in - MAX size, in characters, of the sPath buffer
  256. WCHAR * sSubPath, //in- LDAP subpath of the object
  257. WCHAR * tgtDomain, //in- Domain name where object exists.
  258. WCHAR * sDN //in- Deafault naming context for the Domain
  259. );
  260. BOOL GetDnsAndNetbiosFromName(WCHAR * name,WCHAR * netBios, WCHAR * dns);
  261. void FillupNamingContext(Options * options);
  262. bool IsAccountMigrated(
  263. TAcctReplNode * pNode, //in -Account node that contains the Account info
  264. Options * pOptions, //in -Options as specified by the user.
  265. IIManageDBPtr pDb, //in -Pointer to DB manager. We dont want to create this object for every account we process
  266. WCHAR * sTgtSam //in,out - Name of the target object that was copied if any.
  267. );
  268. bool CheckifAccountExists(
  269. Options const* options, //in-Options as set by the user
  270. WCHAR * acctName //in-Name of the account to look for
  271. );
  272. bool CallExtensions(
  273. CProcessExtensions * pExt, // in - Extension handler.
  274. Options * options, // in -options
  275. TNodeListSortable * acctlist, //in -Accounts to be copied.
  276. IStatusObj * pStatus, // in -status object to support cancellation
  277. ProgressFn * progress //in- Progress function.
  278. );
  279. void
  280. CopyGlobalGroupMembers(
  281. Options const * options ,// in -options
  282. TAcctReplNode * acct ,// in -account to copy
  283. TNodeListSortable * acctlist ,// in -list of accounts being copied
  284. void WindowUpdate (void ) // in - window update function
  285. );
  286. void
  287. CopyLocalGroupMembers(
  288. Options const * options ,// in -options
  289. TAcctReplNode * acct ,// in -account to copy
  290. TNodeListSortable * acctlist ,// in -list of accounts being copied
  291. void WindowUpdate (void ) // in - window update function
  292. );
  293. HRESULT
  294. CopySidHistoryProperty(
  295. Options * pOptions,
  296. TAcctReplNode * pNode,
  297. IStatusObj * pStatus
  298. );
  299. HRESULT
  300. GetRidPoolAllocator(
  301. Options * pOptions
  302. );
  303. void Mark( _bstr_t sMark, _bstr_t sObj);
  304. DWORD GetName(PSID pObjectSID, WCHAR * sNameAccount, WCHAR * sDomain);
  305. typedef HRESULT (CALLBACK * ADSGETOBJECT)(LPWSTR, REFIID, void**);
  306. extern ADSGETOBJECT ADsGetObject;
  307. #endif //__USERCOPY_HPP__