Acl Acl::Make(acl_perm_t ownerPerms,
acl_perm_t groupPerms,
acl_perm_t otherPerms,
- std::vector<EntryPtr> _entries)
+ std::vector<EntryPtr>&& _entries)
{
auto entries = std::move(_entries);
Acl::Acl(const std::vector<EntryPtr> &entries)
{
+ if (entries.empty()) {
+ return;
+ }
+
auto freeAcl = [](acl_t *toFree) {acl_free(*toFree);};
- m_acl = acl_init(entries.size());
+ m_acl = acl_init(entries.size() + 1); // + 1 for ACL_MASK entry
if (m_acl == nullptr) {
LogErrno("acl_init");
Throw(Exception::Base);
LogErrno("acl_calc_mask");
Throw(Exception::Base);
}
- deleter.release();
-}
-
-void Acl::apply(const std::string &path, acl_type_t type) const
-{
- if (m_acl == nullptr) {
- LogError("ACL object is not initialized");
- Throw(Exception::Base);
- }
int last;
int ret = acl_check(m_acl, &last);
Throw(Exception::Base);
}
+ (void)deleter.release();
+}
+
+void Acl::apply(const std::string &path, acl_type_t type) const
+{
+ if (m_acl == nullptr) {
+ LogError("ACL object is not initialized");
+ Throw(Exception::Base);
+ }
+
if (0 != acl_set_file(path.c_str(), type, m_acl)) {
LogErrno("acl_set_file");
Throw(Exception::Base);
}
}
-Acl::Acl(Acl&& other)
+Acl::Acl(Acl&& other) noexcept
{
m_acl = other.m_acl;
other.m_acl = nullptr;
}
-Acl& Acl::operator=(Acl&& other)
+Acl& Acl::operator=(Acl&& other) noexcept
{
if (&other != this)
{
+ if (m_acl)
+ acl_free(m_acl);
m_acl = other.m_acl;
other.m_acl = nullptr;
}
Acl::~Acl()
{
- acl_free(m_acl);
+ if (m_acl)
+ acl_free(m_acl);
}
} // namespace SecurityManager
class Acl
{
private:
- struct Entry
+ class Entry
{
- virtual void setQualifier(acl_entry_t&) const
+ public:
+ Entry(acl_perm_t permissions_, acl_tag_t tag_) :
+ permissions(permissions_), tag(tag_)
{
}
- Entry(acl_perm_t _permissions, acl_tag_t _tag) :
- permissions(_permissions), tag(_tag)
+ Entry(const Entry&) = default;
+ Entry(Entry&&) noexcept = default;
+ Entry& operator=(const Entry&) = default;
+ Entry& operator=(Entry&&) noexcept = default;
+
+ virtual ~Entry() = default;
+
+ virtual void setQualifier(acl_entry_t&) const
{
}
using EntryPtr = std::unique_ptr<Entry>;
template<typename Id, acl_tag_t Tag>
- class IdEntry: public Entry
+ class IdEntry : public Entry
{
public:
IdEntry(acl_perm_t permissions, Id id) :
DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
};
- Acl(Acl&& other);
- Acl& operator=(Acl&& other);
-
Acl() : Acl(std::vector<EntryPtr>())
{
}
+
+ Acl(const Acl&) = delete;
+ Acl(Acl&& other) noexcept;
+ Acl& operator=(const Acl&) = delete;
+ Acl& operator=(Acl&& other) noexcept;
+
~Acl();
static Acl Make(acl_perm_t ownerPerms,
acl_perm_t groupPerms,
acl_perm_t otherPerms,
- std::vector<EntryPtr> entries = {});
+ std::vector<EntryPtr>&& entries = {});
void apply(const std::string &path, acl_type_t type) const;
private:
explicit Acl(const std::vector<EntryPtr> &entries);
- mutable acl_t m_acl = nullptr;
+ acl_t m_acl = nullptr;
};
} // namespace SecurityManager