You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
7.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/security/acl_sequence.hpp
  3. *
  4. * Purpose: Helper for accessing token information.
  5. *
  6. * Created: 26th June 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2003-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/security/acl_sequence.hpp
  40. *
  41. * \brief [C++ only] Definition of the winstl::acl_sequence class
  42. * (\ref group__library__security "Security" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_SECURITY_HPP_ACL_SEQUENCE
  45. #define WINSTL_INCL_WINSTL_SECURITY_HPP_ACL_SEQUENCE
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_SECURITY_HPP_ACL_SEQUENCE_MAJOR 4
  48. # define WINSTL_VER_WINSTL_SECURITY_HPP_ACL_SEQUENCE_MINOR 0
  49. # define WINSTL_VER_WINSTL_SECURITY_HPP_ACL_SEQUENCE_REVISION 2
  50. # define WINSTL_VER_WINSTL_SECURITY_HPP_ACL_SEQUENCE_EDIT 31
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  56. # include <winstl/winstl.h>
  57. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  58. #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
  59. # include <stlsoft/collections/util/collections.hpp>
  60. #endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _WINSTL_NO_NAMESPACE
  65. # if defined(_STLSOFT_NO_NAMESPACE) || \
  66. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  67. /* There is no stlsoft namespace, so must define ::winstl */
  68. namespace winstl
  69. {
  70. # else
  71. /* Define stlsoft::winstl_project */
  72. namespace stlsoft
  73. {
  74. namespace winstl_project
  75. {
  76. # endif /* _STLSOFT_NO_NAMESPACE */
  77. #endif /* !_WINSTL_NO_NAMESPACE */
  78. /* /////////////////////////////////////////////////////////////////////////
  79. * Classes
  80. */
  81. /** \brief Provides an iterable sequence of ACEs in an ACL
  82. *
  83. * \ingroup group__library__security
  84. *
  85. * This class provides an iterable sequence of Access Control Entries (ACEs) in
  86. * an Access Control List (ACL).
  87. */
  88. class acl_sequence
  89. : public stlsoft_ns_qual(stl_collection_tag)
  90. {
  91. /// \name Member Types
  92. /// @{
  93. public:
  94. typedef acl_sequence class_type;
  95. /// @}
  96. /// \name Construction
  97. /// @{
  98. public:
  99. ss_explicit_k acl_sequence(PACL pacl)
  100. : m_pacl(pacl)
  101. {}
  102. /// @}
  103. /// \name Iteration
  104. /// @{
  105. public:
  106. /// The const_iterator for the acl_sequence class
  107. class const_iterator
  108. {
  109. protected:
  110. friend class acl_sequence;
  111. const_iterator(ws_uint32_t count, ACE_HEADER *header)
  112. : m_index(0)
  113. , m_count(count)
  114. , m_header(header)
  115. {}
  116. public:
  117. const_iterator()
  118. : m_index(0)
  119. , m_count(0)
  120. , m_header(0)
  121. {}
  122. const_iterator(const_iterator const& rhs)
  123. : m_index(rhs.m_index)
  124. , m_count(rhs.m_count)
  125. , m_header(rhs.m_header)
  126. {}
  127. const_iterator& operator =(const_iterator const& rhs)
  128. {
  129. m_index = rhs.m_index;
  130. m_count = rhs.m_count;
  131. m_header = rhs.m_header;
  132. return *this;
  133. }
  134. const_iterator& operator ++()
  135. {
  136. WINSTL_MESSAGE_ASSERT("Incrementing an invalid iterator", (m_header != 0 && m_index < m_count));
  137. if(++m_index == m_count)
  138. {
  139. m_header = 0;
  140. }
  141. else
  142. {
  143. m_header = (ACE_HEADER*)ptr_byte_offset(m_header, m_header->AceSize);
  144. }
  145. return *this;
  146. }
  147. const_iterator operator ++(int)
  148. {
  149. const_iterator ret(*this);
  150. operator ++();
  151. return ret;
  152. }
  153. ACE_HEADER *operator *() const
  154. {
  155. WINSTL_MESSAGE_ASSERT("Dereferencing an invalid iterator", m_header != 0);
  156. return m_header;
  157. }
  158. ws_bool_t operator == (const_iterator const& rhs)
  159. {
  160. return m_header == rhs.m_header;
  161. }
  162. ws_bool_t operator != (const_iterator const& rhs)
  163. {
  164. return !operator == (rhs);
  165. }
  166. // Members
  167. private:
  168. ws_uint32_t m_index;
  169. ws_uint32_t m_count;
  170. ACE_HEADER *m_header;
  171. };
  172. const_iterator begin() const
  173. {
  174. return const_iterator(m_pacl->AceCount, (ACE_HEADER*)(m_pacl + 1));
  175. }
  176. const_iterator end() const
  177. {
  178. return const_iterator();
  179. }
  180. /// @}
  181. /// \name Attributes
  182. /// @{
  183. public:
  184. ws_size_t size() const
  185. {
  186. return m_pacl->AceCount;
  187. }
  188. ws_bool_t empty() const
  189. {
  190. return 0 == size();
  191. }
  192. /// @}
  193. /// \name Members
  194. /// @{
  195. private:
  196. PACL m_pacl;
  197. /// @}
  198. /// \name Not to be implemented
  199. /// @{
  200. private:
  201. acl_sequence(class_type const&);
  202. acl_sequence& operator =(class_type const&);
  203. /// @}
  204. };
  205. /* ////////////////////////////////////////////////////////////////////// */
  206. #ifndef _WINSTL_NO_NAMESPACE
  207. # if defined(_STLSOFT_NO_NAMESPACE) || \
  208. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  209. } // namespace winstl
  210. # else
  211. } // namespace winstl_project
  212. } // namespace stlsoft
  213. # endif /* _STLSOFT_NO_NAMESPACE */
  214. #endif /* !_WINSTL_NO_NAMESPACE */
  215. /* ////////////////////////////////////////////////////////////////////// */
  216. #endif /* WINSTL_INCL_WINSTL_SECURITY_HPP_ACL_SEQUENCE */
  217. /* ///////////////////////////// end of file //////////////////////////// */