Okay, according to the docs, you can use an AUTOLOAD to load modules into the compartment.
You can 'use' the module outside the compartment and share an (autoloaded) function with the compartment. If an autoload is triggered by code in the compartment, or by any code anywhere that is called by any means from the compartment, then the eval in the .... module's AUTOLOAD function happens in the namespace of the compartment. Any variables created or used by the eval'd code are now under the control of the code in the compartment ... A similar effect applies to all runtime symbol lookups in code called from a compartment but not compiled within it.
use Safe; package userMath::Math::Complex; sub AUTOLOAD { print "AUTOLOAD $AUTOLOAD\n"; # test require '/usr/lib/perl5/5.8.0/Math/Complex.pm'; *Math::Complex::AUTOLOAD = sub { die "Method undefined\n" }; $AUTOLOAD =~ s/userMath//; goto &$AUTOLOAD; } sub DESTROY {}
The above almost works, except that the compilation of Math::Complex requires that you permit caller, eval and require at least, but still chokes on the overloaded operators. I've gotten roughly the above to work with a simple test module that doesn't do anything special.
Another option is to return a subroutine reference that can be run from within the calling scope, and which therefore has access to packages compiled there. This is however inherently less secure in case a clever attacker probes the packages available and constructs a potentially dangerous combination. Perhaps a better option would be some sort of proxy object that will limit access to modules outside of the compartment.
In reply to Re: Using Safe to reval complex math
by djantzen
in thread Using Safe to reval complex math
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |