Class: Win32::Security

Inherits:
Object
  • Object
show all
Extended by:
Windows::Security::Functions
Includes:
Windows::Security::Constants, Windows::Security::Functions, Windows::Security::Structs
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

Classes: ACE, ACL, Error, SID

Constant Summary collapse

VERSION =

The version of the win32-security library

'0.3.1'
TOKEN_QUERY =

Used by OpenProcessToken

8

Class Method Summary collapse

Class Method Details

.elevated_security?Boolean

Returns whether or not the owner of the current process is running with elevated security privileges.



31
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
# File 'lib/win32/security.rb', line 31

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)
      raise SystemCallError.new("OpenProcessToken", FFI.errno)
    end

    begin
      token = token.read_pointer.to_i

      # Since the TokenElevation struct only has 1 member, we use a pointer.
      te = FFI::MemoryPointer.new(:ulong)
      rl = FFI::MemoryPointer.new(:ulong)

      bool = GetTokenInformation(
        token,
        :TokenElevation,
        te,
        te.size,
        rl
      )

      raise SystemCallError.new("GetTokenInformation", FFI.errno) unless bool

      result = te.read_ulong != 0
    ensure
      CloseHandle(token)
      te.free
      rl.free
    end
  end

  result
end