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.

916 lines
23 KiB

  1. /*---------------------------------------------------------------------------
  2. File: SD.cpp
  3. Comments: class for manipulating security descriptors
  4. This class provides a thin wrapper around the security descriptor APIs, and
  5. also helps us with some of our processing heuristics.
  6. The NT APIs to read and write security descriptors for files, etc. generally
  7. return a self-relative SD when reading, but expect an absolute SD when writing
  8. Thus, we keep the original data of the SD as read, in self-relative form in m_relSD,
  9. and store any changes in absolute form in m_absSD. This allows us to easily track
  10. which parts of the SD have been modified, and to compare the before and after versions
  11. of the SD.
  12. As an optimization in our ACL translation, we can compare each SD to the initial
  13. state of the last SD we processed. If it is the same, we can simply write the
  14. result we have already calculated, instead of calculating it again.
  15. (c) Copyright 1995-1998, Mission Critical Software, Inc., All Rights Reserved
  16. Proprietary and confidential to Mission Critical Software, Inc.
  17. REVISION LOG ENTRY
  18. Revision By: Christy Boles
  19. Revised on 01-Oct-98 15:51:41
  20. ---------------------------------------------------------------------------
  21. */
  22. #include <windows.h>
  23. #include "McsDebug.h"
  24. #include "McsDbgU.h"
  25. #include "SD.hpp"
  26. TSD::TSD(
  27. SECURITY_DESCRIPTOR * pSD, // in - pointer to self-relative security descriptor
  28. SecuredObjectType objectType, // in - type of object this security descriptor secures
  29. BOOL bResponsibleForDelete // in - if TRUE, this class will delete the memory for pSD
  30. )
  31. {
  32. m_absSD = MakeAbsSD(pSD);
  33. m_bOwnerChanged = FALSE;
  34. m_bGroupChanged = FALSE;
  35. m_bDACLChanged = FALSE;
  36. m_bSACLChanged = FALSE;
  37. m_bNeedToFreeSD = TRUE;
  38. m_bNeedToFreeOwner = TRUE;
  39. m_bNeedToFreeGroup = TRUE;
  40. m_bNeedToFreeDacl = TRUE;
  41. m_bNeedToFreeSacl = TRUE;
  42. m_ObjectType = objectType;
  43. if ( bResponsibleForDelete )
  44. {
  45. free(pSD);
  46. }
  47. }
  48. TSD::TSD(
  49. TSD * pSD // in - another security descriptor
  50. )
  51. {
  52. MCSVERIFY(pSD);
  53. if ( pSD )
  54. {
  55. m_absSD = pSD->MakeAbsSD();
  56. m_bOwnerChanged = FALSE;
  57. m_bGroupChanged = FALSE;
  58. m_bDACLChanged = FALSE;
  59. m_bSACLChanged = FALSE;
  60. m_bNeedToFreeSD = TRUE;
  61. m_bNeedToFreeOwner = TRUE;
  62. m_bNeedToFreeGroup = TRUE;
  63. m_bNeedToFreeDacl = TRUE;
  64. m_bNeedToFreeSacl = TRUE;
  65. m_ObjectType = pSD->GetType();
  66. }
  67. }
  68. //
  69. // This constructor allows for construction of an empty security descriptor. This is useful
  70. // if one wishes to create a security descriptor for an object that does not currently have
  71. // one such as a newly created share with default permissions.
  72. //
  73. TSD::TSD(
  74. SecuredObjectType objectType // in - type of object this security descriptor secures
  75. )
  76. {
  77. m_absSD = (SECURITY_DESCRIPTOR*) malloc(sizeof(SECURITY_DESCRIPTOR));
  78. if (m_absSD)
  79. {
  80. InitializeSecurityDescriptor(m_absSD, SECURITY_DESCRIPTOR_REVISION);
  81. }
  82. m_bOwnerChanged = FALSE;
  83. m_bGroupChanged = FALSE;
  84. m_bDACLChanged = FALSE;
  85. m_bSACLChanged = FALSE;
  86. m_bNeedToFreeSD = TRUE;
  87. m_bNeedToFreeOwner = FALSE;
  88. m_bNeedToFreeGroup = FALSE;
  89. m_bNeedToFreeDacl = FALSE;
  90. m_bNeedToFreeSacl = FALSE;
  91. m_ObjectType = objectType;
  92. }
  93. TSD::~TSD()
  94. {
  95. MCSVERIFY(m_absSD);
  96. if ( m_bNeedToFreeSD )
  97. {
  98. if (m_absSD)
  99. FreeAbsSD(m_absSD,FALSE);
  100. m_absSD = NULL;
  101. }
  102. }
  103. void
  104. TSD::FreeAbsSD(
  105. SECURITY_DESCRIPTOR * pSD, // in - pointer to security descriptor to free
  106. BOOL bAll // in - flag whether to free all parts of the SD, or only those
  107. // allocated by this class
  108. )
  109. {
  110. PSID sid = NULL;
  111. PACL acl = NULL;
  112. BOOL defaulted;
  113. BOOL present;
  114. GetSecurityDescriptorOwner(pSD,&sid,&defaulted);
  115. if ( sid && ( m_bNeedToFreeOwner || bAll ) )
  116. {
  117. free(sid);
  118. sid = NULL;
  119. }
  120. GetSecurityDescriptorGroup(pSD,&sid,&defaulted);
  121. if ( sid && ( m_bNeedToFreeGroup || bAll ) )
  122. {
  123. free(sid);
  124. sid = NULL;
  125. }
  126. GetSecurityDescriptorDacl(pSD,&present,&acl,&defaulted);
  127. if ( acl && (m_bNeedToFreeDacl || bAll ) )
  128. {
  129. free(acl);
  130. acl = NULL;
  131. }
  132. GetSecurityDescriptorSacl(pSD,&present,&acl,&defaulted);
  133. if ( acl && ( m_bNeedToFreeSacl || bAll ) )
  134. {
  135. free(acl);
  136. acl = NULL;
  137. }
  138. free(pSD);
  139. }
  140. SECURITY_DESCRIPTOR * // ret- copy of the SD, in Absolute format
  141. TSD::MakeAbsSD(
  142. SECURITY_DESCRIPTOR * pSD // in - security descriptor to copy
  143. ) const
  144. {
  145. DWORD sd_size = (sizeof SECURITY_DESCRIPTOR);
  146. DWORD dacl_size = 0;
  147. DWORD sacl_size = 0;
  148. DWORD owner_size = 0;
  149. DWORD group_size = 0;
  150. // Allocate space for the SD and its parts
  151. SECURITY_DESCRIPTOR * absSD = (SECURITY_DESCRIPTOR *) malloc(sd_size);
  152. if (!absSD || !pSD)
  153. {
  154. if (absSD)
  155. {
  156. free(absSD);
  157. absSD = NULL;
  158. }
  159. return NULL;
  160. }
  161. PACL absDacl = NULL;
  162. PACL absSacl = NULL;
  163. PSID absOwner = NULL;
  164. PSID absGroup = NULL;
  165. if ( ! MakeAbsoluteSD(pSD,absSD,&sd_size,absDacl,&dacl_size,absSacl,&sacl_size
  166. ,absOwner,&owner_size,absGroup,&group_size) )
  167. {
  168. // DWORD rc = GetLastError();
  169. // didn't work: increase sizes and try again
  170. if ( sd_size > (sizeof SECURITY_DESCRIPTOR) )
  171. {
  172. free(absSD);
  173. absSD = (SECURITY_DESCRIPTOR *) malloc(sd_size);
  174. if (!absSD)
  175. return NULL;
  176. }
  177. if ( dacl_size )
  178. {
  179. absDacl = (PACL)malloc(dacl_size);
  180. if (!absDacl)
  181. {
  182. free(absSD);
  183. absSD = NULL;
  184. return NULL;
  185. }
  186. }
  187. if ( sacl_size )
  188. {
  189. absSacl = (PACL)malloc(sacl_size);
  190. if (!absSacl)
  191. {
  192. free(absSD);
  193. free(absDacl);
  194. absSD = NULL;
  195. absDacl = NULL;
  196. return NULL;
  197. }
  198. }
  199. if ( owner_size )
  200. {
  201. absOwner = (PSID)malloc(owner_size);
  202. if (!absOwner)
  203. {
  204. free(absSD);
  205. free(absDacl);
  206. free(absSacl);
  207. absSD = NULL;
  208. absDacl = NULL;
  209. absSacl = NULL;
  210. return NULL;
  211. }
  212. }
  213. if ( group_size )
  214. {
  215. absGroup = (PSID)malloc(group_size);
  216. if (!absGroup)
  217. {
  218. free(absSD);
  219. free(absDacl);
  220. free(absSacl);
  221. free(absOwner);
  222. absSD = NULL;
  223. absDacl = NULL;
  224. absSacl = NULL;
  225. absOwner = NULL;
  226. return NULL;
  227. }
  228. }
  229. // try again with bigger buffers
  230. if ( ! MakeAbsoluteSD(pSD,absSD,&sd_size,absDacl,&dacl_size,absSacl,&sacl_size
  231. ,absOwner,&owner_size,absGroup,&group_size) )
  232. {
  233. free(absSD);
  234. free(absDacl);
  235. free(absSacl);
  236. free(absOwner);
  237. free(absGroup);
  238. absSD = NULL;
  239. absDacl = NULL;
  240. absSacl = NULL;
  241. absOwner = NULL;
  242. absGroup = NULL;
  243. }
  244. }
  245. return absSD;
  246. }
  247. SECURITY_DESCRIPTOR * // ret- copy of the SD, in Absolute format
  248. TSD::MakeAbsSD() const
  249. {
  250. SECURITY_DESCRIPTOR * absSD = NULL;
  251. SECURITY_DESCRIPTOR * relSD = MakeRelSD();
  252. if (relSD)
  253. {
  254. absSD = MakeAbsSD(relSD);
  255. free(relSD);
  256. }
  257. return absSD;
  258. }
  259. SECURITY_DESCRIPTOR * // ret- copy of the SD, in self-relative form
  260. TSD::MakeRelSD() const
  261. {
  262. DWORD nBytes;
  263. SECURITY_DESCRIPTOR * relSD = NULL;
  264. nBytes = GetSecurityDescriptorLength(m_absSD);
  265. relSD = (SECURITY_DESCRIPTOR *)malloc(nBytes);
  266. if (!relSD)
  267. return NULL;
  268. if (! MakeSelfRelativeSD(m_absSD,relSD,&nBytes) )
  269. {
  270. free(relSD);
  271. relSD = NULL;
  272. }
  273. return relSD;
  274. }
  275. PSID const // ret- sid for security descriptor owner field
  276. TSD::GetOwner() const
  277. {
  278. PSID ownersid = NULL;
  279. BOOL ownerDefaulted;
  280. GetSecurityDescriptorOwner(m_absSD,&ownersid,&ownerDefaulted);
  281. return ownersid;
  282. }
  283. void
  284. TSD::SetOwner(
  285. PSID pNewOwner // in - new value for owner field
  286. )
  287. {
  288. MCSVERIFY(IsValidSecurityDescriptor(m_absSD));
  289. if ( IsValidSid(pNewOwner) )
  290. {
  291. if ( m_bNeedToFreeOwner )
  292. {
  293. PSID old = GetOwner();
  294. free(old);
  295. }
  296. SetSecurityDescriptorOwner(m_absSD,pNewOwner,FALSE);
  297. m_bOwnerChanged = TRUE;
  298. m_bNeedToFreeOwner = TRUE;
  299. }
  300. else
  301. {
  302. MCSVERIFY(FALSE);
  303. }
  304. }
  305. PSID const // ret- sid for security descriptor owner field
  306. TSD::GetGroup() const
  307. {
  308. PSID grpsid = NULL;
  309. BOOL grpDefaulted;
  310. MCSVERIFY(IsValidSecurityDescriptor(m_absSD));
  311. GetSecurityDescriptorGroup(m_absSD,&grpsid,&grpDefaulted);
  312. return grpsid;
  313. }
  314. void
  315. TSD::SetGroup(
  316. PSID pNewGroup // in - new value for primary group field.
  317. )
  318. {
  319. MCSVERIFY(IsValidSecurityDescriptor(m_absSD));
  320. if ( IsValidSid(pNewGroup) )
  321. {
  322. if ( m_bNeedToFreeGroup )
  323. {
  324. PSID old = GetGroup();
  325. free(old);
  326. }
  327. SetSecurityDescriptorGroup(m_absSD,pNewGroup,FALSE);
  328. m_bGroupChanged = TRUE;
  329. m_bNeedToFreeGroup = TRUE;
  330. }
  331. else
  332. {
  333. MCSVERIFY(FALSE);
  334. }
  335. }
  336. PACL const // ret- pointer to DACL
  337. TSD::GetDacl() const
  338. {
  339. PACL acl = NULL;
  340. BOOL defaulted;
  341. BOOL present;
  342. GetSecurityDescriptorDacl(m_absSD,&present,&acl,&defaulted);
  343. return acl;
  344. }
  345. BOOL
  346. TSD::SetDacl(
  347. PACL pNewAcl, // in - new DACL
  348. BOOL present // in - flag, TRUE means DACL is present.
  349. )
  350. {
  351. BOOL defaulted = FALSE;
  352. BOOL success = TRUE;
  353. if ( IsValidAcl(pNewAcl) )
  354. {
  355. if ( m_bNeedToFreeDacl )
  356. {
  357. PACL old = GetDacl();
  358. if ( old != pNewAcl )
  359. {
  360. free(old);
  361. }
  362. }
  363. if (! SetSecurityDescriptorDacl(m_absSD,present,pNewAcl,defaulted) )
  364. {
  365. // DWORD rc = GetLastError();
  366. success = FALSE;
  367. }
  368. m_bDACLChanged = TRUE;
  369. m_bNeedToFreeDacl = TRUE;
  370. }
  371. else
  372. {
  373. MCSVERIFY(FALSE);
  374. success = FALSE;
  375. }
  376. return success;
  377. }
  378. PACL const // ret- pointer to SACL
  379. TSD::GetSacl() const
  380. {
  381. PACL acl = NULL;
  382. BOOL defaulted;
  383. BOOL present;
  384. GetSecurityDescriptorSacl(m_absSD,&present,&acl,&defaulted);
  385. return acl;
  386. }
  387. void
  388. TSD::SetSacl(
  389. PACL pNewAcl, // in - new SACL
  390. BOOL present // in - flag, TRUE means SACL is present
  391. )
  392. {
  393. BOOL defaulted = FALSE;
  394. if ( IsValidAcl(pNewAcl) )
  395. {
  396. if ( m_bNeedToFreeSacl )
  397. {
  398. PACL old = GetSacl();
  399. if ( old != pNewAcl )
  400. {
  401. free(old);
  402. }
  403. }
  404. SetSecurityDescriptorSacl(m_absSD,present,pNewAcl,defaulted);
  405. m_bSACLChanged = TRUE;
  406. m_bNeedToFreeSacl = TRUE;
  407. }
  408. else
  409. {
  410. MCSVERIFY(FALSE);
  411. }
  412. }
  413. BOOL
  414. TSD::IsOwnerDefaulted() const
  415. {
  416. PSID ownersid = NULL;
  417. BOOL ownerDefaulted = FALSE;
  418. GetSecurityDescriptorOwner(m_absSD,&ownersid,&ownerDefaulted);
  419. return ownerDefaulted;
  420. }
  421. BOOL
  422. TSD::IsGroupDefaulted() const
  423. {
  424. PSID groupsid = NULL;
  425. BOOL groupDefaulted = FALSE;
  426. GetSecurityDescriptorGroup(m_absSD,&groupsid,&groupDefaulted);
  427. return groupDefaulted;
  428. }
  429. BOOL
  430. TSD::IsDaclDefaulted() const
  431. {
  432. PACL acl = NULL;
  433. BOOL defaulted = FALSE;
  434. BOOL present;
  435. GetSecurityDescriptorDacl(m_absSD,&present,&acl,&defaulted);
  436. return defaulted;
  437. }
  438. BOOL
  439. TSD::IsDaclPresent() const
  440. {
  441. PACL acl = NULL;
  442. BOOL defaulted;
  443. BOOL present = FALSE;
  444. GetSecurityDescriptorDacl(m_absSD,&present,&acl,&defaulted);
  445. return present;
  446. }
  447. BOOL
  448. TSD::IsSaclDefaulted() const
  449. {
  450. PACL acl = NULL;
  451. BOOL defaulted = FALSE;
  452. BOOL present;
  453. GetSecurityDescriptorSacl(m_absSD,&present,&acl,&defaulted);
  454. return defaulted;
  455. }
  456. BOOL
  457. TSD::IsSaclPresent() const
  458. {
  459. PACL acl = NULL;
  460. BOOL defaulted;
  461. BOOL present = FALSE;
  462. GetSecurityDescriptorSacl(m_absSD,&present,&acl,&defaulted);
  463. return present;
  464. }
  465. int // ret- number of aces in the ACL
  466. TSD::ACLGetNumAces(
  467. PACL acl // in - DACL or SACL
  468. )
  469. {
  470. int nAces = 0;
  471. ACL_SIZE_INFORMATION info;
  472. if ( acl )
  473. {
  474. if ( GetAclInformation(acl,&info,(sizeof info),AclSizeInformation) )
  475. {
  476. nAces = info.AceCount;
  477. }
  478. else
  479. {
  480. // DWORD rc=GetLastError();
  481. }
  482. }
  483. return nAces;
  484. }
  485. DWORD // ret- number of free bytes in the ACL
  486. TSD::ACLGetFreeBytes(
  487. PACL acl // in - DACL or SACL
  488. )
  489. {
  490. int nFree = 0;
  491. ACL_SIZE_INFORMATION info;
  492. if ( acl )
  493. {
  494. if ( GetAclInformation(acl,&info,(sizeof info),AclSizeInformation) )
  495. {
  496. nFree = info.AclBytesFree;
  497. }
  498. }
  499. return nFree;
  500. }
  501. DWORD // ret- number of used bytes in the ACL
  502. TSD::ACLGetBytesInUse(
  503. PACL acl // in - DACL or SACL
  504. )
  505. {
  506. int nBytes = 0;
  507. ACL_SIZE_INFORMATION info;
  508. if ( acl )
  509. {
  510. if ( GetAclInformation(acl,&info,(sizeof info),AclSizeInformation) )
  511. {
  512. nBytes = info.AclBytesInUse;
  513. }
  514. }
  515. return nBytes;
  516. }
  517. void * // ret- pointer to ace
  518. TSD::ACLGetAce(
  519. PACL acl, // in - DACL or SACL
  520. int ndx // in - index of ace to retrieve
  521. )
  522. {
  523. void * ace = NULL;
  524. if ( ndx < ACLGetNumAces(acl) )
  525. {
  526. if ( ! GetAce(acl,ndx,(void**)&ace) )
  527. {
  528. ace = NULL;
  529. }
  530. }
  531. else
  532. {
  533. MCSASSERT(FALSE); // you specified a non-existant index
  534. }
  535. return ace;
  536. }
  537. void
  538. TSD::ACLDeleteAce(
  539. PACL acl, // in - DACL or SACL
  540. int ndx // in - index of ace to delete
  541. )
  542. {
  543. int nAces = ACLGetNumAces(acl);
  544. if ( ndx < nAces )
  545. {
  546. DeleteAce(acl,ndx);
  547. }
  548. else
  549. {
  550. MCSASSERT(FALSE); // you specified an invalid index
  551. }
  552. }
  553. // Access allowed aces are added at the beginning of the list, access denied aces are added at the end of the list
  554. // Note: ppAcl and pAce should be of the same revision level, otherwise AddAce will fail
  555. // Most usage of ACLAddAce includes two situations:
  556. // 1) pAce is from ppAcl or a copy of ace from ppAcl
  557. // 2) ppAcl is NULL and pAce is ACCESS_ALLOWED_ACE_TYPE
  558. void
  559. TSD::ACLAddAce(
  560. PACL * ppAcl, // i/o- DACL or SACL (this function may reallocate if the acl doesn't have room
  561. TACE * pAce, // in - ACE to add
  562. int pos // in - position
  563. )
  564. {
  565. DWORD ndx = (DWORD)pos;
  566. DWORD rc;
  567. PACL acl = (*ppAcl);
  568. PACL newAcl = NULL;
  569. BOOL bSuccess = TRUE; // indicates whether the ACE has been added into the ACL
  570. BOOL bOwnAcl = FALSE; // indicates whether the passed ACL is NULL so that we have to create it
  571. DWORD numaces = ACLGetNumAces(acl);
  572. DWORD freebytes = ACLGetFreeBytes(acl);
  573. // allocate a new ACL if it doesn't already exist
  574. if ( ! acl )
  575. {
  576. bOwnAcl = TRUE;
  577. acl = (PACL) malloc(SD_DEFAULT_ACL_SIZE);
  578. if (!acl)
  579. return;
  580. InitializeAcl(acl,SD_DEFAULT_ACL_SIZE,ACL_REVISION);
  581. numaces = ACLGetNumAces(acl);
  582. freebytes = ACLGetFreeBytes(acl);
  583. }
  584. if ( pos == -1 )
  585. {
  586. if ( pAce->IsAccessAllowedAce() )
  587. {
  588. ndx = 0;
  589. }
  590. else
  591. {
  592. ndx = MAXDWORD; // insert at end of the list
  593. }
  594. }
  595. WORD currAceSize = pAce->GetSize();
  596. if ( freebytes < currAceSize ) // we must allocate more space for the ace
  597. {
  598. // if acl is created by us, we need to free it first
  599. if (bOwnAcl)
  600. {
  601. free(acl);
  602. acl = NULL;
  603. }
  604. // make a bigger acl
  605. newAcl = (ACL*)malloc(ACLGetBytesInUse(acl) + freebytes + currAceSize);
  606. if (!newAcl)
  607. {
  608. bSuccess = FALSE;
  609. }
  610. else
  611. {
  612. memcpy(newAcl,acl,ACLGetBytesInUse(acl) + freebytes);
  613. newAcl->AclSize +=currAceSize;
  614. acl = newAcl;
  615. }
  616. }
  617. if (bSuccess)
  618. {
  619. if (!pAce->GetBuffer())
  620. {
  621. bSuccess = FALSE;
  622. }
  623. }
  624. if (bSuccess)
  625. {
  626. if (! AddAce(acl,acl->AclRevision,ndx,pAce->GetBuffer(),currAceSize) )
  627. {
  628. bSuccess = FALSE;
  629. }
  630. }
  631. if (!bSuccess)
  632. {
  633. if (newAcl)
  634. free(newAcl);
  635. else if (bOwnAcl) // if acl is created by us, we need to free it
  636. // note: we only need to do this when newAcl is NULL
  637. free(acl);
  638. acl = NULL;
  639. }
  640. (*ppAcl) = acl;
  641. }
  642. // creates a new ace with the specified properties
  643. TACE::TACE(
  644. BYTE type, // in - type of ace (ACCESS_ALLOWED_ACE_TYPE, etc.)
  645. BYTE flags, // in - ace flags (controls inheritance, etc. use 0 for files)
  646. DWORD mask, // in - access control mask (see constants in sd.hpp)
  647. PSID sid // in - pointer to sid for this ace
  648. )
  649. {
  650. MCSVERIFY(sid);
  651. // allocate memory for the new ace
  652. DWORD size = (sizeof ACCESS_ALLOWED_ACE) + GetLengthSid(sid) - (sizeof DWORD);
  653. m_pAce = (ACCESS_ALLOWED_ACE *)malloc(size);
  654. // Initialize the ACE
  655. if (m_pAce)
  656. {
  657. m_bNeedToFree = TRUE;
  658. m_pAce->Header.AceType = type;
  659. m_pAce->Header.AceFlags = flags;
  660. m_pAce->Header.AceSize = (WORD) size;
  661. m_pAce->Mask = mask;
  662. memcpy(&m_pAce->SidStart,sid,GetLengthSid(sid));
  663. }
  664. }
  665. BYTE // ret- ace type (ACCESS_ALLOWED_ACE_TYPE, etc.)
  666. TACE::GetType()
  667. {
  668. MCSVERIFY(m_pAce);
  669. BYTE type = ACCESS_ALLOWED_ACE_TYPE;
  670. if (m_pAce)
  671. type = m_pAce->Header.AceType;
  672. return type;
  673. }
  674. BYTE // ret- ace flags (OBJECT_INHERIT_ACE, etc.)
  675. TACE::GetFlags()
  676. {
  677. MCSVERIFY(m_pAce);
  678. BYTE flags = OBJECT_INHERIT_ACE;
  679. if (m_pAce)
  680. flags = m_pAce->Header.AceFlags;
  681. return flags;
  682. }
  683. DWORD // ret- access control mask
  684. TACE::GetMask()
  685. {
  686. MCSVERIFY(m_pAce);
  687. DWORD mask = 0;
  688. if (m_pAce)
  689. mask = m_pAce->Mask;
  690. return mask;
  691. }
  692. PSID // ret- sid for this ace
  693. TACE::GetSid()
  694. {
  695. MCSVERIFY(m_pAce);
  696. PSID pSid = NULL;
  697. if (m_pAce)
  698. pSid = &m_pAce->SidStart;
  699. return pSid;
  700. }
  701. WORD // ret- size of the ace, in bytes
  702. TACE::GetSize()
  703. {
  704. MCSVERIFY(m_pAce);
  705. WORD size = 0;
  706. if (m_pAce)
  707. size = m_pAce->Header.AceSize;
  708. return size;
  709. }
  710. BOOL
  711. TACE::SetType(
  712. BYTE newType // in -new type for ace
  713. )
  714. {
  715. MCSVERIFY(m_pAce);
  716. if (!m_pAce)
  717. return FALSE;
  718. MCSASSERT( newType=ACCESS_ALLOWED_ACE_TYPE ||
  719. newType==ACCESS_DENIED_ACE_TYPE ||
  720. newType==SYSTEM_AUDIT_ACE_TYPE );
  721. m_pAce->Header.AceType = newType;
  722. return TRUE;
  723. }
  724. BOOL
  725. TACE::SetFlags(
  726. BYTE newFlags // in - new flags for ace
  727. )
  728. {
  729. MCSVERIFY(m_pAce);
  730. if (!m_pAce)
  731. return FALSE;
  732. m_pAce->Header.AceFlags = newFlags;
  733. return TRUE;
  734. }
  735. BOOL
  736. TACE::SetMask(
  737. DWORD newMask // in - new access control mask
  738. )
  739. {
  740. MCSVERIFY(m_pAce);
  741. if (!m_pAce)
  742. return FALSE;
  743. m_pAce->Mask = newMask;
  744. return TRUE;
  745. }
  746. DWORD
  747. TACE::SetSid(
  748. PSID sid // in - new SID for this ace
  749. )
  750. {
  751. DWORD result = SET_SID_NOTLARGEENOUGH;
  752. MCSVERIFY( m_pAce );
  753. MCSASSERT( IsValidSid(sid) );
  754. if (!m_pAce)
  755. return SET_SID_FAILED;
  756. if ( GetLengthSid(sid) <= GetLengthSid(GetSid()) )
  757. {
  758. memcpy(&m_pAce->SidStart,sid,GetLengthSid(sid));
  759. result = SET_SID_SUCCEEDED;
  760. }
  761. return result;
  762. }
  763. BOOL
  764. TACE::IsAccessAllowedAce()
  765. {
  766. MCSVERIFY(m_pAce);
  767. return ( GetType() == ACCESS_ALLOWED_ACE_TYPE );
  768. }