Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:29

0001 /*
0002  *                 Copyright Lingxi Li 2015.
0003  *              Copyright Andrey Semashev 2015.
0004  * Distributed under the Boost Software License, Version 1.0.
0005  *    (See accompanying file LICENSE_1_0.txt or copy at
0006  *          http://www.boost.org/LICENSE_1_0.txt)
0007  */
0008 /*!
0009  * \file   permissions.hpp
0010  * \author Lingxi Li
0011  * \author Andrey Semashev
0012  * \date   14.10.2015
0013  *
0014  * The header contains an abstraction wrapper for security permissions.
0015  */
0016 
0017 #ifndef BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
0018 #define BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
0019 
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/detail/header.hpp>
0022 
0023 #ifdef BOOST_HAS_PRAGMA_ONCE
0024 #pragma once
0025 #endif
0026 
0027 #ifdef BOOST_WINDOWS
0028 extern "C" {
0029 struct _SECURITY_ATTRIBUTES;
0030 }
0031 #endif // BOOST_WINDOWS
0032 
0033 namespace boost {
0034 
0035 #ifdef BOOST_WINDOWS
0036 #if defined(BOOST_GCC) && BOOST_GCC >= 40600
0037 #pragma GCC diagnostic push
0038 // type attributes ignored after type is already defined
0039 #pragma GCC diagnostic ignored "-Wattributes"
0040 #endif
0041 namespace winapi {
0042 struct BOOST_LOG_MAY_ALIAS _SECURITY_ATTRIBUTES;
0043 }
0044 #if defined(BOOST_GCC) && BOOST_GCC >= 40600
0045 #pragma GCC diagnostic pop
0046 #endif
0047 #endif
0048 
0049 namespace interprocess {
0050 class permissions;
0051 } // namespace interprocess
0052 
0053 BOOST_LOG_OPEN_NAMESPACE
0054 
0055 /*!
0056  * \brief Access permissions wrapper.
0057  *
0058  * On Windows platforms, it represents a pointer to \c SECURITY_ATTRIBUTES. The user is responsible
0059  * for allocating and reclaiming resources associated with the pointer, \c permissions instance does
0060  * not own them.
0061  *
0062  * On POSIX platforms, it represents a \c mode_t value.
0063  */
0064 class permissions
0065 {
0066 public:
0067 #if defined(BOOST_LOG_DOXYGEN_PASS)
0068     //! The type of security permissions, specific to the operating system
0069     typedef implementation_defined native_type;
0070 #elif defined(BOOST_WINDOWS)
0071     typedef ::_SECURITY_ATTRIBUTES* native_type;
0072 #else
0073     // Equivalent to POSIX mode_t
0074     typedef unsigned int native_type;
0075 #endif
0076 
0077 #if !defined(BOOST_LOG_DOXYGEN_PASS)
0078 private:
0079     native_type m_perms;
0080 #endif
0081 
0082 public:
0083     /*!
0084      * Default constructor. The method constructs an object that represents
0085      * a null \c SECURITY_ATTRIBUTES pointer on Windows platforms, and a
0086      * \c mode_t value \c 0644 on POSIX platforms.
0087      */
0088     permissions() BOOST_NOEXCEPT
0089     {
0090         set_default();
0091     }
0092 
0093     /*!
0094      * Copy constructor.
0095      */
0096     permissions(permissions const& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
0097     {
0098     }
0099 
0100     /*!
0101      * Copy assignment.
0102      */
0103     permissions& operator=(permissions const& that) BOOST_NOEXCEPT
0104     {
0105         m_perms = that.m_perms;
0106         return *this;
0107     }
0108 
0109     /*!
0110      * Initializing constructor.
0111      */
0112     permissions(native_type perms) BOOST_NOEXCEPT : m_perms(perms)
0113     {
0114     }
0115 
0116 #ifdef BOOST_WINDOWS
0117     permissions(boost::winapi::_SECURITY_ATTRIBUTES* perms) BOOST_NOEXCEPT : m_perms(reinterpret_cast< native_type >(perms))
0118     {
0119     }
0120 #endif
0121 
0122     /*!
0123      * Initializing constructor.
0124      */
0125     BOOST_LOG_API permissions(boost::interprocess::permissions const& perms) BOOST_NOEXCEPT;
0126 
0127 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0128     /*!
0129      * Move constructor.
0130      */
0131     permissions(permissions&& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
0132     {
0133         that.set_default();
0134     }
0135 
0136     /*!
0137      * Move assignment.
0138      */
0139     permissions& operator=(permissions&& that) BOOST_NOEXCEPT
0140     {
0141         m_perms = that.m_perms;
0142         that.set_default();
0143         return *this;
0144     }
0145 #endif
0146 
0147     /*!
0148      * Sets permissions from the OS-specific permissions.
0149      */
0150     void set_native(native_type perms) BOOST_NOEXCEPT
0151     {
0152         m_perms = perms;
0153     }
0154 
0155     /*!
0156      * Returns the underlying OS-specific permissions.
0157      */
0158     native_type get_native() const BOOST_NOEXCEPT
0159     {
0160         return m_perms;
0161     }
0162 
0163     /*!
0164      * Sets the default permissions, which are equivalent to \c NULL \c SECURITY_ATTRIBUTES
0165      * on Windows and \c 0644 on POSIX platforms.
0166      */
0167     void set_default() BOOST_NOEXCEPT
0168     {
0169 #if defined(BOOST_WINDOWS)
0170         m_perms = 0;
0171 #else
0172         m_perms = 0644;
0173 #endif
0174     }
0175 
0176     /*!
0177      * Sets unrestricted permissions, which are equivalent to \c SECURITY_ATTRIBUTES with \c NULL DACL
0178      * on Windows and \c 0666 on POSIX platforms.
0179      */
0180     void set_unrestricted()
0181     {
0182 #if defined(BOOST_WINDOWS)
0183         m_perms = get_unrestricted_security_attributes();
0184 #else
0185         m_perms = 0666;
0186 #endif
0187     }
0188 
0189     /*!
0190      * The method swaps the object with \a that.
0191      *
0192      * \param that The other object to swap with.
0193      */
0194     void swap(permissions& that) BOOST_NOEXCEPT
0195     {
0196         native_type perms = m_perms;
0197         m_perms = that.m_perms;
0198         that.m_perms = perms;
0199     }
0200 
0201     //! Swaps the two \c permissions objects.
0202     friend void swap(permissions& a, permissions& b) BOOST_NOEXCEPT
0203     {
0204         a.swap(b);
0205     }
0206 
0207 #if !defined(BOOST_LOG_DOXYGEN_PASS) && defined(BOOST_WINDOWS)
0208 private:
0209     static BOOST_LOG_API native_type get_unrestricted_security_attributes();
0210 #endif
0211 };
0212 
0213 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0214 
0215 } // namespace boost
0216 
0217 #include <boost/log/detail/footer.hpp>
0218 
0219 #endif // BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_