Class: Inspec::Resources::DarwinUser

Inherits:
UnixUser show all
Defined in:
lib/inspec/resources/users.rb

Overview

we do not use ‘finger’ for MacOS, because it is harder to parse data with it instead we use ‘dscl’ to request user data

Instance Attribute Summary

Attributes inherited from UnixUser

#id_cmd, #inspec, #list_users_cmd

Attributes inherited from UserInfo

#inspec

Instance Method Summary collapse

Methods inherited from UnixUser

#identity, #list_users, #parse_id_entries, #parse_value

Methods inherited from UserInfo

#collect_user_details, #credentials, #identity, #list_users, #user_details

Methods included from Converter

#convert_to_i

Constructor Details

#initialize(inspec) ⇒ DarwinUser

Returns a new instance of DarwinUser.



560
561
562
563
# File 'lib/inspec/resources/users.rb', line 560

def initialize(inspec)
  @list_users_cmd ||= "dscl . list /Users"
  super
end

Instance Method Details

#meta_info(username) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/inspec/resources/users.rb', line 565

def meta_info(username)
  cmd = inspec.command("dscl -q . -read /Users/#{username} NFSHomeDirectory PrimaryGroupID RecordName UniqueID UserShell")
  return nil if cmd.exit_status != 0

  params = SimpleConfig.new(
    cmd.stdout.chomp,
    assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
    group_re: nil,
    multiple_values: false
  ).params

  {
    home: params["NFSHomeDirectory"],
    shell: params["UserShell"],
  }
end