summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/setuid.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-01 13:49:16 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-01 13:54:32 +0100
commitac71775de5a71945e004f46b184dde4f628d112b (patch)
treebac755ef16ba74bd63d3a359e6aad9e32d2734ae /Kernel/Syscalls/setuid.cpp
parent9af1e1a3bf43140dee327eb4f553c56ba95ad9d9 (diff)
downloadserenity-ac71775de5a71945e004f46b184dde4f628d112b.zip
Kernel: Make all syscall functions return KResultOr<T>
This makes it a lot easier to return errors since we no longer have to worry about negating EFOO errors and can just return them flat.
Diffstat (limited to 'Kernel/Syscalls/setuid.cpp')
-rw-r--r--Kernel/Syscalls/setuid.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/Kernel/Syscalls/setuid.cpp b/Kernel/Syscalls/setuid.cpp
index 9e63ceb6bd..7426e6cf15 100644
--- a/Kernel/Syscalls/setuid.cpp
+++ b/Kernel/Syscalls/setuid.cpp
@@ -28,12 +28,12 @@
namespace Kernel {
-int Process::sys$seteuid(uid_t euid)
+KResultOr<int> Process::sys$seteuid(uid_t euid)
{
REQUIRE_PROMISE(id);
if (euid != m_uid && euid != m_suid && !is_superuser())
- return -EPERM;
+ return EPERM;
if (m_euid != euid)
set_dumpable(false);
@@ -41,12 +41,12 @@ int Process::sys$seteuid(uid_t euid)
return 0;
}
-int Process::sys$setegid(gid_t egid)
+KResultOr<int> Process::sys$setegid(gid_t egid)
{
REQUIRE_PROMISE(id);
if (egid != m_gid && egid != m_sgid && !is_superuser())
- return -EPERM;
+ return EPERM;
if (m_egid != egid)
set_dumpable(false);
@@ -55,12 +55,12 @@ int Process::sys$setegid(gid_t egid)
return 0;
}
-int Process::sys$setuid(uid_t uid)
+KResultOr<int> Process::sys$setuid(uid_t uid)
{
REQUIRE_PROMISE(id);
if (uid != m_uid && uid != m_euid && !is_superuser())
- return -EPERM;
+ return EPERM;
if (m_euid != uid)
set_dumpable(false);
@@ -71,12 +71,12 @@ int Process::sys$setuid(uid_t uid)
return 0;
}
-int Process::sys$setgid(gid_t gid)
+KResultOr<int> Process::sys$setgid(gid_t gid)
{
REQUIRE_PROMISE(id);
if (gid != m_gid && gid != m_egid && !is_superuser())
- return -EPERM;
+ return EPERM;
if (m_egid != gid)
set_dumpable(false);
@@ -87,7 +87,7 @@ int Process::sys$setgid(gid_t gid)
return 0;
}
-int Process::sys$setresuid(uid_t ruid, uid_t euid, uid_t suid)
+KResultOr<int> Process::sys$setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
REQUIRE_PROMISE(id);
@@ -100,7 +100,7 @@ int Process::sys$setresuid(uid_t ruid, uid_t euid, uid_t suid)
auto ok = [this](uid_t id) { return id == m_uid || id == m_euid || id == m_suid; };
if ((!ok(ruid) || !ok(euid) || !ok(suid)) && !is_superuser())
- return -EPERM;
+ return EPERM;
if (m_euid != euid)
set_dumpable(false);
@@ -111,7 +111,7 @@ int Process::sys$setresuid(uid_t ruid, uid_t euid, uid_t suid)
return 0;
}
-int Process::sys$setresgid(gid_t rgid, gid_t egid, gid_t sgid)
+KResultOr<int> Process::sys$setresgid(gid_t rgid, gid_t egid, gid_t sgid)
{
REQUIRE_PROMISE(id);
@@ -124,7 +124,7 @@ int Process::sys$setresgid(gid_t rgid, gid_t egid, gid_t sgid)
auto ok = [this](gid_t id) { return id == m_gid || id == m_egid || id == m_sgid; };
if ((!ok(rgid) || !ok(egid) || !ok(sgid)) && !is_superuser())
- return -EPERM;
+ return EPERM;
if (m_egid != egid)
set_dumpable(false);
@@ -135,13 +135,13 @@ int Process::sys$setresgid(gid_t rgid, gid_t egid, gid_t sgid)
return 0;
}
-int Process::sys$setgroups(ssize_t count, Userspace<const gid_t*> user_gids)
+KResultOr<int> Process::sys$setgroups(ssize_t count, Userspace<const gid_t*> user_gids)
{
REQUIRE_PROMISE(id);
if (count < 0)
- return -EINVAL;
+ return EINVAL;
if (!is_superuser())
- return -EPERM;
+ return EPERM;
if (!count) {
m_extra_gids.clear();
@@ -151,7 +151,7 @@ int Process::sys$setgroups(ssize_t count, Userspace<const gid_t*> user_gids)
Vector<gid_t> gids;
gids.resize(count);
if (!copy_n_from_user(gids.data(), user_gids, count))
- return -EFAULT;
+ return EFAULT;
HashTable<gid_t> unique_extra_gids;
for (auto& gid : gids) {