From: Stefan Metzmacher Date: Fri, 3 Jul 2020 07:55:57 +0000 (+0200) Subject: s3:smbd: make sure smbXsrv_connection_disconnect_transport() closes the socket fd X-Git-Tag: samba-4.13.0rc1~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab14a0d162472899c081c1cb477ac6c888b44e5d;p=thirdparty%2Fsamba.git s3:smbd: make sure smbXsrv_connection_disconnect_transport() closes the socket fd I assumed that TALLOC_FREE(xconn->transport.fde) would close the socket, but until now we didn't use tevent_fd_set_auto_close(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=11898 Signed-off-by: Stefan Metzmacher Reviewed-by: Günther Deschner --- diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 651f72f33fc..011d8702291 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -3914,6 +3914,7 @@ NTSTATUS smbd_add_connection(struct smbXsrv_client *client, int sock_fd, TALLOC_FREE(frame); return NT_STATUS_NO_MEMORY; } + tevent_fd_set_auto_close(xconn->transport.fde); /* for now we only have one connection */ DLIST_ADD_END(client->connections, xconn); diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c index 4c26f822bd4..20ac3da34c6 100644 --- a/source3/smbd/smb2_server.c +++ b/source3/smbd/smb2_server.c @@ -231,8 +231,6 @@ bool smbd_smb2_is_compound(const struct smbd_smb2_request *req) static NTSTATUS smbd_initialize_smb2(struct smbXsrv_connection *xconn, uint64_t expected_seq_low) { - TALLOC_FREE(xconn->transport.fde); - xconn->smb2.credits.seq_low = expected_seq_low; xconn->smb2.credits.seq_range = 1; xconn->smb2.credits.granted = 1; @@ -243,6 +241,9 @@ static NTSTATUS smbd_initialize_smb2(struct smbXsrv_connection *xconn, return NT_STATUS_NO_MEMORY; } + tevent_fd_set_close_fn(xconn->transport.fde, NULL); + TALLOC_FREE(xconn->transport.fde); + xconn->transport.fde = tevent_add_fd( xconn->client->raw_ev_ctx, xconn, @@ -251,8 +252,11 @@ static NTSTATUS smbd_initialize_smb2(struct smbXsrv_connection *xconn, smbd_smb2_connection_handler, xconn); if (xconn->transport.fde == NULL) { + close(xconn->transport.sock); + xconn->transport.sock = -1; return NT_STATUS_NO_MEMORY; } + tevent_fd_set_auto_close(xconn->transport.fde); /* Ensure child is set to non-blocking mode */ set_blocking(xconn->transport.sock, false);