diff --git a/lib/resources/passwd.rb b/lib/resources/passwd.rb index f33158642..7bdb36d66 100644 --- a/lib/resources/passwd.rb +++ b/lib/resources/passwd.rb @@ -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 \ No newline at end of file diff --git a/lib/resources/processes.rb b/lib/resources/processes.rb index 380b6d770..9188d5a63 100644 --- a/lib/resources/processes.rb +++ b/lib/resources/processes.rb @@ -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 \ No newline at end of file +end diff --git a/lib/vulcano/resources.rb b/lib/vulcano/resources.rb index 376336afc..57bf88911 100644 --- a/lib/vulcano/resources.rb +++ b/lib/vulcano/resources.rb @@ -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'