Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2948 lines
95 KiB

  1. // INSHandler.cpp : Implementation of CINSHandler
  2. #include "stdafx.h"
  3. #include "icwhelp.h"
  4. #include "INSHandler.h"
  5. #include "webgate.h"
  6. #include <icwacct.h>
  7. #define MAXNAME 80
  8. #define MAXIPADDRLEN 20
  9. #define MAXLONGLEN 80
  10. #define MAX_ISP_NAME 256
  11. #define MAX_ISP_MSG 560
  12. #define MAX_ISP_PHONENUMBER 80
  13. #define SIZE_ReadBuf 0x00008000 // 32K buffer size
  14. #define myisdigit(ch) (((ch) >= '0') && ((ch) <= '9'))
  15. // The following values are global read only strings used to
  16. // process the INS file
  17. #pragma data_seg(".rdata")
  18. static const TCHAR cszAlias[] = TEXT("Import_Name");
  19. static const TCHAR cszML[] = TEXT("Multilink");
  20. static const TCHAR cszPhoneSection[] = TEXT("Phone");
  21. static const TCHAR cszDialAsIs[] = TEXT("Dial_As_Is");
  22. static const TCHAR cszPhone[] = TEXT("Phone_Number");
  23. static const TCHAR cszAreaCode[] = TEXT("Area_Code");
  24. static const TCHAR cszCountryCode[] = TEXT("Country_Code");
  25. static const TCHAR cszCountryID[] = TEXT("Country_ID");
  26. static const TCHAR cszDeviceSection[] = TEXT("Device");
  27. static const TCHAR cszDeviceType[] = TEXT("Type");
  28. static const TCHAR cszDeviceName[] = TEXT("Name");
  29. static const TCHAR cszDevCfgSize[] = TEXT("Settings_Size");
  30. static const TCHAR cszDevCfg[] = TEXT("Settings");
  31. static const TCHAR cszServerSection[] = TEXT("Server");
  32. static const TCHAR cszServerType[] = TEXT("Type");
  33. static const TCHAR cszSWCompress[] = TEXT("SW_Compress");
  34. static const TCHAR cszPWEncrypt[] = TEXT("PW_Encrypt");
  35. static const TCHAR cszNetLogon[] = TEXT("Network_Logon");
  36. static const TCHAR cszSWEncrypt[] = TEXT("SW_Encrypt");
  37. static const TCHAR cszNetBEUI[] = TEXT("Negotiate_NetBEUI");
  38. static const TCHAR cszIPX[] = TEXT("Negotiate_IPX/SPX");
  39. static const TCHAR cszIP[] = TEXT("Negotiate_TCP/IP");
  40. static TCHAR cszDisableLcp[] = TEXT("Disable_LCP");
  41. static const TCHAR cszIPSection[] = TEXT("TCP/IP");
  42. static const TCHAR cszIPSpec[] = TEXT("Specify_IP_Address");
  43. static const TCHAR cszIPAddress[] = TEXT("IP_address");
  44. static const TCHAR cszServerSpec[] = TEXT("Specify_Server_Address");
  45. static const TCHAR cszDNSAddress[] = TEXT("DNS_address");
  46. static const TCHAR cszDNSAltAddress[] = TEXT("DNS_Alt_address");
  47. static const TCHAR cszWINSAddress[] = TEXT("WINS_address");
  48. static const TCHAR cszWINSAltAddress[]= TEXT("WINS_Alt_address");
  49. static const TCHAR cszIPCompress[] = TEXT("IP_Header_Compress");
  50. static const TCHAR cszWanPri[] = TEXT("Gateway_On_Remote");
  51. static const TCHAR cszMLSection[] = TEXT("Multilink");
  52. static const TCHAR cszLinkIndex[] = TEXT("Line_%s");
  53. static const TCHAR cszScriptingSection[] = TEXT("Scripting");
  54. static const TCHAR cszScriptName[] = TEXT("Name");
  55. static const TCHAR cszScriptSection[] = TEXT("Script_File");
  56. static const TCHAR cszCustomDialerSection[] = TEXT("Custom_Dialer");
  57. static const TCHAR cszAutoDialDLL[] = TEXT("Auto_Dial_DLL");
  58. static const TCHAR cszAutoDialFunc[] = TEXT("Auto_Dial_Function");
  59. // These strings will be use to populate the registry, with the data above
  60. static const TCHAR cszKeyIcwRmind[] = TEXT("Software\\Microsoft\\Internet Connection Wizard\\IcwRmind");
  61. static const TCHAR cszTrialRemindSection[] = TEXT("TrialRemind");
  62. static const TCHAR cszEntryISPName[] = TEXT("ISP_Name");
  63. static const TCHAR cszEntryISPPhone[] = TEXT("ISP_Phone");
  64. static const TCHAR cszEntryISPMsg[] = TEXT("ISP_Message");
  65. static const TCHAR cszEntryTrialDays[] = TEXT("Trial_Days");
  66. static const TCHAR cszEntrySignupURL[] = TEXT("Signup_URL");
  67. // ICWRMIND expects this value in the registry
  68. static const TCHAR cszEntrySignupURLTrialOver[] = TEXT("Expired_URL");
  69. // We get these two from the INS file
  70. static const TCHAR cszEntryExpiredISPFileName[] = TEXT("Expired_ISP_File");
  71. static const TCHAR cszSignupExpiredISPURL[] = TEXT("Expired_ISP_URL");
  72. static const TCHAR cszEntryConnectoidName[] = TEXT("Entry_Name");
  73. static const TCHAR cszSignupSuccessfuly[] = TEXT("TrialConverted");
  74. static const TCHAR cszReminderApp[] = TEXT("ICWRMIND.EXE");
  75. static const TCHAR cszReminderParams[] = TEXT("-t");
  76. static const TCHAR cszPassword[] = TEXT("Password");
  77. static const TCHAR cszCMHeader[] = TEXT("Connection Manager CMS 0");
  78. extern SERVER_TYPES aServerTypes[];
  79. // These are the field names from an INS file that will
  80. // determine the mail and news settings
  81. static const TCHAR cszMailSection[] = TEXT("Internet_Mail");
  82. static const TCHAR cszEntryName[] = TEXT("Entry_Name");
  83. static const TCHAR cszPOPServer[] = TEXT("POP_Server");
  84. static const TCHAR cszPOPServerPortNumber[] = TEXT("POP_Server_Port_Number");
  85. static const TCHAR cszPOPLogonName[] = TEXT("POP_Logon_Name");
  86. static const TCHAR cszPOPLogonPassword[] = TEXT("POP_Logon_Password");
  87. static const TCHAR cszSMTPServer[] = TEXT("SMTP_Server");
  88. static const TCHAR cszSMTPServerPortNumber[] = TEXT("SMTP_Server_Port_Number");
  89. static const TCHAR cszNewsSection[] = TEXT("Internet_News");
  90. static const TCHAR cszNNTPServer[] = TEXT("NNTP_Server");
  91. static const TCHAR cszNNTPServerPortNumber[] = TEXT("NNTP_Server_Port_Number");
  92. static const TCHAR cszNNTPLogonName[] = TEXT("NNTP_Logon_Name");
  93. static const TCHAR cszNNTPLogonPassword[] = TEXT("NNTP_Logon_Password");
  94. static const TCHAR cszUseMSInternetMail[] = TEXT("Install_Mail");
  95. static const TCHAR cszUseMSInternetNews[] = TEXT("Install_News");
  96. static const TCHAR cszEMailSection[] = TEXT("Internet_Mail");
  97. static const TCHAR cszEMailName[] = TEXT("EMail_Name");
  98. static const TCHAR cszEMailAddress[] = TEXT("EMail_Address");
  99. static const TCHAR cszUseExchange[] = TEXT("Use_MS_Exchange");
  100. static const TCHAR cszUserSection[] = TEXT("User");
  101. static const TCHAR cszUserName[] = TEXT("Name");
  102. static const TCHAR cszDisplayPassword[] = TEXT("Display_Password");
  103. static const TCHAR cszYes[] = TEXT("yes");
  104. static const TCHAR cszNo[] = TEXT("no");
  105. #define CLIENT_OFFSET(elem) ((DWORD)(DWORD_PTR)&(((LPINETCLIENTINFO)(NULL))->elem))
  106. #define CLIENT_SIZE(elem) sizeof(((LPINETCLIENTINFO)(NULL))->elem)
  107. #define CLIENT_ENTRY(section, value, elem) \
  108. {section, value, CLIENT_OFFSET(elem), CLIENT_SIZE(elem)}
  109. CLIENT_TABLE iniTable[] =
  110. {
  111. CLIENT_ENTRY(cszEMailSection, cszEMailName, szEMailName),
  112. CLIENT_ENTRY(cszEMailSection, cszEMailAddress, szEMailAddress),
  113. CLIENT_ENTRY(cszEMailSection, cszPOPLogonName, szPOPLogonName),
  114. CLIENT_ENTRY(cszEMailSection, cszPOPLogonPassword, szPOPLogonPassword),
  115. CLIENT_ENTRY(cszEMailSection, cszPOPServer, szPOPServer),
  116. CLIENT_ENTRY(cszEMailSection, cszSMTPServer, szSMTPServer),
  117. CLIENT_ENTRY(cszNewsSection, cszNNTPLogonName, szNNTPLogonName),
  118. CLIENT_ENTRY(cszNewsSection, cszNNTPLogonPassword, szNNTPLogonPassword),
  119. CLIENT_ENTRY(cszNewsSection, cszNNTPServer, szNNTPServer),
  120. {NULL, NULL, 0, 0}
  121. };
  122. static const TCHAR cszFileName[] = TEXT("Custom_File");
  123. static const TCHAR cszCustomFileSection[] = TEXT("Custom_File");
  124. static const TCHAR cszNull[] = TEXT("");
  125. static const TCHAR cszURLSection[] = TEXT("URL");
  126. static const TCHAR cszSignupURL[] = TEXT("Signup");
  127. static const TCHAR cszAutoConfigURL[] = TEXT("Autoconfig");
  128. static const TCHAR cszExtINS[] = TEXT(".ins");
  129. static const TCHAR cszExtISP[] = TEXT(".isp");
  130. static const TCHAR cszExtHTM[] = TEXT(".htm");
  131. static const TCHAR cszExtHTML[] = TEXT(".html");
  132. static const TCHAR cszEntrySection[] = TEXT("Entry");
  133. static const TCHAR cszCancel[] = TEXT("Cancel");
  134. static const TCHAR cszStartURL[] = TEXT("StartURL");
  135. static const TCHAR cszRun[] = TEXT("Run");
  136. static const TCHAR cszArgument[] = TEXT("Argument");
  137. static const TCHAR cszConnect2[] = TEXT("icwconn2.exe");
  138. static const TCHAR cszClientSetupSection[] = TEXT("ClientSetup");
  139. static const TCHAR cszRequiresLogon[] = TEXT("Requires_Logon");
  140. static const TCHAR cszCustomSection[] = TEXT("Custom");
  141. static const TCHAR cszKeepConnection[] = TEXT("Keep_Connection");
  142. static const TCHAR cszKeepBrowser[] = TEXT("Keep_Browser");
  143. static const TCHAR cszBrandingSection[] = TEXT("Branding");
  144. static const TCHAR cszBrandingFlags[] = TEXT("Flags");
  145. static const TCHAR cszHTTPS[] = TEXT("https:");
  146. // code relies on these two being the same length
  147. static const TCHAR cszHTTP[] = TEXT("http:");
  148. static const TCHAR cszFILE[] = TEXT("file:");
  149. static const TCHAR cszKioskMode[] = TEXT("-k ");
  150. static const TCHAR cszOpen[] = TEXT("open");
  151. static const TCHAR cszBrowser[] = TEXT("iexplore.exe");
  152. static const TCHAR szNull[] = TEXT("");
  153. static const TCHAR cszDEFAULT_BROWSER_KEY[] = TEXT("Software\\Microsoft\\Internet Explorer\\Main");
  154. static const TCHAR cszDEFAULT_BROWSER_VALUE[] = TEXT("check_associations");
  155. // Registry keys which will contain News and Mail settings
  156. #define MAIL_KEY TEXT("SOFTWARE\\Microsoft\\Internet Mail and News\\Mail")
  157. #define MAIL_POP3_KEY TEXT("SOFTWARE\\Microsoft\\Internet Mail and News\\Mail\\POP3\\")
  158. #define MAIL_SMTP_KEY TEXT("SOFTWARE\\Microsoft\\Internet Mail and News\\Mail\\SMTP\\")
  159. #define NEWS_KEY TEXT("SOFTWARE\\Microsoft\\Internet Mail and News\\News")
  160. #define MAIL_NEWS_INPROC_SERVER32 TEXT("CLSID\\{89292102-4755-11cf-9DC2-00AA006C2B84}\\InProcServer32")
  161. typedef HRESULT (WINAPI *PFNSETDEFAULTNEWSHANDLER)(void);
  162. // These are the value names where the INS settings will be saved
  163. // into the registry
  164. static const TCHAR cszMailSenderName[] = TEXT("Sender Name");
  165. static const TCHAR cszMailSenderEMail[] = TEXT("Sender EMail");
  166. static const TCHAR cszMailRASPhonebookEntry[]= TEXT("RAS Phonebook Entry");
  167. static const TCHAR cszMailConnectionType[] = TEXT("Connection Type");
  168. static const TCHAR cszDefaultPOP3Server[] = TEXT("Default POP3 Server");
  169. static const TCHAR cszDefaultSMTPServer[] = TEXT("Default SMTP Server");
  170. static const TCHAR cszPOP3Account[] = TEXT("Account");
  171. static const TCHAR cszPOP3Password[] = TEXT("Password");
  172. static const TCHAR cszPOP3Port[] = TEXT("Port");
  173. static const TCHAR cszSMTPPort[] = TEXT("Port");
  174. static const TCHAR cszNNTPSenderName[] = TEXT("Sender Name");
  175. static const TCHAR cszNNTPSenderEMail[] = TEXT("Sender EMail");
  176. static const TCHAR cszNNTPDefaultServer[] = TEXT("DefaultServer"); // NOTE: NO space between "Default" and "Server".
  177. static const TCHAR cszNNTPAccountName[] = TEXT("Account Name");
  178. static const TCHAR cszNNTPPassword[] = TEXT("Password");
  179. static const TCHAR cszNNTPPort[] = TEXT("Port");
  180. static const TCHAR cszNNTPRasPhonebookEntry[]= TEXT("RAS Phonebook Entry");
  181. static const TCHAR cszNNTPConnectionType[] = TEXT("Connection Type");
  182. static const TCHAR arBase64[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',
  183. 'V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
  184. 'q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/','='};
  185. #define ICWCOMPLETEDKEY TEXT("Completed")
  186. // 2/19/97 jmazner Olympus #1106 -- SAM/SBS integration
  187. TCHAR FAR cszSBSCFG_DLL[] = TEXT("SBSCFG.DLL\0");
  188. CHAR FAR cszSBSCFG_CONFIGURE[] = "Configure\0";
  189. typedef DWORD (WINAPI * SBSCONFIGURE) (HWND hwnd, LPTSTR lpszINSFile, LPTSTR szConnectoidName);
  190. SBSCONFIGURE lpfnConfigure;
  191. // 09/02/98 Donaldm: Integrate with Connection Manager
  192. TCHAR FAR cszCMCFG_DLL[] = TEXT("CMCFG32.DLL\0");
  193. CHAR FAR cszCMCFG_CONFIGURE[] = "CMConfig\0"; // Proc address
  194. CHAR FAR cszCMCFG_CONFIGUREEX[] = "CMConfigEx\0"; // Proc address
  195. typedef BOOL (WINAPI * CMCONFIGUREEX)(LPCSTR lpszINSFile);
  196. typedef BOOL (WINAPI * CMCONFIGURE)(LPCSTR lpszINSFile, LPCSTR lpszConnectoidNams);
  197. CMCONFIGURE lpfnCMConfigure;
  198. CMCONFIGUREEX lpfnCMConfigureEx;
  199. #pragma data_seg()
  200. //+----------------------------------------------------------------------------
  201. //
  202. // Function: CallCMConfig
  203. //
  204. // Synopsis: Call into the Connection Manager dll's Configure function to allow CM to
  205. // process the .ins file as needed.
  206. //
  207. // Arguements: lpszINSFile -- full path to the .ins file
  208. //
  209. // Returns: TRUE if a CM profile is created, FALSE otherwise
  210. //
  211. // History: 09/02/98 DONALDM
  212. //
  213. //-----------------------------------------------------------------------------
  214. BOOL CINSHandler::CallCMConfig(LPCTSTR lpszINSFile)
  215. {
  216. HINSTANCE hCMDLL = NULL;
  217. BOOL bRet = FALSE;
  218. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: Calling LoadLibrary on %s\n"), cszCMCFG_DLL);
  219. // Load DLL and entry point
  220. hCMDLL = LoadLibrary(cszCMCFG_DLL);
  221. if (NULL != hCMDLL)
  222. {
  223. // To determine whether we should call CMConfig or CMConfigEx
  224. // Loop to find the appropriate buffer size to retieve the ins to memory
  225. ULONG ulBufferSize = 1024*10;
  226. // Parse the ISP section in the INI file to find query pair to append
  227. TCHAR *pszKeys = NULL;
  228. PTSTR pszKey = NULL;
  229. ULONG ulRetVal = 0;
  230. BOOL bEnumerate = TRUE;
  231. BOOL bUseEx = FALSE;
  232. PTSTR pszBuff = NULL;
  233. ulRetVal = 0;
  234. pszKeys = new TCHAR [ulBufferSize];
  235. while (ulRetVal < (ulBufferSize - 2))
  236. {
  237. ulRetVal = ::GetPrivateProfileString(NULL, NULL, _T(""), pszKeys, ulBufferSize, lpszINSFile);
  238. if (0 == ulRetVal)
  239. bEnumerate = FALSE;
  240. if (ulRetVal < (ulBufferSize - 2))
  241. {
  242. break;
  243. }
  244. delete [] pszKeys;
  245. ulBufferSize += ulBufferSize;
  246. pszKeys = new TCHAR [ulBufferSize];
  247. if (!pszKeys)
  248. {
  249. bEnumerate = FALSE;
  250. }
  251. }
  252. if (bEnumerate)
  253. {
  254. pszKey = pszKeys;
  255. if (ulRetVal != 0)
  256. {
  257. while (*pszKey)
  258. {
  259. if (!lstrcmpi(pszKey, cszCMHeader))
  260. {
  261. bUseEx = TRUE;
  262. break;
  263. }
  264. pszKey += lstrlen(pszKey) + 1;
  265. }
  266. }
  267. }
  268. if (pszKeys)
  269. delete [] pszKeys;
  270. TCHAR szConnectoidName[RAS_MaxEntryName];
  271. // Get the connectoid name from the [Entry] Section
  272. GetPrivateProfileString(cszEntrySection,
  273. cszEntryName,
  274. cszNull,
  275. szConnectoidName,
  276. RAS_MaxEntryName,
  277. lpszINSFile);
  278. if (bUseEx)
  279. {
  280. // Call CMConfigEx
  281. lpfnCMConfigureEx = (CMCONFIGUREEX)GetProcAddress(hCMDLL,cszCMCFG_CONFIGUREEX);
  282. if( lpfnCMConfigureEx )
  283. {
  284. #ifdef UNICODE
  285. CHAR szFile[_MAX_PATH + 1];
  286. wcstombs(szFile, lpszINSFile, _MAX_PATH + 1);
  287. bRet = lpfnCMConfigureEx(szFile);
  288. #else
  289. bRet = lpfnCMConfigureEx(lpszINSFile);
  290. #endif
  291. }
  292. }
  293. else
  294. {
  295. // Call CMConfig
  296. lpfnCMConfigure = (CMCONFIGURE)GetProcAddress(hCMDLL,cszCMCFG_CONFIGURE);
  297. // Call function
  298. if( lpfnCMConfigure )
  299. {
  300. #ifdef UNICODE
  301. CHAR szEntry[RAS_MaxEntryName];
  302. CHAR szFile[_MAX_PATH + 1];
  303. wcstombs(szEntry, szConnectoidName, RAS_MaxEntryName);
  304. wcstombs(szFile, lpszINSFile, _MAX_PATH + 1);
  305. bRet = lpfnCMConfigure(szFile, szEntry);
  306. #else
  307. bRet = lpfnCMConfigure(lpszINSFile, szConnectoidName);
  308. #endif
  309. }
  310. }
  311. if (bRet)
  312. {
  313. // restore original autodial settings
  314. m_lpfnInetSetAutodial(TRUE, szConnectoidName);
  315. }
  316. }
  317. // Cleanup
  318. if( hCMDLL )
  319. FreeLibrary(hCMDLL);
  320. if( lpfnCMConfigure )
  321. lpfnCMConfigure = NULL;
  322. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: CallSBSConfig exiting with error code %d \n"), bRet);
  323. return bRet;
  324. }
  325. //+----------------------------------------------------------------------------
  326. //
  327. // Function: CallSBSConfig
  328. //
  329. // Synopsis: Call into the SBSCFG dll's Configure function to allow SBS to
  330. // process the .ins file as needed
  331. //
  332. // Arguements: hwnd -- hwnd of parent, in case sbs wants to put up messages
  333. // lpszINSFile -- full path to the .ins file
  334. //
  335. // Returns: windows error code that sbscfg returns.
  336. //
  337. // History: 2/19/97 jmazner Created for Olympus #1106
  338. //
  339. //-----------------------------------------------------------------------------
  340. DWORD CINSHandler::CallSBSConfig(HWND hwnd, LPCTSTR lpszINSFile)
  341. {
  342. HINSTANCE hSBSDLL = NULL;
  343. DWORD dwRet = ERROR_SUCCESS;
  344. TCHAR lpszConnectoidName[RAS_MaxEntryName] = TEXT("nogood\0");
  345. //
  346. // Get name of connectoid we created by looking in autodial
  347. // We need to pass this name into SBSCFG
  348. // 5/14/97 jmazner Windosw NT Bugs #87209
  349. //
  350. BOOL fEnabled = FALSE;
  351. if( NULL == m_lpfnInetGetAutodial )
  352. {
  353. TraceMsg(TF_INSHANDLER, TEXT("m_lpfnInetGetAutodial is NULL!!!!"));
  354. return ERROR_INVALID_FUNCTION;
  355. }
  356. dwRet = m_lpfnInetGetAutodial(&fEnabled,lpszConnectoidName,RAS_MaxEntryName);
  357. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: Calling LoadLibrary on %s\n"), cszSBSCFG_DLL);
  358. hSBSDLL = LoadLibrary(cszSBSCFG_DLL);
  359. // Load DLL and entry point
  360. if (NULL != hSBSDLL)
  361. {
  362. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: Calling GetProcAddress on %s\n"), cszSBSCFG_CONFIGURE);
  363. lpfnConfigure = (SBSCONFIGURE)GetProcAddress(hSBSDLL,cszSBSCFG_CONFIGURE);
  364. }
  365. else
  366. {
  367. // 4/2/97 ChrisK Olympus 2759
  368. // If the DLL can't be loaded, pick a specific error message to return.
  369. dwRet = ERROR_DLL_NOT_FOUND;
  370. goto CallSBSConfigExit;
  371. }
  372. // Call function
  373. if( hSBSDLL && lpfnConfigure )
  374. {
  375. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: Calling the Configure entry point: %s, %s\n"), lpszINSFile, lpszConnectoidName);
  376. dwRet = lpfnConfigure(hwnd, (TCHAR *)lpszINSFile, lpszConnectoidName);
  377. }
  378. else
  379. {
  380. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: Unable to call the Configure entry point\n"));
  381. dwRet = GetLastError();
  382. }
  383. CallSBSConfigExit:
  384. if( hSBSDLL )
  385. FreeLibrary(hSBSDLL);
  386. if( lpfnConfigure )
  387. lpfnConfigure = NULL;
  388. TraceMsg(TF_INSHANDLER, TEXT("ICWCONN1: CallSBSConfig exiting with error code %d \n"), dwRet);
  389. return dwRet;
  390. }
  391. BOOL CINSHandler::SetICWCompleted( DWORD dwCompleted )
  392. {
  393. HKEY hKey = NULL;
  394. HRESULT hr = RegCreateKey(HKEY_CURRENT_USER,ICWSETTINGSPATH,&hKey);
  395. if (ERROR_SUCCESS == hr)
  396. {
  397. hr = RegSetValueEx(hKey, ICWCOMPLETEDKEY, 0, REG_DWORD,
  398. (CONST BYTE*)&dwCompleted, sizeof(dwCompleted));
  399. RegCloseKey(hKey);
  400. }
  401. if( ERROR_SUCCESS == hr )
  402. return TRUE;
  403. else
  404. return FALSE;
  405. }
  406. /////////////////////////////////////////////////////////////////////////////
  407. // CINSHandler
  408. HRESULT CINSHandler::OnDraw(ATL_DRAWINFO& di)
  409. {
  410. return S_OK;
  411. }
  412. #define FILE_BUFFER_SIZE 65534
  413. #ifndef FILE_BEGIN
  414. #define FILE_BEGIN 0
  415. #endif
  416. //+---------------------------------------------------------------------------
  417. //
  418. // Function: MassageFile
  419. //
  420. // Synopsis: Convert 0x0d's in the file to 0x0d 0x0A sequences
  421. //
  422. //+---------------------------------------------------------------------------
  423. HRESULT CINSHandler::MassageFile(LPCTSTR lpszFile)
  424. {
  425. LPBYTE lpBufferIn;
  426. LPBYTE lpBufferOut;
  427. HFILE hfile;
  428. HRESULT hr = ERROR_SUCCESS;
  429. if (!SetFileAttributes(lpszFile, FILE_ATTRIBUTE_NORMAL))
  430. {
  431. return GetLastError();
  432. }
  433. lpBufferIn = (LPBYTE) GlobalAlloc(GPTR, 2 * FILE_BUFFER_SIZE);
  434. if (NULL == lpBufferIn)
  435. {
  436. return ERROR_OUTOFMEMORY;
  437. }
  438. lpBufferOut = lpBufferIn + FILE_BUFFER_SIZE;
  439. #ifdef UNICODE
  440. CHAR szTmp[MAX_PATH+1];
  441. wcstombs(szTmp, lpszFile, MAX_PATH+1);
  442. hfile = _lopen(szTmp, OF_READWRITE);
  443. #else
  444. hfile = _lopen(lpszFile, OF_READWRITE);
  445. #endif
  446. if (HFILE_ERROR != hfile)
  447. {
  448. BOOL fChanged = FALSE;
  449. UINT uBytesOut = 0;
  450. UINT uBytesIn = _lread(hfile, lpBufferIn, (UINT)(FILE_BUFFER_SIZE - 1));
  451. // Note: we asume, in our use of lpCharIn, that the file is always less than
  452. // FILE_BUFFER_SIZE
  453. if (HFILE_ERROR != uBytesIn)
  454. {
  455. LPBYTE lpCharIn = lpBufferIn;
  456. LPBYTE lpCharOut = lpBufferOut;
  457. while ((*lpCharIn) && (FILE_BUFFER_SIZE - 2 > uBytesOut))
  458. {
  459. *lpCharOut++ = *lpCharIn;
  460. uBytesOut++;
  461. if ((0x0d == *lpCharIn) && (0x0a != *(lpCharIn + 1)))
  462. {
  463. fChanged = TRUE;
  464. *lpCharOut++ = 0x0a;
  465. uBytesOut++;
  466. }
  467. lpCharIn++;
  468. }
  469. if (fChanged)
  470. {
  471. if (HFILE_ERROR != _llseek(hfile, 0, FILE_BEGIN))
  472. {
  473. if (HFILE_ERROR ==_lwrite(hfile, (LPCSTR) lpBufferOut, uBytesOut))
  474. {
  475. hr = GetLastError();
  476. }
  477. }
  478. else
  479. {
  480. hr = GetLastError();
  481. }
  482. }
  483. }
  484. else
  485. {
  486. hr = GetLastError();
  487. }
  488. _lclose(hfile);
  489. }
  490. else
  491. {
  492. hr = GetLastError();
  493. }
  494. GlobalFree((HGLOBAL)lpBufferIn);
  495. return ERROR_SUCCESS;
  496. }
  497. DWORD CINSHandler::RunExecutable(void)
  498. {
  499. DWORD dwRet;
  500. SHELLEXECUTEINFO sei;
  501. // Hide the active window first
  502. HWND hWndHide = GetActiveWindow();
  503. ::ShowWindow(hWndHide, SW_HIDE);
  504. sei.cbSize = sizeof(sei);
  505. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  506. sei.hwnd = NULL;
  507. sei.lpVerb = cszOpen;
  508. sei.lpFile = m_szRunExecutable;
  509. sei.lpParameters = m_szRunArgument;
  510. sei.lpDirectory = NULL;
  511. sei.nShow = SW_SHOWNORMAL;
  512. sei.hInstApp = NULL;
  513. // Optional members
  514. sei.hProcess = NULL;
  515. if (ShellExecuteEx(&sei))
  516. {
  517. DWORD iWaitResult = 0;
  518. // wait for event or msgs. Dispatch msgs. Exit when event is signalled.
  519. while((iWaitResult=MsgWaitForMultipleObjects(1, &sei.hProcess, FALSE, INFINITE, QS_ALLINPUT))==(WAIT_OBJECT_0 + 1))
  520. {
  521. MSG msg ;
  522. // read all of the messages in this next loop
  523. // removing each message as we read it
  524. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  525. {
  526. if (msg.message == WM_QUIT)
  527. {
  528. CloseHandle(sei.hProcess);
  529. return NO_ERROR;
  530. }
  531. else
  532. DispatchMessage(&msg);
  533. }
  534. }
  535. CloseHandle(sei.hProcess);
  536. dwRet = ERROR_SUCCESS;
  537. }
  538. else
  539. {
  540. dwRet = GetLastError();
  541. }
  542. ::ShowWindow(hWndHide, SW_SHOW);
  543. return dwRet;
  544. }
  545. void CINSHandler::SaveAutoDial(void)
  546. {
  547. Assert(m_lpfnInetGetAutodial);
  548. Assert(m_lpfnInetGetProxy);
  549. Assert(m_lpfnInetSetProxy);
  550. // if the original autodial settings have not been saved
  551. if (!m_fAutodialSaved)
  552. {
  553. // save the current autodial settings
  554. m_lpfnInetGetAutodial(
  555. &m_fAutodialEnabled,
  556. m_szAutodialConnection,
  557. sizeof(m_szAutodialConnection));
  558. m_lpfnInetGetProxy(
  559. &m_fProxyEnabled,
  560. NULL, 0,
  561. NULL, 0);
  562. // turn off proxy
  563. m_lpfnInetSetProxy(FALSE, NULL, NULL);
  564. m_fAutodialSaved = TRUE;
  565. }
  566. }
  567. void CINSHandler::RestoreAutoDial(void)
  568. {
  569. Assert(m_lpfnInetSetAutodial);
  570. Assert(m_lpfnInetSetProxy);
  571. if (m_fAutodialSaved)
  572. {
  573. // restore original autodial settings
  574. m_lpfnInetSetAutodial(m_fAutodialEnabled, m_szAutodialConnection);
  575. m_fAutodialSaved = FALSE;
  576. }
  577. }
  578. BOOL CINSHandler::KeepConnection(LPCTSTR lpszFile)
  579. {
  580. TCHAR szTemp[10];
  581. GetPrivateProfileString(cszCustomSection,
  582. cszKeepConnection,
  583. cszNo,
  584. szTemp,
  585. 10,
  586. lpszFile);
  587. return (!lstrcmpi(szTemp, cszYes));
  588. }
  589. DWORD CINSHandler::ImportCustomInfo
  590. (
  591. LPCTSTR lpszImportFile,
  592. LPTSTR lpszExecutable,
  593. DWORD cbExecutable,
  594. LPTSTR lpszArgument,
  595. DWORD cbArgument
  596. )
  597. {
  598. GetPrivateProfileString(cszCustomSection,
  599. cszRun,
  600. cszNull,
  601. lpszExecutable,
  602. (int)cbExecutable,
  603. lpszImportFile);
  604. GetPrivateProfileString(cszCustomSection,
  605. cszArgument,
  606. cszNull,
  607. lpszArgument,
  608. (int)cbArgument,
  609. lpszImportFile);
  610. return ERROR_SUCCESS;
  611. }
  612. DWORD CINSHandler::ImportFile
  613. (
  614. LPCTSTR lpszImportFile,
  615. LPCTSTR lpszSection,
  616. LPCTSTR lpszOutputFile
  617. )
  618. {
  619. HFILE hFile;
  620. LPTSTR pszLine, pszFile;
  621. int i, iMaxLine;
  622. UINT cbSize, cbRet;
  623. DWORD dwRet = ERROR_SUCCESS;
  624. // Allocate a buffer for the file
  625. if ((pszFile = (LPTSTR)LocalAlloc(LMEM_FIXED, SIZE_ReadBuf * 2)) == NULL)
  626. {
  627. return ERROR_OUTOFMEMORY;
  628. }
  629. // Look for script
  630. if (GetPrivateProfileString(lpszSection,
  631. NULL,
  632. szNull,
  633. pszFile,
  634. SIZE_ReadBuf / sizeof(TCHAR),
  635. lpszImportFile) != 0)
  636. {
  637. // Get the maximum line number
  638. pszLine = pszFile;
  639. iMaxLine = -1;
  640. while (*pszLine)
  641. {
  642. i = _ttoi(pszLine);
  643. iMaxLine = max(iMaxLine, i);
  644. pszLine += lstrlen(pszLine)+1;
  645. };
  646. // If we have at least one line, we will import the script file
  647. if (iMaxLine >= 0)
  648. {
  649. // Create the script file
  650. #ifdef UNICODE
  651. CHAR szTmp[MAX_PATH+1];
  652. wcstombs(szTmp, lpszOutputFile, MAX_PATH+1);
  653. hFile = _lcreat(szTmp, 0);
  654. #else
  655. hFile = _lcreat(lpszOutputFile, 0);
  656. #endif
  657. if (hFile != HFILE_ERROR)
  658. {
  659. TCHAR szLineNum[MAXLONGLEN+1];
  660. // From The first line to the last line
  661. for (i = 0; i <= iMaxLine; i++)
  662. {
  663. // Read the script line
  664. wsprintf(szLineNum, TEXT("%d"), i);
  665. if ((cbSize = GetPrivateProfileString(lpszSection,
  666. szLineNum,
  667. szNull,
  668. pszLine,
  669. SIZE_ReadBuf / sizeof(TCHAR),
  670. lpszImportFile)) != 0)
  671. {
  672. // Write to the script file
  673. lstrcat(pszLine, TEXT("\x0d\x0a"));
  674. #ifdef UNICODE
  675. wcstombs(szTmp, pszLine, MAX_PATH+1);
  676. cbRet=_lwrite(hFile, szTmp, cbSize+2);
  677. #else
  678. cbRet=_lwrite(hFile, pszLine, cbSize+2);
  679. #endif
  680. }
  681. }
  682. _lclose(hFile);
  683. }
  684. else
  685. {
  686. dwRet = ERROR_PATH_NOT_FOUND;
  687. }
  688. }
  689. else
  690. {
  691. dwRet = ERROR_PATH_NOT_FOUND;
  692. }
  693. }
  694. else
  695. {
  696. dwRet = ERROR_PATH_NOT_FOUND;
  697. }
  698. LocalFree(pszFile);
  699. return dwRet;
  700. }
  701. DWORD CINSHandler::ImportCustomFile
  702. (
  703. LPCTSTR lpszImportFile
  704. )
  705. {
  706. TCHAR szFile[_MAX_PATH];
  707. TCHAR szTemp[_MAX_PATH];
  708. // If a custom file name does not exist, do nothing
  709. if (GetPrivateProfileString(cszCustomSection,
  710. cszFileName,
  711. cszNull,
  712. szTemp,
  713. _MAX_PATH,
  714. lpszImportFile) == 0)
  715. {
  716. return ERROR_SUCCESS;
  717. };
  718. GetWindowsDirectory(szFile, _MAX_PATH);
  719. if (*CharPrev(szFile, szFile + lstrlen(szFile)) != '\\')
  720. {
  721. lstrcat(szFile, TEXT("\\"));
  722. }
  723. lstrcat(szFile, szTemp);
  724. return (ImportFile(lpszImportFile, cszCustomFileSection, szFile));
  725. }
  726. BOOL CINSHandler::LoadExternalFunctions(void)
  727. {
  728. BOOL bRet = FALSE;
  729. do
  730. {
  731. // Load the Brading library functions
  732. m_hBranding = LoadLibrary(TEXT("IEDKCS32.DLL"));
  733. if (m_hBranding != NULL)
  734. {
  735. if (NULL == (m_lpfnBrandICW = (PFNBRANDICW)GetProcAddress(m_hBranding, "BrandICW2")))
  736. break;
  737. }
  738. else
  739. {
  740. break;
  741. }
  742. // Load the Inet Config library functions
  743. m_hInetCfg = LoadLibrary(TEXT("INETCFG.DLL"));
  744. if (m_hInetCfg != NULL)
  745. {
  746. #ifdef UNICODE
  747. if (NULL == (m_lpfnInetConfigSystem = (PFNINETCONFIGSYSTEM)GetProcAddress(m_hInetCfg, "InetConfigSystem")))
  748. break;
  749. if (NULL == (m_lpfnInetGetProxy = (PFNINETGETPROXY)GetProcAddress(m_hInetCfg, "InetGetProxyW")))
  750. break;
  751. if (NULL == (m_lpfnInetConfigClient = (PFNINETCONFIGCLIENT)GetProcAddress(m_hInetCfg, "InetConfigClientW")))
  752. break;
  753. //if (NULL == (m_lpfnInetConfigClientEx = (PFNINETCONFIGCLIENTEX)GetProcAddress(m_hInetCfg, "InetConfigClientExW")))
  754. // break;
  755. if (NULL == (m_lpfnInetGetAutodial = (PFNINETGETAUTODIAL)GetProcAddress(m_hInetCfg, "InetGetAutodialW")))
  756. break;
  757. if (NULL == (m_lpfnInetSetAutodial = (PFNINETSETAUTODIAL)GetProcAddress(m_hInetCfg, "InetSetAutodialW")))
  758. break;
  759. if (NULL == (m_lpfnInetSetClientInfo = (PFNINETSETCLIENTINFO)GetProcAddress(m_hInetCfg, "InetSetClientInfoW")))
  760. break;
  761. if (NULL == (m_lpfnInetSetProxy = (PFNINETSETPROXY)GetProcAddress(m_hInetCfg, "InetSetProxyW")))
  762. break;
  763. #else // UNICODE
  764. if (NULL == (m_lpfnInetConfigSystem = (PFNINETCONFIGSYSTEM)GetProcAddress(m_hInetCfg, "InetConfigSystem")))
  765. break;
  766. if (NULL == (m_lpfnInetGetProxy = (PFNINETGETPROXY)GetProcAddress(m_hInetCfg, "InetGetProxy")))
  767. break;
  768. if (NULL == (m_lpfnInetConfigClient = (PFNINETCONFIGCLIENT)GetProcAddress(m_hInetCfg, "InetConfigClient")))
  769. break;
  770. if (NULL == (m_lpfnInetGetAutodial = (PFNINETGETAUTODIAL)GetProcAddress(m_hInetCfg, "InetGetAutodial")))
  771. break;
  772. if (NULL == (m_lpfnInetSetAutodial = (PFNINETSETAUTODIAL)GetProcAddress(m_hInetCfg, "InetSetAutodial")))
  773. break;
  774. if (NULL == (m_lpfnInetSetClientInfo = (PFNINETSETCLIENTINFO)GetProcAddress(m_hInetCfg, "InetSetClientInfo")))
  775. break;
  776. if (NULL == (m_lpfnInetSetProxy = (PFNINETSETPROXY)GetProcAddress(m_hInetCfg, "InetSetProxy")))
  777. break;
  778. #endif // UNICODE
  779. }
  780. else
  781. {
  782. break;
  783. }
  784. if( IsNT() )
  785. {
  786. // Load the RAS functions
  787. m_hRAS = LoadLibrary(TEXT("RASAPI32.DLL"));
  788. if (m_hRAS != NULL)
  789. {
  790. #ifdef UNICODE
  791. if (NULL == (m_lpfnRasSetAutodialEnable = (PFNRASSETAUTODIALENABLE)GetProcAddress(m_hRAS, "RasSetAutodialEnableW")))
  792. break;
  793. if (NULL == (m_lpfnRasSetAutodialAddress = (PFNRASSETAUTODIALADDRESS)GetProcAddress(m_hRAS, "RasSetAutodialAddressW")))
  794. break;
  795. #else
  796. if (NULL == (m_lpfnRasSetAutodialEnable = (PFNRASSETAUTODIALENABLE)GetProcAddress(m_hRAS, "RasSetAutodialEnableA")))
  797. break;
  798. if (NULL == (m_lpfnRasSetAutodialAddress = (PFNRASSETAUTODIALADDRESS)GetProcAddress(m_hRAS, "RasSetAutodialAddressA")))
  799. break;
  800. #endif
  801. }
  802. else
  803. {
  804. break;
  805. }
  806. }
  807. // Success if we get to here
  808. bRet = TRUE;
  809. break;
  810. } while(1);
  811. return bRet;
  812. }
  813. //-----------------------------------------------------------------------------
  814. // OpenIcwRmindKey
  815. //-----------------------------------------------------------------------------
  816. BOOL CINSHandler::OpenIcwRmindKey(CMcRegistry &reg)
  817. {
  818. // This method will open the IcwRmind key in the registry. If the key
  819. // does not exist it will be created here.
  820. bool bRetCode = reg.OpenKey(HKEY_LOCAL_MACHINE, cszKeyIcwRmind);
  821. if (!bRetCode)
  822. {
  823. bRetCode = reg.CreateKey(HKEY_LOCAL_MACHINE, cszKeyIcwRmind);
  824. _ASSERT(bRetCode);
  825. }
  826. return bRetCode;
  827. }
  828. BOOL CINSHandler::ConfigureTrialReminder
  829. (
  830. LPCTSTR lpszFile
  831. )
  832. {
  833. USES_CONVERSION;
  834. TCHAR szISPName[MAX_ISP_NAME];
  835. TCHAR szISPMsg[MAX_ISP_MSG];
  836. TCHAR szISPPhoneNumber[MAX_ISP_PHONENUMBER];
  837. int iTrialDays;
  838. TCHAR szConvertURL[INTERNET_MAX_URL_LENGTH];
  839. TCHAR szExpiredISPFileURL[INTERNET_MAX_URL_LENGTH];
  840. TCHAR szExpiredISPFileName[MAX_PATH]; // The fully qualified path to the final INS file
  841. TCHAR szISPFile[MAX_PATH]; // The name we get in the INS
  842. TCHAR szConnectoidName[MAXNAME];
  843. if (GetPrivateProfileString(cszTrialRemindSection,
  844. cszEntryISPName,
  845. cszNull,
  846. szISPName,
  847. MAX_ISP_NAME,
  848. lpszFile) == 0)
  849. {
  850. return FALSE;
  851. }
  852. if (GetPrivateProfileString(cszTrialRemindSection,
  853. cszEntryISPPhone,
  854. cszNull,
  855. szISPPhoneNumber,
  856. MAX_ISP_PHONENUMBER,
  857. lpszFile) == 0)
  858. {
  859. return FALSE;
  860. }
  861. if ((iTrialDays = GetPrivateProfileInt(cszTrialRemindSection,
  862. cszEntryTrialDays,
  863. 0,
  864. lpszFile)) == 0)
  865. {
  866. return FALSE;
  867. }
  868. if (GetPrivateProfileString(cszTrialRemindSection,
  869. cszEntrySignupURL,
  870. cszNull,
  871. szConvertURL,
  872. INTERNET_MAX_URL_LENGTH,
  873. lpszFile) == 0)
  874. {
  875. return FALSE;
  876. }
  877. //optional
  878. GetPrivateProfileString(cszTrialRemindSection,
  879. cszEntryISPMsg,
  880. cszNull,
  881. szISPMsg,
  882. MAX_ISP_MSG,
  883. lpszFile);
  884. // Get the connectoid name from the [Entry] Section
  885. if (GetPrivateProfileString(cszEntrySection,
  886. cszEntryName,
  887. cszNull,
  888. szConnectoidName,
  889. MAXNAME,
  890. lpszFile) == 0)
  891. {
  892. return FALSE;
  893. }
  894. // If we get to here, we have everything to setup a trial, so let's do it.
  895. CMcRegistry reg;
  896. if (OpenIcwRmindKey(reg))
  897. {
  898. // Set the values we have
  899. reg.SetValue(cszEntryISPName, szISPName);
  900. reg.SetValue(cszEntryISPMsg, szISPMsg);
  901. reg.SetValue(cszEntryISPPhone, szISPPhoneNumber);
  902. reg.SetValue(cszEntryTrialDays, (DWORD)iTrialDays);
  903. reg.SetValue(cszEntrySignupURL, szConvertURL);
  904. reg.SetValue(cszEntryConnectoidName, szConnectoidName);
  905. // See if we have to create an ISP file
  906. if (GetPrivateProfileString(cszTrialRemindSection,
  907. cszEntryExpiredISPFileName,
  908. cszNull,
  909. szISPFile,
  910. MAX_PATH,
  911. lpszFile) != 0)
  912. {
  913. // Set the fully qualified path for the ISP file name
  914. wsprintf(szExpiredISPFileName,TEXT("%s\\%s"),g_pszAppDir,szISPFile);
  915. if (GetPrivateProfileString(cszTrialRemindSection,
  916. cszSignupExpiredISPURL,
  917. cszNull,
  918. szExpiredISPFileURL,
  919. INTERNET_MAX_URL_LENGTH,
  920. lpszFile) != 0)
  921. {
  922. // Download the ISP file, and then copy its contents
  923. IWebGate *pWebGate;
  924. CComBSTR bstrURL;
  925. CComBSTR bstrFname;
  926. BOOL bRetVal;
  927. if (SUCCEEDED(CoCreateInstance (CLSID_WebGate,
  928. NULL,
  929. CLSCTX_INPROC_SERVER,
  930. IID_IWebGate,
  931. (void **)&pWebGate)))
  932. {
  933. // Setup the webGate object, and download the ISP file
  934. bstrURL = A2BSTR(szExpiredISPFileURL);
  935. pWebGate->put_Path(bstrURL);
  936. pWebGate->FetchPage(1, 1, &bRetVal);
  937. if (bRetVal)
  938. {
  939. pWebGate->get_DownloadFname(&bstrFname);
  940. // Copy the file from the temp location, making sure one does not
  941. // yet exist
  942. DeleteFile(szExpiredISPFileName);
  943. MoveFile(OLE2A(bstrFname), szExpiredISPFileName);
  944. // Write the new file to the registry
  945. reg.SetValue(cszEntrySignupURLTrialOver, szExpiredISPFileName);
  946. }
  947. pWebGate->Release();
  948. }
  949. }
  950. }
  951. }
  952. return TRUE;
  953. }
  954. DWORD CINSHandler::ImportBrandingInfo
  955. (
  956. LPCTSTR lpszFile,
  957. LPCTSTR lpszConnectoidName
  958. )
  959. {
  960. TCHAR szPath[_MAX_PATH + 1];
  961. Assert(m_lpfnBrandICW != NULL);
  962. GetWindowsDirectory(szPath, ARRAYSIZE(szPath));
  963. NULL_TERM_TCHARS(szPath);
  964. #ifdef WIN32
  965. #ifdef UNICODE
  966. CHAR szEntry[RAS_MaxEntryName];
  967. CHAR szFile[_MAX_PATH + 1];
  968. CHAR szAsiPath[_MAX_PATH + 1];
  969. WideCharToMultiByte(CP_ACP, 0, lpszFile, -1, szFile, _MAX_PATH + 1, NULL, NULL);
  970. WideCharToMultiByte(CP_ACP, 0, szPath, -1, szAsiPath, _MAX_PATH + 1, NULL, NULL);
  971. WideCharToMultiByte(CP_ACP, 0, lpszConnectoidName, -1, szEntry, RAS_MaxEntryName, NULL, NULL);
  972. m_lpfnBrandICW(szFile, szAsiPath, m_dwBrandFlags, szEntry);
  973. #else
  974. m_lpfnBrandICW(lpszFile, szPath, m_dwBrandFlags, lpszConnectoidName);
  975. #endif
  976. #endif
  977. return ERROR_SUCCESS;
  978. }
  979. DWORD CINSHandler::ReadClientInfo
  980. (
  981. LPCTSTR lpszFile,
  982. LPINETCLIENTINFO lpClientInfo,
  983. LPCLIENT_TABLE lpClientTable
  984. )
  985. {
  986. LPCLIENT_TABLE lpTable;
  987. for (lpTable = lpClientTable; NULL != lpTable->lpszSection; ++lpTable)
  988. {
  989. GetPrivateProfileString(lpTable->lpszSection,
  990. lpTable->lpszValue,
  991. cszNull,
  992. (LPTSTR)((LPBYTE)lpClientInfo + lpTable->uOffset),
  993. lpTable->uSize / sizeof(TCHAR),
  994. lpszFile);
  995. }
  996. lpClientInfo->dwFlags = 0;
  997. if (*lpClientInfo->szPOPLogonName)
  998. {
  999. lpClientInfo->dwFlags |= INETC_LOGONMAIL;
  1000. }
  1001. if ((*lpClientInfo->szNNTPLogonName) || (*lpClientInfo->szNNTPServer))
  1002. {
  1003. lpClientInfo->dwFlags |= INETC_LOGONNEWS;
  1004. }
  1005. return ERROR_SUCCESS;
  1006. }
  1007. BOOL CINSHandler::WantsExchangeInstalled(LPCTSTR lpszFile)
  1008. {
  1009. TCHAR szTemp[10];
  1010. GetPrivateProfileString(cszEMailSection,
  1011. cszUseExchange,
  1012. cszNo,
  1013. szTemp,
  1014. 10,
  1015. lpszFile);
  1016. return (!lstrcmpi(szTemp, cszYes));
  1017. }
  1018. BOOL CINSHandler::DisplayPassword(LPCTSTR lpszFile)
  1019. {
  1020. TCHAR szTemp[10];
  1021. GetPrivateProfileString(cszUserSection,
  1022. cszDisplayPassword,
  1023. cszNo,
  1024. szTemp,
  1025. 10,
  1026. lpszFile);
  1027. return (!lstrcmpi(szTemp, cszYes));
  1028. }
  1029. DWORD CINSHandler::ImportClientInfo
  1030. (
  1031. LPCTSTR lpszFile,
  1032. LPINETCLIENTINFO lpClientInfo
  1033. )
  1034. {
  1035. DWORD dwRet;
  1036. lpClientInfo->dwSize = sizeof(INETCLIENTINFO);
  1037. dwRet = ReadClientInfo(lpszFile, lpClientInfo, iniTable);
  1038. return dwRet;
  1039. }
  1040. DWORD CINSHandler::ConfigureClient
  1041. (
  1042. HWND hwnd,
  1043. LPCTSTR lpszFile,
  1044. LPBOOL lpfNeedsRestart,
  1045. LPBOOL lpfConnectoidCreated,
  1046. BOOL fHookAutodial,
  1047. LPTSTR szConnectoidName,
  1048. DWORD dwConnectoidNameSize
  1049. )
  1050. {
  1051. LPICONNECTION pConn;
  1052. LPINETCLIENTINFO pClientInfo = NULL;
  1053. DWORD dwRet = ERROR_SUCCESS;
  1054. UINT cb = sizeof(ICONNECTION) + sizeof(INETCLIENTINFO);
  1055. DWORD dwfOptions = INETCFG_INSTALLTCP | INETCFG_WARNIFSHARINGBOUND;
  1056. LPRASENTRY pRasEntry = NULL;
  1057. //
  1058. // ChrisK Olympus 4756 5/25/97
  1059. // Do not display busy animation on Win95
  1060. //
  1061. if (!m_bSilentMode && IsNT())
  1062. {
  1063. dwfOptions |= INETCFG_SHOWBUSYANIMATION;
  1064. }
  1065. // Allocate a buffer for connection and clientinfo objects
  1066. //
  1067. if ((pConn = (LPICONNECTION)LocalAlloc(LPTR, cb)) == NULL)
  1068. {
  1069. return ERROR_OUTOFMEMORY;
  1070. }
  1071. if (WantsExchangeInstalled(lpszFile))
  1072. {
  1073. dwfOptions |= INETCFG_INSTALLMAIL;
  1074. }
  1075. // Create either a CM profile, or a connectoid
  1076. if (CallCMConfig(lpszFile))
  1077. {
  1078. *lpfConnectoidCreated = TRUE; // A dialup connection was created
  1079. }
  1080. else
  1081. {
  1082. dwRet = ImportConnection(lpszFile, pConn);
  1083. if (ERROR_SUCCESS == dwRet)
  1084. {
  1085. pRasEntry = &pConn->RasEntry;
  1086. dwfOptions |= INETCFG_SETASAUTODIAL |
  1087. INETCFG_INSTALLRNA |
  1088. INETCFG_INSTALLMODEM;
  1089. }
  1090. else if (ERROR_CANNOT_FIND_PHONEBOOK_ENTRY != dwRet)
  1091. {
  1092. return dwRet;
  1093. }
  1094. if (!m_bSilentMode && DisplayPassword(lpszFile))
  1095. {
  1096. if (*pConn->szPassword || *pConn->szUserName)
  1097. {
  1098. TCHAR szFmt[1024];
  1099. TCHAR szMsg[1024];
  1100. LoadString(_Module.GetModuleInstance(), IDS_PASSWORD, szFmt, 1024);
  1101. wsprintf(szMsg, szFmt, pConn->szUserName, pConn->szPassword);
  1102. ::MessageBox(hwnd, szMsg, GetSz(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  1103. }
  1104. }
  1105. if (fHookAutodial &&
  1106. ((0 == *pConn->RasEntry.szAutodialDll) ||
  1107. (0 == *pConn->RasEntry.szAutodialFunc)))
  1108. {
  1109. lstrcpy(pConn->RasEntry.szAutodialDll, TEXT("isign32.dll"));
  1110. lstrcpy(pConn->RasEntry.szAutodialFunc, TEXT("AutoDialLogon"));
  1111. }
  1112. // humongous hack for ISBU
  1113. Assert(m_lpfnInetConfigClient);
  1114. Assert(m_lpfnInetGetAutodial);
  1115. dwRet = m_lpfnInetConfigClient(hwnd,
  1116. NULL,
  1117. pConn->szEntryName,
  1118. pRasEntry,
  1119. pConn->szUserName,
  1120. pConn->szPassword,
  1121. NULL,
  1122. NULL,
  1123. dwfOptions & ~INETCFG_INSTALLMAIL,
  1124. lpfNeedsRestart);
  1125. lstrcpy(szConnectoidName, pConn->szEntryName);
  1126. LclSetEntryScriptPatch(pRasEntry->szScript,pConn->szEntryName);
  1127. BOOL fEnabled = TRUE;
  1128. DWORD dwResult = 0xba;
  1129. dwResult = m_lpfnInetGetAutodial(&fEnabled, pConn->szEntryName, RAS_MaxEntryName);
  1130. if ((ERROR_SUCCESS == dwRet) && lstrlen(pConn->szEntryName))
  1131. {
  1132. *lpfConnectoidCreated = (NULL != pRasEntry);
  1133. PopulateNTAutodialAddress( lpszFile, pConn->szEntryName );
  1134. }
  1135. else
  1136. {
  1137. TraceMsg(TF_INSHANDLER, TEXT("ISIGNUP: ERROR: InetGetAutodial failed, will not be able to set NT Autodial\n"));
  1138. }
  1139. }
  1140. // If we were successfull in creating the connectio, then see if the user wants a
  1141. // mail client installed
  1142. if (ERROR_SUCCESS == dwRet)
  1143. {
  1144. // Get the mail client info
  1145. INETCLIENTINFO pClientInfo;
  1146. ImportClientInfo(lpszFile, &pClientInfo);
  1147. // use inet config to install the mail client
  1148. dwRet = m_lpfnInetConfigClient(hwnd,
  1149. NULL,
  1150. NULL,
  1151. NULL,
  1152. NULL,
  1153. NULL,
  1154. NULL,
  1155. &pClientInfo,
  1156. dwfOptions & INETCFG_INSTALLMAIL,
  1157. lpfNeedsRestart);
  1158. }
  1159. // cleanup
  1160. LocalFree(pConn);
  1161. return dwRet;
  1162. }
  1163. //+----------------------------------------------------------------------------
  1164. //
  1165. // Function: PopulateNTAutodialAddress
  1166. //
  1167. // Synopsis: Take Internet addresses from INS file and load them into the
  1168. // autodial database
  1169. //
  1170. // Arguments: pszFileName - pointer to INS file name
  1171. //
  1172. // Returns: Error code (ERROR_SUCCESS == success)
  1173. //
  1174. // History: 8/29/96 ChrisK Created
  1175. //
  1176. //-----------------------------------------------------------------------------
  1177. #define AUTODIAL_ADDRESS_BUFFER_SIZE 2048
  1178. #define AUTODIAL_ADDRESS_SECTION_NAME TEXT("Autodial_Addresses_for_NT")
  1179. HRESULT CINSHandler::PopulateNTAutodialAddress(LPCTSTR pszFileName, LPCTSTR pszEntryName)
  1180. {
  1181. HRESULT hr = ERROR_SUCCESS;
  1182. LONG lRC = 0;
  1183. LPLINETRANSLATECAPS lpcap = NULL;
  1184. LPLINETRANSLATECAPS lpTemp = NULL;
  1185. LPLINELOCATIONENTRY lpLE = NULL;
  1186. LPRASAUTODIALENTRY rADE;
  1187. INT idx = 0;
  1188. LPTSTR lpszBuffer = NULL;
  1189. LPTSTR lpszNextAddress = NULL;
  1190. rADE = NULL;
  1191. Assert(m_lpfnRasSetAutodialEnable);
  1192. Assert(m_lpfnRasSetAutodialAddress);
  1193. //RNAAPI *pRnaapi = NULL;
  1194. // jmazner 10/8/96 this function is NT specific
  1195. if( !IsNT() )
  1196. {
  1197. TraceMsg(TF_INSHANDLER, TEXT("ISIGNUP: Bypassing PopulateNTAutodialAddress for win95.\r\n"));
  1198. return( ERROR_SUCCESS );
  1199. }
  1200. //Assert(pszFileName && pszEntryName);
  1201. //dprintf("ISIGNUP: PopulateNTAutodialAddress "%s %s.\r\n",pszFileName, pszEntryName);
  1202. TraceMsg(TF_INSHANDLER, pszFileName);
  1203. TraceMsg(TF_INSHANDLER, TEXT(", "));
  1204. TraceMsg(TF_INSHANDLER, pszEntryName);
  1205. TraceMsg(TF_INSHANDLER, TEXT(".\r\n"));
  1206. //
  1207. // Get list of TAPI locations
  1208. //
  1209. lpcap = (LPLINETRANSLATECAPS)GlobalAlloc(GPTR,sizeof(LINETRANSLATECAPS));
  1210. if (!lpcap)
  1211. {
  1212. hr = ERROR_NOT_ENOUGH_MEMORY;
  1213. goto PopulateNTAutodialAddressExit;
  1214. }
  1215. lpcap->dwTotalSize = sizeof(LINETRANSLATECAPS);
  1216. lRC = lineGetTranslateCaps(0,0x10004,lpcap);
  1217. if (SUCCESS == lRC)
  1218. {
  1219. lpTemp = (LPLINETRANSLATECAPS)GlobalAlloc(GPTR,lpcap->dwNeededSize);
  1220. if (!lpTemp)
  1221. {
  1222. hr = ERROR_NOT_ENOUGH_MEMORY;
  1223. goto PopulateNTAutodialAddressExit;
  1224. }
  1225. lpTemp->dwTotalSize = lpcap->dwNeededSize;
  1226. GlobalFree(lpcap);
  1227. lpcap = (LPLINETRANSLATECAPS)lpTemp;
  1228. lpTemp = NULL;
  1229. lRC = lineGetTranslateCaps(0,0x10004,lpcap);
  1230. }
  1231. if (SUCCESS != lRC)
  1232. {
  1233. hr = (HRESULT)lRC; // REVIEW: not real sure about this.
  1234. goto PopulateNTAutodialAddressExit;
  1235. }
  1236. //
  1237. // Create an array of RASAUTODIALENTRY structs
  1238. //
  1239. rADE = (LPRASAUTODIALENTRY)GlobalAlloc(GPTR,
  1240. sizeof(RASAUTODIALENTRY)*lpcap->dwNumLocations);
  1241. if (!rADE)
  1242. {
  1243. hr = ERROR_NOT_ENOUGH_MEMORY;
  1244. goto PopulateNTAutodialAddressExit;
  1245. }
  1246. //
  1247. // Enable autodialing for all locations
  1248. //
  1249. idx = lpcap->dwNumLocations;
  1250. lpLE = (LPLINELOCATIONENTRY)((DWORD_PTR)lpcap + (DWORD)lpcap->dwLocationListOffset);
  1251. while (idx)
  1252. {
  1253. idx--;
  1254. m_lpfnRasSetAutodialEnable(lpLE[idx].dwPermanentLocationID,TRUE);
  1255. //
  1256. // fill in array values
  1257. //
  1258. rADE[idx].dwSize = sizeof(RASAUTODIALENTRY);
  1259. rADE[idx].dwDialingLocation = lpLE[idx].dwPermanentLocationID;
  1260. lstrcpyn(rADE[idx].szEntry,pszEntryName,RAS_MaxEntryName);
  1261. }
  1262. //
  1263. // Get list of addresses
  1264. //
  1265. lpszBuffer = (LPTSTR)GlobalAlloc(GPTR,AUTODIAL_ADDRESS_BUFFER_SIZE);
  1266. if (!lpszBuffer)
  1267. {
  1268. hr = ERROR_NOT_ENOUGH_MEMORY;
  1269. goto PopulateNTAutodialAddressExit;
  1270. }
  1271. if((AUTODIAL_ADDRESS_BUFFER_SIZE-2) == GetPrivateProfileSection(AUTODIAL_ADDRESS_SECTION_NAME,
  1272. lpszBuffer,AUTODIAL_ADDRESS_BUFFER_SIZE/sizeof(TCHAR),pszFileName))
  1273. {
  1274. //AssertSz(0,"Autodial address section bigger than buffer.\r\n");
  1275. hr = ERROR_NOT_ENOUGH_MEMORY;
  1276. goto PopulateNTAutodialAddressExit;
  1277. }
  1278. //
  1279. // Walk list of addresses and set autodialing for each one
  1280. //
  1281. lpszNextAddress = lpszBuffer;
  1282. do
  1283. {
  1284. lpszNextAddress = MoveToNextAddress(lpszNextAddress);
  1285. if (!(*lpszNextAddress))
  1286. break; // do-while
  1287. m_lpfnRasSetAutodialAddress(lpszNextAddress,0,rADE,
  1288. sizeof(RASAUTODIALENTRY)*lpcap->dwNumLocations,lpcap->dwNumLocations);
  1289. lpszNextAddress = lpszNextAddress + lstrlen(lpszNextAddress);
  1290. } while(1);
  1291. PopulateNTAutodialAddressExit:
  1292. if (lpcap)
  1293. GlobalFree(lpcap);
  1294. lpcap = NULL;
  1295. if (rADE)
  1296. GlobalFree(rADE);
  1297. rADE = NULL;
  1298. if (lpszBuffer)
  1299. GlobalFree(lpszBuffer);
  1300. lpszBuffer = NULL;
  1301. //if( pRnaapi )
  1302. // delete pRnaapi;
  1303. //pRnaapi = NULL;
  1304. return hr;
  1305. }
  1306. //+----------------------------------------------------------------------------
  1307. //
  1308. // Function: MoveToNextAddress
  1309. //
  1310. // Synopsis: Given a pointer into the data bufffer, this function will move
  1311. // through the buffer until it points to the begining of the next
  1312. // address or it reaches the end of the buffer.
  1313. //
  1314. // Arguements: lpsz - pointer into buffer
  1315. //
  1316. // Returns: Pointer to the next address, return value will point to NULL
  1317. // if there are no more addresses
  1318. //
  1319. // History: 8/29/96 ChrisK Created
  1320. //
  1321. //-----------------------------------------------------------------------------
  1322. LPTSTR CINSHandler::MoveToNextAddress(LPTSTR lpsz)
  1323. {
  1324. BOOL fLastCharWasNULL = FALSE;
  1325. //AssertSz(lpsz,"MoveToNextAddress: NULL input\r\n");
  1326. //
  1327. // Look for an = sign
  1328. //
  1329. do
  1330. {
  1331. if (fLastCharWasNULL && '\0' == *lpsz)
  1332. break; // are we at the end of the data?
  1333. if ('\0' == *lpsz)
  1334. fLastCharWasNULL = TRUE;
  1335. else
  1336. fLastCharWasNULL = FALSE;
  1337. if ('=' == *lpsz)
  1338. break;
  1339. if (*lpsz)
  1340. lpsz = CharNext(lpsz);
  1341. else
  1342. lpsz++;
  1343. } while (1);
  1344. //
  1345. // Move to the first character beyond the = sign.
  1346. //
  1347. if (*lpsz)
  1348. lpsz = CharNext(lpsz);
  1349. return lpsz;
  1350. }
  1351. //+----------------------------------------------------------------------------
  1352. //
  1353. // Function: ImportCustomDialer
  1354. //
  1355. // Synopsis: Import custom dialer information from the specified file
  1356. // and save the information in the RASENTRY
  1357. //
  1358. // Arguments: lpRasEntry - pointer to a valid RASENTRY structure
  1359. // szFileName - text file (in .ini file format) containing the
  1360. // Custom Dialer information
  1361. //
  1362. // Returns: ERROR_SUCCESS - success otherwise a Win32 error
  1363. //
  1364. // History: ChrisK Created 7/11/96
  1365. // 8/12/96 ChrisK Ported from \\trango
  1366. //
  1367. //-----------------------------------------------------------------------------
  1368. DWORD CINSHandler::ImportCustomDialer(LPRASENTRY lpRasEntry, LPCTSTR szFileName)
  1369. {
  1370. // If there is an error reading the information from the file, or the entry
  1371. // missing or blank, the default value (cszNull) will be used.
  1372. GetPrivateProfileString(cszCustomDialerSection,
  1373. cszAutoDialDLL,
  1374. cszNull,
  1375. lpRasEntry->szAutodialDll,
  1376. MAX_PATH,
  1377. szFileName);
  1378. GetPrivateProfileString(cszCustomDialerSection,
  1379. cszAutoDialFunc,
  1380. cszNull,
  1381. lpRasEntry->szAutodialFunc,
  1382. MAX_PATH,
  1383. szFileName);
  1384. return ERROR_SUCCESS;
  1385. }
  1386. //****************************************************************************
  1387. // DWORD NEAR PASCAL StrToip (LPTSTR szIPAddress, LPDWORD lpdwAddr)
  1388. //
  1389. // This function converts a IP address string to an IP address structure.
  1390. //
  1391. // History:
  1392. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1393. // Cloned from SMMSCRPT.
  1394. //****************************************************************************
  1395. LPCTSTR CINSHandler::StrToSubip (LPCTSTR szIPAddress, LPBYTE pVal)
  1396. {
  1397. LPCTSTR pszIP = szIPAddress;
  1398. BYTE val = 0;
  1399. // skip separators (non digits)
  1400. while (*pszIP && !myisdigit(*pszIP))
  1401. {
  1402. ++pszIP;
  1403. }
  1404. while (myisdigit(*pszIP))
  1405. {
  1406. val = (val * 10) + (BYTE)(*pszIP - '0');
  1407. ++pszIP;
  1408. }
  1409. *pVal = val;
  1410. return pszIP;
  1411. }
  1412. DWORD CINSHandler::StrToip (LPCTSTR szIPAddress, RASIPADDR *ipAddr)
  1413. {
  1414. LPCTSTR pszIP = szIPAddress;
  1415. pszIP = StrToSubip(pszIP, &ipAddr->a);
  1416. pszIP = StrToSubip(pszIP, &ipAddr->b);
  1417. pszIP = StrToSubip(pszIP, &ipAddr->c);
  1418. pszIP = StrToSubip(pszIP, &ipAddr->d);
  1419. return ERROR_SUCCESS;
  1420. }
  1421. //****************************************************************************
  1422. // DWORD NEAR PASCAL ImportPhoneInfo(PPHONENUM ppn, LPCTSTR szFileName)
  1423. //
  1424. // This function imports the phone number.
  1425. //
  1426. // History:
  1427. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1428. // Created.
  1429. //****************************************************************************
  1430. DWORD CINSHandler::ImportPhoneInfo(LPRASENTRY lpRasEntry, LPCTSTR szFileName)
  1431. {
  1432. TCHAR szYesNo[MAXNAME];
  1433. if (GetPrivateProfileString(cszPhoneSection,
  1434. cszPhone,
  1435. cszNull,
  1436. lpRasEntry->szLocalPhoneNumber,
  1437. RAS_MaxPhoneNumber,
  1438. szFileName) == 0)
  1439. {
  1440. return ERROR_BAD_PHONE_NUMBER;
  1441. }
  1442. lpRasEntry->dwfOptions &= ~RASEO_UseCountryAndAreaCodes;
  1443. GetPrivateProfileString(cszPhoneSection,
  1444. cszDialAsIs,
  1445. cszNo,
  1446. szYesNo,
  1447. MAXNAME,
  1448. szFileName);
  1449. // Do we have to get country code and area code?
  1450. if (!lstrcmpi(szYesNo, cszNo))
  1451. {
  1452. // If we cannot get the country ID or it is zero, default to dial as is
  1453. //
  1454. if ((lpRasEntry->dwCountryID = GetPrivateProfileInt(cszPhoneSection,
  1455. cszCountryID,
  1456. 0,
  1457. szFileName)) != 0)
  1458. {
  1459. lpRasEntry->dwCountryCode = GetPrivateProfileInt(cszPhoneSection,
  1460. cszCountryCode,
  1461. 1,
  1462. szFileName);
  1463. GetPrivateProfileString(cszPhoneSection,
  1464. cszAreaCode,
  1465. cszNull,
  1466. lpRasEntry->szAreaCode,
  1467. RAS_MaxAreaCode,
  1468. szFileName);
  1469. lpRasEntry->dwfOptions |= RASEO_UseCountryAndAreaCodes;
  1470. }
  1471. }
  1472. else
  1473. {
  1474. // bug in RasSetEntryProperties still checks area codes
  1475. // even when RASEO_UseCountryAndAreaCodes is not set
  1476. lstrcpy(lpRasEntry->szAreaCode, TEXT("805"));
  1477. lpRasEntry->dwCountryID = 1;
  1478. lpRasEntry->dwCountryCode = 1;
  1479. }
  1480. return ERROR_SUCCESS;
  1481. }
  1482. //****************************************************************************
  1483. // DWORD NEAR PASCAL ImportServerInfo(PSMMINFO psmmi, LPTSTR szFileName)
  1484. //
  1485. // This function imports the server type name and settings.
  1486. //
  1487. // History:
  1488. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1489. // Created.
  1490. //****************************************************************************
  1491. DWORD CINSHandler::ImportServerInfo(LPRASENTRY lpRasEntry, LPCTSTR szFileName)
  1492. {
  1493. TCHAR szYesNo[MAXNAME];
  1494. TCHAR szType[MAXNAME];
  1495. DWORD i;
  1496. // Get the server type name
  1497. GetPrivateProfileString(cszServerSection,
  1498. cszServerType,
  1499. cszNull,
  1500. szType,
  1501. MAXNAME,
  1502. szFileName);
  1503. // need to convert the string into
  1504. // one of the following values
  1505. // RASFP_Ppp
  1506. // RASFP_Slip Note CSLIP is SLIP with IP compression on
  1507. // RASFP_Ras
  1508. for (i = 0; i < NUM_SERVER_TYPES; ++i)
  1509. {
  1510. if (!lstrcmpi(aServerTypes[i].szType, szType))
  1511. {
  1512. lpRasEntry->dwFramingProtocol = aServerTypes[i].dwType;
  1513. lpRasEntry->dwfOptions |= aServerTypes[i].dwfOptions;
  1514. break;
  1515. }
  1516. }
  1517. // Get the server type settings
  1518. if (GetPrivateProfileString(cszServerSection,
  1519. cszSWCompress,
  1520. cszYes,
  1521. szYesNo,
  1522. MAXNAME,
  1523. szFileName))
  1524. {
  1525. if (!lstrcmpi(szYesNo, cszNo))
  1526. {
  1527. lpRasEntry->dwfOptions &= ~RASEO_SwCompression;
  1528. }
  1529. else
  1530. {
  1531. lpRasEntry->dwfOptions |= RASEO_SwCompression;
  1532. }
  1533. }
  1534. if (GetPrivateProfileString(cszServerSection,
  1535. cszPWEncrypt,
  1536. cszNull,
  1537. szYesNo,
  1538. MAXNAME,
  1539. szFileName))
  1540. {
  1541. if (!lstrcmpi(szYesNo, cszNo))
  1542. {
  1543. lpRasEntry->dwfOptions &= ~RASEO_RequireEncryptedPw;
  1544. }
  1545. else
  1546. {
  1547. lpRasEntry->dwfOptions |= RASEO_RequireEncryptedPw;
  1548. }
  1549. }
  1550. if (GetPrivateProfileString(cszServerSection,
  1551. cszNetLogon,
  1552. cszNo,
  1553. szYesNo,
  1554. MAXNAME,
  1555. szFileName))
  1556. {
  1557. if (!lstrcmpi(szYesNo, cszNo))
  1558. {
  1559. lpRasEntry->dwfOptions &= ~RASEO_NetworkLogon;
  1560. }
  1561. else
  1562. {
  1563. lpRasEntry->dwfOptions |= RASEO_NetworkLogon;
  1564. }
  1565. }
  1566. if (GetPrivateProfileString(cszServerSection,
  1567. cszSWEncrypt,
  1568. cszNo,
  1569. szYesNo,
  1570. MAXNAME,
  1571. szFileName))
  1572. {
  1573. if (!lstrcmpi(szYesNo, cszNo))
  1574. {
  1575. lpRasEntry->dwfOptions &= ~RASEO_RequireDataEncryption;
  1576. }
  1577. else
  1578. {
  1579. lpRasEntry->dwfOptions |= RASEO_RequireDataEncryption;
  1580. }
  1581. }
  1582. // Get the protocol settings
  1583. if (GetPrivateProfileString(cszServerSection,
  1584. cszNetBEUI,
  1585. cszNo,
  1586. szYesNo,
  1587. MAXNAME,
  1588. szFileName))
  1589. {
  1590. if (!lstrcmpi(szYesNo, cszNo))
  1591. {
  1592. lpRasEntry->dwfNetProtocols &= ~RASNP_NetBEUI;
  1593. }
  1594. else
  1595. {
  1596. lpRasEntry->dwfNetProtocols |= RASNP_NetBEUI;
  1597. }
  1598. }
  1599. if (GetPrivateProfileString(cszServerSection,
  1600. cszIPX,
  1601. cszNo,
  1602. szYesNo,
  1603. MAXNAME,
  1604. szFileName))
  1605. {
  1606. if (!lstrcmpi(szYesNo, cszNo))
  1607. {
  1608. lpRasEntry->dwfNetProtocols &= ~RASNP_Ipx;
  1609. }
  1610. else
  1611. {
  1612. lpRasEntry->dwfNetProtocols |= RASNP_Ipx;
  1613. }
  1614. }
  1615. if (GetPrivateProfileString(cszServerSection,
  1616. cszIP,
  1617. cszYes,
  1618. szYesNo,
  1619. MAXNAME,
  1620. szFileName))
  1621. {
  1622. if (!lstrcmpi(szYesNo, cszNo))
  1623. {
  1624. lpRasEntry->dwfNetProtocols &= ~RASNP_Ip;
  1625. }
  1626. else
  1627. {
  1628. lpRasEntry->dwfNetProtocols |= RASNP_Ip;
  1629. }
  1630. }
  1631. if (GetPrivateProfileString(cszServerSection,
  1632. cszDisableLcp,
  1633. cszNull,
  1634. szYesNo,
  1635. MAXNAME,
  1636. szFileName))
  1637. {
  1638. if (!lstrcmpi(szYesNo, cszYes))
  1639. {
  1640. lpRasEntry->dwfOptions |= RASEO_DisableLcpExtensions;
  1641. }
  1642. else
  1643. {
  1644. lpRasEntry->dwfOptions &= ~RASEO_DisableLcpExtensions;
  1645. }
  1646. }
  1647. return ERROR_SUCCESS;
  1648. }
  1649. //****************************************************************************
  1650. // DWORD NEAR PASCAL ImportIPInfo(LPTSTR szEntryName, LPTSTR szFileName)
  1651. //
  1652. // This function imports the TCP/IP information
  1653. //
  1654. // History:
  1655. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1656. // Created.
  1657. //****************************************************************************
  1658. DWORD CINSHandler::ImportIPInfo(LPRASENTRY lpRasEntry, LPCTSTR szFileName)
  1659. {
  1660. TCHAR szIPAddr[MAXIPADDRLEN];
  1661. TCHAR szYesNo[MAXNAME];
  1662. // Import IP address information
  1663. if (GetPrivateProfileString(cszIPSection,
  1664. cszIPSpec,
  1665. cszNo,
  1666. szYesNo,
  1667. MAXNAME,
  1668. szFileName))
  1669. {
  1670. if (!lstrcmpi(szYesNo, cszYes))
  1671. {
  1672. // The import file has IP address specified, get the IP address
  1673. lpRasEntry->dwfOptions |= RASEO_SpecificIpAddr;
  1674. if (GetPrivateProfileString(cszIPSection,
  1675. cszIPAddress,
  1676. cszNull,
  1677. szIPAddr,
  1678. MAXIPADDRLEN,
  1679. szFileName))
  1680. {
  1681. StrToip (szIPAddr, &lpRasEntry->ipaddr);
  1682. }
  1683. }
  1684. else
  1685. {
  1686. lpRasEntry->dwfOptions &= ~RASEO_SpecificIpAddr;
  1687. }
  1688. }
  1689. // Import Server address information
  1690. if (GetPrivateProfileString(cszIPSection,
  1691. cszServerSpec,
  1692. cszNo,
  1693. szYesNo,
  1694. MAXNAME,
  1695. szFileName))
  1696. {
  1697. if (!lstrcmpi(szYesNo, cszYes))
  1698. {
  1699. // The import file has server address specified, get the server address
  1700. lpRasEntry->dwfOptions |= RASEO_SpecificNameServers;
  1701. if (GetPrivateProfileString(cszIPSection,
  1702. cszDNSAddress,
  1703. cszNull,
  1704. szIPAddr,
  1705. MAXIPADDRLEN,
  1706. szFileName))
  1707. {
  1708. StrToip (szIPAddr, &lpRasEntry->ipaddrDns);
  1709. }
  1710. if (GetPrivateProfileString(cszIPSection,
  1711. cszDNSAltAddress,
  1712. cszNull,
  1713. szIPAddr,
  1714. MAXIPADDRLEN,
  1715. szFileName))
  1716. {
  1717. StrToip (szIPAddr, &lpRasEntry->ipaddrDnsAlt);
  1718. }
  1719. if (GetPrivateProfileString(cszIPSection,
  1720. cszWINSAddress,
  1721. cszNull,
  1722. szIPAddr,
  1723. MAXIPADDRLEN,
  1724. szFileName))
  1725. {
  1726. StrToip (szIPAddr, &lpRasEntry->ipaddrWins);
  1727. }
  1728. if (GetPrivateProfileString(cszIPSection,
  1729. cszWINSAltAddress,
  1730. cszNull,
  1731. szIPAddr,
  1732. MAXIPADDRLEN,
  1733. szFileName))
  1734. {
  1735. StrToip (szIPAddr, &lpRasEntry->ipaddrWinsAlt);
  1736. }
  1737. }
  1738. else
  1739. {
  1740. lpRasEntry->dwfOptions &= ~RASEO_SpecificNameServers;
  1741. }
  1742. }
  1743. // Header compression and the gateway settings
  1744. if (GetPrivateProfileString(cszIPSection,
  1745. cszIPCompress,
  1746. cszYes,
  1747. szYesNo,
  1748. MAXNAME,
  1749. szFileName))
  1750. {
  1751. if (!lstrcmpi(szYesNo, cszNo))
  1752. {
  1753. lpRasEntry->dwfOptions &= ~RASEO_IpHeaderCompression;
  1754. }
  1755. else
  1756. {
  1757. lpRasEntry->dwfOptions |= RASEO_IpHeaderCompression;
  1758. }
  1759. }
  1760. if (GetPrivateProfileString(cszIPSection,
  1761. cszWanPri,
  1762. cszYes,
  1763. szYesNo,
  1764. MAXNAME,
  1765. szFileName))
  1766. {
  1767. if (!lstrcmpi(szYesNo, cszNo))
  1768. {
  1769. lpRasEntry->dwfOptions &= ~RASEO_RemoteDefaultGateway;
  1770. }
  1771. else
  1772. {
  1773. lpRasEntry->dwfOptions |= RASEO_RemoteDefaultGateway;
  1774. }
  1775. }
  1776. return ERROR_SUCCESS;
  1777. }
  1778. DWORD CINSHandler::ImportScriptFile(
  1779. LPCTSTR lpszImportFile,
  1780. LPTSTR szScriptFile,
  1781. UINT cbScriptFile)
  1782. {
  1783. TCHAR szTemp[_MAX_PATH];
  1784. DWORD dwRet = ERROR_SUCCESS;
  1785. // Get the script filename
  1786. //
  1787. if (GetPrivateProfileString(cszScriptingSection,
  1788. cszScriptName,
  1789. cszNull,
  1790. szTemp,
  1791. _MAX_PATH,
  1792. lpszImportFile) != 0)
  1793. {
  1794. //!!! commonize this code
  1795. //!!! make it DBCS compatible
  1796. //!!! check for overruns
  1797. //!!! check for absolute path name
  1798. GetWindowsDirectory(szScriptFile, cbScriptFile);
  1799. if (*CharPrev(szScriptFile, szScriptFile + lstrlen(szScriptFile)) != '\\')
  1800. {
  1801. lstrcat(szScriptFile, TEXT("\\"));
  1802. }
  1803. lstrcat(szScriptFile, szTemp);
  1804. dwRet =ImportFile(lpszImportFile, cszScriptSection, szScriptFile);
  1805. }
  1806. return dwRet;
  1807. }
  1808. //****************************************************************************
  1809. // DWORD WINAPI RnaValidateImportEntry (LPTSTR)
  1810. //
  1811. // This function is called to validate an importable file
  1812. //
  1813. // History:
  1814. // Wed 03-Jan-1996 09:45:01 -by- Viroon Touranachun [viroont]
  1815. // Created.
  1816. //****************************************************************************
  1817. DWORD CINSHandler::RnaValidateImportEntry (LPCTSTR szFileName)
  1818. {
  1819. TCHAR szTmp[MAX_PATH+1];
  1820. // Get the alias entry name
  1821. //
  1822. // 12/4/96 jmazner Normandy #12373
  1823. // If no such key, don't return ERROR_INVALID_PHONEBOOK_ENTRY,
  1824. // since ConfigureClient always ignores that error code.
  1825. return (GetPrivateProfileString(cszEntrySection,
  1826. cszEntryName,
  1827. cszNull,
  1828. szTmp,
  1829. MAX_PATH,
  1830. szFileName) > 0 ?
  1831. ERROR_SUCCESS : ERROR_UNKNOWN);
  1832. }
  1833. //****************************************************************************
  1834. // DWORD WINAPI RnaImportEntry (LPTSTR, LPBYTE, DWORD)
  1835. //
  1836. // This function is called to import an entry from a specified file
  1837. //
  1838. // History:
  1839. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1840. // Created.
  1841. //****************************************************************************
  1842. DWORD CINSHandler::ImportRasEntry (LPCTSTR szFileName, LPRASENTRY lpRasEntry)
  1843. {
  1844. DWORD dwRet;
  1845. dwRet = ImportPhoneInfo(lpRasEntry, szFileName);
  1846. if (ERROR_SUCCESS == dwRet)
  1847. {
  1848. // Get device type
  1849. //
  1850. GetPrivateProfileString(cszDeviceSection,
  1851. cszDeviceType,
  1852. cszNull,
  1853. lpRasEntry->szDeviceType,
  1854. RAS_MaxDeviceType,
  1855. szFileName);
  1856. // Get Server Type settings
  1857. //
  1858. dwRet = ImportServerInfo(lpRasEntry, szFileName);
  1859. if (ERROR_SUCCESS == dwRet)
  1860. {
  1861. // Get IP address
  1862. //
  1863. dwRet = ImportIPInfo(lpRasEntry, szFileName);
  1864. }
  1865. }
  1866. return dwRet;
  1867. }
  1868. //****************************************************************************
  1869. // DWORD WINAPI RnaImportEntry (LPTSTR, LPBYTE, DWORD)
  1870. //
  1871. // This function is called to import an entry from a specified file
  1872. //
  1873. // History:
  1874. // Mon 18-Dec-1995 10:07:02 -by- Viroon Touranachun [viroont]
  1875. // Created.
  1876. //****************************************************************************
  1877. DWORD CINSHandler::ImportConnection (LPCTSTR szFileName, LPICONNECTION lpConn)
  1878. {
  1879. DWORD dwRet;
  1880. lpConn->RasEntry.dwSize = sizeof(RASENTRY);
  1881. dwRet = RnaValidateImportEntry(szFileName);
  1882. if (ERROR_SUCCESS != dwRet)
  1883. {
  1884. return dwRet;
  1885. }
  1886. GetPrivateProfileString(cszEntrySection,
  1887. cszEntryName,
  1888. cszNull,
  1889. lpConn->szEntryName,
  1890. RAS_MaxEntryName,
  1891. szFileName);
  1892. GetPrivateProfileString(cszUserSection,
  1893. cszUserName,
  1894. cszNull,
  1895. lpConn->szUserName,
  1896. UNLEN,
  1897. szFileName);
  1898. GetPrivateProfileString(cszUserSection,
  1899. cszPassword,
  1900. cszNull,
  1901. lpConn->szPassword,
  1902. PWLEN,
  1903. szFileName);
  1904. dwRet = ImportRasEntry(szFileName, &lpConn->RasEntry);
  1905. if (ERROR_SUCCESS == dwRet)
  1906. {
  1907. dwRet = ImportCustomDialer(&lpConn->RasEntry, szFileName);
  1908. }
  1909. if (ERROR_SUCCESS == dwRet)
  1910. {
  1911. // Import the script file
  1912. //
  1913. dwRet = ImportScriptFile(szFileName,
  1914. lpConn->RasEntry.szScript,
  1915. sizeof(lpConn->RasEntry.szScript)/sizeof(TCHAR));
  1916. }
  1917. // Use an ISPImport object to Config The ras device
  1918. CISPImport ISPImport;
  1919. ISPImport.set_hWndMain(GetActiveWindow());
  1920. dwRet = ISPImport.ConfigRasEntryDevice(&lpConn->RasEntry);
  1921. switch( dwRet )
  1922. {
  1923. case ERROR_SUCCESS:
  1924. break;
  1925. case ERROR_CANCELLED:
  1926. if(!m_bSilentMode)
  1927. InfoMsg1(NULL, IDS_SIGNUPCANCELLED, NULL);
  1928. // Fall through
  1929. default:
  1930. goto ImportConnectionExit;
  1931. }
  1932. ImportConnectionExit:
  1933. return dwRet;
  1934. }
  1935. // Prototype for acct manager entry point we want
  1936. typedef HRESULT (WINAPI *PFNCREATEACCOUNTSFROMFILEEX)(LPTSTR szFile, CONNECTINFO *pCI, DWORD dwFlags);
  1937. // Regkeys for Acct manager
  1938. #define ACCTMGR_PATHKEY TEXT("SOFTWARE\\Microsoft\\Internet Account Manager")
  1939. #define ACCTMGR_DLLPATH TEXT("DllPath")
  1940. // ############################################################################
  1941. //
  1942. // Name: ImportMailAndNewsInfo
  1943. //
  1944. // Description: Import information from INS file and set the associated
  1945. // registry keys for Internet Mail and News (Athena)
  1946. //
  1947. // Input: lpszFile - Fully qualified filename of INS file
  1948. //
  1949. // Return: Error value
  1950. //
  1951. // History: 6/27/96 Created
  1952. //
  1953. // ############################################################################
  1954. DWORD CINSHandler::ImportMailAndNewsInfo(LPCTSTR lpszFile, BOOL fConnectPhone)
  1955. {
  1956. DWORD dwRet = ERROR_SUCCESS;
  1957. TCHAR szAcctMgrPath[MAX_PATH + 1] = TEXT("");
  1958. TCHAR szExpandedPath[MAX_PATH + 1] = TEXT("");
  1959. DWORD dwAcctMgrPathSize = 0;
  1960. HRESULT hr = S_OK;
  1961. HKEY hKey = NULL;
  1962. HINSTANCE hInst = NULL;
  1963. CONNECTINFO connectInfo;
  1964. TCHAR szConnectoidName[RAS_MaxEntryName] = TEXT("nogood\0");
  1965. PFNCREATEACCOUNTSFROMFILEEX fp = NULL;
  1966. // get path to the AcctMgr dll
  1967. dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ACCTMGR_PATHKEY,0, KEY_READ, &hKey);
  1968. if ( (dwRet != ERROR_SUCCESS) || (NULL == hKey) )
  1969. {
  1970. TraceMsg(TF_INSHANDLER, TEXT("ImportMailAndNewsInfo couldn't open reg key %s\n"), ACCTMGR_PATHKEY);
  1971. return( dwRet );
  1972. }
  1973. dwAcctMgrPathSize = sizeof (szAcctMgrPath);
  1974. dwRet = RegQueryValueEx(hKey, ACCTMGR_DLLPATH, NULL, NULL, (LPBYTE) szAcctMgrPath, &dwAcctMgrPathSize);
  1975. RegCloseKey( hKey );
  1976. if ( dwRet != ERROR_SUCCESS )
  1977. {
  1978. TraceMsg(TF_INSHANDLER, TEXT("ImportMailAndNewsInfo: RegQuery failed with error %d\n"), dwRet);
  1979. return( dwRet );
  1980. }
  1981. // 6/18/97 jmazner Olympus #6819
  1982. TraceMsg(TF_INSHANDLER, TEXT("ImportMailAndNewsInfo: read in DllPath of %s\n"), szAcctMgrPath);
  1983. ExpandEnvironmentStrings( szAcctMgrPath, szExpandedPath, ARRAYSIZE(szExpandedPath));
  1984. NULL_TERM_TCHARS(szExpandedPath);
  1985. //
  1986. // 6/4/97 jmazner
  1987. // if we created a connectoid, then get its name and use that as the
  1988. // connection type. Otherwise, assume we're supposed to connect via LAN
  1989. //
  1990. connectInfo.cbSize = sizeof(CONNECTINFO);
  1991. connectInfo.type = CONNECT_LAN;
  1992. if( fConnectPhone && m_lpfnInetGetAutodial )
  1993. {
  1994. BOOL fEnabled = FALSE;
  1995. dwRet = m_lpfnInetGetAutodial(&fEnabled,szConnectoidName,RAS_MaxEntryName);
  1996. if( ERROR_SUCCESS==dwRet && szConnectoidName[0] )
  1997. {
  1998. connectInfo.type = CONNECT_RAS;
  1999. #ifdef UNICODE
  2000. wcstombs(connectInfo.szConnectoid, szConnectoidName, MAX_PATH);
  2001. #else
  2002. lstrcpyn( connectInfo.szConnectoid, szConnectoidName, sizeof(connectInfo.szConnectoid) );
  2003. #endif
  2004. TraceMsg(TF_INSHANDLER, TEXT("ImportMailAndNewsInfo: setting connection type to RAS with %s\n"), szConnectoidName);
  2005. }
  2006. }
  2007. if( CONNECT_LAN == connectInfo.type )
  2008. {
  2009. TraceMsg(TF_INSHANDLER, TEXT("ImportMailAndNewsInfo: setting connection type to LAN\n"));
  2010. #ifdef UNICODE
  2011. wcstombs(connectInfo.szConnectoid, TEXT("I said CONNECT_LAN!"), MAX_PATH);
  2012. #else
  2013. lstrcpy( connectInfo.szConnectoid, TEXT("I said CONNECT_LAN!") );
  2014. #endif
  2015. }
  2016. hInst = LoadLibrary(szExpandedPath);
  2017. if (hInst)
  2018. {
  2019. fp = (PFNCREATEACCOUNTSFROMFILEEX) GetProcAddress(hInst,"CreateAccountsFromFileEx");
  2020. if (fp)
  2021. hr = fp( (TCHAR *)lpszFile, &connectInfo, NULL );
  2022. }
  2023. else
  2024. {
  2025. TraceMsg(TF_INSHANDLER, TEXT("ImportMailAndNewsInfo unable to LoadLibrary on %s\n"), szAcctMgrPath);
  2026. }
  2027. //
  2028. // Clean up and release resourecs
  2029. //
  2030. if( hInst)
  2031. {
  2032. FreeLibrary(hInst);
  2033. hInst = NULL;
  2034. }
  2035. if( fp )
  2036. {
  2037. fp = NULL;
  2038. }
  2039. return dwRet;
  2040. }
  2041. // ############################################################################
  2042. //
  2043. // Name: WriteMailAndNewsKey
  2044. //
  2045. // Description: Read a string value from the given INS file and write it
  2046. // to the registry
  2047. //
  2048. // Input: hKey - Registry key where the data will be written
  2049. // lpszSection - Section name inside of INS file where data is read
  2050. // from
  2051. // lpszValue - Name of value to read from INS file
  2052. // lpszBuff - buffer where data will be read into
  2053. // dwBuffLen - size of lpszBuff
  2054. // lpszSubKey - Value name where information will be written to
  2055. // dwType - data type (Should always be REG_SZ)
  2056. // lpszFileName - Fully qualified filename to INS file
  2057. //
  2058. // Return: Error value
  2059. //
  2060. // Histroy: 6/27/96 Created
  2061. //
  2062. // ############################################################################
  2063. HRESULT CINSHandler::WriteMailAndNewsKey(HKEY hKey, LPCTSTR lpszSection, LPCTSTR lpszValue,
  2064. LPTSTR lpszBuff, DWORD dwBuffLen,LPCTSTR lpszSubKey,
  2065. DWORD dwType, LPCTSTR lpszFile)
  2066. {
  2067. ZeroMemory(lpszBuff,dwBuffLen);
  2068. GetPrivateProfileString(lpszSection,lpszValue,TEXT(""),lpszBuff,dwBuffLen,lpszFile);
  2069. if (lstrlen(lpszBuff))
  2070. {
  2071. return RegSetValueEx(hKey,lpszSubKey,0,dwType,(CONST BYTE*)lpszBuff,
  2072. sizeof(TCHAR)*(lstrlen(lpszBuff)+1));
  2073. }
  2074. else
  2075. {
  2076. TraceMsg(TF_INSHANDLER, TEXT("ISIGNUP: WriteMailAndNewsKey, missing value in INS file\n"));
  2077. return ERROR_NO_MORE_ITEMS;
  2078. }
  2079. }
  2080. // ############################################################################
  2081. //
  2082. // Name: PreparePassword
  2083. //
  2084. // Description: Encode given password and return value in place. The
  2085. // encoding is done right to left in order to avoid having
  2086. // to allocate a copy of the data. The encoding uses base64
  2087. // standard as specified in RFC 1341 5.2
  2088. //
  2089. // Input: szBuff - Null terminated data to be encoded
  2090. // dwBuffLen - Full length of buffer, this should exceed the length of
  2091. // the input data by at least 1/3
  2092. //
  2093. // Return: Error value
  2094. //
  2095. // Histroy: 6/27/96 Created
  2096. //
  2097. // ############################################################################
  2098. HRESULT CINSHandler::PreparePassword(LPTSTR szBuff, DWORD dwBuffLen)
  2099. {
  2100. DWORD dwX;
  2101. LPTSTR szOut = NULL;
  2102. LPTSTR szNext = NULL;
  2103. HRESULT hr = ERROR_SUCCESS;
  2104. BYTE bTemp = 0;
  2105. DWORD dwLen = 0;
  2106. dwLen = lstrlen(szBuff);
  2107. if (!dwLen)
  2108. {
  2109. hr = ERROR_INVALID_PARAMETER;
  2110. goto PreparePasswordExit;
  2111. }
  2112. // Calculate the size of the buffer that will be needed to hold
  2113. // encoded data
  2114. //
  2115. szNext = &szBuff[dwLen-1];
  2116. dwLen = (((dwLen % 3 ? (3-(dwLen%3)):0) + dwLen) * 4 / 3);
  2117. if (dwBuffLen < dwLen+1)
  2118. {
  2119. hr = ERROR_INVALID_PARAMETER;
  2120. goto PreparePasswordExit;
  2121. }
  2122. szOut = &szBuff[dwLen];
  2123. *szOut-- = '\0';
  2124. // Add padding = characters
  2125. //
  2126. switch (lstrlen(szBuff) % 3)
  2127. {
  2128. case 0:
  2129. // no padding
  2130. break;
  2131. case 1:
  2132. *szOut-- = 64;
  2133. *szOut-- = 64;
  2134. *szOut-- = (*szNext & 0x3) << 4;
  2135. *szOut-- = (*szNext-- & 0xFC) >> 2;
  2136. break;
  2137. case 2:
  2138. *szOut-- = 64;
  2139. *szOut-- = (*szNext & 0xF) << 2;
  2140. *szOut = ((*szNext-- & 0xF0) >> 4);
  2141. *szOut-- |= ((*szNext & 0x3) << 4);
  2142. *szOut-- = (*szNext-- & 0xFC) >> 2;
  2143. }
  2144. // Encrypt data into indicies
  2145. //
  2146. while (szOut > szNext && szNext >= szBuff)
  2147. {
  2148. *szOut-- = *szNext & 0x3F;
  2149. *szOut = ((*szNext-- & 0xC0) >> 6);
  2150. *szOut-- |= ((*szNext & 0xF) << 2);
  2151. *szOut = ((*szNext-- & 0xF0) >> 4);
  2152. *szOut-- |= ((*szNext & 0x3) << 4);
  2153. *szOut-- = (*szNext-- & 0xFC) >> 2;
  2154. }
  2155. // Translate indicies into printable characters
  2156. //
  2157. szNext = szBuff;
  2158. // BUG OSR#10435--if there is a 0 in the generated string of base-64
  2159. // encoded digits (this can happen if the password is "Willypassword"
  2160. // for example), then instead of encoding the 0 to 'A', we just quit
  2161. // at this point, produces an invalid base-64 string.
  2162. for(dwX=0; dwX < dwLen; dwX++)
  2163. *szNext = arBase64[*szNext++];
  2164. PreparePasswordExit:
  2165. return hr;
  2166. }
  2167. // ############################################################################
  2168. //
  2169. // Name: FIsAthenaPresent
  2170. //
  2171. // Description: Determine if Microsoft Internet Mail And News client (Athena)
  2172. // is installed
  2173. //
  2174. // Input: none
  2175. //
  2176. // Return: TRUE - Athena is installed
  2177. // FALSE - Athena is NOT installed
  2178. //
  2179. // History: 7/1/96 Created
  2180. //
  2181. // ############################################################################
  2182. BOOL CINSHandler::FIsAthenaPresent()
  2183. {
  2184. TCHAR szBuff[MAX_PATH + 1];
  2185. HRESULT hr = ERROR_SUCCESS;
  2186. HINSTANCE hInst = NULL;
  2187. DWORD dwLen = 0;
  2188. DWORD dwType = REG_SZ;
  2189. // Get path to Athena client
  2190. //
  2191. dwLen = sizeof(TCHAR)*MAX_PATH;
  2192. hr = RegQueryValueEx(HKEY_CLASSES_ROOT,
  2193. MAIL_NEWS_INPROC_SERVER32,
  2194. NULL,
  2195. &dwType,
  2196. (LPBYTE) szBuff,
  2197. &dwLen);
  2198. if (hr == ERROR_SUCCESS)
  2199. {
  2200. // Attempt to load client
  2201. //
  2202. hInst = LoadLibrary(szBuff);
  2203. if (!hInst)
  2204. {
  2205. TraceMsg(TF_INSHANDLER, TEXT("ISIGNUP: Internet Mail and News server didn't load.\n"));
  2206. hr = ERROR_FILE_NOT_FOUND;
  2207. }
  2208. else
  2209. {
  2210. FreeLibrary(hInst);
  2211. }
  2212. hInst = NULL;
  2213. }
  2214. return (hr == ERROR_SUCCESS);
  2215. }
  2216. // ############################################################################
  2217. //
  2218. // Name: FTurnOffBrowserDefaultChecking
  2219. //
  2220. // Description: Turn Off IE checking to see if it is the default browser
  2221. //
  2222. // Input: none
  2223. //
  2224. // Output: TRUE - success
  2225. // FALSE - failed
  2226. //
  2227. // History: 7/2/96 Created
  2228. //
  2229. // ############################################################################
  2230. BOOL CINSHandler::FTurnOffBrowserDefaultChecking()
  2231. {
  2232. HKEY hKey = NULL;
  2233. DWORD dwType = 0;
  2234. DWORD dwSize = 0;
  2235. BOOL bRC = TRUE;
  2236. //
  2237. // Open IE settings registry key
  2238. //
  2239. if (RegOpenKey(HKEY_CURRENT_USER,cszDEFAULT_BROWSER_KEY,&hKey))
  2240. {
  2241. bRC = FALSE;
  2242. goto FTurnOffBrowserDefaultCheckingExit;
  2243. }
  2244. //
  2245. // Read current settings for check associations
  2246. //
  2247. dwType = 0;
  2248. dwSize = sizeof(m_szCheckAssociations);
  2249. ZeroMemory(m_szCheckAssociations,dwSize);
  2250. RegQueryValueEx(hKey,
  2251. cszDEFAULT_BROWSER_VALUE,
  2252. 0,
  2253. &dwType,
  2254. (LPBYTE)m_szCheckAssociations,
  2255. &dwSize);
  2256. // ignore return value, even if the calls fails we are going to try
  2257. // to change the setting to "NO"
  2258. //
  2259. // Set value to "no" to turn off checking
  2260. //
  2261. if (RegSetValueEx(hKey,
  2262. cszDEFAULT_BROWSER_VALUE,
  2263. 0,
  2264. REG_SZ,
  2265. (LPBYTE)cszNo,
  2266. sizeof(TCHAR)*(lstrlen(cszNo)+1)))
  2267. {
  2268. bRC = FALSE;
  2269. goto FTurnOffBrowserDefaultCheckingExit;
  2270. }
  2271. //
  2272. // Clean up and return
  2273. //
  2274. FTurnOffBrowserDefaultCheckingExit:
  2275. if (hKey)
  2276. RegCloseKey(hKey);
  2277. if (bRC)
  2278. m_fResforeDefCheck = TRUE;
  2279. hKey = NULL;
  2280. return bRC;
  2281. }
  2282. // ############################################################################
  2283. //
  2284. // Name: FRestoreBrowserDefaultChecking
  2285. //
  2286. // Description: Restore IE checking to see if it is the default browser
  2287. //
  2288. // Input: none
  2289. //
  2290. // Output: TRUE - success
  2291. // FALSE - failed
  2292. //
  2293. // History: 7/2/96 Created
  2294. //
  2295. // ############################################################################
  2296. BOOL CINSHandler::FRestoreBrowserDefaultChecking()
  2297. {
  2298. HKEY hKey = NULL;
  2299. BOOL bRC = TRUE;
  2300. //
  2301. // Open IE settings registry key
  2302. //
  2303. if (RegOpenKey(HKEY_CURRENT_USER,cszDEFAULT_BROWSER_KEY,&hKey))
  2304. {
  2305. bRC = FALSE;
  2306. goto FRestoreBrowserDefaultCheckingExit;
  2307. }
  2308. //
  2309. // Set value to original value
  2310. //
  2311. if (RegSetValueEx(hKey,
  2312. cszDEFAULT_BROWSER_VALUE,
  2313. 0,
  2314. REG_SZ,
  2315. (LPBYTE)m_szCheckAssociations,
  2316. sizeof(TCHAR)*(lstrlen(m_szCheckAssociations)+1)))
  2317. {
  2318. bRC = FALSE;
  2319. goto FRestoreBrowserDefaultCheckingExit;
  2320. }
  2321. FRestoreBrowserDefaultCheckingExit:
  2322. if (hKey)
  2323. RegCloseKey(hKey);
  2324. hKey = NULL;
  2325. return bRC;
  2326. }
  2327. // This is the main entry point for processing an INS file.
  2328. // DJM: BUGBUG: TODO: Need to pass in branding flags
  2329. STDMETHODIMP CINSHandler::ProcessINS(BSTR bstrINSFilePath, BOOL * pbRetVal)
  2330. {
  2331. USES_CONVERSION;
  2332. BOOL fConnectoidCreated = FALSE;
  2333. BOOL fClientSetup = FALSE;
  2334. BOOL bKeepConnection = FALSE;
  2335. BOOL fErrMsgShown = FALSE;
  2336. HRESULT hr = E_FAIL;
  2337. LPTSTR lpszFile = NULL;
  2338. LPRASENTRY lpRasEntry = NULL;
  2339. TCHAR szTemp[3] = TEXT("\0");
  2340. TCHAR szConnectoidName[RAS_MaxEntryName*2] = TEXT("");
  2341. *pbRetVal = FALSE;
  2342. // The Connection has not been killed yet
  2343. m_fConnectionKilled = FALSE;
  2344. m_fNeedsRestart = FALSE;
  2345. Assert(bstrINSFilePath);
  2346. lpszFile = OLE2A(bstrINSFilePath);
  2347. do
  2348. {
  2349. // Make sure we can load the necessary extern support functions
  2350. if (!LoadExternalFunctions())
  2351. break;
  2352. // Convert EOL chars in the passed file.
  2353. if (FAILED(MassageFile(lpszFile)))
  2354. {
  2355. if(!m_bSilentMode)
  2356. ErrorMsg1(GetActiveWindow(), IDS_CANNOTPROCESSINS, NULL);
  2357. break;
  2358. }
  2359. if(GetPrivateProfileString(cszURLSection,
  2360. cszStartURL,
  2361. szNull,
  2362. m_szStartURL,
  2363. MAX_PATH + 1,
  2364. lpszFile) == 0)
  2365. {
  2366. m_szStartURL[0] = '\0';
  2367. }
  2368. if (GetPrivateProfileString(cszEntrySection,
  2369. cszCancel,
  2370. szNull,
  2371. szTemp,
  2372. 3,
  2373. lpszFile) != 0)
  2374. {
  2375. // We do not want to process a CANCEL.INS file
  2376. // here.
  2377. break;
  2378. }
  2379. // See if this INS has a client setup section
  2380. if (GetPrivateProfileSection(cszClientSetupSection,
  2381. szTemp,
  2382. 3,
  2383. lpszFile) != 0)
  2384. fClientSetup = TRUE;
  2385. // Process the trial reminder section, if it exists. this needs to be
  2386. // done BEFORE we allow the connection to be closed
  2387. if (ConfigureTrialReminder(lpszFile))
  2388. {
  2389. // We configured a trial, so we need to launch the remind app now
  2390. SHELLEXECUTEINFO sei;
  2391. sei.cbSize = sizeof(sei);
  2392. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  2393. sei.hwnd = NULL;
  2394. sei.lpVerb = cszOpen;
  2395. sei.lpFile = cszReminderApp;
  2396. sei.lpParameters = cszReminderParams;
  2397. sei.lpDirectory = NULL;
  2398. sei.nShow = SW_SHOWNORMAL;
  2399. sei.hInstApp = NULL;
  2400. // Optional members
  2401. sei.hProcess = NULL;
  2402. ShellExecuteEx(&sei);
  2403. }
  2404. // Check to see if we should keep the connection open. The custom section
  2405. // might want this for processing stuff
  2406. if (!fClientSetup && !KeepConnection(lpszFile))
  2407. {
  2408. Fire_KillConnection();
  2409. m_fConnectionKilled = TRUE;
  2410. }
  2411. // Import the Custom Info
  2412. ImportCustomInfo(lpszFile,
  2413. m_szRunExecutable,
  2414. MAX_PATH ,
  2415. m_szRunArgument,
  2416. MAX_PATH );
  2417. ImportCustomFile(lpszFile);
  2418. // configure the client.
  2419. hr = ConfigureClient(GetActiveWindow(),
  2420. lpszFile,
  2421. &m_fNeedsRestart,
  2422. &fConnectoidCreated,
  2423. FALSE,
  2424. szConnectoidName,
  2425. RAS_MaxEntryName);
  2426. if( ERROR_SUCCESS != hr )
  2427. {
  2428. if(!m_bSilentMode)
  2429. ErrorMsg1(GetActiveWindow(), IDS_INSTALLFAILED, NULL);
  2430. fErrMsgShown = TRUE;
  2431. }
  2432. // If we created a connectoid, tell the world that ICW
  2433. // has left the building...
  2434. if(!m_bSilentMode)
  2435. SetICWCompleted( (DWORD)1 );
  2436. // Call IEAK branding dll
  2437. ImportBrandingInfo(lpszFile, szConnectoidName);
  2438. //::MessageBox(NULL, TEXT("Step 4"), TEXT("TEST"), MB_OK);
  2439. // 2/19/97 jmazner Olympus 1106
  2440. // For SBS/SAM integration.
  2441. DWORD dwSBSRet = 0;//CallSBSConfig(GetActiveWindow(), lpszFile);
  2442. switch( dwSBSRet )
  2443. {
  2444. case ERROR_SUCCESS:
  2445. break;
  2446. case ERROR_MOD_NOT_FOUND:
  2447. case ERROR_DLL_NOT_FOUND:
  2448. TraceMsg(TF_INSHANDLER, TEXT("ISIGN32: SBSCFG DLL not found, I guess SAM ain't installed.\n"));
  2449. break;
  2450. default:
  2451. if(!m_bSilentMode)
  2452. ErrorMsg1(GetActiveWindow(), IDS_SBSCFGERROR, NULL);
  2453. }
  2454. //
  2455. // If the INS file contains the ClientSetup section, build the commandline
  2456. // arguments for ICWCONN2.exe.
  2457. //
  2458. if (fClientSetup)
  2459. {
  2460. // Check to see if a REBOOT is needed and tell the next application to
  2461. // handle it.
  2462. if (m_fNeedsRestart)
  2463. {
  2464. wsprintf(m_szRunArgument,TEXT(" /INS:\"%s\" /REBOOT"),lpszFile);
  2465. m_fNeedsRestart = FALSE;
  2466. }
  2467. else
  2468. {
  2469. wsprintf(m_szRunArgument,TEXT(" /INS:\"%s\""),lpszFile);
  2470. }
  2471. }
  2472. // humongous hack for ISBU
  2473. if (ERROR_SUCCESS != hr && fConnectoidCreated)
  2474. {
  2475. if(!m_bSilentMode)
  2476. InfoMsg1(GetActiveWindow(), IDS_MAILFAILED, NULL);
  2477. hr = ERROR_SUCCESS;
  2478. }
  2479. //
  2480. // Import settings for mail and new read from INS file (ChrisK, 7/1/96)
  2481. //
  2482. if (ERROR_SUCCESS == hr)
  2483. {
  2484. ImportMailAndNewsInfo(lpszFile, fConnectoidCreated);
  2485. // If we did not create a connectiod, then restore
  2486. // the autodial one
  2487. if (!fConnectoidCreated)
  2488. {
  2489. RestoreAutoDial();
  2490. }
  2491. // Delete the INS file now
  2492. if (m_szRunExecutable[0] == '\0')
  2493. {
  2494. DeleteFile(lpszFile);
  2495. }
  2496. }
  2497. else
  2498. {
  2499. RestoreAutoDial();
  2500. if( !fErrMsgShown )
  2501. if(!m_bSilentMode)
  2502. ErrorMsg1(GetActiveWindow(), IDS_BADSETTINGS, NULL);
  2503. }
  2504. if (m_szRunExecutable[0] != '\0')
  2505. {
  2506. // Fire an event to the container telling it that we are
  2507. // about to run a custom executable
  2508. Fire_RunningCustomExecutable();
  2509. if FAILED(RunExecutable())
  2510. {
  2511. if(!m_bSilentMode)
  2512. ErrorMsg1(NULL, IDS_EXECFAILED, m_szRunExecutable);
  2513. }
  2514. // If the Connection has not been killed yet
  2515. // then tell the browser to do it now
  2516. if (!m_fConnectionKilled)
  2517. {
  2518. Fire_KillConnection();
  2519. m_fConnectionKilled = TRUE;
  2520. }
  2521. }
  2522. // If we get to here, we are successful.
  2523. if(fConnectoidCreated && SUCCEEDED(hr))
  2524. *pbRetVal = TRUE;
  2525. break;
  2526. } while(1);
  2527. return S_OK;
  2528. }
  2529. // If this is true, then the user will need to reboot, so
  2530. // the finish page should indicate this.
  2531. STDMETHODIMP CINSHandler::get_NeedRestart(BOOL *pVal)
  2532. {
  2533. if (pVal == NULL)
  2534. return E_POINTER;
  2535. *pVal = m_fNeedsRestart;
  2536. return S_OK;
  2537. }
  2538. STDMETHODIMP CINSHandler::put_BrandingFlags(long lFlags)
  2539. {
  2540. m_dwBrandFlags = lFlags;
  2541. return S_OK;
  2542. }
  2543. STDMETHODIMP CINSHandler::put_SilentMode(BOOL bSilent)
  2544. {
  2545. m_bSilentMode = bSilent;
  2546. return S_OK;
  2547. }
  2548. // If this is true, get the URL from the INS file
  2549. STDMETHODIMP CINSHandler::get_DefaultURL(BSTR *pszURL)
  2550. {
  2551. if (pszURL == NULL)
  2552. return E_POINTER;
  2553. *pszURL = A2BSTR(m_szStartURL);;
  2554. return S_OK;
  2555. }