diff options
author | Jeremy Allison <jra@samba.org> | 2009-02-26 11:43:07 -0800 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2009-03-06 08:28:27 +0100 |
commit | 57e5390105f40c1ed9167520a7ade967f0833c60 (patch) | |
tree | 599d60f78cdf0a95ad6bd9b95268f5e491aa53fa | |
parent | 108c1ea57996a286ff7046ec5e54a3a93e59007c (diff) | |
download | samba-57e5390105f40c1ed9167520a7ade967f0833c60.tar.gz samba-57e5390105f40c1ed9167520a7ade967f0833c60.tar.xz samba-57e5390105f40c1ed9167520a7ade967f0833c60.zip |
Make us pass the RAW-RENAME torture test I just added.
Inside a directory, keep a file open and then renaming
the directory should fail with ACCESS_DENIED.
Jeremy.
(cherry picked from commit eb02b1e7fe98f826606d0129b1ba172b8645207a)
-rw-r--r-- | source/include/proto.h | 1 | ||||
-rw-r--r-- | source/smbd/files.c | 43 | ||||
-rw-r--r-- | source/smbd/reply.c | 10 |
3 files changed, 54 insertions, 0 deletions
diff --git a/source/include/proto.h b/source/include/proto.h index 72d3ffe8f49..c008843299a 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -8906,6 +8906,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); +bool file_find_subpath(files_struct *dir_fsp); void file_sync_all(connection_struct *conn); void file_free(files_struct *fsp); files_struct *file_fnum(uint16 fnum); diff --git a/source/smbd/files.c b/source/smbd/files.c index 4e4004c80a8..cdaa5f11db5 100644 --- a/source/smbd/files.c +++ b/source/smbd/files.c @@ -377,6 +377,49 @@ files_struct *file_find_print(void) } /**************************************************************************** + 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. ****************************************************************************/ diff --git a/source/smbd/reply.c b/source/smbd/reply.c index 3eec795cd51..499b67fb9f8 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -2263,6 +2263,16 @@ static NTSTATUS can_rename(connection_struct *conn, files_struct *fsp, } 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; } |