279c13b5e3
https://tickets.puppetlabs.com/browse/MODULES-1676 This is identical to what PASSWORD('') in MySQL does: 5.6.22-debug-log> CREATE USER 'testpwd'@'localhost' IDENTIFIED BY 'foo'; Query OK, 0 rows affected (0.03 sec) 5.6.22-debug-log> SELECT User,Host,Password FROM mysql.user WHERE User='testpwd'; +---------+-----------+-------------------------------------------+ | User | Host | Password | +---------+-----------+-------------------------------------------+ | testpwd | localhost | *F3A2A51A9B0F2BE2468926B4132313728C250DBF | +---------+-----------+-------------------------------------------+ 1 row in set (0.01 sec) 5.6.22-debug-log> SET PASSWORD FOR 'testpwd'@'localhost' = PASSWORD(''); Query OK, 0 rows affected (0.00 sec) 5.6.22-debug-log> SELECT User,Host,Password FROM mysql.user WHERE User='testpwd'; +---------+-----------+----------+ | User | Host | Password | +---------+-----------+----------+ | testpwd | localhost | | +---------+-----------+----------+ 1 row in set (0.00 sec)
16 lines
516 B
Ruby
16 lines
516 B
Ruby
# hash a string as mysql's "PASSWORD()" function would do it
|
|
require 'digest/sha1'
|
|
|
|
module Puppet::Parser::Functions
|
|
newfunction(:mysql_password, :type => :rvalue, :doc => <<-EOS
|
|
Returns the mysql password hash from the clear text password.
|
|
EOS
|
|
) do |args|
|
|
|
|
raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' +
|
|
"given (#{args.size} for 1)") if args.size != 1
|
|
|
|
return '' if args[0].empty?
|
|
'*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase
|
|
end
|
|
end
|