diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-08-27 15:05:20 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-08-28 17:19:35 -0700 |
commit | 093e2cb93d5f8e14fc86d6eb67f174945b7b05af (patch) | |
tree | 3e3b24ba68b6458a8f12a7dadb9ee424edf6bea0 /lib/chef/util | |
parent | 895c8718463029135cc1fe9b3084ff25957ac94d (diff) | |
download | chef-093e2cb93d5f8e14fc86d6eb67f174945b7b05af.tar.gz |
FFI NetUseGetInfo
Diffstat (limited to 'lib/chef/util')
-rw-r--r-- | lib/chef/util/windows/net_use.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/chef/util/windows/net_use.rb b/lib/chef/util/windows/net_use.rb index 34835b6d3d..b9c67a53ac 100644 --- a/lib/chef/util/windows/net_use.rb +++ b/lib/chef/util/windows/net_use.rb @@ -95,19 +95,20 @@ class Chef::Util::Windows::NetUse < Chef::Util::Windows end end - def get_info - ptr = 0.chr * PTR_SIZE - rc = NetUseGetInfo.call(nil, @name, 2, ptr) - - if rc != NERR_Success - raise ArgumentError, get_last_error(rc) + def from_use_info_struct(ui2_hash) + ui2_hash.inject({}) do |memo, (k,v)| + memo[k.to_s.sub('ui2_', '').to_sym] = v + memo end + end - ptr = ptr.unpack('L')[0] - buffer = 0.chr * SIZEOF_USE_INFO_2 - memcpy(buffer, ptr, buffer.size) - NetApiBufferFree(ptr) - use_info_2_unpack(buffer) + def get_info + begin + ui2 = Chef::ReservedNames::Win32::Net.net_use_get_info_l2(nil, use_name) + from_use_info_struct(ui2) + rescue Chef::Exceptions::Win32APIError => e + raise ArgumentError, e + end end def device |