summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-02 12:30:24 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-02 12:52:21 +0200
commite67bfdb7f664dc25f73fba158ce377c9a96f3940 (patch)
treee8bbd1570f968ac8e61128e764e3255baec7ec96 /Kernel
parentaa35c08633e6fe904afbcff2a335675c25d24bab (diff)
downloadserenity-e67bfdb7f664dc25f73fba158ce377c9a96f3940.zip
FileSystem: Route chown() and fchown() through VFS for access control.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/FileDescriptor.cpp2
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp18
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.h1
3 files changed, 13 insertions, 8 deletions
diff --git a/Kernel/FileSystem/FileDescriptor.cpp b/Kernel/FileSystem/FileDescriptor.cpp
index 1f2f0dec31..b807df44fd 100644
--- a/Kernel/FileSystem/FileDescriptor.cpp
+++ b/Kernel/FileSystem/FileDescriptor.cpp
@@ -329,5 +329,5 @@ KResult FileDescriptor::chown(uid_t uid, gid_t gid)
{
if (!m_inode)
return KResult(-EINVAL);
- return m_inode->chown(uid, gid);
+ return VFS::the().chown(*m_inode, uid, gid);
}
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index 820ad65def..fca73d4728 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -402,14 +402,8 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
return KSuccess;
}
-KResult VFS::chown(StringView path, uid_t a_uid, gid_t a_gid, Custody& base)
+KResult VFS::chown(Inode& inode, uid_t a_uid, gid_t a_gid)
{
- auto custody_or_error = resolve_path(path, base);
- if (custody_or_error.is_error())
- return custody_or_error.error();
- auto& custody = *custody_or_error.value();
- auto& inode = custody.inode();
-
if (inode.fs().is_readonly())
return KResult(-EROFS);
@@ -436,6 +430,16 @@ KResult VFS::chown(StringView path, uid_t a_uid, gid_t a_gid, Custody& base)
return inode.chown(new_uid, new_gid);
}
+KResult VFS::chown(StringView path, uid_t a_uid, gid_t a_gid, Custody& base)
+{
+ auto custody_or_error = resolve_path(path, base);
+ if (custody_or_error.is_error())
+ return custody_or_error.error();
+ auto& custody = *custody_or_error.value();
+ auto& inode = custody.inode();
+ return chown(inode, a_uid, a_gid);
+}
+
KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
{
auto old_custody_or_error = resolve_path(old_path, base);
diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h
index 238a2cff03..548d860fa3 100644
--- a/Kernel/FileSystem/VirtualFileSystem.h
+++ b/Kernel/FileSystem/VirtualFileSystem.h
@@ -70,6 +70,7 @@ public:
KResult chmod(StringView path, mode_t, Custody& base);
KResult fchmod(Inode&, mode_t);
KResult chown(StringView path, uid_t, gid_t, Custody& base);
+ KResult chown(Inode&, uid_t, gid_t);
KResult access(StringView path, int mode, Custody& base);
KResult stat(StringView path, int options, Custody& base, struct stat&);
KResult utime(StringView path, Custody& base, time_t atime, time_t mtime);