Credentials.cpp 1.0 KB

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