]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r1598946, r1602989 from trunk:
authorJim Jagielski <jim@apache.org>
Mon, 12 Jan 2015 13:36:17 +0000 (13:36 +0000)
committerJim Jagielski <jim@apache.org>
Mon, 12 Jan 2015 13:36:17 +0000 (13:36 +0000)
Fix computation of the size of 'struct sockaddr_un' when passed to 'connect()'.
Use the same logic as the one in ' in 'proxy_util.c'.

mod_proxy: Don't limit the size of the connectable Unix Domain Socket paths.
Since connect() to UDS path is used at several places, introduce
ap_proxy_connect_uds() in proxy_util.

Submitted by: jailletc36, ylavic
Reviewed/backported by: jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1651081 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
include/ap_mmn.h
modules/proxy/mod_proxy.h
modules/proxy/mod_proxy_fdpass.c
modules/proxy/proxy_util.c

diff --git a/CHANGES b/CHANGES
index 324a86604ea13383ca291f33dc12ea15f562a476..a7757b685331de7f3435bf83021e22e0d005e2ba 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -238,6 +238,9 @@ Changes with Apache 2.4.10
   *) mod_proxy_balancer: Correctly encode user provided data in management
      interface. PR 56532 [Maksymilian, <max cert.cx>]
 
+  *) mod_proxy: Don't limit the size of the connectable Unix Domain Socket
+     paths. [Graham Dumpleton, Christophe Jaillet, Yann Ylavic]
+
   *) mod_proxy_fcgi: Support iobuffersize parameter.  [Jeff Trawick]
 
   *) event: Send the SSL close notify alert when the KeepAliveTimeout
diff --git a/STATUS b/STATUS
index f5d0093c609921b5d04581595f550d46840ee765..4de2e7d181b957bc02c15a98cf03f21fbaed5715 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -138,23 +138,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
      2.4.x patch: trunk works (modulo CHANGES)
      +1: ylavic, rjung, covener
 
-   * mod_proxy: Don't limit the size of the connectable Unix Domain Socket paths.
-                [Graham Dumpleton, Christophe Jaillet, Yann Ylavic]
-     trunk patch: http://svn.apache.org/r1598946
-                  http://svn.apache.org/r1602989
-     2.4.x patch: http://people.apache.org/~ylavic/httpd-2.4.x-ap_proxy_connect_uds.patch
-                  (modulo CHANGES/MMN)
-     +1: ylavic, jim, covener
-
-   * mod_proxy: Shutdown (eg. SSL close notify) the backend connection before closing.
-     trunk patch: http://svn.apache.org/r1601291
-                  http://svn.apache.org/r1601630
-     2.4.x patch: http://people.apache.org/~ylavic/httpd-2.4.x-proxy-SSL-shutdown.patch
-                  (modulo CHANGES)
-     note: depends on ap_shutdown_conn() from r1601185 above.
-     +1: ylavic, rjung, covener
-
-
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
 
index 7a278b9c22745ce5a04d0ddd41def9aff5e19578..633e0520518f755314c9f33f56d592f6bb7f585b 100644 (file)
  * 20120211.36 (2.4.10-dev) Add ap_copy_scoreboard_worker()
  * 20120211.37 (2.4.11-dev) Add r->trailers_{in,out}
  * 20120211.38 (2.4.10-dev) Added ap_shutdown_conn().
+ * 20120211.39 (2.4.10-dev) Add ap_proxy_connect_uds().
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 38                   /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 39                   /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 4ead22e7018972b1859c434f5f7295536a4c2449..5b3473b02970bfe3dcfc80b121f98a361aafc23f 100644 (file)
@@ -865,6 +865,17 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
                                             proxy_conn_rec *conn,
                                             proxy_worker *worker,
                                             server_rec *s);
+
+/**
+ * Make a connection to a Unix Domain Socket (UDS) path
+ * @param sock     UDS to connect
+ * @param uds_path UDS path to connect to
+ * @param p        pool to make the sock addr
+ * @return         APR_SUCCESS or error status
+ */
+PROXY_DECLARE(apr_status_t) ap_proxy_connect_uds(apr_socket_t *sock,
+                                                 const char *uds_path,
+                                                 apr_pool_t *p);
 /**
  * Make a connection record for backend connection
  * @param proxy_function calling proxy scheme (http, ajp, ...)
index 26a7b13e53c15dc4c1eb29cfcbdb5b81c9584899..63cf469664c4dbe4898985e46a5eb36e39527aec 100644 (file)
 #error This module only works on unix platforms with the correct OS support
 #endif
 
-#include "apr_version.h"
-#if APR_MAJOR_VERSION < 2
-/* for apr_wait_for_io_or_timeout */
-#include "apr_support.h"
-#endif
-
 #include "mod_proxy_fdpass.h"
 
 module AP_MODULE_DECLARE_DATA proxy_fdpass_module;
@@ -54,54 +48,10 @@ static int proxy_fdpass_canon(request_rec *r, char *url)
     return OK;
 }
 
