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

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