]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix domain socket handling (STR #1277)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 23 Sep 2005 20:29:27 +0000 (20:29 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 23 Sep 2005 20:29:27 +0000 (20:29 +0000)
cups/http.h:
    - Add httpAddrLength() function.

cups/http-addr.c:
    - httpAddrLength(): Added.

scheduler/conf.c:
    - get_address(): Return immediately if we have a domain
      socket address.
    - read_configuration(): Only default to IPv6 if the local
      system supports it and we are not using OpenBSD.

scheduler/listen.c:
    - StartListening(): Use httpAddrLength() for bind calls,
      and revamp the logging to be more useful.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@4697 7a7537e8-13f0-0310-91df-b6672ffda945

cups/http-addr.c
cups/http.h
scheduler/conf.c
scheduler/listen.c

index e2ddb8cfbfeddd1d99b6089480a94e1556cc9558..121b47ddbbd15915ffb34fa1ca0e579b11f0433a 100644 (file)
@@ -88,6 +88,31 @@ httpAddrEqual(const http_addr_t *addr1,              /* I - First address */
 }
 
 
+/*
+ * 'httpAddrLength()' - Return the length of the address in bytes.
+ */
+
+int                                    /* O - Length in bytes */
+httpAddrLength(const http_addr_t *addr)        /* I - Address */
+{
+#ifdef AF_INET6
+  if (addr->addr.sa_family == AF_INET6)
+    return (sizeof(addr->ipv6));
+  else
+#endif /* AF_INET6 */
+#ifdef AF_LOCAL
+  if (addr->addr.sa_family == AF_LOCAL)
+    return (sizeof(addr->un.sun_family) + strlen(addr->un.sun_path));
+  else
+#endif /* AF_LOCAL */
+  if (addr->addr.sa_family == AF_INET)
+    return (sizeof(addr->ipv4));
+  else
+    return (0);
+
+}
+
+
 /*
  * 'httpAddrLoad()' - Load a host entry address into an HTTP address.
  */
index 8e1778a1b98d041e6379a300f6c0ebf008217bb6..26a2abcfcf49447d5582a8af7ef2dbab466a9301 100644 (file)
@@ -418,6 +418,7 @@ extern void         httpSeparate2(const char *uri,
 extern int             httpAddrAny(const http_addr_t *addr);
 extern int             httpAddrEqual(const http_addr_t *addr1,
                                      const http_addr_t *addr2);
+extern int             httpAddrLength(const http_addr_t *addr);
 extern void            httpAddrLoad(const struct hostent *host, int port,
                                     int n, http_addr_t *addr);
 extern int             httpAddrLocalhost(const http_addr_t *addr);
index 52189118ea9544243dacb0ce34b6913c3f75618d..2649d83ccbe19fed67909cdf604a803c1e7c7d1e 100644 (file)
@@ -1065,8 +1065,9 @@ get_address(const char  *value,           /* I - Value string */
 
     address->un.sun_family = AF_LOCAL;
     strcpy(address->un.sun_path, value);
+
+    return (1);
   }
-  else
 #endif /* AF_LOCAL */
 
  /*
@@ -1780,11 +1781,11 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
 
       memset(lis, 0, sizeof(listener_t));
 
-#ifdef AF_INET6
+#if defined(AF_INET6) && !defined(__OpenBSD__)
       if (get_address(value, INADDR_ANY, IPP_PORT, AF_INET6, &(lis->address)))
 #else
       if (get_address(value, INADDR_ANY, IPP_PORT, AF_INET, &(lis->address)))
-#endif /* AF_INET6 */
+#endif /* AF_INET6  && !__OpenBSD__ */
       {
         httpAddrString(&(lis->address), temp, sizeof(temp));
 
index cb6f56af76222d1a1d6a1d290bae2728282fff08..e67da7b1d3837ae74958787de51fd2278c9737b2 100644 (file)
@@ -170,8 +170,6 @@ StartListening(void)
 #endif /* AF_LOCAL */
     p = ntohs(lis->address.ipv4.sin_port);
 
-    LogMessage(L_DEBUG, "StartListening: address=%s port=%d", s, p);
-
    /*
     * Save the first port that is bound to the local loopback or
     * "any" address...
@@ -222,8 +220,6 @@ StartListening(void)
       exit(errno);
     }
 
-    LogMessage(L_DEBUG2, "StartListening: fd=%d", lis->fd);
-
     fcntl(lis->fd, F_SETFD, fcntl(lis->fd, F_GETFD) | FD_CLOEXEC);
 
    /*
@@ -245,7 +241,7 @@ StartListening(void)
     if (lis->address.addr.sa_family == AF_INET6)
     {
       status = bind(lis->fd, (struct sockaddr *)&(lis->address),
-                   sizeof(lis->address.ipv6));
+                   httpAddrLength(&(lis->address)));
 
 #ifdef IPV6_V6ONLY
       if (status >= 0 &&
@@ -254,6 +250,10 @@ StartListening(void)
        /*
         * Make sure that wildcard and loopback addresses accept
        * connections from both IPv6 and IPv4 clients.
+       *
+       * NOTE: This DOES NOT WORK for OpenBSD, since they adopted a
+       *       stricter behavior in the name of security.  For OpenBSD,
+       *       you must list IPv4 and IPv6 listen addresses separately.
        */
 
         val = 0;
@@ -290,7 +290,7 @@ StartListening(void)
       */
 
       status = bind(lis->fd, (struct sockaddr *)&(lis->address),
-                   SUN_LEN(&(lis->address.un)));
+                   httpAddrLength(&(lis->address)));
 
      /*
       * Restore the umask...
@@ -320,6 +320,13 @@ StartListening(void)
                  s, p, strerror(errno));
       exit(errno);
     }
+
+    if (p)
+      LogMessage(L_INFO, "StartListening: Listening to %s:%d on fd %d...",
+                s, p, lis->fd);
+    else
+      LogMessage(L_INFO, "StartListening: Listening to %s on fd %d...",
+                s, lis->fd);
   }
 
  /*