s3: smbd: Reformat calls to is_visible_file() to one arg per line.
[amitay/samba.git] / source3 / smbd / close.c
index f45371e656c70887c51caf3a32dd5be4fb574b03..42aedff6a785367906a8ee59e634306eab7005c4 100644 (file)
@@ -31,6 +31,7 @@
 #include "auth.h"
 #include "messages.h"
 #include "../librpc/gen_ndr/open_files.h"
+#include "lib/util/tevent_ntstatus.h"
 
 /****************************************************************************
  Run a file if it is a magic script.
@@ -312,7 +313,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                remove_oplock(fsp);
        }
 
-       if (fsp->write_time_forced) {
+       if (fsp->fsp_flags.write_time_forced) {
                struct timespec ts;
 
                DEBUG(10,("close_remove_share_mode: write time forced "
@@ -320,7 +321,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                        fsp_str_dbg(fsp)));
                ts = nt_time_to_full_timespec(lck->data->changed_write_time);
                set_close_write_time(fsp, ts);
-       } else if (fsp->update_write_time_on_close) {
+       } else if (fsp->fsp_flags.update_write_time_on_close) {
                /* Someone had a pending write. */
                if (is_omit_timespec(&fsp->close_write_time)) {
                        DEBUG(10,("close_remove_share_mode: update to current time "
@@ -337,7 +338,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                }
        }
 
-       if (fsp->initial_delete_on_close &&
+       if (fsp->fsp_flags.initial_delete_on_close &&
                        !is_delete_on_close_set(lck, fsp->name_hash)) {
                bool became_user = False;
 
@@ -348,7 +349,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                        become_user_without_service(conn, fsp->vuid);
                        became_user = True;
                }
-               fsp->delete_on_close = true;
+               fsp->fsp_flags.delete_on_close = true;
                set_delete_on_close_lck(fsp, lck,
                                get_current_nttok(conn),
                                get_current_utok(conn));
@@ -382,7 +383,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
        /*
         * Don't try to update the write time when we delete the file
         */
-       fsp->update_write_time_on_close = false;
+       fsp->fsp_flags.update_write_time_on_close = false;
 
        got_tokens = get_delete_on_close_token(lck, fsp->name_hash,
                                        &del_nt_token, &del_token);
@@ -454,7 +455,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                }
        }
 
