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.

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