summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-02-06 10:51:19 -0800
committerGitHub <noreply@github.com>2019-02-06 10:51:19 -0800
commit3ffccac0acebffee22257c62e41902d83b7e3335 (patch)
tree198325ff28431601e049de8ced708f5b618bdc5a /lib
parent7674898ca6dbdf583708eb092fd107961793d12d (diff)
parent3dcacafb63ec280cb3db7dafd37230624b09ae65 (diff)
downloadchef-3ffccac0acebffee22257c62e41902d83b7e3335.tar.gz
Merge pull request #8165 from jjustice6/solaris_usermod
Create a separate Group provider for Solaris systems.
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/group/solaris.rb74
-rw-r--r--lib/chef/provider/group/usermod.rb4
-rw-r--r--lib/chef/providers.rb1
3 files changed, 76 insertions, 3 deletions
diff --git a/lib/chef/provider/group/solaris.rb b/lib/chef/provider/group/solaris.rb
new file mode 100644
index 0000000000..f5df203b78
--- /dev/null
+++ b/lib/chef/provider/group/solaris.rb
@@ -0,0 +1,74 @@
+#
+# Author:: Joshua Justice (<jjustice6@bloomberg.net>)
+# Copyright:: Copyright 2008-2019, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "chef/provider/group/groupadd"
+
+class Chef
+ class Provider
+ class Group
+ class Solaris < Chef::Provider::Group::Groupadd
+
+ # this provides line is setup to only catch the solaris2 platform, but
+ # NOT other platforms in the Solaris platform_family. (See usermod provider.)
+ provides :group, platform: "solaris2"
+
+ def load_current_resource
+ super
+ end
+
+ def define_resource_requirements
+ super
+
+ requirements.assert(:all_actions) do |a|
+ a.assertion { ::File.exist?("/usr/sbin/usermod") }
+ a.failure_message Chef::Exceptions::Group, "Could not find binary /usr/sbin/usermod for #{new_resource}"
+ # No whyrun alternative: this component should be available in the base install of any given system that uses it
+ end
+
+ requirements.assert(:modify, :manage) do |a|
+ a.assertion { (new_resource.members.empty? && new_resource.excluded_members.empty?) || new_resource.append }
+ a.failure_message Chef::Exceptions::Group, "setting group members directly is not supported by #{self}, must set append true in group"
+ # No whyrun alternative - this action is simply not supported.
+ end
+ end
+
+ def set_members(members)
+ unless members.empty?
+ members.each do |member|
+ add_member(member)
+ end
+ end
+ unless excluded_members.empty?
+ excluded_members.each do |excluded_member|
+ remove_member(excluded_member)
+ end
+ end
+ end
+
+ def add_member(member)
+ shell_out!("usermod", "-G", "+#{new_resource.group_name}", member)
+ end
+
+ def remove_member(member)
+ shell_out!("usermod", "-G", "-#{new_resource.group_name}", member)
+ end
+
+ end
+ end
+ end
+end
diff --git a/lib/chef/provider/group/usermod.rb b/lib/chef/provider/group/usermod.rb
index 34a563787f..06e05ff54d 100644
--- a/lib/chef/provider/group/usermod.rb
+++ b/lib/chef/provider/group/usermod.rb
@@ -76,10 +76,8 @@ class Chef
def append_flags
case node[:platform]
- when "openbsd", "netbsd", "aix", "solaris2", "smartos", "omnios"
+ when "openbsd", "netbsd", "aix", "smartos", "omnios"
"-G"
- when "solaris"
- [ "-a", "-G" ]
end
end
diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
index b7b0c52e07..4603be7746 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -117,6 +117,7 @@ require "chef/provider/group/gpasswd"
require "chef/provider/group/groupadd"
require "chef/provider/group/groupmod"
require "chef/provider/group/pw"
+require "chef/provider/group/solaris"
require "chef/provider/group/suse"
require "chef/provider/group/usermod"
require "chef/provider/group/windows"