try to fix SMB_ASSERT(got_token)... TODO
[metze/samba/wip.git] / source3 / smbd / close.c
index 22d756c5c126907181353b4959c6f554a9862063..bdd177cca8f38eb43347cf9ed48eb437f85138da 100644 (file)
@@ -179,9 +179,15 @@ static void notify_deferred_opens(struct smbd_server_connection *sconn,
 
        num_deferred = 0;
        for (i=0; i<lck->data->num_share_modes; i++) {
-               if (is_deferred_open_entry(&lck->data->share_modes[i])) {
-                       num_deferred += 1;
+               struct share_mode_entry *e = &lck->data->share_modes[i];
+
+               if (!is_deferred_open_entry(e)) {
+                       continue;
+               }
+               if (share_mode_stale_pid(lck->data, i)) {
+                       continue;
                }
+               num_deferred += 1;
        }
        if (num_deferred == 0) {
                return;
@@ -379,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;
@@ -414,11 +414,17 @@ 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)) {
                                        continue;
                                }
+                               if (share_mode_stale_pid(lck->data, i)) {
+                                       continue;
+                               }
                                delete_file = False;
                                break;
                        }
@@ -436,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;
        }
@@ -555,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) {
@@ -1081,6 +1101,9 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
                                if (fsp->posix_open && (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
                                        continue;
                                }
+                               if (share_mode_stale_pid(lck->data, i)) {
+                                       continue;
+                               }
                                delete_dir = False;
                                break;
                        }