1 xinetd: socket bind: Invalid argument (errno = 22) when using USERID on ipv6
3 Use right size of addresses in bind() call. Also use getpeername addresses when
4 connecting to ident service to prevent address family mismatch between socket(),
5 bind() and connect() calls.
7 Author: Jan Safranek <jsafrane@redhat.com>
8 Reviewed-By: Adam Tkac <atkac@redhat.com>
10 #diff -up xinetd-2.3.14/xinetd/ident.c.orig xinetd-2.3.14/xinetd/ident.c
13 @@ -97,7 +98,13 @@ idresult_e log_remote_user( const struct
17 - sin_remote = *CONN_XADDRESS( SERVER_CONNECTION( serp ) ) ;
19 + sin_len = sizeof( sin_remote );
20 + if ( getpeername( SERVER_FD( serp ), &sin_remote.sa, &sin_len ) == -1 )
22 + msg( LOG_ERR, func, "(%d) getpeername: %m", getpid() ) ;
23 + return( IDR_ERROR ) ;
25 sin_contact = sin_remote;
26 memcpy( &sin_bind, &sin_local, sizeof(sin_bind) ) ;
28 @@ -121,7 +128,13 @@ idresult_e log_remote_user( const struct
29 msg( LOG_ERR, func, "socket creation: %m" ) ;
32 - if ( bind(sd, &sin_bind.sa, sizeof(sin_bind.sa)) == -1 )
34 + if ( sin_bind.sa.sa_family == AF_INET )
35 + sin_len = sizeof( sin_bind.sa_in ) ;
37 + sin_len = sizeof( sin_bind.sa_in6 ) ;
39 + if ( bind(sd, &sin_bind.sa, sin_len) == -1 )
41 msg( LOG_ERR, func, "socket bind: %m" ) ;