X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fpw_hash.rb;h=0deeb3a6cf2527e9934f1887511d27271cc40081;hb=6963202b4b62c2816655ac9532521b018fdf83bd;hp=ad3e39375d7c4403b72e2113d91b53ee3ad815c7;hpb=a69999e580f8b3abd12446c2d6ad59e517651813;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/pw_hash.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/pw_hash.rb index ad3e39375..0deeb3a6c 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/pw_hash.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/pw_hash.rb @@ -1,3 +1,6 @@ + +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + Puppet::Parser::Functions::newfunction( :pw_hash, :type => :rvalue, @@ -24,6 +27,13 @@ Puppet::Parser::Functions::newfunction( environment contains several different operating systems, ensure that they are compatible before using this function.") do |args| raise ArgumentError, "pw_hash(): wrong number of arguments (#{args.size} for 3)" if args.size != 3 + args.map! do |arg| + if arg.is_a? Puppet::Pops::Types::PSensitiveType::Sensitive + arg.unwrap + else + arg + end + end raise ArgumentError, "pw_hash(): first argument must be a string" unless args[0].is_a? String or args[0].nil? raise ArgumentError, "pw_hash(): second argument must be a string" unless args[1].is_a? String hashes = { 'md5' => '1', @@ -38,19 +48,19 @@ Puppet::Parser::Functions::newfunction( password = args[0] return nil if password.nil? or password.empty? + salt = "$#{hash_type}$#{args[2]}" + # handle weak implementations of String#crypt if 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' # JRuby < 1.7.17 if RUBY_PLATFORM == 'java' - # override String#crypt for password variable - def password.crypt(salt) - # puppetserver bundles Apache Commons Codec - org.apache.commons.codec.digest.Crypt.crypt(self.to_java_bytes, salt) - end + # puppetserver bundles Apache Commons Codec + org.apache.commons.codec.digest.Crypt.crypt(password.to_java_bytes, salt) else # MS Windows and other systems that don't support enhanced salts raise Puppet::ParseError, 'system does not support enhanced salts' end + else + password.crypt(salt) end - password.crypt("$#{hash_type}$#{args[2]}") end