On Thu, 5 Apr 2001, Mike Austin wrote:

> On Thu, 5 Apr 2001, Stas Bekman wrote:
>
> > httpd.conf:
> > PerlSetEnv PERL5OPT -Mops=system
>
> Doesn't work.  I'm still able to use the system() call.
>
> Here's the stanza I used:
>
> <Location /perl/>
>         PerlSetEnv PERL5OPT -M-ops=system
>         SetHandler perl-script
>         PerlHandler Apache::Registry
>         Options +ExecCGI
>         PerlSendHeader On
> </Location>

True, I've played with -Mop:subprocess, which works from the command line,
but not if you set it from the httpd.conf... I guess you need to dive into
Opcode.pm to find out the fine details.

I was lucky to sit next to Nat here at ApacheCon, so here is one way to
hack it:

package My::Override;
require Exporter;
@ISA = 'Exporter';
@EXPORT_OK = qw(GLOBAL_system system);
sub import {
    my $pkg = shift;
    return unless @_;
    my $sym = shift;
    my $where = ($sym =~ s/^GLOBAL_// ? 'CORE::GLOBAL' : caller(0));
    $pkg->export($where, $sym, @_);
}
sub system {
    warn "cannot run @_";
}
1;

then in your code:

  my $r = shift;
  $r->send_http_header("text/plain");
  $r->print("Hello $$\n");
  $ENV{PATH} = '';

  use My::Override qw(system);
  system("/bin/echo", "hello");

prints:

  cannot run /bin/echo hello at /home/httpd/perl/My/Override.pm line 13.

Since you want to override this for the whole interpreter you do this in
the startup.pl:

  use My::Override qw(GLOBAL_system);

the only problem is that people can still call CORE::system() and get the
original function.

Philip told me that he has hacked Apache::Registry to use Safe.pm, and it
works well for him.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



Reply via email to