~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to .pc/CVE-2011-3870.patch/lib/puppet/provider/ssh_authorized_key/parsed.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'puppet/provider/parsedfile'
2
 
 
3
 
 
4
 
      Puppet::Type.type(:ssh_authorized_key).provide(
5
 
        :parsed,
6
 
  :parent => Puppet::Provider::ParsedFile,
7
 
  :filetype => :flat,
8
 
        
9
 
  :default_target => ''
10
 
) do
11
 
  desc "Parse and generate authorized_keys files for SSH."
12
 
 
13
 
  text_line :comment, :match => /^#/
14
 
  text_line :blank, :match => /^\s+/
15
 
 
16
 
  record_line :parsed,
17
 
    :fields   => %w{options type key name},
18
 
    :optional => %w{options},
19
 
    :rts => /^\s+/,
20
 
    :match    => /^(?:(.+) )?(ssh-dss|ssh-rsa) ([^ ]+) ?(.*)$/,
21
 
    :post_parse => proc { |h|
22
 
      h[:name] = "" if h[:name] == :absent
23
 
      h[:options] ||= [:absent]
24
 
      h[:options] = Puppet::Type::Ssh_authorized_key::ProviderParsed.parse_options(h[:options]) if h[:options].is_a? String
25
 
    },
26
 
    :pre_gen => proc { |h|
27
 
      h[:options] = [] if h[:options].include?(:absent)
28
 
      h[:options] = h[:options].join(',')
29
 
    }
30
 
 
31
 
  record_line :key_v1,
32
 
    :fields   => %w{options bits exponent modulus name},
33
 
    :optional => %w{options},
34
 
    :rts      => /^\s+/,
35
 
    :match    => /^(?:(.+) )?(\d+) (\d+) (\d+)(?: (.+))?$/
36
 
 
37
 
  def dir_perm
38
 
    0700
39
 
  end
40
 
 
41
 
  def file_perm
42
 
    0600
43
 
  end
44
 
 
45
 
  def target
46
 
      @resource.should(:target) || File.expand_path("~#{@resource.should(:user)}/.ssh/authorized_keys")
47
 
  rescue
48
 
      raise Puppet::Error, "Target not defined and/or specified user does not exist yet"
49
 
  end
50
 
 
51
 
  def user
52
 
    uid = File.stat(target).uid
53
 
    Etc.getpwuid(uid).name
54
 
  end
55
 
 
56
 
  def flush
57
 
    raise Puppet::Error, "Cannot write SSH authorized keys without user"    unless @resource.should(:user)
58
 
    raise Puppet::Error, "User '#{@resource.should(:user)}' does not exist" unless uid = Puppet::Util.uid(@resource.should(:user))
59
 
    unless File.exist?(dir = File.dirname(target))
60
 
      Puppet.debug "Creating #{dir}"
61
 
      Dir.mkdir(dir, dir_perm)
62
 
      File.chown(uid, nil, dir)
63
 
    end
64
 
 
65
 
    # ParsedFile usually calls backup_target much later in the flush process,
66
 
    # but our SUID makes that fail to open filebucket files for writing.
67
 
    # Fortunately, there's already logic to make sure it only ever happens once,
68
 
    # so calling it here supresses the later attempt by our superclass's flush method.
69
 
    self.class.backup_target(target)
70
 
 
71
 
    Puppet::Util::SUIDManager.asuser(@resource.should(:user)) { super }
72
 
    File.chown(uid, nil, target)
73
 
    File.chmod(file_perm, target)
74
 
  end
75
 
 
76
 
  # parse sshv2 option strings, wich is a comma separated list of
77
 
  # either key="values" elements or bare-word elements
78
 
  def self.parse_options(options)
79
 
    result = []
80
 
    scanner = StringScanner.new(options)
81
 
    while !scanner.eos?
82
 
      scanner.skip(/[ \t]*/)
83
 
      # scan a long option
84
 
      if out = scanner.scan(/[-a-z0-9A-Z_]+=\".*?\"/) or out = scanner.scan(/[-a-z0-9A-Z_]+/)
85
 
        result << out
86
 
      else
87
 
        # found an unscannable token, let's abort
88
 
        break
89
 
      end
90
 
      # eat a comma
91
 
      scanner.skip(/[ \t]*,[ \t]*/)
92
 
    end
93
 
    result
94
 
  end
95
 
end
96