| 1 |
NAME |
| 2 |
Safe::Hole - make a hole to the original main compartment in the Safe |
| 3 |
compartment |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
use Safe; |
| 7 |
use Safe::Hole; |
| 8 |
$cpt = new Safe; |
| 9 |
$hole = new Safe::Hole {}; |
| 10 |
sub test { Test->test; } |
| 11 |
$Testobj = new Test; |
| 12 |
# $cpt->share('&test'); # alternate as next line |
| 13 |
$hole->wrap(\&test, $cpt, '&test'); |
| 14 |
# ${$cpt->varglob('Testobj')} = $Testobj; # alternate as next line |
| 15 |
$hole->wrap($Testobj, $cpt, '$Testobj'); |
| 16 |
$cpt->reval('test; $Testobj->test;'); |
| 17 |
print $@ if $@; |
| 18 |
package Test; |
| 19 |
sub new { bless {},shift(); } |
| 20 |
sub test { my $self = shift; $self->test2; } |
| 21 |
sub test2 { print "Test->test2 called\n"; } |
| 22 |
|
| 23 |
DESCRIPTION |
| 24 |
We can call outside defined subroutines from the Safe compartment |
| 25 |
using share(), or can call methods through the object that is copied |
| 26 |
into the Safe compartment using varglob(). But that subroutines or |
| 27 |
methods are executed in the Safe compartment too, so they cannot call |
| 28 |
another subroutines that are dinamically qualified with the package |
| 29 |
name such as class methods nor can they compile code that uses opcodes |
| 30 |
that are forbidden within the compartment. |
| 31 |
|
| 32 |
Through Safe::Hole, we can execute outside defined subroutines in the |
| 33 |
original main compartment from the Safe compartment. |
| 34 |
|
| 35 |
Note that if a subroutine called through Safe::Hole::call does a |
| 36 |
Carp::croak() it will report the error as having occured within |
| 37 |
Safe::Hole. This can be avoided by including Safe::Hole::User in the |
| 38 |
@ISA for the package containing the subroutine. |
| 39 |
|
| 40 |
Methods |
| 41 |
new [NAMESPACE] |
| 42 |
Class method. Backward compatible constructor. NAMESPACE is the |
| 43 |
alternate root namespace that makes the compartment in which call() |
| 44 |
method execute the subroutine. Default of NAMESPACE means the |
| 45 |
current 'main'. This emulates the behaviour of Safe-Hole-0.08 and |
| 46 |
earlier. |
| 47 |
|
| 48 |
new \%arguments |
| 49 |
Class method. Constructor. The constructor is called with a hash |
| 50 |
reference providing the constructor arguments. The argument ROOT |
| 51 |
specifies the alternate root namespace for the object. If the ROOT |
| 52 |
argument is not specified then Safe::Hole object will attempt |
| 53 |
restore as much as it can of the environment in which it was |
| 54 |
constrtucted. This includes the opcode mask, %INC and @INC. If a |
| 55 |
root namespace is specified then it would not make sense to restore |
| 56 |
the %INC and @INC from main:: so this is not done. Also if a root |
| 57 |
namespace is given the opcode mask is not restored either. |
| 58 |
|
| 59 |
call $coderef [,@args] |
| 60 |
Object method. Call the subroutine refered by $coderef in the |
| 61 |
compartment that is specified with constructor new. @args are passed |
| 62 |
as the arguments to the called $coderef. Note that the arguments are |
| 63 |
not currently passed by reference although this may change in a |
| 64 |
future version. |
| 65 |
|
| 66 |
wrap $ref [,$cpt ,$name] |
| 67 |
Object method. If $ref is a code reference, this method returns the |
| 68 |
anonymous subroutine reference that calls $ref using call() method |
| 69 |
of Safe::Hole (see above). If $ref is a class object, this method |
| 70 |
makes a wrapper class of that object and returns a new object of the |
| 71 |
wrapper class. Through the wrapper class, all original class methods |
| 72 |
called using call() method of Safe::Hole. If $cpt as Safe object and |
| 73 |
$name as subroutine or scalar name specified, this method works like |
| 74 |
share() method of Safe. When $ref is a code reference $name must |
| 75 |
like '&subroutine'. When $ref is a object $name must like '$var'. |
| 76 |
Name $name may not be same as referent of $ref. For example: |
| 77 |
$hole->wrap(\&foo, $cpt, '&bar'); $hole->wrap(sub{...}, $cpt, |
| 78 |
'&foo'); $hole->wrap($objfoo, $cpt, '$objbar'); |
| 79 |
|
| 80 |
root |
| 81 |
Object method. Return the namespace that is specified with |
| 82 |
constructor new(). If no namespace was then root() returns 'main'. |
| 83 |
|
| 84 |
Warning |
| 85 |
You MUST NOT share the Safe::Hole object with the Safe compartment. If |
| 86 |
you do it the Safe compartment is NOT safe. |
| 87 |
|
| 88 |
This module provides a means to go from a state where an opcode is |
| 89 |
denied back to a state where it is not. Reasonable care has been taken |
| 90 |
to ensure that programs cannot simply manipulate the internals to the |
| 91 |
Safe::Hole object to reduce the opmask in effect. However there may |
| 92 |
still be a way that the authors have not considered. In particular it |
| 93 |
relies on the fact that a Perl program cannot change stuff inside the |
| 94 |
magic on a Perl variable. If you install a module that allows a Perl |
| 95 |
program to fiddle inside the magic then this assuption breaks down. One |
| 96 |
would hope that any system that was running un-trusted code would not |
| 97 |
have such a module installed. |
| 98 |
|
| 99 |
AUTHORS |
| 100 |
Sey Nakajima <[email protected]> (Initial version) |
| 101 |
|
| 102 |
Brian McCauley <[email protected]> (Maintenance) |
| 103 |
|
| 104 |
Todd Rinaldo <[email protected]> (Maintenance) |
| 105 |
|
| 106 |
SEE ALSO |
| 107 |
Safe(3). |
| 108 |
|