]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:smbd: make sure smbXsrv_connection_disconnect_transport() closes the socket fd
authorStefan Metzmacher <metze@samba.org>
Fri, 3 Jul 2020 07:55:57 +0000 (09:55 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 8 Jul 2020 15:54:41 +0000 (15:54 +0000)
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 <metze@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
source3/smbd/process.c
source3/smbd/smb2_server.c

index 651f72f33fcdecff732399de446091a79a0ccb9f..011d87022913de9b33a708848a07be123e17770c 100644 (file)
@@ -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);
index 4c26f822bd4d4dd9672cdace5c21001f79f548df..20ac3da34c6f50f73f7e16e6b296f47cb494c30c 100644 (file)
@@ -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);