You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by titetluc titetluc <ti...@gmail.com> on 2008/06/25 08:50:58 UTC
[MP2]mod_perl and index.html
Hello all
I am writing a Perl module to authenticate users (using mod_perl2 and httpd
2.2.6.
I would like to display the user name (r->user) when accessing a directory
(/test_index/index.html)
I have the following httpd configuration
<Location /test_index>
DirectoryIndex index.html
Options +indexes
</Location>
PerlModule Test
<Location /test_index/index.html>
Require valid-user
AuthType basic
AuthName test_index
SetHandler perl-script
PerlAuthenHandler Apache2::AuthSSO::Test->set_user
PerlResponseHandler Apache2::AuthSSO::Test->display_user
</Location>
In addition, I added an empty index.html file in the htdocs/test_index
directory
The Perl Test module is
package Test;
use warnings;
use strict;
use Carp;
use Apache2::Const qw(:common);
sub set_user {
my ($self, $r) = @_;
$r->user('myself');
return OK;
}
sub display_user {
my ($self, $r) = @_;
my $user = defined $r->user ? $r->user : 'user is not defined';
print $user;
return OK;
}
1;
When I access with my browser to http://localhost/test_index/index.html,
user is set to 'myself'
BUT when I access with my browser to http://localhost/test_index/ ... user
is not defined !!!
I don't know if the problem comes from mod_perl or from the httpd
configuration.
Any help would be appreciated.
Thanks
Re: [MP2]mod_perl and index.html
Posted by titetluc titetluc <ti...@gmail.com>.
Torsten,
I created a bug. Bug number is
45297<https://issues.apache.org/bugzilla/show_bug.cgi?id=45297>
Thank you very much for your help
2008/6/27, Torsten Foertsch <to...@gmx.net>:
>
> On Fri 27 Jun 2008, titetluc titetluc wrote:
> > Would it be rather a wrong httpd configuration: my requirement is very
> > common (calling a response handler for an index.html and access the
> r->user
> > information). I may misconfigure Apache ????
> >
> > BTW, how can I verify if it is a bug ? Which apache mailing list do I
> have
> > to use ?
>
>
> On the apache httpd website http://httpd.apache.org you'll find
> instructions
> how to file a bug.
>
> I have verified it without mod_perl with apache 2.2.9:
>
> DirectoryIndex index.shtml
> Options Includes Indexes
> AddType text/html .shtml
> AddOutputFilter INCLUDES .shtml
>
> <Location /index.shtml>
>
> Require valid-user
> AuthType basic
>
> AuthName "Something very secret"
> AuthUserFile /path/to/htpasswd
> </Location>
>
> My index.shtml reads:
>
> <html>
> <body>
> <h1>Hello <!--#echo var="REMOTE_USER" --></h1>
> <pre>
> <!--#printenv -->
> </pre>
> </body>
> </html>
>
> If /index.shtml is requested all works normal. If only / is requested I get
> the password prompt. Then it shows the page but the REMOTE_USER variable is
> unset. This variable is r->user.
>
> File the bug then send its number to the list. I'll fill in the details. In
> your bug description you can reference this thread:
>
> http://www.gossamer-threads.com/lists/modperl/modperl/97533
>
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>
Re: [MP2]mod_perl and index.html
Posted by Torsten Foertsch <to...@gmx.net>.
On Fri 27 Jun 2008, titetluc titetluc wrote:
> Would it be rather a wrong httpd configuration: my requirement is very
> common (calling a response handler for an index.html and access the r->user
> information). I may misconfigure Apache ????
>
> BTW, how can I verify if it is a bug ? Which apache mailing list do I have
> to use ?
On the apache httpd website http://httpd.apache.org you'll find instructions
how to file a bug.
I have verified it without mod_perl with apache 2.2.9:
DirectoryIndex index.shtml
Options Includes Indexes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
<Location /index.shtml>
Require valid-user
AuthType basic
AuthName "Something very secret"
AuthUserFile /path/to/htpasswd
</Location>
My index.shtml reads:
<html>
<body>
<h1>Hello <!--#echo var="REMOTE_USER" --></h1>
<pre>
<!--#printenv -->
</pre>
</body>
</html>
If /index.shtml is requested all works normal. If only / is requested I get
the password prompt. Then it shows the page but the REMOTE_USER variable is
unset. This variable is r->user.
File the bug then send its number to the list. I'll fill in the details. In
your bug description you can reference this thread:
http://www.gossamer-threads.com/lists/modperl/modperl/97533
Torsten
--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: [MP2]mod_perl and index.html
Posted by titetluc titetluc <ti...@gmail.com>.
2008/6/26, Torsten Foertsch <to...@gmx.net>:
>
> On Thu 26 Jun 2008, titetluc titetluc wrote:
> > In PerlResponseHandler, $r->main and $r->prev are undefined. I can not
> > understand why $r->main AND $r->prev are not defined (intuitively,
> $r->prev
> > should be defined)
>
>
> I'd expect $r->user to be set, not $r->prev->user nor $r->main->user. But
> I'd
> expect $r->prev to be set because $r is the result of an internal redirect.
> But I am not sure what exactly ap_internal_fast_redirect does.
>
> Oh my, I found it. ap_internal_fast_redirect isn't exactly an internal
> redirect. Instead it overrides the current request with a subreq. Look at
> modules/http/http_request.c. There is a comment that says something about
> that function:
>
> /* XXX: Is this function is so bogus and fragile that we deep-6 it? */
> AP_DECLARE(void) ap_internal_fast_redirect(request_rec *rr, request_rec *r)
>
> And yes, it forgets about $r->user at least in apache 2.2.6. Maybe you
> file a
> bug for apache?
Would it be rather a wrong httpd configuration: my requirement is very
common (calling a response handler for an index.html and access the r->user
information). I may misconfigure Apache ????
BTW, how can I verify if it is a bug ? Which apache mailing list do I have
to use ?
You can check in the AuthenHandler for $r->main. If it is true you can set
> $r->user as well as $r->main->user.
>
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>
Re: [MP2]mod_perl and index.html
Posted by Torsten Foertsch <to...@gmx.net>.
On Thu 26 Jun 2008, titetluc titetluc wrote:
> In PerlResponseHandler, $r->main and $r->prev are undefined. I can not
> understand why $r->main AND $r->prev are not defined (intuitively, $r->prev
> should be defined)
I'd expect $r->user to be set, not $r->prev->user nor $r->main->user. But I'd
expect $r->prev to be set because $r is the result of an internal redirect.
But I am not sure what exactly ap_internal_fast_redirect does.
Oh my, I found it. ap_internal_fast_redirect isn't exactly an internal
redirect. Instead it overrides the current request with a subreq. Look at
modules/http/http_request.c. There is a comment that says something about
that function:
/* XXX: Is this function is so bogus and fragile that we deep-6 it? */
AP_DECLARE(void) ap_internal_fast_redirect(request_rec *rr, request_rec *r)
And yes, it forgets about $r->user at least in apache 2.2.6. Maybe you file a
bug for apache?
You can check in the AuthenHandler for $r->main. If it is true you can set
$r->user as well as $r->main->user.
Torsten
--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: [MP2]mod_perl and index.html
Posted by titetluc titetluc <ti...@gmail.com>.
2008/6/27, Rolf Schaufelberger <rs...@plusw.de>:
>
> Am Donnerstag, 26. Juni 2008 16:36:49 schrieb titetluc titetluc:
>
> > > > sub set_user {
> > > > my ($self, $r) = @_;
>
>
>
> Shouldn't that be
>
> sub set_user :method {
> my ($self, $r) = @_;
>
> When you use $r as second argument ?
I am not a mod_perl specialist, but declaring the method without the :method
attribute works correctly. According to
http://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers, the
:method attribute is not required
--
>
> Rolf Schaufelberger
>
Re: [MP2]mod_perl and index.html
Posted by Rolf Schaufelberger <rs...@plusw.de>.
Am Donnerstag, 26. Juni 2008 16:36:49 schrieb titetluc titetluc:
> > > sub set_user {
> > > my ($self, $r) = @_;
Shouldn't that be
sub set_user :method {
my ($self, $r) = @_;
When you use $r as second argument ?
--
Rolf Schaufelberger
Re: [MP2]mod_perl and index.html
Posted by titetluc titetluc <ti...@gmail.com>.
2008/6/26 Torsten Foertsch <to...@gmx.net>:
> On Wed 25 Jun 2008, titetluc titetluc wrote:
> > PerlModule Test
> > <Location /test_index/index.html>
> > Require valid-user
> > AuthType basic
> > AuthName test_index
> > SetHandler perl-script
> >
> > PerlAuthenHandler Apache2::AuthSSO::Test->set_user
> >
> > PerlResponseHandler Apache2::AuthSSO::Test->display_user
> > </Location>
> >
>
******
> In addition, I added an empty index.html file in the htdocs/test_index
> directory
> >
> > The Perl Test module is
> >
> > package Test;
> > use warnings;
> > use strict;
> > use Carp;
> >
> > use Apache2::Const qw(:common);
> >
> > sub set_user {
> > my ($self, $r) = @_;
> > $r->user('myself');
> > return OK;
> > }
> > sub display_user {
> > my ($self, $r) = @_;
> > my $user = defined $r->user ? $r->user : 'user is not defined';
> > print $user;
> > return OK;
> > }
> >
> > 1;
> >
> > When I access with my browser to http://localhost/test_index/index.html,
> > user is set to 'myself'
> > BUT when I access with my browser to http://localhost/test_index/ ...
> user
> > is not defined !!!
>
> What happens here? When you access .../index.html your main request matches
> the location condition and is served accordingly. If you access .../ the
> main
> request goes through all phases up to fixup missing the location directives
> because the condition does not match. In fixup mod_dir creates an URI
> subreq
> for each DirectoryIndex.
>
> mod_dir.c contains the following code:
>
> /* The sub request lookup is very liberal, and the core
> map_to_storage
> * handler will almost always result in HTTP_OK as /foo/index.html
> * may be /foo with PATH_INFO="/index.html", or even / with
> * PATH_INFO="/foo/index.html". To get around this we insist that
> the
> * the index be a regular filetype.
> *
> * Another reason is that the core handler also makes the assumption
> * that if r->finfo is still NULL by the time it gets called, the
> * file does not exist.
> */
> if (rr->status == HTTP_OK
> && ( (rr->handler && !strcmp(rr->handler, "proxy-server"))
> || rr->finfo.filetype == APR_REG)) {
> ap_internal_fast_redirect(rr, r);
> return OK;
> }
>
> You see, for the DirectoryIndex feature to work properly the index document
> has to have an associated file. Your index document is a
> PerlResponseHandler.
> So, I suspect there is no index.html file. In that case $r->filename
> is "/path/to/test_index" and $r->path_info "index.html" for the subreq.
>
> Use the source, Luke!
>
> Now, I think you can make it working in one of these ways:
>
> 1) create .../test_index/index.html as a regular file.
> 2) redirect /test_index/index.html to a file (Alias ....).
>
Torsten
I created the test_index/index.html as a regular file (see the stars above
;-)).
The effect is that my PerlResponseHandler is correctly called.
But my problem is that I can not retrieved the user (set in the
PerlAuthenHandler) in the PerlResponseHandler.
In PerlResponseHandler, $r->main and $r->prev are undefined. I can not
understand why $r->main AND $r->prev are not defined (intuitively, $r->prev
should be defined)
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
Re: [MP2]mod_perl and index.html
Posted by Torsten Foertsch <to...@gmx.net>.
On Wed 25 Jun 2008, titetluc titetluc wrote:
> PerlModule Test
> <Location /test_index/index.html>
> Require valid-user
> AuthType basic
> AuthName test_index
> SetHandler perl-script
>
> PerlAuthenHandler Apache2::AuthSSO::Test->set_user
>
> PerlResponseHandler Apache2::AuthSSO::Test->display_user
> </Location>
>
> In addition, I added an empty index.html file in the htdocs/test_index
> directory
>
> The Perl Test module is
>
> package Test;
> use warnings;
> use strict;
> use Carp;
>
> use Apache2::Const qw(:common);
>
> sub set_user {
> my ($self, $r) = @_;
> $r->user('myself');
> return OK;
> }
> sub display_user {
> my ($self, $r) = @_;
> my $user = defined $r->user ? $r->user : 'user is not defined';
> print $user;
> return OK;
> }
>
> 1;
>
> When I access with my browser to http://localhost/test_index/index.html,
> user is set to 'myself'
> BUT when I access with my browser to http://localhost/test_index/ ... user
> is not defined !!!
What happens here? When you access .../index.html your main request matches
the location condition and is served accordingly. If you access .../ the main
request goes through all phases up to fixup missing the location directives
because the condition does not match. In fixup mod_dir creates an URI subreq
for each DirectoryIndex.
mod_dir.c contains the following code:
/* The sub request lookup is very liberal, and the core map_to_storage
* handler will almost always result in HTTP_OK as /foo/index.html
* may be /foo with PATH_INFO="/index.html", or even / with
* PATH_INFO="/foo/index.html". To get around this we insist that the
* the index be a regular filetype.
*
* Another reason is that the core handler also makes the assumption
* that if r->finfo is still NULL by the time it gets called, the
* file does not exist.
*/
if (rr->status == HTTP_OK
&& ( (rr->handler && !strcmp(rr->handler, "proxy-server"))
|| rr->finfo.filetype == APR_REG)) {
ap_internal_fast_redirect(rr, r);
return OK;
}
You see, for the DirectoryIndex feature to work properly the index document
has to have an associated file. Your index document is a PerlResponseHandler.
So, I suspect there is no index.html file. In that case $r->filename
is "/path/to/test_index" and $r->path_info "index.html" for the subreq.
Use the source, Luke!
Now, I think you can make it working in one of these ways:
1) create .../test_index/index.html as a regular file.
2) redirect /test_index/index.html to a file (Alias ....).
Torsten
--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: [MP2]mod_perl and index.html
Posted by titetluc titetluc <ti...@gmail.com>.
2008/6/25 titetluc titetluc <ti...@gmail.com>:
> Hello all
>
> I am writing a Perl module to authenticate users (using mod_perl2 and httpd
> 2.2.6.
> I would like to display the user name (r->user) when accessing a directory
> (/test_index/index.html)
>
> I have the following httpd configuration
>
> <Location /test_index>
> DirectoryIndex index.html
> Options +indexes
> </Location>
>
> PerlModule Test
> <Location /test_index/index.html>
> Require valid-user
> AuthType basic
> AuthName test_index
> SetHandler perl-script
>
> PerlAuthenHandler Apache2::AuthSSO::Test->set_user
>
> PerlResponseHandler Apache2::AuthSSO::Test->display_user
> </Location>
>
> In addition, I added an empty index.html file in the htdocs/test_index
> directory
>
> The Perl Test module is
>
> package Test;
> use warnings;
> use strict;
> use Carp;
>
> use Apache2::Const qw(:common);
>
> sub set_user {
> my ($self, $r) = @_;
> $r->user('myself');
> return OK;
> }
> sub display_user {
> my ($self, $r) = @_;
> my $user = defined $r->user ? $r->user : 'user is not defined';
> print $user;
> return OK;
> }
>
> 1;
>
> When I access with my browser to http://localhost/test_index/index.html,
> user is set to 'myself'
> BUT when I access with my browser to http://localhost/test_index/ ... user
> is not defined !!!
>
> I don't know if the problem comes from mod_perl or from the httpd
> configuration.
> Any help would be appreciated.
>
> Thanks
>
I found a thread related to directory indexes (
http://marc.info/?l=apache-modperl&m=119996305532711&w=2)
According to this thread, user information could be retrieved with
$r->main->user
But in my configuration, when accessing to http://localhost/test_index/,
$r->main is always undefined in the PerlResponseHandler !!!!
Please help
Thanks