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.

2066 lines
49 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. rasnt.c
  5. Abstract:
  6. rasnt.c builds phonebook files for all of the users on win9x that had
  7. Dial-Up networking connections.
  8. Author:
  9. Marc R. Whitten (marcw) 23-Nov-1997
  10. Revision History:
  11. Marc R. Whitten marcw 23-Jul-1998 - Major cleanup.
  12. Jeff Sigman 09-Apr-2001 - Whistler cleanup.
  13. Whistler bugs:
  14. 34270 Win9x: Upgrade: Require Data Encryption setting for VPN
  15. connections is not migrated
  16. 125693 UpgLab9x: DUN Connectoids don't migrate selected modem properly
  17. from Win9x
  18. 208318 Win9x Upg: Username and Password for DUN connectoid not migrated
  19. from Win9x to Whistler
  20. --*/
  21. #include "pch.h" // Pre-compiled
  22. #include "pcache.h" // Private pcache header
  23. #include <rascmn.h> // RAS migration constants
  24. #include <sddl.h> // ConvertSidToStringSid
  25. #define MAX_SPEED_DIAL 8
  26. #define MAX_SID_SIZE 1024
  27. #define RAS_BUFFER_SIZE MEMDB_MAX
  28. //
  29. // For each entry, the following basic information is stored.
  30. //
  31. #define ENTRY_SETTINGS \
  32. FUNSETTING(Type) \
  33. STRSETTING(AutoLogon,S_ZERO) \
  34. STRSETTING(UseRasCredentials,S_ONE) \
  35. FUNSETTING(DialParamsUID) \
  36. STRSETTING(Guid,S_EMPTY) \
  37. FUNSETTING(BaseProtocol) \
  38. FUNSETTING(VpnStrategy) \
  39. FUNSETTING(ExcludedProtocols) \
  40. STRSETTING(LcpExtensions,S_ONE) \
  41. FUNSETTING(DataEncryption) \
  42. FUNSETTING(SwCompression) \
  43. STRSETTING(NegotiateMultilinkAlways,S_ONE) \
  44. STRSETTING(SkipNwcWarning,S_ZERO) \
  45. STRSETTING(SkipDownLevelDialog,S_ZERO) \
  46. STRSETTING(SkipDoubleDialDialog,S_ZERO) \
  47. STRSETTING(DialMode,DEF_DialMode) \
  48. STRSETTING(DialPercent,DEF_DialPercent) \
  49. STRSETTING(DialSeconds,DEF_DialSeconds) \
  50. STRSETTING(HangUpPercent,DEF_HangUpPercent) \
  51. STRSETTING(HangUpSeconds,DEF_HangUpSeconds) \
  52. STRSETTING(OverridePref,DEF_OverridePref) \
  53. FUNSETTING(RedialAttempts) \
  54. FUNSETTING(RedialSeconds) \
  55. FUNSETTING(IdleDisconnectSeconds) \
  56. STRSETTING(RedialOnLinkFailure,S_ZERO) \
  57. STRSETTING(CallbackMode,S_ZERO) \
  58. STRSETTING(CustomDialDll,S_EMPTY) \
  59. STRSETTING(CustomDialFunc,S_EMPTY) \
  60. STRSETTING(CustomRasDialDll,S_EMPTY) \
  61. STRSETTING(AuthenticateServer,S_ZERO) \
  62. FUNSETTING(ShareMsFilePrint) \
  63. STRSETTING(BindMsNetClient,S_ONE) \
  64. FUNSETTING(SharedPhoneNumbers) \
  65. STRSETTING(GlobalDeviceSettings,S_ZERO) \
  66. STRSETTING(PrerequisiteEntry,S_EMPTY) \
  67. STRSETTING(PrerequisitePbk,S_EMPTY) \
  68. STRSETTING(PreferredPort,S_EMPTY) \
  69. STRSETTING(PreferredDevice,S_EMPTY) \
  70. FUNSETTING(PreviewUserPw) \
  71. FUNSETTING(PreviewDomain) \
  72. FUNSETTING(PreviewPhoneNumber) \
  73. STRSETTING(ShowDialingProgress,S_ONE) \
  74. FUNSETTING(ShowMonitorIconInTaskBar) \
  75. STRSETTING(CustomAuthKey,DEF_CustomAuthKey) \
  76. FUNSETTING(AuthRestrictions) \
  77. FUNSETTING(TypicalAuth) \
  78. FUNSETTING(IpPrioritizeRemote) \
  79. FUNSETTING(IpHeaderCompression) \
  80. FUNSETTING(IpAddress) \
  81. FUNSETTING(IpDnsAddress) \
  82. FUNSETTING(IpDns2Address) \
  83. FUNSETTING(IpWinsAddress) \
  84. FUNSETTING(IpWins2Address) \
  85. FUNSETTING(IpAssign) \
  86. FUNSETTING(IpNameAssign) \
  87. STRSETTING(IpFrameSize,DEF_IpFrameSize) \
  88. STRSETTING(IpDnsFlags,S_ZERO) \
  89. STRSETTING(IpNBTFlags,S_ONE) \
  90. STRSETTING(TcpWindowSize,S_ZERO) \
  91. STRSETTING(UseFlags,S_ZERO) \
  92. STRSETTING(IpSecFlags,S_ZERO) \
  93. STRSETTING(IpDnsSuffix,S_EMPTY) \
  94. #define NETCOMPONENT_SETTINGS \
  95. STRSETTING(NETCOMPONENTS,S_EMPTY) \
  96. FUNSETTING(ms_server) \
  97. STRSETTING(ms_msclient,S_ONE) \
  98. #define MEDIA_SETTINGS \
  99. FUNSETTING(MEDIA) \
  100. FUNSETTING(Port) \
  101. FUNSETTING(Device) \
  102. FUNSETTING(ConnectBPS) \
  103. #define GENERAL_DEVICE_SETTINGS \
  104. FUNSETTING(DEVICE) \
  105. FUNSETTING(PhoneNumber) \
  106. FUNSETTING(AreaCode) \
  107. FUNSETTING(CountryCode) \
  108. FUNSETTING(CountryID) \
  109. FUNSETTING(UseDialingRules) \
  110. STRSETTING(Comment,S_EMPTY) \
  111. STRSETTING(LastSelectedPhone,S_ZERO) \
  112. STRSETTING(PromoteAlternates,S_ZERO) \
  113. STRSETTING(TryNextAlternateOnFail,S_ONE) \
  114. #define MODEM_DEVICE_SETTINGS \
  115. FUNSETTING(HwFlowControl) \
  116. FUNSETTING(Protocol) \
  117. FUNSETTING(Compression) \
  118. FUNSETTING(Speaker) \
  119. STRSETTING(MdmProtocol,S_ZERO) \
  120. #define ISDN_DEVICE_SETTINGS \
  121. STRSETTING(LineType,S_ZERO) \
  122. STRSETTING(Fallback,S_ONE) \
  123. STRSETTING(EnableCompression,S_ONE) \
  124. STRSETTING(ChannelAggregation,S_ONE) \
  125. STRSETTING(Proprietary,S_ZERO) \
  126. #define SWITCH_DEVICE_SETTINGS \
  127. FUNSETTING(DEVICE) \
  128. FUNSETTING(Name) \
  129. FUNSETTING(Terminal) \
  130. FUNSETTING(Script) \
  131. //
  132. // Function prototypes.
  133. //
  134. typedef PCTSTR (DATA_FUNCTION_PROTOTYPE)(VOID);
  135. typedef DATA_FUNCTION_PROTOTYPE * DATA_FUNCTION;
  136. #define FUNSETTING(Data) DATA_FUNCTION_PROTOTYPE pGet##Data;
  137. #define STRSETTING(x,y)
  138. ENTRY_SETTINGS
  139. NETCOMPONENT_SETTINGS
  140. MEDIA_SETTINGS
  141. GENERAL_DEVICE_SETTINGS
  142. SWITCH_DEVICE_SETTINGS
  143. MODEM_DEVICE_SETTINGS
  144. ISDN_DEVICE_SETTINGS
  145. #undef FUNSETTING
  146. #undef STRSETTING
  147. //
  148. // Variable declerations.
  149. //
  150. typedef struct {
  151. PCTSTR SettingName;
  152. DATA_FUNCTION SettingFunction;
  153. PCTSTR SettingValue;
  154. } RAS_SETTING, * PRAS_SETTING;
  155. typedef struct {
  156. PCTSTR Name;
  157. PCTSTR Number;
  158. } SPEEDDIAL,*PSPEEDDIAL;
  159. typedef struct {
  160. PCTSTR String;
  161. UINT Value;
  162. WORD DataType;
  163. } MEMDB_RAS_DATA, *PMEMDB_RAS_DATA;
  164. #define FUNSETTING(x) {TEXT(#x), pGet##x, NULL},
  165. #define STRSETTING(x,y) {TEXT(#x), NULL, y},
  166. #define LASTSETTING {NULL,NULL,NULL}
  167. RAS_SETTING g_EntrySettings[] = {ENTRY_SETTINGS LASTSETTING};
  168. RAS_SETTING g_NetCompSettings[] = {NETCOMPONENT_SETTINGS LASTSETTING};
  169. RAS_SETTING g_MediaSettings[] = {MEDIA_SETTINGS LASTSETTING};
  170. RAS_SETTING g_GeneralSettings[] = {GENERAL_DEVICE_SETTINGS LASTSETTING};
  171. RAS_SETTING g_SwitchDeviceSettings[] = {SWITCH_DEVICE_SETTINGS LASTSETTING};
  172. RAS_SETTING g_ModemDeviceSettings[] = {MODEM_DEVICE_SETTINGS LASTSETTING};
  173. RAS_SETTING g_IsdnDeviceSettings[] = {ISDN_DEVICE_SETTINGS LASTSETTING};
  174. DEFINE_GUID(GUID_DEVCLASS_MODEM,
  175. 0x4d36e96dL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 );
  176. BOOL g_SpeedDialSettingsExist = FALSE;
  177. BOOL g_InSwitchSection = FALSE;
  178. BOOL g_RasmansInit = FALSE;
  179. UINT g_CurrentDevice = 0;
  180. UINT g_CurrentDeviceType = 0;
  181. HKEY g_UserRootKey = NULL;
  182. DWORD g_dwDialParamsUID = 0;
  183. DWORD g_dwDialUIDOffset = 0;
  184. TCHAR g_TempBuffer[RAS_BUFFER_SIZE];
  185. LPTSTR g_ptszSid = NULL;
  186. PCTSTR g_CurrentConnection;
  187. PCTSTR g_CurrentUser;
  188. SPEEDDIAL g_Settings[MAX_SPEED_DIAL];
  189. HINSTANCE g_RasmansLib = NULL;
  190. POOLHANDLE g_RasPool;
  191. VOID
  192. pInitLibs (
  193. VOID
  194. )
  195. {
  196. do {
  197. g_RasmansLib = LoadLibrary (S_RASMANSLIB);
  198. if (!g_RasmansLib) {
  199. DEBUGMSG((S_DBG_RAS,"Could not load library %s. Passwords will not be migrated.",
  200. S_RASMANSLIB));
  201. break;
  202. }
  203. (FARPROC) g_SetEntryDialParams = GetProcAddress (
  204. g_RasmansLib,
  205. S_SETENTRYDIALPARAMS);
  206. if (!g_SetEntryDialParams) {
  207. DEBUGMSG((S_DBG_RAS,"Could not load Procedure %s. Passwords will not be migrated.",
  208. S_SETENTRYDIALPARAMS));
  209. break;
  210. }
  211. g_RasmansInit = TRUE;
  212. } while ( FALSE );
  213. return;
  214. }
  215. VOID
  216. pCleanUpLibs (
  217. VOID
  218. )
  219. {
  220. if (g_RasmansLib) {
  221. FreeLibrary(g_RasmansLib);
  222. }
  223. return;
  224. }
  225. BOOL
  226. GetRasUserSid (
  227. IN PCTSTR User
  228. )
  229. {
  230. PSID pSid = NULL;
  231. BOOL bReturn = FALSE;
  232. TCHAR DontCareStr[MAX_SERVER_NAME];
  233. DWORD DontCareSize = sizeof (DontCareStr);
  234. DWORD SizeOfSidBuf = 0;
  235. SID_NAME_USE SidNameUse;
  236. do
  237. {
  238. if (LookupAccountName (
  239. NULL,
  240. User,
  241. pSid,
  242. &SizeOfSidBuf,
  243. DontCareStr,
  244. &DontCareSize,
  245. &SidNameUse) || !SizeOfSidBuf)
  246. {
  247. break;
  248. }
  249. pSid = LocalAlloc (LMEM_ZEROINIT, SizeOfSidBuf);
  250. if (!pSid) {break;}
  251. if (!LookupAccountName (
  252. NULL,
  253. User,
  254. pSid,
  255. &SizeOfSidBuf,
  256. DontCareStr,
  257. &DontCareSize,
  258. &SidNameUse) || (SidNameUse != SidTypeUser))
  259. {
  260. DEBUGMSG ((S_DBG_RAS, "LookupAccountName failed: %d",
  261. GetLastError()));
  262. break;
  263. }
  264. if (!ConvertSidToStringSid (pSid, &g_ptszSid) || !g_ptszSid) {break;}
  265. bReturn = TRUE;
  266. } while (FALSE);
  267. //
  268. // Clean up
  269. //
  270. if (pSid)
  271. {
  272. LocalFree (pSid);
  273. }
  274. return bReturn;
  275. }
  276. PCTSTR
  277. GetFriendlyNamefromPnpId (
  278. IN PCTSTR pszPnpId,
  279. IN BOOL bType
  280. )
  281. {
  282. DWORD i = 0;
  283. TCHAR szHardwareId[MAX_PATH + 1];
  284. TCHAR szDeviceName[MAX_PATH + 1];
  285. PCTSTR pszReturn = NULL;
  286. LPGUID pguidModem = (LPGUID)&GUID_DEVCLASS_MODEM;
  287. HDEVINFO hdi;
  288. SP_DEVINFO_DATA devInfoData = {sizeof (devInfoData), 0};
  289. //
  290. // I need to use the real reg API, not the custom's ones. this prevents the
  291. // reg tracking code from barking. the reason this is necessary is because
  292. // i am using a setup api to open the reg key.
  293. //
  294. #undef RegCloseKey
  295. DEBUGMSG ((S_DBG_RAS, "GetFriendlyNamefromPnpId: %s", pszPnpId));
  296. do
  297. {
  298. hdi = SetupDiGetClassDevs (pguidModem, NULL, NULL, DIGCF_PRESENT);
  299. if (INVALID_HANDLE_VALUE == hdi)
  300. {
  301. break;
  302. }
  303. for (i; SetupDiEnumDeviceInfo (hdi, i, &devInfoData) && !pszReturn; i++)
  304. {
  305. if (SetupDiGetDeviceRegistryProperty (
  306. hdi, &devInfoData, SPDRP_HARDWAREID,
  307. NULL, (PBYTE)szHardwareId, MAX_PATH, NULL) &&
  308. !_wcsnicmp (szHardwareId, pszPnpId, lstrlen(pszPnpId)) &&
  309. SetupDiGetDeviceRegistryProperty (
  310. hdi, &devInfoData, SPDRP_FRIENDLYNAME,
  311. NULL, (PBYTE)szDeviceName, MAX_PATH, NULL) )
  312. {
  313. //
  314. // Get the device name
  315. //
  316. if (bType)
  317. {
  318. pszReturn = PoolMemDuplicateString (g_RasPool, szDeviceName);
  319. DEBUGMSG ((S_DBG_RAS, "GetFriendlyNamefromPnpId - Found: %s",
  320. pszReturn));
  321. }
  322. //
  323. // Get the COM port
  324. //
  325. else
  326. {
  327. HKEY key = NULL;
  328. PTSTR pszAttach = NULL;
  329. key = SetupDiOpenDevRegKey (hdi, &devInfoData,
  330. DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_READ);
  331. if (INVALID_HANDLE_VALUE == key) {break;}
  332. pszAttach = GetRegValueString (key, S_ATTACHEDTO);
  333. if (!pszAttach)
  334. {
  335. RegCloseKey(key);
  336. break;
  337. }
  338. pszReturn = PoolMemDuplicateString (g_RasPool, pszAttach);
  339. DEBUGMSG ((S_DBG_RAS, "GetFriendlyNamefromPnpId - Found: %s",
  340. pszReturn));
  341. MemFree (g_hHeap, 0, pszAttach);
  342. RegCloseKey (key);
  343. }
  344. }
  345. ELSE_DEBUGMSG ((S_DBG_RAS, "GetFriendlyNamefromPnpId - szHardwareId: %s",
  346. szHardwareId));
  347. }
  348. } while (FALSE);
  349. //
  350. // Clean up
  351. //
  352. if (INVALID_HANDLE_VALUE != hdi)
  353. {
  354. SetupDiDestroyDeviceInfoList (hdi);
  355. }
  356. //
  357. // Put it back the way it was
  358. //
  359. #define RegCloseKey USE_CloseRegKey
  360. return pszReturn;
  361. }
  362. BOOL pGetRasDataFromMemDb (
  363. IN PCTSTR DataName,
  364. OUT PMEMDB_RAS_DATA Data
  365. )
  366. {
  367. BOOL rSuccess = FALSE;
  368. TCHAR key[MEMDB_MAX];
  369. DWORD value;
  370. DWORD flags;
  371. MYASSERT(DataName && Data && g_CurrentUser && g_CurrentConnection);
  372. MemDbBuildKey (key, MEMDB_CATEGORY_RAS_INFO, g_CurrentUser,
  373. g_CurrentConnection, DataName);
  374. rSuccess = MemDbGetValueAndFlags (key, &value, &flags);
  375. //
  376. // If that wasn't successful, we need to look in the per-user settings.
  377. //
  378. if (!rSuccess) {
  379. MemDbBuildKey (key, MEMDB_CATEGORY_RAS_INFO, MEMDB_FIELD_USER_SETTINGS,
  380. g_CurrentUser, DataName);
  381. rSuccess = MemDbGetValueAndFlags (key, &value, &flags);
  382. flags = REG_DWORD;
  383. }
  384. if (rSuccess) {
  385. //
  386. // There is information stored here. Fill it in and send it back to the
  387. // user.
  388. //
  389. if (flags == REG_SZ) {
  390. //
  391. // String data, the value points to the offset for the string.
  392. //
  393. if (!MemDbBuildKeyFromOffset (value, g_TempBuffer, 1, NULL)) {
  394. DEBUGMSG ((
  395. DBG_ERROR,
  396. "Could not retrieve RAS string information stored in Memdb. User=%s,Entry=%s,Setting=%s",
  397. g_CurrentUser,
  398. g_CurrentConnection,
  399. DataName
  400. ));
  401. return FALSE;
  402. }
  403. Data -> String = PoolMemDuplicateString (g_RasPool, g_TempBuffer);
  404. }
  405. else {
  406. //
  407. // Not string data. The data is stored as the value.
  408. //
  409. Data -> Value = value;
  410. }
  411. Data -> DataType = (WORD) flags;
  412. }
  413. return rSuccess;
  414. }
  415. //
  416. // Whistler bug: 417745 INTL:Win9x Upg: DBCS chars cause User,Domain,
  417. // Passwrds to not be migrated for DUN
  418. //
  419. VOID
  420. AttemptUserDomainMigrate (
  421. IN OUT PRAS_DIALPARAMS prdp,
  422. IN OUT PDWORD pdwFlag
  423. )
  424. {
  425. MEMDB_RAS_DATA user, domain;
  426. if (pGetRasDataFromMemDb (S_USER, &user) &&
  427. user.String && user.String[0] != '\0')
  428. {
  429. lstrcpyn(prdp->DP_UserName, user.String, UNLEN);
  430. *pdwFlag |= DLPARAMS_MASK_USERNAME;
  431. DEBUGMSG ((S_DBG_RAS, "AttemptUserDomainMigrate success user"));
  432. }
  433. if (pGetRasDataFromMemDb (S_DOMAIN, &domain) &&
  434. domain.String && domain.String[0] != '\0')
  435. {
  436. lstrcpyn(prdp->DP_Domain, domain.String, DNLEN);
  437. *pdwFlag |= DLPARAMS_MASK_DOMAIN;
  438. DEBUGMSG ((S_DBG_RAS, "AttemptUserDomainMigrate success dom"));
  439. }
  440. }
  441. PCTSTR
  442. pGetNetAddress (
  443. IN PCTSTR Setting
  444. )
  445. {
  446. MEMDB_RAS_DATA d;
  447. BYTE address[4];
  448. if (!pGetRasDataFromMemDb (Setting, &d) || !d.Value) {
  449. return DEF_NetAddress; // default
  450. }
  451. //
  452. // Data is stored as a REG_DWORD.
  453. // We need to write it in dotted decimal form.
  454. //
  455. *((LPDWORD)address) = d.Value;
  456. wsprintf (
  457. g_TempBuffer,
  458. TEXT("%d.%d.%d.%d"),
  459. address[3],
  460. address[2],
  461. address[1],
  462. address[0]
  463. );
  464. return g_TempBuffer;
  465. }
  466. BOOL
  467. IsTermEnabled(
  468. VOID
  469. )
  470. {
  471. MEMDB_RAS_DATA d;
  472. //
  473. // Whistler bug: 423598 INTL: Win9x Upg: DUN's country is set to U.S. when
  474. // upgrading DUNs that don't use dialing rules
  475. //
  476. if ((g_CurrentDeviceType == RASDT_Modem_V) &&
  477. (pGetRasDataFromMemDb (S_PPPSCRIPT, &d)) &&
  478. (d.String) && (d.String[0] != '\0')) {
  479. return TRUE;
  480. }
  481. if ((pGetRasDataFromMemDb (S_MODEM_UI_OPTIONS, &d)) &&
  482. (d.Value & (RAS_UI_FLAG_TERMBEFOREDIAL | RAS_UI_FLAG_TERMAFTERDIAL))) {
  483. return TRUE;
  484. }
  485. return FALSE;
  486. }
  487. //
  488. // BEGIN ENTRY_SETTINGS
  489. //
  490. PCTSTR
  491. pGetType (
  492. VOID
  493. )
  494. {
  495. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  496. return RASET_Vpn;
  497. }
  498. else {
  499. return RASET_Phone; // default
  500. }
  501. }
  502. PCTSTR
  503. pGetDialParamsUID (
  504. VOID
  505. )
  506. {
  507. if (g_dwDialParamsUID)
  508. {
  509. wsprintf (g_TempBuffer, TEXT("%d"), g_dwDialParamsUID);
  510. g_dwDialParamsUID = 0;
  511. return g_TempBuffer;
  512. }
  513. else
  514. {
  515. return S_EMPTY;
  516. }
  517. }
  518. PCTSTR
  519. pGetBaseProtocol (
  520. VOID
  521. )
  522. {
  523. MEMDB_RAS_DATA d;
  524. if (!pGetRasDataFromMemDb (S_SMM, &d) || StringIMatch (d.String, S_PPP)) {
  525. return BP_Ppp; // default
  526. }
  527. //
  528. // Map CSLIP to SLIP - Header Compression will be on turned on/off in
  529. // pGetIpHeaderCompression
  530. //
  531. if (StringIMatch (d.String, S_SLIP) || StringIMatch (d.String, S_CSLIP)) {
  532. return BP_Slip;
  533. }
  534. DEBUGMSG ((
  535. DBG_WARNING,
  536. "RAS Migrate: Unusable base protocol type (%s) for %s's entry %s. Forcing PPP.",
  537. d.String,
  538. g_CurrentUser,
  539. g_CurrentConnection
  540. ));
  541. return BP_Ppp;
  542. }
  543. PCTSTR
  544. pGetVpnStrategy (
  545. VOID
  546. )
  547. {
  548. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  549. return VS_PptpOnly;
  550. }
  551. else {
  552. return S_ZERO; // default
  553. }
  554. }
  555. PCTSTR
  556. pGetExcludedProtocols (
  557. VOID
  558. )
  559. {
  560. MEMDB_RAS_DATA d;
  561. //
  562. // Excluded protocols lists what protocols
  563. // are _not_ available for a particular ras connection.
  564. // This is a bit field where bits are set for each protocol
  565. // that is excluded.
  566. // NP_Nbf (0x1), NP_Ipx (0x2), NP_Ip (0x4)
  567. // Luckily, these are the same definitions as for win9x, except
  568. // each bit represents a protocol that is _enabled_ not
  569. // _disabled_. Therefore, all we need to do is reverse the bottom
  570. // three bits of the number.
  571. //
  572. if (!pGetRasDataFromMemDb (S_PROTOCOLS, &d)) {
  573. return S_ZERO; // default
  574. }
  575. wsprintf (g_TempBuffer, TEXT("%d"), ~d.Value & 0x7);
  576. return g_TempBuffer;
  577. }
  578. PCTSTR
  579. pGetDataEncryption (
  580. VOID
  581. )
  582. {
  583. MEMDB_RAS_DATA d;
  584. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  585. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  586. return DE_Require; // vpn default
  587. }
  588. else {
  589. return DE_IfPossible; // default
  590. }
  591. }
  592. if ((d.Value & SMMCFG_SW_ENCRYPTION) ||
  593. (d.Value & SMMCFG_UNUSED)) {
  594. return DE_Require;
  595. }
  596. else if (d.Value & SMMCFG_SW_ENCRYPTION_STRONG) {
  597. return DE_RequireMax;
  598. }
  599. else if (g_CurrentDeviceType == RASDT_Vpn_V) {
  600. return DE_Require; // vpn default
  601. }
  602. else {
  603. return DE_IfPossible; // default
  604. }
  605. }
  606. PCTSTR
  607. pGetSwCompression (
  608. VOID
  609. )
  610. {
  611. MEMDB_RAS_DATA d;
  612. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  613. return S_ONE; // default
  614. }
  615. //
  616. // the 1 bit in SMM_OPTIONS controls software based compression.
  617. // if it is set, the connection is able to handled compression,
  618. // otherwise, it cannot.
  619. //
  620. if (d.Value & SMMCFG_SW_COMPRESSION) {
  621. return S_ONE;
  622. }
  623. else {
  624. return S_ZERO;
  625. }
  626. }
  627. PCTSTR
  628. pGetRedialAttempts (
  629. VOID
  630. )
  631. {
  632. MEMDB_RAS_DATA d;
  633. if (!pGetRasDataFromMemDb (S_REDIAL_TRY, &d)) {
  634. return DEF_RedialAttempts; // default
  635. }
  636. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  637. return g_TempBuffer;
  638. }
  639. PCTSTR
  640. pGetRedialSeconds (
  641. VOID
  642. )
  643. {
  644. MEMDB_RAS_DATA d;
  645. //
  646. // NT wants this as a total number of seconds. The data we have from 9x has
  647. // the number of minutes in the hiword and the number of seconds in the
  648. // loword.
  649. //
  650. if (!pGetRasDataFromMemDb (S_REDIAL_WAIT, &d)) {
  651. return DEF_RedialSeconds; // default
  652. }
  653. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  654. return g_TempBuffer;
  655. }
  656. PCTSTR
  657. pGetIdleDisconnectSeconds (
  658. VOID
  659. )
  660. {
  661. MEMDB_RAS_DATA d;
  662. if (!pGetRasDataFromMemDb (S_MODEM_IDLE_DISCONNECT_SECONDS, &d)) {
  663. return S_ZERO; // default
  664. }
  665. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  666. return g_TempBuffer;
  667. }
  668. PCTSTR
  669. pGetShareMsFilePrint (
  670. VOID
  671. )
  672. {
  673. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  674. return S_ONE; // vpn default
  675. }
  676. else {
  677. return S_ZERO; // default
  678. }
  679. }
  680. PCTSTR
  681. pGetSharedPhoneNumbers (
  682. VOID
  683. )
  684. {
  685. MEMDB_RAS_DATA d;
  686. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  687. return S_ZERO; // vpn default
  688. }
  689. else if (pGetRasDataFromMemDb (S_DEVICECOUNT, &d) && (d.Value > 1)) {
  690. return S_ZERO; // multilink
  691. }
  692. else {
  693. return S_ONE; // default
  694. }
  695. }
  696. PCTSTR
  697. pGetPreviewUserPw (
  698. VOID
  699. )
  700. {
  701. MEMDB_RAS_DATA d;
  702. if (!pGetRasDataFromMemDb (S_DIALUI, &d)) {
  703. return S_ONE; // default
  704. }
  705. if (d.Value & DIALUI_NO_PROMPT) {
  706. return S_ZERO;
  707. }
  708. else {
  709. return S_ONE;
  710. }
  711. }
  712. PCTSTR
  713. pGetPreviewDomain (
  714. VOID
  715. )
  716. {
  717. MEMDB_RAS_DATA d, d2;
  718. //
  719. // Whistler bug: 417745 INTL:Win9x Upg: DBCS chars cause User,Domain,
  720. // Passwrds to not be migrated for DUN
  721. //
  722. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d) ||
  723. !pGetRasDataFromMemDb (S_DOMAIN, &d2)) {
  724. return S_ZERO; // default
  725. }
  726. if ((d.Value & SMMCFG_NW_LOGON) ||
  727. (d2.String != NULL && d2.String[0] != '\0')) {
  728. return S_ONE;
  729. }
  730. else {
  731. return S_ZERO;
  732. }
  733. }
  734. PCTSTR
  735. pGetPreviewPhoneNumber (
  736. VOID
  737. )
  738. {
  739. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  740. return S_ZERO; // vpn default
  741. }
  742. else {
  743. return pGetPreviewUserPw();
  744. }
  745. }
  746. PCTSTR
  747. pGetShowMonitorIconInTaskBar (
  748. VOID
  749. )
  750. {
  751. MEMDB_RAS_DATA d;
  752. //
  753. // This information is stored packed with other Dialing UI on
  754. // windows 9x. All we need to do is look for the specific
  755. // bit which is set when this is turned off.
  756. //
  757. if (pGetRasDataFromMemDb (S_DIALUI, &d) && (d.Value & DIALUI_NO_TRAY)) {
  758. return S_ZERO;
  759. }
  760. else {
  761. return S_ONE; // default
  762. }
  763. }
  764. PCTSTR
  765. pGetAuthRestrictions (
  766. VOID
  767. )
  768. {
  769. MEMDB_RAS_DATA d;
  770. if (!pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) {
  771. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  772. return AR_F_TypicalSecure; // vpn default
  773. }
  774. else {
  775. return AR_F_TypicalUnsecure; // default
  776. }
  777. }
  778. if (d.Value & SMMCFG_PW_ENCRYPTED) {
  779. return AR_F_TypicalSecure;
  780. }
  781. else if (g_CurrentDeviceType == RASDT_Vpn_V) {
  782. return AR_F_TypicalSecure; // vpn default
  783. }
  784. else {
  785. return AR_F_TypicalUnsecure; // default
  786. }
  787. }
  788. PCTSTR
  789. pGetTypicalAuth (
  790. VOID
  791. )
  792. {
  793. MEMDB_RAS_DATA d;
  794. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  795. return TA_Secure; // vpn default
  796. }
  797. else if ((pGetRasDataFromMemDb (S_SMM_OPTIONS, &d)) &&
  798. ((d.Value & SMMCFG_SW_ENCRYPTION) ||
  799. (d.Value & SMMCFG_UNUSED) ||
  800. (d.Value & SMMCFG_SW_ENCRYPTION_STRONG) ||
  801. (d.Value & SMMCFG_PW_ENCRYPTED))) {
  802. return TA_Secure;
  803. }
  804. else {
  805. return TA_Unsecure; // default
  806. }
  807. }
  808. PCTSTR
  809. pGetIpPrioritizeRemote (
  810. VOID
  811. )
  812. {
  813. MEMDB_RAS_DATA d;
  814. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  815. return S_ONE; // default
  816. }
  817. else if (d.Value & IPF_NO_WAN_PRI) {
  818. return S_ZERO;
  819. }
  820. else {
  821. return S_ONE;
  822. }
  823. }
  824. PCTSTR
  825. pGetIpHeaderCompression (
  826. VOID
  827. )
  828. {
  829. MEMDB_RAS_DATA d1, d2;
  830. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  831. return S_ZERO; // vpn default
  832. }
  833. else if (pGetRasDataFromMemDb (S_SMM, &d1)) {
  834. if (StringIMatch (d1.String, S_CSLIP)) {
  835. return S_ONE;
  836. }
  837. else if (StringIMatch (d1.String, S_SLIP)) {
  838. return S_ZERO;
  839. }
  840. }
  841. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d2)) {
  842. return S_ONE; // default
  843. }
  844. else if (d2.Value & IPF_NO_COMPRESS) {
  845. return S_ZERO;
  846. }
  847. else {
  848. return S_ONE;
  849. }
  850. }
  851. PCTSTR
  852. pGetIpAddress (
  853. VOID
  854. )
  855. {
  856. return pGetNetAddress (S_IP_IPADDR);
  857. }
  858. PCTSTR
  859. pGetIpDnsAddress (
  860. VOID
  861. )
  862. {
  863. return pGetNetAddress (S_IP_DNSADDR);
  864. }
  865. PCTSTR
  866. pGetIpDns2Address (
  867. VOID
  868. )
  869. {
  870. return pGetNetAddress (S_IP_DNSADDR2);
  871. }
  872. PCTSTR
  873. pGetIpWinsAddress (
  874. VOID
  875. )
  876. {
  877. return pGetNetAddress (S_IP_WINSADDR);
  878. }
  879. PCTSTR
  880. pGetIpWins2Address (
  881. VOID
  882. )
  883. {
  884. return pGetNetAddress (S_IP_WINSADDR2);
  885. }
  886. PCTSTR
  887. pGetIpAssign (
  888. VOID
  889. )
  890. {
  891. MEMDB_RAS_DATA d;
  892. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  893. return ASRC_ServerAssigned; // default
  894. }
  895. else if (d.Value & IPF_IP_SPECIFIED) {
  896. return ASRC_RequireSpecific;
  897. }
  898. else {
  899. return ASRC_ServerAssigned;
  900. }
  901. }
  902. PCTSTR
  903. pGetIpNameAssign (
  904. VOID
  905. )
  906. {
  907. MEMDB_RAS_DATA d;
  908. if (!pGetRasDataFromMemDb (S_IP_FTCPIP, &d)) {
  909. return ASRC_ServerAssigned; // default
  910. }
  911. else if (d.Value & IPF_NAME_SPECIFIED) {
  912. return ASRC_RequireSpecific;
  913. }
  914. else {
  915. return ASRC_ServerAssigned;
  916. }
  917. }
  918. //
  919. // END ENTRY_SETTINGS
  920. //
  921. //
  922. // BEGIN NETCOMPONENT_SETTINGS
  923. //
  924. PCTSTR
  925. pGetms_server (
  926. VOID
  927. )
  928. {
  929. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  930. return S_ONE; // vpn default
  931. }
  932. else {
  933. return S_ZERO; // default
  934. }
  935. }
  936. //
  937. // END NETCOMPONENT_SETTINGS
  938. //
  939. //
  940. // BEGIN MEDIA_SETTINGS
  941. //
  942. PCTSTR
  943. pGetMEDIA (
  944. VOID
  945. )
  946. {
  947. if (g_CurrentDeviceType == RASDT_Vpn_V ||
  948. g_CurrentDeviceType == RASDT_Atm_V) {
  949. return RASMT_Rastapi;
  950. }
  951. else if (g_CurrentDeviceType == RASDT_Isdn_V) {
  952. return RASDT_Isdn;
  953. }
  954. else {
  955. //
  956. // Couldn't find a matching device, use serial
  957. //
  958. return RASMT_Serial;
  959. }
  960. }
  961. PCTSTR
  962. pGetPort (
  963. VOID
  964. )
  965. {
  966. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  967. return DEF_VPNPort;
  968. }
  969. else if (g_CurrentDeviceType == RASDT_Atm_V) {
  970. return DEF_ATMPort;
  971. }
  972. else if (g_CurrentDeviceType == RASDT_Modem_V) {
  973. PTSTR p = S_DEVICE_ID;
  974. PCTSTR Com = NULL;
  975. MEMDB_RAS_DATA d;
  976. if (g_CurrentDevice)
  977. {
  978. wsprintf (g_TempBuffer, TEXT("ml%d%s"), g_CurrentDevice,
  979. S_DEVICE_ID);
  980. p = g_TempBuffer;
  981. }
  982. if (!pGetRasDataFromMemDb (p, &d)) {
  983. return S_EMPTY;
  984. }
  985. Com = GetFriendlyNamefromPnpId (d.String, FALSE);
  986. if (Com)
  987. {
  988. return Com;
  989. }
  990. p = S_MODEM_COM_PORT;
  991. if (g_CurrentDevice) {
  992. wsprintf (g_TempBuffer, TEXT("ml%d%s"), g_CurrentDevice,
  993. S_MODEM_COM_PORT);
  994. p = g_TempBuffer;
  995. }
  996. if (!pGetRasDataFromMemDb (p, &d)) {
  997. return S_EMPTY;
  998. }
  999. return d.String;
  1000. }
  1001. else {
  1002. return S_EMPTY; // Leave it to the NT PBK code to figure this out
  1003. }
  1004. }
  1005. PCTSTR
  1006. pGetDevice (
  1007. VOID
  1008. )
  1009. {
  1010. if (g_CurrentDeviceType == RASDT_Vpn_V) {
  1011. return RASMT_Vpn;
  1012. }
  1013. else if (g_CurrentDeviceType == RASDT_Modem_V) {
  1014. PTSTR p = S_DEVICE_ID;
  1015. PCTSTR Device = NULL;
  1016. MEMDB_RAS_DATA d;
  1017. if (g_CurrentDevice)
  1018. {
  1019. wsprintf (g_TempBuffer, TEXT("ml%d%s"), g_CurrentDevice,
  1020. S_DEVICE_ID);
  1021. p = g_TempBuffer;
  1022. }
  1023. if (!pGetRasDataFromMemDb (p, &d)) {
  1024. return S_EMPTY;
  1025. }
  1026. Device = GetFriendlyNamefromPnpId (d.String, TRUE);
  1027. if (Device)
  1028. {
  1029. return Device;
  1030. }
  1031. else
  1032. {
  1033. return S_EMPTY;
  1034. }
  1035. }
  1036. else {
  1037. return S_EMPTY; // Leave it to the NT PBK code to figure this out
  1038. }
  1039. }
  1040. PCTSTR
  1041. pGetConnectBPS (
  1042. VOID
  1043. )
  1044. {
  1045. MEMDB_RAS_DATA d;
  1046. if ((g_CurrentDeviceType != RASDT_Modem_V) ||
  1047. (!pGetRasDataFromMemDb (S_MODEM_SPEED, &d))) {
  1048. return S_EMPTY; // Leave it to the NT PBK code to figure this out
  1049. }
  1050. wsprintf (g_TempBuffer, TEXT("%d"), d.Value);
  1051. return g_TempBuffer;
  1052. }
  1053. //
  1054. // END MEDIA_SETTINGS
  1055. //
  1056. //
  1057. // BEGIN GENERAL_DEVICE_SETTINGS
  1058. //
  1059. PCTSTR
  1060. pGetDEVICE (
  1061. VOID
  1062. )
  1063. {
  1064. if (g_InSwitchSection) {
  1065. return MXS_SWITCH_TXT;
  1066. }
  1067. else if (g_CurrentDeviceType == RASDT_Isdn_V) {
  1068. return RASDT_Isdn_NT;
  1069. }
  1070. else if (g_CurrentDeviceType == RASDT_Vpn_V) {
  1071. return RASDT_Vpn_NT;
  1072. }
  1073. else if (g_CurrentDeviceType == RASDT_Atm_V) {
  1074. return RASDT_Atm_NT;
  1075. }
  1076. else {
  1077. return RASDT_Modem_NT; //default to modem
  1078. }
  1079. }
  1080. PCTSTR
  1081. pGetPhoneNumber (
  1082. VOID
  1083. )
  1084. {
  1085. MEMDB_RAS_DATA d;
  1086. TCHAR buffer[MAX_TCHAR_PATH];
  1087. if (g_CurrentDevice == 0) {
  1088. if (!pGetRasDataFromMemDb(S_PHONE_NUMBER, &d)) {
  1089. return S_EMPTY;
  1090. }
  1091. }
  1092. else {
  1093. wsprintf(buffer,TEXT("ml%d%s"),g_CurrentDevice,S_PHONE_NUMBER);
  1094. if (!pGetRasDataFromMemDb(buffer, &d)) {
  1095. return S_EMPTY;
  1096. }
  1097. }
  1098. return d.String;
  1099. }
  1100. PCTSTR
  1101. pGetAreaCode (
  1102. VOID
  1103. )
  1104. {
  1105. MEMDB_RAS_DATA d;
  1106. if (!pGetRasDataFromMemDb(S_AREA_CODE, &d)) {
  1107. return S_EMPTY;
  1108. }
  1109. return d.String;
  1110. }
  1111. PCTSTR
  1112. pGetCountryCode (
  1113. VOID
  1114. )
  1115. {
  1116. MEMDB_RAS_DATA d;
  1117. //
  1118. // Whistler bug: 423598 INTL: Win9x Upg: DUN's country is set to U.S. when
  1119. // upgrading DUNs that don't use dialing rules
  1120. //
  1121. if (!pGetRasDataFromMemDb(S_COUNTRY_CODE, &d) || !d.Value) {
  1122. return S_ZERO; // default
  1123. }
  1124. wsprintf(g_TempBuffer,TEXT("%d"),d.Value);
  1125. return g_TempBuffer;
  1126. }
  1127. PCTSTR
  1128. pGetCountryID (
  1129. VOID
  1130. )
  1131. {
  1132. MEMDB_RAS_DATA d;
  1133. //
  1134. // Whistler bug: 423598 INTL: Win9x Upg: DUN's country is set to U.S. when
  1135. // upgrading DUNs that don't use dialing rules
  1136. //
  1137. if (!pGetRasDataFromMemDb(S_COUNTRY_ID, &d) || !d.Value) {
  1138. return S_ZERO; // default
  1139. }
  1140. wsprintf(g_TempBuffer,TEXT("%d"),d.Value);
  1141. return g_TempBuffer;
  1142. }
  1143. PCTSTR
  1144. pGetUseDialingRules (
  1145. VOID
  1146. )
  1147. {
  1148. MEMDB_RAS_DATA d;
  1149. //
  1150. // Whistler bug: 423598 INTL: Win9x Upg: DUN's country is set to U.S. when
  1151. // upgrading DUNs that don't use dialing rules
  1152. //
  1153. if (!pGetRasDataFromMemDb(S_AREA_CODE, &d)
  1154. || !d.String || d.String[0] == '\0' ) {
  1155. return S_ZERO;
  1156. }
  1157. else {
  1158. return S_ONE;
  1159. }
  1160. }
  1161. //
  1162. // END GENERAL_DEVICE_SETTINGS
  1163. //
  1164. //
  1165. // BEGIN MODEM_DEVICE_SETTINGS
  1166. //
  1167. PCTSTR
  1168. pGetHwFlowControl (
  1169. VOID
  1170. )
  1171. {
  1172. MEMDB_RAS_DATA d;
  1173. if (!pGetRasDataFromMemDb (S_MODEM_CFG_OPTIONS, &d)) {
  1174. return S_ZERO; // default
  1175. }
  1176. if (d.Value & RAS_CFG_FLAG_HARDWARE_FLOW_CONTROL) {
  1177. return S_ONE;
  1178. }
  1179. else {
  1180. return S_ZERO;
  1181. }
  1182. }
  1183. PCTSTR
  1184. pGetProtocol (
  1185. VOID
  1186. )
  1187. {
  1188. MEMDB_RAS_DATA d;
  1189. if (!pGetRasDataFromMemDb (S_MODEM_CFG_OPTIONS, &d)) {
  1190. return S_ZERO; // default
  1191. }
  1192. if (d.Value & RAS_CFG_FLAG_USE_ERROR_CONTROL) {
  1193. return S_ONE;
  1194. }
  1195. else {
  1196. return S_ZERO;
  1197. }
  1198. }
  1199. PCTSTR
  1200. pGetCompression (
  1201. VOID
  1202. )
  1203. {
  1204. MEMDB_RAS_DATA d;
  1205. if (!pGetRasDataFromMemDb (S_MODEM_CFG_OPTIONS, &d)) {
  1206. return S_ZERO; // default
  1207. }
  1208. if (d.Value & RAS_CFG_FLAG_COMPRESS_DATA) {
  1209. return S_ONE;
  1210. }
  1211. else {
  1212. return S_ZERO;
  1213. }
  1214. }
  1215. PCTSTR
  1216. pGetSpeaker (
  1217. VOID
  1218. )
  1219. {
  1220. MEMDB_RAS_DATA d;
  1221. if (!pGetRasDataFromMemDb (S_MODEM_SPEAKER_VOLUME, &d)) {
  1222. return S_ONE; // default
  1223. }
  1224. if (d.Value) {
  1225. return S_ONE;
  1226. }
  1227. else {
  1228. return S_ZERO;
  1229. }
  1230. }
  1231. //
  1232. // END MODEM_DEVICE_SETTINGS
  1233. //
  1234. //
  1235. // BEGIN SWITCH_DEVICE_SETTINGS
  1236. //
  1237. PCTSTR
  1238. pGetName (
  1239. VOID
  1240. )
  1241. {
  1242. MEMDB_RAS_DATA d;
  1243. if (!pGetRasDataFromMemDb (S_PPPSCRIPT, &d)) {
  1244. return S_EMPTY;
  1245. }
  1246. else {
  1247. return d.String;
  1248. }
  1249. }
  1250. PCTSTR
  1251. pGetTerminal (
  1252. VOID
  1253. )
  1254. {
  1255. MEMDB_RAS_DATA d;
  1256. if (!pGetRasDataFromMemDb (S_MODEM_UI_OPTIONS, &d)) {
  1257. return S_ZERO;
  1258. }
  1259. if (d.Value & (RAS_UI_FLAG_TERMBEFOREDIAL | RAS_UI_FLAG_TERMAFTERDIAL)) {
  1260. return S_ONE;
  1261. }
  1262. else {
  1263. return S_ZERO;
  1264. }
  1265. }
  1266. PCTSTR
  1267. pGetScript (
  1268. VOID
  1269. )
  1270. {
  1271. MEMDB_RAS_DATA d;
  1272. //
  1273. // Whistler bug: 423598 INTL: Win9x Upg: DUN's country is set to U.S. when
  1274. // upgrading DUNs that don't use dialing rules
  1275. //
  1276. if ((!pGetRasDataFromMemDb (S_PPPSCRIPT, &d)) ||
  1277. (!d.String) || d.String[0] == '\0') {
  1278. return S_ZERO;
  1279. }
  1280. else {
  1281. return S_ONE;
  1282. }
  1283. }
  1284. //
  1285. // END SWITCH_DEVICE_SETTINGS
  1286. //
  1287. BOOL
  1288. pWritePhoneBookLine (
  1289. IN HANDLE FileHandle,
  1290. IN PCTSTR SettingName,
  1291. IN PCTSTR SettingValue
  1292. )
  1293. {
  1294. BOOL rSuccess = TRUE;
  1295. rSuccess &= WriteFileString (FileHandle, SettingName);
  1296. rSuccess &= WriteFileString (FileHandle, TEXT("="));
  1297. rSuccess &= WriteFileString (FileHandle, SettingValue ?
  1298. SettingValue : S_EMPTY);
  1299. rSuccess &= WriteFileString (FileHandle, TEXT("\r\n"));
  1300. return rSuccess;
  1301. }
  1302. BOOL
  1303. pWriteSettings (
  1304. IN HANDLE FileHandle,
  1305. IN PRAS_SETTING SettingList
  1306. )
  1307. {
  1308. BOOL rSuccess = TRUE;
  1309. while (SettingList->SettingName) {
  1310. rSuccess &= pWritePhoneBookLine (
  1311. FileHandle,
  1312. SettingList->SettingName,
  1313. SettingList->SettingValue ?
  1314. SettingList->SettingValue :
  1315. SettingList->SettingFunction ());
  1316. SettingList++;
  1317. }
  1318. return rSuccess;
  1319. }
  1320. BOOL
  1321. pCreateUserPhonebook (
  1322. IN PCTSTR UserName
  1323. )
  1324. {
  1325. BOOL rSuccess = TRUE;
  1326. BOOL noError;
  1327. MEMDB_RAS_DATA d;
  1328. MEMDB_ENUM e;
  1329. HANDLE file;
  1330. PCTSTR path;
  1331. UINT i;
  1332. UINT count;
  1333. //
  1334. // Set current user global.
  1335. //
  1336. g_CurrentUser = UserName;
  1337. if (MemDbEnumFields (&e, MEMDB_CATEGORY_RAS_INFO, UserName)) {
  1338. DEBUGMSG ((S_DBG_RAS, "Processing dial-up entries for user: %s",
  1339. UserName));
  1340. //
  1341. // Open the phonebook file and set the file pointer to the EOF.
  1342. //
  1343. path = JoinPaths (g_WinDir, S_RASPHONE_SUBPATH);
  1344. file = CreateFile (
  1345. path,
  1346. GENERIC_READ | GENERIC_WRITE,
  1347. 0, // No sharing.
  1348. NULL, // No inheritance
  1349. OPEN_ALWAYS,
  1350. FILE_ATTRIBUTE_NORMAL,
  1351. NULL // No template file.
  1352. );
  1353. if (file == INVALID_HANDLE_VALUE) {
  1354. DEBUGMSG ((DBG_ERROR, "Unable to open the phonebook file (%s)",
  1355. path));
  1356. return TRUE;
  1357. }
  1358. SetFilePointer (file, 0, NULL, FILE_END);
  1359. FreePathString (path);
  1360. //
  1361. // Now, enumerate all of the entries and write a phonebook entry to
  1362. // this file for each.
  1363. //
  1364. do {
  1365. g_CurrentConnection = e.szName;
  1366. g_CurrentDevice = 0;
  1367. DEBUGMSG ((S_DBG_RAS, "---Processing %s's entry settings: %s---",
  1368. UserName, g_CurrentConnection));
  1369. if (g_ptszSid && g_RasmansInit)
  1370. {
  1371. BOOL bMigrate = TRUE;
  1372. DWORD dwSetMask = 0, dwDialParamsUID;
  1373. RAS_DIALPARAMS rdp;
  1374. g_dwDialParamsUID = 0;
  1375. ZeroMemory (&rdp, sizeof (rdp));
  1376. //
  1377. // Whistler bug: 417745 INTL:Win9x Upg: DBCS chars cause User,
  1378. // Domain, Passwrds to not be migrated for DUN
  1379. //
  1380. AttemptUserDomainMigrate(&rdp, &dwSetMask);
  1381. bMigrate = MigrateEntryCreds (&rdp, g_CurrentConnection,
  1382. g_CurrentUser, &dwSetMask);
  1383. DEBUGMSG ((S_DBG_RAS, "MigrateEntryCreds: %d", bMigrate));
  1384. dwDialParamsUID = rdp.DP_Uid = GetTickCount() +
  1385. (++g_dwDialUIDOffset);
  1386. if (dwDialParamsUID && !bMigrate)
  1387. {
  1388. if (!g_SetEntryDialParams ( g_ptszSid, dwDialParamsUID,
  1389. dwSetMask, 0, &rdp))
  1390. {
  1391. g_dwDialParamsUID = dwDialParamsUID;
  1392. DEBUGMSG ((S_DBG_RAS, "SetEntryDialParams success"));
  1393. }
  1394. DEBUGMSG ((S_DBG_RAS, "g_dwDialParamsUID: %d",
  1395. g_dwDialParamsUID));
  1396. DEBUGMSG ((S_DBG_RAS, "dwSetMask: %x", dwSetMask));
  1397. }
  1398. //
  1399. // Clean up
  1400. //
  1401. ZeroMemory (&rdp, sizeof (rdp));
  1402. }
  1403. //
  1404. // Whistler 417479 RAS upgrade code does not migrate the default
  1405. // internet connection setting from WinME to XP
  1406. //
  1407. do
  1408. {
  1409. MEMDB_RAS_DATA defInet;
  1410. HKEY hKeyLM = NULL;
  1411. HKEY hKeyCU = NULL;
  1412. PCTSTR Path = NULL;
  1413. if (!pGetRasDataFromMemDb (S_DEFINTERNETCON, &defInet) ||
  1414. !(defInet.Value))
  1415. {
  1416. DEBUGMSG ((S_DBG_RAS, "No Internet Connection setting present or disabled"));
  1417. break;
  1418. }
  1419. //
  1420. // Get key for the HKLM path
  1421. //
  1422. Path = JoinPaths(TEXT("HKLM\\"),S_AUTODIAL_KEY);
  1423. if (Path)
  1424. {
  1425. hKeyLM = CreateRegKeyStr(Path);
  1426. FreePathString(Path);
  1427. }
  1428. //
  1429. // Get key for the HKCU path
  1430. //
  1431. hKeyCU = CreateRegKey (g_UserRootKey, S_AUTODIAL_KEY);
  1432. //
  1433. // Set the value for both
  1434. //
  1435. if (hKeyLM)
  1436. {
  1437. RegSetValueEx(hKeyLM, S_DEFINTERNETCON, 0, REG_SZ,
  1438. (PBYTE) g_CurrentConnection,
  1439. SizeOfString(g_CurrentConnection));
  1440. DEBUGMSG ((S_DBG_RAS, "Default Internet Connection = 1 (HKLM)"));
  1441. CloseRegKey(hKeyLM);
  1442. }
  1443. else
  1444. {
  1445. DEBUGMSG ((S_DBG_RAS, "Error creating/opening HKLM internet reg_key"));
  1446. }
  1447. if (hKeyCU)
  1448. {
  1449. RegSetValueEx(hKeyCU, S_DEFINTERNETCON, 0, REG_SZ,
  1450. (PBYTE) g_CurrentConnection,
  1451. SizeOfString(g_CurrentConnection));
  1452. DEBUGMSG ((S_DBG_RAS, "Default Internet Connection = 1 (HKCU)"));
  1453. CloseRegKey(hKeyCU);
  1454. }
  1455. else
  1456. {
  1457. DEBUGMSG ((S_DBG_RAS, "Error creating/opening HKCU internet reg_key"));
  1458. }
  1459. } while (FALSE);
  1460. if (!pGetRasDataFromMemDb (S_DEVICE_TYPE, &d)) {
  1461. g_CurrentDeviceType = RASDT_Modem_V;
  1462. }
  1463. else {
  1464. if (StringIMatch (d.String, RASDT_Modem)) {
  1465. g_CurrentDeviceType = RASDT_Modem_V;
  1466. }
  1467. else if (StringIMatch (d.String, RASDT_Isdn)) {
  1468. g_CurrentDeviceType = RASDT_Isdn_V;
  1469. }
  1470. else if (StringIMatch (d.String, RASDT_Vpn)) {
  1471. g_CurrentDeviceType = RASDT_Vpn_V;
  1472. }
  1473. else if (StringIMatch (d.String, RASDT_Atm)) {
  1474. g_CurrentDeviceType = RASDT_Atm_V;
  1475. }
  1476. else {
  1477. g_CurrentDeviceType = RASDT_Modem_V;
  1478. }
  1479. }
  1480. noError = TRUE;
  1481. //
  1482. // Add this entry to the phonebook.
  1483. //
  1484. // Write title.
  1485. //
  1486. // Whistler bug: 417745 INTL:Win9x Upg: DBCS chars cause User,
  1487. // Domain, Passwrds to not be migrated for DUN
  1488. //
  1489. // We truncate the connection name because XP PBK freaks out
  1490. //
  1491. if (SizeOfString(g_CurrentConnection) >= RAS_MaxPortName / 2 )
  1492. {
  1493. TCHAR Truncate[RAS_MaxPortName];
  1494. lstrcpyn(Truncate, g_CurrentConnection, RAS_MaxPortName / 2);
  1495. noError &= WriteFileString (file, TEXT("["));
  1496. noError &= WriteFileString (file, Truncate);
  1497. noError &= WriteFileString (file, TEXT("]\r\n"));
  1498. DEBUGMSG ((S_DBG_RAS, "Truncating Connection Name: %s", Truncate));
  1499. }
  1500. else
  1501. {
  1502. noError &= WriteFileString (file, TEXT("["));
  1503. noError &= WriteFileString (file, g_CurrentConnection);
  1504. noError &= WriteFileString (file, TEXT("]\r\n"));
  1505. }
  1506. //
  1507. // Write base entry settings.
  1508. //
  1509. noError &= pWriteSettings (file, g_EntrySettings);
  1510. noError &= WriteFileString (file, TEXT("\r\n"));
  1511. //
  1512. // Write NetComponent settings
  1513. //
  1514. noError &= pWriteSettings (file, g_NetCompSettings);
  1515. if (!pGetRasDataFromMemDb (S_DEVICECOUNT, &d)) {
  1516. count = 1;
  1517. DEBUGMSG ((DBG_WHOOPS, "No devices listed in memdb for connections %s.",
  1518. g_CurrentConnection));
  1519. }
  1520. else {
  1521. count = d.Value;
  1522. }
  1523. for (i = 0; i < count; i++) {
  1524. g_CurrentDevice = i;
  1525. //
  1526. // Write media settings.
  1527. //
  1528. noError &= WriteFileString (file, TEXT("\r\n"));
  1529. noError &= pWriteSettings (file, g_MediaSettings);
  1530. //
  1531. // Write Device settings.
  1532. //
  1533. noError &= WriteFileString (file, TEXT("\r\n"));
  1534. noError &= pWriteSettings (file, g_GeneralSettings);
  1535. if (g_CurrentDeviceType == RASDT_Modem_V) {
  1536. noError &= pWriteSettings (file, g_ModemDeviceSettings);
  1537. }
  1538. else if (g_CurrentDeviceType == RASDT_Isdn_V) {
  1539. noError &= pWriteSettings (file, g_IsdnDeviceSettings);
  1540. }
  1541. //
  1542. // Write switch settings
  1543. //
  1544. if (IsTermEnabled()) {
  1545. g_InSwitchSection = TRUE;
  1546. noError &= WriteFileString (file, TEXT("\r\n"));
  1547. noError &= pWriteSettings (file, g_SwitchDeviceSettings);
  1548. g_InSwitchSection = FALSE;
  1549. }
  1550. }
  1551. noError &= WriteFileString (file, TEXT("\r\n"));
  1552. if (!noError) {
  1553. LOG ((
  1554. LOG_ERROR,
  1555. "Error while writing phonebook for %s's %s setting.",
  1556. g_CurrentUser,
  1557. g_CurrentConnection
  1558. ));
  1559. }
  1560. } while (MemDbEnumNextValue (&e));
  1561. //
  1562. // Close the handle to the phone book file.
  1563. //
  1564. CloseHandle (file);
  1565. }
  1566. ELSE_DEBUGMSG ((S_DBG_RAS, "No dial-up entries for user %s.", UserName));
  1567. return rSuccess;
  1568. }
  1569. /*++
  1570. Routine Description:
  1571. pGatherPhoneDialerSettings gathers information on phonedialer speeddial
  1572. settings. This information is then used to create each user's speed dial
  1573. settings. Note that this information is per system in win9x, but per user
  1574. in NT.
  1575. There are multiple types of entries on Windows NT, but only one entry type
  1576. on win9x. All entries are migrated as type "POTS" and "PhoneNumber"
  1577. These entries are within the User hive at
  1578. HKCU\Software\Microsoft\Dialer\Speeddial\[SpeedDial<n>] =
  1579. "POTS", "PhoneNumber", "<number>", "<name>"
  1580. Arguments:
  1581. None.
  1582. Return Value:
  1583. --*/
  1584. VOID
  1585. pGatherPhoneDialerSettings (
  1586. VOID
  1587. )
  1588. {
  1589. PCTSTR dialerIniPath = NULL;
  1590. HINF hDialerIni = NULL;
  1591. INFSTRUCT is = INITINFSTRUCT_POOLHANDLE;
  1592. PCTSTR curKey;
  1593. UINT num;
  1594. PCTSTR tempPath = NULL;
  1595. //
  1596. // Open %windir%\dialer.ini
  1597. //
  1598. dialerIniPath = JoinPaths (g_WinDir, S_DIALER_INI);
  1599. tempPath = GetTemporaryLocationForFile (dialerIniPath);
  1600. if (tempPath) {
  1601. //
  1602. // telephon ini is in a temporary location. Use that.
  1603. //
  1604. DEBUGMSG ((S_DBG_RAS, "Using %s for %s.", tempPath, dialerIniPath));
  1605. FreePathString (dialerIniPath);
  1606. dialerIniPath = tempPath;
  1607. }
  1608. hDialerIni = InfOpenInfFile (dialerIniPath);
  1609. if (hDialerIni != INVALID_HANDLE_VALUE) {
  1610. //
  1611. // For each location in [Speed Dial Settings], gather the data and
  1612. // save it into our settings array.
  1613. //
  1614. if (InfFindFirstLine (hDialerIni, S_SPEED_DIAL_SETTINGS, NULL, &is)) {
  1615. do {
  1616. curKey = InfGetStringField (&is, 0);
  1617. if (IsPatternMatch (TEXT("Name*"), curKey)) {
  1618. num = _ttoi (_tcsinc (_tcschr (curKey, TEXT('e'))));
  1619. g_Settings[num].Name = InfGetStringField (&is,1);
  1620. g_SpeedDialSettingsExist = TRUE;
  1621. }
  1622. else if (IsPatternMatch (TEXT("Number*"), curKey)) {
  1623. num = _ttoi (_tcsinc (_tcschr (curKey, TEXT('r'))));
  1624. g_Settings[num].Number = InfGetStringField (&is,1);
  1625. g_SpeedDialSettingsExist = TRUE;
  1626. }
  1627. ELSE_DEBUGMSG ((DBG_WHOOPS, "Unexpected key found in speed dial settings: %s",
  1628. curKey));
  1629. } while (InfFindNextLine (&is));
  1630. }
  1631. InfCloseInfFile (hDialerIni);
  1632. }
  1633. }
  1634. BOOL
  1635. pCreateUserPhoneDialerSettings (
  1636. IN HKEY UserRootKey
  1637. )
  1638. {
  1639. BOOL rSuccess = TRUE;
  1640. HKEY key;
  1641. UINT num;
  1642. TCHAR valueName[40];
  1643. TCHAR dialerSetting[MEMDB_MAX];
  1644. UINT rc;
  1645. if (!g_SpeedDialSettingsExist) {
  1646. return TRUE;
  1647. }
  1648. rc = TrackedRegCreateKey (UserRootKey, S_SPEEDDIALKEY, &key);
  1649. if (rc == ERROR_SUCCESS) {
  1650. for (num = 0; num < MAX_SPEED_DIAL; num++) {
  1651. if (g_Settings[num].Number && g_Settings[num].Name &&
  1652. *g_Settings[num].Name) {
  1653. wsprintf (valueName, TEXT("Speeddial%u"), num);
  1654. wsprintf (
  1655. dialerSetting,
  1656. TEXT("\"POTS\",\"PhoneNumber\",\"%s\",\"%s\""),
  1657. g_Settings[num].Number,
  1658. g_Settings[num].Name
  1659. );
  1660. rc = RegSetValueEx(
  1661. key,
  1662. valueName,
  1663. 0,
  1664. REG_SZ,
  1665. (PBYTE) dialerSetting,
  1666. SizeOfString (dialerSetting)
  1667. );
  1668. DEBUGMSG_IF ((
  1669. rc != ERROR_SUCCESS,
  1670. DBG_ERROR,
  1671. "Error settings speeddial settings for %s. (%s/%s)",
  1672. valueName,
  1673. g_Settings[num].Name,
  1674. g_Settings[num].Number
  1675. ));
  1676. }
  1677. }
  1678. CloseRegKey(key);
  1679. }
  1680. ELSE_DEBUGMSG ((DBG_WARNING, "Could not open speed dial key. Speed dial settings will not be upgraded."));
  1681. return rSuccess;
  1682. }
  1683. BOOL
  1684. Ras_MigrateUser (
  1685. IN PCTSTR User,
  1686. IN HKEY UserRootKey
  1687. )
  1688. {
  1689. BOOL rSuccess = TRUE;
  1690. static BOOL firstTime = TRUE;
  1691. g_UserRootKey = UserRootKey;
  1692. if (firstTime) {
  1693. pGatherPhoneDialerSettings ();
  1694. firstTime = FALSE;
  1695. }
  1696. GetRasUserSid (User);
  1697. if (!pCreateUserPhonebook (User)) {
  1698. DEBUGMSG ((DBG_ERROR, "Failure while creating user phonebook for %s.",
  1699. User));
  1700. }
  1701. if (!pCreateUserPhoneDialerSettings (UserRootKey)) {
  1702. DEBUGMSG ((DBG_ERROR, "Failure while creating user phone dialer settings for %s.",
  1703. User));
  1704. }
  1705. //
  1706. // Clean up
  1707. //
  1708. if (g_ptszSid)
  1709. {
  1710. LocalFree(g_ptszSid);
  1711. g_ptszSid = NULL;
  1712. }
  1713. return rSuccess;
  1714. }
  1715. BOOL
  1716. Ras_MigrateSystem (
  1717. VOID
  1718. )
  1719. {
  1720. //
  1721. // Nothing to do here currently.
  1722. //
  1723. return TRUE;
  1724. }
  1725. BOOL
  1726. Ras_Entry (
  1727. IN HINSTANCE Instance,
  1728. IN DWORD Reason,
  1729. IN PVOID Reserved
  1730. )
  1731. {
  1732. BOOL rSuccess = TRUE;
  1733. switch (Reason)
  1734. {
  1735. case DLL_PROCESS_ATTACH:
  1736. //
  1737. // Initialize Memory pool.
  1738. //
  1739. g_RasPool = PoolMemInitNamedPool ("RAS - NT Side");
  1740. if (!g_RasPool) {
  1741. DEBUGMSG((DBG_ERROR,
  1742. "Ras Migrate: Pool Memory failed to initialize..."));
  1743. rSuccess = FALSE;
  1744. }
  1745. pInitLibs ();
  1746. break;
  1747. case DLL_PROCESS_DETACH:
  1748. //
  1749. // Free memory pool.
  1750. //
  1751. if (g_RasPool) {
  1752. PoolMemDestroyPool(g_RasPool);
  1753. }
  1754. if (g_RasmansInit) {
  1755. pCleanUpLibs();
  1756. }
  1757. //
  1758. // Attempt to delete %windir%\pwls\*.*
  1759. //
  1760. DeleteAllPwls ();
  1761. break;
  1762. }
  1763. return rSuccess;
  1764. }