proxy_util.c revision cfc1ba216dbcc0af93b427d41e16717a772f09be
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 * 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! */
3568de757bac0b47256647504c186d17ca272f85rbbstatic struct wstat {
3568de757bac0b47256647504c186d17ca272f85rbb unsigned int bit;
3568de757bac0b47256647504c186d17ca272f85rbb const char *name;
3568de757bac0b47256647504c186d17ca272f85rbb {PROXY_WORKER_INITIALIZED, PROXY_WORKER_INITIALIZED_FLAG, "Init "},
3568de757bac0b47256647504c186d17ca272f85rbb {PROXY_WORKER_IGNORE_ERRORS, PROXY_WORKER_IGNORE_ERRORS_FLAG, "Ign "},
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {PROXY_WORKER_IN_SHUTDOWN, PROXY_WORKER_IN_SHUTDOWN_FLAG, "Shut "},
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {PROXY_WORKER_DISABLED, PROXY_WORKER_DISABLED_FLAG, "Dis "},
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {PROXY_WORKER_STOPPED, PROXY_WORKER_STOPPED_FLAG, "Stop "},
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {PROXY_WORKER_IN_ERROR, PROXY_WORKER_IN_ERROR_FLAG, "Err "},
3568de757bac0b47256647504c186d17ca272f85rbb {PROXY_WORKER_HOT_STANDBY, PROXY_WORKER_HOT_STANDBY_FLAG, "Stby "},
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick {PROXY_WORKER_FREE, PROXY_WORKER_FREE_FLAG, "Free "},
3568de757bac0b47256647504c186d17ca272f85rbb/* Global balancer counter */
db12cd62083041bf90945eeb90cc40fbd2340797trawickstatic int lb_workers_limit = 0;
db12cd62083041bf90945eeb90cc40fbd2340797trawickconst apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path;
db12cd62083041bf90945eeb90cc40fbd2340797trawickconst apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain;
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawickstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluemstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
3568de757bac0b47256647504c186d17ca272f85rbbstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, create_req,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzPROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src,
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb /* XXX: APR_ENOSPACE would be better */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /* XXX: Once slen and dlen are known, no excuse not to memcpy */
f0e395a55abfcad3d2bd7c63470003b08a93d567nd/* already called in the knowledge that the characters are hex digits */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick int ch = x[0];
3568de757bac0b47256647504c186d17ca272f85rbb#else /*APR_CHARSET_EBCDIC*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we assume that the hex value refers to an ASCII character
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * so convert to EBCDIC so that it makes sense locally;
3568de757bac0b47256647504c186d17ca272f85rbb * example:
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * client specifies %20 in URL to refer to a space char;
24b534291150023e6b68eca89ddd33e475ccddc0wrowe * at this point we're called with EBCDIC "20"; after turning
3568de757bac0b47256647504c186d17ca272f85rbb * EBCDIC "20" into binary 0x20, we then need to assume that 0x20
24b534291150023e6b68eca89ddd33e475ccddc0wrowe * represents an ASCII char and convert 0x20 to EBCDIC, yielding
3568de757bac0b47256647504c186d17ca272f85rbb return buf[0];
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#endif /*APR_CHARSET_EBCDIC*/
3568de757bac0b47256647504c186d17ca272f85rbb x[0] = '%';
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (i >= 10) {
3568de757bac0b47256647504c186d17ca272f85rbb if (i >= 10) {
3568de757bac0b47256647504c186d17ca272f85rbb#else /*APR_CHARSET_EBCDIC*/
3568de757bac0b47256647504c186d17ca272f85rbb x[0] = '%';
239f998fbee5ac5b114b965bb76e217cce0003edstoddard#endif /*APR_CHARSET_EBCDIC*/
6653a33e820463abd4f81915b7a1eba0f602e200brianp * canonicalise a URL-encoded string
6653a33e820463abd4f81915b7a1eba0f602e200brianp * Convert a URL-encoded string to canonical form.
3568de757bac0b47256647504c186d17ca272f85rbb * It decodes characters which need not be encoded,
6653a33e820463abd4f81915b7a1eba0f602e200brianp * and encodes those which must be encoded, and does not touch
6653a33e820463abd4f81915b7a1eba0f602e200brianp * those which must not be touched.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougmPROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len,
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf int i, j, ch;
dd028aa8111afb6534fece555e8c2d408894671etrawick char *allowed; /* characters which should not be encoded */
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin char *reserved; /* characters which much not be en/de-coded */
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * N.B. in addition to :@&=, this allows ';' in an http path
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * and '?' in an ftp path -- this may be revised
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * Also, it makes a '+' character in a search string reserved, as
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * it may be form-encoded. (Although RFC 1738 doesn't allow this -
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * it only permits ; / ? : @ = & as reserved chars.)
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin else if (t == enc_search) {
6653a33e820463abd4f81915b7a1eba0f602e200brianp else if (t == enc_user) {
6653a33e820463abd4f81915b7a1eba0f602e200brianp else if (t == enc_fpath) {
6653a33e820463abd4f81915b7a1eba0f602e200brianp else { /* if (t == enc_parm) */
6653a33e820463abd4f81915b7a1eba0f602e200brianp else if (t == enc_search) {
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick for (i = 0, j = 0; i < len; i++, j++) {
239f998fbee5ac5b114b965bb76e217cce0003edstoddard/* always handle '/' first */
3568de757bac0b47256647504c186d17ca272f85rbb * decode it if not already done. do not decode reverse proxied URLs
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * unless specifically forced
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((forcedec || (proxyreq && proxyreq != PROXYREQ_REVERSE)) && ch == '%') {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (!apr_isxdigit(x[i + 1]) || !apr_isxdigit(x[i + 2])) {
3568de757bac0b47256647504c186d17ca272f85rbb if (ch != 0 && strchr(reserved, ch)) { /* keep it encoded */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* recode it, if necessary */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem y[j] = '\0';
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem * Parses network-location.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * urlp on input the URL; on output the path, after the leading /
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * user NULL if no user/password permitted
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * password holder for password
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * host holder for host
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton * port port number; only set if one is supplied.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Returns an error string.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick return "Malformed URL";
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* find _last_ '@' since it might occur in user/password part */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm/* find password */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf password = ap_proxy_canonenc(p, strp + 1, strlen(strp + 1), enc_user, 1, 0);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf return "Bad %-escape in URL (password)";
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf user = ap_proxy_canonenc(p, user, strlen(user), enc_user, 1, 0);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf return "Bad %-escape in URL (username)";
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames * Parse the host string to separate host portion from optional port.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Perform range checking on port.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm rv = apr_parse_addr_port(&addr, &scope_id, &tmp_port, host, p);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (rv != APR_SUCCESS || addr == NULL || scope_id != NULL) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard return "Invalid host/port";
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if (tmp_port != 0) { /* only update caller's port if port was specified */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick ap_str_tolower(addr); /* DNS names are case-insensitive */
7cd5419264796cfeaf8215383cf0f89130a81fectrawickPROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message)
7cd5419264796cfeaf8215383cf0f89130a81fectrawick "The proxy server could not handle the request <em><a href=\"",
7cd5419264796cfeaf8215383cf0f89130a81fectrawick uri, "\">", ap_escape_html(r->pool, r->method), " ", uri,
4f017cb91aa6591385966ccaf0c326e6b2f2c2b8sf "</a></em>.<p>\n"
7cd5419264796cfeaf8215383cf0f89130a81fectrawick "Reason: <strong>", ap_escape_html(r->pool, message),
7cd5419264796cfeaf8215383cf0f89130a81fectrawick "</strong></p>",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* Allow "error-notes" string to be printed by ap_send_error_response() */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_table_setn(r->notes, "verbose-error-to", apr_pstrdup(r->pool, "*"));
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard 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 *
7cd5419264796cfeaf8215383cf0f89130a81fectrawick char *url, *user = NULL, *password = NULL, *err, *host;
74fd6d9aeadb9022086259c5c1ae00bc0dda9c9astoddard /* Set url to the first char after "scheme://" */
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp if ((url = strchr(r->uri, ':')) == NULL || url[1] != '/' || url[2] != '/') {
83df3fbb3f37cf5337c8793b4559392a672e0696jim url = apr_pstrdup(r->pool, &url[1]); /* make it point to "//", which is what proxy_canon_netloc expects */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard err = ap_proxy_canon_netloc(r->pool, &url, &user, &password, &host, &port);
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00899) "%s", err);
36f5cd02b820ec5fef198c08bf29a76b53700181jim/* Return TRUE if addr represents an IP address (or an IP network address) */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardPROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * if the address is given with an explicit netmask, use that
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Due to a deficiency in apr_inet_addr(), it is impossible to parse
01d315c948a50cb511dbaee108b9571ee9a4d287jim * "partial" addresses (with less than 4 quads) correctly, i.e.
01d315c948a50cb511dbaee108b9571ee9a4d287jim * 192.168.123 is parsed as 192.168.0.123, which is not what I want.
01d315c948a50cb511dbaee108b9571ee9a4d287jim * I therefore have to parse the IP address manually:
dd028aa8111afb6534fece555e8c2d408894671etrawick * if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr) == 0)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * addr and mask were set by proxy_readmask()
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * return 1;
83df3fbb3f37cf5337c8793b4559392a672e0696jim * Parse IP addr manually, optionally allowing
3568de757bac0b47256647504c186d17ca272f85rbb * abbreviated net addresses like 192.168.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* Iterate over up to 4 (dotted) quads. */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz for (quads = 0; quads < 4 && *addr != '\0'; ++quads) {
3568de757bac0b47256647504c186d17ca272f85rbb if (*addr == '/' && quads > 0) { /* netmask starts here. */
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh return 0; /* no digit at start of quad */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (tmp == addr) { /* expected a digit, found something else */
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim /* invalid octet */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ++addr; /* after the 4th quad, a dot would be illegal */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard This->addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh if (addr[0] == '/' && apr_isdigit(addr[1])) { /* net mask follows: */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (tmp == addr) { /* expected a digit, found something else */
3568de757bac0b47256647504c186d17ca272f85rbb if (bits < 0 || bits > 32) { /* netmask must be between 0 and 32 */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Determine (i.e., "guess") netmask by counting the
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * number of trailing .0's; reduce #quads appropriately
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * (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)"; */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /* every zero-byte counts as 8 zero-bits */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (bits != 32) { /* no warning for fully qualified IP address */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00900)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf "Warning: NetMask not supplied with IP-Addr; guessing: %s/%ld",
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf This->mask.s_addr = htonl(APR_INADDR_NONE << (32 - bits));
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (*addr == '\0' && (This->addr.s_addr & ~This->mask.s_addr) != 0) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00901)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf "Warning: NetMask and IP-Addr disagree in %s/%ld",
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00902)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf return (*addr == '\0'); /* okay iff we've parsed the whole string */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* Return TRUE if addr represents an IP address (or an IP network address) */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (4 == sscanf(host, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1], &ip_addr[2], &ip_addr[3])) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /* ap_proxy_is_ipaddr() already confirmed that we have
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * a valid octet in ip_addr[i]
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (This->addr.s_addr == (addr.s_addr & This->mask.s_addr)) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00903)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00904)
3568de757bac0b47256647504c186d17ca272f85rbb ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00905)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00906)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick "1)IP-NoMatch: %s[%s] <-> ", host, inet_ntoa(addr));
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00907)
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00908)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (apr_sockaddr_info_get(&reqaddr, host, APR_UNSPEC, 0, 0, r->pool)
3568de757bac0b47256647504c186d17ca272f85rbb ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00909)
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf /* Try to deal with multiple IP addr's for a host */
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf /* FIXME: This needs to be able to deal with IPv6 */
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf if (This->addr.s_addr == (ip->s_addr & This->mask.s_addr)) {
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00910)
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00911)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00912)
3568de757bac0b47256647504c186d17ca272f85rbb ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00913)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "3)IP-NoMatch: %s[%s] <-> ", host, inet_ntoa(*ip));
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00914)
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00915)
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf/* Return TRUE if addr represents a domain name */
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsfPROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* Domain name must start with a '.' */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
f886987cd0bd4220c14043c4d9be77ec22902e73trawick for (i = 0; apr_isalnum(addr[i]) || addr[i] == '-' || addr[i] == '.'; ++i) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz "@@@@ handle optional port in proxy_is_domainname()");
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* @@@@ handle optional port */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick /* Strip trailing dots */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick for (i = strlen(addr) - 1; i > 0 && addr[i] == '.'; --i) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm/* Return TRUE if host "host" is in domain "domain" */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz const char *host = proxy_get_host_of_request(r);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (host == NULL) { /* some error was logged already */
36c8049de63c446926139936c3d195330a0539cetrawick /* @@@ do this within the setup? */
36c8049de63c446926139936c3d195330a0539cetrawick /* 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 */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick for (i = strlen(host) - 1; i > 0 && host[i] == '.'; --i) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* Return TRUE if host "host" is equal to host2 "host2" */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return 0; /* oops! */
e8f95a682820a599fe41b22977010636be5c2717jim /* Try to deal with multiple IP addr's for a host */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /* Ignore trailing dots in host2 comparison: */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* Return TRUE if addr is to be matched as a word */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickPROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* Return TRUE if string "str2" occurs literally in "str1" */
f2e009134c7e279f99dfca5bd421f721bf1f7840jortonstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r)
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim return host != NULL && ap_strstr_c(host, This->name) != NULL;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm/* checks whether a host in uri_addr matches proxyblock */
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawickPROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf,
f886987cd0bd4220c14043c4d9be77ec22902e73trawick /* XXX FIXME: conf->noproxies->elts is part of an opaque structure */
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
36c8049de63c446926139936c3d195330a0539cetrawick "checking remote machine [%s] against [%s]",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00916)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "connect to remote machine %s blocked: name %s "
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00917)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick "connect to remote machine %s blocked: "
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/* set up the minimal filter set */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickPROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickPROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r,
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * XXX FIXME: Make sure this handled the ambiguous case of the :<PORT>
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * after the hostname
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * XXX FIXME: Ensure the /uri component is a case sensitive match
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick rconf = ap_get_module_config(r->request_config, &proxy_module);
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim ap_get_module_config(r->server->module_config, &proxy_module);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * First check if mapping against a balancer and see
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick * if we have such a entity. If so, then we need to
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick * find the particulars of the actual worker which may
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * or may not be the right one... basically, we need
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * to find which member actually handled this request.
3568de757bac0b47256647504c186d17ca272f85rbb (balancer = ap_proxy_get_balancer(r->pool, sconf, real, 1))) {
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe int n, l3 = 0;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe proxy_worker **worker = (proxy_worker **)balancer->workers->elts;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick /* The balancer comparison is a bit trickier. Given the context
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe * BalancerMember balancer://alias http://example.com/foo
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe * ProxyPassReverse /bash balancer://alias/bar
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe * translate url http://example.com/foo/bar/that to /bash/that
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* urlpart (l3) assuredly starts with its own '/' */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz && strncasecmp((*worker)->s->name, url, l2) == 0
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz u = apr_pstrcat(r->pool, ent[i].fake, &url[l2 + l3],
3568de757bac0b47256647504c186d17ca272f85rbb return ap_is_url(u) ? u : ap_construct_url(r->pool, u, r);
e8f95a682820a599fe41b22977010636be5c2717jim else if (l1 >= l2 && strncasecmp((*worker)->s->name, url, l2) == 0) {
98fb535f829e2a95aabd82420931f476661fa8e3jorton return ap_is_url(u) ? u : ap_construct_url(r->pool, u, r);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return ap_is_url(u) ? u : ap_construct_url(r->pool, u, r);
3568de757bac0b47256647504c186d17ca272f85rbb * Cookies are a bit trickier to match: we've got two substrings to worry
3568de757bac0b47256647504c186d17ca272f85rbb * about, and we can't just find them with strstr 'cos of case. Regexp
ec020ca384efb30d501a5af796ddc3bb237d7b8fgregames * matching would be an easy fix, but for better consistency with all the
3568de757bac0b47256647504c186d17ca272f85rbb * other matches we'll refrain and use apr_strmatch to find path=/domain=
ce03576b2434cec77f2921db9d5b6a0510581c23rederpj * and stick to plain strings for the config values.
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawickPROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r,
397df70abe0bdd78a84fb6c38c02641bcfeadceasf proxy_req_conf *rconf = ap_get_module_config(r->request_config,
3568de757bac0b47256647504c186d17ca272f85rbb const char *pathp;
3568de757bac0b47256647504c186d17ca272f85rbb const char *domainp;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * Find the match and replacement, but save replacing until we've done
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * both path and domain so we know the new strlen
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((pathp = apr_strmatch(ap_proxy_strmatch_path, str, len)) != NULL) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz ent = (struct proxy_alias *)rconf->cookie_paths->elts;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ent = (struct proxy_alias *)conf->cookie_paths->elts;
if (newpath) {
if (newdomain) {
if (newdomain) {
return ret;
const char *url,
int care)
return NULL;
return balancer;
balancer++;
return NULL;
const char *url)
return NULL;
const char *url,
const char *alias,
int do_malloc)
const char *sname;
if (!lbmethod) {
if (do_malloc)
&sname);
return APR_EINVAL;
if (lbmethod)
return APR_SUCCESS;
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;
return NULL;
char *pathstart;
if (balancer) {
return max_worker;
const char *url,
int do_malloc)
int rv;
char *ptr;
* ProxyPass / http://www.example.com
if (balancer) {
} else if (conf) {
if (do_malloc)
return NULL;
return APR_EINVAL;
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) {
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;
NULL));
if (!proxyname) {
if (proxyname) {
const char *proxy_auth;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
server_rec *s)
int status;
int complete = 0;
int len = 0;
if (!complete) {
buffer);
code_str);
return(status);
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) {
int found;
return APR_EGENERAL;
found = 0;
if (!found) {
return rv;
if (b->s->need_reset) {
b->s->need_reset = 0;
return APR_SUCCESS;