]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
pw_hash: Fix functionality on JRuby < 1.7.17
authorEli Young <elyscape@gmail.com>
Tue, 5 May 2015 22:16:35 +0000 (15:16 -0700)
committerEli Young <elyscape@gmail.com>
Tue, 5 May 2015 22:53:34 +0000 (15:53 -0700)
The previous change to this function broke it on JRuby before 1.7.17 by
attempting to use a variable that wasn't defined (`salt`). To fix this,
define `salt` ahead of time and use that instead of building the salt
later.

cf. https://github.com/puppetlabs/puppetlabs-stdlib/pull/443#discussion_r29718588

lib/puppet/parser/functions/pw_hash.rb

index 4682a63672bb9a6aee6885b4128162f56e011387..41d42238d8dc57dd76566c4be2c4cb9951de5185 100644 (file)
@@ -38,6 +38,8 @@ 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
@@ -49,6 +51,6 @@ Puppet::Parser::Functions::newfunction(
         raise Puppet::ParseError, 'system does not support enhanced salts'
       end
     else
-      password.crypt("$#{hash_type}$#{args[2]}")
+      password.crypt(salt)
     end
 end