Skip to content

Commit

Permalink
Do the windows admin privilege check only on the windows versions tha…
Browse files Browse the repository at this point in the history
…t it is possible.
  • Loading branch information
sersut committed Jan 22, 2013
1 parent ef5c0a9 commit 7c647b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
9 changes: 9 additions & 0 deletions lib/chef/platform.rb
Expand Up @@ -476,6 +476,15 @@ def windows?
end
end

def windows_server_2003?
return false unless windows?

require 'ruby-wmi'

host = WMI::Win32_OperatingSystem.find(:first)
(host.version && host.version.start_with?("5.2"))
end

private

def explicit_provider(platform, version, resource_type)
Expand Down
22 changes: 14 additions & 8 deletions lib/chef/win32/security.rb
Expand Up @@ -482,14 +482,20 @@ def self.with_privileges(*privilege_names)
# Checks if the caller has the admin privilages in their
# security token
def self.has_admin_privilages?
process_token = open_process_token(Chef::ReservedNames::Win32::Process.get_current_process, TOKEN_READ)
elevation_result = FFI::Buffer.new(:ulong)
elevation_result_size = FFI::MemoryPointer.new(:uint32)
success = GetTokenInformation(process_token.handle.handle, :TokenElevation, elevation_result, 4, elevation_result_size)

# Assume process is not elevated if the call fails.
# Process is elevated if the result is different than 0.
success && (elevation_result.read_ulong != 0)
if Chef::Platform.windows_server_2003?
# Admin privilages do not exist on Windows Server 2003

true
else
process_token = open_process_token(Chef::ReservedNames::Win32::Process.get_current_process, TOKEN_READ)
elevation_result = FFI::Buffer.new(:ulong)
elevation_result_size = FFI::MemoryPointer.new(:uint32)
success = GetTokenInformation(process_token.handle.handle, :TokenElevation, elevation_result, 4, elevation_result_size)

# Assume process is not elevated if the call fails.
# Process is elevated if the result is different than 0.
success && (elevation_result.read_ulong != 0)
end
end
end
end
Expand Down

0 comments on commit 7c647b1

Please sign in to comment.