Skip to content

Commit 7070f18

Browse files
committed
Improve documentation and fail on Windows
1 parent 3906d21 commit 7070f18

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/puppet/parser/functions/pw_hash.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@
3232
password = args[0].to_s
3333
return nil if password.empty?
3434

35-
# work around JRuby bug in String#crypt for JRuby < 1.7.17
36-
if RUBY_PLATFORM == 'java' and 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.'
37-
def password.crypt(salt)
38-
# puppetserver bundles Apache Commons Codec
39-
org.apache.commons.codec.digest.Crypt.crypt(self.to_java_bytes, salt)
35+
# handle weak implementations of String#crypt
36+
if 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.'
37+
# JRuby < 1.7.17
38+
if RUBY_PLATFORM == 'java'
39+
# override String#crypt for password variable
40+
def password.crypt(salt)
41+
# puppetserver bundles Apache Commons Codec
42+
org.apache.commons.codec.digest.Crypt.crypt(self.to_java_bytes, salt)
43+
end
44+
else
45+
# MS Windows and other systems that don't support enhanced salts
46+
raise Puppet::ParseError, 'system does not support enhanced salts'
4047
end
4148
end
4249
password.crypt("$#{args[1]}$#{args[2]}")

0 commit comments

Comments
 (0)