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.

674 lines
22 KiB

  1. '------------------------------------------------------
  2. ' Constant Definitions
  3. '------------------------------------------------------
  4. '------------------------------------------------------
  5. ' AceMask
  6. Const ADS_RIGHT_DELETE = &H10000&
  7. Const ADS_RIGHT_READ_CONTROL = &H20000&
  8. Const ADS_RIGHT_WRITE_DAC = &H40000&
  9. Const ADS_RIGHT_WRITE_OWNER = &H80000&
  10. Const ADS_RIGHT_SYNCHRONIZE = &H100000&
  11. Const ADS_RIGHT_ACCESS_SYSTEM_SECURITY = &H1000000&
  12. Const ADS_RIGHT_GENERIC_READ = &H80000000&
  13. Const ADS_RIGHT_GENERIC_WRITE = &H40000000&
  14. Const ADS_RIGHT_GENERIC_EXECUTE = &H20000000&
  15. Const ADS_RIGHT_GENERIC_ALL = &H10000000&
  16. Const ADS_RIGHT_DS_CREATE_CHILD = &H1&
  17. Const ADS_RIGHT_DS_DELETE_CHILD = &H2&
  18. Const ADS_RIGHT_ACTRL_DS_LIST = &H4&
  19. Const ADS_RIGHT_DS_SELF = &H8&
  20. Const ADS_RIGHT_DS_READ_PROP = &H10&
  21. Const ADS_RIGHT_DS_WRITE_PROP = &H20&
  22. Const ADS_RIGHT_DS_DELETE_TREE = &H40&
  23. Const ADS_RIGHT_DS_LIST_OBJECT = &H80&
  24. Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100&
  25. '---------------------------------------------------------
  26. ' Ace Type
  27. Const ADS_ACETYPE_ACCESS_ALLOWED = 0
  28. Const ADS_ACETYPE_ACCESS_DENIED = &H1&
  29. Const ADS_ACETYPE_SYSTEM_AUDIT = &H2&
  30. Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &H5&
  31. Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6&
  32. Const ADS_ACETYPE_SYSTEM_AUDIT_OBJECT = &H7&
  33. '---------------------------------------------------------
  34. ' Ace Flags
  35. Const ADS_ACEFLAG_INHERIT_ACE = &H2&
  36. Const ADS_ACEFLAG_NO_PROPAGATE_INHERIT_ACE = &H4&
  37. Const ADS_ACEFLAG_INHERIT_ONLY_ACE = &H8&
  38. Const ADS_ACEFLAG_INHERITED_ACE = &H10&
  39. Const ADS_ACEFLAG_VALID_INHERIT_FLAGS = &H1f&
  40. Const ADS_ACEFLAG_SUCCESSFUL_ACCESS = &H40&
  41. Const ADS_ACEFLAG_FAILED_ACCESS = &H80&
  42. '---------------------------------------------------------
  43. ' AceFlagType: ADS_FLAGTYPE_ENUM
  44. Const ADS_FLAG_OBJECT_TYPE_PRESENT = &H1&
  45. Const ADS_FLAG_INHERITED_OBJECT_TYPE_PRESENT = &H2&
  46. ' manual error handling
  47. On error resume next
  48. ' Checking command line parameters
  49. set args = Wscript.Arguments
  50. if args.count <> 2 Then
  51. wscript.echo "The syntax of the command is:"
  52. wscript.echo "cscript UpdateACL.vbs [ /Domain | /Forest ] <DomainDNSName>"
  53. wscript.echo "Example: cscript UpdateACL.vbs /Domain example.microsoft.com"
  54. wscript.quit
  55. End If
  56. domain = ""
  57. If args.count = 2 then
  58. domain = args(1)
  59. end if
  60. If args (0) = "/Domain" Then
  61. call ACLDomain( domain )
  62. else
  63. if args (0) = "/Forest" Then
  64. call Forest( domain )
  65. else
  66. wscript.echo "The syntax of the command is:"
  67. wscript.echo "cscript UpdateACL.vbs [ /Domain | /Forest ] <DomainDNSName>"
  68. wscript.echo "Example: cscript UpdateACL.vbs /Domain example.microsoft.com"
  69. wscript.quit
  70. end if
  71. end if
  72. '====================================================================
  73. ' Work that has to be performed on a domain level
  74. '====================================================================
  75. Function ACLDomain ( domain )
  76. On error resume next
  77. if domain = "" then
  78. Set rootDSE = GetObject("LDAP://RootDSE")
  79. Set dom = GetObject("LDAP://" & rootDSE.Get("defaultNamingContext"))
  80. else
  81. Set dom = GetObject("LDAP://" & domain )
  82. if err <> 0 then
  83. wscript.echo "Error: Unable to bind to domain " & domain & " , Error is: " & err
  84. wscript.quit
  85. end if
  86. end if
  87. Set sd = dom.Get("ntSecurityDescriptor")
  88. if err <> 0 then
  89. wscript.error "Error reading security descriptor, error is " & err
  90. wscript.quit
  91. end if
  92. Set dacl = sd.DiscretionaryACL
  93. '---------------------------------------------------------------------------------
  94. ' Adding the Anonymous Logon group to the Pre-Windows 2000 Compatible Access group
  95. ' This should only be done if the Everyone is member of the Pre-Windows 2000 Compatible Access group
  96. '---------------------------------------------------------------------------------
  97. set grp = dom.GetObject ("group", "CN=Pre-Windows 2000 Compatible Access,CN=Builtin")
  98. ' S-1-1-0 is in the Everyone group:
  99. set usr = dom.GetObject ("foreignSecurityPrincipal", "CN=S-1-1-0,CN=ForeignSecurityPrincipals")
  100. if grp.IsMember (usr.AdsPath) then
  101. grp.PutEx 3, "member", array("<SID=010100000000000507000000>")
  102. grp.SetInfo
  103. if err <> 0 then
  104. if err = -2147019886 then ' Anonymous Logon already is a member of this group
  105. wscript.echo "Anonymous Logon is member of Pre-Windows 2000 Compatible Access Group"
  106. else
  107. wscript.echo "Error adding Anonymous Logon to Pre-Windows 2000 Compatible Access group, error code is " & err
  108. end if
  109. else
  110. wscript.echo "Anonymous Logon to Pre-Windows 2000 Compatible Access Group added"
  111. end if
  112. else
  113. wscript.echo "Everyone group is not member of Pre-Windows 2000 Compatible Access Group"
  114. wscript.echo "Anonymous Logon group not added to Pre-Windows 2000 Compatible Access Group"
  115. end if
  116. err = 0
  117. '==============================================================================
  118. ' ACL changes
  119. '===============================================================================
  120. ' OBJECT: Domain DNS
  121. '------------------------------------------------------------------------------
  122. '(OA;;RP;c7407360-20bf-11d0-a768-00aa006e0529;;RU)
  123. ' OA: Access Allowed Object Ace Type
  124. ' RP: DS Read Property (Access Type)
  125. ' c7407360-20bf-11d0-a768-00aa006e0529: Domain Password (Property Set)
  126. ' RU: Pre-Windows 2000 Compatible Access Group
  127. Set ace = CreateObject("AccessControlEntry")
  128. ace.Trustee = "BUILTIN\Pre-Windows 2000 Compatible Access"
  129. ace.AccessMask = ADS_RIGHT_DS_READ_PROP
  130. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  131. ace.AceFlags = 0
  132. ace.ObjectType = "{C7407360-20BF-11D0-A768-00AA006E0529}"
  133. ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
  134. dacl.AddAce ace
  135. Set ace = Nothing
  136. ' (OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;RU)
  137. ' OA: Access Allowed Object Ace Type
  138. ' RP: DS Read Property
  139. ' RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a: Domain-Other-Parameters (Property Set)
  140. ' RU: Pre-Windows 2000 Compatible Access Group
  141. Set ace = CreateObject("AccessControlEntry")
  142. ace.Trustee = "BUILTIN\Pre-Windows 2000 Compatible Access"
  143. ace.AccessMask = ADS_RIGHT_DS_READ_PROP
  144. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  145. ace.ObjectType = "{b8119fd0-04f6-4762-ab7a-4986c76b3f9a}"
  146. ace.AceFlags = 0
  147. ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
  148. dacl.AddAce ace
  149. Set ace = Nothing
  150. ' (OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;AU)
  151. ' OA: Access Allowed Object Ace Type
  152. ' RP: DS Read Property
  153. ' RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a: Domain-Other-Parameters (Property Set)
  154. ' AU: NT AUTHORITY\AUTHENTICATED USERS
  155. Set ace = CreateObject("AccessControlEntry")
  156. ace.Trustee = "NT AUTHORITY\AUTHENTICATED USERS"
  157. ace.AccessMask = ADS_RIGHT_DS_READ_PROP
  158. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  159. ace.ObjectType = "{b8119fd0-04f6-4762-ab7a-4986c76b3f9a}"
  160. ace.AceFlags = 0
  161. ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
  162. dacl.AddAce ace
  163. Set ace = Nothing
  164. ' (OA;CIIO;WP;3e0abfd0-126a-11d0-a060-00aa006c33ed;bf967a86-0de6-11d0-a285-00aa003049e2;CO)
  165. ' OA: Access Allowed Object Ace Type
  166. ' CIIO: Flags Container Inheritance and ADS_ACEFLAG_INHERIT_ONLY_ACE
  167. ' Rights:
  168. ' WP: ADS_RIGHT_DS_WRITE_PROP
  169. ' 3e0abfd0-126a-11d0-a060-00aa006c33ed: sAMAccountName attribute
  170. ' bf967a86-0de6-11d0-a285-00aa003049e2: computer object
  171. ' CO: Creator owner
  172. Set ace = CreateObject("AccessControlEntry")
  173. ace.Trustee = "CREATOR OWNER"
  174. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  175. ace.AccessMask = ADS_RIGHT_DS_WRITE_PROP
  176. ace.AceFlags = ADS_ACEFLAG_INHERIT_ACE or ADS_ACEFLAG_INHERIT_ONLY_ACE
  177. ace.InheritedObjectType = "{BF967A86-0DE6-11D0-A285-00AA003049E2}"
  178. ace.Flags = ADS_FLAG_INHERITED_OBJECT_TYPE_PRESENT or ADS_FLAG_OBJECT_TYPE_PRESENT
  179. ace.ObjectType = "{3E0ABFD0-126A-11D0-A060-00AA006C33ED}"
  180. dacl.AddAce ace
  181. Set ace = Nothing
  182. ' (A;CI;LCRPLORC;;bf967aa5-0de6-11d0-a285-00aa003049e2;ED)
  183. ' A: Access Allowed Ace Type
  184. ' CI: Flag: Container Inheritance
  185. ' Rights:
  186. ' LC: DS List Children
  187. ' RP: DS Read Property
  188. ' LO: DS List Object
  189. ' RC: Read Control
  190. ' bf967aa5-0de6-11d0-a285-00aa003049e2: Class Organizational Unit
  191. ' ED: Enterprise Domain Controllers
  192. Set ace = CreateObject("AccessControlEntry")
  193. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  194. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  195. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  196. ace.AceFlags = ADS_ACEFLAG_INHERIT_ACE
  197. ace.Flags = ADS_FLAG_INHERITED_OBJECT_TYPE_PRESENT
  198. ace.InheritedObjectType = "{BF967AA5-0DE6-11D0-A285-00AA003049E2}"
  199. dacl.AddAce ace
  200. Set ace = Nothing
  201. '-- commit changes
  202. sd.DiscretionaryACL = dacl
  203. dom.Put "ntSecurityDescriptor", Array(sd)
  204. dom.SetInfo
  205. if err <> 0 then
  206. wscript.echo "Error setting Domain Password Property Set ACE set for RU, error code is " & err
  207. wscript.echo "Error setting Domain Other Parameters ACE set for RU, error code is " & err
  208. wscript.echo "Inheritable rights on Organizational Units set on Domain Object for RU, error code is " & err
  209. else
  210. wscript.echo "Domain Password Property Set ACE set for RU"
  211. wscript.echo "Domain Other Parameters ACE set for RU"
  212. wscript.echo "Inheritable rights on Organizational Units set on Domain Object for RU"
  213. end if
  214. err = 0
  215. '(A;;LCRPLORC;;;ED)
  216. ' A: Access Allowed Ace Type
  217. ' Rights:
  218. ' LC: DS List Children
  219. ' RP: DS Read Property
  220. ' LO: DS List Object
  221. ' RC: Read Control
  222. ' ED: Enterprise Domain Controllers
  223. ' Domain Policy first:
  224. Set dp = dom.GetObject("GroupPolicyContainer", "CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System")
  225. Set sd = dp.Get("ntSecurityDescriptor")
  226. Set dacl = sd.DiscretionaryACL
  227. Set ace = CreateObject("AccessControlEntry")
  228. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  229. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  230. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
  231. dacl.AddAce ace
  232. '-- commit changes
  233. sd.DiscretionaryACL = dacl
  234. dp.Put "ntSecurityDescriptor", Array(sd)
  235. dp.SetInfo
  236. if err <> 0 then
  237. wscript.echo "Error setting Domain policy ACE for Enterprise Domain Controllers, error code is " & err
  238. else
  239. wscript.echo "Domain policy ACE for Enterprise Domain Controllers set"
  240. end if
  241. err = 0
  242. Set ace = Nothing
  243. ' Domain Controller Policy next:
  244. Set dcp = dom.GetObject("GroupPolicyContainer", "CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System")
  245. Set sd = dcp.Get("ntSecurityDescriptor")
  246. Set dacl = sd.DiscretionaryACL
  247. Set ace = CreateObject("AccessControlEntry")
  248. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  249. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  250. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
  251. dacl.AddAce ace
  252. '-- commit changes
  253. sd.DiscretionaryACL = dacl
  254. dcp.Put "ntSecurityDescriptor", Array(sd)
  255. dcp.SetInfo
  256. if err <> 0 then
  257. wscript.echo "Error setting Domain Controller policy ACE for Enterprise Domain Controllers, error code is " & err
  258. else
  259. wscript.echo "Domain Controller policy ACE for ED set"
  260. end if
  261. err = 0
  262. Set ace = Nothing
  263. ' For all other group policies, the same ACE needs to be set on the container
  264. ' as container inheritable
  265. ' (A;CI;LCRPLORC;;f30e3bc2-9ff0-11d1-b603-0000f80367c1;ED)
  266. '
  267. ' A: Access Allowed Ace Type
  268. ' CI: Flag: Container Inheritance
  269. ' Rights:
  270. ' LC: DS List Children
  271. ' RP: DS Read Property
  272. ' LO: DS List Object
  273. ' RC: Read Control
  274. ' f30e3bc2-9ff0-11d1-b603-0000f80367c1: class GroupPolicyContainer
  275. ' ED: Enterprise Domain Controllers
  276. Set PCon = dom.GetObject("Container", "CN=Policies,CN=System")
  277. Set sd = PCon.Get("ntSecurityDescriptor")
  278. Set dacl = sd.DiscretionaryACL
  279. Set ace = CreateObject("AccessControlEntry")
  280. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  281. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  282. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  283. ace.AceFlags = ADS_ACEFLAG_INHERIT_ACE or ADS_ACEFLAG_NO_PROPAGATE_INHERIT_ACE or ADS_ACEFLAG_INHERIT_ONLY_ACE
  284. ace.Flags = ADS_FLAG_INHERITED_OBJECT_TYPE_PRESENT
  285. ace.InheritedObjectType = "{f30e3bc2-9ff0-11d1-b603-0000f80367c1}"
  286. dacl.AddAce ace
  287. '-- commit changes
  288. sd.DiscretionaryACL = dacl
  289. PCon.Put "ntSecurityDescriptor", Array(sd)
  290. PCon.SetInfo
  291. if err <> 0 then
  292. wscript.echo "Error setting Policy Container ACE for Enterprise Domain Controllers, error code is " & err
  293. else
  294. wscript.echo "Policy Container ACE for Enterprise Domain Controllers set"
  295. end if
  296. err = 0
  297. Set ace = Nothing
  298. '--------------------------------------------------------------------
  299. ' OBJECT: AdminSDHolder: Allow changing password (self)
  300. '--------------------------------------------------------------------
  301. Set sdHolder = dom.GetObject("container", "CN=AdminSDHolder,CN=System")
  302. Set sd = sdHolder.Get("ntSecurityDescriptor")
  303. Set dacl = sd.DiscretionaryACL
  304. ' (OA;;CR;ab721a53-1e2f-11d0-9819-00aa0040529b;;PS) (RAID 177490)
  305. ' OA: Access Allowed Object Ace Type
  306. ' Rights:
  307. ' CR: All Extended Rights
  308. ' ab721a53-1e2f-11d0-9819-00aa0040529b: User Change Password
  309. ' PS: Personal Self
  310. Set ace = CreateObject("AccessControlEntry")
  311. ace.Trustee = "NT AUTHORITY\SELF"
  312. ace.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
  313. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  314. ace.AceFlags = 0
  315. ace.ObjectType = "{AB721A53-1E2F-11D0-9819-00AA0040529B}"
  316. ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
  317. dacl.AddAce ace
  318. Set ace = Nothing
  319. '---------------------------------------------------------------------------------
  320. ' OBJECT: AdminSDHolder: Allow Certificate Admins to publish certificates to admins
  321. '---------------------------------------------------------------------------------
  322. ' (OA;;RPWP;bf967a7f-0de6-11d0-a285-00aa003049e2;;CA) (RAID 231740)
  323. ' OA: Access Allowed Object Ace Type
  324. ' Rights:
  325. ' RP: DS Read Property
  326. ' RW: DS Write Property
  327. ' Property: bf967a7f-0de6-11d0-a285-00aa003049e2: userCert
  328. ' CA: Certificate Server Administrators
  329. Set ace = CreateObject("AccessControlEntry")
  330. ace.Trustee = "Cert Publishers"
  331. ace.AccessMask = ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_DS_WRITE_PROP
  332. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  333. ace.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
  334. ace.AceFlags = 0
  335. ace.ObjectType = "{BF967A7F-0DE6-11D0-A285-00AA003049E2}"
  336. dacl.AddAce ace
  337. sd.DiscretionaryACL = dacl
  338. sdHolder.Put "ntSecurityDescriptor", Array(sd)
  339. sdHolder.SetInfo
  340. if err <> 0 then
  341. wscript.echo "Error setting AdminSDHolder ACEs, error code is " & err
  342. else
  343. wscript.echo "AdminSDHolder ACEs set"
  344. end if
  345. err = 0
  346. Set ace = Nothing
  347. '--------------------------------------------------------------------
  348. ' OBJECT: GPOUsers
  349. '--------------------------------------------------------------------
  350. Set gpo = dom.GetObject("container", "CN=User,CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System")
  351. Set sd = gpo.Get("ntSecurityDescriptor")
  352. Set dacl = sd.DiscretionaryACL
  353. ' (A;;LCRPLORC;;;ED)
  354. ' A: Access Allowed Ace Type
  355. ' Rights:
  356. ' LC: DS List Children
  357. ' RP: DS Read Property
  358. ' LO: DS List Object
  359. ' RC: Read Control
  360. ' ED: Enterprise Domain Controllers
  361. ' Note: Has to be applied to two User GPOs:
  362. ' CN=User, CN={31B2F340-016D-11D2-945F-00C04FB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  363. ' CN=User, CN= {6AC1786C-016F-11D2-945F-00C04fB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  364. Set ace = CreateObject("AccessControlEntry")
  365. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  366. ace.AceFlags = 0
  367. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  368. dacl.AddAce ace
  369. sd.DiscretionaryACL = dacl
  370. gpo.Put "ntSecurityDescriptor", Array(sd)
  371. gpo.SetInfo
  372. if err <> 0 then
  373. wscript.echo "Error setting ACE for Enterprise Domain Controllers on user domain policy, error code is " & err
  374. else
  375. wscript.echo "ACE for Enterprise Domain Controllers on user domain policy set"
  376. end if
  377. err = 0
  378. Set ace = Nothing
  379. Set gpo = dom.GetObject("container", "CN=User,CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System")
  380. Set sd = gpo.Get("ntSecurityDescriptor")
  381. Set dacl = sd.DiscretionaryACL
  382. ' (A;;LCRPLORC;;;ED)
  383. ' A: Access Allowed Ace Type
  384. ' Rights:
  385. ' LC: DS List Children
  386. ' RP: DS Read Property
  387. ' LO: DS List Object
  388. ' RC: Read Control
  389. ' ED: Enterprise Domain Controllers
  390. ' Note: Has to be applied to two User GPOs:
  391. ' CN=User, CN={31B2F340-016D-11D2-945F-00C04FB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  392. ' CN=User, CN= {6AC1786C-016F-11D2-945F-00C04fB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  393. Set ace = CreateObject("AccessControlEntry")
  394. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  395. ace.AceFlags = 0
  396. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  397. dacl.AddAce ace
  398. sd.DiscretionaryACL = dacl
  399. gpo.Put "ntSecurityDescriptor", Array(sd)
  400. gpo.SetInfo
  401. if err <> 0 then
  402. wscript.echo "Error setting ACE for Enterprise Domain Controllers on user DC policy, error code is " & err
  403. else
  404. wscript.echo "ACE for Enterprise Domain Controllers on user DC policy set"
  405. end if
  406. err = 0
  407. Set ace = Nothing
  408. '--------------------------------------------------------------------
  409. ' OBJECT: GPOMachines
  410. '--------------------------------------------------------------------
  411. Set gpo = dom.GetObject("container", "CN=Machine,CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System")
  412. Set sd = gpo.Get("ntSecurityDescriptor")
  413. Set dacl = sd.DiscretionaryACL
  414. ' (A;;LCRPLORC;;;ED)
  415. ' A: Access Allowed Ace Type
  416. ' Rights:
  417. ' LC: DS List Children
  418. ' RP: DS Read Property
  419. ' LO: DS List Object
  420. ' RC: Read Control
  421. ' ED: Enterprise Domain Controllers
  422. ' Note: Has to be applied to two machines GPOs:
  423. ' CN=Machine, CN={31B2F340-016D-11D2-945F-00C04FB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  424. ' CN=Machine, CN= {6AC1786C-016F-11D2-945F-00C04fB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  425. Set ace = CreateObject("AccessControlEntry")
  426. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  427. ace.AceFlags = 0
  428. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  429. dacl.AddAce ace
  430. sd.DiscretionaryACL = dacl
  431. gpo.Put "ntSecurityDescriptor", Array(sd)
  432. gpo.SetInfo
  433. if err <> 0 then
  434. wscript.echo "Error setting ACE for Enterprise Domain Controllers on machine domain policy, error code is " & err
  435. else
  436. wscript.echo "ACE for Enterprise Domain Controllers on machine domain policy set"
  437. end if
  438. err = 0
  439. Set ace = Nothing
  440. Set gpo = dom.GetObject("container", "CN=Machine,CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System")
  441. Set sd = gpo.Get("ntSecurityDescriptor")
  442. Set dacl = sd.DiscretionaryACL
  443. ' (A;;LCRPLORC;;;ED)
  444. ' A: Access Allowed Ace Type
  445. ' Rights:
  446. ' LC: DS List Children
  447. ' RP: DS Read Property
  448. ' LO: DS List Object
  449. ' RC: Read Control
  450. ' ED: Enterprise Domain Controllers
  451. ' Note: Has to be applied to two machine GPOs:
  452. ' CN=Machine, CN={31B2F340-016D-11D2-945F-00C04FB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  453. ' CN=Machine, CN= {6AC1786C-016F-11D2-945F-00C04fB984F9}, CN=Policies, CN=System, DC=<domain>, ...
  454. Set ace = CreateObject("AccessControlEntry")
  455. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  456. ace.AceFlags = 0
  457. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  458. dacl.AddAce ace
  459. sd.DiscretionaryACL = dacl
  460. gpo.Put "ntSecurityDescriptor", Array(sd)
  461. gpo.SetInfo
  462. if err <> 0 then
  463. wscript.echo "Error setting ACE for Enterprise Domain Controllers on machine DC policy, error code is " & err
  464. else
  465. wscript.echo "ACE for Enterprise Domain Controllers on machine DC policy set"
  466. end if
  467. err = 0
  468. Set ace = Nothing
  469. End function ' Domain function
  470. '==============================================================================
  471. ' Forest function
  472. '==============================================================================
  473. Function Forest ( domain )
  474. On error resume next
  475. if domain = "" then
  476. Set RootDSE = GetObject("LDAP://RootDSE")
  477. else
  478. Set RootDSE = GetObject("LDAP://" & domain & "/RootDSE" )
  479. if err <> 0 then
  480. wscript.echo "Error: Unable to bind to domain " & domain & " , Error is: " & err
  481. wscript.quit
  482. end if
  483. end if
  484. '============================================
  485. ' OBJECT: Site
  486. '=============================================
  487. ' (A;OI;LCRPLORC;;bf967ab3-0de6-11d0-a285-00aa003049e2;ED)
  488. ' A: Access Allowed Ace Type
  489. ' OI: Flag: Object Inheritance
  490. ' Rights:
  491. ' LC: DS List Children
  492. ' RP: DS Read Property
  493. ' LO: DS List Object
  494. ' RC: Read Control
  495. ' bf967ab3-0de6-11d0-a285-00aa003049e2: Schema GUID for sites
  496. ' ED: Enterprise Domain Controllers
  497. Set cfg = GetObject("LDAP://" & RootDSE.Get("configurationNamingContext"))
  498. if err <> 0 then
  499. wscript.echo "Error binding to configuration naming context, error is " & err
  500. wscript.quit
  501. end if
  502. Set site = cfg.GetObject("sitesContainer", "CN=Sites")
  503. if err <> 0 then
  504. wscript.echo "Error binding to sites container, error is " & err
  505. wscript.quit
  506. end if
  507. Set sd = site.Get("ntSecurityDescriptor")
  508. if err <> 0 then
  509. wscript.echo "Error getting security descriptor on sites container, error is " & err
  510. wscript.quit
  511. end if
  512. Set dacl = sd.DiscretionaryACL
  513. Set ace = CreateObject("AccessControlEntry")
  514. ace.Trustee = "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS"
  515. ace.AccessMask = ADS_RIGHT_READ_CONTROL or ADS_RIGHT_DS_READ_PROP or ADS_RIGHT_ACTRL_DS_LIST or ADS_RIGHT_DS_LIST_OBJECT
  516. ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
  517. ace.AceFlags = ADS_ACEFLAG_INHERIT_ACE or ADS_ACEFLAG_NO_PROPAGATE_INHERIT_ACE or ADS_ACEFLAG_INHERIT_ONLY_ACE
  518. ace.Flags = ADS_FLAG_INHERITED_OBJECT_TYPE_PRESENT
  519. ace.InheritedObjectType = "{bf967ab3-0de6-11d0-a285-00aa003049e2}"
  520. dacl.AddAce ace
  521. sd.DiscretionaryACL = dacl
  522. site.Put "ntSecurityDescriptor", Array(sd)
  523. site.SetInfo
  524. if err <> 0 then
  525. wscript.echo "Error setting inherited ACE for Enterprise Domain Controllers on Sites container, error code is " & err
  526. else
  527. wscript.echo "Inherited ACE for Enterprise Domain Controllers on Sites container set"
  528. end if
  529. Set ace = Nothing
  530. err = 0
  531. End function