Serenity Operating System
1/*
2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/NonnullRefPtr.h>
8#include <AK/RefPtr.h>
9#include <Kernel/Credentials.h>
10
11namespace Kernel {
12
13ErrorOr<NonnullRefPtr<Credentials>> Credentials::create(UserID uid, GroupID gid, UserID euid, GroupID egid, UserID suid, GroupID sgid, ReadonlySpan<GroupID> extra_gids, SessionID sid, ProcessGroupID pgid)
14{
15 auto extra_gids_array = TRY(FixedArray<GroupID>::create(extra_gids));
16 return adopt_nonnull_ref_or_enomem(new (nothrow) Credentials(uid, gid, euid, egid, suid, sgid, move(extra_gids_array), sid, pgid));
17}
18
19Credentials::Credentials(UserID uid, GroupID gid, UserID euid, GroupID egid, UserID suid, GroupID sgid, FixedArray<GroupID> extra_gids, SessionID sid, ProcessGroupID pgid)
20 : m_uid(uid)
21 , m_gid(gid)
22 , m_euid(euid)
23 , m_egid(egid)
24 , m_suid(suid)
25 , m_sgid(sgid)
26 , m_extra_gids(move(extra_gids))
27 , m_sid(sid)
28 , m_pgid(pgid)
29{
30}
31
32Credentials::~Credentials() = default;
33
34bool Credentials::in_group(Kernel::GroupID gid) const
35{
36 return m_gid == gid || m_extra_gids.contains_slow(gid);
37}
38
39}