summaryrefslogtreecommitdiff
path: root/lib/chef/win32
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-08-27 14:02:54 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-08-28 17:19:34 -0700
commit306423bac260655a9d4b4b152782401f03325519 (patch)
tree0b60a527c8e6a155539b7abd0912ae6b1498514b /lib/chef/win32
parenta9524b0e799c13e90aef846e96c8d32909b5ee39 (diff)
downloadchef-306423bac260655a9d4b4b152782401f03325519.tar.gz
Use FFI for NetUseDel
Diffstat (limited to 'lib/chef/win32')
-rw-r--r--lib/chef/win32/api/net.rb11
-rw-r--r--lib/chef/win32/net.rb20
2 files changed, 31 insertions, 0 deletions
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