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.

307 lines
9.4 KiB

  1. //////////////////////////////////////////////////////////////////////////
  2. // WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING //
  3. // //
  4. // This test file is not current with the security implementation. //
  5. // This file contains references to data types and APIs that do not //
  6. // exist. //
  7. // //
  8. //////////////////////////////////////////////////////////////////////////
  9. /*++
  10. Copyright (c) 1989 Microsoft Corporation
  11. Module Name:
  12. tacl.c
  13. Abstract:
  14. Test program for the acl editing package
  15. Author:
  16. Gary Kimura [GaryKi] 19-Nov-1989
  17. Revision History:
  18. v4: robertre
  19. updated ACL_REVISION
  20. RichardW - updated ACE_HEADER
  21. --*/
  22. #include <stdio.h>
  23. #include "nt.h"
  24. #include "ntrtl.h"
  25. VOID
  26. RtlDumpAcl(
  27. IN PACL Acl
  28. );
  29. UCHAR FredAclBuffer[128];
  30. UCHAR WilmaAclBuffer[128];
  31. UCHAR PebbleAclBuffer[128];
  32. UCHAR DinoAclBuffer[128];
  33. UCHAR BarneyAclBuffer[128];
  34. UCHAR BettyAclBuffer[128];
  35. UCHAR BambamAclBuffer[128];
  36. UCHAR GuidMaskBuffer[512];
  37. STANDARD_ACE AceListBuffer[2];
  38. int
  39. main(
  40. int argc,
  41. char *argv[]
  42. )
  43. {
  44. PACL FredAcl = (PACL)FredAclBuffer;
  45. PACL WilmaAcl = (PACL)WilmaAclBuffer;
  46. PACL PebbleAcl = (PACL)PebbleAclBuffer;
  47. PACL DinoAcl = (PACL)DinoAclBuffer;
  48. PACL BarneyAcl = (PACL)BarneyAclBuffer;
  49. PACL BettyAcl = (PACL)BettyAclBuffer;
  50. PACL BambamAcl = (PACL)BambamAclBuffer;
  51. PMASK_GUID_PAIRS GuidMasks = (PMASK_GUID_PAIRS)GuidMaskBuffer;
  52. ACL_REVISION_INFORMATION AclRevisionInfo;
  53. ACL_SIZE_INFORMATION AclSizeInfo;
  54. //
  55. // We're starting the test
  56. //
  57. DbgPrint("Start Acl Test\n");
  58. //
  59. // test create acl
  60. //
  61. if (!NT_SUCCESS(RtlCreateAcl(FredAcl, 128, 1))) {
  62. DbgPrint("RtlCreateAcl Error\n");
  63. }
  64. RtlDumpAcl(FredAcl);
  65. DbgPrint("\n");
  66. //
  67. // test add ace to add two aces to an empty acl
  68. //
  69. AceListBuffer[0].Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
  70. AceListBuffer[0].Header.AceSize = sizeof(STANDARD_ACE);
  71. AceListBuffer[0].Header.AceFlags = 0;
  72. AceListBuffer[0].Mask = 0x22222222;
  73. CopyGuid(&AceListBuffer[0].Guid, &FredGuid);
  74. AceListBuffer[1].Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
  75. AceListBuffer[1].Header.AceSize = sizeof(STANDARD_ACE);
  76. AceListBuffer[1].Header.AceFlags = 0;
  77. AceListBuffer[1].Mask = 0x44444444;
  78. CopyGuid(&AceListBuffer[1].Guid, &WilmaGuid);
  79. if (!NT_SUCCESS(RtlAddAce(FredAcl, 1, 0, AceListBuffer, 2*sizeof(STANDARD_ACE)))) {
  80. DbgPrint("RtlAddAce Error\n");
  81. }
  82. RtlDumpAcl(FredAcl);
  83. DbgPrint("\n");
  84. //
  85. // test add ace to add one to the beginning of an acl
  86. //
  87. AceListBuffer[0].Header.AceType = SYSTEM_AUDIT_ACE_TYPE;
  88. AceListBuffer[0].Header.AceSize = sizeof(STANDARD_ACE);
  89. AceListBuffer[0].Header.AceFlags = 0;
  90. AceListBuffer[0].Mask = 0x11111111;
  91. CopyGuid(&AceListBuffer[0].Guid, &PebbleGuid);
  92. if (!NT_SUCCESS(RtlAddAce(FredAcl, 1, 0, AceListBuffer, sizeof(STANDARD_ACE)))) {
  93. DbgPrint("RtlAddAce Error\n");
  94. }
  95. RtlDumpAcl(FredAcl);
  96. DbgPrint("\n");
  97. //
  98. // test add ace to add one to the middle of an acl
  99. //
  100. AceListBuffer[0].Header.AceType = ACCESS_DENIED_ACE_TYPE;
  101. AceListBuffer[0].Header.AceSize = sizeof(STANDARD_ACE);
  102. AceListBuffer[0].Header.AceFlags = 0;
  103. AceListBuffer[0].Mask = 0x33333333;
  104. CopyGuid(&AceListBuffer[0].Guid, &DinoGuid);
  105. if (!NT_SUCCESS(RtlAddAce(FredAcl, 1, 2, AceListBuffer, sizeof(STANDARD_ACE)))) {
  106. DbgPrint("RtlAddAce Error\n");
  107. }
  108. RtlDumpAcl(FredAcl);
  109. DbgPrint("\n");
  110. //
  111. // test add ace to add one to the end of an acl
  112. //
  113. AceListBuffer[0].Header.AceType = ACCESS_DENIED_ACE_TYPE;
  114. AceListBuffer[0].Header.AceSize = sizeof(STANDARD_ACE);
  115. AceListBuffer[0].Header.AceFlags = 0;
  116. AceListBuffer[0].Mask = 0x55555555;
  117. CopyGuid(&AceListBuffer[0].Guid, &FlintstoneGuid);
  118. if (!NT_SUCCESS(RtlAddAce(FredAcl, 1, MAXULONG, AceListBuffer, sizeof(STANDARD_ACE)))) {
  119. DbgPrint("RtlAddAce Error\n");
  120. }
  121. RtlDumpAcl(FredAcl);
  122. DbgPrint("\n");
  123. //
  124. // Test get ace
  125. //
  126. {
  127. PSTANDARD_ACE Ace;
  128. if (!NT_SUCCESS(RtlGetAce(FredAcl, 2, (PVOID *)(&Ace)))) {
  129. DbgPrint("RtlGetAce Error\n");
  130. }
  131. if ((Ace->Header.AceType != ACCESS_DENIED_ACE_TYPE) ||
  132. (Ace->Mask != 0x33333333)) {
  133. DbgPrint("Got bad ace from RtlGetAce\n");
  134. }
  135. }
  136. //
  137. // test delete ace middle ace
  138. //
  139. if (!NT_SUCCESS(RtlDeleteAce(FredAcl, 2))) {
  140. DbgPrint("RtlDeleteAce Error\n");
  141. }
  142. RtlDumpAcl(FredAcl);
  143. DbgPrint("\n");
  144. //
  145. // Test query information acl
  146. //
  147. if (!NT_SUCCESS(RtlQueryInformationAcl( FredAcl,
  148. (PVOID)&AclRevisionInfo,
  149. sizeof(ACL_REVISION_INFORMATION),
  150. AclRevisionInformation))) {
  151. DbgPrint("RtlQueryInformationAcl Error\n");
  152. }
  153. if (AclRevisionInfo.AclRevision != ACL_REVISION) {
  154. DbgPrint("RtlAclRevision Error\n");
  155. }
  156. if (!NT_SUCCESS(RtlQueryInformationAcl( FredAcl,
  157. (PVOID)&AclSizeInfo,
  158. sizeof(ACL_SIZE_INFORMATION),
  159. AclSizeInformation))) {
  160. DbgPrint("RtlQueryInformationAcl Error\n");
  161. }
  162. if ((AclSizeInfo.AceCount != 4) ||
  163. (AclSizeInfo.AclBytesInUse != (sizeof(ACL)+4*sizeof(STANDARD_ACE))) ||
  164. (AclSizeInfo.AclBytesFree != 128 - AclSizeInfo.AclBytesInUse)) {
  165. DbgPrint("RtlAclSize Error\n");
  166. DbgPrint("AclSizeInfo.AceCount = %8lx\n", AclSizeInfo.AceCount);
  167. DbgPrint("AclSizeInfo.AclBytesInUse = %8lx\n", AclSizeInfo.AclBytesInUse);
  168. DbgPrint("AclSizeInfo.AclBytesFree = %8lx\n", AclSizeInfo.AclBytesFree);
  169. DbgPrint("\n");
  170. }
  171. //
  172. // Test make Mask from Acl
  173. //
  174. GuidMasks->PairCount = 11;
  175. CopyGuid(&GuidMasks->MaskGuid[ 0].Guid, &FredGuid);
  176. CopyGuid(&GuidMasks->MaskGuid[ 1].Guid, &WilmaGuid);
  177. CopyGuid(&GuidMasks->MaskGuid[ 2].Guid, &PebbleGuid);
  178. CopyGuid(&GuidMasks->MaskGuid[ 3].Guid, &DinoGuid);
  179. CopyGuid(&GuidMasks->MaskGuid[ 4].Guid, &BarneyGuid);
  180. CopyGuid(&GuidMasks->MaskGuid[ 5].Guid, &BettyGuid);
  181. CopyGuid(&GuidMasks->MaskGuid[ 6].Guid, &BambamGuid);
  182. CopyGuid(&GuidMasks->MaskGuid[ 7].Guid, &FlintstoneGuid);
  183. CopyGuid(&GuidMasks->MaskGuid[ 8].Guid, &RubbleGuid);
  184. CopyGuid(&GuidMasks->MaskGuid[ 9].Guid, &AdultGuid);
  185. CopyGuid(&GuidMasks->MaskGuid[10].Guid, &ChildGuid);
  186. if (!NT_SUCCESS(RtlMakeMaskFromAcl(FredAcl, GuidMasks))) {
  187. DbgPrint("RtlMakeMaskFromAcl Error\n");
  188. }
  189. if ((GuidMasks->MaskGuid[ 0].Mask != 0x22222222) ||
  190. (GuidMasks->MaskGuid[ 1].Mask != 0x44444444) ||
  191. (GuidMasks->MaskGuid[ 2].Mask != 0x00000000) ||
  192. (GuidMasks->MaskGuid[ 3].Mask != 0x00000000) ||
  193. (GuidMasks->MaskGuid[ 4].Mask != 0x00000000) ||
  194. (GuidMasks->MaskGuid[ 5].Mask != 0x00000000) ||
  195. (GuidMasks->MaskGuid[ 6].Mask != 0x00000000) ||
  196. (GuidMasks->MaskGuid[ 7].Mask != 0x00000000) ||
  197. (GuidMasks->MaskGuid[ 8].Mask != 0x00000000) ||
  198. (GuidMasks->MaskGuid[ 9].Mask != 0x00000000) ||
  199. (GuidMasks->MaskGuid[10].Mask != 0x00000000)) {
  200. DbgPrint("Make Mask Error\n");
  201. DbgPrint("Fred gets %8lx\n", GuidMasks->MaskGuid[ 0].Mask);
  202. DbgPrint("Wilma gets %8lx\n", GuidMasks->MaskGuid[ 1].Mask);
  203. DbgPrint("Pebble gets %8lx\n", GuidMasks->MaskGuid[ 2].Mask);
  204. DbgPrint("Dino gets %8lx\n", GuidMasks->MaskGuid[ 3].Mask);
  205. DbgPrint("Barney gets %8lx\n", GuidMasks->MaskGuid[ 4].Mask);
  206. DbgPrint("Betty gets %8lx\n", GuidMasks->MaskGuid[ 5].Mask);
  207. DbgPrint("Banbam gets %8lx\n", GuidMasks->MaskGuid[ 6].Mask);
  208. DbgPrint("Flintstone gets %8lx\n", GuidMasks->MaskGuid[ 7].Mask);
  209. DbgPrint("Rubble gets %8lx\n", GuidMasks->MaskGuid[ 8].Mask);
  210. DbgPrint("Adult gets %8lx\n", GuidMasks->MaskGuid[ 9].Mask);
  211. DbgPrint("Child gets %8lx\n", GuidMasks->MaskGuid[10].Mask);
  212. }
  213. //
  214. // test make acl from mask
  215. //
  216. GuidMasks->PairCount = 2;
  217. GuidMasks->MaskGuid[0].Mask = 0x55555555;
  218. CopyGuid(&GuidMasks->MaskGuid[0].Guid, &BarneyGuid);
  219. GuidMasks->MaskGuid[1].Mask = 0xaaaa5555;
  220. CopyGuid(&GuidMasks->MaskGuid[1].Guid, &RubbleGuid);
  221. //
  222. // Initialize and dump a posix style acl
  223. //
  224. if (!NT_SUCCESS(RtlMakeAclFromMask(GuidMasks, AclPosixEnvironment, BarneyAcl, 128, 1))) {
  225. DbgPrint("RtlMakeAclFromMask Error\n");
  226. }
  227. RtlDumpAcl(BarneyAcl);
  228. DbgPrint("\n");
  229. //
  230. // Initialize and dump a OS/2 style acl
  231. //
  232. if (!NT_SUCCESS(RtlMakeAclFromMask(GuidMasks, AclOs2Environment, BettyAcl, 128, 1))) {
  233. DbgPrint("RtlMakeAclFromMask Error\n");
  234. }
  235. RtlDumpAcl(BettyAcl);
  236. DbgPrint("\n");
  237. //
  238. // We're done with the test
  239. //
  240. DbgPrint("End Acl Test\n");
  241. return TRUE;
  242. }
  243.