xserver: Branch 'master' - 2 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 27 22:41:18 UTC 2025


 include/meson.build |    2 ++
 os/access.c         |   17 ++++++++++++-----
 os/connection.c     |   15 ++++++++++++---
 os/utils.c          |    6 +++---
 os/xdmcp.c          |   36 +++++++++++++++++++++++-------------
 5 files changed, 52 insertions(+), 24 deletions(-)

New commits:
commit 6cc358dfb47136ed5b99f20b04674be3bc055dfb
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Jan 18 16:41:15 2025 -0800

    os: if inet_ntop() is available, use it for IPv4 addresses as well
    
    Support for using inet_ntop() was originally added to support IPv6,
    and only used for IPv6 addresses in AuthAudit().  Two decades later,
    support for inet_ntop() is ubiquitous and OS'es have marked inet_ntoa()
    as deprecated, so use the modern interface for IPv4 as well now.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1760>

diff --git a/include/meson.build b/include/meson.build
index 67623f1e6..955721c1e 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -152,6 +152,7 @@ conf_data.set('HAVE_GETPEEREID', cc.has_function('getpeereid') ? '1' : false)
 conf_data.set('HAVE_GETPEERUCRED', cc.has_function('getpeerucred') ? '1' : false)
 conf_data.set('HAVE_GETPROGNAME', cc.has_function('getprogname') ? '1' : false)
 conf_data.set('HAVE_GETZONEID', cc.has_function('getzoneid') ? '1' : false)
+conf_data.set('HAVE_INET_NTOP', cc.has_function('inet_ntop') ? '1' : false)
 conf_data.set('HAVE_MEMFD_CREATE', cc.has_function('memfd_create') ? '1' : false)
 conf_data.set('HAVE_MKOSTEMP', cc.has_function('mkostemp') ? '1' : false)
 conf_data.set('HAVE_MMAP', cc.has_function('mmap') ? '1' : false)
diff --git a/os/connection.c b/os/connection.c
index 60ee6e6f9..8dcc2bf4e 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -390,9 +390,18 @@ AuthAudit(ClientPtr client, Bool letin,
             strlcpy(addr, "local host", sizeof(addr));
             break;
 #if defined(TCPCONN)
-        case AF_INET:
-            snprintf(addr, sizeof(addr), "IP %s",
-                     inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr));
+        case AF_INET:{
+#if defined(HAVE_INET_NTOP)
+            char ipaddr[INET_ADDRSTRLEN];
+
+            inet_ntop(AF_INET, &((struct sockaddr_in *) saddr)->sin_addr,
+                      ipaddr, sizeof(ipaddr));
+#else
+            const char *ipaddr =
+                inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr);
+#endif
+            snprintf(addr, sizeof(addr), "IP %s", ipaddr);
+        }
             break;
 #if defined(IPv6)
         case AF_INET6:{
commit 2ffe0f8a356f5deea1e498441ab9e077602a69ba
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Jan 12 10:45:01 2025 -0800

    os: if getaddrinfo() is available, use it, even if IPv6 support is disabled
    
    Support for using getaddrinfo() was originally added to support IPv6,
    and only used if IPv6 support was enabled.  Two decades later, support
    for getaddrinfo() is ubiquitous and OS'es have marked gethostbyname()
    as deprecated, so use the modern interface whenever we can now.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1760>

diff --git a/include/meson.build b/include/meson.build
index 6d39bf603..67623f1e6 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -146,6 +146,7 @@ conf_data.set('HAVE_GETUID', cc.has_function('getuid') ? '1' : false)
 conf_data.set('HAVE_GETEUID', cc.has_function('geteuid') ? '1' : false)
 conf_data.set('HAVE_ISASTREAM', cc.has_function('isastream') ? '1' : false)
 conf_data.set('HAVE_ISSETUGID', cc.has_function('issetugid') ? '1' : false)
+conf_data.set('HAVE_GETADDRINFO', cc.has_function('getaddrinfo') ? '1' : false)
 conf_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs') ? '1' : false)
 conf_data.set('HAVE_GETPEEREID', cc.has_function('getpeereid') ? '1' : false)
 conf_data.set('HAVE_GETPEERUCRED', cc.has_function('getpeerucred') ? '1' : false)
diff --git a/os/access.c b/os/access.c
index d3ad798cc..44d6c2430 100644
--- a/os/access.c
+++ b/os/access.c
@@ -970,8 +970,11 @@ ResetHosts(const char *display)
             else
 #if defined(TCPCONN)
             {
+#if defined(HAVE_GETADDRINFO)
+                if ((family == FamilyInternet) ||
 #if defined(IPv6)
-                if ((family == FamilyInternet) || (family == FamilyInternet6) ||
+                    (family == FamilyInternet6) ||
+#endif
                     (family == FamilyWild)) {
                     struct addrinfo *addresses;
                     struct addrinfo *a;
@@ -990,7 +993,7 @@ ResetHosts(const char *display)
                         freeaddrinfo(addresses);
                     }
                 }
-#else
+#else                           /* HAVE_GETADDRINFO */
 #ifdef XTHREADS_NEEDS_BYNAMEPARAMS
                 _Xgethostbynameparams hparams;
 #endif
@@ -1017,7 +1020,7 @@ ResetHosts(const char *display)
 #endif
                     }
                 }
