2022-08-20 16:25:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
#include <AK/RefPtr.h>
|
2023-02-24 17:57:27 +00:00
|
|
|
#include <Kernel/Security/Credentials.h>
|
2022-08-20 16:25:54 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2023-02-05 19:02:54 +00:00
|
|
|
ErrorOr<NonnullRefPtr<Credentials>> Credentials::create(UserID uid, GroupID gid, UserID euid, GroupID egid, UserID suid, GroupID sgid, ReadonlySpan<GroupID> extra_gids, SessionID sid, ProcessGroupID pgid)
|
2022-08-20 16:25:54 +00:00
|
|
|
{
|
2023-01-28 20:12:17 +00:00
|
|
|
auto extra_gids_array = TRY(FixedArray<GroupID>::create(extra_gids));
|
2022-12-19 20:21:51 +00:00
|
|
|
return adopt_nonnull_ref_or_enomem(new (nothrow) Credentials(uid, gid, euid, egid, suid, sgid, move(extra_gids_array), sid, pgid));
|
2022-08-20 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 20:21:51 +00:00
|
|
|
Credentials::Credentials(UserID uid, GroupID gid, UserID euid, GroupID egid, UserID suid, GroupID sgid, FixedArray<GroupID> extra_gids, SessionID sid, ProcessGroupID pgid)
|
2022-08-20 16:25:54 +00:00
|
|
|
: m_uid(uid)
|
|
|
|
, m_gid(gid)
|
|
|
|
, m_euid(euid)
|
|
|
|
, m_egid(egid)
|
|
|
|
, m_suid(suid)
|
|
|
|
, m_sgid(sgid)
|
|
|
|
, m_extra_gids(move(extra_gids))
|
2022-12-19 20:21:51 +00:00
|
|
|
, m_sid(sid)
|
|
|
|
, m_pgid(pgid)
|
2022-08-20 16:25:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Credentials::~Credentials() = default;
|
|
|
|
|
2022-08-21 14:02:24 +00:00
|
|
|
bool Credentials::in_group(Kernel::GroupID gid) const
|
|
|
|
{
|
|
|
|
return m_gid == gid || m_extra_gids.contains_slow(gid);
|
|
|
|
}
|
|
|
|
|
2022-08-20 16:25:54 +00:00
|
|
|
}
|