You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Rob Brown <ro...@0catch.com> on 2003/03/07 23:21:10 UTC

[mp2] What happened to $r->connection->remote_addr?

I'm getting complaints about Apache::DNAT not working with Apache 2 because 
mod_perl 1.99 suddenly can't handle the things it used to. 

I'm getting this spewage: 

[Fri Mar 07 11:22:21 2003] [error] [client 166.70.29.72] Can't locate object 
method "connection" via package "Apache::RequestRec" at 
/usr/lib/perl5/site_perl/5.8.0/Apache/DNAT.pm line 8. 

Here is the offending code: 

 my $c = $r->connection;   ##### line 8
 my $old_remote_addr = $c->remote_addr;
 my ($old_port, $old_addr) = sockaddr_in($old_remote_addr);
 $old_addr = inet_ntoa $old_addr;
 # munge and compute $new_port and $new_addr .....
 $c->remote_addr(scalar sockaddr_in($new_port, inet_aton($new_addr)));
 $c->remote_ip($new_addr); 

This all used to work just fine under mod_perl 1.27 but now fails miserably. 

I tried using "Apache::compat" also.  This seemed to pick up the 
$r->connection slightly better.  But $c->remote_addr is really wacked.  Now 
it crashes with this spewage: 

[Fri Mar 07 12:20:32 2003] [error] [client 166.70.29.72] Bad arg length for 
Socket::unpack_sockaddr_in, length is 31, should be 16 at 
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/Socket.pm line 370. 

I did a Data::Dumper on it and it's a ref??!! 

$old_remote_addr = bless( do{\(my $o = 135384736)}, 'APR::SockAddr' ); 

How am I supposed to pull the port and addr out of that nasty beast? 

$c->ip_get  or  $c->addr ? 

NOPE! 

[Fri Mar 07 12:22:12 2003] [error] [client 166.70.29.72] Can't locate object 
method "ip_get" via package "APR::SockAddr" at 
/usr/lib/perl5/site_perl/5.8.0/Apache/DNAT.pm line 13.
[Fri Mar 07 12:24:58 2003] [error] [client 166.70.29.72] Can't locate object 
method "addr" via package "APR::SockAddr" at 
/usr/lib/perl5/site_perl/5.8.0/Apache/DNAT.pm line 13. 

I've tried searching all the documentation for clues, but I must be looking 
in the wrong place.  I've even tried dereferencing the SCALAR ref and 
sending that through sockaddr_in or inet_ntoa, but that totally doesn't work 
either.  I'm running out of possibilities to try. 

Also, once I GET the connection information, I need to be able to SET it 
again to spoof the request into thinking the request is coming from the more 
correct peer instead of what the actual socket reports.  This should be 
reflected in the logs and in the environment REMOTE_ADDR and REMOTE_PORT for 
mod_cgi running CGI scripts. 

 $r->SET_remote_addr($new_remote_addr);  # ?????? 

I just need to port my module from mp1 to mp2.  Any ideas would be 
appreciated. 

 --
Rob 

DETAILS: 

Apache::DNAT is freely available from CPAN: 

http://search.cpan.org/src/BBB/Net-DNAT-0.10/lib/Apache/DNAT.pm 

$ uname -a
Linux box 2.4.18-14 #1 Wed Sep 4 12:13:11 EDT 2002 i686 athlon i386 
GNU/Linux 

I'm using the mod_perl rpm that comes stock with RedHat 8.0 linux: 

mod_perl-1.99_05-3 

I'm using the apache 2.0 rpm that comes stock with RedHat 8.0 linux: 

httpd-2.0.40-11 

I'm using the perl 5.8.0 rpm that comes stock with RedHat 8.0 linux: 

perl-5.8.0-55 

Re: [mp2] $r->document root("/my/hacked/path");

Posted by Stas Bekman <st...@stason.org>.
Rob Brown wrote:
> I need to be able to at least temporarily change the document_root on 
> the fly.  Something like the following:
> $r->document_root("/my/hacked/path");
> But it crashes with a prototype mismatch.  The docs say:
> $r->document_root:cannot currently be modified.  requires locking since 
> it is part ofthe per-server config structure which is shared between 
> threads

