@@ -36,6 +36,8 @@ def initialize(info = {})
36
36
] , Exploit ::Remote ::HttpServer
37
37
)
38
38
39
+ # Used to keep track of resources added to the service manager by
40
+ # this module. see #add_resource and #cleanup
39
41
@my_resources = [ ]
40
42
@service_path = nil
41
43
end
@@ -205,9 +207,8 @@ def start_service(opts = {})
205
207
206
208
# Take care of removing any resources that we created
207
209
def cleanup
208
- @my_resources . delete_if do |resource |
210
+ @my_resources . each do |resource |
209
211
remove_resource ( resource )
210
- true
211
212
end
212
213
213
214
super
@@ -374,7 +375,8 @@ def add_resource(opts)
374
375
@service_path = opts [ 'Path' ]
375
376
res = service . add_resource ( opts [ 'Path' ] , opts )
376
377
377
- # This has to go *after* the call to add_resource in case it raises
378
+ # This has to go *after* the call to service.add_resource in case
379
+ # the service manager doesn't like it for some reason and raises.
378
380
@my_resources . push ( opts [ 'Path' ] )
379
381
380
382
res
@@ -472,7 +474,11 @@ def srvhost_addr
472
474
# Removes a URI resource.
473
475
#
474
476
def remove_resource ( name )
475
- service . remove_resource ( name )
477
+ # Guard against removing resources added by other modules
478
+ if @my_resources . include? ( name )
479
+ @my_resources . delete ( name )
480
+ service . remove_resource ( name )
481
+ end
476
482
end
477
483
478
484
#
0 commit comments