iceoryx_doc  1.0.1
posix_access_rights.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_POSIX_ACCESS_RIGHTS_HPP
17 #define IOX_UTILS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_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/types.hpp"
23 
24 #include <string>
25 
26 namespace iox
27 {
28 namespace posix
29 {
30 static constexpr int MaxNumberOfGroups = 888;
31 
33 {
34  PosixRights(bool f_read, bool f_write, bool f_execute);
35  bool m_read;
36  bool m_write;
37  bool m_execute;
38 };
39 
41 {
42  public:
43  using string_t = cxx::string<100>;
44  PosixGroup(gid_t f_id);
45  PosixGroup(string_t f_name);
46 
47  bool operator==(const PosixGroup& other) const;
48 
49  string_t getName() const;
50  gid_t getID() const;
51 
52  bool doesExist() const;
53 
54  static PosixGroup getGroupOfCurrentProcess();
55 
56  static cxx::optional<uid_t> getGroupID(const string_t& f_name);
57  static cxx::optional<string_t> getGroupName(gid_t f_id);
58 
59  private:
60  gid_t m_id;
61  bool m_doesExist{false};
62 };
63 
64 class PosixUser
65 {
66  public:
68  using string_t = cxx::string<100>;
69 
70  PosixUser(uid_t f_id);
71  PosixUser(const string_t& f_name);
72 
73  groupVector_t getGroups() const;
74  string_t getName() const;
75  uid_t getID() const;
76 
77  bool doesExist() const;
78 
79  static PosixUser getUserOfCurrentProcess();
80 
81  static cxx::optional<uid_t> getUserID(const string_t& f_name);
82  static cxx::optional<string_t> getUserName(uid_t f_id);
83 
84  private:
85  uid_t m_id;
86  bool m_doesExist{false};
87 };
88 
89 } // namespace posix
90 } // namespace iox
91 
92 #endif // IOX_UTILS_POSIX_WRAPPER_POSIX_ACCESS_RIGHTS_HPP
Optional implementation from the C++17 standard with C++11. The interface is analog to the C++17 stan...
Definition: optional.hpp:63
string implementation with some adjustments in the API, because we are not allowed to throw exception...
Definition: string.hpp:86
C++11 compatible vector implementation. We needed to do some adjustments in the API since we do not u...
Definition: vector.hpp:34
Definition: posix_access_rights.hpp:41
Definition: posix_access_rights.hpp:65
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28
Definition: posix_access_rights.hpp:33