Kernel: Add SYS_GET_{,E}{UID,GID}

This commit is contained in:
Bananymous 2023-06-11 22:27:53 +03:00
parent 3fe67e4882
commit 11b68f6a53
4 changed files with 81 additions and 0 deletions

View File

@ -65,6 +65,11 @@ namespace Kernel
BAN::ErrorOr<void> set_reuid(uid_t, uid_t);
BAN::ErrorOr<void> 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<int> open(BAN::StringView, int);
BAN::ErrorOr<int> openat(int, BAN::StringView, int);
BAN::ErrorOr<void> close(int fd);

View File

@ -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;

View File

@ -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

View File

@ -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);