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.

263 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtvbatcr.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Do a batch create, VOLATILE. (Same as rtbatcr, but creates keys volatile.)
  8. rtvbatcr <KeyPath> <KeyName> <basename> <#children> <#values>
  9. Will attempt to create key <KeyName> as child of <KeyPath> If
  10. <#children> and <#values> are 0, this is all it does. If <KeyName>
  11. already exists, it will simply be used.
  12. Will create <#children> child cells, with names of the form
  13. <base>0 <base>1, etc. Will create <#values> value entries,
  14. with similar names, for each created child key. Data of
  15. values will be a constant string including their name.
  16. Example:
  17. rtvbatcr \REGISTRY\MACHINE\TEST bigkey runa_ 100 100
  18. rtvbatcr \REGISTRY\MACHINE\TEST\bigkey runa_1 runb_ 100 100
  19. Will create bigkey, give it 100 values calls runa_1 through
  20. runa_100, create 100 subkeys called runa_1 through runa_100
  21. for each of those children.
  22. It will then open bigkey\runa_1, and create 100 subkeys and
  23. 100 values each for that.
  24. Author:
  25. Bryan Willman (bryanwi) 10-Dec-91
  26. Revision History:
  27. --*/
  28. #include "cmp.h"
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #define WORK_SIZE 1024
  33. void __cdecl main(int, char *);
  34. void processargs();
  35. ULONG failure = 0;
  36. UNICODE_STRING KeyPath;
  37. UNICODE_STRING KeyName;
  38. ULONG NumberChildren;
  39. ULONG NumberValues;
  40. UCHAR BaseName[WORK_SIZE];
  41. UCHAR formatbuffer[WORK_SIZE];
  42. STRING format;
  43. UNICODE_STRING WorkName;
  44. WCHAR workbuffer[WORK_SIZE];
  45. void
  46. __cdecl main(
  47. int argc,
  48. char *argv[]
  49. )
  50. {
  51. NTSTATUS status;
  52. OBJECT_ATTRIBUTES ObjectAttributes;
  53. HANDLE BaseHandle;
  54. HANDLE WorkHandle;
  55. ULONG Disposition;
  56. UNICODE_STRING ClassName;
  57. ULONG i;
  58. ULONG j;
  59. PUCHAR p;
  60. //
  61. // Process args
  62. //
  63. processargs(argc, argv);
  64. //
  65. // Set up and create/open KeyPath|KeyName
  66. //
  67. printf("rtvbatcr: starting\n");
  68. WorkName.MaximumLength = WORK_SIZE;
  69. WorkName.Length = 0L;
  70. WorkName.Buffer = &(workbuffer[0]);
  71. RtlCopyString((PSTRING)&WorkName, (PSTRING)&KeyPath);
  72. p = WorkName.Buffer;
  73. p += WorkName.Length;
  74. *p = '\\';
  75. p++;
  76. *p = '\0';
  77. WorkName.Length += 2;
  78. RtlAppendStringToString((PSTRING)&WorkName, (PSTRING)&KeyName);
  79. RtlInitUnicodeString(
  80. &ClassName,
  81. L"Test Class Name"
  82. );
  83. InitializeObjectAttributes(
  84. &ObjectAttributes,
  85. &WorkName,
  86. 0,
  87. (HANDLE)NULL,
  88. NULL
  89. );
  90. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  91. status = NtCreateKey(
  92. &BaseHandle,
  93. MAXIMUM_ALLOWED,
  94. &ObjectAttributes,
  95. 0,
  96. &ClassName,
  97. REG_OPTION_VOLATILE,
  98. &Disposition
  99. );
  100. if (!NT_SUCCESS(status)) {
  101. printf("rtvbatcr: t0: %08lx\n", status);
  102. failure++;
  103. goto punt;
  104. }
  105. //
  106. // Create NumberChildren subkeys
  107. //
  108. for (i = 0; i < NumberChildren; i++) {
  109. sprintf(formatbuffer, "%s%d", BaseName, i);
  110. RtlInitString(&format, formatbuffer);
  111. RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
  112. InitializeObjectAttributes(
  113. &ObjectAttributes,
  114. &WorkName,
  115. 0,
  116. BaseHandle,
  117. NULL
  118. );
  119. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  120. status = NtCreateKey(
  121. &WorkHandle,
  122. MAXIMUM_ALLOWED,
  123. &ObjectAttributes,
  124. 0,
  125. &ClassName,
  126. REG_OPTION_VOLATILE,
  127. &Disposition
  128. );
  129. if (!NT_SUCCESS(status)) {
  130. printf("rtvbatcr: t1: status = %08lx i = %d\n", status, i);
  131. failure++;
  132. }
  133. //
  134. // Create NumberValues value entries for each (current) key
  135. //
  136. for (j = 0; j < NumberValues; j++) {
  137. sprintf(formatbuffer, "%s%d", BaseName, j);
  138. RtlInitString(&format, formatbuffer);
  139. RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
  140. sprintf(
  141. formatbuffer, "This is a rtvbatcr value for %s%d", BaseName, j
  142. );
  143. status = NtSetValueKey(
  144. WorkHandle,
  145. &WorkName,
  146. j,
  147. j,
  148. formatbuffer,
  149. strlen(formatbuffer)+1
  150. );
  151. if (!NT_SUCCESS(status)) {
  152. printf("rtvbatcr: t2: status = %08lx j = %d\n", status, j);
  153. failure++;
  154. }
  155. }
  156. NtClose(WorkHandle);
  157. }
  158. punt:
  159. printf("rtvbatcr: %d failures\n", failure);
  160. exit(failure);
  161. }
  162. void
  163. processargs(
  164. int argc,
  165. char *argv[]
  166. )
  167. {
  168. ANSI_STRING temp;
  169. if ( (argc != 3) && (argc != 6) )
  170. {
  171. printf("Usage: %s <KeyPath> <KeyName> [<basename> <#children> <#values>]\n",
  172. argv[0]);
  173. exit(1);
  174. }
  175. RtlInitAnsiString(
  176. &temp,
  177. argv[1]
  178. );
  179. RtlAnsiStringToUnicodeString(
  180. &KeyPath,
  181. &temp,
  182. TRUE
  183. );
  184. RtlInitAnsiString(
  185. &temp,
  186. argv[2]
  187. );
  188. RtlAnsiStringToUnicodeString(
  189. &KeyName,
  190. &temp,
  191. TRUE
  192. );
  193. if (argc < 6) {
  194. NumberChildren = 0;
  195. NumberValues = 0;
  196. } else {
  197. strcpy(BaseName, argv[3]);
  198. NumberChildren = atoi(argv[4]);
  199. NumberValues = atoi(argv[5]);
  200. }
  201. return;
  202. }