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.

285 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. mddmp.cxx
  5. Abstract:
  6. Meta Data Dump Utility.
  7. Author:
  8. Keith Moore (keithmo) 03-Feb-1997
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. //
  14. // Private constants.
  15. //
  16. #define TEST_HRESULT(api,hr,fatal) \
  17. if( FAILED(hr) ) { \
  18. \
  19. wprintf( \
  20. L"%S:%lu failed, error %lx %S\n", \
  21. (api), \
  22. __LINE__, \
  23. (result), \
  24. (fatal) \
  25. ? "ABORTING" \
  26. : "CONTINUING" \
  27. ); \
  28. \
  29. if( fatal ) { \
  30. \
  31. goto cleanup; \
  32. \
  33. } \
  34. \
  35. } else
  36. //
  37. // Private types.
  38. //
  39. typedef struct _ENUM_CONTEXT {
  40. LPWSTR Leaf;
  41. WCHAR Path[MAX_PATH];
  42. } ENUM_CONTEXT, *PENUM_CONTEXT;
  43. //
  44. // Private globals.
  45. //
  46. //
  47. // Private prototypes.
  48. //
  49. VOID
  50. DumpTree(
  51. IMSAdminBase * AdmCom,
  52. PENUM_CONTEXT Context
  53. );
  54. BOOL
  55. WINAPI
  56. EnumCallback(
  57. IMSAdminBase * AdmCom,
  58. LPWSTR ObjectName,
  59. VOID * Context
  60. );
  61. //
  62. // Public functions.
  63. //
  64. INT
  65. __cdecl
  66. wmain(
  67. INT argc,
  68. LPWSTR argv[]
  69. )
  70. {
  71. HRESULT result;
  72. IMSAdminBase * admCom;
  73. ENUM_CONTEXT context;
  74. //
  75. // Setup locals so we know how to cleanup on exit.
  76. //
  77. admCom = NULL;
  78. //
  79. // Initialize COM.
  80. //
  81. result = CoInitializeEx(
  82. NULL,
  83. COINIT_MULTITHREADED
  84. );
  85. TEST_HRESULT( "CoInitializeEx()", result, TRUE );
  86. //
  87. // Get the admin object.
  88. //
  89. result = MdGetAdminObject( &admCom );
  90. TEST_HRESULT( "MdGetAdminObject()", result, TRUE );
  91. //
  92. // Dump the metabase tree.
  93. //
  94. wcscpy(
  95. context.Path,
  96. L"/"
  97. );
  98. DumpTree(
  99. admCom,
  100. &context
  101. );
  102. cleanup:
  103. //
  104. // Release the admin object.
  105. //
  106. if( admCom != NULL ) {
  107. result = MdReleaseAdminObject( admCom );
  108. TEST_HRESULT( "MdReleaseAdminObject()", result, FALSE );
  109. }
  110. //
  111. // Shutdown COM.
  112. //
  113. CoUninitialize();
  114. return 0;
  115. } // main
  116. //
  117. // Private functions.
  118. //
  119. VOID
  120. DumpTree(
  121. IMSAdminBase * AdmCom,
  122. PENUM_CONTEXT Context
  123. )
  124. {
  125. HRESULT result;
  126. METADATA_GETALL_RECORD * data;
  127. METADATA_GETALL_RECORD * scan;
  128. DWORD numEntries;
  129. INT pathLen;
  130. LPWSTR leaf;
  131. result = MdGetAllMetaData(
  132. AdmCom,
  133. METADATA_MASTER_ROOT_HANDLE,
  134. Context->Path,
  135. 0,
  136. &data,
  137. &numEntries
  138. );
  139. if( FAILED(result) ) {
  140. wprintf(
  141. L"Cannot get metadata for %s, error %lx\n",
  142. Context->Path,
  143. result
  144. );
  145. return;
  146. }
  147. if( numEntries > 0 ) {
  148. wprintf( L"%s\n", Context->Path );
  149. }
  150. pathLen = wcslen( Context->Path );
  151. for( scan = data ; numEntries > 0 ; numEntries--, scan++ ) {
  152. wprintf( L"%*cIdentifier = %lu\n", pathLen, ' ', scan->dwMDIdentifier );
  153. wprintf( L"%*cAttributes = %08lx\n", pathLen, ' ', scan->dwMDAttributes );
  154. wprintf( L"%*cUserType = %lu\n", pathLen, ' ', scan->dwMDUserType );
  155. wprintf( L"%*cDataType = %lu\n", pathLen, ' ', scan->dwMDDataType );
  156. wprintf( L"\n" );
  157. }
  158. MdFreeMetaDataBuffer( (VOID *)data );
  159. leaf = Context->Leaf;
  160. Context->Leaf = Context->Path + wcslen( Context->Path );
  161. result = MdEnumMetaObjects(
  162. AdmCom,
  163. Context->Path,
  164. &EnumCallback,
  165. (VOID *)Context
  166. );
  167. Context->Leaf = leaf;
  168. if( FAILED(result) ) {
  169. wprintf(
  170. L"Cannot enumerate meta objects, error %lx\n",
  171. result
  172. );
  173. return;
  174. }
  175. } // DumpTree
  176. BOOL
  177. WINAPI
  178. EnumCallback(
  179. IMSAdminBase * AdmCom,
  180. LPWSTR ObjectName,
  181. VOID * Context
  182. )
  183. {
  184. PENUM_CONTEXT context;
  185. LPWSTR leaf;
  186. if( *ObjectName != '\0' ) {
  187. context = (PENUM_CONTEXT)Context;
  188. leaf = context->Leaf;
  189. if( leaf > ( context->Path + 1 ) ) {
  190. *leaf++ = L'/';
  191. }
  192. wcscpy(
  193. leaf,
  194. ObjectName
  195. );
  196. DumpTree(
  197. AdmCom,
  198. context
  199. );
  200. }
  201. return TRUE;
  202. } // EnumCallback