From 17671fd435517f8a82f930158248950a14df0dd4 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 28 Oct 2022 17:24:28 +0200 Subject: [PATCH] libc: Implement getuid, geteuid, getgid, getegid --- libs/libc/include/unistd.h | 12 ++++++++++++ libs/libc/src/unistd.cpp | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libs/libc/include/unistd.h b/libs/libc/include/unistd.h index ba410e8e..ff770cc3 100644 --- a/libs/libc/include/unistd.h +++ b/libs/libc/include/unistd.h @@ -38,6 +38,18 @@ extern "C" /* Returns the current process' parent's process ID. */ pid_t getppid(void); + /* Returns the current process' real user ID. */ + uid_t getuid(void); + + /* Returns the current process' effective user ID. */ + uid_t geteuid(void); + + /* Returns the current process' real group ID. */ + gid_t getgid(void); + + /* Returns the current process' effective group ID. */ + gid_t getegid(void); + /* Terminates the program with the status code status. */ __lc_noreturn void _exit(int status); diff --git a/libs/libc/src/unistd.cpp b/libs/libc/src/unistd.cpp index f9c5fb83..ab4c9421 100644 --- a/libs/libc/src/unistd.cpp +++ b/libs/libc/src/unistd.cpp @@ -38,6 +38,26 @@ extern "C" return getprocid(ID_PPID); } + uid_t getuid(void) + { + return (uid_t)getprocid(ID_UID); + } + + uid_t geteuid(void) + { + return (uid_t)getprocid(ID_EUID); + } + + gid_t getgid(void) + { + return (gid_t)getprocid(ID_GID); + } + + gid_t getegid(void) + { + return (gid_t)getprocid(ID_EGID); + } + unsigned int sleep(unsigned int seconds) { return msleep(seconds * 1000);