s3:smbd/close: use talloc_get_type_abort() as private_data can't be NULL
[kai/samba.git] / source3 / smbd / close.c
index b31daf366f5ea2c767de6c26497594787ceba13e..9eedaf9e66bdd2ad81d0a6f506cef45200a5534b 100644 (file)
@@ -28,6 +28,7 @@
 #include "transfer_file.h"
 #include "auth.h"
 #include "messages.h"
+#include "../librpc/gen_ndr/open_files.h"
 
 /****************************************************************************
  Run a file if it is a magic script.
@@ -159,7 +160,7 @@ static NTSTATUS close_filestruct(files_struct *fsp)
  If any deferred opens are waiting on this close, notify them.
 ****************************************************************************/
 
-static void notify_deferred_opens(struct messaging_context *msg_ctx,
+static void notify_deferred_opens(struct smbd_server_connection *sconn,
                                  struct share_mode_lock *lck)
 {
        int i;
@@ -182,13 +183,14 @@ static void notify_deferred_opens(struct messaging_context *msg_ctx,
                         * the head of the queue and changing the wait time to
                         * zero.
                         */
-                       schedule_deferred_open_message_smb(e->op_mid);
+                       schedule_deferred_open_message_smb(sconn, e->op_mid);
                } else {
                        char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
 
                        share_mode_entry_to_message(msg, e);
 
-                       messaging_send_buf(msg_ctx, e->pid, MSG_SMB_OPEN_RETRY,
+                       messaging_send_buf(sconn->msg_ctx, e->pid,
+                                          MSG_SMB_OPEN_RETRY,
                                           (uint8 *)msg,
                                           MSG_SMB_SHARE_MODE_ENTRY_SIZE);
                }
@@ -201,14 +203,14 @@ static void notify_deferred_opens(struct messaging_context *msg_ctx,
 
 NTSTATUS delete_all_streams(connection_struct *conn, const char *fname)
 {
-       struct stream_struct *stream_info;
+       struct stream_struct *stream_info = NULL;
        int i;
-       unsigned int num_streams;
+       unsigned int num_streams = 0;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
 
-       status = SMB_VFS_STREAMINFO(conn, NULL, fname, talloc_tos(),
-                                   &num_streams, &stream_info);
+       status = vfs_streaminfo(conn, NULL, fname, talloc_tos(),
+                               &num_streams, &stream_info);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
                DEBUG(10, ("no streams around\n"));
@@ -217,7 +219,7 @@ NTSTATUS delete_all_streams(connection_struct *conn, const char *fname)
        }
 
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(10, ("SMB_VFS_STREAMINFO failed: %s\n",
+               DEBUG(10, ("vfs_streaminfo failed: %s\n",
                           nt_errstr(status)));
                goto fail;
        }
@@ -283,7 +285,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
 
        /* Ensure any pending write time updates are done. */
        if (fsp->update_write_time_event) {
-               update_write_time_handler(server_event_context(),
+               update_write_time_handler(fsp->conn->sconn->ev_ctx,
                                        fsp->update_write_time_event,
                                        timeval_current(),
                                        (void *)fsp);
@@ -372,7 +374,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
        }
 
        /* Notify any deferred opens waiting on this close. */
-       notify_deferred_opens(conn->sconn->msg_ctx, lck);
+       notify_deferred_opens(conn->sconn, lck);
        reply_to_oplock_break_requests(fsp);
 
        /*
@@ -576,11 +578,9 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
        }
 
        ft.mtime = fsp->close_write_time;
-       /* We must use NULL for the fsp handle here, as smb_set_file_time()
-          checks the fsp access_mask, which may not include FILE_WRITE_ATTRIBUTES.
-          As this is a close based update, we are not directly changing the
+       /* As this is a close based update, we are not directly changing the
           file attributes from a client call, but indirectly from a write. */
-       status = smb_set_file_time(fsp->conn, NULL, fsp->fsp_name, &ft, false);
+       status = smb_set_file_time(fsp->conn, fsp, fsp->fsp_name, &ft, false);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10,("update_write_time_on_close: smb_set_file_time "
                        "on file %s returned %s\n",
@@ -1134,15 +1134,11 @@ void msg_close_file(struct messaging_context *msg_ctx,
                        struct server_id server_id,
                        DATA_BLOB *data)
 {
-       struct smbd_server_connection *sconn;
        files_struct *fsp = NULL;
        struct share_mode_entry e;
-
-       sconn = msg_ctx_to_sconn(msg_ctx);
-       if (sconn == NULL) {
-               DEBUG(1, ("could not find sconn\n"));
-               return;
-       }
+       struct smbd_server_connection *sconn =
+               talloc_get_type_abort(private_data,
+               struct smbd_server_connection);
 
        message_to_share_mode_entry(&e, (char *)data->data);