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.

445 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: delegwiz.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "preDNSsn.h"
  11. #include <SnapBase.h>
  12. #include "resource.h"
  13. #include "dnsutil.h"
  14. #include "DNSSnap.h"
  15. #include "snapdata.h"
  16. #include "server.h"
  17. #include "domain.h"
  18. #include "record.h"
  19. #include "zone.h"
  20. #include "delegwiz.h"
  21. #ifdef DEBUG_ALLOCATOR
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. #endif
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // CDNSDelegationWiz_StartPropertyPage
  30. CDNSDelegationWiz_StartPropertyPage::CDNSDelegationWiz_StartPropertyPage()
  31. : CPropertyPageBase(IDD_DELEGWIZ_START)
  32. {
  33. InitWiz97(TRUE, 0,0, true);
  34. }
  35. BOOL CDNSDelegationWiz_StartPropertyPage::OnInitDialog()
  36. {
  37. CPropertyPageBase::OnInitDialog();
  38. SetBigBoldFont(m_hWnd, IDC_STATIC_WELCOME);
  39. return TRUE;
  40. }
  41. BOOL CDNSDelegationWiz_StartPropertyPage::OnSetActive()
  42. {
  43. // need at least one record in the page to finish
  44. GetHolder()->SetWizardButtonsFirst(TRUE);
  45. return TRUE;
  46. }
  47. void CDNSDelegationWiz_StartPropertyPage::OnWizardHelp()
  48. {
  49. CComPtr<IDisplayHelp> spHelp;
  50. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  51. if (SUCCEEDED(hr))
  52. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_DELWIZ_01.htm");
  53. }
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // CDNSDelegationWiz_DomainNamePropertyPage
  56. BEGIN_MESSAGE_MAP(CDNSDelegationWiz_DomainNamePropertyPage, CPropertyPageBase)
  57. ON_EN_CHANGE(IDC_NEW_DOMAIN_NAME_EDIT, OnChangeDomainNameEdit)
  58. END_MESSAGE_MAP()
  59. CDNSDelegationWiz_DomainNamePropertyPage::CDNSDelegationWiz_DomainNamePropertyPage()
  60. : CPropertyPageBase(IDD_DELEGWIZ_DOMAIN_NAME)
  61. {
  62. InitWiz97(FALSE, IDS_DELEGWIZ_DOMAIN_NAME_TITLE,IDS_DELEGWIZ_DOMAIN_NAME_SUBTITLE, true);
  63. }
  64. void CDNSDelegationWiz_DomainNamePropertyPage::OnWizardHelp()
  65. {
  66. CComPtr<IDisplayHelp> spHelp;
  67. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  68. if (SUCCEEDED(hr))
  69. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_DELWIZ_02.htm");
  70. }
  71. BOOL CDNSDelegationWiz_DomainNamePropertyPage::OnInitDialog()
  72. {
  73. CPropertyPageBase::OnInitDialog();
  74. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  75. m_nUTF8ParentLen = UTF8StringLen(pHolder->GetDomainNode()->GetFullName());
  76. CWnd* pWnd = GetDlgItem(IDC_NEW_DOMAIN_FQDN);
  77. CString szText;
  78. PCWSTR pszFullName = pHolder->GetDomainNode()->GetFullName();
  79. if (pszFullName && pszFullName[0] == L'.')
  80. {
  81. szText = pszFullName;
  82. }
  83. else if (pszFullName)
  84. {
  85. szText.Format(_T(".%s"), pszFullName);
  86. }
  87. pWnd->SetWindowText(szText);
  88. return TRUE;
  89. }
  90. void CDNSDelegationWiz_DomainNamePropertyPage::OnChangeDomainNameEdit()
  91. {
  92. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  93. DWORD dwNameChecking = pHolder->GetDomainNode()->GetZoneNode()->GetServerNode()->GetNameCheckFlag();
  94. //
  95. // Get the name from the control
  96. //
  97. GetDomainEdit()->GetWindowText(m_szDomainName);
  98. //
  99. // Trim spaces
  100. //
  101. m_szDomainName.TrimLeft();
  102. m_szDomainName.TrimRight();
  103. //
  104. // Construct the FQDN
  105. //
  106. CString szText;
  107. PCWSTR pszFullName = pHolder->GetDomainNode()->GetFullName();
  108. if (pszFullName && pszFullName[0] == L'.')
  109. {
  110. szText.Format(_T("%s%s"), m_szDomainName, pszFullName);
  111. }
  112. else if (pszFullName)
  113. {
  114. szText.Format(_T("%s.%s"), m_szDomainName, pszFullName);
  115. }
  116. //
  117. // Enable next button if it is a valid name
  118. //
  119. BOOL bIsValidName = (0 == ValidateDnsNameAgainstServerFlags(szText,
  120. DnsNameDomain,
  121. dwNameChecking));
  122. GetHolder()->SetWizardButtonsMiddle(bIsValidName);
  123. //
  124. // Set the FQDN in the control
  125. //
  126. CWnd* pWnd = GetDlgItem(IDC_NEW_DOMAIN_FQDN);
  127. pWnd->SetWindowText(szText);
  128. }
  129. BOOL CDNSDelegationWiz_DomainNamePropertyPage::OnSetActive()
  130. {
  131. //
  132. // Retrieve server flags
  133. //
  134. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  135. DWORD dwNameChecking = pHolder->GetDomainNode()->GetZoneNode()->GetServerNode()->GetNameCheckFlag();
  136. //
  137. // Construct the FQDN
  138. //
  139. CString szText;
  140. szText.Format(_T("%s.%s"), m_szDomainName, pHolder->GetDomainNode()->GetFullName());
  141. //
  142. // Enable next button if it is a valid name
  143. //
  144. BOOL bIsValidName = (0 == ValidateDnsNameAgainstServerFlags(szText,
  145. DnsNameDomain,
  146. dwNameChecking));
  147. //
  148. // Set the next button if its a valid name
  149. //
  150. GetHolder()->SetWizardButtonsMiddle(bIsValidName);
  151. return TRUE;
  152. }
  153. BOOL CDNSDelegationWiz_DomainNamePropertyPage::OnKillActive()
  154. {
  155. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  156. CDNSRootData* pRootData = (CDNSRootData*)pHolder->GetComponentData()->GetRootData();
  157. ASSERT(pHolder->m_pSubdomainNode != NULL);
  158. pHolder->GetDomainNode()->SetSubdomainName(pHolder->m_pSubdomainNode,
  159. m_szDomainName,
  160. pRootData->IsAdvancedView());
  161. return TRUE;
  162. }
  163. ///////////////////////////////////////////////////////////////////////////////
  164. // CDNSDelegationWiz_NameServersPropertyPage
  165. CDNSDelegationWiz_NameServersPropertyPage::CDNSDelegationWiz_NameServersPropertyPage()
  166. : CDNSNameServersPropertyPage(IDD_DELEGWIZ_NAME_SERVERS)
  167. {
  168. InitWiz97(FALSE, IDS_DELEGWIZ_DOMAIN_NS_TITLE,IDS_DELEGWIZ_DOMAIN_NS_SUBTITLE, true);
  169. }
  170. void CDNSDelegationWiz_NameServersPropertyPage::OnWizardHelp()
  171. {
  172. CComPtr<IDisplayHelp> spHelp;
  173. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  174. if (SUCCEEDED(hr))
  175. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_DELWIZ_03.htm");
  176. }
  177. BOOL CDNSDelegationWiz_NameServersPropertyPage::OnSetActive()
  178. {
  179. // need at least one record in the page to finish
  180. GetHolder()->SetWizardButtonsMiddle(m_listCtrl.GetItemCount() > 0);
  181. return TRUE;
  182. }
  183. void CDNSDelegationWiz_NameServersPropertyPage::OnCountChange(int nCount)
  184. {
  185. GetHolder()->SetWizardButtonsMiddle(nCount > 0);
  186. }
  187. BOOL CDNSDelegationWiz_NameServersPropertyPage::CreateNewNSRecords(CDNSDomainNode* pSubdomainNode)
  188. {
  189. ASSERT(pSubdomainNode != NULL);
  190. BOOL bRes = pSubdomainNode->UpdateNSRecordNodesInfo(m_pCloneInfoList, GetHolder()->GetComponentData());
  191. if (!bRes)
  192. return OnWriteNSRecordNodesListError();
  193. return bRes;
  194. }
  195. ///////////////////////////////////////////////////////////////////////////////
  196. // CDNSDelegationWiz_FinishPropertyPage
  197. CDNSDelegationWiz_FinishPropertyPage::CDNSDelegationWiz_FinishPropertyPage()
  198. : CPropertyPageBase(IDD_DELEGWIZ_FINISH)
  199. {
  200. InitWiz97(TRUE, 0,0, true);
  201. }
  202. void CDNSDelegationWiz_FinishPropertyPage::OnWizardHelp()
  203. {
  204. CComPtr<IDisplayHelp> spHelp;
  205. HRESULT hr = GetHolder()->GetComponentData()->GetConsole()->QueryInterface(IID_IDisplayHelp, (void **)&spHelp);
  206. if (SUCCEEDED(hr))
  207. spHelp->ShowTopic(L"DNSConcepts.chm::/sag_DNS_DELWIZ_04.htm");
  208. }
  209. BOOL CDNSDelegationWiz_FinishPropertyPage::OnSetActive()
  210. {
  211. // need at least one record in the page to finish
  212. GetHolder()->SetWizardButtonsLast(TRUE);
  213. DisplaySummaryInfo();
  214. return TRUE;
  215. }
  216. BOOL CDNSDelegationWiz_FinishPropertyPage::OnWizardFinish()
  217. {
  218. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  219. ASSERT(pHolder->IsWizardMode());
  220. return pHolder->OnFinish();
  221. }
  222. void CDNSDelegationWiz_FinishPropertyPage::DisplaySummaryInfo()
  223. {
  224. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  225. GetDlgItem(IDC_NAME_STATIC)->SetWindowText(pHolder->m_pSubdomainNode->GetFullName());
  226. }
  227. ///////////////////////////////////////////////////////////////////////////////
  228. // CDNSDelegationWizardHolder
  229. CDNSDelegationWizardHolder::CDNSDelegationWizardHolder(CDNSMTContainerNode* pContainerNode,
  230. CDNSDomainNode* pThisDomainNode, CComponentDataObject* pComponentData)
  231. : CPropertyPageHolderBase(pContainerNode, pThisDomainNode, pComponentData)
  232. {
  233. ASSERT(pComponentData != NULL);
  234. ASSERT(pContainerNode != NULL);
  235. ASSERT(pContainerNode == GetContainerNode());
  236. ASSERT(pThisDomainNode != NULL);
  237. ASSERT(pThisDomainNode == GetDomainNode());
  238. m_bAutoDeletePages = FALSE; // we have the page as embedded member
  239. AddPageToList((CPropertyPageBase*)&m_startPage);
  240. AddPageToList((CPropertyPageBase*)&m_domainNamePage);
  241. AddPageToList((CPropertyPageBase*)&m_nameServersPage);
  242. AddPageToList((CPropertyPageBase*)&m_finishPage);
  243. m_pSubdomainNode = GetDomainNode()->CreateSubdomainNode(/*bDelegation*/TRUE);
  244. ASSERT(m_pSubdomainNode != NULL);
  245. m_nameServersPage.SetDomainNode(m_pSubdomainNode);
  246. }
  247. CDNSDelegationWizardHolder::~CDNSDelegationWizardHolder()
  248. {
  249. if (m_pSubdomainNode != NULL)
  250. delete m_pSubdomainNode;
  251. }
  252. CDNSDomainNode* CDNSDelegationWizardHolder::GetDomainNode()
  253. {
  254. return (CDNSDomainNode*)GetTreeNode();
  255. }
  256. BOOL CDNSDelegationWizardHolder::OnFinish()
  257. {
  258. ASSERT(m_pSubdomainNode != NULL);
  259. if (m_pSubdomainNode == NULL)
  260. {
  261. return FALSE;
  262. }
  263. //
  264. // See if a child of that name already exists
  265. //
  266. RECORD_SEARCH recordSearch = RECORD_NOT_FOUND;
  267. CDNSDomainNode* pNewParentDomain = NULL;
  268. CString szFullDomainName;
  269. szFullDomainName = m_pSubdomainNode->GetFullName();
  270. CString szNonExistentDomain;
  271. CDNSRecordNodeBase* pExistingRecordNode = 0;
  272. recordSearch = GetDomainNode()->GetZoneNode()->DoesContain(szFullDomainName,
  273. GetComponentData(),
  274. &pNewParentDomain,
  275. &pExistingRecordNode,
  276. szNonExistentDomain,
  277. TRUE);
  278. if (recordSearch == RECORD_NOT_FOUND && pNewParentDomain != NULL)
  279. {
  280. //
  281. // first create the subdomain in the server and UI
  282. //
  283. DNS_STATUS err = pNewParentDomain->CreateSubdomain(m_pSubdomainNode, GetComponentData());
  284. if (err != 0)
  285. {
  286. DNSErrorDialog(err, IDS_MSG_DELEGWIZ_SUBDOMAIN_FAILED);
  287. }
  288. else
  289. {
  290. //
  291. // mark the node as enumerated and force transition to "loaded"
  292. //
  293. m_pSubdomainNode->MarkEnumeratedAndLoaded(GetComponentData());
  294. //
  295. // then create the NS records underneath
  296. //
  297. BOOL bSuccess = m_nameServersPage.CreateNewNSRecords(m_pSubdomainNode);
  298. if (!bSuccess)
  299. DNSErrorDialog(-1, IDS_MSG_DELEGWIZ_NS_RECORD_FAILED);
  300. m_pSubdomainNode = NULL; // relinquish ownership
  301. }
  302. }
  303. else if (recordSearch == NON_EXISTENT_SUBDOMAIN && pNewParentDomain != NULL)
  304. {
  305. //
  306. // first create the subdomain in the server and UI
  307. //
  308. DNS_STATUS err = m_pSubdomainNode->Create();
  309. if (err != 0)
  310. {
  311. DNSErrorDialog(err, IDS_MSG_DELEGWIZ_SUBDOMAIN_FAILED);
  312. return FALSE;
  313. }
  314. else
  315. {
  316. //
  317. // then create the NS records underneath
  318. //
  319. BOOL bSuccess = m_nameServersPage.CreateNewNSRecords(m_pSubdomainNode);
  320. if (!bSuccess)
  321. {
  322. DNSErrorDialog(-1, IDS_MSG_DELEGWIZ_NS_RECORD_FAILED);
  323. return FALSE;
  324. }
  325. ASSERT(!szNonExistentDomain.IsEmpty());
  326. if (!szNonExistentDomain.IsEmpty())
  327. {
  328. //
  329. // Create the first subdomain because the current domain is already enumerated
  330. // so we have to start the remaining enumeration at the new subdomain that is needed
  331. //
  332. CDNSDomainNode* pSubdomainNode = pNewParentDomain->CreateSubdomainNode();
  333. ASSERT(pSubdomainNode != NULL);
  334. CDNSRootData* pRootData = (CDNSRootData*)GetComponentData()->GetRootData();
  335. pNewParentDomain->SetSubdomainName(pSubdomainNode, szNonExistentDomain, pRootData->IsAdvancedView());
  336. VERIFY(pNewParentDomain->AddChildToListAndUISorted(pSubdomainNode, GetComponentData()));
  337. GetComponentData()->SetDescriptionBarText(pNewParentDomain);
  338. //
  339. // I don't care what the results of this are, I am just using it
  340. // to do the expansion to the new record
  341. //
  342. recordSearch = pSubdomainNode->GetZoneNode()->DoesContain(szFullDomainName,
  343. GetComponentData(),
  344. &pNewParentDomain,
  345. &pExistingRecordNode,
  346. szNonExistentDomain,
  347. TRUE);
  348. }
  349. //
  350. // mark the node as enumerated and force transition to "loaded"
  351. //
  352. m_pSubdomainNode->MarkEnumeratedAndLoaded(GetComponentData());
  353. m_pSubdomainNode = NULL; // relinquish ownership
  354. }
  355. }
  356. else if (recordSearch == RECORD_NOT_FOUND_AT_THE_NODE)
  357. {
  358. DNSMessageBox(IDS_MSG_DELEGWIZ_SUDOMAIN_EXISTS);
  359. return FALSE;
  360. }
  361. else
  362. {
  363. }
  364. return TRUE;
  365. }