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.

103 lines
2.6 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <ntseapi.h>
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. int _cdecl
  9. main(int argc, char * argv[])
  10. {
  11. NTSTATUS status;
  12. OBJECT_ATTRIBUTES objectAttributes;
  13. WCHAR unicodeName[MAX_PATH];
  14. UCHAR SecurityDescriptorBuffer[512];
  15. UNICODE_STRING nameString;
  16. IO_STATUS_BLOCK ioStatusBlock;
  17. ULONG lengthNeeded;
  18. HANDLE fileHandle;
  19. if (argc < 2) {
  20. printf("usage: %s file\n", argv[0]);
  21. return -1;
  22. }
  23. mbstowcs(unicodeName, argv[1], strlen(argv[1]) + 1);
  24. RtlDosPathNameToNtPathName_U(
  25. unicodeName,
  26. &nameString,
  27. NULL,
  28. NULL);
  29. InitializeObjectAttributes(
  30. &objectAttributes,
  31. &nameString,
  32. OBJ_CASE_INSENSITIVE,
  33. NULL,
  34. NULL);
  35. status = NtOpenFile(
  36. &fileHandle,
  37. READ_CONTROL | WRITE_DAC,
  38. &objectAttributes,
  39. &ioStatusBlock,
  40. FILE_SHARE_READ | FILE_SHARE_WRITE,
  41. 0);
  42. if (!NT_SUCCESS(status) || !NT_SUCCESS(ioStatusBlock.Status)) {
  43. printf("%s: NtOpenFile on %wZ failed %lx %lx\n", argv[0], &nameString, status, ioStatusBlock.Status);
  44. return -1;
  45. }
  46. //
  47. // Now read the DACL from the server file.
  48. //
  49. status = NtQuerySecurityObject(
  50. fileHandle,
  51. DACL_SECURITY_INFORMATION,
  52. (PSECURITY_DESCRIPTOR)SecurityDescriptorBuffer,
  53. sizeof(SecurityDescriptorBuffer),
  54. &lengthNeeded);
  55. if (!NT_SUCCESS(status)) {
  56. printf("%s: NtQuerySecurityObject on %wZ failed %lx %lx\n", argv[0], &nameString, status, lengthNeeded);
  57. return -1;
  58. }
  59. #if 0
  60. status = RtlSetDaclSecurityDescriptor(
  61. (PSECURITY_DESCRIPTOR)SecurityDescriptorBuffer,
  62. FALSE,
  63. NULL,
  64. FALSE);
  65. if (!NT_SUCCESS(status)) {
  66. printf("%s: RtlSetDaclSecurityDescriptor on %wZ failed %lx\n", argv[0], &nameString, status);
  67. return -1;
  68. }
  69. #else
  70. ((PISECURITY_DESCRIPTOR)SecurityDescriptorBuffer)->Control &= ~SE_DACL_PRESENT;
  71. #endif
  72. status = NtSetSecurityObject(
  73. fileHandle,
  74. DACL_SECURITY_INFORMATION,
  75. (PSECURITY_DESCRIPTOR)SecurityDescriptorBuffer);
  76. if (!NT_SUCCESS(status)) {
  77. printf("%s: NtSetSecurityObject on %wZ failed %lx %lx\n", argv[0], &nameString, status);
  78. return -1;
  79. }
  80. printf("%s: DACL successfully cleared on %wZ\n", argv[0], &nameString);
  81. return 0;
  82. }