Bug # 1680 Now you can set the hashed passwords on solaris

Straight /etc/shadow hackery
This commit is contained in:
Andrew Shafer 2008-12-01 00:21:20 -07:00 коммит произвёл James Turnbull
Родитель 0a40668b34
Коммит f6fa4f7b8c
1 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -29,7 +29,8 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd do
cmd = []
Puppet::Type.type(:user).validproperties.each do |property|
#skip the password because we can't create it with the solaris useradd
next if property == :ensure || property == :password
next if [:ensure, :password].include?(property)
# 1680 Now you can set the hashed passwords on solaris:lib/puppet/provider/user/user_role_add.rb
# the value needs to be quoted, mostly because -c might
# have spaces in it
if value = @resource.should(property) and value != ""
@ -167,6 +168,7 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd do
#Read in /etc/shadow, find the line for our used and rewrite it with the new pw
#Smooth like 80 grit
def password=(cryptopw)
begin
File.open("/etc/shadow", "r") do |shadow|
File.open("/etc/shadow_tmp", "w", 0600) do |shadow_tmp|
while line = shadow.gets do
@ -179,8 +181,13 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd do
end
end
end
File.rename("/etc/shadow_tmp", "/etc/shadow")
rescue => detail
fail "Could not write temporary shadow file: %s" % detail
ensure
# Make sure this *always* gets deleted
File.unlink("/etc/shadow_tmp") if File.exist?("/etc/shadow_tmp")
end
end
end