Skip to content

Commit

Permalink
iox-#1176 Build ACL support according to the feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Oct 13, 2024
1 parent 7459452 commit e597773
Show file tree
Hide file tree
Showing 22 changed files with 300 additions and 455 deletions.
21 changes: 11 additions & 10 deletions iceoryx_hoofs/posix/filesystem/source/posix_acl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool PosixAcl::writePermissionsToFile(const int32_t fileDescriptor) const noexce
}

// check if acl is valid
auto aclCheckCall = IOX_POSIX_CALL(acl_valid)(workingACL.get()).successReturnValue(0).evaluate();
auto aclCheckCall = IOX_POSIX_CALL(iox_acl_valid)(workingACL.get()).successReturnValue(0).evaluate();

if (aclCheckCall.has_error())
{
Expand All @@ -73,7 +73,8 @@ bool PosixAcl::writePermissionsToFile(const int32_t fileDescriptor) const noexce
}

// set acl in the file given by descriptor
auto aclSetFdCall = IOX_POSIX_CALL(acl_set_fd)(fileDescriptor, workingACL.get()).successReturnValue(0).evaluate();
auto aclSetFdCall =
IOX_POSIX_CALL(iox_acl_set_fd)(fileDescriptor, workingACL.get()).successReturnValue(0).evaluate();
if (aclSetFdCall.has_error())
{
IOX_LOG(ERROR, "Error: Could not set file ACL.");
Expand All @@ -86,7 +87,7 @@ bool PosixAcl::writePermissionsToFile(const int32_t fileDescriptor) const noexce
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();
auto aclInitCall = IOX_POSIX_CALL(iox_acl_init)(numEntries).failureReturnValue(nullptr).evaluate();

if (aclInitCall.has_error())
{
Expand All @@ -95,7 +96,7 @@ expected<PosixAcl::smartAclPointer_t, PosixAcl::Error> PosixAcl::createACL(const

// define how to free the memory (custom deleter for the smart pointer)
function<void(acl_t)> freeACL = [&](acl_t acl) {
auto aclFreeCall = IOX_POSIX_CALL(acl_free)(acl).successReturnValue(0).evaluate();
auto aclFreeCall = IOX_POSIX_CALL(iox_acl_free)(acl).successReturnValue(0).evaluate();
// We ensure here instead of returning as this lambda will be called by unique_ptr
IOX_ENFORCE(!aclFreeCall.has_error(), "Could not free ACL memory");
};
Expand Down Expand Up @@ -186,7 +187,7 @@ bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noe
acl_entry_t newEntry{};
acl_t l_ACL{ACL};

auto aclCreateEntryCall = IOX_POSIX_CALL(acl_create_entry)(&l_ACL, &newEntry).successReturnValue(0).evaluate();
auto aclCreateEntryCall = IOX_POSIX_CALL(iox_acl_create_entry)(&l_ACL, &newEntry).successReturnValue(0).evaluate();

if (aclCreateEntryCall.has_error())
{
Expand All @@ -196,7 +197,7 @@ bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noe

// set tag type for new entry (user, group, ...)
auto tagType = static_cast<acl_tag_t>(entry.m_category);
auto aclSetTagTypeCall = IOX_POSIX_CALL(acl_set_tag_type)(newEntry, tagType).successReturnValue(0).evaluate();
auto aclSetTagTypeCall = IOX_POSIX_CALL(iox_acl_set_tag_type)(newEntry, tagType).successReturnValue(0).evaluate();

if (aclSetTagTypeCall.has_error())
{
Expand All @@ -210,7 +211,7 @@ bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noe
case ACL_USER:
{
auto aclSetQualifierCall =
IOX_POSIX_CALL(acl_set_qualifier)(newEntry, &(entry.m_id)).successReturnValue(0).evaluate();
IOX_POSIX_CALL(iox_acl_set_qualifier)(newEntry, &(entry.m_id)).successReturnValue(0).evaluate();

if (aclSetQualifierCall.has_error())
{
Expand All @@ -223,7 +224,7 @@ bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noe
case ACL_GROUP:
{
auto aclSetQualifierCall =
IOX_POSIX_CALL(acl_set_qualifier)(newEntry, &(entry.m_id)).successReturnValue(0).evaluate();
IOX_POSIX_CALL(iox_acl_set_qualifier)(newEntry, &(entry.m_id)).successReturnValue(0).evaluate();

if (aclSetQualifierCall.has_error())
{
Expand All @@ -241,7 +242,7 @@ bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noe
acl_permset_t entryPermissionSet{};

auto aclGetPermsetCall =
IOX_POSIX_CALL(acl_get_permset)(newEntry, &entryPermissionSet).successReturnValue(0).evaluate();
IOX_POSIX_CALL(iox_acl_get_permset)(newEntry, &entryPermissionSet).successReturnValue(0).evaluate();

if (aclGetPermsetCall.has_error())
{
Expand Down Expand Up @@ -280,7 +281,7 @@ bool PosixAcl::createACLEntry(const acl_t ACL, const PermissionEntry& entry) noe

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();
auto aclAddPermCall = IOX_POSIX_CALL(iox_acl_add_perm)(permset, perm).successReturnValue(0).evaluate();

if (aclAddPermCall.has_error())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
//
// SPDX-License-Identifier: Apache-2.0

#if defined(__linux__)
#include "iox/detail/posix_acl.hpp"

#if IOX_FEATURE_ACL

#include "iceoryx_platform/pwd.hpp"
#include "iceoryx_platform/stat.hpp"
#include "iox/detail/posix_acl.hpp"
#include "iox/posix_call.hpp"
#include "test.hpp"

Expand Down Expand Up @@ -300,4 +302,5 @@ TEST_F(PosixAcl_test, addStrangeNames)
EXPECT_FALSE(entryAdded);
}
} // namespace
#endif

#endif // IOX_FEATURE_ACL
104 changes: 0 additions & 104 deletions iceoryx_platform/freertos/include/iceoryx_platform/acl.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions iceoryx_platform/freertos/include/iceoryx_platform/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <sys/types.h>

using iox_ssize_t = ssize_t;

using iox_gid_t = gid_t;
using iox_uid_t = uid_t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#define IOX_SC_PAGESIZE _SC_PAGESIZE

using iox_off_t = off_t;
using iox_ssize_t = ssize_t;

#define IOX_F_OK F_OK
#define IOX_X_OK X_OK
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by ekxide IO GmbH. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,9 +13,14 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_LINUX_PLATFORM_ACL_HPP
#define IOX_HOOFS_LINUX_PLATFORM_ACL_HPP

#include <sys/acl.h>
#ifndef IOX_PLATFORM_ACL_HPP
#define IOX_PLATFORM_ACL_HPP

#endif // IOX_HOOFS_LINUX_PLATFORM_ACL_HPP
#if __has_include("iceoryx_platform/override/acl.hpp")
#include "iceoryx_platform/override/acl.hpp"
#else
#include "iceoryx_platform/generic/acl.hpp"
#endif // __has_include

#endif // IOX_PLATFORM_ACL_HPP
87 changes: 87 additions & 0 deletions iceoryx_platform/generic/include/iceoryx_platform/generic/acl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2024 by ekxide IO GmbH. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_GENERIC_PLATFORM_ACL_HPP
#define IOX_HOOFS_GENERIC_PLATFORM_ACL_HPP

#include "iceoryx_platform/platform_settings.hpp"
#include "iceoryx_platform/types.hpp"

// NOTE: The functions can be individually overwritten by setting the corresponding 'IOX_PLATFORM_OVERRIDE_*' define in
// the respective platform specific 'override/*.h' header


#ifndef IOX_PLATFORM_OVERRIDE_ACL_ALL

#if IOX_FEATURE_ACL

#include <sys/acl.h>

#else

// NOLINTBEGIN(cppcoreguidelines-macro-usage) Macros are required for compatibility with the ones from acl.h

#define ACL_USER_OBJ 0
#define ACL_USER 1
#define ACL_GROUP_OBJ 2
#define ACL_GROUP 3
#define ACL_OTHER 4
#define ACL_READ 5
#define ACL_WRITE 6
#define ACL_MASK 7

// NOLINTEND(cppcoreguidelines-macro-usage)

struct iox_internal_acl_ext
{
};

using acl_t = struct iox_internal_acl_ext*;
using acl_permset_t = int;
using acl_perm_t = int;
using acl_entry_t = int;
using acl_tag_t = int;

#endif // IOX_FEATURE_ACL

#endif // IOX_PLATFORM_OVERRIDE_ACL_ALL

int iox_acl_valid(acl_t /*acl*/);

int iox_acl_set_fd(int /*fd*/, acl_t /*acl*/);

acl_t iox_acl_init(int /*count*/);

int iox_acl_free(void* /*obj_p*/);

int iox_acl_create_entry(acl_t* /*acl_p*/, acl_entry_t* /*entry_p*/);

int iox_acl_set_tag_type(acl_entry_t /*entry_d*/, acl_tag_t /*tag_type*/);

int iox_acl_set_qualifier(acl_entry_t /*entry_d*/, const void* /*qualifier_p*/);

int iox_acl_get_permset(acl_entry_t /*entry_d*/, acl_permset_t* /*permset_p*/);

int iox_acl_add_perm(acl_permset_t /*permset_d*/, acl_perm_t /*perm*/);

char* iox_acl_to_text(acl_t /*acl*/, iox_ssize_t* /*len_p*/);

acl_t iox_acl_from_text(const char* /*buf_p*/);

acl_t iox_acl_get_fd(int /*fd*/);

#endif // IOX_HOOFS_GENERIC_PLATFORM_ACL_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include <cstdlib>

// NOTE: The functions can be individually overwritten by setting the corresponding 'IOX_PLATFORM_OVERRIDE_*' define in
// the respective platform specific 'override/*.h' header

/// @brief Implementation of 'getenv_s'
/// @param[out] actual_size_with_null of the value of the env variable including null-termination or 0 if the
/// environment variable does not exist
Expand Down
Loading

0 comments on commit e597773

Please sign in to comment.