From 3d913534ce2d60d8f245f65304907b8e1eb24665 Mon Sep 17 00:00:00 2001 From: Marcel Haerry Date: Thu, 23 Dec 2010 10:39:33 +0100 Subject: adjust mkpasswd function to use plain ruby method, add tests for that function --- lib/puppet/parser/functions/mkpasswd.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3