Class: Win32::Security
- Inherits:
-
Object
- Object
- Win32::Security
- Extended by:
- Windows::Security::Functions
- Defined in:
- lib/win32/security.rb,
lib/win32/security/ace.rb,
lib/win32/security/acl.rb,
lib/win32/security/sid.rb
Overview
The Security class serves as a toplevel class namespace.
Defined Under Namespace
Constant Summary collapse
- VERSION =
The version of the win32-security library
'0.5.0'
- TOKEN_QUERY =
Used by OpenProcessToken
8
Class Method Summary collapse
-
.elevated_security? ⇒ Boolean
Returns whether or not the owner of the current process is running with elevated security privileges.
Class Method Details
.elevated_security? ⇒ Boolean
Returns whether or not the owner of the current process is running with elevated security privileges.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/win32/security.rb', line 32 def self.elevated_security? result = false # Work around a 64-bit JRuby bug if RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] == '64' ptr_type = :ulong_long else ptr_type = :uintptr_t end FFI::MemoryPointer.new(ptr_type) do |token| unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token) FFI.raise_windows_error('OpenProcessToken') end begin token = token.read_pointer.to_i # Since the TokenElevation struct only has 1 member, we use a pointer. te = FFI::MemoryPointer.new(:pointer) rl = FFI::MemoryPointer.new(:ulong) bool = GetTokenInformation( token, :TokenElevation, te, te.size, rl ) te.free te = FFI::MemoryPointer.new(rl.read_ulong) rl.clear bool = GetTokenInformation( token, :TokenElevation, te, te.size, rl ) FFI.raise_windows_error('GetTokenInformation') unless bool token_info = rl.read_ulong == 4 ? te.read_uint : te.read_ulong result = token_info != 0 ensure CloseHandle(token) te.free rl.free end end result end |