diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-08-27 15:23:39 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-08-28 17:19:36 -0700 |
commit | 9b4a7da265329ffc4a41f565f3932c2b0d681a62 (patch) | |
tree | d080316f3d41d7ade0f7b79d3a404e73f5627900 | |
parent | 093e2cb93d5f8e14fc86d6eb67f174945b7b05af (diff) | |
download | chef-9b4a7da265329ffc4a41f565f3932c2b0d681a62.tar.gz |
FFI NetUseAdd
-rw-r--r-- | lib/chef/util/windows/net_use.rb | 18 | ||||
-rw-r--r-- | lib/chef/win32/api/net.rb | 8 | ||||
-rw-r--r-- | lib/chef/win32/net.rb | 16 |
3 files changed, 37 insertions, 5 deletions
diff --git a/lib/chef/util/windows/net_use.rb b/lib/chef/util/windows/net_use.rb index b9c67a53ac..e2a91db1a4 100644 --- a/lib/chef/util/windows/net_use.rb +++ b/lib/chef/util/windows/net_use.rb @@ -80,6 +80,13 @@ class Chef::Util::Windows::NetUse < Chef::Util::Windows @use_name = localname end + def to_ui2_struct(use_info) + use_info.inject({}) do |memo, (k,v)| + memo["ui2_#{k}".to_sym] = v + memo + end + end + def add(args) if args.class == String remote = args @@ -87,11 +94,12 @@ class Chef::Util::Windows::NetUse < Chef::Util::Windows args[:remote] = remote end args[:local] ||= @localname - use = use_info_2(args) - buffer = use_info_2_pack(use) - rc = NetUseAdd.call(nil, 2, buffer, nil) - if rc != NERR_Success - raise ArgumentError, get_last_error(rc) + ui2_hash = to_ui2_struct(args) + + begin + Chef::ReservedNames::Win32::Net.net_use_add_l2(nil, ui2_hash) + rescue Chef::Exceptions::Win32APIError => e + raise ArgumentError, e end end diff --git a/lib/chef/win32/api/net.rb b/lib/chef/win32/api/net.rb index b4be47e418..6828d7ee2f 100644 --- a/lib/chef/win32/api/net.rb +++ b/lib/chef/win32/api/net.rb @@ -309,6 +309,14 @@ class Chef #_Out_ LPBYTE *BufPtr #); safe_attach_function :NetUseGetInfo, [:LMSTR, :LMSTR, :DWORD, :pointer], :DWORD + +#NET_API_STATUS NetUseAdd( + #_In_ LMSTR UncServerName, + #_In_ DWORD Level, + #_In_ LPBYTE Buf, + #_Out_ LPDWORD ParmError +#); + safe_attach_function :NetUseAdd, [:LMSTR, :DWORD, :LPBYTE, :LPDWORD], :DWORD end end end diff --git a/lib/chef/win32/net.rb b/lib/chef/win32/net.rb index 2520e7a117..c1ef3e83ce 100644 --- a/lib/chef/win32/net.rb +++ b/lib/chef/win32/net.rb @@ -322,6 +322,22 @@ END ui2 end + + def self.net_use_add_l2(server_name, ui2_hash) + server_name = wstring(server_name) + group_name = wstring(group_name) + + buf = USE_INFO_2.new + + ui2_hash.each do |(k,v)| + buf.set(k,v) + end + + rc = NetUseAdd(server_name, 2, buf, nil) + if rc != NERR_Success + net_api_error!(rc) + end + end end NetUser = Net # For backwards compatibility end |