inspec/lib/resources/group_policy.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

# encoding: utf-8
2015-07-15 13:15:18 +00:00
# copyright: 2015, Vulcano Security GmbH
# license: All rights reserved
require 'json'
2015-07-26 10:30:12 +00:00
# return JSON object
def gpo (policy_path, policy_name)
file = ::File.read(::File.join ::File.dirname(__FILE__), "gpo.json")
gpo_hash = JSON.parse(file)
2015-07-26 10:30:12 +00:00
key = "Machine--" + policy_path + "--" + policy_name
gpo_hash[key]
end
2015-07-26 10:30:12 +00:00
# Group Policy
class GroupPolicy < Vulcano.resource(1)
name 'group_policy'
2015-07-26 10:30:12 +00:00
def getRegistryValue(entry)
keys = entry['registry_information'][0]
cmd = "(Get-Item 'Registry::#{keys['path']}').GetValue('#{keys['key']}')"
command_result ||= vulcano.run_command(cmd)
2015-07-26 10:30:12 +00:00
val = { :exit_code => command_result.exit_status.to_i, :data => command_result.stdout }
val
end
2015-09-03 18:43:58 +00:00
def convertValue(value)
2015-07-26 10:30:12 +00:00
val = value.strip
val = val.to_i if val.match(/^\d+$/)
end
2015-07-26 10:30:12 +00:00
# returns nil, if not existant or value
def method_missing(meth)
# map gpo to registry key
entry = gpo(@name, meth.to_s)
2015-07-26 10:30:12 +00:00
# get data
val = getRegistryValue(entry)
2015-07-26 10:30:12 +00:00
# verify data
if (val[:exit_code] == 0)
val = convertValue(val[:data])
else
nil
end
2015-07-26 10:30:12 +00:00
end
2015-07-26 10:30:12 +00:00
def to_s
'Group Policy'
end
end