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.


"The dead do not recognize context" -- Kai, Lexx

In reply to Re: Using Safe to reval complex math by djantzen
in thread Using Safe to reval complex math by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.