s3: smbd: Plumb close_type parameter through close_file_in_loop(), file_close_conn()
authorJeremy Allison <jra@samba.org>
Wed, 17 Aug 2022 18:43:47 +0000 (11:43 -0700)
committerJule Anger <janger@samba.org>
Tue, 23 Aug 2022 07:45:16 +0000 (07:45 +0000)
Allows close_file_in_loop() to differentiate between SHUTDOWN_CLOSE
(previously it only used this close type) and ERROR_CLOSE - called
on error from smbXsrv_tcon_disconnect() in the error path. In that
case we want to close the fd, but not run any delete-on-close actions.

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

Signed-off-by: Jeremy Allison <jra@samba.org>
Reivewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Noel Power <npower@samba.org>
Autobuild-Date(master): Thu Aug 18 14:10:18 UTC 2022 on sn-devel-184

(cherry picked from commit cf5f7b1489930f6d64c3e3512f116ccf286d4605)

source3/smbd/files.c

index 7996d62bc91474145645b2256a820460341d9cfa..e2591b4d77da0e4e95e1a8315f74b46c5431fc40 100644 (file)
@@ -752,7 +752,8 @@ NTSTATUS parent_pathref(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
-static bool close_file_in_loop(struct files_struct *fsp)
+static bool close_file_in_loop(struct files_struct *fsp,
+                              enum file_close_type close_type)
 {
        if (fsp->base_fsp != NULL) {
                /*
@@ -770,7 +771,7 @@ static bool close_file_in_loop(struct files_struct *fsp)
                fsp->base_fsp->stream_fsp = NULL;
                fsp->base_fsp = NULL;
 
-               close_file_free(NULL, &fsp, SHUTDOWN_CLOSE);
+               close_file_free(NULL, &fsp, close_type);
                return NULL;
        }
 
@@ -794,7 +795,7 @@ static bool close_file_in_loop(struct files_struct *fsp)
                return false;
        }
 
-       close_file_free(NULL, &fsp, SHUTDOWN_CLOSE);
+       close_file_free(NULL, &fsp, close_type);
        return true;
 }
 
@@ -804,6 +805,7 @@ static bool close_file_in_loop(struct files_struct *fsp)
 
 struct file_close_conn_state {
        struct connection_struct *conn;
+       enum file_close_type close_type;
        bool fsp_left_behind;
 };
 
@@ -825,7 +827,7 @@ static struct files_struct *file_close_conn_fn(
                fsp->op->global->durable = false;
        }
 
-       did_close = close_file_in_loop(fsp);
+       did_close = close_file_in_loop(fsp, state->close_type);
        if (!did_close) {
                state->fsp_left_behind = true;
        }
@@ -835,7 +837,8 @@ static struct files_struct *file_close_conn_fn(
 
 void file_close_conn(connection_struct *conn, enum file_close_type close_type)
 {
-       struct file_close_conn_state state = { .conn = conn };
+       struct file_close_conn_state state = { .conn = conn,
+                                              .close_type = close_type };
 
        files_forall(conn->sconn, file_close_conn_fn, &state);
 
@@ -921,7 +924,7 @@ static struct files_struct *file_close_user_fn(
                return NULL;
        }
 
-       did_close = close_file_in_loop(fsp);
+       did_close = close_file_in_loop(fsp, SHUTDOWN_CLOSE);
        if (!did_close) {
                state->fsp_left_behind = true;
        }