class Chef::Provider::User::Pw

Public Instance Methods

check_lock() click to toggle source
# File lib/chef/provider/user/pw.rb, line 49
def check_lock
  @locked = case current_resource.password
            when /^\*LOCKED\*/
              true
            else
              false
            end
  @locked
end
create_user() click to toggle source
# File lib/chef/provider/user/pw.rb, line 33
def create_user
  shell_out!("pw", "useradd", set_options)
  modify_password
end
load_current_resource() click to toggle source
# File lib/chef/provider/user/pw.rb, line 28
def load_current_resource
  super
  raise Chef::Exceptions::User, "Could not find binary /usr/sbin/pw for #{new_resource}" unless ::TargetIO::File.exist?("/usr/sbin/pw")
end
lock_user() click to toggle source
# File lib/chef/provider/user/pw.rb, line 59
def lock_user
  shell_out!("pw", "lock", new_resource.username)
end
manage_user() click to toggle source
# File lib/chef/provider/user/pw.rb, line 38
def manage_user
  shell_out!("pw", "usermod", set_options)
  modify_password
end
modify_password() click to toggle source
# File lib/chef/provider/user/pw.rb, line 94
def modify_password
  if !new_resource.password.nil? && (current_resource.password != new_resource.password)
    logger.trace("#{new_resource} updating password")
    command = "pw usermod #{new_resource.username} -H 0"
    shell_out!(command, input: new_resource.password.to_s)
  else
    logger.debug("#{new_resource} no change needed to password")
  end
end
remove_user() click to toggle source
# File lib/chef/provider/user/pw.rb, line 43
def remove_user
  command = [ "pw", "userdel", new_resource.username ]
  command << "-r" if new_resource.manage_home
  shell_out!(command)
end
set_options() click to toggle source
# File lib/chef/provider/user/pw.rb, line 67
def set_options
  opts = [ new_resource.username ]

  field_list = {
    "comment" => "-c",
    "home" => "-d",
    "gid" => "-g",
    "uid" => "-u",
    "shell" => "-s",
  }
  field_list.sort_by { |a| a[0] }.each do |field, option|
    field_symbol = field.to_sym
    next unless current_resource.send(field_symbol) != new_resource.send(field_symbol)

    if new_resource.send(field_symbol)
      logger.trace("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}")
      opts << option
      opts << new_resource.send(field_symbol)
    end
  end
  if new_resource.manage_home
    logger.trace("#{new_resource} is managing the users home directory")
    opts << "-m"
  end
  opts
end
unlock_user() click to toggle source
# File lib/chef/provider/user/pw.rb, line 63
def unlock_user
  shell_out!("pw", "unlock", new_resource.username)
end