Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c50031b1cfd8e269027ba5b478c8406d39043560 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
configFolder = Wscript.Arguments.Item(0)

'WScript.Echo "Fixing permissions on " & configFolder

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 'Load up WMI with the right dll

Dim files(0)
files(0) = "org.eclipse.virgo.kernel.jmxremote.access.properties"

For Each file In files
	updateInheritance(configFolder & file)
	updateOwnership(configFolder & file)
	updatePermissions(configFolder & file)
Next 

Sub updateInheritance(file)
	'WScript.Echo "Updating inheritance of " & file
	
	Const SE_DACL_PRESENT = 4
	Const SE_DACL_PROTECTED = 4096
	Const SE_SELF_RELATIVE = 32768

	Set objFileSecSetting = objWMIService.Get("Win32_LogicalFileSecuritySetting.Path='" & file & "'")
    objFileSecSetting.GetSecurityDescriptor objSecurityDescriptor

	objSecurityDescriptor.ControlFlags = SE_DACL_PRESENT + SE_DACL_PROTECTED + SE_SELF_RELATIVE

	Set objMethod = objFileSecSetting.Methods_("SetSecurityDescriptor")
	Set objInParam = objMethod.inParameters.SpawnInstance_()
	objInParam.Properties_.item("Descriptor") = objSecurityDescriptor
	objFileSecSetting.ExecMethod_ "SetSecurityDescriptor", objInParam
	
	'WScript.Echo "Updated inheritance of " & file
End Sub

Sub updateOwnership(file)
	'WScript.Echo "Updating ownership of " & file
	Set objDataFile = objWMIService.Get("CIM_DataFile.Name='" & file & "'")

	Set objMethod = objDataFile.Methods_("TakeOwnerShipEx")
	Set objInParam = objMethod.inParameters.SpawnInstance_()

	objDataFile.ExecMethod_ "TakeOwnerShipEx", objInParam

	'WScript.Echo "Updated ownership of " & file
End Sub

Sub updatePermissions(file)	
	'WScript.Echo "Updating permissions of " & file
	
	Set objFileSecSetting = objWMIService.Get("Win32_LogicalFileSecuritySetting.Path='" & file & "'")
    objFileSecSetting.GetSecurityDescriptor objSecurityDescriptor

	Set WshNetwork = WScript.CreateObject("WScript.Network")
	Dim specificAce(0)
	For Each ace in objSecurityDescriptor.DACL
		If ace.Trustee.Name = WshNetwork.UserName Then
			Set specificAce(0) = ace
		End If
	Next
	
	objSecurityDescriptor.DACL = specificAce

	Set objMethod = objFileSecSetting.Methods_("SetSecurityDescriptor")
	Set objInParam = objMethod.inParameters.SpawnInstance_()
	objInParam.Properties_.item("Descriptor") = objSecurityDescriptor
	objFileSecSetting.ExecMethod_ "SetSecurityDescriptor", objInParam
	
	'WScript.Echo "Updated permissions of " & file
End Sub

Back to the top