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.

417 lines
11 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. #include "precomp.h"
  3. #include "..\Common\ServiceThread.h"
  4. #include "moredlg.h"
  5. #ifdef EXT_DEBUG
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. #include "resource.h"
  10. #include "..\common\util.h"
  11. #include "IDDlg.h"
  12. #include "NetUtility.h"
  13. #include "NetHelpIDs.h"
  14. #include "common.h"
  15. static const DWORD _help_map[] =
  16. {
  17. IDC_FULL_NAME, IDH_IDENT_CHANGES_PREVIEW_NAME,
  18. IDC_NEW_NAME, IDH_IDENT_CHANGES_NEW_NAME,
  19. IDC_MORE, IDH_IDENT_CHANGES_MORE_BUTTON,
  20. IDC_DOMAIN_BUTTON, IDH_IDENT_CHANGES_MEMBER_DOMAIN,
  21. IDC_WORKGROUP_BUTTON, IDH_IDENT_CHANGES_MEMBER_WORKGRP,
  22. IDC_DOMAIN, IDH_IDENT_CHANGES_MEMBER_DOMAIN_TEXTBOX,
  23. IDC_WORKGROUP, IDH_IDENT_CHANGES_MEMBER_WORKGRP_TEXTBOX,
  24. IDC_FIND, -1,
  25. 0, 0
  26. };
  27. //---------------------------------------------------------------------
  28. IDChangesDialog::IDChangesDialog(WbemServiceThread *serviceThread,
  29. State &state)
  30. : WBEMPageHelper(serviceThread),
  31. m_state(state)
  32. {
  33. }
  34. //-------------------------------------------------------------
  35. IDChangesDialog::~IDChangesDialog()
  36. {
  37. }
  38. //----------------------------------------------------------
  39. void IDChangesDialog::enable()
  40. {
  41. bool networking_installed = m_state.IsNetworkingInstalled();
  42. BOOL workgroup = IsDlgButtonChecked(IDC_WORKGROUP_BUTTON) == BST_CHECKED;
  43. ::EnableWindow(GetDlgItem(IDC_DOMAIN),
  44. !workgroup && networking_installed);
  45. ::EnableWindow(GetDlgItem(IDC_FIND),
  46. !workgroup && networking_installed);
  47. ::EnableWindow(GetDlgItem(IDC_WORKGROUP),
  48. workgroup && networking_installed);
  49. bool b = false;
  50. if (workgroup)
  51. {
  52. b = !GetTrimmedDlgItemText(m_hWnd, IDC_WORKGROUP).IsEmpty();
  53. }
  54. else
  55. {
  56. b = !GetTrimmedDlgItemText(m_hWnd, IDC_DOMAIN).IsEmpty();
  57. }
  58. bool enable = m_state.ChangesNeedSaving() && b &&
  59. !GetTrimmedDlgItemText(m_hWnd, IDC_NEW_NAME).IsEmpty();
  60. ::EnableWindow(GetDlgItem(IDOK), enable);
  61. }
  62. //----------------------------------------------------------
  63. LRESULT IDChangesDialog::OnInit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  64. {
  65. m_hDlg = m_hWnd;
  66. SetDlgItemText(IDC_FULL_NAME, m_state.GetFullComputerName());
  67. SetDlgItemText(IDC_NEW_NAME, m_state.GetShortComputerName());
  68. bool joined_to_workgroup = m_state.IsMemberOfWorkgroup();
  69. CheckDlgButton(IDC_WORKGROUP_BUTTON,
  70. joined_to_workgroup ? BST_CHECKED : BST_UNCHECKED);
  71. CheckDlgButton(IDC_DOMAIN_BUTTON,
  72. joined_to_workgroup ? BST_UNCHECKED : BST_CHECKED);
  73. SetDlgItemText(joined_to_workgroup ? IDC_WORKGROUP : IDC_DOMAIN,
  74. m_state.GetDomainName());
  75. bool networking_installed = m_state.IsNetworkingInstalled();
  76. bool tcp_installed = networking_installed && IsTCPIPInstalled();
  77. int show = tcp_installed ? SW_SHOW : SW_HIDE;
  78. ::ShowWindow(GetDlgItem(IDC_FULL_LABEL), show);
  79. ::ShowWindow(GetDlgItem(IDC_FULL_NAME), show);
  80. ::ShowWindow(GetDlgItem(IDC_MORE), show);
  81. HWND new_name_edit = GetDlgItem(IDC_NEW_NAME);
  82. HWND domain_name_edit = GetDlgItem(IDC_DOMAIN);
  83. // Edit_LimitText(domain_name_edit, tcp_installed ? DNS::MAX_NAME_LENGTH : DNLEN);
  84. // Edit_LimitText(new_name_edit, tcp_installed ? DNS::MAX_LABEL_LENGTH : MAX_COMPUTERNAME_LENGTH);
  85. if (!tcp_installed)
  86. {
  87. // Set the uppercase style on the new name & domain edit boxes
  88. LONG style = ::GetWindowLong(new_name_edit, GWL_STYLE);
  89. style |= ES_UPPERCASE;
  90. ::SetWindowLong(new_name_edit, GWL_STYLE, style);
  91. style = ::GetWindowLong(domain_name_edit, GWL_STYLE);
  92. style |= ES_UPPERCASE;
  93. ::SetWindowLong(domain_name_edit, GWL_STYLE, style);
  94. }
  95. //TODO::Edit_LimitText(GetDlgItem(IDC_WORKGROUP), DNLEN);
  96. // no networking at all further restricts the UI to just NetBIOS-like
  97. // computer name changes.
  98. if (!networking_installed)
  99. {
  100. ::EnableWindow(GetDlgItem(IDC_DOMAIN_BUTTON), false);
  101. ::EnableWindow(GetDlgItem(IDC_WORKGROUP_BUTTON), false);
  102. ::EnableWindow(GetDlgItem(IDC_DOMAIN), false);
  103. ::EnableWindow(GetDlgItem(IDC_WORKGROUP), false);
  104. ::EnableWindow(GetDlgItem(IDC_GROUP), false);
  105. TCHAR temp[256] = {0};
  106. StringLoad(IDS_NAME_MESSAGE, temp, 256);
  107. ::SetWindowText(GetDlgItem(IDC_MESSAGE), temp);
  108. }
  109. else
  110. {
  111. TCHAR temp[256] = {0};
  112. StringLoad(IDS_NAME_AND_MEMBERSHIP_MESSAGE, temp, 256);
  113. ::SetWindowText(GetDlgItem(IDC_MESSAGE), temp);
  114. }
  115. enable();
  116. return S_OK;
  117. }
  118. //----------------------------------------------------------
  119. NET_API_STATUS IDChangesDialog::myNetValidateName(const CHString& name,
  120. NETSETUP_NAME_TYPE nameType)
  121. {
  122. /* ATLASSERT(!name.IsEmpty());
  123. if(!name.IsEmpty())
  124. {
  125. NET_API_STATUS status;// = ::NetValidateName(0, name,
  126. // 0, 0, nameType);
  127. return status;
  128. }
  129. */
  130. return ERROR_INVALID_PARAMETER;
  131. }
  132. //----------------------------------------------------------
  133. bool IDChangesDialog::validateName(HWND dialog,
  134. int nameResID,
  135. const CHString &name,
  136. NETSETUP_NAME_TYPE nameType)
  137. {
  138. /* ATLASSERT(IsWindow(dialog));
  139. ATLASSERT(nameResID);
  140. NET_API_STATUS status;// = myNetValidateName(name, nameType);
  141. if(status != NERR_Success)
  142. {
  143. TCHAR temp[256] = {0};
  144. StringLoad(IDS_VALIDATE_NAME_FAILED, temp, 256);
  145. gripe(dialog,
  146. nameResID,
  147. HRESULT_FROM_WIN32(status),
  148. temp,
  149. IDS_APP_TITLE);
  150. return false;
  151. }
  152. */
  153. return true;
  154. }
  155. // this is also good for the tcp/ip not installed case, as the edit control
  156. // limits the text length, and we decided not to allow '.' in netbios names
  157. // any longer
  158. //----------------------------------------------------------
  159. bool IDChangesDialog::validateShortComputerName(HWND dialog)
  160. {
  161. /* ATLASSERT(IsWindow(dialog));
  162. if(!m_state.WasShortComputerNameChanged())
  163. {
  164. return true;
  165. }
  166. CHString name = m_state.GetShortComputerName();
  167. CHString message;
  168. switch (DNS::ValidateDNSLabelSyntax(name))
  169. {
  170. case DNS::VALID_LABEL:
  171. {
  172. if (state.IsNetworkingInstalled())
  173. {
  174. return validateName(dialog, IDC_NEW_NAME, name, NetSetupMachine);
  175. }
  176. else
  177. {
  178. return true;
  179. }
  180. }
  181. case DNS::LABEL_TOO_LONG:
  182. {
  183. message = String::format(IDS_COMPUTER_NAME_TOO_LONG,
  184. name.c_str(),
  185. DNS::MAX_LABEL_LENGTH);
  186. break;
  187. }
  188. case DNS::NON_RFC_LABEL:
  189. {
  190. message = String::format(IDS_NON_RFC_COMPUTER_NAME_SYNTAX,
  191. name.c_str());
  192. if(MessageBox(dialog, message,
  193. String::load(IDS_APP_TITLE),
  194. MB_ICONWARNING | MB_YESNO) == IDYES)
  195. {
  196. return validateName(dialog, IDC_NEW_NAME, name, NetSetupMachine);
  197. }
  198. HWND edit = GetDlgItem(IDC_NEW_NAME);
  199. ::SendMessage(edit, EM_SETSEL, 0, -1);
  200. ::SetFocus(edit);
  201. return false;
  202. }
  203. case DNS::INVALID_LABEL:
  204. {
  205. message = CHString::format(IDS_BAD_COMPUTER_NAME_SYNTAX,
  206. name.c_str());
  207. break;
  208. }
  209. default:
  210. {
  211. ATLASSERT(false);
  212. message = CHString::format(IDS_BAD_COMPUTER_NAME_SYNTAX,
  213. name.c_str());
  214. break;
  215. }
  216. }
  217. gripe(dialog, IDC_NEW_NAME,
  218. message, IDS_APP_TITLE);
  219. */
  220. return false;
  221. }
  222. //----------------------------------------------------------
  223. bool IDChangesDialog::validateDomainOrWorkgroupName(HWND dialog)
  224. {
  225. /* ATLASSERT(IsWindow(dialog));
  226. if (!State::GetInstance().WasMembershipChanged())
  227. {
  228. return true;
  229. }
  230. NETSETUP_NAME_TYPE name_type = NetSetupWorkgroup;
  231. int name_id = IDC_WORKGROUP;
  232. if(IsDlgButtonChecked(IDC_DOMAIN_BUTTON) == BST_CHECKED)
  233. {
  234. name_type = NetSetupDomain;
  235. name_id = IDC_DOMAIN;
  236. }
  237. CHString name = GetTrimmedDlgItemText(m_hWnd, name_id);
  238. return validateName(dialog, name_id, name, name_type);
  239. */
  240. return false;
  241. }
  242. //----------------------------------------------------------
  243. bool IDChangesDialog::onOKButton()
  244. {
  245. ATLASSERT(m_state.ChangesNeedSaving());
  246. HourGlass(true);
  247. // computer primary DNS name has already been validated by
  248. // MoreChangesDialog
  249. // this is redundant, really, but I'm paranoid.
  250. m_state.SetShortComputerName(GetTrimmedDlgItemText(m_hWnd, IDC_NEW_NAME));
  251. bool workgroup = IsDlgButtonChecked(IDC_WORKGROUP_BUTTON) == BST_CHECKED;
  252. m_state.SetIsMemberOfWorkgroup(workgroup);
  253. if(workgroup)
  254. {
  255. m_state.SetDomainName(GetTrimmedDlgItemText(m_hWnd, IDC_WORKGROUP));
  256. }
  257. else
  258. {
  259. m_state.SetDomainName(GetTrimmedDlgItemText(m_hWnd, IDC_DOMAIN));
  260. }
  261. if(!validateShortComputerName(m_hWnd) ||
  262. !validateDomainOrWorkgroupName(m_hWnd))
  263. {
  264. HourGlass(false);
  265. return false;
  266. }
  267. if(m_state.SaveChanges(m_hWnd))
  268. {
  269. AppMessage(m_hWnd, IDS_MUST_REBOOT);
  270. m_state.SetMustRebootFlag(true);
  271. return true;
  272. }
  273. HourGlass(false);
  274. return false;
  275. }
  276. //----------------------------------------------------------
  277. LRESULT IDChangesDialog::OnCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  278. {
  279. switch(wID)
  280. {
  281. case IDC_MORE:
  282. {
  283. if (wNotifyCode == BN_CLICKED)
  284. {
  285. MoreChangesDialog dlg(g_serviceThread, m_state);
  286. if (dlg.DoModal() == MoreChangesDialog::CHANGES_MADE)
  287. {
  288. SetDlgItemText(IDC_FULL_NAME, m_state.GetFullComputerName());
  289. enable();
  290. }
  291. }
  292. break;
  293. }
  294. case IDC_WORKGROUP_BUTTON:
  295. case IDC_DOMAIN_BUTTON:
  296. {
  297. if (wNotifyCode == BN_CLICKED)
  298. {
  299. bool workgroup = IsDlgButtonChecked(IDC_WORKGROUP_BUTTON) == BST_CHECKED;
  300. m_state.SetIsMemberOfWorkgroup(workgroup);
  301. if(workgroup)
  302. {
  303. m_state.SetDomainName(GetTrimmedDlgItemText(m_hWnd, IDC_WORKGROUP));
  304. }
  305. else
  306. {
  307. m_state.SetDomainName(GetTrimmedDlgItemText(m_hWnd, IDC_DOMAIN));
  308. }
  309. enable();
  310. }
  311. break;
  312. }
  313. case IDC_WORKGROUP: // the editboxes
  314. case IDC_DOMAIN:
  315. {
  316. if (wNotifyCode == EN_CHANGE)
  317. {
  318. //TODOSetModified(wID);
  319. m_state.SetDomainName(GetTrimmedDlgItemText(m_hWnd, wID));
  320. enable();
  321. }
  322. break;
  323. }
  324. case IDC_NEW_NAME:
  325. {
  326. if (wNotifyCode == EN_CHANGE)
  327. {
  328. //TODOSetChanged(wID);
  329. m_state.SetShortComputerName(GetTrimmedDlgItemText(m_hWnd, wID));
  330. SetDlgItemText(IDC_FULL_NAME, m_state.GetFullComputerName());
  331. enable();
  332. }
  333. break;
  334. }
  335. case IDOK:
  336. {
  337. if(wNotifyCode == BN_CLICKED)
  338. {
  339. if(onOKButton())
  340. {
  341. EndDialog(wID);
  342. }
  343. }
  344. break;
  345. }
  346. case IDCANCEL:
  347. {
  348. if(wNotifyCode == BN_CLICKED)
  349. {
  350. EndDialog(wID);
  351. }
  352. break;
  353. }
  354. default:
  355. {
  356. bHandled = false;
  357. break;
  358. }
  359. }
  360. return true;
  361. }