add passwd support

This commit is contained in:
Christoph Hartmann 2015-07-15 00:47:17 +02:00
parent 4ff1687f6e
commit 8c17ab29a5
2 changed files with 64 additions and 0 deletions

63
lib/resources/passwd.rb Normal file
View file

@ -0,0 +1,63 @@
module Serverspec
module Type
class Passwd < File
attr_accessor :uid
def to_s
%Q[Passwd]
end
def determine_uid ()
parsed = parse()
uids = Array.new
parsed.each {|x|
if ( x.at(2) == "#{@uid}") then
uids.push(x.at(0))
end
}
uids
end
def username
uids = determine_uid()
uids.at(0)
end
def uids
determine_uid()
end
def count
arr = determine_uid()
arr.length
end
def homedirs
parsed = parse()
parsed.map {|x|
x.at(5)
}
end
def parse
entries = Array.new
content().split("\n").each do |line|
entries.push(line.split(':'))
end
entries
end
end
def passwd(filename, uid=nil)
i = Passwd.new(filename)
i.uid = uid
i
end
end
end
include Serverspec::Type

View file

@ -22,6 +22,7 @@ require 'resources/file'
require 'resources/group_policy'
require 'resources/mysql_conf'
require 'resources/mysql_session'
require 'resources/passwd'
require 'resources/postgres_conf'
require 'resources/postgres_session'
require 'resources/processes'