Fixes #5338. Note that defined methods are always shared across bindings, no matter what. This patch allows for local variables and other locally-scoped things to behave the same way.

git-svn-id: file:///home/svn/framework3/trunk@14126 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Tod Beardsley 2011-10-31 17:48:03 +00:00
parent 667175c650
commit 2a6b002054
1 changed files with 13 additions and 3 deletions

View File

@ -283,6 +283,7 @@ class Driver < Msf::Ui::Driver
processed_resource = erb.result(binding)
lines = processed_resource.each_line.to_a
bindings = {}
while lines.length > 0
line = lines.shift
@ -290,8 +291,17 @@ class Driver < Msf::Ui::Driver
line.strip!
next if line.length == 0
next if line =~ /^#/
if line =~ /<ruby>/
# Pretty soon, this is going to need an XML parser :)
# TODO: case matters for the tag and for binding names
if line =~ /<ruby/
if line =~ /\s+binding=(?:'(\w+)'|"(\w+)")(>|\s+)/
bin = ($~[1] || $~[2])
bindings[bin] = binding unless bindings.has_key? bin
bin = bindings[bin]
else
bin = binding
end
buff = ''
while lines.length > 0
line = lines.shift
@ -302,7 +312,7 @@ class Driver < Msf::Ui::Driver
if ! buff.empty?
print_status("resource (#{path})> Ruby Code (#{buff.length} bytes)")
begin
eval(buff, binding)
eval(buff, bin)
rescue ::Interrupt
raise $!
rescue ::Exception => e