Kernel: Expose Inode::can_access as static member

This commit is contained in:
2026-08-08 01:41:48 +03:00
parent 2be915a1df
commit 2c4fee4a82
2 changed files with 17 additions and 11 deletions
+1
View File
@@ -83,6 +83,7 @@ namespace Kernel
public:
virtual ~Inode() {}
static bool can_access(uid_t uid, gid_t gid, mode_t mode, const Credentials& credentials, int);
bool can_access(const Credentials&, int) const;
bool operator==(const Inode& other) const { return dev() == other.dev() && ino() == other.ino(); }
+16 -11
View File
@@ -11,18 +11,18 @@
namespace Kernel
{
bool Inode::can_access(const Credentials& credentials, int flags) const
bool Inode::can_access(uid_t uid, gid_t gid, mode_t mode, const Credentials& credentials, int flags)
{
if (credentials.is_superuser())
return true;
if (flags & O_RDONLY)
{
if (mode().mode & S_IROTH)
if (mode & S_IROTH)
{ }
else if ((mode().mode & S_IRUSR) && credentials.euid() == uid())
else if ((mode & S_IRUSR) && credentials.euid() == uid)
{ }
else if ((mode().mode & S_IRGRP) && credentials.has_egid(gid()))
else if ((mode & S_IRGRP) && credentials.has_egid(gid))
{ }
else
{
@@ -32,11 +32,11 @@ namespace Kernel
if (flags & O_WRONLY)
{
if (mode().mode & S_IWOTH)
if (mode & S_IWOTH)
{ }
else if ((mode().mode & S_IWUSR) && credentials.euid() == uid())
else if ((mode & S_IWUSR) && credentials.euid() == uid)
{ }
else if ((mode().mode & S_IWGRP) && credentials.has_egid(gid()))
else if ((mode & S_IWGRP) && credentials.has_egid(gid))
{ }
else
{
@@ -44,13 +44,13 @@ namespace Kernel
}
}
if ((flags & O_EXEC) || (mode().ifdir() && (flags & O_SEARCH)))
if ((flags & O_EXEC) || (Mode { mode }.ifdir() && (flags & O_SEARCH)))
{
if (mode().mode & S_IXOTH)
if (mode & S_IXOTH)
{ }
else if ((mode().mode & S_IXUSR) && credentials.euid() == uid())
else if ((mode & S_IXUSR) && credentials.euid() == uid)
{ }
else if ((mode().mode & S_IXGRP) && credentials.has_egid(gid()))
else if ((mode & S_IXGRP) && credentials.has_egid(gid))
{ }
else
{
@@ -61,6 +61,11 @@ namespace Kernel
return true;
}
bool Inode::can_access(const Credentials& credentials, int flags) const
{
return can_access(uid(), gid(), mode().mode, credentials, flags);
}
BAN::ErrorOr<BAN::RefPtr<Inode>> Inode::find_inode(BAN::StringView name)
{
if (!mode().ifdir())