[MP2]mod_perl and index.html - modperl

This is a discussion on [MP2]mod_perl and index.html - modperl ; 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 DirectoryIndex index.html Options +indexes ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: [MP2]mod_perl and index.html

  1. [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


    DirectoryIndex index.html
    Options +indexes


    PerlModule Test

    Require valid-user
    AuthType basic
    AuthName test_index
    SetHandler perl-script

    PerlAuthenHandler Apache2::AuthSSO::Test->set_user

    PerlResponseHandler Apache2::AuthSSO::Test->display_user


    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


  2. Re: [MP2]mod_perl and index.html

    2008/6/25 titetluc titetluc :

    > 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
    >
    >
    > DirectoryIndex index.html
    > Options +indexes
    >

    >
    > PerlModule Test
    >
    > Require valid-user
    > AuthType basic
    > AuthName test_index
    > SetHandler perl-script
    >
    > PerlAuthenHandler Apache2::AuthSSO::Test->set_user
    >
    > PerlResponseHandler Apache2::AuthSSO::Test->display_user
    >

    >
    > 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...6305532711&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


  3. Re: [MP2]mod_perl and index.html

    On Wed 25 Jun 2008, titetluc titetluc wrote:
    > PerlModule Test
    >
    > * * Require valid-user
    > * * AuthType basic
    > * * AuthName test_index
    > * * SetHandler perl-script
    >
    > * * PerlAuthenHandler Apache2::AuthSSO::Test->set_user
    >
    > * * PerlResponseHandler Apache2::AuthSSO::Test->display_user
    >

    >
    > 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 thatthe
    * 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


  4. Re: [MP2]mod_perl and index.html

    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


+ Reply to Thread