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.

163 lines
5.2 KiB

  1. /*****************************************************************************/
  2. /* Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved /
  3. /*****************************************************************************/
  4. //=================================================================
  5. //
  6. // ObjAccessRights.CPP -- Class for obtaining effective access
  7. // rights on an unspecified object for a particular
  8. // user or group.
  9. //
  10. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  11. //
  12. // Revisions: 6/29/99 a-kevhu Created
  13. //
  14. //=================================================================
  15. #include "precomp.h"
  16. #ifdef NTONLY
  17. #include <assertbreak.h>
  18. #include "AdvApi32Api.h"
  19. #include "accctrl.h"
  20. #include "sid.h"
  21. #include "AccessEntryList.h"
  22. #include "AccessRights.h"
  23. #include "ObjAccessRights.h"
  24. #include "ImpLogonUser.h"
  25. #include "aclapi.h"
  26. #include "DACL.h"
  27. // Default initialization...
  28. CObjAccessRights::CObjAccessRights(bool fUseCurThrTok /* = false */)
  29. : CAccessRights(fUseCurThrTok)
  30. {
  31. }
  32. CObjAccessRights::CObjAccessRights(LPCWSTR wstrObjName, SE_OBJECT_TYPE ObjectType, bool fUseCurThrTok /* = false */)
  33. : CAccessRights(fUseCurThrTok)
  34. {
  35. m_dwError = SetObj(wstrObjName, ObjectType);
  36. }
  37. CObjAccessRights::CObjAccessRights(const USER user, USER_SPECIFIER usp)
  38. : CAccessRights(user, usp)
  39. {
  40. }
  41. CObjAccessRights::CObjAccessRights(const USER user, LPCWSTR wstrObjName, SE_OBJECT_TYPE ObjectType, USER_SPECIFIER usp)
  42. : CAccessRights(user, usp)
  43. {
  44. m_dwError = SetObj(wstrObjName, ObjectType);
  45. }
  46. // Members clean up after themselves. Nothing to do here.
  47. CObjAccessRights::~CObjAccessRights()
  48. {
  49. }
  50. // Extracts the Obj's acl, and stores a copy of it.
  51. DWORD CObjAccessRights::SetObj(LPCWSTR wstrObjName, SE_OBJECT_TYPE ObjectType)
  52. {
  53. DWORD dwRet = E_FAIL;
  54. PACL pacl = NULL;
  55. PSECURITY_DESCRIPTOR psd = NULL;
  56. CAdvApi32Api *pAdvApi32 = NULL;
  57. if(wcslen(wstrObjName) != 0)
  58. {
  59. pAdvApi32 = (CAdvApi32Api*) CResourceManager::sm_TheResourceManager.GetResource(g_guidAdvApi32Api, NULL);
  60. if(pAdvApi32 == NULL) return E_FAIL;
  61. CRelResource RelMe(&CResourceManager::sm_TheResourceManager,g_guidAdvApi32Api,pAdvApi32 );
  62. if(pAdvApi32->GetNamedSecurityInfoW(_bstr_t(wstrObjName),
  63. ObjectType,
  64. DACL_SECURITY_INFORMATION,
  65. NULL,
  66. NULL,
  67. &pacl,
  68. NULL,
  69. &psd,
  70. &dwRet))
  71. {
  72. if(dwRet == ERROR_SUCCESS && psd != NULL)
  73. {
  74. OnDelete<HLOCAL,HLOCAL(*)(HLOCAL),LocalFree> FreeMeSD(psd);
  75. if(pacl != NULL) // might be null in the case of a null dacl!
  76. {
  77. if(!SetAcl(pacl))
  78. {
  79. dwRet = ERROR_INVALID_PARAMETER;
  80. }
  81. else
  82. {
  83. m_chstrObjName = wstrObjName;
  84. }
  85. }
  86. else
  87. {
  88. // We have a security descriptor, we returned ERROR_SUCCESS from GetNamedSecurityInfo, so this
  89. // means we have a null dacl. In this case, we will create a NULL dacl using our security classes -
  90. // more overhead, but will happen relatively infrequently.
  91. CDACL newnulldacl;
  92. if(newnulldacl.CreateNullDACL())
  93. {
  94. if((dwRet = newnulldacl.ConfigureDACL(pacl)) == ERROR_SUCCESS)
  95. {
  96. if(pacl != NULL) // might be null in the case of a null dacl!
  97. {
  98. OnDelete<void *,void(__cdecl *)(void *),free> FreeMeACL(pacl);
  99. if(!SetAcl(pacl))
  100. {
  101. dwRet = ERROR_INVALID_PARAMETER;
  102. }
  103. else
  104. {
  105. m_chstrObjName = wstrObjName;
  106. }
  107. // Since the memory we used for pacl, in this case, is not part of psd, and therefor
  108. // won't be freed via the call to LocalFree(psd), we free it here.
  109. pacl = NULL;
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }
  116. }
  117. return dwRet;
  118. }
  119. #endif