Blame SOURCES/xinetd-2.3.14-ident-bind.patch

76ef8a
448069: xinetd: socket bind: Invalid argument (errno = 22) when using USERID on ipv6
76ef8a
76ef8a
Use right size of addresses in bind() call. Also use getpeername addresses when
76ef8a
connecting to ident service to prevent address family mismatch between socket(),
76ef8a
bind() and connect() calls.
76ef8a
76ef8a
Author: Jan Safranek <jsafrane@redhat.com>
76ef8a
Reviewed-By: Adam Tkac <atkac@redhat.com>
76ef8a
76ef8a
diff -up xinetd-2.3.14/xinetd/ident.c.orig xinetd-2.3.14/xinetd/ident.c
76ef8a
--- xinetd-2.3.14/xinetd/ident.c.orig	2008-05-29 16:30:19.000000000 +0200
76ef8a
+++ xinetd-2.3.14/xinetd/ident.c	2008-05-29 16:29:57.000000000 +0200
76ef8a
@@ -97,7 +98,13 @@ idresult_e log_remote_user( const struct
76ef8a
    }
76ef8a
 
76ef8a
    CLEAR( sin_contact );
76ef8a
-   sin_remote = *CONN_XADDRESS( SERVER_CONNECTION( serp ) ) ;
76ef8a
+
76ef8a
+   sin_len = sizeof( sin_remote );
76ef8a
+   if ( getpeername( SERVER_FD( serp ), &sin_remote.sa, &sin_len ) == -1 )
76ef8a
+   {
76ef8a
+      msg( LOG_ERR, func, "(%d) getpeername: %m", getpid() ) ;
76ef8a
+      return( IDR_ERROR ) ;
76ef8a
+   }
76ef8a
    sin_contact = sin_remote;
76ef8a
    memcpy( &sin_bind, &sin_local, sizeof(sin_bind) ) ;
76ef8a
    local_port = 0;
76ef8a
@@ -121,7 +128,13 @@ idresult_e log_remote_user( const struct
76ef8a
       msg( LOG_ERR, func, "socket creation: %m" ) ;
76ef8a
       return( IDR_ERROR ) ;
76ef8a
    }
76ef8a
-   if ( bind(sd, &sin_bind.sa, sizeof(sin_bind.sa)) == -1 )
76ef8a
+
76ef8a
+   if ( sin_bind.sa.sa_family == AF_INET ) 
76ef8a
+      sin_len = sizeof( sin_bind.sa_in ) ;
76ef8a
+   else
76ef8a
+      sin_len = sizeof( sin_bind.sa_in6 ) ;
76ef8a
+
76ef8a
+   if ( bind(sd, &sin_bind.sa, sin_len) == -1 )
76ef8a
    { 
76ef8a
       msg( LOG_ERR, func, "socket bind: %m" ) ;
76ef8a
       (void) Sclose( sd ) ;