forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iox-eclipse-iceoryx#1391 Move 'PosixGroup' and 'PosixUser' to 'iox/po…
…six_group.hpp' and 'iox/posix_user.hpp'
- Loading branch information
1 parent
f0622f1
commit af2bd8f
Showing
45 changed files
with
329 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
iceoryx_hoofs/legacy/include/iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.