diff options
author | Stuart Preston <stuart@chef.io> | 2018-12-14 11:08:04 +0100 |
---|---|---|
committer | Stuart Preston <stuart@chef.io> | 2018-12-14 10:10:41 +0000 |
commit | 6247d28ac360873a2346fe852dc7fc442fdc92db (patch) | |
tree | 4be4e4d61b06112c06f5d7e6d99fe0752ab1ccf8 /lib | |
parent | 9a3c016feebcb2116a016e1eb8a96427aa581b3e (diff) | |
download | chef-6247d28ac360873a2346fe852dc7fc442fdc92db.tar.gz |
Merge pull request #8038 from MsysTechnologiesllc/Kapil/MSYS-897_allow_setting_the_comment_on_a_Windows_groupsp/chef14-backport-8038
Added property `comment` on Windows group.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/group/windows.rb | 1 | ||||
-rw-r--r-- | lib/chef/resource/group.rb | 4 | ||||
-rw-r--r-- | lib/chef/util/windows/net_group.rb | 6 | ||||
-rw-r--r-- | lib/chef/win32/api/net.rb | 16 | ||||
-rw-r--r-- | lib/chef/win32/net.rb | 15 |
5 files changed, 42 insertions, 0 deletions
diff --git a/lib/chef/provider/group/windows.rb b/lib/chef/provider/group/windows.rb index e0cb3b804b..6981c7126e 100644 --- a/lib/chef/provider/group/windows.rb +++ b/lib/chef/provider/group/windows.rb @@ -77,6 +77,7 @@ class Chef else @net_group.local_set_members(new_resource.members) end + @net_group.local_group_set_info(new_resource.comment) if new_resource.comment end def has_current_group_member?(member) diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index 2f8406faf4..7aaecc1374 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -51,6 +51,10 @@ class Chef property :non_unique, [ TrueClass, FalseClass ], default: false, description: "Allow gid duplication. May only be used with the Groupadd provider." + property :comment, String, + introduced: "14.9", + description: "Specifies a comment to associate with the local group." + alias_method :users, :members end end diff --git a/lib/chef/util/windows/net_group.rb b/lib/chef/util/windows/net_group.rb index efe2561bf2..0d2a366c4f 100644 --- a/lib/chef/util/windows/net_group.rb +++ b/lib/chef/util/windows/net_group.rb @@ -58,6 +58,12 @@ class Chef::Util::Windows::NetGroup raise ArgumentError, e end + def local_group_set_info(comment) + Chef::ReservedNames::Win32::NetUser.net_local_group_set_info(nil, groupname, comment) + rescue Chef::Exceptions::Win32APIError => e + raise ArgumentError, e + end + def local_delete_members(members) Chef::ReservedNames::Win32::NetUser.net_local_group_del_members(nil, groupname, members) rescue Chef::Exceptions::Win32APIError => e diff --git a/lib/chef/win32/api/net.rb b/lib/chef/win32/api/net.rb index e7c191dd9c..8c624866d4 100644 --- a/lib/chef/win32/api/net.rb +++ b/lib/chef/win32/api/net.rb @@ -144,6 +144,11 @@ class Chef layout :lgrpi0_name, :LPWSTR end + class LOCALGROUP_INFO_1 < FFI::Struct + layout :lgrpi1_name, :LPWSTR, + :lgrpi1_comment, :LPWSTR + end + class USE_INFO_2 < FFI::Struct include StructHelpers @@ -168,6 +173,17 @@ class Chef :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD ], :DWORD + # NET_API_STATUS NetLocalGroupSetInfo( + # _In_ LPCWSTR servername, + # _In_ LPCWSTR groupname, + # _In_ DWORD level, + # _In_ LPBYTE buf, + # _Out_ LPDWORD parm_err + # ); + safe_attach_function :NetLocalGroupSetInfo, [ + :LPCWSTR, :LPCWSTR, :DWORD, :LPBYTE, :LPDWORD + ], :DWORD + # NET_API_STATUS NetLocalGroupDel( # _In_ LPCWSTR servername, # _In_ LPCWSTR groupname diff --git a/lib/chef/win32/net.rb b/lib/chef/win32/net.rb index 09db2af89d..06d91e9823 100644 --- a/lib/chef/win32/net.rb +++ b/lib/chef/win32/net.rb @@ -180,6 +180,21 @@ class Chef end end + def self.net_local_group_set_info(server_name, group_name, comment) + server_name = wstring(server_name) + group_name = wstring(group_name) + comment = wstring(comment) + + buf = LOCALGROUP_INFO_1.new + buf[:lgrpi1_name] = FFI::MemoryPointer.from_string(group_name) + buf[:lgrpi1_comment] = FFI::MemoryPointer.from_string(comment) + + rc = NetLocalGroupSetInfo(server_name, group_name, 1, buf, nil) + if rc != NERR_Success + Chef::ReservedNames::Win32::Error.raise!(nil, rc) + end + end + def self.net_user_del(server_name, user_name) server_name = wstring(server_name) user_name = wstring(user_name) |