diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-08 07:03:34 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-05-15 08:51:16 -0700 |
commit | ca93171b6d2ed8a5a36c1f10f09a26b47fea47bf (patch) | |
tree | b16051150c8f541367fec8825bc86e8329c2aafb /lib/chef/win32/api | |
parent | e0fb4b98b6af2c4eb03eab7b84d2ea55cba87d35 (diff) | |
download | chef-ca93171b6d2ed8a5a36c1f10f09a26b47fea47bf.tar.gz |
NetUserGetInfo uses ffi
Diffstat (limited to 'lib/chef/win32/api')
-rw-r--r-- | lib/chef/win32/api/net.rb | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/lib/chef/win32/api/net.rb b/lib/chef/win32/api/net.rb index f2cfa93828..5eb77ae2b0 100644 --- a/lib/chef/win32/api/net.rb +++ b/lib/chef/win32/api/net.rb @@ -45,6 +45,7 @@ class Chef NERR_NotPrimary = 2226 NERR_SpeGroupOp = 2234 NERR_LastAdmin = 2452 + NERR_BadUsername = 2202 NERR_BadPassword = 2203 NERR_PasswordTooShort = 2245 NERR_UserNotFound = 2221 @@ -85,11 +86,44 @@ class Chef def set(key, val) - if val.class == String + if val.is_a? String val = FFI::MemoryPointer.from_string(val.to_wstring) end self[key] = val end + + def get(key) + if respond_to? key + send(key) + else + val = self[key] + if val.is_a? FFI::Pointer + if val.null? + nil + else + val.read_wstring + end + else + val + end + end + end + + def usri3_logon_hours + val = self[:usri3_logon_hours] + if !val.nil? && !val.null? + val.read_bytes(21) + else + nil + end + end + + def as_ruby + members.inject({}) do |memo, key| + memo[key] = get(key) + memo + end + end end class LOCALGROUP_MEMBERS_INFO_3 < FFI::Struct @@ -130,6 +164,18 @@ class Chef #); safe_attach_function :NetLocalGroupAddMembers, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :DWORD ], :DWORD +#NET_API_STATUS NetUserGetInfo( +# _In_ LPCWSTR servername, +# _In_ LPCWSTR username, +# _In_ DWORD level, +# _Out_ LPBYTE *bufptr +#); + safe_attach_function :NetUserGetInfo, [:LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE], :DWORD + +#NET_API_STATUS NetApiBufferFree( +# _In_ LPVOID Buffer +#); + safe_attach_function :NetApiBufferFree, [:LPVOID], :DWORD end end end |