-       if (fsp->kernel_share_modes_taken) {
+       if (fsp->fsp_flags.kernel_share_modes_taken) {
                int ret_flock;
 
                /*
@@ -467,7 +468,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                                  fsp_str_dbg(fsp), strerror(errno));
                }
 
-               fsp->kernel_share_modes_taken = false;
+               fsp->fsp_flags.kernel_share_modes_taken = false;
        }
 
 
@@ -498,7 +499,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
         * the delete on close flag. JRA.
         */
 
-       fsp->delete_on_close = false;
+       fsp->fsp_flags.delete_on_close = false;
        reset_delete_on_close_lck(fsp, lck);
 
  done:
@@ -508,7 +509,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                pop_sec_ctx();
        }
 
-       if (fsp->kernel_share_modes_taken) {
+       if (fsp->fsp_flags.kernel_share_modes_taken) {
                int ret_flock;
 
                /* remove filesystem sharemodes */
@@ -554,8 +555,8 @@ void set_close_write_time(struct files_struct *fsp, struct timespec ts)
        if (is_omit_timespec(&ts)) {
                return;
        }
-       fsp->write_time_forced = false;
-       fsp->update_write_time_on_close = true;
+       fsp->fsp_flags.write_time_forced = false;
+       fsp->fsp_flags.update_write_time_on_close = true;
        fsp->close_write_time = ts;
 }
 
@@ -567,7 +568,7 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
 
        init_smb_file_time(&ft);
 
-       if (!fsp->update_write_time_on_close) {
+       if (!(fsp->fsp_flags.update_write_time_on_close)) {
                return NT_STATUS_OK;
        }
 
@@ -635,6 +636,20 @@ static NTSTATUS ntstatus_keeperror(NTSTATUS s1, NTSTATUS s2)
        return s2;
 }
 
+static void assert_no_pending_aio(struct files_struct *fsp,
+                                 enum file_close_type close_type)
+{
+       unsigned num_requests = fsp->num_aio_requests;
+
+       if (num_requests == 0) {
+               return;
+       }
+
+       DBG_ERR("fsp->num_aio_requests=%u\n", num_requests);
+       smb_panic("can not close with outstanding aio requests");
+       return;
+}
+
 /****************************************************************************
  Close a file.
 
@@ -651,45 +666,7 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
        connection_struct *conn = fsp->conn;
        bool is_durable = false;
 
-       if (fsp->num_aio_requests != 0) {
-
-               if (close_type != SHUTDOWN_CLOSE) {
-                       /*
-                        * reply_close and the smb2 close must have
-                        * taken care of this. No other callers of
-                        * close_file should ever have created async
-                        * I/O.
-                        *
-                        * We need to panic here because if we close()
-                        * the fd while we have outstanding async I/O
-                        * requests, in the worst case we could end up
-                        * writing to the wrong file.
-                        */
-                       DEBUG(0, ("fsp->num_aio_requests=%u\n",
-                                 fsp->num_aio_requests));
-                       smb_panic("can not close with outstanding aio "
-                                 "requests");
-               }
-
-               /*
-                * For shutdown close, just drop the async requests
-                * including a potential close request pending for
-                * this fsp. Drop the close request first, the
-                * destructor for the aio_requests would execute it.
-                */
-               TALLOC_FREE(fsp->deferred_close);
-
-               while (fsp->num_aio_requests != 0) {
-                       /*
-                        * The destructor of the req will remove
-                        * itself from the fsp.
-                        * Don't use TALLOC_FREE here, this will overwrite
-                        * what the destructor just wrote into
-                        * aio_requests[0].
-                        */
-                       talloc_free(fsp->aio_requests[0]);
-               }
-       }
+       assert_no_pending_aio(fsp, close_type);
 
        while (talloc_array_length(fsp->blocked_smb1_lock_reqs) != 0) {
                smbd_smb1_brl_finish_by_req(
@@ -855,8 +832,11 @@ bool recursive_rmdir(TALLOC_CTX *ctx,
                        continue;
                }
 
-               if (!is_visible_file(conn, smb_dname->base_name, dname, &st,
-                                    false)) {
+               if (!is_visible_file(conn,
+                                       smb_dname,
+                                       dname,
+                                       &st,
+                                       false)) {
                        TALLOC_FREE(talloced);
                        continue;
                }
@@ -992,8 +972,11 @@ static NTSTATUS rmdir_internals(TALLOC_CTX *ctx, files_struct *fsp)
                                TALLOC_FREE(talloced);
                                continue;
                        }
-                       if (!is_visible_file(conn, smb_dname->base_name, dname,
-                                            &st, false)) {
+                       if (!is_visible_file(conn,
+                                               smb_dname,
+                                               dname,
+                                               &st,
+                                               false)) {
                                TALLOC_FREE(talloced);
                                continue;
                        }
@@ -1027,8 +1010,11 @@ static NTSTATUS rmdir_internals(TALLOC_CTX *ctx, files_struct *fsp)
                                TALLOC_FREE(talloced);
                                continue;
                        }
-                       if (!is_visible_file(conn, smb_dname->base_name, dname,
-                                            &st, false)) {
+                       if (!is_visible_file(conn,
+                                               smb_dname,
+                                               dname,
+                                               &st,
+                                               false)) {
                                TALLOC_FREE(talloced);
                                continue;
                        }
@@ -1134,30 +1120,7 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
                notify_status = NT_STATUS_OK;
        }
 
-       if (fsp->num_aio_requests != 0) {
-               if (close_type != SHUTDOWN_CLOSE) {
-                       /*
-                        * We panic here because if we close() the fd while we
-                        * have outstanding async I/O requests, an async IO
-                        * request might use the fd. For directories the fd is
-                        * read-only, so this is not as bad as with files, but
-                        * still, better safe then sorry.
-                        */
-                       DBG_ERR("fsp->num_aio_requests=%u\n",
-                               fsp->num_aio_requests);
-                       smb_panic("close with outstanding aio requests");
-                       return NT_STATUS_INTERNAL_ERROR;
-               }
-
-               while (fsp->num_aio_requests != 0) {
-                       /*
-                        * The destructor of the req will remove itself from the
-                        * fsp.  Don't use TALLOC_FREE here, this will overwrite
-                        * what the destructor just wrote into aio_requests[0].
-                        */
-                       talloc_free(fsp->aio_requests[0]);
-               }
-       }
+       assert_no_pending_aio(fsp, close_type);
 
        /*
         * NT can set delete_on_close of the last open
@@ -1172,7 +1135,7 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       if (fsp->initial_delete_on_close) {
+       if (fsp->fsp_flags.initial_delete_on_close) {
                bool became_user = False;
 
                /* Initial delete on close was set - for
@@ -1188,7 +1151,7 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
                set_delete_on_close_lck(fsp, lck,
                                get_current_nttok(fsp->conn),
                                get_current_utok(fsp->conn));
-               fsp->delete_on_close = true;
+               fsp->fsp_flags.delete_on_close = true;
                if (became_user) {
                        unbecome_user_without_service();
                }
@@ -1289,7 +1252,7 @@ NTSTATUS close_file(struct smb_request *req, files_struct *fsp,
        NTSTATUS status;
        struct files_struct *base_fsp = fsp->base_fsp;
 
-       if(fsp->is_directory) {
+       if (fsp->fsp_flags.is_directory) {
                status = close_directory(req, fsp, close_type);
        } else if (fsp->fake_file_handle != NULL) {
                status = close_fake_file(req, fsp);