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-08-28 18:52:22 +00:00
|
|
|
class RegistryKey < Vulcano.resource(1)
|
|
|
|
name 'registry_key'
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
attr_accessor :reg_key
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-08-28 18:52:22 +00:00
|
|
|
def initialize(name, reg_key = nil)
|
|
|
|
# if we have one parameter, we use it as name
|
|
|
|
reg_key = name if reg_key == nil
|
|
|
|
@name = name
|
|
|
|
@reg_key = reg_key
|
|
|
|
end
|
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def getRegistryValue(path, key)
|
|
|
|
cmd = "(Get-Item 'Registry::#{path}').GetValue('#{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)
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# get data
|
|
|
|
val = getRegistryValue(@reg_key, meth)
|
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
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
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
|
|
|
|
"Registry Key #{@name}"
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|