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.

503 lines
14 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // TCPUI.C - Functions for Wizard TCP/IP pages
  7. //
  8. //
  9. // HISTORY:
  10. //
  11. // 1/9/95 jeremys Created.
  12. // 96/03/10 markdu Made all TCP/IP stuff be per-connectoid.
  13. // 96/03/11 markdu Set RASEO_ flags for ip and dns addresses.
  14. // 96/03/22 markdu Remove IP setup from LAN path.
  15. // 96/03/23 markdu Remove all LAN path leftovers.
  16. // 96/03/23 markdu Removed ReadTCPIPSettings.
  17. // 96/03/25 markdu If a fatal error occurs, set gfQuitWizard.
  18. // 96/03/26 markdu Store values from UI even when back is pressed.
  19. // 96/04/04 markdu Added pfNeedsRestart to WarnIfServerBound
  20. // 96/04/06 markdu Moved CommitConfigurationChanges call to last page.
  21. // 96/05/06 markdu NASH BUG 15637 Removed unused code.
  22. // 96/05/14 markdu NASH BUG 22681 Took out mail and news pages.
  23. // 96/05/16 markdu NASH BUG 21810 Perform same IP address validation as RNA.
  24. //
  25. #include "wizard.h"
  26. #include "icwextsn.h"
  27. #include "icwaprtc.h"
  28. #include "imnext.h"
  29. VOID EnableDNSAddressControls(HWND hDlg);
  30. VOID EnableIPControls(HWND hDlg);
  31. VOID DisplayInvalidIPAddrMsg(HWND hDlg,UINT uCtrl,TCHAR * pszAddr);
  32. /*******************************************************************
  33. NAME: EnableIPControls
  34. SYNOPSIS: If "Use DHCP" is checked, disables controls for
  35. specific IP selection; if not, enables them.
  36. ********************************************************************/
  37. VOID EnableIPControls(HWND hDlg)
  38. {
  39. BOOL fDHCP = IsDlgButtonChecked(hDlg,IDC_USE_DHCP);
  40. EnableDlgItem(hDlg,IDC_IP_ADDR_LABEL,!fDHCP);
  41. EnableDlgItem(hDlg,IDC_IPADDR,!fDHCP);
  42. EnableDlgItem(hDlg,IDC_TX_IPADDR,!fDHCP);
  43. }
  44. /*******************************************************************
  45. NAME: IPAddressInitProc
  46. SYNOPSIS: Called when IP address page is displayed
  47. ENTRY: hDlg - dialog window
  48. fFirstInit - TRUE if this is the first time the dialog
  49. is initialized, FALSE if this InitProc has been called
  50. before (e.g. went past this page and backed up)
  51. ********************************************************************/
  52. BOOL CALLBACK IPAddressInitProc(HWND hDlg,BOOL fFirstInit)
  53. {
  54. TCHAR szAddr[IP_ADDRESS_LEN+1];
  55. if (fFirstInit)
  56. {
  57. // limit IP address control text lengths
  58. SendDlgItemMessage(hDlg,IDC_IPADDR,EM_LIMITTEXT,IP_ADDRESS_LEN,0L);
  59. }
  60. // check either the "use DHCP" or "use specific IP" buttons.
  61. // if IP address is set to 0.0.0.0, that means use DHCP.
  62. // (The "0.0.0.0 == DHCP" convention is used by the TCP/IP
  63. // VxDs, we might as well play along.)
  64. BOOL fDHCP = (gpRasEntry->dwfOptions & RASEO_SpecificIpAddr) ? FALSE : TRUE;
  65. CheckDlgButton(hDlg,(IDC_USE_DHCP),fDHCP);
  66. CheckDlgButton(hDlg,(IDC_USE_IP),!fDHCP);
  67. // set the IP address in dialog control
  68. // 11/25/96 jmazner Normandy #10222
  69. // don't use return value of DwFromIa as basis of deciding whether or
  70. // not to fill in IP address field; rely only on the SpecificIPAddr flag.
  71. //if ((gpRasEntry->dwfOptions & RASEO_SpecificIpAddr) &&
  72. // DwFromIa(&gpRasEntry->ipaddr))
  73. if (gpRasEntry->dwfOptions & RASEO_SpecificIpAddr)
  74. {
  75. IPLongToStr(DwFromIa(&gpRasEntry->ipaddr),
  76. szAddr,sizeof(szAddr));
  77. SetDlgItemText(hDlg,IDC_IPADDR,szAddr);
  78. }
  79. else
  80. {
  81. SetDlgItemText(hDlg,IDC_IPADDR,szNull);
  82. }
  83. // enable IP address controls appropriately
  84. EnableIPControls(hDlg);
  85. return TRUE;
  86. }
  87. /*******************************************************************
  88. NAME: IPAddressOKProc
  89. SYNOPSIS: Called when Next or Back btns pressed from IP address page
  90. ENTRY: hDlg - dialog window
  91. EXIT: returns TRUE to allow page to be turned, FALSE
  92. to keep the same page.
  93. ********************************************************************/
  94. BOOL CALLBACK IPAddressOKProc(HWND hDlg)
  95. {
  96. ASSERT(puNextPage);
  97. // check the radio buttons to determine if DHCP or not
  98. BOOL fDHCP = IsDlgButtonChecked(hDlg,IDC_USE_DHCP);
  99. if (fDHCP)
  100. {
  101. // for DHCP, set IP address to 0.0.0.0
  102. CopyDw2Ia(0, &gpRasEntry->ipaddr);
  103. // Turn off Specific IP address flag
  104. gpRasEntry->dwfOptions &= ~RASEO_SpecificIpAddr;
  105. }
  106. else
  107. {
  108. TCHAR szAddr[IP_ADDRESS_LEN+1];
  109. DWORD dwAddr;
  110. // get IP address
  111. GetDlgItemText(hDlg,IDC_IPADDR,szAddr,ARRAYSIZE(szAddr));
  112. if (!lstrlen(szAddr))
  113. {
  114. // IP address field is blank, warn user and stay on this page
  115. DisplayFieldErrorMsg(hDlg,IDC_IPADDR,IDS_NEED_IPADDR);
  116. return FALSE;
  117. }
  118. //
  119. // 5/17/97 jmazner Olympus #137
  120. // check for DBCS chars.
  121. //
  122. #if !defined(WIN16)
  123. if (!IsSBCSString(szAddr))
  124. {
  125. DisplayFieldErrorMsg(hDlg,IDC_IPADDR,IDS_SBCSONLY);
  126. return FALSE;
  127. }
  128. #endif
  129. // convert text to numeric address
  130. if (IPStrToLong(szAddr,&dwAddr))
  131. {
  132. CopyDw2Ia(dwAddr, &gpRasEntry->ipaddr);
  133. // 96/05/16 markdu NASH BUG 21810 Perform same IP address validation as RNA.
  134. /* if (!FValidIa(&gpRasEntry->ipaddr))
  135. {
  136. // IP address field is invalid, warn user and stay on this page
  137. DisplayInvalidIPAddrMsg(hDlg,IDC_IPADDR,szAddr);
  138. return FALSE;
  139. }
  140. */
  141. }
  142. else
  143. {
  144. // conversion failed, the string is not valid
  145. DisplayInvalidIPAddrMsg(hDlg,IDC_IPADDR,szAddr);
  146. return FALSE;
  147. }
  148. // Turn on Specific IP address flag
  149. gpRasEntry->dwfOptions |= RASEO_SpecificIpAddr;
  150. }
  151. return TRUE;
  152. }
  153. /*******************************************************************
  154. NAME: IPAddressCmdProc
  155. SYNOPSIS: Called when dlg control pressed on IP address page
  156. ENTRY: hDlg - dialog window
  157. uCtrlID - control ID of control that was touched
  158. EXIT: returns TRUE to allow page to be turned, FALSE
  159. to keep the same page.
  160. ********************************************************************/
  161. BOOL CALLBACK IPAddressCmdProc(HWND hDlg,UINT uCtrlID)
  162. {
  163. switch (uCtrlID) {
  164. case IDC_USE_DHCP:
  165. case IDC_USE_IP:
  166. // if radio buttons pushed, enable IP controls appropriately
  167. EnableIPControls(hDlg);
  168. break;
  169. }
  170. return TRUE;
  171. }
  172. /*******************************************************************
  173. NAME: EnableDNSAddressControls
  174. SYNOPSIS: If static DNS address is checked, enable controls to
  175. enter DNS addresses. If not, disable them.
  176. ********************************************************************/
  177. VOID EnableDNSAddressControls(HWND hDlg)
  178. {
  179. BOOL fEnable = IsDlgButtonChecked(hDlg,IDC_STATIC_DNS);
  180. EnableDlgItem(hDlg,IDC_DNSADDR1,fEnable);
  181. EnableDlgItem(hDlg,IDC_DNSADDR2,fEnable);
  182. EnableDlgItem(hDlg,IDC_TX_DNSADDR1,fEnable);
  183. EnableDlgItem(hDlg,IDC_TX_DNSADDR2,fEnable);
  184. EnableDlgItem(hDlg,IDC_PRIM_LABEL,fEnable);
  185. EnableDlgItem(hDlg,IDC_SEC_LABEL,fEnable);
  186. }
  187. /*******************************************************************
  188. NAME: DNSAddressInitProc
  189. SYNOPSIS: Called when DNS page is displayed
  190. ENTRY: hDlg - dialog window
  191. fFirstInit - TRUE if this is the first time the dialog
  192. is initialized, FALSE if this InitProc has been called
  193. before (e.g. went past this page and backed up)
  194. ********************************************************************/
  195. BOOL CALLBACK DNSAddressInitProc(HWND hDlg,BOOL fFirstInit)
  196. {
  197. if (fFirstInit)
  198. {
  199. // if file server is bound to instance of TCP/IP that will be
  200. // used to access the internet, warn user and remove
  201. BOOL fTemp;
  202. WarnIfServerBound(hDlg, INSTANCE_PPPDRIVER, &fTemp);
  203. if (TRUE == fTemp)
  204. {
  205. gpWizardState->fNeedReboot = TRUE;
  206. }
  207. // limit DNS address control text lengths
  208. SendDlgItemMessage(hDlg,IDC_DNSADDR1,EM_LIMITTEXT,IP_ADDRESS_LEN,0L);
  209. SendDlgItemMessage(hDlg,IDC_DNSADDR2,EM_LIMITTEXT,IP_ADDRESS_LEN,0L);
  210. // set radio buttons
  211. CheckDlgButton(hDlg,IDC_AUTO_DNS,gpUserInfo->fAutoDNS);
  212. CheckDlgButton(hDlg,IDC_STATIC_DNS,!gpUserInfo->fAutoDNS);
  213. }
  214. TCHAR szAddr[IP_ADDRESS_LEN+1];
  215. // set primary DNS server
  216. // 11/25/96 jmazner Normandy #10222
  217. // don't use return value of DwFromIa as basis of deciding whether or
  218. // not to fill in IP address field; rely only on the SpecificNameServers flag.
  219. //if ((gpRasEntry->dwfOptions & RASEO_SpecificNameServers) &&
  220. // DwFromIa(&gpRasEntry->ipaddrDns))
  221. if (gpRasEntry->dwfOptions & RASEO_SpecificNameServers)
  222. {
  223. IPLongToStr(DwFromIa(&gpRasEntry->ipaddrDns),
  224. szAddr,sizeof(szAddr));
  225. SetDlgItemText(hDlg,IDC_DNSADDR1,szAddr);
  226. }
  227. else
  228. {
  229. SetDlgItemText(hDlg,IDC_DNSADDR1,szNull);
  230. }
  231. // set backup DNS server
  232. // 11/25/96 jmazner Normandy #10222
  233. //if ((gpRasEntry->dwfOptions & RASEO_SpecificNameServers) &&
  234. // DwFromIa(&gpRasEntry->ipaddrDnsAlt))
  235. if (gpRasEntry->dwfOptions & RASEO_SpecificNameServers)
  236. {
  237. IPLongToStr(DwFromIa(&gpRasEntry->ipaddrDnsAlt),
  238. szAddr,sizeof(szAddr));
  239. SetDlgItemText(hDlg,IDC_DNSADDR2,szAddr);
  240. }
  241. else
  242. {
  243. SetDlgItemText(hDlg,IDC_DNSADDR2,szNull);
  244. }
  245. EnableDNSAddressControls(hDlg);
  246. return TRUE;
  247. }
  248. /*******************************************************************
  249. NAME: DNSAddressOKProc
  250. SYNOPSIS: Called when Next or Back btns pressed from DNS address page
  251. ENTRY: hDlg - dialog window
  252. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  253. puNextPage - if 'Next' was pressed,
  254. proc can fill this in with next page to go to. This
  255. parameter is ingored if 'Back' was pressed.
  256. pfKeepHistory - page will not be kept in history if
  257. proc fills this in with FALSE.
  258. EXIT: returns TRUE to allow page to be turned, FALSE
  259. to keep the same page.
  260. ********************************************************************/
  261. BOOL CALLBACK DNSAddressOKProc(HWND hDlg)
  262. {
  263. ASSERT(puNextPage);
  264. UINT uServers = 0;
  265. TCHAR szAddr[IP_ADDRESS_LEN+1];
  266. DWORD dwAddr;
  267. gpUserInfo->fAutoDNS = IsDlgButtonChecked(hDlg, IDC_AUTO_DNS);
  268. if (gpUserInfo->fAutoDNS)
  269. {
  270. // Turn off Specific Name servers address flag
  271. gpRasEntry->dwfOptions &= ~RASEO_SpecificNameServers;
  272. }
  273. else
  274. {
  275. // get primary DNS server address
  276. GetDlgItemText(hDlg,IDC_DNSADDR1,szAddr,ARRAYSIZE(szAddr));
  277. if (lstrlen(szAddr))
  278. {
  279. //
  280. // 5/17/97 jmazner Olympus #137
  281. // check for DBCS chars.
  282. //
  283. #if !defined(WIN16)
  284. if (!IsSBCSString(szAddr))
  285. {
  286. DisplayFieldErrorMsg(hDlg,IDC_DNSADDR1,IDS_SBCSONLY);
  287. return FALSE;
  288. }
  289. #endif
  290. // convert text to numeric address
  291. if (IPStrToLong(szAddr,&dwAddr))
  292. {
  293. CopyDw2Ia(dwAddr, &gpRasEntry->ipaddrDns);
  294. // 96/05/16 markdu NASH BUG 21810 Perform same IP address validation as RNA.
  295. /* if (!FValidIaOrZero(&gpRasEntry->ipaddrDns))
  296. {
  297. // DNS address field is invalid, warn user and stay on this page
  298. DisplayInvalidIPAddrMsg(hDlg,IDC_DNSADDR1,szAddr);
  299. return FALSE;
  300. }
  301. */
  302. }
  303. else
  304. {
  305. // conversion failed, the string is not valid
  306. DisplayInvalidIPAddrMsg(hDlg,IDC_DNSADDR1,szAddr);
  307. return FALSE;
  308. }
  309. uServers++;
  310. }
  311. else
  312. {
  313. CopyDw2Ia(0, &gpRasEntry->ipaddrDns);
  314. }
  315. // get alternate DNS server address
  316. GetDlgItemText(hDlg,IDC_DNSADDR2,szAddr,ARRAYSIZE(szAddr));
  317. if (lstrlen(szAddr))
  318. {
  319. //
  320. // 5/17/97 jmazner Olympus #137
  321. // check for DBCS chars.
  322. //
  323. #if !defined(WIN16)
  324. if (!IsSBCSString(szAddr))
  325. {
  326. DisplayFieldErrorMsg(hDlg,IDC_DNSADDR2,IDS_SBCSONLY);
  327. return FALSE;
  328. }
  329. #endif
  330. // convert text to numeric address
  331. if (IPStrToLong(szAddr,&dwAddr))
  332. {
  333. CopyDw2Ia(dwAddr, &gpRasEntry->ipaddrDnsAlt);
  334. // 96/05/16 markdu NASH BUG 21810 Perform same IP address validation as RNA.
  335. /* if (!FValidIaOrZero(&gpRasEntry->ipaddrDnsAlt))
  336. {
  337. // DNS address field is invalid, warn user and stay on this page
  338. DisplayInvalidIPAddrMsg(hDlg,IDC_DNSADDR2,szAddr);
  339. return FALSE;
  340. }
  341. */
  342. }
  343. else
  344. {
  345. // conversion failed, the string is not valid
  346. DisplayInvalidIPAddrMsg(hDlg,IDC_DNSADDR2,szAddr);
  347. return FALSE;
  348. }
  349. uServers++;
  350. }
  351. else
  352. {
  353. CopyDw2Ia(0, &gpRasEntry->ipaddrDnsAlt);
  354. }
  355. if (uServers)
  356. {
  357. // Turn on Specific name servers
  358. gpRasEntry->dwfOptions |= RASEO_SpecificNameServers;
  359. }
  360. else
  361. {
  362. // no DNS servers entered, warn user (but let her proceed if
  363. // she really wants to)
  364. if (!WarnFieldIsEmpty(hDlg,IDC_DNSADDR1,IDS_WARN_EMPTY_DNS))
  365. return FALSE; // user heeded warning, stay on this page
  366. // Turn off Specific Name servers address flag
  367. gpRasEntry->dwfOptions &= ~RASEO_SpecificNameServers;
  368. }
  369. }
  370. return TRUE;
  371. }
  372. /*******************************************************************
  373. NAME: DNSAddressCmdProc
  374. SYNOPSIS: Called when dlg control pressed on DNS address page
  375. ENTRY: hDlg - dialog window
  376. uCtrlID - control ID of control that was touched
  377. EXIT: returns TRUE to allow page to be turned, FALSE
  378. to keep the same page.
  379. ********************************************************************/
  380. BOOL CALLBACK DNSAddressCmdProc(HWND hDlg,UINT uCtrlID)
  381. {
  382. switch (uCtrlID) {
  383. case IDC_AUTO_DNS:
  384. case IDC_STATIC_DNS:
  385. // if radio buttons pushed, enable IP controls appropriately
  386. EnableDNSAddressControls(hDlg);
  387. break;
  388. }
  389. return TRUE;
  390. }
  391. /*******************************************************************
  392. NAME: DisplayInvalidIPAddrMsg
  393. SYNOPSIS: Displays a message that the address the user typed
  394. is invalid and adds a tip on who to contact if they
  395. don't know what address to type
  396. ********************************************************************/
  397. VOID DisplayInvalidIPAddrMsg(HWND hDlg,UINT uCtrl,TCHAR * pszAddr)
  398. {
  399. MsgBoxParam(hDlg,IDS_INVALID_IPADDR,MB_ICONINFORMATION,MB_OK,
  400. pszAddr);
  401. SetFocus(GetDlgItem(hDlg,uCtrl));
  402. SendDlgItemMessage(hDlg,uCtrl,EM_SETSEL,0,-1);
  403. }