How to use modules inside a safe compartment? 
Author Message
 How to use modules inside a safe compartment?

[A complimentary Cc of this posting was sent to
Christoph Bergmann

> I tried this:

> $code='print get " http://www.*-*-*.com/ ";';

> use LWP::Simple;
> eval $code;        # this works - now everything should be loaded or am I
> wrong?

> use Safe;
> $safe=new Safe; $safe->share(qw(get));
> $safe->reval($code);

This is the minimal example which I could make work (but it required
enormous amount of hacking to get the quotes and ref/deref correct)...

Note also that I could not code CORE::GLOBAL::require(); I also know
no way to override entereval.  This would not work with 5.6.1, but
works with 5.005 and the bleading edge Perls.

#!/usr/bin/perl -w
use strict;
use Safe;

my $main = \%main:: ;

# This is not needed if LWP::Simple is preloaded, or if `caller' is added to
# the `permit' list

  my $code = shift;

  # Opcode::_safe_call_sv($obj->{Root}, $obj->{Mask}, $evalsub)
  # Resets the root stash and %INC
  no strict 'refs';
  local *{'__fakemain__::'} = $main;
  Opcode::_safe_call_sv( '__fakemain__', # Let the {*filter*} hide main, then unhide it again...
                         sub {   local *CORE::GLOBAL::caller = $caller;


my $url = " http://www.*-*-*.com/ ";
sub wget { my $res = call_with_main {   require LWP::Simple;
                                        LWP::Simple::get(shift) } $url;



my $safe = new Safe;


# These two guys use too many opcodes to be loaded inside a compartment
require "$" for qw(IO/Handle IO/Socket);

# Any one of these two is sufficient
#use LWP::Simple;
$safe->permit( qw(require entereval) );

$safe->reval('print wget()');



Tue, 13 Jul 2004 19:50:48 GMT  
 [ 1 post ] 

 Relevant Pages 

1. How to use modules inside a safe compartment?

2. Good Third Party Grid (db)?

3. Strange D3/FoxPro table behavior.

4. Paradox lock file has grown too large

5. Using other modules in a Safe compartment

6. Inheritance inside a Safe compartment

7. Inheritance inside a Safe compartment

8. ttable filter y2k problem

9. POSIX in Safe compartments (was: Q: Safe...)

10. Data::Dumper output & Safe compartments

11. use Module inside a Safe?

12. cannot use SUPER inside Safe module?


Powered by phpBB® Forum Software