[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

James Turnbull james at lovedthanlost.net
Fri Jan 23 14:21:50 UTC 2009


The following commit has been merged in the master branch:
commit f6fa4f7b8c85303dd801fa6e4c5f47845af53c54
Author: Andrew Shafer <andrew at reductivelabs.com>
Date:   Mon Dec 1 00:21:20 2008 -0700

    Bug # 1680 Now you can set the hashed passwords on solaris
    
    Straight /etc/shadow hackery

diff --git a/lib/puppet/provider/user/user_role_add.rb b/lib/puppet/provider/user/user_role_add.rb
index 65bd639..2788937 100644
--- a/lib/puppet/provider/user/user_role_add.rb
+++ b/lib/puppet/provider/user/user_role_add.rb
@@ -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,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
     #Smooth like 80 grit
     def password=(cryptopw)
-        File.open("/etc/shadow", "r") do |shadow|
-            File.open("/etc/shadow_tmp", "w", 0600) do |shadow_tmp|
-                while line = shadow.gets do
-                    line_arr = line.split(':')
-                    if line_arr[0] == @resource[:name]
-                        line_arr[1] = cryptopw
-                        line = line_arr.join(':')
+        begin
+            File.open("/etc/shadow", "r") do |shadow|
+                File.open("/etc/shadow_tmp", "w", 0600) do |shadow_tmp|
+                    while line = shadow.gets do
+                        line_arr = line.split(':')
+                        if line_arr[0] == @resource[:name]
+                            line_arr[1] = cryptopw
+                            line = line_arr.join(':')
+                        end
+                        shadow_tmp.print line
                     end
-                    shadow_tmp.print line
                 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
-
-        File.rename("/etc/shadow_tmp", "/etc/shadow")
     end
 end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list