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.



574
575
576
577
# File 'lib/inspec/resources/users.rb', line 574

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

Instance Method Details

#meta_info(username) ⇒ Object



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/inspec/resources/users.rb', line 579

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