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.

809 lines
24 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 "pch.h"
  13. #include "resource.h"
  14. #include <SnapBase.h>
  15. #include "ADSIEdit.h"
  16. #include "snapdata.h"
  17. #include "editor.h"
  18. #include "connection.h"
  19. #include "querynode.h"
  20. #include "IAttredt.h"
  21. #include "editorui.h"
  22. #include "editimpl.h"
  23. //#include "HelpArr.h" // context help ID's
  24. // Version info
  25. #include <ntverp.h>
  26. #define IDS_SNAPIN_VERSION VER_PRODUCTVERSION_STR
  27. #define IDS_SNAPIN_PROVIDER VER_COMPANYNAME_STR
  28. #ifdef DEBUG_ALLOCATOR
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. #endif
  35. //////////////////////////////////////////////////////////////////////////////
  36. // regsvr debugging
  37. // define to enable MsgBox debugging for regsvr32
  38. //#define _MSGBOX_ON_REG_FAIL
  39. #ifdef _MSGBOX_ON_REG_FAIL
  40. #define _MSGBOX(x) AfxMessageBox(x)
  41. #else
  42. #define _MSGBOX(x)
  43. #endif
  44. #ifdef _MSGBOX_ON_REG_FAIL
  45. #define _REPORT_FAIL(lpszMessage, lpszClsid, lRes) \
  46. ReportFail(lpszMessage, lpszClsid, lRes)
  47. void ReportFail(LPCWSTR lpszMessage, LPCWSTR lpszClsid, LONG lRes)
  48. {
  49. if (lRes == ERROR_SUCCESS)
  50. return;
  51. CThemeContextActivator activator;
  52. CString sz;
  53. sz.Format(_T("%s %s %d"), lpszMessage,lpszClsid, lRes);
  54. AfxMessageBox(sz);
  55. }
  56. #else
  57. #define _REPORT_FAIL(lpszMessage, lpszClsid, lRes)
  58. #endif
  59. //////////////////////////////////////////////////////////////////////////////
  60. // global constants and macros
  61. // GUIDs for snapin
  62. // {1C5DACFA-16BA-11d2-81D0-0000F87A7AA3}
  63. static const GUID CLSID_ADSIEditSnapin =
  64. { 0x1c5dacfa, 0x16ba, 0x11d2, { 0x81, 0xd0, 0x0, 0x0, 0xf8, 0x7a, 0x7a, 0xa3 } };
  65. // {E6F27C2A-16BA-11d2-81D0-0000F87A7AA3}
  66. static const GUID CLSID_ADSIEditAbout =
  67. { 0xe6f27c2a, 0x16ba, 0x11d2, { 0x81, 0xd0, 0x0, 0x0, 0xf8, 0x7a, 0x7a, 0xa3 } };
  68. // GUIDs for node types
  69. ///////////////////////////////////////////////////////////////////////////////
  70. // RESOURCES
  71. // # of columns in the result pane and map for resource strings
  72. extern RESULT_HEADERMAP _HeaderStrings[] =
  73. {
  74. { L"", IDS_HEADER_NAME, LVCFMT_LEFT, 180},
  75. { L"", IDS_HEADER_TYPE, LVCFMT_LEFT, 90},
  76. { L"", IDS_HEADER_DN, LVCFMT_LEFT, 450},
  77. };
  78. COLUMN_DEFINITION DefaultColumnDefinition =
  79. {
  80. COLUMNSET_ID_DEFAULT,
  81. N_HEADER_COLS,
  82. _HeaderStrings
  83. };
  84. extern RESULT_HEADERMAP _PartitionsHeaderStrings[] =
  85. {
  86. { L"", IDS_HEADER_NAME, LVCFMT_LEFT, 180},
  87. { L"", IDS_HEADER_NCNAME, LVCFMT_LEFT, 200},
  88. { L"", IDS_HEADER_TYPE, LVCFMT_LEFT, 90},
  89. { L"", IDS_HEADER_DN, LVCFMT_LEFT, 450},
  90. };
  91. COLUMN_DEFINITION PartitionsColumnDefinition =
  92. {
  93. COLUMNSET_ID_PARTITIONS,
  94. N_PARTITIONS_HEADER_COLS,
  95. _PartitionsHeaderStrings
  96. };
  97. extern PCOLUMN_DEFINITION ColumnDefinitions[] =
  98. {
  99. &DefaultColumnDefinition,
  100. &PartitionsColumnDefinition,
  101. NULL
  102. };
  103. ///////////////////////////////////////////////////////////////////////////////
  104. // CADSIEditModule
  105. HRESULT WINAPI CADSIEditModule::UpdateRegistryCLSID(const CLSID& clsid, BOOL bRegister)
  106. {
  107. static const WCHAR szIPS32[] = _T("InprocServer32");
  108. static const WCHAR szCLSID[] = _T("CLSID");
  109. HRESULT hRes = S_OK;
  110. LPOLESTR lpOleStrCLSIDValue;
  111. ::StringFromCLSID(clsid, &lpOleStrCLSIDValue);
  112. if (lpOleStrCLSIDValue == NULL)
  113. {
  114. return E_OUTOFMEMORY;
  115. }
  116. CRegKey key;
  117. if (bRegister)
  118. {
  119. LONG lRes = key.Open(HKEY_CLASSES_ROOT, szCLSID);
  120. _REPORT_FAIL(L"key.Open(HKEY_CLASSES_ROOT", lpOleStrCLSIDValue, lRes);
  121. if (lRes == ERROR_SUCCESS)
  122. {
  123. lRes = key.Create(key, lpOleStrCLSIDValue);
  124. _REPORT_FAIL(L"key.Create(key", lpOleStrCLSIDValue, lRes);
  125. if (lRes == ERROR_SUCCESS)
  126. {
  127. // NOTICE-NTRAID#NTBUG9-551295-2002/02/21-artm
  128. // GetModuleFileName() does not guarantee null termination.
  129. // Therefore, we allocated + 1 to hold the NULL and zero out
  130. // the buffer first. We also check for a truncation and set
  131. // the error code if there was one.
  132. WCHAR szModule[_MAX_PATH + 1];
  133. ZeroMemory(szModule, sizeof(WCHAR) * (_MAX_PATH + 1) );
  134. DWORD numCopied = ::GetModuleFileName(m_hInst, szModule, _MAX_PATH);
  135. if (numCopied < _MAX_PATH)
  136. {
  137. lRes = key.SetKeyValue(szIPS32, szModule);
  138. _REPORT_FAIL(L"key.SetKeyValue(szIPS32", lpOleStrCLSIDValue, lRes);
  139. }
  140. else
  141. { // The module name was too big. Something's fishy.
  142. hRes = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
  143. }
  144. }
  145. }
  146. if (lRes != ERROR_SUCCESS)
  147. hRes = HRESULT_FROM_WIN32(lRes);
  148. }
  149. else
  150. {
  151. key.Attach(HKEY_CLASSES_ROOT);
  152. if (key.Open(key, szCLSID) == ERROR_SUCCESS)
  153. key.RecurseDeleteKey(lpOleStrCLSIDValue);
  154. }
  155. ::CoTaskMemFree(lpOleStrCLSIDValue);
  156. return hRes;
  157. }
  158. ///////////////////////////////////////////////////////////////////////////////
  159. // Module, Object Map and DLL entry points
  160. CADSIEditModule _Module;
  161. BEGIN_OBJECT_MAP(ObjectMap)
  162. OBJECT_ENTRY(CLSID_ADSIEditSnapin, CADSIEditComponentDataObject)
  163. OBJECT_ENTRY(CLSID_ADSIEditAbout, CADSIEditAbout)
  164. OBJECT_ENTRY(CLSID_DsAttributeEditor, CAttributeEditor)
  165. END_OBJECT_MAP()
  166. STDAPI DllCanUnloadNow(void)
  167. {
  168. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  169. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  170. }
  171. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  172. {
  173. return _Module.GetClassObject(rclsid, riid, ppv);
  174. }
  175. static _NODE_TYPE_INFO_ENTRY _NodeTypeInfoEntryArray[] = {
  176. { &CADSIEditRootData::NodeTypeGUID, _T("Root ADSI Edit Subtree") },
  177. { &CADSIEditConnectionNode::NodeTypeGUID, _T("ADSI Edit Connection Node") },
  178. { &CADSIEditContainerNode::NodeTypeGUID, _T("ADSI Edit Container Node") },
  179. { &CADSIEditLeafNode::NodeTypeGUID, _T("ADSI Edit Leaf Node") },
  180. { &CADSIEditQueryNode::NodeTypeGUID, _T("ADSI Edit Query Node") },
  181. { NULL, NULL }
  182. };
  183. ////////////////////////////////////////////////////////////////////
  184. STDAPI DllRegisterServer(void)
  185. {
  186. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  187. CThemeContextActivator activator;
  188. // registers all objects
  189. HRESULT hr = _Module.RegisterServer(/* bRegTypeLib */ FALSE);
  190. ASSERT(SUCCEEDED(hr));
  191. if (FAILED(hr))
  192. {
  193. _MSGBOX(_T("_Module.RegisterServer() failed"));
  194. return hr;
  195. }
  196. CString szVersion, szProvider, szSnapinName, szSnapinNameEx;
  197. szVersion = IDS_SNAPIN_VERSION;
  198. szProvider = IDS_SNAPIN_PROVIDER;
  199. // NOTICE-2002/03/06-artm CString can throw out of memory exception but
  200. // that needs to be handled at a higher level. Also, the return value
  201. // is not checked but the call should _never_ fail if there is enough
  202. // memory (o'wise there was a serious screw up in including the resource).
  203. szSnapinName.LoadString(IDS_SNAPIN_NAME);
  204. // register the standalone ADSI Edit snapin into the console snapin list
  205. hr = RegisterSnapin(&CLSID_ADSIEditSnapin,
  206. &CADSIEditRootData::NodeTypeGUID,
  207. &CLSID_ADSIEditAbout,
  208. szSnapinName, szVersion, szProvider,
  209. FALSE /*bExtension*/,
  210. _NodeTypeInfoEntryArray);
  211. ASSERT(SUCCEEDED(hr));
  212. if (FAILED(hr))
  213. {
  214. _MSGBOX(_T("RegisterSnapin(&CLSID_DNSSnapin) failed"));
  215. return hr;
  216. }
  217. // register the snapin nodes into the console node list
  218. for (_NODE_TYPE_INFO_ENTRY* pCurrEntry = _NodeTypeInfoEntryArray;
  219. pCurrEntry->m_pNodeGUID != NULL; pCurrEntry++)
  220. {
  221. hr = RegisterNodeType(pCurrEntry->m_pNodeGUID,pCurrEntry->m_lpszNodeDescription);
  222. ASSERT(SUCCEEDED(hr));
  223. if (FAILED(hr))
  224. {
  225. _MSGBOX(_T("RegisterNodeType() failed"));
  226. return hr;
  227. }
  228. }
  229. return hr;
  230. }
  231. STDAPI DllUnregisterServer(void)
  232. {
  233. HRESULT hr = _Module.UnregisterServer();
  234. ASSERT(SUCCEEDED(hr));
  235. // un register the standalone snapin
  236. hr = UnregisterSnapin(&CLSID_ADSIEditSnapin);
  237. ASSERT(SUCCEEDED(hr));
  238. // unregister the snapin nodes,
  239. // this removes also the server node, with the Services Snapin extension keys
  240. for (_NODE_TYPE_INFO_ENTRY* pCurrEntry = _NodeTypeInfoEntryArray;
  241. pCurrEntry->m_pNodeGUID != NULL; pCurrEntry++)
  242. {
  243. hr = UnregisterNodeType(pCurrEntry->m_pNodeGUID);
  244. ASSERT(SUCCEEDED(hr));
  245. }
  246. return S_OK;
  247. }
  248. ///////////////////////////////////////////////////////////////////////////////
  249. // CADSIEditSnapinApp
  250. class CADSIEditSnapinApp : public CWinApp
  251. {
  252. public:
  253. virtual BOOL InitInstance();
  254. virtual int ExitInstance();
  255. };
  256. CADSIEditSnapinApp theApp;
  257. BOOL CADSIEditSnapinApp::InitInstance()
  258. {
  259. _Module.Init(ObjectMap, m_hInstance);
  260. // Add theming support
  261. SHFusionInitializeFromModuleID(m_hInstance, 2);
  262. HRESULT hr = ::OleInitialize(NULL);
  263. if (FAILED(hr))
  264. {
  265. return FALSE;
  266. }
  267. if (!CADSIEditComponentDataObject::LoadResources())
  268. return FALSE;
  269. return CWinApp::InitInstance();
  270. }
  271. int CADSIEditSnapinApp::ExitInstance()
  272. {
  273. #ifdef _DEBUG_REFCOUNT
  274. TRACE(_T("CADSIEditSnapinApp::ExitInstance()\n"));
  275. ASSERT(CComponentDataObject::m_nOustandingObjects == 0);
  276. ASSERT(CComponentObject::m_nOustandingObjects == 0);
  277. ASSERT(CDataObject::m_nOustandingObjects == 0);
  278. #endif // _DEBUG_REFCOUNT
  279. // Theming support
  280. SHFusionUninitialize();
  281. _Module.Term();
  282. return CWinApp::ExitInstance();
  283. }
  284. ////////////////////////////////////////////////////////////////////////
  285. // CADSIEditComponentObject (.i.e "view")
  286. HRESULT CADSIEditComponentObject::InitializeHeaders(CContainerNode* pContainerNode)
  287. {
  288. HRESULT hr = S_OK;
  289. ASSERT(m_pHeader);
  290. CColumnSet* pColumnSet = pContainerNode->GetColumnSet();
  291. POSITION pos = pColumnSet->GetHeadPosition();
  292. while (pos != NULL)
  293. {
  294. CColumn* pColumn = pColumnSet->GetNext(pos);
  295. hr = m_pHeader->InsertColumn(pColumn->GetColumnNum(),
  296. pColumn->GetHeader(),
  297. pColumn->GetFormat(),
  298. AUTO_WIDTH);
  299. if (FAILED(hr))
  300. return hr;
  301. hr = m_pHeader->SetColumnWidth(pColumn->GetColumnNum(),
  302. pColumn->GetWidth());
  303. if (FAILED(hr))
  304. return hr;
  305. }
  306. return hr;
  307. }
  308. HRESULT CADSIEditComponentObject::InitializeBitmaps(CTreeNode* cookie)
  309. {
  310. HRESULT hr = S_OK;
  311. // image lists for nodes
  312. CBitmapHolder<IDB_16x16> _bmp16x16;
  313. CBitmapHolder<IDB_32x32> _bmp32x32;
  314. bool bBmpsLoaded = _bmp16x16.LoadBitmap() && _bmp32x32.LoadBitmap();
  315. if (bBmpsLoaded)
  316. {
  317. ASSERT(m_pImageResult != NULL);
  318. hr = m_pImageResult->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp16x16)),
  319. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp32x32)),
  320. 0,
  321. BMP_COLOR_MASK);
  322. }
  323. else
  324. {
  325. hr = S_FALSE;
  326. }
  327. return hr;
  328. }
  329. ////////////////////////////////////////////////////////////////////////
  330. // CADSIEditComponentDataObject (.i.e "document")
  331. CADSIEditComponentDataObject::CADSIEditComponentDataObject()
  332. {
  333. /*
  334. CWatermarkInfo* pWatermarkInfo = new CWatermarkInfo;
  335. pWatermarkInfo->m_nIDBanner = IDB_WIZBANNER;
  336. pWatermarkInfo->m_nIDWatermark = IDB_WIZWATERMARK;
  337. SetWatermarkInfo(pWatermarkInfo);
  338. */
  339. m_pColumnSet = new CADSIEditColumnSet(COLUMNSET_ID_DEFAULT);
  340. }
  341. HRESULT CADSIEditComponentDataObject::OnSetImages(LPIMAGELIST lpScopeImage)
  342. {
  343. HRESULT hr = S_OK;
  344. // image lists for nodes
  345. CBitmapHolder<IDB_16x16> _bmp16x16;
  346. CBitmapHolder<IDB_32x32> _bmp32x32;
  347. bool bBmpsLoaded = _bmp16x16.LoadBitmap() && _bmp32x32.LoadBitmap();
  348. if (bBmpsLoaded)
  349. {
  350. ASSERT(lpScopeImage != NULL);
  351. hr = lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp16x16)),
  352. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(_bmp32x32)),
  353. 0,
  354. BMP_COLOR_MASK);
  355. }
  356. else
  357. {
  358. hr = S_FALSE;
  359. }
  360. return hr;
  361. }
  362. CRootData* CADSIEditComponentDataObject::OnCreateRootData()
  363. {
  364. CADSIEditRootData* pADSIEditRootNode = new CADSIEditRootData(this);
  365. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  366. CString szSnapinType;
  367. // NOTICE-2002/02/20-artm LoadString() can throw out of memory exception.
  368. // This needs to be handled at a higher level, if at all.
  369. szSnapinType.LoadString(IDS_SNAPIN_NAME);
  370. pADSIEditRootNode->SetDisplayName(szSnapinType);
  371. return pADSIEditRootNode;
  372. }
  373. BOOL CADSIEditComponentDataObject::LoadResources()
  374. {
  375. BOOL bLoadColumnHeaders = TRUE;
  376. for (UINT nIdx = 0; ColumnDefinitions[nIdx]; nIdx++)
  377. {
  378. PCOLUMN_DEFINITION pColumnDef = ColumnDefinitions[nIdx];
  379. bLoadColumnHeaders = LoadResultHeaderResources(pColumnDef->headers, pColumnDef->dwColumnCount);
  380. if (!bLoadColumnHeaders)
  381. {
  382. break;
  383. }
  384. }
  385. return
  386. LoadContextMenuResources(CADSIEditConnectMenuHolder::GetMenuMap()) &&
  387. LoadContextMenuResources(CADSIEditContainerMenuHolder::GetMenuMap()) &&
  388. LoadContextMenuResources(CADSIEditRootMenuHolder::GetMenuMap()) &&
  389. LoadContextMenuResources(CADSIEditLeafMenuHolder::GetMenuMap()) &&
  390. LoadContextMenuResources(CADSIEditQueryMenuHolder::GetMenuMap()) &&
  391. bLoadColumnHeaders;
  392. }
  393. STDMETHODIMP CADSIEditComponentDataObject::CreateComponent(LPCOMPONENT* ppComponent)
  394. {
  395. ASSERT(ppComponent != NULL);
  396. CComObject<CADSIEditComponentObject>* pObject;
  397. CComObject<CADSIEditComponentObject>::CreateInstance(&pObject);
  398. ASSERT(pObject != NULL);
  399. // Store IComponentData
  400. pObject->SetIComponentData(this);
  401. return pObject->QueryInterface(IID_IComponent,
  402. reinterpret_cast<void**>(ppComponent));
  403. }
  404. void CADSIEditComponentDataObject::OnNodeContextHelp(CTreeNode* pNode)
  405. {
  406. ASSERT(pNode != NULL);
  407. CComPtr<IDisplayHelp> spHelp;
  408. HRESULT hr = GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  409. if (SUCCEEDED(hr))
  410. spHelp->ShowTopic(L"w2rksupp.chm::/topics/adsiedit.htm");
  411. // spHelp->ShowTopic(L"w2rksupp.chm");
  412. /*
  413. CString szNode;
  414. if (IS_CLASS(*pNode, CDNSRootData))
  415. {
  416. szNode = _T("Root Node");
  417. }
  418. else if (IS_CLASS(*pNode, CDNSServerNode))
  419. {
  420. szNode = _T("Server Node");
  421. }
  422. else if (IS_CLASS(*pNode, CDNSForwardZonesNode))
  423. {
  424. szNode = _T("Forward Zones Node");
  425. }
  426. else if (IS_CLASS(*pNode, CDNSReverseZonesNode))
  427. {
  428. szNode = _T("Reverse Zones Node");
  429. }
  430. else if (IS_CLASS(*pNode, CDNSZoneNode))
  431. {
  432. szNode = _T("Zone Node");
  433. }
  434. else if (IS_CLASS(*pNode, CDNSDomainNode))
  435. {
  436. szNode = _T("Domain Node");
  437. }
  438. else if (IS_CLASS(*pNode, CDNSCacheNode))
  439. {
  440. szNode = _T("Domain Node");
  441. }
  442. else if (dynamic_cast<CDNSRecordNodeBase*>(pNode) != NULL)
  443. {
  444. szNode = _T("Record Node");
  445. }
  446. if (!szNode.IsEmpty())
  447. {
  448. CString szMsg = _T("Context Help on ");
  449. szMsg += szNode;
  450. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  451. CThemeContextActivator activator;
  452. AfxMessageBox(szMsg);
  453. }
  454. */
  455. }
  456. LPCWSTR g_szContextHelpFileName = L"\\help\\adsiedit.hlp";
  457. LPCWSTR g_szHTMLHelpFileName = L"w2rksupp.chm";
  458. LPCWSTR CADSIEditComponentDataObject::GetHTMLHelpFileName()
  459. {
  460. return g_szHTMLHelpFileName;
  461. }
  462. void CADSIEditComponentDataObject::OnDialogContextHelp(UINT nDialogID, HELPINFO* pHelpInfo)
  463. {
  464. ULONG nContextTopic;
  465. // TODO
  466. //if (FindDialogContextTopic(nDialogID, pHelpInfo, &nContextTopic))
  467. // WinHelp(g_szContextHelpFileName, HELP_CONTEXTPOPUP, nContextTopic);
  468. }
  469. STDMETHODIMP CADSIEditComponentDataObject::GetHelpTopic(LPOLESTR* lpCompiledHelpFile)
  470. {
  471. // FUTURE-2002/02/21-artm Review function to make sure that all return values are
  472. // documented for ISnapinHelp.
  473. if (lpCompiledHelpFile == NULL)
  474. return E_INVALIDARG;
  475. LPCWSTR lpszHelpFileName = GetHTMLHelpFileName();
  476. if (lpszHelpFileName == NULL)
  477. {
  478. *lpCompiledHelpFile = NULL;
  479. return E_NOTIMPL;
  480. }
  481. // FUTURE-2002/02/21-artm Replace string literals with named constants.
  482. // Will improve readability and maintenance.
  483. CString szResourceKitDir = _T("");
  484. CString szKey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Components\\5A18D5BFC37FA0A4E99D24135BABE742";
  485. HRESULT err = S_OK;
  486. CRegKey key;
  487. LONG lRes = key.Open(HKEY_LOCAL_MACHINE, szKey);
  488. _REPORT_FAIL(L"key.Open(HKEY_LOCAL_MACHINE", szKey, lRes);
  489. if (lRes == ERROR_SUCCESS)
  490. {
  491. DWORD dwCount = 2 * MAX_PATH;
  492. PTSTR ptszValue = new TCHAR[dwCount];
  493. DWORD byteCount = dwCount * sizeof(TCHAR);
  494. DWORD bytesCopied = byteCount;
  495. ZeroMemory(ptszValue, byteCount);
  496. // NOTICE-NTRAID#NTBUG9-550463-2002/02/21-artm
  497. // Need to check that string read from registry null terminated.
  498. lRes = key.QueryValue(
  499. ptszValue, // Destination buffer.
  500. L"DC5632422F082D1189A9000CF497879A", // Value to read
  501. &bytesCopied); // In: size of destination buffer; Out: number of bytes written.
  502. _REPORT_FAIL(L"key.QueryValue(key", L"DC5632422F082D1189A9000CF497879A", lRes);
  503. if (lRes == ERROR_SUCCESS &&
  504. // Make sure that the value read wasn't truncated.
  505. ptszValue[dwCount - 1] == NULL &&
  506. // Check that something was written.
  507. bytesCopied > 0)
  508. {
  509. CString szValue = ptszValue;
  510. // Extract the directory from the path read from the registry.
  511. szResourceKitDir = szValue.Left(szValue.ReverseFind(L'\\') + 1);
  512. }
  513. else
  514. {
  515. if (lRes == ERROR_SUCCESS)
  516. {
  517. // This should never happen unless someone changed the location.
  518. // If it breaks from that it should be caught during testing.
  519. ASSERT(false);
  520. err = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
  521. }
  522. }
  523. // NOTICE-NTRAID#NTBUG9-550528-2002/02/21-artm Memory leak if lRes != ERROR_SUCCESS.
  524. // Fixed by moving delete outside of if()else statement.
  525. delete[] ptszValue;
  526. }
  527. if (FAILED(err))
  528. {
  529. return err;
  530. }
  531. CString szHelpFilePath = szResourceKitDir + CString(lpszHelpFileName);
  532. UINT nBytes = (szHelpFilePath.GetLength()+1) * sizeof(WCHAR);
  533. // NOTICE-2002/02/21-artm lpCompiledHelpFile strictly an out parameter
  534. //
  535. // Since lpCompiledHelpFile is an OUT parm for ISnapinHelp::GetHelpTopic(),
  536. // it is assumed here that no memory has been allocated to the pointer. If
  537. // the caller mistakenly does allocate lpCompiledHelpFile some memory before
  538. // calling, this will result in leaking memory since this function does not
  539. // free that memory before allocating memory with CoTaskMemAlloc().
  540. *lpCompiledHelpFile = (LPOLESTR)::CoTaskMemAlloc(nBytes);
  541. if (*lpCompiledHelpFile != NULL)
  542. {
  543. memcpy(*lpCompiledHelpFile, (LPCWSTR)szHelpFilePath, nBytes);
  544. }
  545. else
  546. {
  547. // NOTICE-NTRAID-NTBUG9-551264-2002/02/21-artm Need to handle case where CoTaskMemAlloc() fails.
  548. // If allocation fails, should return error code, not S_OK.
  549. err = E_OUTOFMEMORY;
  550. }
  551. return err;
  552. }
  553. ////////////////////////////////////////////////////////////////////////////////
  554. // help context macros and maps
  555. #if (FALSE)
  556. #define BEGIN_HELP_MAP(map) static DWORD map[] = {
  557. #define HELP_MAP_ENTRY(x) x, (DWORD)&g_aHelpIDs_##x ,
  558. #define END_HELP_MAP 0, 0 };
  559. #define NEXT_HELP_MAP_ENTRY(p) ((p)+2)
  560. #define MAP_ENTRY_DLG_ID(p) (*p)
  561. #define MAP_ENTRY_TABLE(p) ((DWORD*)(*(p+1)))
  562. #define IS_LAST_MAP_ENTRY(p) (MAP_ENTRY_DLG_ID(p) == 0)
  563. #define NEXT_HELP_TABLE_ENTRY(p) ((p)+2)
  564. #define TABLE_ENTRY_CTRL_ID(p) (*p)
  565. #define TABLE_ENTRY_HELP_ID(p) (*(p+1))
  566. #define IS_LAST_TABLE_ENTRY(p) (TABLE_ENTRY_CTRL_ID(p) == 0)
  567. BEGIN_HELP_MAP(_DNSMgrContextHelpMap)
  568. // misc dialogs
  569. HELP_MAP_ENTRY(IDD_CHOOSER_CHOOSE_MACHINE)
  570. HELP_MAP_ENTRY(IDD_BROWSE_DIALOG)
  571. // misc. add dialogs
  572. HELP_MAP_ENTRY(IDD_DOMAIN_ADDNEWHOST) // TODO
  573. HELP_MAP_ENTRY(IDD_DOMAIN_ADDNEWDOMAIN)// TODO
  574. HELP_MAP_ENTRY(IDD_SELECT_RECORD_TYPE_DIALOG)
  575. // NOTE: this has several incarnations...
  576. HELP_MAP_ENTRY(IDD_NAME_SERVERS_PAGE)
  577. // server property pages
  578. HELP_MAP_ENTRY(IDD_SERVER_INTERFACES_PAGE)
  579. HELP_MAP_ENTRY(IDD_SERVER_FORWARDERS_PAGE)
  580. HELP_MAP_ENTRY(IDD_SERVER_ADVANCED_PAGE)
  581. HELP_MAP_ENTRY(IDD_SERVER_LOGGING_PAGE)
  582. HELP_MAP_ENTRY(IDD_SERVER_BOOTMETHOD_PAGE)
  583. HELP_MAP_ENTRY(IDD_SERVMON_STATISTICS_PAGE)
  584. HELP_MAP_ENTRY(IDD_SERVMON_TEST_PAGE)
  585. // zone property pages
  586. HELP_MAP_ENTRY(IDD_ZONE_GENERAL_PAGE)
  587. HELP_MAP_ENTRY(IDD_ZONE_WINS_PAGE)
  588. HELP_MAP_ENTRY(IDD_ZONE_NBSTAT_PAGE)
  589. HELP_MAP_ENTRY(IDD_ZONE_NOTIFY_PAGE)
  590. HELP_MAP_ENTRY(IDD_ZONE_WINS_ADVANCED) // this is a subdialog, need to hook up
  591. // record property pages
  592. HELP_MAP_ENTRY(IDD_RR_NS_EDIT)
  593. HELP_MAP_ENTRY(IDD_RR_SOA)
  594. HELP_MAP_ENTRY(IDD_RR_A)
  595. HELP_MAP_ENTRY(IDD_RR_CNAME)
  596. HELP_MAP_ENTRY(IDD_RR_MX)
  597. HELP_MAP_ENTRY(IDD_RR_UNK)
  598. HELP_MAP_ENTRY(IDD_RR_TXT)
  599. HELP_MAP_ENTRY(IDD_RR_X25)
  600. HELP_MAP_ENTRY(IDD_RR_ISDN)
  601. HELP_MAP_ENTRY(IDD_RR_HINFO)
  602. HELP_MAP_ENTRY(IDD_RR_AAAA)
  603. HELP_MAP_ENTRY(IDD_RR_MB)
  604. HELP_MAP_ENTRY(IDD_RR_MG)
  605. HELP_MAP_ENTRY(IDD_RR_MD)
  606. HELP_MAP_ENTRY(IDD_RR_MF)
  607. HELP_MAP_ENTRY(IDD_RR_MR)
  608. HELP_MAP_ENTRY(IDD_RR_MINFO)
  609. HELP_MAP_ENTRY(IDD_RR_RP)
  610. HELP_MAP_ENTRY(IDD_RR_RT)
  611. HELP_MAP_ENTRY(IDD_RR_AFSDB)
  612. HELP_MAP_ENTRY(IDD_RR_WKS)
  613. HELP_MAP_ENTRY(IDD_RR_PTR)
  614. HELP_MAP_ENTRY(IDD_RR_SRV)
  615. HELP_MAP_ENTRY(IDD_RR_KEY)
  616. HELP_MAP_ENTRY(IDD_RR_SIG)
  617. END_HELP_MAP
  618. BOOL CDNSComponentDataObjectBase::FindDialogContextTopic(/*IN*/UINT nDialogID,
  619. /*IN*/ HELPINFO* pHelpInfo,
  620. /*OUT*/ ULONG* pnContextTopic)
  621. {
  622. ASSERT(pHelpInfo != NULL);
  623. *pnContextTopic = 0;
  624. const DWORD* pMapEntry = _DNSMgrContextHelpMap;
  625. while (!IS_LAST_MAP_ENTRY(pMapEntry))
  626. {
  627. if (nDialogID == MAP_ENTRY_DLG_ID(pMapEntry))
  628. {
  629. DWORD* pTable = MAP_ENTRY_TABLE(pMapEntry);
  630. // look inside the table
  631. while (!IS_LAST_TABLE_ENTRY(pTable))
  632. {
  633. if (TABLE_ENTRY_CTRL_ID(pTable) == pHelpInfo->iCtrlId)
  634. {
  635. *pnContextTopic = TABLE_ENTRY_HELP_ID(pTable);
  636. return TRUE;
  637. }
  638. pTable = NEXT_HELP_TABLE_ENTRY(pTable);
  639. }
  640. }
  641. pMapEntry = NEXT_HELP_MAP_ENTRY(pMapEntry);
  642. }
  643. return FALSE;
  644. }
  645. #endif
  646. //////////////////////////////////////////////////////////////////////////
  647. // CADSIEditAbout
  648. CADSIEditAbout::CADSIEditAbout()
  649. {
  650. m_szProvider = IDS_SNAPIN_PROVIDER;
  651. m_szVersion = IDS_SNAPIN_VERSION;
  652. m_uIdStrDestription = IDS_SNAPINABOUT_DESCRIPTION;
  653. m_uIdIconImage = IDI_ADSIEDIT_SNAPIN;
  654. m_uIdBitmapSmallImage = IDB_ABOUT_16x16;
  655. m_uIdBitmapSmallImageOpen = IDB_ABOUT_16x16;
  656. m_uIdBitmapLargeImage = IDB_ABOUT_32x32;
  657. m_crImageMask = BMP_COLOR_MASK;
  658. }