its in todo/api.txt:
$r->document_root:
cannot currently be modified.  requires locking since it is part of
the per-server config structure which is shared between threads

> Well, I could care less about actually modifying the server record. 
> Isn't there a way to point it to a temporary string just for the request?
> In Apache1, it worked fine to copy the entire server record into a 
> malloc and hack the document_root setting in the copy and point the 
> server record pointer there just for the request.  Then free this 
> temporary server record.
> Or in mod_perl, just set the document_root to the real path just long 
> enough for the Translation phase and then fix it back to the original 
> value in the Cleanup phase.
> What do you recommend in order to accomplish this under mod_perl 1.99 
> for Apache 2.0?

It needs to be implemented. Patches are welcome.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [mp2] $r->document root("/my/hacked/path");

Posted by Rob Brown <ro...@0catch.com>.
I need to be able to at least temporarily change the document_root on the 
fly.  Something like the following: 

$r->document_root("/my/hacked/path"); 

But it crashes with a prototype mismatch.  The docs say: 

$r->document_root:cannot currently be modified.  requires locking since it 
is part ofthe per-server config structure which is shared between threads 


Well, I could care less about actually modifying the server record. Isn't 
there a way to point it to a temporary string just for the request? 

In Apache1, it worked fine to copy the entire server record into a malloc 
and hack the document_root setting in the copy and point the server record 
pointer there just for the request.  Then free this temporary server record. 

Or in mod_perl, just set the document_root to the real path just long enough 
for the Translation phase and then fix it back to the original value in the 
Cleanup phase. 

What do you recommend in order to accomplish this under mod_perl 1.99 for 
Apache 2.0? 

Re[2]: [mp2] What happened to $r->connection->remote_addr?

Posted by Kamil <ka...@666.afraid.org>.
SB> 1.99_05 is one 7 months old. Please test it again with the released 1.99_08 or
SB> even better with the current cvs:
SB> http://perl.apache.org/download/source.html#2_0_Development_Source_Distribution

SB> As for missing methods reports, see:
SB> http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html
SB> e.g. you need to load 'Apache::Connection' to get remote_addr

I've tried to test ModPerl::MethodLookup, but cannot find this module.
Where can i find it ? Sorry if lame, its my first steps with mp2.

%perl -MApache2 -MModPerl::MethodLookup -le 'print((ModPerl::MethodLookup::lookup_method(shift))[0])' construct_url
Can't locate ModPerl/MethodLookup.pm in @INC (@INC contains: /usr/local/perl/lib/site_perl/5.8.0/i586-linux/Apache2
/usr/local/perl/lib/5.8.0/i586-linux /usr/local/perl/lib/5.8.0
/usr/local/perl/lib/site_perl/5.8.0/i586-linux /usr/local/perl/lib/site_perl/5.8.0 /usr/local/perl/lib/site_perl .).
BEGIN failed--compilation aborted.

%/usr/local/perl/lib/site_perl/5.8.0/i586-linux/ModPerl# ls
BuildOptions.pm  FunctionMap.pm  MapUtil.pm      RegistryBB.pm      TestRun.pm
Code.pm          Global.pm       ParseSource.pm  RegistryCooker.pm  TypeMap.pm
Config.pm        MM.pm           PerlRun.pm      RegistryLoader.pm  Util.pm
Const.pm         Manifest.pm     Registry.pm     StructureMap.pm    WrapXS.pm

I've tested it with mod_perl/1.99_08 (standard instalation), apache 2.0.44, perl 5.8.0.


--
Pozdrawiam, Kamil.


Re: [mp2] What happened to $r->connection->remote_addr?

