~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to .pc/CVE-2011-3869.patch/lib/puppet/type/k5login.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Plug-in type for handling k5login files
2
 
 
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
6
 
    property principals."
7
 
 
8
 
  ensurable
9
 
 
10
 
  # Principals that should exist in the file
11
 
  newproperty(:principals, :array_matching => :all) do
12
 
    desc "The principals present in the `.k5login` file."
13
 
  end
14
 
 
15
 
  # The path/name of the k5login file
16
 
  newparam(:path) do
17
 
    isnamevar
18
 
    desc "The path to the file to manage.  Must be fully qualified."
19
 
 
20
 
    validate do |value|
21
 
      unless value =~ /^#{File::SEPARATOR}/
22
 
        raise Puppet::Error, "File paths must be fully qualified"
23
 
      end
24
 
    end
25
 
  end
26
 
 
27
 
  # To manage the mode of the file
28
 
  newproperty(:mode) do
29
 
    desc "Manage the k5login file's mode"
30
 
    defaultto { "644" }
31
 
  end
32
 
 
33
 
  provide(:k5login) do
34
 
    desc "The k5login provider is the only provider for the k5login
35
 
      type."
36
 
 
37
 
    # Does this file exist?
38
 
    def exists?
39
 
      File.exists?(@resource[:name])
40
 
    end
41
 
 
42
 
    # create the file
43
 
    def create
44
 
      write(@resource.should(:principals))
45
 
      should_mode = @resource.should(:mode)
46
 
      unless self.mode == should_mode
47
 
        self.mode = should_mode
48
 
      end
49
 
    end
50
 
 
51
 
    # remove the file
52
 
    def destroy
53
 
      File.unlink(@resource[:name])
54
 
    end
55
 
 
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 }
60
 
      else
61
 
        :absent
62
 
      end
63
 
    end
64
 
 
65
 
    # Write the principals out to the k5login file
66
 
    def principals=(value)
67
 
      write(value)
68
 
    end
69
 
 
70
 
    # Return the mode as an octal string, not as an integer
71
 
    def mode
72
 
      "%o" % (File.stat(@resource[:name]).mode & 007777)
73
 
    end
74
 
 
75
 
    # Set the file mode, converting from a string to an integer.
76
 
    def mode=(value)
77
 
      File.chmod(Integer("0#{value}"), @resource[:name])
78
 
    end
79
 
 
80
 
    private
81
 
    def write(value)
82
 
      File.open(@resource[:name], "w") { |f| f.puts value.join("\n") }
83
 
    end
84
 
  end
85
 
end