iceoryx_doc  1.0.1
access_control.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_UTILS_POSIX_WRAPPER_ACCESS_CONTROL_HPP
17 #define IOX_UTILS_POSIX_WRAPPER_ACCESS_CONTROL_HPP
18 
19 #include "iceoryx_utils/cxx/optional.hpp"
20 #include "iceoryx_utils/cxx/string.hpp"
21 #include "iceoryx_utils/cxx/vector.hpp"
22 #include "iceoryx_utils/platform/acl.hpp"
23 
24 #include <cstdint>
25 #include <functional>
26 #include <iostream>
27 #include <memory>
28 #include <type_traits>
29 
30 namespace iox
31 {
32 namespace posix
33 {
42 {
43  public:
44  using string_t = cxx::string<100>;
45 
47  static constexpr int32_t MaxNumOfPermissions = 20;
48 
50 #if defined(QNX) || defined(QNX__) || defined(__QNX__)
51  enum class Category : std::underlying_type<acl_tag_t>::type
52 #else
53  enum class Category : acl_tag_t
54 #endif
55  {
56  USER = ACL_USER_OBJ,
58  SPECIFIC_USER = ACL_USER,
59  GROUP = ACL_GROUP_OBJ,
61  SPECIFIC_GROUP = ACL_GROUP,
62  OTHERS = ACL_OTHER,
63  };
64 
66 #if defined(QNX) || defined(QNX__) || defined(__QNX__)
67  enum class Permission : std::underlying_type<acl_perm_t>::type
68 #else
69  enum class Permission : acl_perm_t
70 #endif
71  {
72  READ = ACL_READ,
73  WRITE = ACL_WRITE,
74  READWRITE = Permission::READ | Permission::WRITE,
75  NONE = 0
76  };
77 
86  bool addPermissionEntry(const Category f_category, const Permission f_permission, const uint32_t f_id = -1u);
87 
89  bool addPermissionEntry(const Category f_category, const Permission f_permission, const string_t& f_name);
90 
95  bool writePermissionsToFile(const int32_t f_fileDescriptor) const;
96 
97  private:
98  using smartAclPointer_t = std::unique_ptr<std::remove_pointer<acl_t>::type, std::function<void(acl_t)>>;
99 
100  struct PermissionEntry
101  {
102  unsigned int m_category;
103  Permission m_permission;
104  unsigned int m_id;
105  };
106 
108 
109  smartAclPointer_t createACL(const int32_t f_numEntries) const;
110  bool createACLEntry(const acl_t f_ACL, const PermissionEntry& f_entry) const;
111  bool addAclPermission(acl_permset_t f_permset, acl_perm_t f_perm) const;
112 
113  bool m_useACLMask{false};
114 };
115 } // namespace posix
116 } // namespace iox
117 
118 #endif // IOX_UTILS_POSIX_WRAPPER_ACCESS_CONTROL_HPP
string implementation with some adjustments in the API, because we are not allowed to throw exception...
Definition: string.hpp:86
abstraction class for the management of access control lists (ACLs).
Definition: access_control.hpp:42
Category
identifier for a permission entry (user, group, others, ...)
Definition: access_control.hpp:55
@ SPECIFIC_GROUP
a specific group must be identified by a name
@ SPECIFIC_USER
a specific user must be identified by a name
bool addPermissionEntry(const Category f_category, const Permission f_permission, const string_t &f_name)
just like addPermissionEntry(Category, Permission, int) but using a name instead of an id.
bool writePermissionsToFile(const int32_t f_fileDescriptor) const
Write permission entries stored by the AccessController to a file identified by a file descriptor.
bool addPermissionEntry(const Category f_category, const Permission f_permission, const uint32_t f_id=-1u)
define and store a specific permission entry to be used by writePermissionsToFile.
static constexpr int32_t MaxNumOfPermissions
maximum number of permission entries the AccessController can store
Definition: access_control.hpp:47
Permission
access right for a permission entry
Definition: access_control.hpp:71
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28