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.

276 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtbatcr.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Do a batch create.
  8. rtbatcr <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. rtbatcr \REGISTRY\MACHINE\TEST bigkey runa_ 100 100
  18. rtbatcr \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. BOOLEAN CreateVolatile = FALSE;
  44. UNICODE_STRING WorkName;
  45. WCHAR workbuffer[WORK_SIZE];
  46. void
  47. __cdecl main(
  48. int argc,
  49. char *argv[]
  50. )
  51. {
  52. NTSTATUS status;
  53. OBJECT_ATTRIBUTES ObjectAttributes;
  54. HANDLE BaseHandle;
  55. HANDLE WorkHandle;
  56. ULONG Disposition;
  57. UNICODE_STRING ClassName;
  58. ULONG i;
  59. ULONG j;
  60. PUCHAR p;
  61. ULONG CreateOption;
  62. //
  63. // Process args
  64. //
  65. processargs(argc, argv);
  66. //
  67. // Set up and create/open KeyPath|KeyName
  68. //
  69. printf("rtbatcr: starting\n");
  70. WorkName.MaximumLength = WORK_SIZE;
  71. WorkName.Length = 0L;
  72. WorkName.Buffer = &(workbuffer[0]);
  73. RtlCopyString((PSTRING)&WorkName, (PSTRING)&KeyPath);
  74. p = WorkName.Buffer;
  75. p += WorkName.Length;
  76. *p = '\\';
  77. p++;
  78. *p = '\0';
  79. WorkName.Length += 2;
  80. RtlAppendStringToString((PSTRING)&WorkName, (PSTRING)&KeyName);
  81. RtlInitUnicodeString(
  82. &ClassName,
  83. L"Test Class Name"
  84. );
  85. InitializeObjectAttributes(
  86. &ObjectAttributes,
  87. &WorkName,
  88. 0,
  89. (HANDLE)NULL,
  90. NULL
  91. );
  92. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  93. if (CreateVolatile) {
  94. CreateOption = REG_OPTION_VOLATILE;
  95. } else {
  96. CreateOption = 0;
  97. }
  98. status = NtCreateKey(
  99. &BaseHandle,
  100. MAXIMUM_ALLOWED,
  101. &ObjectAttributes,
  102. 0,
  103. &ClassName,
  104. CreateOption,
  105. &Disposition
  106. );
  107. if (!NT_SUCCESS(status)) {
  108. printf("rtbatcr: t0: %08lx\n", status);
  109. failure++;
  110. goto punt;
  111. }
  112. //
  113. // Create NumberChildren subkeys
  114. //
  115. for (i = 0; i < NumberChildren; i++) {
  116. sprintf(formatbuffer, "%s%d", BaseName, i);
  117. RtlInitString(&format, formatbuffer);
  118. RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
  119. InitializeObjectAttributes(
  120. &ObjectAttributes,
  121. &WorkName,
  122. 0,
  123. BaseHandle,
  124. NULL
  125. );
  126. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  127. status = NtCreateKey(
  128. &WorkHandle,
  129. MAXIMUM_ALLOWED,
  130. &ObjectAttributes,
  131. 0,
  132. &ClassName,
  133. CreateOption,
  134. &Disposition
  135. );
  136. if (!NT_SUCCESS(status)) {
  137. printf("rtbatcr: t1: status = %08lx i = %d\n", status, i);
  138. failure++;
  139. }
  140. //
  141. // Create NumberValues value entries for each (current) key
  142. //
  143. for (j = 0; j < NumberValues; j++) {
  144. sprintf(formatbuffer, "%s%d", BaseName, j);
  145. RtlInitString(&format, formatbuffer);
  146. RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
  147. sprintf(
  148. formatbuffer, "This is a rtbatcr value for %s%d", BaseName, j
  149. );
  150. status = NtSetValueKey(
  151. WorkHandle,
  152. &WorkName,
  153. j,
  154. j,
  155. formatbuffer,
  156. strlen(formatbuffer)+1
  157. );
  158. if (!NT_SUCCESS(status)) {
  159. printf("rtbatcr: t2: status = %08lx j = %d\n", status, j);
  160. failure++;
  161. }
  162. }
  163. NtClose(WorkHandle);
  164. }
  165. punt:
  166. printf("rtbatcr: %d failures\n", failure);
  167. exit(failure);
  168. }
  169. void
  170. processargs(
  171. int argc,
  172. char *argv[]
  173. )
  174. {
  175. ANSI_STRING temp;
  176. if ( (argc < 3) || (argc > 7) )
  177. {
  178. printf("Usage: %s [volatile] <KeyPath> <KeyName> [<basename> <#children> <#values>]\n",
  179. argv[0]);
  180. exit(1);
  181. }
  182. if (_stricmp(argv[1],"volatile")==0) {
  183. CreateVolatile = TRUE;
  184. ++argv;
  185. }
  186. RtlInitAnsiString(
  187. &temp,
  188. argv[1]
  189. );
  190. RtlAnsiStringToUnicodeString(
  191. &KeyPath,
  192. &temp,
  193. TRUE
  194. );
  195. RtlInitAnsiString(
  196. &temp,
  197. argv[2]
  198. );
  199. RtlAnsiStringToUnicodeString(
  200. &KeyName,
  201. &temp,
  202. TRUE
  203. );
  204. if (argc < 6) {
  205. NumberChildren = 0;
  206. NumberValues = 0;
  207. } else {
  208. strcpy(BaseName, argv[3]);
  209. NumberChildren = atoi(argv[4]);
  210. NumberValues = atoi(argv[5]);
  211. }
  212. return;
  213. }