proxy_connect.c revision 700e336393ed1b32cf6f5967dcacb910a22505e9
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/* CONNECT method for Apache proxy */
#include "mod_proxy.h"
#include "http_log.h"
#include "http_main.h"
#ifdef HAVE_BSTRING_H
#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
#endif
/*
* This handles Netscape CONNECT method secure proxy requests.
* A connection is opened to the specified host and data is
* passed through between the WWW site and the browser.
*
* This code is based on the INTERNET-DRAFT document
* "Tunneling SSL Through a WWW Proxy" currently at
*
* If proxyhost and proxyport are set, we send a CONNECT to
* the specified proxy..
*
* FIXME: this is bad, because it does its own socket I/O
* instead of using the I/O in buff.c. However,
* the I/O in buff.c blocks on reads, and because
* this function doesn't know how much data will
* be sent either way (or when) it can't use blocking
* I/O. This may be very implementation-specific
* (to Linux). Any suggestions?
* FIXME: this doesn't log the number of bytes sent, but
* that may be okay, since the data is supposed to
* be transparent. In fact, this doesn't log at all
* yet. 8^)
* FIXME: doesn't check any headers initally sent from the
* client.
* FIXME: should allow authentication, but hopefully the
* generic proxy authentication is good enough.
* FIXME: no check for r->assbackwards, whatever that is.
*/
static int
{
int i;
return 1;
}
return 0;
}
{
const char *host;
char *p;
int port;
char buffer[HUGE_STRING_LEN];
int nbytes, i;
/* Break the URL into host:port pairs */
if (p == NULL)
else {
*p = '\0';
}
/* check if ProxyBlock directive on this host */
return ap_proxyerror(r, HTTP_FORBIDDEN,
"Connect to remote machine blocked");
}
/* Check if it is an allowed port */
/* Default setting if not overridden by AllowCONNECT */
switch (port) {
case DEFAULT_HTTPS_PORT:
case DEFAULT_SNEWS_PORT:
break;
default:
return HTTP_FORBIDDEN;
}
return HTTP_FORBIDDEN;
if (proxyhost) {
}
else {
}
"proxy: error creating socket");
return HTTP_INTERNAL_SERVER_ERROR;
}
return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
}
/* If we are connecting through a remote proxy, we need to pass
* the CONNECT request on to it.
*/
if (proxyport) {
/* FIXME: We should not be calling write() directly, but we currently
* have no alternative. Error checking ignored. Also, we force
* a HTTP/1.0 request to keep things simple.
*/
"Sending the CONNECT request to the remote proxy");
}
else {
"Returning 200 OK Status");
ap_rflush(r);
}
{
"proxy: error apr_setup_poll()");
return HTTP_INTERNAL_SERVER_ERROR;
}
/* Add client side to the poll */
#if 0
/* FIXME !!!! SDM !!! If someone can figure out how to turn a conn_rec into a ap_sock_t or something
this code might work. However if we must we can change r->connection->client to non-blocking and
just see if a recv gives us anything and do the same to sock (server) side, I'll leave this as TBD so
one can decide the best path to take
*/
r->pool) != APR_SUCCESS)
{
"proxy: error creating client apr_socket_t");
return HTTP_INTERNAL_SERVER_ERROR;
}
#endif
/* Add the server side to the poll */
while (1) { /* Infinite loop until error (one side closes the connection) */
{
return HTTP_INTERNAL_SERVER_ERROR;
}
"Woke from select(), i=%d", pollcnt);
if (pollcnt) {
if (pollevent & APR_POLLIN) {
"sock was set");
int o = 0;
while(nbytes)
{
i = nbytes;
o += i;
nbytes -= i;
}
}
else
break;
}
if (pollevent & APR_POLLIN) {
"client was set");
int o = 0;
while(nbytes)
{
i = nbytes;
o += i;
nbytes -= i;
}
}
else
break;
}
}
else
break;
}
return OK;
}