summaryrefslogtreecommitdiff
path: root/lib/chef/provider/group
diff options
context:
space:
mode:
authorSean Karlage <skarlage@get9.io>2018-01-08 09:14:53 -0800
committerPhil Dibowitz <phil@ipom.com>2018-01-08 12:14:53 -0500
commitd9a69df03137753d5948a28a0bc9a2493dd8b89c (patch)
treef96b7224d81c3e24bc1255dbda7ff718139b1918 /lib/chef/provider/group
parent2f1e097d0516b968fac4fe6bed790b88414f282c (diff)
downloadchef-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')
-rw-r--r--lib/chef/provider/group/dscl.rb8
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