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.

1965 lines
66 KiB

  1. /*-----------------------------------------------------------------------------
  2. rnaapi.cpp
  3. Wrapper to softlink to RNAPH and RASAPI32.DLL
  4. Copyright (C) 1999 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. vyung
  8. History:
  9. 2/7/99 Vyung created
  10. -----------------------------------------------------------------------------*/
  11. #include <util.h>
  12. #include "obcomglb.h"
  13. #include "rnaapi.h"
  14. #include "enumodem.h"
  15. #include "mapicall.h"
  16. #include "wininet.h"
  17. #include "wancfg.h"
  18. #include "assert.h"
  19. extern DWORD SetIEClientInfo(LPINETCLIENTINFO lpClientInfo);
  20. static const WCHAR cszRASAPI32_DLL[] = L"RASAPI32.DLL";
  21. static const WCHAR cszRNAPH_DLL[] = L"RNAPH.DLL";
  22. static const CHAR cszRasEnumDevices[] = "RasEnumDevicesW";
  23. static const CHAR cszRasValidateEntryName[] = "RasValidateEntryName";
  24. static const CHAR cszRasValidateEntryNameA[] = "RasValidateEntryNameW";
  25. static const CHAR cszRasSetCredentials[] = "RasSetCredentialsW";
  26. static const CHAR cszRasSetEntryProperties[] = "RasSetEntryPropertiesW";
  27. static const CHAR cszRasGetEntryProperties[] = "RasGetEntryPropertiesW";
  28. static const CHAR cszRasDeleteEntry[] = "RasDeleteEntryW";
  29. static const CHAR cszRasHangUp[] = "RasHangUpW";
  30. static const CHAR cszRasGetConnectStatus[] = "RasGetConnectStatusW";
  31. static const CHAR cszRasDial[] = "RasDialW";
  32. static const CHAR cszRasEnumConnections[] = "RasEnumConnectionsW";
  33. static const CHAR cszRasGetEntryDialParams[] = "RasGetEntryDialParamsW";
  34. static const CHAR cszRasGetCountryInfo[] = "RasGetCountryInfoW";
  35. static const CHAR cszRasSetEntryDialParams[] = "RasSetEntryDialParamsW";
  36. static const WCHAR cszWininet[] = L"WININET.DLL";
  37. static const CHAR cszInternetSetOption[] = "InternetSetOptionW";
  38. static const CHAR cszInternetQueryOption[] = "InternetQueryOptionW";
  39. #define INTERNET_OPTION_PER_CONNECTION_OPTION 75
  40. //
  41. // Options used in INTERNET_PER_CONN_OPTON struct
  42. //
  43. #define INTERNET_PER_CONN_FLAGS 1
  44. #define INTERNET_PER_CONN_PROXY_SERVER 2
  45. #define INTERNET_PER_CONN_PROXY_BYPASS 3
  46. #define INTERNET_PER_CONN_AUTOCONFIG_URL 4
  47. #define INTERNET_PER_CONN_AUTODISCOVERY_FLAGS 5
  48. //
  49. // PER_CONN_FLAGS
  50. //
  51. #define PROXY_TYPE_DIRECT 0x00000001 // direct to net
  52. #define PROXY_TYPE_PROXY 0x00000002 // via named proxy
  53. #define PROXY_TYPE_AUTO_PROXY_URL 0x00000004 // autoproxy URL
  54. #define PROXY_TYPE_AUTO_DETECT 0x00000008 // use autoproxy detection
  55. //
  56. // PER_CONN_AUTODISCOVERY_FLAGS
  57. //
  58. #define AUTO_PROXY_FLAG_USER_SET 0x00000001 // user changed this setting
  59. #define AUTO_PROXY_FLAG_ALWAYS_DETECT 0x00000002 // force detection even when its not needed
  60. #define AUTO_PROXY_FLAG_DETECTION_RUN 0x00000004 // detection has been run
  61. #define AUTO_PROXY_FLAG_MIGRATED 0x00000008 // migration has just been done
  62. #define AUTO_PROXY_FLAG_DONT_CACHE_PROXY_RESULT 0x00000010 // don't cache result of host=proxy name
  63. #define AUTO_PROXY_FLAG_CACHE_INIT_RUN 0x00000020 // don't initalize and run unless URL expired
  64. #define AUTO_PROXY_FLAG_DETECTION_SUSPECT 0x00000040 // if we're on a LAN & Modem, with only one IP, bad?!?
  65. typedef DWORD (WINAPI* RASSETCREDENTIALS)(
  66. LPCTSTR lpszPhonebook,
  67. LPCTSTR lpszEntry,
  68. LPRASCREDENTIALS lpCredentials,
  69. BOOL fClearCredentials
  70. );
  71. typedef HRESULT (WINAPI * INTERNETSETOPTION) (IN HINTERNET hInternet OPTIONAL, IN DWORD dwOption,IN LPVOID lpBuffer,IN DWORD dwBufferLength);
  72. typedef INTERNET_PER_CONN_OPTION_LISTW INTERNET_PER_CONN_OPTION_LIST;
  73. typedef LPINTERNET_PER_CONN_OPTION_LISTW LPINTERNET_PER_CONN_OPTION_LIST;
  74. // on NT we have to call RasGetEntryProperties with a larger buffer than RASENTRY.
  75. // This is a bug in WinNT4.0 RAS, that didn't get fixed.
  76. //
  77. #define RASENTRY_SIZE_PATCH (7 * sizeof(DWORD))
  78. HRESULT UpdateMailSettings(
  79. HWND hwndParent,
  80. LPINETCLIENTINFO lpINetClientInfo,
  81. LPWSTR lpszEntryName);
  82. DWORD EntryTypeFromDeviceType(
  83. LPCWSTR szDeviceType
  84. );
  85. //+----------------------------------------------------------------------------LPRASDEVINFO
  86. //
  87. // Function: RNAAPI::RNAAPI
  88. //
  89. // Synopsis: Initialize class members and load DLLs
  90. //
  91. // Arguments: None
  92. //
  93. // Returns: None
  94. //
  95. // History: ChrisK Created 1/15/96
  96. //
  97. //-----------------------------------------------------------------------------
  98. RNAAPI::RNAAPI()
  99. {
  100. m_hInst = LoadLibrary(cszRASAPI32_DLL);
  101. m_bUseAutoProxyforConnectoid = 0;
  102. if (FALSE == IsNT ())
  103. {
  104. //
  105. // we only load RNAPH.DLL if it is not NT
  106. // MKarki (5/4/97) - Fix for Bug #3378
  107. //
  108. m_hInst2 = LoadLibrary(cszRNAPH_DLL);
  109. }
  110. else
  111. {
  112. m_hInst2 = NULL;
  113. }
  114. m_fnRasEnumDeviecs = NULL;
  115. m_fnRasValidateEntryName = NULL;
  116. m_fnRasSetEntryProperties = NULL;
  117. m_fnRasGetEntryProperties = NULL;
  118. m_fnRasDeleteEntry = NULL;
  119. m_fnRasHangUp = NULL;
  120. m_fnRasGetConnectStatus = NULL;
  121. m_fnRasEnumConnections = NULL;
  122. m_fnRasDial = NULL;
  123. m_fnRasGetEntryDialParams = NULL;
  124. m_fnRasGetCountryInfo = NULL;
  125. m_fnRasSetEntryDialParams = NULL;
  126. m_pEnumModem = NULL;
  127. }
  128. //+----------------------------------------------------------------------------
  129. //
  130. // Function: RNAAPI::~RNAAPI
  131. //
  132. // Synopsis: release DLLs
  133. //
  134. // Arguments: None
  135. //
  136. // Returns: None
  137. //
  138. // History: ChrisK Created 1/15/96
  139. //
  140. //-----------------------------------------------------------------------------
  141. RNAAPI::~RNAAPI()
  142. {
  143. //
  144. // Clean up
  145. //
  146. if (m_hInst) FreeLibrary(m_hInst);
  147. if (m_hInst2) FreeLibrary(m_hInst2);
  148. }
  149. //+----------------------------------------------------------------------------
  150. //
  151. // Function: RNAAPI::RasEnumDevices
  152. //
  153. // Synopsis: Softlink to RAS function
  154. //
  155. // Arguments: see RAS documentation
  156. //
  157. // Returns: see RAS documentation
  158. //
  159. // History: ChrisK Created 1/15/96
  160. //
  161. //-----------------------------------------------------------------------------
  162. DWORD RNAAPI::RasEnumDevices(LPRASDEVINFO lpRasDevInfo, LPDWORD lpcb,
  163. LPDWORD lpcDevices)
  164. {
  165. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  166. // Look for the API if we haven't already found it
  167. LoadApi(cszRasEnumDevices, (FARPROC*)&m_fnRasEnumDeviecs);
  168. if (m_fnRasEnumDeviecs)
  169. dwRet = (*m_fnRasEnumDeviecs) (lpRasDevInfo, lpcb, lpcDevices);
  170. return dwRet;
  171. }
  172. //+----------------------------------------------------------------------------
  173. //
  174. // Function: RNAAPI::LoadApi
  175. //
  176. // Synopsis: If the given function pointer is NULL, then try to load the API
  177. // from the first DLL, if that fails, try to load from the second
  178. // DLL
  179. //
  180. // Arguments: pszFName - the name of the exported function
  181. // pfnProc - point to where the proc address will be returned
  182. //
  183. // Returns: TRUE - success
  184. //
  185. // History: ChrisK Created 1/15/96
  186. //
  187. //-----------------------------------------------------------------------------
  188. BOOL RNAAPI::LoadApi(LPCSTR pszFName, FARPROC* pfnProc)
  189. {
  190. USES_CONVERSION;
  191. if (*pfnProc == NULL)
  192. {
  193. // Look for the entry point in the first DLL
  194. if (m_hInst)
  195. *pfnProc = GetProcAddress(m_hInst, pszFName);
  196. // if that fails, look for the entry point in the second DLL
  197. if (m_hInst2 && !(*pfnProc))
  198. *pfnProc = GetProcAddress(m_hInst2, pszFName);
  199. }
  200. return (pfnProc != NULL);
  201. }
  202. //+----------------------------------------------------------------------------
  203. //
  204. // Function: RNAAPI::RasGetConnectStatus
  205. //
  206. // Synopsis: Softlink to RAS function
  207. //
  208. // Arguments: see RAS documentation
  209. //
  210. // Returns: see RAS documentation
  211. //
  212. // History: ChrisK Created 7/16/96
  213. //
  214. //-----------------------------------------------------------------------------
  215. DWORD RNAAPI::RasGetConnectStatus(HRASCONN hrasconn, LPRASCONNSTATUS lprasconnstatus)
  216. {
  217. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  218. // Look for the API if we haven't already found it
  219. LoadApi(cszRasGetConnectStatus, (FARPROC*)&m_fnRasGetConnectStatus);
  220. if (m_fnRasGetConnectStatus)
  221. dwRet = (*m_fnRasGetConnectStatus) (hrasconn, lprasconnstatus);
  222. return dwRet;
  223. }
  224. //+----------------------------------------------------------------------------
  225. //
  226. // Function: RNAAPI::RasValidateEntryName
  227. //
  228. // Synopsis: Softlink to RAS function
  229. //
  230. // Arguments: see RAS documentation
  231. //
  232. // Returns: see RAS documentation
  233. //
  234. // History: ChrisK Created 1/15/96
  235. //
  236. //-----------------------------------------------------------------------------
  237. DWORD RNAAPI::RasValidateEntryName(LPCWSTR lpszPhonebook, LPCWSTR lpszEntry)
  238. {
  239. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  240. // Look for the API if we haven't already found it
  241. LoadApi(cszRasValidateEntryName, (FARPROC*)&m_fnRasValidateEntryName);
  242. LoadApi(cszRasValidateEntryNameA, (FARPROC*)&m_fnRasValidateEntryName);
  243. if (m_fnRasValidateEntryName)
  244. dwRet = (*m_fnRasValidateEntryName) (lpszPhonebook, lpszEntry);
  245. return dwRet;
  246. }
  247. //+----------------------------------------------------------------------------
  248. //
  249. // Function: RNAAPI::RasSetEntryProperties
  250. //
  251. // Synopsis: Softlink to RAS function
  252. //
  253. // Arguments: see RAS documentation
  254. //
  255. // Returns: see RAS documentation
  256. //
  257. // History: ChrisK Created 1/15/96
  258. //
  259. //-----------------------------------------------------------------------------
  260. DWORD RNAAPI::RasSetEntryProperties(LPCWSTR lpszPhonebook, LPCWSTR lpszEntry,
  261. LPBYTE lpbEntryInfo, DWORD dwEntryInfoSize,
  262. LPBYTE lpbDeviceInfo, DWORD dwDeviceInfoSize)
  263. {
  264. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  265. RASENTRY FAR *lpRE = NULL;
  266. // Look for the API if we haven't already found it
  267. LoadApi(cszRasSetEntryProperties, (FARPROC*)&m_fnRasSetEntryProperties);
  268. /*//////Assert(
  269. (NULL != lpbDeviceInfo) && (NULL != dwDeviceInfoSize)
  270. ||
  271. (NULL == lpbDeviceInfo) && (NULL == dwDeviceInfoSize)
  272. );*/
  273. #define RASGETCOUNTRYINFO_BUFFER_SIZE 256
  274. if (0 == ((LPRASENTRY)lpbEntryInfo)->dwCountryCode)
  275. {
  276. BYTE rasCI[RASGETCOUNTRYINFO_BUFFER_SIZE];
  277. LPRASCTRYINFO prasCI;
  278. DWORD dwSize;
  279. DWORD dw;
  280. prasCI = (LPRASCTRYINFO)rasCI;
  281. ZeroMemory(prasCI, sizeof(rasCI));
  282. prasCI->dwSize = sizeof(RASCTRYINFO);
  283. dwSize = sizeof(rasCI);
  284. ////////Assert(((LPRASENTRY)lpbEntryInfo)->dwCountryID);
  285. prasCI->dwCountryID = ((LPRASENTRY)lpbEntryInfo)->dwCountryID;
  286. dw = RNAAPI::RasGetCountryInfo(prasCI, &dwSize);
  287. if (ERROR_SUCCESS == dw)
  288. {
  289. ////////Assert(prasCI->dwCountryCode);
  290. ((LPRASENTRY)lpbEntryInfo)->dwCountryCode = prasCI->dwCountryCode;
  291. }
  292. else
  293. {
  294. ////////AssertMsg(0, L"Unexpected error from RasGetCountryInfo.\r\n");
  295. }
  296. }
  297. if (m_fnRasSetEntryProperties)
  298. dwRet = (*m_fnRasSetEntryProperties) (lpszPhonebook, lpszEntry,
  299. lpbEntryInfo, dwEntryInfoSize,
  300. lpbDeviceInfo, dwDeviceInfoSize);
  301. lpRE = (RASENTRY FAR*)lpbEntryInfo;
  302. LclSetEntryScriptPatch(lpRE->szScript, lpszEntry);
  303. return dwRet;
  304. }
  305. //+----------------------------------------------------------------------------
  306. //
  307. // Function: RNAAPI::RasGetEntryProperties
  308. //
  309. // Synopsis: Softlink to RAS function
  310. //
  311. // Arguments: see RAS documentation
  312. //
  313. // Returns: see RAS documentation
  314. //
  315. // History: ChrisK Created 1/15/96
  316. // jmazner 9/17/96 Modified to allow calls with buffers = NULL and
  317. // InfoSizes = 0. (Based on earlier modification
  318. // to the same procedure in icwdial) See
  319. // RasGetEntryProperties docs to learn why this is
  320. // needed.
  321. //
  322. //-----------------------------------------------------------------------------
  323. DWORD RNAAPI::RasGetEntryProperties(LPCWSTR lpszPhonebook, LPCWSTR lpszEntry,
  324. LPBYTE lpbEntryInfo, LPDWORD lpdwEntryInfoSize,
  325. LPBYTE lpbDeviceInfo, LPDWORD lpdwDeviceInfoSize)
  326. {
  327. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  328. LPBYTE lpbEntryInfoPatch = NULL;
  329. LPDWORD lpdwEntryInfoPatchSize = 0;
  330. // BUGBUG: 990203 (dane) Changed WINVER != 0x400 to WINVER < 0x400 so code
  331. // would compile for Whistler. This has the potential for causing many
  332. // problems. Per ChrisK this code was hand tuned for WINVER == 0x400 and
  333. // is very fragile. If something is failing in regard to modems, RAS,
  334. // ISPs, etc. LOOK HERE FIRST.
  335. //
  336. #if defined(_REMOVE_) // What is the significance of this? Can it be changed to (WINVER < 0x400)?
  337. #if (WINVER != 0x400)
  338. #error This was built with WINVER not equal to 0x400. The size of RASENTRY may not be valid.
  339. #endif
  340. #endif // _REMOVE_
  341. #if (WINVER < 0x400)
  342. #error This was built with WINVER less than 0x400. The size of RASENTRY may not be valid.
  343. #endif
  344. if( (NULL == lpbEntryInfo) && (NULL == lpbDeviceInfo) )
  345. {
  346. ////////Assert( NULL != lpdwEntryInfoSize );
  347. //////Assert( NULL != lpdwDeviceInfoSize );
  348. //////Assert( 0 == *lpdwEntryInfoSize );
  349. //////Assert( 0 == *lpdwDeviceInfoSize );
  350. // we're here to ask RAS what size these buffers need to be, don't use the patch stuff
  351. // (see RasGetEntryProperties docs)
  352. lpbEntryInfoPatch = lpbEntryInfo;
  353. lpdwEntryInfoPatchSize = lpdwEntryInfoSize;
  354. }
  355. else
  356. {
  357. //////Assert((*lpdwEntryInfoSize) >= sizeof(RASENTRY));
  358. //////Assert(lpbEntryInfo && lpdwEntryInfoSize);
  359. //
  360. // We are going to fake out RasGetEntryProperties by creating a slightly larger
  361. // temporary buffer and copying the data in and out.
  362. //
  363. lpdwEntryInfoPatchSize = (LPDWORD) GlobalAlloc(GPTR, sizeof(DWORD));
  364. if (NULL == lpdwEntryInfoPatchSize)
  365. return ERROR_NOT_ENOUGH_MEMORY;
  366. *lpdwEntryInfoPatchSize = (*lpdwEntryInfoSize) + RASENTRY_SIZE_PATCH;
  367. lpbEntryInfoPatch = (LPBYTE)GlobalAlloc(GPTR, *lpdwEntryInfoPatchSize);
  368. if (NULL == lpbEntryInfoPatch)
  369. return ERROR_NOT_ENOUGH_MEMORY;
  370. // RAS expects the dwSize field to contain the size of the LPRASENTRY struct
  371. // (used to check which version of the struct we're using) rather than the amount
  372. // of memory actually allocated to the pointer.
  373. //((LPRASENTRY)lpbEntryInfoPatch)->dwSize = dwEntryInfoPatch;
  374. ((LPRASENTRY)lpbEntryInfoPatch)->dwSize = sizeof(RASENTRY);
  375. }
  376. // Look for the API if we haven't already found it
  377. LoadApi(cszRasGetEntryProperties, (FARPROC*)&m_fnRasGetEntryProperties);
  378. if (m_fnRasGetEntryProperties)
  379. dwRet = (*m_fnRasGetEntryProperties) (lpszPhonebook, lpszEntry,
  380. lpbEntryInfoPatch, lpdwEntryInfoPatchSize,
  381. lpbDeviceInfo, lpdwDeviceInfoSize);
  382. //TraceMsg(TF_RNAAPI, L"ICWHELP: RasGetEntryProperties returned %lu\r\n", dwRet);
  383. if( NULL != lpbEntryInfo )
  384. {
  385. //
  386. // Copy out the contents of the temporary buffer UP TO the size of the original buffer
  387. //
  388. //////Assert(lpbEntryInfoPatch);
  389. memcpy(lpbEntryInfo, lpbEntryInfoPatch,*lpdwEntryInfoSize);
  390. GlobalFree(lpbEntryInfoPatch);
  391. lpbEntryInfoPatch = NULL;
  392. if( lpdwEntryInfoPatchSize )
  393. {
  394. GlobalFree( lpdwEntryInfoPatchSize );
  395. lpdwEntryInfoPatchSize = NULL;
  396. }
  397. //
  398. // We are again faking Ras functionality here by over writing the size value;
  399. // This is neccesary due to a bug in the NT implementation of RasSetEntryProperties
  400. *lpdwEntryInfoSize = sizeof(RASENTRY);
  401. }
  402. return dwRet;
  403. }
  404. //+----------------------------------------------------------------------------
  405. //
  406. // Function: RNAAPI::RasDeleteEntry
  407. //
  408. // Synopsis: Softlink to RAS function
  409. //
  410. // Arguments: see RAS documentation
  411. //
  412. // Returns: see RAS documentation
  413. //
  414. // History: ChrisK Created 1/15/96
  415. //
  416. //-----------------------------------------------------------------------------
  417. DWORD RNAAPI::RasDeleteEntry(LPWSTR lpszPhonebook, LPWSTR lpszEntry)
  418. {
  419. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  420. // Look for the API if we haven't already found it
  421. LoadApi(cszRasDeleteEntry, (FARPROC*)&m_fnRasDeleteEntry);
  422. if (m_fnRasDeleteEntry)
  423. dwRet = (*m_fnRasDeleteEntry) (lpszPhonebook, lpszEntry);
  424. return dwRet;
  425. }
  426. //+----------------------------------------------------------------------------
  427. //
  428. // Function: RNAAPI::RasHangUp
  429. //
  430. // Synopsis: Softlink to RAS function
  431. //
  432. // Arguments: see RAS documentation
  433. //
  434. // Returns: see RAS documentation
  435. //
  436. // History: ChrisK Created 1/15/96
  437. //
  438. //-----------------------------------------------------------------------------
  439. DWORD RNAAPI::RasHangUp(HRASCONN hrasconn)
  440. {
  441. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  442. // Look for the API if we haven't already found it
  443. LoadApi(cszRasHangUp, (FARPROC*)&m_fnRasHangUp);
  444. if (m_fnRasHangUp)
  445. {
  446. dwRet = (*m_fnRasHangUp) (hrasconn);
  447. Sleep(3000);
  448. }
  449. return dwRet;
  450. }
  451. // ############################################################################
  452. DWORD RNAAPI::RasDial(LPRASDIALEXTENSIONS lpRasDialExtensions, LPWSTR lpszPhonebook,
  453. LPRASDIALPARAMS lpRasDialParams, DWORD dwNotifierType,
  454. LPVOID lpvNotifier, LPHRASCONN lphRasConn)
  455. {
  456. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  457. // Look for the API if we haven't already found it
  458. LoadApi(cszRasDial, (FARPROC*)&m_fnRasDial);
  459. if (m_fnRasDial)
  460. {
  461. dwRet = (*m_fnRasDial) (lpRasDialExtensions, lpszPhonebook,lpRasDialParams,
  462. dwNotifierType, lpvNotifier,lphRasConn);
  463. }
  464. return dwRet;
  465. }
  466. // ############################################################################
  467. DWORD RNAAPI::RasEnumConnections(LPRASCONN lprasconn, LPDWORD lpcb,LPDWORD lpcConnections)
  468. {
  469. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  470. // Look for the API if we haven't already found it
  471. LoadApi(cszRasEnumConnections, (FARPROC*)&m_fnRasEnumConnections);
  472. if (m_fnRasEnumConnections)
  473. {
  474. dwRet = (*m_fnRasEnumConnections) (lprasconn, lpcb,lpcConnections);
  475. }
  476. return dwRet;
  477. }
  478. // ############################################################################
  479. DWORD RNAAPI::RasGetEntryDialParams(LPCWSTR lpszPhonebook, LPRASDIALPARAMS lprasdialparams,
  480. LPBOOL lpfPassword)
  481. {
  482. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  483. // Look for the API if we haven't already found it
  484. LoadApi(cszRasGetEntryDialParams, (FARPROC*)&m_fnRasGetEntryDialParams);
  485. if (m_fnRasGetEntryDialParams)
  486. {
  487. dwRet = (*m_fnRasGetEntryDialParams) (lpszPhonebook, lprasdialparams,lpfPassword);
  488. }
  489. return dwRet;
  490. }
  491. //+----------------------------------------------------------------------------
  492. //
  493. // Function: RNAAPI::RasGetCountryInfo
  494. //
  495. // Synopsis: Softlink to RAS function
  496. //
  497. // Arguments: see RAS documentation
  498. //
  499. // Returns: see RAS documentation
  500. //
  501. // History: ChrisK Created 8/16/96
  502. //
  503. //-----------------------------------------------------------------------------
  504. DWORD RNAAPI::RasGetCountryInfo(LPRASCTRYINFO lprci, LPDWORD lpdwSize)
  505. {
  506. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  507. // Look for the API if we haven't already found it
  508. LoadApi(cszRasGetCountryInfo, (FARPROC*)&m_fnRasGetCountryInfo);
  509. if (m_fnRasGetCountryInfo)
  510. {
  511. dwRet = (*m_fnRasGetCountryInfo) (lprci, lpdwSize);
  512. }
  513. return dwRet;
  514. }
  515. //+----------------------------------------------------------------------------
  516. //
  517. // Function: RNAAPI::RasSetEntryDialParams
  518. //
  519. // Synopsis: Softlink to RAS function
  520. //
  521. // Arguments: see RAS documentation
  522. //
  523. // Returns: see RAS documentation
  524. //
  525. // History: ChrisK Created 8/20/96
  526. //
  527. //-----------------------------------------------------------------------------
  528. DWORD RNAAPI::RasSetEntryDialParams(LPCWSTR lpszPhonebook, LPRASDIALPARAMS lprasdialparams,
  529. BOOL fRemovePassword)
  530. {
  531. DWORD dwRet = ERROR_DLL_NOT_FOUND;
  532. // Look for the API if we haven't already found it
  533. LoadApi(cszRasSetEntryDialParams, (FARPROC*)&m_fnRasSetEntryDialParams);
  534. if (m_fnRasSetEntryDialParams)
  535. {
  536. dwRet = (*m_fnRasSetEntryDialParams) (lpszPhonebook, lprasdialparams,
  537. fRemovePassword);
  538. }
  539. return dwRet;
  540. }
  541. /*******************************************************************
  542. NAME: CreateConnectoid
  543. SYNOPSIS: Creates a connectoid (phone book entry) with specified
  544. name and phone number
  545. ENTRY: pszConnectionName - name for the new connectoid
  546. pszUserName - optional. If non-NULL, this will be set for the
  547. user name in new connectoid
  548. pszPassword - optional. If non-NULL, this will be set for the
  549. password in new connectoid
  550. EXIT: returns ERROR_SUCCESS if successful, or an RNA error code
  551. HISTORY:
  552. 96/02/26 markdu Moved ClearConnectoidIPParams functionality
  553. into CreateConnectoid
  554. ********************************************************************/
  555. DWORD RNAAPI::CreateConnectoid(LPCWSTR pszPhonebook, LPCWSTR pszConnectionName,
  556. LPRASENTRY lpRasEntry, LPCWSTR pszUserName, LPCWSTR pszPassword, LPBYTE lpDeviceInfo, LPDWORD lpdwDeviceInfoSize)
  557. {
  558. //DEBUGMSG(L"rnacall.c::CreateConnectoid()");
  559. DWORD dwRet;
  560. ////Assert(pszConnectionName);
  561. // if we don't have a valid RasEntry, bail
  562. if ((NULL == lpRasEntry) || (sizeof(RASENTRY) != lpRasEntry->dwSize))
  563. {
  564. return ERROR_INVALID_PARAMETER;
  565. }
  566. // Enumerate the modems.
  567. if (m_pEnumModem)
  568. {
  569. // Re-enumerate the modems to be sure we have the most recent changes
  570. dwRet = m_pEnumModem->ReInit();
  571. }
  572. else
  573. {
  574. // The object does not exist, so create it.
  575. m_pEnumModem = new CEnumModem;
  576. if (m_pEnumModem)
  577. {
  578. dwRet = m_pEnumModem->GetError();
  579. }
  580. else
  581. {
  582. dwRet = ERROR_NOT_ENOUGH_MEMORY;
  583. }
  584. }
  585. if (ERROR_SUCCESS != dwRet)
  586. {
  587. return dwRet;
  588. }
  589. // Make sure there is at least one device
  590. if (0 == m_pEnumModem->GetNumDevices())
  591. {
  592. return ERROR_DEVICE_DOES_NOT_EXIST;
  593. }
  594. // Validate the device if possible
  595. if (lstrlen(lpRasEntry->szDeviceName) && lstrlen(lpRasEntry->szDeviceType))
  596. {
  597. // Verify that there is a device with the given name and type
  598. if (!m_pEnumModem->VerifyDeviceNameAndType(lpRasEntry->szDeviceName,
  599. lpRasEntry->szDeviceType))
  600. {
  601. // There was no device that matched both name and type,
  602. // so try to get the first device with matching name.
  603. LPWSTR szDeviceType =
  604. m_pEnumModem->GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  605. if (szDeviceType)
  606. {
  607. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  608. }
  609. else
  610. {
  611. // There was no device that matched the given name,
  612. // so try to get the first device with matching type.
  613. // If this fails, fall through to recovery case below.
  614. LPWSTR szDeviceName =
  615. m_pEnumModem->GetDeviceNameFromType(lpRasEntry->szDeviceType);
  616. if (szDeviceName)
  617. {
  618. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  619. }
  620. else
  621. {
  622. // There was no device that matched the given name OR
  623. // the given type. Reset the values so they will be
  624. // replaced with the first device.
  625. lpRasEntry->szDeviceName[0] = L'\0';
  626. lpRasEntry->szDeviceType[0] = L'\0';
  627. }
  628. }
  629. }
  630. }
  631. else if (lstrlen(lpRasEntry->szDeviceName))
  632. {
  633. // Only the name was given. Try to find a matching type.
  634. // If this fails, fall through to recovery case below.
  635. LPWSTR szDeviceType =
  636. m_pEnumModem->GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  637. if (szDeviceType)
  638. {
  639. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  640. }
  641. }
  642. else if (lstrlen(lpRasEntry->szDeviceType))
  643. {
  644. // Only the type was given. Try to find a matching name.
  645. // If this fails, fall through to recovery case below.
  646. LPWSTR szDeviceName =
  647. m_pEnumModem->GetDeviceNameFromType(lpRasEntry->szDeviceType);
  648. if (szDeviceName)
  649. {
  650. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  651. }
  652. }
  653. // If either name or type is missing, just get first device.
  654. // Since we already verified that there was at least one device,
  655. // we can assume that this will succeed.
  656. if(!lstrlen(lpRasEntry->szDeviceName) ||
  657. !lstrlen(lpRasEntry->szDeviceType))
  658. {
  659. LPWSTR szDeviceName = m_pEnumModem->GetDeviceNameFromType(RASDT_Modem);
  660. if (NULL != szDeviceName)
  661. {
  662. lstrcpyn(lpRasEntry->szDeviceType, RASDT_Modem, RAS_MaxDeviceType);
  663. lstrcpyn(lpRasEntry->szDeviceName, szDeviceName, RAS_MaxDeviceName);
  664. }
  665. else
  666. {
  667. return ERROR_INETCFG_UNKNOWN;
  668. }
  669. }
  670. lpRasEntry->dwType = EntryTypeFromDeviceType(lpRasEntry->szDeviceType);
  671. // Verify the connectoid name
  672. dwRet = RasValidateEntryName(pszPhonebook, pszConnectionName);
  673. if ((ERROR_SUCCESS != dwRet) &&
  674. (ERROR_ALREADY_EXISTS != dwRet))
  675. {
  676. //DEBUGMSG(L"RasValidateEntryName returned %lu", dwRet);
  677. return dwRet;
  678. }
  679. // 96/04/07 markdu NASH BUG 15645
  680. // If there is no area code string, and RASEO_UseCountryAndAreaCodes is not
  681. // set, then the area code will be ignored so put in a default otherwise the
  682. // call to RasSetEntryProperties will fail due to an RNA bug.
  683. // if RASEO_UseCountryAndAreaCodes is set, then area code is required, so not
  684. // having one is an error. Let RNA report the error.
  685. if (!lstrlen(lpRasEntry->szAreaCode) &&
  686. !(lpRasEntry->dwfOptions & RASEO_UseCountryAndAreaCodes))
  687. {
  688. lstrcpy (lpRasEntry->szAreaCode, szDefaultAreaCode);
  689. }
  690. lpRasEntry->dwfOptions |= RASEO_ModemLights;
  691. // 96/05/14 markdu NASH BUG 22730 Work around RNA bug. Flags for terminal
  692. // settings are swapped by RasSetEntryproperties, so we swap them before
  693. // the call.
  694. /*if (IsWin95())
  695. SwapDWBits(&lpRasEntry->dwfOptions, RASEO_TerminalBeforeDial,
  696. RASEO_TerminalAfterDial);*/
  697. // call RNA to create the connectoid
  698. ////Assert(lpRasSetEntryProperties);
  699. dwRet = RasSetEntryProperties(pszPhonebook, pszConnectionName,
  700. (LPBYTE)lpRasEntry, sizeof(RASENTRY), NULL, 0);
  701. // 96/05/14 markdu NASH BUG 22730 Work around RNA bug. Put the bits back
  702. // to the way they were originally,
  703. /*if (IsWin95())
  704. SwapDWBits(&lpRasEntry->dwfOptions, RASEO_TerminalBeforeDial,
  705. RASEO_TerminalAfterDial);*/
  706. // populate the connectoid with user's account name and password.
  707. if (dwRet == ERROR_SUCCESS)
  708. {
  709. if (pszUserName || pszPassword)
  710. {
  711. dwRet = SetConnectoidUsername(pszPhonebook, pszConnectionName,
  712. pszUserName, pszPassword);
  713. }
  714. }
  715. // RAS ATM (PPPOA) Integration: We have to set auxillary device properties!
  716. if ( !lstrcmpi(lpRasEntry->szDeviceType, RASDT_Atm) ) {
  717. if ( (lpDeviceInfo != 0) && (lpdwDeviceInfoSize != 0) && (*lpdwDeviceInfoSize > 0) )
  718. {
  719. LPATMPBCONFIG lpAtmConfig = (LPATMPBCONFIG) lpDeviceInfo;
  720. LPBYTE lpBuffer = 0;
  721. DWORD dwBufSize = 0;
  722. DWORD dwRasEntrySize = sizeof(RASENTRY);
  723. if (!m_fnRasSetEntryProperties)
  724. LoadApi(cszRasSetEntryProperties, (FARPROC*)&m_fnRasSetEntryProperties);
  725. if (!m_fnRasGetEntryProperties)
  726. LoadApi(cszRasGetEntryProperties, (FARPROC*)&m_fnRasGetEntryProperties);
  727. if (m_fnRasGetEntryProperties)
  728. {
  729. if (!(*m_fnRasGetEntryProperties)(pszPhonebook, pszConnectionName, (LPBYTE)lpRasEntry, &dwRasEntrySize, 0, &dwBufSize))
  730. {
  731. if ( dwBufSize )
  732. {
  733. if ( !(lpBuffer = (LPBYTE) malloc ( dwBufSize ) ))
  734. {
  735. return ERROR_NOT_ENOUGH_MEMORY;
  736. }
  737. else
  738. {
  739. memset ( lpBuffer, 0, dwBufSize );
  740. }
  741. if (!( (*m_fnRasGetEntryProperties) (pszPhonebook, pszConnectionName, (LPBYTE)lpRasEntry, &dwRasEntrySize, lpBuffer, &dwBufSize) ))
  742. {
  743. // buffer is now available. we now update its content.
  744. LPWANPBCONFIG lpw = (LPWANPBCONFIG) lpBuffer;
  745. assert ( lpw->cbDeviceSize == sizeof (ATMPBCONFIG) );
  746. assert ( lpw->cbVendorSize == sizeof (ATMPBCONFIG) );
  747. assert ( lpw->cbTotalSize <= dwBufSize );
  748. memcpy ( lpBuffer+(lpw->dwDeviceOffset), lpDeviceInfo, sizeof(ATMPBCONFIG) );
  749. memcpy ( lpBuffer+(lpw->dwVendorOffset), lpDeviceInfo, sizeof(ATMPBCONFIG) );
  750. if ( m_fnRasSetEntryProperties )
  751. {
  752. (*m_fnRasSetEntryProperties)(pszPhonebook, pszConnectionName, (LPBYTE)lpRasEntry, sizeof(RASENTRY), lpBuffer, dwBufSize);
  753. }
  754. else
  755. {
  756. // free (lpBuffer);
  757. // report error?
  758. }
  759. }
  760. free (lpBuffer);
  761. lpBuffer = NULL;
  762. }
  763. }
  764. }
  765. }
  766. }
  767. #ifndef _NT_ // BUGBUG: Should this be in Whistler?
  768. if (dwRet == ERROR_SUCCESS)
  769. {
  770. // We don't use auto discovery for referral and signup connectoid
  771. if (!m_bUseAutoProxyforConnectoid)
  772. {
  773. // VYUNG 12/16/1998
  774. // REMOVE AUTO DISCOVERY FROM THE DIALUP CONNECTOID
  775. INTERNET_PER_CONN_OPTION_LIST list;
  776. DWORD dwBufSize = sizeof(list);
  777. // fill out list struct
  778. list.dwSize = sizeof(list);
  779. WCHAR szConnectoid [RAS_MaxEntryName];
  780. lstrcpyn(szConnectoid, pszConnectionName, lstrlen(pszConnectionName)+1);
  781. list.pszConnection = szConnectoid;
  782. list.dwOptionCount = 1; // one option
  783. list.pOptions = new INTERNET_PER_CONN_OPTION[1];
  784. if(list.pOptions)
  785. {
  786. // set flags
  787. list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
  788. list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT; // no proxy, autoconfig url, or autodiscovery
  789. // tell wininet
  790. HINSTANCE hInst = NULL;
  791. FARPROC fpInternetSetOption = NULL;
  792. dwRet = ERROR_SUCCESS;
  793. hInst = LoadLibrary(cszWininet);
  794. if (hInst)
  795. {
  796. fpInternetSetOption = GetProcAddress(hInst, cszInternetSetOption);
  797. if (fpInternetSetOption)
  798. {
  799. if( !((INTERNETSETOPTION)fpInternetSetOption) (NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize) )
  800. {
  801. dwRet = GetLastError();
  802. //DEBUGMSG("INETCFG export.c::InetSetAutodial() InternetSetOption failed");
  803. }
  804. }
  805. else
  806. dwRet = GetLastError();
  807. FreeLibrary(hInst);
  808. }
  809. delete [] list.pOptions;
  810. }
  811. }
  812. }
  813. #endif //_NT_
  814. return dwRet;
  815. }
  816. /*******************************************************************
  817. NAME: SetConnectoidUsername
  818. SYNOPSIS: Set the username and password strings for the phonebook
  819. entry name specified.
  820. The RASCM_DefaultCreds bit makes this entry available to all users.
  821. ENTRY: pszConnectoidName - phonebook entry name
  822. pszUserName - string with user name
  823. pszPassword - string with password
  824. EXIT: Return value of GetEntryDialParams or SetEntryDialParams
  825. ********************************************************************/
  826. DWORD RNAAPI::SetConnectoidUsername(
  827. LPCWSTR pszPhonebook,
  828. LPCWSTR pszConnectoidName,
  829. LPCWSTR pszUserName,
  830. LPCWSTR pszPassword
  831. )
  832. {
  833. DWORD dwRet = ERROR_SUCCESS;
  834. TRACE(L"rnacall.c::SetConnectoidUsername()");
  835. MYASSERT(pszConnectoidName);
  836. FARPROC fp = GetProcAddress(m_hInst, cszRasSetCredentials);
  837. if (fp)
  838. {
  839. // fill in credential structure
  840. RASCREDENTIALS rascred;
  841. ZeroMemory(&rascred, sizeof(rascred));
  842. rascred.dwSize = sizeof(rascred);
  843. rascred.dwMask = RASCM_UserName
  844. | RASCM_Password
  845. | RASCM_Domain
  846. | RASCM_DefaultCreds;
  847. lstrcpyn(rascred.szUserName, pszUserName,UNLEN);
  848. lstrcpyn(rascred.szPassword, pszPassword,PWLEN);
  849. lstrcpyn(rascred.szDomain, L"",DNLEN);
  850. dwRet = ((RASSETCREDENTIALS)fp)(NULL,
  851. (LPWSTR)pszConnectoidName,
  852. &rascred,
  853. FALSE
  854. );
  855. TRACE1(L"RasSetCredentials returned, %lu", dwRet);
  856. }
  857. else
  858. {
  859. TRACE(L"RasSetCredentials api not found.");
  860. }
  861. return dwRet;
  862. }
  863. //*******************************************************************
  864. //
  865. // FUNCTION: InetConfigClientEx
  866. //
  867. // PURPOSE: This function requires a valid phone book entry name
  868. // (unless it is being used just to set the client info).
  869. // If lpRasEntry points to a valid RASENTRY struct, the phone
  870. // book entry will be created (or updated if it already exists)
  871. // with the data in the struct.
  872. // If username and password are given, these
  873. // will be set as the dial params for the phone book entry.
  874. // If a client info struct is given, that data will be set.
  875. // Any files (ie TCP and RNA) that are needed will be
  876. // installed by calling InetConfigSystem().
  877. // This function will also perform verification on the device
  878. // specified in the RASENTRY struct. If no device is specified,
  879. // the user will be prompted to install one if there are none
  880. // installed, or they will be prompted to choose one if there
  881. // is more than one installed.
  882. //
  883. // PARAMETERS: hwndParent - window handle of calling application. This
  884. // handle will be used as the parent for any dialogs that
  885. // are required for error messages or the "installing files"
  886. // dialog.
  887. // lpszPhonebook - name of phone book to store the entry in
  888. // lpszEntryName - name of phone book entry to be
  889. // created or modified
  890. // lpRasEntry - specifies a RASENTRY struct that contains
  891. // the phone book entry data for the entry lpszEntryName
  892. // lpszUsername - username to associate with the phone book entry
  893. // lpszPassword - password to associate with the phone book entry
  894. // lpszProfileName - Name of client info profile to
  895. // retrieve. If this is NULL, the default profile is used.
  896. // lpINetClientInfo - client information
  897. // dwfOptions - a combination of INETCFG_ flags that controls
  898. // the installation and configuration as follows:
  899. //
  900. // INETCFG_INSTALLMAIL - install exchange and internet mail
  901. // INETCFG_INSTALLMODEM - Invoke InstallModem wizard if NO
  902. // MODEM IS INSTALLED. Note that if
  903. // no modem is installed and this flag
  904. // is not set, the function will fail
  905. // INETCFG_INSTALLRNA - install RNA (if needed)
  906. // INETCFG_INSTALLTCP - install TCP/IP (if needed)
  907. // INETCFG_CONNECTOVERLAN - connecting with LAN (vs modem)
  908. // INETCFG_SETASAUTODIAL - Set the phone book entry for autodial
  909. // INETCFG_OVERWRITEENTRY - Overwrite the phone book entry if it
  910. // exists. Note: if this flag is not
  911. // set, and the entry exists, a unique
  912. // name will be created for the entry.
  913. // INETCFG_WARNIFSHARINGBOUND - Check if TCP/IP file sharing is
  914. // turned on, and warn user to turn
  915. // it off. Reboot is required if
  916. // the user turns it off.
  917. // INETCFG_REMOVEIFSHARINGBOUND - Check if TCP/IP file sharing is
  918. // turned on, and force user to turn
  919. // it off. If user does not want to
  920. // turn it off, return will be
  921. // ERROR_CANCELLED. Reboot is
  922. // required if the user turns it off.
  923. //
  924. // lpfNeedsRestart - if non-NULL, then on return, this will be
  925. // TRUE if windows must be restarted to complete the installation.
  926. //
  927. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  928. //
  929. // HISTORY:
  930. // 96/03/11 markdu Created.
  931. //
  932. //*******************************************************************
  933. HRESULT RNAAPI::InetConfigClientEx(
  934. HWND hwndParent,
  935. LPCWSTR lpszPhonebook,
  936. LPCWSTR lpszEntryName,
  937. LPRASENTRY lpRasEntry,
  938. LPCWSTR lpszUsername,
  939. LPCWSTR lpszPassword,
  940. LPCWSTR lpszProfileName,
  941. LPINETCLIENTINFO lpINetClientInfo,
  942. DWORD dwfOptions,
  943. LPBOOL lpfNeedsRestart,
  944. LPWSTR szConnectoidName,
  945. DWORD dwSizeOfCreatedEntryName,
  946. LPBYTE lpDeviceInfo,
  947. LPDWORD lpdwDeviceInfoSize)
  948. {
  949. BOOL fNeedsRestart = FALSE; // Default to no reboot needed
  950. HWND hwndWaitDlg = NULL;
  951. DWORD dwRet = ERROR_SUCCESS;
  952. //DEBUGMSG(L"export.c::InetConfigClient()");
  953. // Install files if needed.
  954. // Note: the parent hwnd is validated in InetConfigSystem
  955. // We must also mask out the InstallModem flag since we want to
  956. // do that here, not in InetConfigSystem
  957. /*
  958. DWORD dwRet = InetConfigSystem(hwndParent,
  959. dwfOptions & ~INETCFG_INSTALLMODEM, &fNeedsRestart);
  960. if (ERROR_SUCCESS != dwRet)
  961. {
  962. return dwRet;
  963. }*/
  964. if (dwSizeOfCreatedEntryName < MAX_ISP_NAME + 1)
  965. {
  966. return E_FAIL;
  967. }
  968. // Make sure we have a connectoid name
  969. if (lpszEntryName && lstrlen(lpszEntryName))
  970. {
  971. // Copy the name into a private buffer in case we have
  972. // to muck around with it
  973. lstrcpyn(szConnectoidName, lpszEntryName, dwSizeOfCreatedEntryName);
  974. // Make sure the name is valid.
  975. dwRet = RasValidateEntryName(lpszPhonebook, szConnectoidName);
  976. if ((ERROR_SUCCESS == dwRet) ||
  977. (ERROR_ALREADY_EXISTS == dwRet))
  978. {
  979. // Find out if we can overwrite an existing connectoid
  980. if (!(dwfOptions & INETCFG_OVERWRITEENTRY) && (ERROR_ALREADY_EXISTS == dwRet))
  981. {
  982. WCHAR szConnectoidNameBase[MAX_ISP_NAME + 1];
  983. // Create a base string that is truncated to leave room for a space
  984. // and a 3-digit number to be appended. So, the buffer size will be
  985. // MAX_ISP_NAME + 1 - (LEN_APPEND_INT + 1)
  986. lstrcpyn(szConnectoidNameBase, szConnectoidName,
  987. MAX_ISP_NAME - LEN_APPEND_INT);
  988. // If the entry exists, we have to create a unique name
  989. int nSuffix = 2;
  990. while ((ERROR_ALREADY_EXISTS == dwRet) && (nSuffix < MAX_APPEND_INT))
  991. {
  992. // Add the integer to the end of the base string and then bump it
  993. wsprintf(szConnectoidName, szFmtAppendIntToString,
  994. szConnectoidNameBase, nSuffix++);
  995. // Validate this new name
  996. dwRet = RasValidateEntryName(lpszPhonebook, szConnectoidName);
  997. }
  998. // If we could not create a unique name, bail
  999. // Note that dwRet should still be ERROR_ALREADY_EXISTS in this case
  1000. if (nSuffix >= MAX_APPEND_INT)
  1001. {
  1002. return dwRet;
  1003. }
  1004. }
  1005. if (lpRasEntry && lpRasEntry->dwSize == sizeof(RASENTRY))
  1006. {
  1007. // For NT 5 and greater, File sharing is disabled per connectoid by setting this RAS option.
  1008. //if (TRUE == IsNT5())
  1009. //{
  1010. // lpRasEntry->dwfOptions |= RASEO_SecureLocalFiles;
  1011. //}
  1012. // Create a connectoid with given properties
  1013. dwRet = MakeConnectoid(hwndParent, dwfOptions, lpszPhonebook,
  1014. szConnectoidName, lpRasEntry, lpszUsername, lpszPassword, &fNeedsRestart, lpDeviceInfo, lpdwDeviceInfoSize);
  1015. }
  1016. else if ((lpszUsername && lstrlen(lpszUsername)) ||
  1017. (lpszPassword && lstrlen(lpszPassword)))
  1018. {
  1019. // If we created a connectoid, we already updated the dial params
  1020. // with the user name and password. However, if we didn't create a
  1021. // connectoid we still may need to update dial params of an existing one
  1022. // Update the dial params for the given connectoid.
  1023. dwRet = SetConnectoidUsername(lpszPhonebook, szConnectoidName,
  1024. lpszUsername, lpszPassword);
  1025. }
  1026. // If the connectoid was created/updated successfully, see
  1027. // if it is supposed to be set as the autodial connectoid.
  1028. if ((ERROR_SUCCESS == dwRet) && (dwfOptions & INETCFG_SETASAUTODIAL))
  1029. {
  1030. // dwRet = InetSetAutodial((DWORD)TRUE, szConnectoidName);
  1031. }
  1032. }
  1033. }
  1034. // Now set the client info if provided and no errors have occurred yet.
  1035. if (ERROR_SUCCESS == dwRet)
  1036. {
  1037. if (NULL != lpINetClientInfo)
  1038. {
  1039. dwRet = InetSetClientInfo(lpszProfileName, lpINetClientInfo);
  1040. if (ERROR_SUCCESS != dwRet)
  1041. {
  1042. if (NULL != hwndWaitDlg)
  1043. DestroyWindow(hwndWaitDlg);
  1044. hwndWaitDlg = NULL;
  1045. return dwRet;
  1046. }
  1047. // update IE news settings
  1048. dwRet = SetIEClientInfo(lpINetClientInfo);
  1049. if (ERROR_SUCCESS != dwRet)
  1050. {
  1051. if (NULL != hwndWaitDlg)
  1052. DestroyWindow(hwndWaitDlg);
  1053. hwndWaitDlg = NULL;
  1054. return dwRet;
  1055. }
  1056. }
  1057. // Now update the mail client if we were asked to do so.
  1058. // Note: if we got here without errors, and INETCFG_INSTALLMAIL is set,
  1059. // then mail has been installed by now.
  1060. if (dwfOptions & INETCFG_INSTALLMAIL)
  1061. {
  1062. INETCLIENTINFO INetClientInfo;
  1063. ZeroMemory(&INetClientInfo, sizeof(INETCLIENTINFO));
  1064. INetClientInfo.dwSize = sizeof(INETCLIENTINFO);
  1065. // Use a temp pointer that we can modify.
  1066. LPINETCLIENTINFO lpTmpINetClientInfo = lpINetClientInfo;
  1067. // If no client info struct was given, try to get the profile by name
  1068. if ((NULL == lpTmpINetClientInfo) && (NULL != lpszProfileName) &&
  1069. lstrlen(lpszProfileName))
  1070. {
  1071. lpTmpINetClientInfo = &INetClientInfo;
  1072. dwRet = InetGetClientInfo(lpszProfileName, lpTmpINetClientInfo);
  1073. if (ERROR_SUCCESS != dwRet)
  1074. {
  1075. if (NULL != hwndWaitDlg)
  1076. DestroyWindow(hwndWaitDlg);
  1077. hwndWaitDlg = NULL;
  1078. return dwRet;
  1079. }
  1080. }
  1081. // If we still don't have client info, we should enumerate the profiles
  1082. // If there is one profile, get it. If multiple, show UI to allow user
  1083. // to choose. If none, there is nothing to do at this point.
  1084. // For now, we don't support enumeration, so just try to get the default.
  1085. if (NULL == lpTmpINetClientInfo)
  1086. {
  1087. lpTmpINetClientInfo = &INetClientInfo;
  1088. dwRet = InetGetClientInfo(NULL, lpTmpINetClientInfo);
  1089. if (ERROR_SUCCESS != dwRet)
  1090. {
  1091. if (NULL != hwndWaitDlg)
  1092. DestroyWindow(hwndWaitDlg);
  1093. hwndWaitDlg = NULL;
  1094. return dwRet;
  1095. }
  1096. }
  1097. // If we have client info, update mail settings.
  1098. if (NULL != lpTmpINetClientInfo)
  1099. {
  1100. dwRet = UpdateMailSettings(hwndParent, lpTmpINetClientInfo, szConnectoidName);
  1101. }
  1102. }
  1103. }
  1104. // tell caller whether we need to reboot or not
  1105. if ((ERROR_SUCCESS == dwRet) && (lpfNeedsRestart))
  1106. {
  1107. *lpfNeedsRestart = fNeedsRestart;
  1108. }
  1109. if (NULL != hwndWaitDlg)
  1110. DestroyWindow(hwndWaitDlg);
  1111. hwndWaitDlg = NULL;
  1112. return dwRet;
  1113. }
  1114. //*******************************************************************
  1115. //
  1116. // FUNCTION: MakeConnectoid
  1117. //
  1118. // PURPOSE: This function will create a connectoid with the
  1119. // supplied name if lpRasEntry points to a valid RASENTRY
  1120. // struct. If username and password are given, these
  1121. // will be set as the dial params for the connectoid.
  1122. //
  1123. // PARAMETERS:
  1124. // hwndParent - window handle of calling application. This
  1125. // handle will be used as the parent for any dialogs that
  1126. // are required for error messages or the "choose modem"
  1127. // dialog.
  1128. // dwfOptions - a combination of INETCFG_ flags that controls
  1129. // the installation and configuration.
  1130. // lpszPhonebook - name of phone book to store the entry in
  1131. // lpszEntryName - name of connectoid to create/modify
  1132. // lpRasEntry - connectoid data
  1133. // lpszUsername - username to associate with connectoid
  1134. // lpszPassword - password to associate with connectoid
  1135. // lpfNeedsRestart - set to true if we need a restart. Note that
  1136. // since this is an internal helper function, we
  1137. // assume that the pointer is valid, and we don't
  1138. // initialize it (we only touch it if we are setting
  1139. // it to TRUE).
  1140. //
  1141. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  1142. //
  1143. // HISTORY:
  1144. // 96/03/12 markdu Created.
  1145. //
  1146. //*******************************************************************
  1147. DWORD RNAAPI::MakeConnectoid(
  1148. HWND hwndParent,
  1149. DWORD dwfOptions,
  1150. LPCWSTR lpszPhonebook,
  1151. LPCWSTR lpszEntryName,
  1152. LPRASENTRY lpRasEntry,
  1153. LPCWSTR lpszUsername,
  1154. LPCWSTR lpszPassword,
  1155. LPBOOL lpfNeedsRestart,
  1156. LPBYTE lpDeviceInfo,
  1157. LPDWORD lpdwDeviceInfoSize)
  1158. {
  1159. DWORD dwRet;
  1160. //ASSERT(lpfNeedsRestart);
  1161. if (dwfOptions & RASEO_UseCountryAndAreaCodes)
  1162. {
  1163. if ((0 == lpRasEntry->dwCountryCode) || (0 == lpRasEntry->dwCountryID))
  1164. return ERROR_INVALID_PARAMETER;
  1165. }
  1166. if (0 == lstrlen(lpRasEntry->szLocalPhoneNumber))
  1167. {
  1168. return ERROR_INVALID_PARAMETER;
  1169. }
  1170. // Load RNA if not already loaded since ENUM_MODEM needs it.
  1171. /*dwRet = EnsureRNALoaded();
  1172. if (ERROR_SUCCESS != dwRet)
  1173. {
  1174. return dwRet;
  1175. }*/
  1176. //
  1177. // Enumerate the modems
  1178. //
  1179. CEnumModem EnumModem;
  1180. dwRet = EnumModem.GetError();
  1181. if (ERROR_SUCCESS != dwRet)
  1182. {
  1183. return dwRet;
  1184. }
  1185. // If there are no modems, install one if requested.
  1186. if (0 == EnumModem.GetNumDevices())
  1187. {
  1188. // We have not been asked to install a modem, so there
  1189. // is nothing further we can do.
  1190. return ERROR_INVALID_PARAMETER;
  1191. /*
  1192. if (FALSE == IsNT())
  1193. {
  1194. //
  1195. // 5/22/97 jmazner Olympus #4698
  1196. // On Win95, calling RasEnumDevices launches RNAAP.EXE
  1197. // If RNAAP.EXE is running, any modems you install won't be usable
  1198. // So, nuke RNAAP.EXE before installing the modem.
  1199. //
  1200. WCHAR szWindowTitle[255] = L"\0nogood";
  1201. //
  1202. // Unload the RAS dll's before killing RNAAP, just to be safe
  1203. //
  1204. DeInitRNA();
  1205. LoadSz(IDS_RNAAP_TITLE, szWindowTitle,255);
  1206. HWND hwnd = FindWindow(szWindowTitle, NULL);
  1207. if (NULL != hwnd)
  1208. {
  1209. if (!PostMessage(hwnd, WM_CLOSE, 0, 0))
  1210. {
  1211. DEBUGMSG(L"Trying to kill RNAAP window returned getError %d", GetLastError());
  1212. }
  1213. }
  1214. }*/
  1215. }
  1216. // Validate the device if possible
  1217. if (lstrlen(lpRasEntry->szDeviceName) && lstrlen(lpRasEntry->szDeviceType))
  1218. {
  1219. // Verify that there is a device with the given name and type
  1220. if (!EnumModem.VerifyDeviceNameAndType(lpRasEntry->szDeviceName,
  1221. lpRasEntry->szDeviceType))
  1222. {
  1223. // There was no device that matched both name and type,
  1224. // so reset the strings and bring up the choose modem UI.
  1225. lpRasEntry->szDeviceName[0] = L'\0';
  1226. lpRasEntry->szDeviceType[0] = L'\0';
  1227. }
  1228. }
  1229. else if (lstrlen(lpRasEntry->szDeviceName))
  1230. {
  1231. // Only the name was given. Try to find a matching type.
  1232. // If this fails, fall through to recovery case below.
  1233. LPWSTR szDeviceType =
  1234. EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  1235. if (szDeviceType)
  1236. {
  1237. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  1238. }
  1239. }
  1240. else if (lstrlen(lpRasEntry->szDeviceType))
  1241. {
  1242. // Only the type was given. Try to find a matching name.
  1243. // If this fails, fall through to recovery case below.
  1244. LPWSTR szDeviceName =
  1245. EnumModem.GetDeviceNameFromType(lpRasEntry->szDeviceType);
  1246. if (szDeviceName)
  1247. {
  1248. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  1249. }
  1250. }
  1251. // If either name or type is missing, bring up choose modem UI if there
  1252. // are multiple devices, else just get first device.
  1253. // Since we already verified that there was at least one device,
  1254. // we can assume that this will succeed.
  1255. // If either name or type is missing at this point, fall back to the modem
  1256. // that is enumerated first. If no modem is enumerated, return an error.
  1257. //
  1258. if(!lstrlen(lpRasEntry->szDeviceName) ||
  1259. !lstrlen(lpRasEntry->szDeviceType))
  1260. {
  1261. LPWSTR szDeviceName = EnumModem.GetDeviceNameFromType(RASDT_Modem);
  1262. if (NULL != szDeviceName)
  1263. {
  1264. lstrcpyn(lpRasEntry->szDeviceType, RASDT_Modem, RAS_MaxDeviceType);
  1265. lstrcpyn(lpRasEntry->szDeviceName, szDeviceName, RAS_MaxDeviceName);
  1266. }
  1267. else
  1268. {
  1269. return ERROR_INETCFG_UNKNOWN;
  1270. }
  1271. }
  1272. // Create a connectoid with given properties
  1273. dwRet = CreateConnectoid(lpszPhonebook, lpszEntryName, lpRasEntry,
  1274. lpszUsername, lpszPassword, lpDeviceInfo, lpdwDeviceInfoSize);
  1275. return dwRet;
  1276. }
  1277. //+----------------------------------------------------------------------------
  1278. //
  1279. // Function LclSetEntryScriptPatch
  1280. //
  1281. // Synopsis Softlink to RasSetEntryPropertiesScriptPatch
  1282. //
  1283. // Arguments see RasSetEntryPropertiesScriptPatch
  1284. //
  1285. // Returns see RasSetEntryPropertiesScriptPatch
  1286. //
  1287. // Histroy 10/3/96 ChrisK Created
  1288. //
  1289. //-----------------------------------------------------------------------------
  1290. //typedef BOOL (WINAPI* LCLSETENTRYSCRIPTPATCH)(LPWSTR, LPWSTR);
  1291. /*
  1292. BOOL RNAAPI::LclSetEntryScriptPatch(LPCWSTR lpszScript, LPCWSTR lpszEntry)
  1293. {
  1294. HINSTANCE hinst = NULL;
  1295. LCLSETENTRYSCRIPTPATCH fp = NULL;
  1296. BOOL bRC = FALSE;
  1297. hinst = LoadLibrary(L"ICWDIAL.DLL");
  1298. if (hinst)
  1299. {
  1300. fp = (LCLSETENTRYSCRIPTPATCH)GetProcAddress(hinst, L"RasSetEntryPropertiesScriptPatch");
  1301. if (fp)
  1302. bRC = (fp)(lpszScript, lpszEntry);
  1303. FreeLibrary(hinst);
  1304. hinst = NULL;
  1305. fp = NULL;
  1306. }
  1307. return bRC;
  1308. }
  1309. */
  1310. //+----------------------------------------------------------------------------
  1311. //
  1312. // Function RemoveOldScriptFilenames
  1313. //
  1314. // Synopsis Given the data returned from a call to GetPrivateProfileSection
  1315. // remove any information about existing script file so that
  1316. // we can replace it with the new script information.
  1317. //
  1318. // Arguments lpszData - pointer to input data
  1319. //
  1320. // Returns TRUE - success
  1321. // lpdwSize - size of resulting data
  1322. //
  1323. // History 10/2/96 ChrisK Created
  1324. //
  1325. //-----------------------------------------------------------------------------
  1326. static BOOL RemoveOldScriptFilenames(LPWSTR lpszData, LPDWORD lpdwSize)
  1327. {
  1328. BOOL bRC = FALSE;
  1329. LPWSTR lpszTemp = lpszData;
  1330. LPWSTR lpszCopyTo = lpszData;
  1331. INT iLen = 0;
  1332. //
  1333. // Walk through list of name value pairs
  1334. //
  1335. if (!lpszData || L'\0' == lpszData[0])
  1336. goto RemoveOldScriptFilenamesExit;
  1337. while (*lpszTemp) {
  1338. if (0 != lstrcmpi(lpszTemp, cszDeviceSwitch))
  1339. {
  1340. //
  1341. // Keep pairs that don't match criteria
  1342. //
  1343. iLen = BYTES_REQUIRED_BY_SZ(lpszTemp);
  1344. if (lpszCopyTo != lpszTemp)
  1345. {
  1346. memmove(lpszCopyTo, lpszTemp, iLen+1);
  1347. }
  1348. lpszCopyTo += iLen + 1;
  1349. lpszTemp += iLen + 1;
  1350. }
  1351. else
  1352. {
  1353. //
  1354. // Skip the pair that matches and the one after that
  1355. //
  1356. lpszTemp += lstrlen(lpszTemp) + 1;
  1357. if (*lpszTemp)
  1358. lpszTemp += lstrlen(lpszTemp) + 1;
  1359. }
  1360. }
  1361. //
  1362. // Add second trailing NULL
  1363. //
  1364. *lpszCopyTo = L'\0';
  1365. //
  1366. // Return new size
  1367. // Note the size does not include the final \0
  1368. //
  1369. *lpdwSize = (DWORD)(lpszCopyTo - lpszData);
  1370. bRC = TRUE;
  1371. RemoveOldScriptFilenamesExit:
  1372. return bRC;
  1373. }
  1374. //+----------------------------------------------------------------------------
  1375. //
  1376. // Function GleanRealScriptFileName
  1377. //
  1378. // Synopsis Given a string figure out the real filename
  1379. // Due to another NT4.0 Ras bug, script filenames returned by
  1380. // RasGetEntryProperties may contain a leading garbage character
  1381. //
  1382. // Arguments lppszOut - pointer that will point to real filename
  1383. // lpszIn - points to current filename
  1384. //
  1385. // Returns TRUE - success
  1386. // *lppszOut - points to real file name, remember to free the memory
  1387. // in this variable when you are done. And don't talk with
  1388. // your mouth full - mom.
  1389. //
  1390. // History 10/2/96 ChrisK Created
  1391. //
  1392. //-----------------------------------------------------------------------------
  1393. static BOOL GleanRealScriptFileName(LPWSTR *lppszOut, LPWSTR lpszIn)
  1394. {
  1395. BOOL bRC = FALSE;
  1396. LPWSTR lpsz = NULL;
  1397. DWORD dwRet = 0;
  1398. //
  1399. // Validate parameters
  1400. //
  1401. //Assert(lppszOut && lpszIn);
  1402. if (!(lppszOut && lpszIn))
  1403. goto GleanFilenameExit;
  1404. //
  1405. // first determine if the filename is OK as is
  1406. //
  1407. dwRet = GetFileAttributes(lpszIn);
  1408. if (L'\0' != lpszIn[0] && 0xFFFFFFFF == dwRet) // Empty filename is OK
  1409. {
  1410. //
  1411. // Check for the same filename without the first character
  1412. //
  1413. lpsz = lpszIn+1;
  1414. dwRet = GetFileAttributes(lpsz);
  1415. if (0xFFFFFFFF == dwRet)
  1416. goto GleanFilenameExit;
  1417. }
  1418. else
  1419. {
  1420. lpsz = lpszIn;
  1421. }
  1422. //
  1423. // Return filename
  1424. //
  1425. *lppszOut = (LPWSTR)GlobalAlloc(GPTR, BYTES_REQUIRED_BY_SZ(lpsz));
  1426. lstrcpy(*lppszOut, lpsz);
  1427. bRC = TRUE;
  1428. GleanFilenameExit:
  1429. return bRC;
  1430. }
  1431. //+----------------------------------------------------------------------------
  1432. //
  1433. // Function IsScriptPatchNeeded
  1434. //
  1435. // Synopsis Check version to see if patch is needed
  1436. //
  1437. // Arguments lpszData - contents of section in rasphone.pbk
  1438. // lpszScript - name of script file
  1439. //
  1440. // Returns TRUE - patch is needed
  1441. //
  1442. // Histroy 10/1/96
  1443. //
  1444. //-----------------------------------------------------------------------------
  1445. static BOOL IsScriptPatchNeeded(LPWSTR lpszData, LPWSTR lpszScript)
  1446. {
  1447. BOOL bRC = FALSE;
  1448. LPWSTR lpsz = lpszData;
  1449. WCHAR szType[MAX_PATH + MAX_CHARS_IN_BUFFER(cszType) + 1];
  1450. lstrcpy(szType, cszType);
  1451. lstrcat(szType, lpszScript);
  1452. //Assert(MAX_PATH + MAX_CHARS_IN_BUFFER(cszType) +1 > lstrlen(szType));
  1453. lpsz = lpszData;
  1454. while(*lpsz)
  1455. {
  1456. if (0 == lstrcmp(lpsz, cszDeviceSwitch))
  1457. {
  1458. lpsz += lstrlen(lpsz)+1;
  1459. // if we find a DEVICE=switch statement and the script is empty
  1460. // then we'll have to patch the entry
  1461. if (0 == lpszScript[0])
  1462. bRC = TRUE;
  1463. // if we find a DEVICE=switch statement and the script is different
  1464. // then we'll have to patch the entry
  1465. else if (0 != lstrcmp(lpsz, szType))
  1466. bRC = TRUE;
  1467. // if we find a DEVICE=switch statement and the script is the same
  1468. // then we DON'T have to patch it
  1469. else
  1470. bRC = FALSE;
  1471. break; // get out of while statement
  1472. }
  1473. lpsz += lstrlen(lpsz)+1;
  1474. }
  1475. if (L'\0' == *lpsz)
  1476. {
  1477. // if we didn't find DEVICE=switch statement and the script is empty
  1478. // then we DON'T have to patch it
  1479. if (L'\0' == lpszScript[0])
  1480. bRC = FALSE;
  1481. // if we didn't find DEVICE=switch statement and the script is not
  1482. // empty the we'll have to patch it.
  1483. else
  1484. bRC = TRUE;
  1485. }
  1486. return bRC;
  1487. }
  1488. //+----------------------------------------------------------------------------
  1489. //
  1490. // Function GetRasPBKFilename
  1491. //
  1492. // Synopsis Find the Ras phone book and return the fully qualified path
  1493. // in the buffer
  1494. //
  1495. // Arguments lpBuffer - pointer to buffer
  1496. // dwSize - size of buffer (must be at least MAX_PATH)
  1497. //
  1498. // Returns TRUE - success
  1499. //
  1500. // History 10/1/96 ChrisK Created
  1501. //
  1502. //-----------------------------------------------------------------------------
  1503. static BOOL GetRasPBKFilename(LPWSTR lpBuffer, DWORD dwSize)
  1504. {
  1505. BOOL bRC = FALSE;
  1506. UINT urc = 0;
  1507. LPWSTR lpsz = NULL;
  1508. //
  1509. // Validate parameters
  1510. //
  1511. //Assert(lpBuffer && (dwSize >= MAX_PATH));
  1512. //
  1513. // Get path to system directory
  1514. //
  1515. urc = GetSystemDirectory(lpBuffer, dwSize);
  1516. if (0 == urc || urc > dwSize)
  1517. goto GetRasPBKExit;
  1518. //
  1519. // Check for trailing '\' and add \ras\rasphone.pbk to path
  1520. //
  1521. lpsz = &lpBuffer[lstrlen(lpBuffer)-1];
  1522. if (L'\\' != *lpsz)
  1523. lpsz++;
  1524. lstrcpy(lpsz, cszRasPBKFilename);
  1525. bRC = TRUE;
  1526. GetRasPBKExit:
  1527. return bRC;
  1528. }
  1529. //+----------------------------------------------------------------------------
  1530. //
  1531. // Function RasSetEntryPropertiesScriptPatch
  1532. //
  1533. // Synopsis Work around bug in NT4.0 that does not save script file names
  1534. // to RAS phone book entries
  1535. //
  1536. // Arguments lpszScript - name of script file
  1537. // lpszEntry - name of phone book entry
  1538. //
  1539. // Returns TRUE - success
  1540. //
  1541. // Histroy 10/1/96 ChrisK Created
  1542. //
  1543. //-----------------------------------------------------------------------------
  1544. BOOL WINAPI RasSetEntryPropertiesScriptPatch(LPWSTR lpszScript, LPCWSTR lpszEntry)
  1545. {
  1546. BOOL bRC = FALSE;
  1547. WCHAR szRasPBK[MAX_PATH+1];
  1548. WCHAR szData[SCRIPT_PATCH_BUFFER_SIZE];
  1549. DWORD dwrc = 0;
  1550. LPWSTR lpszTo;
  1551. LPWSTR lpszFixedFilename = NULL;
  1552. //
  1553. // Validate parameters
  1554. //
  1555. //Assert(lpszScript && lpszEntry);
  1556. //TraceMsg(TF_GENERAL, L"ICWDIAL: ScriptPatch script %s, entry %s.\r\n", lpszScript, lpszEntry);
  1557. //
  1558. // Verify and fix filename
  1559. //
  1560. if (!GleanRealScriptFileName(&lpszFixedFilename, lpszScript))
  1561. goto ScriptPatchExit;
  1562. //
  1563. // Get the path to the RAS phone book
  1564. //
  1565. if (!GetRasPBKFilename(szRasPBK, MAX_PATH+1))
  1566. goto ScriptPatchExit;
  1567. //
  1568. // Get data
  1569. //
  1570. ZeroMemory(szData, SCRIPT_PATCH_BUFFER_SIZE);
  1571. dwrc = GetPrivateProfileSection(lpszEntry, szData,SCRIPT_PATCH_BUFFER_SIZE,szRasPBK);
  1572. if (SCRIPT_PATCH_BUFFER_SIZE == (dwrc + 2))
  1573. goto ScriptPatchExit;
  1574. //
  1575. // Verify version
  1576. //
  1577. if (!IsScriptPatchNeeded(szData, lpszFixedFilename))
  1578. {
  1579. bRC = TRUE;
  1580. goto ScriptPatchExit;
  1581. }
  1582. //
  1583. // Clean up data
  1584. //
  1585. RemoveOldScriptFilenames(szData, &dwrc);
  1586. //
  1587. // Make sure there is enough space left to add new data
  1588. //
  1589. if (SCRIPT_PATCH_BUFFER_SIZE <=
  1590. (dwrc + sizeof(cszDeviceSwitch) + SIZEOF_NULL + MAX_CHARS_IN_BUFFER(cszType) + MAX_PATH))
  1591. goto ScriptPatchExit;
  1592. //
  1593. // Add data
  1594. //
  1595. if (L'\0' != lpszFixedFilename[0])
  1596. {
  1597. lpszTo = &szData[dwrc];
  1598. lstrcpy(lpszTo, cszDeviceSwitch);
  1599. lpszTo += MAX_CHARS_IN_BUFFER(cszDeviceSwitch);
  1600. lstrcpy(lpszTo, cszType);
  1601. lpszTo += MAX_CHARS_IN_BUFFER(cszType) - 1;
  1602. lstrcpy(lpszTo, lpszFixedFilename);
  1603. lpszTo += lstrlen(lpszFixedFilename) + SIZEOF_NULL;
  1604. *lpszTo = L'\0'; // extra terminating NULL
  1605. //Assert(&lpszTo[SIZEOF_NULL]<&szData[SCRIPT_PATCH_BUFFER_SIZE]);
  1606. }
  1607. //
  1608. // Write data
  1609. //
  1610. bRC = WritePrivateProfileSection(lpszEntry, szData,szRasPBK);
  1611. ScriptPatchExit:
  1612. if (lpszFixedFilename)
  1613. GlobalFree(lpszFixedFilename);
  1614. lpszFixedFilename = NULL;
  1615. //if (!bRC)
  1616. // TraceMsg(TF_GENERAL, L"ICWDIAL: ScriptPatch failed.\r\n");
  1617. return bRC;
  1618. }
  1619. //+----------------------------------------------------------------------------
  1620. //
  1621. // Function LclSetEntryScriptPatch
  1622. //
  1623. // Synopsis Softlink to RasSetEntryPropertiesScriptPatch
  1624. //
  1625. // Arguments see RasSetEntryPropertiesScriptPatch
  1626. //
  1627. // Returns see RasSetEntryPropertiesScriptPatch
  1628. //
  1629. // Histroy 10/3/96 ChrisK Created
  1630. //
  1631. //-----------------------------------------------------------------------------
  1632. typedef BOOL (WINAPI* LCLSETENTRYSCRIPTPATCH)(LPCWSTR, LPCWSTR);
  1633. BOOL LclSetEntryScriptPatch(LPWSTR lpszScript, LPCWSTR lpszEntry)
  1634. {
  1635. return RasSetEntryPropertiesScriptPatch(lpszScript, lpszEntry);
  1636. }
  1637. //*******************************************************************
  1638. //
  1639. // FUNCTION: UpdateMailSettings
  1640. //
  1641. // PURPOSE: This function will update the settings for mail in
  1642. // the profile of the user's choice.
  1643. //
  1644. // PARAMETERS: hwndParent - window handle of calling application. This
  1645. // handle will be used as the parent for any dialogs that
  1646. // are required for error messages or the "choose profile"
  1647. // dialog.
  1648. // lpINetClientInfo - client information
  1649. // lpszEntryName - name of phone book entry to be
  1650. // set for connection.
  1651. //
  1652. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  1653. //
  1654. // HISTORY:
  1655. // 96/03/26 markdu Created.
  1656. //
  1657. //*******************************************************************
  1658. HRESULT UpdateMailSettings(
  1659. HWND hwndParent,
  1660. LPINETCLIENTINFO lpINetClientInfo,
  1661. LPWSTR lpszEntryName)
  1662. {
  1663. DWORD dwRet = ERROR_SUCCESS;
  1664. MAILCONFIGINFO MailConfigInfo;
  1665. ZeroMemory(&MailConfigInfo, sizeof(MAILCONFIGINFO)); // zero out structure
  1666. // 96/04/06 markdu NASH BUG 16404
  1667. // Funcionts in mapicall.c expect us to allocate global structure
  1668. // call MAPI to set up profile and store this information in it
  1669. if (InitMAPI(NULL))
  1670. {
  1671. // structure to pass to dialog to fill out
  1672. CHOOSEPROFILEDLGINFO ChooseProfileDlgInfo;
  1673. ZeroMemory(&ChooseProfileDlgInfo, sizeof(CHOOSEPROFILEDLGINFO));
  1674. ChooseProfileDlgInfo.fSetProfileAsDefault = TRUE;
  1675. // 96/04/25 markdu NASH BUG 19572 Only show choose profile dialog
  1676. // if there are any existing profiles,
  1677. // 99/2/18 Remove multi profile dialog for OOBE
  1678. // set up a structure with mail config information
  1679. MailConfigInfo.pszEmailAddress = lpINetClientInfo->szEMailAddress;
  1680. MailConfigInfo.pszEmailServer = lpINetClientInfo->szPOPServer;
  1681. MailConfigInfo.pszEmailDisplayName = lpINetClientInfo->szEMailName;
  1682. MailConfigInfo.pszEmailAccountName = lpINetClientInfo->szPOPLogonName;
  1683. MailConfigInfo.pszEmailAccountPwd = lpINetClientInfo->szPOPLogonPassword;
  1684. MailConfigInfo.pszConnectoidName = lpszEntryName;
  1685. MailConfigInfo.fRememberPassword = TRUE;
  1686. MailConfigInfo.pszProfileName = ChooseProfileDlgInfo.szProfileName;
  1687. MailConfigInfo.fSetProfileAsDefault = ChooseProfileDlgInfo.fSetProfileAsDefault;
  1688. // BUGBUG SMTP
  1689. // set up the profile through MAPI
  1690. dwRet = SetMailProfileInformation(&MailConfigInfo);
  1691. // Hide error messages for OOBE
  1692. /*
  1693. if (ERROR_SUCCESS != dwRet)
  1694. {
  1695. DisplayErrorMessage(hwndParent, IDS_ERRConfigureMail,
  1696. (DWORD) dwRet, ERRCLS_MAPI,MB_ICONEXCLAMATION);
  1697. }*/
  1698. DeInitMAPI();
  1699. }
  1700. else
  1701. {
  1702. // an error occurred.
  1703. dwRet = GetLastError();
  1704. if (ERROR_SUCCESS == dwRet)
  1705. {
  1706. // Error occurred, but the error code was not set.
  1707. dwRet = ERROR_INETCFG_UNKNOWN;
  1708. }
  1709. }
  1710. return dwRet;
  1711. }
  1712. DWORD EntryTypeFromDeviceType(
  1713. LPCWSTR szDeviceType
  1714. )
  1715. {
  1716. DWORD dwType;
  1717. MYASSERT(
  1718. !lstrcmpi(RASDT_PPPoE, szDeviceType) ||
  1719. !lstrcmpi(RASDT_Atm, szDeviceType) ||
  1720. !lstrcmpi(RASDT_Isdn, szDeviceType) ||
  1721. !lstrcmpi(RASDT_Modem, szDeviceType)
  1722. );
  1723. if (lstrcmpi(RASDT_PPPoE, szDeviceType) == 0)
  1724. {
  1725. dwType = RASET_Broadband;
  1726. }
  1727. else
  1728. {
  1729. dwType = RASET_Phone;
  1730. }
  1731. return dwType;
  1732. }