-
-
Save kakwa/6244f3336b8d65cdbb91 to your computer and use it in GitHub Desktop.
patched version of pw_hash.rb working with puppetserver and jruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet/parser/functions' | |
module Puppet::Parser::Functions | |
newfunction(:pw_hash, :type => :rvalue, :doc => "Returns the hash of a password." | |
) do |args| | |
raise Puppet::ParseError, "pw_hash takes exactly two arguments," + | |
"#{args.length} provided" if args.length != 2 | |
pwd = args[0] | |
slt = args[1] | |
# walk around jruby bug on String::crypt | |
if RUBY_PLATFORM == "java" and "test".crypt('$1$1') != "$1$1$Bp8CU9Oujr9SSEw53WV6G." | |
# yum install apache-commons-codec.noarch | |
require '/usr/share/java/commons-codec.jar' | |
def pwd.crypt(salt) | |
org.apache.commons.codec.digest.Crypt.crypt(self.to_java_bytes, salt) | |
end | |
end | |
pwd.crypt("$6$#{slt}") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user { 'root': | |
ensure => present, | |
password => pw_hash($root_pw, $root_salt), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment