1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2009. 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 
11 #ifndef BOOST_INTERPROCESS_PERMISSIONS_HPP
12 #define BOOST_INTERPROCESS_PERMISSIONS_HPP
13 
14 /// @cond
15 
16 #if defined (_MSC_VER) && (_MSC_VER >= 1200)
17 #  pragma once
18 #endif
19 
20 #include <boost/interprocess/detail/config_begin.hpp>
21 #include <boost/interprocess/detail/workaround.hpp>
22 #include <boost/interprocess/interprocess_fwd.hpp>
23 
24 #if defined(BOOST_INTERPROCESS_WINDOWS)
25 
26 #include <boost/interprocess/detail/win32_api.hpp>
27 
28 #endif
29 
30 /// @endcond
31 
32 //!\file
33 //!Describes permissions class
34 
35 namespace boost {
36 namespace interprocess {
37 
38 /// @cond
39 
40 #if defined(BOOST_INTERPROCESS_WINDOWS)
41 
42 namespace detail {
43 
44 template <int Dummy>
45 struct unrestricted_permissions_holder
46 {
47    static winapi::interprocess_all_access_security unrestricted;
48 };
49 
50 template<int Dummy>
51 winapi::interprocess_all_access_security unrestricted_permissions_holder<Dummy>::unrestricted;
52 
53 }  //namespace detail {
54 
55 #endif   //defined BOOST_INTERPROCESS_WINDOWS
56 
57 /// @endcond
58 
59 //!The permissions class represents permissions to be set to shared memory or
60 //!files, that can be constructed form usual permission representations:
61 //!a SECURITY_ATTRIBUTES pointer in windows or ORed rwx chmod integer in UNIX.
62 class permissions
63 {
64    /// @cond
65 
66    #if defined(BOOST_INTERPROCESS_WINDOWS)
67    typedef void*  os_permissions_type;
68    #else
69    typedef int    os_permissions_type;
70    #endif
71    os_permissions_type  m_perm;
72 
73    /// @endcond
74 
75    public:
76    //!Constructs a permissions object from a user provided os-dependent
77    //!permissions.
permissions(os_permissions_type type)78    permissions(os_permissions_type type)
79       : m_perm(type)
80    {}
81 
82    //!Constructs a default permissions object:
83    //!A null security attributes pointer for windows or 0644
84    //!for UNIX.
permissions()85    permissions()
86    {  set_default(); }
87 
88    //!Sets permissions to default values:
89    //!A null security attributes pointer for windows or 0644
90    //!for UNIX.
set_default()91    void set_default()
92    {
93       /// @cond
94       #if defined (BOOST_INTERPROCESS_WINDOWS)
95       m_perm = 0;
96       #else
97       m_perm = 0644;
98       #endif
99       /// @endcond
100    }
101 
102    //!Sets permissions to unrestricted access:
103    //!A null DACL for windows or 0666 for UNIX.
set_unrestricted()104    void set_unrestricted()
105    {
106       /// @cond
107       #if defined (BOOST_INTERPROCESS_WINDOWS)
108       m_perm = &detail::unrestricted_permissions_holder<0>::unrestricted;
109       #else
110       m_perm = 0666;
111       #endif
112       /// @endcond
113    }
114 
115    //!Sets permissions from a user provided os-dependent
116    //!permissions.
set_permissions(os_permissions_type perm)117    void set_permissions(os_permissions_type perm)
118    {  m_perm = perm; }
119 
120    //!Returns stored os-dependent
121    //!permissions
get_permissions() const122    os_permissions_type get_permissions() const
123    {  return m_perm; }
124 };
125 
126 }  //namespace interprocess {
127 }  //namespace boost {
128 
129 #include <boost/interprocess/detail/config_end.hpp>
130 
131 #endif   //BOOST_INTERPROCESS_PERMISSIONS_HPP
132 
133