mirror of
https://github.com/inspec/inspec
synced 2024-09-21 23:11:54 +00:00
migrate passwd and processes
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
dc0f61a0ef
commit
d9d67e943a
3 changed files with 26 additions and 35 deletions
|
@ -11,20 +11,24 @@
|
|||
# - home directory
|
||||
# - command
|
||||
|
||||
include Serverspec::Type
|
||||
|
||||
class Passwd < Serverspec::Type::File
|
||||
class Passwd < Vulcano.resource(1)
|
||||
name 'passwd'
|
||||
|
||||
attr_accessor :uid
|
||||
|
||||
def initialize(path = nil, uid: nil)
|
||||
@path = path || '/etc/passwd'
|
||||
@content = @vulcano.file(@path).contents
|
||||
@parsed = parse(@content)
|
||||
end
|
||||
|
||||
def to_s
|
||||
%Q[/etc/passwd]
|
||||
@path
|
||||
end
|
||||
|
||||
def determine_uid ()
|
||||
parsed = parse()
|
||||
uids = Array.new
|
||||
parsed.each {|x|
|
||||
@parsed.each {|x|
|
||||
if ( x.at(2) == "#{@uid}") then
|
||||
uids.push(x.at(0))
|
||||
end
|
||||
|
@ -43,8 +47,7 @@ class Passwd < Serverspec::Type::File
|
|||
end
|
||||
|
||||
def map_data (id)
|
||||
parsed = parse()
|
||||
parsed.map {|x|
|
||||
@parsed.map {|x|
|
||||
x.at(id)
|
||||
}
|
||||
end
|
||||
|
@ -66,8 +69,7 @@ class Passwd < Serverspec::Type::File
|
|||
end
|
||||
|
||||
def users
|
||||
parsed = parse()
|
||||
parsed.map {|x|
|
||||
@parsed.map {|x|
|
||||
{
|
||||
"name" => x.at(0),
|
||||
"password" => x.at(1),
|
||||
|
@ -80,20 +82,12 @@ class Passwd < Serverspec::Type::File
|
|||
}
|
||||
end
|
||||
|
||||
def parse
|
||||
entries = Array.new
|
||||
content().split("\n").each do |line|
|
||||
entries.push(line.split(':'))
|
||||
private
|
||||
|
||||
def parse(content)
|
||||
content.split("\n").map do |line|
|
||||
line.split(':')
|
||||
end
|
||||
entries
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module Serverspec::Type
|
||||
def passwd(uid=nil)
|
||||
i = Passwd.new('/etc/passwd')
|
||||
i.uid = uid
|
||||
i
|
||||
end
|
||||
end
|
|
@ -2,17 +2,19 @@
|
|||
# copyright: 2015, Vulcano Security GmbH
|
||||
# license: All rights reserved
|
||||
|
||||
include Serverspec::Type
|
||||
class Processes < Vulcano.resource(1)
|
||||
name 'processes'
|
||||
|
||||
class Processes < Serverspec::Type::Base
|
||||
def initialize grep
|
||||
attr_reader :list
|
||||
def initialize(grep)
|
||||
# turn into a regexp if it isn't one yet
|
||||
if grep.class == String
|
||||
grep = '(/[^/]*)*'+grep if grep[0] != '/'
|
||||
grep = Regexp.new('^'+grep+'(\s|$)')
|
||||
end
|
||||
|
||||
# get all running processes
|
||||
cmd = Serverspec::Type::Command.new('ps aux')
|
||||
cmd = @vulcano.run_command('ps aux')
|
||||
all = cmd.stdout.split("\n")[1..-1]
|
||||
all_cmds = all.map do |line|
|
||||
# user 32296 0.0 0.0 42592 7972 pts/15 Ss+ Apr06 0:00 zsh
|
||||
|
@ -37,10 +39,5 @@ class Processes < Serverspec::Type::Base
|
|||
hm[:command] =~ grep
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Serverspec::Type
|
||||
def processes( grep )
|
||||
Processes.new(grep)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,11 +18,11 @@ require 'vulcano/resource'
|
|||
# require 'resources/mysql_session'
|
||||
# require 'resources/ntp_conf'
|
||||
# require 'resources/parse_config'
|
||||
# require 'resources/passwd'
|
||||
require 'resources/passwd'
|
||||
# require 'resources/postgres'
|
||||
# require 'resources/postgres_conf'
|
||||
# require 'resources/postgres_session'
|
||||
# require 'resources/processes'
|
||||
require 'resources/processes'
|
||||
require 'resources/registry_key'
|
||||
require 'resources/security_policy'
|
||||
require 'resources/ssh_conf'
|
||||
|
|
Loading…
Reference in a new issue