-#endif                          /* IPv6 */
+#endif                          /* HAVE_GETADDRINFO */
             }
 #endif                          /* TCPCONN */
             family = FamilyWild;
@@ -1765,8 +1768,12 @@ siHostnameAddrMatch(int family, void *addr, int len,
  * support for other address families, such as DECnet, could be added if
  * desired.
  */
+#if defined(HAVE_GETADDRINFO)
+    if ((family == FamilyInternet)
 #if defined(IPv6)
-    if ((family == FamilyInternet) || (family == FamilyInternet6)) {
+        || (family == FamilyInternet6)
+#endif
+        ) {
         char hostname[SI_HOSTNAME_MAXLEN];
         struct addrinfo *addresses;
         struct addrinfo *a;
@@ -1791,7 +1798,7 @@ siHostnameAddrMatch(int family, void *addr, int len,
             freeaddrinfo(addresses);
         }
     }
-#else                           /* IPv6 not supported, use gethostbyname instead for IPv4 */
+#else /* getaddrinfo not supported, use gethostbyname instead for IPv4 */
     if (family == FamilyInternet) {
         register struct hostent *hp;
 
diff --git a/os/utils.c b/os/utils.c
index b34145b1f..c6489bfe8 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -887,7 +887,7 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
         char hname[1024], *hnameptr;
         unsigned int len;
 
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
         struct addrinfo hints, *ai = NULL;
 #else
         struct hostent *host;
@@ -898,7 +898,7 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
 #endif
 
         gethostname(hname, 1024);
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
         memset(&hints, 0, sizeof(hints));
         hints.ai_flags = AI_CANONNAME;
         if (getaddrinfo(hname, NULL, &hints, &ai) == 0) {
@@ -928,7 +928,7 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
         p += sizeof(AUTHORIZATION_NAME);
         memcpy(p, hnameptr, len);
         p += len;
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
         if (ai) {
             freeaddrinfo(ai);
         }
diff --git a/os/xdmcp.c b/os/xdmcp.c
index 4a12cae5b..955cee1b4 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -89,10 +89,12 @@ static char *xdmAuthCookie;
 
 static XdmcpBuffer buffer;
 
-#if defined(IPv6)
-
+#if defined(HAVE_GETADDRINFO)
 static struct addrinfo *mgrAddr;
 static struct addrinfo *mgrAddrFirst;
+#endif
+
+#if defined(IPv6)
 
 #define SOCKADDR_TYPE		struct sockaddr_storage
 #define SOCKADDR_FAMILY(s)	((struct sockaddr *)&(s))->sa_family
@@ -836,15 +838,19 @@ timeout(void)
         return;
     }
 
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
     if (state == XDM_COLLECT_QUERY || state == XDM_COLLECT_INDIRECT_QUERY) {
         /* Try next address */
         for (mgrAddr = mgrAddr->ai_next;; mgrAddr = mgrAddr->ai_next) {
             if (mgrAddr == NULL) {
                 mgrAddr = mgrAddrFirst;
             }
-            if (mgrAddr->ai_family == AF_INET || mgrAddr->ai_family == AF_INET6)
+            if (mgrAddr->ai_family == AF_INET)
+                break;
+#if defined(IPv6)
+            if (mgrAddr->ai_family == AF_INET6)
                 break;
+#endif
         }
 #ifndef SIN6_LEN
         ManagerAddressLen = mgrAddr->ai_addrlen;
@@ -1351,12 +1357,12 @@ get_addr_by_name(const char *argtype,
                  const char *namestr,
                  int port,
                  int socktype, SOCKADDR_TYPE * addr, SOCKLEN_TYPE * addrlen
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
                  , struct addrinfo **aip, struct addrinfo **aifirstp
 #endif
     )
 {
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
     struct addrinfo *ai;
     struct addrinfo hints;
     char portstr[6];
@@ -1383,8 +1389,12 @@ get_addr_by_name(const char *argtype,
 
     if ((gaierr = getaddrinfo(namestr, pport, &hints, aifirstp)) == 0) {
         for (ai = *aifirstp; ai != NULL; ai = ai->ai_next) {
-            if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6)
+            if (ai->ai_family == AF_INET)
+                break;
+#if defined(IPv6)
+            if (ai->ai_family == AF_INET6)
                 break;
+#endif
         }
         if ((ai == NULL) || (ai->ai_addrlen > sizeof(SOCKADDR_TYPE))) {
             FatalError("Xserver: %s host %s not on supported network type\n",
@@ -1400,7 +1410,7 @@ get_addr_by_name(const char *argtype,
         FatalError("Xserver: %s: %s %s\n", gai_strerror(gaierr), argtype,
                    namestr);
     }
-#else
+#else /* HAVE_GETADDRINFO */
     struct hostent *hep;
 
 #ifdef XTHREADS_NEEDS_BYNAMEPARAMS
@@ -1422,7 +1432,7 @@ get_addr_by_name(const char *argtype,
         FatalError("Xserver: %s host on strange network %s\n", argtype,
                    namestr);
     }
-#endif
+#endif /* HAVE_GETADDRINFO */
 }
 
 static void
@@ -1435,7 +1445,7 @@ get_manager_by_name(int argc, char **argv, int i)
 
     get_addr_by_name(argv[i], argv[i + 1], xdm_udp_port, SOCK_DGRAM,
                      &ManagerAddress, &ManagerAddressLen
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
                      , &mgrAddr, &mgrAddrFirst
 #endif
         );
@@ -1444,7 +1454,7 @@ get_manager_by_name(int argc, char **argv, int i)
 static void
 get_fromaddr_by_name(int argc, char **argv, int i)
 {
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
     struct addrinfo *ai = NULL;
     struct addrinfo *aifirst = NULL;
 #endif
@@ -1452,11 +1462,11 @@ get_fromaddr_by_name(int argc, char **argv, int i)
         FatalError("Xserver: missing -from host name in command line\n");
     }
     get_addr_by_name("-from", argv[i], 0, 0, &FromAddress, &FromAddressLen
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
                      , &ai, &aifirst
 #endif
         );
-#if defined(IPv6)
+#if defined(HAVE_GETADDRINFO)
     if (aifirst != NULL)
         freeaddrinfo(aifirst);
 #endif


More information about the xorg-commit mailing list