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.

358 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtsetopt.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. This program attempts to force all cases through the various
  8. optimizations in the NtSetValueKey code.
  9. This is a whitebox test intended force system errors (crashes)
  10. when run. Returned values are not very interesting.
  11. rtsetopt <root of test tree>
  12. Example:
  13. rtsetopt \registry\machine\software\test
  14. Named key must already exist.
  15. Author:
  16. Bryan Willman (bryanwi) 17-Nov-92
  17. Revision History:
  18. --*/
  19. #include "cmp.h"
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #define WORK_SIZE 1024
  24. void __cdecl main(int, char **);
  25. void processargs();
  26. ULONG failure = 0;
  27. UNICODE_STRING KeyPath;
  28. UCHAR TestData[] =
  29. "This is some test data, it is short. But long enough for most of our tests.";
  30. UNICODE_STRING WorkName;
  31. WCHAR workbuffer[2 * CM_MAX_STASH];
  32. LONG testvector0[] = { 0, 3, 4, 5, -1 };
  33. LONG testvector1[] = { 0, 0, 3, 0, 4, 0, 5, 0, 3, 3, 4, 3, 5, 3,
  34. 4, 4, 5, 4, 5, 5, -1 };
  35. LONG testvector2[] = { 8, 6, 8, 32,
  36. PAGE_SIZE, PAGE_SIZE-1, PAGE_SIZE, PAGE_SIZE+1,
  37. -1 };
  38. LONG testvector3[] = { CM_MAX_STASH, CM_MAX_STASH-1, CM_MAX_STASH,
  39. CM_MAX_STASH+1, -1 };
  40. PLONG supervector[] = { &(testvector1[0]), &(testvector2[1]),
  41. &(testvector3[0]), NULL };
  42. void
  43. __cdecl main(
  44. int argc,
  45. char **argv
  46. )
  47. {
  48. NTSTATUS status;
  49. OBJECT_ATTRIBUTES ObjectAttributes;
  50. HANDLE BaseHandle;
  51. UNICODE_STRING ValueName;
  52. ULONG ResultLength;
  53. PKEY_VALUE_FULL_INFORMATION pvaluefull;
  54. PKEY_VALUE_PARTIAL_INFORMATION pvaluepart;
  55. ULONG i;
  56. ULONG index;
  57. LONG testsize;
  58. PUCHAR p;
  59. PLONG activevector;
  60. for (i = 0; i < 2 * CM_MAX_STASH; i++) {
  61. workbuffer[i] = 'e';
  62. }
  63. //
  64. // Process args
  65. //
  66. processargs(argc, argv);
  67. //
  68. // Open the specified keypath, punt on failure
  69. //
  70. printf("rtsetopt: starting\n");
  71. WorkName.MaximumLength = WORK_SIZE;
  72. WorkName.Length = 0L;
  73. WorkName.Buffer = &(workbuffer[0]);
  74. RtlCopyString((PSTRING)&WorkName, (PSTRING)&KeyPath);
  75. InitializeObjectAttributes(
  76. &ObjectAttributes,
  77. &WorkName,
  78. 0,
  79. (HANDLE)NULL,
  80. NULL
  81. );
  82. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  83. status = NtOpenKey(
  84. &BaseHandle,
  85. MAXIMUM_ALLOWED,
  86. &ObjectAttributes
  87. );
  88. if (!NT_SUCCESS(status)) {
  89. printf("line_%4d: abort %08lx\n", __LINE__, status);
  90. failure++;
  91. goto punt;
  92. }
  93. //
  94. // Perform new value entry tests, with an empty list.
  95. //
  96. RtlInitUnicodeString(
  97. &ValueName,
  98. L"NewValueTest1"
  99. );
  100. for (index = 0; testvector0[index] != -1; index++) {
  101. testsize = testvector0[index];
  102. printf("AT line_%4d: %d\n", __LINE__, testsize);
  103. status = NtSetValueKey(
  104. BaseHandle,
  105. &ValueName,
  106. 1,
  107. REG_BINARY,
  108. &(TestData[0]),
  109. testsize
  110. );
  111. if (!NT_SUCCESS(status)) {
  112. printf("line_%4d: %08lx\n", __LINE__, status);
  113. failure++;
  114. }
  115. printf("AT line_%4d: %d\n", __LINE__, testsize);
  116. for (i = 0; i < WORK_SIZE; i++) workbuffer[i] = '?';
  117. status = NtQueryValueKey(
  118. BaseHandle,
  119. &ValueName,
  120. KeyValueFullInformation,
  121. &(workbuffer[0]),
  122. WORK_SIZE,
  123. &ResultLength
  124. );
  125. if (!NT_SUCCESS(status)) {
  126. printf("line_%4d: %08lx\n", __LINE__, status);
  127. failure++;
  128. }
  129. pvaluefull = (PKEY_VALUE_FULL_INFORMATION)(&(workbuffer[0]));
  130. if (pvaluefull->DataLength != testsize) {
  131. printf("line_%4d: %08lx\n", __LINE__, 9999);
  132. failure++;
  133. }
  134. if (testsize > 0) {
  135. p = (PUCHAR)pvaluefull;
  136. p = p+pvaluefull->DataOffset;
  137. if (p[2] != 'i') {
  138. printf("line_%4d: %08lx\n", __LINE__, 9999);
  139. failure++;
  140. }
  141. }
  142. printf("AT line_%4d: %d\n", __LINE__, testsize);
  143. if (testvector0[index+1] != -1) {
  144. status = NtDeleteValueKey(
  145. BaseHandle,
  146. &ValueName
  147. );
  148. if (!NT_SUCCESS(status)) {
  149. printf("line_%4d: abort %08lx\n", __LINE__, status);
  150. failure++;
  151. goto punt;
  152. }
  153. }
  154. }
  155. //
  156. // Perform new value entry tests, with a non empty list.
  157. //
  158. RtlInitUnicodeString(
  159. &ValueName,
  160. L"NewValueTest2"
  161. );
  162. for (index = 0; testvector0[index] != -1; index++) {
  163. testsize = testvector0[index];
  164. printf("AT line_%4d: %d\n", __LINE__, testsize);
  165. status = NtSetValueKey(
  166. BaseHandle,
  167. &ValueName,
  168. 1,
  169. REG_BINARY,
  170. &(TestData[0]),
  171. testsize
  172. );
  173. if (!NT_SUCCESS(status)) {
  174. printf("line_%4d: %08lx\n", __LINE__, status);
  175. failure++;
  176. }
  177. printf("AT line_%4d: %d\n", __LINE__, testsize);
  178. for (i = 0; i < WORK_SIZE; i++) workbuffer[i] = '?';
  179. status = NtQueryValueKey(
  180. BaseHandle,
  181. &ValueName,
  182. KeyValuePartialInformation,
  183. &(workbuffer[0]),
  184. WORK_SIZE,
  185. &ResultLength
  186. );
  187. if (!NT_SUCCESS(status)) {
  188. printf("line_%4d: %08lx\n", __LINE__, status);
  189. failure++;
  190. }
  191. pvaluepart = (PKEY_VALUE_PARTIAL_INFORMATION)(&(workbuffer[0]));
  192. if (pvaluepart->DataLength != testsize) {
  193. printf("line_%4d: %08lx\n", __LINE__, 9999);
  194. failure++;
  195. }
  196. if (testsize > 0) {
  197. if (pvaluepart->Data[2] != 'i') {
  198. printf("line_%4d: %08lx\n", __LINE__, 9999);
  199. failure++;
  200. }
  201. }
  202. printf("AT line_%4d: %d\n", __LINE__, testsize);
  203. status = NtDeleteValueKey(
  204. BaseHandle,
  205. &ValueName
  206. );
  207. if (!NT_SUCCESS(status)) {
  208. printf("line_%4d: abort %08lx\n", __LINE__, status);
  209. failure++;
  210. goto punt;
  211. }
  212. }
  213. //
  214. // Perform existing value entry tests, with all the relevent
  215. // size transitions.
  216. //
  217. RtlInitUnicodeString(
  218. &ValueName,
  219. L"NewValueTest3"
  220. );
  221. for (i = 0; i < 2 * CM_MAX_STASH; i++) {
  222. workbuffer[i] = 'e';
  223. }
  224. for (i = 0; supervector[i] != NULL; i++) {
  225. activevector = supervector[i];
  226. for (index = 0; activevector[index] != -1; index++) {
  227. testsize = activevector[index];
  228. printf("AT line_%4d: %d\n", __LINE__, testsize);
  229. status = NtSetValueKey(
  230. BaseHandle,
  231. &ValueName,
  232. 1,
  233. REG_BINARY,
  234. &(workbuffer[0]),
  235. testsize
  236. );
  237. if (!NT_SUCCESS(status)) {
  238. printf("line_%4d: %08lx\n", __LINE__, status);
  239. failure++;
  240. }
  241. printf("AT line_%4d: %d\n", __LINE__, testsize);
  242. status = NtQueryValueKey(
  243. BaseHandle,
  244. &ValueName,
  245. KeyValuePartialInformation,
  246. &(workbuffer[0]),
  247. 2 * CM_MAX_STASH,
  248. &ResultLength
  249. );
  250. if (!NT_SUCCESS(status)) {
  251. printf("line_%4d: %08lx\n", __LINE__, status);
  252. failure++;
  253. }
  254. }
  255. }
  256. punt:
  257. printf("rtsetopt: %d failures\n", failure);
  258. exit(failure);
  259. }
  260. void
  261. processargs(
  262. int argc,
  263. char *argv[]
  264. )
  265. {
  266. ANSI_STRING temp;
  267. if (argc != 2)
  268. {
  269. printf("Usage: %s <KeyPath>\n", argv[0]);
  270. exit(1);
  271. }
  272. RtlInitAnsiString(
  273. &temp,
  274. argv[1]
  275. );
  276. RtlAnsiStringToUnicodeString(
  277. &KeyPath,
  278. &temp,
  279. TRUE
  280. );
  281. return;
  282. }