VFS: Implement sticky bit behavior for rename() and unlink().

Removing entries from a sticky directory is only allowed when you are either
the owner of the entry, or the superuser. :^)
This commit is contained in:
Andreas Kling 2019-04-28 22:54:30 +02:00
parent a104d7cc93
commit e4eca17848

View file

@ -326,6 +326,11 @@ KResult VFS::rename(StringView old_path, StringView new_path, Inode& base)
if (!old_parent_inode->metadata().may_write(current->process()))
return KResult(-EACCES);
if (old_parent_inode->metadata().is_sticky()) {
if (!current->process().is_superuser() && old_inode->metadata().uid != current->process().euid())
return KResult(-EACCES);
}
if (!new_inode_or_error.is_error()) {
auto new_inode = new_inode_or_error.value();
// FIXME: Is this really correct? Check what other systems do.
@ -436,6 +441,11 @@ KResult VFS::unlink(StringView path, Inode& base)
if (!parent_inode->metadata().may_write(current->process()))
return KResult(-EACCES);
if (parent_inode->metadata().is_sticky()) {
if (!current->process().is_superuser() && inode->metadata().uid != current->process().euid())
return KResult(-EACCES);
}
return parent_inode->remove_child(FileSystemPath(path).basename());
}