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.

826 lines
24 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : SecurityInfo.cpp //
  3. // //
  4. // DESCRIPTION : The ISecurityInformation implmentation used to //
  5. // instantiate a security page. //
  6. // //
  7. // AUTHOR : yossg //
  8. // //
  9. // HISTORY : //
  10. // Feb 7 2000 yossg Create //
  11. // //
  12. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "SecurityInfo.h"
  16. #include "FaxServer.h"
  17. #include "FaxServerNode.h"
  18. #include "MsFxsSnp.h"
  19. //#pragma hdrstop
  20. const GENERIC_MAPPING gc_FaxGenericMapping =
  21. {
  22. (STANDARD_RIGHTS_READ | FAX_GENERIC_READ),
  23. (STANDARD_RIGHTS_WRITE | FAX_GENERIC_WRITE),
  24. (STANDARD_RIGHTS_EXECUTE | FAX_GENERIC_EXECUTE),
  25. (READ_CONTROL | WRITE_DAC | WRITE_OWNER | FAX_GENERIC_ALL)
  26. };
  27. CFaxSecurityInformation::CFaxSecurityInformation()
  28. {
  29. DebugPrint(( TEXT("CFaxSecurityInfo Created") ));
  30. }
  31. CFaxSecurityInformation::~CFaxSecurityInformation()
  32. {
  33. DebugPrint(( TEXT("CFaxSecurityInfo Destroyed") ));
  34. }
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CFaxSecurityInformation
  37. // *** ISecurityInformation methods implementation ***
  38. /*
  39. - CFaxSecurityInformation::GetObjectInformation
  40. -
  41. * Purpose:
  42. * Performs an access check against the fax service security descriptor
  43. *
  44. * Arguments:
  45. * [in] pObjectInfo - pointer to object information structure.
  46. *
  47. * Return:
  48. * OLE error code
  49. */
  50. HRESULT
  51. STDMETHODCALLTYPE
  52. CFaxSecurityInformation::GetObjectInformation(
  53. IN OUT PSI_OBJECT_INFO pObjectInfo
  54. )
  55. {
  56. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::GetObjectInformation"));
  57. DWORD ec = ERROR_SUCCESS;
  58. CFaxServer * pFaxServer = NULL;
  59. HINSTANCE hInst;
  60. HANDLE hPrivBeforeSE_TAKE_OWNERSHIP = INVALID_HANDLE_VALUE;
  61. HANDLE hPrivBeforeSE_SECURITY = INVALID_HANDLE_VALUE;
  62. ATLASSERT( pObjectInfo != NULL );
  63. if( pObjectInfo == NULL )
  64. {
  65. DebugPrintEx( DEBUG_ERR,
  66. _T("Invalid parameter - pObjectInfo == NULL"));
  67. return E_POINTER;
  68. }
  69. //
  70. // Set Flags
  71. //
  72. pObjectInfo->dwFlags = SI_EDIT_ALL |
  73. SI_NO_TREE_APPLY |
  74. SI_NO_ACL_PROTECT |
  75. SI_ADVANCED;
  76. pFaxServer = m_pFaxServerNode->GetFaxServer();
  77. ATLASSERT(pFaxServer);
  78. if (!pFaxServer->GetFaxServerHandle())
  79. {
  80. ec= GetLastError();
  81. DebugPrintEx(
  82. DEBUG_ERR,
  83. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  84. ec);
  85. goto Error;
  86. }
  87. //
  88. // Check if to add SI_READONLY
  89. //
  90. if (!FaxAccessCheckEx(
  91. pFaxServer->GetFaxServerHandle(),
  92. WRITE_DAC,
  93. NULL))
  94. {
  95. ec = GetLastError();
  96. if (ERROR_SUCCESS == ec)
  97. {
  98. pObjectInfo->dwFlags |= SI_READONLY;
  99. }
  100. else
  101. {
  102. DebugPrintEx(
  103. DEBUG_ERR,
  104. _T("Fail check access for WRITE_DAC."));
  105. goto Error;
  106. }
  107. }
  108. //
  109. // Check if to add SI_OWNER_READONLY
  110. //
  111. hPrivBeforeSE_TAKE_OWNERSHIP = EnablePrivilege (SE_TAKE_OWNERSHIP_NAME);
  112. //
  113. // No error checking - If we failed we will get ERROR_ACCESS_DENIED in the access check
  114. //
  115. if (!FaxAccessCheckEx(
  116. pFaxServer->GetFaxServerHandle(),
  117. WRITE_OWNER,
  118. NULL))
  119. {
  120. ec = GetLastError();
  121. if (ERROR_SUCCESS == ec)
  122. {
  123. pObjectInfo->dwFlags |= SI_OWNER_READONLY;
  124. }
  125. else
  126. {
  127. DebugPrintEx(
  128. DEBUG_ERR,
  129. _T("Fail check access for WRITE_OWNER."));
  130. goto Error;
  131. }
  132. }
  133. //
  134. // Check if to remove SI_EDIT_AUDITS
  135. //
  136. hPrivBeforeSE_SECURITY = EnablePrivilege (SE_SECURITY_NAME);
  137. //
  138. // No error checking - If we failed we will get ERROR_ACCESS_DENIED in the access check
  139. //
  140. if (!FaxAccessCheckEx(
  141. pFaxServer->GetFaxServerHandle(),
  142. ACCESS_SYSTEM_SECURITY,
  143. NULL))
  144. {
  145. ec = GetLastError();
  146. if (ERROR_SUCCESS == ec)
  147. {
  148. pObjectInfo->dwFlags &= ~SI_EDIT_AUDITS;
  149. }
  150. else
  151. {
  152. DebugPrintEx(
  153. DEBUG_ERR,
  154. _T("Fail check access for ACCESS_SYSTEM_SECURITY."));
  155. goto Error;
  156. }
  157. }
  158. //
  159. // Set all other fields
  160. //
  161. hInst = _Module.GetResourceInstance();
  162. pObjectInfo->hInstance = hInst;
  163. m_bstrServerName = m_pFaxServerNode->GetServerName();
  164. if ( 0 == m_bstrServerName.Length() )
  165. {
  166. pObjectInfo->pszServerName = NULL;
  167. DebugPrintEx( DEBUG_MSG,
  168. _T("NULL ServerName ie: Local machine."));
  169. }
  170. else
  171. {
  172. pObjectInfo->pszServerName = m_bstrServerName;
  173. DebugPrintEx( DEBUG_MSG,
  174. _T("ServerName is: %s."),
  175. pObjectInfo->pszServerName);
  176. }
  177. if (!m_bstrObjectName.LoadString(IDS_SECURITY_CAT_NODE_DESC))
  178. {
  179. ec = ERROR_NOT_ENOUGH_MEMORY;
  180. DebugPrintEx(
  181. DEBUG_ERR,
  182. TEXT("Out of memory. Failed to load string."));
  183. goto Error;
  184. }
  185. pObjectInfo->pszObjectName = m_bstrObjectName;
  186. ATLASSERT ( ERROR_SUCCESS == ec );
  187. ReleasePrivilege (hPrivBeforeSE_SECURITY);
  188. ReleasePrivilege (hPrivBeforeSE_TAKE_OWNERSHIP);
  189. goto Exit;
  190. Error:
  191. ATLASSERT(ERROR_SUCCESS != ec);
  192. ReleasePrivilege (hPrivBeforeSE_SECURITY);
  193. ReleasePrivilege (hPrivBeforeSE_TAKE_OWNERSHIP);
  194. return HRESULT_FROM_WIN32(ec);
  195. Exit:
  196. return S_OK;
  197. }
  198. /*
  199. - CFaxSecurityInformation::GetSecurity
  200. -
  201. * Purpose:
  202. * requests a security descriptor for the securable object whose
  203. * security descriptor is being edited. The access control editor
  204. * calls this method to retrieve the object's current or default security descriptor.
  205. *
  206. * Arguments:
  207. * [in] RequestedInformation - security information.
  208. * [out] ppSecurityDescriptor - pointer to security descriptor.
  209. * [in] fDefault - not implemented
  210. *
  211. * Return:
  212. * OLE error code
  213. */
  214. HRESULT
  215. STDMETHODCALLTYPE
  216. CFaxSecurityInformation::GetSecurity(
  217. IN SECURITY_INFORMATION RequestedInformation,
  218. OUT PSECURITY_DESCRIPTOR *ppSecurityDescriptor,
  219. IN BOOL fDefault
  220. )
  221. {
  222. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::GetSecurity"));
  223. HRESULT hRc = S_OK;
  224. CFaxServer * pFaxServer = NULL;
  225. PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  226. DWORD ec = ERROR_SUCCESS;
  227. BOOL bResult;
  228. HANDLE hPrivBeforeSE_SECURITY = INVALID_HANDLE_VALUE;
  229. ATLASSERT( ppSecurityDescriptor);
  230. if( fDefault == TRUE )
  231. {
  232. DebugPrintEx( DEBUG_MSG,
  233. _T("Non implemeted feature -> fDefault == TRUE"));
  234. return E_NOTIMPL;
  235. }
  236. if (RequestedInformation & SACL_SECURITY_INFORMATION)
  237. {
  238. hPrivBeforeSE_SECURITY = EnablePrivilege (SE_SECURITY_NAME);
  239. }
  240. pFaxServer = m_pFaxServerNode->GetFaxServer();
  241. ATLASSERT(pFaxServer);
  242. if (!pFaxServer->GetFaxServerHandle())
  243. {
  244. ec= GetLastError();
  245. DebugPrintEx(
  246. DEBUG_ERR,
  247. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  248. ec);
  249. hRc = HRESULT_FROM_WIN32(ec);
  250. goto Exit;
  251. }
  252. //
  253. // Get the current relative descriptor from the fax server
  254. //
  255. bResult = FaxGetSecurityEx( pFaxServer->GetFaxServerHandle(),
  256. RequestedInformation,
  257. &pSecurityDescriptor);
  258. if( bResult == FALSE )
  259. {
  260. ec = GetLastError();
  261. if (IsNetworkError(ec))
  262. {
  263. DebugPrintEx(
  264. DEBUG_ERR,
  265. _T("Network Error was found. Failed to set security info.(ec: %ld)"),
  266. ec);
  267. pFaxServer->Disconnect();
  268. }
  269. else
  270. {
  271. DebugPrintEx(
  272. DEBUG_ERR,
  273. _T("Failed while call to FaxGetSecurityEx. (ec: %ld)"),
  274. ec);
  275. }
  276. hRc = HRESULT_FROM_WIN32(ec);
  277. goto Exit;
  278. }
  279. //
  280. // return a self relative descriptor copy allocated with LocalAlloc()
  281. //
  282. hRc = MakeSelfRelativeCopy( pSecurityDescriptor, ppSecurityDescriptor );
  283. if( FAILED( hRc ) )
  284. {
  285. DebugPrintEx(
  286. DEBUG_ERR,
  287. _T("MakeSelfRelativeCopy Failed. (hRc : %08X)"),
  288. hRc);
  289. goto Exit;
  290. }
  291. ATLASSERT(S_OK == hRc);
  292. Exit:
  293. if (NULL != pSecurityDescriptor)
  294. {
  295. FaxFreeBuffer(pSecurityDescriptor);
  296. }
  297. ReleasePrivilege (hPrivBeforeSE_SECURITY);
  298. return hRc;
  299. }
  300. /*
  301. - CFaxSecurityInformation::SetSecurity
  302. -
  303. * Purpose:
  304. * Provides a security descriptor containing the security information
  305. * the user wants to apply to the securable object. The access control
  306. * editor calls this method when the user clicks the Okay or Apply buttons.
  307. *
  308. * Arguments:
  309. * [in] SecurityInformation - security information structure.
  310. * [in] pSecurityDescriptor - pointer to security descriptor.
  311. *
  312. * Return:
  313. * OLE error code
  314. */
  315. HRESULT
  316. STDMETHODCALLTYPE
  317. CFaxSecurityInformation::SetSecurity(
  318. IN SECURITY_INFORMATION SecurityInformation,
  319. IN PSECURITY_DESCRIPTOR pSecurityDescriptor
  320. )
  321. {
  322. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::SetSecurity"));
  323. HRESULT hRc = S_OK;
  324. DWORD ec = ERROR_SUCCESS;
  325. BOOL bResult;
  326. HINSTANCE hInst = _Module.GetResourceInstance();
  327. PSECURITY_DESCRIPTOR psdSelfRelativeCopy = NULL;
  328. CFaxServer * pFaxServer = NULL;
  329. HANDLE hPrivBeforeSE_TAKE_OWNERSHIP = INVALID_HANDLE_VALUE;
  330. HANDLE hPrivBeforeSE_SECURITY = INVALID_HANDLE_VALUE;
  331. ATLASSERT( NULL != pSecurityDescriptor );
  332. ATLASSERT( IsValidSecurityDescriptor( pSecurityDescriptor ) );
  333. //
  334. // Prepare self relative descriptor
  335. //
  336. hRc = MakeSelfRelativeCopy( pSecurityDescriptor, &psdSelfRelativeCopy );
  337. if( FAILED( hRc ) )
  338. {
  339. DebugPrintEx(
  340. DEBUG_ERR,
  341. _T("MakeSelfRelativeCopy Failed. (hRc : %08X)"),
  342. hRc);
  343. goto Exit;
  344. }
  345. if (SecurityInformation & OWNER_SECURITY_INFORMATION)
  346. {
  347. hPrivBeforeSE_TAKE_OWNERSHIP = EnablePrivilege (SE_TAKE_OWNERSHIP_NAME);
  348. }
  349. if (SecurityInformation & SACL_SECURITY_INFORMATION)
  350. {
  351. hPrivBeforeSE_SECURITY = EnablePrivilege (SE_SECURITY_NAME);
  352. }
  353. pFaxServer = m_pFaxServerNode->GetFaxServer();
  354. ATLASSERT(pFaxServer);
  355. if (!pFaxServer->GetFaxServerHandle())
  356. {
  357. ec= GetLastError();
  358. DebugPrintEx(
  359. DEBUG_ERR,
  360. _T("Failed to GetFaxServerHandle. (ec: %ld)"),
  361. ec);
  362. hRc = HRESULT_FROM_WIN32(ec);
  363. goto Exit;
  364. }
  365. //
  366. // save the new relative descriptor to the fax server
  367. //
  368. bResult = FaxSetSecurity( pFaxServer->GetFaxServerHandle(),
  369. SecurityInformation,
  370. psdSelfRelativeCopy);
  371. if( bResult == FALSE )
  372. {
  373. ec = GetLastError();
  374. if (IsNetworkError(ec))
  375. {
  376. DebugPrintEx(
  377. DEBUG_ERR,
  378. _T("Network Error was found. Failed to set security info.(ec: %ld)"),
  379. ec);
  380. pFaxServer->Disconnect();
  381. }
  382. else
  383. {
  384. DebugPrintEx(
  385. DEBUG_ERR,
  386. _T("Failed while call to FaxSetSecurity. (ec: %ld)"),
  387. ec);
  388. }
  389. hRc = HRESULT_FROM_WIN32(ec);
  390. goto Exit;
  391. }
  392. ATLASSERT( S_OK == hRc || E_ACCESSDENIED == hRc);
  393. Exit:
  394. if (NULL != psdSelfRelativeCopy)
  395. {
  396. ::LocalFree(psdSelfRelativeCopy);
  397. psdSelfRelativeCopy = NULL;
  398. }
  399. ReleasePrivilege (hPrivBeforeSE_SECURITY);
  400. ReleasePrivilege (hPrivBeforeSE_TAKE_OWNERSHIP);
  401. return hRc;
  402. }
  403. /*
  404. - CFaxSecurityInformation::GetAccessRights
  405. -
  406. * Purpose:
  407. * Requests information about the access rights that can be
  408. * controlled for a securable object. The access control
  409. * editor calls this method to retrieve display strings and
  410. * other information used to initialize the property pages.
  411. *
  412. * Arguments:
  413. * [in] pguidObjectType - Pointer to a GUID structure that
  414. * identifies the type of object for which
  415. * access rights are being requested.
  416. * [in] dwFlags - A set of bit flags that indicate the property
  417. * page being initialized
  418. * [out] ppAccess - Pointer to a variable that you should
  419. * set to a pointer to an array of SI_ACCESS
  420. * structures.
  421. * [out] pcAccesses - Pointer to a variable that you should set
  422. * to indicate the number of entries in the ppAccess array.
  423. * [out] piDefaultAccess - Pointer to a variable that you should set
  424. * to indicate the zero-based index of the array entry that contains
  425. * the default access rights.
  426. * The access control editor uses this entry as the initial access rights in a new ACE.
  427. *
  428. * Return:
  429. * OLE error code
  430. */
  431. HRESULT
  432. STDMETHODCALLTYPE
  433. CFaxSecurityInformation::GetAccessRights(
  434. IN const GUID* pguidObjectType,
  435. IN DWORD dwFlags, // SI_EDIT_AUDITS, SI_EDIT_PROPERTIES
  436. OUT PSI_ACCESS *ppAccess,
  437. OUT ULONG *pcAccesses,
  438. OUT ULONG *piDefaultAccess
  439. )
  440. {
  441. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::GetAccessRights"));
  442. ATLASSERT( ppAccess );
  443. ATLASSERT( pcAccesses );
  444. ATLASSERT( piDefaultAccess );
  445. //
  446. // Access rights for the Advanced security page
  447. //
  448. static SI_ACCESS siFaxAccesses[] =
  449. {
  450. // 0 submit permission
  451. {
  452. &GUID_NULL,
  453. FAX_ACCESS_SUBMIT ,
  454. MAKEINTRESOURCE(IDS_FAXSEC_SUB_LOW),
  455. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  456. },
  457. // 1 submit normal permission
  458. {
  459. &GUID_NULL,
  460. FAX_ACCESS_SUBMIT_NORMAL ,
  461. MAKEINTRESOURCE(IDS_FAXSEC_SUB_NORMAL),
  462. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  463. },
  464. // 2 submit high permission
  465. {
  466. &GUID_NULL,
  467. FAX_ACCESS_SUBMIT_HIGH ,
  468. MAKEINTRESOURCE(IDS_FAXSEC_SUB_HIGH),
  469. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  470. },
  471. // 3 query jobs
  472. {
  473. &GUID_NULL,
  474. FAX_ACCESS_QUERY_JOBS,
  475. MAKEINTRESOURCE(IDS_FAXSEC_JOB_QRY),
  476. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  477. },
  478. // 4 Manage jobs
  479. {
  480. &GUID_NULL,
  481. FAX_ACCESS_MANAGE_JOBS,
  482. MAKEINTRESOURCE(IDS_FAXSEC_JOB_MNG),
  483. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  484. },
  485. // 5 query configuration
  486. {
  487. &GUID_NULL,
  488. FAX_ACCESS_QUERY_CONFIG,
  489. MAKEINTRESOURCE(IDS_FAXSEC_CONFIG_QRY),
  490. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  491. },
  492. // 6 Manage configuration
  493. {
  494. &GUID_NULL,
  495. FAX_ACCESS_MANAGE_CONFIG,
  496. MAKEINTRESOURCE(IDS_FAXSEC_CONFIG_SET),
  497. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  498. },
  499. // 7 Query incoming faxes archive
  500. {
  501. &GUID_NULL,
  502. FAX_ACCESS_QUERY_IN_ARCHIVE,
  503. MAKEINTRESOURCE(IDS_FAXSEC_QRY_IN_ARCH),
  504. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  505. },
  506. // 8 Manage incoming faxes archive
  507. {
  508. &GUID_NULL,
  509. FAX_ACCESS_MANAGE_IN_ARCHIVE,
  510. MAKEINTRESOURCE(IDS_FAXSEC_MNG_IN_ARCH),
  511. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  512. },
  513. // 9 Query outgoing faxes archive
  514. {
  515. &GUID_NULL,
  516. FAX_ACCESS_QUERY_OUT_ARCHIVE,
  517. MAKEINTRESOURCE(IDS_FAXSEC_QRY_OUT_ARCH),
  518. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  519. },
  520. // 10 Manage outgoing faxes archive
  521. {
  522. &GUID_NULL,
  523. FAX_ACCESS_MANAGE_OUT_ARCHIVE,
  524. MAKEINTRESOURCE(IDS_FAXSEC_MNG_OUT_ARCH),
  525. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  526. },
  527. // specific permissions
  528. // 11 Read permission
  529. {
  530. &GUID_NULL,
  531. READ_CONTROL,
  532. MAKEINTRESOURCE(IDS_FAXSEC_READ_PERM),
  533. SI_ACCESS_SPECIFIC
  534. },
  535. // 12 Change Permissions
  536. {
  537. &GUID_NULL,
  538. WRITE_DAC,
  539. MAKEINTRESOURCE(IDS_FAXSEC_CHNG_PERM),
  540. SI_ACCESS_SPECIFIC
  541. },
  542. // 13 Take ownership
  543. {
  544. &GUID_NULL,
  545. WRITE_OWNER,
  546. MAKEINTRESOURCE(IDS_FAXSEC_CHNG_OWNER),
  547. SI_ACCESS_SPECIFIC
  548. }
  549. };
  550. //
  551. // Access rights for the Basic security page
  552. //
  553. static SI_ACCESS siFaxBasicAccess[] =
  554. {
  555. // 0 Fax
  556. {
  557. &GUID_NULL,
  558. FAX_ACCESS_SUBMIT_NORMAL | FAX_ACCESS_SUBMIT,
  559. MAKEINTRESOURCE(IDS_RIGHT_FAX),
  560. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  561. },
  562. // 1 Manage fax configuration
  563. {
  564. &GUID_NULL,
  565. FAX_ACCESS_MANAGE_CONFIG | FAX_ACCESS_QUERY_CONFIG,
  566. MAKEINTRESOURCE(IDS_RIGHT_MNG_CFG),
  567. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  568. },
  569. // 2 Manage fax documents
  570. {
  571. &GUID_NULL,
  572. FAX_ACCESS_MANAGE_JOBS | FAX_ACCESS_QUERY_JOBS |
  573. FAX_ACCESS_MANAGE_IN_ARCHIVE | FAX_ACCESS_QUERY_IN_ARCHIVE |
  574. FAX_ACCESS_MANAGE_OUT_ARCHIVE | FAX_ACCESS_QUERY_OUT_ARCHIVE,
  575. MAKEINTRESOURCE(IDS_RIGHT_MNG_DOC),
  576. SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC
  577. }
  578. };
  579. *ppAccess = (0 == dwFlags) ? siFaxBasicAccess : siFaxAccesses;
  580. *pcAccesses = ULONG((0 == dwFlags) ? ARR_SIZE(siFaxBasicAccess) : ARR_SIZE(siFaxAccesses));
  581. *piDefaultAccess = (0 == dwFlags) ? 0 : 1;
  582. return S_OK;
  583. }
  584. /*
  585. - CFaxSecurityInformation::MapGeneric
  586. -
  587. * Purpose:
  588. * Requests that the generic access rights in an access mask
  589. * be mapped to their corresponding standard and specific access rights.
  590. *
  591. * Arguments:
  592. *
  593. * Return:
  594. * OLE error code
  595. */
  596. HRESULT
  597. STDMETHODCALLTYPE
  598. CFaxSecurityInformation::MapGeneric(
  599. IN const GUID *pguidObjectType,
  600. IN UCHAR *pAceFlags,
  601. IN OUT ACCESS_MASK *pMask
  602. )
  603. {
  604. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::MapGeneric"));
  605. MapGenericMask( pMask, const_cast<PGENERIC_MAPPING>(&gc_FaxGenericMapping) );
  606. return S_OK;
  607. }
  608. /*
  609. - CFaxSecurityInformation::GetInheritTypes
  610. -
  611. * Purpose:
  612. * Not implemented.
  613. *
  614. * Arguments:
  615. *
  616. * Return:
  617. * OLE error code
  618. */
  619. HRESULT
  620. STDMETHODCALLTYPE
  621. CFaxSecurityInformation::GetInheritTypes(
  622. OUT PSI_INHERIT_TYPE *ppInheritTypes,
  623. OUT ULONG *pcInheritTypes
  624. )
  625. {
  626. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::GetInheritTypes --- Not implemented"));
  627. return E_NOTIMPL;
  628. }
  629. /*
  630. - CFaxSecurityInformation::PropertySheetPageCallback
  631. -
  632. * Purpose:
  633. * Notifies an EditSecurity or CreateSecurityPage caller
  634. * that an access control editor property page is being created or destroyed.
  635. *
  636. * Arguments:
  637. *
  638. * Return:
  639. * OLE error code
  640. */
  641. HRESULT
  642. STDMETHODCALLTYPE
  643. CFaxSecurityInformation::PropertySheetPageCallback(
  644. IN HWND hwnd,
  645. IN UINT uMsg,
  646. IN SI_PAGE_TYPE uPage
  647. )
  648. {
  649. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::PropertySheetPageCallback"));
  650. return S_OK;
  651. }
  652. /*
  653. - CFaxSecurityInformation::MakeSelfRelativeCopy
  654. -
  655. * Purpose:
  656. * This pravite method copies Security descriptors
  657. *
  658. * Arguments:
  659. *
  660. * Return:
  661. * OLE error code
  662. */
  663. HRESULT CFaxSecurityInformation::MakeSelfRelativeCopy(
  664. PSECURITY_DESCRIPTOR psdOriginal,
  665. PSECURITY_DESCRIPTOR* ppsdNew
  666. )
  667. {
  668. DEBUG_FUNCTION_NAME( _T("CFaxSecurityInformation::MakeSelfRelativeCopy"));
  669. ATLASSERT( NULL != psdOriginal );
  670. // we have to find out whether the original is already self-relative
  671. SECURITY_DESCRIPTOR_CONTROL sdc = 0;
  672. PSECURITY_DESCRIPTOR psdSelfRelativeCopy = NULL;
  673. DWORD dwRevision = 0;
  674. DWORD cb = 0;
  675. ATLASSERT( IsValidSecurityDescriptor( psdOriginal ) );
  676. if( !::GetSecurityDescriptorControl( psdOriginal, &sdc, &dwRevision ) )
  677. {
  678. DWORD err = ::GetLastError();
  679. DebugPrintEx( DEBUG_ERR,
  680. _T("Invalid security descriptor."));
  681. return HRESULT_FROM_WIN32( err );
  682. }
  683. if( sdc & SE_SELF_RELATIVE )
  684. {
  685. // the original is in self-relative format, just byte-copy it
  686. // get size
  687. cb = ::GetSecurityDescriptorLength( psdOriginal );
  688. // alloc the memory
  689. psdSelfRelativeCopy = (PSECURITY_DESCRIPTOR) ::LocalAlloc( LMEM_ZEROINIT, cb );
  690. if(NULL == psdSelfRelativeCopy)
  691. {
  692. DebugPrintEx(
  693. DEBUG_ERR,
  694. TEXT("Out of memory."));
  695. //GetRootNode()->NodeMsgBox(IDS_MEMORY);
  696. return E_OUTOFMEMORY;
  697. }
  698. // make the copy
  699. ::memcpy( psdSelfRelativeCopy, psdOriginal, cb );
  700. }
  701. else
  702. {
  703. // the original is in absolute format, convert-copy it
  704. // get new size - it will fail and set cb to the correct buffer size
  705. ::MakeSelfRelativeSD( psdOriginal, NULL, &cb );
  706. // alloc the new amount of memory
  707. psdSelfRelativeCopy = (PSECURITY_DESCRIPTOR) ::LocalAlloc( LMEM_ZEROINIT, cb );
  708. if(NULL == psdSelfRelativeCopy)
  709. {
  710. DebugPrintEx(
  711. DEBUG_ERR,
  712. TEXT("Out of memory."));
  713. //GetRootNode()->NodeMsgBox(IDS_MEMORY);
  714. return E_OUTOFMEMORY; // just in case the exception is ignored
  715. }
  716. if( !::MakeSelfRelativeSD( psdOriginal, psdSelfRelativeCopy, &cb ) )
  717. {
  718. DebugPrintEx(
  719. DEBUG_ERR,
  720. _T("::MakeSelfRelativeSD returned NULL"));
  721. if( NULL == ::LocalFree( psdSelfRelativeCopy ) )
  722. {
  723. DWORD err = ::GetLastError();
  724. return HRESULT_FROM_WIN32( err );
  725. }
  726. psdSelfRelativeCopy = NULL;
  727. }
  728. }
  729. *ppsdNew = psdSelfRelativeCopy;
  730. return S_OK;
  731. }