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.

999 lines
30 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: init.cpp
  4. //
  5. // Module: CMDIAL32.DLL
  6. //
  7. // Synopsis: The various initialization routines live here.
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: nickball Created 2/11/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include "ConnStat.h"
  16. #include "profile_str.h"
  17. #include "log_str.h"
  18. #include "dial_str.h"
  19. #include "userinfo_str.h"
  20. #include "pwd_str.h"
  21. const TCHAR* const c_pszCmEntryHideUserName = TEXT("HideUserName");
  22. const TCHAR* const c_pszCmEntryHidePassword = TEXT("HidePassword");
  23. const TCHAR* const c_pszCmEntryDisableBalloonTips = TEXT("HideBalloonTips");
  24. //+----------------------------------------------------------------------------
  25. //
  26. // Function: RegisterBitmapClass
  27. //
  28. // Synopsis: Helper function to encapsulate registration of our bitmap class
  29. //
  30. // Arguments: HINSTANCE hInst - HINSTANCE to associate registration with
  31. //
  32. // Returns: DWORD - error code
  33. //
  34. // History: nickball Created Header 2/9/98
  35. //
  36. //+----------------------------------------------------------------------------
  37. DWORD RegisterBitmapClass(HINSTANCE hInst)
  38. {
  39. //
  40. // Register Bitmap class
  41. //
  42. WNDCLASSEX wcClass;
  43. ZeroMemory(&wcClass,sizeof(WNDCLASSEX));
  44. wcClass.cbSize = sizeof(WNDCLASSEX);
  45. wcClass.lpfnWndProc = BmpWndProc;
  46. wcClass.cbWndExtra = sizeof(HBITMAP) + sizeof(LPBITMAPINFO);
  47. wcClass.hInstance = hInst;
  48. wcClass.lpszClassName = ICONNMGR_BMP_CLASS;
  49. if (!RegisterClassExU(&wcClass))
  50. {
  51. DWORD dwError = GetLastError();
  52. CMTRACE1(TEXT("RegisterBitmapClass() RegisterClassEx() failed, GLE=%u."), dwError);
  53. //
  54. // Only fail if the class does not already exist
  55. //
  56. if (ERROR_CLASS_ALREADY_EXISTS != dwError)
  57. {
  58. return dwError;
  59. }
  60. }
  61. return ERROR_SUCCESS;
  62. }
  63. //+----------------------------------------------------------------------------
  64. //
  65. // Function: ReleaseIniObjects
  66. //
  67. // Synopsis: Encapsulates freeing of ini objects
  68. //
  69. // Arguments: ArgsStruct *pArgs - Ptr to global args struct
  70. //
  71. // Returns: Nothing
  72. //
  73. // History: nickball Created 2/12/98
  74. //
  75. //+----------------------------------------------------------------------------
  76. void ReleaseIniObjects(ArgsStruct *pArgs)
  77. {
  78. if (pArgs->piniProfile)
  79. {
  80. delete pArgs->piniProfile;
  81. pArgs->piniProfile = NULL;
  82. }
  83. if (pArgs->piniService)
  84. {
  85. delete pArgs->piniService;
  86. pArgs->piniService = NULL;
  87. }
  88. if (pArgs->piniBoth)
  89. {
  90. delete pArgs->piniBoth;
  91. pArgs->piniBoth = NULL;
  92. }
  93. if (pArgs->piniBothNonFav)
  94. {
  95. delete pArgs->piniBothNonFav;
  96. pArgs->piniBothNonFav = NULL;
  97. }
  98. }
  99. //+----------------------------------------------------------------------------
  100. //
  101. // Function: CreateIniObjects
  102. //
  103. // Synopsis: Encapsulates creation of ini objects
  104. //
  105. // Arguments: ArgsStruct *pArgs - Ptr to global args struct
  106. //
  107. // Returns: LRESULT - Failure code
  108. //
  109. // History: nickball Created 2/12/98
  110. //
  111. //+----------------------------------------------------------------------------
  112. LRESULT CreateIniObjects(ArgsStruct *pArgs)
  113. {
  114. MYDBGASSERT(pArgs);
  115. if (NULL == pArgs)
  116. {
  117. return ERROR_INVALID_PARAMETER;
  118. }
  119. LRESULT lRes = ERROR_SUCCESS;
  120. //
  121. // Try to create each ini object
  122. //
  123. pArgs->piniProfile = new CIni; // &iniProfile;
  124. if (NULL == pArgs->piniProfile)
  125. {
  126. lRes = ERROR_NOT_ENOUGH_MEMORY;
  127. }
  128. pArgs->piniService = new CIni; // &iniService;
  129. if (NULL == pArgs->piniProfile)
  130. {
  131. lRes = ERROR_NOT_ENOUGH_MEMORY;
  132. }
  133. pArgs->piniBoth = new CIni; // &iniBoth;
  134. if (NULL == pArgs->piniProfile)
  135. {
  136. lRes = ERROR_NOT_ENOUGH_MEMORY;
  137. }
  138. pArgs->piniBothNonFav = new CIni; //&iniBothNonFav
  139. if (NULL == pArgs->piniBothNonFav)
  140. {
  141. lRes = ERROR_NOT_ENOUGH_MEMORY;
  142. }
  143. //
  144. // If something failed, release CIni classes
  145. //
  146. if (ERROR_SUCCESS != lRes)
  147. {
  148. if (pArgs->piniProfile)
  149. {
  150. delete pArgs->piniProfile;
  151. }
  152. if (pArgs->piniService)
  153. {
  154. delete pArgs->piniService;
  155. }
  156. if (pArgs->piniBoth)
  157. {
  158. delete pArgs->piniBoth;
  159. }
  160. if (pArgs->piniBothNonFav)
  161. {
  162. delete pArgs->piniBothNonFav;
  163. }
  164. }
  165. return lRes;
  166. }
  167. //+----------------------------------------------------------------------------
  168. //
  169. // Function: InitProfile
  170. //
  171. // Synopsis: Initialize the profile based upon the entry name.
  172. //
  173. // Arguments: ArgsStruct *pArgs - Ptr to global Args struct
  174. // LPCTSTR pszEntry - Ptr to name of Ras entry
  175. //
  176. // Returns: HRESULT - Failure code.
  177. //
  178. // History: nickball Created 2/9/98
  179. //
  180. //+----------------------------------------------------------------------------
  181. HRESULT InitProfile(ArgsStruct *pArgs, LPCTSTR pszEntry)
  182. {
  183. MYDBGASSERT(pArgs);
  184. MYDBGASSERT(pszEntry);
  185. if (NULL == pArgs || NULL == pszEntry)
  186. {
  187. return E_POINTER;
  188. }
  189. if (0 == pszEntry[0])
  190. {
  191. return E_INVALIDARG;
  192. }
  193. HRESULT hrRes = S_OK;
  194. LPTSTR pszProfileName = (LPTSTR) CmMalloc(sizeof(TCHAR) * (MAX_PATH + 1));
  195. if (pszProfileName)
  196. {
  197. if (FALSE == ReadMapping(pszEntry, pszProfileName, MAX_PATH, pArgs->fAllUser, TRUE)) // TRUE == bExpandEnvStrings
  198. {
  199. //
  200. // No mappings key, report failure
  201. //
  202. LPTSTR pszTmp = CmFmtMsg(g_hInst,IDMSG_DAMAGED_PROFILE);
  203. MessageBoxEx(NULL, pszTmp, pszEntry, MB_OK|MB_ICONSTOP, LANG_USER_DEFAULT);
  204. CmFree(pszTmp);
  205. hrRes = E_FAIL;
  206. }
  207. else
  208. {
  209. MYDBGASSERT(!(*pArgs->piniProfile->GetFile())); // can't have a profile yet
  210. //
  211. // Migration code is called here because this is the first place where
  212. // we get the path to the cmp. The migration code moves the cmp entries
  213. // to the registry and then replaces the cmp file
  214. //
  215. /*
  216. //
  217. // This was commented out because it created some issues when trying to import old
  218. // profiles. It migrated some values into the wrong sections of the registry.
  219. //
  220. // MoveCmpEntriesToReg(pszEntry, pszProfileName, pArgs->fAllUser);
  221. //
  222. */
  223. InitProfileFromName(pArgs, pszProfileName);
  224. }
  225. }
  226. else
  227. {
  228. hrRes = E_OUTOFMEMORY;
  229. CMASSERTMSG(FALSE, TEXT("InitProfile -- Unable to allocate memory for the profile name."));
  230. }
  231. CmFree(pszProfileName);
  232. return hrRes;
  233. }
  234. //+---------------------------------------------------------------------------
  235. //
  236. // Function: InitProfileFromName
  237. //
  238. // Synopsis: Helper function to intialize the service
  239. // profile based upon a service name
  240. //
  241. // Arguments: ArgsStruct *pArgs - Pointer to global args struct
  242. // LPCTSTR pszArg - Full path to .CMP file
  243. //
  244. // Returns: Nothing - Use *pArgs->piniProfile->GetFile() to test success
  245. //
  246. // History: a-nichb - Created - 4/22/97
  247. //----------------------------------------------------------------------------
  248. void InitProfileFromName(ArgsStruct *pArgs,
  249. LPCTSTR pszArg)
  250. {
  251. MYDBGASSERT(pArgs);
  252. MYDBGASSERT(pszArg);
  253. if (NULL == pArgs || NULL == pszArg)
  254. {
  255. return;
  256. }
  257. //
  258. // Clear INI objects to make sure there are no misunderstandings about
  259. // there viability should we be forced to make an early return.
  260. //
  261. pArgs->piniProfile->Clear();
  262. pArgs->piniService->Clear();
  263. pArgs->piniBoth->Clear();
  264. pArgs->piniBothNonFav->Clear();
  265. //
  266. // Verify the existence of the file
  267. //
  268. if (FALSE == FileExists(pszArg))
  269. {
  270. return;
  271. }
  272. //
  273. // Initialize the profile INI object with the filename
  274. //
  275. pArgs->piniProfile->SetHInst(g_hInst);
  276. pArgs->piniProfile->SetFile(pszArg);
  277. //
  278. // Check the service name
  279. //
  280. LPTSTR pszService = pArgs->piniProfile->GPPS(c_pszCmSection, c_pszCmEntryCmsFile);
  281. if (*pszService)
  282. {
  283. //
  284. // We have a service file, build the full path to the file
  285. //
  286. LPTSTR pszFullServiceName = CmBuildFullPathFromRelative(pArgs->piniProfile->GetFile(), pszService);
  287. if (pszFullServiceName)
  288. {
  289. MYDBGASSERT(*pszFullServiceName); // should be something there
  290. pArgs->piniService->SetHInst(pArgs->piniProfile->GetHInst());
  291. pArgs->piniService->SetFile(pszFullServiceName);
  292. //
  293. // Get the service name, we use this throughout
  294. //
  295. LPTSTR pszTmp = GetServiceName(pArgs->piniService);
  296. MYDBGASSERT(pszTmp && *pszTmp);
  297. if (pszTmp)
  298. {
  299. lstrcpyU(pArgs->szServiceName, pszTmp);
  300. }
  301. CmFree(pszTmp);
  302. //
  303. // Both: The .CMP file takes precedence over the .CMS
  304. // file, so specify the .CMP file as the primary file
  305. //
  306. pArgs->piniBoth->SetHInst(pArgs->piniProfile->GetHInst());
  307. pArgs->piniBoth->SetFile(pArgs->piniService->GetFile());
  308. pArgs->piniBoth->SetPrimaryFile(pArgs->piniProfile->GetFile());
  309. pArgs->piniBothNonFav->SetHInst(pArgs->piniProfile->GetHInst());
  310. pArgs->piniBothNonFav->SetFile(pArgs->piniService->GetFile());
  311. pArgs->piniBothNonFav->SetPrimaryFile(pArgs->piniProfile->GetFile());
  312. //
  313. // Get whether balloon tips are enabled
  314. //
  315. pArgs->fHideBalloonTips = pArgs->piniBothNonFav->GPPB(c_pszCmSection, c_pszCmEntryDisableBalloonTips);
  316. //
  317. // Get the values of the current access point and a flag to say if
  318. // access points are enabled
  319. //
  320. PVOID pv = &pArgs->fAccessPointsEnabled;
  321. if ((ReadUserInfoFromReg(pArgs, UD_ID_ACCESSPOINTENABLED, (PVOID*)&pv)) && (pArgs->fAccessPointsEnabled))
  322. {
  323. LPTSTR pszCurrentAccessPoint = NULL;
  324. ReadUserInfoFromReg(pArgs, UD_ID_CURRENTACCESSPOINT, (PVOID*)&pszCurrentAccessPoint);
  325. if (pszCurrentAccessPoint)
  326. {
  327. pArgs->pszCurrentAccessPoint = CmStrCpyAlloc(pszCurrentAccessPoint);
  328. CmFree(pszCurrentAccessPoint);
  329. }
  330. else
  331. {
  332. pArgs->fAccessPointsEnabled = FALSE;
  333. pArgs->pszCurrentAccessPoint = CmLoadString(g_hInst, IDS_DEFAULT_ACCESSPOINT);
  334. }
  335. }
  336. else
  337. {
  338. pArgs->pszCurrentAccessPoint = CmLoadString(g_hInst, IDS_DEFAULT_ACCESSPOINT);
  339. }
  340. //
  341. // piniProfile, piniBoth, and piniBothNonFav all access the cmp and reg, set the reg path by default
  342. // to the one with the current access point except the piniBothNonFav which uses the base favorites
  343. // registry path.
  344. //
  345. //
  346. // Okay, here is how this all works ...
  347. // CIni classes have a reg path, a primary reg path, a file path, and a primary file path.
  348. // The reg path and the file path are checked first (the registry is accessed and if empty, then the file is checked), and
  349. // then the primary reg path and the primary file path are checked (again the registry is checked first and if the
  350. // setting doesn't exist then it checks the file). This allows settings in the primary file/reg to override settings in the
  351. // file/reg. This allows us to have cmp settings override settings in the cms by accessing the cms settings first and
  352. // then overwriting the setting with the value from the cmp if it exists or keeping the cms setting if the cmp is empty.
  353. //
  354. // The four CIni objects break out like this:
  355. // piniProfile - reg = current favorite reg path
  356. // file = cmp file
  357. // primary reg = (nothing)
  358. // primary file = (nothing)
  359. // For direct access to the cmp settings.
  360. //
  361. // piniService - reg = none (cms settings not in the registry).
  362. // file = cms file
  363. // primary reg = (nothing)
  364. // primary file = (nothing)
  365. // For direct access to the cms settings.
  366. //
  367. // piniBoth - reg = none (cms settings not in the registry)
  368. // file = cms file
  369. // primary reg = current favorite reg path
  370. // primary file = cmp file
  371. // For access to any settings that can be overridden from the "cmp" and are favorites enabled (phone number
  372. // settings, which device to use, etc).
  373. //
  374. // piniBothNonFav - reg = non-favorite registry path (Software\Microsoft\Connection Manager\UserInfo\<LongService>)
  375. // file = cms file
  376. // primary reg = non-favorite registry path (Software\Microsoft\Connection Manager\UserInfo\<LongService>)
  377. // primary file = cmp file
  378. // For access to any settings that can be overridden from the "cmp" and are NOT favorites enabled
  379. // (tunnel settings, idle disconnect, logging enabled, etc.)
  380. // NOTE that the reg path and the primary reg path are the same. That is because on writing on the
  381. // regpath value is used and I only wanted one ini object to handle non favorites settings instead of two.
  382. //
  383. LPTSTR pszRegPath = FormRegPathFromAccessPoint(pArgs);
  384. pArgs->piniProfile->SetRegPath(pszRegPath);
  385. pArgs->piniBoth->SetPrimaryRegPath(pszRegPath);
  386. CmFree(pszRegPath);
  387. pszRegPath = BuildUserInfoSubKey(pArgs->szServiceName, pArgs->fAllUser);
  388. MYDBGASSERT(pszRegPath);
  389. pArgs->piniBothNonFav->SetPrimaryRegPath(pszRegPath); // For reads
  390. pArgs->piniBothNonFav->SetRegPath(pszRegPath); // For writes
  391. CmFree(pszRegPath);
  392. }
  393. CmFree(pszFullServiceName);
  394. }
  395. CmFree(pszService);
  396. }
  397. //+----------------------------------------------------------------------------
  398. //
  399. // Function: GetEntryFromCmp
  400. //
  401. // Synopsis: Helper function to read a value from the cmp
  402. //
  403. // Arguments: LPTSTR pszSectionName - The section to be accessed
  404. // LPTSTR pszCmpPath - The complete path to the cmp
  405. // LPTSTR pszEntryName - The entry to be accessed in the cmp
  406. //
  407. // Returns: PVOID - Pointer to the result of cmp access
  408. //
  409. // History: t-urama Created Header 07/11/00
  410. //
  411. //+----------------------------------------------------------------------------
  412. LPTSTR GetEntryFromCmp(const TCHAR *pszSectionName, LPTSTR pszEntryName, LPCTSTR pszCmpPath)
  413. {
  414. BOOL bExitLoop = TRUE;
  415. DWORD dwSize = (MAX_PATH + 1);
  416. LPTSTR pszEntryBuffer = NULL;
  417. DWORD dwRet;
  418. LPCTSTR c_pszDefault = TEXT("");
  419. do
  420. {
  421. pszEntryBuffer = (LPTSTR)CmMalloc(dwSize*sizeof(TCHAR));
  422. if (pszEntryBuffer)
  423. {
  424. dwRet = GetPrivateProfileStringU(pszSectionName, pszEntryName, c_pszDefault, pszEntryBuffer, dwSize, pszCmpPath);
  425. if (dwRet)
  426. {
  427. if (dwRet > dwSize)
  428. {
  429. dwSize = dwRet + 1;
  430. bExitLoop = FALSE; // we didn't get all of the string, try again
  431. free(pszEntryBuffer);
  432. }
  433. }
  434. else
  435. {
  436. CmFree(pszEntryBuffer);
  437. return NULL;
  438. }
  439. }
  440. else
  441. {
  442. CmFree(pszEntryBuffer);
  443. return NULL;
  444. }
  445. } while (!bExitLoop);
  446. return pszEntryBuffer;
  447. }
  448. //+----------------------------------------------------------------------------
  449. //
  450. // Function: ReplaceCmpFile
  451. //
  452. // Synopsis: Helper function to delete the existing cmp and replace it with
  453. // one which has entries for Version and CMSFile
  454. //
  455. // Arguments: LPTSTR pszCmpPath - The complete path to the cmp
  456. //
  457. // Returns: None
  458. //
  459. // History: t-urama Created Header 07/11/00
  460. //
  461. //+----------------------------------------------------------------------------
  462. void ReplaceCmpFile(LPCTSTR pszCmpPath)
  463. {
  464. LPTSTR pszCMSFileEntry = (LPTSTR) GetEntryFromCmp(c_pszCmSection, (LPTSTR) c_pszCmEntryCmsFile, pszCmpPath);
  465. if (NULL != pszCMSFileEntry && *pszCMSFileEntry)
  466. {
  467. //
  468. // Clear the CM section
  469. //
  470. WritePrivateProfileStringU(c_pszCmSection, NULL, NULL, pszCmpPath);
  471. //
  472. // Now write back the cms file entry
  473. //
  474. WritePrivateProfileStringU(c_pszCmSection, c_pszCmEntryCmsFile, pszCMSFileEntry, pszCmpPath);
  475. }
  476. CmFree(pszCMSFileEntry);
  477. }
  478. //+----------------------------------------------------------------------------
  479. //
  480. // Function: FormRegPathFromAccessPoint
  481. //
  482. // Synopsis: Function to create a path to the current access point in the registry
  483. //
  484. // Arguments: ArgsStruct *pArgs - ptr to global args structure
  485. //
  486. // Returns: LPTSTR - The path to the access point. It is the caller's responsibility to free this
  487. //
  488. // History: t-urama Created Header 07/11/00
  489. //
  490. //+----------------------------------------------------------------------------
  491. LPTSTR FormRegPathFromAccessPoint(ArgsStruct *pArgs)
  492. {
  493. LPTSTR pszRegPath = NULL;
  494. pszRegPath = BuildUserInfoSubKey(pArgs->szServiceName, pArgs->fAllUser);
  495. MYDBGASSERT(pszRegPath);
  496. if (NULL == pszRegPath)
  497. {
  498. return NULL;
  499. }
  500. CmStrCatAlloc(&pszRegPath, TEXT("\\"));
  501. CmStrCatAlloc(&pszRegPath, c_pszRegKeyAccessPoints);
  502. CmStrCatAlloc(&pszRegPath, TEXT("\\"));
  503. CmStrCatAlloc(&pszRegPath, pArgs->pszCurrentAccessPoint);
  504. return pszRegPath;
  505. }
  506. //+----------------------------------------------------------------------------
  507. //
  508. // Function: InitArgsForConnect
  509. //
  510. // Synopsis: Encapsulates initialization of pArgs members necessary to begin dial
  511. //
  512. // Arguments: ArgsStruct *pArgs - Ptr to global args struct
  513. // LPCTSTR pszRasPhoneBook - RAS phonebook containing entry
  514. // LPCMDIALINFO lpCmInfo - Ptr to dial info for this dial attempt
  515. // BOOL fAllUser - The All User attribute of the profile
  516. //
  517. // Returns: HRESULT - Failure code.
  518. //
  519. // History: nickball Created Header 02/09/98
  520. // nickball pszRasPhoneBook 08/14/98
  521. //
  522. //+----------------------------------------------------------------------------
  523. HRESULT InitArgsForConnect(ArgsStruct *pArgs,
  524. LPCTSTR pszRasPhoneBook,
  525. LPCMDIALINFO lpCmInfo,
  526. BOOL fAllUser)
  527. {
  528. MYDBGASSERT(pArgs);
  529. if (NULL == pArgs)
  530. {
  531. return E_POINTER;
  532. }
  533. //
  534. // Get the flags first
  535. //
  536. pArgs->dwFlags = lpCmInfo->dwCmFlags;
  537. //
  538. // Get the RAS phonebook for the entry, and set user mode accordngly
  539. //
  540. if (pszRasPhoneBook && *pszRasPhoneBook)
  541. {
  542. pArgs->pszRasPbk = CmStrCpyAlloc(pszRasPhoneBook);
  543. }
  544. pArgs->fAllUser = fAllUser;
  545. //
  546. // Initialize pArgs->tlsTapiLink.dwOldTapiLocation to -1
  547. //
  548. pArgs->tlsTapiLink.dwOldTapiLocation = -1;
  549. //
  550. // Create stats class
  551. //
  552. if (!OS_NT4)
  553. {
  554. pArgs->pConnStatistics = new CConnStatistics();
  555. if (NULL == pArgs->pConnStatistics)
  556. {
  557. return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  558. }
  559. }
  560. if (OS_W9X)
  561. {
  562. pArgs->uLanaMsgId = RegisterWindowMessageU(TEXT("ConnectionManagerLanaMsg"));
  563. CMTRACE1(TEXT("InitArgsForConnect() RegisterWindowMessage(\"ConnectionManagerLanaMsg\") uLanaMsgId is %d"), pArgs->uLanaMsgId);
  564. }
  565. if (!OS_NT5)
  566. {
  567. //
  568. // Register Window Messages
  569. //
  570. pArgs->uMsgId = RegisterWindowMessageU(TEXT(RASDIALEVENT));
  571. if (!pArgs->uMsgId)
  572. {
  573. CMTRACE1(TEXT("InitArgsForConnect() RegisterWindowMessage(\"InternetConnectionManager\") failed, GLE=%u."), GetLastError());
  574. pArgs->uMsgId = WM_RASDIALEVENT;
  575. }
  576. }
  577. pArgs->fChangedPassword = FALSE;
  578. pArgs->fWaitingForCallback = FALSE;
  579. //
  580. // Create new CIni classes, and set initial exit code
  581. //
  582. pArgs->dwExitCode = (DWORD)CreateIniObjects(pArgs);
  583. return HRESULT_FROM_WIN32(pArgs->dwExitCode);
  584. }
  585. //+----------------------------------------------------------------------------
  586. //
  587. // Function: InitCredentials
  588. //
  589. // Synopsis: Transfers credentials from either WinLogon or Reconnect
  590. //
  591. // Arguments: ArgsStruct *pArgs - Ptr to global args struct.
  592. // LPCMDIALINFO lpCmInfo - Ptr to CmInfo struct.
  593. // DWORD dwFlags - Flags from RasDialDlg, if any.
  594. // PVOID pvLogonBlob - Ptr to WinLogon blob, if any.
  595. //
  596. //
  597. // Returns: Nothing
  598. //
  599. // History: nickball Created 09/21/99
  600. //
  601. //+----------------------------------------------------------------------------
  602. HRESULT InitCredentials(ArgsStruct *pArgs,
  603. LPCMDIALINFO lpCmInfo,
  604. DWORD dwFlags,
  605. PVOID pvLogonBlob)
  606. {
  607. MYDBGASSERT(pArgs);
  608. MYDBGASSERT(pArgs->piniService);
  609. if (NULL == pArgs || NULL == pArgs->piniService)
  610. {
  611. return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  612. }
  613. //
  614. // Get credential display flags as they can dictate how we manage creds
  615. //
  616. pArgs->fHideUserName = pArgs->piniService->GPPB(c_pszCmSection, c_pszCmEntryHideUserName);
  617. pArgs->fHidePassword = pArgs->piniService->GPPB(c_pszCmSection, c_pszCmEntryHidePassword);
  618. //
  619. // If its a non-tunneling profile, the domain display default is false.
  620. //
  621. pArgs->fHideDomain = pArgs->piniService->GPPB(c_pszCmSection,
  622. c_pszCmEntryHideDomain,
  623. !IsTunnelEnabled(pArgs));
  624. //
  625. // Handle special credential scenarios such as reconnect or WinLogon
  626. // (note that pvLogonBlob can be NULL if the user did a ctrl-alt-del
  627. // and typed a password but then used an EAP profile to connect.)
  628. //
  629. if ((OS_NT5 && !OS_NT51 && pvLogonBlob) || (OS_NT51 && (dwFlags & RCD_Logon)))
  630. {
  631. CMTRACE(TEXT("InitCredentials - we have been called from Winlogon"));
  632. //
  633. // Set the type of logon. Assert if we aren't logged on as system
  634. //
  635. pArgs->dwWinLogonType = CM_LOGON_TYPE_WINLOGON;
  636. MYDBGASSERT(IsLogonAsSystem());
  637. //
  638. // First make sure that integration is not explicitly disabled
  639. //
  640. if (pArgs->piniService->GPPB(c_pszCmSection, c_pszCmEntryUseWinLogonCredentials, TRUE))
  641. {
  642. if (pvLogonBlob)
  643. {
  644. if (dwFlags & RCD_Eap)
  645. {
  646. pArgs->lpEapLogonInfo = (PEAPLOGONINFO) pvLogonBlob;
  647. }
  648. else
  649. {
  650. //
  651. // We have a RASNOUSER struct to play with.
  652. // FYI: If the dwFlags member is set with RASNOUSER_SmartCard
  653. // then the user initiated a logon with a SmartCard, but then
  654. // chose a connection that was not configured for EAP. RAS
  655. // handles that situation by setting the flag and passing an
  656. // empty RASNOUSER struct. The flag is currently unused by CM.
  657. //
  658. pArgs->lpRasNoUser = (LPRASNOUSER) pvLogonBlob;
  659. MYDBGASSERT(sizeof(RASNOUSER) == pArgs->lpRasNoUser->dwSize);
  660. CMTRACE1(TEXT("InitCredentials - pArgs->lpRasNoUser->dwFlags is 0x%x"), pArgs->lpRasNoUser->dwFlags);
  661. }
  662. }
  663. // else here is the ctrl-alt-del case with an EAP profile
  664. }
  665. else
  666. {
  667. CMTRACE1(TEXT("InitCredentials - pvLogonBlob ignored because %s=0"), c_pszCmEntryUseWinLogonCredentials);
  668. }
  669. }
  670. else
  671. {
  672. if (IsLogonAsSystem() && OS_NT51)
  673. {
  674. //
  675. // ICS case where a user isn't logged it
  676. //
  677. pArgs->dwWinLogonType = CM_LOGON_TYPE_ICS;
  678. }
  679. else
  680. {
  681. //
  682. // User is logged in
  683. //
  684. pArgs->dwWinLogonType = CM_LOGON_TYPE_USER;
  685. }
  686. }
  687. if (pArgs->dwFlags & FL_RECONNECT)
  688. {
  689. //
  690. // Update any password data that was passed to us. In the reconnect
  691. // case we handed the data to CMMON at connect time so it is
  692. // already encoded.
  693. //
  694. if (lpCmInfo->szPassword)
  695. {
  696. lstrcpyU(pArgs->szPassword, lpCmInfo->szPassword);
  697. }
  698. if (lpCmInfo->szInetPassword)
  699. {
  700. lstrcpyU(pArgs->szInetPassword, lpCmInfo->szInetPassword);
  701. }
  702. }
  703. else
  704. {
  705. if (pArgs->lpRasNoUser)
  706. {
  707. //
  708. // Filter credential integration.
  709. if (!pArgs->fHideUserName)
  710. {
  711. lstrcpyU(pArgs->szUserName, pArgs->lpRasNoUser->szUserName);
  712. }
  713. if (!pArgs->fHidePassword)
  714. {
  715. CmDecodePassword(pArgs->lpRasNoUser->szPassword); // password is already encoded from RasCustomDialDlg
  716. lstrcpyU(pArgs->szPassword, pArgs->lpRasNoUser->szPassword);
  717. CmEncodePassword(pArgs->lpRasNoUser->szPassword);
  718. CmEncodePassword(pArgs->szPassword);
  719. }
  720. if (!pArgs->fHideDomain)
  721. {
  722. lstrcpyU(pArgs->szDomain, pArgs->lpRasNoUser->szDomain);
  723. }
  724. CMTRACE1(TEXT("InitCredentials: pArgs->szUserName is %s"), pArgs->szUserName);
  725. CMTRACE1(TEXT("InitCredentials: pArgs->szDomain is %s"), pArgs->szDomain);
  726. }
  727. }
  728. CMTRACE1(TEXT("InitCredentials: pArgs->dwWinLogonType is %d"), pArgs->dwWinLogonType);
  729. //
  730. // This is to setup (global or user) credential support. Since
  731. // RAS dll isn't loaded, we don't get the credentials yet so
  732. // in LoadProperties we actually get to see which creds exist.
  733. //
  734. if (FALSE == InitializeCredentialSupport(pArgs))
  735. {
  736. return S_FALSE;
  737. }
  738. return S_OK;
  739. }
  740. //+----------------------------------------------------------------------------
  741. //
  742. // Function: InitArgsForDisconnect
  743. //
  744. // Synopsis: Encapsulates initialization of pArgs members necessary to hangup
  745. //
  746. // Arguments: ArgsStruct *pArgs - Ptr to global args struct
  747. // BOOL fAllUser - All User flag
  748. //
  749. // Returns: HRESULT - Failure code.
  750. //
  751. // History: nickball Created Header 02/11/98
  752. // nickball pszRasPhoneBook 08/14/98
  753. // nickball fAllUser 10/28/98
  754. //
  755. //+----------------------------------------------------------------------------
  756. HRESULT InitArgsForDisconnect(ArgsStruct *pArgs,
  757. BOOL fAllUser)
  758. {
  759. MYDBGASSERT(pArgs);
  760. if (NULL == pArgs)
  761. {
  762. return E_POINTER;
  763. }
  764. //
  765. // Set the All User attribute of the profile
  766. //
  767. pArgs->fAllUser = fAllUser;
  768. //
  769. // Create new CIni classes, and set initial exit code
  770. //
  771. pArgs->dwExitCode = (DWORD)CreateIniObjects(pArgs);
  772. return HRESULT_FROM_WIN32(pArgs->dwExitCode);
  773. }
  774. //+----------------------------------------------------------------------------
  775. //
  776. // Function: InitLogging
  777. //
  778. // Synopsis: Initialize the logging functionality for this profile.
  779. //
  780. // Arguments: ArgsStruct *pArgs - Ptr to global Args struct
  781. // LPCTSTR pszEntry - Ptr to name of Ras entry
  782. // BOOL fBanner - do we want a banner for this?
  783. //
  784. // Returns: HRESULT - Failure code.
  785. //
  786. // History: 20-Jul-2000 SumitC Created
  787. //
  788. //+----------------------------------------------------------------------------
  789. HRESULT InitLogging(ArgsStruct *pArgs, LPCTSTR pszEntry, BOOL fBanner)
  790. {
  791. MYDBGASSERT(pArgs);
  792. MYDBGASSERT(pszEntry);
  793. BOOL fEnabled = FALSE;
  794. DWORD dwMaxSize = 0;
  795. LPTSTR pszFileDir = NULL;
  796. LPTSTR pszRegPath = NULL;
  797. LPTSTR pszTempRegPath = NULL;
  798. //
  799. // Check the params
  800. //
  801. if (NULL == pArgs || NULL == pszEntry)
  802. {
  803. return E_POINTER;
  804. }
  805. if (0 == pszEntry[0])
  806. {
  807. return E_INVALIDARG;
  808. }
  809. HRESULT hr = S_OK;
  810. //
  811. // Initialize the logging object (the order is important)
  812. //
  813. hr = pArgs->Log.Init(g_hInst, pArgs->fAllUser, pArgs->szServiceName);
  814. if (S_OK != hr)
  815. {
  816. goto Cleanup;
  817. }
  818. //
  819. // Accessing EnableLogging, make sure to use piniBothNonFav as this setting is
  820. // not favorites enabled.
  821. //
  822. fEnabled = pArgs->piniBothNonFav->GPPB(c_pszCmSection, c_pszCmEntryEnableLogging, c_fEnableLogging);
  823. //
  824. // Now get the Max log file size and the log file directory.
  825. //
  826. dwMaxSize = pArgs->piniService->GPPI(c_pszCmSectionLogging, c_pszCmEntryMaxLogFileSize, c_dwMaxFileSize);
  827. pszFileDir = pArgs->piniService->GPPS(c_pszCmSectionLogging, c_pszCmEntryLogFileDirectory, c_szLogFileDirectory);
  828. hr = pArgs->Log.SetParams(fEnabled, dwMaxSize, pszFileDir);
  829. if (S_OK != hr)
  830. {
  831. goto Cleanup;
  832. }
  833. if (pArgs->Log.IsEnabled())
  834. {
  835. hr = pArgs->Log.Start(fBanner);
  836. if (S_OK != hr)
  837. {
  838. CMTRACE(TEXT("cmdial32 InitLogging - failed to start log, no logging for this connectoid"));
  839. goto Cleanup;
  840. }
  841. }
  842. CMASSERTMSG(S_OK == hr, TEXT("cmdial32 InitLogging - at end"));
  843. Cleanup:
  844. CmFree(pszFileDir);
  845. CMTRACEHR("InitLogging", hr);
  846. return hr;
  847. }