libc: Add setuid, setgid, seteuid, setegid

This commit is contained in:
apio 2022-10-28 17:52:39 +02:00
parent 09a615bd99
commit 8f0e358360
2 changed files with 32 additions and 0 deletions

View File

@ -50,6 +50,18 @@ extern "C"
/* Returns the current process' effective group ID. */
gid_t getegid(void);
/* Sets the current process' real and effective user IDs. */
int setuid(uid_t uid);
/* Sets the current process' effective user ID. */
int seteuid(uid_t uid);
/* Sets the current process' real and effective group IDs. */
int setgid(gid_t gid);
/* Sets the current process' effective group ID. */
int setegid(gid_t gid);
/* Terminates the program with the status code status. */
__lc_noreturn void _exit(int status);

View File

@ -58,6 +58,26 @@ extern "C"
return (gid_t)getprocid(ID_EGID);
}
int setuid(uid_t uid)
{
return (int)__lc_fast_syscall2(SYS_setuid, uid, uid);
}
int seteuid(uid_t uid)
{
return (int)__lc_fast_syscall2(SYS_setuid, getprocid(ID_UID), uid);
}
int setgid(gid_t gid)
{
return (int)__lc_fast_syscall2(SYS_setgid, gid, gid);
}
int setegid(gid_t gid)
{
return (int)__lc_fast_syscall2(SYS_setgid, getprocid(ID_GID), gid);
}
unsigned int sleep(unsigned int seconds)
{
return msleep(seconds * 1000);