Class: LinuxUser

Inherits:
UnixUser show all
Includes:
ContentParser
Defined in:
lib/resources/user.rb

Instance Attribute Summary

Attributes inherited from UserInfo

#inspec

Instance Method Summary collapse

Methods included from ContentParser

#parse_comment_line, #parse_passwd, #parse_passwd_line

Methods inherited from UnixUser

#identity, #parse_value

Methods inherited from UserInfo

#initialize

Methods included from Converter

#convert_to_i

Constructor Details

This class inherits a constructor from UserInfo

Instance Method Details

#credentials(username) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/resources/user.rb', line 229

def credentials(username)
  cmd = inspec.command("chage -l #{username}")
  return nil if cmd.exit_status != 0

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

  {
    mindays: convert_to_i(params['Minimum number of days between password change']),
    maxdays: convert_to_i(params['Maximum number of days between password change']),
    warndays: convert_to_i(params['Number of days of warning before password expires']),
  }
end

#meta_info(username) ⇒ Object



218
219
220
221
222
223
224
225
226
227
# File 'lib/resources/user.rb', line 218

def meta_info(username)
  cmd = inspec.command("getent passwd #{username}")
  return nil if cmd.exit_status != 0
  # returns: root:x:0:0:root:/root:/bin/bash
  passwd = parse_passwd_line(cmd.stdout.chomp)
  {
    home: passwd['home'],
    shell: passwd['shell'],
  }
end