diff options
author | cgerke <cgerke@users.noreply.github.com> | 2016-11-02 21:01:44 +1100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-11-02 10:01:44 +0000 |
commit | c1caccb4f10a86b8d59a7ea4a8c0bf22d0c1ba83 (patch) | |
tree | 42cf060d5adcb89637a57ac6813e757a5f71fdb2 | |
parent | a7145cdadc00041a6877d05e6deb0dbe42281b76 (diff) | |
download | chef-c1caccb4f10a86b8d59a7ea4a8c0bf22d0c1ba83.tar.gz |
Add a default GID for user creation on MacOS (#5393)
* Avoid ArgumentError
new_resource.gid.to_s will be empty if a recipe calls the user resource without gid and changes the home property. Will result in an exception and if chef is run by root, the home dir will end up being owned by root from the mv.
* Avoid chown issues when using manage_home and not specifying a gid
Using a sensible CONSTANT for gid when new_resource.gid.nil?
Signed-off-by: Chris Gerke <chris.gerke@gmail.com>
-rw-r--r-- | lib/chef/provider/user/dscl.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 01203c0d9f..16d60ba116 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -51,6 +51,11 @@ class Chef provides :dscl_user provides :user, os: "darwin" + # Just-in-case a recipe calls the user dscl provider without specifying + # a gid property. Avoids chown issues in move_home when the manage_home + # property is in use. #5393 + STAFF_GROUP_ID = 20 + def define_resource_requirements super @@ -264,12 +269,12 @@ user password using shadow hash.") # # Sets the group id for the user using dscl. Fails if a group doesn't # exist on the system with given group id. If `gid` is not specified, it - # sets a default Mac user group "staff", with id 20. + # sets a default Mac user group "staff", with id 20 using the CONSTANT # def dscl_set_gid if new_resource.gid.nil? # XXX: mutates the new resource - new_resource.gid(20) + new_resource.gid(STAFF_GROUP_ID) elsif !new_resource.gid.to_s.match(/^\d+$/) begin possible_gid = run_dscl("read /Groups/#{new_resource.gid} PrimaryGroupID").split(" ").last @@ -329,7 +334,7 @@ user password using shadow hash.") def move_home Chef::Log.debug("#{new_resource} moving #{self} home from #{current_resource.home} to #{new_resource.home}") - + new_resource.gid(STAFF_GROUP_ID) if new_resource.gid.nil? src = current_resource.home FileUtils.mkdir_p(new_resource.home) files = ::Dir.glob("#{Chef::Util::PathHelper.escape_glob_dir(src)}/*", ::File::FNM_DOTMATCH) - ["#{src}/.", "#{src}/.."] |