* fhandler.h (enum conn_state): Add "connect_credxchg" state.

(class fhandler_socket): Grant another bit to connect_state flag.
	* fhandler_socket.cc (fhandler_socket::af_local_connect): Rearrange
	variable definition.  Set connect_state to connect_credxchg.
	(fhandler_socket::af_local_accept): Ditto.
	(fhandler_socket::recv_internal): Accept connect_credxchg on connection
	oriented AF_LOCAL sockets as well to allow the credential exchange.
	Extend comment to explain.
This commit is contained in:
Corinna Vinschen
2014-08-19 09:47:12 +00:00
parent 67986ac4a4
commit de1c312566
3 changed files with 31 additions and 9 deletions

View File

@@ -396,12 +396,14 @@ fhandler_socket::af_local_send_cred ()
int
fhandler_socket::af_local_connect ()
{
bool orig_async_io, orig_is_nonblocking;
/* This keeps the test out of select. */
if (get_addr_family () != AF_LOCAL || get_socket_type () != SOCK_STREAM)
return 0;
debug_printf ("af_local_connect called");
bool orig_async_io, orig_is_nonblocking;
connect_state (connect_credxchg);
af_local_setblocking (orig_async_io, orig_is_nonblocking);
if (!af_local_send_secret () || !af_local_recv_secret ()
|| !af_local_send_cred () || !af_local_recv_cred ())
@@ -418,8 +420,10 @@ fhandler_socket::af_local_connect ()
int
fhandler_socket::af_local_accept ()
{
debug_printf ("af_local_accept called");
bool orig_async_io, orig_is_nonblocking;
debug_printf ("af_local_accept called");
connect_state (connect_credxchg);
af_local_setblocking (orig_async_io, orig_is_nonblocking);
if (!af_local_recv_secret () || !af_local_send_secret ()
|| !af_local_recv_cred () || !af_local_send_cred ())
@@ -1402,8 +1406,14 @@ fhandler_socket::recv_internal (LPWSAMSG wsamsg, bool use_recvmsg)
int orig_namelen = wsamsg->namelen;
/* Windows event handling does not check for the validity of the desired
flags so we have to do it here. */
if (get_socket_type () == SOCK_STREAM && connect_state () != connected)
flags so we have to do it here.
The check goes like this:
STREAM sockets must be either connected, or they are AF_LOCAL
sockets in the pre-connected credential exchange phase.
All other states are disallowed. */
if (get_socket_type () == SOCK_STREAM && connect_state () != connected
&& (get_addr_family () != AF_LOCAL
|| connect_state () != connect_credxchg))
{
WSASetLastError (WSAENOTCONN);
set_winsock_errno ();