You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ben Laurie <be...@algroup.co.uk> on 1997/08/31 17:23:32 UTC

Auth failure in Win32

I've tracked it down to this bit of code (http_request.c, line 384):

	    if (entry_core->r
		|| entry_dir[0] != '/'
		|| entry_core->d_components > i) break;

What is the purpose of the entry_dir[0] != '/' test? Dean introduced
this in 1.70, BTW (or so it seems).

Eliminating it makes auth work on Win32. But note:

<Directory />
.
.
.
</Directory>

doesn't do the trick, you have to use:

<Directory c:/>
.
.
.
</Directory>

Sigh. We should probably flag <Directory /> as a config error.

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 994 6435|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 994 6472|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Re: Auth failure in Win32

Posted by Alexei Kosut <ak...@organic.com>.
On Mon, 1 Sep 1997, Ben Laurie wrote:

> I don't see why we should try to make it work. Just accept that
> pathnames on Win32 look like <drive>:/<path>. It's the way it is. You
> don't expect Apache to warn you that <DirectoryMatch ^x$> is a stupid
> thing to do, so why expect it to warn about <DirectoryMatch ^/$>?
> 
> I admit I'm reversing my previous position :-)

Yes, well... okay. But pathnames on Win32 don't always look like
<drive>:/<path>, where <drive> and <path> are lowercase strings. In fact,
the Windows tools nearly always use uppercase drive letters. I agree that
it's fine to use lowercase representations internally, but I don't think
we should just say "oh, all <Directory> entries have to be lowercase, and
with lowercase drive letters," and expect people to do so. Especially
since no other Windows program does, and even the DirectoryRoot and Alias
and such functions do not (Apache will expand it out after translating
the URL).

So I think a patch like this one is appropriate:

Index: main/http_core.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_core.c,v
retrieving revision 1.118
diff -u -r1.118 http_core.c
--- http_core.c	1997/09/02 16:12:08	1.118
+++ http_core.c	1997/09/03 23:46:25
@@ -753,6 +753,16 @@
     return NULL;
 }
 
+/* We use this in <DirectoryMatch> and <FilesMatch>, to ensure that 
+ * people don't get bitten by wrong-cased regex matches
+ */
+
+#ifdef WIN32
+#define USE_ICASE REG_ICASE
+#else
+#define USE_ICASE 0
+#endif
+
 static const char end_dir_magic[] = "</Directory> outside of any <Directory> section";
 
 const char *end_dirsection (cmd_parms *cmd, void *dummy) {
@@ -782,11 +792,15 @@
     cmd->override = OR_ALL|ACCESS_CONF;
 
     if (cmd->info) { /* <DirectoryMatch> */
-	r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
+	r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
     }
     else if (!strcmp(cmd->path, "~")) {
 	cmd->path = getword_conf (cmd->pool, &arg);
-	r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
+	r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
+    }
+    else {
+	/* Ensure that the pathname is canonical */
+	cmd->path = os_canonical_filename(cmd->pool, cmd->path);
     }
 
     errmsg = srm_command_loop (cmd, new_dir_conf);
@@ -881,16 +895,21 @@
     if (cmd->info) { /* <FilesMatch> */
 	if (old_path && cmd->path[0] != '/' && cmd->path[0] != '^')
             cmd->path = pstrcat(cmd->pool, "^", old_path, cmd->path, NULL);
-        r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
+        r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
     }
     else if (!strcmp(cmd->path, "~")) {
 	cmd->path = getword_conf (cmd->pool, &arg);
 	if (old_path && cmd->path[0] != '/' && cmd->path[0] != '^')
 	    cmd->path = pstrcat(cmd->pool, "^", old_path, cmd->path, NULL);
-	r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
+	r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
+    }
+    else {
+	if (old_path && cmd->path[0] != '/')
+	    cmd->path = pstrcat(cmd->pool, old_path, cmd->path, NULL);
+
+	/* Ensure that the pathname is canonical */
+	cmd->path = os_canonical_filename(cmd->pool, cmd->path);
     }
-    else if (old_path && cmd->path[0] != '/')
-	cmd->path = pstrcat(cmd->pool, old_path, cmd->path, NULL);
 
     errmsg = srm_command_loop (cmd, new_file_conf);
     if (errmsg != end_file_magic) return errmsg;


-- Alexei Kosut <ak...@organic.com>


Re: Auth failure in Win32

Posted by Ben Laurie <be...@algroup.co.uk>.
Alexei Kosut wrote:
> 
> On Sun, 31 Aug 1997, Ben Laurie wrote:
> 
> > <Directory />
> 
> [...]
> 
> > doesn't do the trick, you have to use:
> >
> > <Directory c:/>
> 
> [...]
> 
> > Sigh. We should probably flag <Directory /> as a config error.
> 
> That's right... I knew there was another reason we should be calling
> os_canonical_filename() on <Directory> and <Files> arguments. Though I
> wish someone could explain to me how we can make
> <DirectoryMatch ^/$> work, or flag it as a config error.

I don't see why we should try to make it work. Just accept that
pathnames on Win32 look like <drive>:/<path>. It's the way it is. You
don't expect Apache to warn you that <DirectoryMatch ^x$> is a stupid
thing to do, so why expect it to warn about <DirectoryMatch ^/$>?

I admit I'm reversing my previous position :-)

Cheers,

Ben.

-- 
Ben Laurie            |Phone: +44 (181) 994 6435|Apache Group member
Freelance Consultant  |Fax:   +44 (181) 994 6472|http://www.apache.org
and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache

Re: Auth failure in Win32

Posted by Alexei Kosut <ak...@organic.com>.
On Sun, 31 Aug 1997, Ben Laurie wrote:

> <Directory />

[...]

> doesn't do the trick, you have to use:
> 
> <Directory c:/>

[...]

> Sigh. We should probably flag <Directory /> as a config error.

That's right... I knew there was another reason we should be calling
os_canonical_filename() on <Directory> and <Files> arguments. Though I
wish someone could explain to me how we can make
<DirectoryMatch ^/$> work, or flag it as a config error.

-- Alexei Kosut <ak...@organic.com>


Re: Auth failure in Win32

Posted by Dean Gaudet <dg...@arctic.org>.
On Sun, 31 Aug 1997, Ben Laurie wrote:

> I've tracked it down to this bit of code (http_request.c, line 384):
> 
> 	    if (entry_core->r
> 		|| entry_dir[0] != '/'
> 		|| entry_core->d_components > i) break;
> 
> What is the purpose of the entry_dir[0] != '/' test? Dean introduced
> this in 1.70, BTW (or so it seems).

This is a somewhat obscure thing that existed before my work in 1.70... 
but it seems I did goof.

If the directory name does not start with a '/' then it is considered
"special" (consider <Directory proxy:*>) and is dealt with entirely
differently.  This is legacy crud, since proxy:* is really better off
done in location_walk rather than directory_walk.

My goof is that I didn't bother thinking about OS2/WIN32 drive letters.
You need to fix it here, and in the core_reorder_directories function in
http_core.c.  You'll also find more docs about this stuff in http_core.c.

Dean