Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1391 Rename 'AccessController' to 'PosixAcl' and …
Browse files Browse the repository at this point in the history
…move to new module structure
  • Loading branch information
elBoberido committed Nov 29, 2023
1 parent 5bdd842 commit 59ee26c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 75 deletions.
2 changes: 1 addition & 1 deletion iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ iox_add_library(
source/cxx/requires.cpp
source/error_handling/error_handler.cpp
source/error_handling/error_handling.cpp
source/posix_wrapper/access_control.cpp
source/posix_wrapper/file_lock.cpp
source/posix_wrapper/mutex.cpp
source/posix_wrapper/named_semaphore.cpp
Expand All @@ -123,6 +122,7 @@ iox_add_library(
posix/auth/source/posix_user.cpp
posix/design/source/file_management_interface.cpp
posix/filesystem/source/file.cpp
posix/filesystem/source/posix_acl.cpp
posix/time/source/adaptive_wait.cpp
posix/time/source/deadline_timer.cpp
posix/vocabulary/source/file_name.cpp
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
| class | internal | description |
|:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`filesystem` | | Implementation of C++17 filesystem features for instance `iox::access_rights` and `iox::perms` to abstract file permissions |
|`AccessController` | i | Interface for Access Control Lists (ACL). |
|`PosixAcl` | i | Interface for Access Control Lists (ACL). |
|`FileLock` | | File lock C++ wrapping class. |

### Functional (functional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_POSIX_WRAPPER_ACCESS_CONTROL_HPP
#define IOX_HOOFS_POSIX_WRAPPER_ACCESS_CONTROL_HPP

#ifndef IOX_HOOFS_POSIX_FILESYSTEM_POSIX_ACL_HPP
#define IOX_HOOFS_POSIX_FILESYSTEM_POSIX_ACL_HPP

#include "iceoryx_platform/acl.hpp"
#include "iox/expected.hpp"
Expand All @@ -31,24 +32,22 @@

namespace iox
{
namespace posix
{
/// @brief abstraction class for the management of access control lists (ACLs).
///
/// ACLs allow to define fine-grained access rights for files. In addition to the standard access rights, which can only
/// distinguish between user/group/others, ACLs can be used to give specific access rights to named users and groups.
/// ACL is part of the posix specification. The AccessController class is used to store ACL permission entries and
/// ACL is part of the posix specification. The 'PosixAcl' class is used to store ACL permission entries and
/// provides a way to write those entries to a file. A permission entry can be seen as a combination of an access
/// Category, a Permission and an optional name (used to identify specific users and groups.)
class AccessController
class PosixAcl
{
public:
enum class AccessControllerError : uint8_t
enum class Error : uint8_t
{
COULD_NOT_ALLOCATE_NEW_ACL,
};

/// @brief maximum number of permission entries the AccessController can store
/// @brief maximum number of permission entries the 'PosixAcl' can store
static constexpr int32_t MaxNumOfPermissions = 20;

/// @brief identifier for a permission entry (user, group, others, ...)
Expand Down Expand Up @@ -106,7 +105,7 @@ class AccessController
/// @return true when the permissions are applied, on failure false
bool addGroupPermission(const Permission permission, const PosixGroup::groupName_t& name) noexcept;

/// @brief Write permission entries stored by the AccessController to a file identified by a file descriptor.
/// @brief Write permission entries stored by the 'PosixAcl' to a file identified by a file descriptor.
/// @param[fileDescriptor] identifier for a file (can be regular file, shared memory file, message queue file...
/// everything is a file).
/// @return true if succesful. If false, you can assume that the file has not been touched at all.
Expand All @@ -124,13 +123,12 @@ class AccessController

vector<PermissionEntry, MaxNumOfPermissions> m_permissions;

static expected<smartAclPointer_t, AccessControllerError> createACL(const int32_t numEntries) noexcept;
static expected<smartAclPointer_t, Error> createACL(const int32_t numEntries) noexcept;
static bool createACLEntry(const acl_t ACL, const PermissionEntry& entry) noexcept;
static bool addAclPermission(acl_permset_t permset, acl_perm_t perm) noexcept;

bool m_useACLMask{false};
};
} // namespace posix
} // namespace iox

#endif // IOX_HOOFS_POSIX_WRAPPER_ACCESS_CONTROL_HPP
#endif // IOX_HOOFS_POSIX_FILESYSTEM_POSIX_ACL_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/internal/posix_wrapper/access_control.hpp"
#include "iox/detail/posix_acl.hpp"
#include "iox/function.hpp"
#include "iox/logging.hpp"
#include "iox/posix_call.hpp"
Expand All @@ -25,11 +25,9 @@
#include "iceoryx_platform/platform_correction.hpp"
namespace iox
{
namespace posix
{
// NOLINTJUSTIFICATION the function size results from the error handling and the expanded log macro
// NOLINTNEXTLINE(readability-function-size)
bool AccessController::writePermissionsToFile(const int32_t fileDescriptor) const noexcept
bool PosixAcl::writePermissionsToFile(const int32_t fileDescriptor) const noexcept
{
if (m_permissions.empty())
{
Expand Down Expand Up @@ -83,15 +81,14 @@ bool AccessController::writePermissionsToFile(const int32_t fileDescriptor) cons
}
// NOLINTEND(readability-function-size,readability-function-cognitive-complexity)

expected<AccessController::smartAclPointer_t, AccessController::AccessControllerError>
AccessController::createACL(const int32_t numEntries) noexcept
expected<PosixAcl::smartAclPointer_t, PosixAcl::Error> PosixAcl::createACL(const int32_t numEntries) noexcept
{
// allocate memory for a new ACL
auto aclInitCall = IOX_POSIX_CALL(acl_init)(numEntries).failureReturnValue(nullptr).evaluate();

if (aclInitCall.has_error())
{
return err(AccessControllerError::COULD_NOT_ALLOCATE_NEW_ACL);
return err(Error::COULD_NOT_ALLOCATE_NEW_ACL);
}

// define how to free the memory (custom deleter for the smart pointer)
Expand All @@ -106,7 +103,7 @@ AccessController::createACL(const int32_t numEntries) noexcept
return ok<smartAclPointer_t>(aclInitCall->value, freeACL);
}

bool AccessController::addUserPermission(const Permission permission, const PosixUser::userName_t& name) noexcept
bool PosixAcl::addUserPermission(const Permission permission, const PosixUser::userName_t& name) noexcept
{
if (name.empty())
{
Expand All @@ -123,7 +120,7 @@ bool AccessController::addUserPermission(const Permission permission, const Posi
return addPermissionEntry(Category::SPECIFIC_USER, permission, id.value());
}

bool AccessController::addGroupPermission(const Permission permission, const PosixGroup::groupName_t& name) noexcept
bool PosixAcl::addGroupPermission(const Permission permission, const PosixGroup::groupName_t& name) noexcept
{
if (name.empty())
{
Expand All @@ -140,9 +137,7 @@ bool AccessController::addGroupPermission(const Permission permission, const Pos
return addPermissionEntry(Category::SPECIFIC_GROUP, permission, id.value());
}

bool AccessController::addPermissionEntry(const Category category,
const Permission permission,
const uint32_t id) noexcept
bool PosixAcl::addPermissionEntry(const Category category, const Permission permission, const uint32_t id) noexcept
{
if (m_permissions.size() >= m_permissions.capacity())
{
Expand Down Expand Up @@ -185,7 +180,7 @@ bool AccessController::addPermissionEntry(const Category category,

// NOLINTJUSTIFICATION the function size results from the error handling and the expanded log macro
// NOLINTNEXTLINE(readability-function-size)
bool AccessController::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noexcept
bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noexcept
{
// create new entry in acl
acl_entry_t newEntry{};
Expand Down Expand Up @@ -283,7 +278,7 @@ bool AccessController::createACLEntry(const acl_t ACL, const PermissionEntry& en
}
}

bool AccessController::addAclPermission(acl_permset_t permset, acl_perm_t perm) noexcept
bool PosixAcl::addAclPermission(acl_permset_t permset, acl_perm_t perm) noexcept
{
auto aclAddPermCall = IOX_POSIX_CALL(acl_add_perm)(permset, perm).successReturnValue(0).evaluate();

Expand All @@ -295,5 +290,4 @@ bool AccessController::addAclPermission(acl_permset_t permset, acl_perm_t perm)
return true;
}

} // namespace posix
} // namespace iox
Loading

0 comments on commit 59ee26c

Please sign in to comment.