File Not Found / DirectoryIndex Problem / mod_dir conflict etc. Explanation and Solution (not the best...)

"Bryan Ross" <[email protected]> Wed, 29 Oct 2003 11:21:21 -0000
Newsgroups gmane.comp.apache.mod-backhand.general
Organization LiquidState
Message-ID <[email protected]>
Hey there,
 
Sent an email to the list which appeared on the web and in my inbox, but
then strangely disappeared (deleted??). Anyway, we've been looking at a
problem where-by mod_backhand doesn't seem to play nice with DirectoryIndex,
and gives strange File Not Found messages.
 
Here's our progress (and temporary solution). All credits to Gavin for
tracking this down.
 
Bryan.


  _____  

From: Gavin Brown 
Sent: Wednesday, October 29, 2003 11:02 AM
To:  Bryan Ross
Subject: File Not Found / DirectoryIndex Problem / mod_dir conflict etc.
Explanation and Solution (not the best...)

Ok like a lot of people I have been experiencing the whole "File Not Found"
problem when using mod_backhand trying to access directoryIndex files.
 
I decided to take a look at the code to see why its not working and who was
complaining about what.
 
This is basically what happens (well as I understand it, my knowledge of
apache module traversing is not the best ;)
 
If you don't want to read all this and just want to know the fix just skip
to the bottom :)
 
Request comes in for say "/mydir/".
This doesn't contain a file name so Mod_dir intercepts this and starts
looking for files that match the DirectoryIndex list.
So on my box it looks for "index.cgi"
It does this by making a 'fake' request to apache
 
    request_rec *rr = ap_sub_req_lookup_uri(name_ptr, r); 
 
I'm not entirely sure what this is , it seems to be a full blown request but
internally (does this go through mod_backhand? Theo?)
So on my box its something like "/mydir/index.cgi", this succeeds.
 
    if (rr->status == HTTP_OK && S_ISREG(rr->finfo.st_mode)) {
       char *new_uri = ap_escape_uri(r->pool, rr->uri);
 
So mod_dir then recreates its new uri from the 'fake' request rather than
just building it it's self (does any one know why it would need to do this,
possibly because another module along the way might have played with it to
make that request successful? But surely if it does the same request as the
fake request it will succeed?)
      
      ap_destroy_sub_req(rr);
 
Destroys the sub request it just did
 
     ap_internal_redirect(new_uri, r);
 
Then does an internal redirect to the new uri, this is where the
mod_backhand problem comes in.
Although the 'fake' request succeeded, mod backhand played with the uri for
that request.
So instead of
  rr->uri = "/mydir/index.cgi" 
It has
  rr->uri = "backhand: /mydir/index.cgi"
Which is not a proper uri so when apache finally tries to access the file,
in my case its mod_cgi that tries, apache can't read the file and fails.
However the prepended "backhand:" seems to effect the way apache tries to
access the file, and it seems to try and access the files in the root dir,
as some folk have reported (bad!)
 
So to fix the problem....
Easy One ...ish (if you are compiling apache your self):
  Patch mod_dir to remove the prepended "backhand:" before the
internal_redirect is done.
  I can give the code if any one wants.
Harder One
  Change backhand not to prepend "backhand:" when it does need to (when does
it need to and when does it not? I'm still working on that bit)
 
I'll keep you posted on how I get on.