smbd: No base fsps to close_file_free() from file_close_user()
authorVolker Lendecke <vl@samba.org>
Wed, 2 Feb 2022 07:58:15 +0000 (08:58 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 10 Feb 2022 18:16:36 +0000 (18:16 +0000)
Same logic as the change for file_close_conn()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/files.c

index da3f3dc29beb0b01e81f189a83b2a2c3a0556277..917f854aa7eaafe9a3833d755ae3e4c9702598bb 100644 (file)
@@ -912,15 +912,40 @@ bool file_init(struct smbd_server_connection *sconn)
  Close files open by a specified vuid.
 ****************************************************************************/
 
+struct file_close_user_state {
+       uint64_t vuid;
+       bool fsp_left_behind;
+};
+
+static struct files_struct *file_close_user_fn(
+       struct files_struct *fsp,
+       void *private_data)
+{
+       struct file_close_user_state *state = private_data;
+       bool did_close;
+
+       if (fsp->vuid != state->vuid) {
+               return NULL;
+       }
+
+       did_close = close_file_in_loop(fsp);
+       if (!did_close) {
+               state->fsp_left_behind = true;
+       }
+
+       return NULL;
+}
+
 void file_close_user(struct smbd_server_connection *sconn, uint64_t vuid)
 {
-       files_struct *fsp, *next;
+       struct file_close_user_state state = { .vuid = vuid };
 
-       for (fsp=sconn->files; fsp; fsp=next) {
-               next=fsp->next;
-               if (fsp->vuid == vuid) {
-                       close_file_free(NULL, &fsp, SHUTDOWN_CLOSE);
-               }
+       files_forall(sconn, file_close_user_fn, &state);
+
+       if (state.fsp_left_behind) {
+               state.fsp_left_behind = false;
+               files_forall(sconn, file_close_user_fn, &state);
+               SMB_ASSERT(!state.fsp_left_behind);
        }
 }