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.

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