permissions.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  13. #ifndef BOOST_CONFIG_HPP
  14. # include <boost/config.hpp>
  15. #endif
  16. #
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/interprocess/detail/config_begin.hpp>
  21. #include <boost/interprocess/detail/workaround.hpp>
  22. #include <boost/interprocess/interprocess_fwd.hpp>
  23. #if defined(BOOST_INTERPROCESS_WINDOWS)
  24. #include <boost/interprocess/detail/win32_api.hpp>
  25. #else
  26. #include <sys/stat.h>
  27. #endif
  28. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  29. //!\file
  30. //!Describes permissions class
  31. namespace boost {
  32. namespace interprocess {
  33. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  34. #if defined(BOOST_INTERPROCESS_WINDOWS)
  35. namespace ipcdetail {
  36. template <int Dummy>
  37. struct unrestricted_permissions_holder
  38. {
  39. static winapi::interprocess_all_access_security unrestricted;
  40. };
  41. template<int Dummy>
  42. winapi::interprocess_all_access_security unrestricted_permissions_holder<Dummy>::unrestricted;
  43. } //namespace ipcdetail {
  44. #endif //defined BOOST_INTERPROCESS_WINDOWS
  45. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  46. //!The permissions class represents permissions to be set to shared memory or
  47. //!files, that can be constructed form usual permission representations:
  48. //!a SECURITY_ATTRIBUTES pointer in windows or ORed rwx chmod integer in UNIX.
  49. class permissions
  50. {
  51. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  52. #if defined(BOOST_INTERPROCESS_WINDOWS)
  53. typedef void* os_permissions_type;
  54. #else
  55. typedef ::mode_t os_permissions_type;
  56. #endif
  57. os_permissions_type m_perm;
  58. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  59. public:
  60. //!Constructs a permissions object from a user provided os-dependent
  61. //!permissions.
  62. permissions(os_permissions_type type) BOOST_NOEXCEPT
  63. : m_perm(type)
  64. {}
  65. //!Constructs a default permissions object:
  66. //!A null security attributes pointer for windows or 0644
  67. //!for UNIX.
  68. permissions() BOOST_NOEXCEPT
  69. { set_default(); }
  70. //!Sets permissions to default values:
  71. //!A null security attributes pointer for windows or 0644
  72. //!for UNIX.
  73. void set_default() BOOST_NOEXCEPT
  74. {
  75. #if defined (BOOST_INTERPROCESS_WINDOWS)
  76. m_perm = 0;
  77. #else
  78. m_perm = 0644;
  79. #endif
  80. }
  81. //!Sets permissions to unrestricted access:
  82. //!A null DACL for windows or 0666 for UNIX.
  83. void set_unrestricted() BOOST_NOEXCEPT
  84. {
  85. #if defined (BOOST_INTERPROCESS_WINDOWS)
  86. m_perm = &ipcdetail::unrestricted_permissions_holder<0>::unrestricted;
  87. #else
  88. m_perm = 0666;
  89. #endif
  90. }
  91. //!Sets permissions from a user provided os-dependent
  92. //!permissions.
  93. void set_permissions(os_permissions_type perm) BOOST_NOEXCEPT
  94. { m_perm = perm; }
  95. //!Returns stored os-dependent
  96. //!permissions
  97. os_permissions_type get_permissions() const BOOST_NOEXCEPT
  98. { return m_perm; }
  99. };
  100. } //namespace interprocess {
  101. } //namespace boost {
  102. #include <boost/interprocess/detail/config_end.hpp>
  103. #endif //BOOST_INTERPROCESS_PERMISSIONS_HPP