]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_proxy: Fixup UDS filename for mod_proxy called through r->handler.
authorYann Ylavic <ylavic@apache.org>
Tue, 25 Jun 2024 23:49:09 +0000 (23:49 +0000)
committerYann Ylavic <ylavic@apache.org>
Tue, 25 Jun 2024 23:49:09 +0000 (23:49 +0000)
* modules/proxy/proxy_util.c:
  Export ap_proxy_fixup_uds_filename() from fix_uds_filename.
  Call it from ap_proxy_pre_request() even for rewritten balancer workers.

* modules/proxy/mod_proxy.h:
  Declare ap_proxy_fixup_uds_filename()

* modules/proxy/mod_proxy.c:
  Fixup UDS filename from r->handler in proxy_handler().

* include/ap_mmn.h:
  Bump MMN minor for ap_proxy_fixup_uds_filename()

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1918626 13f79535-47bb-0310-9956-ffa450edef68

include/ap_mmn.h
modules/proxy/mod_proxy.c
modules/proxy/mod_proxy.h
modules/proxy/proxy_util.c

index f48c3188ec9a86cc8223b6ec3113ba0ac81bc251..4e942ada1ded0daa80502d3fc03ba83719f559ad 100644 (file)
  * 20211221.22 (2.5.1-dev) Add AP_MPMQ_CAN_WAITIO
  * 20211221.23 (2.5.1-dev) Add ap_set_content_type_ex(), ap_filepath_merge(),
  *                         and AP_REQUEST_TRUSTED_CT BNOTE.
+ * 20211221.24 (2.5.1-dev) Add ap_proxy_fixup_uds_filename()
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20211221
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 23             /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 24             /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 24e6515bd2b910effbd4920a8ec20cb9c561542f..17d28c51ccc4c959eabd673e12d7dd7141835656 100644 (file)
@@ -1251,6 +1251,7 @@ static int proxy_fixup(request_rec *r)
 
     return OK;      /* otherwise; we've done the best we can */
 }
+
 /* Send a redirection if the request contains a hostname which is not */
 /* fully qualified, i.e. doesn't have a domain name appended. Some proxy */
 /* servers like Netscape's allow this and access hosts from the local */
@@ -1304,7 +1305,7 @@ static int proxy_handler(request_rec *r)
         ap_get_module_config(sconf, &proxy_module);
     apr_array_header_t *proxies = conf->proxies;
     struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
-    int i, rc, access_status;
+    int rc = DECLINED, access_status, i;
     int direct_connect = 0;
     const char *str;
     apr_int64_t maxfwd;
@@ -1319,22 +1320,29 @@ static int proxy_handler(request_rec *r)
         return DECLINED;
     }
 
-    if (!r->proxyreq) {
-        rc = DECLINED;
-        /* We may have forced the proxy handler via config or .htaccess */
-        if (r->handler &&
-            strncmp(r->handler, "proxy:", 6) == 0 &&
-            strncmp(r->filename, "proxy:", 6) != 0) {
-            r->proxyreq = PROXYREQ_REVERSE;
-            r->filename = apr_pstrcat(r->pool, r->handler, r->filename, NULL);
-            /* Still need to fixup/canonicalize r->filename */
+    /* We may have forced the proxy handler via config or .htaccess */
+    if (!r->proxyreq && r->handler && strncmp(r->handler, "proxy:", 6) == 0) {
+        char *old_filename = r->filename;
+
+        r->proxyreq = PROXYREQ_REVERSE;
+        r->filename = apr_pstrcat(r->pool, r->handler, r->filename, NULL);
+
+        /* Still need to fixup/canonicalize r->filename */
+        uri = r->filename + 6;
+        rc = ap_proxy_fixup_uds_filename(r, &uri);
+        if (rc <= OK) {
             rc = proxy_fixup(r);
         }
         if (rc != OK) {
-            return rc;
+            r->filename = old_filename;
+            r->proxyreq = 0;
         }
-    } else if (strncmp(r->filename, "proxy:", 6) != 0) {
-        return DECLINED;
+    }
+    else if (r->proxyreq && strncmp(r->filename, "proxy:", 6) == 0) {
+        rc = OK;
+    }
+    if (rc != OK) {
+        return rc;
     }
 
     /* handle max-forwards / OPTIONS / TRACE */
index 2cd2e06246012101bb76c4cfb27644795d3ba02b..fc4b559e35eb6dcc31f6353e0680355525be18e1 100644 (file)
@@ -1029,6 +1029,16 @@ PROXY_DECLARE(proxy_balancer_shared *) ap_proxy_find_balancershm(ap_slotmem_prov
                                                                  proxy_balancer *balancer,
                                                                  unsigned int *index);
 
+/*
+ * In the case of the reverse proxy, we need to see if we
+ * were passed a UDS url (eg: from mod_proxy) and adjust uds_path
+ * as required.  
+ * @param r        current request
+ * @param url      request url to be fixed
+ * @return         OK if fixed up, DECLINED if not UDS, or an HTTP_XXX error
+ */
+PROXY_DECLARE(int) ap_proxy_fixup_uds_filename(request_rec *r, char **url);
+
 /**
  * Get the most suitable worker and/or balancer for the request
  * @param worker   worker used for processing request
index 46cc4e2068d464f341761f5149b90480825e5da2..628b74aebf31b1ded9b242e5a5a7e0c6284f363a 100644 (file)
@@ -2425,7 +2425,7 @@ static int ap_proxy_retry_worker(const char *proxy_function, proxy_worker *worke
  * were passed a UDS url (eg: from mod_proxy) and adjust uds_path
  * as required.  
  */
-static int fix_uds_filename(request_rec *r, char **url) 
+PROXY_DECLARE(int) ap_proxy_fixup_uds_filename(request_rec *r, char **url) 
 {
     char *uds_url = r->filename + 6, *origin_url;
 
@@ -2448,7 +2448,7 @@ static int fix_uds_filename(request_rec *r, char **url)
         if (!uds_path) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10292)
                     "Invalid proxy UDS filename (%s)", r->filename);
-            return 0;
+            return HTTP_BAD_REQUEST;
         }
         apr_table_setn(r->notes, "uds_path", uds_path);
 
@@ -2460,8 +2460,10 @@ static int fix_uds_filename(request_rec *r, char **url)
         ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
                 "*: rewrite of url due to UDS(%s): %s (%s)",
                 uds_path, *url, r->filename);
+        return OK;
     }
-    return 1;
+
+    return DECLINED;
 }
 
 PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
@@ -2480,9 +2482,6 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
             ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
                           "%s: found worker %s for %s",
                           (*worker)->s->scheme, (*worker)->s->name, *url);
-            if (!forward && !fix_uds_filename(r, url)) {
-                return HTTP_INTERNAL_SERVER_ERROR;
-            }
             access_status = OK;
         }
         else if (forward) {
@@ -2512,9 +2511,6 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
                  * regarding the Connection header in the request.
                  */
                 apr_table_setn(r->subprocess_env, "proxy-nokeepalive", "1");
-                if (!fix_uds_filename(r, url)) {
-                    return HTTP_INTERNAL_SERVER_ERROR;
-                }
             }
         }
     }
@@ -2524,6 +2520,13 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
                       "all workers are busy.  Unable to serve %s", *url);
         access_status = HTTP_SERVICE_UNAVAILABLE;
     }
+
+    if (access_status == OK
+        && r->proxyreq == PROXYREQ_REVERSE
+        && ap_proxy_fixup_uds_filename(r, url) > OK) {
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
     return access_status;
 }