[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Is there a Ruby equivilant to Python's exec_file?

Wayne Pierce

6/10/2005 4:52:00 PM

I'm working on a white-box security auditing framework, which is
currently written in Python and makes use of exec_file to load some
security scans at startup. Is there a way to do the same thing in
Ruby?

For those not familiar with Python, exec_file allows me to read an
external file and save the resulting objects to a hash/dictionary of
my choosing. I can then check the values or execute functions that
have been saved in my hash.

The beginning of each security check looks like:

author = "Wayne Pierce"
authorEmail = "shalofin@gmail.com"
license = "GNU GPL v2"
licenseLink = "http://www.gnu.org/licenses/gpl....
date = "19 June 2004"
version = "1.0.0"
status = "production"
platform = ["win32"]
category = ["system"]
connectionType = ["local","remote"]
description = "Return a listing of the running processes on a system."

def check():
...

The Python program reads each file and saves the results in a hash
under the scan name. Then I can compare the requirements passed to
the scanner against the saved data; for example I might want to only
run scans that are in cagetory "network", platform "win32", have a
status of "production" and can be run over the network (connectionType
of "remote", "ssh" or "wmi").

I haven't been able to find a way in Ruby to evaluate these files and
save the results to a variable, I would also need to save the function
"check" without executing it. However, if a scan met the criteria I
would then execute the function.

I have looked at Kernel#load, but the results aren't saved.
Kernel#readlines could work, although interpreting the code block
portion looks like it would be very ugly.

Does anyone know if there is an existing way to do this?

Thanks for any help,

Wayne


4 Answers

Joel VanderWerf

6/10/2005 5:43:00 PM

0

Wayne Pierce wrote:
> I'm working on a white-box security auditing framework, which is
> currently written in Python and makes use of exec_file to load some
> security scans at startup. Is there a way to do the same thing in
> Ruby?
>
> For those not familiar with Python, exec_file allows me to read an
> external file and save the resulting objects to a hash/dictionary of
> my choosing. I can then check the values or execute functions that
> have been saved in my hash.

Check out "script" on RAA: http://raa.ruby-lang.org/proj....


Ara.T.Howard

6/10/2005 6:14:00 PM

0

Joel VanderWerf

6/10/2005 9:16:00 PM

0

Ara.T.Howard wrote:
> On Sat, 11 Jun 2005, Joel VanderWerf wrote:
>
>> Wayne Pierce wrote:
>>
>>> I'm working on a white-box security auditing framework, which is
>>> currently written in Python and makes use of exec_file to load some
>>> security scans at startup. Is there a way to do the same thing in
>>> Ruby?
>>>
>>> For those not familiar with Python, exec_file allows me to read an
>>> external file and save the resulting objects to a hash/dictionary of
>>> my choosing. I can then check the values or execute functions that
>>> have been saved in my hash.
>>
>>
>> Check out "script" on RAA: http://raa.ruby-lang.org/proj....
>
>
> that's very cool joel! i did something with a similar intent, but slight
> different impl, at
>
> http://raa.ruby-lang.org/project...

One difference: using script.rb, the loaded file doesn't have to know
that it is being used in that way. The entire file (and its local
dependencies) are encapsulated, rather than only the selected modules
that you pass to Dynaload::export.

I like the #modules and #classes methods of Dynaload. Maybe I will
borrow that for Script instances. Maybe they should even be instance
methods of Module.

It might make sense to propose something like these two libraries as
RCRs, since so many people either ask for it or reinvent it, but the
implementation is so easy that it's probably not worth it...


Ara.T.Howard

6/10/2005 9:48:00 PM

0