From: Max Bachmann Date: Thu, 5 May 2022 16:46:03 +0000 (+0200) Subject: Add config option OPENSSL_NO_UNIX_SOCK X-Git-Tag: openssl-3.2.0-alpha1~2422 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=081f3484593cdd3be2b7fdd8818c3f928ce729bc;p=thirdparty%2Fopenssl.git Add config option OPENSSL_NO_UNIX_SOCK Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/18256) --- diff --git a/crypto/bio/bio_addr.c b/crypto/bio/bio_addr.c index 92305cc7dc1..b9027e684b5 100644 --- a/crypto/bio/bio_addr.c +++ b/crypto/bio/bio_addr.c @@ -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; diff --git a/crypto/bio/bio_local.h b/crypto/bio/bio_local.h index 557a1d35d7a..87779c8e02b 100644 --- a/crypto/bio/bio_local.h +++ b/crypto/bio/bio_local.h @@ -33,13 +33,6 @@ # 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 }; diff --git a/include/internal/sockets.h b/include/internal/sockets.h index 4701eb7e0e4..bc1de716df8 100644 --- a/include/internal/sockets.h +++ b/include/internal/sockets.h @@ -75,7 +75,7 @@ struct servent *PASCAL getservbyname(const char *, const char *); # include # else # include -# ifndef NO_SYS_UN_H +# if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK) # include # 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