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.

297 lines
6.4 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // "More" dialog (spawned from IDChanges)
  4. //
  5. // 3-11-98 sburns
  6. #include "headers.hxx"
  7. #include "moredlg.hpp"
  8. #include "resource.h"
  9. #include "helpids.h"
  10. #include "state.hpp"
  11. #include "iddlg.hpp" // showAndEnableWindow
  12. // the max length of a DNS name is 255 utf-8 bytes. The hostname must be
  13. // at least 1 byte. Then there's the dot between the hostname and the
  14. // suffix. So 255 - 1 - 1 = 253.
  15. // note that this is *not* Dns::MAX_NAME_LENGTH
  16. static const int MAX_SUFFIX_LEN = DNS_MAX_NAME_LENGTH - 1 - 1;
  17. static const DWORD HELP_MAP[] =
  18. {
  19. IDC_DNS, IDH_IDENT_NAMES_DNS_NAME,
  20. IDC_CHANGE, IDH_IDENT_NAMES_CHANGE_DNS_CHECKBOX,
  21. IDC_NETBIOS, IDH_IDENT_NAMES_NETBIOS_NAME,
  22. 0, 0
  23. };
  24. MoreChangesDialog::MoreChangesDialog(bool isPersonal)
  25. :
  26. Dialog(IDD_MORE, HELP_MAP),
  27. startingSyncDnsNames(false),
  28. fIsPersonal(isPersonal)
  29. {
  30. LOG_CTOR(MoreChangesDialog);
  31. }
  32. MoreChangesDialog::~MoreChangesDialog()
  33. {
  34. LOG_DTOR(MoreChangesDialog);
  35. }
  36. void
  37. MoreChangesDialog::enable()
  38. {
  39. bool enabled = WasChanged(IDC_DNS);
  40. if (WasChanged(IDC_CHANGE))
  41. {
  42. if (
  43. startingSyncDnsNames
  44. != Win::IsDlgButtonChecked(hwnd, IDC_CHANGE))
  45. {
  46. enabled = true;
  47. }
  48. }
  49. Win::EnableWindow(Win::GetDlgItem(hwnd, IDOK), enabled);
  50. }
  51. void
  52. MoreChangesDialog::OnInit()
  53. {
  54. LOG_FUNCTION(MoreChangesDialog::OnInit);
  55. State& state = State::GetInstance();
  56. Win::Edit_LimitText(
  57. Win::GetDlgItem(hwnd, IDC_DNS),
  58. MAX_SUFFIX_LEN);
  59. Win::SetDlgItemText(
  60. hwnd,
  61. IDC_DNS,
  62. state.GetComputerDomainDnsName());
  63. Win::SetDlgItemText(hwnd, IDC_NETBIOS, state.GetNetbiosComputerName());
  64. startingSyncDnsNames = state.GetSyncDNSNames();
  65. Win::CheckDlgButton(
  66. hwnd,
  67. IDC_CHANGE,
  68. startingSyncDnsNames ? BST_CHECKED : BST_UNCHECKED);
  69. if (fIsPersonal) // JonN 10/4/00
  70. showAndEnableWindow( hwnd, IDC_CHANGE, SW_HIDE );
  71. ClearChanges();
  72. enable();
  73. }
  74. MoreChangesDialog::ExecuteResult
  75. MoreChangesDialog::ModalExecute(HWND parent)
  76. {
  77. if (Dialog::ModalExecute(parent))
  78. {
  79. return CHANGES_MADE;
  80. }
  81. return NO_CHANGES;
  82. }
  83. // returns
  84. // -1 if a validation error has occurred
  85. // 1 if a change was made
  86. // 0 if no change was made
  87. int
  88. MoreChangesDialog::OnOkButton()
  89. {
  90. int endCode = 0;
  91. State& state = State::GetInstance();
  92. String preconditionErrorMessage = CheckPreconditions();
  93. if (!preconditionErrorMessage.empty())
  94. {
  95. popup.Error(
  96. hwnd,
  97. preconditionErrorMessage);
  98. return -1;
  99. }
  100. if (WasChanged(IDC_CHANGE))
  101. {
  102. state.SetSyncDNSNames(
  103. Win::IsDlgButtonChecked(hwnd, IDC_CHANGE));
  104. endCode = 1;
  105. }
  106. if (WasChanged(IDC_DNS))
  107. {
  108. // compare the new value to the old one. If they're different,
  109. // validate and save the new value
  110. String newDomain = Win::GetTrimmedDlgItemText(hwnd, IDC_DNS);
  111. if (newDomain.empty())
  112. {
  113. state.SetComputerDomainDnsName(newDomain);
  114. return 1;
  115. }
  116. String oldDomain = state.GetComputerDomainDnsName();
  117. if (newDomain.icompare(oldDomain) != 0)
  118. {
  119. switch (
  120. Dns::ValidateDnsNameSyntax(
  121. newDomain,
  122. MAX_SUFFIX_LEN,
  123. MAX_SUFFIX_LEN))
  124. {
  125. case Dns::NON_RFC:
  126. {
  127. Win::MessageBox(
  128. hwnd,
  129. String::format(IDS_NON_RFC_NAME, newDomain.c_str()),
  130. String::load(IDS_APP_TITLE),
  131. MB_OK | MB_ICONWARNING);
  132. //lint -e(616) fall-thru
  133. }
  134. case Dns::VALID:
  135. {
  136. state.SetComputerDomainDnsName(newDomain);
  137. endCode = 1;
  138. break;
  139. }
  140. case Dns::TOO_LONG:
  141. {
  142. endCode = -1;
  143. popup.Gripe(
  144. hwnd,
  145. IDC_DNS,
  146. String::format(
  147. IDS_DNS_NAME_TOO_LONG,
  148. newDomain.c_str(),
  149. MAX_SUFFIX_LEN));
  150. break;
  151. }
  152. case Dns::NUMERIC:
  153. {
  154. endCode = -1;
  155. popup.Gripe(
  156. hwnd,
  157. IDC_DNS,
  158. String::format(IDS_NUMERIC_DNS_NAME, newDomain.c_str()));
  159. break;
  160. }
  161. case Dns::BAD_CHARS:
  162. {
  163. endCode = -1;
  164. popup.Gripe(
  165. hwnd,
  166. IDC_DNS,
  167. String::format(IDS_BAD_DNS_CHARS, newDomain.c_str()));
  168. break;
  169. }
  170. case Dns::INVALID:
  171. default:
  172. {
  173. endCode = -1;
  174. popup.Gripe(
  175. hwnd,
  176. IDC_DNS,
  177. String::format(
  178. IDS_BAD_DNS_SYNTAX,
  179. newDomain.c_str(),
  180. Dns::MAX_LABEL_LENGTH));
  181. break;
  182. }
  183. }
  184. }
  185. }
  186. return endCode;
  187. }
  188. bool
  189. MoreChangesDialog::OnCommand(
  190. HWND /* windowFrom */ ,
  191. unsigned controlIDFrom,
  192. unsigned code)
  193. {
  194. switch (controlIDFrom)
  195. {
  196. case IDOK:
  197. {
  198. if (code == BN_CLICKED)
  199. {
  200. int endCode = OnOkButton();
  201. if (endCode != -1)
  202. {
  203. HRESULT unused = Win::EndDialog(hwnd, endCode);
  204. ASSERT(SUCCEEDED(unused));
  205. }
  206. }
  207. break;
  208. }
  209. case IDCANCEL:
  210. {
  211. if (code == BN_CLICKED)
  212. {
  213. // 0 => no changes made
  214. HRESULT unused = Win::EndDialog(hwnd, 0);
  215. ASSERT(SUCCEEDED(unused));
  216. }
  217. break;
  218. }
  219. case IDC_CHANGE:
  220. {
  221. if (code == BN_CLICKED)
  222. {
  223. SetChanged(controlIDFrom);
  224. enable();
  225. }
  226. break;
  227. }
  228. case IDC_DNS:
  229. {
  230. if (code == EN_CHANGE)
  231. {
  232. SetChanged(controlIDFrom);
  233. enable();
  234. }
  235. break;
  236. }
  237. default:
  238. {
  239. break;
  240. }
  241. }
  242. return true;
  243. }