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.

218 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtdeltre.c
  5. Abstract:
  6. NT level registry api test program #4, basic non-error paths.
  7. Sub-tree delete for the registry.
  8. rtdeltre <KeyPath>
  9. Will ennumerate and delete the subkeys and values of KeyPath,
  10. and each of their subkeys, and so on.
  11. Example:
  12. rtdeltre \REGISTRY\MACHINE\TEST\bigkey
  13. Author:
  14. Bryan Willman (bryanwi) 10-Dec-91
  15. Revision History:
  16. --*/
  17. #include "cmp.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #define WORK_SIZE 1024
  22. void __cdecl main(int argc, char *);
  23. void processargs();
  24. void print(PUNICODE_STRING);
  25. void
  26. Delete(
  27. HANDLE Handle
  28. );
  29. UNICODE_STRING WorkName;
  30. WCHAR workbuffer[WORK_SIZE];
  31. void
  32. __cdecl main(
  33. int argc,
  34. char *argv[]
  35. )
  36. {
  37. NTSTATUS status;
  38. OBJECT_ATTRIBUTES ObjectAttributes;
  39. HANDLE BaseHandle;
  40. //
  41. // Process args
  42. //
  43. WorkName.MaximumLength = WORK_SIZE;
  44. WorkName.Length = 0L;
  45. WorkName.Buffer = &(workbuffer[0]);
  46. processargs(argc, argv);
  47. //
  48. // Set up and open KeyPath
  49. //
  50. printf("regtest3: starting\n");
  51. InitializeObjectAttributes(
  52. &ObjectAttributes,
  53. &WorkName,
  54. 0,
  55. (HANDLE)NULL,
  56. NULL
  57. );
  58. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  59. status = NtOpenKey(
  60. &BaseHandle,
  61. DELETE | KEY_ENUMERATE_SUB_KEYS,
  62. &ObjectAttributes
  63. );
  64. if (!NT_SUCCESS(status)) {
  65. printf("regtest3: t0: %08lx\n", status);
  66. exit(1);
  67. }
  68. Delete(BaseHandle);
  69. }
  70. void
  71. Delete(
  72. HANDLE Handle
  73. )
  74. {
  75. NTSTATUS status;
  76. PKEY_BASIC_INFORMATION KeyInformation;
  77. OBJECT_ATTRIBUTES ObjectAttributes;
  78. ULONG NamePos;
  79. ULONG index;
  80. STRING enumname;
  81. HANDLE WorkHandle;
  82. ULONG ResultLength;
  83. static char buffer[WORK_SIZE];
  84. KeyInformation = (PKEY_BASIC_INFORMATION)buffer;
  85. NamePos = WorkName.Length;
  86. //
  87. // Enumerate node's children and apply ourselves to each one
  88. //
  89. index = 0;
  90. do {
  91. RtlZeroMemory(KeyInformation, WORK_SIZE);
  92. status = NtEnumerateKey(
  93. Handle,
  94. index,
  95. KeyBasicInformation,
  96. KeyInformation,
  97. WORK_SIZE,
  98. &ResultLength
  99. );
  100. if (status == STATUS_NO_MORE_ENTRIES) {
  101. WorkName.Length = NamePos;
  102. break;
  103. } else if (!NT_SUCCESS(status)) {
  104. printf("regtest3: dump1: status = %08lx\n", status);
  105. exit(1);
  106. }
  107. enumname.Buffer = &(KeyInformation->Name[0]);
  108. enumname.Length = KeyInformation->NameLength;
  109. enumname.MaximumLength = KeyInformation->NameLength;
  110. RtlAppendStringToString((PSTRING)&WorkName, (PSTRING)&enumname);
  111. InitializeObjectAttributes(
  112. &ObjectAttributes,
  113. &enumname,
  114. OBJ_CASE_INSENSITIVE,
  115. Handle,
  116. NULL
  117. );
  118. status = NtOpenKey(
  119. &WorkHandle,
  120. DELETE | KEY_ENUMERATE_SUB_KEYS,
  121. &ObjectAttributes
  122. );
  123. if (!NT_SUCCESS(status)) {
  124. printf("regtest3: couldn't delete %wZ: %08lx\n", &enumname,status);
  125. index++;
  126. } else {
  127. Delete(WorkHandle);
  128. NtClose(WorkHandle);
  129. }
  130. WorkName.Length = NamePos;
  131. } while (TRUE);
  132. //
  133. // If we're here, then we have delt with all children, so deal with
  134. // the node we were applied to
  135. //
  136. NtDeleteKey(Handle);
  137. NtClose(Handle); // Force it to actually go away
  138. return;
  139. }
  140. void
  141. processargs(
  142. int argc,
  143. char *argv[]
  144. )
  145. {
  146. ANSI_STRING temp;
  147. if ( (argc != 2) )
  148. {
  149. printf("Usage: %s <KeyPath>\n",
  150. argv[0]);
  151. exit(1);
  152. }
  153. RtlInitAnsiString(
  154. &temp,
  155. argv[1]
  156. );
  157. RtlAnsiStringToUnicodeString(
  158. &WorkName,
  159. &temp,
  160. TRUE
  161. );
  162. return;
  163. }