Module: PasswdParser
- Included in:
- Inspec::Resources::FreeBSDUser, Inspec::Resources::LinuxUser, Inspec::Resources::Passwd
- Defined in:
- lib/utils/parser.rb
Overview
author: Christoph Hartmann author: Dominik Richter
Instance Method Summary collapse
-
#parse_passwd(content) ⇒ Array
Parse /etc/passwd files.
-
#parse_passwd_line(line) ⇒ Hash
Parse a line of /etc/passwd.
Instance Method Details
#parse_passwd(content) ⇒ Array
Parse /etc/passwd files.
10 11 12 13 14 15 |
# File 'lib/utils/parser.rb', line 10 def parse_passwd(content) content.to_s.split("\n").map do |line| next if line[0] == '#' parse_passwd_line(line) end.compact end |
#parse_passwd_line(line) ⇒ Hash
Parse a line of /etc/passwd
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/utils/parser.rb', line 21 def parse_passwd_line(line) x = line.split(':') { 'user' => x.at(0), 'password' => x.at(1), 'uid' => x.at(2), 'gid' => x.at(3), 'desc' => x.at(4), 'home' => x.at(5), 'shell' => x.at(6), } end |