proxy_util.c revision a792dc2db8e08bd65be6ac844a1fdb001a456b1a
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * Unless required by applicable law or agreed to in writing, software
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * distributed under the License is distributed on an "AS IS" BASIS,
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * See the License for the specific language governing permissions and
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * limitations under the License.
3568de757bac0b47256647504c186d17ca272f85rbb/* Utility routines for Apache proxy */
3568de757bac0b47256647504c186d17ca272f85rbb#include "apr_support.h" /* for apr_wait_for_io_or_timeout() */
3568de757bac0b47256647504c186d17ca272f85rbb * Opaque structure containing target server info when
3568de757bac0b47256647504c186d17ca272f85rbb * using a forward proxy.
3568de757bac0b47256647504c186d17ca272f85rbb * Up to now only used in combination with HTTP CONNECT.
3568de757bac0b47256647504c186d17ca272f85rbbtypedef struct {
3568de757bac0b47256647504c186d17ca272f85rbb int use_http_connect; /* Use SSL Tunneling via HTTP CONNECT */
3568de757bac0b47256647504c186d17ca272f85rbb/* Keep synced with mod_proxy.h! */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic struct wstat {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unsigned int bit;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *name;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick {PROXY_WORKER_INITIALIZED, PROXY_WORKER_INITIALIZED_FLAG, "Init "},
3568de757bac0b47256647504c186d17ca272f85rbb {PROXY_WORKER_IGNORE_ERRORS, PROXY_WORKER_IGNORE_ERRORS_FLAG, "Ign "},
3568de757bac0b47256647504c186d17ca272f85rbb {PROXY_WORKER_IN_SHUTDOWN, PROXY_WORKER_IN_SHUTDOWN_FLAG, "Shut "},
3568de757bac0b47256647504c186d17ca272f85rbb {PROXY_WORKER_DISABLED, PROXY_WORKER_DISABLED_FLAG, "Dis "},
98fb535f829e2a95aabd82420931f476661fa8e3jorton {PROXY_WORKER_STOPPED, PROXY_WORKER_STOPPED_FLAG, "Stop "},
db12cd62083041bf90945eeb90cc40fbd2340797trawick {PROXY_WORKER_IN_ERROR, PROXY_WORKER_IN_ERROR_FLAG, "Err "},
db12cd62083041bf90945eeb90cc40fbd2340797trawick {PROXY_WORKER_HOT_STANDBY, PROXY_WORKER_HOT_STANDBY_FLAG, "Stby "},
db12cd62083041bf90945eeb90cc40fbd2340797trawick {PROXY_WORKER_FREE, PROXY_WORKER_FREE_FLAG, "Free "},
3568de757bac0b47256647504c186d17ca272f85rbb/* Global balancer counter */
3568de757bac0b47256647504c186d17ca272f85rbbstatic int lb_workers_limit = 0;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzconst apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzconst apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain;
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbbstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r);
3d96ee83babeec32482c9082c9426340cee8c44dwroweAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, create_req,
98fb535f829e2a95aabd82420931f476661fa8e3jortonPROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick /* special case handling */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick /* XXX: APR_ENOSPACE would be better */
3568de757bac0b47256647504c186d17ca272f85rbb/* already called in the knowledge that the characters are hex digits */
3568de757bac0b47256647504c186d17ca272f85rbb int ch = x[0];
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#else /*APR_CHARSET_EBCDIC*/
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * we assume that the hex value refers to an ASCII character
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * so convert to EBCDIC so that it makes sense locally;
3568de757bac0b47256647504c186d17ca272f85rbb * client specifies %20 in URL to refer to a space char;
3568de757bac0b47256647504c186d17ca272f85rbb * at this point we're called with EBCDIC "20"; after turning
3568de757bac0b47256647504c186d17ca272f85rbb * EBCDIC "20" into binary 0x20, we then need to assume that 0x20
3568de757bac0b47256647504c186d17ca272f85rbb * represents an ASCII char and convert 0x20 to EBCDIC, yielding
3568de757bac0b47256647504c186d17ca272f85rbb return buf[0];
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#endif /*APR_CHARSET_EBCDIC*/
397df70abe0bdd78a84fb6c38c02641bcfeadceasf x[0] = '%';
397df70abe0bdd78a84fb6c38c02641bcfeadceasf if (i >= 10) {
78ae889ffe0fdfab72f56c6993b0f302cb48da55rbb if (i >= 10) {
41634f717c623556a16b27b25d7d909a66fe20f8wrowe#else /*APR_CHARSET_EBCDIC*/
3568de757bac0b47256647504c186d17ca272f85rbb x[0] = '%';
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin#endif /*APR_CHARSET_EBCDIC*/
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * canonicalise a URL-encoded string
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * Convert a URL-encoded string to canonical form.
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * It decodes characters which need not be encoded,
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * and encodes those which must be encoded, and does not touch
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * those which must not be touched.
dd028aa8111afb6534fece555e8c2d408894671etrawickPROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len,
6653a33e820463abd4f81915b7a1eba0f602e200brianp int i, j, ch;
6653a33e820463abd4f81915b7a1eba0f602e200brianp char *allowed; /* characters which should not be encoded */
6653a33e820463abd4f81915b7a1eba0f602e200brianp char *reserved; /* characters which much not be en/de-coded */
6653a33e820463abd4f81915b7a1eba0f602e200brianp * N.B. in addition to :@&=, this allows ';' in an http path
6653a33e820463abd4f81915b7a1eba0f602e200brianp * and '?' in an ftp path -- this may be revised
6653a33e820463abd4f81915b7a1eba0f602e200brianp * Also, it makes a '+' character in a search string reserved, as
6653a33e820463abd4f81915b7a1eba0f602e200brianp * it may be form-encoded. (Although RFC 1738 doesn't allow this -
6653a33e820463abd4f81915b7a1eba0f602e200brianp * it only permits ; / ? : @ = & as reserved chars.)
239f998fbee5ac5b114b965bb76e217cce0003edstoddard else if (t == enc_search) {
3568de757bac0b47256647504c186d17ca272f85rbb else if (t == enc_user) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard else if (t == enc_fpath) {
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb else { /* if (t == enc_parm) */
3568de757bac0b47256647504c186d17ca272f85rbb else if (t == enc_search) {
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem for (i = 0, j = 0; i < len; i++, j++) {
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/* always handle '/' first */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem * decode it if not already done. do not decode reverse proxied URLs
83a5021aef5ebb67395b93f75df4fd0f0b4fc8c8fuankg * unless specifically forced
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem if ((forcedec || (proxyreq && proxyreq != PROXYREQ_REVERSE)) && ch == '%') {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (!apr_isxdigit(x[i + 1]) || !apr_isxdigit(x[i + 2])) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (ch != 0 && strchr(reserved, ch)) { /* keep it encoded */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* recode it, if necessary */
98cd3186185bb28ae6c95a3f159899fcf56a663ftrawick y[j] = '\0';
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * Parses network-location.
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * urlp on input the URL; on output the path, after the leading /
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * user NULL if no user/password permitted
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * password holder for password
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * host holder for host
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * port port number; only set if one is supplied.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * Returns an error string.
3cbd177a6c885562f9ad0cf11695f044489c881dgregames ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames return "Malformed URL";
7cd5419264796cfeaf8215383cf0f89130a81fectrawick /* find _last_ '@' since it might occur in user/password part */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick/* find password */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick password = ap_proxy_canonenc(p, strp + 1, strlen(strp + 1), enc_user, 1, 0);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick return "Bad %-escape in URL (password)";
7cd5419264796cfeaf8215383cf0f89130a81fectrawick user = ap_proxy_canonenc(p, user, strlen(user), enc_user, 1, 0);
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard return "Bad %-escape in URL (username)";
3568de757bac0b47256647504c186d17ca272f85rbb * Parse the host string to separate host portion from optional port.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * Perform range checking on port.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick rv = apr_parse_addr_port(&addr, &scope_id, &tmp_port, host, p);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if (rv != APR_SUCCESS || addr == NULL || scope_id != NULL) {
7cd5419264796cfeaf8215383cf0f89130a81fectrawick return "Invalid host/port";
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (tmp_port != 0) { /* only update caller's port if port was specified */
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp ap_str_tolower(addr); /* DNS names are case-insensitive */
b5ffe4f30780fb159db08bd9f628980d2a092711sfPROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "The proxy server could not handle the request <em><a href=\"",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard uri, "\">", ap_escape_html(r->pool, r->method), " ", uri,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "</a></em>.<p>\n"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "Reason: <strong>", ap_escape_html(r->pool, message),
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "</strong></p>",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* Allow "error-notes" string to be printed by ap_send_error_response() */
dd028aa8111afb6534fece555e8c2d408894671etrawick r->status_line = apr_psprintf(r->pool, "%3.3u Proxy Error", statuscode);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00898) "%s returned by %s", message,
3568de757bac0b47256647504c186d17ca272f85rbbstatic const char *
f714f1a7002928d785e53e70349700a7f595fee3trawick char *url, *user = NULL, *password = NULL, *err, *host = NULL;
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh /* Set url to the first char after "scheme://" */
3568de757bac0b47256647504c186d17ca272f85rbb if ((url = strchr(r->uri, ':')) == NULL || url[1] != '/' || url[2] != '/') {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard url = apr_pstrdup(r->pool, &url[1]); /* make it point to "//", which is what proxy_canon_netloc expects */
3568de757bac0b47256647504c186d17ca272f85rbb err = ap_proxy_canon_netloc(r->pool, &url, &user, &password, &host, &port);
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00899) "%s", err);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return host; /* ought to return the port, too */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* Return TRUE if addr represents an IP address (or an IP network address) */
3568de757bac0b47256647504c186d17ca272f85rbbPROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p)
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh * if the address is given with an explicit netmask, use that
3568de757bac0b47256647504c186d17ca272f85rbb * Due to a deficiency in apr_inet_addr(), it is impossible to parse
3568de757bac0b47256647504c186d17ca272f85rbb * "partial" addresses (with less than 4 quads) correctly, i.e.
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim * 192.168.123 is parsed as 192.168.0.123, which is not what I want.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * I therefore have to parse the IP address manually:
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr) == 0)
3568de757bac0b47256647504c186d17ca272f85rbb * addr and mask were set by proxy_readmask()
3568de757bac0b47256647504c186d17ca272f85rbb * Parse IP addr manually, optionally allowing
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * abbreviated net addresses like 192.168.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* Iterate over up to 4 (dotted) quads. */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (quads = 0; quads < 4 && *addr != '\0'; ++quads) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (*addr == '/' && quads > 0) { /* netmask starts here. */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return 0; /* no digit at start of quad */
3568de757bac0b47256647504c186d17ca272f85rbb if (tmp == addr) { /* expected a digit, found something else */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick /* invalid octet */
beb70d51e435dc36c56a72b6cd83556c04db9283wrowe ++addr; /* after the 4th quad, a dot would be illegal */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (This->addr.s_addr = 0, i = 0; i < quads; ++i) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (addr[0] == '/' && apr_isdigit(addr[1])) { /* net mask follows: */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (tmp == addr) { /* expected a digit, found something else */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (bits < 0 || bits > 32) { /* netmask must be between 0 and 32 */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * Determine (i.e., "guess") netmask by counting the
3568de757bac0b47256647504c186d17ca272f85rbb * number of trailing .0's; reduce #quads appropriately
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * (so that 192.168.0.0 is equivalent to 192.168.)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* "IP Address should be given in dotted-quad form, optionally followed by a netmask (e.g., 192.168.111.0/24)"; */
3568de757bac0b47256647504c186d17ca272f85rbb /* every zero-byte counts as 8 zero-bits */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (bits != 32) { /* no warning for fully qualified IP address */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00900)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "Warning: NetMask not supplied with IP-Addr; guessing: %s/%ld",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick This->mask.s_addr = htonl(APR_INADDR_NONE << (32 - bits));
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (*addr == '\0' && (This->addr.s_addr & ~This->mask.s_addr) != 0) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00901)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "Warning: NetMask and IP-Addr disagree in %s/%ld",
f886987cd0bd4220c14043c4d9be77ec22902e73trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00902)
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick return (*addr == '\0'); /* okay iff we've parsed the whole string */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick/* Return TRUE if addr represents an IP address (or an IP network address) */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawickstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (4 == sscanf(host, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1], &ip_addr[2], &ip_addr[3])) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* ap_proxy_is_ipaddr() already confirmed that we have
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * a valid octet in ip_addr[i]
36c8049de63c446926139936c3d195330a0539cetrawick if (This->addr.s_addr == (addr.s_addr & This->mask.s_addr)) {
36c8049de63c446926139936c3d195330a0539cetrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00903)
36c8049de63c446926139936c3d195330a0539cetrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00904)
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00905)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00906)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "1)IP-NoMatch: %s[%s] <-> ", host, inet_ntoa(addr));
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00907)
36c8049de63c446926139936c3d195330a0539cetrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00908)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (apr_sockaddr_info_get(&reqaddr, host, APR_UNSPEC, 0, 0, r->pool)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00909)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "2)IP-NoMatch: hostname=%s msg=Host not found", host);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* Try to deal with multiple IP addr's for a host */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* FIXME: This needs to be able to deal with IPv6 */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (This->addr.s_addr == (ip->s_addr & This->mask.s_addr)) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00910)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00911)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00912)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00913)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00914)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00915)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm/* Return TRUE if addr represents a domain name */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougmPROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p)
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp /* Domain name must start with a '.' */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick for (i = 0; apr_isalnum(addr[i]) || addr[i] == '-' || addr[i] == '.'; ++i) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "@@@@ handle optional port in proxy_is_domainname()");
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton /* @@@@ handle optional port */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* Strip trailing dots */
36c8049de63c446926139936c3d195330a0539cetrawick for (i = strlen(addr) - 1; i > 0 && addr[i] == '.'; --i) {
36c8049de63c446926139936c3d195330a0539cetrawick/* Return TRUE if host "host" is in domain "domain" */
36c8049de63c446926139936c3d195330a0539cetrawickstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (host == NULL) { /* some error was logged already */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* @@@ do this within the setup? */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* Ignore trailing dots in domain comparison: */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick && strncasecmp(&host[h_len - d_len], This->name, d_len) == 0;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* Return TRUE if host represents a host name */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickPROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* Host names must not start with a '.' */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick for (i = 0; apr_isalnum(host[i]) || host[i] == '-' || host[i] == '.'; ++i);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (host[i] != '\0' || apr_sockaddr_info_get(&addr, host, APR_UNSPEC, 0, 0, p) != APR_SUCCESS) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* Strip trailing dots */
f886987cd0bd4220c14043c4d9be77ec22902e73trawick for (i = strlen(host) - 1; i > 0 && host[i] == '.'; --i) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm/* Return TRUE if host "host" is equal to host2 "host2" */
3568de757bac0b47256647504c186d17ca272f85rbbstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r)
e8f95a682820a599fe41b22977010636be5c2717jim return 0; /* oops! */
44d2e75323651320b480d8bc2f098448a08de4fcwrowe /* Try to deal with multiple IP addr's for a host */
3568de757bac0b47256647504c186d17ca272f85rbb /* Ignore trailing dots in host2 comparison: */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe/* Return TRUE if addr is to be matched as a word */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowePROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* Return TRUE if string "str2" occurs literally in "str1" */
3568de757bac0b47256647504c186d17ca272f85rbbstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz const char *host = proxy_get_host_of_request(r);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return host != NULL && ap_strstr_c(host, This->name) != NULL;
98fb535f829e2a95aabd82420931f476661fa8e3jortonPROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf,
98fb535f829e2a95aabd82420931f476661fa8e3jorton /* XXX FIXME: conf->noproxies->elts is part of an opaque structure */
98fb535f829e2a95aabd82420931f476661fa8e3jorton struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "checking remote machine [%s] against [%s]",
3568de757bac0b47256647504c186d17ca272f85rbb if (ap_strstr_c(hostname, npent[j].name) || npent[j].name[0] == '*') {
3568de757bac0b47256647504c186d17ca272f85rbb ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00916)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "connect to remote machine %s blocked: name %s "
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe /* No IP address checks if no IP address was passed in,
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe * i.e. the forward address proxy case, where this server does
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe * not resolve the hostname. */
85c5af648e9f414bd4f157490766d2fd5515a9f5rpluem for (conf_addr = npent[j].addr; conf_addr; conf_addr = conf_addr->next) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (apr_sockaddr_ip_getbuf(caddr, sizeof caddr, conf_addr))
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz for (uri_addr = addr; uri_addr; uri_addr = uri_addr->next) {
3568de757bac0b47256647504c186d17ca272f85rbb if (apr_sockaddr_ip_getbuf(uaddr, sizeof uaddr, uri_addr))
3568de757bac0b47256647504c186d17ca272f85rbb ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00917)
ec020ca384efb30d501a5af796ddc3bb237d7b8fgregames "connect to remote machine %s blocked: "
9d0665da83d1e22c0ea0e5f6f940f70f75bf5237ianh/* set up the minimal filter set */
3568de757bac0b47256647504c186d17ca272f85rbbPROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r)
7cd5419264796cfeaf8215383cf0f89130a81fectrawickPROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * XXX FIXME: Make sure this handled the ambiguous case of the :<PORT>
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * after the hostname
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * XXX FIXME: Ensure the /uri component is a case sensitive match
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz rconf = ap_get_module_config(r->request_config, &proxy_module);
int n, l3 = 0;
if (urlpart) {
* BalancerMember balancer://alias http://example.com/foo
* translate url http://example.com/foo/bar/that to /bash/that
if (urlpart) {
--l2;
NULL);
worker++;
if (part) {
if (part) {
return url;
&proxy_module);
const char *pathp;
const char *domainp;
int ddiff = 0;
int pdiff = 0;
char *ret;
return str;
if (newpath) {
if (newdomain) {
if (newdomain) {
return ret;
const char *url,
int care)
return NULL;
return balancer;
balancer++;
return NULL;
const char *url)
if (!url) {
return NULL;
return NULL;
const char *url,
const char *alias,
int do_malloc)
const char *sname;
if (do_malloc)
&sname);
return APR_EINVAL;
if (lbmethod) {
return APR_EINVAL;
return rv;
PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balancer, server_rec *s, apr_pool_t *p)
unsigned int num;
if (!storage) {
return APR_EGENERAL;
return APR_EGENERAL;
return rv;
return APR_EGENERAL;
return rv;
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
if (conn->r) {
return APR_SUCCESS;
apr_pool_clear(p);
return APR_SUCCESS;
request_rec *r)
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
const char *url)
int max_match = 0;
int url_length;
int min_match;
int worker_name_length;
char *url_copy;
if (!url) {
return NULL;
return NULL;
char *pathstart;
if (balancer) {
return max_worker;
const char *url,
int do_malloc)
int rv;
* require format: unix:/path/foo/bar.sock|http://ignored/path2/
if (ptr) {
if (sockpath) {
* ProxyPass / http://www.example.com
if (balancer) {
} else if (conf) {
if (do_malloc)
if (sockpath) {
return NULL;
return APR_EINVAL;
if (pool) {
return APR_SUCCESS;
PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, server_rec *s, apr_pool_t *p)
int mpm_threads;
return rv;
return APR_EGENERAL;
void *conn;
return rv;
server_rec *s)
return OK;
return DECLINED;
return OK;
request_rec *r,
int access_status;
if (*worker) {
char *ptr;
char *ptr2;
return access_status;
request_rec *r,
if (balancer) {
return access_status;
const char *proxy_function,
const char *backend_name,
request_rec *r)
int connected = 0;
int loglevel;
server_rec *s)
return HTTP_SERVICE_UNAVAILABLE;
return HTTP_SERVICE_UNAVAILABLE;
return OK;
server_rec *s)
return OK;
PROXY_DECLARE(int)
char **url,
const char *proxyname,
char *server_portstr,
int server_portstr_size)
int server_port;
const char *uds_path;
NULL));
if (!proxyname) {
if (uds_path) {
if (proxyname) {
const char *proxy_auth;
if (!will_reuse) {
if (will_reuse) {
return HTTP_INTERNAL_SERVER_ERROR;
const char *ssl_hostname;
ssl_hostname) != 0)) ||
return OK;
server_rec *s)
int status;
int complete = 0;
int len = 0;
if (!complete) {
buffer);
code_str);
return(status);
/* lifted from mod_proxy_fdpass.c; tweaked addrlen in connect() call */
return rv;
return rv;
return rv;
return errno;
return APR_SUCCESS;
server_rec *s)
int connected = 0;
int loglevel;
sizeof(apr_sockaddr_t));
conn_rec *c,
server_rec *s)
int rc;
return OK;
0, NULL,
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return rc;
return OK;
int ap_proxy_lb_workers(void)
if (!lb_workers_limit)
return lb_workers_limit;
apr_bucket *e;
if (r->main)
c->bucket_alloc);
PROXY_DECLARE(unsigned int)
unsigned int hash;
return hash;
unsigned int hash;
return hash;
if (set)
return APR_SUCCESS;
pwt++;
return APR_EINVAL;
pwt++;
if (PROXY_WORKER_IS_USABLE(w))
return ret;
int index;
return APR_SUCCESS;
if (lbmethod) {
return APR_EINVAL;
int found;
return APR_EGENERAL;
found = 0;
if (!found) {
return rv;
if (b->s->need_reset) {
b->s->need_reset = 0;
return APR_SUCCESS;
unsigned int *index)
unsigned int i, limit;
for (i = 0; i < limit; i++) {
return NULL;
*index = i;
return shm;
return NULL;
unsigned int *index)
unsigned int i, limit;
for (i = 0; i < limit; i++) {
return NULL;
*index = i;
return shm;
return NULL;
typedef struct header_connection {
const char *first;
const char *name;
val++;
if (!x->first) {
const char **elt;
if (!x->array) {
} while (*val);
const char **name;
x.closed = 0;
if (x.first) {
if (x.array) {
return x.closed;
request_rec *r,
char **old_cl_val,
char **old_te_val)
int counter;
char *buf;
apr_bucket *e;
int do_100_continue;
const char *fpr1;
&& !(fpr1)
&& ap_request_has_body(r));
if (fpr1) {
if (r->expecting_100) {
return HTTP_EXPECTATION_FAILED;
if (!hostname) {
if (do_100_continue) {
const char *val;
if (!r->expecting_100) {
const char *buf;
r->useragent_ip);
proxy_run_fixups(r);
if (r->main) {
NULL);
return OK;
int flush)
if (flush) {
const char *ssl_note;
return HTTP_GATEWAY_TIME_OUT;
return HTTP_BAD_REQUEST;
return OK;
typedef struct proxy_schemes_t {
const char *name;
} proxy_schemes_t ;
if (scheme) {
return port;