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.

202 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtload.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Perform an NtLoadKey call to link a hive file into the registry.
  8. If KeyPath is not present, it loads the hive file at
  9. \Registry\User\FileName
  10. rtload [ <KeyPath> ] <FileName>
  11. Example:
  12. rtload \registry\user\JVert JVUser
  13. Author:
  14. John Vert (jvert) 15-Apr-92
  15. Revision History:
  16. --*/
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.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. UNICODE_STRING KeyPath;
  27. WCHAR KeyPathBuffer[WORK_SIZE];
  28. UNICODE_STRING FileName;
  29. WCHAR FileNameBuffer[WORK_SIZE];
  30. OBJECT_ATTRIBUTES FileAttributes;
  31. OBJECT_ATTRIBUTES KeyAttributes;
  32. void
  33. __cdecl main(
  34. int argc,
  35. char *argv[]
  36. )
  37. {
  38. NTSTATUS status;
  39. IO_STATUS_BLOCK IoStatus;
  40. HANDLE FileHandle;
  41. HANDLE KeyHandle;
  42. //
  43. // Process args
  44. //
  45. KeyPath.MaximumLength = WORK_SIZE;
  46. KeyPath.Length = 0L;
  47. KeyPath.Buffer = &(KeyPathBuffer[0]);
  48. FileName.MaximumLength = WORK_SIZE;
  49. FileName.Length = 0L;
  50. FileName.Buffer = &(FileNameBuffer[0]);
  51. processargs(argc, argv);
  52. //
  53. // Set up FileName
  54. //
  55. printf("rtload: starting\n");
  56. status = NtLoadKey(&KeyAttributes, &FileAttributes);
  57. if (!NT_SUCCESS(status)) {
  58. printf("rtload: key load failed status = %08lx\n", status);
  59. exit(1);
  60. } else {
  61. printf("rtload: success!\n");
  62. }
  63. exit(0);
  64. }
  65. void
  66. processargs(
  67. int argc,
  68. char *argv[]
  69. )
  70. {
  71. ANSI_STRING temp;
  72. UNICODE_STRING DosFileName;
  73. HANDLE UserHandle;
  74. PWSTR FilePart;
  75. NTSTATUS Status;
  76. if ( (argc != 2) && (argc != 3))
  77. {
  78. printf("Usage: %s [ <KeyName> ] <FileName>\n",
  79. argv[0]);
  80. exit(1);
  81. }
  82. if (argc == 3) {
  83. RtlInitAnsiString(
  84. &temp,
  85. argv[1]
  86. );
  87. RtlAnsiStringToUnicodeString(
  88. &KeyPath,
  89. &temp,
  90. TRUE
  91. );
  92. RtlInitAnsiString(
  93. &temp,
  94. argv[2]
  95. );
  96. RtlAnsiStringToUnicodeString(
  97. &DosFileName,
  98. &temp,
  99. TRUE
  100. );
  101. RtlDosPathNameToNtPathName_U( DosFileName.Buffer,
  102. &FileName,
  103. NULL,
  104. NULL );
  105. InitializeObjectAttributes(
  106. &FileAttributes,
  107. &FileName,
  108. OBJ_CASE_INSENSITIVE,
  109. (HANDLE)NULL,
  110. NULL
  111. );
  112. //
  113. // Set up KeyPath
  114. //
  115. InitializeObjectAttributes(
  116. &KeyAttributes,
  117. &KeyPath,
  118. OBJ_CASE_INSENSITIVE,
  119. (HANDLE)NULL,
  120. NULL
  121. );
  122. } else if (argc==2) {
  123. RtlInitAnsiString(&temp, argv[1]);
  124. RtlAnsiStringToUnicodeString(&DosFileName, &temp, TRUE);
  125. RtlDosPathNameToNtPathName_U( DosFileName.Buffer,
  126. &FileName,
  127. &FilePart,
  128. NULL );
  129. InitializeObjectAttributes( &FileAttributes,
  130. &FileName,
  131. OBJ_CASE_INSENSITIVE,
  132. NULL,
  133. NULL );
  134. RtlInitUnicodeString(&KeyPath, L"\\Registry\\User");
  135. InitializeObjectAttributes( &KeyAttributes,
  136. &KeyPath,
  137. OBJ_CASE_INSENSITIVE,
  138. NULL,
  139. NULL );
  140. Status = NtOpenKey( &UserHandle,
  141. KEY_READ,
  142. &KeyAttributes);
  143. if (!NT_SUCCESS(Status)) {
  144. printf("Couldn't open \\Registry\\User, status %08lx\n",Status);
  145. exit(1);
  146. }
  147. RtlInitUnicodeString(&KeyPath, FilePart);
  148. InitializeObjectAttributes( &KeyAttributes,
  149. &KeyPath,
  150. OBJ_CASE_INSENSITIVE,
  151. UserHandle,
  152. NULL );
  153. }
  154. return;
  155. }