Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1391 Move 'PosixGroup' and 'PosixUser' to 'iox/po…
Browse files Browse the repository at this point in the history
…six_group.hpp' and 'iox/posix_user.hpp'
  • Loading branch information
elBoberido committed Nov 28, 2023
1 parent f0622f1 commit af2bd8f
Show file tree
Hide file tree
Showing 45 changed files with 329 additions and 217 deletions.
2 changes: 1 addition & 1 deletion doc/website/advanced/configuration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int main(int argc, char* argv[])
mepooConfig.addMemPool({128, 10000}); // payload in bytes, chunk count
mepooConfig.addMemPool({265, 10000});

auto currentGroup = iox::posix::PosixGroup::getGroupOfCurrentProcess();
auto currentGroup = iox::PosixGroup::getGroupOfCurrentProcess();
roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mepooConfig});

// configure the chunk count for the introspection; each introspection topic gets this number of chunks
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_examples/iceperf/roudi_main_static_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char* argv[])
mepooConfig.addMemPool({ONE_MEGABYTE * 4, 10});

/// We want to use the Shared Memory Segment for the current user
auto currentGroup = iox::posix::PosixGroup::getGroupOfCurrentProcess();
auto currentGroup = iox::PosixGroup::getGroupOfCurrentProcess();

/// Create an Entry for a new Shared Memory Segment from the MempoolConfig and add it to the RouDiConfig
roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mepooConfig});
Expand All @@ -59,12 +59,12 @@ int main(int argc, char* argv[])
/// These names defines groups whose members are either to read/write from/to the respective shared memory segment.
/// @note the groups needs to be registered in /etc/groups.
/// @code
/// iox::posix::PosixGroup::string_t readerGroup{iox::TruncateToCapacity, "readerGroup"};
/// iox::posix::PosixGroup::string_t writerGroup{iox::TruncateToCapacity, "writerGroup"};
/// iox::PosixGroup::string_t readerGroup{iox::TruncateToCapacity, "readerGroup"};
/// iox::PosixGroup::string_t writerGroup{iox::TruncateToCapacity, "writerGroup"};
/// iox::mepoo::SegmentConfig::SegmentEntry segentry({readerGroup, writerGroup, mepooConfig});
/// roudiConfig.m_sharedMemorySegments.push_back(
/// {iox::posix::PosixGroup::string_t(iox::TruncateToCapacity, reader),
/// iox::posix::PosixGroup::string_t(iox::TruncateToCapacity, writer),
/// {iox::PosixGroup::string_t(iox::TruncateToCapacity, reader),
/// iox::PosixGroup::string_t(iox::TruncateToCapacity, writer),
/// mempoolConfig})
/// @endcode

