1
# Plug-in type for handling k5login files
3
Puppet::Type.newtype(:k5login) do
4
@doc = "Manage the `.k5login` file for a user. Specify the full path to
5
the `.k5login` file as the name and an array of principals as the
10
# Principals that should exist in the file
11
newproperty(:principals, :array_matching => :all) do
12
desc "The principals present in the `.k5login` file."
15
# The path/name of the k5login file
18
desc "The path to the file to manage. Must be fully qualified."
21
unless value =~ /^#{File::SEPARATOR}/
22
raise Puppet::Error, "File paths must be fully qualified"
27
# To manage the mode of the file
29
desc "Manage the k5login file's mode"
34
desc "The k5login provider is the only provider for the k5login
37
# Does this file exist?
39
File.exists?(@resource[:name])
44
write(@resource.should(:principals))
45
should_mode = @resource.should(:mode)
46
unless self.mode == should_mode
47
self.mode = should_mode
53
File.unlink(@resource[:name])
56
# Return the principals
57
def principals(dummy_argument=:work_arround_for_ruby_GC_bug)
58
if File.exists?(@resource[:name])
59
File.readlines(@resource[:name]).collect { |line| line.chomp }
65
# Write the principals out to the k5login file
66
def principals=(value)
70
# Return the mode as an octal string, not as an integer
72
"%o" % (File.stat(@resource[:name]).mode & 007777)
75
# Set the file mode, converting from a string to an integer.
77
File.chmod(Integer("0#{value}"), @resource[:name])
82
File.open(@resource[:name], "w") { |f| f.puts value.join("\n") }