2015-06-07 15:09:02 +00:00
|
|
|
# encoding: utf-8
|
2015-07-15 13:15:18 +00:00
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
2015-06-07 15:09:02 +00:00
|
|
|
# license: All rights reserved
|
|
|
|
|
2015-04-17 13:37:17 +00:00
|
|
|
require 'json'
|
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
include Serverspec::Type
|
2015-04-17 13:37:17 +00:00
|
|
|
|
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")
|
2015-08-03 00:40:08 +00:00
|
|
|
gpo_hash = JSON.parse(file)
|
2015-07-26 10:30:12 +00:00
|
|
|
key = "Machine--" + policy_path + "--" + policy_name
|
|
|
|
gpo_hash[key]
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# Group Policy
|
|
|
|
class GroupPolicy < Serverspec::Type::Base
|
|
|
|
|
|
|
|
def getRegistryValue(entry)
|
|
|
|
keys = entry['registry_information'][0]
|
|
|
|
cmd = "(Get-Item 'Registry::#{keys['path']}').GetValue('#{keys['key']}')"
|
|
|
|
command_result ||= @runner.run_command(cmd)
|
|
|
|
val = { :exit_code => command_result.exit_status.to_i, :data => command_result.stdout }
|
|
|
|
val
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def convertValue (value)
|
|
|
|
val = value.strip
|
|
|
|
val = val.to_i if val.match(/^\d+$/)
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
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-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# get data
|
|
|
|
val = getRegistryValue(entry)
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# verify data
|
|
|
|
if (val[:exit_code] == 0)
|
|
|
|
val = convertValue(val[:data])
|
|
|
|
else
|
|
|
|
nil
|
2015-04-17 13:37:17 +00:00
|
|
|
end
|
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def to_s
|
|
|
|
'Group Policy'
|
2015-04-17 13:37:17 +00:00
|
|
|
end
|
2015-07-26 10:30:12 +00:00
|
|
|
|
2015-04-17 13:37:17 +00:00
|
|
|
end
|
|
|
|
|
2015-08-03 00:40:08 +00:00
|
|
|
module Serverspec::Type
|
|
|
|
def group_policy(policy_path)
|
|
|
|
GroupPolicy.new(policy_path)
|
|
|
|
end
|
|
|
|
end
|