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

« back to all changes in this revision

Viewing changes to lib/puppet/util.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:
1
1
# A module to collect utility functions.
2
2
 
 
3
require 'puppet/util/monkey_patches'
3
4
require 'sync'
4
5
require 'puppet/external/lock'
5
6
 
9
10
    end
10
11
module Util
11
12
    require 'benchmark'
12
 
    
 
13
 
13
14
    # These are all for backward compatibility -- these are methods that used
14
15
    # to be in Puppet::Util but have been moved into external modules.
15
16
    require 'puppet/util/posix'
26
27
 
27
28
    # Change the process to a different user
28
29
    def self.chuser
29
 
        if Facter["operatingsystem"].value == "Darwin"
30
 
            $stderr.puts "Ruby on darwin is broken; puppetmaster will not set its UID to 'puppet' and must run as root"
31
 
            return
32
 
        end
33
30
        if group = Puppet[:group]
34
31
            group = self.gid(group)
35
32
            unless group
37
34
            end
38
35
            unless Puppet::Util::SUIDManager.gid == group
39
36
                begin
40
 
                    Puppet::Util::SUIDManager.egid = group 
41
 
                    Puppet::Util::SUIDManager.gid = group 
 
37
                    Puppet::Util::SUIDManager.egid = group
 
38
                    Puppet::Util::SUIDManager.gid = group
42
39
                rescue => detail
43
40
                    Puppet.warning "could not change to group %s: %s" %
44
41
                        [group.inspect, detail]
58
55
            end
59
56
            unless Puppet::Util::SUIDManager.uid == user
60
57
                begin
61
 
                    Puppet::Util::SUIDManager.uid = user 
62
 
                    Puppet::Util::SUIDManager.euid = user 
63
 
                rescue
64
 
                    $stderr.puts "could not change to user %s" % user
 
58
                    Puppet::Util::SUIDManager.initgroups(user)
 
59
                    Puppet::Util::SUIDManager.uid = user
 
60
                    Puppet::Util::SUIDManager.euid = user
 
61
                rescue => detail
 
62
                    $stderr.puts "Could not change to user %s: %s" % [user, detail]
65
63
                    exit(74)
66
64
                end
67
65
            end
188
186
 
189
187
    def binary(bin)
190
188
        if bin =~ /^\//
191
 
            if FileTest.file? bin and FileTest.executable? bin
192
 
                return bin
193
 
            else
194
 
                return nil
195
 
            end
 
189
            return bin if FileTest.file? bin and FileTest.executable? bin
196
190
        else
197
 
            x = %x{which #{bin} 2>/dev/null}.chomp
198
 
            if x == ""
199
 
                return nil
200
 
            else
201
 
                return x
202
 
            end
 
191
           ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
 
192
               dest=File.join(dir, bin)
 
193
               return dest if FileTest.file? dest and FileTest.executable? dest
 
194
           end
203
195
        end
 
196
        return nil
204
197
    end
205
198
    module_function :binary
206
199
 
255
248
        else
256
249
            Puppet.debug "Executing '%s'" % str
257
250
        end
258
 
        
 
251
 
259
252
        if arguments[:uid]
260
253
            arguments[:uid] = Puppet::Util::SUIDManager.convert_xid(:uid, arguments[:uid])
261
254
        end
262
255
        if arguments[:gid]
263
256
            arguments[:gid] = Puppet::Util::SUIDManager.convert_xid(:gid, arguments[:gid])
264
257
        end
265
 
        
 
258
 
266
259
        @@os ||= Facter.value(:operatingsystem)
267
260
        output = nil
268
261
        child_pid, child_status = nil
282
275
        end
283
276
 
284
277
        oldverb = $VERBOSE
285
 
        $VERBOSE = false
 
278
        $VERBOSE = nil
286
279
        child_pid = Kernel.fork
287
280
        $VERBOSE = oldverb
288
281
        if child_pid
300
293
                $stdout.reopen(output_file)
301
294
                $stderr.reopen(error_file)
302
295
 
303
 
                3.upto(256){|fd| IO::new(fd).close rescue nil} 
 
296
                3.upto(256){|fd| IO::new(fd).close rescue nil}
304
297
                if arguments[:gid]
305
298
                    Process.egid = arguments[:gid]
306
299
                    Process.gid = arguments[:gid] unless @@os == "Darwin"
320
313
                exit!(1)
321
314
            end # begin; rescue
322
315
        end # if child_pid
323
 
        
 
316
 
324
317
        # read output in if required
325
318
        if ! arguments[:squelch]
326
319