malcontent/nss/user_policy.hh

32 lines
728 B
C++
Raw Permalink Normal View History

2024-01-05 18:10:45 +01:00
// SPDX-FileCopyrightText: Matteo Settenvini <matteo.settenvini@montecristosoftware.eu>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <memory>
#include <shared_mutex>
#include <optional>
#include <unordered_map>
#include <unistd.h>
namespace malcontent {
class Resolver;
class UserPolicy {
public:
UserPolicy() = default;
UserPolicy(const UserPolicy&) = delete;
UserPolicy(UserPolicy&&) = delete;
~UserPolicy() noexcept = default;
auto resolver(std::optional<uid_t> uid = {}) const -> std::shared_ptr<Resolver>;
private:
mutable std::unordered_map<uid_t, std::shared_ptr<Resolver>> _resolver_cache;
mutable std::shared_mutex _cache_mutex;
};
} // ~ namespace malcontent