akosut 96/06/09 19:04:07
Modified: src http_core.c http_protocol.c http_request.c httpd.h Log: Add ServerPath directive for use with non IP-based virtual hosts and compatibility with old HTTP/1.0 clients. Cause Apache to reject (400 error response) requests that are HTTP/1.1 or later and come without a hostname. Revision Changes Path 1.17 +15 -1 apache/src/http_core.c Index: http_core.c =================================================================== RCS file: /export/home/cvs/apache/src/http_core.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C3 -r1.16 -r1.17 *** http_core.c 1996/06/08 14:01:36 1.16 --- http_core.c 1996/06/10 02:04:03 1.17 *************** *** 689,694 **** --- 689,700 ---- return NULL; } + char *set_serverpath (cmd_parms *cmd, void *dummy, char *arg) { + cmd->server->path = pstrdup (cmd->pool, arg); + cmd->server->pathlen = strlen (arg); + return NULL; + } + char *set_content_md5 (cmd_parms *cmd, core_dir_config *d, int arg) { d->content_md5 = arg; return NULL; *************** *** 822,827 **** --- 828,835 ---- { "ServerAlias", set_server_string_slot, (void *)XtOffsetOf (server_rec, names), RSRC_CONF, RAW_ARGS, "a name or names alternately used to access the server" }, + { "ServerPath", set_serverpath, NULL, RSRC_CONF, TAKE1, + "The pathname the server can be reached at" }, { "Timeout", set_timeout, NULL, RSRC_CONF, TAKE1, "timeout duration (sec)"}, { "KeepAliveTimeout", set_keep_alive_timeout, NULL, RSRC_CONF, TAKE1, "Keep-Alive timeout duration (sec)"}, { "KeepAlive", set_keep_alive, NULL, RSRC_CONF, TAKE1, "Maximum Keep-Alive requests per connection (0 to disable)" }, *************** *** 857,863 **** if (r->proxyreq) return NOT_IMPLEMENTED; if (r->uri[0] != '/') return BAD_REQUEST; ! r->filename = pstrcat (r->pool, conf->document_root, r->uri, NULL); return OK; } --- 865,877 ---- if (r->proxyreq) return NOT_IMPLEMENTED; if (r->uri[0] != '/') return BAD_REQUEST; ! if (r->server->path && ! !strncmp(r->uri, r->server->path, r->server->pathlen)) ! r->filename = pstrcat (r->pool, conf->document_root, ! (r->uri + r->server->pathlen), NULL); ! else ! r->filename = pstrcat (r->pool, conf->document_root, r->uri, NULL); ! return OK; } 1.22 +20 -0 apache/src/http_protocol.c Index: http_protocol.c =================================================================== RCS file: /export/home/cvs/apache/src/http_protocol.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C3 -r1.21 -r1.22 *** http_protocol.c 1996/06/07 20:18:59 1.21 --- http_protocol.c 1996/06/10 02:04:04 1.22 *************** *** 310,315 **** --- 310,316 ---- char l[HUGE_STRING_LEN]; char *ll = l, *uri; conn_rec *conn = r->connection; + int major = 1, minor = 0; /* Assume HTTP/1.0 if non-"HTTP" protocol*/ l[0] = '\0'; if(!getline(l, HUGE_STRING_LEN, conn->client)) *************** *** 325,330 **** --- 326,334 ---- r->assbackwards = (ll[0] == '\0'); r->protocol = ll[0] ? pstrdup (r->pool, ll) : "HTTP/0.9"; + sscanf(r->protocol, "HTTP/%d.%d", &major, &minor); + r->proto_num = 1000*major + minor; + return 1; } *************** *** 387,392 **** --- 391,410 ---- } } + void check_serverpath (request_rec *r) { + server_rec *s; + + /* This is in conjunction with the ServerPath code in + * http_core, so we get the right host attached to a non- + * Host-sending request. + */ + + for (s = r->server->next; s; s = s->next) { + if (s->path && !strncmp(r->uri, s->path, s->pathlen)) + r->server = r->connection->server = s; + } + } + request_rec *read_request (conn_rec *conn) { request_rec *r = (request_rec *)pcalloc (conn->pool, sizeof(request_rec)); *************** *** 427,432 **** --- 445,452 ---- if (r->hostname || (r->hostname = table_get(r->headers_in, "Host"))) check_hostalias(r); + else + check_serverpath(r); kill_timeout (r); conn->keptalive = 0; /* We now have a request - so no more short timeouts */ 1.8 +11 -0 apache/src/http_request.c Index: http_request.c =================================================================== RCS file: /export/home/cvs/apache/src/http_request.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C3 -r1.7 -r1.8 *** http_request.c 1996/05/22 17:35:37 1.7 --- http_request.c 1996/06/10 02:04:04 1.8 *************** *** 678,683 **** --- 678,694 ---- return; } + if (!r->hostname && (r->proto_num >= 1001)) { + /* Client sent us a HTTP/1.1 or later request without telling + * us the hostname, either with a full URL or a Host: header. + * We therefore need to (as per the 1.1 spec) send an error + */ + log_reason ("client sent HTTP/1.1 request without hostname", + r->uri, r); + die (BAD_REQUEST, r); + return; + } + if (!r->proxyreq) { access_status = unescape_url(r->uri); 1.27 +4 -0 apache/src/httpd.h Index: httpd.h =================================================================== RCS file: /export/home/cvs/apache/src/httpd.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C3 -r1.26 -r1.27 *** httpd.h 1996/06/07 20:19:00 1.26 --- httpd.h 1996/06/10 02:04:04 1.27 *************** *** 338,343 **** --- 338,344 ---- int proxyreq; /* A proxy request */ int header_only; /* HEAD request, as opposed to GET */ char *protocol; /* Protocol, as given to us, or HTTP/0.9 */ + int proto_num; /* Number version of protocol; 1.1 = 1001 */ char *hostname; /* Host, as set by full URI or Host: */ int hostlen; /* Length of http://host:port in full URI */ *************** *** 484,489 **** --- 485,493 ---- int timeout; /* Timeout, in seconds, before we give up */ int keep_alive_timeout; /* Seconds we'll wait for another request */ int keep_alive; /* Maximum requests per connection */ + + char *path; /* Pathname for ServerPath */ + int pathlen; /* Length of path */ char *names; /* Wildcarded names for HostAlias servers */ char *virthost; /* The name given in <VirtualHost> */