~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to lib/puppet/type/resources.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        metaparams specified here will be passed on to any generated resources,
9
9
        so you can purge umanaged resources but set ``noop`` to true so the
10
10
        purging is only logged and does not actually happen."
11
 
    
12
 
    
 
11
 
 
12
 
13
13
    newparam(:name) do
14
14
        desc "The name of the type to be managed."
15
 
        
 
15
 
16
16
        validate do |name|
17
17
            unless Puppet::Type.type(name)
18
18
                raise ArgumentError, "Could not find resource type '%s'" % name
19
19
            end
20
20
        end
21
 
        
 
21
 
22
22
        munge { |v| v.to_s }
23
23
    end
24
 
    
 
24
 
25
25
    newparam(:purge, :boolean => true) do
26
26
        desc "Purge unmanaged resources.  This will delete any resource
27
27
            that is not specified in your configuration
28
28
            and is not required by any specified resources."
29
 
            
 
29
 
30
30
        newvalues(:true, :false)
31
 
        
 
31
 
32
32
        validate do |value|
33
33
            if [:true, true, "true"].include?(value)
34
34
                unless @resource.resource_type.respond_to?(:instances)
40
40
            end
41
41
        end
42
42
    end
43
 
    
 
43
 
44
44
    newparam(:unless_system_user) do
45
45
        desc "This keeps system users from being purged.  By default, it
46
46
            does not purge users whose UIDs are less than or equal to 500, but you can specify
47
47
            a different UID as the inclusive limit."
48
 
        
 
48
 
49
49
        newvalues(:true, :false, /^\d+$/)
50
 
        
 
50
 
51
51
        munge do |value|
52
52
            case value
53
53
            when /^\d+/
56
56
                500
57
57
            when :false, false
58
58
                false
59
 
            when Integer: value
 
59
            when Integer; value
60
60
            else
61
61
                raise ArgumentError, "Invalid value %s" % value.inspect
62
62
            end
63
63
        end
64
 
        
 
64
 
65
65
        defaultto {
66
66
            if @resource[:name] == "user"
67
67
                500
70
70
            end
71
71
        }
72
72
    end
73
 
    
 
73
 
74
74
    def check(resource)
75
75
        unless defined? @checkmethod
76
76
            @checkmethod = "%s_check" % self[:name]
84
84
            return true
85
85
        end
86
86
    end
87
 
    
 
87
 
 
88
    def able_to_ensure_absent?(resource)
 
89
        begin
 
90
            resource[:ensure] = :absent
 
91
        rescue ArgumentError, Puppet::Error => detail
 
92
            err "The 'ensure' attribute on #{self[:name]} resources does not accept 'absent' as a value"
 
93
            false
 
94
        end
 
95
    end
 
96
 
88
97
    # Generate any new resources we need to manage.  This is pretty hackish
89
98
    # right now, because it only supports purging.
90
99
    def generate
91
100
        return [] unless self.purge?
92
 
        hascheck = false
93
 
        method = 
94
 
        resource_type.instances.find_all do |resource|
95
 
            ! resource.managed?
96
 
        end.find_all do |resource|
97
 
            check(resource)
98
 
        end.each do |resource|
99
 
            begin
100
 
                resource[:ensure] = :absent
101
 
            rescue ArgumentError, Puppet::Error => detail
102
 
                err "The 'ensure' attribute on %s resources does not accept 'absent' as a value" %
103
 
                    [self[:name]]
104
 
                return []
105
 
            end
 
101
        resource_type.instances.
 
102
          reject { |r| managed? }.
 
103
          reject { |r| catalog.resources.include? r.ref }.
 
104
          select { |r| check(r) }.
 
105
          select { |r| able_to_ensure_absent?(r) }.
 
106
          each { |resource|
106
107
            @parameters.each do |name, param|
107
 
                next unless param.metaparam?
108
 
                resource[name] = param.value
 
108
                resource[name] = param.value if param.metaparam?
109
109
            end
110
110
 
111
111
            # Mark that we're purging, so transactions can handle relationships
112
112
            # correctly
113
113
            resource.purging
114
 
        end
 
114
          }
115
115
    end
116
 
    
 
116
 
117
117
    def resource_type
118
118
        unless defined? @resource_type
119
119
            unless type = Puppet::Type.type(self[:name])
123
123
        end
124
124
        @resource_type
125
125
    end
126
 
    
 
126
 
127
127
    # Make sure we don't purge users below a certain uid, if the check
128
128
    # is enabled.
129
129
    def user_check(resource)
130
130
        return true unless self[:name] == "user"
131
131
        return true unless self[:unless_system_user]
132
 
        
 
132
 
133
133
        resource[:check] = :uid
134
134
        current_values = resource.retrieve
135
 
        
 
135
 
136
136
        if system_users().include?(resource[:name])
137
137
            return false
138
138
        end