Leaked source code of windows server 2003
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.

364 lines
10 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990, 1991 **/
  4. /**********************************************************************/
  5. /*
  6. Perm.hxx
  7. This file contains the PERMISSION, ACCESS_PERMISSION and AUDIT_PERMISSION
  8. class definitions.
  9. FILE HISTORY:
  10. Johnl 05-Aug-1991 Created
  11. */
  12. #ifndef _PERM_HXX_
  13. #define _PERM_HXX_
  14. #include <bitfield.hxx>
  15. #include <maskmap.hxx>
  16. #include <base.hxx>
  17. #include <subject.hxx>
  18. class SUBJECT ; // Forward declaration
  19. /*************************************************************************
  20. NAME: PERMISSION
  21. SYNOPSIS: Abstract base class for ACL type permissions.
  22. INTERFACE:
  23. SaveSpecial()
  24. Stores the current bits because the user is changing the
  25. selection, but they may want to change back to the "special"
  26. setting. Only one special bitset for the class can be kept
  27. around at any time.
  28. PARENT: BASE
  29. USES: BITFIELD, MASK_MAP, SUBJECT
  30. CAVEATS:
  31. NOTES:
  32. HISTORY:
  33. Johnl 05-Aug-1991 Created
  34. **************************************************************************/
  35. class PERMISSION : public BASE
  36. {
  37. private:
  38. SUBJECT * _psubject ;
  39. BITFIELD _bitsPermFlags ;
  40. //
  41. // Will the container permissions be propagated to new containers?
  42. //
  43. BOOL _fContainerPermsInheritted ;
  44. //
  45. // All bits in the bitfields are present in the mask map. If this
  46. // is FALSE, we don't allow manipulation except in the main dialog
  47. // (i.e., no special access).
  48. //
  49. BOOL _fIsMapped ;
  50. //
  51. // Stores the special mask if the user changes there mind
  52. //
  53. BITFIELD _bitsSpecialFlags ;
  54. BOOL _fSpecialContInheritted ;
  55. BOOL _fSpecialIsMapped ;
  56. protected:
  57. PERMISSION( SUBJECT * subject,
  58. BITFIELD * pbitsInitPerm,
  59. BOOL fContainerPermsInheritted,
  60. BOOL fIsMapped = TRUE ) ;
  61. BITFIELD * QueryPermBits( void ) ;
  62. public:
  63. const TCHAR * QueryDisplayName( void ) const
  64. { return _psubject->QueryDisplayName() ; }
  65. const SUBJECT * QuerySubject( void ) const
  66. { return _psubject ; }
  67. virtual APIERR SaveSpecial( void ) ;
  68. virtual APIERR RestoreSpecial( void ) ;
  69. //
  70. // TRUE if this permission contains both the container permission and
  71. // the new object permission
  72. //
  73. virtual BOOL IsNewObjectPermsSupported( void ) const ;
  74. //
  75. // If new object permissions are not specified, then
  76. // QueryNewObjectAccessBits will return NULL.
  77. //
  78. virtual BOOL IsNewObjectPermsSpecified( void ) const ;
  79. virtual BITFIELD * QueryNewObjectAccessBits( void ) ;
  80. //
  81. // There will be some cases where the container permissions are not
  82. // inheritted (i.e., an Owner Creator ACE that gets propagated).
  83. //
  84. BOOL IsContainerPermsInheritted( void ) const
  85. { return _fContainerPermsInheritted ; }
  86. BOOL IsMapped( void ) const
  87. { return _fIsMapped ; }
  88. void operator|=( const BITFIELD & bits )
  89. { _bitsPermFlags |= bits ; }
  90. void operator=( const BITFIELD & bits )
  91. { _bitsPermFlags = bits ; }
  92. virtual ~PERMISSION() ;
  93. //
  94. // Sets the permission bits of a permission object using the passed
  95. // perm bits and permission name.
  96. //
  97. virtual APIERR SetPermission( const NLS_STR & nlsPermName,
  98. MASK_MAP * pmapThis,
  99. MASK_MAP * pmapNewObj = NULL ) ;
  100. //
  101. // Sets whether the container permissions are inheritted by new containers
  102. //
  103. void SetContainerPermsInheritted( BOOL fInheritted = TRUE )
  104. { _fContainerPermsInheritted = fInheritted ; }
  105. //
  106. // Are the bits fully mapped in the mask map for this object?
  107. //
  108. void SetMappedStatus( BOOL fIsMapped = TRUE )
  109. { _fIsMapped = fIsMapped ; }
  110. } ;
  111. /*************************************************************************
  112. NAME: ACCESS_PERMISSION
  113. SYNOPSIS: Grants/denies access for a particular subject
  114. INTERFACE:
  115. PARENT: PERMISSION
  116. USES: BITFIELD, SUBJECT
  117. CAVEATS:
  118. NOTES: IsGrantAll and IsDenyAll default to NT style permissions
  119. (i.e., GENERIC_ALL and 32 bit access mask).
  120. IsDenyAllForEveryone also defaults to NT. Note that there
  121. should really be an intermediate class NT_PERMISSION
  122. that should contain the NT implementation of these
  123. (possible codework item).
  124. HISTORY:
  125. Johnl 05-Aug-1991 Created
  126. Johnl 16-Oct-1992 Added IsDenyAllForEveryone
  127. **************************************************************************/
  128. class ACCESS_PERMISSION : public PERMISSION
  129. {
  130. public:
  131. ACCESS_PERMISSION( SUBJECT * psubject,
  132. BITFIELD * pbitsInitPerm,
  133. BOOL fContainerPermsInheritted = TRUE,
  134. BOOL fIsMapped = TRUE ) ;
  135. virtual ~ACCESS_PERMISSION() ;
  136. BITFIELD * QueryAccessBits( void ) ;
  137. //
  138. // Note: The following two methods look at bitsPermMask and not
  139. // "this", due to historical reasons...
  140. //
  141. virtual BOOL IsGrantAll( const BITFIELD & bitsPermMask ) const ;
  142. virtual BOOL IsDenyAll( const BITFIELD & bitsPermMask ) const ;
  143. //
  144. // Returns TRUE if this ACCESS_PERMISSION grants any permissions
  145. //
  146. virtual BOOL IsGrant( void ) const ;
  147. //
  148. // Returns TRUE if this permission denies all access to everyone
  149. //
  150. virtual APIERR IsDenyAllForEveryone( BOOL * pfIsDenyAll ) const ;
  151. } ;
  152. /*************************************************************************
  153. NAME: LM_ACCESS_PERMISSION
  154. SYNOPSIS: Simple derivation of ACCESS_PERMISSION for Lan Man.
  155. INTERFACE:
  156. PARENT: PERMISSION
  157. USES: BITFIELD, SUBJECT
  158. CAVEATS:
  159. NOTES: This derivation subclasses IsGrantAll and IsDenyAll for Lan
  160. Manager.
  161. HISTORY:
  162. Johnl 26-May-1992 Created
  163. **************************************************************************/
  164. class LM_ACCESS_PERMISSION : public ACCESS_PERMISSION
  165. {
  166. private:
  167. /* TRUE if this permission is for a file. This means that IsGrantAll
  168. * needs to use ACCESS_ALL minus the create bit.
  169. */
  170. BOOL _fIsFile ;
  171. public:
  172. LM_ACCESS_PERMISSION( SUBJECT * psubject,
  173. BITFIELD * pbitsInitPerm,
  174. BOOL fIsFile ) ;
  175. virtual ~LM_ACCESS_PERMISSION() ;
  176. virtual BOOL IsGrantAll( const BITFIELD & bitsPermMask ) const ;
  177. virtual BOOL IsDenyAll( const BITFIELD & bitsPermMask ) const ;
  178. virtual APIERR IsDenyAllForEveryone( BOOL * pfIsDenyAll ) const ;
  179. virtual BOOL IsGrant( void ) const ;
  180. } ;
  181. /*************************************************************************
  182. NAME: NT_CONT_ACCESS_PERMISSION
  183. SYNOPSIS: Grants/denies access for a particular subject. We also
  184. allow new object permissions to be specified
  185. INTERFACE:
  186. PARENT: ACCESS_PERMISSION
  187. USES: BITFIELD, MASK_MAP, SUBJECT
  188. CAVEATS:
  189. NOTES:
  190. HISTORY:
  191. Johnl 012-Sep-1991 Created
  192. **************************************************************************/
  193. class NT_CONT_ACCESS_PERMISSION : public ACCESS_PERMISSION
  194. {
  195. private:
  196. /* Contains the permission bitmask for the "New Objects". New objects
  197. * are objects that maybe created inside this container. When they
  198. * are created, the OS applies the permissions specified with this mask.
  199. */
  200. BITFIELD _bitsNewObjectPerm ;
  201. /* Is TRUE if _bitsNewObjectPerm contains a mask that should be applied
  202. * to new objects. Otherwise no new object permissions are specified
  203. * for this subject.
  204. */
  205. BOOL _fNewObjectPermsSpecified ;
  206. /* Temporary storage during dialog processing (retains the "Special"
  207. * flags so the user can change their mind).
  208. */
  209. BITFIELD _bitsSpecialNewFlags ;
  210. BOOL _fSpecialNewPermsSpecified ;
  211. public:
  212. NT_CONT_ACCESS_PERMISSION( SUBJECT * psubject,
  213. BITFIELD * pbitsInitPerm,
  214. BITFIELD * pbitsInitNewObjectPerm,
  215. BOOL fIsInherittedByContainers = TRUE,
  216. BOOL fIsMapped = TRUE ) ;
  217. virtual ~NT_CONT_ACCESS_PERMISSION() ;
  218. virtual APIERR SaveSpecial( void ) ;
  219. virtual APIERR RestoreSpecial( void ) ;
  220. virtual APIERR SetPermission( const NLS_STR & nlsPermName,
  221. MASK_MAP * pmapThis,
  222. MASK_MAP * pmapNewObj = NULL ) ;
  223. virtual BOOL IsNewObjectPermsSupported( void ) const ;
  224. virtual BOOL IsNewObjectPermsSpecified( void ) const ;
  225. virtual BITFIELD * QueryNewObjectAccessBits( void ) ;
  226. virtual APIERR IsDenyAllForEveryone( BOOL * pfIsDenyAll ) const ;
  227. virtual BOOL IsGrant( void ) const ;
  228. /* Sets whether this New object permission is specified or not specified.
  229. */
  230. void SetNewObjectPermsSpecified( BOOL fSpecified = TRUE )
  231. { _fNewObjectPermsSpecified = fSpecified ; }
  232. } ;
  233. /*************************************************************************
  234. NAME: AUDIT_PERMISSION
  235. SYNOPSIS: Provides Audit masks (success & failed) for a subject
  236. INTERFACE:
  237. PARENT: PERMISSION
  238. USES: BITFIELD, SUBJECT
  239. CAVEATS: It is assumed that the Success and Failed bitfield bits
  240. have the same meaning.
  241. NOTES:
  242. HISTORY:
  243. Johnl 12-Sep-1991 Created
  244. **************************************************************************/
  245. class AUDIT_PERMISSION : public PERMISSION
  246. {
  247. public:
  248. AUDIT_PERMISSION( SUBJECT * psubject,
  249. BITFIELD * pbitsSuccessFlags,
  250. BITFIELD * pbitsFailFlags,
  251. BOOL fPermsInherited,
  252. BOOL fIsMapped ) ;
  253. ~AUDIT_PERMISSION() ;
  254. BITFIELD * QuerySuccessAuditBits( void )
  255. { return QueryPermBits() ; }
  256. BITFIELD * QueryFailAuditBits( void )
  257. { return &_bitsFailAuditFlags ; }
  258. private:
  259. BITFIELD _bitsFailAuditFlags ;
  260. } ;
  261. #endif // _PERM_HXX_