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.

255 lines
5.7 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: POP3Page.cpp
  4. //
  5. // Synopsis: Defines the POP3 internal page of the CYS wizard
  6. //
  7. // History: 06/17/2002 JeffJon Created
  8. #include "pch.h"
  9. #include "resource.h"
  10. #include "InstallationUnitProvider.h"
  11. #include "POP3Page.h"
  12. static PCWSTR POP3_PAGE_HELP = L"cys.chm::/mail_server_role.htm#mailsrvoptions";
  13. POP3Page::POP3Page()
  14. :
  15. defaultAuthMethodIndex(0),
  16. ADIntegratedIndex(CB_ERR),
  17. localAccountsIndex(CB_ERR),
  18. passwordFilesIndex(CB_ERR),
  19. CYSWizardPage(
  20. IDD_POP3_PAGE,
  21. IDS_POP3_TITLE,
  22. IDS_POP3_SUBTITLE,
  23. POP3_PAGE_HELP)
  24. {
  25. LOG_CTOR(POP3Page);
  26. }
  27. POP3Page::~POP3Page()
  28. {
  29. LOG_DTOR(POP3Page);
  30. }
  31. void
  32. POP3Page::OnInit()
  33. {
  34. LOG_FUNCTION(POP3Page::OnInit);
  35. CYSWizardPage::OnInit();
  36. bool isDC = State::GetInstance().IsDC();
  37. bool isJoinedToDomain = State::GetInstance().IsJoinedToDomain();
  38. // Add the strings to the combobox
  39. // The order of the insertion is extremely important so that
  40. // the combo box index matches the authentication method index
  41. // in the POP3 service.
  42. // - The SAM auth method needs to be added first if the local server
  43. // isn't a DC
  44. // - AD integrated needs to be added next if the local server is a DC
  45. // or is joined to a domain
  46. // - Hash (encrypted password files) needs to be added last
  47. if (!isDC)
  48. {
  49. localAccountsIndex =
  50. Win::ComboBox_AddString(
  51. Win::GetDlgItem(hwnd, IDC_AUTH_METHOD_COMBO),
  52. String::load(IDS_LOCAL_ACCOUNTS));
  53. if (localAccountsIndex == CB_ERR)
  54. {
  55. LOG(L"Failed to add local accounts string to combobox");
  56. }
  57. }
  58. if (isDC ||
  59. isJoinedToDomain)
  60. {
  61. ADIntegratedIndex =
  62. Win::ComboBox_AddString(
  63. Win::GetDlgItem(hwnd, IDC_AUTH_METHOD_COMBO),
  64. String::load(IDS_AD_INTEGRATED));
  65. if (ADIntegratedIndex == CB_ERR)
  66. {
  67. LOG(L"Failed to add AD integrated string to combobox");
  68. }
  69. }
  70. passwordFilesIndex =
  71. Win::ComboBox_AddString(
  72. Win::GetDlgItem(hwnd, IDC_AUTH_METHOD_COMBO),
  73. String::load(IDS_ENCRYPTED_PASSWORD_FILES));
  74. if (passwordFilesIndex == CB_ERR)
  75. {
  76. LOG(L"Failed to add encrypted password files string to combobox");
  77. }
  78. // Now figure out which one to select by default
  79. // If the machine is a DC or is joined to a domain
  80. // default to AD integrated authentication, else
  81. // default to local Windows accounts
  82. int defaultAuthMethodIndex = localAccountsIndex;
  83. if (State::GetInstance().IsDC() &&
  84. ADIntegratedIndex != CB_ERR)
  85. {
  86. defaultAuthMethodIndex = ADIntegratedIndex;
  87. }
  88. else
  89. {
  90. defaultAuthMethodIndex = localAccountsIndex;
  91. }
  92. // Make sure we have a valid default
  93. if (defaultAuthMethodIndex == CB_ERR)
  94. {
  95. defaultAuthMethodIndex = 0;
  96. }
  97. // Select the default
  98. Win::ComboBox_SetCurSel(
  99. Win::GetDlgItem(
  100. hwnd,
  101. IDC_AUTH_METHOD_COMBO),
  102. defaultAuthMethodIndex);
  103. LOG(
  104. String::format(
  105. L"Defaulting combobox to: %1!d!",
  106. defaultAuthMethodIndex));
  107. // Set the limit text for the domain name page
  108. Win::Edit_LimitText(
  109. Win::GetDlgItem(hwnd, IDC_EMAIL_DOMAIN_EDIT),
  110. DNS_MAX_NAME_LENGTH);
  111. }
  112. bool
  113. POP3Page::OnSetActive()
  114. {
  115. LOG_FUNCTION(POP3Page::OnSetActive);
  116. SetButtonState();
  117. return true;
  118. }
  119. void
  120. POP3Page::SetButtonState()
  121. {
  122. LOG_FUNCTION(POP3Page::SetButtonState);
  123. String emailDomainName =
  124. Win::GetDlgItemText(
  125. hwnd,
  126. IDC_EMAIL_DOMAIN_EDIT);
  127. Win::PropSheet_SetWizButtons(
  128. Win::GetParent(hwnd),
  129. (!emailDomainName.empty()) ? PSWIZB_NEXT | PSWIZB_BACK : PSWIZB_BACK);
  130. }
  131. bool
  132. POP3Page::OnCommand(
  133. HWND /*windowFrom*/,
  134. unsigned int controlIDFrom,
  135. unsigned int code)
  136. {
  137. if (code == EN_CHANGE &&
  138. controlIDFrom == IDC_EMAIL_DOMAIN_EDIT)
  139. {
  140. SetButtonState();
  141. }
  142. return false;
  143. }
  144. int
  145. POP3Page::Validate()
  146. {
  147. LOG_FUNCTION(POP3Page::Validate);
  148. int nextPage = -1;
  149. do
  150. {
  151. String emailDomainName =
  152. Win::GetDlgItemText(
  153. hwnd,
  154. IDC_EMAIL_DOMAIN_EDIT);
  155. DNS_STATUS status = MyDnsValidateName(emailDomainName, DnsNameDomain);
  156. if (status != ERROR_SUCCESS)
  157. {
  158. String message =
  159. String::format(
  160. IDS_BAD_DNS_SYNTAX,
  161. emailDomainName.c_str(),
  162. DNS_MAX_NAME_LENGTH);
  163. popup.Gripe(hwnd, IDC_EMAIL_DOMAIN_EDIT, message);
  164. nextPage = -1;
  165. break;
  166. }
  167. POP3InstallationUnit& pop3InstallationUnit =
  168. InstallationUnitProvider::GetInstance().GetPOP3InstallationUnit();
  169. pop3InstallationUnit.SetDomainName(emailDomainName);
  170. int authIndex =
  171. Win::ComboBox_GetCurSel(
  172. Win::GetDlgItem(
  173. hwnd,
  174. IDC_AUTH_METHOD_COMBO));
  175. if (authIndex == CB_ERR)
  176. {
  177. LOG(L"Failed to get the selected index, reverting to default");
  178. ASSERT(authIndex != CB_ERR);
  179. authIndex = defaultAuthMethodIndex;
  180. }
  181. // Set the auth method in the installation unit
  182. // Since the auth method is a 1 based index and the
  183. // combo selection is a zero based index, add 1.
  184. pop3InstallationUnit.SetAuthMethodIndex(authIndex + 1);
  185. nextPage = IDD_MILESTONE_PAGE;
  186. } while (false);
  187. LOG(String::format(
  188. L"nextPage = %1!d!",
  189. nextPage));
  190. return nextPage;
  191. }