diff options
author | Sean Karlage <skarlage@get9.io> | 2018-01-08 09:14:53 -0800 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2018-01-08 12:14:53 -0500 |
commit | d9a69df03137753d5948a28a0bc9a2493dd8b89c (patch) | |
tree | f96b7224d81c3e24bc1255dbda7ff718139b1918 /lib/chef/provider/group/dscl.rb | |
parent | 2f1e097d0516b968fac4fe6bed790b88414f282c (diff) | |
download | chef-d9a69df03137753d5948a28a0bc9a2493dd8b89c.tar.gz |
Fix dscl group provider gid_used? (#6703)
Use dscl search verb in gid_used?
`dscl` has a search verb which makes checking whether a gid is
currently used much easier than parsing string output of listing all
gids.
Signed-off-by: Sean Karlage <skarlage@fb.com>
Diffstat (limited to 'lib/chef/provider/group/dscl.rb')
-rw-r--r-- | lib/chef/provider/group/dscl.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb index 71e42b36ba..fe152eda33 100644 --- a/lib/chef/provider/group/dscl.rb +++ b/lib/chef/provider/group/dscl.rb @@ -88,8 +88,12 @@ class Chef def gid_used?(gid) return false unless gid - groups_gids = safe_dscl("list", "/Groups", "gid") - !!( groups_gids =~ Regexp.new("#{Regexp.escape(gid.to_s)}\n") ) + search_gids = safe_dscl("search", "/Groups", "PrimaryGroupID", gid.to_s) + + # dscl -search should not return anything if the gid doesn't exist, + # but on the off-chance that it does, check whether the given gid is + # in the output. + !!(search_gids =~ /\b#{gid}\b/) end def set_gid |