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

« back to all changes in this revision

Viewing changes to lib/puppet/network/http/rack/xmlrpc.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
require 'puppet/network/http/rack/httphandler'
 
2
require 'puppet/network/xmlrpc/server'
 
3
require 'resolv'
 
4
 
 
5
class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler
 
6
    def initialize(handlers)
 
7
        @xmlrpc_server = Puppet::Network::XMLRPCServer.new
 
8
        handlers.each do |name|
 
9
            Puppet.debug "  -> register xmlrpc namespace %s" % name
 
10
            unless handler = Puppet::Network::Handler.handler(name)
 
11
                raise ArgumentError, "Invalid XMLRPC handler %s" % name
 
12
            end
 
13
            @xmlrpc_server.add_handler(handler.interface, handler.new({}))
 
14
        end
 
15
        super()
 
16
    end
 
17
 
 
18
    def process(request, response)
 
19
        # errors are sent as text/plain
 
20
        response['Content-Type'] = 'text/plain'
 
21
        if not request.post? then
 
22
            response.status = 405
 
23
            response.write 'Method Not Allowed'
 
24
            return
 
25
        end
 
26
        if request.media_type() != "text/xml" then
 
27
            response.status = 400
 
28
            response.write 'Bad Request'
 
29
            return
 
30
        end
 
31
 
 
32
        # get auth/certificate data
 
33
        client_request = build_client_request(request)
 
34
 
 
35
        response_body = @xmlrpc_server.process(request.body.read(), client_request)
 
36
 
 
37
        response.status = 200
 
38
        response['Content-Type'] =  'text/xml; charset=utf-8'
 
39
        response.write response_body
 
40
    end
 
41
 
 
42
    def build_client_request(request)
 
43
        ip = request.ip
 
44
 
 
45
        # if we find SSL info in the headers, use them to get a hostname.
 
46
        # try this with :ssl_client_header.
 
47
        # For Apache you need special configuration, see ext/rack/README.
 
48
        if dn = ssl_client_header(request) and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/)
 
49
            node = dn_matchdata[1].to_str
 
50
            authenticated = (ssl_client_verify_header(request) == 'SUCCESS')
 
51
        else
 
52
            begin
 
53
                node = Resolv.getname(ip)
 
54
            rescue => detail
 
55
                Puppet.err "Could not resolve %s: %s" % [ip, detail]
 
56
                node = "unknown"
 
57
            end
 
58
            authenticated = false
 
59
        end
 
60
 
 
61
        Puppet::Network::ClientRequest.new(node, ip, authenticated)
 
62
    end
 
63
 
 
64
end
 
65