From 306423bac260655a9d4b4b152782401f03325519 Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Thu, 27 Aug 2015 14:02:54 -0700 Subject: Use FFI for NetUseDel --- lib/chef/win32/api/net.rb | 11 +++++++++++ lib/chef/win32/net.rb | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'lib/chef/win32') diff --git a/lib/chef/win32/api/net.rb b/lib/chef/win32/api/net.rb index 0519e93a96..a7e20d0aeb 100644 --- a/lib/chef/win32/api/net.rb +++ b/lib/chef/win32/api/net.rb @@ -40,6 +40,10 @@ class Chef UF_NORMAL_ACCOUNT = 0x000200 UF_DONT_EXPIRE_PASSWD = 0x010000 + USE_NOFORCE = 0 + USE_FORCE = 1 + USE_LOTS_OF_FORCE = 2 #every windows API should support this flag + NERR_Success = 0 NERR_InvalidComputer = 2351 NERR_NotPrimary = 2226 @@ -272,6 +276,13 @@ class Chef #); safe_attach_function :NetUserDel, [:LPCWSTR, :LPCWSTR], :DWORD +#NET_API_STATUS NetUseDel( + #_In_ LMSTR UncServerName, + #_In_ LMSTR UseName, + #_In_ DWORD ForceCond +#); + safe_attach_function :NetUseDel, [:LMSTR, :LMSTR, :DWORD], :DWORD + end end end diff --git a/lib/chef/win32/net.rb b/lib/chef/win32/net.rb index babe5f829e..e481be7ddb 100644 --- a/lib/chef/win32/net.rb +++ b/lib/chef/win32/net.rb @@ -286,6 +286,26 @@ END net_api_error!(rc) end end + + def self.net_use_del(server_name, use_name, force=:use_noforce) + server_name = wstring(server_name) + use_name = wstring(use_name) + force_const = case force + when :use_noforce + USE_NOFORCE + when :use_force + USE_FORCE + when :use_lots_of_force + USE_LOTS_OF_FORCE + else + raise ArgumentError, "force must be one of [:use_noforce, :use_force, or :use_lots_of_force]" + end + + rc = NetUseDel(server_name, use_name, force_const) + if rc != NERR_Success + net_api_error!(rc) + end + end end NetUser = Net # For backwards compatibility end -- cgit v1.2.1