smbXsrv_client: move the connection passing to smb2srv_client_mc_negprot_send/recv
authorStefan Metzmacher <metze@samba.org>
Mon, 6 Jul 2020 15:27:05 +0000 (17:27 +0200)
committerJeremy Allison <jra@samba.org>
Sat, 6 Mar 2021 03:30:06 +0000 (03:30 +0000)
commitb145434f24f35a3d43d49980ef10bf59aae9243d
treeab7065298ad06fc3d778611119dc5599f757730a
parentf1f5c36581a942bcccd63ede4b023fdb1a1d3ed4
smbXsrv_client: move the connection passing to smb2srv_client_mc_negprot_send/recv

We need a full request/response pair in order to avoid races in
the multichannel connection passing.

smb2srv_client_mc_negprot_send/recv locks the
db record for the given client_guid.

If there's no entry found, we add ourself and
return NT_STATUS_OK.

If there's an existing process for that client guid
we start messaging_filtered_read_send()
dbwrap_watched_watch_send() before calling
smb2srv_client_connection_pass().

Then we release the lock and wait for either
MSG_SMBXSRV_CONNECTION_PASSED to arrive or
retry if dbwrap_watched_watch_recv signaled
a change in the database.

If we got MSG_SMBXSRV_CONNECTION_PASSED we'll
return NT_STATUS_MESSAGE_RETRIEVED in order to
signal that the other process will take care of
the connection and we terminate the current process.

All that is done completely async, which means that
the IDLE_CLOSED_TIMEOUT (60 seconds) may trigger
deadtime_fn(), which will send itself a MSG_SHUTDOWN.
So the process that accepted the tcp connection
exists if there was no MSG_SMBXSRV_CONNECTION_PASSED
within 60 seconds.

However the fd may still exists in the kernel (and
the new connection may still be handed to the other
process. If that process somehow exists before
there's no way to prevent a connection termination
for the client.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14433

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Mar  6 03:30:06 UTC 2021 on sn-devel-184
librpc/idl/messaging.idl
source3/librpc/idl/smbXsrv.idl
source3/smbd/globals.h
source3/smbd/smb2_negprot.c
source3/smbd/smbXsrv_client.c