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.

962 lines
23 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: domobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "domobj.h"
  12. #include "domobjui.h"
  13. #include "cdomain.h"
  14. #include "domain.h"
  15. #include "proppage.h"
  16. #include "notify.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. ///////////////////////////////////////////////////////////////////////
  23. // global helper functions
  24. int _MessageBox(HWND hWnd, // handle to owner window
  25. LPCTSTR lpText, // pointer to text in message box
  26. UINT uType) // style of message box
  27. {
  28. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  29. CString szCaption;
  30. szCaption.LoadString(AFX_IDS_APP_TITLE);
  31. return ::MessageBox(hWnd, lpText, szCaption, uType);
  32. }
  33. void ReportError(HWND hWnd, UINT nMsgID, HRESULT hr)
  34. {
  35. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  36. LPTSTR ptzSysMsg = NULL;
  37. int cch = 0;
  38. int retval = MB_OK;
  39. // load message for this HRESULT
  40. cch = cchLoadHrMsg( hr, &ptzSysMsg, TRUE );
  41. CString szError;
  42. if (cch == 0)
  43. {
  44. // could not get a message string, format the raw hr value
  45. CString s;
  46. s.LoadString(IDS_FAILURE_UNK);
  47. szError.Format((LPCWSTR)s, hr);
  48. }
  49. else
  50. {
  51. szError = ptzSysMsg;
  52. }
  53. // format message string with
  54. CString szFmt;
  55. szFmt.LoadString(nMsgID);
  56. CString szMsg;
  57. szMsg.Format((LPCWSTR)szFmt, (LPCWSTR)szError);
  58. _MessageBox(hWnd, szMsg, MB_OK|MB_ICONERROR);
  59. // cleanup
  60. if (NULL != ptzSysMsg)
  61. LocalFree(ptzSysMsg);
  62. }
  63. ///////////////////////////////////////////////////////////////////////
  64. //CDsUiWizDLL g_dsUiWizDLL;
  65. enum
  66. {
  67. // Identifiers for each of the commands to be inserted into the context menu.
  68. IDM_MANAGE,
  69. IDM_TRUST_WIZ,
  70. IDM_RETARGET,
  71. IDM_EDIT_FSMO,
  72. IDM_DOMAIN_VERSION,
  73. IDM_FOREST_VERSION
  74. };
  75. HRESULT _AddMenuItemHelper(IContextMenuCallback* pIContextMenuCallback,
  76. UINT nResourceID, // contains text and status text seperated by '\n'
  77. long lCommandID,
  78. long lInsertionPointID,
  79. long fFlags = 0,
  80. long fSpecialFlags = 0)
  81. {
  82. ASSERT( pIContextMenuCallback != NULL );
  83. // load the resource
  84. CString strText;
  85. strText.LoadString(nResourceID);
  86. ASSERT( !strText.IsEmpty() );
  87. // split the resource into the menu text and status text
  88. CString strStatusText;
  89. int iSeparator = strText.Find(_T('\n'));
  90. if (0 > iSeparator)
  91. {
  92. ASSERT( FALSE );
  93. strStatusText = strText;
  94. }
  95. else
  96. {
  97. strStatusText = strText.Right( strText.GetLength()-(iSeparator+1) );
  98. strText = strText.Left( iSeparator );
  99. }
  100. // add the menu item
  101. USES_CONVERSION;
  102. CONTEXTMENUITEM contextmenuitem;
  103. ::ZeroMemory( &contextmenuitem, sizeof(contextmenuitem) );
  104. contextmenuitem.strName = T2OLE(const_cast<LPTSTR>((LPCTSTR)strText));
  105. contextmenuitem.strStatusBarText = T2OLE(const_cast<LPTSTR>((LPCTSTR)strStatusText));
  106. contextmenuitem.lCommandID = lCommandID;
  107. contextmenuitem.lInsertionPointID = lInsertionPointID;
  108. contextmenuitem.fFlags = fFlags;
  109. contextmenuitem.fSpecialFlags = fSpecialFlags;
  110. HRESULT hr = pIContextMenuCallback->AddItem( &contextmenuitem );
  111. ASSERT(hr == S_OK);
  112. return hr;
  113. }
  114. ///////////////////////////////////////////////////////////////////////
  115. // CDomainTreeBrowser
  116. HRESULT CDomainTreeBrowser::Bind(MyBasePathsInfo* pInfo)
  117. {
  118. TRACE(L"CDomainTreeBrowser::Bind()\n");
  119. ASSERT(pInfo != NULL);
  120. _Reset();
  121. HRESULT hr = S_OK;
  122. // create a browse object
  123. hr = ::CoCreateInstance(CLSID_DsDomainTreeBrowser,
  124. NULL,
  125. CLSCTX_INPROC_SERVER,
  126. IID_IDsBrowseDomainTree,
  127. (LPVOID*)&m_spIDsBrowseDomainTree);
  128. if (FAILED(hr))
  129. {
  130. TRACE(L"CoCreateInstance(CLSID_DsDomainTreeBrowser, ...) failed with hr = 0x%x\n");
  131. goto error;
  132. }
  133. // set the target computer
  134. hr = m_spIDsBrowseDomainTree->SetComputer(pInfo->GetServerName(), NULL, NULL);
  135. TRACE(L"m_spIDsBrowseDomainTree->SetComputer(%s, NULL, NULL) returned hr = 0x%x\n",
  136. pInfo->GetServerName(), hr);
  137. if (FAILED(hr))
  138. goto error;
  139. ASSERT(SUCCEEDED(hr));
  140. return hr; // all was fine
  141. error:
  142. // things went wrong, clear all
  143. _Reset();
  144. return hr;
  145. }
  146. HRESULT CDomainTreeBrowser::GetData()
  147. {
  148. ASSERT(m_spIDsBrowseDomainTree != NULL);
  149. HRESULT hr = S_OK;
  150. PDOMAIN_TREE pNewDomains = NULL;
  151. m_spIDsBrowseDomainTree->FlushCachedDomains();
  152. DWORD dwFlags = DBDTF_RETURNFQDN;
  153. hr = m_spIDsBrowseDomainTree->GetDomains(&pNewDomains, dwFlags);
  154. TRACE(L"m_spIDsBrowseDomainTree->GetDomains(...) returned hr = 0x%x\n", hr);
  155. if (SUCCEEDED(hr) && (pNewDomains != NULL))
  156. {
  157. _FreeDomains();
  158. m_pDomains = pNewDomains;
  159. }
  160. return hr;
  161. }
  162. ///////////////////////////////////////////////////////////////////////
  163. // CFolderObject
  164. CFolderObject::~CFolderObject()
  165. {
  166. RemoveAllChildren();
  167. }
  168. BOOL CFolderObject::AddChild(CFolderObject* pChildFolderObject)
  169. {
  170. return (m_childList.AddTail(pChildFolderObject) != NULL);
  171. }
  172. void CFolderObject::RemoveAllChildren()
  173. {
  174. while (!m_childList.IsEmpty())
  175. delete m_childList.RemoveHead();
  176. }
  177. void CFolderObject::IncrementSheetLockCount()
  178. {
  179. ++m_nSheetLockCount;
  180. if (m_pParentFolder != NULL)
  181. m_pParentFolder->IncrementSheetLockCount();
  182. }
  183. void CFolderObject::DecrementSheetLockCount()
  184. {
  185. ASSERT(m_nSheetLockCount > 0);
  186. --m_nSheetLockCount;
  187. if (m_pParentFolder != NULL)
  188. m_pParentFolder->DecrementSheetLockCount();
  189. }
  190. BOOL CFolderObject::_WarningOnSheetsUp(CComponentDataImpl* pCD)
  191. {
  192. if (!IsSheetLocked())
  193. return FALSE; // no warning, all is cool
  194. // warning to user that oeration cannot be performed
  195. AfxMessageBox(IDS_SHEETS_UP_DELETE, MB_OK);
  196. ASSERT(FALSE);
  197. // need to bring sheets on the foreground
  198. pCD->GetCookieSheet()->BringToForeground(this, pCD);
  199. return TRUE;
  200. }
  201. ///////////////////////////////////////////////////////////////////////
  202. // CRootFolderObject
  203. CRootFolderObject::CRootFolderObject(CComponentDataImpl* pCD) :
  204. m_pEnterpriseRoot(NULL)
  205. {
  206. m_pCD = pCD;
  207. }
  208. HRESULT CRootFolderObject::Bind()
  209. {
  210. return m_domainTreeBrowser.Bind(m_pCD->GetBasePathsInfo());
  211. }
  212. HRESULT CRootFolderObject::GetData()
  213. {
  214. HRESULT hr = m_domainTreeBrowser.GetData();
  215. if (FAILED(hr))
  216. return hr;
  217. // firs time, try to load the domain icon
  218. VERIFY(SUCCEEDED(m_pCD->AddDomainIcon()));
  219. RemoveAllChildren(); // clear the UI structures
  220. return hr;
  221. }
  222. HRESULT CRootFolderObject::EnumerateRootFolder(CComponentDataImpl* pComponentData)
  223. {
  224. TRACE(L"CRootFolderObject::EnumerateRootFolder()\n");
  225. if (!m_domainTreeBrowser.HasData())
  226. {
  227. TRACE(L"m_domainTreeBrowser.HasData() == FALSE \n");
  228. return S_OK;
  229. }
  230. HRESULT hr = S_OK;
  231. MyBasePathsInfo * pBPI;
  232. //
  233. // Get the enterprise root domain DN from the RootDSE.
  234. //
  235. pBPI = pComponentData->GetBasePathsInfo();
  236. if (!pBPI)
  237. {
  238. ASSERT(FALSE);
  239. return E_FAIL;
  240. }
  241. PCWSTR pwzRoot = pBPI->GetRootDomainNamingContext();
  242. TRACE(L"Root path: %ws\n", pwzRoot);
  243. PDOMAIN_DESC pRootDomain = NULL;
  244. //
  245. // Insert the root nodes. First insert the enterprise root.
  246. //
  247. for (pRootDomain = m_domainTreeBrowser.GetDomainTree()->aDomains; pRootDomain;
  248. pRootDomain = pRootDomain->pdNextSibling)
  249. {
  250. if (_wcsicmp(pwzRoot, pRootDomain->pszNCName) == 0)
  251. {
  252. TRACE(L"Enterprise root found!\n");
  253. CDomainObject* pDomain = new CDomainObject;
  254. if (!pDomain)
  255. {
  256. ASSERT(FALSE);
  257. return E_OUTOFMEMORY;
  258. }
  259. pDomain->Initialize(pRootDomain, m_pCD->GetDomainImageIndex());
  260. AddChild(pDomain);
  261. pDomain->SetParentFolder(this);
  262. hr = pComponentData->AddFolder(pDomain, GetScopeID(), TRUE); // has children
  263. if (FAILED(hr))
  264. {
  265. return hr;
  266. }
  267. //
  268. // Create a non-refcounted reference to the enterprise root domain node.
  269. // Do NOT call delete on the m_pEnterpriseRoot pointer!
  270. //
  271. m_pEnterpriseRoot = pDomain;
  272. break;
  273. }
  274. }
  275. //
  276. // Now insert the rest of the root nodes.
  277. //
  278. for (pRootDomain = m_domainTreeBrowser.GetDomainTree()->aDomains; pRootDomain;
  279. pRootDomain = pRootDomain->pdNextSibling)
  280. {
  281. if (_wcsicmp(pwzRoot, pRootDomain->pszNCName) == 0)
  282. {
  283. // Root already inserted.
  284. continue;
  285. }
  286. CDomainObject* pDomain = new CDomainObject;
  287. if (!pDomain)
  288. {
  289. ASSERT(FALSE);
  290. return E_OUTOFMEMORY;
  291. }
  292. pDomain->Initialize(pRootDomain, m_pCD->GetDomainImageIndex());
  293. AddChild(pDomain);
  294. pDomain->SetParentFolder(this);
  295. hr = pComponentData->AddFolder(pDomain, GetScopeID(), TRUE); // has children
  296. if (FAILED(hr))
  297. {
  298. break;
  299. }
  300. }
  301. return hr;
  302. }
  303. HRESULT
  304. CRootFolderObject::EnumerateFolder(CFolderObject* pFolderObject,
  305. HSCOPEITEM pParent,
  306. CComponentDataImpl* pComponentData)
  307. {
  308. HRESULT hr = E_FAIL;
  309. if (!m_domainTreeBrowser.HasData())
  310. return hr;
  311. ASSERT(pFolderObject != NULL);
  312. ASSERT(pFolderObject->GetScopeID() == pParent);
  313. CDomainObject* pDomainObject = dynamic_cast<CDomainObject*>(pFolderObject);
  314. if (pDomainObject == NULL)
  315. return hr;
  316. DOMAIN_DESC* pDomainDesc = pDomainObject->GetDescriptionPtr();
  317. if (pDomainDesc == NULL)
  318. return hr;
  319. if (pDomainDesc->pdChildList == NULL)
  320. return S_OK;
  321. for (DOMAIN_DESC* pChild = pDomainDesc->pdChildList; pChild;
  322. pChild = pChild->pdNextSibling)
  323. {
  324. CDomainObject* pDomain = new CDomainObject;
  325. pDomain->Initialize(pChild,
  326. m_pCD->GetDomainImageIndex());
  327. hr = pComponentData->AddFolder(pDomain, pDomainObject->GetScopeID(),
  328. TRUE); // has children
  329. pFolderObject->AddChild(pDomain);
  330. pDomain->SetParentFolder(pFolderObject);
  331. if (FAILED(hr))
  332. break;
  333. } // for
  334. return hr;
  335. }
  336. HRESULT CRootFolderObject::OnAddMenuItems(LPCONTEXTMENUCALLBACK pContextMenuCallback,
  337. long *pInsertionAllowed)
  338. {
  339. HRESULT hr = S_OK;
  340. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  341. {
  342. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  343. /*
  344. if (g_dsUiWizDLL.Load())
  345. {
  346. return _AddMenuItemHelper(pContextMenuCallback, IDS_COMMAND_TRUST_WIZ, IDM_TRUST_WIZ, CCM_INSERTIONPOINTID_PRIMARY_TOP);
  347. }
  348. */
  349. _AddMenuItemHelper(pContextMenuCallback, IDS_COMMAND_RETARGET, IDM_RETARGET, CCM_INSERTIONPOINTID_PRIMARY_TOP);
  350. _AddMenuItemHelper(pContextMenuCallback, IDS_COMMAND_EDIT_FSMO, IDM_EDIT_FSMO, CCM_INSERTIONPOINTID_PRIMARY_TOP);
  351. _AddMenuItemHelper(pContextMenuCallback, IDS_COMMAND_FOREST_VER, IDM_FOREST_VERSION, CCM_INSERTIONPOINTID_PRIMARY_TOP);
  352. }
  353. return hr;
  354. }
  355. HRESULT CRootFolderObject::OnCommand(CComponentDataImpl* pCD, long nCommandID)
  356. {
  357. HRESULT hr = S_OK;
  358. CString strConfig, strPartitions, strSchema;
  359. switch (nCommandID)
  360. {
  361. //case IDM_TRUST_WIZ:
  362. // OnDomainTrustWizard();
  363. // break;
  364. case IDM_RETARGET:
  365. OnRetarget();
  366. break;
  367. case IDM_EDIT_FSMO:
  368. OnEditFSMO();
  369. break;
  370. case IDM_FOREST_VERSION:
  371. MyBasePathsInfo * pBPI;
  372. pBPI = pCD->GetBasePathsInfo();
  373. if (!pBPI)
  374. {
  375. ASSERT(FALSE);
  376. return E_FAIL;
  377. }
  378. pBPI->GetConfigPath(strConfig);
  379. pBPI->GetPartitionsPath(strPartitions);
  380. pBPI->GetSchemaPath(strSchema);
  381. HWND hWndParent;
  382. pCD->GetMainWindow(&hWndParent);
  383. CDomainObject* pRoot;
  384. pRoot = GetEnterpriseRootNode();
  385. if (!pRoot)
  386. {
  387. ASSERT(FALSE);
  388. return E_FAIL;
  389. }
  390. DSPROP_ForestVersionDlg(strConfig, strPartitions, strSchema,
  391. pRoot->GetDomainName(), hWndParent);
  392. break;
  393. default:
  394. ASSERT(FALSE); // Unknown command!
  395. hr = E_FAIL;
  396. }
  397. return hr;
  398. }
  399. //void CRootFolderObject::OnDomainTrustWizard()
  400. //{
  401. //g_dsUiWizDLL.TrustWizard();
  402. //}
  403. void CRootFolderObject::OnRetarget()
  404. {
  405. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  406. if (_WarningOnSheetsUp(m_pCD))
  407. return;
  408. HWND hWndParent;
  409. m_pCD->GetMainWindow(&hWndParent);
  410. CComPtr<IDsAdminChooseDC> spIDsAdminChooseDC;
  411. CComBSTR bstrSelectedDC;
  412. HRESULT hr = ::CoCreateInstance(CLSID_DsAdminChooseDCObj,
  413. NULL,
  414. CLSCTX_INPROC_SERVER,
  415. IID_IDsAdminChooseDC,
  416. (void **) &spIDsAdminChooseDC);
  417. if (FAILED(hr))
  418. {
  419. ::ReportError(hWndParent, IDS_CANT_GET_PARTITIONS_INFORMATION, hr);
  420. return;
  421. }
  422. // invoke the dialog
  423. hr = spIDsAdminChooseDC->InvokeDialog(hWndParent,
  424. m_pCD->GetBasePathsInfo()->GetDomainName(),
  425. m_pCD->GetBasePathsInfo()->GetServerName(),
  426. 0x0,
  427. &bstrSelectedDC);
  428. if (SUCCEEDED(hr) && (hr != S_FALSE))
  429. {
  430. TRACE(L"CChangeDCDialog returned IDOK, with dlg.GetNewDCName() = %s\n", bstrSelectedDC);
  431. // attempt to bind
  432. MyBasePathsInfo tempBasePathsInfo;
  433. {
  434. CWaitCursor wait;
  435. hr = tempBasePathsInfo.InitFromName(bstrSelectedDC);
  436. }
  437. TRACE(L"tempBasePathsInfo.GetServerName() == %s\n", tempBasePathsInfo.GetServerName());
  438. if (FAILED(hr))
  439. {
  440. TRACE(L"tempBasePathsInfo.InitFromName(bstrSelectedDC) failed with hr = 0x%x\n", hr);
  441. ReportError(hWndParent, IDS_CANT_GET_PARTITIONS_INFORMATION, hr);
  442. // TODO: error handling, change icon
  443. }
  444. else
  445. {
  446. m_pCD->GetBasePathsInfo()->InitFromInfo(&tempBasePathsInfo);
  447. m_pCD->SetInit();
  448. TRACE(L"m_pCD->GetBasePathsInfo()->GetServerName() == %s\n", m_pCD->GetBasePathsInfo()->GetServerName());
  449. hr = m_pCD->GetDsDisplaySpecOptionsCFHolder()->Init(m_pCD->GetBasePathsInfo());
  450. ASSERT(SUCCEEDED(hr));
  451. {
  452. CWaitCursor wait;
  453. m_pCD->OnRefreshVerbHandler(this, NULL, TRUE /*bBindAgain */);
  454. }
  455. } // if
  456. } // if
  457. }
  458. void CRootFolderObject::OnEditFSMO()
  459. {
  460. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  461. HWND hWndParent;
  462. m_pCD->GetMainWindow(&hWndParent);
  463. CComPtr<IDisplayHelp> spIDisplayHelp;
  464. HRESULT hr = m_pCD->m_pConsole->QueryInterface (IID_IDisplayHelp,
  465. (void **)&spIDisplayHelp);
  466. ASSERT(spIDisplayHelp != NULL);
  467. CEditFsmoDialog dlg(m_pCD->GetBasePathsInfo(), hWndParent, spIDisplayHelp);
  468. dlg.DoModal();
  469. }
  470. HRESULT CRootFolderObject::OnAddPages(LPPROPERTYSHEETCALLBACK lpProvider,
  471. LONG_PTR handle)
  472. {
  473. CUpnSuffixPropertyPage* pPage = new CUpnSuffixPropertyPage();
  474. HPROPSHEETPAGE hPage = ::CreatePropertySheetPage(&pPage->m_psp);
  475. return lpProvider->AddPage(hPage);
  476. }
  477. ///////////////////////////////////////////////////////////////////////
  478. // CDomainObject
  479. CDomainObject::~CDomainObject()
  480. {
  481. if (m_bSecondary)
  482. {
  483. ASSERT(m_pDomainDescription != NULL);
  484. ::free(m_pDomainDescription);
  485. }
  486. }
  487. LPCTSTR CDomainObject::GetDisplayString(int nCol)
  488. {
  489. switch (nCol)
  490. {
  491. case 0:
  492. return GetDomainName();
  493. case 1:
  494. return GetClass();
  495. default:
  496. ASSERT(FALSE);
  497. } // switch
  498. return _T("");
  499. }
  500. void CDomainObject::Initialize(DOMAIN_DESC* pDomainDescription,
  501. int nImage,
  502. BOOL bHasChildren)
  503. {
  504. SetImageIndex(nImage);
  505. // save pointer to domain description in DOMAIN_TREE
  506. m_pDomainDescription = pDomainDescription;
  507. }
  508. void CDomainObject::InitializeForSecondaryPage(LPCWSTR pszNCName,
  509. LPCWSTR pszObjectClass,
  510. int nImage)
  511. {
  512. ASSERT(pszNCName != NULL);
  513. ASSERT(pszObjectClass != NULL);
  514. SetImageIndex(nImage);
  515. // standalone node, need to build a dummy DOMAIN_DESC
  516. m_bSecondary = TRUE;
  517. // allocate and zero memory
  518. int nNCNameLen = lstrlen(pszNCName)+1;
  519. int nObjectClassLen = lstrlen(pszObjectClass)+1;
  520. int nByteLen = sizeof(DOMAIN_DESC) + sizeof(WCHAR)*(nNCNameLen + nObjectClassLen);
  521. m_pDomainDescription = (DOMAIN_DESC*)::malloc(nByteLen);
  522. ASSERT(m_pDomainDescription);
  523. if (!m_pDomainDescription)
  524. {
  525. return;
  526. }
  527. ::ZeroMemory(m_pDomainDescription, nByteLen);
  528. // copy the strings
  529. m_pDomainDescription->pszNCName = (WCHAR*) (((BYTE*)m_pDomainDescription) + sizeof(DOMAIN_DESC));
  530. wcscpy(m_pDomainDescription->pszNCName, pszNCName);
  531. m_pDomainDescription->pszObjectClass = (WCHAR*) (((BYTE*)m_pDomainDescription->pszNCName) + sizeof(WCHAR)*nNCNameLen);
  532. wcscpy(m_pDomainDescription->pszObjectClass, pszObjectClass);
  533. }
  534. HRESULT CDomainObject::OnAddMenuItems(LPCONTEXTMENUCALLBACK pContextMenuCallback,
  535. long *pInsertionAllowed)
  536. {
  537. HRESULT hr = S_OK;
  538. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  539. {
  540. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  541. hr = _AddMenuItemHelper(pContextMenuCallback, IDS_COMMAND_MANAGE, IDM_MANAGE, CCM_INSERTIONPOINTID_PRIMARY_TOP);
  542. if (FAILED(hr))
  543. return hr;
  544. hr = _AddMenuItemHelper(pContextMenuCallback, IDS_COMMAND_DOMAIN_VER, IDM_DOMAIN_VERSION, CCM_INSERTIONPOINTID_PRIMARY_TOP);
  545. if (FAILED(hr))
  546. return hr;
  547. }
  548. return hr;
  549. }
  550. HRESULT CDomainObject::OnCommand(CComponentDataImpl* pCD, long nCommandID)
  551. {
  552. HRESULT hr = S_OK;
  553. CString strPath;
  554. switch (nCommandID)
  555. {
  556. case IDM_MANAGE:
  557. OnManage(pCD);
  558. break;
  559. //case IDM_TRUST_WIZ:
  560. // OnDomainTrustWizard(pCD);
  561. // break;
  562. case IDM_DOMAIN_VERSION:
  563. HWND hWndParent;
  564. MyBasePathsInfo * pBPI;
  565. pBPI = pCD->GetBasePathsInfo();
  566. if (!pBPI)
  567. {
  568. ASSERT(FALSE);
  569. return E_FAIL;
  570. }
  571. pCD->GetMainWindow(&hWndParent);
  572. // build an LDAP path out of the DN
  573. if (PdcAvailable())
  574. {
  575. strPath = L"LDAP://";
  576. strPath += GetPDC();
  577. strPath += L"/";
  578. strPath += GetNCName();
  579. }
  580. else
  581. {
  582. pBPI->ComposeADsIPath(strPath, GetNCName());
  583. }
  584. DSPROP_DomainVersionDlg(strPath, GetDomainName(), hWndParent);
  585. break;
  586. default:
  587. ASSERT(FALSE); // Unknown command!
  588. hr = E_FAIL;
  589. }
  590. return hr;
  591. }
  592. void CDomainObject::OnManage(CComponentDataImpl* pCD)
  593. {
  594. static LPCWSTR lpszSearchArr[] =
  595. {
  596. L"%userprofile%\\Application Data\\Microsoft\\AdminTools\\dsa.msc",
  597. L"%systemroot%\\system32\\dsa.msc",
  598. NULL
  599. };
  600. WCHAR szParamString[MAX_PATH];
  601. WCHAR szFileName[MAX_PATH];
  602. wcscpy (szParamString, L" /Domain=");
  603. wcscat (szParamString, (LPWSTR)(GetDomainName()));
  604. SHELLEXECUTEINFO seiManage = {0};
  605. seiManage.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI;
  606. seiManage.cbSize = sizeof (SHELLEXECUTEINFO);
  607. seiManage.lpParameters = (LPCWSTR)&szParamString;
  608. seiManage.nShow = SW_SHOW;
  609. BOOL bExecuted = FALSE;
  610. DWORD dwErr = 0;
  611. for (int k=0; lpszSearchArr[k] != NULL; k++)
  612. {
  613. CWaitCursor cWait;
  614. seiManage.lpFile = (LPCWSTR)lpszSearchArr[k];
  615. if (!ShellExecuteEx(&seiManage))
  616. {
  617. dwErr = ::GetLastError();
  618. }
  619. else
  620. {
  621. bExecuted = TRUE;
  622. break;
  623. }
  624. }
  625. if (!bExecuted)
  626. {
  627. HWND hWndParent;
  628. pCD->GetMainWindow(&hWndParent);
  629. ReportError(hWndParent, IDS_ERROR_MANAGE, HRESULT_FROM_WIN32(dwErr));
  630. }
  631. }
  632. //void CDomainObject::OnDomainTrustWizard(CComponentDataImpl* pCD)
  633. //{
  634. //g_dsUiWizDLL.TrustWizard();
  635. //}
  636. void CDomainObject::SetPdcAvailable(bool fAvail)
  637. {
  638. _fPdcAvailable = fAvail;
  639. }
  640. ////////////////////////////////////////////////////////////////////
  641. // CCookieTableBase
  642. #define NUMBER_OF_COOKIE_TABLE_ENTRIES 4 // default count, expandable at run time
  643. CCookieTableBase::CCookieTableBase() :
  644. m_pCookieArr(NULL)
  645. {
  646. m_nEntries = NUMBER_OF_COOKIE_TABLE_ENTRIES;
  647. m_pCookieArr =(CFolderObject**)malloc(m_nEntries*sizeof(CFolderObject*));
  648. ASSERT(m_pCookieArr);
  649. if (m_pCookieArr)
  650. {
  651. ZeroMemory(m_pCookieArr, m_nEntries*sizeof(CFolderObject*));
  652. }
  653. }
  654. CCookieTableBase::~CCookieTableBase()
  655. {
  656. if (m_pCookieArr)
  657. {
  658. free(m_pCookieArr);
  659. }
  660. }
  661. void CCookieTableBase::Add(CFolderObject* pCookie)
  662. {
  663. ASSERT(!IsPresent(pCookie));
  664. if (!m_pCookieArr)
  665. {
  666. return;
  667. }
  668. UINT nFreeSlot = m_nEntries;
  669. for (UINT k=0; k<m_nEntries; k++)
  670. {
  671. if (m_pCookieArr[k] == NULL)
  672. {
  673. m_pCookieArr[k] = pCookie;
  674. return;
  675. }
  676. }
  677. // no space left, need to allocate
  678. int nAlloc = m_nEntries*2;
  679. m_pCookieArr = (CFolderObject**)realloc(m_pCookieArr, sizeof(CFolderObject*)*nAlloc);
  680. ASSERT(m_pCookieArr);
  681. if (m_pCookieArr)
  682. {
  683. ::ZeroMemory(&m_pCookieArr[m_nEntries], sizeof(CFolderObject*)*m_nEntries);
  684. m_pCookieArr[m_nEntries] = pCookie;
  685. m_nEntries = nAlloc;
  686. }
  687. }
  688. BOOL CCookieTableBase::Remove(CFolderObject* pCookie)
  689. {
  690. if (!m_pCookieArr)
  691. {
  692. return FALSE;
  693. }
  694. for (UINT k=0; k<m_nEntries; k++)
  695. {
  696. if (m_pCookieArr[k] == pCookie)
  697. {
  698. m_pCookieArr[k] = NULL;
  699. return TRUE; // found
  700. }
  701. }
  702. return FALSE; // not found
  703. }
  704. BOOL CCookieTableBase::IsPresent(CFolderObject* pCookie)
  705. {
  706. if (!m_pCookieArr)
  707. {
  708. return FALSE;
  709. }
  710. for (UINT k=0; k<m_nEntries; k++)
  711. {
  712. if (m_pCookieArr[k] == pCookie)
  713. return TRUE;
  714. }
  715. return FALSE;
  716. }
  717. void CCookieTableBase::Reset()
  718. {
  719. if (!m_pCookieArr)
  720. {
  721. return;
  722. }
  723. for (UINT k=0; k<m_nEntries; k++)
  724. {
  725. m_pCookieArr[k] = NULL;
  726. }
  727. }
  728. UINT CCookieTableBase::GetCount()
  729. {
  730. if (!m_pCookieArr)
  731. {
  732. return 0;
  733. }
  734. UINT nCount = 0;
  735. for (UINT k=0; k<m_nEntries; k++)
  736. {
  737. if (m_pCookieArr[k] != NULL)
  738. nCount++;
  739. }
  740. return nCount;
  741. }
  742. ////////////////////////////////////////////////////////////////////
  743. // CDSCookieSheetTable
  744. void CCookieSheetTable::BringToForeground(CFolderObject* pCookie, CComponentDataImpl* pCD)
  745. {
  746. ASSERT(pCD != NULL);
  747. ASSERT(pCookie != NULL);
  748. if (!m_pCookieArr)
  749. {
  750. return;
  751. }
  752. // look for the cookie itself and for all the cookies that have the
  753. // given cookie as parent or ancestor
  754. BOOL bActivate = TRUE;
  755. for (UINT k=0; k<m_nEntries; k++)
  756. {
  757. if (m_pCookieArr[k] != NULL)
  758. {
  759. CFolderObject* pAncestorCookie = m_pCookieArr[k];
  760. while (pAncestorCookie != NULL)
  761. {
  762. if (pAncestorCookie == pCookie)
  763. {
  764. CString szADSIPath;
  765. LPCWSTR lpszNamingContext = ((CDomainObject *)m_pCookieArr[k])->GetNCName();
  766. pCD->GetBasePathsInfo()->ComposeADsIPath(szADSIPath, lpszNamingContext);
  767. // the first one will be also activated
  768. VERIFY(BringSheetToForeground((LPWSTR)(LPCWSTR)szADSIPath, bActivate));
  769. if (bActivate)
  770. bActivate = !bActivate;
  771. }
  772. pAncestorCookie = pAncestorCookie->GetParentFolder();
  773. } // while
  774. } // if
  775. } // for
  776. }
  777. ///////////////////////////////////////////////////////////////////////
  778. // CDsUiWizDLL