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.

1073 lines
37 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994-1995 **
  4. //*********************************************************************
  5. //
  6. // INETAPI.C - APIs for external components to use to configure system
  7. //
  8. //
  9. // HISTORY:
  10. //
  11. // 3/9/95 jeremys Created.
  12. // 96/02/26 markdu Moved ClearConnectoidIPParams functionality
  13. // into CreateConnectoid, so SetPhoneNumber only makes the
  14. // call to CreateConnectoid
  15. // 96/03/09 markdu Added LPRASENTRY parameter to CreateConnectoid()
  16. // and SetPhoneNumber
  17. // 96/03/09 markdu Moved all references to 'need terminal window after
  18. // dial' into RASENTRY.dwfOptions.
  19. // 96/03/10 markdu Moved all references to modem name into RASENTRY.
  20. // 96/03/10 markdu Copy phone number info into the RASENTRY struct
  21. // in SetPhoneNumber().
  22. // 96/03/10 markdu Set TCP/IP info and autodial info per-connectoid.
  23. // 96/03/21 markdu Set RASEO flags appropriately.
  24. // 96/03/22 markdu Validate pointers before using them.
  25. // 96/03/23 markdu Replaced CLIENTINFO references with CLIENTCONFIG.
  26. // 96/03/24 markdu Replaced memset with ZeroMemory for consistency.
  27. // 96/03/24 markdu Replaced lstrcpy with lstrcpyn where appropriate.
  28. // 96/03/25 markdu Replaced ApplyGlobalTcpInfo with ClearGlobalTcpInfo.
  29. // and replaced GetGlobalTcpInfo with IsThereGlobalTcpInfo.
  30. // 96/03/26 markdu Put #ifdef __cplusplus around extern "C"
  31. // 96/03/26 markdu Use MAX_ISP_NAME instead of RAS_MaxEntryName
  32. // because of bug in RNA.
  33. // 96/04/04 markdu Added phonebook name param to CreateConnectoid.
  34. // 96/04/06 markdu NASH BUG 15653 Use exported autodial API.
  35. // 96/05/25 markdu Use ICFG_ flags for lpNeedDrivers and lpInstallDrivers.
  36. // 96/05/26 markdu Use lpIcfgTurnOffFileSharing and lpIcfgIsFileSharingTurnedOn,
  37. // lpIsGlobalDNS and lpIcfgRemoveGlobalDNS.
  38. // 96/05/27 markdu Use lpIcfgInstallInetComponents and lpIcfgNeedInetComponents.
  39. // 96/06/04 markdu OSR BUG 7246 If no area code supplied, turn off
  40. // RASEO_UseCountryAndAreaCodes flag.
  41. //
  42. #include "wizard.h"
  43. #ifdef __cplusplus
  44. extern "C"
  45. {
  46. #endif // __cplusplus
  47. #include "inetapi.h"
  48. // avoid name mangling
  49. VOID WINAPI InetPerformSecurityCheck(HWND hWnd,BOOL * pfNeedRestart);
  50. #define ERROR_ALREADY_DISPLAYED -1
  51. BOOL ConfigureSystemForInternet_W(LPINTERNET_CONFIG lpInternetConfig,
  52. BOOL fPromptIfConfigNeeded);
  53. #ifdef __cplusplus
  54. }
  55. #endif // __cplusplus
  56. DWORD SetPhoneNumber(LPTSTR pszEntryName,UINT cbEntryName,LPRASENTRY lpRasEntry,
  57. PHONENUM * pPhoneNum,
  58. LPCTSTR pszUserName,LPCTSTR pszPassword,UINT uDefNameID);
  59. INT_PTR CALLBACK SecurityCheckDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  60. LPARAM lParam);
  61. BOOL CenterWindow (HWND hwndChild, HWND hwndParent);
  62. BOOL CALLBACK WarningDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  63. LPARAM lParam);
  64. extern ICFGINSTALLSYSCOMPONENTS lpIcfgInstallInetComponents;
  65. extern ICFGNEEDSYSCOMPONENTS lpIcfgNeedInetComponents;
  66. extern ICFGISGLOBALDNS lpIcfgIsGlobalDNS;
  67. extern ICFGREMOVEGLOBALDNS lpIcfgRemoveGlobalDNS;
  68. extern ICFGTURNOFFFILESHARING lpIcfgTurnOffFileSharing;
  69. extern ICFGISFILESHARINGTURNEDON lpIcfgIsFileSharingTurnedOn;
  70. extern ICFGGETLASTINSTALLERRORTEXT lpIcfgGetLastInstallErrorText;
  71. typedef struct tagWARNINGDLGINFO {
  72. BOOL fResult; // TRUE if user chose yes/OK to warning
  73. BOOL fDisableWarning; // TRUE if user wants to disable warning in future
  74. } WARNINGDLGINFO;
  75. #ifdef UNICODE
  76. PWCHAR ToUnicodeWithAlloc(LPCSTR);
  77. #endif
  78. /*******************************************************************
  79. NAME: ConfigureSystemForInternet
  80. SYNOPSIS: Performs all necessary configuration to set system up
  81. to use Internet.
  82. ENTRY: lpInternetConfig - pointer to structure with configuration
  83. information.
  84. EXIT: TRUE if successful, or FALSE if fails. Displays its
  85. own error message upon failure.
  86. If the output flag ICOF_NEEDREBOOT is set, the caller
  87. must restart the system before continuing.
  88. NOTES: Will install TCP/IP, RNA, PPPMAC as necessary; will
  89. create or modify an Internet RNA connectoid.
  90. This API displays error messages itself rather than
  91. passing back an error code because there is a wide range of
  92. possible error codes from different families, it is difficult
  93. for the caller to obtain text for all of them.
  94. Calls worker function ConfigureSystemForInternet_W.
  95. ********************************************************************/
  96. #ifdef UNICODE
  97. extern "C" BOOL WINAPI ConfigureSystemForInternetA
  98. (
  99. LPINTERNET_CONFIGA lpInternetConfig
  100. )
  101. {
  102. HRESULT hr;
  103. LPTSTR pszModemNameW = ToUnicodeWithAlloc(lpInternetConfig->pszModemName);
  104. LPTSTR pszUserNameW = ToUnicodeWithAlloc(lpInternetConfig->pszUserName);
  105. LPTSTR pszPasswordW = ToUnicodeWithAlloc(lpInternetConfig->pszPassword);
  106. LPTSTR pszEntryNameW = ToUnicodeWithAlloc(lpInternetConfig->pszEntryName);
  107. LPTSTR pszEntryName2W = ToUnicodeWithAlloc(lpInternetConfig->pszEntryName2);
  108. LPTSTR pszDNSServerW = ToUnicodeWithAlloc(lpInternetConfig->pszDNSServer);
  109. LPTSTR pszDNSServer2W = ToUnicodeWithAlloc(lpInternetConfig->pszDNSServer2);
  110. LPTSTR pszAutodialDllNameW = ToUnicodeWithAlloc(lpInternetConfig->pszAutodialDllName);
  111. LPTSTR pszAutodialFcnNameW = ToUnicodeWithAlloc(lpInternetConfig->pszAutodialFcnName);
  112. INTERNET_CONFIGW InternetConfigW;
  113. InternetConfigW.cbSize = sizeof(INTERNET_CONFIGW);
  114. InternetConfigW.hwndParent = lpInternetConfig->hwndParent;
  115. InternetConfigW.pszModemName = pszModemNameW;
  116. InternetConfigW.pszUserName = pszUserNameW;
  117. InternetConfigW.pszEntryName = pszEntryNameW;
  118. InternetConfigW.pszEntryName2 = pszEntryName2W;
  119. InternetConfigW.pszDNSServer = pszDNSServerW;
  120. InternetConfigW.pszDNSServer2 = pszDNSServer2W;
  121. InternetConfigW.pszAutodialDllName = pszAutodialDllNameW;
  122. InternetConfigW.pszAutodialFcnName = pszAutodialFcnNameW;
  123. InternetConfigW.dwInputFlags = lpInternetConfig->dwInputFlags;
  124. InternetConfigW.dwOutputFlags = lpInternetConfig->dwOutputFlags;
  125. InternetConfigW.PhoneNum.dwCountryID = lpInternetConfig->PhoneNum.dwCountryID;
  126. InternetConfigW.PhoneNum.dwCountryCode = lpInternetConfig->PhoneNum.dwCountryCode;
  127. mbstowcs(InternetConfigW.PhoneNum.szAreaCode,
  128. lpInternetConfig->PhoneNum.szAreaCode,
  129. lstrlenA(lpInternetConfig->PhoneNum.szAreaCode)+1);
  130. mbstowcs(InternetConfigW.PhoneNum.szLocal,
  131. lpInternetConfig->PhoneNum.szLocal,
  132. lstrlenA(lpInternetConfig->PhoneNum.szLocal)+1);
  133. mbstowcs(InternetConfigW.PhoneNum.szExtension,
  134. lpInternetConfig->PhoneNum.szExtension,
  135. lstrlenA(lpInternetConfig->PhoneNum.szExtension)+1);
  136. InternetConfigW.PhoneNum2.dwCountryID = lpInternetConfig->PhoneNum2.dwCountryID;
  137. InternetConfigW.PhoneNum2.dwCountryCode = lpInternetConfig->PhoneNum2.dwCountryCode;
  138. mbstowcs(InternetConfigW.PhoneNum2.szAreaCode,
  139. lpInternetConfig->PhoneNum2.szAreaCode,
  140. lstrlenA(lpInternetConfig->PhoneNum2.szAreaCode)+1);
  141. mbstowcs(InternetConfigW.PhoneNum2.szLocal,
  142. lpInternetConfig->PhoneNum2.szLocal,
  143. lstrlenA(lpInternetConfig->PhoneNum2.szLocal)+1);
  144. mbstowcs(InternetConfigW.PhoneNum2.szExtension,
  145. lpInternetConfig->PhoneNum2.szExtension,
  146. lstrlenA(lpInternetConfig->PhoneNum2.szExtension)+1);
  147. hr = ConfigureSystemForInternetW(&InternetConfigW);
  148. // Free all allocated WCHAR.
  149. if(pszModemNameW)
  150. GlobalFree(pszModemNameW);
  151. if(pszUserNameW)
  152. GlobalFree(pszUserNameW);
  153. if(pszEntryNameW)
  154. GlobalFree(pszEntryNameW);
  155. if(pszEntryName2W)
  156. GlobalFree(pszEntryName2W);
  157. if(pszDNSServerW)
  158. GlobalFree(pszDNSServerW);
  159. if(pszDNSServer2W)
  160. GlobalFree(pszDNSServer2W);
  161. if(pszAutodialDllNameW)
  162. GlobalFree(pszAutodialDllNameW);
  163. if(pszAutodialFcnNameW)
  164. GlobalFree(pszAutodialFcnNameW);
  165. return hr;
  166. }
  167. extern "C" BOOL WINAPI ConfigureSystemForInternetW
  168. #else
  169. extern "C" BOOL WINAPI ConfigureSystemForInternetA
  170. #endif
  171. (
  172. LPINTERNET_CONFIG lpInternetConfig
  173. )
  174. {
  175. BOOL fRet;
  176. // call worker function
  177. fRet = ConfigureSystemForInternet_W(lpInternetConfig,FALSE);
  178. if (fRet)
  179. {
  180. // make sure "The Internet" icon on desktop points to web browser
  181. // (it may initially be pointing at internet wizard) (for versions < IE 4)
  182. // //10/24/96 jmazner Normandy 6968
  183. // //No longer neccessary thanks to Valdon's hooks for invoking ICW.
  184. // 11/21/96 jmazner Normandy 11812
  185. // oops, it _is_ neccessary, since if user downgrades from IE 4 to IE 3,
  186. // ICW 1.1 needs to morph the IE 3 icon.
  187. SetDesktopInternetIconToBrowser();
  188. }
  189. return fRet;
  190. }
  191. /*******************************************************************
  192. NAME: SetInternetPhoneNumber
  193. SYNOPSIS: Sets the phone number used to auto-dial to the Internet.
  194. If the system is not fully configured when this API is called,
  195. this API will do the configuration after checking with the user.
  196. (This step is included for extra robustness, in case the user has
  197. removed something since the system was configured.)
  198. ENTRY: lpPhonenumConfig - pointer to structure with configuration
  199. information.
  200. If the input flag ICIF_NOCONFIGURE is set, then if the system
  201. is not already configured properly, this API will display an
  202. error message and return FALSE. (Otherwise this API will
  203. ask the user if it's OK to configure the system, and do it.)
  204. EXIT: TRUE if successful, or FALSE if fails. Displays its
  205. own error message upon failure.
  206. If the output flag ICOF_NEEDREBOOT is set, the caller
  207. must restart the system before continuing. (
  208. NOTES: Will create a new connectoid if a connectoid for the internet
  209. does not exist yet, otherwise modifies existing internet
  210. connectoid.
  211. This API displays error messages itself rather than
  212. passing back an error code because there is a wide range of
  213. possible error codes from different families, it is difficult
  214. for the caller to obtain text for all of them.
  215. Calls worker function ConfigureSystemForInternet_W.
  216. ********************************************************************/
  217. #ifdef UNICODE
  218. extern "C" BOOL WINAPI SetInternetPhoneNumberA
  219. (
  220. LPINTERNET_CONFIGA lpInternetConfig
  221. )
  222. {
  223. HRESULT hr;
  224. LPTSTR pszModemNameW = ToUnicodeWithAlloc(lpInternetConfig->pszModemName);
  225. LPTSTR pszUserNameW = ToUnicodeWithAlloc(lpInternetConfig->pszUserName);
  226. LPTSTR pszPasswordW = ToUnicodeWithAlloc(lpInternetConfig->pszPassword);
  227. LPTSTR pszEntryNameW = ToUnicodeWithAlloc(lpInternetConfig->pszEntryName);
  228. LPTSTR pszEntryName2W = ToUnicodeWithAlloc(lpInternetConfig->pszEntryName2);
  229. LPTSTR pszDNSServerW = ToUnicodeWithAlloc(lpInternetConfig->pszDNSServer);
  230. LPTSTR pszDNSServer2W = ToUnicodeWithAlloc(lpInternetConfig->pszDNSServer2);
  231. LPTSTR pszAutodialDllNameW = ToUnicodeWithAlloc(lpInternetConfig->pszAutodialDllName);
  232. LPTSTR pszAutodialFcnNameW = ToUnicodeWithAlloc(lpInternetConfig->pszAutodialFcnName);
  233. INTERNET_CONFIGW InternetConfigW;
  234. InternetConfigW.cbSize = sizeof(INTERNET_CONFIGW);
  235. InternetConfigW.hwndParent = lpInternetConfig->hwndParent;
  236. InternetConfigW.pszModemName = pszModemNameW;
  237. InternetConfigW.pszUserName = pszUserNameW;
  238. InternetConfigW.pszEntryName = pszEntryNameW;
  239. InternetConfigW.pszEntryName2 = pszEntryName2W;
  240. InternetConfigW.pszDNSServer = pszDNSServerW;
  241. InternetConfigW.pszDNSServer2 = pszDNSServer2W;
  242. InternetConfigW.pszAutodialDllName = pszAutodialDllNameW;
  243. InternetConfigW.pszAutodialFcnName = pszAutodialFcnNameW;
  244. InternetConfigW.dwInputFlags = lpInternetConfig->dwInputFlags;
  245. InternetConfigW.dwOutputFlags = lpInternetConfig->dwOutputFlags;
  246. InternetConfigW.PhoneNum.dwCountryID = lpInternetConfig->PhoneNum.dwCountryID;
  247. InternetConfigW.PhoneNum.dwCountryCode = lpInternetConfig->PhoneNum.dwCountryCode;
  248. mbstowcs(InternetConfigW.PhoneNum.szAreaCode,
  249. lpInternetConfig->PhoneNum.szAreaCode,
  250. lstrlenA(lpInternetConfig->PhoneNum.szAreaCode)+1);
  251. mbstowcs(InternetConfigW.PhoneNum.szLocal,
  252. lpInternetConfig->PhoneNum.szLocal,
  253. lstrlenA(lpInternetConfig->PhoneNum.szLocal)+1);
  254. mbstowcs(InternetConfigW.PhoneNum.szExtension,
  255. lpInternetConfig->PhoneNum.szExtension,
  256. lstrlenA(lpInternetConfig->PhoneNum.szExtension)+1);
  257. InternetConfigW.PhoneNum2.dwCountryID = lpInternetConfig->PhoneNum2.dwCountryID;
  258. InternetConfigW.PhoneNum2.dwCountryCode = lpInternetConfig->PhoneNum2.dwCountryCode;
  259. mbstowcs(InternetConfigW.PhoneNum2.szAreaCode,
  260. lpInternetConfig->PhoneNum2.szAreaCode,
  261. lstrlenA(lpInternetConfig->PhoneNum2.szAreaCode)+1);
  262. mbstowcs(InternetConfigW.PhoneNum2.szLocal,
  263. lpInternetConfig->PhoneNum2.szLocal,
  264. lstrlenA(lpInternetConfig->PhoneNum2.szLocal)+1);
  265. mbstowcs(InternetConfigW.PhoneNum2.szExtension,
  266. lpInternetConfig->PhoneNum2.szExtension,
  267. lstrlenA(lpInternetConfig->PhoneNum2.szExtension)+1);
  268. hr = SetInternetPhoneNumberW(&InternetConfigW);
  269. // Free all allocated WCHAR.
  270. if(pszModemNameW)
  271. GlobalFree(pszModemNameW);
  272. if(pszUserNameW)
  273. GlobalFree(pszUserNameW);
  274. if(pszEntryNameW)
  275. GlobalFree(pszEntryNameW);
  276. if(pszEntryName2W)
  277. GlobalFree(pszEntryName2W);
  278. if(pszDNSServerW)
  279. GlobalFree(pszDNSServerW);
  280. if(pszDNSServer2W)
  281. GlobalFree(pszDNSServer2W);
  282. if(pszAutodialDllNameW)
  283. GlobalFree(pszAutodialDllNameW);
  284. if(pszAutodialFcnNameW)
  285. GlobalFree(pszAutodialFcnNameW);
  286. return hr;
  287. }
  288. extern "C" BOOL WINAPI SetInternetPhoneNumberW
  289. #else
  290. extern "C" BOOL WINAPI SetInternetPhoneNumberA
  291. #endif
  292. (
  293. LPINTERNET_CONFIG lpInternetConfig
  294. )
  295. {
  296. // call worker function
  297. return ConfigureSystemForInternet_W(lpInternetConfig,TRUE);
  298. }
  299. /*******************************************************************
  300. NAME: ConfigureSystemForInternet_W
  301. SYNOPSIS: worker function to do system configuration for Internet
  302. ENTRY: lpInternetConfig - pointer to structure with configuration
  303. information.
  304. fPromptIfConfigNeeded - if TRUE, then if any system
  305. configuration is needed the user will be prompted and
  306. asked if it's OK to reconfigure the system
  307. EXIT: TRUE if successful, or FALSE if fails. Displays its
  308. own error message upon failure.
  309. If the output flag ICOF_NEEDREBOOT is set, the caller
  310. must restart the system before continuing.
  311. NOTES: Will install TCP/IP, RNA, PPPMAC as necessary; will
  312. create or modify an Internet RNA connectoid.
  313. This API displays error messages itself rather than
  314. passing back an error code because there is a wide range of
  315. possible error codes from different families, it is difficult
  316. for the caller to obtain text for all of them.
  317. ********************************************************************/
  318. BOOL ConfigureSystemForInternet_W(LPINTERNET_CONFIG lpInternetConfig,
  319. BOOL fPromptIfConfigNeeded)
  320. {
  321. UINT uErr=ERROR_SUCCESS,uErrMsgID=IDS_ERRSetPhoneNumber;
  322. DWORD dwErrCls = ERRCLS_STANDARD;
  323. BOOL fNeedDrivers = FALSE;
  324. BOOL fRet = FALSE;
  325. BOOL fNeedReboot = FALSE;
  326. TCHAR szEntryName[MAX_ISP_NAME+1]=TEXT("");
  327. BOOL fNeedToDeInitRNA = FALSE;
  328. DWORD dwfInstallOptions;
  329. DEBUGMSG("inetapi.c::ConfigureSystemForInternet_W()");
  330. // validate parameters
  331. ASSERT(lpInternetConfig);
  332. if (!lpInternetConfig)
  333. return FALSE;
  334. ASSERT(lpInternetConfig->cbSize == sizeof(INTERNET_CONFIG));
  335. if (lpInternetConfig->cbSize != sizeof(INTERNET_CONFIG))
  336. return FALSE;
  337. // clear output flags
  338. lpInternetConfig->dwOutputFlags = 0;
  339. HWND hwndParent = lpInternetConfig->hwndParent;
  340. WAITCURSOR WaitCursor; // set an hourglass cursor
  341. // Also allocate a RASENTRY struct for connectoid data
  342. LPRASENTRY pRasEntry = new RASENTRY;
  343. ASSERT(pRasEntry);
  344. if (!pRasEntry)
  345. {
  346. // out of memory!
  347. uErr = ERROR_NOT_ENOUGH_MEMORY;
  348. dwErrCls = ERRCLS_STANDARD;
  349. goto exit;
  350. }
  351. InitRasEntry(pRasEntry);
  352. // based on config and preferences, find out if we need to install
  353. // drivers/files or not
  354. dwfInstallOptions = ICFG_INSTALLTCP | ICFG_INSTALLRAS;
  355. if (!(lpInternetConfig->dwInputFlags & ICIF_NOCONFIGURE))
  356. {
  357. uErr = lpIcfgNeedInetComponents(dwfInstallOptions, &fNeedDrivers);
  358. if (ERROR_SUCCESS != uErr)
  359. {
  360. TCHAR szErrorText[MAX_ERROR_TEXT+1]=TEXT("");
  361. // Get the text of the error message and display it.
  362. if (lpIcfgGetLastInstallErrorText(szErrorText, MAX_ERROR_TEXT+1))
  363. {
  364. MsgBoxSz(NULL,szErrorText,MB_ICONEXCLAMATION,MB_OK);
  365. uErr = (UINT) ERROR_ALREADY_DISPLAYED;
  366. }
  367. goto exit;
  368. }
  369. }
  370. else
  371. {
  372. fNeedDrivers = FALSE;
  373. }
  374. if (fNeedDrivers && fPromptIfConfigNeeded) {
  375. // if this API is just getting called to set a new phone number,
  376. // we check the configuration anyway in case the user has accidentally
  377. // changed something. Since we noticed we need to do something
  378. // to user's config and fPromptIfConfigNeeded is TRUE, we will ask
  379. // the user if it's OK to change the machine's config.
  380. if (MsgBox(hwndParent,IDS_OKTOCHANGECONFIG,MB_ICONQUESTION,MB_YESNO)
  381. != IDYES) {
  382. // user elected not to have us do necessary setup, so just set
  383. // fNeedDrivers flag to FALSE so we don't do setup. We will
  384. // stil try to set internet phone # below... this may fail
  385. // if part of the required setup was to do something like install
  386. // RNA
  387. fNeedDrivers = FALSE;
  388. }
  389. }
  390. if (fNeedDrivers) {
  391. // yes, need to install some drivers
  392. // warn user that we're about to do stuff that may need win 95 disks.
  393. // also let user cancel this part
  394. // the message is long and takes up two string resources, allocate
  395. // memory to build the string
  396. BUFFER MsgBuf(MAX_RES_LEN*2+1),Msg1(MAX_RES_LEN),Msg2(MAX_RES_LEN);
  397. ASSERT(MsgBuf);
  398. ASSERT(Msg1);
  399. ASSERT(Msg2);
  400. if (!MsgBuf || !Msg1 || !Msg2) {
  401. // out of memory!
  402. uErr = ERROR_NOT_ENOUGH_MEMORY;
  403. dwErrCls = ERRCLS_STANDARD;
  404. goto exit;
  405. }
  406. LoadSz(IDS_ABOUTTOCHANGECONFIG1,Msg1.QueryPtr(),Msg1.QuerySize());
  407. LoadSz(IDS_ABOUTTOCHANGECONFIG2,Msg2.QueryPtr(),Msg2.QuerySize());
  408. wsprintf(MsgBuf.QueryPtr(),Msg1.QueryPtr(),Msg2.QueryPtr());
  409. if (MsgBoxSz(hwndParent,MsgBuf.QueryPtr(),MB_ICONINFORMATION,
  410. MB_OKCANCEL) != IDOK) {
  411. // user cancelled, stop
  412. uErr = (UINT) ERROR_ALREADY_DISPLAYED;
  413. goto exit;
  414. }
  415. WAITCURSOR WaitCursor; // construct a wait cursor since MessageBox
  416. // destroys the hourglass cursor
  417. // install the drivers we need
  418. uErr = lpIcfgInstallInetComponents(hwndParent, dwfInstallOptions, &fNeedReboot);
  419. if (ERROR_SUCCESS != uErr)
  420. {
  421. TCHAR szErrorText[MAX_ERROR_TEXT+1]=TEXT("");
  422. // Get the text of the error message and display it.
  423. if (lpIcfgGetLastInstallErrorText(szErrorText, MAX_ERROR_TEXT+1))
  424. {
  425. MsgBoxSz(hwndParent,szErrorText,MB_ICONEXCLAMATION,MB_OK);
  426. uErr = (UINT) ERROR_ALREADY_DISPLAYED;
  427. }
  428. goto exit;
  429. }
  430. // set "need reboot" output flag if appropriate
  431. if (fNeedReboot)
  432. lpInternetConfig->dwOutputFlags |= ICOF_NEEDREBOOT;
  433. }
  434. // MSN dial-in points dynamically assign DNS (as of this writing)... if
  435. // DNS is set statically in registry, dynamic DNS assignment will not
  436. // work and user may be hosed. Check, warn user and offer to remove if
  437. // set...
  438. if (!(lpInternetConfig->dwInputFlags & (ICIF_NOCONFIGURE | ICIF_NODNSCHECK))) {
  439. if (DoDNSCheck(lpInternetConfig->hwndParent,&fNeedReboot)) {
  440. // set "need reboot" output flag if appropriate
  441. if (fNeedReboot)
  442. lpInternetConfig->dwOutputFlags |= ICOF_NEEDREBOOT;
  443. }
  444. }
  445. // create or modify connectoid(s)
  446. // make sure RNA is loaded
  447. fRet = InitRNA(hwndParent);
  448. if (!fRet) {
  449. uErr = (UINT) ERROR_ALREADY_DISPLAYED;
  450. goto exit;
  451. }
  452. fNeedToDeInitRNA = TRUE; // set a flag so we know to free RNA later
  453. // Copy the modem name into the rasentry struct
  454. if (lpInternetConfig->pszModemName)
  455. {
  456. lstrcpyn(pRasEntry->szDeviceName,lpInternetConfig->pszModemName,
  457. ARRAYSIZE(pRasEntry->szDeviceName));
  458. }
  459. // set autodial handler dll if specified by caller
  460. // only do anything if both DLL and function name are set
  461. if (lpInternetConfig && lpInternetConfig->pszAutodialDllName &&
  462. lpInternetConfig->pszAutodialFcnName &&
  463. lpInternetConfig->pszAutodialDllName[0] &&
  464. lpInternetConfig->pszAutodialFcnName[0])
  465. {
  466. lstrcpyn(pRasEntry->szAutodialDll,lpInternetConfig->pszAutodialDllName,
  467. ARRAYSIZE(pRasEntry->szAutodialDll));
  468. lstrcpyn(pRasEntry->szAutodialFunc,lpInternetConfig->pszAutodialFcnName,
  469. ARRAYSIZE(pRasEntry->szAutodialFunc));
  470. }
  471. // Default to not show terminal window after dial.
  472. pRasEntry->dwfOptions &= ~RASEO_TerminalAfterDial;
  473. // Don't use specific IP addresses.
  474. pRasEntry->dwfOptions &= ~RASEO_SpecificIpAddr;
  475. // set DNS information if specified
  476. if (lpInternetConfig->pszDNSServer && lstrlen(lpInternetConfig->pszDNSServer))
  477. {
  478. IPADDRESS dwDNSAddr;
  479. if (IPStrToLong(lpInternetConfig->pszDNSServer,&dwDNSAddr))
  480. {
  481. CopyDw2Ia(dwDNSAddr, &pRasEntry->ipaddrDns);
  482. // Turn on Specific name servers
  483. pRasEntry->dwfOptions |= RASEO_SpecificNameServers;
  484. }
  485. }
  486. if (lpInternetConfig->pszDNSServer2 && lstrlen(lpInternetConfig->pszDNSServer2))
  487. {
  488. IPADDRESS dwDNSAddr;
  489. if (IPStrToLong(lpInternetConfig->pszDNSServer2,&dwDNSAddr))
  490. {
  491. CopyDw2Ia(dwDNSAddr, &pRasEntry->ipaddrDnsAlt);
  492. }
  493. }
  494. // set first phone number
  495. // should always have a real phone number for first phone number
  496. ASSERT(lstrlen(lpInternetConfig->PhoneNum.szLocal));
  497. if (lstrlen(lpInternetConfig->PhoneNum.szLocal))
  498. {
  499. if (lpInternetConfig->pszEntryName)
  500. {
  501. lstrcpyn(szEntryName,lpInternetConfig->pszEntryName,
  502. ARRAYSIZE(szEntryName));
  503. }
  504. else
  505. {
  506. szEntryName[0] = '\0';
  507. }
  508. uErr = SetPhoneNumber(szEntryName,sizeof(szEntryName),pRasEntry,
  509. &lpInternetConfig->PhoneNum,lpInternetConfig->pszUserName,
  510. lpInternetConfig->pszPassword,IDS_DEF_CONNECTION_NAME_1);
  511. dwErrCls = ERRCLS_RNA;
  512. if (uErr == ERROR_SUCCESS)
  513. {
  514. if (!(lpInternetConfig->dwInputFlags & ICIF_DONTSETASINTERNETENTRY))
  515. {
  516. // set this number as the number used to autodial to the Internet
  517. // 96/04/06 markdu NASH BUG 15653 Use exported autodial API.
  518. InetSetAutodial(TRUE, szEntryName);
  519. }
  520. }
  521. }
  522. // set 2nd (backup) phone number
  523. if ((uErr == ERROR_SUCCESS) && (lpInternetConfig->PhoneNum2.szLocal) &&
  524. (lstrlen(lpInternetConfig->PhoneNum2.szLocal)))
  525. {
  526. TCHAR szEntryNameTmp[MAX_ISP_NAME+1];
  527. if (lpInternetConfig->pszEntryName2)
  528. {
  529. lstrcpyn(szEntryNameTmp,lpInternetConfig->pszEntryName2,
  530. ARRAYSIZE(szEntryNameTmp));
  531. }
  532. else
  533. {
  534. szEntryNameTmp[0] = '\0';
  535. }
  536. uErr = SetPhoneNumber(szEntryNameTmp,sizeof(szEntryNameTmp),
  537. pRasEntry,&lpInternetConfig->PhoneNum2,lpInternetConfig->pszUserName,
  538. lpInternetConfig->pszPassword,IDS_DEF_CONNECTION_NAME_2);
  539. dwErrCls = ERRCLS_RNA;
  540. if (uErr == ERROR_SUCCESS)
  541. {
  542. if (!(lpInternetConfig->dwInputFlags & ICIF_DONTSETASINTERNETENTRY))
  543. {
  544. // set this number as the backup number used to autodial to the Internet
  545. SetBackupInternetConnectoid(szEntryNameTmp);
  546. }
  547. }
  548. }
  549. exit:
  550. // free memory
  551. if (pRasEntry)
  552. delete pRasEntry;
  553. // display error message if error occurred
  554. if (uErr != ERROR_SUCCESS && uErr != ERROR_ALREADY_DISPLAYED) {
  555. DisplayErrorMessage(hwndParent,uErrMsgID,uErr,dwErrCls,MB_ICONEXCLAMATION);
  556. }
  557. // free RNA if need be. Note we must do this *after* the call to
  558. // DisplayErrorMessage, because DisplayErrorMessage needs to call RNA
  559. // to get error description if an RNA error was generated.
  560. if (fNeedToDeInitRNA) {
  561. DeInitRNA();
  562. }
  563. return (uErr == ERROR_SUCCESS);
  564. }
  565. /*******************************************************************
  566. NAME: SetPhoneNumber
  567. SYNOPSIS: Creates or modifies a connectoid with specified information
  568. ENTRY: pszEntryName - name to use for the connectoid. If empty, the
  569. default name stored in string resource specified by
  570. uDefNameID will be used. On exit, this buffer is filled
  571. in with the actual name used.
  572. cbEntryName - size of buffer pointed to by szEntryName
  573. pPhoneNum - pointer to struct with phone number
  574. pszUserName - user name to populate connectoid with. Ignored
  575. if NULL.
  576. pszPassword - password to populate connectoid with. Ignored
  577. if NULL.
  578. uDefNameID - ID of string resource with default name to use
  579. if pszEntryName is NULL.
  580. EXIT: returns an RNA error code
  581. NOTES: This is a wrapper to call CreateConnectoid, to avoid duplicating
  582. code to load default name out of resource.
  583. Since the pszEntryName buffer is filled at exit with the
  584. actual name used, callers should be careful not to pass in buffers
  585. from API callers, since apps using API won't expect their own
  586. buffers to be modified.
  587. ********************************************************************/
  588. DWORD SetPhoneNumber(LPTSTR pszEntryName,UINT cbEntryName,
  589. LPRASENTRY lpRasEntry, PHONENUM * pPhoneNum,
  590. LPCTSTR pszUserName,LPCTSTR pszPassword,UINT uDefNameID)
  591. {
  592. ASSERT(pszEntryName);
  593. ASSERT(pPhoneNum);
  594. ASSERT(lpRasEntry);
  595. // (all other parameters may be NULL)
  596. // if a connectoid name was specified, use it; if NULL, use a default
  597. // name.
  598. if (!lstrlen(pszEntryName))
  599. {
  600. LoadSz(uDefNameID,pszEntryName,cbEntryName);
  601. }
  602. // 96/06/04 markdu OSR BUG 7246
  603. // If no area code was specified, turn off area code flag
  604. if (lstrlen(pPhoneNum->szAreaCode))
  605. {
  606. lpRasEntry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  607. }
  608. else
  609. {
  610. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  611. }
  612. // copy the phone number data
  613. lpRasEntry->dwCountryID = pPhoneNum->dwCountryID;
  614. lpRasEntry->dwCountryCode = pPhoneNum->dwCountryCode;
  615. lstrcpyn (lpRasEntry->szAreaCode, pPhoneNum->szAreaCode,
  616. ARRAYSIZE(lpRasEntry->szAreaCode));
  617. lstrcpyn (lpRasEntry->szLocalPhoneNumber, pPhoneNum->szLocal,
  618. ARRAYSIZE(lpRasEntry->szLocalPhoneNumber));
  619. // create/update the connectoid
  620. DWORD dwRet = CreateConnectoid(NULL, pszEntryName,lpRasEntry,
  621. pszUserName,pszPassword);
  622. return dwRet;
  623. }
  624. /*******************************************************************
  625. NAME: InetPerformSecurityCheck
  626. SYNOPSIS: Checks to make sure win 95 file/print sharing is not
  627. bound to TCP/IP used for the internet
  628. ENTRY: hWnd - parent window (if any)
  629. pfNeedRestart - on exit, set to TRUE if restart is needed.
  630. NOTES: If we warn user about file/print sharing and user tells us
  631. to fix, then a reboot is necessary. Caller is responsible
  632. for checking *pfNeedRestart on return and restarting system
  633. if necessary.
  634. ********************************************************************/
  635. VOID WINAPI InetPerformSecurityCheck(HWND hWnd,BOOL * pfNeedRestart)
  636. {
  637. ASSERT(pfNeedRestart);
  638. *pfNeedRestart = FALSE;
  639. // see if the server is bound to internet instance
  640. BOOL fSharingOn;
  641. HRESULT hr = lpIcfgIsFileSharingTurnedOn(INSTANCE_PPPDRIVER, &fSharingOn);
  642. //
  643. // 5/12/97 jmazner Olympus #3442 IE #30886
  644. // TEMP TODO at the moment, icfgnt doesn't implement FileSharingTurnedOn
  645. // Until it does, assume that on NT file sharing is always off.
  646. //
  647. if( IsNT() )
  648. {
  649. DEBUGMSG("Ignoring return code from IcfgIsFileSharingTurnedOn");
  650. fSharingOn = FALSE;
  651. }
  652. if ((ERROR_SUCCESS == hr) && (TRUE == fSharingOn))
  653. {
  654. // ask user if we can disable file/print sharing on TCP/IP instance
  655. // to the Internet
  656. BOOL fRet=(BOOL)DialogBox(ghInstance,MAKEINTRESOURCE(IDD_SECURITY_CHECK),
  657. hWnd,SecurityCheckDlgProc);
  658. if (fRet) {
  659. // user OK'd it, go ahead and unbind the server from the instance
  660. // in question
  661. HRESULT hr = lpIcfgTurnOffFileSharing(INSTANCE_PPPDRIVER, hWnd);
  662. ASSERT(hr == ERROR_SUCCESS);
  663. if (hr == ERROR_SUCCESS) {
  664. // we need to restart for the changes to take effect
  665. *pfNeedRestart = TRUE;
  666. }
  667. }
  668. }
  669. }
  670. /*******************************************************************
  671. NAME: SecurityCheckDlgProc
  672. SYNOPSIS: Dialog proc for security check dialog
  673. NOTES: This is basically just a yes/no dialog, so we could
  674. almost just use MessageBox, except we also need a "don't
  675. do this any more" checkbox.
  676. ********************************************************************/
  677. INT_PTR CALLBACK SecurityCheckDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  678. LPARAM lParam)
  679. {
  680. switch (uMsg) {
  681. case WM_INITDIALOG:
  682. CenterWindow(hDlg,GetDesktopWindow());
  683. SetFocus(GetDlgItem(hDlg,IDOK));
  684. return TRUE;
  685. break;
  686. case WM_COMMAND:
  687. switch (wParam) {
  688. case IDOK:
  689. // dismiss the dialog
  690. EndDialog(hDlg,TRUE);
  691. break;
  692. case IDCANCEL:
  693. // if "don't display this in the future" is checked, then
  694. // turn off registry switch for security check
  695. if (IsDlgButtonChecked(hDlg,IDC_DISABLE_CHECK)) {
  696. RegEntry re(szRegPathInternetSettings,HKEY_CURRENT_USER);
  697. ASSERT(re.GetError() == ERROR_SUCCESS);
  698. if (re.GetError() == ERROR_SUCCESS) {
  699. re.SetValue(szRegValEnableSecurityCheck,
  700. (DWORD) 0 );
  701. ASSERT(re.GetError() == ERROR_SUCCESS);
  702. }
  703. }
  704. // dismiss the dialog
  705. EndDialog(hDlg,FALSE);
  706. break;
  707. case IDC_DISABLE_CHECK:
  708. // if "don't do this in the future" is checked, then
  709. // disable 'OK' button
  710. EnableDlgItem(hDlg,IDOK,!IsDlgButtonChecked(hDlg,
  711. IDC_DISABLE_CHECK));
  712. break;
  713. }
  714. break;
  715. }
  716. return FALSE;
  717. }
  718. /****************************************************************************
  719. FUNCTION: CenterWindow (HWND, HWND)
  720. PURPOSE: Center one window over another
  721. COMMENTS:
  722. Dialog boxes take on the screen position that they were designed at,
  723. which is not always appropriate. Centering the dialog over a particular
  724. window usually results in a better position.
  725. ****************************************************************************/
  726. BOOL CenterWindow (HWND hwndChild, HWND hwndParent)
  727. {
  728. RECT rChild, rParent;
  729. int wChild, hChild, wParent, hParent;
  730. int wScreen, hScreen, xNew, yNew;
  731. HDC hdc;
  732. // Get the Height and Width of the child window
  733. GetWindowRect (hwndChild, &rChild);
  734. wChild = rChild.right - rChild.left;
  735. hChild = rChild.bottom - rChild.top;
  736. // Get the Height and Width of the parent window
  737. GetWindowRect (hwndParent, &rParent);
  738. wParent = rParent.right - rParent.left;
  739. hParent = rParent.bottom - rParent.top;
  740. // Get the display limits
  741. hdc = GetDC (hwndChild);
  742. wScreen = GetDeviceCaps (hdc, HORZRES);
  743. hScreen = GetDeviceCaps (hdc, VERTRES);
  744. ReleaseDC (hwndChild, hdc);
  745. // Calculate new X position, then adjust for screen
  746. xNew = rParent.left + ((wParent - wChild) /2);
  747. if (xNew < 0) {
  748. xNew = 0;
  749. } else if ((xNew+wChild) > wScreen) {
  750. xNew = wScreen - wChild;
  751. }
  752. // Calculate new Y position, then adjust for screen
  753. yNew = rParent.top + ((hParent - hChild) /2);
  754. if (yNew < 0) {
  755. yNew = 0;
  756. } else if ((yNew+hChild) > hScreen) {
  757. yNew = hScreen - hChild;
  758. }
  759. // Set it, and return
  760. return SetWindowPos (hwndChild, NULL,
  761. xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  762. }
  763. /*******************************************************************
  764. NAME: DoDNSCheck
  765. SYNOPSIS: Checks to see if DNS is configured statically in the
  766. registry. If it is, then displays a dialog offering
  767. to remove it, and removes it if user chooses.
  768. ENTRY: hwndParent - parent window
  769. pfNeedRestart - filled in on exit with TRUE if restart
  770. is necessary, FALSE otherwise
  771. NOTES: Need to do this to work around Win 95 bug where
  772. dynamically assigned DNS servers are ignored if static
  773. DNS servers are set.
  774. Note that the UI is MSN specific and contains MSN
  775. references!
  776. ********************************************************************/
  777. BOOL DoDNSCheck(HWND hwndParent,BOOL * pfNeedRestart)
  778. {
  779. ASSERT(pfNeedRestart);
  780. *pfNeedRestart = FALSE;
  781. /******** ChrisK 10/24/96 Normandy 3722 - see bug for LONG discussion on this
  782. // see if this warning has already been disabled
  783. RegEntry re(szRegPathWarningFlags,HKEY_CURRENT_USER);
  784. if (re.GetError() == ERROR_SUCCESS) {
  785. if (re.GetNumber(szRegValDisableDNSWarning,0) > 0) {
  786. // user has asked for warning to be disabled, nothing to do
  787. return TRUE;
  788. }
  789. }
  790. // if there are DNS servers set statically (e.g. in net setup),
  791. // warn the user and ask if we should remove
  792. BOOL fGlobalDNS;
  793. HRESULT hr = lpIcfgIsGlobalDNS(&fGlobalDNS);
  794. if ((ERROR_SUCCESS == hr) && (TRUE == fGlobalDNS))
  795. {
  796. WARNINGDLGINFO WarningDlgInfo;
  797. ZeroMemory(&WarningDlgInfo,sizeof(WARNINGDLGINFO));
  798. DialogBoxParam(ghInstance,MAKEINTRESOURCE(IDD_DNS_WARNING),
  799. hwndParent,WarningDlgProc,(LPARAM) &WarningDlgInfo);
  800. // one field or the other can be TRUE, but not both...
  801. ASSERT(!(WarningDlgInfo.fResult && WarningDlgInfo.fDisableWarning));
  802. if (WarningDlgInfo.fResult)
  803. {
  804. // remove static DNS servers from registry
  805. HRESULT hr = lpIcfgRemoveGlobalDNS();
  806. ASSERT(hr == ERROR_SUCCESS);
  807. if (hr != ERROR_SUCCESS)
  808. {
  809. DisplayErrorMessage(hwndParent,IDS_ERRWriteDNS,hr,
  810. ERRCLS_STANDARD,MB_ICONEXCLAMATION);
  811. }
  812. else
  813. {
  814. *pfNeedRestart = TRUE;
  815. }
  816. }
  817. else if (WarningDlgInfo.fDisableWarning)
  818. {
  819. // disable warning switch in registry
  820. re.SetValue(szRegValDisableDNSWarning,(DWORD) TRUE);
  821. }
  822. }
  823. ChrisK 10/24/96 Normandy 3722 - see bug for LONG discussion on this ********/
  824. return TRUE;
  825. }
  826. /*******************************************************************
  827. NAME: WarningDlgProc
  828. SYNOPSIS: Dialog proc for DNS warning dialog
  829. ********************************************************************/
  830. BOOL CALLBACK WarningDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  831. LPARAM lParam)
  832. {
  833. WARNINGDLGINFO * pWarningDlgInfo;
  834. switch (uMsg) {
  835. case WM_INITDIALOG:
  836. // center dialog on screen if we're not owned
  837. if (!GetParent(hDlg)) {
  838. CenterWindow(hDlg,GetDesktopWindow());
  839. }
  840. SetFocus(GetDlgItem(hDlg,IDOK));
  841. // lParam should point to WARNINGDLGINFO struct
  842. ASSERT(lParam);
  843. if (!lParam)
  844. return FALSE;
  845. // store pointer in window data
  846. SetWindowLongPtr(hDlg,DWLP_USER,lParam);
  847. return TRUE;
  848. break;
  849. case WM_COMMAND:
  850. pWarningDlgInfo = (WARNINGDLGINFO *) GetWindowLongPtr(hDlg,DWLP_USER);
  851. ASSERT(pWarningDlgInfo);
  852. switch (wParam) {
  853. case IDOK:
  854. pWarningDlgInfo->fResult=TRUE;
  855. pWarningDlgInfo->fDisableWarning=FALSE;
  856. EndDialog(hDlg,TRUE);
  857. break;
  858. case IDC_CANCEL:
  859. pWarningDlgInfo->fResult=FALSE;
  860. pWarningDlgInfo->fDisableWarning=
  861. IsDlgButtonChecked(hDlg,IDC_DISABLE_WARNING);
  862. EndDialog(hDlg,FALSE);
  863. break;
  864. case IDC_DISABLE_WARNING:
  865. // when 'disable warning' is checked, disable the 'yes'
  866. // button
  867. EnableDlgItem(hDlg,IDOK,!IsDlgButtonChecked(hDlg,
  868. IDC_DISABLE_WARNING));
  869. break;
  870. }
  871. }
  872. return FALSE;
  873. }