|
Lines 1-70
Link Here
|
| 1 |
configFolder = Wscript.Arguments.Item(0) |
|
|
| 2 |
|
| 3 |
'WScript.Echo "Fixing permissions on " & configFolder |
| 4 |
|
| 5 |
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 'Load up WMI with the right dll |
| 6 |
|
| 7 |
Dim files(0) |
| 8 |
files(0) = "org.eclipse.virgo.kernel.jmxremote.access.properties" |
| 9 |
|
| 10 |
For Each file In files |
| 11 |
updateInheritance(configFolder & file) |
| 12 |
updateOwnership(configFolder & file) |
| 13 |
updatePermissions(configFolder & file) |
| 14 |
Next |
| 15 |
|
| 16 |
Sub updateInheritance(file) |
| 17 |
'WScript.Echo "Updating inheritance of " & file |
| 18 |
|
| 19 |
Const SE_DACL_PRESENT = 4 |
| 20 |
Const SE_DACL_PROTECTED = 4096 |
| 21 |
Const SE_SELF_RELATIVE = 32768 |
| 22 |
|
| 23 |
Set objFileSecSetting = objWMIService.Get("Win32_LogicalFileSecuritySetting.Path='" & file & "'") |
| 24 |
objFileSecSetting.GetSecurityDescriptor objSecurityDescriptor |
| 25 |
|
| 26 |
objSecurityDescriptor.ControlFlags = SE_DACL_PRESENT + SE_DACL_PROTECTED + SE_SELF_RELATIVE |
| 27 |
|
| 28 |
Set objMethod = objFileSecSetting.Methods_("SetSecurityDescriptor") |
| 29 |
Set objInParam = objMethod.inParameters.SpawnInstance_() |
| 30 |
objInParam.Properties_.item("Descriptor") = objSecurityDescriptor |
| 31 |
objFileSecSetting.ExecMethod_ "SetSecurityDescriptor", objInParam |
| 32 |
|
| 33 |
'WScript.Echo "Updated inheritance of " & file |
| 34 |
End Sub |
| 35 |
|
| 36 |
Sub updateOwnership(file) |
| 37 |
'WScript.Echo "Updating ownership of " & file |
| 38 |
Set objDataFile = objWMIService.Get("CIM_DataFile.Name='" & file & "'") |
| 39 |
|
| 40 |
Set objMethod = objDataFile.Methods_("TakeOwnerShipEx") |
| 41 |
Set objInParam = objMethod.inParameters.SpawnInstance_() |
| 42 |
|
| 43 |
objDataFile.ExecMethod_ "TakeOwnerShipEx", objInParam |
| 44 |
|
| 45 |
'WScript.Echo "Updated ownership of " & file |
| 46 |
End Sub |
| 47 |
|
| 48 |
Sub updatePermissions(file) |
| 49 |
'WScript.Echo "Updating permissions of " & file |
| 50 |
|
| 51 |
Set objFileSecSetting = objWMIService.Get("Win32_LogicalFileSecuritySetting.Path='" & file & "'") |
| 52 |
objFileSecSetting.GetSecurityDescriptor objSecurityDescriptor |
| 53 |
|
| 54 |
Set WshNetwork = WScript.CreateObject("WScript.Network") |
| 55 |
Dim specificAce(0) |
| 56 |
For Each ace in objSecurityDescriptor.DACL |
| 57 |
If ace.Trustee.Name = WshNetwork.UserName Then |
| 58 |
Set specificAce(0) = ace |
| 59 |
End If |
| 60 |
Next |
| 61 |
|
| 62 |
objSecurityDescriptor.DACL = specificAce |
| 63 |
|
| 64 |
Set objMethod = objFileSecSetting.Methods_("SetSecurityDescriptor") |
| 65 |
Set objInParam = objMethod.inParameters.SpawnInstance_() |
| 66 |
objInParam.Properties_.item("Descriptor") = objSecurityDescriptor |
| 67 |
objFileSecSetting.ExecMethod_ "SetSecurityDescriptor", objInParam |
| 68 |
|
| 69 |
'WScript.Echo "Updated permissions of " & file |
| 70 |
End Sub |
| 71 |
- |