lib/win32/security/sid.rb in win32-security-0.4.0 vs lib/win32/security/sid.rb in win32-security-0.4.1
- old
+ new
@@ -12,11 +12,11 @@
include Windows::Security::Functions
include Windows::Security::Structs
extend Windows::Security::Functions
# The version of the Win32::Security::SID class.
- VERSION = '0.2.3'
+ VERSION = '0.2.4'
# Some constant SID's for your convenience, in string format.
# See http://support.microsoft.com/kb/243330 for details.
Null = 'S-1-0'
@@ -77,11 +77,11 @@
def self.sid_to_string(sid)
result = nil
FFI::MemoryPointer.new(:pointer) do |string_sid|
unless ConvertSidToStringSid(sid, string_sid)
- raise SystemCallError.new("ConvertSidToStringSid", FFI.errno)
+ FFI.raise_windows_error('ConvertSidToStringSid')
end
result = string_sid.read_pointer.read_string
end
@@ -93,11 +93,11 @@
def self.string_to_sid(string)
result = nil
FFI::MemoryPointer.new(:pointer) do |sid|
unless ConvertStringSidToSid(string, sid)
- raise SystemCallError.new("ConvertStringSidToSid", FFI.errno)
+ FFI.raise_windows_error('ConvertStringSidToSid')
end
ptr = sid.read_pointer
result = ptr.read_bytes(GetLengthSid(ptr))
@@ -137,11 +137,11 @@
FFI::MemoryPointer.new(:uchar, size) do |sid|
auth = SID_IDENTIFIER_AUTHORITY.new
auth[:Value][5] = authority
unless InitializeSid(sid, auth, sub_authorities.length)
- raise SystemCallError.new("InitializeSid", FFI.errno)
+ FFI.raise_windows_error('InitializeSid')
end
sub_authorities.each_index do |i|
ptr = GetSidSubAuthority(sid, i)
ptr.write_ulong(sub_authorities[i])
@@ -192,16 +192,14 @@
ptoken = FFI::MemoryPointer.new(ptr_type)
# Try the thread token first, default to the process token.
bool = OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, 1, ptoken)
- if !bool && FFI.errno != ERROR_NO_TOKEN
- raise SystemCallError.new("OpenThreadToken", FFI.errno)
- else
+ unless bool
ptoken.clear
unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, ptoken)
- raise SystemCallError.new("OpenProcessToken", FFI.errno)
+ FFI.raise_windows_error('OpenProcessToken')
end
end
token = ptoken.read_pointer.to_i
@@ -214,11 +212,11 @@
pinfo = FFI::MemoryPointer.new(plength.read_ulong)
plength.clear
# Second pass, actual call (1 is TokenOwner)
unless GetTokenInformation(token, 1, pinfo, pinfo.size, plength)
- raise SystemCallError.new("GetTokenInformation", FFI.errno)
+ FFI.raise_windows_error('GetTokenInformation')
end
token_info = pinfo.read_pointer
ensure
CloseHandle(token) if token
@@ -246,11 +244,11 @@
domain,
domain_size,
use_ptr
)
unless bool
- raise SystemCallError.new("LookupAccountSid", FFI.errno)
+ FFI.raise_windows_error('LookupAccountSid')
end
elsif ordinal_val < 10 # Assume it's a binary SID.
account_ptr = FFI::MemoryPointer.from_string(account)
bool = LookupAccountSid(
@@ -262,11 +260,11 @@
domain_size,
use_ptr
)
unless bool
- raise SystemCallError.new("LookupAccountSid", FFI.errno)
+ FFI.raise_windows_error('LookupAccountSid')
end
account_ptr.free
else
bool = LookupAccountName(
@@ -277,11 +275,11 @@
domain,
domain_size,
use_ptr
)
unless bool
- raise SystemCallError.new("LookupAccountName", FFI.errno)
+ FFI.raise_windows_error('LookupAccountName')
end
end
# The arguments are flipped depending on which path we took
if ordinal_val.nil?
@@ -316,10 +314,10 @@
def to_s
string = nil
FFI::MemoryPointer.new(:pointer) do |ptr|
unless ConvertSidToStringSid(@sid, ptr)
- raise SystemCallError.new("ConvertSidToStringSid", FFI.errno)
+ FFI.raise_windows_error('ConvertSidToStringSid')
end
string = ptr.read_pointer.read_string
end