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)
9 * \file permissions.hpp
11 * \author Andrey Semashev
14 * The header contains an abstraction wrapper for security permissions.
17 #ifndef BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
18 #define BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/header.hpp>
23 #ifdef BOOST_HAS_PRAGMA_ONCE
29 struct _SECURITY_ATTRIBUTES;
31 #endif // BOOST_WINDOWS
36 #if defined(BOOST_GCC) && BOOST_GCC >= 40600
37 #pragma GCC diagnostic push
38 // type attributes ignored after type is already defined
39 #pragma GCC diagnostic ignored "-Wattributes"
42 struct BOOST_LOG_MAY_ALIAS _SECURITY_ATTRIBUTES;
44 #if defined(BOOST_GCC) && BOOST_GCC >= 40600
45 #pragma GCC diagnostic pop
49 namespace interprocess {
51 } // namespace interprocess
53 BOOST_LOG_OPEN_NAMESPACE
56 * \brief Access permissions wrapper.
58 * On Windows platforms, it represents a pointer to \c SECURITY_ATTRIBUTES. The user is responsible
59 * for allocating and reclaiming resources associated with the pointer, \c permissions instance does
62 * On POSIX platforms, it represents a \c mode_t value.
67 #if defined(BOOST_LOG_DOXYGEN_PASS)
68 //! The type of security permissions, specific to the operating system
69 typedef implementation_defined native_type;
70 #elif defined(BOOST_WINDOWS)
71 typedef ::_SECURITY_ATTRIBUTES* native_type;
73 // Equivalent to POSIX mode_t
74 typedef unsigned int native_type;
77 #if !defined(BOOST_LOG_DOXYGEN_PASS)
84 * Default constructor. The method constructs an object that represents
85 * a null \c SECURITY_ATTRIBUTES pointer on Windows platforms, and a
86 * \c mode_t value \c 0644 on POSIX platforms.
88 permissions() BOOST_NOEXCEPT
96 permissions(permissions const& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
103 permissions& operator=(permissions const& that) BOOST_NOEXCEPT
105 m_perms = that.m_perms;
110 * Initializing constructor.
112 permissions(native_type perms) BOOST_NOEXCEPT : m_perms(perms)
117 permissions(boost::winapi::_SECURITY_ATTRIBUTES* perms) BOOST_NOEXCEPT : m_perms(reinterpret_cast< native_type >(perms))
123 * Initializing constructor.
125 BOOST_LOG_API permissions(boost::interprocess::permissions const& perms) BOOST_NOEXCEPT;
127 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
131 permissions(permissions&& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
139 permissions& operator=(permissions&& that) BOOST_NOEXCEPT
141 m_perms = that.m_perms;
148 * Sets permissions from the OS-specific permissions.
150 void set_native(native_type perms) BOOST_NOEXCEPT
156 * Returns the underlying OS-specific permissions.
158 native_type get_native() const BOOST_NOEXCEPT
164 * Sets the default permissions, which are equivalent to \c NULL \c SECURITY_ATTRIBUTES
165 * on Windows and \c 0644 on POSIX platforms.
167 void set_default() BOOST_NOEXCEPT
169 #if defined(BOOST_WINDOWS)
177 * Sets unrestricted permissions, which are equivalent to \c SECURITY_ATTRIBUTES with \c NULL DACL
178 * on Windows and \c 0666 on POSIX platforms.
180 void set_unrestricted()
182 #if defined(BOOST_WINDOWS)
183 m_perms = get_unrestricted_security_attributes();
190 * The method swaps the object with \a that.
192 * \param that The other object to swap with.
194 void swap(permissions& that) BOOST_NOEXCEPT
196 native_type perms = m_perms;
197 m_perms = that.m_perms;
198 that.m_perms = perms;
201 //! Swaps the two \c permissions objects.
202 friend void swap(permissions& a, permissions& b) BOOST_NOEXCEPT
207 #if !defined(BOOST_LOG_DOXYGEN_PASS) && defined(BOOST_WINDOWS)
209 static BOOST_LOG_API native_type get_unrestricted_security_attributes();
213 BOOST_LOG_CLOSE_NAMESPACE // namespace log
217 #include <boost/log/detail/footer.hpp>
219 #endif // BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_