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

« back to all changes in this revision

Viewing changes to lib/puppet/util/windows/user.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-07-14 01:56:30 UTC
  • mfrom: (1.1.29) (3.1.43 sid)
  • Revision ID: package-import@ubuntu.com-20120714015630-ntj41rkvkq4zph4y
Tags: 2.7.18-1ubuntu1
* Resynchronise with Debian. (LP: #1023931) Remaining changes:
  - debian/puppetmaster-passenger.postinst: Make sure we error if puppet
    config print doesn't work
  - debian/puppetmaster-passenger.postinst: Ensure upgrades from
    <= 2.7.11-1 fixup passenger apache configuration.
* Dropped upstreamed patches:
  - debian/patches/CVE-2012-1906_CVE-2012-1986_to_CVE-2012-1989.patch
  - debian/patches/puppet-12844
  - debian/patches/2.7.17-Puppet-July-2012-CVE-fixes.patch
* Drop Build-Depends on ruby-rspec (in universe):
  - debian/control: remove ruby-rspec from Build-Depends
  - debian/patches/no-rspec.patch: make Rakefile work anyway if rspec
    isn't installed so we can use it in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppet/util/windows'
 
2
 
 
3
require 'win32/security'
 
4
 
 
5
module Puppet::Util::Windows::User
 
6
  include Windows::Security
 
7
  extend Windows::Security
 
8
 
 
9
  def admin?
 
10
    require 'facter'
 
11
 
 
12
    majversion = Facter.value(:kernelmajversion)
 
13
    return false unless majversion
 
14
 
 
15
    # if Vista or later, check for unrestricted process token
 
16
    return Win32::Security.elevated_security? unless majversion.to_f < 6.0
 
17
 
 
18
    # otherwise 2003 or less
 
19
    check_token_membership
 
20
  end
 
21
  module_function :admin?
 
22
 
 
23
  def check_token_membership
 
24
    sid = 0.chr * 80
 
25
    size = [80].pack('L')
 
26
    member = 0.chr * 4
 
27
 
 
28
    unless CreateWellKnownSid(WinBuiltinAdministratorsSid, nil, sid, size)
 
29
      raise Puppet::Util::Windows::Error.new("Failed to create administrators SID")
 
30
    end
 
31
 
 
32
    unless IsValidSid(sid)
 
33
      raise Puppet::Util::Windows::Error.new("Invalid SID")
 
34
    end
 
35
 
 
36
    unless CheckTokenMembership(nil, sid, member)
 
37
      raise Puppet::Util::Windows::Error.new("Failed to check membership")
 
38
    end
 
39
 
 
40
    # Is administrators SID enabled in calling thread's access token?
 
41
    member.unpack('L')[0] == 1
 
42
  end
 
43
  module_function :check_token_membership
 
44
end