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.

409 lines
12 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);
  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. ///////////////////////////////////////////////////////////////////////////////
  48. // CDNSDelegationWiz_DomainNamePropertyPage
  49. BEGIN_MESSAGE_MAP(CDNSDelegationWiz_DomainNamePropertyPage, CPropertyPageBase)
  50. ON_EN_CHANGE(IDC_NEW_DOMAIN_NAME_EDIT, OnChangeDomainNameEdit)
  51. END_MESSAGE_MAP()
  52. CDNSDelegationWiz_DomainNamePropertyPage::CDNSDelegationWiz_DomainNamePropertyPage()
  53. : CPropertyPageBase(IDD_DELEGWIZ_DOMAIN_NAME)
  54. {
  55. InitWiz97(FALSE, IDS_DELEGWIZ_DOMAIN_NAME_TITLE,IDS_DELEGWIZ_DOMAIN_NAME_SUBTITLE);
  56. }
  57. BOOL CDNSDelegationWiz_DomainNamePropertyPage::OnInitDialog()
  58. {
  59. CPropertyPageBase::OnInitDialog();
  60. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  61. m_nUTF8ParentLen = UTF8StringLen(pHolder->GetDomainNode()->GetFullName());
  62. CWnd* pWnd = GetDlgItem(IDC_NEW_DOMAIN_FQDN);
  63. CString szText;
  64. PCWSTR pszFullName = pHolder->GetDomainNode()->GetFullName();
  65. if (pszFullName && pszFullName[0] == L'.')
  66. {
  67. szText = pszFullName;
  68. }
  69. else if (pszFullName)
  70. {
  71. szText.Format(_T(".%s"), pszFullName);
  72. }
  73. pWnd->SetWindowText(szText);
  74. return TRUE;
  75. }
  76. void CDNSDelegationWiz_DomainNamePropertyPage::OnChangeDomainNameEdit()
  77. {
  78. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  79. DWORD dwNameChecking = pHolder->GetDomainNode()->GetZoneNode()->GetServerNode()->GetNameCheckFlag();
  80. //
  81. // Get the name from the control
  82. //
  83. GetDomainEdit()->GetWindowText(m_szDomainName);
  84. //
  85. // Trim spaces
  86. //
  87. m_szDomainName.TrimLeft();
  88. m_szDomainName.TrimRight();
  89. //
  90. // Construct the FQDN
  91. //
  92. CString szText;
  93. PCWSTR pszFullName = pHolder->GetDomainNode()->GetFullName();
  94. if (pszFullName && pszFullName[0] == L'.')
  95. {
  96. szText.Format(_T("%s%s"), m_szDomainName, pszFullName);
  97. }
  98. else if (pszFullName)
  99. {
  100. szText.Format(_T("%s.%s"), m_szDomainName, pszFullName);
  101. }
  102. //
  103. // Enable next button if it is a valid name
  104. //
  105. BOOL bIsValidName = (0 == ValidateDnsNameAgainstServerFlags(szText,
  106. DnsNameDomain,
  107. dwNameChecking));
  108. GetHolder()->SetWizardButtonsMiddle(bIsValidName);
  109. //
  110. // Set the FQDN in the control
  111. //
  112. CWnd* pWnd = GetDlgItem(IDC_NEW_DOMAIN_FQDN);
  113. pWnd->SetWindowText(szText);
  114. }
  115. BOOL CDNSDelegationWiz_DomainNamePropertyPage::OnSetActive()
  116. {
  117. //
  118. // Retrieve server flags
  119. //
  120. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  121. DWORD dwNameChecking = pHolder->GetDomainNode()->GetZoneNode()->GetServerNode()->GetNameCheckFlag();
  122. //
  123. // Construct the FQDN
  124. //
  125. CString szText;
  126. szText.Format(_T("%s.%s"), m_szDomainName, pHolder->GetDomainNode()->GetFullName());
  127. //
  128. // Enable next button if it is a valid name
  129. //
  130. BOOL bIsValidName = (0 == ValidateDnsNameAgainstServerFlags(szText,
  131. DnsNameDomain,
  132. dwNameChecking));
  133. //
  134. // Set the next button if its a valid name
  135. //
  136. GetHolder()->SetWizardButtonsMiddle(bIsValidName);
  137. return TRUE;
  138. }
  139. BOOL CDNSDelegationWiz_DomainNamePropertyPage::OnKillActive()
  140. {
  141. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  142. CDNSRootData* pRootData = (CDNSRootData*)pHolder->GetComponentData()->GetRootData();
  143. ASSERT(pHolder->m_pSubdomainNode != NULL);
  144. pHolder->GetDomainNode()->SetSubdomainName(pHolder->m_pSubdomainNode,
  145. m_szDomainName,
  146. pRootData->IsAdvancedView());
  147. return TRUE;
  148. }
  149. ///////////////////////////////////////////////////////////////////////////////
  150. // CDNSDelegationWiz_NameServersPropertyPage
  151. CDNSDelegationWiz_NameServersPropertyPage::CDNSDelegationWiz_NameServersPropertyPage()
  152. : CDNSNameServersPropertyPage(IDD_DELEGWIZ_NAME_SERVERS)
  153. {
  154. InitWiz97(FALSE, IDS_DELEGWIZ_DOMAIN_NS_TITLE,IDS_DELEGWIZ_DOMAIN_NS_SUBTITLE);
  155. }
  156. BOOL CDNSDelegationWiz_NameServersPropertyPage::OnSetActive()
  157. {
  158. // need at least one record in the page to finish
  159. GetHolder()->SetWizardButtonsMiddle(m_listCtrl.GetItemCount() > 0);
  160. return TRUE;
  161. }
  162. void CDNSDelegationWiz_NameServersPropertyPage::OnCountChange(int nCount)
  163. {
  164. GetHolder()->SetWizardButtonsMiddle(nCount > 0);
  165. }
  166. BOOL CDNSDelegationWiz_NameServersPropertyPage::CreateNewNSRecords(CDNSDomainNode* pSubdomainNode)
  167. {
  168. ASSERT(pSubdomainNode != NULL);
  169. BOOL bRes = pSubdomainNode->UpdateNSRecordNodesInfo(m_pCloneInfoList, GetHolder()->GetComponentData());
  170. if (!bRes)
  171. return OnWriteNSRecordNodesListError();
  172. return bRes;
  173. }
  174. ///////////////////////////////////////////////////////////////////////////////
  175. // CDNSDelegationWiz_FinishPropertyPage
  176. CDNSDelegationWiz_FinishPropertyPage::CDNSDelegationWiz_FinishPropertyPage()
  177. : CPropertyPageBase(IDD_DELEGWIZ_FINISH)
  178. {
  179. InitWiz97(TRUE, 0,0);
  180. }
  181. BOOL CDNSDelegationWiz_FinishPropertyPage::OnSetActive()
  182. {
  183. // need at least one record in the page to finish
  184. GetHolder()->SetWizardButtonsLast(TRUE);
  185. DisplaySummaryInfo();
  186. return TRUE;
  187. }
  188. BOOL CDNSDelegationWiz_FinishPropertyPage::OnWizardFinish()
  189. {
  190. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  191. ASSERT(pHolder->IsWizardMode());
  192. return pHolder->OnFinish();
  193. }
  194. void CDNSDelegationWiz_FinishPropertyPage::DisplaySummaryInfo()
  195. {
  196. CDNSDelegationWizardHolder* pHolder = (CDNSDelegationWizardHolder*)GetHolder();
  197. GetDlgItem(IDC_NAME_STATIC)->SetWindowText(pHolder->m_pSubdomainNode->GetFullName());
  198. }
  199. ///////////////////////////////////////////////////////////////////////////////
  200. // CDNSDelegationWizardHolder
  201. CDNSDelegationWizardHolder::CDNSDelegationWizardHolder(CDNSMTContainerNode* pContainerNode,
  202. CDNSDomainNode* pThisDomainNode, CComponentDataObject* pComponentData)
  203. : CPropertyPageHolderBase(pContainerNode, pThisDomainNode, pComponentData)
  204. {
  205. ASSERT(pComponentData != NULL);
  206. ASSERT(pContainerNode != NULL);
  207. ASSERT(pContainerNode == GetContainerNode());
  208. ASSERT(pThisDomainNode != NULL);
  209. ASSERT(pThisDomainNode == GetDomainNode());
  210. m_bAutoDeletePages = FALSE; // we have the page as embedded member
  211. AddPageToList((CPropertyPageBase*)&m_startPage);
  212. AddPageToList((CPropertyPageBase*)&m_domainNamePage);
  213. AddPageToList((CPropertyPageBase*)&m_nameServersPage);
  214. AddPageToList((CPropertyPageBase*)&m_finishPage);
  215. m_pSubdomainNode = GetDomainNode()->CreateSubdomainNode(/*bDelegation*/TRUE);
  216. ASSERT(m_pSubdomainNode != NULL);
  217. m_nameServersPage.SetDomainNode(m_pSubdomainNode);
  218. }
  219. CDNSDelegationWizardHolder::~CDNSDelegationWizardHolder()
  220. {
  221. if (m_pSubdomainNode != NULL)
  222. delete m_pSubdomainNode;
  223. }
  224. CDNSDomainNode* CDNSDelegationWizardHolder::GetDomainNode()
  225. {
  226. return (CDNSDomainNode*)GetTreeNode();
  227. }
  228. BOOL CDNSDelegationWizardHolder::OnFinish()
  229. {
  230. ASSERT(m_pSubdomainNode != NULL);
  231. if (m_pSubdomainNode == NULL)
  232. {
  233. return FALSE;
  234. }
  235. //
  236. // See if a child of that name already exists
  237. //
  238. RECORD_SEARCH recordSearch = RECORD_NOT_FOUND;
  239. CDNSDomainNode* pNewParentDomain = NULL;
  240. CString szFullDomainName;
  241. szFullDomainName = m_pSubdomainNode->GetFullName();
  242. CString szNonExistentDomain;
  243. recordSearch = GetDomainNode()->GetZoneNode()->DoesContain(szFullDomainName,
  244. GetComponentData(),
  245. &pNewParentDomain,
  246. szNonExistentDomain,
  247. TRUE);
  248. if (recordSearch == RECORD_NOT_FOUND && pNewParentDomain != NULL)
  249. {
  250. //
  251. // first create the subdomain in the server and UI
  252. //
  253. DNS_STATUS err = pNewParentDomain->CreateSubdomain(m_pSubdomainNode, GetComponentData());
  254. if (err != 0)
  255. {
  256. DNSErrorDialog(err, IDS_MSG_DELEGWIZ_SUBDOMAIN_FAILED);
  257. }
  258. else
  259. {
  260. //
  261. // mark the node as enumerated and force transition to "loaded"
  262. //
  263. m_pSubdomainNode->MarkEnumeratedAndLoaded(GetComponentData());
  264. //
  265. // then create the NS records underneath
  266. //
  267. BOOL bSuccess = m_nameServersPage.CreateNewNSRecords(m_pSubdomainNode);
  268. if (!bSuccess)
  269. DNSErrorDialog(-1, IDS_MSG_DELEGWIZ_NS_RECORD_FAILED);
  270. m_pSubdomainNode = NULL; // relinquish ownership
  271. }
  272. }
  273. else if (recordSearch == NON_EXISTENT_SUBDOMAIN && pNewParentDomain != NULL)
  274. {
  275. //
  276. // first create the subdomain in the server and UI
  277. //
  278. DNS_STATUS err = m_pSubdomainNode->Create();
  279. if (err != 0)
  280. {
  281. DNSErrorDialog(err, IDS_MSG_DELEGWIZ_SUBDOMAIN_FAILED);
  282. return FALSE;
  283. }
  284. else
  285. {
  286. //
  287. // then create the NS records underneath
  288. //
  289. BOOL bSuccess = m_nameServersPage.CreateNewNSRecords(m_pSubdomainNode);
  290. if (!bSuccess)
  291. {
  292. DNSErrorDialog(-1, IDS_MSG_DELEGWIZ_NS_RECORD_FAILED);
  293. return FALSE;
  294. }
  295. ASSERT(!szNonExistentDomain.IsEmpty());
  296. if (!szNonExistentDomain.IsEmpty())
  297. {
  298. //
  299. // Create the first subdomain because the current domain is already enumerated
  300. // so we have to start the remaining enumeration at the new subdomain that is needed
  301. //
  302. CDNSDomainNode* pSubdomainNode = pNewParentDomain->CreateSubdomainNode();
  303. ASSERT(pSubdomainNode != NULL);
  304. CDNSRootData* pRootData = (CDNSRootData*)GetComponentData()->GetRootData();
  305. pNewParentDomain->SetSubdomainName(pSubdomainNode, szNonExistentDomain, pRootData->IsAdvancedView());
  306. VERIFY(pNewParentDomain->AddChildToListAndUISorted(pSubdomainNode, GetComponentData()));
  307. GetComponentData()->SetDescriptionBarText(pNewParentDomain);
  308. //
  309. // I don't care what the results of this are, I am just using it
  310. // to do the expansion to the new record
  311. //
  312. recordSearch = pSubdomainNode->GetZoneNode()->DoesContain(szFullDomainName,
  313. GetComponentData(),
  314. &pNewParentDomain,
  315. szNonExistentDomain,
  316. TRUE);
  317. }
  318. //
  319. // mark the node as enumerated and force transition to "loaded"
  320. //
  321. m_pSubdomainNode->MarkEnumeratedAndLoaded(GetComponentData());
  322. m_pSubdomainNode = NULL; // relinquish ownership
  323. }
  324. }
  325. else if (recordSearch == RECORD_NOT_FOUND_AT_THE_NODE)
  326. {
  327. DNSMessageBox(IDS_MSG_DELEGWIZ_SUDOMAIN_EXISTS);
  328. return FALSE;
  329. }
  330. else
  331. {
  332. }
  333. return TRUE;
  334. }