Source code of Windows XP (NT5)
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.

526 lines
17 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990, 1991 **/
  4. /**********************************************************************/
  5. /*
  6. AclConv.hxx
  7. This file contains the ACL_TO_PERM_CONVERTER class definition
  8. FILE HISTORY:
  9. Johnl 01-Aug-1991 Created
  10. */
  11. #ifndef _ACLCONV_HXX_
  12. #define _ACLCONV_HXX_
  13. #include <uimsg.h>
  14. #define IERR_ACL_CONV_BASE (IDS_UI_ACLEDIT_BASE+400)
  15. #define IERR_ACLCONV_NONST_ACL_CANT_EDIT (IERR_ACL_CONV_BASE+1)
  16. #define IERR_ACLCONV_NONST_ACL_CAN_EDIT (IERR_ACL_CONV_BASE+2)
  17. #define IERR_ACLCONV_CANT_VIEW_CAN_EDIT (IERR_ACL_CONV_BASE+3)
  18. #define IERR_ACLCONV_LM_INHERITING_PERMS (IERR_ACL_CONV_BASE+4)
  19. #define IERR_ACLCONV_LM_NO_ACL (IERR_ACL_CONV_BASE+5)
  20. #define IERR_ACLCONV_READ_ONLY (IERR_ACL_CONV_BASE+6)
  21. #define IERR_ACLCONV_CANT_EDIT_PERM_ON_LM_SHARE_LEVEL (IERR_ACL_CONV_BASE+7)
  22. #ifndef RC_INVOKED
  23. #include <base.hxx>
  24. #include <lmobj.hxx>
  25. #include <lmoacces.hxx>
  26. extern "C"
  27. {
  28. #include <sedapi.h>
  29. APIERR QueryLoggedOnDomainInfo( NLS_STR * pnlsDC,
  30. NLS_STR * pnlsDomain,
  31. HWND hwnd ) ;
  32. }
  33. #include <subject.hxx>
  34. enum TREE_APPLY_FLAGS {
  35. TREEAPPLY_ACCESS_PERMS,
  36. TREEAPPLY_AUDIT_PERMS,
  37. } ;
  38. /*************************************************************************
  39. NAME: ACL_TO_PERM_CONVERTER
  40. SYNOPSIS: Abstract superclass that can retrieve, interpret and set
  41. an ACL.
  42. INTERFACE:
  43. PARENT:
  44. USES:
  45. CAVEATS:
  46. NOTES: New Sub-objects refers to objects (such as files) that will
  47. be created in an NT container object (such as a directory)
  48. and gets the New Object permissions set up in the container
  49. object.
  50. HISTORY:
  51. Johnl 02-Aug-1991 Created
  52. **************************************************************************/
  53. class MASK_MAP ; // Forward reference
  54. class ACCPERM ;
  55. class PERMISSION ;
  56. class ACL_TO_PERM_CONVERTER : public BASE
  57. {
  58. public:
  59. /* Fill the passed ACCPERM with the set of PERMISSIONS that represent this
  60. * ACL. If the ACL is one we don't recognize, then the ACCPERM will be
  61. * empty and the error code will be one of the IERR_ACLCONV_* error codes
  62. *
  63. */
  64. virtual APIERR GetPermissions( ACCPERM * pAccperm, BOOL fAccessPerms ) = 0 ;
  65. /* Initialize the ACCPERM with the default "Blank" permissions. Used
  66. * when applying an ACL to a resource that doesn't have an ACL already,
  67. * or when blowing away an unrecognized ACL.
  68. */
  69. virtual APIERR GetBlankPermissions( ACCPERM * pAccperm ) = 0 ;
  70. /* Applies the new permissions specified in the ACCPERM class to the
  71. * specified resource.
  72. * accperm - New permission set
  73. * fApplyToSubContainers - Apply this permission set to subcontainer
  74. * objects (such as directories etc., will only
  75. * be TRUE if this is a container resource.
  76. * fApplyToSubObjects - Apply this permission set to container objects
  77. * (such as files etc.). Will only be TRUE if
  78. * this is a container resource.
  79. * applyflags - Indicates whether we should set access or audit perms.
  80. * pfReportError - Set to TRUE if the caller should report the error,
  81. * FALSE if the error has already been reported
  82. */
  83. virtual APIERR WritePermissions( ACCPERM & accperm,
  84. BOOL fApplyToSubContainers,
  85. BOOL fApplyToSubObjects,
  86. enum TREE_APPLY_FLAGS applyflags,
  87. BOOL *pfReportError ) = 0 ;
  88. /* Create a permission object that is ready to be added to an ACCPERM
  89. *
  90. * ppPerm - Pointer to receive new'ed PERMISSION object (client should
  91. * delete or add to an ACCPERM and let it delete the
  92. * permission)
  93. * fAccessPermission - TRUE if this is an ACCESS_PERMISSION or an
  94. * AUDIT_PERMISSION
  95. * pSubj - Pointer to new'ed SUBJECT (will be deleted by permission)
  96. *
  97. * The pointer to the bitfields contain the following information:
  98. *
  99. * NT Obj Perm NT Obj Audit
  100. * LM Perm. LM Audit NT Cont Perm NT Cont Audit
  101. * =====================================================================
  102. * pbits1 - Access Perm Success Access Perm Success
  103. * pbits2 - NA Failed NEW Obj Access Perm Failed
  104. * (pbits3 - NA NA NA * )
  105. * (pbits4 - NA NA NA * )
  106. *
  107. * * We don't support NEW Obj. auditting settings, if we did, then we
  108. * would add the pbits3 and pbits4.
  109. */
  110. virtual APIERR BuildPermission( PERMISSION * * ppPerm,
  111. BOOL fAccessPermission,
  112. SUBJECT * pSubj,
  113. BITFIELD * pbits1,
  114. BITFIELD * pbits2 = NULL,
  115. BOOL fContainerPermsInheritted = TRUE ) ;
  116. /* When we try and write a permission list but one of the users/groups
  117. * have been removed from the server's list, we need to let the user
  118. * know which one. This method retrieves the responsible subject.
  119. *
  120. * This should only be called immediately after WritePermissions returns
  121. * NERR_UserNotFound.
  122. */
  123. virtual APIERR QueryFailingSubject( NLS_STR * pnlsSubjUniqueName ) = 0 ;
  124. //
  125. // If the ACL has an owner, this virtual returns it. If there is no
  126. // owner, then NULL will be returned. Note that only NT ACLs have
  127. // owners.
  128. //
  129. virtual const TCHAR * QueryOwnerName( void ) const ;
  130. /* Returns a server in the user's logged on domain and/or the logged on
  131. * domain. Note that either parameter maybe NULL.
  132. */
  133. APIERR QueryLoggedOnDomainInfo( NLS_STR * pnlsDCInLoggedOnDomain,
  134. NLS_STR * pnlsLoggedOnDomain ) ;
  135. MASK_MAP * QueryAccessMap( void ) const
  136. { return _paccmaskmap ; }
  137. MASK_MAP * QueryAuditMap( void ) const
  138. { return _pauditmaskmap ; }
  139. /* Note: Not all ACLs will support the New object concept, the default
  140. * implementation will simply return NULL.
  141. */
  142. virtual MASK_MAP * QueryNewObjectAccessMap( void ) const ;
  143. /* In some cases (i.e., LM) the resource maybe inheritting from a parent
  144. * resource. This method returns the name of the resource that
  145. * is being inheritted from. This will only be defined in the LM case.
  146. */
  147. virtual APIERR QueryInherittingResource( NLS_STR * pnlsInherittingResName );
  148. const LOCATION * QueryLocation( void ) const
  149. { return &_location ; }
  150. /* Returns TRUE if this resource is readonly.
  151. */
  152. BOOL IsReadOnly( void ) const
  153. { return _fReadOnly ; }
  154. /* Returns TRUE if this resource is based on an NT platform.
  155. *
  156. * We know this can't fail, getting it from the location class may fail
  157. */
  158. BOOL IsNT( void ) const
  159. { return _fIsNT ; }
  160. /* Returns TRUE if the object is a container object
  161. */
  162. BOOL IsContainer( void ) const
  163. { return _fIsContainer ; }
  164. BOOL IsNewObjectsSupported( void ) const
  165. { return _fIsNewObjectsSupported ; }
  166. virtual ~ACL_TO_PERM_CONVERTER() ;
  167. void SetWritePermHwnd( HWND hwndOwner )
  168. { _hwndErrorParent = hwndOwner ; }
  169. HWND QueryWritePermHwnd( void ) const
  170. { return _hwndErrorParent ; }
  171. BOOL IsMnemonicsDisplayed( void ) const
  172. { return _fShowMnemonics ; }
  173. protected:
  174. ACL_TO_PERM_CONVERTER( const TCHAR * pszServer,
  175. MASK_MAP * paccessmap,
  176. MASK_MAP * pauditmap,
  177. BOOL fIsNT,
  178. BOOL fIsContainer,
  179. BOOL fIsNewObjectsSupported,
  180. BOOL fShowMnemonics = TRUE ) ;
  181. void SetReadOnlyFlag( BOOL fIsReadOnly )
  182. { _fReadOnly = fIsReadOnly ; }
  183. LOCATION _location ;
  184. private:
  185. BOOL _fReadOnly ; // We can only read the ACL if TRUE
  186. BOOL _fIsNT ; // This resource is on an NT machine
  187. BOOL _fIsContainer ;
  188. BOOL _fIsNewObjectsSupported ;
  189. MASK_MAP * _paccmaskmap ;
  190. MASK_MAP * _pauditmaskmap ;
  191. /* Caches a DC from the logged on domain. Initialized from
  192. * QueryDCInLoggedOnDomain.
  193. */
  194. NLS_STR _nlsLoggedOnDC ;
  195. NLS_STR _nlsLoggedOnDomain ;
  196. /* This member is needed for a semi-hack. When WritePermission is called
  197. * for an NT ACL converter what actually happens is the callback function
  198. * is called and it is responsible for all error handling. Thus this
  199. * member is passed to the callback where it is used for message boxes etc.
  200. */
  201. HWND _hwndErrorParent ;
  202. //
  203. // True if mnemonics (i.e., (RWXD)) should be shown
  204. //
  205. BOOL _fShowMnemonics ;
  206. } ;
  207. /*************************************************************************
  208. NAME: LM_ACL_TO_PERM_CONVERTER
  209. SYNOPSIS: This class converts a Lanman ACE to a set of PERMISSIONs
  210. stored in the ACCPERM class.
  211. INTERFACE:
  212. PARENT:
  213. USES:
  214. CAVEATS: The fApplyTo* flags on WritePermissions should only be set
  215. if the resource is a *file* resource, otherwise bad things
  216. will happen.
  217. NOTES:
  218. HISTORY:
  219. Johnl 02-Aug-1991 Created
  220. **************************************************************************/
  221. class LM_ACL_TO_PERM_CONVERTER : public ACL_TO_PERM_CONVERTER
  222. {
  223. public:
  224. /* Constructor:
  225. * pchServer is the server name of the resource
  226. * pchResourceName is the LM canonicalized resource name (i.e.,
  227. * appropriate to call NetAccessSetInfo with).
  228. * paccessmap is the access permission bitfield map
  229. * pauditmap is the audit permission bitfield map
  230. * fIsContainer - TRUE if directory, FALSE if file
  231. * pfuncCallback - What to call back to when writing security
  232. * ulCallbackContext - Context for the callback
  233. * fIsBadIntersection - TRUE if this is a multi-select and the
  234. * security is not the same on all of the resources
  235. */
  236. LM_ACL_TO_PERM_CONVERTER( const TCHAR * pchServer,
  237. const TCHAR * pchResourceName,
  238. MASK_MAP *paccessmap,
  239. MASK_MAP *pauditmap,
  240. BOOL fIsContainer,
  241. PSED_FUNC_APPLY_SEC_CALLBACK pfuncCallback,
  242. ULONG_PTR ulCallbackContext,
  243. BOOL fIsBadIntersection ) ;
  244. ~LM_ACL_TO_PERM_CONVERTER() ;
  245. /* See parent for more info.
  246. */
  247. virtual APIERR GetPermissions( ACCPERM * pAccperm, BOOL fAccessPerms ) ;
  248. virtual APIERR GetBlankPermissions( ACCPERM * pAccperm ) ;
  249. virtual APIERR WritePermissions( ACCPERM & accperm,
  250. BOOL fApplyToSubContainers,
  251. BOOL fApplyToSubObjects,
  252. enum TREE_APPLY_FLAGS applyflags,
  253. BOOL *pfReportError ) ;
  254. virtual APIERR QueryInherittingResource( NLS_STR * pnlsInherittingResName );
  255. virtual APIERR QueryFailingSubject( NLS_STR * pnlsSubjUniqueName ) ;
  256. protected:
  257. /* The name of the resource this resource is inheritting from (NULL if
  258. * none).
  259. */
  260. NLS_STR _nlsInherittingResName ;
  261. /* This method fills in the _nlsInherittingResName by working back up
  262. * the directory tree until it finds a resource that the current resource
  263. * is inheritting from.
  264. */
  265. APIERR FindInherittingResource( void ) ;
  266. /* These two methods map the failed to successful audit bits and the
  267. * successful to failed audit bits respectively.
  268. */
  269. USHORT FailToSuccessAuditFlags( USHORT usFailAuditMask ) ;
  270. USHORT SuccessToFailAuditFlags( USHORT usSuccessAuditMask ) ;
  271. private:
  272. /* Used to retrieve the ACL and write the ACL on GetPermissions and
  273. * WritePermissions.
  274. */
  275. NET_ACCESS_1 _lmobjNetAccess1 ;
  276. // The following two are for the call back method
  277. PSED_FUNC_APPLY_SEC_CALLBACK _pfuncCallback ;
  278. ULONG_PTR _ulCallbackContext ;
  279. //
  280. // Set to TRUE if we should blank out the audit/perm info because the
  281. // user has multi-selected non-equal ACLs
  282. //
  283. BOOL _fIsBadIntersection ;
  284. } ;
  285. /*************************************************************************
  286. NAME: NT_ACL_TO_PERM_CONVERTER
  287. SYNOPSIS: The ACL Converter for NT ACLs
  288. INTERFACE: See ACL_TO_PERM_CONVERTER
  289. PARENT: ACL_TO_PERM_CONVERTER
  290. USES: MASK_MAP
  291. CAVEATS: If the client indicates that NewObjectPerms are supported,
  292. then the accperm will contain NT_CONT_ACCESS_PERMS (and
  293. this class will assume that), otherwise the accperm will
  294. contain ACCESS_PERMS objects.
  295. NOTES: If New Sub-Objects are not supported, then the paccessmapNewObject
  296. parameter should be NULL. If they are supported, then the
  297. PERMTYPE_GENERAL permissions of the new object MASK_MAP should
  298. match exactly the PERMTYPE_GENERAL permissions of the
  299. paccessmap parameter.
  300. HISTORY:
  301. Johnl 27-Sep-1991 Created
  302. **************************************************************************/
  303. class NT_ACL_TO_PERM_CONVERTER : public ACL_TO_PERM_CONVERTER
  304. {
  305. private:
  306. MASK_MAP * _pmaskmapNewObject ;
  307. /* This member gets initialized by BuildNewObjectPerms.
  308. */
  309. OS_SECURITY_DESCRIPTOR * _possecdescNewItemPerms ;
  310. //
  311. // Contains the owner name of the security descriptor (initialized
  312. // in SidsToNames()).
  313. //
  314. NLS_STR _nlsOwner ;
  315. /* These private members are stored here till we need them for the callback
  316. * method.
  317. */
  318. PSECURITY_DESCRIPTOR _psecuritydesc ;
  319. PGENERIC_MAPPING _pGenericMapping ;
  320. PGENERIC_MAPPING _pGenericMappingNewObjects ;
  321. BOOL _fMapSpecificToGeneric ;
  322. BOOL _fCantReadACL ;
  323. ULONG_PTR _ulCallbackContext ;
  324. HANDLE _hInstance ;
  325. LPDWORD _lpdwReturnStatus ;
  326. PSED_FUNC_APPLY_SEC_CALLBACK _pfuncCallback ;
  327. protected:
  328. /* These two methods convert a security descriptor to an accperm
  329. * and an accperm to a security descriptor, respectively.
  330. *
  331. * SecurityDesc2Accperm will return, in addition to standard APIERRs,
  332. * IERR_ACLCONV_* manifests.
  333. */
  334. APIERR SecurityDesc2Accperm( const PSECURITY_DESCRIPTOR psecdesc,
  335. ACCPERM * pAccperm,
  336. BOOL fAccessPerm ) ;
  337. APIERR Accperm2SecurityDesc( ACCPERM * pAccperm,
  338. OS_SECURITY_DESCRIPTOR * possecdesc,
  339. BOOL fAccessPerm ) ;
  340. /* Help method for building access permissions
  341. */
  342. APIERR NT_ACL_TO_PERM_CONVERTER::CreateNewPermission(
  343. PERMISSION ** ppPermission,
  344. BOOL fAccess,
  345. PSID psidSubject,
  346. ACCESS_MASK Mask1,
  347. BOOL fMask2Used,
  348. ACCESS_MASK Mask2,
  349. BOOL fContainerPermsInheritted = TRUE ) ;
  350. APIERR SidsToNames( ACCPERM * pAccperm,
  351. BOOL fAccess,
  352. PSID psidOwner = NULL ) ;
  353. /* These two methods are used by Accperm2SecurityDesc, specifically, they
  354. * are helper routines for building up the the security descriptor's
  355. * DACL.
  356. */
  357. APIERR ConvertAllowAccessPerms( ACCPERM * pAccperm,
  358. OS_ACL * posaclDACL ) ;
  359. APIERR ConvertDenyAllAccessPerms( ACCPERM * pAccperm,
  360. OS_ACL * posaclDACL ) ;
  361. APIERR BuildNewObjectPerms( const OS_SECURITY_DESCRIPTOR & ossecContainer );
  362. APIERR RemoveUndesirableACEs( OS_ACL * posacl ) ;
  363. OS_SECURITY_DESCRIPTOR * QueryNewObjectPerms( void ) const
  364. { return _possecdescNewItemPerms ; }
  365. //
  366. // The client indicated they were unable to read the ACL because the
  367. // user doesn't have privilege. Presumably they have write permissions
  368. //
  369. BOOL IsNonReadable( void ) const
  370. { return _fCantReadACL ; }
  371. public:
  372. /* Constructor:
  373. * pchServer is the server name of the resource
  374. * pchResourceName is the name
  375. * paccessmap is the access permission bitfield map
  376. * paccessmapNewObject is the new object permission bitfield map, it
  377. * should be NULL if this is not a container object that supports
  378. * new sub-objects
  379. * pauditmap is the audit permission bitfield map
  380. */
  381. NT_ACL_TO_PERM_CONVERTER( const TCHAR * pchServer,
  382. const TCHAR * pchResourceName,
  383. MASK_MAP * paccessmap,
  384. MASK_MAP * paccessmapNewObject,
  385. MASK_MAP * pauditmap,
  386. BOOL fIsContainer,
  387. BOOL fIsNewObjectsSupported,
  388. PSECURITY_DESCRIPTOR psecdesc,
  389. PGENERIC_MAPPING pGenericMapping,
  390. PGENERIC_MAPPING pGenericMappingNewObjects,
  391. BOOL fMapSpecificToGeneric,
  392. BOOL fCantReadACL,
  393. BOOL fCantWriteACL,
  394. PSED_FUNC_APPLY_SEC_CALLBACK pfuncCallback,
  395. ULONG_PTR ulCallbackContext,
  396. HANDLE hInstance,
  397. LPDWORD lpdwReturnStatus,
  398. BOOL fShowMnemonics ) ;
  399. ~NT_ACL_TO_PERM_CONVERTER() ;
  400. /* See parent for more info.
  401. */
  402. virtual APIERR GetPermissions( ACCPERM * pAccperm, BOOL fAccessPerms ) ;
  403. virtual APIERR GetBlankPermissions( ACCPERM * pAccperm ) ;
  404. virtual APIERR WritePermissions( ACCPERM & accperm,
  405. BOOL fApplyToSubContainers,
  406. BOOL fApplyToSubObjects,
  407. enum TREE_APPLY_FLAGS applyflags,
  408. BOOL *pfReportError ) ;
  409. virtual APIERR QueryFailingSubject( NLS_STR * pnlsSubjUniqueName ) ;
  410. virtual MASK_MAP * QueryNewObjectAccessMap( void ) const ;
  411. virtual const TCHAR * QueryOwnerName( void ) const ;
  412. } ;
  413. #endif //RC_INVOKED
  414. #endif //_ACLCONV_HXX_