try to fix SMB_ASSERT(got_token)... TODO
[metze/samba/wip.git] / source3 / smbd / close.c
index 2252ce73d075fe5c1d4a7f2643f7a623631818a9..bdd177cca8f38eb43347cf9ed48eb437f85138da 100644 (file)
@@ -385,12 +385,6 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                }
        }
 
-       if (!del_share_mode(lck, fsp)) {
-               DEBUG(0, ("close_remove_share_mode: Could not delete share "
-                         "entry for file %s\n",
-                         fsp_str_dbg(fsp)));
-       }
-
        if (fsp->initial_delete_on_close &&
                        !is_delete_on_close_set(lck, fsp->name_hash)) {
                bool became_user = False;
@@ -420,6 +414,9 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                   POSIX delete now. */
                for (i=0; i<lck->data->num_share_modes; i++) {
                        struct share_mode_entry *e = &lck->data->share_modes[i];
+
+                       //TODO: continue if our own entry...
+
                        if (is_valid_share_mode_entry(e) &&
                                        e->name_hash == fsp->name_hash) {
                                if (fsp->posix_open && (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
@@ -445,6 +442,12 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
 
        if (!(close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) ||
                        !delete_file) {
+               if (!del_share_mode(lck, fsp)) {
+                       DEBUG(0, ("close_remove_share_mode: Could not delete share "
+                                 "entry for file %s\n",
+                                 fsp_str_dbg(fsp)));
+               }
+
                TALLOC_FREE(lck);
                return NT_STATUS_OK;
        }
@@ -564,6 +567,14 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                pop_sec_ctx();
        }
 
+       if (delete_file) {
+               if (!del_share_mode(lck, fsp)) {
+                       DEBUG(0, ("close_remove_share_mode: Could not delete share "
+                                 "entry for file %s\n",
+                                 fsp_str_dbg(fsp)));
+               }
+       }
+
        TALLOC_FREE(lck);
 
        if (delete_file) {
@@ -688,7 +699,6 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
        NTSTATUS status = NT_STATUS_OK;
        NTSTATUS tmp;
        connection_struct *conn = fsp->conn;
-       struct smbd_server_connection *sconn = conn->sconn;
        int ret;
 
        /*
@@ -701,71 +711,6 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
                        status, map_nt_error_from_unix(ret));
        }
 
-       if (close_type == SHUTDOWN_CLOSE && fsp->smbXsrv->global->durable) {
-               struct share_mode_lock *lck;
-
-               lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
-               if (lck != NULL && lck->data->num_share_modes == 1) {
-                       lck->data->share_modes[0].pid.pid = UINT64_MAX;
-                       lck->data->share_modes[0].pid.task_id = UINT32_MAX;
-                       lck->data->share_modes[0].pid.vnn = UINT32_MAX;
-                       lck->data->share_modes[0].pid.unique_id = UINT64_MAX; //todo place NTTIME expire timer here
-                       lck->data->modified = true;
-#if 0
-               } else if (lck != NULL) {
-                       uint32_t i;
-
-                       for (i=0; i < lck->data->num_share_modes; i++) {
-                               struct share_mode_entry *e = &lck->data->share_modes[i];
-                               char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
-
-                               if (procid_is_me(&e->pid)) {
-                                       continue;
-                               }
-
-                               share_mode_entry_to_message(msg, e);
-
-                               messaging_send_buf(fsp->conn->sconn->msg_ctx,
-                                                  e->pid,
-                                                  MSG_SMB_BREAK_RESPONSE,
-                                                  (uint8 *)msg,
-                                                  MSG_SMB_SHARE_MODE_ENTRY_SIZE);
-                       }
-               }
-#endif
-
-                       tmp = close_filestruct(fsp);
-                       status = ntstatus_keeperror(status, tmp);
-
-                       if (fsp->oplock_type == LEVEL_II_OPLOCK) {
-                               sconn->oplocks.level_II_open--;
-                       } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
-                               sconn->oplocks.exclusive_open--;
-                       }
-
-                       SMB_ASSERT(sconn->oplocks.exclusive_open>=0);
-                       SMB_ASSERT(sconn->oplocks.level_II_open>=0);
-
-                       TALLOC_FREE(lck);
-
-                       tmp = fd_close(fsp);
-                       status = ntstatus_keeperror(status, tmp);
-                       file_free(req, fsp);
-                       return status;
-               }
-
-               TALLOC_FREE(lck);
-
-#if 0
-               TALLOC_FREE(lck);
-
-               tmp = fd_close(fsp);
-               status = ntstatus_keeperror(status, tmp);
-               file_free(req, fsp);
-               return status;
-#endif
-       }
-
        /*
         * If we're flushing on a close we can get a write
         * error here, we must remember this.