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.

371 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /**********************************************************************/
  5. /*
  6. lsaaccnt.hxx
  7. This file contains the LSA account object.
  8. FILE HISTORY:
  9. Yi-HsinS 3-Mar-1992 Created
  10. */
  11. #ifndef _LSAACCNT_HXX_
  12. #define _LSAACCNT_HXX_
  13. #include "uintlsa.hxx"
  14. #include "lmobj.hxx"
  15. #include "security.hxx"
  16. /*************************************************************************
  17. NAME: OS_LUID
  18. SYNOPSIS: The wrapper class for the LUID
  19. INTERFACE: OS_LUID() - Constructor
  20. QueryLuid() - Query the LUID
  21. SetLuid() - Set the LUID
  22. operator==()- Compare two OS_LUID
  23. PARENT:
  24. USES: LUID
  25. NOTES: Just to add the access methods
  26. HISTORY:
  27. Yi-HsinS 3-Mar-1992 Created
  28. **************************************************************************/
  29. DLL_CLASS OS_LUID
  30. {
  31. private:
  32. LUID _luid;
  33. public:
  34. OS_LUID( LUID luid )
  35. : _luid( luid ) {}
  36. OS_LUID() {}
  37. VOID SetLuid( LUID luid )
  38. { _luid = luid; }
  39. LUID QueryLuid( VOID ) const
  40. { return _luid; }
  41. BOOL operator==( const OS_LUID & osluid ) const ;
  42. };
  43. /*************************************************************************
  44. NAME: OS_LUID_AND_ATTRIBUTES
  45. SYNOPSIS: The wrapper class for the LUID_AND_ATTRIBUTES
  46. INTERFACE: OS_LUID_AND_ATTRIBUTES() - Constructor
  47. SetLuidAndAttrib() - Set the luid and attribute
  48. QueryOsLuid() - Query the LUID
  49. QueryAttributes() - Query the attribute
  50. PARENT:
  51. USES: LUID_AND_ATTRIBUTES
  52. NOTES: Just to add the access methods
  53. HISTORY:
  54. Yi-HsinS 3-Mar-1992 Created
  55. **************************************************************************/
  56. DLL_CLASS OS_LUID_AND_ATTRIBUTES
  57. {
  58. private:
  59. OS_LUID _osluid;
  60. ULONG _ulAttributes;
  61. public:
  62. OS_LUID_AND_ATTRIBUTES( LUID_AND_ATTRIBUTES luidAndAttrib )
  63. : _osluid( luidAndAttrib.Luid ),
  64. _ulAttributes( luidAndAttrib.Attributes) {}
  65. OS_LUID_AND_ATTRIBUTES() {}
  66. VOID SetLuidAndAttrib( LUID_AND_ATTRIBUTES luidAndAttrib )
  67. { _osluid = luidAndAttrib.Luid; _ulAttributes = luidAndAttrib.Attributes; }
  68. const OS_LUID &QueryOsLuid( VOID ) const
  69. { return _osluid; }
  70. ULONG QueryAttributes( VOID ) const
  71. { return _ulAttributes; }
  72. };
  73. /*************************************************************************
  74. NAME: OS_PRIVILEGE_SET
  75. SYNOPSIS: The wrapper class for the PRIVILEGE_SET
  76. INTERFACE: OS_PRIVILEGE_SET() - Constructor
  77. ~OS_PRIVILEGE_SET() - Destructor
  78. QueryPrivSet() - Return a pointer to the PRIVILEGE_SET
  79. SetPtr() - Set the object point to another
  80. PRIVILEGE_SET
  81. QueryNumberOfPrivileges() - Query the number of privileges
  82. in this PRIVILEGE_SET
  83. QueryPrivilege() - Return OS_LUID_AND_ATTRIBUTES of the
  84. ith privilege
  85. FindPrivilege() - Return the index in the PRIVILEGE_SET
  86. for the requested LUID.
  87. // The following two methods can only be applied to
  88. // non owner-alloc PRIVILEGE_SET
  89. AddPrivilege() - Add a privilege to this PRIVILEGE_SET
  90. RemovePrivilege() - Remove a privilege from this PRIVILEGE_SET
  91. Clear() - Clear the privilege set ( remove all
  92. privileges from this privilege set )
  93. PARENT: OS_OBJECT_WITH_DATA
  94. USES: PPRIVILEGE_SET
  95. NOTES: This class can either point to a PRIVILEGE_SET returned
  96. by some API ( owner alloc ) or a newly created PRIVILEGE_SET
  97. in which case we have to resize the buffer as necessary
  98. ( 'cause of AddPrivilege or DeletePrivilege ).
  99. HISTORY:
  100. Yi-HsinS 3-Mar-1992 Created
  101. **************************************************************************/
  102. DLL_CLASS OS_PRIVILEGE_SET: public OS_OBJECT_WITH_DATA
  103. {
  104. private:
  105. PPRIVILEGE_SET _pPrivSet;
  106. OS_LUID_AND_ATTRIBUTES _osluidAndAttrib;
  107. // Maximum number of privileges that the current buffer size can hold
  108. ULONG _ulMaxNumPrivInBuf;
  109. BOOL IsOwnerAlloc( VOID ) const
  110. { return ( (VOID *) _pPrivSet) != QueryPtr(); }
  111. // Helper method for initializing owner-alloc privilege set
  112. VOID InitializeMemory( VOID );
  113. public:
  114. OS_PRIVILEGE_SET( PPRIVILEGE_SET pPrivSet = NULL );
  115. ~OS_PRIVILEGE_SET();
  116. VOID SetPtr( PPRIVILEGE_SET pPrivSet )
  117. { _pPrivSet = pPrivSet; }
  118. PPRIVILEGE_SET QueryPrivSet( VOID ) const
  119. { return _pPrivSet; }
  120. ULONG QueryNumberOfPrivileges( VOID ) const
  121. { return _pPrivSet->PrivilegeCount; }
  122. const OS_LUID_AND_ATTRIBUTES *QueryPrivilege( LONG i ) ;
  123. // Return the index of the privilege
  124. LONG FindPrivilege( LUID luid ) const;
  125. // The following methods are only valid if the privilege set is owner alloc.
  126. // Will assert out if AddPrivilege or RemovePrivilege is applied to
  127. // a PRIVILEGE_SET we got back from LSA APIs ( non owner alloc) .
  128. APIERR AddPrivilege( LUID luid,
  129. ULONG ulAttribs = SE_PRIVILEGE_ENABLED_BY_DEFAULT );
  130. APIERR RemovePrivilege( LUID luid );
  131. // Remove the ith privilege from the set
  132. APIERR RemovePrivilege( LONG i );
  133. VOID Clear( VOID );
  134. };
  135. /*************************************************************************
  136. NAME: LSA_ACCOUNT_PRIVILEGE_ENUM_ITER
  137. SYNOPSIS: Iterator for getting all the privileges of a account in the
  138. LSA
  139. INTERFACE: LSA_ACCOUNT_PRIVILEGE_ENUM_ITER() - Constructor
  140. ~LSA_ACCOUNT_PRIVILEGE_ENUM_ITER() - Destructor
  141. operator()() - Return the next OS_LUID_AND_ATTRIBUTES
  142. PARENT: BASE
  143. USES: OS_PRIVILEGE_SET
  144. NOTES:
  145. HISTORY:
  146. Yi-HsinS 3-Mar-1992 Created
  147. **************************************************************************/
  148. DLL_CLASS LSA_ACCOUNT_PRIVILEGE_ENUM_ITER: public BASE
  149. {
  150. private:
  151. OS_PRIVILEGE_SET *_pOsPrivSet;
  152. LONG _iNext;
  153. public:
  154. LSA_ACCOUNT_PRIVILEGE_ENUM_ITER( OS_PRIVILEGE_SET * pOsPrivSet );
  155. ~LSA_ACCOUNT_PRIVILEGE_ENUM_ITER();
  156. const OS_LUID_AND_ATTRIBUTES *operator()( VOID );
  157. };
  158. /*************************************************************************
  159. NAME: LSA_ACCOUNT
  160. SYNOPSIS: The wrapper class for the Account object in LSA
  161. INTERFACE: LSA_ACCOUNT() - Constructor
  162. ~LSA_ACCOUNT() - Destructor
  163. QueryHandle() - Query the account handle
  164. QueryOsSid() - Query the OS_SID of the account
  165. QueryName() - Query the name of the account
  166. QueryAccess() - Query access mask used in Open or Create
  167. QuerySystemAccess() - Query the current system access
  168. mode of the account.
  169. InsertSystemAccessMode() - Add a system access mode to
  170. this account
  171. DeleteSystemAccessMode() - Remove a system access mode from
  172. this account
  173. DeleteAllSystemAccessMode() - Remove all system access modes
  174. from this account
  175. QueryPrivilegeEnumIter - Return an iterator to get the
  176. privileges this account has.
  177. InsertPrivilege() - Add a privilege to this account
  178. DeletePrivilege() - Remove a privilege from this account
  179. // Inherit from NEW_LM_OBJ
  180. GetInfo()
  181. WriteInfo()
  182. CreateNew()
  183. WriteNew()
  184. Write()
  185. Delete()
  186. PARENT: BASE
  187. USES: LSA_POLICY, OS_SID, NLS_STR, OS_PRIVILEGE_SET
  188. NOTES: This class inherits from NEW_LM_OBJ. All information about the
  189. account will be available after GetInfo(). All modifications
  190. made to an existing account will only happen on WriteInfo().
  191. An account will only be created only after WriteNew().
  192. HISTORY:
  193. Yi-HsinS 3-Mar-1992 Created
  194. **************************************************************************/
  195. #define LSA_ACCOUNT_DEFAULT_MASK ( ACCOUNT_ALL_ACCESS | DELETE )
  196. #define LSA_ACCOUNT_DEFAULT_FOCUS NULL
  197. DLL_CLASS LSA_ACCOUNT: public NEW_LM_OBJ
  198. {
  199. private:
  200. LSA_POLICY *_plsaPolicy; // Pointer to LSA_POLICY
  201. LSA_HANDLE _handleAccount; // Handle of this account object
  202. OS_SID _ossid; // SID of the account
  203. NLS_STR _nlsName; // Name of the account
  204. ACCESS_MASK _accessDesired; // Access mask for use in Open or Create
  205. // the privilege set the account currently owns
  206. OS_PRIVILEGE_SET _osPrivSetCurrent;
  207. // the privilege set to be added to the account
  208. OS_PRIVILEGE_SET _osPrivSetAdd;
  209. // the privilege set to be deleted from the account
  210. OS_PRIVILEGE_SET _osPrivSetDelete;
  211. // current system access mode
  212. ULONG _ulSystemAccessCurrent;
  213. // modified system access - we have this so that we know whether
  214. // system access mode has been modified or not. If not, we could
  215. // avoid an API call.
  216. ULONG _ulSystemAccessNew;
  217. protected:
  218. virtual APIERR I_GetInfo( VOID );
  219. virtual APIERR I_WriteInfo( VOID );
  220. virtual APIERR I_CreateNew( VOID );
  221. virtual APIERR I_WriteNew( VOID );
  222. virtual APIERR I_Delete( UINT uiForce = 0 );
  223. virtual APIERR W_CreateNew( VOID );
  224. VOID PrintInfo( const TCHAR *pszString );
  225. public:
  226. LSA_ACCOUNT( LSA_POLICY *plsaPolicy,
  227. PSID psid,
  228. ACCESS_MASK accessDesired = LSA_ACCOUNT_DEFAULT_MASK,
  229. const TCHAR * pszFocus = LSA_ACCOUNT_DEFAULT_FOCUS,
  230. PSID psidFocus = NULL );
  231. ~LSA_ACCOUNT();
  232. LSA_HANDLE QueryHandle( VOID ) const
  233. { return _handleAccount; }
  234. const OS_SID &QueryOsSid( VOID ) const
  235. { return _ossid; }
  236. virtual const TCHAR *QueryName( VOID ) const
  237. { return _nlsName.QueryPch(); }
  238. ACCESS_MASK QueryAccess( VOID ) const
  239. { return _accessDesired; }
  240. ULONG QuerySystemAccess( VOID ) const
  241. { return _ulSystemAccessNew; }
  242. APIERR QueryPrivilegeEnumIter( LSA_ACCOUNT_PRIVILEGE_ENUM_ITER **ppIter ) ;
  243. VOID InsertSystemAccessMode( ULONG ulSystemAccess )
  244. { _ulSystemAccessNew |= ulSystemAccess; }
  245. VOID DeleteSystemAccessMode( ULONG ulSystemAccess )
  246. { _ulSystemAccessNew &= ~ulSystemAccess; }
  247. VOID DeleteAllSystemAccessMode( VOID )
  248. { _ulSystemAccessNew = 0; }
  249. APIERR InsertPrivilege( LUID luid,
  250. ULONG ulAttribs = 0 );
  251. APIERR DeletePrivilege( LUID luid );
  252. BOOL IsDefaultSettings( VOID );
  253. };
  254. #endif