Source code of Windows XP (NT5)
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.

322 lines
8.6 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: Dump the dhcp objects in DS (recursively).
  5. //================================================================================
  6. //BeginExport(overview)
  7. //DOC DDSDMP is a command line for dumping the dhcp objects in DS.
  8. //DOC It takes as parameter the DS DC to contact (optional).
  9. //DOC The output is too fluid to spec out at this moment. Hopefully, it would be
  10. //DOC something that would be understood by DDSINI (whenever that gets written).
  11. //EndExport(overview)
  12. //BeginImports(headers)
  13. #include <hdrmacro.h>
  14. #include <store.h>
  15. #include <stdio.h>
  16. #include <dhcpbas.h>
  17. //EndImports(headers)
  18. //BeginInternal(globals)
  19. static DWORD nTabs = 0;
  20. static LPWSTR RecurseFilter = L"(|(objectClass=dHCPClass)(objectClass=container))" ;
  21. static WCHAR Buffer[1000];
  22. static WCHAR Strings[30][100];
  23. //EndExport(globals)
  24. VOID
  25. ErrorPrint(
  26. IN LPSTORE_HANDLE hStore,
  27. IN DWORD Result,
  28. IN LPWSTR Comment
  29. )
  30. {
  31. if( NULL != hStore ) {
  32. printf("\n#%ws\n#%ws (errror %ld, 0x%lx)\n", hStore->Location, Comment, Result, Result );
  33. return;
  34. }
  35. printf("\n#%ws (errror %ld, 0x%lx)\n", Comment, Result, Result);
  36. }
  37. LPWSTR
  38. ConvertDWORD(
  39. IN DWORD d
  40. )
  41. {
  42. swprintf(Buffer, L"0x%08lx", d);
  43. return Buffer;
  44. }
  45. #define HEX(ch) ( ((ch) < 10)? ((ch) + L'0') : ((ch) + L'A' - 10))
  46. LPWSTR
  47. ConvertBINARY(
  48. IN DWORD l,
  49. IN LPBYTE s
  50. )
  51. {
  52. DWORD i;
  53. i = 0;
  54. while( l ) {
  55. Buffer[i++] = HEX(((*s)>>4));
  56. Buffer[i++] = HEX(((*s) & 0x0F));
  57. l --; s ++;
  58. }
  59. Buffer[i] = L'\0';
  60. return Buffer;
  61. }
  62. VOID
  63. Print(
  64. IN LPWSTR Operation,
  65. IN DWORD Type,
  66. IN LPWSTR AttributeName
  67. )
  68. {
  69. DWORD i;
  70. putchar('\n');
  71. for(i = 1; i < nTabs; i ++ ) printf(" ");
  72. printf("%ws %ld :%ws", Operation, Type, AttributeName);
  73. }
  74. VOID
  75. PrintMore(
  76. IN LPWSTR String
  77. )
  78. {
  79. printf("=%ws", String);
  80. }
  81. VOID
  82. PrintName(
  83. IN LPSTORE_HANDLE hStore
  84. )
  85. {
  86. DWORD i;
  87. if( 1 == nTabs ) return;
  88. putchar('\n');
  89. for(i = 1; i < nTabs; i ++ ) printf(" ");
  90. printf("object");
  91. }
  92. DWORD
  93. AttributesDmp(
  94. IN LPSTORE_HANDLE hStore
  95. )
  96. {
  97. DWORD Result;
  98. DWORD FoundParams, Type, MScopeId;
  99. LARGE_INTEGER UniqueKey, Flags;
  100. LPWSTR Name, Description, Location;
  101. Result = DhcpDsGetAttribs(
  102. /* Reserved */ DDS_RESERVED_DWORD,
  103. /* hStore */ hStore,
  104. /* FoundParams */ &FoundParams,
  105. /* UniqueKey */ &UniqueKey,
  106. /* Type */ &Type,
  107. /* Flags */ &Flags,
  108. /* Name */ &Name,
  109. /* Description */ &Description,
  110. /* Location */ &Location,
  111. /* MScopeId */ &MScopeId
  112. );
  113. if( ERROR_SUCCESS != Result ) return Result;
  114. if( !DhcpCheckParams(FoundParams, 0) ) {
  115. Print(L"clear", 0, DHCP_ATTRIB_UNIQUE_KEY);
  116. } else {
  117. Print(L"update", 0, DHCP_ATTRIB_UNIQUE_KEY);
  118. PrintMore(ConvertDWORD(UniqueKey.LowPart));
  119. PrintMore(L" ");
  120. PrintMore(ConvertDWORD(UniqueKey.HighPart));
  121. }
  122. if( !DhcpCheckParams(FoundParams, 1) ) {
  123. Print(L"clear", 0, DHCP_ATTRIB_TYPE);
  124. } else {
  125. Print(L"update", 0, DHCP_ATTRIB_TYPE);
  126. PrintMore(ConvertDWORD(Type));
  127. }
  128. if( !DhcpCheckParams(FoundParams, 2) ) {
  129. Print(L"clear", 0, DHCP_ATTRIB_FLAGS);
  130. } else {
  131. Print(L"update", 0, DHCP_ATTRIB_FLAGS);
  132. PrintMore(ConvertDWORD(Flags.LowPart));
  133. PrintMore(L" ");
  134. PrintMore(ConvertDWORD(Flags.HighPart));
  135. }
  136. if( !DhcpCheckParams(FoundParams, 3) ) {
  137. Print(L"clear", 0, DHCP_ATTRIB_OBJ_NAME);
  138. } else {
  139. Print(L"update", 0, DHCP_ATTRIB_OBJ_NAME);
  140. PrintMore(Name?Name:L"");
  141. if( Name ) MemFree(Name);
  142. }
  143. if( !DhcpCheckParams(FoundParams, 4) ) {
  144. Print(L"clear", 0, DHCP_ATTRIB_OBJ_DESCRIPTION);
  145. } else {
  146. Print(L"update", 0, DHCP_ATTRIB_OBJ_DESCRIPTION);
  147. PrintMore(Description?Description:L"");
  148. if( Description ) MemFree(Description);
  149. }
  150. if( !DhcpCheckParams(FoundParams, 5) ) {
  151. Print(L"clear", 0, DHCP_ATTRIB_LOCATION_DN);
  152. } else {
  153. Print(L"update", 0, DHCP_ATTRIB_LOCATION_DN);
  154. PrintMore(Location?Location:L"");
  155. if( Location ) MemFree(Location);
  156. }
  157. if( !DhcpCheckParams(FoundParams, 6) ) {
  158. Print(L"clear", 0, DHCP_ATTRIB_MSCOPEID);
  159. } else {
  160. Print(L"update", 0, DHCP_ATTRIB_MSCOPEID);
  161. PrintMore(ConvertDWORD(MScopeId));
  162. }
  163. return ERROR_SUCCESS;
  164. }
  165. DWORD
  166. RecurseDmp(
  167. IN OUT LPSTORE_HANDLE hStore
  168. )
  169. {
  170. DWORD Result;
  171. STORE_HANDLE hStore2;
  172. nTabs ++;
  173. PrintName(hStore);
  174. Result = AttributesDmp(hStore);
  175. if( ERROR_SUCCESS != Result ) {
  176. ErrorPrint(hStore, Result, L"AttributesDmp failed");
  177. }
  178. Result = StoreSetSearchOneLevel(hStore, 0);
  179. if( ERROR_SUCCESS != Result ) {
  180. ErrorPrint(hStore, Result, L"StoreSetSearchOneLevel failed");
  181. nTabs --;
  182. return Result;
  183. }
  184. Result = StoreBeginSearch(hStore, 0, RecurseFilter);
  185. if( ERROR_SUCCESS != Result ) {
  186. ErrorPrint(hStore, Result, L"StoreBeginSearch failed");
  187. } else {
  188. while ( ERROR_SUCCESS == Result ) {
  189. Result = StoreSearchGetNext(hStore, 0, &hStore2);
  190. if( ERROR_SUCCESS != Result ) {
  191. if( ERROR_FILE_NOT_FOUND == Result ) break;
  192. if( ERROR_NO_MORE_ITEMS == Result ) break;
  193. ErrorPrint(hStore, Result, L"StoreSearchGetNext failed");
  194. break;
  195. }
  196. Result = RecurseDmp(&hStore2);
  197. if( ERROR_SUCCESS != Result ) {
  198. ErrorPrint(&hStore2, Result, L"RecurseDmp failed");
  199. break;
  200. }
  201. StoreCleanupHandle(&hStore2, 0);
  202. }
  203. StoreEndSearch(hStore, 0);
  204. }
  205. nTabs --;
  206. return ERROR_SUCCESS;
  207. }
  208. LPWSTR
  209. ConvertToLPWSTR(
  210. IN LPSTR s
  211. )
  212. {
  213. LPWSTR u, v;
  214. if( NULL == s ) return L"";
  215. u = LocalAlloc(LMEM_FIXED, (strlen(s)+1)*sizeof(WCHAR));
  216. if( NULL == u ) return L"";
  217. v = u;
  218. while( *v++ = *s++)
  219. ;
  220. return u;
  221. }
  222. void _cdecl main(
  223. int argc,
  224. char *argv[]
  225. )
  226. {
  227. LPWSTR RootName;
  228. STORE_HANDLE Store, Store2;
  229. DWORD Result;
  230. RootName = NULL;
  231. if( argc > 2 ) {
  232. printf("Usage: %s ServerToContact\n", argv[0]);
  233. return;
  234. }
  235. if( 2 == argc ) {
  236. RootName = ConvertToLPWSTR(argv[1]);
  237. if( NULL == RootName ) {
  238. printf("RootDN confusing\n");
  239. return;
  240. }
  241. }
  242. Result = StoreInitHandle(
  243. &Store, 0, RootName, NULL, NULL, NULL,
  244. ADS_SECURE_AUTHENTICATION
  245. );
  246. if( ERROR_SUCCESS != Result ) {
  247. printf("StoreInitHandle: %ld\n", Result);
  248. return;
  249. }
  250. Result = StoreGetHandle(
  251. /* hStore */ &Store,
  252. /* Reserved */ DDS_RESERVED_DWORD,
  253. /* StoreGetType */ StoreGetChildType,
  254. /* Path */ L"CN=NetServices,CN=Services",
  255. /* hStoreOut */ &Store2
  256. );
  257. if( ERROR_SUCCESS != Result ) {
  258. printf("Could not get the netservices container\n");
  259. return;
  260. }
  261. StoreCleanupHandle(&Store,0);
  262. printf("################################################################################\n");
  263. printf("## G E N E R E R A T E D D D S D U M P ##\n");
  264. printf("## command line : (will be filled in future versions) ##\n");
  265. printf("## DDSMP.EXE 1.0 ##\n");
  266. printf("################################################################################\n");
  267. printf("object %ws", RootName);
  268. RecurseDmp(&Store2);
  269. putchar('\n');
  270. exit(0);
  271. }
  272. //================================================================================
  273. // end of file
  274. //================================================================================