Expand Down
2 changes: 2 additions & 0 deletions iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cc_library(
"design/source/*.cpp",
"filesystem/source/*.cpp",
"memory/source/*.cpp",
"posix/auth/source/*.cpp",
"posix/design/source/*.cpp",
"posix/filesystem/source/*.cpp",
"posix/time/source/*.cpp",
Expand All @@ -66,6 +67,7 @@ cc_library(
"include/",
"legacy/include/",
"memory/include/",
"posix/auth/include/",
"posix/design/include/",
"posix/filesystem/include/",
"posix/time/include/",
Expand Down
5 changes: 4 additions & 1 deletion iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ iox_add_library(
${PROJECT_SOURCE_DIR}/functional/include
${PROJECT_SOURCE_DIR}/reporting/include

${PROJECT_SOURCE_DIR}/posix/auth/include
${PROJECT_SOURCE_DIR}/posix/design/include
${PROJECT_SOURCE_DIR}/posix/filesystem/include
${PROJECT_SOURCE_DIR}/posix/time/include
Expand All @@ -82,6 +83,7 @@ iox_add_library(
functional/include/
reporting/include/

posix/auth/include/
posix/design/include/
posix/filesystem/include/
posix/time/include/
Expand All @@ -103,7 +105,6 @@ iox_add_library(
source/posix_wrapper/file_lock.cpp
source/posix_wrapper/mutex.cpp
source/posix_wrapper/named_semaphore.cpp
source/posix_wrapper/posix_access_rights.cpp
source/posix_wrapper/scheduler.cpp
source/posix_wrapper/semaphore_interface.cpp
source/posix_wrapper/shared_memory_object.cpp
Expand All @@ -118,6 +119,8 @@ iox_add_library(
time/source/duration.cpp
utility/source/unique_id.cpp

posix/auth/source/posix_group.cpp
posix/auth/source/posix_user.cpp
posix/design/source/file_management_interface.cpp
posix/filesystem/source/file.cpp
posix/time/source/adaptive_wait.cpp
Expand Down
8 changes: 7 additions & 1 deletion iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
|`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). |
|`FileLock` | | File lock C++ wrapping class. |
|`posix_access_rights` | | Rights and user management interface. |

### Functional (functional)

Expand Down Expand Up @@ -174,6 +173,13 @@ setTimeout(5_ms); // 5 milliseconds
|`deadline_timer | | Polling based timer to check for an elapsed deadline. |
|`adaptive_wait` | i | Building block to realize busy waiting loops with low CPU load. |
### Authentication (auth)
| class | internal | description |
|:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`posix_group` | | Access to user information. |
|`posix_user` | | Access to group information. |
<center>
[Check out iceoryx_hoofs on GitHub :fontawesome-brands-github:](https://github.com/eclipse-iceoryx/iceoryx/tree/master/iceoryx_hoofs/){ .md-button } <!--NOLINT required only for the website, github URL required-->
</center>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#ifndef IOX_HOOFS_POSIX_WRAPPER_ACCESS_CONTROL_HPP
#define IOX_HOOFS_POSIX_WRAPPER_ACCESS_CONTROL_HPP

#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp"
#include "iceoryx_platform/acl.hpp"
#include "iox/expected.hpp"
#include "iox/posix_group.hpp"
#include "iox/posix_user.hpp"
#include "iox/string.hpp"
#include "iox/unique_ptr.hpp"
#include "iox/vector.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. 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_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP
#define IOX_HOOFS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP

#include "iox/detail/deprecation_marker.hpp"
#include "iox/posix_group.hpp"
#include "iox/posix_user.hpp"

IOX_DEPRECATED_HEADER_SINCE(3, "Please include 'iox/posix_call.hpp' instead.")

namespace iox
{
namespace posix
{
using PosixGroup IOX_DEPRECATED_SINCE(3,
"Please use 'iox::PosixGroup' from 'iox/posix_group.hpp' instead.") = PosixGroup;
using PosixUser IOX_DEPRECATED_SINCE(3, "Please use 'iox::PosixUser' from 'iox/posix_user.hpp' instead.") = PosixUser;
} // namespace posix
} // namespace iox

#endif // IOX_HOOFS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP
#define IOX_HOOFS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP

#ifndef IOX_HOOFS_POSIX_AUTH_POSIX_GROUP_HPP
#define IOX_HOOFS_POSIX_AUTH_POSIX_GROUP_HPP

#include "iceoryx_platform/platform_settings.hpp"
#include "iceoryx_platform/types.hpp"
#include "iox/optional.hpp"
#include "iox/string.hpp"
#include "iox/vector.hpp"

#include <string>

namespace iox
{
namespace posix
{
static constexpr int MaxNumberOfGroups = 888;

class PosixGroup
{
public:
Expand All @@ -55,33 +51,6 @@ class PosixGroup
bool m_doesExist{false};
};

class PosixUser
{
public:
using groupVector_t = vector<PosixGroup, MaxNumberOfGroups>;

using userName_t = string<platform::MAX_USER_NAME_LENGTH>;

explicit PosixUser(const uid_t id) noexcept;
explicit PosixUser(const userName_t& name) noexcept;

groupVector_t getGroups() const noexcept;
userName_t getName() const noexcept;
uid_t getID() const noexcept;

bool doesExist() const noexcept;

static PosixUser getUserOfCurrentProcess() noexcept;

static optional<uid_t> getUserID(const userName_t& name) noexcept;
static optional<userName_t> getUserName(uid_t id) noexcept;

private:
uid_t m_id;
bool m_doesExist{false};
};

} // namespace posix
} // namespace iox

#endif // IOX_HOOFS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP
#endif // IOX_HOOFS_POSIX_AUTH_POSIX_GROUP_HPP
61 changes: 61 additions & 0 deletions iceoryx_hoofs/posix/auth/include/iox/posix_user.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. 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_POSIX_AUTH_POSIX_USER_HPP
#define IOX_HOOFS_POSIX_AUTH_POSIX_USER_HPP

#include "iceoryx_platform/platform_settings.hpp"
#include "iceoryx_platform/types.hpp"
#include "iox/optional.hpp"
#include "iox/posix_group.hpp"
#include "iox/string.hpp"
#include "iox/vector.hpp"

#include <string>

namespace iox
{
class PosixUser
{
public:
static constexpr uint64_t MAX_NUMBER_OF_GROUPS = 888;
using groupVector_t = vector<PosixGroup, MAX_NUMBER_OF_GROUPS>;

using userName_t = string<platform::MAX_USER_NAME_LENGTH>;

explicit PosixUser(const uid_t id) noexcept;
explicit PosixUser(const userName_t& name) noexcept;

groupVector_t getGroups() const noexcept;
userName_t getName() const noexcept;
uid_t getID() const noexcept;

bool doesExist() const noexcept;

static PosixUser getUserOfCurrentProcess() noexcept;

static optional<uid_t> getUserID(const userName_t& name) noexcept;
static optional<userName_t> getUserName(uid_t id) noexcept;

private:
uid_t m_id;
bool m_doesExist{false};
};

} // namespace iox

#endif // IOX_HOOFS_POSIX_AUTH_POSIX_USER_HPP
106 changes: 106 additions & 0 deletions iceoryx_hoofs/posix/auth/source/posix_group.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. 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

#include "iox/posix_group.hpp"
#include "iceoryx_platform/grp.hpp"
#include "iceoryx_platform/platform_correction.hpp"
#include "iceoryx_platform/types.hpp"
#include "iox/logging.hpp"
#include "iox/posix_call.hpp"
#include "iox/uninitialized_array.hpp"

#include <limits>

namespace iox
{
PosixGroup::PosixGroup(gid_t id) noexcept
: m_id(id)
, m_doesExist(getGroupName(id).has_value())
{
}

PosixGroup::PosixGroup(const PosixGroup::groupName_t& name) noexcept
{
auto id = getGroupID(name);
if (id.has_value())
{
m_id = id.value();
}
else
{
IOX_LOG(ERROR, "Error: Group name not found");
m_id = std::numeric_limits<gid_t>::max();
}
}

bool PosixGroup::operator==(const PosixGroup& other) const noexcept
{
return (m_id == other.m_id);
}

PosixGroup PosixGroup::getGroupOfCurrentProcess() noexcept
{
return PosixGroup(getgid());
}

optional<gid_t> PosixGroup::getGroupID(const PosixGroup::groupName_t& name) noexcept
{
auto getgrnamCall = IOX_POSIX_CALL(getgrnam)(name.c_str()).failureReturnValue(nullptr).evaluate();

if (getgrnamCall.has_error())
{
IOX_LOG(ERROR, "Error: Could not find group '" << name << "'.");
return nullopt_t();
}

return make_optional<gid_t>(getgrnamCall->value->gr_gid);
}

optional<PosixGroup::groupName_t> PosixGroup::getGroupName(gid_t id) noexcept
{
auto getgrgidCall = IOX_POSIX_CALL(getgrgid)(id).failureReturnValue(nullptr).evaluate();

if (getgrgidCall.has_error())
{
IOX_LOG(ERROR, "Error: Could not find group with id '" << id << "'.");
return nullopt_t();
}

return make_optional<groupName_t>(groupName_t(iox::TruncateToCapacity, getgrgidCall->value->gr_name));
}

PosixGroup::groupName_t PosixGroup::getName() const noexcept
{
auto name = getGroupName(m_id);
if (name.has_value())
{
return name.value();
}

return groupName_t();
}

gid_t PosixGroup::getID() const noexcept
{
return m_id;
}

bool PosixGroup::doesExist() const noexcept
{
return m_doesExist;
}
} // namespace iox
Loading

0 comments on commit af2bd8f

Please sign in to comment.