summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarcel Haerry <haerry@puzzle.ch>2010-12-23 10:39:33 +0100
committerMarcel Haerry <haerry@puzzle.ch>2010-12-23 10:39:33 +0100
commit3d913534ce2d60d8f245f65304907b8e1eb24665 (patch)
tree60efb5caed61b938c3e3ffe05f562660c35ce5d8 /lib
parent17ea81d4d6eac289f5431b8817be9b38eb7a6966 (diff)
adjust mkpasswd function to use plain ruby method, add tests for that function
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/mkpasswd.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/puppet/parser/functions/mkpasswd.rb b/lib/puppet/parser/functions/mkpasswd.rb
index 645df9b..92c218c 100644
--- a/lib/puppet/parser/functions/mkpasswd.rb
+++ b/lib/puppet/parser/functions/mkpasswd.rb
@@ -1,6 +1,8 @@
-# needs an 8-char salt *always*
module Puppet::Parser::Functions
- newfunction(:mkpasswd, :type => :rvalue) do |args|
- %x{/usr/bin/mkpasswd -H MD5 #{args[0]} #{args[1]}}.chomp
+ newfunction(:mkpasswd, :type => :rvalue, :doc =>
+ "Returns a salted md5 hash to be used for shadowed passwords") do |args|
+ raise Puppet::ParseError, "Wrong number of arguments" unless args.length == 2
+ raise Puppet::ParseError, "Salt must be 8 characters long" unless args[1].length == 8
+ args[0].crypt('$1$' << args[1] << '$')
end
end