Mailing List Archive

File Not Found / DirectoryIndex Problem / mod_dir conflict etc. Explanation and Solution (not the best...)
This is a multi-part message in MIME format.

------=_NextPart_000_0105_01C39E0E.C86A5B50
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

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.


------=_NextPart_000_0105_01C39E0E.C86A5B50
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<META content=3D"MSHTML 6.00.2800.1264" name=3DGENERATOR></HEAD>
<BODY>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003>Hey there,</SPAN></FONT></DIV>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003>Sent an email to the list which appeared on =
the web and=20
in my inbox, but then strangely disappeared (deleted??). Anyway, we've =
been=20
looking at a problem where-by mod_backhand doesn't seem to play nice =
with=20
DirectoryIndex, and gives strange File Not Found =
messages.</SPAN></FONT></DIV>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003>Here's our progress&nbsp;(and&nbsp;temporary =
solution).=20
All credits to Gavin for tracking this down.</SPAN></FONT></DIV>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D946041811-29102003>Bryan.</SPAN></FONT></DIV><FONT face=3DArial=20
color=3D#0000ff size=3D2></FONT><BR>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr align=3Dleft>
<HR tabIndex=3D-1>
</DIV>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr =
align=3Dleft><FONT=20
face=3DTahoma><FONT size=3D2><B>From:</B> Gavin Brown<SPAN=20
class=3D946041811-29102003><FONT face=3DArial=20
color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr =
align=3Dleft><FONT=20
face=3DTahoma><FONT size=3D2><B>Sent:</B> Wednesday, October 29, 2003 =
11:02=20
AM<BR><B>To:</B>&nbsp;<SPAN class=3D946041811-29102003><FONT =
face=3DArial=20
color=3D#0000ff>&nbsp;<FONT face=3DTahoma color=3D#000000>Bryan=20
Ross</FONT></FONT></SPAN></FONT></FONT></DIV>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr =
align=3Dleft><FONT=20
face=3DTahoma><FONT size=3D2><SPAN =
class=3D946041811-29102003></SPAN><B>Subject:</B>=20
File Not Found / DirectoryIndex Problem / mod_dir conflict etc. =
Explanation and=20
Solution (not the best...)<BR></FONT></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>Ok =
like a lot of=20
people I have been experiencing the whole "File Not Found" problem when =
using=20
mod_backhand trying to access directoryIndex files.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>I =
decided to take a=20
look at the code to see why its not working and who was complaining =
about=20
what.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>This =
is basically=20
what happens (well as I understand it, my knowledge of apache module =
traversing=20
is not the best ;)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>If you =
don't want to=20
read all this and just want to know the fix just skip to the bottom=20
:)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>Request comes in for=20
say "/mydir/".</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>This =
doesn't contain=20
a file name so </SPAN></FONT><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>Mod_dir intercepts this and starts looking =
for files=20
that match the DirectoryIndex list.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>So on =
my box it=20
looks for "index.cgi"</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>It =
does this by=20
making a 'fake' request to apache</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>&nbsp;&nbsp;=20
&nbsp;request_rec *rr =3D ap_sub_req_lookup_uri(name_ptr, r); =
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>I'm =
not entirely=20
sure what this is , it seems to be a full blown request but internally =
(does=20
this go through mod_backhand? Theo?)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003><SPAN=20
class=3D127163009-29102003>So on my box its something=20
like&nbsp;"/mydir/index.cgi", this succeeds.</SPAN></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>&nbsp;&nbsp;&nbsp;=20
if (rr-&gt;status =3D=3D HTTP_OK &amp;&amp; =
S_ISREG(rr-&gt;finfo.st_mode))=20
{</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char =
*new_uri =3D=20
ap_escape_uri(r-&gt;pool, rr-&gt;uri);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>So =
mod_dir then=20
recreates its new uri from the 'fake' request rather than&nbsp;just =
building it=20
it's self (does any one know why it would need to do this, possibly =
because=20
another module along the way might have played with it to make that =
request=20
successful? But surely if it does the same request as the fake request =
it will=20
succeed?)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
ap_destroy_sub_req(rr);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>Destroys the sub=20
request it just did</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>&nbsp;&nbsp;&nbsp;&nbsp; =
ap_internal_redirect(new_uri,=20
r);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>Then =
does an=20
internal redirect to the new uri, this is where the mod_backhand problem =
comes=20
in.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>Although the 'fake'=20
request succeeded, mod backhand played with the uri for that=20
request.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>So =
instead=20
of</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>&nbsp;&nbsp;rr-&gt;uri =3D "/mydir/index.cgi" =

</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>It=20
has</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003>&nbsp;&nbsp;rr-&gt;uri =3D "backhand:=20
/mydir/index.cgi"</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>Which =
is not a=20
proper uri so when apache finally tries to access the file, in my case =
its=20
mod_cgi that tries, apache can't read the file and =
fails.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>However the=20
prepended "backhand:" seems to effect the way apache tries to access the =
file,=20
and it seems to try and access the files in the root dir, as some folk =
have=20
reported (bad!)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>So to =
fix the=20
problem....</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>Easy =
One ...ish (if=20
you are compiling apache your self):</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>&nbsp; =
Patch mod_dir=20
to remove the prepended "backhand:" before the internal_redirect is=20
done.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>&nbsp; =
I can give=20
the code if any one wants.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D127163009-29102003>Harder =

One</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003>&nbsp;&nbsp;Change=20
backhand not to prepend "backhand:" when it does need to (when does it =
need to=20
and when does it not? I'm still working on that bit)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D127163009-29102003></SPAN></FONT><FONT face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D127163009-29102003>I'll keep you posted on how I =
get=20
on.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D127163009-29102003></SPAN></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0105_01C39E0E.C86A5B50--