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.

1314 lines
41 KiB

  1. // Import.cpp: implementation of the CISPImport class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "appdefs.h"
  6. #include "icwhelp.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static TCHAR THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. #pragma data_seg(".rdata")
  13. TCHAR cszEntrySection[] = TEXT("Entry");
  14. TCHAR cszEntryName[] = TEXT("Entry_Name");
  15. TCHAR cszAlias[] = TEXT("Import_Name");
  16. TCHAR cszML[] = TEXT("Multilink");
  17. TCHAR cszPhoneSection[] = TEXT("Phone");
  18. TCHAR cszDialAsIs[] = TEXT("Dial_As_Is");
  19. TCHAR cszPhone[] = TEXT("Phone_Number");
  20. TCHAR cszISDN[] = TEXT("ISDN_Number");
  21. TCHAR cszAreaCode[] = TEXT("Area_Code");
  22. TCHAR cszCountryCode[] = TEXT("Country_Code");
  23. TCHAR cszCountryID[] = TEXT("Country_ID");
  24. TCHAR cszDeviceSection[] = TEXT("Device");
  25. TCHAR cszDeviceType[] = TEXT("Type");
  26. TCHAR cszDeviceName[] = TEXT("Name");
  27. TCHAR cszDevCfgSize[] = TEXT("Settings_Size");
  28. TCHAR cszDevCfg[] = TEXT("Settings");
  29. TCHAR cszServerSection[] = TEXT("Server");
  30. TCHAR cszServerType[] = TEXT("Type");
  31. TCHAR cszSWCompress[] = TEXT("SW_Compress");
  32. TCHAR cszPWEncrypt[] = TEXT("PW_Encrypt");
  33. TCHAR cszNetLogon[] = TEXT("Network_Logon");
  34. TCHAR cszSWEncrypt[] = TEXT("SW_Encrypt");
  35. TCHAR cszNetBEUI[] = TEXT("Negotiate_NetBEUI");
  36. TCHAR cszIPX[] = TEXT("Negotiate_IPX/SPX");
  37. TCHAR cszIP[] = TEXT("Negotiate_TCP/IP");
  38. TCHAR cszDisableLcp[] = TEXT("Disable_LCP");
  39. TCHAR cszIPSection[] = TEXT("TCP/IP");
  40. TCHAR cszIPSpec[] = TEXT("Specify_IP_Address");
  41. TCHAR cszIPAddress[] = TEXT("IP_address");
  42. TCHAR cszServerSpec[] = TEXT("Specify_Server_Address");
  43. TCHAR cszDNSAddress[] = TEXT("DNS_address");
  44. TCHAR cszDNSAltAddress[] = TEXT("DNS_Alt_address");
  45. TCHAR cszWINSAddress[] = TEXT("WINS_address");
  46. TCHAR cszWINSAltAddress[]= TEXT("WINS_Alt_address");
  47. TCHAR cszIPCompress[] = TEXT("IP_Header_Compress");
  48. TCHAR cszWanPri[] = TEXT("Gateway_On_Remote");
  49. TCHAR cszMLSection[] = TEXT("Multilink");
  50. TCHAR cszLinkIndex[] = TEXT("Line_%s");
  51. TCHAR cszScriptingSection[] = TEXT("Scripting");
  52. TCHAR cszScriptName[] = TEXT("Name");
  53. TCHAR cszScriptSection[] = TEXT("Script_File");
  54. TCHAR cszYes[] = TEXT("yes");
  55. TCHAR cszNo[] = TEXT("no");
  56. TCHAR cszUserSection[] = TEXT("User");
  57. TCHAR cszUserName[] = TEXT("Name");
  58. TCHAR cszPassword[] = TEXT("Password");
  59. TCHAR szNull[] = TEXT("");
  60. TCHAR cszSupport[] = TEXT("Support");
  61. TCHAR cszSupportNumber[] = TEXT("SupportPhoneNumber");
  62. SERVER_TYPES aServerTypes[] =
  63. {
  64. {TEXT("PPP"), RASFP_Ppp, 0},
  65. {TEXT("SLIP"), RASFP_Slip, 0},
  66. {TEXT("CSLIP"), RASFP_Slip, RASEO_IpHeaderCompression},
  67. {TEXT("RAS"), RASFP_Ras, 0}
  68. };
  69. #pragma data_seg()
  70. TCHAR g_szDeviceName[RAS_MaxDeviceName + 1] = TEXT("\0"); //holds the user's modem choice when multiple
  71. TCHAR g_szDeviceType[RAS_MaxDeviceType + 1] = TEXT("\0"); // modems are installed
  72. #define ISIGNUP_KEY TEXT("Software\\Microsoft\\ISIGNUP")
  73. #define DEVICENAMEKEY TEXT("DeviceName")
  74. #define DEVICETYPEKEY TEXT("DeviceType")
  75. static const TCHAR cszInetcfg[] = TEXT("Inetcfg.dll");
  76. static const CHAR cszSetAutoProxyConnectoid[] = "SetAutoProxyConnectoid"; // Proc name. Must be ansi.
  77. typedef HRESULT (WINAPI * SETAUTOPROXYCONNECTOID) (IN BOOL bEnable);
  78. //////////////////////////////////////////////////////////////////////
  79. // Construction/Destruction
  80. //////////////////////////////////////////////////////////////////////
  81. CISPImport::CISPImport()
  82. {
  83. m_szDeviceName[0] = TEXT('\0');
  84. m_szDeviceType[0] = TEXT('\0');
  85. m_szConnectoidName[0] = TEXT('\0');
  86. m_bIsISDNDevice = FALSE;
  87. }
  88. CISPImport::~CISPImport()
  89. {
  90. // Clean up the registry
  91. DeleteUserDeviceSelection(DEVICENAMEKEY);
  92. DeleteUserDeviceSelection(DEVICETYPEKEY);
  93. }
  94. //+----------------------------------------------------------------------------
  95. // DWORD NEAR PASCAL StrToip (LPTSTR szIPAddress, LPDWORD lpdwAddr)
  96. //
  97. // This function converts a IP address string to an IP address structure.
  98. //
  99. //
  100. LPCTSTR NEAR PASCAL StrToSubip (LPCTSTR szIPAddress, LPBYTE pVal)
  101. {
  102. LPCTSTR pszIP = szIPAddress;
  103. *pVal = (BYTE)Sz2W(pszIP);
  104. // skip over digits
  105. while (FIsDigit(*pszIP))
  106. {
  107. ++pszIP;
  108. }
  109. // skip over one or more separators
  110. while (*pszIP && !FIsDigit(*pszIP))
  111. {
  112. ++pszIP;
  113. }
  114. return pszIP;
  115. }
  116. DWORD NEAR PASCAL StrToip (LPCTSTR szIPAddress, RASIPADDR FAR *ipAddr)
  117. {
  118. LPCTSTR pszIP = szIPAddress;
  119. pszIP = StrToSubip(pszIP, &ipAddr->a);
  120. pszIP = StrToSubip(pszIP, &ipAddr->b);
  121. pszIP = StrToSubip(pszIP, &ipAddr->c);
  122. pszIP = StrToSubip(pszIP, &ipAddr->d);
  123. return ERROR_SUCCESS;
  124. }
  125. //****************************************************************************
  126. // DWORD NEAR PASCAL ImportPhoneInfo(PPHONENUM ppn, LPCTSTR szFileName)
  127. //
  128. // This function imports the phone number.
  129. //
  130. // History:
  131. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  132. // Created.
  133. //****************************************************************************
  134. DWORD NEAR PASCAL ImportPhoneInfo(LPRASENTRY lpRasEntry, LPCTSTR szFileName, BOOL bISDN)
  135. {
  136. TCHAR szYesNo[MAXNAME];
  137. if (!GetPrivateProfileString(cszPhoneSection,
  138. (bISDN ? cszISDN : cszPhone),
  139. szNull,
  140. lpRasEntry->szLocalPhoneNumber,
  141. ARRAYSIZE(lpRasEntry->szLocalPhoneNumber),
  142. szFileName))
  143. {
  144. // If the ISDN_Number is empty, we read from the Phone_Number
  145. GetPrivateProfileString(cszPhoneSection,
  146. cszPhone,
  147. DUN_NOPHONENUMBER,
  148. lpRasEntry->szLocalPhoneNumber,
  149. ARRAYSIZE(lpRasEntry->szLocalPhoneNumber),
  150. szFileName);
  151. }
  152. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  153. GetPrivateProfileString(cszPhoneSection,
  154. cszDialAsIs,
  155. cszYes,
  156. szYesNo,
  157. ARRAYSIZE(szYesNo),
  158. szFileName);
  159. // Do we have to get country code and area code?
  160. //
  161. if (!lstrcmpi(szYesNo, cszNo))
  162. {
  163. // If we cannot get the country ID or it is zero, default to dial as is
  164. //
  165. if ((lpRasEntry->dwCountryID = GetPrivateProfileInt(cszPhoneSection,
  166. cszCountryID,
  167. 0,
  168. szFileName)) != 0)
  169. {
  170. lpRasEntry->dwCountryCode = GetPrivateProfileInt(cszPhoneSection,
  171. cszCountryCode,
  172. 1,
  173. szFileName);
  174. if (GetPrivateProfileString(cszPhoneSection,
  175. cszAreaCode,
  176. szNull,
  177. lpRasEntry->szAreaCode,
  178. ARRAYSIZE(lpRasEntry->szAreaCode),
  179. szFileName) != 0)
  180. {
  181. lpRasEntry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  182. }
  183. }
  184. }
  185. return ERROR_SUCCESS;
  186. }
  187. //****************************************************************************
  188. // DWORD NEAR PASCAL ImportServerInfo(PSMMINFO psmmi, LPTSTR szFileName)
  189. //
  190. // This function imports the server type name and settings.
  191. //
  192. // History:
  193. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  194. // Created.
  195. //****************************************************************************
  196. DWORD NEAR PASCAL ImportServerInfo(LPRASENTRY lpRasEntry, LPCTSTR szFileName)
  197. {
  198. TCHAR szYesNo[MAXNAME];
  199. TCHAR szType[MAXNAME];
  200. DWORD i;
  201. // Get the server type name
  202. //
  203. GetPrivateProfileString(cszServerSection,
  204. cszServerType,
  205. szNull,
  206. szType,
  207. ARRAYSIZE(szType),
  208. szFileName);
  209. // need to convert the string into
  210. // one of the following values
  211. // RASFP_Ppp
  212. // RASFP_Slip Note CSLIP is SLIP with IP compression on
  213. // RASFP_Ras
  214. for (i = 0; i < NUM_SERVER_TYPES; ++i)
  215. {
  216. if (!lstrcmpi(aServerTypes[i].szType, szType))
  217. {
  218. lpRasEntry->dwFramingProtocol = aServerTypes[i].dwType;
  219. lpRasEntry->dwfOptions |= aServerTypes[i].dwfOptions;
  220. break;
  221. }
  222. }
  223. // Get the server type settings
  224. //
  225. if (GetPrivateProfileString(cszServerSection,
  226. cszSWCompress,
  227. szNull,
  228. szYesNo,
  229. ARRAYSIZE(szYesNo),
  230. szFileName))
  231. {
  232. if (!lstrcmpi(szYesNo, cszNo))
  233. {
  234. lpRasEntry->dwfOptions &= ~RASEO_SwCompression;
  235. }
  236. else
  237. {
  238. lpRasEntry->dwfOptions |= RASEO_SwCompression;
  239. };
  240. };
  241. if (GetPrivateProfileString(cszServerSection,
  242. cszPWEncrypt,
  243. szNull,
  244. szYesNo,
  245. ARRAYSIZE(szYesNo),
  246. szFileName))
  247. {
  248. if (!lstrcmpi(szYesNo, cszNo))
  249. {
  250. lpRasEntry->dwfOptions &= ~RASEO_RequireEncryptedPw;
  251. }
  252. else
  253. {
  254. lpRasEntry->dwfOptions |= RASEO_RequireEncryptedPw;
  255. };
  256. };
  257. if (GetPrivateProfileString(cszServerSection,
  258. cszNetLogon,
  259. szNull,
  260. szYesNo,
  261. ARRAYSIZE(szYesNo),
  262. szFileName))
  263. {
  264. if (!lstrcmpi(szYesNo, cszNo))
  265. {
  266. lpRasEntry->dwfOptions &= ~RASEO_NetworkLogon;
  267. }
  268. else
  269. {
  270. lpRasEntry->dwfOptions |= RASEO_NetworkLogon;
  271. };
  272. };
  273. if (GetPrivateProfileString(cszServerSection,
  274. cszSWEncrypt,
  275. szNull,
  276. szYesNo,
  277. ARRAYSIZE(szYesNo),
  278. szFileName))
  279. {
  280. if (!lstrcmpi(szYesNo, cszNo))
  281. {
  282. lpRasEntry->dwfOptions &= ~RASEO_RequireDataEncryption;
  283. }
  284. else
  285. {
  286. lpRasEntry->dwfOptions |= RASEO_RequireDataEncryption;
  287. };
  288. };
  289. // Get the protocol settings
  290. //
  291. if (GetPrivateProfileString(cszServerSection,
  292. cszNetBEUI,
  293. szNull,
  294. szYesNo,
  295. ARRAYSIZE(szYesNo),
  296. szFileName))
  297. {
  298. if (!lstrcmpi(szYesNo, cszNo))
  299. {
  300. lpRasEntry->dwfNetProtocols &= ~RASNP_NetBEUI;
  301. }
  302. else
  303. {
  304. lpRasEntry->dwfNetProtocols |= RASNP_NetBEUI;
  305. };
  306. };
  307. if (GetPrivateProfileString(cszServerSection,
  308. cszIPX,
  309. szNull,
  310. szYesNo,
  311. ARRAYSIZE(szYesNo),
  312. szFileName))
  313. {
  314. if (!lstrcmpi(szYesNo, cszNo))
  315. {
  316. lpRasEntry->dwfNetProtocols &= ~RASNP_Ipx;
  317. }
  318. else
  319. {
  320. lpRasEntry->dwfNetProtocols |= RASNP_Ipx;
  321. };
  322. };
  323. if (GetPrivateProfileString(cszServerSection,
  324. cszIP,
  325. szNull,
  326. szYesNo,
  327. ARRAYSIZE(szYesNo),
  328. szFileName))
  329. {
  330. if (!lstrcmpi(szYesNo, cszNo))
  331. {
  332. lpRasEntry->dwfNetProtocols &= ~RASNP_Ip;
  333. }
  334. else
  335. {
  336. lpRasEntry->dwfNetProtocols |= RASNP_Ip;
  337. };
  338. };
  339. if (GetPrivateProfileString(cszServerSection,
  340. cszDisableLcp,
  341. szNull,
  342. szYesNo,
  343. ARRAYSIZE(szYesNo),
  344. szFileName))
  345. {
  346. if (!lstrcmpi(szYesNo, cszYes))
  347. {
  348. lpRasEntry->dwfOptions |= RASEO_DisableLcpExtensions;
  349. }
  350. else
  351. {
  352. lpRasEntry->dwfOptions &= ~RASEO_DisableLcpExtensions;
  353. }
  354. };
  355. return ERROR_SUCCESS;
  356. }
  357. //****************************************************************************
  358. // DWORD NEAR PASCAL ImportIPInfo(LPTSTR szEntryName, LPTSTR szFileName)
  359. //
  360. // This function imports the TCP/IP information
  361. //
  362. // History:
  363. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  364. // Created.
  365. //****************************************************************************
  366. DWORD NEAR PASCAL ImportIPInfo(LPRASENTRY lpRasEntry, LPCTSTR szFileName)
  367. {
  368. TCHAR szIPAddr[MAXIPADDRLEN];
  369. TCHAR szYesNo[MAXNAME];
  370. // Import IP address information
  371. //
  372. if (GetPrivateProfileString(cszIPSection,
  373. cszIPSpec,
  374. szNull,
  375. szYesNo,
  376. ARRAYSIZE(szYesNo),
  377. szFileName))
  378. {
  379. if (!lstrcmpi(szYesNo, cszYes))
  380. {
  381. // The import file has IP address specified, get the IP address
  382. //
  383. lpRasEntry->dwfOptions |= RASEO_SpecificIpAddr;
  384. if (GetPrivateProfileString(cszIPSection,
  385. cszIPAddress,
  386. szNull,
  387. szIPAddr,
  388. ARRAYSIZE(szIPAddr),
  389. szFileName))
  390. {
  391. StrToip (szIPAddr, &lpRasEntry->ipaddr);
  392. };
  393. }
  394. else
  395. {
  396. lpRasEntry->dwfOptions &= ~RASEO_SpecificIpAddr;
  397. };
  398. };
  399. // Import Server address information
  400. //
  401. if (GetPrivateProfileString(cszIPSection,
  402. cszServerSpec,
  403. szNull,
  404. szYesNo,
  405. ARRAYSIZE(szYesNo),
  406. szFileName))
  407. {
  408. if (!lstrcmpi(szYesNo, cszYes))
  409. {
  410. // The import file has server address specified, get the server address
  411. //
  412. lpRasEntry->dwfOptions |= RASEO_SpecificNameServers;
  413. if (GetPrivateProfileString(cszIPSection,
  414. cszDNSAddress,
  415. szNull,
  416. szIPAddr,
  417. ARRAYSIZE(szIPAddr),
  418. szFileName))
  419. {
  420. StrToip (szIPAddr, &lpRasEntry->ipaddrDns);
  421. };
  422. if (GetPrivateProfileString(cszIPSection,
  423. cszDNSAltAddress,
  424. szNull,
  425. szIPAddr,
  426. ARRAYSIZE(szIPAddr),
  427. szFileName))
  428. {
  429. StrToip (szIPAddr, &lpRasEntry->ipaddrDnsAlt);
  430. };
  431. if (GetPrivateProfileString(cszIPSection,
  432. cszWINSAddress,
  433. szNull,
  434. szIPAddr,
  435. ARRAYSIZE(szIPAddr),
  436. szFileName))
  437. {
  438. StrToip (szIPAddr, &lpRasEntry->ipaddrWins);
  439. };
  440. if (GetPrivateProfileString(cszIPSection,
  441. cszWINSAltAddress,
  442. szNull,
  443. szIPAddr,
  444. ARRAYSIZE(szIPAddr),
  445. szFileName))
  446. {
  447. StrToip (szIPAddr, &lpRasEntry->ipaddrWinsAlt);
  448. };
  449. }
  450. else
  451. {
  452. lpRasEntry->dwfOptions &= ~RASEO_SpecificNameServers;
  453. };
  454. };
  455. // Header compression and the gateway settings
  456. //
  457. if (GetPrivateProfileString(cszIPSection,
  458. cszIPCompress,
  459. szNull,
  460. szYesNo,
  461. ARRAYSIZE(szYesNo),
  462. szFileName))
  463. {
  464. if (!lstrcmpi(szYesNo, cszNo))
  465. {
  466. lpRasEntry->dwfOptions &= ~RASEO_IpHeaderCompression;
  467. }
  468. else
  469. {
  470. lpRasEntry->dwfOptions |= RASEO_IpHeaderCompression;
  471. };
  472. };
  473. if (GetPrivateProfileString(cszIPSection,
  474. cszWanPri,
  475. szNull,
  476. szYesNo,
  477. ARRAYSIZE(szYesNo),
  478. szFileName))
  479. {
  480. if (!lstrcmpi(szYesNo, cszNo))
  481. {
  482. lpRasEntry->dwfOptions &= ~RASEO_RemoteDefaultGateway;
  483. }
  484. else
  485. {
  486. lpRasEntry->dwfOptions |= RASEO_RemoteDefaultGateway;
  487. };
  488. };
  489. return ERROR_SUCCESS;
  490. }
  491. //****************************************************************************
  492. // HANDLE NEAR PASCAL CreateUniqueFile(LPTSTR szPath, LPTSTR szFile)
  493. //
  494. // This function creates a unique file. If the file already exists, it will
  495. // try to create a file with similar name and return the name.
  496. //
  497. // History:
  498. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  499. // Created.
  500. //****************************************************************************
  501. HANDLE NEAR PASCAL CreateUniqueFile(LPTSTR szPath, LPTSTR szScript)
  502. {
  503. HANDLE hFile;
  504. LPTSTR pszSuffix, lpsz;
  505. UINT uSuffix;
  506. pszSuffix = szPath + lstrlen(szPath);
  507. lpsz = CharPrev(szPath, pszSuffix);
  508. if (*lpsz != '\\')
  509. {
  510. *pszSuffix = '\\';
  511. pszSuffix++;
  512. };
  513. lstrcpy(pszSuffix, szScript);
  514. // Try the specified filename
  515. //
  516. hFile = CreateFile(szPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
  517. FILE_ATTRIBUTE_NORMAL, NULL);
  518. // If the file exists
  519. //
  520. if ((hFile == INVALID_HANDLE_VALUE) && (GetLastError() == ERROR_FILE_EXISTS))
  521. {
  522. TCHAR szNewName[MAX_PATH];
  523. // Need to copy it to another name in the same directory
  524. //
  525. if (LoadString(_Module.GetModuleInstance(), IDS_DEFAULT_SCP, szNewName, ARRAYSIZE(szNewName)))
  526. {
  527. // Increment the file index until a non-duplicated file can be created
  528. //
  529. uSuffix = 0;
  530. do
  531. {
  532. wsprintf(pszSuffix, szNewName, uSuffix);
  533. uSuffix++;
  534. hFile = CreateFile(szPath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
  535. FILE_ATTRIBUTE_NORMAL, NULL);
  536. }
  537. while ((hFile == INVALID_HANDLE_VALUE) &&
  538. (GetLastError() == ERROR_FILE_EXISTS) &&
  539. (uSuffix < 0x0000FFFF));
  540. };
  541. };
  542. // If we do not have the file, reserve the pathname
  543. //
  544. if (hFile == INVALID_HANDLE_VALUE)
  545. {
  546. *pszSuffix = '\0';
  547. };
  548. return hFile;
  549. }
  550. //****************************************************************************
  551. // HANDLE NEAR PASCAL CreateScriptFile(LPTSTR szScript, LPTSTR szImportFile)
  552. //
  553. // This function creates the script file
  554. //
  555. // History:
  556. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  557. // Created.
  558. //****************************************************************************
  559. HANDLE NEAR PASCAL CreateScriptFile(LPTSTR szScript, LPCTSTR szImportFile)
  560. {
  561. LPTSTR pszDir;
  562. DWORD cb;
  563. HANDLE hFile;
  564. // Assume failure
  565. //
  566. hFile = INVALID_HANDLE_VALUE;
  567. // Allocate a buffer for pathname
  568. //
  569. TCHAR pszPath[MAX_PATH * 2];
  570. TCHAR pszShortName[MAX_PATH * 2]; //pszShortName = pszPath+MAX_PATH;
  571. // Get the default directory
  572. //
  573. if (GetWindowsDirectory(pszPath, MAX_PATH) != 0)
  574. {
  575. // Get the Windows drive
  576. //
  577. pszDir = pszPath;
  578. while((*pszDir != '\\') && (*pszDir != '\0'))
  579. {
  580. pszDir = CharNext(pszDir);
  581. };
  582. // Did we find Windows drive?
  583. //
  584. if (*pszDir != '\0')
  585. {
  586. // Prepare the drive
  587. //
  588. cb = (DWORD)(pszDir - pszPath);
  589. MyMemCpy((LPBYTE) szScript, (const LPBYTE) pszPath, (size_t) cb);
  590. pszDir = szScript + cb;
  591. // Get the script filename
  592. //
  593. if (GetPrivateProfileString(cszScriptingSection,
  594. cszScriptName,
  595. szNull,
  596. pszShortName,
  597. MAX_PATH,
  598. szImportFile) != 0)
  599. {
  600. // Try the favorite script directory
  601. //
  602. if (LoadString(_Module.GetModuleInstance(), IDS_INI_SCRIPT_DIR, pszDir,
  603. (MAX_PATH - cb)) != 0)
  604. {
  605. // Try creating the file
  606. //
  607. hFile = CreateUniqueFile(szScript, pszShortName);
  608. };
  609. // If we do not have the file yet, try the second favorite
  610. //
  611. if (hFile == INVALID_HANDLE_VALUE)
  612. {
  613. if (LoadString(_Module.GetModuleInstance(), IDS_INI_SCRIPT_SHORTDIR, pszDir,
  614. (MAX_PATH - cb)))
  615. {
  616. // Try creating the file
  617. //
  618. hFile = CreateUniqueFile(szScript, pszShortName);
  619. };
  620. };
  621. // If we do not have the file yet, try Windows directory
  622. //
  623. if (hFile == INVALID_HANDLE_VALUE)
  624. {
  625. // Get original Windows directory
  626. //
  627. lstrcpy(szScript, pszPath);
  628. // Try one more time
  629. //
  630. hFile = CreateUniqueFile(szScript, pszShortName);
  631. };
  632. };
  633. };
  634. };
  635. return hFile;
  636. }
  637. //****************************************************************************
  638. // DWORD NEAR PASCAL ImportScriptFile(LPTSTR szEntryName, LPTSTR szImportFile)
  639. //
  640. // This function imports the script file
  641. //
  642. // History:
  643. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  644. // Created.
  645. //****************************************************************************
  646. DWORD NEAR PASCAL ImportScriptFile(LPRASENTRY lpRasEntry, LPCTSTR szImportFile)
  647. {
  648. HANDLE hfScript;
  649. LPTSTR pszLine;
  650. LPTSTR pszFile;
  651. int i, iMaxLine;
  652. UINT cbSize, cbRet;
  653. TCHAR szTmp[4];
  654. DWORD dwRet;
  655. dwRet=ERROR_SUCCESS;
  656. // If a script section does not exist, do nothing
  657. //
  658. if (GetPrivateProfileString(cszScriptingSection,
  659. cszScriptName,
  660. szNull,
  661. szTmp,
  662. 4,
  663. szImportFile) == 0)
  664. {
  665. return ERROR_SUCCESS;
  666. };
  667. // Allocate a buffer for the script lines
  668. //
  669. pszLine = new TCHAR[SIZE_ReadBuf+MAX_PATH];
  670. if (pszLine == NULL)
  671. {
  672. TraceMsg(TF_GENERAL,TEXT("CONNECT:ImportScriptFile(): Local Alloc failed\n"));
  673. return ERROR_OUTOFMEMORY;
  674. }
  675. // Look for script
  676. //
  677. if (GetPrivateProfileString(cszScriptSection,
  678. NULL,
  679. szNull,
  680. pszLine,
  681. SIZE_ReadBuf,
  682. szImportFile) != 0)
  683. {
  684. // Get the maximum line number
  685. //
  686. pszFile = pszLine;
  687. iMaxLine = -1;
  688. while (*pszFile)
  689. {
  690. i = Sz2W(pszFile);
  691. iMaxLine = max(iMaxLine, i);
  692. pszFile += lstrlen(pszFile)+1;
  693. };
  694. // If we have at least one line, we will import the script file
  695. //
  696. if (iMaxLine >= 0)
  697. {
  698. pszFile = pszLine+SIZE_ReadBuf;
  699. // Create the script file
  700. //
  701. //DebugBreak();
  702. hfScript = CreateScriptFile(pszFile, szImportFile);
  703. TraceMsg(TF_GENERAL, TEXT("CONNECT:ImportScriptFile(): CreateScriptFile hfScript %d, %s, %s\n"),hfScript,pszFile,szImportFile);
  704. if (hfScript != INVALID_HANDLE_VALUE)
  705. {
  706. TCHAR szLineNum[MAXLONGLEN+1];
  707. // From The first line to the last line
  708. //
  709. for (i = 0; i <= iMaxLine; i++)
  710. {
  711. // Read the script line
  712. //
  713. wsprintf(szLineNum, TEXT("%d"), i);
  714. if ((cbSize = GetPrivateProfileString(cszScriptSection,
  715. szLineNum,
  716. szNull,
  717. pszLine,
  718. SIZE_ReadBuf,
  719. szImportFile)) != 0)
  720. {
  721. // Write to the script file
  722. //
  723. lstrcat(pszLine, TEXT("\x0d\x0a"));
  724. #ifdef UNICODE
  725. CHAR szTmp[SIZE_ReadBuf];
  726. size_t nSize = wcstombs(szTmp, pszLine, SIZE_ReadBuf);
  727. if (nSize > 0)
  728. WriteFile(hfScript, szTmp, nSize, (LPDWORD)&cbRet, NULL);
  729. #else
  730. WriteFile(hfScript, pszLine, cbSize+2, (LPDWORD)&cbRet, NULL);
  731. #endif
  732. };
  733. };
  734. CloseHandle(hfScript);
  735. // Associate it with the phonebook entry
  736. //
  737. lstrcpyn(lpRasEntry->szScript, pszFile, RAS_MaxEntryName);
  738. }
  739. else
  740. {
  741. dwRet = GetLastError();
  742. };
  743. }
  744. else
  745. {
  746. dwRet = ERROR_PATH_NOT_FOUND;
  747. };
  748. }
  749. else
  750. {
  751. dwRet = ERROR_PATH_NOT_FOUND;
  752. };
  753. delete [] pszLine;
  754. return dwRet;
  755. }
  756. //****************************************************************************
  757. // DWORD WINAPI RnaValidateImportEntry (LPTSTR)
  758. //
  759. // This function is called to validate an importable file
  760. //
  761. // History:
  762. // Wed 03-Jan-1996 09:45:01 -by- Viroon Touranachun [viroont]
  763. // Created.
  764. //****************************************************************************
  765. DWORD CISPImport::RnaValidateImportEntry (LPCTSTR szFileName)
  766. {
  767. TCHAR szTmp[4];
  768. // Get the alias entry name
  769. //
  770. return (GetPrivateProfileString(cszEntrySection,
  771. cszEntryName,
  772. szNull,
  773. szTmp,
  774. 4,
  775. szFileName) > 0 ?
  776. ERROR_SUCCESS : ERROR_CORRUPT_PHONEBOOK);
  777. }
  778. //****************************************************************************
  779. // HRESULT ImportConnection (LPCTSTR szFileName, LPTSTR pszEntryName, LPTSTR pszUserName, LPTSTR pszPassword)
  780. //
  781. // This function is called to import an entry from a specified file
  782. //
  783. // History:
  784. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  785. // Created.
  786. // Sat 16-Mar-1996 10:01:00 -by- Chris Kauffman [chrisk]
  787. // Modified to return HRESULT and load DLL dynamically
  788. //****************************************************************************
  789. HRESULT CISPImport::ImportConnection (LPCTSTR szFileName, LPTSTR pszSupportNumber, LPTSTR pszEntryName, LPTSTR pszUserName, LPTSTR pszPassword, LPBOOL pfNeedsRestart)
  790. {
  791. LPRASENTRY lpRasEntry;
  792. DWORD dwRet;
  793. DWORD dwOptions;
  794. HINSTANCE hinetcfg;
  795. FARPROC fp, fpSetAutoProxy;
  796. // Get the size of device configuration
  797. // This also validates an exported file
  798. //
  799. if ((dwRet = RnaValidateImportEntry(szFileName)) != ERROR_SUCCESS)
  800. {
  801. return dwRet;
  802. };
  803. // Allocate a buffer for entry and device config
  804. //
  805. if ((lpRasEntry = (LPRASENTRY)GlobalAlloc(GPTR, sizeof(RASENTRY))) == NULL)
  806. {
  807. return ERROR_OUTOFMEMORY;
  808. };
  809. // Get the entry name
  810. // Need to find a good name for it and remember it as an alias
  811. //
  812. GetPrivateProfileString(cszEntrySection,
  813. cszEntryName,
  814. szNull,
  815. pszEntryName,
  816. RAS_MaxEntryName+1,
  817. szFileName);
  818. GetPrivateProfileString(cszUserSection,
  819. cszUserName,
  820. szNull,
  821. pszUserName,
  822. UNLEN+1,
  823. szFileName);
  824. GetPrivateProfileString(cszUserSection,
  825. cszPassword,
  826. szNull,
  827. pszPassword,
  828. PWLEN+1,
  829. szFileName);
  830. // Get ISP support number
  831. //
  832. GetPrivateProfileString(cszSupport,
  833. cszSupportNumber,
  834. szNull,
  835. pszSupportNumber,
  836. RAS_MaxAreaCode + RAS_MaxPhoneNumber +1,
  837. szFileName);
  838. // Get device name, type and config
  839. //
  840. GetPrivateProfileString(cszDeviceSection,
  841. cszDeviceType,
  842. szNull,
  843. lpRasEntry->szDeviceType,
  844. ARRAYSIZE(lpRasEntry->szDeviceType),
  845. szFileName);
  846. // Get Server Type settings
  847. //
  848. ImportServerInfo(lpRasEntry, szFileName);
  849. // Get IP address
  850. //
  851. ImportIPInfo(lpRasEntry, szFileName);
  852. // Import the script file
  853. //
  854. if ((dwRet = ImportScriptFile(lpRasEntry, szFileName)) != ERROR_SUCCESS)
  855. {
  856. TraceMsg(TF_GENERAL,TEXT("CONNECT:ImportScriptFile Failed with the error %d,%s,%s"),dwRet,szFileName,lpRasEntry->szScript);
  857. }
  858. lpRasEntry->dwSize = sizeof(RASENTRY);
  859. // Load and Locate AutoRunSignUpWizard entry point
  860. //
  861. hinetcfg = LoadLibrary(TEXT("INETCFG.DLL"));
  862. AssertMsg(hinetcfg != NULL, TEXT("Cannot find INETCFG.DLL"));
  863. if (!hinetcfg)
  864. {
  865. dwRet = GetLastError();
  866. goto ImportConnectionExit;
  867. }
  868. fpSetAutoProxy = GetProcAddress(hinetcfg,cszSetAutoProxyConnectoid);
  869. if (fpSetAutoProxy)
  870. {
  871. ((SETAUTOPROXYCONNECTOID)fpSetAutoProxy) (FALSE);
  872. }
  873. fp = GetProcAddress(hinetcfg,AUTORUNSIGNUPWIZARDAPI);
  874. AssertMsg(fp != NULL, TEXT("Cannot find AutoRunSignupWizard entry point"));
  875. if (!fp)
  876. {
  877. dwRet = GetLastError();
  878. goto ImportConnectionExit;
  879. }
  880. // 10/19/96 jmazner Normandy #8462 -- multiple modems
  881. dwRet = ConfigRasEntryDevice(lpRasEntry);
  882. switch( dwRet )
  883. {
  884. case ERROR_SUCCESS:
  885. break;
  886. case ERROR_CANCELLED:
  887. if( IDYES != MessageBox(GetActiveWindow(),GetSz(IDS_WANTTOEXIT),GetSz(IDS_TITLE),
  888. MB_APPLMODAL | MB_ICONQUESTION |
  889. MB_YESNO | MB_DEFBUTTON2) )
  890. {
  891. dwRet = ERROR_RETRY;
  892. }
  893. goto ImportConnectionExit;
  894. default:
  895. goto ImportConnectionExit;
  896. }
  897. // See if this is a ISDN type device, and if so, then set the CFGFLAG_ISDN_OFFER
  898. if (lstrcmpi(g_szDeviceType, RASDT_Isdn) == 0)
  899. m_bIsISDNDevice = TRUE;
  900. ImportPhoneInfo(lpRasEntry, szFileName, m_bIsISDNDevice);
  901. //
  902. // ChrisK Olympus 4756 5/25/97
  903. // Do not display busy animation on Win95
  904. //
  905. dwOptions = INETCFG_INSTALLRNA |
  906. INETCFG_INSTALLTCP |
  907. INETCFG_OVERWRITEENTRY;
  908. dwRet = ((PFNAUTORUNSIGNUPWIZARD)fp)(
  909. NULL,
  910. NULL,
  911. pszEntryName,
  912. lpRasEntry,
  913. pszUserName,
  914. pszPassword,
  915. NULL,
  916. NULL,
  917. dwOptions,
  918. pfNeedsRestart);
  919. if (fpSetAutoProxy)
  920. {
  921. ((SETAUTOPROXYCONNECTOID)fpSetAutoProxy) (TRUE);
  922. }
  923. LclSetEntryScriptPatch(lpRasEntry->szScript,pszEntryName);
  924. // now that we've made the connectoid in InetConfigClient (PFNAUTORUNSIGNUPWIZARD),
  925. // store its name in psheet's global so that we can delete it if user cancels
  926. lstrcpyn( m_szConnectoidName, pszEntryName, lstrlen(pszEntryName) + 1);
  927. TraceMsg(TF_GENERAL,TEXT("CONNECT:EntryName %s, User %s, Password (not shown), Number %s\n"),pszEntryName,pszUserName,lpRasEntry->szLocalPhoneNumber);
  928. //AssertMsg(!fNeedsRestart,TEXT("We have to reboot AGAIN!!"));
  929. // Exit and cleanup
  930. //
  931. ImportConnectionExit:
  932. if (hinetcfg) FreeLibrary(hinetcfg);
  933. GlobalFree(lpRasEntry);
  934. return dwRet;
  935. }
  936. //+----------------------------------------------------------------------------
  937. //
  938. // Function GetDeviceSelectedByUser
  939. //
  940. // Synopsis Get the name of the RAS device that the user had already picked
  941. //
  942. // Arguements szKey - name of sub key
  943. // szBuf - pointer to buffer
  944. // dwSize - size of buffer
  945. //
  946. // Return TRUE - success
  947. //
  948. // History 10/24/96 ChrisK Created
  949. //-----------------------------------------------------------------------------
  950. BOOL CISPImport::GetDeviceSelectedByUser (LPTSTR szKey, LPTSTR szBuf, DWORD dwSize)
  951. {
  952. BOOL bRC = FALSE;
  953. HKEY hkey = NULL;
  954. DWORD dwType = 0;
  955. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,ISIGNUP_KEY,&hkey))
  956. {
  957. if (ERROR_SUCCESS == RegQueryValueEx(hkey,szKey,0,&dwType,
  958. (LPBYTE)szBuf,&dwSize))
  959. bRC = TRUE;
  960. }
  961. if (hkey)
  962. RegCloseKey(hkey);
  963. return bRC;
  964. }
  965. //+----------------------------------------------------------------------------
  966. // Function SetDeviceSelectedByUser
  967. //
  968. // Synopsis Write user's device selection to registry
  969. //
  970. // Arguments szKey - name of key
  971. // szBuf - data to write to key
  972. //
  973. // Returns TRUE - success
  974. //
  975. // History 10/24/96 ChrisK Created
  976. //-----------------------------------------------------------------------------
  977. BOOL CISPImport::SetDeviceSelectedByUser (LPTSTR szKey, LPTSTR szBuf)
  978. {
  979. BOOL bRC = FALSE;
  980. HKEY hkey = 0;
  981. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,
  982. ISIGNUP_KEY,&hkey))
  983. {
  984. if (ERROR_SUCCESS == RegSetValueEx(hkey,szKey,0,REG_SZ,
  985. (LPBYTE)szBuf,sizeof(TCHAR)*(lstrlen(szBuf)+1)))
  986. bRC = TRUE;
  987. }
  988. if (hkey)
  989. RegCloseKey(hkey);
  990. return bRC;
  991. }
  992. //+----------------------------------------------------------------------------
  993. // Funciton DeleteUserDeviceSelection
  994. //
  995. // Synopsis Remove registry keys with device selection
  996. //
  997. // Arguments szKey - name of value to remove
  998. //
  999. // Returns TRUE - success
  1000. //
  1001. // History 10/24/96 ChrisK Created
  1002. //-----------------------------------------------------------------------------
  1003. BOOL CISPImport::DeleteUserDeviceSelection(LPTSTR szKey)
  1004. {
  1005. BOOL bRC = FALSE;
  1006. HKEY hkey = NULL;
  1007. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,ISIGNUP_KEY,&hkey))
  1008. {
  1009. bRC = (ERROR_SUCCESS == RegDeleteValue(hkey,szKey));
  1010. RegCloseKey(hkey);
  1011. }
  1012. return bRC;
  1013. }
  1014. //+---------------------------------------------------------------------------
  1015. //
  1016. // Function: ConfigRasEntryDevice()
  1017. //
  1018. // Synopsis: Checks whether user has already specified a modem to use;
  1019. // If so, verifies that modem is valid.
  1020. // If not, or if modem is invalid, presents user a dialog
  1021. // to choose which modem to use (if only one modem is installed,
  1022. // it automaticaly selects that device and bypasses the dialog)
  1023. //
  1024. // Arguments: lpRasEntry - Pointer to the RasEntry whose szDeviceName and
  1025. // szDeviceType members you wish to verify/configure
  1026. //
  1027. // Returns: ERROR_CANCELLED - Had to bring up "Choose Modem" dialog, and
  1028. // and user hit its "Cancel" button
  1029. // Otherwise returns any error code encountered.
  1030. // ERROR_SUCCESS indicates success.
  1031. //
  1032. // History: 5/18/96 VetriV Created
  1033. // 3/7/98 DonSc Added the process-wide tracking of the previously
  1034. // selected device.
  1035. //
  1036. //----------------------------------------------------------------------------
  1037. DWORD CISPImport::ConfigRasEntryDevice( LPRASENTRY lpRasEntry )
  1038. {
  1039. DWORD dwRet = ERROR_SUCCESS;
  1040. CEnumModem EnumModem;
  1041. GetDeviceSelectedByUser(DEVICENAMEKEY, g_szDeviceName, sizeof(g_szDeviceName));
  1042. GetDeviceSelectedByUser(DEVICETYPEKEY, g_szDeviceType, sizeof(g_szDeviceType));
  1043. ASSERT(lpRasEntry);
  1044. dwRet = EnumModem.GetError();
  1045. if (ERROR_SUCCESS != dwRet)
  1046. {
  1047. return dwRet;
  1048. }
  1049. // If there are no modems, we're horked
  1050. if (0 == EnumModem.GetNumDevices())
  1051. {
  1052. TraceMsg(TF_GENERAL,TEXT("ICWHELP: import.cpp: ConfigRasEntryDevice: ERROR: No modems installed!\n"));
  1053. return ERROR_CANCELLED;
  1054. }
  1055. // Validate the device if possible
  1056. if ( lpRasEntry->szDeviceName[0] && lpRasEntry->szDeviceType[0] )
  1057. {
  1058. // Verify that there is a device with the given name and type
  1059. if (!EnumModem.VerifyDeviceNameAndType(lpRasEntry->szDeviceName,
  1060. lpRasEntry->szDeviceType))
  1061. {
  1062. // There was no device that matched both name and type,
  1063. // so reset the strings and bring up the choose modem UI.
  1064. lpRasEntry->szDeviceName[0] = '\0';
  1065. lpRasEntry->szDeviceType[0] = '\0';
  1066. }
  1067. }
  1068. else if ( lpRasEntry->szDeviceName[0] )
  1069. {
  1070. // Only the name was given. Try to find a matching type.
  1071. // If this fails, fall through to recovery case below.
  1072. LPTSTR szDeviceType =
  1073. EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceName);
  1074. if (szDeviceType)
  1075. {
  1076. lstrcpy (lpRasEntry->szDeviceType, szDeviceType);
  1077. }
  1078. }
  1079. else if ( lpRasEntry->szDeviceType[0] )
  1080. {
  1081. // Only the type was given. Try to find a matching name.
  1082. // If this fails, fall through to recovery case below.
  1083. LPTSTR szDeviceName =
  1084. EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceType);
  1085. if (szDeviceName)
  1086. {
  1087. lstrcpy (lpRasEntry->szDeviceName, szDeviceName);
  1088. }
  1089. }
  1090. // If either name or type is missing, check whether the user has already made a choice.
  1091. // if not, bring up choose modem UI if there
  1092. // are multiple devices, else just get first device.
  1093. // Since we already verified that there was at least one device,
  1094. // we can assume that this will succeed.
  1095. if( !(lpRasEntry->szDeviceName[0]) ||
  1096. !(lpRasEntry->szDeviceType[0]) )
  1097. {
  1098. TraceMsg(TF_GENERAL,TEXT("ICWHELP: ConfigRasEntryDevice: no valid device passed in\n"));
  1099. if( g_szDeviceName[0] )
  1100. {
  1101. // it looks like we have already stored the user's choice.
  1102. // store the DeviceName in lpRasEntry, then call GetDeviceTypeFromName
  1103. // to confirm that the deviceName we saved actually exists on the system
  1104. lstrcpy(lpRasEntry->szDeviceName, g_szDeviceName);
  1105. if( 0 == lstrcmp(EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceName),
  1106. g_szDeviceType) )
  1107. {
  1108. lstrcpy(lpRasEntry->szDeviceType, g_szDeviceType);
  1109. return ERROR_SUCCESS;
  1110. }
  1111. }
  1112. if (1 == EnumModem.GetNumDevices())
  1113. {
  1114. // There is just one device installed, so copy the name
  1115. TraceMsg(TF_GENERAL,TEXT("ICWHELP: import.cpp: ConfigRasEntryDevice: only one modem installed, using it\n"));
  1116. lstrcpy (lpRasEntry->szDeviceName, EnumModem.Next());
  1117. }
  1118. else
  1119. {
  1120. TraceMsg(TF_GENERAL,TEXT("ICWHELP: import.cpp: ConfigRasEntryDevice: multiple modems detected\n"));
  1121. if (IsNT4SP3Lower())
  1122. lstrcpy (lpRasEntry->szDeviceName, EnumModem.Next() );
  1123. else
  1124. {
  1125. CHOOSEMODEMDLGINFO ChooseModemDlgInfo;
  1126. BOOL fRet=(BOOL)DialogBoxParam(GetModuleHandle(TEXT("ICWHELP.DLL")), MAKEINTRESOURCE(IDD_CHOOSEMODEMNAME), GetActiveWindow(),
  1127. ChooseModemDlgProc,(LPARAM) &ChooseModemDlgInfo);
  1128. if (TRUE != fRet)
  1129. {
  1130. // user cancelled or an error occurred.
  1131. dwRet = ChooseModemDlgInfo.hr;
  1132. /*
  1133. dwRet = GetLastError(); //This will NEVER be ERROR_SUCCESS
  1134. //BUBGUG -- If the user hits OK -> then ChooseModemDlgInfo.hr == ERROR_SUCCESS,
  1135. BUT if OK was hit then the function returns true and this can never be hit!
  1136. if (ERROR_SUCCESS == dwRet)
  1137. {
  1138. // Error occurred, but the error code was not set.
  1139. dwRet = ERROR_INETCFG_UNKNOWN;
  1140. }*/
  1141. return dwRet;
  1142. }
  1143. // Copy the modem name string
  1144. lstrcpy (lpRasEntry->szDeviceName, ChooseModemDlgInfo.szModemName);
  1145. }
  1146. }
  1147. // Now get the type string for this modem
  1148. lstrcpy (lpRasEntry->szDeviceType,EnumModem.GetDeviceTypeFromName(lpRasEntry->szDeviceName));
  1149. }
  1150. lstrcpy(g_szDeviceName, lpRasEntry->szDeviceName);
  1151. lstrcpy(g_szDeviceType, lpRasEntry->szDeviceType);
  1152. // Save device name and type
  1153. lstrcpy( m_szDeviceName, lpRasEntry->szDeviceName);
  1154. lstrcpy( m_szDeviceType, lpRasEntry->szDeviceType);
  1155. // Save data in registry
  1156. SetDeviceSelectedByUser(DEVICENAMEKEY, g_szDeviceName);
  1157. SetDeviceSelectedByUser (DEVICETYPEKEY, g_szDeviceType);
  1158. return dwRet;
  1159. }