summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-08-19 15:32:19 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-08-19 15:34:23 -0700
commitf769d7eba17b3f5aa9e0561126bd9f6801c1bac2 (patch)
tree801dcc6f208510b9b7329e2bfcbc2ccbc055e09d /lib
parent0447477abd41488674f609cfa59c2bdf35ed6d03 (diff)
downloadchef-f769d7eba17b3f5aa9e0561126bd9f6801c1bac2.tar.gz
user provider manage_home behavior and refactor
split out the user provider into 1:1 resources. fix the behavior of the linux user provider to implement manage_home behavior correctly. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/user/aix.rb5
-rw-r--r--lib/chef/provider/user/dscl.rb1
-rw-r--r--lib/chef/provider/user/linux.rb33
-rw-r--r--lib/chef/provider/user/pw.rb3
-rw-r--r--lib/chef/provider/user/solaris.rb3
-rw-r--r--lib/chef/provider/user/useradd.rb9
-rw-r--r--lib/chef/provider/user/windows.rb2
-rw-r--r--lib/chef/providers.rb5
-rw-r--r--lib/chef/resource/user.rb6
-rw-r--r--lib/chef/resource/user/aix_user.rb31
-rw-r--r--lib/chef/resource/user/dscl_user.rb31
-rw-r--r--lib/chef/resource/user/linux_user.rb52
-rw-r--r--lib/chef/resource/user/pw_user.rb31
-rw-r--r--lib/chef/resource/user/solaris_user.rb31
-rw-r--r--lib/chef/resource/user/windows_user.rb31
-rw-r--r--lib/chef/resources.rb6
16 files changed, 267 insertions, 13 deletions
diff --git a/lib/chef/provider/user/aix.rb b/lib/chef/provider/user/aix.rb
index befb6ac3fd..8ac229ae4d 100644
--- a/lib/chef/provider/user/aix.rb
+++ b/lib/chef/provider/user/aix.rb
@@ -14,11 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+require "chef/provider/user/useradd"
+
class Chef
class Provider
class User
class Aix < Chef::Provider::User::Useradd
- provides :user, platform: %w{aix}
+ provides :user, os: "aix"
+ provides :aix_user
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]]
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb
index e933bf9dc0..821fa8e8a7 100644
--- a/lib/chef/provider/user/dscl.rb
+++ b/lib/chef/provider/user/dscl.rb
@@ -48,6 +48,7 @@ class Chef
attr_accessor :authentication_authority
attr_accessor :password_shadow_conversion_algorithm
+ provides :dscl_user
provides :user, os: "darwin"
def define_resource_requirements
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb
new file mode 100644
index 0000000000..ca331311f1
--- /dev/null
+++ b/lib/chef/provider/user/linux.rb
@@ -0,0 +1,33 @@
+#
+# Copyright:: Copyright 2016, 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/user/useradd"
+
+class Chef
+ class Provider
+ class User
+ class Linux < Chef::Provider::User::Useradd
+ # MAJOR XXX: the implementation of "linux" is the base class and all needs to be moved here
+ provides :linux_user
+ provides :user, os: "linux"
+
+ def managing_home_dir?
+ new_resource.manage_home # linux always 'supports' manage_home
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/provider/user/pw.rb b/lib/chef/provider/user/pw.rb
index 949a21790b..a1d7671c28 100644
--- a/lib/chef/provider/user/pw.rb
+++ b/lib/chef/provider/user/pw.rb
@@ -22,7 +22,8 @@ class Chef
class Provider
class User
class Pw < Chef::Provider::User
- provides :user, platform: %w{freebsd}
+ provides :pw_user
+ provides :user, os: "freebsd"
def load_current_resource
super
diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb
index 83ee8346a9..8d3df9e68b 100644
--- a/lib/chef/provider/user/solaris.rb
+++ b/lib/chef/provider/user/solaris.rb
@@ -24,7 +24,8 @@ class Chef
class Provider
class User
class Solaris < Chef::Provider::User::Useradd
- provides :user, platform: %w{omnios solaris2}
+ provides :solaris_user
+ provides :user, os: %w{omnios solaris2}
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]]
attr_writer :password_file
diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb
index 3fef8d3642..68b62812a7 100644
--- a/lib/chef/provider/user/useradd.rb
+++ b/lib/chef/provider/user/useradd.rb
@@ -23,7 +23,7 @@ class Chef
class Provider
class User
class Useradd < Chef::Provider::User
- provides :user
+ # MAJOR XXX: this should become the base class of all Useradd providers instead of the linux implementation
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:password, "-p"], [:shell, "-s"], [:uid, "-u"]]
@@ -116,15 +116,15 @@ class Chef
update_options(field, option, opts)
end
if updating_home?
+ opts << "-d" << new_resource.home
if managing_home_dir?
Chef::Log.debug("#{new_resource} managing the users home directory")
- opts << "-d" << new_resource.home << "-m"
+ opts << "-m"
else
Chef::Log.debug("#{new_resource} setting home to #{new_resource.home}")
- opts << "-d" << new_resource.home
end
end
- opts << "-o" if new_resource.non_unique || new_resource.supports[:non_unique]
+ opts << "-o" if new_resource.non_unique
opts
end
end
@@ -141,6 +141,7 @@ class Chef
def useradd_options
opts = []
opts << "-r" if new_resource.system
+ opts << "-M" unless managing_home_dir?
opts
end
diff --git a/lib/chef/provider/user/windows.rb b/lib/chef/provider/user/windows.rb
index 9545b1fd59..b086a1e32b 100644
--- a/lib/chef/provider/user/windows.rb
+++ b/lib/chef/provider/user/windows.rb
@@ -26,7 +26,7 @@ class Chef
class Provider
class User
class Windows < Chef::Provider::User
-
+ provides :windows_user
provides :user, os: "windows"
def initialize(new_resource, run_context)
diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
index 14c47df939..9e2a914b71 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -101,12 +101,13 @@ require "chef/provider/service/macosx"
require "chef/provider/service/aixinit"
require "chef/provider/service/aix"
+require "chef/provider/user/aix"
require "chef/provider/user/dscl"
+require "chef/provider/user/linux"
require "chef/provider/user/pw"
+require "chef/provider/user/solaris"
require "chef/provider/user/useradd"
require "chef/provider/user/windows"
-require "chef/provider/user/solaris"
-require "chef/provider/user/aix"
require "chef/provider/group/aix"
require "chef/provider/group/dscl"
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index 012fa278f1..a07ce8b24b 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -21,6 +21,7 @@ require "chef/resource"
class Chef
class Resource
class User < Chef::Resource
+ resource_name :user_resource_abstract_base_class # this prevents magickal class name DSL wiring
identity_attr :username
state_attrs :uid, :gid, :home
@@ -42,8 +43,8 @@ class Chef
@force = false
@non_unique = false
@supports = {
- :manage_home => false,
- :non_unique => false,
+ manage_home: false,
+ non_unique: false,
}
@iterations = 27855
@salt = nil
@@ -154,7 +155,6 @@ class Chef
:kind_of => [ TrueClass, FalseClass ]
)
end
-
end
end
end
diff --git a/lib/chef/resource/user/aix_user.rb b/lib/chef/resource/user/aix_user.rb
new file mode 100644
index 0000000000..7c07db2e25
--- /dev/null
+++ b/lib/chef/resource/user/aix_user.rb
@@ -0,0 +1,31 @@
+#
+# Copyright:: Copyright 2016, 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/resource/user"
+
+class Chef
+ class Resource
+ class User
+ class AixUser < Chef::Resource::User
+ resource_name :aix_user
+
+ provides :aix_user
+ provides :user, os: "aix"
+ end
+ end
+ end
+end
diff --git a/lib/chef/resource/user/dscl_user.rb b/lib/chef/resource/user/dscl_user.rb
new file mode 100644
index 0000000000..61517d8b44
--- /dev/null
+++ b/lib/chef/resource/user/dscl_user.rb
@@ -0,0 +1,31 @@
+#
+# Copyright:: Copyright 2016, 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/resource/user"
+
+class Chef
+ class Resource
+ class User
+ class DsclUser < Chef::Resource::User
+ resource_name :dscl_user
+
+ provides :dscl_user
+ provides :user, os: "darwin"
+ end
+ end
+ end
+end
diff --git a/lib/chef/resource/user/linux_user.rb b/lib/chef/resource/user/linux_user.rb
new file mode 100644
index 0000000000..3452459e39
--- /dev/null
+++ b/lib/chef/resource/user/linux_user.rb
@@ -0,0 +1,52 @@
+#
+# Copyright:: Copyright 2016, 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/resource/user"
+
+class Chef
+ class Resource
+ class User
+ class LinuxUser < Chef::Resource::User
+ resource_name :linux_user
+
+ provides :linux_user
+ provides :user, os: "linux"
+
+ def initialize(name, run_context = nil)
+ super
+ @supports = {
+ manage_home: true,
+ non_unique: true,
+ }
+ @manage_home = true
+ end
+
+ def supports(args = {})
+ Chef.log_deprecation "setting supports on the linux_user resource is deprecated"
+ # setting is deliberately disabled
+ super({})
+ end
+
+ def supports=(args)
+ Chef.log_deprecation "setting supports on the linux_user resource is deprecated"
+ # setting is deliberately disabled
+ supports({})
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/resource/user/pw_user.rb b/lib/chef/resource/user/pw_user.rb
new file mode 100644
index 0000000000..873be19d59
--- /dev/null
+++ b/lib/chef/resource/user/pw_user.rb
@@ -0,0 +1,31 @@
+#
+# Copyright:: Copyright 2016, 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/resource/user"
+
+class Chef
+ class Resource
+ class User
+ class PwUser < Chef::Resource::User
+ resource_name :pw_user
+
+ provides :pw_user
+ provides :user, os: "freebsd"
+ end
+ end
+ end
+end
diff --git a/lib/chef/resource/user/solaris_user.rb b/lib/chef/resource/user/solaris_user.rb
new file mode 100644
index 0000000000..bb897228b9
--- /dev/null
+++ b/lib/chef/resource/user/solaris_user.rb
@@ -0,0 +1,31 @@
+#
+# Copyright:: Copyright 2016, 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/resource/user"
+
+class Chef
+ class Resource
+ class User
+ class SolarisUser < Chef::Resource::User
+ resource_name :solaris_user
+
+ provides :solaris_user
+ provides :user, os: %w{omnios solaris2}
+ end
+ end
+ end
+end
diff --git a/lib/chef/resource/user/windows_user.rb b/lib/chef/resource/user/windows_user.rb
new file mode 100644
index 0000000000..d1a249fb50
--- /dev/null
+++ b/lib/chef/resource/user/windows_user.rb
@@ -0,0 +1,31 @@
+#
+# Copyright:: Copyright 2016, 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/resource/user"
+
+class Chef
+ class Resource
+ class User
+ class WindowsUser < Chef::Resource::User
+ resource_name :windows_user
+
+ provides :windows_user
+ provides :user, os: "windows"
+ end
+ end
+ end
+end
diff --git a/lib/chef/resources.rb b/lib/chef/resources.rb
index af9c918f55..0e73264832 100644
--- a/lib/chef/resources.rb
+++ b/lib/chef/resources.rb
@@ -82,6 +82,12 @@ require "chef/resource/smartos_package"
require "chef/resource/template"
require "chef/resource/timestamped_deploy"
require "chef/resource/user"
+require "chef/resource/user/aix_user"
+require "chef/resource/user/dscl_user"
+require "chef/resource/user/linux_user"
+require "chef/resource/user/pw_user"
+require "chef/resource/user/solaris_user"
+require "chef/resource/user/windows_user"
require "chef/resource/whyrun_safe_ruby_block"
require "chef/resource/windows_package"
require "chef/resource/yum_package"