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.

330 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. FixUp.c
  5. Abstract:
  6. This module contains common security routines for
  7. NT Clusters rolling upgrade and backward compatibility.
  8. Author:
  9. Galen Barbee (galenb) 31-Mar-1998
  10. --*/
  11. #include "clusrtlp.h"
  12. PSECURITY_DESCRIPTOR
  13. ClRtlConvertClusterSDToNT4Format(
  14. IN PSECURITY_DESCRIPTOR psd
  15. )
  16. /*++
  17. Routine Description:
  18. Convert the SD from nt 5 to nt 4 format. This means enforcing the
  19. following rules:
  20. 1. Convert denied ACE to allowed ACE. Convert "Full Control" access
  21. mask to CLUAPI_NO_ACCESS.
  22. Arguments:
  23. psd [IN] Security descriptor.
  24. Return Value:
  25. The new SD in self-Relative format
  26. --*/
  27. {
  28. PACL pacl;
  29. BOOL bHasDACL;
  30. BOOL bDACLDefaulted;
  31. PSECURITY_DESCRIPTOR psec = NULL;
  32. if (NULL == psd) {
  33. return NULL;
  34. }
  35. psec = ClRtlCopySecurityDescriptor(psd);
  36. ASSERT(psec != NULL);
  37. if ( (GetSecurityDescriptorDacl(psec, (LPBOOL) &bHasDACL, (PACL *) &pacl, (LPBOOL) &bDACLDefaulted)) &&
  38. ( bHasDACL != FALSE ) ) {
  39. ACL_SIZE_INFORMATION asiAclSize;
  40. DWORD dwBufLength;
  41. dwBufLength = sizeof(asiAclSize);
  42. if (GetAclInformation(pacl, &asiAclSize, dwBufLength, AclSizeInformation)) {
  43. ACCESS_DENIED_ACE * pAce;
  44. DWORD dwIndex;
  45. for (dwIndex = 0; dwIndex < asiAclSize.AceCount; dwIndex++) {
  46. if (GetAce(pacl, dwIndex, (LPVOID *) &pAce)) {
  47. if (pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE) {
  48. if (pAce->Mask & SPECIFIC_RIGHTS_ALL) {
  49. pAce->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
  50. pAce->Mask = CLUSAPI_NO_ACCESS;
  51. }
  52. } // end if (pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE)
  53. } // end if (GetAce())
  54. } // end for
  55. } // end if (GetAclInformation())
  56. } // end if (HrGetSecurityDescriptorDacl()) and DACL is present
  57. ASSERT(IsValidSecurityDescriptor(psec));
  58. return psec;
  59. } //*** ClRtlConvertClusterSDToNT4Format()
  60. PSECURITY_DESCRIPTOR
  61. ClRtlConvertClusterSDToNT5Format(
  62. IN PSECURITY_DESCRIPTOR psd
  63. )
  64. /*++
  65. Routine Description:
  66. Convert the SD from nt 5 to nt 4 format. This means enforcing the
  67. following rules:
  68. 1. Convert allowed ACE with mask CLUAPI_NO_ACCESS to denied ACE mask full control.
  69. Arguments:
  70. psd [IN] Security descriptor.
  71. Return Value:
  72. The new SD in self-Relative format
  73. --*/
  74. {
  75. PACL pacl;
  76. BOOL bHasDACL;
  77. BOOL bDACLDefaulted;
  78. PSECURITY_DESCRIPTOR psec = NULL;
  79. if (NULL == psd) {
  80. return NULL;
  81. }
  82. psec = ClRtlCopySecurityDescriptor(psd);
  83. ASSERT(psec != NULL);
  84. if ( (GetSecurityDescriptorDacl(psec, (LPBOOL) &bHasDACL, (PACL *) &pacl, (LPBOOL) &bDACLDefaulted)) &&
  85. ( bHasDACL != FALSE ) ) {
  86. ACL_SIZE_INFORMATION asiAclSize;
  87. DWORD dwBufLength;
  88. dwBufLength = sizeof(asiAclSize);
  89. if (GetAclInformation(pacl, &asiAclSize, dwBufLength, AclSizeInformation)) {
  90. ACCESS_DENIED_ACE * pAce;
  91. DWORD dwIndex;
  92. for (dwIndex = 0; dwIndex < asiAclSize.AceCount; dwIndex++) {
  93. if (GetAce(pacl, dwIndex, (LPVOID *) &pAce)) {
  94. if (pAce->Header.AceType == ACCESS_ALLOWED_ACE_TYPE) {
  95. if (pAce->Mask & CLUSAPI_NO_ACCESS) {
  96. pAce->Header.AceType = ACCESS_DENIED_ACE_TYPE;
  97. pAce->Mask = SPECIFIC_RIGHTS_ALL;
  98. }
  99. } // end if (pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE)
  100. } // end if (GetAce())
  101. } // end for
  102. } // end if (GetAclInformation())
  103. } // end if (HrGetSecurityDescriptorDacl()) and DACL is present
  104. ASSERT(IsValidSecurityDescriptor(psec));
  105. return psec;
  106. } //*** ClRtlConvertClusterSDToNT5Format()
  107. static GENERIC_MAPPING gmFileShareMap =
  108. {
  109. FILE_GENERIC_READ,
  110. FILE_GENERIC_WRITE,
  111. FILE_GENERIC_EXECUTE,
  112. FILE_ALL_ACCESS
  113. };
  114. #define SPECIFIC_CHANGE (DELETE | FILE_GENERIC_WRITE)
  115. #define SPECIFIC_READ (FILE_GENERIC_READ | FILE_LIST_DIRECTORY | FILE_EXECUTE)
  116. #define GENERIC_CHANGE (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | DELETE)
  117. PSECURITY_DESCRIPTOR
  118. ClRtlConvertFileShareSDToNT4Format(
  119. IN PSECURITY_DESCRIPTOR psd
  120. )
  121. /*++
  122. Routine Description:
  123. Convert the SD from nt 5 to nt 4 format. This means enforcing the
  124. following rules:
  125. Arguments:
  126. psd [IN] Security descriptor.
  127. Return Value:
  128. The new SD in self-Relative format
  129. --*/
  130. {
  131. PACL pacl;
  132. BOOL bHasDACL;
  133. BOOL bDACLDefaulted;
  134. PSECURITY_DESCRIPTOR psec = NULL;
  135. if (NULL == psd) {
  136. return NULL;
  137. }
  138. psec = ClRtlCopySecurityDescriptor(psd);
  139. ASSERT(psec != NULL);
  140. if ( (GetSecurityDescriptorDacl(psec, (LPBOOL) &bHasDACL, (PACL *) &pacl, (LPBOOL) &bDACLDefaulted)) &&
  141. ( bHasDACL != FALSE ) ) {
  142. ACL_SIZE_INFORMATION asiAclSize;
  143. DWORD dwBufLength;
  144. ACCESS_MASK amTemp1;
  145. ACCESS_MASK amTemp2;
  146. dwBufLength = sizeof(asiAclSize);
  147. if (GetAclInformation(pacl, &asiAclSize, dwBufLength, AclSizeInformation)) {
  148. ACCESS_DENIED_ACE * pAce;
  149. DWORD dwSid;
  150. DWORD dwIndex;
  151. for (dwIndex = 0; dwIndex < asiAclSize.AceCount; dwIndex++) {
  152. amTemp1 = 0;
  153. amTemp2 = 0;
  154. if (GetAce(pacl, dwIndex, (LPVOID *) &pAce)) {
  155. // delete deny read ACEs since they don't mean anything to AclEdit
  156. if ((pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE) &&
  157. (pAce->Mask == SPECIFIC_READ)) {
  158. dwSid = pAce->SidStart;
  159. if (DeleteAce(pacl, dwIndex)) {
  160. asiAclSize.AceCount -= 1;
  161. dwIndex -= 1;
  162. }
  163. else {
  164. ClRtlDbgPrint(LOG_UNUSUAL,
  165. "[ClRtl] DeteteAce failed removing ACE #%1!d! due to error %2!d!\n",
  166. dwIndex,
  167. GetLastError());
  168. }
  169. continue;
  170. }
  171. // convert deny change deny read ACEs to deny all ACEs
  172. if ((pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE) &&
  173. (pAce->Mask == (SPECIFIC_CHANGE | SPECIFIC_READ))) {
  174. pAce->Mask = GENERIC_ALL;
  175. continue;
  176. }
  177. // convert deny change ACEs to allow read (read only) ACEs
  178. if ((pAce->Header.AceType == ACCESS_DENIED_ACE_TYPE) &&
  179. (pAce->Mask == SPECIFIC_CHANGE)) {
  180. pAce->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
  181. pAce->Mask = GENERIC_READ | GENERIC_EXECUTE;
  182. continue;
  183. }
  184. // convert specific allow change to generic allow change
  185. if ((pAce->Header.AceType == ACCESS_ALLOWED_ACE_TYPE) &&
  186. (pAce->Mask == SPECIFIC_CHANGE)) {
  187. pAce->Mask = GENERIC_CHANGE;
  188. continue;
  189. }
  190. // convert specific all to generic all
  191. if ((pAce->Mask & gmFileShareMap.GenericAll) == gmFileShareMap.GenericAll) {
  192. amTemp1 |= GENERIC_ALL;
  193. amTemp2 |= gmFileShareMap.GenericAll;
  194. }
  195. else {
  196. // convert specific read to generic read
  197. if ((pAce->Mask & gmFileShareMap.GenericRead) == gmFileShareMap.GenericRead) {
  198. amTemp1 |= GENERIC_READ;
  199. amTemp2 |= gmFileShareMap.GenericRead;
  200. }
  201. // convert specific write to generic write which includes delete
  202. if ((pAce->Mask & gmFileShareMap.GenericWrite) == gmFileShareMap.GenericWrite) {
  203. amTemp1 |= (GENERIC_WRITE | DELETE);
  204. amTemp2 |= gmFileShareMap.GenericWrite;
  205. }
  206. // convert specific execute to generic execute
  207. if ((pAce->Mask & gmFileShareMap.GenericExecute) == gmFileShareMap.GenericExecute) {
  208. amTemp1 |= GENERIC_EXECUTE;
  209. amTemp2 |= gmFileShareMap.GenericExecute;
  210. }
  211. }
  212. pAce->Mask &= ~amTemp2; // turn off specific bits
  213. pAce->Mask |= amTemp1; // turn on generic bits
  214. } // end if (GetAce())
  215. } // end for
  216. } // end if (GetAclInformation())
  217. } // end if (HrGetSecurityDescriptorDacl()) and DACL is present
  218. ASSERT(IsValidSecurityDescriptor(psec));
  219. return psec;
  220. } //*** ClRtlConvertFileShareSDToNT4Format()