diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index 7f2ac097..42c6ea73 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -65,6 +65,11 @@ namespace Kernel BAN::ErrorOr set_reuid(uid_t, uid_t); BAN::ErrorOr set_regid(gid_t, gid_t); + uid_t get_uid() const { return m_credentials.ruid(); } + gid_t get_gid() const { return m_credentials.rgid(); } + uid_t get_euid() const { return m_credentials.euid(); } + gid_t get_egid() const { return m_credentials.egid(); } + BAN::ErrorOr open(BAN::StringView, int); BAN::ErrorOr openat(int, BAN::StringView, int); BAN::ErrorOr close(int fd); diff --git a/kernel/kernel/Syscall.cpp b/kernel/kernel/Syscall.cpp index aa30f4a6..ed63ef84 100644 --- a/kernel/kernel/Syscall.cpp +++ b/kernel/kernel/Syscall.cpp @@ -208,6 +208,26 @@ namespace Kernel return 0; } + long sys_get_uid() + { + return Process::current().get_uid(); + } + + long sys_get_gid() + { + return Process::current().get_gid(); + } + + long sys_get_euid() + { + return Process::current().get_euid(); + } + + long sys_get_egid() + { + return Process::current().get_egid(); + } + extern "C" long sys_fork_trampoline(); extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5) @@ -303,6 +323,18 @@ namespace Kernel case SYS_SET_REGID: ret = sys_set_regid((gid_t)arg1, (gid_t)arg2); break; + case SYS_GET_UID: + ret = sys_get_uid(); + break; + case SYS_GET_GID: + ret = sys_get_gid(); + break; + case SYS_GET_EUID: + ret = sys_get_euid(); + break; + case SYS_GET_EGID: + ret = sys_get_egid(); + break; default: dwarnln("Unknown syscall {}", syscall); ret = -ENOSYS; diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h index 311616d2..272b3127 100644 --- a/libc/include/sys/syscall.h +++ b/libc/include/sys/syscall.h @@ -32,6 +32,10 @@ __BEGIN_DECLS #define SYS_SET_EGID 25 #define SYS_SET_REUID 26 #define SYS_SET_REGID 27 +#define SYS_GET_UID 28 +#define SYS_GET_GID 29 +#define SYS_GET_EUID 30 +#define SYS_GET_EGID 31 __END_DECLS diff --git a/libc/unistd.cpp b/libc/unistd.cpp index b5474a2d..54b7f73f 100644 --- a/libc/unistd.cpp +++ b/libc/unistd.cpp @@ -213,6 +213,26 @@ long syscall(long syscall, ...) ret = Kernel::syscall(SYS_SET_REGID, rgid, egid); break; } + case SYS_GET_UID: + { + ret = Kernel::syscall(SYS_GET_UID); + break; + } + case SYS_GET_GID: + { + ret = Kernel::syscall(SYS_GET_GID); + break; + } + case SYS_GET_EUID: + { + ret = Kernel::syscall(SYS_GET_EUID); + break; + } + case SYS_GET_EGID: + { + ret = Kernel::syscall(SYS_GET_EGID); + break; + } default: puts("LibC: Unhandeled syscall"); ret = -ENOSYS; @@ -322,6 +342,26 @@ unsigned int sleep(unsigned int seconds) return syscall(SYS_SLEEP, seconds); } +uid_t getuid(void) +{ + return syscall(SYS_GET_UID); +} + +gid_t getgid(void) +{ + return syscall(SYS_GET_GID); +} + +uid_t geteuid(void) +{ + return syscall(SYS_GET_EUID); +} + +gid_t getegid(void) +{ + return syscall(SYS_GET_EGID); +} + int seteuid(uid_t uid) { return syscall(SYS_SET_EUID, uid);