Posted by Stas Bekman <st...@stason.org>.
Rob Brown wrote:
> I'm getting complaints about Apache::DNAT not working with Apache 2 
> because mod_perl 1.99 suddenly can't handle the things it used to.
> I'm getting this spewage:
> [Fri Mar 07 11:22:21 2003] [error] [client 166.70.29.72] Can't locate 
> object method "connection" via package "Apache::RequestRec" at 
> /usr/lib/perl5/site_perl/5.8.0/Apache/DNAT.pm line 8.
> Here is the offending code:
> my $c = $r->connection;   ##### line 8
> my $old_remote_addr = $c->remote_addr;
> my ($old_port, $old_addr) = sockaddr_in($old_remote_addr);
> $old_addr = inet_ntoa $old_addr;
> # munge and compute $new_port and $new_addr .....
> $c->remote_addr(scalar sockaddr_in($new_port, inet_aton($new_addr)));
> $c->remote_ip($new_addr);
> This all used to work just fine under mod_perl 1.27 but now fails 
> miserably.
> I tried using "Apache::compat" also.  This seemed to pick up the 
> $r->connection slightly better.  But $c->remote_addr is really wacked.  
> Now it crashes with this spewage:
> [Fri Mar 07 12:20:32 2003] [error] [client 166.70.29.72] Bad arg length 
> for Socket::unpack_sockaddr_in, length is 31, should be 16 at 
> /usr/lib/perl5/5.8.0/i386-linux-thread-multi/Socket.pm line 370.
> I did a Data::Dumper on it and it's a ref??!!
> $old_remote_addr = bless( do{\(my $o = 135384736)}, 'APR::SockAddr' );
> How am I supposed to pull the port and addr out of that nasty beast?
> $c->ip_get  or  $c->addr ?
> NOPE!
> [Fri Mar 07 12:22:12 2003] [error] [client 166.70.29.72] Can't locate 
> object method "ip_get" via package "APR::SockAddr" at 
> /usr/lib/perl5/site_perl/5.8.0/Apache/DNAT.pm line 13.
> [Fri Mar 07 12:24:58 2003] [error] [client 166.70.29.72] Can't locate 
> object method "addr" via package "APR::SockAddr" at 
> /usr/lib/perl5/site_perl/5.8.0/Apache/DNAT.pm line 13.
> I've tried searching all the documentation for clues, but I must be 
> looking in the wrong place.  I've even tried dereferencing the SCALAR 
> ref and sending that through sockaddr_in or inet_ntoa, but that totally 
> doesn't work either.  I'm running out of possibilities to try.
> Also, once I GET the connection information, I need to be able to SET it 
> again to spoof the request into thinking the request is coming from the 
> more correct peer instead of what the actual socket reports.  This 
> should be reflected in the logs and in the environment REMOTE_ADDR and 
> REMOTE_PORT for mod_cgi running CGI scripts.
> $r->SET_remote_addr($new_remote_addr);  # ??????
> I just need to port my module from mp1 to mp2.  Any ideas would be 
> appreciated.
> -- 
> Rob
> DETAILS:
> Apache::DNAT is freely available from CPAN:
> http://search.cpan.org/src/BBB/Net-DNAT-0.10/lib/Apache/DNAT.pm
> $ uname -a
> Linux box 2.4.18-14 #1 Wed Sep 4 12:13:11 EDT 2002 i686 athlon i386 
> GNU/Linux
> I'm using the mod_perl rpm that comes stock with RedHat 8.0 linux:
> mod_perl-1.99_05-3

1.99_05 is one 7 months old. Please test it again with the released 1.99_08 or 
even better with the current cvs:
http://perl.apache.org/download/source.html#2_0_Development_Source_Distribution

As for missing methods reports, see:
http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html
e.g. you need to load 'Apache::Connection' to get remote_addr


Also, in the future please add some new lines in your reports, it's extremely 
hard to parse when everything is piled in one para. Thanks.

> I'm using the apache 2.0 rpm that comes stock with RedHat 8.0 linux:
> httpd-2.0.40-11
> I'm using the perl 5.8.0 rpm that comes stock with RedHat 8.0 linux:
> perl-5.8.0-55


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com