From 1d20e0608e48e44344f76bcc23bd00e6fc87a913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 22 Nov 2004 20:30:24 +0000 Subject: [PATCH] Inode::Create() allowed to create a symlink "above" a file. Also, it did not check the access permissions if the file already existed. Removed check for INODE_NO_CACHE, as this no longer applies. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10184 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index 08f42772cc..a8c40dc04e 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -2081,7 +2081,7 @@ Inode::Remove(Transaction &transaction, const char *name, off_t *_id, bool isDir status_t Inode::Create(Transaction &transaction, Inode *parent, const char *name, int32 mode, - int omode, uint32 type, off_t *_id, Inode **_inode) + int openMode, uint32 type, off_t *_id, Inode **_inode) { FUNCTION(); @@ -2101,8 +2101,8 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, int32 m // does the file already exist? off_t offset; if (tree->Find((uint8 *)name, (uint16)strlen(name), &offset) == B_OK) { - // return if the file should be a directory or opened in exclusive mode - if (mode & S_DIRECTORY || omode & O_EXCL) + // return if the file should be a directory/link or opened in exclusive mode + if (S_ISDIR(mode) || S_ISLNK(mode) || openMode & O_EXCL) return B_FILE_EXISTS; Vnode vnode(volume, offset); @@ -2117,13 +2117,12 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, int32 m if (inode->IsDirectory()) return B_IS_A_DIRECTORY; - // if it is a mounted device or the VM file, we don't allow to delete it - // while it is open and in use - if (inode->Flags() & INODE_NO_CACHE) + // we want to open the file, so we should have the rights to do so + if (inode->CheckPermissions(openModeToAccess(openMode)) != B_OK) return B_NOT_ALLOWED; - // if omode & O_TRUNC, truncate the existing file - if (omode & O_TRUNC) { + if (openMode & O_TRUNC) { + // truncate the existing file WriteLocked locked(inode->Lock()); status_t status = inode->SetFileSize(transaction, 0);