summaryrefslogtreecommitdiffstats
path: root/usr.sbin/httpd/src/modules/proxy/proxy_connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/httpd/src/modules/proxy/proxy_connect.c')
-rw-r--r--usr.sbin/httpd/src/modules/proxy/proxy_connect.c119
1 files changed, 61 insertions, 58 deletions
diff --git a/usr.sbin/httpd/src/modules/proxy/proxy_connect.c b/usr.sbin/httpd/src/modules/proxy/proxy_connect.c
index 4870e009088..9b955d51776 100644
--- a/usr.sbin/httpd/src/modules/proxy/proxy_connect.c
+++ b/usr.sbin/httpd/src/modules/proxy/proxy_connect.c
@@ -66,7 +66,7 @@
#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.
@@ -75,8 +75,8 @@
* "Tunneling SSL Through a WWW Proxy" currently at
* http://www.mcom.com/newsref/std/tunneling_ssl.html.
*
- * If proxyhost and proxyport are set, we send a CONNECT to
- * the specified proxy..
+ * 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,
@@ -96,14 +96,13 @@
* FIXME: no check for r->assbackwards, whatever that is.
*/
-static int
-allowed_port(proxy_server_conf *conf, int port)
+static int allowed_port(proxy_server_conf *conf, int port)
{
int i;
- int *list = (int *) conf->allowed_connect_ports->elts;
+ int *list = (int *)conf->allowed_connect_ports->elts;
- for(i = 0; i < conf->allowed_connect_ports->nelts; i++) {
- if(port == list[i])
+ for (i = 0; i < conf->allowed_connect_ports->nelts; i++) {
+ if (port == list[i])
return 1;
}
return 0;
@@ -111,7 +110,7 @@ allowed_port(proxy_server_conf *conf, int port)
int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
- const char *proxyhost, int proxyport)
+ const char *proxyhost, int proxyport)
{
struct sockaddr_in server;
struct in_addr destaddr;
@@ -125,8 +124,8 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
void *sconf = r->server->module_config;
proxy_server_conf *conf =
- (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
- struct noproxy_entry *npent = (struct noproxy_entry *)conf->noproxies->elts;
+ (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
+ struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
memset(&server, '\0', sizeof(server));
server.sin_family = AF_INET;
@@ -156,22 +155,23 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
if (conf->allowed_connect_ports->nelts == 0) {
/* Default setting if not overridden by AllowCONNECT */
switch (port) {
- case DEFAULT_HTTPS_PORT:
- case DEFAULT_SNEWS_PORT:
- break;
- default:
- return HTTP_FORBIDDEN;
+ case DEFAULT_HTTPS_PORT:
+ case DEFAULT_SNEWS_PORT:
+ break;
+ default:
+ return HTTP_FORBIDDEN;
}
- } else if(!allowed_port(conf, port))
+ }
+ else if (!allowed_port(conf, port))
return HTTP_FORBIDDEN;
if (proxyhost) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
}
else {
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "CONNECT to %s on port %d", host, port);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "CONNECT to %s on port %d", host, port);
}
/* Nasty cast to work around broken terniary expressions on MSVC */
@@ -180,7 +180,7 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
if (err != NULL)
return ap_proxyerror(r,
- proxyhost ? HTTP_BAD_GATEWAY : HTTP_INTERNAL_SERVER_ERROR, err);
+ proxyhost ? HTTP_BAD_GATEWAY : HTTP_INTERNAL_SERVER_ERROR, err);
sock = ap_psocket(r->pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == -1) {
@@ -190,11 +190,11 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
#ifdef CHECK_FD_SETSIZE
if (sock >= FD_SETSIZE) {
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
- "proxy_connect_handler: filedescriptor (%u) "
- "larger than FD_SETSIZE (%u) "
- "found, you probably need to rebuild Apache with a "
- "larger FD_SETSIZE", sock, FD_SETSIZE);
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_WARNING, NULL,
+ "proxy_connect_handler: filedescriptor (%u) "
+ "larger than FD_SETSIZE (%u) "
+ "found, you probably need to rebuild Apache with a "
+ "larger FD_SETSIZE", sock, FD_SETSIZE);
ap_pclosesocket(r->pool, sock);
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -212,73 +212,76 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
if (i == -1) {
ap_pclosesocket(r->pool, sock);
return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, ap_pstrcat(r->pool,
- "Could not connect to remote machine:<br>", strerror(errno), NULL));
+ "Could not connect to remote machine:<br>", strerror(errno), NULL));
}
- /* If we are connecting through a remote proxy, we need to pass
- * the CONNECT request on to it.
+ /*
+ * 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.
+ /*
+ * 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.
*/
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "Sending the CONNECT request to the remote proxy");
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "Sending the CONNECT request to the remote proxy");
ap_snprintf(buffer, sizeof(buffer), "CONNECT %s HTTP/1.0" CRLF, r->uri);
- send(sock, buffer, strlen(buffer),0);
+ send(sock, buffer, strlen(buffer), 0);
ap_snprintf(buffer, sizeof(buffer),
- "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
- send(sock, buffer, strlen(buffer),0);
+ "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
+ send(sock, buffer, strlen(buffer), 0);
}
else {
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "Returning 200 OK Status");
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "Returning 200 OK Status");
ap_rvputs(r, "HTTP/1.0 200 Connection established" CRLF, NULL);
ap_rvputs(r, "Proxy-agent: ", ap_get_server_version(), CRLF CRLF, NULL);
ap_bflush(r->connection->client);
}
- while (1) { /* Infinite loop until error (one side closes the connection) */
+ while (1) { /* Infinite loop until error (one side closes
+ * the connection) */
FD_ZERO(&fds);
FD_SET(sock, &fds);
FD_SET(ap_bfileno(r->connection->client, B_WR), &fds);
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "Going to sleep (select)");
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "Going to sleep (select)");
i = ap_select((ap_bfileno(r->connection->client, B_WR) > sock ?
- ap_bfileno(r->connection->client, B_WR) + 1 :
- sock + 1), &fds, NULL, NULL, NULL);
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "Woke from select(), i=%d", i);
+ ap_bfileno(r->connection->client, B_WR) + 1 :
+ sock + 1), &fds, NULL, NULL, NULL);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "Woke from select(), i=%d", i);
if (i) {
if (FD_ISSET(sock, &fds)) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "sock was set");
- if ((nbytes = recv(sock, buffer, HUGE_STRING_LEN,0)) != 0) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "sock was set");
+ if ((nbytes = recv(sock, buffer, HUGE_STRING_LEN, 0)) != 0) {
if (nbytes == -1)
break;
if (send(ap_bfileno(r->connection->client, B_WR), buffer,
- nbytes,0) == EOF)
+ nbytes, 0) == EOF)
break;
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO,
- r->server, "Wrote %d bytes to client", nbytes);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO,
+ r->server, "Wrote %d bytes to client", nbytes);
}
else
break;
}
else if (FD_ISSET(ap_bfileno(r->connection->client, B_WR), &fds)) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
- "client->fd was set");
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+ "client->fd was set");
if ((nbytes = recv(ap_bfileno(r->connection->client, B_WR),
- buffer, HUGE_STRING_LEN, 0)) != 0) {
+ buffer, HUGE_STRING_LEN, 0)) != 0) {
if (nbytes == -1)
break;
if (send(sock, buffer, nbytes, 0) == EOF)
break;
- ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO,
- r->server, "Wrote %d bytes to server", nbytes);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO,
+ r->server, "Wrote %d bytes to server", nbytes);
}
else
break;