mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
restore parse_passwd_line to be public, thanks @chris-rock
This commit is contained in:
parent
d5973d1189
commit
471a723b83
1 changed files with 27 additions and 17 deletions
|
@ -3,13 +3,39 @@
|
|||
# author: Dominik Richter
|
||||
|
||||
module ContentParser
|
||||
# parse etc/passwd file
|
||||
# Parse /etc/passwd files.
|
||||
#
|
||||
# @param [String] content the raw content of /etc/passwd
|
||||
# @return [Array] Collection of passwd entries
|
||||
def parse_passwd(content)
|
||||
content.to_s.split("\n").map do |line|
|
||||
parse_passwd_line(line)
|
||||
end
|
||||
end
|
||||
|
||||
# Parse a line of /etc/passwd
|
||||
#
|
||||
# @param [String] line a line of /etc/passwd
|
||||
# @return [Hash] Map of entries in this line
|
||||
def parse_passwd_line(line)
|
||||
x = line.split(':')
|
||||
{
|
||||
'name' => 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
|
||||
|
||||
# Parse a line with a command. For example: `a = b # comment`.
|
||||
# Retrieves the actual content.
|
||||
#
|
||||
# @param [String] raw the content lines you want to be parsed
|
||||
# @param [Hash] opts optional configuration
|
||||
# @return [Array] contains the actual line and the position of the line end
|
||||
def parse_comment_line(raw, opts)
|
||||
idx_nl = raw.index("\n")
|
||||
idx_comment = raw.index(opts[:comment_char])
|
||||
|
@ -32,20 +58,4 @@ module ContentParser
|
|||
end
|
||||
[line, idx_nl]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# parse a etc/passwd line
|
||||
def parse_passwd_line(line)
|
||||
x = line.split(':')
|
||||
{
|
||||
'name' => 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
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue