Source code of Windows XP (NT5)
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.

4397 lines
144 KiB

  1. /*-----------------------------------------------------------------------------
  2. INSHandler.cpp
  3. Implementation of CINSHandler - INS file processing
  4. Copyright (C) 1999 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. vyung
  8. thomasje
  9. History:
  10. 2/7/99 Vyung created - code borrowed from ICW, icwhelp.dll
  11. 10/30/99 Thomasje modified - Broadband support (1483, PPPOA)
  12. -----------------------------------------------------------------------------*/
  13. #include "msobcomm.h"
  14. #include <shellapi.h>
  15. #include "inshdlr.h"
  16. #include "webgate.h"
  17. #include "import.h"
  18. #include "rnaapi.h"
  19. #include "inetreg.h"
  20. #include "wininet.h"
  21. #include "appdefs.h"
  22. #include "util.h"
  23. #include "wancfg.h"
  24. #include "inets.h"
  25. #define MAXNAME 80
  26. #define MAXIPADDRLEN 20
  27. #define MAXLONGLEN 80
  28. #define MAX_ISP_MSG 560
  29. #define MAX_ISP_PHONENUMBER 80
  30. #define CCH_ReadBuf (SIZE_ReadBuf / sizeof(WCHAR)) // 32K buffer size
  31. #define myisdigit(ch) (((ch) >= L'0') && ((ch) <= L'9'))
  32. #define IS_PROXY L"Proxy"
  33. #define IK_PROXYENABLE L"Proxy_Enable"
  34. #define IK_HTTPPROXY L"HTTP_Proxy_Server"
  35. // ICW INS PROCESSING FAIL
  36. #define OEM_CONFIG_INS_FILENAME L"icw\\OEMCNFG.INS"
  37. #define OEM_CONFIG_REGKEY L"SOFTWARE\\Microsoft\\Internet Connection Wizard\\INS processing"
  38. #define OEM_CONFIG_REGVAL_FAILED L"Process failed"
  39. #define OEM_CONFIG_REGVAL_ISPNAME L"ISP name"
  40. #define OEM_CONFIG_REGVAL_SUPPORTNUM L"Support number"
  41. #define OEM_CONFIG_INS_SECTION L"Entry"
  42. #define OEM_CONFIG_INS_ISPNAME L"Entry_Name"
  43. #define OEM_CONFIG_INS_SUPPORTNUM L"Support_Number"
  44. typedef HRESULT (WINAPI * INTERNETSETOPTION) (IN HINTERNET hInternet OPTIONAL, IN DWORD dwOption, IN LPVOID lpBuffer, IN DWORD dwBufferLength);
  45. typedef HRESULT (WINAPI * INTERNETQUERYOPTION) (IN HINTERNET hInternet OPTIONAL, IN DWORD dwOption, IN LPVOID lpBuffer, IN LPDWORD dwBufferLength);
  46. extern CObCommunicationManager* gpCommMgr;
  47. // The following values are global read only strings used to
  48. // process the INS file
  49. #pragma data_seg(".rdata")
  50. static const WCHAR cszAlias[] = L"Import_Name";
  51. static const WCHAR cszML[] = L"Multilink";
  52. static const WCHAR cszPhoneSection[] = L"Phone";
  53. static const WCHAR cszDialAsIs[] = L"Dial_As_Is";
  54. static const WCHAR cszPhone[] = L"Phone_Number";
  55. static const WCHAR cszAreaCode[] = L"Area_Code";
  56. static const WCHAR cszCountryCode[] = L"Country_Code";
  57. static const WCHAR cszCountryID[] = L"Country_ID";
  58. static const WCHAR cszDeviceSection[] = L"Device";
  59. static const WCHAR cszDeviceType[] = L"Type";
  60. static const WCHAR cszDeviceName[] = L"Name";
  61. static const WCHAR cszDevCfgSize[] = L"Settings_Size";
  62. static const WCHAR cszDevCfg[] = L"Settings";
  63. static const WCHAR cszPnpId[] = L"Plug_and_Play_Id";
  64. static const WCHAR cszServerSection[] = L"Server";
  65. static const WCHAR cszServerType[] = L"Type";
  66. static const WCHAR cszSWCompress[] = L"SW_Compress";
  67. static const WCHAR cszPWEncrypt[] = L"PW_Encrypt";
  68. static const WCHAR cszNetLogon[] = L"Network_Logon";
  69. static const WCHAR cszSWEncrypt[] = L"SW_Encrypt";
  70. static const WCHAR cszNetBEUI[] = L"Negotiate_NetBEUI";
  71. static const WCHAR cszIPX[] = L"Negotiate_IPX/SPX";
  72. static const WCHAR cszIP[] = L"Negotiate_TCP/IP";
  73. static WCHAR cszDisableLcp[] = L"Disable_LCP";
  74. static const WCHAR cszIPSection[] = L"TCP/IP";
  75. static const WCHAR cszIPSpec[] = L"Specify_IP_Address";
  76. static const WCHAR cszIPAddress[] = L"IP_address";
  77. static const WCHAR cszIPMask[] = L"Subnet_Mask";
  78. static const WCHAR cszServerSpec[] = L"Specify_Server_Address";
  79. static const WCHAR cszGatewayList[] = L"Default_Gateway_List";
  80. static const WCHAR cszDNSSpec[] = L"Specify_DNS_Address";
  81. static const WCHAR cszDNSList[] = L"DNS_List";
  82. static const WCHAR cszDNSAddress[] = L"DNS_address";
  83. static const WCHAR cszDNSAltAddress[] = L"DNS_Alt_address";
  84. static const WCHAR cszWINSSpec[] = L"Specify_WINS_Address";
  85. static const WCHAR cszWINSList[] = L"WINS_List";
  86. static const WCHAR cszScopeID[] = L"ScopeID";
  87. static const WCHAR cszDHCPSpec[] = L"Specify_DHCP_Address";
  88. static const WCHAR cszDHCPServer[] = L"DHCP_Server";
  89. static const WCHAR cszWINSAddress[] = L"WINS_address";
  90. static const WCHAR cszWINSAltAddress[]= L"WINS_Alt_address";
  91. static const WCHAR cszIPCompress[] = L"IP_Header_Compress";
  92. static const WCHAR cszWanPri[] = L"Gateway_On_Remote";
  93. static const WCHAR cszDefaultGateway[] = L"Default_Gateway";
  94. static const WCHAR cszDomainName[] = L"Domain_Name";
  95. static const WCHAR cszHostName[] = L"Host_Name";
  96. static const WCHAR cszDomainSuffixSearchList[] = L"Domain_Suffix_Search_List";
  97. static const WCHAR cszATMSection[] = L"ATM";
  98. static const WCHAR cszCircuitSpeed[] = L"Circuit_Speed";
  99. static const WCHAR cszCircuitQOS[] = L"Circuit_QOS";
  100. static const WCHAR cszCircuitType[] = L"Circuit_Type";
  101. static const WCHAR cszSpeedAdjust[] = L"Speed_Adjust";
  102. static const WCHAR cszQOSAdjust[] = L"QOS_Adjust";
  103. static const WCHAR cszEncapsulation[] = L"Encapsulation";
  104. static const WCHAR cszVPI[] = L"VPI";
  105. static const WCHAR cszVCI[] = L"VCI";
  106. static const WCHAR cszVendorConfig[] = L"Vendor_Config";
  107. static const WCHAR cszShowStatus[] = L"Show_Status";
  108. static const WCHAR cszEnableLog[] = L"Enable_Log";
  109. static const WCHAR cszRfc1483Section[] = L"RFC1483";
  110. static const WCHAR cszPppoeSection[] = L"PPPOE";
  111. static const WCHAR cszMLSection[] = L"Multilink";
  112. static const WCHAR cszLinkIndex[] = L"Line_%s";
  113. static const WCHAR cszScriptingSection[] = L"Scripting";
  114. static const WCHAR cszScriptName[] = L"Name";
  115. static const WCHAR cszScriptSection[] = L"Script_File";
  116. static const WCHAR cszCustomDialerSection[] = L"Custom_Dialer";
  117. static const WCHAR cszAutoDialDLL[] = L"Auto_Dial_DLL";
  118. static const WCHAR cszAutoDialFunc[] = L"Auto_Dial_Function";
  119. // These strings will be use to populate the registry, with the data above
  120. static const WCHAR cszKeyIcwRmind[] = L"Software\\Microsoft\\Internet Connection Wizard\\IcwRmind";
  121. static const WCHAR cszTrialRemindSection[] = L"TrialRemind";
  122. static const WCHAR cszEntryISPName[] = L"ISP_Name";
  123. static const WCHAR cszEntryISPPhone[] = L"ISP_Phone";
  124. static const WCHAR cszEntryISPMsg[] = L"ISP_Message";
  125. static const WCHAR cszEntryTrialDays[] = L"Trial_Days";
  126. static const WCHAR cszEntrySignupURL[] = L"Signup_URL";
  127. // ICWRMIND expects this value in the registry
  128. static const WCHAR cszEntrySignupURLTrialOver[] = L"Expired_URL";
  129. // We get these two from the INS file
  130. static const WCHAR cszEntryExpiredISPFileName[] = L"Expired_ISP_File";
  131. static const WCHAR cszSignupExpiredISPURL[] = L"Expired_ISP_URL";
  132. static const WCHAR cszEntryConnectoidName[] = L"Entry_Name";
  133. static const WCHAR cszSignupSuccessfuly[] = L"TrialConverted";
  134. static const WCHAR cszReminderApp[] = L"ICWRMIND.EXE";
  135. static const WCHAR cszReminderParams[] = L"-t";
  136. static const WCHAR cszPassword[] = L"Password";
  137. extern SERVER_TYPES aServerTypes[];
  138. // These are the field names from an INS file that will
  139. // determine the mail and news settings
  140. static const WCHAR cszMailSection[] = L"Internet_Mail";
  141. static const WCHAR cszPOPServer[] = L"POP_Server";
  142. static const WCHAR cszPOPServerPortNumber[] = L"POP_Server_Port_Number";
  143. static const WCHAR cszPOPLogonName[] = L"POP_Logon_Name";
  144. static const WCHAR cszPOPLogonPassword[] = L"POP_Logon_Password";
  145. static const WCHAR cszSMTPServer[] = L"SMTP_Server";
  146. static const WCHAR cszSMTPServerPortNumber[] = L"SMTP_Server_Port_Number";
  147. static const WCHAR cszNewsSection[] = L"Internet_News";
  148. static const WCHAR cszNNTPServer[] = L"NNTP_Server";
  149. static const WCHAR cszNNTPServerPortNumber[] = L"NNTP_Server_Port_Number";
  150. static const WCHAR cszNNTPLogonName[] = L"NNTP_Logon_Name";
  151. static const WCHAR cszNNTPLogonPassword[] = L"NNTP_Logon_Password";
  152. static const WCHAR cszUseMSInternetMail[] = L"Install_Mail";
  153. static const WCHAR cszUseMSInternetNews[] = L"Install_News";
  154. static const WCHAR cszEMailSection[] = L"Internet_Mail";
  155. static const WCHAR cszEMailName[] = L"EMail_Name";
  156. static const WCHAR cszEMailAddress[] = L"EMail_Address";
  157. static const WCHAR cszUseExchange[] = L"Use_MS_Exchange";
  158. static const WCHAR cszUserSection[] = L"User";
  159. static const WCHAR cszUserName[] = L"Name";
  160. static const WCHAR cszDisplayPassword[] = L"Display_Password";
  161. static const WCHAR cszYes[] = L"yes";
  162. static const WCHAR cszNo[] = L"no";
  163. // "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
  164. static const WCHAR szRegPathInternetSettings[] = REGSTR_PATH_INTERNET_SETTINGS;
  165. static const WCHAR szRegPathDefInternetSettings[] = L".DEFAULT\\" REGSTR_PATH_INTERNET_SETTINGS;
  166. static const WCHAR cszCMHeader[] = L"Connection Manager CMS 0";
  167. // "InternetProfile"
  168. static const WCHAR szRegValInternetProfile[] = REGSTR_VAL_INTERNETPROFILE;
  169. // "EnableAutodial"
  170. static const WCHAR szRegValEnableAutodial[] = REGSTR_VAL_ENABLEAUTODIAL;
  171. // "NoNetAutodial"
  172. #ifndef REGSTR_VAL_NONETAUTODIAL
  173. #define REGSTR_VAL_NONETAUTODIAL L"NoNetAutodial"
  174. #endif
  175. static const WCHAR szRegValNoNetAutodial[] = REGSTR_VAL_NONETAUTODIAL;
  176. // "RemoteAccess"
  177. static const WCHAR szRegPathRNAWizard[] = REGSTR_PATH_REMOTEACCESS;
  178. #define CLIENT_ELEM(elem) (((LPINETCLIENTINFO)(NULL))->elem)
  179. #define CLIENT_OFFSET(elem) ((DWORD_PTR)&CLIENT_ELEM(elem))
  180. #define CLIENT_SIZE(elem) (sizeof(CLIENT_ELEM(elem)) / sizeof(CLIENT_ELEM(elem)[0]))
  181. #define CLIENT_ENTRY(section, value, elem) \
  182. {section, value, CLIENT_OFFSET(elem), CLIENT_SIZE(elem)}
  183. CLIENT_TABLE iniTable[] =
  184. {
  185. CLIENT_ENTRY(cszEMailSection, cszEMailName, szEMailName),
  186. CLIENT_ENTRY(cszEMailSection, cszEMailAddress, szEMailAddress),
  187. CLIENT_ENTRY(cszEMailSection, cszPOPLogonName, szPOPLogonName),
  188. CLIENT_ENTRY(cszEMailSection, cszPOPLogonPassword, szPOPLogonPassword),
  189. CLIENT_ENTRY(cszEMailSection, cszPOPServer, szPOPServer),
  190. CLIENT_ENTRY(cszEMailSection, cszSMTPServer, szSMTPServer),
  191. CLIENT_ENTRY(cszNewsSection, cszNNTPLogonName, szNNTPLogonName),
  192. CLIENT_ENTRY(cszNewsSection, cszNNTPLogonPassword, szNNTPLogonPassword),
  193. CLIENT_ENTRY(cszNewsSection, cszNNTPServer, szNNTPServer),
  194. {NULL, NULL, 0, 0}
  195. };
  196. static const WCHAR cszFileName[] = L"Custom_File";
  197. static const WCHAR cszCustomFileSection[] = L"Custom_File";
  198. static const WCHAR cszNull[] = L"";
  199. static const WCHAR cszURLSection[] = L"URL";
  200. static const WCHAR cszSignupURL[] = L"Signup";
  201. static const WCHAR cszAutoConfigURL[] = L"Autoconfig";
  202. static const WCHAR cszExtINS[] = L".ins";
  203. static const WCHAR cszExtISP[] = L".isp";
  204. static const WCHAR cszExtHTM[] = L".htm";
  205. static const WCHAR cszExtHTML[] = L".html";
  206. static const WCHAR cszEntrySection[] = L"Entry";
  207. static const WCHAR cszCancel[] = L"Cancel";
  208. static const WCHAR cszRun[] = L"Run";
  209. static const WCHAR cszArgument[] = L"Argument";
  210. static const WCHAR cszConnect2[] = L"icwconn2.exe";
  211. static const WCHAR cszClientSetupSection[] = L"ClientSetup";
  212. static const WCHAR cszRequiresLogon[] = L"Requires_Logon";
  213. static const WCHAR cszCustomSection[] = L"Custom";
  214. static const WCHAR cszKeepConnection[] = L"Keep_Connection";
  215. static const WCHAR cszKeepBrowser[] = L"Keep_Browser";
  216. static const WCHAR cszKioskMode[] = L"-k ";
  217. static const WCHAR cszOpen[] = L"open";
  218. static const WCHAR cszBrowser[] = L"iexplore.exe";
  219. static const WCHAR szNull[] = L"";
  220. static const WCHAR cszNullIP[] = L"0.0.0.0";
  221. static const WCHAR cszWininet[] = L"WININET.DLL";
  222. static const CHAR cszInternetSetOption[] = "InternetSetOptionA";
  223. static const CHAR cszInternetQueryOption[] = "InternetQueryOptionA";
  224. static const WCHAR cszDEFAULT_BROWSER_KEY[] = L"Software\\Microsoft\\Internet Explorer\\Main";
  225. static const WCHAR cszDEFAULT_BROWSER_VALUE[] = L"check_associations";
  226. // Registry keys which will contain News and Mail settings
  227. #define MAIL_KEY L"SOFTWARE\\Microsoft\\Internet Mail and News\\Mail"
  228. #define MAIL_POP3_KEY L"SOFTWARE\\Microsoft\\Internet Mail and News\\Mail\\POP3\\"
  229. #define MAIL_SMTP_KEY L"SOFTWARE\\Microsoft\\Internet Mail and News\\Mail\\SMTP\\"
  230. #define NEWS_KEY L"SOFTWARE\\Microsoft\\Internet Mail and News\\News"
  231. #define MAIL_NEWS_INPROC_SERVER32 L"CLSID\\{89292102-4755-11cf-9DC2-00AA006C2B84}\\InProcServer32"
  232. typedef HRESULT (WINAPI *PFNSETDEFAULTNEWSHANDLER)(void);
  233. // These are the value names where the INS settings will be saved
  234. // into the registry
  235. static const WCHAR cszMailSenderName[] = L"Sender Name";
  236. static const WCHAR cszMailSenderEMail[] = L"Sender EMail";
  237. static const WCHAR cszMailRASPhonebookEntry[] = L"RAS Phonebook Entry";
  238. static const WCHAR cszMailConnectionType[] = L"Connection Type";
  239. static const WCHAR cszDefaultPOP3Server[] = L"Default POP3 Server";
  240. static const WCHAR cszDefaultSMTPServer[] = L"Default SMTP Server";
  241. static const WCHAR cszPOP3Account[] = L"Account";
  242. static const WCHAR cszPOP3Password[] = L"Password";
  243. static const WCHAR cszPOP3Port[] = L"Port";
  244. static const WCHAR cszSMTPPort[] = L"Port";
  245. static const WCHAR cszNNTPSenderName[] = L"Sender Name";
  246. static const WCHAR cszNNTPSenderEMail[] = L"Sender EMail";
  247. static const WCHAR cszNNTPDefaultServer[] = L"DefaultServer"; // NOTE: NO space between "Default" and "Server".
  248. static const WCHAR cszNNTPAccountName[] = L"Account Name";
  249. static const WCHAR cszNNTPPassword[] = L"Password";
  250. static const WCHAR cszNNTPPort[] = L"Port";
  251. static const WCHAR cszNNTPRasPhonebookEntry[] = L"RAS Phonebook Entry";
  252. static const WCHAR cszNNTPConnectionType[] = L"Connection Type";
  253. static const WCHAR arBase64[] =
  254. {
  255. L'A',L'B',L'C',L'D',L'E',L'F',L'G',L'H',L'I',L'J',L'K',L'L',L'M',
  256. L'N',L'O',L'P',L'Q',L'R',L'S',L'T',L'U',L'V',L'W',L'X',L'Y',L'Z',
  257. L'a',L'b',L'c',L'd',L'e',L'f',L'g',L'h',L'i',L'j',L'k',L'l',L'm',
  258. L'n',L'o',L'p',L'q',L'r',L's',L't',L'u',L'v',L'w',L'x',L'y',L'z',
  259. L'0',L'1',L'2',L'3',L'4',L'5',L'6',L'7',L'8',L'9',L'+',L'/',L'='
  260. };
  261. #define ICWCOMPLETEDKEY L"Completed"
  262. // 2/19/97 jmazner Olympus #1106 -- SAM/SBS integration
  263. WCHAR FAR cszSBSCFG_DLL[] = L"SBSCFG.DLL\0";
  264. CHAR FAR cszSBSCFG_CONFIGURE[] = "Configure\0";
  265. typedef DWORD (WINAPI * SBSCONFIGURE) (HWND hwnd, LPWSTR lpszINSFile, LPWSTR szConnectoidName);
  266. SBSCONFIGURE lpfnConfigure;
  267. // 09/02/98 Donaldm: Integrate with Connection Manager
  268. WCHAR FAR cszCMCFG_DLL[] = L"CMCFG32.DLL\0";
  269. CHAR FAR cszCMCFG_CONFIGURE[] = "CMConfig\0";
  270. CHAR FAR cszCMCFG_CONFIGUREEX[] = "CMConfigEx\0";
  271. typedef BOOL (WINAPI * CMCONFIGUREEX)(LPCWSTR lpszINSFile);
  272. typedef BOOL (WINAPI * CMCONFIGURE)(LPCWSTR lpszINSFile, LPCWSTR lpszConnectoidNams);
  273. CMCONFIGURE lpfnCMConfigure;
  274. CMCONFIGUREEX lpfnCMConfigureEx;
  275. #pragma data_seg()
  276. HRESULT InetGetAutodial(LPBOOL lpfEnable, LPWSTR lpszEntryName,
  277. DWORD cchEntryName)
  278. {
  279. HRESULT dwRet;
  280. HKEY hKey = NULL;
  281. MYASSERT(lpfEnable);
  282. MYASSERT(lpszEntryName);
  283. MYASSERT(cchEntryName);
  284. // Get the name of the connectoid set for autodial.
  285. // HKCU\RemoteAccess\InternetProfile
  286. dwRet = RegCreateKey(HKEY_CURRENT_USER, szRegPathRNAWizard, &hKey);
  287. if (ERROR_SUCCESS == dwRet)
  288. {
  289. DWORD dwType = REG_SZ;
  290. DWORD cbEntryName = BYTES_REQUIRED_BY_CCH(cchEntryName);
  291. dwRet = RegQueryValueEx(hKey, (LPWSTR) szRegValInternetProfile, 0, &dwType, (LPBYTE)lpszEntryName,
  292. &cbEntryName);
  293. RegCloseKey(hKey);
  294. }
  295. if (ERROR_SUCCESS != dwRet)
  296. {
  297. return dwRet;
  298. }
  299. // Get setting from registry that indicates whether autodialing is enabled.
  300. // HKCU\Software\Microsoft\Windows\CurrentVersion\InternetSettings\EnableAutodial
  301. dwRet = RegCreateKey(HKEY_CURRENT_USER, szRegPathInternetSettings, &hKey);
  302. if (ERROR_SUCCESS == dwRet)
  303. {
  304. DWORD dwType = REG_BINARY;
  305. DWORD dwNumber = 0L;
  306. DWORD dwSize = sizeof(dwNumber);
  307. dwRet = RegQueryValueEx(hKey, (LPWSTR) szRegValEnableAutodial, 0, &dwType, (LPBYTE)&dwNumber,
  308. &dwSize);
  309. if (ERROR_SUCCESS == dwRet)
  310. {
  311. *lpfEnable = dwNumber;
  312. }
  313. RegCloseKey(hKey);
  314. }
  315. return dwRet;
  316. }
  317. //*******************************************************************
  318. //
  319. // FUNCTION: InetSetAutodial
  320. //
  321. // PURPOSE: This function will set the autodial settings in the registry.
  322. //
  323. // PARAMETERS: fEnable - If set to TRUE, autodial will be enabled.
  324. // If set to FALSE, autodial will be disabled.
  325. // lpszEntryName - name of the phone book entry to set
  326. // for autodial. If this is "", the
  327. // entry is cleared. If NULL, it is not changed.
  328. //
  329. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  330. //
  331. // HISTORY:
  332. // 96/03/11 markdu Created.
  333. //
  334. //*******************************************************************
  335. HRESULT InetSetAutodial(BOOL fEnable, LPCWSTR lpszEntryName)
  336. {
  337. HRESULT dwRet = ERROR_SUCCESS;
  338. BOOL bRet = FALSE;
  339. // 2 seperate calls:
  340. HINSTANCE hInst = NULL;
  341. FARPROC fp = NULL;
  342. dwRet = ERROR_SUCCESS;
  343. hInst = LoadLibrary(cszWininet);
  344. if (hInst && lpszEntryName)
  345. {
  346. fp = GetProcAddress(hInst, cszInternetSetOption);
  347. if (fp)
  348. {
  349. WCHAR szNewDefaultConnection[RAS_MaxEntryName+1];
  350. lstrcpyn(szNewDefaultConnection, lpszEntryName, lstrlen(lpszEntryName)+1);
  351. bRet = ((INTERNETSETOPTION)fp) (NULL,
  352. INTERNET_OPTION_AUTODIAL_CONNECTION,
  353. szNewDefaultConnection,
  354. lstrlen(szNewDefaultConnection));
  355. if (bRet)
  356. {
  357. DWORD dwMode = AUTODIAL_MODE_ALWAYS;
  358. bRet = ((INTERNETSETOPTION)fp) (NULL, INTERNET_OPTION_AUTODIAL_MODE, &dwMode, sizeof(DWORD));
  359. }
  360. if( !bRet )
  361. {
  362. dwRet = GetLastError();
  363. }
  364. }
  365. else
  366. {
  367. dwRet = GetLastError();
  368. }
  369. }
  370. // From DarrnMi, INTERNETSETOPTION for autodial is new for 5.5.
  371. // We should try it this way and if the InternetSetOption fails (you'll get invalid option),
  372. // set the registry the old way. That'll work everywhere.
  373. if (!bRet)
  374. {
  375. HKEY hKey = NULL;
  376. // Set the name if given, else do not change the entry.
  377. if (lpszEntryName)
  378. {
  379. // Set the name of the connectoid for autodial.
  380. // HKCU\RemoteAccess\InternetProfile
  381. if (ERROR_SUCCESS == RegCreateKey(HKEY_CURRENT_USER, szRegPathRNAWizard, &hKey))
  382. {
  383. dwRet = RegSetValueEx(hKey, szRegValInternetProfile, 0, REG_SZ,
  384. (BYTE*)lpszEntryName, BYTES_REQUIRED_BY_SZ(lpszEntryName));
  385. RegCloseKey(hKey);
  386. }
  387. }
  388. hKey = NULL;
  389. if (ERROR_SUCCESS == dwRet)
  390. {
  391. // Set setting in the registry that indicates whether autodialing is enabled.
  392. // HKCC\Software\Microsoft\Windows\CurrentVersion\InternetSettings\EnableAutodial
  393. if (ERROR_SUCCESS == RegCreateKey(HKEY_CURRENT_CONFIG, szRegPathInternetSettings, &hKey))
  394. {
  395. dwRet = RegSetValueEx(hKey, szRegValEnableAutodial, 0, REG_DWORD,
  396. (BYTE*)&fEnable, sizeof(DWORD));
  397. RegCloseKey(hKey);
  398. }
  399. if (ERROR_SUCCESS == RegCreateKey(HKEY_LOCAL_MACHINE, szRegPathInternetSettings, &hKey))
  400. {
  401. dwRet = RegSetValueEx(hKey, szRegValEnableAutodial, 0, REG_DWORD,
  402. (BYTE*)&fEnable, sizeof(DWORD));
  403. RegCloseKey(hKey);
  404. }
  405. // Set setting in the registry that indicates whether autodialing is enabled.
  406. // HKCU\Software\Microsoft\Windows\CurrentVersion\InternetSettings\EnableAutodial
  407. if (ERROR_SUCCESS == RegCreateKey(HKEY_CURRENT_USER, szRegPathInternetSettings, &hKey))
  408. {
  409. BOOL bVal = FALSE;
  410. dwRet = RegSetValueEx(hKey, szRegValEnableAutodial, 0, REG_DWORD,
  411. (BYTE*)&fEnable, sizeof(DWORD));
  412. dwRet = RegSetValueEx(hKey, szRegValNoNetAutodial, 0, REG_DWORD,
  413. (BYTE*)&bVal, sizeof(DWORD));
  414. RegCloseKey(hKey);
  415. }
  416. }
  417. // 2/10/97 jmazner Normandy #9705, 13233 Notify wininet
  418. // when we change proxy or autodial
  419. if (fp)
  420. {
  421. if( !((INTERNETSETOPTION)fp) (NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0) )
  422. {
  423. dwRet = GetLastError();
  424. }
  425. }
  426. else
  427. {
  428. dwRet = GetLastError();
  429. }
  430. }
  431. if (hInst)
  432. {
  433. FreeLibrary(hInst);
  434. hInst = NULL;
  435. }
  436. return dwRet;
  437. }
  438. //+----------------------------------------------------------------------------
  439. //
  440. // Function: CallCMConfig
  441. //
  442. // Synopsis: Call into the Connection Manager dll's Configure function to allow CM to
  443. // process the .ins file as needed.
  444. //
  445. // Arguements: lpszINSFile -- full path to the .ins file
  446. //
  447. // Returns: TRUE if a CM profile is created, FALSE otherwise
  448. //
  449. // History: 09/02/98 DONALDM
  450. //
  451. //-----------------------------------------------------------------------------
  452. BOOL CINSHandler::CallCMConfig(LPCWSTR lpszINSFile)
  453. {
  454. HINSTANCE hCMDLL = NULL;
  455. BOOL bRet = FALSE;
  456. //// TraceMsg(TF_INSHANDLER, L"ICWCONN1: Calling LoadLibrary on %s\n", cszCMCFG_DLL);
  457. // Load DLL and entry point
  458. hCMDLL = LoadLibrary(cszCMCFG_DLL);
  459. if (NULL != hCMDLL)
  460. {
  461. // To determine whether we should call CMConfig or CMConfigEx
  462. ULONG ulBufferSize = 1024*10;
  463. // Parse the ISP section in the INI file to find query pair to append
  464. WCHAR *pszKeys = NULL;
  465. PWSTR pszKey = NULL;
  466. ULONG ulRetVal = 0;
  467. BOOL bEnumerate = TRUE;
  468. BOOL bUseEx = FALSE;
  469. PWSTR pszBuff = NULL;
  470. do
  471. {
  472. if (NULL != pszKeys)
  473. {
  474. delete [] pszKeys;
  475. ulBufferSize += ulBufferSize;
  476. }
  477. pszKeys = new WCHAR [ulBufferSize];
  478. if (NULL == pszKeys)
  479. {
  480. bEnumerate = FALSE;
  481. break;
  482. }
  483. ulRetVal = ::GetPrivateProfileString(NULL, NULL, L"", pszKeys, ulBufferSize, lpszINSFile);
  484. if (0 == ulRetVal)
  485. {
  486. bEnumerate = FALSE;
  487. break;
  488. }
  489. } while (ulRetVal == (ulBufferSize - 2));
  490. if (bEnumerate)
  491. {
  492. pszKey = pszKeys;
  493. while (*pszKey)
  494. {
  495. if (!lstrcmpi(pszKey, cszCMHeader))
  496. {
  497. bUseEx = TRUE;
  498. break;
  499. }
  500. pszKey += lstrlen(pszKey) + 1;
  501. }
  502. }
  503. if (pszKeys)
  504. delete [] pszKeys;
  505. WCHAR szConnectoidName[RAS_MaxEntryName];
  506. // Get the connectoid name from the [Entry] Section
  507. GetPrivateProfileString(cszEntrySection,
  508. cszEntryName,
  509. cszNull,
  510. szConnectoidName,
  511. RAS_MaxEntryName,
  512. lpszINSFile);
  513. if (bUseEx)
  514. {
  515. // Call CMConfigEx
  516. lpfnCMConfigureEx = (CMCONFIGUREEX)GetProcAddress(hCMDLL, cszCMCFG_CONFIGUREEX);
  517. if( lpfnCMConfigureEx )
  518. {
  519. bRet = lpfnCMConfigureEx(lpszINSFile);
  520. }
  521. }
  522. else
  523. {
  524. // Call CMConfig
  525. lpfnCMConfigure = (CMCONFIGURE)GetProcAddress(hCMDLL, cszCMCFG_CONFIGURE);
  526. // Call function
  527. if( lpfnCMConfigure )
  528. {
  529. bRet = lpfnCMConfigure(lpszINSFile, szConnectoidName);
  530. }
  531. }
  532. if (bRet)
  533. {
  534. // restore original autodial settings
  535. SetDefaultConnectoid(AutodialTypeAlways, szConnectoidName);
  536. }
  537. }
  538. // Cleanup
  539. if( hCMDLL )
  540. FreeLibrary(hCMDLL);
  541. if( lpfnCMConfigure )
  542. lpfnCMConfigure = NULL;
  543. // TraceMsg(TF_INSHANDLER, L"ICWCONN1: CallSBSConfig exiting with error code %d \n", bRet);
  544. return bRet;
  545. }
  546. //+----------------------------------------------------------------------------
  547. //
  548. // Function: CallSBSConfig
  549. //
  550. // Synopsis: Call into the SBSCFG dll's Configure function to allow SBS to
  551. // process the .ins file as needed
  552. //
  553. // Arguements: hwnd -- hwnd of parent, in case sbs wants to put up messages
  554. // lpszINSFile -- full path to the .ins file
  555. //
  556. // Returns: windows error code that sbscfg returns.
  557. //
  558. // History: 2/19/97 jmazner Created for Olympus #1106
  559. //
  560. //-----------------------------------------------------------------------------
  561. DWORD CINSHandler::CallSBSConfig(HWND hwnd, LPCWSTR lpszINSFile)
  562. {
  563. HINSTANCE hSBSDLL = NULL;
  564. DWORD dwRet = ERROR_SUCCESS;
  565. WCHAR lpszConnectoidName[RAS_MaxEntryName] = L"nogood\0";
  566. //
  567. // Get name of connectoid we created by looking in autodial
  568. // We need to pass this name into SBSCFG
  569. // 5/14/97 jmazner Windosw NT Bugs #87209
  570. //
  571. BOOL fEnabled = FALSE;
  572. dwRet = InetGetAutodial(&fEnabled, lpszConnectoidName, RAS_MaxEntryName);
  573. // TraceMsg(TF_INSHANDLER, L"ICWCONN1: Calling LoadLibrary on %s\n", cszSBSCFG_DLL);
  574. hSBSDLL = LoadLibrary(cszSBSCFG_DLL);
  575. // Load DLL and entry point
  576. if (NULL != hSBSDLL)
  577. {
  578. // TraceMsg(TF_INSHANDLER, L"ICWCONN1: Calling GetProcAddress on %s\n", cszSBSCFG_CONFIGURE);
  579. lpfnConfigure = (SBSCONFIGURE)GetProcAddress(hSBSDLL, cszSBSCFG_CONFIGURE);
  580. }
  581. else
  582. {
  583. // 4/2/97 ChrisK Olympus 2759
  584. // If the DLL can't be loaded, pick a specific error message to return.
  585. dwRet = ERROR_DLL_NOT_FOUND;
  586. goto CallSBSConfigExit;
  587. }
  588. // Call function
  589. if( hSBSDLL && lpfnConfigure )
  590. {
  591. // TraceMsg(TF_INSHANDLER, L"ICWCONN1: Calling the Configure entry point: %s, %s\n", lpszINSFile, lpszConnectoidName);
  592. dwRet = lpfnConfigure(hwnd, (WCHAR *)lpszINSFile, lpszConnectoidName);
  593. }
  594. else
  595. {
  596. // TraceMsg(TF_INSHANDLER, L"ICWCONN1: Unable to call the Configure entry point\n");
  597. dwRet = GetLastError();
  598. }
  599. CallSBSConfigExit:
  600. if( hSBSDLL )
  601. FreeLibrary(hSBSDLL);
  602. if( lpfnConfigure )
  603. lpfnConfigure = NULL;
  604. // TraceMsg(TF_INSHANDLER, L"ICWCONN1: CallSBSConfig exiting with error code %d \n", dwRet);
  605. return dwRet;
  606. }
  607. BOOL CINSHandler::SetICWCompleted( DWORD dwCompleted )
  608. {
  609. HKEY hKey = NULL;
  610. HRESULT hr = RegCreateKey(HKEY_CURRENT_USER, ICWSETTINGSPATH, &hKey);
  611. if (ERROR_SUCCESS == hr)
  612. {
  613. hr = RegSetValueEx(hKey, ICWCOMPLETEDKEY, 0, REG_DWORD,
  614. (CONST BYTE*)&dwCompleted, sizeof(dwCompleted));
  615. RegCloseKey(hKey);
  616. }
  617. if( ERROR_SUCCESS == hr )
  618. return TRUE;
  619. else
  620. return FALSE;
  621. }
  622. /////////////////////////////////////////////////////////////////////////////
  623. #define FILE_BUFFER_SIZE 65534
  624. #ifndef FILE_BEGIN
  625. #define FILE_BEGIN 0
  626. #endif
  627. //+---------------------------------------------------------------------------
  628. //
  629. // Function: MassageFile
  630. //
  631. // Synopsis: Convert lone carriage returns to CR/LF pairs.
  632. //
  633. // Note: The file is ANSI because these need to be shared with Win9X.
  634. //
  635. //+---------------------------------------------------------------------------
  636. HRESULT CINSHandler::MassageFile(LPCWSTR lpszFile)
  637. {
  638. LPBYTE lpBufferIn;
  639. LPBYTE lpBufferOut;
  640. HANDLE hfile;
  641. HRESULT hr = ERROR_SUCCESS;
  642. if (!SetFileAttributes(lpszFile, FILE_ATTRIBUTE_NORMAL))
  643. {
  644. return GetLastError();
  645. }
  646. lpBufferIn = (LPBYTE) GlobalAlloc(GPTR, 2 * FILE_BUFFER_SIZE);
  647. if (NULL == lpBufferIn)
  648. {
  649. return ERROR_OUTOFMEMORY;
  650. }
  651. lpBufferOut = lpBufferIn + FILE_BUFFER_SIZE;
  652. hfile = CreateFile(lpszFile,
  653. GENERIC_READ | GENERIC_WRITE,
  654. FILE_SHARE_READ,
  655. NULL, // security attributes
  656. OPEN_EXISTING,
  657. FILE_ATTRIBUTE_NORMAL,
  658. NULL);
  659. if (INVALID_HANDLE_VALUE != hfile)
  660. {
  661. BOOL fChanged = FALSE;
  662. DWORD cbOut = 0;
  663. DWORD cbIn = 0;
  664. if (ReadFile(hfile,
  665. lpBufferIn,
  666. FILE_BUFFER_SIZE - 1,
  667. &cbIn,
  668. NULL
  669. )
  670. )
  671. // Note: we asume, in our use of lpCharIn, that the file is always less than
  672. // FILE_BUFFER_SIZE
  673. {
  674. LPBYTE lpCharIn = lpBufferIn;
  675. LPBYTE lpCharOut = lpBufferOut;
  676. while ((*lpCharIn) && (FILE_BUFFER_SIZE - 2 > cbOut))
  677. {
  678. *lpCharOut++ = *lpCharIn;
  679. cbOut++;
  680. if (('\r' == *lpCharIn) && ('\n' != *(lpCharIn + 1)))
  681. {
  682. fChanged = TRUE;
  683. *lpCharOut++ = '\n';
  684. cbOut++;
  685. }
  686. lpCharIn++;
  687. }
  688. if (fChanged)
  689. {
  690. LARGE_INTEGER lnOffset = {0,0};
  691. if (SetFilePointerEx(hfile, lnOffset, NULL, FILE_BEGIN))
  692. {
  693. DWORD cbWritten = 0;
  694. if (! WriteFile(hfile,
  695. lpBufferOut,
  696. cbOut,
  697. &cbWritten,
  698. NULL
  699. )
  700. )
  701. {
  702. hr = GetLastError();
  703. }
  704. }
  705. else
  706. {
  707. hr = GetLastError();
  708. }
  709. }
  710. }
  711. else
  712. {
  713. hr = GetLastError();
  714. }
  715. CloseHandle(hfile);
  716. }
  717. else
  718. {
  719. hr = GetLastError();
  720. }
  721. GlobalFree((HGLOBAL)lpBufferIn);
  722. return ERROR_SUCCESS;
  723. }
  724. DWORD CINSHandler::RunExecutable(void)
  725. {
  726. DWORD dwRet;
  727. SHELLEXECUTEINFO sei;
  728. // Hide the active window first
  729. HWND hWndHide = GetActiveWindow();
  730. ::ShowWindow(hWndHide, SW_HIDE);
  731. sei.cbSize = sizeof(sei);
  732. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  733. sei.hwnd = NULL;
  734. sei.lpVerb = cszOpen;
  735. sei.lpFile = m_szRunExecutable;
  736. sei.lpParameters = m_szRunArgument;
  737. sei.lpDirectory = NULL;
  738. sei.nShow = SW_SHOWNORMAL;
  739. sei.hInstApp = NULL;
  740. // Optional members
  741. sei.hProcess = NULL;
  742. if (ShellExecuteEx(&sei))
  743. {
  744. DWORD iWaitResult = 0;
  745. // wait for event or msgs. Dispatch msgs. Exit when event is signalled.
  746. while((iWaitResult=MsgWaitForMultipleObjects(1, &sei.hProcess, FALSE, INFINITE, QS_ALLINPUT))==(WAIT_OBJECT_0 + 1))
  747. {
  748. MSG msg ;
  749. // read all of the messages in this next loop
  750. // removing each message as we read it
  751. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  752. {
  753. if (msg.message == WM_QUIT)
  754. {
  755. CloseHandle(sei.hProcess);
  756. return NO_ERROR;
  757. }
  758. else
  759. DispatchMessage(&msg);
  760. }
  761. }
  762. CloseHandle(sei.hProcess);
  763. dwRet = ERROR_SUCCESS;
  764. }
  765. else
  766. {
  767. dwRet = GetLastError();
  768. }
  769. ::ShowWindow(hWndHide, SW_SHOW);
  770. return dwRet;
  771. }
  772. void CINSHandler::SaveAutoDial(void)
  773. {
  774. // if the original autodial settings have not been saved
  775. if (!m_fAutodialSaved)
  776. {
  777. // save the current autodial settings
  778. InetGetAutodial(
  779. &m_fAutodialEnabled,
  780. m_szAutodialConnection,
  781. sizeof(m_szAutodialConnection));
  782. m_fAutodialSaved = TRUE;
  783. }
  784. }
  785. void CINSHandler::RestoreAutoDial(void)
  786. {
  787. if (m_fAutodialSaved)
  788. {
  789. // restore original autodial settings
  790. AUTODIAL_TYPE eType =
  791. m_fAutodialEnabled ? AutodialTypeAlways : AutodialTypeNever;
  792. SetDefaultConnectoid(eType, m_szAutodialConnection);
  793. m_fAutodialSaved = FALSE;
  794. }
  795. }
  796. BOOL CINSHandler::KeepConnection(LPCWSTR lpszFile)
  797. {
  798. WCHAR szTemp[10];
  799. GetPrivateProfileString(cszCustomSection,
  800. cszKeepConnection,
  801. cszNo,
  802. szTemp,
  803. MAX_CHARS_IN_BUFFER(szTemp),
  804. lpszFile);
  805. return (!lstrcmpi(szTemp, cszYes));
  806. }
  807. DWORD CINSHandler::ImportCustomInfo
  808. (
  809. LPCWSTR lpszImportFile,
  810. LPWSTR lpszExecutable,
  811. DWORD cchExecutable,
  812. LPWSTR lpszArgument,
  813. DWORD cchArgument
  814. )
  815. {
  816. GetPrivateProfileString(cszCustomSection,
  817. cszRun,
  818. cszNull,
  819. lpszExecutable,
  820. (int)cchExecutable,
  821. lpszImportFile);
  822. GetPrivateProfileString(cszCustomSection,
  823. cszArgument,
  824. cszNull,
  825. lpszArgument,
  826. (int)cchArgument,
  827. lpszImportFile);
  828. return ERROR_SUCCESS;
  829. }
  830. DWORD CINSHandler::ImportFile
  831. (
  832. LPCWSTR lpszImportFile,
  833. LPCWSTR lpszSection,
  834. LPCWSTR lpszOutputFile
  835. )
  836. {
  837. HANDLE hScriptFile = INVALID_HANDLE_VALUE;
  838. LPWSTR pszLine, pszFile;
  839. int i, iMaxLine;
  840. UINT cch;
  841. DWORD cbRet;
  842. DWORD dwRet = ERROR_SUCCESS;
  843. // Allocate a buffer for the file
  844. if ((pszFile = (LPWSTR)LocalAlloc(LMEM_FIXED, CCH_ReadBuf * sizeof(WCHAR))) == NULL)
  845. {
  846. return ERROR_OUTOFMEMORY;
  847. }
  848. // Look for script
  849. if (GetPrivateProfileString(lpszSection,
  850. NULL,
  851. szNull,
  852. pszFile,
  853. CCH_ReadBuf,
  854. lpszImportFile) != 0)
  855. {
  856. // Get the maximum line number
  857. pszLine = pszFile;
  858. iMaxLine = -1;
  859. while (*pszLine)
  860. {
  861. i = _wtoi(pszLine);
  862. iMaxLine = max(iMaxLine, i);
  863. pszLine += lstrlen(pszLine)+1;
  864. };
  865. // If we have at least one line, we will import the script file
  866. if (iMaxLine >= 0)
  867. {
  868. // Create the script file
  869. hScriptFile = CreateFile(lpszOutputFile,
  870. GENERIC_READ | GENERIC_WRITE,
  871. FILE_SHARE_READ,
  872. NULL, // security attributes
  873. CREATE_ALWAYS,
  874. FILE_ATTRIBUTE_NORMAL,
  875. NULL
  876. );
  877. if (INVALID_HANDLE_VALUE != hScriptFile)
  878. {
  879. WCHAR szLineNum[MAXLONGLEN+1];
  880. // From The first line to the last line
  881. for (i = 0; i <= iMaxLine; i++)
  882. {
  883. // Read the script line
  884. wsprintf(szLineNum, L"%d", i);
  885. if ((cch = GetPrivateProfileString(lpszSection,
  886. szLineNum,
  887. szNull,
  888. pszLine,
  889. CCH_ReadBuf,
  890. lpszImportFile)) != 0)
  891. {
  892. // Write to the script file
  893. lstrcat(pszLine, L"\x0d\x0a");
  894. if (! WriteFile(hScriptFile,
  895. pszLine,
  896. BYTES_REQUIRED_BY_CCH(cch + 2),
  897. &cbRet,
  898. NULL
  899. )
  900. )
  901. {
  902. dwRet = GetLastError();
  903. break;
  904. }
  905. }
  906. }
  907. CloseHandle(hScriptFile);
  908. }
  909. else
  910. {
  911. dwRet = GetLastError();
  912. }
  913. }
  914. else
  915. {
  916. dwRet = ERROR_NOT_FOUND;
  917. }
  918. }
  919. else
  920. {
  921. dwRet = ERROR_NOT_FOUND;
  922. }
  923. LocalFree(pszFile);
  924. return dwRet;
  925. }
  926. DWORD CINSHandler::ImportCustomFile
  927. (
  928. LPCWSTR lpszImportFile
  929. )
  930. {
  931. WCHAR szFile[_MAX_PATH];
  932. WCHAR szTemp[_MAX_PATH];
  933. // If a custom file name does not exist, do nothing
  934. if (GetPrivateProfileString(cszCustomSection,
  935. cszFileName,
  936. cszNull,
  937. szTemp,
  938. MAX_CHARS_IN_BUFFER(szTemp),
  939. lpszImportFile) == 0)
  940. {
  941. return ERROR_SUCCESS;
  942. };
  943. GetWindowsDirectory(szFile, MAX_CHARS_IN_BUFFER(szFile));
  944. if (*CharPrev(szFile, szFile + lstrlen(szFile)) != L'\\')
  945. {
  946. lstrcat(szFile, L"\\");
  947. }
  948. lstrcat(szFile, szTemp);
  949. return (ImportFile(lpszImportFile, cszCustomFileSection, szFile));
  950. }
  951. BOOL CINSHandler::LoadExternalFunctions(void)
  952. {
  953. BOOL bRet = FALSE;
  954. do
  955. {
  956. // Load the Brading library functions
  957. m_hBranding = LoadLibrary(L"IEDKCS32.DLL");
  958. if (m_hBranding != NULL)
  959. {
  960. if (NULL == (m_lpfnBrandICW2 = (PFNBRANDICW2)GetProcAddress(m_hBranding, "BrandICW2")))
  961. break;
  962. }
  963. else
  964. {
  965. break;
  966. }
  967. if( IsNT() )
  968. {
  969. // Load the RAS functions
  970. m_hRAS = LoadLibrary(L"RASAPI32.DLL");
  971. if (m_hRAS != NULL)
  972. {
  973. if (NULL == (m_lpfnRasSetAutodialEnable = (PFNRASSETAUTODIALENABLE)GetProcAddress(m_hRAS, "RasSetAutodialEnableA")))
  974. break;
  975. if (NULL == (m_lpfnRasSetAutodialAddress = (PFNRASSETAUTODIALADDRESS)GetProcAddress(m_hRAS, "RasSetAutodialAddressA")))
  976. break;
  977. }
  978. else
  979. {
  980. break;
  981. }
  982. }
  983. // Success if we get to here
  984. bRet = TRUE;
  985. break;
  986. } while(1);
  987. return bRet;
  988. }
  989. //-----------------------------------------------------------------------------
  990. // OpenIcwRmindKey
  991. //-----------------------------------------------------------------------------
  992. BOOL CINSHandler::OpenIcwRmindKey(HKEY* phkey)
  993. {
  994. // This method will open the IcwRmind key in the registry. If the key
  995. // does not exist it will be created here.
  996. LONG lResult = ERROR_SUCCESS;
  997. if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, cszKeyIcwRmind, 0, KEY_READ | KEY_WRITE, phkey))
  998. {
  999. lResult = RegCreateKey(HKEY_LOCAL_MACHINE, cszKeyIcwRmind, phkey);
  1000. }
  1001. return ( ERROR_SUCCESS == lResult );
  1002. }
  1003. BOOL CINSHandler::ConfigureTrialReminder
  1004. (
  1005. LPCWSTR lpszFile
  1006. )
  1007. {
  1008. WCHAR szISPName[MAX_ISP_NAME];
  1009. WCHAR szISPMsg[MAX_ISP_MSG];
  1010. WCHAR szISPPhoneNumber[MAX_ISP_PHONENUMBER];
  1011. int iTrialDays;
  1012. WCHAR szConvertURL[INTERNET_MAX_URL_LENGTH];
  1013. WCHAR szExpiredISPFileURL[INTERNET_MAX_URL_LENGTH];
  1014. WCHAR szExpiredISPFileName[MAX_PATH]; // The fully qualified path to the final INS file
  1015. WCHAR szISPFile[MAX_PATH]; // The name we get in the INS
  1016. WCHAR szConnectoidName[MAXNAME];
  1017. if (GetPrivateProfileString(cszTrialRemindSection,
  1018. cszEntryISPName,
  1019. cszNull,
  1020. szISPName,
  1021. MAX_CHARS_IN_BUFFER(szISPName),
  1022. lpszFile) == 0)
  1023. {
  1024. return FALSE;
  1025. }
  1026. if (GetPrivateProfileString(cszTrialRemindSection,
  1027. cszEntryISPPhone,
  1028. cszNull,
  1029. szISPPhoneNumber,
  1030. MAX_CHARS_IN_BUFFER(szISPPhoneNumber),
  1031. lpszFile) == 0)
  1032. {
  1033. return FALSE;
  1034. }
  1035. if ((iTrialDays = GetPrivateProfileInt(cszTrialRemindSection,
  1036. cszEntryTrialDays,
  1037. 0,
  1038. lpszFile)) == 0)
  1039. {
  1040. return FALSE;
  1041. }
  1042. if (GetPrivateProfileString(cszTrialRemindSection,
  1043. cszEntrySignupURL,
  1044. cszNull,
  1045. szConvertURL,
  1046. MAX_CHARS_IN_BUFFER(szConvertURL),
  1047. lpszFile) == 0)
  1048. {
  1049. return FALSE;
  1050. }
  1051. //optional
  1052. GetPrivateProfileString(cszTrialRemindSection,
  1053. cszEntryISPMsg,
  1054. cszNull,
  1055. szISPMsg,
  1056. MAX_CHARS_IN_BUFFER(szISPMsg),
  1057. lpszFile);
  1058. // Get the connectoid name from the [Entry] Section
  1059. if (GetPrivateProfileString(cszEntrySection,
  1060. cszEntry_Name,
  1061. cszNull,
  1062. szConnectoidName,
  1063. MAX_CHARS_IN_BUFFER(szConnectoidName),
  1064. lpszFile) == 0)
  1065. {
  1066. return FALSE;
  1067. }
  1068. // If we get to here, we have everything to setup a trial, so let's do it.
  1069. HKEY hkey;
  1070. if (OpenIcwRmindKey(&hkey))
  1071. {
  1072. // Set the values we have
  1073. RegSetValueEx(hkey, cszEntryISPName, 0, REG_SZ, LPBYTE(szISPName), BYTES_REQUIRED_BY_SZ((LPWSTR)szISPName) );
  1074. RegSetValueEx(hkey, cszEntryISPMsg, 0, REG_SZ, LPBYTE(szISPMsg), BYTES_REQUIRED_BY_SZ((LPWSTR)szISPMsg) );
  1075. RegSetValueEx(hkey, cszEntryISPPhone, 0, REG_SZ, LPBYTE(szISPPhoneNumber), BYTES_REQUIRED_BY_SZ((LPWSTR)szISPPhoneNumber) );
  1076. RegSetValueEx(hkey, cszEntryTrialDays, 0, REG_DWORD, (LPBYTE)&iTrialDays, sizeof(DWORD) + 1);
  1077. RegSetValueEx(hkey, cszEntrySignupURL, 0, REG_SZ, LPBYTE(szConvertURL), BYTES_REQUIRED_BY_SZ((LPWSTR)szConvertURL) );
  1078. RegSetValueEx(hkey, cszEntryConnectoidName, 0, REG_SZ, LPBYTE(szConnectoidName), BYTES_REQUIRED_BY_SZ((LPWSTR)szConnectoidName) );
  1079. // See if we have to create an ISP file
  1080. if (GetPrivateProfileString(cszTrialRemindSection,
  1081. cszEntryExpiredISPFileName,
  1082. cszNull,
  1083. szISPFile,
  1084. MAX_CHARS_IN_BUFFER(szISPFile),
  1085. lpszFile) != 0)
  1086. {
  1087. // Set the fully qualified path for the ISP file name
  1088. WCHAR szAppDir[MAX_PATH];
  1089. LPWSTR p;
  1090. if (GetModuleFileName(GetModuleHandle(L"msobcomm.ldl"), szAppDir, MAX_PATH))
  1091. {
  1092. p = &szAppDir[lstrlen(szAppDir)-1];
  1093. while (*p != L'\\' && p >= szAppDir)
  1094. p--;
  1095. if (*p == L'\\') *(p++) = L'\0';
  1096. }
  1097. wsprintf(szExpiredISPFileName, L"%s\\%s",szAppDir,szISPFile);
  1098. if (GetPrivateProfileString(cszTrialRemindSection,
  1099. cszSignupExpiredISPURL,
  1100. cszNull,
  1101. szExpiredISPFileURL,
  1102. MAX_CHARS_IN_BUFFER(szExpiredISPFileURL),
  1103. lpszFile) != 0)
  1104. {
  1105. // Download the ISP file, and then copy its contents
  1106. CWebGate WebGate;
  1107. BSTR bstrURL;
  1108. BSTR bstrFname;
  1109. BOOL bRetVal;
  1110. // Setup the webGate object, and download the ISP file
  1111. bstrURL = SysAllocString(szExpiredISPFileURL);
  1112. WebGate.put_Path(bstrURL);
  1113. SysFreeString(bstrURL);
  1114. WebGate.FetchPage(1, &bRetVal);
  1115. if (bRetVal)
  1116. {
  1117. WebGate.get_DownloadFname(&bstrFname);
  1118. // Copy the file from the temp location, making sure one does not
  1119. // yet exist
  1120. DeleteFile(szExpiredISPFileName);
  1121. MoveFile(bstrFname, szExpiredISPFileName);
  1122. SysFreeString(bstrFname);
  1123. // Write the new file to the registry
  1124. RegSetValueEx(hkey, cszEntrySignupURLTrialOver, 0, REG_SZ, LPBYTE(szExpiredISPFileName), BYTES_REQUIRED_BY_SZ((LPWSTR)szExpiredISPFileName) );
  1125. }
  1126. }
  1127. }
  1128. // The key was opened inside OpenIcwRmindKey, close it here.
  1129. RegCloseKey(hkey);
  1130. }
  1131. return TRUE;
  1132. }
  1133. DWORD CINSHandler::ImportBrandingInfo
  1134. (
  1135. LPCWSTR lpszFile,
  1136. LPCWSTR lpszConnectoidName
  1137. )
  1138. {
  1139. USES_CONVERSION;
  1140. WCHAR szPath[_MAX_PATH + 1];
  1141. MYASSERT(m_lpfnBrandICW2 != NULL);
  1142. GetWindowsDirectory(szPath, MAX_CHARS_IN_BUFFER(szPath));
  1143. m_lpfnBrandICW2(W2A(lpszFile), W2A(szPath), m_dwBrandFlags, W2A(lpszConnectoidName));
  1144. return ERROR_SUCCESS;
  1145. }
  1146. DWORD CINSHandler::ReadClientInfo
  1147. (
  1148. LPCWSTR lpszFile,
  1149. LPINETCLIENTINFO lpClientInfo,
  1150. LPCLIENT_TABLE lpClientTable
  1151. )
  1152. {
  1153. LPCLIENT_TABLE lpTable;
  1154. for (lpTable = lpClientTable; NULL != lpTable->lpszSection; ++lpTable)
  1155. {
  1156. GetPrivateProfileString(lpTable->lpszSection,
  1157. lpTable->lpszValue,
  1158. cszNull,
  1159. (LPWSTR)((LPBYTE)lpClientInfo + lpTable->uOffset),
  1160. lpTable->uSize,
  1161. lpszFile);
  1162. }
  1163. lpClientInfo->dwFlags = 0;
  1164. if (*lpClientInfo->szPOPLogonName)
  1165. {
  1166. lpClientInfo->dwFlags |= INETC_LOGONMAIL;
  1167. }
  1168. if ((*lpClientInfo->szNNTPLogonName) || (*lpClientInfo->szNNTPServer))
  1169. {
  1170. lpClientInfo->dwFlags |= INETC_LOGONNEWS;
  1171. }
  1172. return ERROR_SUCCESS;
  1173. }
  1174. BOOL CINSHandler::WantsExchangeInstalled(LPCWSTR lpszFile)
  1175. {
  1176. WCHAR szTemp[10];
  1177. GetPrivateProfileString(cszEMailSection,
  1178. cszUseExchange,
  1179. cszNo,
  1180. szTemp,
  1181. MAX_CHARS_IN_BUFFER(szTemp),
  1182. lpszFile);
  1183. return (!lstrcmpi(szTemp, cszYes));
  1184. }
  1185. BOOL CINSHandler::DisplayPassword(LPCWSTR lpszFile)
  1186. {
  1187. WCHAR szTemp[10];
  1188. GetPrivateProfileString(cszUserSection,
  1189. cszDisplayPassword,
  1190. cszNo,
  1191. szTemp,
  1192. MAX_CHARS_IN_BUFFER(szTemp),
  1193. lpszFile);
  1194. return (!lstrcmpi(szTemp, cszYes));
  1195. }
  1196. DWORD CINSHandler::ImportClientInfo
  1197. (
  1198. LPCWSTR lpszFile,
  1199. LPINETCLIENTINFO lpClientInfo
  1200. )
  1201. {
  1202. DWORD dwRet;
  1203. lpClientInfo->dwSize = sizeof(INETCLIENTINFO);
  1204. dwRet = ReadClientInfo(lpszFile, lpClientInfo, iniTable);
  1205. return dwRet;
  1206. }
  1207. DWORD CINSHandler::ConfigureClient
  1208. (
  1209. HWND hwnd,
  1210. LPCWSTR lpszFile,
  1211. LPBOOL lpfNeedsRestart,
  1212. LPBOOL lpfConnectoidCreated,
  1213. BOOL fHookAutodial,
  1214. LPWSTR szConnectoidName,
  1215. DWORD dwConnectoidNameSize
  1216. )
  1217. {
  1218. LPICONNECTION pConn = NULL;
  1219. LPINETCLIENTINFO pClientInfo = NULL;
  1220. DWORD dwRet = ERROR_SUCCESS;
  1221. UINT cb = sizeof(ICONNECTION) + sizeof(INETCLIENTINFO);
  1222. DWORD dwfOptions = INETCFG_INSTALLTCP | INETCFG_WARNIFSHARINGBOUND;
  1223. LPRASINFO pRasInfo = NULL;
  1224. LPRASENTRY pRasEntry = NULL;
  1225. RNAAPI Rnaapi;
  1226. LPBYTE lpDeviceInfo = NULL;
  1227. DWORD dwDeviceInfoSize = 0;
  1228. BOOL lpfNeedsRestartLan = FALSE;
  1229. //
  1230. // ChrisK Olympus 4756 5/25/97
  1231. // Do not display busy animation on Win95
  1232. //
  1233. if (!m_bSilentMode && IsNT())
  1234. {
  1235. dwfOptions |= INETCFG_SHOWBUSYANIMATION;
  1236. }
  1237. // Allocate a buffer for connection and clientinfo objects
  1238. if ((pConn = (LPICONNECTION)LocalAlloc(LPTR, cb)) == NULL)
  1239. {
  1240. return ERROR_OUTOFMEMORY;
  1241. }
  1242. if (WantsExchangeInstalled(lpszFile))
  1243. {
  1244. dwfOptions |= INETCFG_INSTALLMAIL;
  1245. }
  1246. // Create either a CM profile, or a connectoid
  1247. if (CallCMConfig(lpszFile))
  1248. {
  1249. *lpfConnectoidCreated = TRUE; // A dialup connection was created
  1250. }
  1251. else
  1252. {
  1253. switch ( InetSGetConnectionType ( lpszFile ) ) {
  1254. case InetS_RASModem :
  1255. case InetS_RASIsdn :
  1256. {
  1257. break;
  1258. }
  1259. case InetS_RASAtm :
  1260. {
  1261. lpDeviceInfo = (LPBYTE) malloc ( sizeof (ATMPBCONFIG) );
  1262. if ( !lpDeviceInfo )
  1263. {
  1264. return ERROR_NOT_ENOUGH_MEMORY;
  1265. }
  1266. dwDeviceInfoSize = sizeof( ATMPBCONFIG );
  1267. break;
  1268. }
  1269. case InetS_LANCable :
  1270. {
  1271. DWORD nRetVal = 0;
  1272. LANINFO LanInfo;
  1273. memset ( &LanInfo, 0, sizeof (LANINFO) );
  1274. LanInfo.dwSize = sizeof (LanInfo);
  1275. if ((nRetVal = InetSImportLanConnection (LanInfo, lpszFile)) != ERROR_SUCCESS )
  1276. {
  1277. return nRetVal;
  1278. }
  1279. if ((nRetVal = InetSSetLanConnection (LanInfo)) != ERROR_SUCCESS )
  1280. {
  1281. return nRetVal;
  1282. }
  1283. lpfNeedsRestartLan = TRUE;
  1284. goto next_step; // skip the RAS processing code.
  1285. break; // not reached, of course
  1286. }
  1287. case InetS_LAN1483 :
  1288. {
  1289. DWORD nRetVal = 0;
  1290. RFC1483INFO Rfc1483Info;
  1291. memset ( &Rfc1483Info, 0, sizeof (RFC1483INFO) );
  1292. Rfc1483Info.dwSize = sizeof ( Rfc1483Info );
  1293. // first, we determine the size of the buffer required
  1294. // to hold the 1483 settings.
  1295. if ((nRetVal = InetSImportRfc1483Connection (Rfc1483Info, lpszFile)) != ERROR_SUCCESS ) {
  1296. return nRetVal;
  1297. }
  1298. // verify that the size has been returned.
  1299. if ( !Rfc1483Info.Rfc1483Module.dwRegSettingsBufSize )
  1300. {
  1301. return E_FAIL;
  1302. }
  1303. // we create the buffer.
  1304. if ( !(Rfc1483Info.Rfc1483Module.lpbRegSettingsBuf = (LPBYTE) malloc ( Rfc1483Info.Rfc1483Module.dwRegSettingsBufSize ) ))
  1305. {
  1306. return ERROR_OUTOFMEMORY;
  1307. }
  1308. // we call the function again with the correct settings.
  1309. if ((nRetVal = InetSImportRfc1483Connection (Rfc1483Info, lpszFile)) != ERROR_SUCCESS ) {
  1310. free(Rfc1483Info.Rfc1483Module.lpbRegSettingsBuf);
  1311. return nRetVal;
  1312. }
  1313. // we place the imported settings in the registry.
  1314. if ((nRetVal = InetSSetRfc1483Connection (Rfc1483Info) ) != ERROR_SUCCESS ) {
  1315. free(Rfc1483Info.Rfc1483Module.lpbRegSettingsBuf);
  1316. return nRetVal;
  1317. }
  1318. // we clean up.
  1319. free(Rfc1483Info.Rfc1483Module.lpbRegSettingsBuf);
  1320. lpfNeedsRestartLan = TRUE;
  1321. goto next_step; // skip RAS processing code.
  1322. break; // not reached
  1323. }
  1324. case InetS_LANPppoe :
  1325. {
  1326. DWORD nRetVal = 0;
  1327. PPPOEINFO PppoeInfo;
  1328. memset ( &PppoeInfo, 0, sizeof (RFC1483INFO) );
  1329. PppoeInfo.dwSize = sizeof ( PppoeInfo );
  1330. // first, we determine the size of the buffer required
  1331. // to hold the 1483 settings.
  1332. if ((nRetVal = InetSImportPppoeConnection (PppoeInfo, lpszFile)) != ERROR_SUCCESS ) {
  1333. return nRetVal;
  1334. }
  1335. // verify that the size has been returned.
  1336. if ( !PppoeInfo.PppoeModule.dwRegSettingsBufSize )
  1337. {
  1338. return E_FAIL;
  1339. }
  1340. // we create the buffer.
  1341. if ( !(PppoeInfo.PppoeModule.lpbRegSettingsBuf = (LPBYTE) malloc ( PppoeInfo.PppoeModule.dwRegSettingsBufSize ) ))
  1342. {
  1343. return ERROR_OUTOFMEMORY;
  1344. }
  1345. // we call the function again with the correct settings.
  1346. if ((nRetVal = InetSImportPppoeConnection (PppoeInfo, lpszFile)) != ERROR_SUCCESS ) {
  1347. free(PppoeInfo.PppoeModule.lpbRegSettingsBuf);
  1348. return nRetVal;
  1349. }
  1350. // we place the imported settings in the registry.
  1351. if ((nRetVal = InetSSetPppoeConnection (PppoeInfo) ) != ERROR_SUCCESS ) {
  1352. free(PppoeInfo.PppoeModule.lpbRegSettingsBuf);
  1353. return nRetVal;
  1354. }
  1355. // we clean up.
  1356. free(PppoeInfo.PppoeModule.lpbRegSettingsBuf);
  1357. lpfNeedsRestartLan = TRUE;
  1358. goto next_step; // skip RAS processing code.
  1359. break; // not reached
  1360. }
  1361. default:
  1362. break;
  1363. }
  1364. dwRet = ImportConnection(lpszFile, pConn, lpDeviceInfo, &dwDeviceInfoSize);
  1365. if (ERROR_SUCCESS == dwRet)
  1366. {
  1367. pRasEntry = &pConn->RasEntry;
  1368. dwfOptions |= INETCFG_SETASAUTODIAL |
  1369. INETCFG_INSTALLRNA |
  1370. INETCFG_INSTALLMODEM;
  1371. }
  1372. else if (ERROR_CANNOT_FIND_PHONEBOOK_ENTRY != dwRet)
  1373. {
  1374. free (lpDeviceInfo);
  1375. return dwRet;
  1376. }
  1377. if (!m_bSilentMode && DisplayPassword(lpszFile))
  1378. {
  1379. if (*pConn->szPassword || *pConn->szUserName)
  1380. {
  1381. //WCHAR szFmt[128];
  1382. //WCHAR szMsg[384];
  1383. //LoadString(_Module.GetModuleInstance(), IDS_PASSWORD, szFmt, MAX_CHARS_IN_BUFFER(szFmt));
  1384. //wsprintf(szMsg, szFmt, pConn->szUserName, pConn->szPassword);
  1385. //::MessageBox(hwnd, szMsg, GetSz(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  1386. }
  1387. }
  1388. if (fHookAutodial &&
  1389. ((0 == *pConn->RasEntry.szAutodialDll) ||
  1390. (0 == *pConn->RasEntry.szAutodialFunc)))
  1391. {
  1392. lstrcpy(pConn->RasEntry.szAutodialDll, L"isign32.dll");
  1393. lstrcpy(pConn->RasEntry.szAutodialFunc, L"AutoDialLogon");
  1394. }
  1395. pRasEntry->dwfOptions |= RASEO_ShowDialingProgress;
  1396. // humongous hack for ISBU
  1397. dwRet = Rnaapi.InetConfigClientEx(hwnd,
  1398. NULL,
  1399. pConn->szEntryName,
  1400. pRasEntry,
  1401. pConn->szUserName,
  1402. pConn->szPassword,
  1403. NULL,
  1404. NULL,
  1405. dwfOptions & ~INETCFG_INSTALLMAIL,
  1406. lpfNeedsRestart,
  1407. szConnectoidName,
  1408. dwConnectoidNameSize,
  1409. lpDeviceInfo,
  1410. &dwDeviceInfoSize);
  1411. if ( lpDeviceInfo )
  1412. free (lpDeviceInfo);
  1413. LclSetEntryScriptPatch(pRasEntry->szScript, pConn->szEntryName);
  1414. BOOL fEnabled = TRUE;
  1415. DWORD dwResult = 0xba;
  1416. dwResult = InetGetAutodial(&fEnabled, pConn->szEntryName, RAS_MaxEntryName+1);
  1417. if ((ERROR_SUCCESS == dwRet) && lstrlen(szConnectoidName))
  1418. {
  1419. *lpfConnectoidCreated = (NULL != pRasEntry);
  1420. PopulateNTAutodialAddress( lpszFile, pConn->szEntryName );
  1421. }
  1422. }
  1423. next_step:
  1424. // If we were successfull in creating the connectiod, then see if the user wants a
  1425. // mail client installed
  1426. if (ERROR_SUCCESS == dwRet)
  1427. {
  1428. // Get the mail client info
  1429. if (m_dwDeviceType == InetS_LANCable)
  1430. {
  1431. if (!(pClientInfo = (LPINETCLIENTINFO) malloc (sizeof (INETCLIENTINFO))))
  1432. {
  1433. return ERROR_OUTOFMEMORY;
  1434. }
  1435. }
  1436. else
  1437. {
  1438. if (!pConn)
  1439. return ERROR_INVALID_PARAMETER;
  1440. pClientInfo = (LPINETCLIENTINFO)(((LPBYTE)pConn) + sizeof(ICONNECTION));
  1441. }
  1442. ImportClientInfo(lpszFile, pClientInfo);
  1443. // use inet config to install the mail client
  1444. dwRet = Rnaapi.InetConfigClientEx(hwnd,
  1445. NULL,
  1446. NULL,
  1447. NULL,
  1448. NULL,
  1449. NULL,
  1450. NULL,
  1451. pClientInfo,
  1452. dwfOptions & INETCFG_INSTALLMAIL,
  1453. lpfNeedsRestart,
  1454. szConnectoidName,
  1455. dwConnectoidNameSize);
  1456. }
  1457. // cleanup
  1458. if (m_dwDeviceType == InetS_LANCable)
  1459. free (pClientInfo);
  1460. if (pConn)
  1461. LocalFree(pConn);
  1462. *lpfNeedsRestart |= lpfNeedsRestartLan;
  1463. return dwRet;
  1464. }
  1465. //+----------------------------------------------------------------------------
  1466. //
  1467. // Function: PopulateNTAutodialAddress
  1468. //
  1469. // Synopsis: Take Internet addresses from INS file and load them into the
  1470. // autodial database
  1471. //
  1472. // Arguments: pszFileName - pointer to INS file name
  1473. //
  1474. // Returns: Error code (ERROR_SUCCESS == success)
  1475. //
  1476. // History: 8/29/96 ChrisK Created
  1477. //
  1478. //-----------------------------------------------------------------------------
  1479. #define AUTODIAL_ADDRESS_BUFFER_SIZE 2048
  1480. #define AUTODIAL_ADDRESS_SECTION_NAME L"Autodial_Addresses_for_NT"
  1481. HRESULT CINSHandler::PopulateNTAutodialAddress(LPCWSTR pszFileName, LPCWSTR pszEntryName)
  1482. {
  1483. HRESULT hr = ERROR_SUCCESS;
  1484. LONG lRC = 0;
  1485. LPLINETRANSLATECAPS lpcap = NULL;
  1486. LPLINETRANSLATECAPS lpTemp = NULL;
  1487. LPLINELOCATIONENTRY lpLE = NULL;
  1488. RASAUTODIALENTRY* rADE;
  1489. INT idx = 0;
  1490. LPWSTR lpszBuffer = NULL;
  1491. LPWSTR lpszNextAddress = NULL;
  1492. rADE = NULL;
  1493. //RNAAPI *pRnaapi = NULL;
  1494. // jmazner 10/8/96 this function is NT specific
  1495. if( !IsNT() )
  1496. {
  1497. // TraceMsg(TF_INSHANDLER, L"ISIGNUP: Bypassing PopulateNTAutodialAddress for win95.\r\n");
  1498. return( ERROR_SUCCESS );
  1499. }
  1500. MYASSERT(m_lpfnRasSetAutodialEnable);
  1501. MYASSERT(m_lpfnRasSetAutodialAddress);
  1502. //MYASSERT(pszFileName && pszEntryName);
  1503. //dprintf(L"ISIGNUP: PopulateNTAutodialAddress "%s %s.\r\n", pszFileName, pszEntryName);
  1504. // TraceMsg(TF_INSHANDLER, pszFileName);
  1505. // TraceMsg(TF_INSHANDLER, L", ");
  1506. // TraceMsg(TF_INSHANDLER, pszEntryName);
  1507. // TraceMsg(TF_INSHANDLER, L".\r\n");
  1508. //
  1509. // Get list of TAPI locations
  1510. //
  1511. lpcap = (LPLINETRANSLATECAPS)GlobalAlloc(GPTR, sizeof(LINETRANSLATECAPS));
  1512. if (!lpcap)
  1513. {
  1514. hr = ERROR_NOT_ENOUGH_MEMORY;
  1515. goto PopulateNTAutodialAddressExit;
  1516. }
  1517. lpcap->dwTotalSize = sizeof(LINETRANSLATECAPS);
  1518. lRC = lineGetTranslateCaps(0, 0x10004, lpcap);
  1519. if (SUCCESS == lRC)
  1520. {
  1521. lpTemp = (LPLINETRANSLATECAPS)GlobalAlloc(GPTR, lpcap->dwNeededSize);
  1522. if (!lpTemp)
  1523. {
  1524. hr = ERROR_NOT_ENOUGH_MEMORY;
  1525. goto PopulateNTAutodialAddressExit;
  1526. }
  1527. lpTemp->dwTotalSize = lpcap->dwNeededSize;
  1528. GlobalFree(lpcap);
  1529. lpcap = (LPLINETRANSLATECAPS)lpTemp;
  1530. lpTemp = NULL;
  1531. lRC = lineGetTranslateCaps(0, 0x10004, lpcap);
  1532. }
  1533. if (SUCCESS != lRC)
  1534. {
  1535. hr = (HRESULT)lRC; // REVIEW: not real sure about this.
  1536. goto PopulateNTAutodialAddressExit;
  1537. }
  1538. //
  1539. // Create an array of RASAUTODIALENTRY structs
  1540. //
  1541. rADE = (RASAUTODIALENTRY*)GlobalAlloc(GPTR,
  1542. sizeof(RASAUTODIALENTRY)*lpcap->dwNumLocations);
  1543. if (!rADE)
  1544. {
  1545. hr = ERROR_NOT_ENOUGH_MEMORY;
  1546. goto PopulateNTAutodialAddressExit;
  1547. }
  1548. //
  1549. // Enable autodialing for all locations
  1550. //
  1551. idx = lpcap->dwNumLocations;
  1552. lpLE = (LPLINELOCATIONENTRY)((DWORD_PTR)lpcap + lpcap->dwLocationListOffset);
  1553. while (idx)
  1554. {
  1555. idx--;
  1556. m_lpfnRasSetAutodialEnable(lpLE[idx].dwPermanentLocationID, TRUE);
  1557. //
  1558. // fill in array values
  1559. //
  1560. rADE[idx].dwSize = sizeof(RASAUTODIALENTRY);
  1561. rADE[idx].dwDialingLocation = lpLE[idx].dwPermanentLocationID;
  1562. lstrcpyn(rADE[idx].szEntry, pszEntryName, RAS_MaxEntryName);
  1563. }
  1564. //
  1565. // Get list of addresses
  1566. //
  1567. lpszBuffer = (LPWSTR)GlobalAlloc(GPTR, AUTODIAL_ADDRESS_BUFFER_SIZE * sizeof(WCHAR));
  1568. if (!lpszBuffer)
  1569. {
  1570. hr = ERROR_NOT_ENOUGH_MEMORY;
  1571. goto PopulateNTAutodialAddressExit;
  1572. }
  1573. if((AUTODIAL_ADDRESS_BUFFER_SIZE-2) == GetPrivateProfileSection(AUTODIAL_ADDRESS_SECTION_NAME,
  1574. lpszBuffer, AUTODIAL_ADDRESS_BUFFER_SIZE, pszFileName))
  1575. {
  1576. //AssertSz(0, L"Autodial address section bigger than buffer.\r\n");
  1577. hr = ERROR_NOT_ENOUGH_MEMORY;
  1578. goto PopulateNTAutodialAddressExit;
  1579. }
  1580. //
  1581. // Walk list of addresses and set autodialing for each one
  1582. //
  1583. lpszNextAddress = lpszBuffer;
  1584. do
  1585. {
  1586. lpszNextAddress = MoveToNextAddress(lpszNextAddress);
  1587. if (!(*lpszNextAddress))
  1588. break; // do-while
  1589. m_lpfnRasSetAutodialAddress(lpszNextAddress, 0, rADE,
  1590. sizeof(RASAUTODIALENTRY)*lpcap->dwNumLocations, lpcap->dwNumLocations);
  1591. lpszNextAddress = lpszNextAddress + lstrlen(lpszNextAddress);
  1592. } while(1);
  1593. PopulateNTAutodialAddressExit:
  1594. if (lpcap)
  1595. GlobalFree(lpcap);
  1596. lpcap = NULL;
  1597. if (rADE)
  1598. GlobalFree(rADE);
  1599. rADE = NULL;
  1600. if (lpszBuffer)
  1601. GlobalFree(lpszBuffer);
  1602. lpszBuffer = NULL;
  1603. //if( pRnaapi )
  1604. // delete pRnaapi;
  1605. //pRnaapi = NULL;
  1606. return hr;
  1607. }
  1608. //+----------------------------------------------------------------------------
  1609. //
  1610. // Function: MoveToNextAddress
  1611. //
  1612. // Synopsis: Given a pointer into the data bufffer, this function will move
  1613. // through the buffer until it points to the begining of the next
  1614. // address or it reaches the end of the buffer.
  1615. //
  1616. // Arguements: lpsz - pointer into buffer
  1617. //
  1618. // Returns: Pointer to the next address, return value will point to NULL
  1619. // if there are no more addresses
  1620. //
  1621. // History: 8/29/96 ChrisK Created
  1622. //
  1623. //-----------------------------------------------------------------------------
  1624. LPWSTR CINSHandler::MoveToNextAddress(LPWSTR lpsz)
  1625. {
  1626. BOOL fLastCharWasNULL = FALSE;
  1627. //assertSz(lpsz, L"MoveToNextAddress: NULL input\r\n");
  1628. //
  1629. // Look for an = sign
  1630. //
  1631. do
  1632. {
  1633. if (fLastCharWasNULL && L'\0' == *lpsz)
  1634. break; // are we at the end of the data?
  1635. if (L'\0' == *lpsz)
  1636. fLastCharWasNULL = TRUE;
  1637. else
  1638. fLastCharWasNULL = FALSE;
  1639. if (L'=' == *lpsz)
  1640. break;
  1641. if (*lpsz)
  1642. lpsz = CharNext(lpsz);
  1643. else
  1644. lpsz += BYTES_REQUIRED_BY_CCH(1);
  1645. } while (1);
  1646. //
  1647. // Move to the first character beyond the = sign.
  1648. //
  1649. if (*lpsz)
  1650. lpsz = CharNext(lpsz);
  1651. return lpsz;
  1652. }
  1653. //+----------------------------------------------------------------------------
  1654. //
  1655. // Function: ImportCustomDialer
  1656. //
  1657. // Synopsis: Import custom dialer information from the specified file
  1658. // and save the information in the RASENTRY
  1659. //
  1660. // Arguments: lpRasEntry - pointer to a valid RASENTRY structure
  1661. // szFileName - text file (in .ini file format) containing the
  1662. // Custom Dialer information
  1663. //
  1664. // Returns: ERROR_SUCCESS - success otherwise a Win32 error
  1665. //
  1666. // History: ChrisK Created 7/11/96
  1667. // 8/12/96 ChrisK Ported from \\trango
  1668. //
  1669. //-----------------------------------------------------------------------------
  1670. DWORD CINSHandler::ImportCustomDialer(LPRASENTRY lpRasEntry, LPCWSTR szFileName)
  1671. {
  1672. // If there is an error reading the information from the file, or the entry
  1673. // missing or blank, the default value (cszNull) will be used.
  1674. GetPrivateProfileString(cszCustomDialerSection,
  1675. cszAutoDialDLL,
  1676. cszNull,
  1677. lpRasEntry->szAutodialDll,
  1678. MAX_CHARS_IN_BUFFER(lpRasEntry->szAutodialDll),
  1679. szFileName);
  1680. GetPrivateProfileString(cszCustomDialerSection,
  1681. cszAutoDialFunc,
  1682. cszNull,
  1683. lpRasEntry->szAutodialFunc,
  1684. MAX_CHARS_IN_BUFFER(lpRasEntry->szAutodialFunc),
  1685. szFileName);
  1686. return ERROR_SUCCESS;
  1687. }
  1688. //****************************************************************************
  1689. // DWORD NEAR PASCAL StrToip (LPWSTR szIPAddress, LPDWORD lpdwAddr)
  1690. //
  1691. // This function converts a IP address string to an IP address structure.
  1692. //
  1693. // History:
  1694. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1695. // Cloned from SMMSCRPT.
  1696. //****************************************************************************
  1697. LPCWSTR CINSHandler::StrToSubip (LPCWSTR szIPAddress, LPBYTE pVal)
  1698. {
  1699. LPCWSTR pszIP = szIPAddress;
  1700. BYTE val = 0;
  1701. // skip separators (non digits)
  1702. while (*pszIP && !myisdigit(*pszIP))
  1703. {
  1704. ++pszIP;
  1705. }
  1706. while (myisdigit(*pszIP))
  1707. {
  1708. val = (val * 10) + (BYTE)(*pszIP - L'0');
  1709. ++pszIP;
  1710. }
  1711. *pVal = val;
  1712. return pszIP;
  1713. }
  1714. DWORD CINSHandler::StrToip (LPCWSTR szIPAddress, RASIPADDR *ipAddr)
  1715. {
  1716. LPCWSTR pszIP = szIPAddress;
  1717. pszIP = StrToSubip(pszIP, &ipAddr->a);
  1718. pszIP = StrToSubip(pszIP, &ipAddr->b);
  1719. pszIP = StrToSubip(pszIP, &ipAddr->c);
  1720. pszIP = StrToSubip(pszIP, &ipAddr->d);
  1721. return ERROR_SUCCESS;
  1722. }
  1723. //****************************************************************************
  1724. // DWORD NEAR PASCAL ImportPhoneInfo(PPHONENUM ppn, LPCWSTR szFileName)
  1725. //
  1726. // This function imports the phone number.
  1727. //
  1728. // History:
  1729. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1730. // Created.
  1731. //****************************************************************************
  1732. DWORD CINSHandler::ImportPhoneInfo(LPRASENTRY lpRasEntry, LPCWSTR szFileName)
  1733. {
  1734. WCHAR szYesNo[MAXNAME];
  1735. if (GetPrivateProfileString(cszPhoneSection,
  1736. cszPhone,
  1737. cszNull,
  1738. lpRasEntry->szLocalPhoneNumber,
  1739. MAX_CHARS_IN_BUFFER(lpRasEntry->szLocalPhoneNumber),
  1740. szFileName) == 0)
  1741. {
  1742. return ERROR_BAD_PHONE_NUMBER;
  1743. }
  1744. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  1745. GetPrivateProfileString(cszPhoneSection,
  1746. cszDialAsIs,
  1747. cszNo,
  1748. szYesNo,
  1749. MAX_CHARS_IN_BUFFER(szYesNo),
  1750. szFileName);
  1751. // Do we have to get country code and area code?
  1752. if (!lstrcmpi(szYesNo, cszNo))
  1753. {
  1754. // If we cannot get the country ID or it is zero, default to dial as is
  1755. //
  1756. if ((lpRasEntry->dwCountryID = GetPrivateProfileInt(cszPhoneSection,
  1757. cszCountryID,
  1758. 0,
  1759. szFileName)) != 0)
  1760. {
  1761. lpRasEntry->dwCountryCode = GetPrivateProfileInt(cszPhoneSection,
  1762. cszCountryCode,
  1763. 1,
  1764. szFileName);
  1765. GetPrivateProfileString(cszPhoneSection,
  1766. cszAreaCode,
  1767. cszNull,
  1768. lpRasEntry->szAreaCode,
  1769. MAX_CHARS_IN_BUFFER(lpRasEntry->szAreaCode),
  1770. szFileName);
  1771. lpRasEntry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  1772. }
  1773. }
  1774. else
  1775. {
  1776. // bug in RasSetEntryProperties still checks area codes
  1777. // even when RASEO_UseCountryAndAreaCodes is not set
  1778. lstrcpy(lpRasEntry->szAreaCode, L"805");
  1779. lpRasEntry->dwCountryID = 1;
  1780. lpRasEntry->dwCountryCode = 1;
  1781. }
  1782. return ERROR_SUCCESS;
  1783. }
  1784. //****************************************************************************
  1785. // DWORD NEAR PASCAL ImportServerInfo(PSMMINFO psmmi, LPWSTR szFileName)
  1786. //
  1787. // This function imports the server type name and settings.
  1788. //
  1789. // History:
  1790. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1791. // Created.
  1792. //****************************************************************************
  1793. DWORD CINSHandler::ImportServerInfo(LPRASENTRY lpRasEntry, LPCWSTR szFileName)
  1794. {
  1795. WCHAR szYesNo[MAXNAME];
  1796. WCHAR szType[MAXNAME];
  1797. DWORD i;
  1798. // Get the server type name
  1799. GetPrivateProfileString(cszServerSection,
  1800. cszServerType,
  1801. cszNull,
  1802. szType,
  1803. MAX_CHARS_IN_BUFFER(szType),
  1804. szFileName);
  1805. // need to convert the string into
  1806. // one of the following values
  1807. // RASFP_Ppp
  1808. // RASFP_Slip Note CSLIP is SLIP with IP compression on
  1809. // RASFP_Ras
  1810. for (i = 0; i < NUM_SERVER_TYPES; ++i)
  1811. {
  1812. if (!lstrcmpi(aServerTypes[i].szType, szType))
  1813. {
  1814. lpRasEntry->dwFramingProtocol = aServerTypes[i].dwType;
  1815. lpRasEntry->dwfOptions |= aServerTypes[i].dwfOptions;
  1816. break;
  1817. }
  1818. }
  1819. // Get the server type settings
  1820. if (GetPrivateProfileString(cszServerSection,
  1821. cszSWCompress,
  1822. cszYes,
  1823. szYesNo,
  1824. MAX_CHARS_IN_BUFFER(szYesNo),
  1825. szFileName))
  1826. {
  1827. if (!lstrcmpi(szYesNo, cszNo))
  1828. {
  1829. lpRasEntry->dwfOptions &= ~RASEO_SwCompression;
  1830. }
  1831. else
  1832. {
  1833. lpRasEntry->dwfOptions |= RASEO_SwCompression;
  1834. }
  1835. }
  1836. if (GetPrivateProfileString(cszServerSection,
  1837. cszPWEncrypt,
  1838. cszNull,
  1839. szYesNo,
  1840. MAX_CHARS_IN_BUFFER(szYesNo),
  1841. szFileName))
  1842. {
  1843. if (!lstrcmpi(szYesNo, cszNo))
  1844. {
  1845. lpRasEntry->dwfOptions &= ~RASEO_RequireEncryptedPw;
  1846. }
  1847. else
  1848. {
  1849. lpRasEntry->dwfOptions |= RASEO_RequireEncryptedPw;
  1850. }
  1851. }
  1852. if (GetPrivateProfileString(cszServerSection,
  1853. cszNetLogon,
  1854. cszNo,
  1855. szYesNo,
  1856. MAX_CHARS_IN_BUFFER(szYesNo),
  1857. szFileName))
  1858. {
  1859. if (!lstrcmpi(szYesNo, cszNo))
  1860. {
  1861. lpRasEntry->dwfOptions &= ~RASEO_NetworkLogon;
  1862. }
  1863. else
  1864. {
  1865. lpRasEntry->dwfOptions |= RASEO_NetworkLogon;
  1866. }
  1867. }
  1868. if (GetPrivateProfileString(cszServerSection,
  1869. cszSWEncrypt,
  1870. cszNo,
  1871. szYesNo,
  1872. MAX_CHARS_IN_BUFFER(szYesNo),
  1873. szFileName))
  1874. {
  1875. if (!lstrcmpi(szYesNo, cszNo))
  1876. {
  1877. lpRasEntry->dwfOptions &= ~RASEO_RequireDataEncryption;
  1878. }
  1879. else
  1880. {
  1881. lpRasEntry->dwfOptions |= RASEO_RequireDataEncryption;
  1882. }
  1883. }
  1884. // Get the protocol settings
  1885. if (GetPrivateProfileString(cszServerSection,
  1886. cszNetBEUI,
  1887. cszNo,
  1888. szYesNo,
  1889. MAX_CHARS_IN_BUFFER(szYesNo),
  1890. szFileName))
  1891. {
  1892. if (!lstrcmpi(szYesNo, cszNo))
  1893. {
  1894. lpRasEntry->dwfNetProtocols &= ~RASNP_NetBEUI;
  1895. }
  1896. else
  1897. {
  1898. lpRasEntry->dwfNetProtocols |= RASNP_NetBEUI;
  1899. }
  1900. }
  1901. if (GetPrivateProfileString(cszServerSection,
  1902. cszIPX,
  1903. cszNo,
  1904. szYesNo,
  1905. MAX_CHARS_IN_BUFFER(szYesNo),
  1906. szFileName))
  1907. {
  1908. if (!lstrcmpi(szYesNo, cszNo))
  1909. {
  1910. lpRasEntry->dwfNetProtocols &= ~RASNP_Ipx;
  1911. }
  1912. else
  1913. {
  1914. lpRasEntry->dwfNetProtocols |= RASNP_Ipx;
  1915. }
  1916. }
  1917. if (GetPrivateProfileString(cszServerSection,
  1918. cszIP,
  1919. cszYes,
  1920. szYesNo,
  1921. MAX_CHARS_IN_BUFFER(szYesNo),
  1922. szFileName))
  1923. {
  1924. if (!lstrcmpi(szYesNo, cszNo))
  1925. {
  1926. lpRasEntry->dwfNetProtocols &= ~RASNP_Ip;
  1927. }
  1928. else
  1929. {
  1930. lpRasEntry->dwfNetProtocols |= RASNP_Ip;
  1931. }
  1932. }
  1933. if (GetPrivateProfileString(cszServerSection,
  1934. cszDisableLcp,
  1935. cszNull,
  1936. szYesNo,
  1937. MAX_CHARS_IN_BUFFER(szYesNo),
  1938. szFileName))
  1939. {
  1940. if (!lstrcmpi(szYesNo, cszYes))
  1941. {
  1942. lpRasEntry->dwfOptions |= RASEO_DisableLcpExtensions;
  1943. }
  1944. else
  1945. {
  1946. lpRasEntry->dwfOptions &= ~RASEO_DisableLcpExtensions;
  1947. }
  1948. }
  1949. return ERROR_SUCCESS;
  1950. }
  1951. //****************************************************************************
  1952. // DWORD NEAR PASCAL ImportIPInfo(LPWSTR szEntryName, LPWSTR szFileName)
  1953. //
  1954. // This function imports the TCP/IP information
  1955. //
  1956. // History:
  1957. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1958. // Created.
  1959. //****************************************************************************
  1960. DWORD CINSHandler::ImportIPInfo(LPRASENTRY lpRasEntry, LPCWSTR szFileName)
  1961. {
  1962. WCHAR szIPAddr[MAXIPADDRLEN];
  1963. WCHAR szYesNo[MAXNAME];
  1964. // Import IP address information
  1965. if (GetPrivateProfileString(cszIPSection,
  1966. cszIPSpec,
  1967. cszNo,
  1968. szYesNo,
  1969. MAX_CHARS_IN_BUFFER(szYesNo),
  1970. szFileName))
  1971. {
  1972. if (!lstrcmpi(szYesNo, cszYes))
  1973. {
  1974. // The import file has IP address specified, get the IP address
  1975. lpRasEntry->dwfOptions |= RASEO_SpecificIpAddr;
  1976. if (GetPrivateProfileString(cszIPSection,
  1977. cszIPAddress,
  1978. cszNull,
  1979. szIPAddr,
  1980. MAX_CHARS_IN_BUFFER(szIPAddr),
  1981. szFileName))
  1982. {
  1983. StrToip (szIPAddr, &lpRasEntry->ipaddr);
  1984. }
  1985. }
  1986. else
  1987. {
  1988. lpRasEntry->dwfOptions &= ~RASEO_SpecificIpAddr;
  1989. }
  1990. }
  1991. // Import Server address information
  1992. if (GetPrivateProfileString(cszIPSection,
  1993. cszServerSpec,
  1994. cszNo,
  1995. szYesNo,
  1996. MAX_CHARS_IN_BUFFER(szYesNo),
  1997. szFileName))
  1998. {
  1999. if (!lstrcmpi(szYesNo, cszYes))
  2000. {
  2001. // The import file has server address specified, get the server address
  2002. lpRasEntry->dwfOptions |= RASEO_SpecificNameServers;
  2003. if (GetPrivateProfileString(cszIPSection,
  2004. cszDNSAddress,
  2005. cszNull,
  2006. szIPAddr,
  2007. MAX_CHARS_IN_BUFFER(szIPAddr),
  2008. szFileName))
  2009. {
  2010. StrToip (szIPAddr, &lpRasEntry->ipaddrDns);
  2011. }
  2012. if (GetPrivateProfileString(cszIPSection,
  2013. cszDNSAltAddress,
  2014. cszNull,
  2015. szIPAddr,
  2016. MAX_CHARS_IN_BUFFER(szIPAddr),
  2017. szFileName))
  2018. {
  2019. StrToip (szIPAddr, &lpRasEntry->ipaddrDnsAlt);
  2020. }
  2021. if (GetPrivateProfileString(cszIPSection,
  2022. cszWINSAddress,
  2023. cszNull,
  2024. szIPAddr,
  2025. MAX_CHARS_IN_BUFFER(szIPAddr),
  2026. szFileName))
  2027. {
  2028. StrToip (szIPAddr, &lpRasEntry->ipaddrWins);
  2029. }
  2030. if (GetPrivateProfileString(cszIPSection,
  2031. cszWINSAltAddress,
  2032. cszNull,
  2033. szIPAddr,
  2034. MAX_CHARS_IN_BUFFER(szIPAddr),
  2035. szFileName))
  2036. {
  2037. StrToip (szIPAddr, &lpRasEntry->ipaddrWinsAlt);
  2038. }
  2039. }
  2040. else
  2041. {
  2042. lpRasEntry->dwfOptions &= ~RASEO_SpecificNameServers;
  2043. }
  2044. }
  2045. // Header compression and the gateway settings
  2046. if (GetPrivateProfileString(cszIPSection,
  2047. cszIPCompress,
  2048. cszYes,
  2049. szYesNo,
  2050. MAX_CHARS_IN_BUFFER(szYesNo),
  2051. szFileName))
  2052. {
  2053. if (!lstrcmpi(szYesNo, cszNo))
  2054. {
  2055. lpRasEntry->dwfOptions &= ~RASEO_IpHeaderCompression;
  2056. }
  2057. else
  2058. {
  2059. lpRasEntry->dwfOptions |= RASEO_IpHeaderCompression;
  2060. }
  2061. }
  2062. if (GetPrivateProfileString(cszIPSection,
  2063. cszWanPri,
  2064. cszYes,
  2065. szYesNo,
  2066. MAX_CHARS_IN_BUFFER(szYesNo),
  2067. szFileName))
  2068. {
  2069. if (!lstrcmpi(szYesNo, cszNo))
  2070. {
  2071. lpRasEntry->dwfOptions &= ~RASEO_RemoteDefaultGateway;
  2072. }
  2073. else
  2074. {
  2075. lpRasEntry->dwfOptions |= RASEO_RemoteDefaultGateway;
  2076. }
  2077. }
  2078. return ERROR_SUCCESS;
  2079. }
  2080. DWORD CINSHandler::ImportScriptFile(
  2081. LPCWSTR lpszImportFile,
  2082. LPWSTR szScriptFile,
  2083. UINT cbScriptFile)
  2084. {
  2085. WCHAR szTemp[_MAX_PATH];
  2086. DWORD dwRet = ERROR_SUCCESS;
  2087. // Get the script filename
  2088. //
  2089. if (GetPrivateProfileString(cszScriptingSection,
  2090. cszScriptName,
  2091. cszNull,
  2092. szTemp,
  2093. MAX_CHARS_IN_BUFFER(szTemp),
  2094. lpszImportFile) != 0)
  2095. {
  2096. //!!! commonize this code
  2097. //!!! make it DBCS compatible
  2098. //!!! check for overruns
  2099. //!!! check for absolute path name
  2100. GetWindowsDirectory(szScriptFile, cbScriptFile);
  2101. if (*CharPrev(szScriptFile, szScriptFile + lstrlen(szScriptFile)) != L'\\')
  2102. {
  2103. lstrcat(szScriptFile, L"\\");
  2104. }
  2105. lstrcat(szScriptFile, szTemp);
  2106. dwRet =ImportFile(lpszImportFile, cszScriptSection, szScriptFile);
  2107. }
  2108. return dwRet;
  2109. }
  2110. //****************************************************************************
  2111. // DWORD WINAPI RnaValidateImportEntry (LPWSTR)
  2112. //
  2113. // This function is called to validate an importable file
  2114. //
  2115. // History:
  2116. // Wed 03-Jan-1996 09:45:01 -by- Viroon Touranachun [viroont]
  2117. // Created.
  2118. //****************************************************************************
  2119. DWORD CINSHandler::RnaValidateImportEntry (LPCWSTR szFileName)
  2120. {
  2121. WCHAR szTmp[4];
  2122. // Get the alias entry name
  2123. //
  2124. // 12/4/96 jmazner Normandy #12373
  2125. // If no such key, don't return ERROR_INVALID_PHONEBOOK_ENTRY,
  2126. // since ConfigureClient always ignores that error code.
  2127. return (GetPrivateProfileString(cszEntrySection,
  2128. cszEntry_Name,
  2129. cszNull,
  2130. szTmp,
  2131. MAX_CHARS_IN_BUFFER(szTmp),
  2132. szFileName) > 0 ?
  2133. ERROR_SUCCESS : ERROR_UNKNOWN);
  2134. }
  2135. DWORD CINSHandler::ImportRasEntry (LPCWSTR szFileName, LPRASENTRY lpRasEntry, LPBYTE & lpDeviceInfo, LPDWORD lpdwDeviceInfoSize)
  2136. {
  2137. DWORD dwRet;
  2138. dwRet = ImportPhoneInfo(lpRasEntry, szFileName);
  2139. if (ERROR_SUCCESS == dwRet)
  2140. {
  2141. // Get device type
  2142. //
  2143. GetPrivateProfileString(cszDeviceSection,
  2144. cszDeviceType,
  2145. cszNull,
  2146. lpRasEntry->szDeviceType,
  2147. MAX_CHARS_IN_BUFFER(lpRasEntry->szDeviceType),
  2148. szFileName);
  2149. // Get Server Type settings
  2150. //
  2151. dwRet = ImportServerInfo(lpRasEntry, szFileName);
  2152. if (ERROR_SUCCESS == dwRet)
  2153. {
  2154. // Get IP address
  2155. //
  2156. dwRet = ImportIPInfo(lpRasEntry, szFileName);
  2157. }
  2158. if ( (ERROR_SUCCESS == dwRet) && (m_dwDeviceType == InetS_RASAtm) )
  2159. {
  2160. // Get ATM-Specific Information
  2161. //
  2162. dwRet = ImportAtmInfo(lpRasEntry, szFileName, lpDeviceInfo, lpdwDeviceInfoSize);
  2163. }
  2164. }
  2165. return dwRet;
  2166. }
  2167. //****************************************************************************
  2168. // DWORD ImportATMInfo (LPRASENTRY, LPCWSTR, LPBYTE, LPDWORD)
  2169. //
  2170. // This function is called to import ATM Information into a buffer.
  2171. // Note: Memory is allocated in this function to accomodate ATM data.
  2172. // This memory can be deallocated using delete.
  2173. //
  2174. // History:
  2175. // Mon 1-Nov-1999 11:27:02 -by- Thomas Jeyaseelan [thomasje]
  2176. // Created.
  2177. //****************************************************************************
  2178. DWORD CINSHandler::ImportAtmInfo (LPRASENTRY lpRasEntry, LPCWSTR cszFileName,
  2179. LPBYTE & lpDeviceInfo, LPDWORD lpdwDeviceInfoSize)
  2180. {
  2181. // Error handling. Make sure that lpDeviceInfo = 0 and lpdwDeviceInfo != 0
  2182. // and lpdwDeviceInfo points to a DWORD that is assigned a value of 0.
  2183. DWORD dwRet = ERROR_SUCCESS; // <== investigate correct return value for failure
  2184. if ( lpDeviceInfo && lpdwDeviceInfoSize && (*lpdwDeviceInfoSize == sizeof (ATMPBCONFIG) ) )
  2185. {
  2186. // Creating the ATM Buffer. Note that memory is allocated on the heap.
  2187. // This memory must be carefully deallocated in one of the caller routines.
  2188. LPATMPBCONFIG lpAtmConfig = (LPATMPBCONFIG) lpDeviceInfo;
  2189. DWORD dwCircuitSpeed = 0;
  2190. DWORD dwCircuitQOS = 0;
  2191. DWORD dwCircuitType = 0;
  2192. WCHAR szYesNo [MAXNAME]; // for Speed_Adjust, QOS_Adjust, Vendor_Config, Show_Status and Enable_Log.
  2193. DWORD dwEncapsulation = 0;
  2194. DWORD dwVpi = 0;
  2195. DWORD dwVci = 0;
  2196. dwCircuitSpeed = GetPrivateProfileInt (cszATMSection, cszCircuitSpeed, dwCircuitSpeed, cszFileName);
  2197. switch (dwCircuitSpeed) {
  2198. case 0:
  2199. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_LINE_RATE;
  2200. break;
  2201. case 1:
  2202. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_USER_SPEC;
  2203. break;
  2204. case 512:
  2205. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_512KB;
  2206. break;
  2207. case 1536:
  2208. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_1536KB;
  2209. break;
  2210. case 25000:
  2211. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_25MB;
  2212. break;
  2213. case 155000:
  2214. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_155MB;
  2215. break;
  2216. default:
  2217. lpAtmConfig->dwCircuitSpeed = ATM_CIRCUIT_SPEED_DEFAULT;
  2218. break;
  2219. }
  2220. lpAtmConfig->dwCircuitOpt |= lpAtmConfig->dwCircuitSpeed;
  2221. dwCircuitQOS = GetPrivateProfileInt (cszATMSection, cszCircuitQOS, dwCircuitQOS, cszFileName);
  2222. switch (dwCircuitQOS) {
  2223. case 0:
  2224. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_QOS_UBR;
  2225. break;
  2226. case 1:
  2227. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_QOS_VBR;
  2228. break;
  2229. case 2:
  2230. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_QOS_CBR;
  2231. break;
  2232. case 3:
  2233. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_QOS_ABR;
  2234. break;
  2235. default:
  2236. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_QOS_DEFAULT;
  2237. break;
  2238. }
  2239. dwCircuitType = GetPrivateProfileInt (cszATMSection, cszCircuitType, dwCircuitType, cszFileName);
  2240. switch (dwCircuitType) {
  2241. case 0:
  2242. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_SVC;
  2243. break;
  2244. case 1:
  2245. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_PVC;
  2246. break;
  2247. default:
  2248. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_SVC;
  2249. break;
  2250. }
  2251. dwEncapsulation = GetPrivateProfileInt (cszATMSection, cszEncapsulation, dwEncapsulation, cszFileName);
  2252. switch (dwEncapsulation) {
  2253. case 0:
  2254. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_ENCAP_NULL;
  2255. break;
  2256. case 1:
  2257. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_ENCAP_LLC;
  2258. break;
  2259. default:
  2260. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_ENCAP_DEFAULT;
  2261. break;
  2262. }
  2263. dwVpi = GetPrivateProfileInt (cszATMSection, cszVPI, dwVpi, cszFileName);
  2264. lpAtmConfig->wPvcVpi = (WORD) dwVpi;
  2265. dwVci = GetPrivateProfileInt (cszATMSection, cszVCI, dwVci, cszFileName);
  2266. lpAtmConfig->wPvcVci = (WORD) dwVci;
  2267. // Speed_Adjust
  2268. if (GetPrivateProfileString(cszATMSection,
  2269. cszSpeedAdjust,
  2270. cszYes,
  2271. szYesNo,
  2272. MAX_CHARS_IN_BUFFER(szYesNo),
  2273. cszFileName))
  2274. {
  2275. if (!lstrcmpi(szYesNo, cszYes)) {
  2276. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_SPEED_ADJUST;
  2277. } else {
  2278. lpAtmConfig->dwCircuitOpt &= ~ATM_CIRCUIT_OPT_SPEED_ADJUST;
  2279. }
  2280. } else {
  2281. // if this field is not correctly specified, we use the default settings
  2282. // as specified in the ATMCFG header file.
  2283. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_SPEED_ADJUST;
  2284. }
  2285. // QOS_Adjust
  2286. if (GetPrivateProfileString(cszATMSection,
  2287. cszQOSAdjust,
  2288. cszYes,
  2289. szYesNo,
  2290. MAX_CHARS_IN_BUFFER(szYesNo),
  2291. cszFileName))
  2292. {
  2293. if (!lstrcmpi(szYesNo, cszYes)) {
  2294. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_QOS_ADJUST;
  2295. } else {
  2296. lpAtmConfig->dwCircuitOpt &= ~ATM_CIRCUIT_OPT_QOS_ADJUST;
  2297. }
  2298. } else {
  2299. lpAtmConfig->dwCircuitOpt |= ATM_CIRCUIT_OPT_QOS_ADJUST;
  2300. }
  2301. // Vendor_Config
  2302. if (GetPrivateProfileString(cszATMSection,
  2303. cszVendorConfig,
  2304. cszYes,
  2305. szYesNo,
  2306. MAX_CHARS_IN_BUFFER(szYesNo),
  2307. cszFileName))
  2308. {
  2309. if (!lstrcmpi(szYesNo, cszYes)) {
  2310. lpAtmConfig->dwGeneralOpt |= ATM_GENERAL_OPT_VENDOR_CONFIG;
  2311. } else {
  2312. lpAtmConfig->dwGeneralOpt &= ~ATM_GENERAL_OPT_VENDOR_CONFIG;
  2313. }
  2314. } else {
  2315. lpAtmConfig->dwGeneralOpt &= ~ATM_GENERAL_OPT_VENDOR_CONFIG;
  2316. }
  2317. // Show_Status
  2318. if (GetPrivateProfileString(cszATMSection,
  2319. cszShowStatus,
  2320. cszYes,
  2321. szYesNo,
  2322. MAX_CHARS_IN_BUFFER(szYesNo),
  2323. cszFileName))
  2324. {
  2325. if (!lstrcmpi(szYesNo, cszYes)) {
  2326. lpAtmConfig->dwGeneralOpt |= ATM_GENERAL_OPT_SHOW_STATUS;
  2327. } else {
  2328. lpAtmConfig->dwGeneralOpt &= ~ATM_GENERAL_OPT_SHOW_STATUS;
  2329. }
  2330. } else {
  2331. lpAtmConfig->dwGeneralOpt &= ~ATM_GENERAL_OPT_SHOW_STATUS;
  2332. }
  2333. // Enable_Log
  2334. if (GetPrivateProfileString(cszATMSection,
  2335. cszEnableLog,
  2336. cszYes,
  2337. szYesNo,
  2338. MAX_CHARS_IN_BUFFER(szYesNo),
  2339. cszFileName))
  2340. {
  2341. if (!lstrcmpi(szYesNo, cszYes)) {
  2342. lpAtmConfig->dwGeneralOpt |= ATM_GENERAL_OPT_ENABLE_LOG;
  2343. } else {
  2344. lpAtmConfig->dwGeneralOpt &= ~ATM_GENERAL_OPT_ENABLE_LOG;
  2345. }
  2346. } else {
  2347. lpAtmConfig->dwGeneralOpt &= ~ATM_GENERAL_OPT_ENABLE_LOG;
  2348. }
  2349. } else dwRet = ERROR_CANCELLED;
  2350. return dwRet; // note that lpDeviceInfo now points to a buffer. also, *lpdwDeviceInfoSize > 0.
  2351. }
  2352. //****************************************************************************
  2353. // DWORD WINAPI RnaImportEntry (LPWSTR, LPBYTE, DWORD)
  2354. //
  2355. // This function is called to import an entry from a specified file
  2356. //
  2357. // History:
  2358. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  2359. // Created.
  2360. //****************************************************************************
  2361. DWORD CINSHandler::ImportConnection (LPCWSTR szFileName, LPICONNECTION lpConn,
  2362. LPBYTE & lpDeviceInfo, LPDWORD lpdwDeviceInfoSize)
  2363. {
  2364. DWORD dwRet;
  2365. lpConn->RasEntry.dwSize = sizeof(RASENTRY);
  2366. dwRet = RnaValidateImportEntry(szFileName);
  2367. if (ERROR_SUCCESS != dwRet)
  2368. {
  2369. return dwRet;
  2370. }
  2371. GetPrivateProfileString(cszEntrySection,
  2372. cszEntry_Name,
  2373. cszNull,
  2374. lpConn->szEntryName,
  2375. MAX_CHARS_IN_BUFFER(lpConn->szEntryName),
  2376. szFileName);
  2377. GetPrivateProfileString(cszUserSection,
  2378. cszUserName,
  2379. cszNull,
  2380. lpConn->szUserName,
  2381. MAX_CHARS_IN_BUFFER(lpConn->szUserName),
  2382. szFileName);
  2383. GetPrivateProfileString(cszUserSection,
  2384. cszPassword,
  2385. cszNull,
  2386. lpConn->szPassword,
  2387. MAX_CHARS_IN_BUFFER(lpConn->szPassword),
  2388. szFileName);
  2389. // thomasje - We are no longer dealing with only RAS.
  2390. // There are two types of connections. One is RAS
  2391. // and the other is Ethernet. By exmining the device type
  2392. // we will call the correct engine to handle the matter.
  2393. dwRet = ImportRasEntry(szFileName, &lpConn->RasEntry, lpDeviceInfo, lpdwDeviceInfoSize);
  2394. if (ERROR_SUCCESS == dwRet)
  2395. {
  2396. dwRet = ImportCustomDialer(&lpConn->RasEntry, szFileName);
  2397. }
  2398. if (ERROR_SUCCESS == dwRet)
  2399. {
  2400. // Import the script file
  2401. //
  2402. dwRet = ImportScriptFile(szFileName,
  2403. lpConn->RasEntry.szScript,
  2404. MAX_CHARS_IN_BUFFER(lpConn->RasEntry.szScript));
  2405. }
  2406. // Use an ISPImport object to Config The ras device
  2407. CISPImport ISPImport;
  2408. ISPImport.set_hWndMain(GetActiveWindow());
  2409. dwRet = ISPImport.ConfigRasEntryDevice(&lpConn->RasEntry);
  2410. switch( dwRet )
  2411. {
  2412. case ERROR_SUCCESS:
  2413. break;
  2414. case ERROR_CANCELLED:
  2415. /*
  2416. if(!m_bSilentMode)
  2417. InfoMsg1(NULL, IDS_SIGNUPCANCELLED, NULL);
  2418. */
  2419. // Fall through
  2420. default:
  2421. goto ImportConnectionExit;
  2422. }
  2423. ImportConnectionExit:
  2424. return dwRet;
  2425. }
  2426. // Prototype for acct manager entry point we want
  2427. typedef HRESULT (WINAPI *PFNCREATEACCOUNTSFROMFILEEX)(LPSTR szFile, CONNECTINFO *pCI, DWORD dwFlags);
  2428. // Regkeys for Acct manager
  2429. #define ACCTMGR_PATHKEY L"SOFTWARE\\Microsoft\\Internet Account Manager"
  2430. #define ACCTMGR_DLLPATH L"DllPath"
  2431. // ############################################################################
  2432. //
  2433. // Name: ImportMailAndNewsInfo
  2434. //
  2435. // Description: Import information from INS file and set the associated
  2436. // registry keys for Internet Mail and News (Athena)
  2437. //
  2438. // Input: lpszFile - Fully qualified filename of INS file
  2439. //
  2440. // Return: Error value
  2441. //
  2442. // History: 6/27/96 Created
  2443. //
  2444. // ############################################################################
  2445. DWORD CINSHandler::ImportMailAndNewsInfo(LPCWSTR lpszFile, BOOL fConnectPhone)
  2446. {
  2447. USES_CONVERSION;
  2448. DWORD dwRet = ERROR_SUCCESS;
  2449. WCHAR szAcctMgrPath[MAX_PATH + 1] = L"";
  2450. WCHAR szExpandedPath[MAX_PATH + 1] = L"";
  2451. DWORD dwAcctMgrPathSize = 0;
  2452. HRESULT hr = S_OK;
  2453. HKEY hKey = NULL;
  2454. HINSTANCE hInst = NULL;
  2455. CONNECTINFO connectInfo;
  2456. WCHAR szConnectoidName[RAS_MaxEntryName] = L"nogood\0";
  2457. PFNCREATEACCOUNTSFROMFILEEX fp = NULL;
  2458. // get path to the AcctMgr dll
  2459. dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ACCTMGR_PATHKEY, 0, KEY_READ, &hKey);
  2460. if ( (dwRet != ERROR_SUCCESS) || (NULL == hKey) )
  2461. {
  2462. // TraceMsg(TF_INSHANDLER, L"ImportMailAndNewsInfo couldn't open reg key %s\n", ACCTMGR_PATHKEY);
  2463. return( dwRet );
  2464. }
  2465. dwAcctMgrPathSize = sizeof (szAcctMgrPath);
  2466. dwRet = RegQueryValueEx(hKey, ACCTMGR_DLLPATH, NULL, NULL, (LPBYTE) szAcctMgrPath, &dwAcctMgrPathSize);
  2467. RegCloseKey( hKey );
  2468. if ( dwRet != ERROR_SUCCESS )
  2469. {
  2470. // TraceMsg(TF_INSHANDLER, L"ImportMailAndNewsInfo: RegQuery failed with error %d\n", dwRet);
  2471. return( dwRet );
  2472. }
  2473. // 6/18/97 jmazner Olympus #6819
  2474. // TraceMsg(TF_INSHANDLER, L"ImportMailAndNewsInfo: read in DllPath of %s\n", szAcctMgrPath);
  2475. ExpandEnvironmentStrings( szAcctMgrPath, szExpandedPath, MAX_CHARS_IN_BUFFER(szExpandedPath) );
  2476. //
  2477. // 6/4/97 jmazner
  2478. // if we created a connectoid, then get its name and use that as the
  2479. // connection type. Otherwise, assume we're supposed to connect via LAN
  2480. //
  2481. connectInfo.cbSize = sizeof(CONNECTINFO);
  2482. connectInfo.type = CONNECT_LAN;
  2483. if( fConnectPhone )
  2484. {
  2485. BOOL fEnabled = FALSE;
  2486. dwRet = InetGetAutodial(&fEnabled, szConnectoidName, RAS_MaxEntryName);
  2487. if( ERROR_SUCCESS==dwRet && szConnectoidName[0] )
  2488. {
  2489. connectInfo.type = CONNECT_RAS;
  2490. lstrcpyn( connectInfo.szConnectoid, szConnectoidName, MAX_CHARS_IN_BUFFER(connectInfo.szConnectoid) );
  2491. // TraceMsg(TF_INSHANDLER, L"ImportMailAndNewsInfo: setting connection type to RAS with %s\n", szConnectoidName);
  2492. }
  2493. }
  2494. if( CONNECT_LAN == connectInfo.type )
  2495. {
  2496. // TraceMsg(TF_INSHANDLER, L"ImportMailAndNewsInfo: setting connection type to LAN\n");
  2497. lstrcpy( connectInfo.szConnectoid, L"I said CONNECT_LAN!" );
  2498. }
  2499. hInst = LoadLibrary(szExpandedPath);
  2500. if (hInst)
  2501. {
  2502. fp = (PFNCREATEACCOUNTSFROMFILEEX) GetProcAddress(hInst, "CreateAccountsFromFileEx");
  2503. if (fp)
  2504. hr = fp( W2A(lpszFile), &connectInfo, NULL );
  2505. }
  2506. else
  2507. {
  2508. // TraceMsg(TF_INSHANDLER, L"ImportMailAndNewsInfo unable to LoadLibrary on %s\n", szAcctMgrPath);
  2509. }
  2510. //
  2511. // Clean up and release resourecs
  2512. //
  2513. if( hInst)
  2514. {
  2515. FreeLibrary(hInst);
  2516. hInst = NULL;
  2517. }
  2518. if( fp )
  2519. {
  2520. fp = NULL;
  2521. }
  2522. return dwRet;
  2523. }
  2524. // ############################################################################
  2525. //
  2526. // Name: WriteMailAndNewsKey
  2527. //
  2528. // Description: Read a string value from the given INS file and write it
  2529. // to the registry
  2530. //
  2531. // Input: hKey - Registry key where the data will be written
  2532. // lpszSection - Section name inside of INS file where data is read
  2533. // from
  2534. // lpszValue - Name of value to read from INS file
  2535. // lpszBuff - buffer where data will be read into
  2536. // dwBuffLen - size of lpszBuff
  2537. // lpszSubKey - Value name where information will be written to
  2538. // dwType - data type (Should always be REG_SZ)
  2539. // lpszFileName - Fully qualified filename to INS file
  2540. //
  2541. // Return: Error value
  2542. //
  2543. // Histroy: 6/27/96 Created
  2544. //
  2545. // ############################################################################
  2546. HRESULT CINSHandler::WriteMailAndNewsKey(HKEY hKey, LPCWSTR lpszSection, LPCWSTR lpszValue,
  2547. LPWSTR lpszBuff, DWORD dwBuffLen, LPCWSTR lpszSubKey,
  2548. DWORD dwType, LPCWSTR lpszFile)
  2549. {
  2550. ZeroMemory(lpszBuff, dwBuffLen);
  2551. GetPrivateProfileString(lpszSection, lpszValue, L"", lpszBuff, dwBuffLen, lpszFile);
  2552. if (lstrlen(lpszBuff))
  2553. {
  2554. return RegSetValueEx(hKey, lpszSubKey, 0, dwType, (CONST BYTE*)lpszBuff,
  2555. BYTES_REQUIRED_BY_SZ(lpszBuff));
  2556. }
  2557. else
  2558. {
  2559. // TraceMsg(TF_INSHANDLER, L"ISIGNUP: WriteMailAndNewsKey, missing value in INS file\n");
  2560. return ERROR_NO_MORE_ITEMS;
  2561. }
  2562. }
  2563. // ############################################################################
  2564. //
  2565. // Name: PreparePassword
  2566. //
  2567. // Description: Encode given password and return value in place. The
  2568. // encoding is done right to left in order to avoid having
  2569. // to allocate a copy of the data. The encoding uses base64
  2570. // standard as specified in RFC 1341 5.2
  2571. //
  2572. // Input: szBuff - Null terminated data to be encoded
  2573. // dwBuffLen - Full length of buffer, this should exceed the length of
  2574. // the input data by at least 1/3
  2575. //
  2576. // Return: Error value
  2577. //
  2578. // Histroy: 6/27/96 Created
  2579. //
  2580. // ############################################################################
  2581. HRESULT CINSHandler::PreparePassword(LPWSTR szBuff, DWORD dwBuffLen)
  2582. {
  2583. DWORD dwX;
  2584. LPWSTR szOut = NULL;
  2585. LPWSTR szNext = NULL;
  2586. HRESULT hr = ERROR_SUCCESS;
  2587. BYTE bTemp = 0;
  2588. DWORD dwLen = 0;
  2589. dwLen = lstrlen(szBuff);
  2590. if (!dwLen)
  2591. {
  2592. hr = ERROR_INVALID_PARAMETER;
  2593. goto PreparePasswordExit;
  2594. }
  2595. // Calculate the size of the buffer that will be needed to hold
  2596. // encoded data
  2597. //
  2598. szNext = &szBuff[dwLen-1];
  2599. dwLen = (((dwLen % 3 ? (3-(dwLen%3)):0) + dwLen) * 4 / 3);
  2600. if (dwBuffLen < dwLen+1)
  2601. {
  2602. hr = ERROR_INVALID_PARAMETER;
  2603. goto PreparePasswordExit;
  2604. }
  2605. szOut = &szBuff[dwLen];
  2606. *szOut-- = L'\0';
  2607. // Add padding = characters
  2608. //
  2609. switch (lstrlen(szBuff) % 3)
  2610. {
  2611. case 0:
  2612. // no padding
  2613. break;
  2614. case 1:
  2615. *szOut-- = 64;
  2616. *szOut-- = 64;
  2617. *szOut-- = (*szNext & 0x3) << 4;
  2618. *szOut-- = (*szNext-- & 0xFC) >> 2;
  2619. break;
  2620. case 2:
  2621. *szOut-- = 64;
  2622. *szOut-- = (*szNext & 0xF) << 2;
  2623. *szOut = ((*szNext-- & 0xF0) >> 4);
  2624. *szOut-- |= ((*szNext & 0x3) << 4);
  2625. *szOut-- = (*szNext-- & 0xFC) >> 2;
  2626. }
  2627. // Encrypt data into indicies
  2628. //
  2629. while (szOut > szNext && szNext >= szBuff)
  2630. {
  2631. *szOut-- = *szNext & 0x3F;
  2632. *szOut = ((*szNext-- & 0xC0) >> 6);
  2633. *szOut-- |= ((*szNext & 0xF) << 2);
  2634. *szOut = ((*szNext-- & 0xF0) >> 4);
  2635. *szOut-- |= ((*szNext & 0x3) << 4);
  2636. *szOut-- = (*szNext-- & 0xFC) >> 2;
  2637. }
  2638. // Translate indicies into printable characters
  2639. //
  2640. szNext = szBuff;
  2641. // BUG OSR#10435--if there is a 0 in the generated string of base-64
  2642. // encoded digits (this can happen if the password is "Willypassword"
  2643. // for example), then instead of encoding the 0 to 'A', we just quit
  2644. // at this point, produces an invalid base-64 string.
  2645. for(dwX=0; dwX < dwLen; dwX++)
  2646. *szNext = arBase64[*szNext++];
  2647. PreparePasswordExit:
  2648. return hr;
  2649. }
  2650. // ############################################################################
  2651. //
  2652. // Name: FIsAthenaPresent
  2653. //
  2654. // Description: Determine if Microsoft Internet Mail And News client (Athena)
  2655. // is installed
  2656. //
  2657. // Input: none
  2658. //
  2659. // Return: TRUE - Athena is installed
  2660. // FALSE - Athena is NOT installed
  2661. //
  2662. // History: 7/1/96 Created
  2663. //
  2664. // ############################################################################
  2665. BOOL CINSHandler::FIsAthenaPresent()
  2666. {
  2667. WCHAR szBuff[MAX_PATH + 1];
  2668. HRESULT hr = ERROR_SUCCESS;
  2669. HINSTANCE hInst = NULL;
  2670. DWORD dwLen = 0;
  2671. DWORD dwType = REG_SZ;
  2672. // Get path to Athena client
  2673. //
  2674. dwLen = MAX_PATH;
  2675. hr = RegQueryValueEx(HKEY_CLASSES_ROOT,
  2676. MAIL_NEWS_INPROC_SERVER32,
  2677. NULL,
  2678. &dwType,
  2679. (LPBYTE) szBuff,
  2680. &dwLen);
  2681. if (hr == ERROR_SUCCESS)
  2682. {
  2683. // Attempt to load client
  2684. //
  2685. hInst = LoadLibrary(szBuff);
  2686. if (!hInst)
  2687. {
  2688. // TraceMsg(TF_INSHANDLER, L"ISIGNUP: Internet Mail and News server didn't load.\n");
  2689. hr = ERROR_FILE_NOT_FOUND;
  2690. }
  2691. else
  2692. {
  2693. FreeLibrary(hInst);
  2694. }
  2695. hInst = NULL;
  2696. }
  2697. return (hr == ERROR_SUCCESS);
  2698. }
  2699. // ############################################################################
  2700. //
  2701. // Name: FTurnOffBrowserDefaultChecking
  2702. //
  2703. // Description: Turn Off IE checking to see if it is the default browser
  2704. //
  2705. // Input: none
  2706. //
  2707. // Output: TRUE - success
  2708. // FALSE - failed
  2709. //
  2710. // History: 7/2/96 Created
  2711. //
  2712. // ############################################################################
  2713. BOOL CINSHandler::FTurnOffBrowserDefaultChecking()
  2714. {
  2715. HKEY hKey = NULL;
  2716. DWORD dwType = 0;
  2717. DWORD dwSize = 0;
  2718. BOOL bRC = TRUE;
  2719. //
  2720. // Open IE settings registry key
  2721. //
  2722. if (RegOpenKey(HKEY_CURRENT_USER, cszDEFAULT_BROWSER_KEY, &hKey))
  2723. {
  2724. bRC = FALSE;
  2725. goto FTurnOffBrowserDefaultCheckingExit;
  2726. }
  2727. //
  2728. // Read current settings for check associations
  2729. //
  2730. dwType = 0;
  2731. dwSize = sizeof(m_szCheckAssociations);
  2732. ZeroMemory(m_szCheckAssociations, dwSize);
  2733. RegQueryValueEx(hKey,
  2734. cszDEFAULT_BROWSER_VALUE,
  2735. 0,
  2736. &dwType,
  2737. (LPBYTE)m_szCheckAssociations,
  2738. &dwSize);
  2739. // ignore return value, even if the calls fails we are going to try
  2740. // to change the setting to "NO"
  2741. //
  2742. // Set value to "no" to turn off checking
  2743. //
  2744. if (RegSetValueEx(hKey,
  2745. cszDEFAULT_BROWSER_VALUE,
  2746. 0,
  2747. REG_SZ,
  2748. (LPBYTE)cszNo,
  2749. BYTES_REQUIRED_BY_SZ(cszNo)))
  2750. {
  2751. bRC = FALSE;
  2752. goto FTurnOffBrowserDefaultCheckingExit;
  2753. }
  2754. //
  2755. // Clean up and return
  2756. //
  2757. FTurnOffBrowserDefaultCheckingExit:
  2758. if (hKey)
  2759. RegCloseKey(hKey);
  2760. if (bRC)
  2761. m_fResforeDefCheck = TRUE;
  2762. hKey = NULL;
  2763. return bRC;
  2764. }
  2765. // ############################################################################
  2766. //
  2767. // Name: FRestoreBrowserDefaultChecking
  2768. //
  2769. // Description: Restore IE checking to see if it is the default browser
  2770. //
  2771. // Input: none
  2772. //
  2773. // Output: TRUE - success
  2774. // FALSE - failed
  2775. //
  2776. // History: 7/2/96 Created
  2777. //
  2778. // ############################################################################
  2779. BOOL CINSHandler::FRestoreBrowserDefaultChecking()
  2780. {
  2781. HKEY hKey = NULL;
  2782. BOOL bRC = TRUE;
  2783. //
  2784. // Open IE settings registry key
  2785. //
  2786. if (RegOpenKey(HKEY_CURRENT_USER, cszDEFAULT_BROWSER_KEY, &hKey))
  2787. {
  2788. bRC = FALSE;
  2789. goto FRestoreBrowserDefaultCheckingExit;
  2790. }
  2791. //
  2792. // Set value to original value
  2793. //
  2794. if (RegSetValueEx(hKey,
  2795. cszDEFAULT_BROWSER_VALUE,
  2796. 0,
  2797. REG_SZ,
  2798. (LPBYTE)m_szCheckAssociations,
  2799. BYTES_REQUIRED_BY_SZ(m_szCheckAssociations)))
  2800. {
  2801. bRC = FALSE;
  2802. goto FRestoreBrowserDefaultCheckingExit;
  2803. }
  2804. FRestoreBrowserDefaultCheckingExit:
  2805. if (hKey)
  2806. RegCloseKey(hKey);
  2807. hKey = NULL;
  2808. return bRC;
  2809. }
  2810. // This is the main entry point for processing an INS file.
  2811. // DJM: BUGBUG: TODO: Need to pass in branding flags
  2812. HRESULT CINSHandler::ProcessINS(
  2813. LPCWSTR lpszFile,
  2814. LPWSTR lpszConnectoidName,
  2815. BOOL * pbRetVal
  2816. )
  2817. {
  2818. BOOL fConnectoidCreated = FALSE;
  2819. BOOL fClientSetup = FALSE;
  2820. BOOL bKeepConnection = FALSE;
  2821. BOOL fErrMsgShown = FALSE;
  2822. HRESULT hr = E_FAIL;
  2823. LPRASENTRY lpRasEntry = NULL;
  2824. WCHAR szTemp[3] = L"\0";
  2825. WCHAR szConnectoidName[RAS_MaxEntryName] = L"";
  2826. if (NULL == lpszFile || NULL == lpszConnectoidName || NULL == pbRetVal )
  2827. {
  2828. MYASSERT(FALSE);
  2829. return E_INVALIDARG;
  2830. }
  2831. *pbRetVal = FALSE;
  2832. // The Connection has not been killed yet
  2833. m_fConnectionKilled = FALSE;
  2834. m_fNeedsRestart = FALSE;
  2835. MYASSERT(NULL != lpszFile);
  2836. if (0xFFFFFFFF == GetFileAttributes(lpszFile))
  2837. {
  2838. return E_FAIL;
  2839. }
  2840. do
  2841. {
  2842. // Make sure we can load the necessary extern support functions
  2843. if (!LoadExternalFunctions())
  2844. break;
  2845. // Convert EOL chars in the passed file.
  2846. if (FAILED(MassageFile(lpszFile)))
  2847. {
  2848. break;
  2849. }
  2850. if(GetPrivateProfileString(cszURLSection,
  2851. cszStartURL,
  2852. szNull,
  2853. m_szStartURL,
  2854. MAX_CHARS_IN_BUFFER(m_szStartURL),
  2855. lpszFile) == 0)
  2856. {
  2857. m_szStartURL[0] = L'\0';
  2858. }
  2859. if (GetPrivateProfileString(cszEntrySection,
  2860. cszCancel,
  2861. szNull,
  2862. szTemp,
  2863. MAX_CHARS_IN_BUFFER(szTemp),
  2864. lpszFile) != 0)
  2865. {
  2866. // We do not want to process a CANCEL.INS file
  2867. // here.
  2868. break;
  2869. }
  2870. // See if this INS has a client setup section
  2871. if (GetPrivateProfileSection(cszClientSetupSection,
  2872. szTemp,
  2873. MAX_CHARS_IN_BUFFER(szTemp),
  2874. lpszFile) != 0)
  2875. fClientSetup = TRUE;
  2876. // Process the trial reminder section, if it exists. this needs to be
  2877. // done BEFORE we allow the connection to be closed
  2878. //
  2879. // VYUNG 2/25/99 ReminderApp not supported by OOBE.
  2880. // Ask WJPARK for more questions
  2881. /*
  2882. if (ConfigureTrialReminder(lpszFile))
  2883. {
  2884. // We configured a trial, so we need to launch the remind app now
  2885. SHELLEXECUTEINFO sei;
  2886. sei.cbSize = sizeof(sei);
  2887. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  2888. sei.hwnd = NULL;
  2889. sei.lpVerb = cszOpen;
  2890. sei.lpFile = cszReminderApp;
  2891. sei.lpParameters = cszReminderParams;
  2892. sei.lpDirectory = NULL;
  2893. sei.nShow = SW_SHOWNORMAL;
  2894. sei.hInstApp = NULL;
  2895. // Optional members
  2896. sei.hProcess = NULL;
  2897. ShellExecuteEx(&sei);
  2898. }*/
  2899. // Check to see if we should keep the connection open. The custom section
  2900. // might want this for processing stuff
  2901. if (!fClientSetup && !KeepConnection(lpszFile))
  2902. {
  2903. // Kill the connection
  2904. gpCommMgr->m_pRefDial->DoHangup();
  2905. m_fConnectionKilled = TRUE;
  2906. }
  2907. // Import the Custom Info
  2908. ImportCustomInfo(lpszFile,
  2909. m_szRunExecutable,
  2910. MAX_CHARS_IN_BUFFER(m_szRunExecutable),
  2911. m_szRunArgument,
  2912. MAX_CHARS_IN_BUFFER(m_szRunArgument));
  2913. ImportCustomFile(lpszFile);
  2914. // configure the client.
  2915. hr = ConfigureClient(GetActiveWindow(),
  2916. lpszFile,
  2917. &m_fNeedsRestart,
  2918. &fConnectoidCreated,
  2919. FALSE,
  2920. szConnectoidName,
  2921. RAS_MaxEntryName);
  2922. if( ERROR_SUCCESS != hr )
  2923. {
  2924. /*if(!m_bSilentMode)
  2925. ErrorMsg1(GetActiveWindow(), IDS_INSTALLFAILED, NULL);*/
  2926. fErrMsgShown = TRUE;
  2927. }
  2928. lstrcpy(lpszConnectoidName, szConnectoidName);
  2929. ImportBrandingInfo(lpszFile, szConnectoidName);
  2930. // If we created a connectoid, tell the world that ICW
  2931. // has left the building...
  2932. if(ERROR_SUCCESS == hr)
  2933. SetICWCompleted( (DWORD)1 );
  2934. // 2/19/97 jmazner Olympus 1106
  2935. // For SBS/SAM integration.
  2936. DWORD dwSBSRet = CallSBSConfig(GetActiveWindow(), lpszFile);
  2937. switch( dwSBSRet )
  2938. {
  2939. case ERROR_SUCCESS:
  2940. break;
  2941. case ERROR_MOD_NOT_FOUND:
  2942. case ERROR_DLL_NOT_FOUND:
  2943. // TraceMsg(TF_INSHANDLER, L"ISIGN32: SBSCFG DLL not found, I guess SAM ain't installed.\n");
  2944. break;
  2945. }
  2946. //
  2947. // If the INS file contains the ClientSetup section, build the commandline
  2948. // arguments for ICWCONN2.exe.
  2949. //
  2950. if (fClientSetup)
  2951. {
  2952. // Check to see if a REBOOT is needed and tell the next application to
  2953. // handle it.
  2954. if (m_fNeedsRestart)
  2955. {
  2956. wsprintf(m_szRunArgument, L" /INS:\"%s\" /REBOOT", lpszFile);
  2957. m_fNeedsRestart = FALSE;
  2958. }
  2959. else
  2960. {
  2961. wsprintf(m_szRunArgument, L" /INS:\"%s\"", lpszFile);
  2962. }
  2963. }
  2964. // humongous hack for ISBU
  2965. if (ERROR_SUCCESS != hr && fConnectoidCreated)
  2966. {
  2967. //if(!m_bSilentMode)
  2968. // InfoMsg1(GetActiveWindow(), IDS_MAILFAILED, NULL);
  2969. hr = ERROR_SUCCESS;
  2970. }
  2971. //
  2972. // Import settings for mail and new read from INS file (ChrisK, 7/1/96)
  2973. //
  2974. if (ERROR_SUCCESS == hr)
  2975. {
  2976. ImportMailAndNewsInfo(lpszFile, fConnectoidCreated);
  2977. // If we did not create a connectiod, then restore
  2978. // the autodial one
  2979. if (!fConnectoidCreated)
  2980. {
  2981. RestoreAutoDial();
  2982. }
  2983. else
  2984. {
  2985. SetDefaultConnectoid(AutodialTypeAlways, szConnectoidName);
  2986. }
  2987. //InetSetAutodial(TRUE, m_szAutodialConnection);
  2988. // Delete the INS file now
  2989. /**** VYUNG DO NOT REMOVE ISP FILE IN OOBE ****
  2990. if (m_szRunExecutable[0] == L'\0')
  2991. {
  2992. DeleteFile(lpszFile);
  2993. }*/
  2994. }
  2995. else
  2996. {
  2997. RestoreAutoDial();
  2998. }
  2999. if (m_szRunExecutable[0] != L'\0')
  3000. {
  3001. // Fire an event to the container telling it that we are
  3002. // about to run a custom executable
  3003. //Fire_RunningCustomExecutable();
  3004. if FAILED(RunExecutable())
  3005. {
  3006. //if(!m_bSilentMode)
  3007. // ErrorMsg1(NULL, IDS_EXECFAILED, m_szRunExecutable);
  3008. }
  3009. // If the Connection has not been killed yet
  3010. // then tell the browser to do it now
  3011. if (!m_fConnectionKilled)
  3012. {
  3013. gpCommMgr->m_pRefDial->DoHangup();
  3014. m_fConnectionKilled = TRUE;
  3015. }
  3016. }
  3017. // If we get to here, we are successful.
  3018. if(fConnectoidCreated && SUCCEEDED(hr))
  3019. *pbRetVal = TRUE;
  3020. break;
  3021. } while(1);
  3022. return S_OK;
  3023. }
  3024. // If this is true, then the user will need to reboot, so
  3025. // the finish page should indicate this.
  3026. STDMETHODIMP CINSHandler::get_NeedRestart(BOOL *pVal)
  3027. {
  3028. if (pVal == NULL)
  3029. return E_POINTER;
  3030. *pVal = m_fNeedsRestart;
  3031. return S_OK;
  3032. }
  3033. STDMETHODIMP CINSHandler::put_BrandingFlags(long lFlags)
  3034. {
  3035. m_dwBrandFlags = lFlags;
  3036. return S_OK;
  3037. }
  3038. STDMETHODIMP CINSHandler::put_SilentMode(BOOL bSilent)
  3039. {
  3040. m_bSilentMode = bSilent;
  3041. return S_OK;
  3042. }
  3043. // If this is true, get the URL from the INS file
  3044. STDMETHODIMP CINSHandler::get_DefaultURL(BSTR *pszURL)
  3045. {
  3046. if (pszURL == NULL)
  3047. return E_POINTER;
  3048. *pszURL = SysAllocString(m_szStartURL);
  3049. return S_OK;
  3050. }
  3051. // This is the main entry point for merge an INS file.
  3052. HRESULT CINSHandler::MergeINSFiles(LPCWSTR lpszMainFile, LPCWSTR lpszOtherFile, LPWSTR lpszOutputFile, DWORD dwFNameSize)
  3053. {
  3054. PWSTR pszSection;
  3055. WCHAR *pszKeys = NULL;
  3056. PWSTR pszKey = NULL;
  3057. WCHAR szValue[MAX_PATH];
  3058. WCHAR szTempFileFullName[MAX_PATH];
  3059. ULONG ulRetVal = 0;
  3060. HRESULT hr = E_FAIL;
  3061. ULONG ulBufferSize = MAX_SECTIONS_BUFFER;
  3062. WCHAR *pszSections = NULL;
  3063. if (dwFNameSize < MAX_PATH)
  3064. goto MergeINSFilesExit;
  3065. // Check if branding file doesn't exists, just use the original
  3066. if (0xFFFFFFFF == GetFileAttributes(lpszOtherFile))
  3067. {
  3068. lstrcpy(lpszOutputFile, lpszMainFile);
  3069. return S_OK;
  3070. }
  3071. // Make sure it is an htm extension, otherwise, IE will promp for download
  3072. GetTempPath(MAX_CHARS_IN_BUFFER(szTempFileFullName), szTempFileFullName);
  3073. lstrcat(szTempFileFullName, L"OBEINS.htm");
  3074. if(!CopyFile(lpszMainFile, szTempFileFullName, FALSE))
  3075. goto MergeINSFilesExit;
  3076. lstrcpy(lpszOutputFile, szTempFileFullName);
  3077. //
  3078. // Unfortunately the .ini file functions don't offer a direct way of updating
  3079. // some entry value. So enumerate each of the sections of the .ini file, enumerate
  3080. // each of the keys within each section, get the value for each of the keys,
  3081. // write them to the value specified and if they compare equal.
  3082. //
  3083. // Loop to find the appropriate buffer size to retieve the ins to memory
  3084. do
  3085. {
  3086. if (NULL != pszSections)
  3087. {
  3088. GlobalFree( pszSections);
  3089. ulBufferSize += ulBufferSize;
  3090. }
  3091. pszSections = (LPWSTR)GlobalAlloc(GPTR, ulBufferSize*sizeof(WCHAR));
  3092. if (NULL == pszSections)
  3093. {
  3094. goto MergeINSFilesExit;
  3095. }
  3096. ulRetVal = ::GetPrivateProfileString(NULL, NULL, L"", pszSections, ulBufferSize, lpszOtherFile);
  3097. if (0 == ulRetVal)
  3098. {
  3099. goto MergeINSFilesExit;
  3100. }
  3101. } while (ulRetVal == (ulBufferSize - 2));
  3102. pszSection = pszSections;
  3103. ulRetVal= 0;
  3104. while (*pszSection)
  3105. {
  3106. ulBufferSize = MAX_KEYS_BUFFER;
  3107. ulRetVal = 0;
  3108. // Loop to find the appropriate buffer size to retieve the ins to memory
  3109. do
  3110. {
  3111. if (NULL != pszKeys)
  3112. {
  3113. GlobalFree( pszKeys );
  3114. ulBufferSize += ulBufferSize;
  3115. }
  3116. pszKeys = (LPWSTR)GlobalAlloc(GPTR, ulBufferSize*sizeof(WCHAR));
  3117. if (NULL == pszKeys)
  3118. {
  3119. goto MergeINSFilesExit;
  3120. }
  3121. ulRetVal = ::GetPrivateProfileString(pszSection, NULL, L"", pszKeys, ulBufferSize, lpszOtherFile);
  3122. if (0 == ulRetVal)
  3123. {
  3124. goto MergeINSFilesExit;
  3125. }
  3126. } while (ulRetVal == (ulBufferSize - 2));
  3127. // Enumerate each key value pair in the section
  3128. pszKey = pszKeys;
  3129. while (*pszKey)
  3130. {
  3131. ulRetVal = ::GetPrivateProfileString(pszSection, pszKey, L"", szValue, MAX_CHARS_IN_BUFFER(szValue), lpszOtherFile);
  3132. if ((ulRetVal != 0) && (ulRetVal < (MAX_CHARS_IN_BUFFER(szValue) - 1)))
  3133. {
  3134. WritePrivateProfileString(pszSection, pszKey, szValue, szTempFileFullName);
  3135. }
  3136. pszKey += lstrlen(pszKey) + 1;
  3137. }
  3138. pszSection += lstrlen(pszSection) + 1;
  3139. }
  3140. hr = S_OK;
  3141. MergeINSFilesExit:
  3142. if (pszSections)
  3143. GlobalFree( pszSections );
  3144. if (pszKeys)
  3145. GlobalFree( pszKeys );
  3146. return hr;
  3147. }
  3148. /*******************************************************************
  3149. NAME: ProcessOEMBrandINS
  3150. SYNOPSIS: Read OfflineOffers flag from the oeminfo.ini file
  3151. ENTRY: None
  3152. RETURN: True if OEM offline is read
  3153. ********************************************************************/
  3154. BOOL CINSHandler::ProcessOEMBrandINS(
  3155. BSTR bstrFileName,
  3156. LPWSTR lpszConnectoidName
  3157. )
  3158. {
  3159. // OEM code
  3160. //
  3161. WCHAR szOeminfoPath [MAX_PATH + 1];
  3162. WCHAR szMergedINSFName [MAX_PATH + 1];
  3163. WCHAR szOrigINSFile [MAX_PATH + 1];
  3164. WCHAR *lpszTerminator = NULL;
  3165. WCHAR *lpszLastChar = NULL;
  3166. BOOL bRet = FALSE;
  3167. // If we already checked, don't do it again
  3168. //if( 0 != GetSystemDirectory( szOeminfoPath, MAX_PATH + 1 ) )
  3169. {
  3170. /*
  3171. lpszTerminator = &(szOeminfoPath[ lstrlen(szOeminfoPath) ]);
  3172. lpszLastChar = CharPrev( szOeminfoPath, lpszTerminator );
  3173. if( L'\\' != *lpszLastChar )
  3174. {
  3175. lpszLastChar = CharNext( lpszLastChar );
  3176. *lpszLastChar = L'\\';
  3177. lpszLastChar = CharNext( lpszLastChar );
  3178. *lpszLastChar = L'\0';
  3179. }
  3180. if (bstrFileName)
  3181. {
  3182. // Download INS case
  3183. lstrcat( szOeminfoPath, cszOEMBRND );
  3184. lstrcpy( szOrigINSFile, bstrFileName);
  3185. }
  3186. else
  3187. {
  3188. // Proconfig case
  3189. lstrcpy( szPreCfgINSPath, szOeminfoPath);
  3190. lstrcat( szPreCfgINSPath, cszISPCNFG );
  3191. lstrcat( szOeminfoPath, cszOEMBRND );
  3192. lstrcpy( szOrigINSFile, szPreCfgINSPath);
  3193. }
  3194. */
  3195. // find the oemcnfg.ins file
  3196. if (0 == SearchPath(NULL, cszOEMCNFG, NULL, MAX_PATH, szOeminfoPath, NULL))
  3197. {
  3198. *szOeminfoPath = L'\0';
  3199. }
  3200. if (bstrFileName) // if Filename is there, read the ins file
  3201. {
  3202. lstrcpy( szOrigINSFile, bstrFileName);
  3203. }
  3204. else
  3205. {
  3206. // find the ISPCNFG.ins file
  3207. // If it is not there, it is ok. It is not an error condition. Just bail out.
  3208. WCHAR szINSPath[MAX_PATH];
  3209. if (!GetOOBEPath((LPWSTR)szINSPath))
  3210. return 0;
  3211. lstrcat(szINSPath, L"\\HTML\\ISPSGNUP");
  3212. if (0 == SearchPath(szINSPath, cszISPCNFG, NULL, MAX_PATH, szOrigINSFile, NULL))
  3213. {
  3214. *szOrigINSFile = L'\0';
  3215. return 0;
  3216. }
  3217. }
  3218. if (S_OK == MergeINSFiles(szOrigINSFile , szOeminfoPath, szMergedINSFName, MAX_PATH))
  3219. {
  3220. ProcessINS(szMergedINSFName, lpszConnectoidName, &bRet);
  3221. }
  3222. if (!bRet)
  3223. {
  3224. HKEY hKey = NULL;
  3225. DWORD dwDisposition = 0;
  3226. DWORD dwFailed = 1;
  3227. WCHAR szIspName [MAX_PATH+1] = L"\0";
  3228. WCHAR szSupportNum [MAX_PATH+1] = L"\0";
  3229. //ProcessINS will nuke the file so if we want this info we should get it now
  3230. GetPrivateProfileString(OEM_CONFIG_INS_SECTION,
  3231. OEM_CONFIG_INS_ISPNAME,
  3232. L"",
  3233. szIspName,
  3234. MAX_CHARS_IN_BUFFER(szIspName),
  3235. szMergedINSFName);
  3236. GetPrivateProfileString(OEM_CONFIG_INS_SECTION,
  3237. OEM_CONFIG_INS_SUPPORTNUM,
  3238. L"",
  3239. szSupportNum,
  3240. MAX_CHARS_IN_BUFFER(szSupportNum),
  3241. szMergedINSFName);
  3242. RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  3243. OEM_CONFIG_REGKEY,
  3244. 0,
  3245. NULL,
  3246. REG_OPTION_NON_VOLATILE,
  3247. KEY_ALL_ACCESS,
  3248. NULL,
  3249. &hKey,
  3250. &dwDisposition);
  3251. if(hKey)
  3252. {
  3253. RegSetValueEx(hKey,
  3254. OEM_CONFIG_REGVAL_FAILED,
  3255. 0,
  3256. REG_DWORD,
  3257. (LPBYTE)&dwFailed,
  3258. sizeof(dwFailed));
  3259. RegSetValueEx(hKey,
  3260. OEM_CONFIG_REGVAL_ISPNAME,
  3261. 0,
  3262. REG_SZ,
  3263. (LPBYTE)szIspName,
  3264. BYTES_REQUIRED_BY_SZ(szIspName)
  3265. );
  3266. RegSetValueEx(hKey,
  3267. OEM_CONFIG_REGVAL_SUPPORTNUM,
  3268. 0,
  3269. REG_SZ,
  3270. (LPBYTE)szSupportNum,
  3271. BYTES_REQUIRED_BY_SZ(szSupportNum)
  3272. );
  3273. RegCloseKey(hKey);
  3274. }
  3275. }
  3276. }
  3277. return bRet;
  3278. }
  3279. // This function will restore connetoid password
  3280. HRESULT CINSHandler::RestoreConnectoidInfo()
  3281. {
  3282. WCHAR szPassword[PWLEN+1];
  3283. WCHAR szConnectoid[MAX_RASENTRYNAME+1];
  3284. LPRASDIALPARAMS lpRasDialParams = NULL;
  3285. HRESULT hr = ERROR_SUCCESS;
  3286. BOOL bPW;
  3287. DWORD dwSize;
  3288. RNAAPI *pcRNA = new RNAAPI;
  3289. if (!pcRNA)
  3290. {
  3291. hr = ERROR_NOT_ENOUGH_MEMORY;
  3292. goto RestoreConnectoidInfoExit;
  3293. }
  3294. dwSize = sizeof(szConnectoid);
  3295. ReadSignUpReg((LPBYTE)szConnectoid, &dwSize, REG_SZ, CONNECTOIDNAME);
  3296. // Get connectoid information
  3297. //
  3298. lpRasDialParams = (LPRASDIALPARAMS)GlobalAlloc(GPTR, sizeof(RASDIALPARAMS));
  3299. if (!lpRasDialParams)
  3300. {
  3301. hr = ERROR_NOT_ENOUGH_MEMORY;
  3302. goto RestoreConnectoidInfoExit;
  3303. }
  3304. lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
  3305. lstrcpyn(lpRasDialParams->szEntryName, szConnectoid, MAX_CHARS_IN_BUFFER(lpRasDialParams->szEntryName));
  3306. bPW = FALSE;
  3307. hr = pcRNA->RasGetEntryDialParams(NULL, lpRasDialParams, &bPW);
  3308. if (hr != ERROR_SUCCESS)
  3309. {
  3310. goto RestoreConnectoidInfoExit;
  3311. }
  3312. // If the original connectoid had password, do not reset it
  3313. if (lstrlen(lpRasDialParams->szPassword) == 0)
  3314. {
  3315. szPassword[0] = 0;
  3316. dwSize = sizeof(szPassword);
  3317. ReadSignUpReg((LPBYTE)szPassword, &dwSize, REG_SZ, ACCESSINFO);
  3318. if(szPassword[0])
  3319. lstrcpy(lpRasDialParams->szPassword, szPassword);
  3320. hr = pcRNA->RasSetEntryDialParams(NULL, lpRasDialParams, FALSE);
  3321. }
  3322. RestoreConnectoidInfoExit:
  3323. DeleteSignUpReg(CONNECTOIDNAME);
  3324. DeleteSignUpReg(ACCESSINFO);
  3325. if (lpRasDialParams)
  3326. GlobalFree(lpRasDialParams);
  3327. lpRasDialParams = NULL;
  3328. if (pcRNA)
  3329. delete pcRNA;
  3330. return hr;
  3331. }
  3332. DWORD CINSHandler::InetSImportLanConnection(LANINFO& LANINFO, LPCWSTR cszINSFile)
  3333. {
  3334. if (
  3335. cszINSFile &&
  3336. ( GetPrivateProfileString( cszDeviceSection, cszPnpId, L"", LANINFO.szPnPId, MAX_CHARS_IN_BUFFER (LANINFO.szPnPId), cszINSFile ) != 0 ) &&
  3337. ( InetSImportTcpIpModule ( LANINFO.TcpIpInfo, cszINSFile ) == ERROR_SUCCESS )
  3338. )
  3339. return ERROR_SUCCESS;
  3340. else return E_FAIL;
  3341. }
  3342. // Caution: Memory might have been allocated.
  3343. // this function is currently not used, due to lack of legacy support.
  3344. DWORD CINSHandler::InetSImportRasConnection(RASINFO &RasEntry, LPCWSTR cszINSFile)
  3345. {
  3346. if (!cszINSFile) return ERROR_INVALID_PARAMETER;
  3347. // how do you get the RAS Entry and RAS Phonebook Entry information ?
  3348. ImportPhoneInfo ( &RasEntry.RasEntry, cszINSFile );
  3349. ImportServerInfo( &RasEntry.RasEntry, cszINSFile );
  3350. ImportIPInfo ( &RasEntry.RasEntry, cszINSFile );
  3351. // Now, we consider the device-specific data.
  3352. switch ( m_dwDeviceType ) {
  3353. case InetS_RASAtm: {
  3354. ATMPBCONFIG AtmMod;
  3355. memset ( &AtmMod, 0, sizeof (ATMPBCONFIG) );
  3356. if (InetSImportAtmModule ( AtmMod, cszINSFile ) != ERROR_SUCCESS) {
  3357. // function aborted as ATM Module fails
  3358. return E_ABORT;
  3359. }
  3360. // copy this into the RASINFO Buffer.
  3361. // the lpDeviceInfo and dwDeviceInfoSize cannot have been previously used!
  3362. if ( RasEntry.lpDeviceInfo || RasEntry.dwDeviceInfoSize ) {
  3363. return ERROR_INVALID_PARAMETER;
  3364. }
  3365. if (! (RasEntry.lpDeviceInfo = (LPBYTE) malloc (sizeof(ATMPBCONFIG))) ) {
  3366. return ERROR_NOT_ENOUGH_MEMORY;
  3367. }
  3368. memcpy ( RasEntry.lpDeviceInfo, &AtmMod, sizeof (ATMPBCONFIG) );
  3369. RasEntry.dwDeviceInfoSize = sizeof (ATMPBCONFIG);
  3370. }
  3371. break;
  3372. default:
  3373. break;
  3374. }
  3375. return ERROR_SUCCESS;
  3376. }
  3377. DWORD CINSHandler::InetSImportTcpIpModule(TCPIP_INFO_EXT &TcpIpInfoMod, LPCWSTR cszINSFile)
  3378. {
  3379. DWORD nReturnValue = ERROR_SUCCESS;
  3380. WCHAR szYesNo [GEN_MAX_STRING_LENGTH]; // temporary buffer for storing Yes/No results
  3381. if (!cszINSFile) {
  3382. return ERROR_INVALID_PARAMETER;
  3383. }
  3384. // IP
  3385. GetPrivateProfileString( cszIPSection, cszIPSpec, cszNo, szYesNo, MAX_CHARS_IN_BUFFER (szYesNo ), cszINSFile );
  3386. if (!(TcpIpInfoMod.EnableIP = !lstrcmpi(szYesNo, cszYes))) {
  3387. // we do not need to look for IPAddress or IPMask values if EnableIP is false.
  3388. goto GATEWAY;
  3389. }
  3390. GetPrivateProfileString( cszIPSection, cszIPAddress, cszNullIP, TcpIpInfoMod.szIPAddress, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szIPAddress), cszINSFile );
  3391. GetPrivateProfileString( cszIPSection, cszIPMask, cszNullIP, TcpIpInfoMod.szIPMask, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szIPMask), cszINSFile );
  3392. GATEWAY:
  3393. GetPrivateProfileString( cszIPSection, cszGatewayList, cszNullIP, TcpIpInfoMod.szDefaultGatewayList, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szDefaultGatewayList), cszINSFile );
  3394. // DNS: we do not need to mention "DNS:" but will do so within comments, for clarity.
  3395. // DNS
  3396. GetPrivateProfileString( cszIPSection, cszDNSSpec, cszNo, szYesNo, MAX_CHARS_IN_BUFFER (szYesNo ), cszINSFile );
  3397. if (!(TcpIpInfoMod.EnableDNS = !lstrcmpi(szYesNo, cszYes))) {
  3398. // we do not need to look for other DNS entries if EnableDNS is false.
  3399. goto WINS;
  3400. }
  3401. GetPrivateProfileString( cszIPSection, cszHostName, cszNull, TcpIpInfoMod.szHostName, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szHostName), cszINSFile );
  3402. GetPrivateProfileString( cszIPSection, cszDomainName, cszNull, TcpIpInfoMod.szDomainName, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szDomainName), cszINSFile );
  3403. GetPrivateProfileString( cszIPSection, cszDNSList, cszNullIP, TcpIpInfoMod.szDNSList, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szDNSList), cszINSFile );
  3404. GetPrivateProfileString( cszIPSection, cszDomainSuffixSearchList, cszNull, TcpIpInfoMod.szSuffixSearchList, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szSuffixSearchList), cszINSFile );
  3405. // WINS
  3406. WINS:
  3407. GetPrivateProfileString( cszIPSection, cszWINSSpec, cszNo, szYesNo, MAX_CHARS_IN_BUFFER (szYesNo ), cszINSFile );
  3408. if (!(TcpIpInfoMod.EnableWINS = !lstrcmpi(szYesNo, cszYes))) {
  3409. // we do not need to look for other DNS entries if EnableDNS is false.
  3410. goto DHCP;
  3411. }
  3412. GetPrivateProfileString( cszIPSection, cszWINSList, cszNullIP, TcpIpInfoMod.szWINSList, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szWINSList), cszINSFile );
  3413. TcpIpInfoMod.uiScopeID = GetPrivateProfileInt ( cszIPSection, cszScopeID, ~0x0, cszINSFile );
  3414. // DHCP
  3415. DHCP:
  3416. GetPrivateProfileString( cszIPSection, cszDHCPSpec, cszNo, szYesNo, MAX_CHARS_IN_BUFFER (szYesNo ), cszINSFile );
  3417. if (!(TcpIpInfoMod.EnableDHCP = !lstrcmpi(szYesNo, cszYes))) {
  3418. // we do not need to look for other DNS entries if EnableDNS is false.
  3419. goto end;
  3420. }
  3421. GetPrivateProfileString( cszIPSection, cszDHCPServer, cszNullIP, TcpIpInfoMod.szDHCPServer, MAX_CHARS_IN_BUFFER (TcpIpInfoMod.szDHCPServer), cszINSFile );
  3422. end:
  3423. return nReturnValue;
  3424. }
  3425. DWORD CINSHandler::InetSImportRfc1483Connection ( RFC1483INFO &Rfc1483Info, LPCWSTR cszINSFile )
  3426. {
  3427. BOOL bBufGiven = FALSE;
  3428. if ( !cszINSFile ) return ERROR_INVALID_PARAMETER;
  3429. if ( ( Rfc1483Info.Rfc1483Module.dwRegSettingsBufSize!=0 && Rfc1483Info.Rfc1483Module.lpbRegSettingsBuf==NULL) ||
  3430. ( Rfc1483Info.Rfc1483Module.dwRegSettingsBufSize==0 && Rfc1483Info.Rfc1483Module.lpbRegSettingsBuf!=NULL)
  3431. )
  3432. {
  3433. return ERROR_INVALID_PARAMETER;
  3434. }
  3435. bBufGiven = (BOOL) (Rfc1483Info.Rfc1483Module.dwRegSettingsBufSize != 0);
  3436. if ( InetSImportRfc1483Module ( Rfc1483Info.Rfc1483Module, cszINSFile ) != ERROR_SUCCESS ) {
  3437. return E_FAIL;
  3438. }
  3439. if ( !bBufGiven ) return ERROR_SUCCESS;
  3440. if ( InetSImportLanConnection ( Rfc1483Info.TcpIpInfo, cszINSFile ) != ERROR_SUCCESS ) {
  3441. return E_FAIL;
  3442. }
  3443. return ERROR_SUCCESS;
  3444. }
  3445. DWORD CINSHandler::InetSImportPppoeConnection ( PPPOEINFO &PppoeInfo, LPCWSTR cszINSFile )
  3446. {
  3447. BOOL bBufGiven = FALSE;
  3448. if ( !cszINSFile ) return ERROR_INVALID_PARAMETER;
  3449. if (!( (PppoeInfo.PppoeModule.dwRegSettingsBufSize==0) ^
  3450. (PppoeInfo.PppoeModule.lpbRegSettingsBuf==NULL)) )
  3451. {
  3452. return ERROR_INVALID_PARAMETER;
  3453. }
  3454. bBufGiven = (BOOL) !PppoeInfo.PppoeModule.dwRegSettingsBufSize;
  3455. if ( InetSImportPppoeModule ( PppoeInfo.PppoeModule, cszINSFile ) != ERROR_SUCCESS ) {
  3456. return E_FAIL;
  3457. }
  3458. if ( !bBufGiven ) return ERROR_SUCCESS;
  3459. if ( InetSImportLanConnection ( PppoeInfo.TcpIpInfo, cszINSFile ) != ERROR_SUCCESS ) {
  3460. return E_FAIL;
  3461. }
  3462. return ERROR_SUCCESS;
  3463. }
  3464. DWORD CINSHandler::InetSImportRfc1483Module (RFC1483_INFO_EXT &Rfc1483InfoMod, LPCWSTR cszINSFile)
  3465. {
  3466. static const INT CCH_BUF_MIN = 200;
  3467. static const INT CCH_BUF_PAD = 10;
  3468. LPBYTE lpbTempBuf = NULL;
  3469. DWORD cchTempBuf = 0;
  3470. DWORD cchFinalBuf = 0; // not required but used for clarity.
  3471. BOOL bBufferGiven = FALSE;
  3472. if (!cszINSFile) return ERROR_INVALID_PARAMETER;
  3473. // check if a buffer has been given, or a buffer size is required.
  3474. if ( !(Rfc1483InfoMod.dwRegSettingsBufSize) )
  3475. {
  3476. // we will create a temporary buffer to find out how large a buffer we need
  3477. // to accomodate the entire 1483 section. this buffer will be freed at the
  3478. // end of the function (or if error conditions arise).
  3479. bBufferGiven = FALSE;
  3480. if ( !(lpbTempBuf = (LPBYTE) malloc (BYTES_REQUIRED_BY_CCH(CCH_BUF_MIN))) )
  3481. {
  3482. return ERROR_OUTOFMEMORY;
  3483. }
  3484. cchTempBuf = CCH_BUF_MIN;
  3485. }
  3486. else
  3487. {
  3488. bBufferGiven = TRUE;
  3489. lpbTempBuf = Rfc1483InfoMod.lpbRegSettingsBuf;
  3490. cchTempBuf = Rfc1483InfoMod.dwRegSettingsBufSize;
  3491. }
  3492. while ( (cchFinalBuf = GetPrivateProfileSection(
  3493. cszRfc1483Section,
  3494. (WCHAR*)lpbTempBuf,
  3495. cchTempBuf,
  3496. cszINSFile
  3497. )
  3498. ) == (cchTempBuf - 2)
  3499. )
  3500. {
  3501. if (!bBufferGiven)
  3502. {
  3503. if ( !(lpbTempBuf = (LPBYTE) realloc (lpbTempBuf, BYTES_REQUIRED_BY_CCH(cchTempBuf = cchTempBuf * 2) )))
  3504. {
  3505. free (lpbTempBuf);
  3506. return ERROR_OUTOFMEMORY;
  3507. }
  3508. }
  3509. else
  3510. {
  3511. // if the caller has provided a buffer, we do not reallocate it
  3512. // to try to fit the section in. the caller has to reallocate it.
  3513. return ERROR_INSUFFICIENT_BUFFER;
  3514. }
  3515. }
  3516. if ( bBufferGiven )
  3517. {
  3518. return ERROR_SUCCESS;
  3519. }
  3520. else
  3521. {
  3522. free (lpbTempBuf); // clear the temporary buffer.
  3523. Rfc1483InfoMod.dwRegSettingsBufSize = BYTES_REQUIRED_BY_CCH(cchFinalBuf + 1 + CCH_BUF_PAD); // needed for '\0'. BUGBUG: WHY ARE WE PADDING THE BUFFER?
  3524. return ERROR_SUCCESS;
  3525. }
  3526. }
  3527. DWORD CINSHandler::InetSImportPppoeModule (PPPOE_INFO_EXT &PppoeInfoMod, LPCWSTR cszINSFile)
  3528. {
  3529. static const INT MIN_BUF_SIZE = 200;
  3530. static const INT CCH_BUF_PAD = 10;
  3531. LPBYTE lpbTempBuf = NULL;
  3532. DWORD cchTempBuf = 0;
  3533. DWORD cchFinalBuf = 0; // not required but used for clarity.
  3534. BOOL bBufferGiven = FALSE;
  3535. if (!cszINSFile) return ERROR_INVALID_PARAMETER;
  3536. // check if a buffer has been given, or a buffer size is required.
  3537. if ( !(PppoeInfoMod.dwRegSettingsBufSize) )
  3538. {
  3539. // we will create a temporary buffer to find out how large a buffer we need
  3540. // to accomodate the entire pppoe section. this buffer will be freed at the
  3541. // end of the function (or if error conditions arise).
  3542. bBufferGiven = FALSE;
  3543. if ( !(lpbTempBuf = (LPBYTE) malloc (MIN_BUF_SIZE*sizeof(WCHAR))) )
  3544. {
  3545. return ERROR_OUTOFMEMORY;
  3546. }
  3547. cchTempBuf = MIN_BUF_SIZE;
  3548. }
  3549. else
  3550. {
  3551. bBufferGiven = TRUE;
  3552. lpbTempBuf = PppoeInfoMod.lpbRegSettingsBuf;
  3553. cchTempBuf = PppoeInfoMod.dwRegSettingsBufSize / sizeof(WCHAR);
  3554. }
  3555. while ( (cchFinalBuf = GetPrivateProfileSection (cszPppoeSection, (WCHAR*)lpbTempBuf, cchTempBuf, cszINSFile)) == (cchTempBuf - 2) )
  3556. {
  3557. if (!bBufferGiven)
  3558. {
  3559. cchTempBuf *= 2;
  3560. if ( !(lpbTempBuf = (LPBYTE) realloc (lpbTempBuf, cchTempBuf*sizeof(WCHAR) )))
  3561. {
  3562. free (lpbTempBuf);
  3563. return ERROR_OUTOFMEMORY;
  3564. }
  3565. }
  3566. else
  3567. {
  3568. // if the caller has provided a buffer, we do not reallocate it
  3569. // to try to fit the section in. the caller has to reallocate it.
  3570. return ERROR_INSUFFICIENT_BUFFER;
  3571. }
  3572. }
  3573. if ( bBufferGiven )
  3574. {
  3575. return ERROR_SUCCESS;
  3576. }
  3577. else
  3578. {
  3579. free (lpbTempBuf); // clear the temporary buffer.
  3580. PppoeInfoMod.dwRegSettingsBufSize = BYTES_REQUIRED_BY_CCH(cchFinalBuf+CCH_BUF_PAD);
  3581. return ERROR_SUCCESS;
  3582. }
  3583. }
  3584. // It is acceptable for many of the values to be default. if a
  3585. // parameter is not given in the file, the default will be chosen.
  3586. DWORD CINSHandler::InetSImportAtmModule(ATMPBCONFIG &AtmInfoMod, LPCWSTR cszINSFile)
  3587. {
  3588. if (!cszINSFile) return ERROR_INVALID_PARAMETER;
  3589. DWORD dwCircuitSpeed = 0;
  3590. DWORD dwCircuitQOS = 0;
  3591. DWORD dwCircuitType = 0;
  3592. DWORD dwEncapsulation = 0;
  3593. DWORD dwVpi = 0;
  3594. DWORD dwVci = 0;
  3595. WCHAR szYesNo [MAXNAME]; // for Speed_Adjust, QOS_Adjust, Vendor_Config, Show_Status and Enable_Log.
  3596. dwCircuitSpeed = GetPrivateProfileInt (cszATMSection, cszCircuitSpeed, dwCircuitSpeed, cszINSFile);
  3597. AtmInfoMod.dwCircuitSpeed &= ~ATM_CIRCUIT_SPEED_MASK;
  3598. switch (dwCircuitSpeed) {
  3599. case 0:
  3600. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_LINE_RATE;
  3601. break;
  3602. case 1:
  3603. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_USER_SPEC;
  3604. break;
  3605. case 512:
  3606. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_512KB;
  3607. break;
  3608. case 1536:
  3609. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_1536KB;
  3610. break;
  3611. case 25000:
  3612. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_25MB;
  3613. break;
  3614. case 155000:
  3615. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_155MB;
  3616. break;
  3617. default:
  3618. AtmInfoMod.dwCircuitSpeed = ATM_CIRCUIT_SPEED_DEFAULT;
  3619. break;
  3620. }
  3621. AtmInfoMod.dwCircuitOpt &= ~ATM_CIRCUIT_SPEED_MASK;
  3622. AtmInfoMod.dwCircuitOpt |= AtmInfoMod.dwCircuitSpeed;
  3623. dwCircuitQOS = GetPrivateProfileInt (cszATMSection, cszCircuitQOS, dwCircuitQOS, cszINSFile);
  3624. AtmInfoMod.dwCircuitOpt &= ~ATM_CIRCUIT_QOS_MASK;
  3625. switch (dwCircuitQOS) {
  3626. case 0:
  3627. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_QOS_UBR;
  3628. break;
  3629. case 1:
  3630. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_QOS_VBR;
  3631. break;
  3632. case 2:
  3633. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_QOS_CBR;
  3634. break;
  3635. case 3:
  3636. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_QOS_ABR;
  3637. break;
  3638. default:
  3639. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_QOS_DEFAULT;
  3640. break;
  3641. }
  3642. dwCircuitType = GetPrivateProfileInt (cszATMSection, cszCircuitType, dwCircuitType, cszINSFile);
  3643. AtmInfoMod.dwCircuitOpt &= ~ATM_CIRCUIT_OPT_MASK;
  3644. switch (dwCircuitType) {
  3645. case 0:
  3646. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_SVC;
  3647. break;
  3648. case 1:
  3649. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_PVC;
  3650. break;
  3651. default:
  3652. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_SVC;
  3653. break;
  3654. }
  3655. dwEncapsulation = GetPrivateProfileInt (cszATMSection, cszEncapsulation, dwEncapsulation, cszINSFile);
  3656. AtmInfoMod.dwCircuitOpt &= ~ATM_CIRCUIT_ENCAP_MASK;
  3657. switch (dwEncapsulation) {
  3658. case 0:
  3659. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_ENCAP_NULL;
  3660. break;
  3661. case 1:
  3662. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_ENCAP_LLC;
  3663. break;
  3664. default:
  3665. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_ENCAP_DEFAULT;
  3666. break;
  3667. }
  3668. dwVpi = GetPrivateProfileInt (cszATMSection, cszVPI, dwVpi, cszINSFile);
  3669. AtmInfoMod.wPvcVpi = (WORD) dwVpi;
  3670. dwVci = GetPrivateProfileInt (cszATMSection, cszVCI, dwVci, cszINSFile);
  3671. AtmInfoMod.wPvcVci = (WORD) dwVci;
  3672. // Speed_Adjust
  3673. if (GetPrivateProfileString(cszATMSection,
  3674. cszSpeedAdjust,
  3675. cszYes,
  3676. szYesNo,
  3677. MAX_CHARS_IN_BUFFER(szYesNo),
  3678. cszINSFile))
  3679. {
  3680. if (!lstrcmpi(szYesNo, cszYes)) {
  3681. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_SPEED_ADJUST;
  3682. } else {
  3683. AtmInfoMod.dwCircuitOpt &= ~ATM_CIRCUIT_OPT_SPEED_ADJUST;
  3684. }
  3685. } else {
  3686. // if this field is not correctly specified, we use the default settings
  3687. // as specified in the ATMCFG header file.
  3688. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_SPEED_ADJUST;
  3689. }
  3690. // QOS_Adjust
  3691. if (GetPrivateProfileString(cszATMSection,
  3692. cszQOSAdjust,
  3693. cszYes,
  3694. szYesNo,
  3695. MAX_CHARS_IN_BUFFER(szYesNo),
  3696. cszINSFile))
  3697. {
  3698. if (!lstrcmpi(szYesNo, cszYes)) {
  3699. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_QOS_ADJUST;
  3700. } else {
  3701. AtmInfoMod.dwCircuitOpt &= ~ATM_CIRCUIT_OPT_QOS_ADJUST;
  3702. }
  3703. } else {
  3704. AtmInfoMod.dwCircuitOpt |= ATM_CIRCUIT_OPT_QOS_ADJUST;
  3705. }
  3706. // Vendor_Config
  3707. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_MASK;
  3708. if (GetPrivateProfileString(cszATMSection,
  3709. cszVendorConfig,
  3710. cszYes,
  3711. szYesNo,
  3712. MAX_CHARS_IN_BUFFER(szYesNo),
  3713. cszINSFile))
  3714. {
  3715. if (!lstrcmpi(szYesNo, cszYes)) {
  3716. AtmInfoMod.dwGeneralOpt |= ATM_GENERAL_OPT_VENDOR_CONFIG;
  3717. } else {
  3718. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_VENDOR_CONFIG;
  3719. }
  3720. } else {
  3721. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_VENDOR_CONFIG;
  3722. }
  3723. // Show_Status
  3724. if (GetPrivateProfileString(cszATMSection,
  3725. cszShowStatus,
  3726. cszYes,
  3727. szYesNo,
  3728. MAX_CHARS_IN_BUFFER(szYesNo),
  3729. cszINSFile))
  3730. {
  3731. if (!lstrcmpi(szYesNo, cszYes)) {
  3732. AtmInfoMod.dwGeneralOpt |= ATM_GENERAL_OPT_SHOW_STATUS;
  3733. } else {
  3734. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_SHOW_STATUS;
  3735. }
  3736. } else {
  3737. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_SHOW_STATUS;
  3738. }
  3739. // Enable_Log
  3740. if (GetPrivateProfileString(cszATMSection,
  3741. cszEnableLog,
  3742. cszYes,
  3743. szYesNo,
  3744. MAX_CHARS_IN_BUFFER(szYesNo),
  3745. cszINSFile))
  3746. {
  3747. if (!lstrcmpi(szYesNo, cszYes)) {
  3748. AtmInfoMod.dwGeneralOpt |= ATM_GENERAL_OPT_ENABLE_LOG;
  3749. } else {
  3750. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_ENABLE_LOG;
  3751. }
  3752. } else {
  3753. AtmInfoMod.dwGeneralOpt &= ~ATM_GENERAL_OPT_ENABLE_LOG;
  3754. }
  3755. return ERROR_SUCCESS;
  3756. }
  3757. DWORD CINSHandler::InetSGetConnectionType ( LPCWSTR cszINSFile ) {
  3758. WCHAR szDeviceTypeBuf [MAX_PATH];
  3759. DWORD dwBufSize = MAX_CHARS_IN_BUFFER (szDeviceTypeBuf);
  3760. if (!GetPrivateProfileString ( cszDeviceSection, cszDeviceType, szNull, szDeviceTypeBuf, dwBufSize, cszINSFile ) ) {
  3761. return (m_dwDeviceType = 0);
  3762. }
  3763. if (!lstrcmpi (szDeviceTypeBuf, RASDT_Modem)) {
  3764. return (m_dwDeviceType = InetS_RASModem);
  3765. }
  3766. if (!lstrcmpi (szDeviceTypeBuf, RASDT_Isdn)) {
  3767. return (m_dwDeviceType = InetS_RASIsdn);
  3768. }
  3769. if (!lstrcmpi (szDeviceTypeBuf, RASDT_Atm)) {
  3770. return (m_dwDeviceType = InetS_RASAtm);
  3771. }
  3772. if (!lstrcmpi (szDeviceTypeBuf, LANDT_Cable)) {
  3773. return (m_dwDeviceType = InetS_LANCable);
  3774. }
  3775. if (!lstrcmpi (szDeviceTypeBuf, LANDT_Ethernet)) {
  3776. return (m_dwDeviceType = InetS_LANEthernet);
  3777. }
  3778. if (!lstrcmpi (szDeviceTypeBuf, LANDT_Pppoe)) {
  3779. return (m_dwDeviceType = InetS_LANPppoe);
  3780. }
  3781. if (!lstrcmpi (szDeviceTypeBuf, LANDT_1483)) {
  3782. return (m_dwDeviceType = InetS_LAN1483);
  3783. }
  3784. return (m_dwDeviceType = InetS_RASModem); // we default to modem!
  3785. }