~ubuntu-branches/ubuntu/quantal/puppet/quantal-security

« back to all changes in this revision

Viewing changes to .pc/CVE-2011-3872.patch/lib/puppet/network/client.rb

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-10-24 15:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20111024150512-yxqwfdp6hcs6of5l
Tags: 2.7.1-1ubuntu3.2
* SECURITY UPDATE: puppet master impersonation via incorrect certificates
  - debian/patches/CVE-2011-3872.patch: refactor certificate handling.
  - Thanks to upstream for providing the patch.
  - CVE-2011-3872

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# the available clients
 
2
 
 
3
require 'puppet'
 
4
require 'puppet/network/xmlrpc/client'
 
5
require 'puppet/util/subclass_loader'
 
6
require 'puppet/util/methodhelper'
 
7
require 'puppet/sslcertificates/support'
 
8
 
 
9
require 'puppet/network/handler'
 
10
 
 
11
require 'net/http'
 
12
 
 
13
# Some versions of ruby don't have this method defined, which basically causes
 
14
# us to never use ssl.  Yay.
 
15
class Net::HTTP
 
16
  def use_ssl?
 
17
    if defined?(@use_ssl)
 
18
      @use_ssl
 
19
    else
 
20
      false
 
21
    end
 
22
  end
 
23
 
 
24
  # JJM: This is a "backport" of sorts to older ruby versions which
 
25
  # do not have this accessor.  See #896 for more information.
 
26
  attr_accessor :enable_post_connection_check unless Net::HTTP.method_defined? "enable_post_connection_check"
 
27
end
 
28
 
 
29
# The base class for all of the clients.  Many clients just directly
 
30
# call methods, but some of them need to do some extra work or
 
31
# provide a different interface.
 
32
class Puppet::Network::Client
 
33
  Client = self
 
34
  include Puppet::Util
 
35
  extend Puppet::Util::SubclassLoader
 
36
  include Puppet::Util::MethodHelper
 
37
 
 
38
  # This handles reading in the key and such-like.
 
39
  include Puppet::SSLCertificates::Support
 
40
 
 
41
  attr_accessor :schedule, :lastrun, :local, :stopping
 
42
 
 
43
  attr_reader :driver
 
44
 
 
45
  # Set up subclass loading
 
46
  handle_subclasses :client, "puppet/network/client"
 
47
 
 
48
  # Determine what clients look for when being passed an object for local
 
49
  # client/server stuff.  E.g., you could call Client::CA.new(:CA => ca).
 
50
  def self.drivername
 
51
    @drivername ||= self.name
 
52
  end
 
53
 
 
54
  # Figure out the handler for our client.
 
55
  def self.handler
 
56
    @handler ||= Puppet::Network::Handler.handler(self.name)
 
57
  end
 
58
 
 
59
  # The class that handles xmlrpc interaction for us.
 
60
  def self.xmlrpc_client
 
61
    @xmlrpc_client ||= Puppet::Network::XMLRPCClient.handler_class(self.handler)
 
62
  end
 
63
 
 
64
  # Create our client.
 
65
  def initialize(hash)
 
66
    # to whom do we connect?
 
67
    @server = nil
 
68
 
 
69
    if hash.include?(:Cache)
 
70
      @cache = hash[:Cache]
 
71
    else
 
72
      @cache = true
 
73
    end
 
74
 
 
75
    driverparam = self.class.drivername
 
76
    if hash.include?(:Server)
 
77
      args = {:Server => hash[:Server]}
 
78
      @server = hash[:Server]
 
79
      args[:Port] = hash[:Port] || Puppet[:masterport]
 
80
 
 
81
      @driver = self.class.xmlrpc_client.new(args)
 
82
 
 
83
      self.read_cert
 
84
 
 
85
      # We have to start the HTTP connection manually before we start
 
86
      # sending it requests or keep-alive won't work.  Note that with #1010,
 
87
      # we don't currently actually want keep-alive.
 
88
      @driver.start if @driver.respond_to? :start and Puppet::Network::HttpPool.keep_alive?
 
89
 
 
90
      @local = false
 
91
    elsif hash.include?(driverparam)
 
92
      @driver = hash[driverparam]
 
93
      if @driver == true
 
94
        @driver = self.class.handler.new
 
95
      end
 
96
      @local = true
 
97
    else
 
98
      raise Puppet::Network::ClientError, "#{self.class} must be passed a Server or #{driverparam}"
 
99
    end
 
100
  end
 
101
 
 
102
  # Are we a local client?
 
103
  def local?
 
104
    if @local
 
105
      true
 
106
    else
 
107
      false
 
108
    end
 
109
  end
 
110
 
 
111
  # Make sure we set the driver up when we read the cert in.
 
112
  def recycle_connection
 
113
    @driver.recycle_connection if @driver.respond_to?(:recycle_connection)
 
114
  end
 
115
 
 
116
  # A wrapper method to run and then store the last run time
 
117
  def runnow
 
118
    if self.stopping
 
119
      Puppet.notice "In shutdown progress; skipping run"
 
120
      return
 
121
    end
 
122
    begin
 
123
      self.run
 
124
      self.lastrun = Time.now.to_i
 
125
    rescue => detail
 
126
      puts detail.backtrace if Puppet[:trace]
 
127
      Puppet.err "Could not run #{self.class}: #{detail}"
 
128
    end
 
129
  end
 
130
 
 
131
  def run
 
132
    raise Puppet::DevError, "Client type #{self.class} did not override run"
 
133
  end
 
134
 
 
135
  def scheduled?
 
136
    if sched = self.schedule
 
137
      return sched.match?(self.lastrun)
 
138
    else
 
139
      return true
 
140
    end
 
141
  end
 
142
 
 
143
  def shutdown
 
144
    if self.stopping
 
145
      Puppet.notice "Already in shutdown"
 
146
    else
 
147
      self.stopping = true
 
148
      Puppet::Util::Storage.store if self.respond_to? :running? and self.running?
 
149
      rmpidfile
 
150
    end
 
151
  end
 
152
 
 
153
  # Start listening for events.  We're pretty much just listening for
 
154
  # timer events here.
 
155
  def start
 
156
    # Create our timer.  Puppet will handle observing it and such.
 
157
 
 
158
          timer = Puppet.newtimer(
 
159
                
 
160
      :interval => Puppet[:runinterval],
 
161
      :tolerance => 1,
 
162
        
 
163
      :start? => true
 
164
    ) do
 
165
      begin
 
166
        self.runnow if self.scheduled?
 
167
      rescue => detail
 
168
        puts detail.backtrace if Puppet[:trace]
 
169
        Puppet.err "Could not run client; got otherwise uncaught exception: #{detail}"
 
170
      end
 
171
    end
 
172
 
 
173
    # Run once before we start following the timer
 
174
    self.runnow
 
175
  end
 
176
 
 
177
  require 'puppet/network/client/proxy'
 
178
end
 
179