1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

smbd: let smbd_server_connection_terminate_ex() always go through smbXsrv_connection_shutdown_send()

This ensures common cleanup code via

  smbXsrv_connection_shutdown_send() ->
  -> smbXsrv_session_disconnect_xconn()
  -> smbXsrv_session_remove_channel()
  -> smb2srv_session_shutdown_send()

is used if the last (only) connection goes away as well. In the future this
should be implemented for the

  xconn->has_cluster_movable_ip

case.

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

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
Ralph Boehme 2024-09-28 16:44:31 +02:00
parent ee5d3c63f6
commit f86208d272
2 changed files with 43 additions and 22 deletions

View File

@ -1,2 +1 @@
^samba3.smb2.lease.initial_delete_disconnect\(fileserver\)
^samba3.smb2.lease.initial_delete_tdis\(fileserver\)

View File

@ -1721,12 +1721,21 @@ static NTSTATUS smbXsrv_connection_shutdown_recv(struct tevent_req *req)
return tevent_req_simple_recv_ntstatus(req);
}
struct smbd_server_connection_terminate_state {
struct smbXsrv_connection *xconn;
char *reason;
};
static void smbd_server_connection_terminate_done(struct tevent_req *subreq)
{
struct smbXsrv_connection *xconn =
tevent_req_callback_data(subreq,
struct smbXsrv_connection);
struct smbd_server_connection_terminate_state *state =
tevent_req_callback_data(
subreq,
struct smbd_server_connection_terminate_state);
struct smbXsrv_connection *xconn = state->xconn;
struct smbXsrv_client *client = xconn->client;
const char *reason = state->reason;
size_t num_ok;
NTSTATUS status;
status = smbXsrv_connection_shutdown_recv(subreq);
@ -1737,15 +1746,37 @@ static void smbd_server_connection_terminate_done(struct tevent_req *subreq)
DLIST_REMOVE(client->connections, xconn);
TALLOC_FREE(xconn);
num_ok = smbXsrv_client_valid_connections(client);
if (num_ok > 0) {
return;
}
/*
* The last connection was disconnected
*/
exit_server_cleanly(reason);
}
void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
const char *reason,
const char *location)
{
struct smbd_server_connection_terminate_state *state = NULL;
struct smbXsrv_client *client = xconn->client;
struct tevent_req *subreq = NULL;
size_t num_ok = 0;
state = talloc_zero(xconn, struct smbd_server_connection_terminate_state);
if (state == NULL) {
exit_server("smbXsrv_connection_shutdown_send failed");
}
state->xconn = xconn;
state->reason = talloc_strdup(state, reason);
if (state->reason == NULL) {
exit_server("talloc_strdup failed");
}
/*
* Make sure that no new request will be able to use this session.
*
@ -1785,25 +1816,16 @@ void smbd_server_connection_terminate_ex(struct smbXsrv_connection *xconn,
return;
}
if (num_ok != 0) {
struct tevent_req *subreq = NULL;
subreq = smbXsrv_connection_shutdown_send(client,
client->raw_ev_ctx,
xconn);
if (subreq == NULL) {
exit_server("smbXsrv_connection_shutdown_send failed");
}
tevent_req_set_callback(subreq,
smbd_server_connection_terminate_done,
xconn);
return;
subreq = smbXsrv_connection_shutdown_send(client,
client->raw_ev_ctx,
xconn);
if (subreq == NULL) {
exit_server("smbXsrv_connection_shutdown_send failed");
}
/*
* The last connection was disconnected
*/
exit_server_cleanly(reason);
tevent_req_set_callback(subreq,
smbd_server_connection_terminate_done,
state);
return;
}
void smbd_server_disconnect_client_ex(struct smbXsrv_client *client,