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.

1217 lines
35 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) Microsoft Corporation, 1995 - 1999
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. // You will need the NT SUR Beta 2 SDK or VC 4.2 in order to build this
  9. // project. This is because you will need MIDL 3.00.15 or higher and new
  10. // headers and libs. If you have VC 4.2 installed, then everything should
  11. // already be configured correctly.
  12. #include "preDNSsn.h"
  13. #include <SnapBase.h>
  14. #include "resource.h"
  15. #include "dnsutil.h"
  16. #include "DNSSnap.h"
  17. #include "snapdata.h"
  18. #include "server.h"
  19. #include "domain.h"
  20. #include "record.h"
  21. #include "zone.h"
  22. #include "HelpArr.h" // context help ID's
  23. #ifdef DEBUG_ALLOCATOR
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. #endif
  30. //////////////////////////////////////////////////////////////////////////////
  31. // regsvr debugging
  32. // define to enable MsgBox debugging for regsvr32
  33. //#define _MSGBOX_ON_REG_FAIL
  34. #ifdef _MSGBOX_ON_REG_FAIL
  35. #define _MSGBOX(x) AfxMessageBox(x)
  36. #else
  37. #define _MSGBOX(x)
  38. #endif
  39. #ifdef _MSGBOX_ON_REG_FAIL
  40. #define _REPORT_FAIL(lpszMessage, lpszClsid, lRes) \
  41. ReportFail(lpszMessage, lpszClsid, lRes)
  42. void ReportFail(LPCWSTR lpszMessage, LPCWSTR lpszClsid, LONG lRes)
  43. {
  44. if (lRes == ERROR_SUCCESS)
  45. return;
  46. CString sz;
  47. sz.Format(_T("%s %s %d"), lpszMessage,lpszClsid, lRes);
  48. AfxMessageBox(sz);
  49. }
  50. #else
  51. #define _REPORT_FAIL(lpszMessage, lpszClsid, lRes)
  52. #endif
  53. //////////////////////////////////////////////////////////////////////////////
  54. // global constants and macros
  55. // GUIDs for snapin
  56. const CLSID CLSID_DNSSnapin =
  57. { 0x2faebfa2, 0x3f1a, 0x11d0, { 0x8c, 0x65, 0x0, 0xc0, 0x4f, 0xd8, 0xfe, 0xcb } };
  58. // {80105023-50B1-11d1-B930-00A0C9A06D2D}
  59. const CLSID CLSID_DNSSnapinEx =
  60. { 0x80105023, 0x50b1, 0x11d1, { 0xb9, 0x30, 0x0, 0xa0, 0xc9, 0xa0, 0x6d, 0x2d } };
  61. // {6C1303DC-BA00-11d1-B949-00A0C9A06D2D}
  62. const CLSID CLSID_DNSSnapinAbout =
  63. { 0x6c1303dc, 0xba00, 0x11d1, { 0xb9, 0x49, 0x0, 0xa0, 0xc9, 0xa0, 0x6d, 0x2d } };
  64. // {6C1303DD-BA00-11d1-B949-00A0C9A06D2D}
  65. const CLSID CLSID_DNSSnapinAboutEx =
  66. { 0x6c1303dd, 0xba00, 0x11d1, { 0xb9, 0x49, 0x0, 0xa0, 0xc9, 0xa0, 0x6d, 0x2d } };
  67. ///////////////////////////////////////////////////////////////////////////////
  68. // RESOURCES
  69. BEGIN_MENU(CDNSRootDataMenuHolder)
  70. BEGIN_CTX
  71. CTX_ENTRY_VIEW(IDM_SNAPIN_ADVANCED_VIEW, L"_DNS_ADVANCED")
  72. CTX_ENTRY_VIEW(IDM_SNAPIN_FILTERING, L"_DNS_FILTER")
  73. CTX_ENTRY_TOP(IDM_SNAPIN_CONNECT_TO_SERVER, L"_DNS_CONNECTTOP")
  74. CTX_ENTRY_TASK(IDM_SNAPIN_CONNECT_TO_SERVER, L"_DNS_CONNECTTASK")
  75. END_CTX
  76. BEGIN_RES
  77. RES_ENTRY(IDS_SNAPIN_ADVANCED_VIEW)
  78. RES_ENTRY(IDS_SNAPIN_FILTERING)
  79. RES_ENTRY(IDS_SNAPIN_CONNECT_TO_SERVER)
  80. RES_ENTRY(IDS_SNAPIN_CONNECT_TO_SERVER)
  81. END_RES
  82. END_MENU
  83. BEGIN_MENU(CDNSServerMenuHolder)
  84. BEGIN_CTX
  85. CTX_ENTRY_VIEW(IDM_SNAPIN_ADVANCED_VIEW, L"_DNS_ADVANCED")
  86. CTX_ENTRY_VIEW(IDM_SNAPIN_MESSAGE, L"_DNS_MESSAGE")
  87. CTX_ENTRY_VIEW(IDM_SNAPIN_FILTERING, L"_DNS_FILTER")
  88. CTX_ENTRY_TOP(IDM_SERVER_CONFIGURE, L"_DNS_CONFIGURETOP")
  89. #ifdef USE_NDNC
  90. CTX_ENTRY_TOP(IDM_SERVER_CREATE_NDNC, L"_DNS_CREATENDNC")
  91. #endif
  92. CTX_ENTRY_TOP(IDM_SERVER_NEW_ZONE, L"_DNS_ZONE")
  93. CTX_ENTRY_TOP(IDM_SERVER_SET_AGING, L"_DNS_AGING")
  94. CTX_ENTRY_TOP(IDM_SERVER_SCAVENGE, L"_DNS_SCAVENGETOP")
  95. CTX_ENTRY_TOP(IDM_SERVER_UPDATE_DATA_FILES, L"_DNS_UPDATETOP")
  96. CTX_ENTRY_TOP(IDM_SERVER_CLEAR_CACHE, L"_DNS_CLEARCACHETOP")
  97. CTX_ENTRY_TASK(IDM_SERVER_CONFIGURE, L"_DNS_CONFIGURETASK")
  98. CTX_ENTRY_TASK(IDM_SERVER_SCAVENGE, L"_DNS_SCAVENGETASK")
  99. CTX_ENTRY_TASK(IDM_SERVER_UPDATE_DATA_FILES, L"_DNS_UPDATETASK")
  100. CTX_ENTRY_TASK(IDM_SERVER_CLEAR_CACHE, L"_DNS_CLEARCACHETASK")
  101. END_CTX
  102. BEGIN_RES
  103. RES_ENTRY(IDS_SNAPIN_ADVANCED_VIEW)
  104. RES_ENTRY(IDS_SNAPIN_MESSAGE)
  105. RES_ENTRY(IDS_SNAPIN_FILTERING)
  106. RES_ENTRY(IDS_SERVER_CONFIGURE)
  107. #ifdef USE_NDNC
  108. RES_ENTRY(IDS_SERVER_CREATE_NDNC)
  109. #endif
  110. RES_ENTRY(IDS_SERVER_NEW_ZONE)
  111. RES_ENTRY(IDS_SERVER_SET_AGING)
  112. RES_ENTRY(IDS_SERVER_SCAVENGE)
  113. RES_ENTRY(IDS_SERVER_UPDATE_DATA_FILES)
  114. RES_ENTRY(IDS_SERVER_CLEAR_CACHE)
  115. RES_ENTRY(IDS_SERVER_CONFIGURE)
  116. RES_ENTRY(IDS_SERVER_SCAVENGE)
  117. RES_ENTRY(IDS_SERVER_UPDATE_DATA_FILES)
  118. RES_ENTRY(IDS_SERVER_CLEAR_CACHE)
  119. END_RES
  120. END_MENU
  121. BEGIN_MENU(CDNSCathegoryFolderHolder)
  122. BEGIN_CTX
  123. CTX_ENTRY_VIEW(IDM_SNAPIN_ADVANCED_VIEW, L"_DNS_ADVANCED")
  124. CTX_ENTRY_VIEW(IDM_SNAPIN_FILTERING, L"_DNS_FILTER")
  125. END_CTX
  126. BEGIN_RES
  127. RES_ENTRY(IDS_SNAPIN_ADVANCED_VIEW)
  128. RES_ENTRY(IDS_SNAPIN_FILTERING)
  129. END_RES
  130. END_MENU
  131. BEGIN_MENU(CDNSAuthoritatedZonesMenuHolder)
  132. BEGIN_CTX
  133. CTX_ENTRY_VIEW(IDM_SNAPIN_ADVANCED_VIEW, L"_DNS_ADVANCED")
  134. CTX_ENTRY_VIEW(IDM_SNAPIN_FILTERING, L"_DNS_FILTER")
  135. CTX_ENTRY_TOP(IDM_SERVER_NEW_ZONE, L"_DNS_ZONETOP")
  136. END_CTX
  137. BEGIN_RES
  138. RES_ENTRY(IDS_SNAPIN_ADVANCED_VIEW)
  139. RES_ENTRY(IDS_SNAPIN_FILTERING)
  140. RES_ENTRY(IDS_SERVER_NEW_ZONE)
  141. END_RES
  142. END_MENU
  143. BEGIN_MENU(CDNSCacheMenuHolder)
  144. BEGIN_CTX
  145. CTX_ENTRY_TOP(IDM_CACHE_FOLDER_CLEAR_CACHE, L"_DNS_CLEARCACHETOP")
  146. CTX_ENTRY_TASK(IDM_CACHE_FOLDER_CLEAR_CACHE, L"_DNS_CLEARCACHETASK")
  147. END_CTX
  148. BEGIN_RES
  149. RES_ENTRY(IDS_CACHE_FOLDER_CLEAR_CACHE)
  150. RES_ENTRY(IDS_CACHE_FOLDER_CLEAR_CACHE)
  151. END_RES
  152. END_MENU
  153. BEGIN_MENU(CDNSZoneMenuHolder)
  154. BEGIN_CTX
  155. CTX_ENTRY_VIEW(IDM_SNAPIN_ADVANCED_VIEW, L"_DNS_ADVANCED")
  156. CTX_ENTRY_VIEW(IDM_SNAPIN_FILTERING, L"_DNS_FILTER")
  157. CTX_ENTRY_TOP(IDM_ZONE_UPDATE_DATA_FILE, L"_DNS_UPDATETOP")
  158. CTX_ENTRY_TOP(IDM_ZONE_RELOAD, L"_DNS_RELOADTOP")
  159. CTX_ENTRY_TOP(IDM_ZONE_TRANSFER, L"_DNS_TRANSFERTOP")
  160. CTX_ENTRY_TOP(IDM_ZONE_RELOAD_FROM_MASTER, L"_DNS_RELOADMASTERTOP")
  161. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_HOST, L"_DNS_NEWHOST")
  162. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_PTR, L"_DNS_NEWPTR")
  163. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_ALIAS, L"_DNS_NEWALIAS")
  164. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_MX, L"_DNS_NEWMX")
  165. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_DOMAIN, L"_DNS_NEWDOMAIN")
  166. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_DELEGATION, L"_DNS_NEWDELEGATION")
  167. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_RECORD, L"_DNS_NEWRECORD")
  168. CTX_ENTRY_TASK(IDM_ZONE_UPDATE_DATA_FILE, L"_DNS_UPDATETASK")
  169. CTX_ENTRY_TASK(IDM_ZONE_RELOAD, L"_DNS_RELOADTASK")
  170. CTX_ENTRY_TASK(IDM_ZONE_TRANSFER, L"_DNS_TRANSFERTASK")
  171. CTX_ENTRY_TASK(IDM_ZONE_RELOAD_FROM_MASTER, L"_DNS_RELOADMASTERTASK")
  172. END_CTX
  173. BEGIN_RES
  174. RES_ENTRY(IDS_SNAPIN_ADVANCED_VIEW)
  175. RES_ENTRY(IDS_SNAPIN_FILTERING)
  176. //RES_ENTRY(IDS_ZONE_PAUSE)
  177. RES_ENTRY(IDS_ZONE_UPDATE_DATA_FILE)
  178. RES_ENTRY(IDS_ZONE_RELOAD)
  179. RES_ENTRY(IDS_ZONE_TRANSFER)
  180. RES_ENTRY(IDS_ZONE_RELOAD_FROM_MASTER)
  181. RES_ENTRY(IDS_DOMAIN_NEW_NEW_HOST)
  182. RES_ENTRY(IDS_DOMAIN_NEW_NEW_PTR)
  183. RES_ENTRY(IDS_DOMAIN_NEW_NEW_ALIAS)
  184. RES_ENTRY(IDS_DOMAIN_NEW_NEW_MX)
  185. RES_ENTRY(IDS_DOMAIN_NEW_NEW_DOMAIN)
  186. RES_ENTRY(IDS_DOMAIN_NEW_NEW_DELEGATION)
  187. RES_ENTRY(IDS_DOMAIN_NEW_NEW_RECORD)
  188. RES_ENTRY(IDS_ZONE_UPDATE_DATA_FILE)
  189. RES_ENTRY(IDS_ZONE_RELOAD)
  190. RES_ENTRY(IDS_ZONE_TRANSFER)
  191. RES_ENTRY(IDS_ZONE_RELOAD_FROM_MASTER)
  192. END_RES
  193. END_MENU
  194. BEGIN_MENU(CDNSDomainMenuHolder)
  195. BEGIN_CTX
  196. CTX_ENTRY_VIEW(IDM_SNAPIN_ADVANCED_VIEW, L"_DNS_ADVANCED")
  197. CTX_ENTRY_VIEW(IDM_SNAPIN_FILTERING, L"_DNS_FITLER")
  198. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_HOST, L"_DNS_NEWHOST")
  199. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_PTR, L"_DNS_NEWPTR")
  200. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_ALIAS, L"_DNS_NEWALIAS")
  201. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_MX, L"_DNS_NEWMX")
  202. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_DOMAIN, L"_DNS_NEWDOMAIN")
  203. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_DELEGATION, L"_DNS_NEWDELEGATION")
  204. CTX_ENTRY_TOP(IDM_DOMAIN_NEW_RECORD, L"_DNS_NEWRECORD")
  205. END_CTX
  206. BEGIN_RES
  207. RES_ENTRY(IDS_SNAPIN_ADVANCED_VIEW)
  208. RES_ENTRY(IDS_SNAPIN_FILTERING)
  209. RES_ENTRY(IDS_DOMAIN_NEW_NEW_HOST)
  210. RES_ENTRY(IDS_DOMAIN_NEW_NEW_PTR)
  211. RES_ENTRY(IDS_DOMAIN_NEW_NEW_ALIAS)
  212. RES_ENTRY(IDS_DOMAIN_NEW_NEW_MX)
  213. RES_ENTRY(IDS_DOMAIN_NEW_NEW_DOMAIN)
  214. RES_ENTRY(IDS_DOMAIN_NEW_NEW_DELEGATION)
  215. RES_ENTRY(IDS_DOMAIN_NEW_NEW_RECORD)
  216. END_RES
  217. END_MENU
  218. BEGIN_MENU(CDNSRecordMenuHolder)
  219. BEGIN_CTX
  220. END_CTX
  221. BEGIN_RES
  222. END_RES
  223. END_MENU
  224. // # of columns in the result pane and map for resource strings
  225. extern RESULT_HEADERMAP _DefaultHeaderStrings[] =
  226. {
  227. { L"", IDS_HEADER_NAME, LVCFMT_LEFT, 180},
  228. { L"", IDS_HEADER_TYPE, LVCFMT_LEFT, 90},
  229. { L"", IDS_HEADER_DATA, LVCFMT_LEFT, 160}
  230. };
  231. extern RESULT_HEADERMAP _ServerHeaderStrings[] =
  232. {
  233. { L"", IDS_HEADER_NAME, LVCFMT_LEFT, 180},
  234. };
  235. extern RESULT_HEADERMAP _ZoneHeaderStrings[] =
  236. {
  237. { L"", IDS_HEADER_NAME, LVCFMT_LEFT, 180},
  238. { L"", IDS_HEADER_TYPE, LVCFMT_LEFT, 90},
  239. // { L"", IDS_HEADER_PARTITION, LVCFMT_LEFT, 100},
  240. { L"", IDS_HEADER_STATUS, LVCFMT_LEFT, 160}
  241. };
  242. #define N_ZONE_TYPES (7)
  243. extern ZONE_TYPE_MAP _ZoneTypeStrings[] =
  244. {
  245. { L"", IDS_ZONE_TYPE_AD_INTEGRATED },
  246. { L"", IDS_ZONE_TYPE_STANDARD_PRIMARY },
  247. { L"", IDS_ZONE_TYPE_SECONDARY },
  248. { L"", IDS_ZONE_TYPE_RUNNING },
  249. { L"", IDS_ZONE_TYPE_PAUSED },
  250. { L"", IDS_ZONE_TYPE_STUB },
  251. { L"", IDS_ZONE_TYPE_STUB_DS }
  252. };
  253. //
  254. // Toolbar buttons
  255. //
  256. MMCBUTTON g_DNSMGR_SnapinButtons[] =
  257. {
  258. { 0, toolbarNewServer, !TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  259. { 1, toolbarNewRecord, !TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  260. { 2, toolbarNewZone, !TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }
  261. };
  262. //
  263. // We have to maintain the memory for the toolbar button strings
  264. // so this class holds the strings until it is time for them to be
  265. // deleted
  266. //
  267. class CButtonStringsHolder
  268. {
  269. public:
  270. CButtonStringsHolder()
  271. {
  272. m_astr = NULL;
  273. }
  274. ~CButtonStringsHolder()
  275. {
  276. if (m_astr != NULL)
  277. delete[] m_astr;
  278. }
  279. CString* m_astr; // dynamic array of CStrings
  280. };
  281. CButtonStringsHolder g_astrButtonStrings;
  282. BOOL LoadZoneTypeResources(ZONE_TYPE_MAP* pHeaderMap, int nCols)
  283. {
  284. HINSTANCE hInstance = _Module.GetModuleInstance();
  285. for ( int i = 0; i < nCols ; i++)
  286. {
  287. if ( 0 == ::LoadString(hInstance, pHeaderMap[i].uResID, pHeaderMap[i].szBuffer, MAX_RESULT_HEADER_STRLEN))
  288. return TRUE;
  289. }
  290. return TRUE;
  291. }
  292. ///////////////////////////////////////////////////////////////////////////////
  293. // CDNSMgrModule
  294. HRESULT WINAPI CDNSMgrModule::UpdateRegistryCLSID(const CLSID& clsid, BOOL bRegister)
  295. {
  296. static const WCHAR szIPS32[] = _T("InprocServer32");
  297. static const WCHAR szCLSID[] = _T("CLSID");
  298. HRESULT hRes = S_OK;
  299. LPOLESTR lpOleStrCLSIDValue = NULL;
  300. ::StringFromCLSID(clsid, &lpOleStrCLSIDValue);
  301. if (lpOleStrCLSIDValue == NULL)
  302. {
  303. return E_OUTOFMEMORY;
  304. }
  305. CRegKey key;
  306. if (bRegister)
  307. {
  308. LONG lRes = key.Open(HKEY_CLASSES_ROOT, szCLSID);
  309. _REPORT_FAIL(L"key.Open(HKEY_CLASSES_ROOT", lpOleStrCLSIDValue, lRes);
  310. if (lRes == ERROR_SUCCESS)
  311. {
  312. lRes = key.Create(key, lpOleStrCLSIDValue);
  313. _REPORT_FAIL(L"key.Create(key", lpOleStrCLSIDValue, lRes);
  314. if (lRes == ERROR_SUCCESS)
  315. {
  316. WCHAR szModule[_MAX_PATH];
  317. ::GetModuleFileName(m_hInst, szModule, _MAX_PATH);
  318. lRes = key.SetKeyValue(szIPS32, szModule);
  319. _REPORT_FAIL(L"key.SetKeyValue(szIPS32", lpOleStrCLSIDValue, lRes);
  320. }
  321. }
  322. if (lRes != ERROR_SUCCESS)
  323. hRes = HRESULT_FROM_WIN32(lRes);
  324. }
  325. else
  326. {
  327. key.Attach(HKEY_CLASSES_ROOT);
  328. if (key.Open(key, szCLSID) == ERROR_SUCCESS)
  329. key.RecurseDeleteKey(lpOleStrCLSIDValue);
  330. }
  331. ::CoTaskMemFree(lpOleStrCLSIDValue);
  332. return hRes;
  333. }
  334. ///////////////////////////////////////////////////////////////////////////////
  335. // Module, Object Map and DLL entry points
  336. CDNSMgrModule _Module;
  337. BEGIN_OBJECT_MAP(ObjectMap)
  338. OBJECT_ENTRY(CLSID_DNSSnapin, CDNSComponentDataObject) // standalone snapin
  339. OBJECT_ENTRY(CLSID_DNSSnapinEx, CDNSComponentDataObjectEx) // namespace extension
  340. OBJECT_ENTRY(CLSID_DNSSnapinAbout, CDNSSnapinAbout) // standalone snapin about
  341. OBJECT_ENTRY(CLSID_DNSSnapinAboutEx, CDNSSnapinAboutEx) // namespace extension about
  342. END_OBJECT_MAP()
  343. STDAPI DllCanUnloadNow(void)
  344. {
  345. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  346. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  347. }
  348. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  349. {
  350. return _Module.GetClassObject(rclsid, riid, ppv);
  351. }
  352. static _NODE_TYPE_INFO_ENTRY _NodeTypeInfoEntryArray[] = {
  353. { &CDNSRootData::NodeTypeGUID, _T("Root DNS Snapin Subtree") },
  354. { &CDNSServerNode::NodeTypeGUID, _T("DNS Snapin Server Node") },
  355. { &CDNSZoneNode::NodeTypeGUID, _T("DNS Snapin Zone Node") },
  356. { &CDNSDomainNode::NodeTypeGUID, _T("DNS Snapin Domain Node") },
  357. { &CDNSRecordNodeBase::NodeTypeGUID, _T("DNS Snapin Record Node") },
  358. { NULL, NULL }
  359. };
  360. ///////////////////////////////////////////////////////////////////////////
  361. // external GUIDs (from Computer Management Snapin)
  362. const CLSID CLSID_SystemServiceManagementExt =
  363. {0x58221C6a,0xEA27,0x11CF,{0xAD,0xCF,0x00,0xAA,0x00,0xA8,0x00,0x33}};
  364. const CLSID CLSID_NodeTypeServerApps =
  365. { 0x476e6449, 0xaaff, 0x11d0, { 0xb9, 0x44, 0x0, 0xc0, 0x4f, 0xd8, 0xd5, 0xb0 } };
  366. const CLSID CLSID_EventViewerExt =
  367. { 0x394C052E, 0xB830, 0x11D0, { 0x9A, 0x86, 0x00, 0xC0, 0x4F, 0xD8, 0xDB, 0xF7 } };
  368. ////////////////////////////////////////////////////////////////////
  369. // Server Applications Registration functions
  370. const TCHAR DNS_KEY[] = TEXT("System\\CurrentControlSet\\Services\\DNS");
  371. const TCHAR CONTROL_KEY[] = TEXT("System\\CurrentControlSet\\Control\\");
  372. BOOL IsDNSServerInstalled()
  373. {
  374. CRegKey regkeyDNSService;
  375. LONG lRes = regkeyDNSService.Open(HKEY_LOCAL_MACHINE, DNS_KEY);
  376. return (lRes == ERROR_SUCCESS);
  377. }
  378. ////////////////////////////////////////////////////////////////////
  379. STDAPI DllRegisterServer(void)
  380. {
  381. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  382. // registers all objects
  383. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  384. ASSERT(SUCCEEDED(hr));
  385. if (FAILED(hr))
  386. {
  387. _MSGBOX(_T("_Module.RegisterServer() failed"));
  388. return hr;
  389. }
  390. CString szVersion, szProvider, szSnapinName, szSnapinNameEx;
  391. szVersion.LoadString(IDS_SNAPIN_VERSION);
  392. szProvider.LoadString(IDS_SNAPIN_PROVIDER);
  393. szSnapinName.LoadString(IDS_SNAPIN_NAME);
  394. szSnapinNameEx.LoadString(IDS_SNAPIN_NAME_EX);
  395. // register the standalone DNS snapin into the console snapin list
  396. hr = RegisterSnapin(&CLSID_DNSSnapin,
  397. &CDNSRootData::NodeTypeGUID,
  398. &CLSID_DNSSnapinAbout,
  399. szSnapinName, szVersion, szProvider,
  400. FALSE /*bExtension*/,
  401. _NodeTypeInfoEntryArray,
  402. IDS_SNAPIN_NAME);
  403. ASSERT(SUCCEEDED(hr));
  404. if (FAILED(hr))
  405. {
  406. _MSGBOX(_T("RegisterSnapin(&CLSID_DNSSnapin) failed"));
  407. return hr;
  408. }
  409. // register the extension DNS snapin into the console snapin list
  410. hr = RegisterSnapin(&CLSID_DNSSnapinEx,
  411. &CDNSRootData::NodeTypeGUID,
  412. &CLSID_DNSSnapinAboutEx,
  413. szSnapinNameEx, szVersion, szProvider,
  414. TRUE /*bExtension*/,
  415. _NodeTypeInfoEntryArray,
  416. IDS_SNAPIN_NAME);
  417. ASSERT(SUCCEEDED(hr));
  418. if (FAILED(hr))
  419. {
  420. _MSGBOX(_T("RegisterSnapin(&CLSID_DNSSnapinEx) failed"));
  421. return hr;
  422. }
  423. // register the snapin nodes into the console node list
  424. for (_NODE_TYPE_INFO_ENTRY* pCurrEntry = _NodeTypeInfoEntryArray;
  425. pCurrEntry->m_pNodeGUID != NULL; pCurrEntry++)
  426. {
  427. hr = RegisterNodeType(pCurrEntry->m_pNodeGUID,pCurrEntry->m_lpszNodeDescription);
  428. ASSERT(SUCCEEDED(hr));
  429. if (FAILED(hr))
  430. {
  431. _MSGBOX(_T("RegisterNodeType() failed"));
  432. return hr;
  433. }
  434. }
  435. // the Services Snapin will extend the Server Node (context menu to start/stop DNS)
  436. //
  437. // JonN 9/15/98: Removed the "dynamic" setting. I don't understand why this was
  438. // being registered as a dynamic extension.
  439. hr = RegisterNodeExtension(&CDNSServerNode::NodeTypeGUID, _T("ContextMenu"),
  440. &CLSID_SystemServiceManagementExt,
  441. _T("System Service Management Extension"), FALSE /*bDynamic*/);
  442. if (FAILED(hr))
  443. {
  444. _MSGBOX(_T("RegisterNodeExtension(&CDNSServerNode::NodeTypeGUID) failed"));
  445. return hr;
  446. }
  447. //
  448. // Register the event viewer as a namespace extension of the server node
  449. //
  450. hr = RegisterNodeExtension(&CDNSServerNode::NodeTypeGUID, _T("NameSpace"),
  451. &CLSID_EventViewerExt, _T("Event Viewer Extension"), FALSE);
  452. if (FAILED(hr))
  453. {
  454. _MSGBOX(_T("RegisterNodeExtension(&CDNSServerNode::NodeTypeGUID) failed"));
  455. return hr;
  456. }
  457. //
  458. // the DNS Snapin will be a namespace extension for the Server Apps node
  459. // in the Computer Management Snapin
  460. //
  461. //
  462. // Fixed Bug 13620 DNSMGR: on workstation with AdminPak, dnsmgr.dll should not get loaded
  463. //
  464. OSVERSIONINFOEX verInfoEx;
  465. verInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  466. if (!::GetVersionEx((OSVERSIONINFO*)&verInfoEx) || verInfoEx.wProductType != VER_NT_WORKSTATION)
  467. {
  468. hr = RegisterNodeExtension(&CLSID_NodeTypeServerApps, _T("NameSpace"),
  469. &CLSID_DNSSnapinEx, szSnapinNameEx, TRUE /*bDynamic*/);
  470. if (FAILED(hr))
  471. {
  472. _MSGBOX(_T("RegisterNodeExtension(&CLSID_NodeTypeServerApps) failed"));
  473. return hr;
  474. }
  475. }
  476. return hr;
  477. }
  478. STDAPI DllUnregisterServer(void)
  479. {
  480. HRESULT hr = _Module.UnregisterServer();
  481. ASSERT(SUCCEEDED(hr));
  482. // un register the standalone snapin
  483. hr = UnregisterSnapin(&CLSID_DNSSnapin);
  484. ASSERT(SUCCEEDED(hr));
  485. // un register the extension snapin
  486. hr = UnregisterSnapin(&CLSID_DNSSnapinEx);
  487. ASSERT(SUCCEEDED(hr));
  488. // unregister the snapin nodes,
  489. // this removes also the server node, with the Services Snapin extension keys
  490. for (_NODE_TYPE_INFO_ENTRY* pCurrEntry = _NodeTypeInfoEntryArray;
  491. pCurrEntry->m_pNodeGUID != NULL; pCurrEntry++)
  492. {
  493. hr = UnregisterNodeType(pCurrEntry->m_pNodeGUID);
  494. ASSERT(SUCCEEDED(hr));
  495. }
  496. // the DNS Snapin will be a namespace extension for the Server Apps node
  497. // in the Computer Management Snapin
  498. hr = UnregisterNodeExtension(&CLSID_NodeTypeServerApps, _T("NameSpace"),
  499. &CLSID_DNSSnapinEx, TRUE /*bDynamic*/);
  500. ASSERT(SUCCEEDED(hr));
  501. return S_OK;
  502. }
  503. ///////////////////////////////////////////////////////////////////////////////
  504. // CDNSSnapinApp
  505. class CDNSSnapinApp : public CWinApp
  506. {
  507. public:
  508. virtual BOOL InitInstance();
  509. virtual int ExitInstance();
  510. };
  511. CDNSSnapinApp theApp;
  512. BOOL CDNSSnapinApp::InitInstance()
  513. {
  514. _Module.Init(ObjectMap, m_hInstance);
  515. // initialize font for Mask Control
  516. WCHAR szFontName[LF_FACESIZE];
  517. int nFontSize;
  518. VERIFY(LoadFontInfoFromResource(IDS_MASK_CTRL_FONT_NAME,
  519. IDS_MASK_CTRL_FONT_SIZE,
  520. szFontName, LF_FACESIZE,
  521. nFontSize,
  522. L"MS Shell Dlg", 8 // default if something goes wrong
  523. ));
  524. if (!DNS_ControlsInitialize(m_hInstance, szFontName, nFontSize))
  525. return FALSE;
  526. if (!CDNSComponentDataObject::LoadResources())
  527. return FALSE;
  528. return CWinApp::InitInstance();
  529. }
  530. int CDNSSnapinApp::ExitInstance()
  531. {
  532. #ifdef _DEBUG_REFCOUNT
  533. TRACE(_T("CDNSSnapinApp::ExitInstance()\n"));
  534. ASSERT(CComponentDataObject::m_nOustandingObjects == 0);
  535. ASSERT(CComponentObject::m_nOustandingObjects == 0);
  536. ASSERT(CDataObject::m_nOustandingObjects == 0);
  537. #endif // _DEBUG_REFCOUNT
  538. _Module.Term();
  539. return CWinApp::ExitInstance();
  540. }
  541. ////////////////////////////////////////////////////////////////////////
  542. // CDNSComponentObject (.i.e "view")
  543. HRESULT CDNSComponentObject::InitializeHeaders(CContainerNode* pContainerNode)
  544. {
  545. HRESULT hr = S_OK;
  546. ASSERT(m_pHeader);
  547. CColumnSet* pColumnSet = pContainerNode->GetColumnSet();
  548. POSITION pos = pColumnSet->GetHeadPosition();
  549. while (pos != NULL)
  550. {
  551. CColumn* pColumn = pColumnSet->GetNext(pos);
  552. hr = m_pHeader->InsertColumn(pColumn->GetColumnNum(),
  553. pColumn->GetHeader(),
  554. pColumn->GetFormat(),
  555. AUTO_WIDTH);
  556. if (FAILED(hr))
  557. return hr;
  558. hr = m_pHeader->SetColumnWidth(pColumn->GetColumnNum(), pColumn->GetWidth());
  559. if (FAILED(hr))
  560. return hr;
  561. }
  562. return hr;
  563. }
  564. HRESULT CDNSComponentObject::InitializeBitmaps(CTreeNode*)
  565. {
  566. // image lists for nodes
  567. CBitmapHolder<IDB_16x16> _bmp16x16;
  568. CBitmapHolder<IDB_32x32> _bmp32x32;
  569. HRESULT hr = S_OK;
  570. BOOL bLoaded = _bmp16x16.LoadBitmap() && _bmp32x32.LoadBitmap();
  571. if (bLoaded)
  572. {
  573. ASSERT(m_pImageResult != NULL);
  574. hr = m_pImageResult->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp16x16)),
  575. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp32x32)),
  576. 0, BMP_COLOR_MASK);
  577. }
  578. else
  579. {
  580. hr = S_FALSE;
  581. }
  582. return hr;
  583. }
  584. CONST INT cButtons = sizeof(g_DNSMGR_SnapinButtons)/sizeof(MMCBUTTON);
  585. HRESULT CDNSComponentObject::InitializeToolbar(IToolbar* pToolbar)
  586. {
  587. ASSERT(pToolbar != NULL);
  588. HRESULT hr = S_OK;
  589. LoadToolbarStrings(g_DNSMGR_SnapinButtons);
  590. CBitmapHolder<IDB_TOOLBAR_BUTTONS> _bmpToolbarButtons;
  591. BOOL bLoaded = _bmpToolbarButtons.LoadBitmap();
  592. if (bLoaded)
  593. {
  594. hr = m_pToolbar->AddBitmap(cButtons, (HBITMAP)_bmpToolbarButtons, 16, 16, RGB(255,0,255));
  595. }
  596. hr = m_pToolbar->AddButtons(cButtons, g_DNSMGR_SnapinButtons);
  597. return hr;
  598. }
  599. HRESULT CDNSComponentObject::LoadToolbarStrings(MMCBUTTON * Buttons)
  600. {
  601. if (g_astrButtonStrings.m_astr == NULL )
  602. {
  603. //
  604. // load strings
  605. //
  606. g_astrButtonStrings.m_astr = new CString[2*cButtons];
  607. for (UINT i = 0; i < cButtons; i++)
  608. {
  609. UINT iButtonTextId = 0, iTooltipTextId = 0;
  610. switch (Buttons[i].idCommand)
  611. {
  612. case toolbarNewServer:
  613. iButtonTextId = IDS_BUTTON_NEW_SERVER;
  614. iTooltipTextId = IDS_TOOLTIP_NEW_SERVER;
  615. break;
  616. case toolbarNewRecord:
  617. iButtonTextId = IDS_BUTTON_NEW_RECORD;
  618. iTooltipTextId = IDS_TOOLTIP_NEW_RECORD;
  619. break;
  620. case toolbarNewZone:
  621. iButtonTextId = IDS_BUTTON_NEW_ZONE;
  622. iTooltipTextId = IDS_TOOLTIP_NEW_ZONE;
  623. break;
  624. default:
  625. ASSERT(FALSE);
  626. break;
  627. }
  628. g_astrButtonStrings.m_astr[i*2].LoadString(iButtonTextId);
  629. Buttons[i].lpButtonText =
  630. const_cast<BSTR>((LPCTSTR)(g_astrButtonStrings.m_astr[i*2]));
  631. g_astrButtonStrings.m_astr[(i*2)+1].LoadString(iTooltipTextId);
  632. Buttons[i].lpTooltipText =
  633. const_cast<BSTR>((LPCTSTR)(g_astrButtonStrings.m_astr[(i*2)+1]));
  634. }
  635. }
  636. return S_OK;
  637. }
  638. ////////////////////////////////////////////////////////////////////////
  639. // CDNSComponentDataObjectBase (.i.e "document")
  640. CDNSComponentDataObjectBase::CDNSComponentDataObjectBase()
  641. {
  642. CWatermarkInfo* pWatermarkInfo = new CWatermarkInfo;
  643. if (pWatermarkInfo)
  644. {
  645. pWatermarkInfo->m_nIDBanner = IDB_WIZBANNER;
  646. pWatermarkInfo->m_nIDWatermark = IDB_WIZWATERMARK;
  647. }
  648. SetWatermarkInfo(pWatermarkInfo);
  649. m_columnSetList.AddTail(new CDNSDefaultColumnSet(L"---Default Column Set---"));
  650. m_columnSetList.AddTail(new CDNSServerColumnSet(L"---Server Column Set---"));
  651. m_columnSetList.AddTail(new CDNSZoneColumnSet(L"---Zone Column Set---"));
  652. SetLogFileName(L"dcpromodns");
  653. }
  654. HRESULT CDNSComponentDataObjectBase::OnSetImages(LPIMAGELIST lpScopeImage)
  655. {
  656. // image lists for nodes
  657. CBitmapHolder<IDB_16x16> _bmp16x16;
  658. CBitmapHolder<IDB_32x32> _bmp32x32;
  659. BOOL bLoaded = _bmp16x16.LoadBitmap() && _bmp32x32.LoadBitmap();
  660. HRESULT hr = S_OK;
  661. if (bLoaded)
  662. {
  663. ASSERT(lpScopeImage != NULL);
  664. hr = lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp16x16)),
  665. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp32x32)),
  666. 0, BMP_COLOR_MASK);
  667. }
  668. else
  669. {
  670. hr = S_FALSE;
  671. }
  672. return hr;
  673. }
  674. CRootData* CDNSComponentDataObjectBase::OnCreateRootData()
  675. {
  676. CDNSRootData* pDNSRootNode = new CDNSRootData(this);
  677. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  678. CString szSnapinType;
  679. szSnapinType.LoadString(IDS_SNAPIN_NAME);
  680. pDNSRootNode->SetDisplayName(szSnapinType);
  681. return pDNSRootNode;
  682. }
  683. BOOL CDNSComponentDataObjectBase::LoadResources()
  684. {
  685. return
  686. LoadContextMenuResources(CDNSRootDataMenuHolder::GetMenuMap()) &&
  687. LoadContextMenuResources(CDNSServerMenuHolder::GetMenuMap()) &&
  688. LoadContextMenuResources(CDNSCathegoryFolderHolder::GetMenuMap()) &&
  689. LoadContextMenuResources(CDNSAuthoritatedZonesMenuHolder::GetMenuMap()) &&
  690. LoadContextMenuResources(CDNSCacheMenuHolder::GetMenuMap()) &&
  691. LoadContextMenuResources(CDNSZoneMenuHolder::GetMenuMap()) &&
  692. LoadContextMenuResources(CDNSDomainMenuHolder::GetMenuMap()) &&
  693. LoadContextMenuResources(CDNSRecordMenuHolder::GetMenuMap()) &&
  694. LoadResultHeaderResources(_DefaultHeaderStrings,N_DEFAULT_HEADER_COLS) &&
  695. LoadResultHeaderResources(_ServerHeaderStrings,N_SERVER_HEADER_COLS) &&
  696. LoadResultHeaderResources(_ZoneHeaderStrings,N_ZONE_HEADER_COLS) &&
  697. LoadZoneTypeResources(_ZoneTypeStrings, N_ZONE_TYPES) &&
  698. CDNSRecordInfo::LoadResources();
  699. }
  700. STDMETHODIMP CDNSComponentDataObjectBase::CreateComponent(LPCOMPONENT* ppComponent)
  701. {
  702. ASSERT(ppComponent != NULL);
  703. CComObject<CDNSComponentObject>* pObject;
  704. CComObject<CDNSComponentObject>::CreateInstance(&pObject);
  705. ASSERT(pObject != NULL);
  706. // Store IComponentData
  707. pObject->SetIComponentData(this);
  708. return pObject->QueryInterface(IID_IComponent,
  709. reinterpret_cast<void**>(ppComponent));
  710. }
  711. void CDNSComponentDataObjectBase::OnTimer()
  712. {
  713. CDNSRootData* pDNSRootData = (CDNSRootData*)GetRootData();
  714. pDNSRootData->TestServers(m_dwTimerTime, GetTimerInterval(), this);
  715. m_dwTimerTime += GetTimerInterval();
  716. }
  717. void CDNSComponentDataObjectBase::OnTimerThread(WPARAM wParam, LPARAM lParam)
  718. {
  719. CDNSRootData* pDNSRootData = (CDNSRootData*)GetRootData();
  720. pDNSRootData->OnServerTestData(wParam,lParam, this);
  721. }
  722. CTimerThread* CDNSComponentDataObjectBase::OnCreateTimerThread()
  723. {
  724. return new CDNSServerTestTimerThread;
  725. }
  726. void CDNSComponentDataObjectBase::OnNodeContextHelp(CNodeList* pNodeList)
  727. {
  728. ASSERT(pNodeList != NULL);
  729. CComPtr<IDisplayHelp> spHelp;
  730. HRESULT hr = GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  731. if (SUCCEEDED(hr))
  732. spHelp->ShowTopic(L"DNSconcepts.chm::/sag_DNStopnode.htm");
  733. /*
  734. CString szNode;
  735. if (IS_CLASS(*pNode, CDNSRootData))
  736. {
  737. szNode = _T("Root Node");
  738. }
  739. else if (IS_CLASS(*pNode, CDNSServerNode))
  740. {
  741. szNode = _T("Server Node");
  742. }
  743. else if (IS_CLASS(*pNode, CDNSForwardZonesNode))
  744. {
  745. szNode = _T("Forward Zones Node");
  746. }
  747. else if (IS_CLASS(*pNode, CDNSReverseZonesNode))
  748. {
  749. szNode = _T("Reverse Zones Node");
  750. }
  751. else if (IS_CLASS(*pNode, CDNSZoneNode))
  752. {
  753. szNode = _T("Zone Node");
  754. }
  755. else if (IS_CLASS(*pNode, CDNSDomainNode))
  756. {
  757. szNode = _T("Domain Node");
  758. }
  759. else if (IS_CLASS(*pNode, CDNSCacheNode))
  760. {
  761. szNode = _T("Domain Node");
  762. }
  763. else if (dynamic_cast<CDNSRecordNodeBase*>(pNode) != NULL)
  764. {
  765. szNode = _T("Record Node");
  766. }
  767. if (!szNode.IsEmpty())
  768. {
  769. CString szMsg = _T("Context Help on ");
  770. szMsg += szNode;
  771. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  772. AfxMessageBox(szMsg);
  773. }
  774. */
  775. }
  776. LPCWSTR g_szContextHelpFileName = L"\\help\\dnsmgr.hlp";
  777. LPCWSTR g_szHTMLHelpFileName = L"\\help\\dnsmgr.chm";
  778. LPCWSTR CDNSComponentDataObjectBase::GetHTMLHelpFileName()
  779. {
  780. return g_szHTMLHelpFileName;
  781. }
  782. void CDNSComponentDataObjectBase::OnDialogContextHelp(UINT nDialogID, HELPINFO* pHelpInfo)
  783. {
  784. ULONG nContextTopic;
  785. if (FindDialogContextTopic(nDialogID, pHelpInfo, &nContextTopic))
  786. WinHelp(g_szContextHelpFileName, HELP_CONTEXTPOPUP, nContextTopic);
  787. }
  788. ////////////////////////////////////////////////////////////////////////////////
  789. // help context macros and maps
  790. #define BEGIN_HELP_MAP(map) static DWORD_PTR map[] = {
  791. #define HELP_MAP_ENTRY(x) x, (DWORD_PTR)&g_aHelpIDs_##x ,
  792. #define END_HELP_MAP 0, 0 };
  793. #define NEXT_HELP_MAP_ENTRY(p) ((p)+2)
  794. #define MAP_ENTRY_DLG_ID(p) (*p)
  795. #define MAP_ENTRY_TABLE(p) ((DWORD*)(*(p+1)))
  796. #define IS_LAST_MAP_ENTRY(p) (MAP_ENTRY_DLG_ID(p) == 0)
  797. #define NEXT_HELP_TABLE_ENTRY(p) ((p)+2)
  798. #define TABLE_ENTRY_CTRL_ID(p) (*p)
  799. #define TABLE_ENTRY_HELP_ID(p) (*(p+1))
  800. #define IS_LAST_TABLE_ENTRY(p) (TABLE_ENTRY_CTRL_ID(p) == 0)
  801. BEGIN_HELP_MAP(_DNSMgrContextHelpMap)
  802. // misc dialogs
  803. HELP_MAP_ENTRY(IDD_CHOOSER_CHOOSE_MACHINE)
  804. HELP_MAP_ENTRY(IDD_BROWSE_DIALOG)
  805. HELP_MAP_ENTRY(IDD_FILTERING_LIMITS)
  806. HELP_MAP_ENTRY(IDD_FILTERING_NAME)
  807. // misc. add dialogs
  808. HELP_MAP_ENTRY(IDD_DOMAIN_ADDNEWHOST) // TODO
  809. HELP_MAP_ENTRY(IDD_DOMAIN_ADDNEWDOMAIN)// TODO
  810. HELP_MAP_ENTRY(IDD_SELECT_RECORD_TYPE_DIALOG)
  811. // name servers page, there are more than one
  812. HELP_MAP_ENTRY(IDD_NAME_SERVERS_PAGE)
  813. HELP_MAP_ENTRY(IDD_COPY_ROOTHINTS_DIALOG)
  814. // server property pages
  815. HELP_MAP_ENTRY(IDD_SERVER_INTERFACES_PAGE)
  816. HELP_MAP_ENTRY(IDD_SERVER_DOMAIN_FORWARDERS_PAGE)
  817. HELP_MAP_ENTRY(IDD_SERVER_NEW_DOMAIN_FORWARDER)
  818. HELP_MAP_ENTRY(IDD_SERVER_ADVANCED_PAGE)
  819. HELP_MAP_ENTRY(IDD_SERVER_DEBUG_LOGGING_PAGE)
  820. HELP_MAP_ENTRY(IDD_IP_FILTER_DIALOG)
  821. HELP_MAP_ENTRY(IDD_SERVER_EVENT_LOGGING_PAGE)
  822. HELP_MAP_ENTRY(IDD_SERVMON_TEST_PAGE)
  823. HELP_MAP_ENTRY(IDD_SERVER_AGING_DIALOG)
  824. // zone property pages
  825. #ifdef USE_NDNC
  826. HELP_MAP_ENTRY(IDD_ZONE_GENERAL_PAGE_NDNC)
  827. HELP_MAP_ENTRY(IDD_ZONE_GENERAL_CHANGE_REPLICATION)
  828. #else
  829. HELP_MAP_ENTRY(IDD_ZONE_GENERAL_PAGE)
  830. #endif // USE_NDNC
  831. HELP_MAP_ENTRY(IDD_ZONE_GENERAL_CHANGE_TYPE)
  832. HELP_MAP_ENTRY(IDD_ZONE_WINS_PAGE)
  833. HELP_MAP_ENTRY(IDD_ZONE_NBSTAT_PAGE)
  834. HELP_MAP_ENTRY(IDD_ZONE_ZONE_TRANSFER_PAGE)
  835. HELP_MAP_ENTRY(IDD_ZONE_WINS_ADVANCED) // this is a subdialog
  836. HELP_MAP_ENTRY(IDD_ZONE_NOTIFY_SUBDIALOG) // this is a subdialog
  837. HELP_MAP_ENTRY(IDD_ZONE_AGING_DIALOG)
  838. // record property pages
  839. HELP_MAP_ENTRY(IDD_RR_NS_EDIT)
  840. HELP_MAP_ENTRY(IDD_RR_SOA)
  841. HELP_MAP_ENTRY(IDD_RR_A)
  842. HELP_MAP_ENTRY(IDD_RR_ATMA)
  843. HELP_MAP_ENTRY(IDD_RR_CNAME)
  844. HELP_MAP_ENTRY(IDD_RR_MX)
  845. HELP_MAP_ENTRY(IDD_RR_UNK)
  846. HELP_MAP_ENTRY(IDD_RR_TXT)
  847. HELP_MAP_ENTRY(IDD_RR_X25)
  848. HELP_MAP_ENTRY(IDD_RR_ISDN)
  849. HELP_MAP_ENTRY(IDD_RR_HINFO)
  850. HELP_MAP_ENTRY(IDD_RR_AAAA)
  851. HELP_MAP_ENTRY(IDD_RR_MB)
  852. HELP_MAP_ENTRY(IDD_RR_MG)
  853. HELP_MAP_ENTRY(IDD_RR_MD)
  854. HELP_MAP_ENTRY(IDD_RR_MF)
  855. HELP_MAP_ENTRY(IDD_RR_MR)
  856. HELP_MAP_ENTRY(IDD_RR_MINFO)
  857. HELP_MAP_ENTRY(IDD_RR_RP)
  858. HELP_MAP_ENTRY(IDD_RR_RT)
  859. HELP_MAP_ENTRY(IDD_RR_AFSDB)
  860. HELP_MAP_ENTRY(IDD_RR_WKS)
  861. HELP_MAP_ENTRY(IDD_RR_PTR)
  862. HELP_MAP_ENTRY(IDD_RR_SRV)
  863. HELP_MAP_ENTRY(IDD_RR_KEY)
  864. HELP_MAP_ENTRY(IDD_RR_SIG)
  865. HELP_MAP_ENTRY(IDD_RR_NXT)
  866. END_HELP_MAP
  867. BOOL CDNSComponentDataObjectBase::FindDialogContextTopic(/*IN*/UINT nDialogID,
  868. /*IN*/ HELPINFO* pHelpInfo,
  869. /*OUT*/ ULONG* pnContextTopic)
  870. {
  871. ASSERT(pHelpInfo != NULL);
  872. *pnContextTopic = 0;
  873. const DWORD_PTR* pMapEntry = _DNSMgrContextHelpMap;
  874. while (!IS_LAST_MAP_ENTRY(pMapEntry))
  875. {
  876. if (nDialogID == MAP_ENTRY_DLG_ID(pMapEntry))
  877. {
  878. DWORD* pTable = MAP_ENTRY_TABLE(pMapEntry);
  879. // look inside the table
  880. while (!IS_LAST_TABLE_ENTRY(pTable))
  881. {
  882. if (TABLE_ENTRY_CTRL_ID(pTable) == static_cast<UINT>(pHelpInfo->iCtrlId))
  883. {
  884. *pnContextTopic = TABLE_ENTRY_HELP_ID(pTable);
  885. return TRUE;
  886. }
  887. pTable = NEXT_HELP_TABLE_ENTRY(pTable);
  888. }
  889. }
  890. pMapEntry = NEXT_HELP_MAP_ENTRY(pMapEntry);
  891. }
  892. return FALSE;
  893. }
  894. ////////////////////////////////////////////////////////////////////////
  895. // CDNSComponentDataObjectEx (.i.e "document")
  896. // extension snapin
  897. unsigned int g_CFMachineName =
  898. RegisterClipboardFormat(L"MMC_SNAPIN_MACHINE_NAME");
  899. LPWSTR ExtractMachineName(LPDATAOBJECT lpDataObject)
  900. {
  901. ASSERT(lpDataObject != NULL);
  902. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  903. FORMATETC formatetc = { (CLIPFORMAT)g_CFMachineName, NULL,
  904. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  905. };
  906. // Allocate memory for the stream
  907. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, 512);
  908. LPWSTR pwszMachineName = NULL;
  909. // Attempt to get data from the object
  910. do
  911. {
  912. if (stgmedium.hGlobal == NULL)
  913. break;
  914. if (FAILED(lpDataObject->GetDataHere(&formatetc, &stgmedium)))
  915. break;
  916. pwszMachineName = reinterpret_cast<LPWSTR>(stgmedium.hGlobal);
  917. if (pwszMachineName == NULL)
  918. break;
  919. } while (FALSE);
  920. return pwszMachineName;
  921. }
  922. HRESULT CDNSComponentDataObjectEx::OnExtensionExpand(LPDATAOBJECT lpDataObject, LPARAM param)
  923. {
  924. // this is a namespace extension, need to add
  925. // the root of the snapin
  926. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  927. // NOTICE: the name of the root node is already set in the constructor
  928. // insert the root node in the console
  929. CDNSRootData* pDNSRootNode = (CDNSRootData*)GetRootData();
  930. HSCOPEITEM pParent = param;
  931. pDNSRootNode->SetScopeID(pParent);
  932. HRESULT hr = AddContainerNode(pDNSRootNode, pParent);
  933. if (FAILED(hr))
  934. return hr;
  935. BOOL bLocalHost = FALSE;
  936. if (!pDNSRootNode->IsEnumerated())
  937. {
  938. // get information from the data object
  939. LPWSTR pwszMachineName = ExtractMachineName(lpDataObject);
  940. if ( (pwszMachineName == NULL) || (pwszMachineName[0] == NULL) )
  941. {
  942. if (pwszMachineName != NULL)
  943. ::GlobalFree((void*)pwszMachineName);
  944. DWORD dwCharLen = MAX_COMPUTERNAME_LENGTH+1;
  945. pwszMachineName = (LPWSTR)GlobalAlloc(GMEM_SHARE, sizeof(WCHAR)*dwCharLen);
  946. if (pwszMachineName)
  947. {
  948. BOOL bRes = ::GetComputerName(pwszMachineName, &dwCharLen);
  949. ASSERT(dwCharLen <= MAX_COMPUTERNAME_LENGTH);
  950. if (!bRes)
  951. {
  952. wcscpy(pwszMachineName, _T("localhost."));
  953. }
  954. bLocalHost = TRUE;
  955. }
  956. }
  957. // add a new server node with the server name from the data object
  958. CDNSServerNode* pDNSServerNode = new CDNSServerNode(pwszMachineName, bLocalHost);
  959. FREE_INTERNAL((void*)pwszMachineName);
  960. VERIFY(pDNSRootNode->AddChildToList(pDNSServerNode));
  961. pDNSRootNode->AddServerToThreadList(pDNSServerNode, this);
  962. pDNSRootNode->MarkEnumerated();
  963. }
  964. return hr;
  965. }
  966. HRESULT CDNSComponentDataObjectEx::OnRemoveChildren(LPDATAOBJECT, LPARAM)
  967. {
  968. ASSERT(IsExtensionSnapin());
  969. CDNSRootData* pDNSRootNode = (CDNSRootData*)GetRootData();
  970. CNodeList* pChildList = pDNSRootNode->GetContainerChildList();
  971. ASSERT(pChildList != NULL);
  972. // loop through thelist of servers and remove them from
  973. // the test list
  974. for(POSITION pos = pChildList->GetHeadPosition(); pos != NULL; )
  975. {
  976. CDNSServerNode* pCurrServerNode = (CDNSServerNode*)pChildList->GetNext(pos);
  977. ASSERT(pCurrServerNode != NULL);
  978. pDNSRootNode->RemoveServerFromThreadList(pCurrServerNode, this);
  979. }
  980. // detach all the threads that might be still running
  981. GetRunningThreadTable()->RemoveAll();
  982. // shut down property sheets, if any
  983. GetPropertyPageHolderTable()->WaitForAllToShutDown();
  984. // remove all the children of the root from chaild list
  985. pDNSRootNode->RemoveAllChildrenFromList();
  986. pDNSRootNode->MarkEnumerated(FALSE);
  987. return S_OK;
  988. }
  989. //////////////////////////////////////////////////////////////////////////
  990. // CDNSSnapinAbout
  991. CDNSSnapinAbout::CDNSSnapinAbout()
  992. {
  993. m_uIdStrProvider = IDS_SNAPIN_PROVIDER;
  994. m_uIdStrVersion = IDS_SNAPIN_VERSION;
  995. m_uIdStrDestription = IDS_SNAPINABOUT_DESCRIPTION;
  996. m_uIdIconImage = IDI_DNS_SNAPIN;
  997. m_uIdBitmapSmallImage = IDB_ABOUT_16x16;
  998. m_uIdBitmapSmallImageOpen = IDB_ABOUT_OPEN_16x16;
  999. m_uIdBitmapLargeImage = IDB_ABOUT_32x32;
  1000. m_crImageMask = BMP_COLOR_MASK;
  1001. }
  1002. //////////////////////////////////////////////////////////////////////////
  1003. // CDNSSnapinAboutEx
  1004. CDNSSnapinAboutEx::CDNSSnapinAboutEx()
  1005. {
  1006. m_uIdStrProvider = IDS_SNAPIN_PROVIDER;
  1007. m_uIdStrVersion = IDS_SNAPIN_VERSION;
  1008. m_uIdStrDestription = IDS_SNAPINABOUT_DESCRIPTION;
  1009. m_uIdIconImage = IDI_DNS_SNAPIN;
  1010. m_uIdBitmapSmallImage = IDB_16x16;
  1011. m_uIdBitmapSmallImageOpen = IDB_16x16;
  1012. m_uIdBitmapLargeImage = IDB_32x32;
  1013. m_crImageMask = BMP_COLOR_MASK;
  1014. }