-/* TODO: In APR 2.x: Extend apr_sockaddr_t to possibly be a path !!! */
-static apr_status_t socket_connect_un(apr_socket_t *sock,
-                                      struct sockaddr_un *sa)
-{
-    apr_status_t rv;
-    apr_os_sock_t rawsock;
-    apr_interval_time_t t;
-
-    rv = apr_os_sock_get(&rawsock, sock);
-    if (rv != APR_SUCCESS) {
-        return rv;
-    }
-
-    rv = apr_socket_timeout_get(sock, &t);
-    if (rv != APR_SUCCESS) {
-        return rv;
-    }
-
-    do {
-        rv = connect(rawsock, (struct sockaddr*)sa,
-                               sizeof(*sa) + strlen(sa->sun_path));
-    } while (rv == -1 && errno == EINTR);
-
-    if ((rv == -1) && (errno == EINPROGRESS || errno == EALREADY)
-        && (t > 0)) {
-#if APR_MAJOR_VERSION < 2
-        rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
-#else
-        rv = apr_socket_wait(sock, APR_WAIT_WRITE);
-#endif
-
-        if (rv != APR_SUCCESS) {
-            return rv;
-        }
-    }
-
-    if (rv == -1 && errno != EISCONN) {
-        return errno;
-    }
-
-    return APR_SUCCESS;
-}
-
 static apr_status_t get_socket_from_path(apr_pool_t *p,
                                          const char* path,
                                          apr_socket_t **out_sock)
 {
-    struct sockaddr_un sa;
     apr_socket_t *s;
     apr_status_t rv;
     *out_sock = NULL;
@@ -112,10 +62,7 @@ static apr_status_t get_socket_from_path(apr_pool_t *p,
         return rv;
     }
 
-    sa.sun_family = AF_UNIX;
-    apr_cpystrn(sa.sun_path, path, sizeof(sa.sun_path));
-
-    rv = socket_connect_un(s, &sa);
+    rv = ap_proxy_connect_uds(s, path, p);
     if (rv != APR_SUCCESS) {
         return rv;
     }
index d89f44be0878fe96dd804a6d7ed158c783dc6f77..3e74ec9ce0bb419c806ea03bef5641ddcd063611 100644 (file)
@@ -2558,13 +2558,16 @@ static apr_status_t send_http_connect(proxy_conn_rec *backend,
 
 
 #if APR_HAVE_SYS_UN_H
-/* lifted from mod_proxy_fdpass.c; tweaked addrlen in connect() call */
-static apr_status_t socket_connect_un(apr_socket_t *sock,
-                                      struct sockaddr_un *sa)
+/* TODO: In APR 2.x: Extend apr_sockaddr_t to possibly be a path !!! */
+PROXY_DECLARE(apr_status_t) ap_proxy_connect_uds(apr_socket_t *sock,
+                                                 const char *uds_path,
+                                                 apr_pool_t *p)
 {
     apr_status_t rv;
     apr_os_sock_t rawsock;
     apr_interval_time_t t;
+    struct sockaddr_un *sa;
+    apr_socklen_t addrlen, pathlen;
 
     rv = apr_os_sock_get(&rawsock, sock);
     if (rv != APR_SUCCESS) {
@@ -2576,29 +2579,30 @@ static apr_status_t socket_connect_un(apr_socket_t *sock,
         return rv;
     }
 
+    pathlen = strlen(uds_path);
+    /* copy the UDS path (including NUL) to the sockaddr_un */
+    addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path) + pathlen;
+    sa = (struct sockaddr_un *)apr_palloc(p, addrlen + 1);
+    memcpy(sa->sun_path, uds_path, pathlen + 1);
+    sa->sun_family = AF_UNIX;
+
     do {
-        const socklen_t addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path)
-                                  + strlen(sa->sun_path) + 1;
         rv = connect(rawsock, (struct sockaddr*)sa, addrlen);
-    } while (rv == -1 && errno == EINTR);
+    } while (rv == -1 && (rv = errno) == EINTR);
 
-    if ((rv == -1) && (errno == EINPROGRESS || errno == EALREADY)
-        && (t > 0)) {
+    if (rv && rv != EISCONN) {
+        if ((rv == EINPROGRESS || rv == EALREADY) && (t > 0))  {
 #if APR_MAJOR_VERSION < 2
-        rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
+            rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
 #else
-        rv = apr_socket_wait(sock, APR_WAIT_WRITE);
+            rv = apr_socket_wait(sock, APR_WAIT_WRITE);
 #endif
-
+        }
         if (rv != APR_SUCCESS) {
             return rv;
         }
     }
 
-    if (rv == -1 && errno != EISCONN) {
-        return errno;
-    }
-
     return APR_SUCCESS;
 }
 #endif
@@ -2631,8 +2635,6 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
 #if APR_HAVE_SYS_UN_H
         if (conn->uds_path)
         {
-            struct sockaddr_un sa;
-
             rv = apr_socket_create(&newsock, AF_UNIX, SOCK_STREAM, 0,
                                    conn->scpool);
             if (rv != APR_SUCCESS) {
@@ -2646,10 +2648,7 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
             }
             conn->connection = NULL;
 
-            sa.sun_family = AF_UNIX;
-            apr_cpystrn(sa.sun_path, conn->uds_path, sizeof(sa.sun_path));
-
-            rv = socket_connect_un(newsock, &sa);
+            rv = ap_proxy_connect_uds(newsock, conn->uds_path, conn->scpool);
             if (rv != APR_SUCCESS) {
                 apr_socket_close(newsock);
                 ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(02454)