]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/log/include/boost/log/utility/permissions.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / log / include / boost / log / utility / permissions.hpp
CommitLineData
7c673cae
FG
1/*
2 * Copyright Lingxi Li 2015.
3 * Copyright Andrey Semashev 2015.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 */
8/*!
9 * \file permissions.hpp
10 * \author Lingxi Li
11 * \author Andrey Semashev
12 * \date 14.10.2015
13 *
14 * The header contains an abstraction wrapper for security permissions.
15 */
16
17#ifndef BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
18#define BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
19
20#include <boost/log/detail/config.hpp>
21#include <boost/log/detail/header.hpp>
22
23#ifdef BOOST_HAS_PRAGMA_ONCE
24#pragma once
25#endif
26
27#ifdef BOOST_WINDOWS
28extern "C" {
29struct _SECURITY_ATTRIBUTES;
30}
31#endif // BOOST_WINDOWS
32
33namespace boost {
34
35#ifdef BOOST_WINDOWS
36namespace detail {
37namespace winapi {
38struct BOOST_LOG_MAY_ALIAS _SECURITY_ATTRIBUTES;
39}
40}
41#endif
42
43namespace interprocess {
44class permissions;
45} // namespace interprocess
46
47BOOST_LOG_OPEN_NAMESPACE
48
49/*!
50 * \brief Access permissions wrapper.
51 *
52 * On Windows platforms, it represents a pointer to \c SECURITY_ATTRIBUTES. The user is responsible
53 * for allocating and reclaiming resources associated with the pointer, \c permissions instance does
54 * not own them.
55 *
56 * On POSIX platforms, it represents a \c mode_t value.
57 */
58class permissions
59{
60public:
61#if defined(BOOST_LOG_DOXYGEN_PASS)
62 //! The type of security permissions, specific to the operating system
63 typedef implementation_defined native_type;
64#elif defined(BOOST_WINDOWS)
65 typedef ::_SECURITY_ATTRIBUTES* native_type;
66#else
67 // Equivalent to POSIX mode_t
68 typedef unsigned int native_type;
69#endif
70
71#if !defined(BOOST_LOG_DOXYGEN_PASS)
72private:
73 native_type m_perms;
74#endif
75
76public:
77 /*!
78 * Default constructor. The method constructs an object that represents
79 * a null \c SECURITY_ATTRIBUTES pointer on Windows platforms, and a
80 * \c mode_t value \c 0644 on POSIX platforms.
81 */
82 permissions() BOOST_NOEXCEPT
83 {
84 set_default();
85 }
86
87 /*!
88 * Copy constructor.
89 */
90 permissions(permissions const& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
91 {
92 }
93
94 /*!
95 * Copy assignment.
96 */
97 permissions& operator=(permissions const& that) BOOST_NOEXCEPT
98 {
99 m_perms = that.m_perms;
100 return *this;
101 }
102
103 /*!
104 * Initializing constructor.
105 */
106 permissions(native_type perms) BOOST_NOEXCEPT : m_perms(perms)
107 {
108 }
109
110#ifdef BOOST_WINDOWS
111 permissions(boost::detail::winapi::_SECURITY_ATTRIBUTES* perms) BOOST_NOEXCEPT : m_perms(reinterpret_cast< native_type >(perms))
112 {
113 }
114#endif
115
116 /*!
117 * Initializing constructor.
118 */
119 BOOST_LOG_API permissions(boost::interprocess::permissions const& perms) BOOST_NOEXCEPT;
120
121#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
122 /*!
123 * Move constructor.
124 */
125 permissions(permissions&& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
126 {
127 that.set_default();
128 }
129
130 /*!
131 * Move assignment.
132 */
133 permissions& operator=(permissions&& that) BOOST_NOEXCEPT
134 {
135 m_perms = that.m_perms;
136 that.set_default();
137 return *this;
138 }
139#endif
140
141 /*!
142 * Sets permissions from the OS-specific permissions.
143 */
144 void set_native(native_type perms) BOOST_NOEXCEPT
145 {
146 m_perms = perms;
147 }
148
149 /*!
150 * Returns the underlying OS-specific permissions.
151 */
152 native_type get_native() const BOOST_NOEXCEPT
153 {
154 return m_perms;
155 }
156
157 /*!
158 * Sets the default permissions, which are equivalent to \c NULL \c SECURITY_ATTRIBUTES
159 * on Windows and \c 0644 on POSIX platforms.
160 */
161 void set_default() BOOST_NOEXCEPT
162 {
163#if defined(BOOST_WINDOWS)
164 m_perms = 0;
165#else
166 m_perms = 0644;
167#endif
168 }
169
170 /*!
171 * Sets unrestricted permissions, which are equivalent to \c SECURITY_ATTRIBUTES with \c NULL DACL
172 * on Windows and \c 0666 on POSIX platforms.
173 */
174 void set_unrestricted()
175 {
176#if defined(BOOST_WINDOWS)
177 m_perms = get_unrestricted_security_attributes();
178#else
179 m_perms = 0666;
180#endif
181 }
182
183 /*!
184 * The method swaps the object with \a that.
185 *
186 * \param that The other object to swap with.
187 */
188 void swap(permissions& that) BOOST_NOEXCEPT
189 {
190 native_type perms = m_perms;
191 m_perms = that.m_perms;
192 that.m_perms = perms;
193 }
194
195 //! Swaps the two \c permissions objects.
196 friend void swap(permissions& a, permissions& b) BOOST_NOEXCEPT
197 {
198 a.swap(b);
199 }
200
201#if !defined(BOOST_LOG_DOXYGEN_PASS) && defined(BOOST_WINDOWS)
202private:
203 static BOOST_LOG_API native_type get_unrestricted_security_attributes();
204#endif
205};
206
207BOOST_LOG_CLOSE_NAMESPACE // namespace log
208
209} // namespace boost
210
211#include <boost/log/detail/footer.hpp>
212
213#endif // BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_