Bug # 1680 Now you can set the hashed passwords on solaris
Straight /etc/shadow hackery
This commit is contained in:
Родитель
0a40668b34
Коммит
f6fa4f7b8c
|
@ -29,7 +29,8 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd do
|
||||||
cmd = []
|
cmd = []
|
||||||
Puppet::Type.type(:user).validproperties.each do |property|
|
Puppet::Type.type(:user).validproperties.each do |property|
|
||||||
#skip the password because we can't create it with the solaris useradd
|
#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
|
# the value needs to be quoted, mostly because -c might
|
||||||
# have spaces in it
|
# have spaces in it
|
||||||
if value = @resource.should(property) and value != ""
|
if value = @resource.should(property) and value != ""
|
||||||
|
@ -167,20 +168,26 @@ 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
|
#Read in /etc/shadow, find the line for our used and rewrite it with the new pw
|
||||||
#Smooth like 80 grit
|
#Smooth like 80 grit
|
||||||
def password=(cryptopw)
|
def password=(cryptopw)
|
||||||
File.open("/etc/shadow", "r") do |shadow|
|
begin
|
||||||
File.open("/etc/shadow_tmp", "w", 0600) do |shadow_tmp|
|
File.open("/etc/shadow", "r") do |shadow|
|
||||||
while line = shadow.gets do
|
File.open("/etc/shadow_tmp", "w", 0600) do |shadow_tmp|
|
||||||
line_arr = line.split(':')
|
while line = shadow.gets do
|
||||||
if line_arr[0] == @resource[:name]
|
line_arr = line.split(':')
|
||||||
line_arr[1] = cryptopw
|
if line_arr[0] == @resource[:name]
|
||||||
line = line_arr.join(':')
|
line_arr[1] = cryptopw
|
||||||
|
line = line_arr.join(':')
|
||||||
|
end
|
||||||
|
shadow_tmp.print line
|
||||||
end
|
end
|
||||||
shadow_tmp.print line
|
|
||||||
end
|
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
|
||||||
|
|
||||||
File.rename("/etc/shadow_tmp", "/etc/shadow")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче