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.

1617 lines
62 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. dhcpcomp.cpp
  7. This file contains the derived implementations from CComponent
  8. and CComponentData for the DHCP admin snapin.
  9. FILE HISTORY:
  10. */
  11. #include "stdafx.h"
  12. #include "dhcpcomp.h"
  13. #include "croot.h"
  14. #include "server.h"
  15. #include "servbrow.h"
  16. #include <util.h> // for InitWatermarkInfo
  17. #include <atlimpl.cpp>
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. #define DHCPSNAP_HELP_FILE_NAME "dhcpsnap.chm"
  24. LARGE_INTEGER gliDhcpsnapVersion;
  25. CAuthServerList g_AuthServerList;
  26. WATERMARKINFO g_WatermarkInfoServer = {0};
  27. WATERMARKINFO g_WatermarkInfoScope = {0};
  28. UINT aColumns[DHCPSNAP_NODETYPE_MAX][MAX_COLUMNS] =
  29. {
  30. {IDS_ROOT_NAME, IDS_STATUS, 0, 0, 0, 0, 0},
  31. {IDS_DHCPSERVER_NAME, IDS_STATUS, IDS_DESCRIPTION, 0, 0, 0, 0},
  32. {IDS_BOOT_IMAGE, IDS_FILE_NAME, IDS_FILE_SERVER, 0, 0, 0, 0},
  33. {IDS_SUPERSCOPE_NAME, IDS_STATUS, IDS_DESCRIPTION, 0, 0, 0, 0},
  34. {IDS_SCOPE_NAME, 0, 0, 0, 0, 0, 0},
  35. {IDS_SCOPE_NAME, 0, 0, 0, 0, 0, 0},
  36. {IDS_START_IP_ADDR, IDS_END_IP_ADDR, IDS_DESCRIPTION, 0, 0, 0, 0},
  37. {IDS_CLIENT_IP_ADDR, IDS_NAME, IDS_LEASE, IDS_TYPE, IDS_UID, IDS_COMMENT, 0},
  38. {IDS_CLIENT_IP_ADDR, IDS_NAME, IDS_LEASE_START, IDS_LEASE, IDS_CLIENT_ID, 0, 0},
  39. {IDS_RESERVATIONS_FOLDER, 0, 0, 0, 0, 0, 0},
  40. {IDS_OPTION_NAME, IDS_VENDOR, IDS_VALUE, IDS_CLASS, 0, 0, 0},
  41. {IDS_OPTION_NAME, IDS_VENDOR, IDS_VALUE, IDS_CLASS, 0, 0, 0},
  42. {IDS_OPTION_NAME, IDS_VENDOR, IDS_VALUE, IDS_CLASS, 0, 0, 0},
  43. {IDS_NAME, IDS_COMMENT, 0, 0, 0, 0, 0},
  44. {0,0,0,0,0,0,0}
  45. };
  46. //
  47. // CODEWORK this should be in a resource, for example code on loading data resources see
  48. // D:\nt\private\net\ui\common\src\applib\applib\lbcolw.cxx ReloadColumnWidths()
  49. // JonN 10/11/96
  50. //
  51. int aColumnWidths[DHCPSNAP_NODETYPE_MAX][MAX_COLUMNS] =
  52. {
  53. {200 ,150 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_ROOT
  54. {250 ,150 ,200 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_SERVER
  55. {175 ,175 ,175 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_BOOTP_TABLE
  56. {200 ,150 ,200 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_SUPERSCOPE
  57. {150 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_SCOPE
  58. {150 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_MSCOPE
  59. {150 ,150 ,250 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_ADDRESS_POOL
  60. {125 ,125 ,200 ,75 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_ACTIVE_LEASES
  61. {125 ,125 ,200 ,200 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_MSCOPE_LEASES
  62. {200 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_RESERVATIONS
  63. {175 ,100 ,200 ,150 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_RESERVATION_CLIENT
  64. {175 ,100 ,200 ,150 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_SCOPE_OPTIONS
  65. {175 ,100 ,200 ,150 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH}, // DHCPSNAP_SERVER_OPTIONS
  66. {175 ,200 ,200 ,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH,AUTO_WIDTH} // DHCPSNAP_CLASSID_HOLDER
  67. };
  68. // array to hold all of the possible toolbar buttons
  69. MMCBUTTON g_SnapinButtons[] =
  70. {
  71. { TOOLBAR_IDX_ADD_SERVER, IDS_ADD_SERVER, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  72. { TOOLBAR_IDX_REFRESH, IDS_REFRESH, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  73. { TOOLBAR_IDX_CREATE_SCOPE, IDS_CREATE_NEW_SCOPE, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  74. { TOOLBAR_IDX_CREATE_SUPERSCOPE, IDS_CREATE_NEW_SUPERSCOPE, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  75. { TOOLBAR_IDX_DEACTIVATE, IDS_DEACTIVATE, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  76. { TOOLBAR_IDX_ACTIVATE, IDS_ACTIVATE, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  77. { TOOLBAR_IDX_ADD_BOOTP, IDS_CREATE_NEW_BOOT_IMAGE, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  78. { TOOLBAR_IDX_ADD_RESERVATION, IDS_CREATE_NEW_RESERVATION, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  79. { TOOLBAR_IDX_ADD_EXCLUSION, IDS_CREATE_NEW_EXCLUSION, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  80. { TOOLBAR_IDX_OPTION_GLOBAL, IDS_CREATE_OPTION_GLOBAL, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  81. { TOOLBAR_IDX_OPTION_SCOPE, IDS_CREATE_OPTION_SCOPE, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  82. { TOOLBAR_IDX_OPTION_RESERVATION,IDS_CREATE_OPTION_RESERVATION, TBSTATE_HIDDEN, TBSTYLE_BUTTON, NULL, NULL },
  83. };
  84. // array to hold resource IDs for the toolbar button text
  85. int g_SnapinButtonStrings[TOOLBAR_IDX_MAX][2] =
  86. {
  87. {IDS_TB_TEXT_ADD_SERVER, IDS_TB_TOOLTIP_ADD_SERVER}, // TOOLBAR_IDX_ADD_SERVER
  88. {IDS_TB_TEXT_REFRESH, IDS_TB_TOOLTIP_REFRESH}, // TOOLBAR_IDX_REFRESH
  89. {IDS_TB_TEXT_CREATE_SCOPE, IDS_TB_TOOLTIP_CREATE_SCOPE}, // TOOLBAR_IDX_CREATE_SCOPE
  90. {IDS_TB_TEXT_CREATE_SUPERSCOPE, IDS_TB_TOOLTIP_CREATE_SUPERSCOPE}, // TOOLBAR_IDX_CREATE_SUPERSCOPE
  91. {IDS_TB_TEXT_DEACTIVATE, IDS_TB_TOOLTIP_DEACTIVATE}, // TOOLBAR_IDX_DEACTIVATE
  92. {IDS_TB_TEXT_ACTIVATE, IDS_TB_TOOLTIP_ACTIVATE}, // TOOLBAR_IDX_ACTIVATE
  93. {IDS_TB_TEXT_ADD_BOOTP, IDS_TB_TOOLTIP_ADD_BOOTP}, // TOOLBAR_IDX_ADD_BOOTP
  94. {IDS_TB_TEXT_ADD_RESERVATION, IDS_TB_TOOLTIP_ADD_RESERVATION}, // TOOLBAR_IDX_ADD_RESERVATION
  95. {IDS_TB_TEXT_ADD_EXCLUSION, IDS_TB_TOOLTIP_ADD_EXCLUSION}, // TOOLBAR_IDX_ADD_EXCLUSION
  96. {IDS_TB_TEXT_OPTION_GLOBAL, IDS_TB_TOOLTIP_OPTION_GLOBAL}, // TOOLBAR_IDX_OPTION_GLOBAL
  97. {IDS_TB_TEXT_OPTION_SCOPE, IDS_TB_TOOLTIP_OPTION_SCOPE}, // TOOLBAR_IDX_OPTION_SCOPE
  98. {IDS_TB_TEXT_OPTION_RESERVATION, IDS_TB_TOOLTIP_OPTION_RESERVATION}, // TOOLBAR_IDX_OPTION_RESERVATION
  99. };
  100. #define HI HIDDEN
  101. #define EN ENABLED
  102. // default states for the toolbar buttons (only scope pane items have toolbar buttons)
  103. MMC_BUTTON_STATE g_SnapinButtonStates[DHCPSNAP_NODETYPE_MAX][TOOLBAR_IDX_MAX] =
  104. {
  105. {EN, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_ROOT
  106. {HI, HI, EN, EN, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_SERVER
  107. {HI, HI, HI, HI, HI, HI, EN, HI, HI, HI, HI, HI}, // DHCPSNAP_BOOTP_TABLE
  108. {HI, HI, EN, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_SUPERSCOPE
  109. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_SCOPE
  110. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_MSCOPE
  111. {HI, HI, HI, HI, HI, HI, HI, HI, EN, HI, HI, HI}, // DHCPSNAP_ADDRESS_POOL
  112. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_ACTIVE_LEASES
  113. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_MSCOPE_LEASES
  114. {HI, HI, HI, HI, HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_RESERVATIONS
  115. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, EN}, // DHCPSNAP_RESERVATION_CLIENT
  116. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_SCOPE_OPTIONS
  117. {HI, HI, HI, HI, HI, HI, HI, HI, HI, EN, HI, HI}, // DHCPSNAP_SERVER_OPTIONS
  118. {HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_CLASSID_HOLDER
  119. };
  120. MMC_CONSOLE_VERB g_ConsoleVerbs[] =
  121. {
  122. MMC_VERB_OPEN,
  123. MMC_VERB_COPY,
  124. MMC_VERB_PASTE,
  125. MMC_VERB_DELETE,
  126. MMC_VERB_PROPERTIES,
  127. MMC_VERB_RENAME,
  128. MMC_VERB_REFRESH,
  129. MMC_VERB_PRINT
  130. };
  131. // default states for the console verbs
  132. MMC_BUTTON_STATE g_ConsoleVerbStates[DHCPSNAP_NODETYPE_MAX][ARRAYLEN(g_ConsoleVerbs)] =
  133. {
  134. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_ROOT
  135. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_SERVER
  136. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_BOOTP_TABLE
  137. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_SUPERSCOPE
  138. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_SCOPE
  139. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_MSCOPE
  140. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_ADDRESS_POOL
  141. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_ACTIVE_LEASES
  142. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_MSCOPE_LEASES
  143. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_RESERVATIONS
  144. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_RESERVATION_CLIENT
  145. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_SCOPE_OPTIONS
  146. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_SERVER_OPTIONS
  147. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_CLASSID_HOLDER
  148. {HI, HI, HI, EN, HI, HI, EN, HI}, // DHCPSNAP_ACTIVE_LEASE
  149. {HI, HI, HI, HI, HI, HI, EN, HI}, // DHCPSNAP_ALLOCATION_RANGE
  150. {HI, HI, HI, EN, HI, HI, EN, HI}, // DHCPSNAP_EXCLUSION_RANGE
  151. {HI, HI, HI, EN, HI, HI, EN, HI}, // DHCPSNAP_BOOTP_ENTRY
  152. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_OPTION_ITEM
  153. {HI, HI, HI, EN, EN, HI, EN, HI}, // DHCPSNAP_CLASSID
  154. {HI, HI, HI, EN, HI, HI, EN, HI} // DHCPSNAP_MCAST_LEASE
  155. };
  156. // default states for the console verbs
  157. MMC_BUTTON_STATE g_ConsoleVerbStatesMultiSel[DHCPSNAP_NODETYPE_MAX][ARRAYLEN(g_ConsoleVerbs)] =
  158. {
  159. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_ROOT
  160. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_SERVER
  161. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_BOOTP_TABLE
  162. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_SUPERSCOPE
  163. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_SCOPE
  164. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_MSCOPE
  165. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_ADDRESS_POOL
  166. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_ACTIVE_LEASES
  167. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_MSCOPE_LEASES
  168. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_RESERVATIONS
  169. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_RESERVATION_CLIENT
  170. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_SCOPE_OPTIONS
  171. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_SERVER_OPTIONS
  172. {HI, HI, HI, EN, HI, HI, HI, HI}, // DHCPSNAP_CLASSID_HOLDER
  173. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_ACTIVE_LEASE
  174. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_ALLOCATION_RANGE
  175. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_EXCLUSION_RANGE
  176. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_BOOTP_ENTRY
  177. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_OPTION_ITEM
  178. {HI, HI, HI, HI, HI, HI, HI, HI}, // DHCPSNAP_CLASSID
  179. {HI, HI, HI, HI, HI, HI, HI, HI} // DHCPSNAP_MCAST_LEASE
  180. };
  181. // Help ID array for help on scope items
  182. DWORD g_dwMMCHelp[DHCPSNAP_NODETYPE_MAX] =
  183. {
  184. DHCPSNAP_HELP_ROOT, // DHCPSNAP_ROOT
  185. DHCPSNAP_HELP_SERVER, // DHCPSNAP_SERVER
  186. DHCPSNAP_HELP_BOOTP_TABLE, // DHCPSNAP_BOOTP_TABLE
  187. DHCPSNAP_HELP_SUPERSCOPE, // DHCPSNAP_SUPERSCOPE
  188. DHCPSNAP_HELP_SCOPE, // DHCPSNAP_SCOPE
  189. DHCPSNAP_HELP_MSCOPE, // DHCPSNAP_MSCOPE
  190. DHCPSNAP_HELP_ADDRESS_POOL, // DHCPSNAP_ADDRESS_POOL
  191. DHCPSNAP_HELP_ACTIVE_LEASES, // DHCPSNAP_ACTIVE_LEASES
  192. DHCPSNAP_HELP_ACTIVE_LEASES, // DHCPSNAP_MSCOPE_LEASES
  193. DHCPSNAP_HELP_RESERVATIONS, // DHCPSNAP_RESERVATIONS
  194. DHCPSNAP_HELP_RESERVATION_CLIENT, // DHCPSNAP_RESERVATION_CLIENT
  195. DHCPSNAP_HELP_SCOPE_OPTIONS, // DHCPSNAP_SCOPE_OPTIONS
  196. DHCPSNAP_HELP_GLOBAL_OPTIONS, // DHCPSNAP_SERVER_OPTIONS
  197. DHCPSNAP_HELP_CLASSID_HOLDER, // DHCPSNAP_CLASSID_HOLDER
  198. DHCPSNAP_HELP_ACTIVE_LEASE, // DHCPSNAP_ACTIVE_LEASE
  199. DHCPSNAP_HELP_ALLOCATION_RANGE, // DHCPSNAP_ALLOCATION_RANGE
  200. DHCPSNAP_HELP_EXCLUSION_RANGE, // DHCPSNAP_EXCLUSION_RANGE
  201. DHCPSNAP_HELP_BOOTP_ENTRY, // DHCPSNAP_BOOTP_ENTRY
  202. DHCPSNAP_HELP_OPTION_ITEM, // DHCPSNAP_OPTION_ITEM
  203. DHCPSNAP_HELP_CLASSID, // DHCPSNAP_CLASSID
  204. DHCPSNAP_HELP_MCAST_LEASE // DHCPSNAP_MCAST_LEASE
  205. };
  206. // help mapper for dialogs and property pages
  207. struct ContextHelpMap
  208. {
  209. UINT uID;
  210. const DWORD * pdwMap;
  211. };
  212. ContextHelpMap g_uContextHelp[DHCPSNAP_NUM_HELP_MAPS] =
  213. {
  214. {IDD_ADD_SERVER, g_aHelpIDs_IDD_ADD_SERVER},
  215. {IDD_ADD_TO_SUPERSCOPE, g_aHelpIDs_IDD_ADD_TO_SUPERSCOPE},
  216. {IDD_BINARY_EDITOR, g_aHelpIDs_IDD_BINARY_EDITOR},
  217. {IDD_BOOTP_NEW, g_aHelpIDs_IDD_BOOTP_NEW},
  218. {IDD_BROWSE_SERVERS, g_aHelpIDs_IDD_BROWSE_SERVERS},
  219. {IDD_CLASSES, g_aHelpIDs_IDD_CLASSES},
  220. {IDD_CLASSID_NEW, g_aHelpIDs_IDD_CLASSID_NEW},
  221. {IDD_CREDENTIALS, g_aHelpIDs_IDD_CREDENTIALS},
  222. {IDD_DATA_ENTRY_BINARY, g_aHelpIDs_IDD_DATA_ENTRY_BINARY},
  223. {IDD_DATA_ENTRY_BINARY_ARRAY, g_aHelpIDs_IDD_DATA_ENTRY_BINARY_ARRAY},
  224. {IDD_DATA_ENTRY_DWORD, g_aHelpIDs_IDD_DATA_ENTRY_DWORD},
  225. {IDD_DATA_ENTRY_IPADDRESS, g_aHelpIDs_IDD_DATA_ENTRY_IPADDRESS},
  226. {IDD_DATA_ENTRY_IPADDRESS_ARRAY, g_aHelpIDs_IDD_DATA_ENTRY_IPADDRESS_ARRAY},
  227. {IDD_DATA_ENTRY_NONE, NULL},
  228. {IDD_DATA_ENTRY_STRING, g_aHelpIDs_IDD_DATA_ENTRY_STRING},
  229. {IDD_DATA_ENTRY_ROUTE_ARRAY, g_aHelpIDs_IDD_DATA_ENTRY_ROUTE_ARRAY},
  230. {IDD_DEFAULT_VALUE, g_aHelpIDs_IDD_DEFAULT_VALUE},
  231. {IDD_DEFINE_PARAM, g_aHelpIDs_IDD_DEFINE_PARAM},
  232. {IDD_EXCLUSION_NEW, g_aHelpIDs_IDD_EXCLUSION_NEW},
  233. {IDD_GET_SERVER, g_aHelpIDs_IDD_GET_SERVER},
  234. {IDD_GET_SERVER_CONFIRM, g_aHelpIDs_IDD_GET_SERVER_CONFIRM},
  235. {IDD_IP_ARRAY_EDIT, g_aHelpIDs_IDD_IP_ARRAY_EDIT},
  236. {IDD_RECONCILIATION, g_aHelpIDs_IDD_RECONCILIATION},
  237. {IDD_RESERVATION_NEW, g_aHelpIDs_IDD_RESERVATION_NEW},
  238. {IDD_SERVER_BINDINGS, g_aHelpIDs_IDD_SERVER_BINDINGS},
  239. {IDD_STATS_NARROW, NULL},
  240. {IDP_BOOTP_GENERAL, g_aHelpIDs_IDP_BOOTP_GENERAL},
  241. {IDP_DNS_INFORMATION, g_aHelpIDs_IDP_DNS_INFORMATION},
  242. {IDP_MSCOPE_GENERAL, g_aHelpIDs_IDP_MSCOPE_GENERAL},
  243. {IDP_MSCOPE_LIFETIME, g_aHelpIDs_IDP_MSCOPE_LIFETIME},
  244. {IDP_OPTION_ADVANCED, g_aHelpIDs_IDP_OPTION_ADVANCED},
  245. {IDP_OPTION_BASIC, g_aHelpIDs_IDP_OPTION_BASIC},
  246. {IDP_RESERVED_CLIENT_GENERAL, g_aHelpIDs_IDP_RESERVED_CLIENT_GENERAL},
  247. {IDP_SCOPE_ADVANCED, g_aHelpIDs_IDP_SCOPE_ADVANCED},
  248. {IDP_SCOPE_GENERAL, g_aHelpIDs_IDP_SCOPE_GENERAL},
  249. {IDP_SERVER_ADVANCED, g_aHelpIDs_IDP_SERVER_ADVANCED},
  250. {IDP_SERVER_GENERAL, g_aHelpIDs_IDP_SERVER_GENERAL},
  251. {IDP_SUPERSCOPE_GENERAL, g_aHelpIDs_IDP_SUPERSCOPE_GENERAL},
  252. {IDD_ADD_ROUTE_DIALOG, g_aHelpIDs_IDD_ADD_ROUTE_DIALOG},
  253. {IDD_ROUTE_ARRAY_EDIT, g_aHelpIDs_IDD_ROUTE_ARRAY_EDIT},
  254. {IDD_STRING_ARRAY_EDIT, g_aHelpIDs_IDD_STRING_ARRAY_EDIT},
  255. };
  256. CDhcpContextHelpMap g_dhcpContextHelpMap;
  257. DWORD * DhcpGetHelpMap(UINT uID)
  258. {
  259. DWORD * pdwMap = NULL;
  260. g_dhcpContextHelpMap.Lookup(uID, pdwMap);
  261. return pdwMap;
  262. }
  263. UINT g_uIconMap[ICON_IDX_MAX + 1][2] =
  264. {
  265. {IDI_ICON01, ICON_IDX_ACTIVE_LEASES_FOLDER_OPEN},
  266. {IDI_ICON02, ICON_IDX_ACTIVE_LEASES_LEAF},
  267. {IDI_ICON03, ICON_IDX_ACTIVE_LEASES_FOLDER_CLOSED},
  268. {IDI_ICON04, ICON_IDX_ACTIVE_LEASES_FOLDER_OPEN_BUSY},
  269. {IDI_ICON05, ICON_IDX_ACTIVE_LEASES_LEAF_BUSY},
  270. {IDI_ICON06, ICON_IDX_ACTIVE_LEASES_FOLDER_CLOSED_BUSY},
  271. {IDI_ICON07, ICON_IDX_ACTIVE_LEASES_FOLDER_OPEN_LOST_CONNECTION},
  272. {IDI_ICON08, ICON_IDX_ACTIVE_LEASES_LEAF_LOST_CONNECTION},
  273. {IDI_ICON09, ICON_IDX_ACTIVE_LEASES_FOLDER_CLOSED_LOST_CONNECTION},
  274. {IDI_ICON10, ICON_IDX_ADDR_POOL_FOLDER_OPEN},
  275. {IDI_ICON11, ICON_IDX_ADDR_POOL_LEAF},
  276. {IDI_ICON12, ICON_IDX_ADDR_POOL_FOLDER_CLOSED},
  277. {IDI_ICON13, ICON_IDX_ADDR_POOL_FOLDER_OPEN_BUSY},
  278. {IDI_ICON14, ICON_IDX_ADDR_POOL_LEAF_BUSY},
  279. {IDI_ICON15, ICON_IDX_ADDR_POOL_FOLDER_CLOSED_BUSY},
  280. {IDI_ICON16, ICON_IDX_ADDR_POOL_FOLDER_OPEN_LOST_CONNECTION},
  281. {IDI_ICON17, ICON_IDX_ADDR_POOL_LEAF_LOST_CONNECTION},
  282. {IDI_ICON18, ICON_IDX_ADDR_POOL_FOLDER_CLOSED_LOST_CONNECTION},
  283. {IDI_ICON19, ICON_IDX_ALLOCATION_RANGE},
  284. {IDI_ICON20, ICON_IDX_BOOTP_ENTRY},
  285. {IDI_ICON21, ICON_IDX_BOOTP_TABLE_CLOSED},
  286. {IDI_ICON22, ICON_IDX_BOOTP_TABLE_OPEN},
  287. {IDI_ICON87, ICON_IDX_BOOTP_TABLE_OPEN_LOST_CONNECTION},
  288. {IDI_ICON88, ICON_IDX_BOOTP_TABLE_OPEN_BUSY},
  289. {IDI_ICON89, ICON_IDX_BOOTP_TABLE_CLOSED_LOST_CONNECTION},
  290. {IDI_ICON90, ICON_IDX_BOOTP_TABLE_CLOSED_BUSY},
  291. {IDI_ICON23, ICON_IDX_CLIENT},
  292. {IDI_ICON24, ICON_IDX_CLIENT_DNS_REGISTERING},
  293. {IDI_ICON25, ICON_IDX_CLIENT_EXPIRED},
  294. {IDI_ICON26, ICON_IDX_CLIENT_RAS},
  295. {IDI_ICON27, ICON_IDX_CLIENT_OPTION_FOLDER_OPEN},
  296. {IDI_ICON28, ICON_IDX_CLIENT_OPTION_LEAF},
  297. {IDI_ICON29, ICON_IDX_CLIENT_OPTION_FOLDER_CLOSED},
  298. {IDI_ICON30, ICON_IDX_CLIENT_OPTION_FOLDER_OPEN_BUSY},
  299. {IDI_ICON31, ICON_IDX_CLIENT_OPTION_LEAF_BUSY},
  300. {IDI_ICON32, ICON_IDX_CLIENT_OPTION_FOLDER_CLOSED_BUSY},
  301. {IDI_ICON33, ICON_IDX_CLIENT_OPTION_FOLDER_OPEN_LOST_CONNECTION},
  302. {IDI_ICON34, ICON_IDX_CLIENT_OPTION_LEAF_LOST_CONNECTION},
  303. {IDI_ICON35, ICON_IDX_CLIENT_OPTION_FOLDER_CLOSED_LOST_CONNECTION},
  304. {IDI_ICON36, ICON_IDX_EXCLUSION_RANGE},
  305. {IDI_ICON37, ICON_IDX_FOLDER_CLOSED},
  306. {IDI_ICON38, ICON_IDX_FOLDER_OPEN},
  307. {IDI_ICON39, ICON_IDX_RES_CLIENT},
  308. {IDI_ICON40, ICON_IDX_RES_CLIENT_BUSY},
  309. {IDI_ICON41, ICON_IDX_RES_CLIENT_LOST_CONNECTION},
  310. {IDI_ICON42, ICON_IDX_RESERVATIONS_FOLDER_OPEN},
  311. {IDI_ICON43, ICON_IDX_RESERVATIONS_FOLDER_CLOSED},
  312. {IDI_ICON44, ICON_IDX_RESERVATIONS_FOLDER_OPEN_BUSY},
  313. {IDI_ICON45, ICON_IDX_RESERVATIONS_FOLDER_CLOSED_BUSY},
  314. {IDI_ICON46, ICON_IDX_RESERVATIONS_FOLDER_OPEN_LOST_CONNECTION},
  315. {IDI_ICON47, ICON_IDX_RESERVATIONS_FOLDER_CLOSED_LOST_CONNECTION},
  316. {IDI_ICON48, ICON_IDX_SCOPE_OPTION_FOLDER_OPEN},
  317. {IDI_ICON49, ICON_IDX_SCOPE_OPTION_LEAF},
  318. {IDI_ICON50, ICON_IDX_SCOPE_OPTION_FOLDER_CLOSED},
  319. {IDI_ICON51, ICON_IDX_SCOPE_OPTION_FOLDER_OPEN_BUSY},
  320. {IDI_ICON52, ICON_IDX_SCOPE_OPTION_LEAF_BUSY},
  321. {IDI_ICON53, ICON_IDX_SCOPE_OPTION_FOLDER_CLOSED_BUSY},
  322. {IDI_ICON54, ICON_IDX_SCOPE_OPTION_FOLDER_OPEN_LOST_CONNECTION},
  323. {IDI_ICON55, ICON_IDX_SCOPE_OPTION_FOLDER_CLOSED_LOST_CONNECTION},
  324. {IDI_ICON56, ICON_IDX_SCOPE_OPTION_LEAF_LOST_CONNECTION},
  325. {IDI_ICON57, ICON_IDX_SERVER},
  326. {IDI_ICON58, ICON_IDX_SERVER_WARNING},
  327. {IDI_ICON59, ICON_IDX_SERVER_BUSY},
  328. {IDI_ICON60, ICON_IDX_SERVER_CONNECTED},
  329. {IDI_ICON61, ICON_IDX_SERVER_GROUP},
  330. {IDI_ICON62, ICON_IDX_SERVER_ROGUE},
  331. {IDI_ICON63, ICON_IDX_SERVER_LOST_CONNECTION},
  332. {IDI_ICON64, ICON_IDX_SERVER_NO_ACCESS},
  333. {IDI_ICON65, ICON_IDX_SERVER_ALERT},
  334. {IDI_ICON66, ICON_IDX_SERVER_OPTION_FOLDER_OPEN},
  335. {IDI_ICON67, ICON_IDX_SERVER_OPTION_LEAF},
  336. {IDI_ICON68, ICON_IDX_SERVER_OPTION_FOLDER_CLOSED},
  337. {IDI_ICON69, ICON_IDX_SERVER_OPTION_FOLDER_OPEN_BUSY},
  338. {IDI_ICON70, ICON_IDX_SERVER_OPTION_LEAF_BUSY},
  339. {IDI_ICON71, ICON_IDX_SERVER_OPTION_FOLDER_CLOSED_BUSY},
  340. {IDI_ICON72, ICON_IDX_SERVER_OPTION_FOLDER_OPEN_LOST_CONNECTION},
  341. {IDI_ICON73, ICON_IDX_SERVER_OPTION_LEAF_LOST_CONNECTION},
  342. {IDI_ICON74, ICON_IDX_SERVER_OPTION_FOLDER_CLOSED_LOST_CONNECTION},
  343. {IDI_ICON75, ICON_IDX_SCOPE_FOLDER_OPEN},
  344. {IDI_ICON91, ICON_IDX_SCOPE_FOLDER_OPEN_BUSY},
  345. {IDI_ICON92, ICON_IDX_SCOPE_FOLDER_CLOSED_BUSY},
  346. {IDI_ICON76, ICON_IDX_SCOPE_FOLDER_OPEN_WARNING},
  347. {IDI_ICON77, ICON_IDX_SCOPE_FOLDER_CLOSED_WARNING},
  348. {IDI_ICON78, ICON_IDX_SCOPE_FOLDER_OPEN_LOST_CONNECTION},
  349. {IDI_ICON79, ICON_IDX_SCOPE_FOLDER_CLOSED_LOST_CONNECTION},
  350. {IDI_ICON80, ICON_IDX_SCOPE_FOLDER_OPEN_ALERT},
  351. {IDI_ICON81, ICON_IDX_SCOPE_INACTIVE_FOLDER_OPEN},
  352. {IDI_ICON82, ICON_IDX_SCOPE_INACTIVE_FOLDER_CLOSED},
  353. {IDI_ICON83, ICON_IDX_SCOPE_INACTIVE_FOLDER_OPEN_LOST_CONNECTION},
  354. {IDI_ICON84, ICON_IDX_SCOPE_INACTIVE_FOLDER_CLOSED_LOST_CONNECTION},
  355. {IDI_ICON85, ICON_IDX_SCOPE_FOLDER_CLOSED},
  356. {IDI_ICON86, ICON_IDX_SCOPE_FOLDER_CLOSED_ALERT},
  357. {IDI_DHCP_SNAPIN, ICON_IDX_APPLICATION},
  358. {0, 0}
  359. };
  360. /*!--------------------------------------------------------------------------
  361. FilterOption
  362. Filters returns whether or not to filter out the given option.
  363. Some options we don't want the user to see.
  364. Author: EricDav
  365. ---------------------------------------------------------------------------*/
  366. BOOL
  367. FilterOption
  368. (
  369. DHCP_OPTION_ID id
  370. )
  371. {
  372. //
  373. // Filter out subnet mask, lease duration,
  374. // T1, and T2
  375. //
  376. return (id == 1 || // Subnet mask
  377. id == 51 || // Client Lease Time
  378. id == 58 || // Time between addr assignment to RENEWING state
  379. id == 59 || // Time from addr assignment to REBINDING state
  380. id == 81); // Client DNS name registration
  381. }
  382. /*!--------------------------------------------------------------------------
  383. FilterUserClassOption
  384. Filters returns whether or not to filter out the given option for
  385. a user class. Some options we don't want the user to see.
  386. Author: EricDav
  387. ---------------------------------------------------------------------------*/
  388. BOOL
  389. FilterUserClassOption
  390. (
  391. DHCP_OPTION_ID id
  392. )
  393. {
  394. //
  395. // Filter out subnet mask,
  396. // T1, and T2
  397. //
  398. return (id == 1 || // Subnet mask
  399. id == 58 || // Time between addr assignment to RENEWING state
  400. id == 59 || // Time from addr assignment to REBINDING state
  401. id == 81); // Client DNS name registration
  402. }
  403. /*!--------------------------------------------------------------------------
  404. IsBasicOption
  405. Returns whether the given option is what we've defined as a
  406. basic option.
  407. Author: EricDav
  408. ---------------------------------------------------------------------------*/
  409. BOOL
  410. IsBasicOption
  411. (
  412. DHCP_OPTION_ID id
  413. )
  414. {
  415. //
  416. // Basic Options are:
  417. // Router
  418. // DNS Server
  419. // Domain Name
  420. // WINS/NBNS Servers
  421. // WINS/NBT Node Type
  422. //
  423. return (id == 3 ||
  424. id == 6 ||
  425. id == 15 ||
  426. id == 44 ||
  427. id == 46);
  428. }
  429. /*!--------------------------------------------------------------------------
  430. IsAdvancedOption
  431. Returns whether the given option is what we've defined as an
  432. advanced option.
  433. Author: EricDav
  434. ---------------------------------------------------------------------------*/
  435. BOOL
  436. IsAdvancedOption
  437. (
  438. DHCP_OPTION_ID id
  439. )
  440. {
  441. //
  442. // All non-basic and non-custom options are advanced.
  443. //
  444. return (id < 128 && !IsBasicOption(id));
  445. }
  446. /*!--------------------------------------------------------------------------
  447. IsCustomOption
  448. Returns whether the given option is a user defined option.
  449. Author: EricDav
  450. ---------------------------------------------------------------------------*/
  451. BOOL
  452. IsCustomOption
  453. (
  454. DHCP_OPTION_ID id
  455. )
  456. {
  457. //
  458. // Custom options are anything with an id > 128
  459. //
  460. return (id > 128);
  461. }
  462. /*!--------------------------------------------------------------------------
  463. GetSystemMessage
  464. Use FormatMessage() to get a system error message
  465. Author: EricDav
  466. ---------------------------------------------------------------------------*/
  467. LONG
  468. GetSystemMessage
  469. (
  470. UINT nId,
  471. TCHAR * chBuffer,
  472. int cbBuffSize
  473. )
  474. {
  475. TCHAR * pszText = NULL ;
  476. HINSTANCE hdll = NULL ;
  477. DWORD flags = FORMAT_MESSAGE_IGNORE_INSERTS
  478. | FORMAT_MESSAGE_MAX_WIDTH_MASK;
  479. //
  480. // Interpret the error. Need to special case
  481. // the lmerr & ntstatus ranges, as well as
  482. // dhcp server error messages.
  483. //
  484. if ( nId >= NERR_BASE && nId <= MAX_NERR )
  485. {
  486. hdll = LoadLibraryEx( _T("netmsg.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE);
  487. }
  488. else
  489. if ( nId >= 20000 && nId <= 20099 )
  490. {
  491. // DHCP Server error
  492. hdll = LoadLibraryEx( _T("dhcpsapi.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE );
  493. }
  494. else
  495. if (nId >= 0x5000 && nId < 0x50FF)
  496. {
  497. // It's an ADSI error.
  498. hdll = LoadLibraryEx( _T("activeds.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE );
  499. nId |= 0x80000000;
  500. }
  501. else
  502. if( nId >= 0x40000000L )
  503. {
  504. hdll = LoadLibraryEx( _T("ntdll.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE );
  505. }
  506. if ( hdll == NULL )
  507. {
  508. flags |= FORMAT_MESSAGE_FROM_SYSTEM;
  509. }
  510. else
  511. {
  512. flags |= FORMAT_MESSAGE_FROM_HMODULE;
  513. }
  514. //
  515. // Let FormatMessage do the dirty work.
  516. //
  517. DWORD dwResult = ::FormatMessage( flags,
  518. (LPVOID) hdll,
  519. nId,
  520. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  521. chBuffer,
  522. cbBuffSize,
  523. NULL ) ;
  524. if ( hdll != NULL )
  525. {
  526. LONG err = GetLastError();
  527. FreeLibrary( hdll );
  528. if ( dwResult == 0 )
  529. {
  530. ::SetLastError( err );
  531. }
  532. }
  533. return dwResult ? 0 : ::GetLastError() ;
  534. }
  535. /*!--------------------------------------------------------------------------
  536. LoadMessage
  537. Loads the error message from the correct DLL.
  538. Author: EricDav
  539. ---------------------------------------------------------------------------*/
  540. BOOL
  541. LoadMessage
  542. (
  543. UINT nIdPrompt,
  544. TCHAR * chMsg,
  545. int nMsgSize
  546. )
  547. {
  548. BOOL bOk;
  549. //
  550. // Substitute a friendly message for "RPC server not
  551. // available" and "No more endpoints available from
  552. // the endpoint mapper".
  553. //
  554. if (nIdPrompt == EPT_S_NOT_REGISTERED ||
  555. nIdPrompt == RPC_S_SERVER_UNAVAILABLE)
  556. {
  557. nIdPrompt = IDS_ERR_DHCP_DOWN;
  558. }
  559. else if (nIdPrompt == RPC_S_PROCNUM_OUT_OF_RANGE)
  560. {
  561. nIdPrompt = IDS_ERR_RPC_NO_ENTRY;
  562. }
  563. //
  564. // If it's a socket error or our error, the text is in our resource fork.
  565. // Otherwise, use FormatMessage() and the appropriate DLL.
  566. //
  567. if ( (nIdPrompt >= IDS_ERR_BASE && nIdPrompt < IDS_MESG_MAX) ||
  568. (nIdPrompt >= WSABASEERR && nIdPrompt < WSABASEERR + 2000)
  569. )
  570. {
  571. //
  572. // It's in our resource fork
  573. //
  574. bOk = ::LoadString( AfxGetInstanceHandle(), nIdPrompt, chMsg, nMsgSize ) != 0 ;
  575. }
  576. else
  577. {
  578. //
  579. // It's in the system somewhere.
  580. //
  581. bOk = GetSystemMessage( nIdPrompt, chMsg, nMsgSize ) == 0 ;
  582. }
  583. //
  584. // If the error message did not compute, replace it.
  585. //
  586. if ( ! bOk )
  587. {
  588. TCHAR chBuff [STRING_LENGTH_MAX] ;
  589. static const TCHAR * pszReplacement = _T("System Error: %ld");
  590. const TCHAR * pszMsg = pszReplacement ;
  591. //
  592. // Try to load the generic (translatable) error message text
  593. //
  594. if ( ::LoadString( AfxGetInstanceHandle(), IDS_ERR_MESSAGE_GENERIC,
  595. chBuff, sizeof(chBuff)/sizeof(TCHAR) ) != 0 )
  596. {
  597. pszMsg = chBuff ;
  598. }
  599. ::wsprintf( chMsg, pszMsg, nIdPrompt ) ;
  600. }
  601. return bOk;
  602. }
  603. /*!--------------------------------------------------------------------------
  604. DhcpMessageBox
  605. Puts up a message box with the corresponding error text.
  606. Author: EricDav
  607. ---------------------------------------------------------------------------*/
  608. int
  609. DhcpMessageBox
  610. (
  611. DWORD dwIdPrompt,
  612. UINT nType,
  613. const TCHAR * pszSuffixString,
  614. UINT nHelpContext
  615. )
  616. {
  617. TCHAR chMesg [4000] ;
  618. BOOL bOk ;
  619. UINT nIdPrompt = (UINT) dwIdPrompt;
  620. bOk = LoadMessage(nIdPrompt, chMesg, sizeof(chMesg)/sizeof(TCHAR));
  621. if ( pszSuffixString )
  622. {
  623. ::lstrcat( chMesg, _T(" ") ) ;
  624. ::lstrcat( chMesg, pszSuffixString ) ;
  625. }
  626. return ::AfxMessageBox( chMesg, nType, nHelpContext ) ;
  627. }
  628. /*!--------------------------------------------------------------------------
  629. DhcpMessageBoxEx
  630. Puts up a message box with the corresponding error text.
  631. Author: EricDav
  632. ---------------------------------------------------------------------------*/
  633. int
  634. DhcpMessageBoxEx
  635. (
  636. DWORD dwIdPrompt,
  637. LPCTSTR pszPrefixMessage,
  638. UINT nType,
  639. UINT nHelpContext
  640. )
  641. {
  642. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  643. TCHAR chMesg[4000];
  644. CString strMessage;
  645. BOOL bOk;
  646. UINT nIdPrompt = (UINT) dwIdPrompt;
  647. bOk = LoadMessage(nIdPrompt, chMesg, sizeof(chMesg)/sizeof(TCHAR));
  648. if ( pszPrefixMessage )
  649. {
  650. strMessage = pszPrefixMessage;
  651. strMessage += _T("\n");
  652. strMessage += _T("\n");
  653. strMessage += chMesg;
  654. }
  655. else
  656. {
  657. strMessage = chMesg;
  658. }
  659. return AfxMessageBox(strMessage, nType, nHelpContext);
  660. }
  661. /*---------------------------------------------------------------------------
  662. Class CDhcpComponent implementation
  663. ---------------------------------------------------------------------------*/
  664. CDhcpComponent::CDhcpComponent()
  665. {
  666. m_pbmpToolbar = NULL;
  667. InitCommonControls();
  668. }
  669. CDhcpComponent::~CDhcpComponent()
  670. {
  671. if (m_pbmpToolbar)
  672. {
  673. delete m_pbmpToolbar;
  674. m_pbmpToolbar = NULL;
  675. }
  676. }
  677. STDMETHODIMP CDhcpComponent::InitializeBitmaps(MMC_COOKIE cookie)
  678. {
  679. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  680. ASSERT(m_spImageList != NULL);
  681. // Set the images
  682. HICON hIcon;
  683. HRESULT hr;
  684. LPOLESTR pszGuid = NULL;
  685. long lViewOptions = 0;
  686. CLSID clsid;
  687. CORg (GetResultViewType(cookie, &pszGuid, &lViewOptions));
  688. CLSIDFromString(pszGuid, &clsid);
  689. CoTaskMemFree( pszGuid );
  690. // if the result pane is not the message view then add the icons
  691. if (clsid != CLSID_MessageView)
  692. {
  693. for (int i = 0; i < ICON_IDX_MAX; i++)
  694. {
  695. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  696. if (hIcon)
  697. {
  698. // call mmc
  699. hr = m_spImageList->ImageListSetIcon(reinterpret_cast<LONG_PTR*>(hIcon), g_uIconMap[i][1]);
  700. }
  701. }
  702. }
  703. Error:
  704. return S_OK;
  705. }
  706. /*!--------------------------------------------------------------------------
  707. CDhcpComponentData::QueryDataObject
  708. For multiple select we need to add things to the data object.....
  709. In order to do this we need to call into the result handler for
  710. the node
  711. Author: EricDav
  712. ---------------------------------------------------------------------------*/
  713. STDMETHODIMP CDhcpComponent::QueryDataObject
  714. (
  715. MMC_COOKIE cookie,
  716. DATA_OBJECT_TYPES type,
  717. LPDATAOBJECT* ppDataObject
  718. )
  719. {
  720. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  721. HRESULT hr = hrOK;
  722. SPITFSNode spRootNode;
  723. // this is a special case for multiple select. We need to build a list
  724. // of GUIDs and the code to do this is in the handler...
  725. if (cookie == MMC_MULTI_SELECT_COOKIE)
  726. {
  727. SPITFSNode spNode;
  728. SPITFSResultHandler spResultHandler;
  729. CORg (GetSelectedNode(&spNode));
  730. CORg (spNode->GetResultHandler(&spResultHandler));
  731. spResultHandler->OnCreateDataObject(this, cookie, type, ppDataObject);
  732. }
  733. else
  734. if (cookie == MMC_WINDOW_COOKIE)
  735. {
  736. // this cookie needs the text for the static root node, so build the DO with
  737. // the root node cookie
  738. m_spNodeMgr->GetRootNode(&spRootNode);
  739. CORg (m_spComponentData->QueryDataObject((MMC_COOKIE) spRootNode->GetData(TFS_DATA_COOKIE), type, ppDataObject));
  740. }
  741. else
  742. {
  743. // Delegate it to the IComponentData
  744. Assert(m_spComponentData != NULL);
  745. CORg (m_spComponentData->QueryDataObject(cookie, type, ppDataObject));
  746. }
  747. Error:
  748. return hr;
  749. }
  750. /*!--------------------------------------------------------------------------
  751. CDhcpComponentData::SetControlbar
  752. -
  753. Author: EricDav, KennT
  754. ---------------------------------------------------------------------------*/
  755. HRESULT
  756. CDhcpComponent::SetControlbar
  757. (
  758. LPCONTROLBAR pControlbar
  759. )
  760. {
  761. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  762. HRESULT hr = hrOK;
  763. SPIToolbar spToolbar;
  764. COM_PROTECT_TRY
  765. {
  766. if (pControlbar)
  767. {
  768. // Create the Toolbar
  769. GetToolbar(&spToolbar);
  770. if (!spToolbar)
  771. {
  772. CORg(pControlbar->Create(TOOLBAR, this, reinterpret_cast<LPUNKNOWN*>(&spToolbar)));
  773. if (!spToolbar)
  774. goto Error;
  775. SetToolbar(spToolbar);
  776. // Add the bitmap
  777. m_pbmpToolbar = new CBitmap;
  778. m_pbmpToolbar->LoadBitmap(IDB_TOOLBAR);
  779. hr = spToolbar->AddBitmap(TOOLBAR_IDX_MAX, *m_pbmpToolbar, 16, 16, RGB(192, 192, 192));
  780. ASSERT(SUCCEEDED(hr));
  781. // Add the buttons to the toolbar
  782. for (int i = 0; i < TOOLBAR_IDX_MAX; i++)
  783. {
  784. CString strText, strTooltip;
  785. strText.LoadString(g_SnapinButtonStrings[i][0]);
  786. strTooltip.LoadString(g_SnapinButtonStrings[i][1]);
  787. g_SnapinButtons[i].lpButtonText = (LPOLESTR) ((LPCTSTR) strText);
  788. g_SnapinButtons[i].lpTooltipText = (LPOLESTR) ((LPCTSTR) strTooltip);
  789. hr = spToolbar->InsertButton(i, &g_SnapinButtons[i]);
  790. ASSERT(SUCCEEDED(hr));
  791. }
  792. }
  793. }
  794. }
  795. COM_PROTECT_CATCH
  796. // store the control bar away for future use
  797. Error:
  798. m_spControlbar.Set(pControlbar);
  799. return hr;
  800. }
  801. /*!--------------------------------------------------------------------------
  802. CDhcpComponentData::ControlbarNotify
  803. -
  804. Author: EricDav
  805. ---------------------------------------------------------------------------*/
  806. STDMETHODIMP
  807. CDhcpComponent::ControlbarNotify
  808. (
  809. MMC_NOTIFY_TYPE event,
  810. LPARAM arg,
  811. LPARAM param
  812. )
  813. {
  814. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  815. HRESULT hr = hrOK;
  816. SPINTERNAL spInternal;
  817. SPITFSNode spNode;
  818. MMC_COOKIE cookie;
  819. LPDATAOBJECT pDataObject;
  820. SPIDataObject spDataObject;
  821. DHCPTOOLBARNOTIFY dhcpToolbarNotify;
  822. SPIControlBar spControlbar;
  823. SPIToolbar spToolbar;
  824. SPITFSNodeHandler spNodeHandler;
  825. SPITFSResultHandler spResultHandler;
  826. BOOL bScope;
  827. BOOL bSelect;
  828. COM_PROTECT_TRY
  829. {
  830. CORg(GetControlbar(&spControlbar));
  831. Assert(spControlbar != NULL);
  832. CORg(GetToolbar(&spToolbar));
  833. Assert(spToolbar != NULL);
  834. // set the controlbar and toolbar pointers in the notify struct
  835. dhcpToolbarNotify.pControlbar = spControlbar;
  836. dhcpToolbarNotify.pToolbar = spToolbar;
  837. switch (event)
  838. {
  839. case MMCN_SELECT:
  840. // extract the node information from the data object
  841. bScope = LOWORD(arg);
  842. bSelect = HIWORD(arg);
  843. if (!bScope)
  844. {
  845. Assert(param);
  846. pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  847. if (pDataObject == NULL)
  848. return hr;
  849. if ( IS_SPECIAL_DATAOBJECT(pDataObject) ||
  850. IsMMCMultiSelectDataObject(pDataObject) )
  851. {
  852. // CODEWORK: Do we need to do anything special to the toolbar
  853. // during multiselect? Disable our toolbar buttons?
  854. GetSelectedNode(&spNode);
  855. }
  856. else
  857. {
  858. CORg(ExtractNodeFromDataObject(m_spNodeMgr,
  859. m_spTFSComponentData->GetCoClassID(),
  860. pDataObject,
  861. FALSE,
  862. &spNode,
  863. NULL,
  864. &spInternal));
  865. if (spInternal->m_type == CCT_RESULT)
  866. {
  867. // a result item was selected
  868. cookie = spNode->GetData(TFS_DATA_COOKIE);
  869. }
  870. else
  871. {
  872. // a scope item in the result pane was selected
  873. cookie = NULL;
  874. }
  875. }
  876. if (spNode)
  877. {
  878. CORg( spNode->GetResultHandler(&spResultHandler) );
  879. dhcpToolbarNotify.event = event;
  880. dhcpToolbarNotify.id = param;
  881. dhcpToolbarNotify.bSelect = bSelect;
  882. if (spResultHandler)
  883. CORg( spResultHandler->UserResultNotify(spNode, DHCP_MSG_CONTROLBAR_NOTIFY, (LPARAM) &dhcpToolbarNotify) );
  884. }
  885. }
  886. else
  887. {
  888. dhcpToolbarNotify.cookie = 0;
  889. dhcpToolbarNotify.event = event;
  890. dhcpToolbarNotify.id = 0;
  891. dhcpToolbarNotify.bSelect = bSelect;
  892. // check to see if an item is being deselected
  893. Assert(param);
  894. pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  895. if (pDataObject == NULL)
  896. return hr;
  897. CORg(ExtractNodeFromDataObject(m_spNodeMgr,
  898. m_spTFSComponentData->GetCoClassID(),
  899. pDataObject,
  900. FALSE,
  901. &spNode,
  902. NULL,
  903. &spInternal));
  904. CORg( spNode->GetHandler(&spNodeHandler) );
  905. if (spNodeHandler)
  906. CORg( spNodeHandler->UserNotify(spNode, DHCP_MSG_CONTROLBAR_NOTIFY, (LPARAM) &dhcpToolbarNotify) );
  907. }
  908. break;
  909. case MMCN_BTN_CLICK:
  910. Assert(arg);
  911. pDataObject = reinterpret_cast<LPDATAOBJECT>(arg);
  912. if (pDataObject == NULL)
  913. return hr;
  914. if ( IS_SPECIAL_DATAOBJECT(pDataObject) )
  915. {
  916. // get a data object for the selected node.
  917. GetSelectedNode(&spNode);
  918. CORg(QueryDataObject((MMC_COOKIE) spNode->GetData(TFS_DATA_COOKIE), CCT_SCOPE, &spDataObject));
  919. spNode.Release();
  920. pDataObject = spDataObject;
  921. }
  922. CORg(ExtractNodeFromDataObject(m_spNodeMgr,
  923. m_spTFSComponentData->GetCoClassID(),
  924. pDataObject,
  925. FALSE,
  926. &spNode,
  927. NULL,
  928. &spInternal));
  929. if (spInternal)
  930. {
  931. switch (spInternal->m_type)
  932. {
  933. case CCT_RESULT:
  934. cookie = spNode->GetData(TFS_DATA_COOKIE);
  935. CORg( spNode->GetResultHandler(&spResultHandler) );
  936. dhcpToolbarNotify.cookie = cookie;
  937. dhcpToolbarNotify.event = event;
  938. dhcpToolbarNotify.id = param;
  939. dhcpToolbarNotify.bSelect = TRUE;
  940. if (spResultHandler)
  941. CORg( spResultHandler->UserResultNotify(spNode,
  942. DHCP_MSG_CONTROLBAR_NOTIFY,
  943. (LPARAM) &dhcpToolbarNotify) );
  944. break;
  945. case CCT_SCOPE:
  946. CORg( spNode->GetHandler(&spNodeHandler) );
  947. dhcpToolbarNotify.cookie = 0;
  948. dhcpToolbarNotify.event = event;
  949. dhcpToolbarNotify.id = param;
  950. dhcpToolbarNotify.bSelect = TRUE;
  951. if (spNodeHandler)
  952. CORg( spNodeHandler->UserNotify(spNode,
  953. DHCP_MSG_CONTROLBAR_NOTIFY,
  954. (LPARAM) &dhcpToolbarNotify) );
  955. break;
  956. default:
  957. Assert(FALSE);
  958. break;
  959. }
  960. }
  961. break;
  962. case MMCN_DESELECT_ALL:
  963. // what are we supposed to do here???
  964. break;
  965. default:
  966. Panic1("CDhcpComponent::ControlbarNotify - Unknown event %d", event);
  967. break;
  968. }
  969. COM_PROTECT_ERROR_LABEL;
  970. }
  971. COM_PROTECT_CATCH
  972. return hr;
  973. }
  974. /*!--------------------------------------------------------------------------
  975. CDhcpComponentData::OnSnapinHelp
  976. -
  977. Author: EricDav
  978. ---------------------------------------------------------------------------*/
  979. STDMETHODIMP
  980. CDhcpComponent::OnSnapinHelp
  981. (
  982. LPDATAOBJECT pDataObject,
  983. LPARAM arg,
  984. LPARAM param
  985. )
  986. {
  987. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  988. HRESULT hr = hrOK;
  989. HtmlHelpA(NULL, DHCPSNAP_HELP_FILE_NAME, HH_DISPLAY_TOPIC, 0);
  990. return hr;
  991. }
  992. /*---------------------------------------------------------------------------
  993. Class CDhcpComponentData implementation
  994. ---------------------------------------------------------------------------*/
  995. CDhcpComponentData::CDhcpComponentData()
  996. {
  997. gliDhcpsnapVersion.LowPart = DHCPSNAP_MINOR_VERSION;
  998. gliDhcpsnapVersion.HighPart = DHCPSNAP_MAJOR_VERSION;
  999. // initialize our global help map
  1000. for (int i = 0; i < DHCPSNAP_NUM_HELP_MAPS; i++)
  1001. {
  1002. g_dhcpContextHelpMap.SetAt(g_uContextHelp[i].uID, (LPDWORD) g_uContextHelp[i].pdwMap);
  1003. }
  1004. }
  1005. /*!--------------------------------------------------------------------------
  1006. CDhcpComponentData::OnInitialize
  1007. -
  1008. Author: EricDav, KennT
  1009. ---------------------------------------------------------------------------*/
  1010. STDMETHODIMP CDhcpComponentData::OnInitialize(LPIMAGELIST pScopeImage)
  1011. {
  1012. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1013. HICON hIcon;
  1014. // thread deletes itself
  1015. CStandaloneAuthServerWorker * pWorker = new CStandaloneAuthServerWorker();
  1016. pWorker->CreateThread();
  1017. // initialize icon images with MMC
  1018. for (int i = 0; i < ICON_IDX_MAX; i++)
  1019. {
  1020. hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  1021. if (hIcon)
  1022. {
  1023. // call mmc
  1024. VERIFY(SUCCEEDED(pScopeImage->ImageListSetIcon(reinterpret_cast<LONG_PTR*>(hIcon), g_uIconMap[i][1])));
  1025. }
  1026. }
  1027. return hrOK;
  1028. }
  1029. /*!--------------------------------------------------------------------------
  1030. CDhcpComponentData::OnDestroy
  1031. -
  1032. Author: EricDav, KennT
  1033. ---------------------------------------------------------------------------*/
  1034. STDMETHODIMP CDhcpComponentData::OnDestroy()
  1035. {
  1036. m_spNodeMgr.Release();
  1037. return hrOK;
  1038. }
  1039. /*!--------------------------------------------------------------------------
  1040. CDhcpComponentData::OnInitializeNodeMgr
  1041. -
  1042. Author: KennT
  1043. ---------------------------------------------------------------------------*/
  1044. STDMETHODIMP
  1045. CDhcpComponentData::OnInitializeNodeMgr
  1046. (
  1047. ITFSComponentData * pTFSCompData,
  1048. ITFSNodeMgr * pNodeMgr
  1049. )
  1050. {
  1051. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1052. // For now create a new node handler for each new node,
  1053. // this is rather bogus as it can get expensive. We can
  1054. // consider creating only a single node handler for each
  1055. // node type.
  1056. CDhcpRootHandler * pHandler = NULL;
  1057. SPITFSNodeHandler spHandler;
  1058. SPITFSNode spNode;
  1059. HRESULT hr = hrOK;
  1060. try
  1061. {
  1062. pHandler = new CDhcpRootHandler(pTFSCompData);
  1063. // Do this so that it will get released correctly
  1064. spHandler = pHandler;
  1065. }
  1066. catch(...)
  1067. {
  1068. hr = E_OUTOFMEMORY;
  1069. }
  1070. CORg( hr );
  1071. // Create the root node for this sick puppy
  1072. CORg( CreateContainerTFSNode(&spNode,
  1073. &GUID_DhcpRootNodeType,
  1074. pHandler,
  1075. pHandler, /* result handler */
  1076. pNodeMgr) );
  1077. // Need to initialize the data for the root node
  1078. pHandler->InitializeNode(spNode);
  1079. CORg( pNodeMgr->SetRootNode(spNode) );
  1080. m_spRootNode.Set(spNode);
  1081. // setup watermark info
  1082. if (g_WatermarkInfoServer.hHeader == NULL)
  1083. {
  1084. // haven't been initialized yet
  1085. InitWatermarkInfo(AfxGetInstanceHandle(),
  1086. &g_WatermarkInfoServer,
  1087. IDB_SRVWIZ_BANNER, // Header ID
  1088. IDB_SRVWIZ_WATERMARK, // Watermark ID
  1089. NULL, // hPalette
  1090. FALSE); // bStretch
  1091. InitWatermarkInfo(AfxGetInstanceHandle(),
  1092. &g_WatermarkInfoScope,
  1093. IDB_SCPWIZ_BANNER, // Header ID
  1094. IDB_SCPWIZ_WATERMARK, // Watermark ID
  1095. NULL, // hPalette
  1096. FALSE); // bStretch
  1097. }
  1098. pTFSCompData->SetHTMLHelpFileName(_T(DHCPSNAP_HELP_FILE_NAME));
  1099. // disable taskpads by default
  1100. pTFSCompData->SetTaskpadState(TASKPAD_ROOT_INDEX, FALSE);
  1101. pTFSCompData->SetTaskpadState(TASKPAD_SERVER_INDEX, FALSE);
  1102. Error:
  1103. return hr;
  1104. }
  1105. /*!--------------------------------------------------------------------------
  1106. CDhcpComponentData::OnCreateComponent
  1107. -
  1108. Author: EricDav, KennT
  1109. ---------------------------------------------------------------------------*/
  1110. STDMETHODIMP
  1111. CDhcpComponentData::OnCreateComponent
  1112. (
  1113. LPCOMPONENT *ppComponent
  1114. )
  1115. {
  1116. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1117. ASSERT(ppComponent != NULL);
  1118. HRESULT hr = hrOK;
  1119. CDhcpComponent * pComp = NULL;
  1120. try
  1121. {
  1122. pComp = new CDhcpComponent;
  1123. }
  1124. catch(...)
  1125. {
  1126. hr = E_OUTOFMEMORY;
  1127. }
  1128. if ( NULL != pComp )
  1129. {
  1130. pComp->Construct( m_spNodeMgr,
  1131. static_cast<IComponentData *>(this),
  1132. m_spTFSComponentData );
  1133. *ppComponent = static_cast<IComponent *>(pComp);
  1134. }
  1135. else {
  1136. hr = E_OUTOFMEMORY;
  1137. }
  1138. return hr;
  1139. }
  1140. /*!--------------------------------------------------------------------------
  1141. CDhcpComponentData::GetCoClassID
  1142. -
  1143. Author: KennT
  1144. ---------------------------------------------------------------------------*/
  1145. STDMETHODIMP_(const CLSID *)
  1146. CDhcpComponentData::GetCoClassID()
  1147. {
  1148. return &CLSID_DhcpSnapin;
  1149. }
  1150. /*!--------------------------------------------------------------------------
  1151. CDhcpComponentData::OnCreateDataObject
  1152. -
  1153. Author: KennT
  1154. ---------------------------------------------------------------------------*/
  1155. STDMETHODIMP
  1156. CDhcpComponentData::OnCreateDataObject
  1157. (
  1158. MMC_COOKIE cookie,
  1159. DATA_OBJECT_TYPES type,
  1160. IDataObject ** ppDataObject
  1161. )
  1162. {
  1163. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1164. Assert(ppDataObject != NULL);
  1165. CDataObject * pObject = NULL;
  1166. SPIDataObject spDataObject;
  1167. pObject = new CDataObject;
  1168. spDataObject = pObject; // do this so that it gets released correctly
  1169. Assert(pObject != NULL);
  1170. // Save cookie and type for delayed rendering
  1171. pObject->SetType(type);
  1172. pObject->SetCookie(cookie);
  1173. // Store the coclass with the data object
  1174. pObject->SetClsid(*GetCoClassID());
  1175. pObject->SetTFSComponentData(m_spTFSComponentData);
  1176. return pObject->QueryInterface(IID_IDataObject,
  1177. reinterpret_cast<void**>(ppDataObject));
  1178. }
  1179. ///////////////////////////////////////////////////////////////////////////////
  1180. //// IPersistStream interface members
  1181. STDMETHODIMP
  1182. CDhcpComponentData::GetClassID
  1183. (
  1184. CLSID *pClassID
  1185. )
  1186. {
  1187. ASSERT(pClassID != NULL);
  1188. // Copy the CLSID for this snapin
  1189. *pClassID = CLSID_DhcpSnapin;
  1190. return hrOK;
  1191. }
  1192. STDMETHODIMP
  1193. CDhcpComponentData::IsDirty()
  1194. {
  1195. return m_spRootNode->GetData(TFS_DATA_DIRTY) ? hrOK : hrFalse;
  1196. }
  1197. STDMETHODIMP
  1198. CDhcpComponentData::Load
  1199. (
  1200. IStream *pStm
  1201. )
  1202. {
  1203. HRESULT hr = hrOK;
  1204. LARGE_INTEGER liSavedVersion;
  1205. CString str;
  1206. ASSERT(pStm);
  1207. CStringArray strArrayIp;
  1208. CStringArray strArrayName;
  1209. CDWordArray dwArrayServerOptions;
  1210. CDWordArray dwArrayRefreshInterval;
  1211. CDWordArray dwArrayColumnInfo;
  1212. DWORD dwFileVersion;
  1213. CDhcpRootHandler * pRootHandler;
  1214. DWORD dwFlags = 0;
  1215. int i, j;
  1216. ASSERT(pStm);
  1217. // set the mode for this stream
  1218. XferStream xferStream(pStm, XferStream::MODE_READ);
  1219. // read the version of the file format
  1220. CORg(xferStream.XferDWORD(DHCPSTRM_TAG_VERSION, &dwFileVersion));
  1221. if (dwFileVersion < DHCPSNAP_FILE_VERSION)
  1222. {
  1223. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1224. AfxMessageBox(_T("This console file was saved with a previous version of the snapin and is not compatible. The settings could not be restored."));
  1225. return hr;
  1226. }
  1227. // Read the version # of the admin tool
  1228. CORg(xferStream.XferLARGEINTEGER(DHCPSTRM_TAG_VERSIONADMIN, &liSavedVersion));
  1229. if (liSavedVersion.QuadPart < gliDhcpsnapVersion.QuadPart)
  1230. {
  1231. // File is an older version. Warn the user and then don't
  1232. // load anything else
  1233. Assert(FALSE);
  1234. }
  1235. // Read the root node name
  1236. CORg(xferStream.XferCString(DHCPSTRM_TAB_SNAPIN_NAME, &str));
  1237. Assert(m_spRootNode);
  1238. pRootHandler = GETHANDLER(CDhcpRootHandler, m_spRootNode);
  1239. pRootHandler->SetDisplayName(str);
  1240. // now read all of the server information
  1241. CORg(xferStream.XferCStringArray(DHCPSTRM_TAG_SERVER_IP, &strArrayIp));
  1242. CORg(xferStream.XferCStringArray(DHCPSTRM_TAG_SERVER_NAME, &strArrayName));
  1243. CORg(xferStream.XferDWORDArray(DHCPSTRM_TAG_SERVER_OPTIONS, &dwArrayServerOptions));
  1244. CORg(xferStream.XferDWORDArray(DHCPSTRM_TAG_SERVER_REFRESH_INTERVAL, &dwArrayRefreshInterval));
  1245. // now load the column information
  1246. for (i = 0; i < NUM_SCOPE_ITEMS; i++)
  1247. {
  1248. CORg(xferStream.XferDWORDArray(DHCPSTRM_TAG_COLUMN_INFO, &dwArrayColumnInfo));
  1249. for (j = 0; j < MAX_COLUMNS; j++)
  1250. {
  1251. // mmc now saves column widths for us, but we don't want to change the
  1252. // format of this file, so just don't set our internal struct
  1253. //aColumnWidths[i][j] = dwArrayColumnInfo[j];
  1254. }
  1255. }
  1256. // now create the servers based on the information
  1257. for (i = 0; i < strArrayIp.GetSize(); i++)
  1258. {
  1259. //
  1260. // now create the server object
  1261. //
  1262. pRootHandler->AddServer((LPCWSTR) strArrayIp[i],
  1263. strArrayName[i],
  1264. FALSE,
  1265. dwArrayServerOptions[i],
  1266. dwArrayRefreshInterval[i]);
  1267. }
  1268. // read in flags (for taskpads)
  1269. CORg(xferStream.XferDWORD(DHCPSTRM_TAG_SNAPIN_OPTIONS, &dwFlags));
  1270. if (!FUseTaskpadsByDefault(NULL))
  1271. dwFlags = 0;
  1272. // disable taskpads, the default is off
  1273. //m_spTFSComponentData->SetTaskpadState(TASKPAD_ROOT_INDEX, dwFlags & TASKPAD_ROOT_FLAG);
  1274. //m_spTFSComponentData->SetTaskpadState(TASKPAD_SERVER_INDEX, dwFlags & TASKPAD_SERVER_FLAG);
  1275. Error:
  1276. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  1277. }
  1278. STDMETHODIMP
  1279. CDhcpComponentData::Save
  1280. (
  1281. IStream *pStm,
  1282. BOOL fClearDirty
  1283. )
  1284. {
  1285. HRESULT hr = hrOK;
  1286. CStringArray strArrayIp;
  1287. CStringArray strArrayName;
  1288. CDWordArray dwArrayServerOptions;
  1289. CDWordArray dwArrayRefreshInterval;
  1290. CDWordArray dwArrayColumnInfo;
  1291. CString str;
  1292. DWORD dwFileVersion = DHCPSNAP_FILE_VERSION;
  1293. CDhcpRootHandler * pRootHandler;
  1294. SPITFSNodeEnum spNodeEnum;
  1295. SPITFSNode spCurrentNode;
  1296. ULONG nNumReturned = 0;
  1297. int nNumServers = 0, nVisibleCount = 0;
  1298. int i, j, nCount = 0;
  1299. CDhcpServer * pServer;
  1300. DWORD dwFlags = 0;
  1301. ASSERT(pStm);
  1302. // set the mode for this stream
  1303. XferStream xferStream(pStm, XferStream::MODE_WRITE);
  1304. // Write the version # of the file format
  1305. CORg(xferStream.XferDWORD(DHCPSTRM_TAG_VERSION, &dwFileVersion));
  1306. // Write the version # of the admin tool
  1307. CORg(xferStream.XferLARGEINTEGER(DHCPSTRM_TAG_VERSIONADMIN, &gliDhcpsnapVersion));
  1308. // write the root node name
  1309. Assert(m_spRootNode);
  1310. pRootHandler = GETHANDLER(CDhcpRootHandler, m_spRootNode);
  1311. str = pRootHandler->GetDisplayName();
  1312. CORg(xferStream.XferCString(DHCPSTRM_TAB_SNAPIN_NAME, &str));
  1313. //
  1314. // Build our array of servers
  1315. //
  1316. hr = m_spRootNode->GetChildCount(&nVisibleCount, &nNumServers);
  1317. strArrayIp.SetSize(nNumServers);
  1318. strArrayName.SetSize(nNumServers);
  1319. dwArrayServerOptions.SetSize(nNumServers);
  1320. dwArrayRefreshInterval.SetSize(nNumServers);
  1321. dwArrayColumnInfo.SetSize(MAX_COLUMNS);
  1322. //
  1323. // loop and save off all the server's attributes
  1324. //
  1325. m_spRootNode->GetEnum(&spNodeEnum);
  1326. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  1327. while (nNumReturned)
  1328. {
  1329. pServer = GETHANDLER(CDhcpServer, spCurrentNode);
  1330. // query the server for it's options:
  1331. // auto refresh, bootp and classid visibility
  1332. // NOTE: the audit logging state is also kept in here, but
  1333. // it will get updated when the server node is enumerated
  1334. dwArrayServerOptions[nCount] = pServer->GetServerOptions();
  1335. pServer->GetAutoRefresh(NULL, &dwArrayRefreshInterval[nCount]);
  1336. // put the information in our array
  1337. strArrayIp[nCount] = pServer->GetIpAddress();
  1338. strArrayName[nCount] = pServer->GetName();
  1339. // go to the next node
  1340. spCurrentNode.Release();
  1341. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  1342. nCount++;
  1343. }
  1344. // now write out all of the server information
  1345. CORg(xferStream.XferCStringArray(DHCPSTRM_TAG_SERVER_IP, &strArrayIp));
  1346. CORg(xferStream.XferCStringArray(DHCPSTRM_TAG_SERVER_NAME, &strArrayName));
  1347. CORg(xferStream.XferDWORDArray(DHCPSTRM_TAG_SERVER_OPTIONS, &dwArrayServerOptions));
  1348. CORg(xferStream.XferDWORDArray(DHCPSTRM_TAG_SERVER_REFRESH_INTERVAL, &dwArrayRefreshInterval));
  1349. // now save the column information
  1350. for (i = 0; i < NUM_SCOPE_ITEMS; i++)
  1351. {
  1352. CORg(xferStream.XferDWORDArray(DHCPSTRM_TAG_COLUMN_INFO, &dwArrayColumnInfo));
  1353. for (j = 0; j < MAX_COLUMNS; j++)
  1354. {
  1355. dwArrayColumnInfo[j] = aColumnWidths[i][j];
  1356. }
  1357. }
  1358. if (fClearDirty)
  1359. {
  1360. m_spRootNode->SetData(TFS_DATA_DIRTY, FALSE);
  1361. }
  1362. // save off taskpad states
  1363. // root node taskpad state
  1364. if (m_spTFSComponentData->GetTaskpadState(TASKPAD_ROOT_INDEX))
  1365. dwFlags |= TASKPAD_ROOT_FLAG;
  1366. // server node taskpad state
  1367. if (m_spTFSComponentData->GetTaskpadState(TASKPAD_SERVER_INDEX))
  1368. dwFlags |= TASKPAD_SERVER_FLAG;
  1369. CORg(xferStream.XferDWORD(DHCPSTRM_TAG_SNAPIN_OPTIONS, &dwFlags));
  1370. Error:
  1371. return SUCCEEDED(hr) ? S_OK : STG_E_CANTSAVE;
  1372. }
  1373. STDMETHODIMP
  1374. CDhcpComponentData::GetSizeMax
  1375. (
  1376. ULARGE_INTEGER *pcbSize
  1377. )
  1378. {
  1379. ASSERT(pcbSize);
  1380. // Set the size of the string to be saved
  1381. ULISet32(*pcbSize, 10240);
  1382. return S_OK;
  1383. }
  1384. STDMETHODIMP
  1385. CDhcpComponentData::InitNew()
  1386. {
  1387. return hrOK;
  1388. }
  1389. HRESULT
  1390. CDhcpComponentData::FinalConstruct()
  1391. {
  1392. HRESULT hr = hrOK;
  1393. hr = CComponentData::FinalConstruct();
  1394. if (FHrSucceeded(hr))
  1395. {
  1396. m_spTFSComponentData->GetNodeMgr(&m_spNodeMgr);
  1397. }
  1398. return hr;
  1399. }
  1400. void
  1401. CDhcpComponentData::FinalRelease()
  1402. {
  1403. DhcpDsCleanup();
  1404. CComponentData::FinalRelease();
  1405. }