Add config option OPENSSL_NO_UNIX_SOCK
authorMax Bachmann <kontakt@maxbachmann.de>
Thu, 5 May 2022 16:46:03 +0000 (18:46 +0200)
committerPauli <pauli@openssl.org>
Fri, 8 Jul 2022 04:08:45 +0000 (14:08 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18256)

crypto/bio/bio_addr.c
crypto/bio/bio_local.h
include/internal/sockets.h

index 92305cc7dc1e066b4df5f288545b401613a8ddad..b9027e684b59c7870be0f4db1b5975d70668227e 100644 (file)
@@ -101,7 +101,7 @@ int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa)
         return 1;
     }
 #endif
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     if (sa->sa_family == AF_UNIX) {
         memcpy(&(ap->s_un), sa, sizeof(struct sockaddr_un));
         return 1;
@@ -115,7 +115,7 @@ int BIO_ADDR_rawmake(BIO_ADDR *ap, int family,
                      const void *where, size_t wherelen,
                      unsigned short port)
 {
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     if (family == AF_UNIX) {
         if (wherelen + 1 > sizeof(ap->s_un.sun_path))
             return 0;
@@ -169,7 +169,7 @@ int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l)
         addrptr = &ap->s_in6.sin6_addr;
     }
 #endif
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     else if (ap->sa.sa_family == AF_UNIX) {
         len = strlen(ap->s_un.sun_path);
         addrptr = &ap->s_un.sun_path;
@@ -308,7 +308,7 @@ char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric)
 
 char *BIO_ADDR_path_string(const BIO_ADDR *ap)
 {
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     if (ap->sa.sa_family == AF_UNIX)
         return OPENSSL_strdup(ap->s_un.sun_path);
 #endif
@@ -350,7 +350,7 @@ socklen_t BIO_ADDR_sockaddr_size(const BIO_ADDR *ap)
     if (ap->sa.sa_family == AF_INET6)
         return sizeof(ap->s_in6);
 #endif
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     if (ap->sa.sa_family == AF_UNIX)
         return sizeof(ap->s_un);
 #endif
@@ -390,7 +390,7 @@ int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai)
         if (bai->bai_protocol != 0)
             return bai->bai_protocol;
 
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
         if (bai->bai_family == AF_UNIX)
             return 0;
 #endif
@@ -442,7 +442,7 @@ void BIO_ADDRINFO_free(BIO_ADDRINFO *bai)
         return;
 
 #ifdef AI_PASSIVE
-# ifdef AF_UNIX
+# ifndef OPENSSL_NO_UNIX_SOCK
 #  define _cond bai->bai_family != AF_UNIX
 # else
 #  define _cond 1
@@ -601,7 +601,7 @@ static int addrinfo_wrap(int family, int socktype,
         (*bai)->bai_protocol = IPPROTO_TCP;
     if (socktype == SOCK_DGRAM)
         (*bai)->bai_protocol = IPPROTO_UDP;
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     if (family == AF_UNIX)
         (*bai)->bai_protocol = 0;
 #endif
@@ -671,7 +671,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
 #if OPENSSL_USE_IPV6
     case AF_INET6:
 #endif
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     case AF_UNIX:
 #endif
 #ifdef AF_UNSPEC
@@ -683,7 +683,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
         return 0;
     }
 
-#ifdef AF_UNIX
+#ifndef OPENSSL_NO_UNIX_SOCK
     if (family == AF_UNIX) {
         if (addrinfo_wrap(family, socktype, host, strlen(host), 0, res))
             return 1;
index 557a1d35d7ab6289078506fa089a07b5733efef9..87779c8e02b707b935e7145522910a68104d34bb 100644 (file)
 #  error openssl/bio.h included before bio_local.h
 # endif
 
-/*
- * Undefine AF_UNIX on systems that define it but don't support it.
- */
-# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_VMS)
-#  undef AF_UNIX
-# endif
-
 # ifdef AI_PASSIVE
 
 /*
@@ -77,7 +70,7 @@ union bio_addr_st {
     struct sockaddr_in6 s_in6;
 # endif
     struct sockaddr_in s_in;
-# ifdef AF_UNIX
+# ifndef OPENSSL_NO_UNIX_SOCK
     struct sockaddr_un s_un;
 # endif
 };
index 4701eb7e0e483af1685e4871d8b9653aa6673281..bc1de716df830a0bb1155087e561e6f99804163a 100644 (file)
@@ -75,7 +75,7 @@ struct servent *PASCAL getservbyname(const char *, const char *);
 #   include <inet.h>
 #  else
 #   include <sys/socket.h>
-#   ifndef NO_SYS_UN_H
+#   if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
 #    include <sys/un.h>
 #    ifndef UNIX_PATH_MAX
 #     define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
@@ -123,6 +123,15 @@ struct servent *PASCAL getservbyname(const char *, const char *);
 #  endif
 # endif
 
+/*
+ * Some platforms define AF_UNIX, but don't support it
+ */
+# if !defined(OPENSSL_NO_UNIX_SOCK)
+#  if !defined(AF_UNIX) || defined(NO_SYS_UN_H)
+#   define OPENSSL_NO_UNIX_SOCK
+#  endif
+# endif
+
 # define get_last_socket_error() errno
 # define clear_socket_error()    errno=0