• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *             Copyright Andrey Semashev 2015.
3  * Distributed under the Boost Software License, Version 1.0.
4  *    (See accompanying file LICENSE_1_0.txt or copy at
5  *          http://www.boost.org/LICENSE_1_0.txt)
6  */
7 /*!
8  * \file   permissions.cpp
9  * \author Andrey Semashev
10  * \date   26.12.2015
11  *
12  * \brief  This header is the Boost.Log library implementation, see the library documentation
13  *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
14  */
15 
16 #include <boost/log/detail/config.hpp>
17 #include <boost/log/utility/permissions.hpp>
18 #include <boost/interprocess/permissions.hpp>
19 
20 #if defined(BOOST_WINDOWS)
21 
22 #include <boost/log/exceptions.hpp>
23 #include <boost/throw_exception.hpp>
24 #include <boost/log/utility/once_block.hpp>
25 #include <windows.h>
26 #include <boost/log/detail/header.hpp>
27 
28 namespace boost {
29 
30 BOOST_LOG_OPEN_NAMESPACE
31 
32 BOOST_LOG_ANONYMOUS_NAMESPACE {
33 
34 static ::SECURITY_DESCRIPTOR g_unrestricted_security_descriptor;
35 static ::SECURITY_ATTRIBUTES g_unrestricted_security_attributes;
36 
37 } // namespace
38 
39 BOOST_LOG_API permissions::native_type permissions::get_unrestricted_security_attributes()
40 {
BOOST_LOG_ONCE_BLOCK()41     BOOST_LOG_ONCE_BLOCK()
42     {
43         if (!InitializeSecurityDescriptor(&g_unrestricted_security_descriptor, SECURITY_DESCRIPTOR_REVISION))
44         {
45             DWORD err = GetLastError();
46             BOOST_LOG_THROW_DESCR_PARAMS(system_error, "Failed to initialize security descriptor", (err));
47         }
48 
49         if (!SetSecurityDescriptorDacl(&g_unrestricted_security_descriptor, TRUE, NULL, FALSE))
50         {
51             DWORD err = GetLastError();
52             BOOST_LOG_THROW_DESCR_PARAMS(system_error, "Failed to set null DACL to a security descriptor", (err));
53         }
54 
55         g_unrestricted_security_attributes.nLength = sizeof(g_unrestricted_security_attributes);
56         g_unrestricted_security_attributes.lpSecurityDescriptor = &g_unrestricted_security_descriptor;
57         g_unrestricted_security_attributes.bInheritHandle = FALSE;
58     }
59 
60     return &g_unrestricted_security_attributes;
61 }
62 
63 //! Initializing constructor
permissions(boost::interprocess::permissions const & perms)64 BOOST_LOG_API permissions::permissions(boost::interprocess::permissions const& perms) BOOST_NOEXCEPT :
65     m_perms(reinterpret_cast< native_type >(perms.get_permissions()))
66 {
67 }
68 
69 
70 BOOST_LOG_CLOSE_NAMESPACE // namespace log
71 
72 } // namespace boost
73 
74 #else // defined(BOOST_WINDOWS)
75 
76 #include <boost/log/detail/header.hpp>
77 
78 namespace boost {
79 
80 BOOST_LOG_OPEN_NAMESPACE
81 
82 //! Initializing constructor
permissions(boost::interprocess::permissions const & perms)83 BOOST_LOG_API permissions::permissions(boost::interprocess::permissions const& perms) BOOST_NOEXCEPT :
84     m_perms(static_cast< native_type >(perms.get_permissions()))
85 {
86 }
87 
88 BOOST_LOG_CLOSE_NAMESPACE // namespace log
89 
90 } // namespace boost
91 
92 #endif // defined(BOOST_WINDOWS)
93 
94 #include <boost/log/detail/footer.hpp>
95