permissions.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_PERMISSIONS_HPP
  11. #define BOOST_INTERPROCESS_PERMISSIONS_HPP
  12. /// @cond
  13. #if defined (_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/interprocess/detail/config_begin.hpp>
  17. #include <boost/interprocess/detail/workaround.hpp>
  18. #include <boost/interprocess/interprocess_fwd.hpp>
  19. #if defined(BOOST_INTERPROCESS_WINDOWS)
  20. #include <boost/interprocess/detail/win32_api.hpp>
  21. #endif
  22. /// @endcond
  23. //!\file
  24. //!Describes permissions class
  25. namespace boost {
  26. namespace interprocess {
  27. /// @cond
  28. #if defined(BOOST_INTERPROCESS_WINDOWS)
  29. namespace ipcdetail {
  30. template <int Dummy>
  31. struct unrestricted_permissions_holder
  32. {
  33. static winapi::interprocess_all_access_security unrestricted;
  34. };
  35. template<int Dummy>
  36. winapi::interprocess_all_access_security unrestricted_permissions_holder<Dummy>::unrestricted;
  37. } //namespace ipcdetail {
  38. #endif //defined BOOST_INTERPROCESS_WINDOWS
  39. /// @endcond
  40. //!The permissions class represents permissions to be set to shared memory or
  41. //!files, that can be constructed form usual permission representations:
  42. //!a SECURITY_ATTRIBUTES pointer in windows or ORed rwx chmod integer in UNIX.
  43. class permissions
  44. {
  45. /// @cond
  46. #if defined(BOOST_INTERPROCESS_WINDOWS)
  47. typedef void* os_permissions_type;
  48. #else
  49. typedef int os_permissions_type;
  50. #endif
  51. os_permissions_type m_perm;
  52. /// @endcond
  53. public:
  54. //!Constructs a permissions object from a user provided os-dependent
  55. //!permissions.
  56. permissions(os_permissions_type type)
  57. : m_perm(type)
  58. {}
  59. //!Constructs a default permissions object:
  60. //!A null security attributes pointer for windows or 0644
  61. //!for UNIX.
  62. permissions()
  63. { set_default(); }
  64. //!Sets permissions to default values:
  65. //!A null security attributes pointer for windows or 0644
  66. //!for UNIX.
  67. void set_default()
  68. {
  69. /// @cond
  70. #if defined (BOOST_INTERPROCESS_WINDOWS)
  71. m_perm = 0;
  72. #else
  73. m_perm = 0644;
  74. #endif
  75. /// @endcond
  76. }
  77. //!Sets permissions to unrestricted access:
  78. //!A null DACL for windows or 0666 for UNIX.
  79. void set_unrestricted()
  80. {
  81. /// @cond
  82. #if defined (BOOST_INTERPROCESS_WINDOWS)
  83. m_perm = &ipcdetail::unrestricted_permissions_holder<0>::unrestricted;
  84. #else
  85. m_perm = 0666;
  86. #endif
  87. /// @endcond
  88. }
  89. //!Sets permissions from a user provided os-dependent
  90. //!permissions.
  91. void set_permissions(os_permissions_type perm)
  92. { m_perm = perm; }
  93. //!Returns stored os-dependent
  94. //!permissions
  95. os_permissions_type get_permissions() const
  96. { return m_perm; }
  97. };
  98. } //namespace interprocess {
  99. } //namespace boost {
  100. #include <boost/interprocess/detail/config_end.hpp>
  101. #endif //BOOST_INTERPROCESS_PERMISSIONS_HPP