Make us pass the RAW-RENAME torture test I just added.
authorJeremy Allison <jra@samba.org>
Thu, 26 Feb 2009 19:42:23 +0000 (11:42 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 26 Feb 2009 19:42:23 +0000 (11:42 -0800)
Inside a directory, keep a file open and then renaming
the directory should fail with ACCESS_DENIED.

Jeremy.

source3/include/proto.h
source3/smbd/files.c
source3/smbd/reply.c

index 27b4ce9604c713825f85982e4aeabf933ba46628..ce316402721b57a3971532bbdfa3256048fc70cf 100644 (file)
@@ -6520,6 +6520,7 @@ files_struct *file_find_fsp(files_struct *orig_fsp);
 files_struct *file_find_di_first(struct file_id id);
 files_struct *file_find_di_next(files_struct *start_fsp);
 files_struct *file_find_print(void);
 files_struct *file_find_di_first(struct file_id id);
 files_struct *file_find_di_next(files_struct *start_fsp);
 files_struct *file_find_print(void);
+bool file_find_subpath(files_struct *dir_fsp);
 void file_sync_all(connection_struct *conn);
 void file_free(struct smb_request *req, files_struct *fsp);
 files_struct *file_fnum(uint16 fnum);
 void file_sync_all(connection_struct *conn);
 void file_free(struct smb_request *req, files_struct *fsp);
 files_struct *file_fnum(uint16 fnum);
index efaadffc061cda7569db49ce9186d0af951f76d1..36e80a086ac26cb957c5f408442a2867f3f7c56a 100644 (file)
@@ -355,6 +355,49 @@ files_struct *file_find_print(void)
        return NULL;
 }
 
        return NULL;
 }
 
+/****************************************************************************
+ Find any fsp open with a pathname below that of an already open path.
+****************************************************************************/
+
+bool file_find_subpath(files_struct *dir_fsp)
+{
+       files_struct *fsp;
+       size_t dlen;
+       char *d_fullname = talloc_asprintf(talloc_tos(),
+                                       "%s/%s",
+                                       dir_fsp->conn->connectpath,
+                                       dir_fsp->fsp_name);
+
+       if (!d_fullname) {
+               return false;
+       }
+
+       dlen = strlen(d_fullname);
+
+       for (fsp=Files;fsp;fsp=fsp->next) {
+               char *d1_fullname;
+
+               if (fsp == dir_fsp) {
+                       continue;
+               }
+
+               d1_fullname = talloc_asprintf(talloc_tos(),
+                                       "%s/%s",
+                                       fsp->conn->connectpath,
+                                       fsp->fsp_name);
+
+               if (strnequal(d_fullname, d1_fullname, dlen)) {
+                       TALLOC_FREE(d_fullname);
+                       TALLOC_FREE(d1_fullname);
+                       return true;
+               }
+               TALLOC_FREE(d1_fullname);
+       } 
+
+       TALLOC_FREE(d_fullname);
+       return false;
+}
+
 /****************************************************************************
  Sync open files on a connection.
 ****************************************************************************/
 /****************************************************************************
  Sync open files on a connection.
 ****************************************************************************/
index 80ed019e0f0248f414878a0b4fbbfa4290dffb3c..22e4c1aad7fb6b50ef9f0bb633f9b68e3933f6da 100644 (file)
@@ -2214,6 +2214,16 @@ static NTSTATUS can_rename(connection_struct *conn, files_struct *fsp,
        }
 
        if (S_ISDIR(pst->st_mode)) {
        }
 
        if (S_ISDIR(pst->st_mode)) {
+               if (fsp->posix_open) {
+                       return NT_STATUS_OK;
+               }
+
+               /* If no pathnames are open below this
+                  directory, allow the rename. */
+
+               if (file_find_subpath(fsp)) {
+                       return NT_STATUS_ACCESS_DENIED;
+               }
                return NT_STATUS_OK;
        }
 
                return NT_STATUS_OK;
        }