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

« back to all changes in this revision

Viewing changes to lib/puppet/indirector/file_server.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:
2
2
#  Created by Luke Kanies on 2007-10-19.
3
3
#  Copyright (c) 2007. All rights reserved.
4
4
 
5
 
require 'puppet/util/uri_helper'
6
5
require 'puppet/file_serving/configuration'
7
6
require 'puppet/file_serving/fileset'
8
7
require 'puppet/file_serving/terminus_helper'
10
9
 
11
10
# Look files up using the file server.
12
11
class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
13
 
    include Puppet::Util::URIHelper
14
12
    include Puppet::FileServing::TerminusHelper
15
13
 
16
14
    # Is the client authorized to perform this action?
17
15
    def authorized?(request)
18
16
        return false unless [:find, :search].include?(request.method)
19
17
 
20
 
        uri = key2uri(request.key)
 
18
        mount, file_path = configuration.split_path(request)
21
19
 
22
 
        configuration.authorized?(uri.path, :node => request.node, :ipaddress => request.ip)
 
20
        # If we're not serving this mount, then access is denied.
 
21
        return false unless mount
 
22
        return mount.allowed?(request.node, request.ip)
23
23
    end
24
24
 
25
25
    # Find our key using the fileserver.
26
26
    def find(request)
27
 
        return nil unless path = find_path(request)
28
 
        result =  model.new(request.key, :path => path)
 
27
        mount, relative_path = configuration.split_path(request)
 
28
 
 
29
        return nil unless mount
 
30
 
 
31
        # The mount checks to see if the file exists, and returns nil
 
32
        # if not.
 
33
        return nil unless path = mount.find(relative_path, request)
 
34
        result = model.new(path)
29
35
        result.links = request.options[:links] if request.options[:links]
30
 
        return result
 
36
        result.collect
 
37
        result
31
38
    end
32
39
 
33
40
    # Search for files.  This returns an array rather than a single
34
41
    # file.
35
42
    def search(request)
36
 
        return nil unless path = find_path(request)
37
 
 
38
 
        path2instances(request, path)
 
43
        mount, relative_path = configuration.split_path(request)
 
44
 
 
45
        unless mount and paths = mount.search(relative_path, request)
 
46
            Puppet.info "Could not find filesystem info for file '%s' in environment %s" % [request.key, request.environment]
 
47
            return nil
 
48
        end
 
49
 
 
50
        filesets = paths.collect do |path|
 
51
            # Filesets support indirector requests as an options collection
 
52
            Puppet::FileServing::Fileset.new(path, request)
 
53
        end
 
54
 
 
55
        Puppet::FileServing::Fileset.merge(*filesets).collect do |file, base_path|
 
56
            inst = model.new(base_path, :relative_path => file)
 
57
            inst.links = request.options[:links] if request.options[:links]
 
58
            inst.collect
 
59
            inst
 
60
        end
39
61
    end
40
62
 
41
63
    private
44
66
    def configuration
45
67
        Puppet::FileServing::Configuration.create
46
68
    end
47
 
 
48
 
    # Find our path; used by :find and :search.
49
 
    def find_path(request)
50
 
        uri = key2uri(request.key)
51
 
 
52
 
        return nil unless path = configuration.file_path(uri.path, :node => request.node)
53
 
 
54
 
        return path
55
 
    end
56
69
end