/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include namespace Kernel { ErrorOr Process::sys$getuid() { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); return credentials->uid().value(); } ErrorOr Process::sys$getgid() { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); return credentials->gid().value(); } ErrorOr Process::sys$geteuid() { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); return credentials->euid().value(); } ErrorOr Process::sys$getegid() { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); return credentials->egid().value(); } ErrorOr Process::sys$getresuid(Userspace user_ruid, Userspace user_euid, Userspace user_suid) { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); auto uid = credentials->uid(); auto euid = credentials->euid(); auto suid = credentials->suid(); TRY(copy_to_user(user_ruid, &uid)); TRY(copy_to_user(user_euid, &euid)); TRY(copy_to_user(user_suid, &suid)); return 0; } ErrorOr Process::sys$getresgid(Userspace user_rgid, Userspace user_egid, Userspace user_sgid) { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); auto gid = credentials->gid(); auto egid = credentials->egid(); auto sgid = credentials->sgid(); TRY(copy_to_user(user_rgid, &gid)); TRY(copy_to_user(user_egid, &egid)); TRY(copy_to_user(user_sgid, &sgid)); return 0; } ErrorOr Process::sys$getgroups(size_t count, Userspace user_gids) { VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto credentials = this->credentials(); if (!count) return credentials->extra_gids().size(); if (count != credentials->extra_gids().size()) return EINVAL; TRY(copy_n_to_user(user_gids, credentials->extra_gids().data(), count)); return 0; } }