You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1997/03/04 08:45:16 UTC

Re: [PATCH] VirtualHost confusion

In article <Pi...@twinlark.arctic.org> you wrote:
> On Sat, 1 Feb 1997, Marc Slemko wrote:

> >   * user and server get confused over what should be a virtual host
> >     and what is the main server, resulting in access to something
> >     other than the name defined in the virtualhost directive (but
> >     with the same IP address) failing.  
> >         Status: should be looked at, may not be a nice way to fix 
> >             since it is likely not technically a bug.

> When I put in the multiple ip support I didn't do multiple name support,
> but I put most of the code in that it needed.  I don't remember why I
> didn't do the last step... here is a patch which does that last step.  It
> treats all the names in a <VirtualHost> statement as if they were
> ServerAliased. 

> It requires a tweak to mod_rewrite.  I haven't tested this part of the
> patch.  Ralf? 

> Index: mod_rewrite.c
> ===================================================================
> RCS file: /export/home/cvs/apache/src/mod_rewrite.c,v
> retrieving revision 1.16
> diff -c -3 -r1.16 mod_rewrite.c
> *** mod_rewrite.c 1997/01/29 23:51:37 1.16
> --- mod_rewrite.c 1997/02/01 22:10:45
> ***************
> *** 2925,2930 ****
> --- 2925,2938 ----
>       }
>       else if (r->server->is_virtual) {
>           /* virtual servers */
> +     server_addr_rec *sar;
> + 
> +     /* check for the names supplied in the VirtualHost directive */
> +     for( sar = r->server->addrs; sar; sar = sar->next ) {
> +         if( !strcasecmp( sar->virthost, testhost ) ) {
> +         return YES;
> +         }
> +     }
>   
>           /* check for the virtual-server aliases */
>           if (r->server->names != NULL && r->server->names[0] != '\0') {

Sorry, -1 because 

1. the patch snippet has wrong line numbers. Seems like
   you've diffed against an old version of mod_rewrite.

2. this is really not enough:
   - VirtualHost could contain IP-adresses instead
     of names, so this case has to be taken into account, too.
   - VirtualHost could contain Host syntax with
     additional Port-number. So mod_rewrite has to take into account the
     difference between http://myhost/ and http://myhost:1234/, too.

I will investigate against this problematic cases with virtual hosts and I
will post a patch today which brings the CVS version of mod_rewrite up-todate
with my 3.0.0-SNAP (mostly comments changed for 1.2) and which also should
solve the virtual host problematic for mod_rewrite a little bit more precise.

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Re: [PATCH] VirtualHost confusion

Posted by Dean Gaudet <dg...@arctic.org>.
The patch applies cleanly against the current CVS tree, with an offset
but that's not a problem.

Matching IP addresses is not a bad thing.  This is exactly how the code
in the main server works.  If a "Host:" header contains an ip address,
then it'll match.  IMHO this is the correct behaviour.

The port number is taken care of when the <VirtualHost> is parsed.
So the server_addr_rec has the hostname in the virthost field, and the
port number in the host_port field.  But if ports are an issue with my
patch then ports are also an issue with your existing code.  I essentially
looked at how you parse the ServerAlias directive, and copied it.  That
is exactly what this patch is supposed to achieve.

As I commented when you put this matching code into mod_rewrite ages
ago it really should be a subroutine that is used both by read_request()
and your code.  Otherwise we're forever going to have to make sure both
little snippets parse things exactly the same.  And as we've discovered
many times, the snippet in the main server has subtle little bugs.

Dean

On Tue, 4 Mar 1997, Ralf S. Engelschall wrote:

> 
> In article <Pi...@twinlark.arctic.org> you wrote:
> > On Sat, 1 Feb 1997, Marc Slemko wrote:
> 
> > >   * user and server get confused over what should be a virtual host
> > >     and what is the main server, resulting in access to something
> > >     other than the name defined in the virtualhost directive (but
> > >     with the same IP address) failing.  
> > >         Status: should be looked at, may not be a nice way to fix 
> > >             since it is likely not technically a bug.
> 
> > When I put in the multiple ip support I didn't do multiple name support,
> > but I put most of the code in that it needed.  I don't remember why I
> > didn't do the last step... here is a patch which does that last step.  It
> > treats all the names in a <VirtualHost> statement as if they were
> > ServerAliased. 
> 
> > It requires a tweak to mod_rewrite.  I haven't tested this part of the
> > patch.  Ralf? 
> 
> > Index: mod_rewrite.c
> > ===================================================================
> > RCS file: /export/home/cvs/apache/src/mod_rewrite.c,v
> > retrieving revision 1.16
> > diff -c -3 -r1.16 mod_rewrite.c
> > *** mod_rewrite.c 1997/01/29 23:51:37 1.16
> > --- mod_rewrite.c 1997/02/01 22:10:45
> > ***************
> > *** 2925,2930 ****
> > --- 2925,2938 ----
> >       }
> >       else if (r->server->is_virtual) {
> >           /* virtual servers */
> > +     server_addr_rec *sar;
> > + 
> > +     /* check for the names supplied in the VirtualHost directive */
> > +     for( sar = r->server->addrs; sar; sar = sar->next ) {
> > +         if( !strcasecmp( sar->virthost, testhost ) ) {
> > +         return YES;
> > +         }
> > +     }
> >   
> >           /* check for the virtual-server aliases */
> >           if (r->server->names != NULL && r->server->names[0] != '\0') {
> 
> Sorry, -1 because 
> 
> 1. the patch snippet has wrong line numbers. Seems like
>    you've diffed against an old version of mod_rewrite.
> 
> 2. this is really not enough:
>    - VirtualHost could contain IP-adresses instead
>      of names, so this case has to be taken into account, too.
>    - VirtualHost could contain Host syntax with
>      additional Port-number. So mod_rewrite has to take into account the
>      difference between http://myhost/ and http://myhost:1234/, too.
> 
> I will investigate against this problematic cases with virtual hosts and I
> will post a patch today which brings the CVS version of mod_rewrite up-todate
> with my 3.0.0-SNAP (mostly comments changed for 1.2) and which also should
> solve the virtual host problematic for mod_rewrite a little bit more precise.
> 
> Greetings,
>                                        Ralf S. Engelschall
>                                        rse@engelschall.com
>                                        www.engelschall.com
>