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.

269 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. regdir.c
  5. Abstract:
  6. Utility to display all or part of the registry directory.
  7. REGDIR [KeyPath]
  8. Will ennumerate and dump out the subkeys and values of KeyPath,
  9. and then apply itself recursively to each subkey it finds.
  10. Default KeyPath if none specified is \Registry
  11. Author:
  12. Steve Wood (stevewo) 12-Mar-92
  13. Revision History:
  14. --*/
  15. #include "regutil.h"
  16. void
  17. DumpValues(
  18. HKEY KeyHandle,
  19. PWSTR KeyName,
  20. ULONG Depth
  21. );
  22. void
  23. DumpKeys(
  24. HKEY ParentKeyHandle,
  25. PWSTR KeyName,
  26. ULONG Depth
  27. );
  28. BOOLEAN RecurseIntoSubkeys = FALSE;
  29. BOOL
  30. CtrlCHandler(
  31. IN ULONG CtrlType
  32. )
  33. {
  34. RTDisconnectFromRegistry( &RegistryContext );
  35. return FALSE;
  36. }
  37. int
  38. __cdecl
  39. main(
  40. int argc,
  41. char *argv[]
  42. )
  43. {
  44. ULONG n;
  45. char *s;
  46. LONG Error;
  47. PWSTR RegistryPath;
  48. InitCommonCode( CtrlCHandler,
  49. "REGDIR",
  50. "[-r] registryPath",
  51. "-r specifies to recurse into subdirectories\n"
  52. "registryPath specifies where to start displaying.\n"
  53. );
  54. RegistryPath = NULL;
  55. while (--argc) {
  56. s = *++argv;
  57. if (*s == '-' || *s == '/') {
  58. while (*++s) {
  59. switch( tolower( *s ) ) {
  60. case 'r':
  61. RecurseIntoSubkeys = TRUE;
  62. break;
  63. default:
  64. CommonSwitchProcessing( &argc, &argv, *s );
  65. break;
  66. }
  67. }
  68. }
  69. else
  70. if (RegistryPath == NULL) {
  71. RegistryPath = GetArgAsUnicode( s );
  72. }
  73. else {
  74. Usage( "May only specify one registry path to display", 0 );
  75. }
  76. }
  77. Error = RTConnectToRegistry( MachineName,
  78. HiveFileName,
  79. HiveRootName,
  80. Win95Path,
  81. Win95UserPath,
  82. &RegistryPath,
  83. &RegistryContext
  84. );
  85. if (Error != NO_ERROR) {
  86. FatalError( "Unable to access registry specifed (%u)", Error, 0 );
  87. }
  88. DumpKeys( RegistryContext.HiveRootHandle, RegistryPath, 0 );
  89. RTDisconnectFromRegistry( &RegistryContext );
  90. return 0;
  91. }
  92. void
  93. DumpKeys(
  94. HKEY ParentKeyHandle,
  95. PWSTR KeyName,
  96. ULONG Depth
  97. )
  98. {
  99. LONG Error;
  100. HKEY KeyHandle;
  101. ULONG SubKeyIndex;
  102. WCHAR SubKeyName[ MAX_PATH ];
  103. ULONG SubKeyNameLength;
  104. FILETIME LastWriteTime;
  105. Error = RTOpenKey( &RegistryContext,
  106. ParentKeyHandle,
  107. KeyName,
  108. MAXIMUM_ALLOWED,
  109. REG_OPTION_OPEN_LINK,
  110. &KeyHandle
  111. );
  112. if (Error != NO_ERROR) {
  113. if (Depth == 0) {
  114. FatalError( "Unable to open key '%ws' (%u)\n",
  115. (ULONG_PTR)KeyName,
  116. (ULONG)Error
  117. );
  118. }
  119. if (DebugOutput) {
  120. fprintf( stderr,
  121. "Unable to open key '%ws' (%u)\n",
  122. KeyName,
  123. (ULONG)Error
  124. );
  125. }
  126. return;
  127. }
  128. //
  129. // Print name of node we are about to dump out
  130. //
  131. printf( "%.*s%ws",
  132. Depth * IndentMultiple,
  133. " ",
  134. KeyName
  135. );
  136. RTFormatKeySecurity( (PREG_OUTPUT_ROUTINE)fprintf, stdout, KeyHandle, NULL );
  137. printf( "\n" );
  138. //
  139. // Print out node's values
  140. //
  141. if (Depth != 1 || RecurseIntoSubkeys) {
  142. DumpValues( KeyHandle, KeyName, Depth + 1 );
  143. }
  144. //
  145. // Enumerate node's children and apply ourselves to each one
  146. //
  147. if (Depth == 0 || RecurseIntoSubkeys) {
  148. for (SubKeyIndex = 0; TRUE; SubKeyIndex++) {
  149. SubKeyNameLength = sizeof( SubKeyName ) / sizeof(WCHAR);
  150. Error = RTEnumerateKey( &RegistryContext,
  151. KeyHandle,
  152. SubKeyIndex,
  153. &LastWriteTime,
  154. &SubKeyNameLength,
  155. SubKeyName
  156. );
  157. if (Error != NO_ERROR) {
  158. if (Error != ERROR_NO_MORE_ITEMS && Error != ERROR_ACCESS_DENIED) {
  159. fprintf( stderr,
  160. "RTEnumerateKey( %ws ) failed (%u), skipping\n",
  161. KeyName,
  162. Error
  163. );
  164. }
  165. break;
  166. }
  167. DumpKeys( KeyHandle, SubKeyName, Depth + 1 );
  168. }
  169. }
  170. RTCloseKey( &RegistryContext, KeyHandle );
  171. return;
  172. }
  173. void
  174. DumpValues(
  175. HKEY KeyHandle,
  176. PWSTR KeyName,
  177. ULONG Depth
  178. )
  179. {
  180. LONG Error;
  181. DWORD ValueIndex;
  182. DWORD ValueType;
  183. DWORD ValueNameLength;
  184. WCHAR ValueName[ MAX_PATH ];
  185. DWORD ValueDataLength;
  186. for (ValueIndex = 0; TRUE; ValueIndex++) {
  187. ValueType = REG_NONE;
  188. ValueNameLength = sizeof( ValueName ) / sizeof( WCHAR );
  189. ValueDataLength = OldValueBufferSize;
  190. Error = RTEnumerateValueKey( &RegistryContext,
  191. KeyHandle,
  192. ValueIndex,
  193. &ValueType,
  194. &ValueNameLength,
  195. ValueName,
  196. &ValueDataLength,
  197. OldValueBuffer
  198. );
  199. if (Error == NO_ERROR) {
  200. RTFormatKeyValue( OutputWidth,
  201. (PREG_OUTPUT_ROUTINE)fprintf,
  202. stdout,
  203. TRUE,
  204. Depth * IndentMultiple,
  205. ValueName,
  206. ValueDataLength,
  207. ValueType,
  208. OldValueBuffer
  209. );
  210. }
  211. else
  212. if (Error == ERROR_NO_MORE_ITEMS) {
  213. return;
  214. }
  215. else {
  216. if (DebugOutput) {
  217. fprintf( stderr,
  218. "RTEnumerateValueKey( %ws ) failed (%u)\n",
  219. KeyName,
  220. Error
  221. );
  222. }
  223. return;
  224. }
  225. }
  226. }