Removed
Link Here
|
1 |
--- lib/puppet/provider/user/pw.rb |
2 |
+++ lib/puppet/provider/user/pw.rb |
3 |
@@ -1,10 +1,11 @@ |
4 |
require 'puppet/provider/nameservice/pw' |
5 |
+require 'open3' |
6 |
|
7 |
Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::PW do |
8 |
desc "User management via `pw` on FreeBSD." |
9 |
|
10 |
commands :pw => "pw" |
11 |
- has_features :manages_homedir, :allows_duplicates |
12 |
+ has_features :manages_homedir, :allows_duplicates, :manages_passwords |
13 |
|
14 |
defaultfor :operatingsystem => :freebsd |
15 |
|
16 |
@@ -23,7 +24,7 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService:: |
17 |
def addcmd |
18 |
cmd = [command(:pw), "useradd", @resource[:name]] |
19 |
@resource.class.validproperties.each do |property| |
20 |
- next if property == :ensure |
21 |
+ next if property == :ensure or property == :password |
22 |
# the value needs to be quoted, mostly because -c might |
23 |
# have spaces in it |
24 |
if value = @resource.should(property) and value != "" |
25 |
@@ -37,5 +38,30 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService:: |
26 |
|
27 |
cmd |
28 |
end |
29 |
+ |
30 |
+ def create |
31 |
+ super |
32 |
+ |
33 |
+ # Set the password after create if given |
34 |
+ self.password = @resource[:password] if @resource[:password] |
35 |
+ end |
36 |
+ |
37 |
+ # use pw to update password hash |
38 |
+ def password=(cryptopw) |
39 |
+ Puppet.debug "change password for user '#{@resource[:name]}' method called with hash '#{cryptopw}'" |
40 |
+ stdin, stdout, stderr = Open3.popen3("pw user mod #{@resource[:name]} -H 0") |
41 |
+ stdin.puts(cryptopw) |
42 |
+ stdin.close |
43 |
+ Puppet.debug "finished password for user '#{@resource[:name]}' method called with hash '#{cryptopw}'" |
44 |
+ end |
45 |
+ |
46 |
+ # get password from /etc/master.passwd |
47 |
+ def password |
48 |
+ Puppet.debug "checking password for user '#{@resource[:name]}' method called" |
49 |
+ current_passline = `getent passwd #{@resource[:name]}` |
50 |
+ current_password = current_passline.chomp.split(':')[1] if current_passline |
51 |
+ Puppet.debug "finished password for user '#{@resource[:name]}' method called : '#{current_password}'" |
52 |
+ current_password |
53 |
+ end |
54 |
end |
55 |
|