summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-05-08 08:32:03 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-05-15 08:51:17 -0700
commit4f1c79cb4f6de820d2bb29ea1cb5e3adf914c1ec (patch)
tree70a1af64b62134a43d89d5ca1caedc8426775d73 /lib
parentca93171b6d2ed8a5a36c1f10f09a26b47fea47bf (diff)
downloadchef-4f1c79cb4f6de820d2bb29ea1cb5e3adf914c1ec.tar.gz
NetUserSetInfo uses ffi
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/util/windows/net_user.rb11
-rw-r--r--lib/chef/win32/api/net.rb22
-rw-r--r--lib/chef/win32/user.rb21
3 files changed, 45 insertions, 9 deletions
diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb
index 1144645eef..5da0fc3835 100644
--- a/lib/chef/util/windows/net_user.rb
+++ b/lib/chef/util/windows/net_user.rb
@@ -126,7 +126,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
def usri3_to_hash(usri3)
t = USER_INFO_3_TRANSFORM.invert
usri3.inject({}) do |memo, (k,v)|
- memo[USER_INFO_3_TRANSFORM[k]] = v
+ memo[t[k]] = v
memo
end
end
@@ -153,11 +153,10 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
end
def set_info(args)
- user = user_info_3(args)
- buffer = user_info_3_pack(user)
- rc = NetUserSetInfo.call(nil, @name, 3, buffer, nil)
- if rc != NERR_Success
- raise ArgumentError, get_last_error(rc)
+ begin
+ rc = Chef::ReservedNames::Win32::NetUser::net_user_set_info_l3(nil, @username, transform_usri3(args))
+ 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 5eb77ae2b0..91d665c49e 100644
--- a/lib/chef/win32/api/net.rb
+++ b/lib/chef/win32/api/net.rb
@@ -84,10 +84,16 @@ class Chef
:usri3_home_dir_drive, :LPWSTR,
:usri3_password_expired, :DWORD
-
def set(key, val)
- if val.is_a? String
- val = FFI::MemoryPointer.from_string(val.to_wstring)
+ val = if val.is_a? String
+ encoded = if val.encoding == Encoding::UTF_16LE
+ val
+ else
+ val.to_wstring
+ end
+ FFI::MemoryPointer.from_string(encoded)
+ else
+ val
end
self[key] = val
end
@@ -176,6 +182,16 @@ class Chef
# _In_ LPVOID Buffer
#);
safe_attach_function :NetApiBufferFree, [:LPVOID], :DWORD
+
+#NET_API_STATUS NetUserSetInfo(
+# _In_ LPCWSTR servername,
+# _In_ LPCWSTR username,
+# _In_ DWORD level,
+# _In_ LPBYTE buf,
+# _Out_ LPDWORD parm_err
+#);
+ safe_attach_function :NetUserSetInfo, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD], :DWORD
+
end
end
end
diff --git a/lib/chef/win32/user.rb b/lib/chef/win32/user.rb
index 345eb3b6c7..8b28bf8b29 100644
--- a/lib/chef/win32/user.rb
+++ b/lib/chef/win32/user.rb
@@ -152,6 +152,27 @@ END
ui3
end
+ def self.net_user_set_info_l3(server_name, user_name, info)
+ param_err = FFI::Buffer.new(:long)
+ buf = default_user_info_3
+
+ info.each do |k, v|
+ buf.set(k, v)
+ end
+
+ server_name = wstring(server_name)
+ user_name = wstring(user_name)
+
+ rc = NetUserSetInfo(server_name, user_name, 3, buf, param_err)
+ if rc != NERR_Success
+ if Chef::ReservedNames::Win32::Error.get_last_error != 0
+ Chef::ReservedNames::Win32::Error.raise!
+ else
+ net_api_error!(rc)
+ end
+ end
+ end
+
def self.net_local_group_add_member(server_name, group_name, domain_user)
server_name = server_name.to_wstring if server_name
group_name = group_name.to_wstring