diff options
author | Dave Eddy <dave@daveeddy.com> | 2015-03-16 20:23:42 -0400 |
---|---|---|
committer | Thom May <thom@chef.io> | 2015-09-02 13:52:18 +0100 |
commit | a3ac271fdd43a2f6ecf4c6dbe825b0f03f154fa3 (patch) | |
tree | f94e1dd274c578e68274fe1466bc559396646ec8 /lib/chef/provider | |
parent | c89c0a4e91d9c80c3d48f40e559ee30aa6051843 (diff) | |
download | chef-a3ac271fdd43a2f6ecf4c6dbe825b0f03f154fa3.tar.gz |
fix locking/unlocking users on SmartOS
Diffstat (limited to 'lib/chef/provider')
-rw-r--r-- | lib/chef/provider/user/solaris.rb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb index b242095f0c..c16db22ad4 100644 --- a/lib/chef/provider/user/solaris.rb +++ b/lib/chef/provider/user/solaris.rb @@ -1,7 +1,9 @@ # # Author:: Stephen Nelson-Smith (<sns@opscode.com>) # Author:: Jon Ramsey (<jonathon.ramsey@gmail.com>) +# Author:: Dave Eddy (<dave@daveeddy.com>) # Copyright:: Copyright (c) 2012 Opscode, Inc. +# Copyright:: Copyright 2015, Dave Eddy # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +25,6 @@ class Chef class User class Solaris < Chef::Provider::User::Useradd provides :user, platform: %w(omnios solaris2) - UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]] attr_writer :password_file @@ -43,6 +44,32 @@ class Chef super end + def check_lock + shadow_line = shell_out!('getent', 'shadow', new_resource.username).stdout.strip rescue nil + + # if the command fails we return nil, this can happen if the user + # in question doesn't exist + return nil if shadow_line.nil? + + # convert "dave:NP:16507::::::\n" to "NP" + fields = shadow_line.split(':') + + # '*LK*...' and 'LK' are both considered locked, + # so look for LK at the beginning of the shadow entry + # optionally surrounded by '*' + @locked = !!fields[1].match(/^\*?LK\*?/) + + @locked + end + + def lock_user + shell_out!('passwd', '-l', new_resource.username) + end + + def unlock_user + shell_out!('passwd', '-u', new_resource.username) + end + private def manage_password @@ -67,9 +94,10 @@ class Chef buffer.close # FIXME: mostly duplicates code with file provider deploying a file - mode = ::File.stat(@password_file).mode & 07777 - uid = ::File.stat(@password_file).uid - gid = ::File.stat(@password_file).gid + s = ::File.stat(@password_file) + mode = s.mode & 07777 + uid = s.uid + gid = s.gid FileUtils.chown uid, gid, buffer.path FileUtils.chmod mode, buffer.path |