lib/win32/security.rb in win32-security-0.1.2 vs lib/win32/security.rb in win32-security-0.1.3

- old
+ new

@@ -4,62 +4,63 @@ require 'windows/process' require 'windows/security' require 'windows/handle' require 'windows/error' -$LOAD_PATH.unshift(File.dirname(File.dirname(File.expand_path(__FILE__)))) - # The Win32 module serves as a namespace only. module Win32 - # The Security class encapsulates security aspects of MS Windows. - class Security + # The Security class encapsulates security aspects of MS Windows. + class Security - # Base error class for all Win32::Security errors. - class Error < StandardError; end + # Base error class for all Win32::Security errors. + class Error < StandardError; end - include Windows::Security + include Windows::Security - extend Windows::Process - extend Windows::Security - extend Windows::Handle - extend Windows::Error + extend Windows::Process + extend Windows::Security + extend Windows::Handle + extend Windows::Error - # The version of the win32-security library - VERSION = '0.1.2' + # The version of the win32-security library + VERSION = '0.1.3' - # Returns whether or not the owner of the current process is running - # with elevated security privileges. - # - def self.elevated_security? - token = 0.chr * 4 + # Returns whether or not the owner of the current process is running + # with elevated security privileges. + # + # Only supported on Windows Vista or later. + # + def self.elevated_security? + token = 0.chr * 4 - unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token) - raise Error, get_last_error - end + unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token) + raise Error, get_last_error + end - begin - token = token.unpack('V')[0] + begin + token = token.unpack('V')[0] - te = 0.chr * 4 # TOKEN_ELEVATION - rl = 0.chr * 4 # Return length + te = 0.chr * 4 # TOKEN_ELEVATION + rl = 0.chr * 4 # Return length - bool = GetTokenInformation( - token, - TokenElevation, - te, - te.size, - rl - ) + bool = GetTokenInformation( + token, + TokenElevation, + te, + te.size, + rl + ) - raise Error, get_last_error unless bool - ensure - CloseHandle(token) - end - - te.unpack('L')[0] != 0 + raise Error, get_last_error unless bool + ensure + CloseHandle(token) end - end + + # TokenIsElevated member of the TOKEN_ELEVATION struct + te.unpack('L')[0] != 0 + end + end end require 'win32/security/sid' #require 'win32/security/acl' #require 'win32/security/ace'