require 'puppet' |
require 'puppet/util/windows' |
|
class Tester |
include Puppet::Util::Windows::Security |
|
def replace_file(path, mode) |
if Puppet::FileSystem.exist?(path) |
Puppet::FileSystem.unlink(path) |
end |
|
Puppet::FileSystem.touch(path) |
|
dacl = Puppet::Util::Windows::AccessControlList.new |
dacl.allow(Puppet::Util::Windows::SID::LocalSystem, |
Puppet::Util::Windows::File::FILE_ALL_ACCESS) |
dacl.allow(Puppet::Util::Windows::SID::BuiltinAdministrators, |
Puppet::Util::Windows::File::FILE_ALL_ACCESS) |
|
sd = Puppet::Util::Windows::SecurityDescriptor.new( |
Puppet::Util::Windows::SID::LocalSystem, |
Puppet::Util::Windows::SID::LocalSystem, |
dacl, |
true |
) |
|
set_security_descriptor(path, sd) |
dump_sd(path) |
|
set_mode(mode, path) |
dump_sd(path) |
end |
|
def dump_sd(path) |
sd = get_security_descriptor(path) |
puts "Owner: #{sd.owner}" |
puts "Group: #{sd.group}" |
puts "DACL:" |
puts sd.dacl.inspect |
end |
end |
|
tester = Tester.new |
tester.replace_file('c:\Users\josh\newfile.txt', 0640)
|