summaryrefslogtreecommitdiff
path: root/lib/chef/provider/user/dscl.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-07-02 15:09:07 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-07-02 15:09:07 -0700
commit7a1a6c8ef26c787e4b6dd1602f3d158b37e81720 (patch)
tree1e390cd535b38368d091cbb33e5d419408d5ce00 /lib/chef/provider/user/dscl.rb
parent77f8739a4741e2370e40ec39345a92a6ea393a1a (diff)
downloadchef-7a1a6c8ef26c787e4b6dd1602f3d158b37e81720.tar.gz
fix Layout/EmptyLineAfterGuardClause
i like this one, gives visual priority to returns or raises that are buried in the middle of things. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/provider/user/dscl.rb')
-rw-r--r--lib/chef/provider/user/dscl.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb
index 1ec80af039..147de19a65 100644
--- a/lib/chef/provider/user/dscl.rb
+++ b/lib/chef/provider/user/dscl.rb
@@ -230,6 +230,7 @@ in 'password', with the associated 'salt' and 'iterations'.")
#
def uid_used?(uid)
return false unless uid
+
users_uids = run_dscl("list", "/Users", "uid").split("\n")
uid_map = users_uids.each_with_object({}) do |tuid, tmap|
x = tuid.split
@@ -562,6 +563,7 @@ in 'password', with the associated 'salt' and 'iterations'.")
#
def dscl_set(user_hash, key, value)
raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.keys.include?(key)
+
user_hash[DSCL_PROPERTY_MAP[key]] = [ value ]
user_hash
end
@@ -571,6 +573,7 @@ in 'password', with the associated 'salt' and 'iterations'.")
#
def dscl_get(user_hash, key)
raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.keys.include?(key)
+
# DSCL values are set as arrays
value = user_hash[DSCL_PROPERTY_MAP[key]]
value.nil? ? value : value.first
@@ -585,12 +588,14 @@ in 'password', with the associated 'salt' and 'iterations'.")
return "" if ( args.first =~ /^delete/ ) && ( result.exitstatus != 0 )
raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") unless result.exitstatus == 0
raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") if result.stdout =~ /No such key: /
+
result.stdout
end
def run_plutil(*args)
result = shell_out("plutil", "-#{args[0]}", args[1..-1])
raise(Chef::Exceptions::PlistUtilCommandFailed, "plutil error: #{result.inspect}") unless result.exitstatus == 0
+
if result.stdout.encoding == Encoding::ASCII_8BIT
result.stdout.encode("utf-8", "binary", undef: :replace, invalid: :replace, replace: "?")
else