Blame view

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