permissions.hpp 3.4 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. #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. #endif
  26. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  27. //!\file
  28. //!Describes permissions class
  29. namespace boost {
  30. namespace interprocess {
  31. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  32. #if defined(BOOST_INTERPROCESS_WINDOWS)
  33. namespace ipcdetail {
  34. template <int Dummy>
  35. struct unrestricted_permissions_holder
  36. {
  37. static winapi::interprocess_all_access_security unrestricted;
  38. };
  39. template<int Dummy>
  40. winapi::interprocess_all_access_security unrestricted_permissions_holder<Dummy>::unrestricted;
  41. } //namespace ipcdetail {
  42. #endif //defined BOOST_INTERPROCESS_WINDOWS
  43. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  44. //!The permissions class represents permissions to be set to shared memory or
  45. //!files, that can be constructed form usual permission representations:
  46. //!a SECURITY_ATTRIBUTES pointer in windows or ORed rwx chmod integer in UNIX.
  47. class permissions
  48. {
  49. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  50. #if defined(BOOST_INTERPROCESS_WINDOWS)
  51. typedef void* os_permissions_type;
  52. #else
  53. typedef int os_permissions_type;
  54. #endif
  55. os_permissions_type m_perm;
  56. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  57. public:
  58. //!Constructs a permissions object from a user provided os-dependent
  59. //!permissions.
  60. permissions(os_permissions_type type)
  61. : m_perm(type)
  62. {}
  63. //!Constructs a default permissions object:
  64. //!A null security attributes pointer for windows or 0644
  65. //!for UNIX.
  66. permissions()
  67. { set_default(); }
  68. //!Sets permissions to default values:
  69. //!A null security attributes pointer for windows or 0644
  70. //!for UNIX.
  71. void set_default()
  72. {
  73. #if defined (BOOST_INTERPROCESS_WINDOWS)
  74. m_perm = 0;
  75. #else
  76. m_perm = 0644;
  77. #endif
  78. }
  79. //!Sets permissions to unrestricted access:
  80. //!A null DACL for windows or 0666 for UNIX.
  81. void set_unrestricted()
  82. {
  83. #if defined (BOOST_INTERPROCESS_WINDOWS)
  84. m_perm = &ipcdetail::unrestricted_permissions_holder<0>::unrestricted;
  85. #else
  86. m_perm = 0666;
  87. #endif
  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