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.

7219 lines
204 KiB

  1. // Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. //
  3. // file.c
  4. // Remote Access phonebook library
  5. // File access routines
  6. // Listed alphabetically
  7. //
  8. // 09/21/95 Steve Cobb
  9. //
  10. // About .PBK files:
  11. // -----------------
  12. //
  13. // A phonebook file is an MB ANSI file containing 0-n []ed sections, each
  14. // containing information for a single phonebook entry. The single entry may
  15. // contain multiple link information. Refer to file 'notes.txt' for a
  16. // description of how this format differs from the NT 3.51 format.
  17. //
  18. // [ENTRY]
  19. // Encoding=<encoding> ; New
  20. // Type=<RASET-code> ; New
  21. // Description=<text> ; Used for upgrade only
  22. // AutoLogon=<1/0>
  23. // DialParamsUID=<unique-ID>
  24. // Guid=<16-byte-binary> ; Absence indicates pre-NT5 entry
  25. // BaseProtocol=<BP-code>
  26. // VpnStrategy=<VS-code>
  27. // Authentication=<AS-code>
  28. // ExcludedProtocols=<NP-bits>
  29. // LcpExtensions=<1/0>
  30. // DataEncryption=<DE-code>
  31. // SkipNwcWarning=<1/0>
  32. // SkipDownLevelDialog=<1/0>
  33. // SkipDoubleDialDialog=<1/0>
  34. // SwCompression=<1/0>
  35. // UseCountryAndAreaCodes=<1/0> ; Used for upgrade only
  36. // AreaCode=<string> ; Used for upgrade only
  37. // CountryID=<id> ; Used for upgrade only
  38. // CountryCode=<code> ; Used for upgrade only
  39. // ShowMonitorIconInTaskBar
  40. // CustomAuthKey=<EAP-IANA-code>
  41. // CustomAuthData=<hexdump>
  42. // CustomAuthIdentity=<name>
  43. // AuthRestrictions=<AR-code>
  44. // TypicalAuth=<TA-code>
  45. // ShowMonitorIconInTaskBar=<1/0>
  46. // OverridePref=<RASOR-bits>
  47. // DialMode=<DM-code>
  48. // DialPercent=<0-100>
  49. // DialSeconds=<1-n>
  50. // HangUpPercent=<0-100>
  51. // HangUpSeconds=<1-n>
  52. // RedialAttempts=<n>
  53. // RedialSeconds=<n>
  54. // IdleDisconnectSeconds=<-1,0,1-n>
  55. // RedialOnLinkFailure=<1/0>
  56. // CallbackMode=<CBM-code>
  57. // CustomDialDll=<path>
  58. // CustomDialFunc=<func-name>
  59. // AuthenticateServer=<1/0>
  60. // ShareMsFilePrint=<1/0>
  61. // BindMsNetClient=<1/0>
  62. // SharedPhoneNumbers=<1/0>
  63. // PrerequisiteEntry=<entry-name>
  64. // PrerequisitePbk=<PBK-path>
  65. // PreferredPort=<port name>
  66. // PreferredDevice=<device name>
  67. // PreviewUserPw=<1/0>
  68. // PreviewDomain=<1/0>
  69. // PreviewPhoneNumber=<1/0>
  70. // ShowDialingProgress=<1/0>
  71. // CustomScript=<1/0>
  72. //
  73. // The following single set of IP parameters appear in place of the equivalent
  74. // separate sets of PppXxx or SlipXxx parameters in the previous phonebook.
  75. //
  76. // IpPrioritizeRemote=<1/0>
  77. // IpHeaderCompression=<1/0>
  78. // IpAddress=<a.b.c.d>
  79. // IpDnsAddress=<a.b.c.d>
  80. // IpDns2Address=<a.b.c.d>
  81. // IpWinsAddress=<a.b.c.d>
  82. // IpWins2Address=<a.b.c.d>
  83. // IpAssign=<ASRC-code>
  84. // IpNameAssign=<ASRC-code>
  85. // IpFrameSize=<1006/1500>
  86. // IpDnsFlags=<DNS_ bits>
  87. // IpDnsSuffix=<dns suffix>
  88. //
  89. // Each entry contains a NETCOMPONENT subsection containing a freeform list of
  90. // keys and values representing installed net component parameters.
  91. //
  92. // NETCOMPONENTS=
  93. // <key1>=<value1>
  94. // <key2>=<value2>
  95. // <keyn>=<valuen>
  96. //
  97. // In general each section contains subsections delimited by MEDIA=<something>
  98. // and DEVICE=<something> lines. In NT 3.51 there had to be exactly one MEDIA
  99. // subsection and it had to be the first subsection of the section. There
  100. // could be any number of DEVICE subsections. Now, there can be multiple
  101. // MEDIA/DEVICE sets where the position of the set determines it's sub-entry
  102. // index, the first being 1, the second 2, etc.
  103. //
  104. // For serial media, the program currently expects 1 to 4 DEVICE subsections,
  105. // representing a preconnect switch, modem, X.25 PAD, and postconnect switch
  106. // (often a script). Following is a full serial link:
  107. //
  108. // MEDIA=serial
  109. // Port=<port-name>
  110. // Device=<device-name> ; Absence indicates a 3.51- phonebook
  111. // ConnectBps=<bps>
  112. //
  113. // DEVICE=switch
  114. // Type=<switchname or Terminal> ; Used for upgrade only
  115. // Name=<switchname>
  116. // Terminal=<1/0>
  117. //
  118. // DEVICE=modem
  119. // PhoneNumber=<phonenumber1>
  120. // AreaCode=<area-code1>
  121. // CountryID=<id>
  122. // CountryCode=<country-code>
  123. // UseDialingRules=<1/0>
  124. // Comment=<arbitrary-text1>
  125. // PhoneNumber=<phonenumber2>
  126. // AreaCode=<area-code1>
  127. // CountryID=<id>
  128. // CountryCode=<country-code>
  129. // UseDialingRules=<1/0>
  130. // Comment=<arbitrary-text2>
  131. // PhoneNumber=<phonenumberN>
  132. // AreaCode=<area-code1>
  133. // CountryID=<id>
  134. // CountryCode=<country-code>
  135. // UseDialingRules=<1/0>
  136. // Comment=<arbitrary-textn>
  137. // LastSelectedPhone=<index>
  138. // PromoteAlternates=<1/0>
  139. // TryNextAlternateOnFail=<1/0>
  140. // TapiBlob=<hexdump>
  141. // HwFlowControl=<1/0>
  142. // Protocol=<1/0>
  143. // Compression=<1/0>
  144. // Speaker=<0/1>
  145. //
  146. // DEVICE=pad
  147. // X25Pad=<padtype>
  148. // X25Address=<X121address>
  149. // UserData=<userdata>
  150. // Facilities=<facilities>
  151. //
  152. // DEVICE=switch
  153. // Type=<switchname or Terminal> ; Used for upgrade only
  154. // Name=<switchname>
  155. // Terminal=<1/0>
  156. //
  157. // In the above, when a "pad" device appears without a modem (local PAD card),
  158. // the X25Pad field is written but is empty, because this is what the old
  159. // library/UI appears to do (though it does not look to be what was intended).
  160. //
  161. // For ISDN media, the program expects exactly 1 DEVICE subsection.
  162. //
  163. // MEDIA=isdn
  164. // Port=<port>
  165. // Device=<device-name>
  166. //
  167. // DEVICE=isdn
  168. // PhoneNumber=<phonenumber1>
  169. // AreaCode=<area-code1>
  170. // CountryID=<id>
  171. // CountryCode=<country-code>
  172. // UseDialingRules=<1/0>
  173. // Comment=<arbitrary-text1>
  174. // PhoneNumber=<phonenumber2>
  175. // AreaCode=<area-code1>
  176. // CountryID=<id>
  177. // CountryCode=<country-code>
  178. // UseDialingRules=<1/0>
  179. // Comment=<arbitrary-text2>
  180. // PhoneNumber=<phonenumberN>
  181. // AreaCode=<area-code1>
  182. // CountryID=<id>
  183. // CountryCode=<country-code>
  184. // UseDialingRules=<1/0>
  185. // Comment=<arbitrary-textn>
  186. // LastSelectedPhone=<index>
  187. // PromoteAlternates=<1/0>
  188. // TryNextAlternateOnFail=<1/0>
  189. // LineType=<0/1/2>
  190. // Fallback=<1/0>
  191. // EnableCompression=<1/0> ; Old proprietary protocol only
  192. // ChannelAggregation=<channels> ; Old proprietary protocol only
  193. // Proprietary=<1/0> ; Exists only in new, not found is 1.
  194. //
  195. //
  196. // For X.25 media, the program expects exactly 1 DEVICE subsection.
  197. //
  198. // MEDIA=x25
  199. // Port=<port-name>
  200. // Device=<device-name>
  201. //
  202. // DEVICE=x25
  203. // X25Address=<X121address>
  204. // UserData=<userdata>
  205. // Facilities=<facilities>
  206. //
  207. // For other media, the program expects exactly one DEVICE subsection with
  208. // device name matching the media. "Other" media and devices are created for
  209. // entries assigned to all non-serial, non-isdn medias.
  210. //
  211. // MEDIA=<media>
  212. // Port=<port-name>
  213. // Device=<device-name>
  214. //
  215. // DEVICE=<media>
  216. // PhoneNumber=<phonenumber1>
  217. // AreaCode=<area-code1>
  218. // CountryID=<id>
  219. // CountryCode=<country-code>
  220. // UseDialingRules=<1/0>
  221. // Comment=<arbitrary-text1>
  222. // PhoneNumber=<phonenumber2>
  223. // AreaCode=<area-code1>
  224. // CountryID=<id>
  225. // CountryCode=<country-code>
  226. // UseDialingRules=<1/0>
  227. // Comment=<arbitrary-text2>
  228. // PhoneNumber=<phonenumberN>
  229. // AreaCode=<area-code1>
  230. // CountryID=<id>
  231. // CountryCode=<country-code>
  232. // UseDialingRules=<1/0>
  233. // Comment=<arbitrary-textn>
  234. // LastSelectedPhone=<index>
  235. // PromoteAlternates=<1/0>
  236. // TryNextAlternateOnFail=<1/0>
  237. //
  238. // The phonebook also supports the concept of "custom" entries, i.e. entries
  239. // that fit the MEDIA followed by DEVICE subsection rules but which do not
  240. // include certain expected key fields. A custom entry is not editable with
  241. // the UI, but may be chosen for connection. This gives us a story for new
  242. // drivers added by 3rd parties or after release and not yet fully supported
  243. // in the UI. (Note: The RAS API support for most the custom entry discussion
  244. // above may be removed for NT SUR)
  245. //
  246. #include <nt.h>
  247. #include <ntrtl.h> // for DbgPrint
  248. #include <nturtl.h>
  249. #include <shlobj.h> // for CSIDL_*
  250. #include "pbkp.h"
  251. // This mutex guards against multiple RASFILE access to any phonebook file
  252. // across processes. Because this is currently a static library there is no
  253. // easy way to protect a single file at a time though this would be adequate.
  254. //
  255. #define PBMUTEXNAME "RasPbFile"
  256. HANDLE g_hmutexPb = NULL;
  257. #define MARK_LastLineToDelete 249
  258. #define MARK_BeginNetComponentsSearch 248
  259. #define IB_BytesPerLine 64
  260. const WCHAR c_pszRegKeySecureVpn[] = L"System\\CurrentControlSet\\Services\\Rasman\\PPP";
  261. const WCHAR c_pszRegValSecureVpn[] = L"SecureVPN";
  262. const WCHAR* c_pszRegKeyForceStrongEncryption = c_pszRegKeySecureVpn;
  263. const WCHAR c_pszRegValForceStrongEncryption[] = L"ForceStrongEncryption";
  264. //
  265. // Enumerated values define what encoding was used to store information
  266. // in the phonebook.
  267. //
  268. #define EN_Ansi 0x0 // Ansi encoding
  269. #define EN_Standard 0x1 // Utf8 encoding
  270. //
  271. // pmay: 124594
  272. //
  273. // Defines a function prototype that converts a string from ansi to TCHAR.
  274. //
  275. typedef
  276. TCHAR*
  277. (* STRDUP_T_FROM_A_FUNC)(
  278. IN CHAR* pszAnsi);
  279. //----------------------------------------------------------------------------
  280. // Local prototypes
  281. //----------------------------------------------------------------------------
  282. BOOL
  283. DeleteCurrentSection(
  284. IN HRASFILE h );
  285. DWORD
  286. GetPersonalPhonebookFile(
  287. IN TCHAR* pszUser,
  288. IN LONG lNum,
  289. OUT TCHAR* pszFile );
  290. BOOL
  291. GetPhonebookPath(
  292. IN PBUSER* pUser,
  293. IN DWORD dwFlags,
  294. OUT TCHAR** ppszPath,
  295. OUT DWORD* pdwPhonebookMode );
  296. DWORD
  297. InsertBinary(
  298. IN HRASFILE h,
  299. IN CHAR* pszKey,
  300. IN BYTE* pData,
  301. IN DWORD cbData );
  302. DWORD
  303. InsertBinaryChunk(
  304. IN HRASFILE h,
  305. IN CHAR* pszKey,
  306. IN BYTE* pData,
  307. IN DWORD cbData );
  308. DWORD
  309. InsertDeviceList(
  310. IN PBFILE *pFile,
  311. IN HRASFILE h,
  312. IN PBENTRY* ppbentry,
  313. IN PBLINK* ppblink );
  314. DWORD
  315. InsertFlag(
  316. IN HRASFILE h,
  317. IN CHAR* pszKey,
  318. IN BOOL fValue );
  319. DWORD
  320. InsertGroup(
  321. IN HRASFILE h,
  322. IN CHAR* pszGroupKey,
  323. IN TCHAR* pszValue );
  324. DWORD
  325. InsertLong(
  326. IN HRASFILE h,
  327. IN CHAR* pszKey,
  328. IN LONG lValue );
  329. DWORD
  330. InsertNetComponents(
  331. IN HRASFILE h,
  332. IN DTLLIST* pdtllist );
  333. DWORD
  334. InsertPhoneList(
  335. IN HRASFILE h,
  336. IN DTLLIST* pdtllist );
  337. DWORD
  338. InsertSection(
  339. IN HRASFILE h,
  340. IN TCHAR* pszSectionName );
  341. DWORD
  342. InsertString(
  343. IN HRASFILE h,
  344. IN CHAR* pszKey,
  345. IN TCHAR* pszValue );
  346. DWORD
  347. InsertStringA(
  348. IN HRASFILE h,
  349. IN CHAR* pszKey,
  350. IN CHAR* pszValue );
  351. DWORD
  352. InsertStringList(
  353. IN HRASFILE h,
  354. IN CHAR* pszKey,
  355. IN DTLLIST* pdtllistValues );
  356. BOOL
  357. IsGroup(
  358. IN CHAR* pszText );
  359. DWORD
  360. ModifyEntryList(
  361. IN PBFILE* pFile );
  362. DWORD
  363. ReadBinary(
  364. IN HRASFILE h,
  365. IN RFSCOPE rfscope,
  366. IN CHAR* pszKey,
  367. OUT BYTE** ppResult,
  368. OUT DWORD* pcb );
  369. DWORD
  370. ReadDeviceList(
  371. IN HRASFILE h,
  372. IN STRDUP_T_FROM_A_FUNC pStrDupTFromA,
  373. IN OUT PBENTRY* ppbentry,
  374. IN OUT PBLINK* ppblink,
  375. IN BOOL fUnconfiguredPort,
  376. IN BOOL* pfSpeaker );
  377. DWORD
  378. ReadEntryList(
  379. IN OUT PBFILE* pFile,
  380. IN DWORD dwFlags,
  381. IN LPCTSTR pszSection);
  382. DWORD
  383. ReadFlag(
  384. IN HRASFILE h,
  385. IN RFSCOPE rfscope,
  386. IN CHAR* pszKey,
  387. OUT BOOL* pfResult );
  388. DWORD
  389. ReadLong(
  390. IN HRASFILE h,
  391. IN RFSCOPE rfscope,
  392. IN CHAR* pszKey,
  393. OUT LONG* plResult );
  394. VOID
  395. ReadNetComponents(
  396. IN HRASFILE h,
  397. IN DTLLIST* pdtllist );
  398. DWORD
  399. ReadPhoneList(
  400. IN HRASFILE h,
  401. IN RFSCOPE rfscope,
  402. OUT DTLLIST** ppdtllist,
  403. OUT BOOL* pfDirty );
  404. DWORD
  405. ReadString(
  406. IN HRASFILE h,
  407. IN STRDUP_T_FROM_A_FUNC pStrDupTFromA,
  408. IN RFSCOPE rfscope,
  409. IN CHAR* pszKey,
  410. OUT TCHAR** ppszResult );
  411. DWORD
  412. ReadStringList(
  413. IN HRASFILE h,
  414. IN RFSCOPE rfscope,
  415. IN CHAR* pszKey,
  416. OUT DTLLIST** ppdtllistResult );
  417. BOOL
  418. PbportTypeMatchesEntryType(
  419. IN PBPORT * ppbport,
  420. IN PBENTRY* ppbentry);
  421. PBPORT*
  422. PpbportFromNullModem(
  423. IN DTLLIST* pdtllistPorts,
  424. IN TCHAR* pszPort,
  425. IN TCHAR* pszDevice );
  426. DWORD
  427. UpgradeRegistryOptions(
  428. IN HANDLE hConnection,
  429. IN PBENTRY* pEntry );
  430. //----------------------------------------------------------------------------
  431. // Routines
  432. //----------------------------------------------------------------------------
  433. VOID
  434. ClosePhonebookFile(
  435. IN OUT PBFILE* pFile )
  436. // Closes the currently open phonebook file for shutdown.
  437. //
  438. {
  439. if (pFile->hrasfile != -1)
  440. {
  441. RasfileClose( pFile->hrasfile );
  442. pFile->hrasfile = -1;
  443. }
  444. if(pFile->pszPath != NULL){
  445. Free0( pFile->pszPath );
  446. pFile->pszPath = NULL;
  447. }
  448. if (pFile->pdtllistEntries != NULL)
  449. {
  450. if (DtlGetListId( pFile->pdtllistEntries ) == RPBF_HeadersOnly)
  451. {
  452. DtlDestroyList( pFile->pdtllistEntries, DestroyPszNode );
  453. }
  454. else if (DtlGetListId(pFile->pdtllistEntries) == RPBF_HeaderType)
  455. {
  456. DtlDestroyList(pFile->pdtllistEntries, DestroyEntryTypeNode);
  457. }
  458. else
  459. {
  460. DtlDestroyList( pFile->pdtllistEntries, DestroyEntryNode );
  461. }
  462. pFile->pdtllistEntries = NULL;
  463. }
  464. }
  465. BOOL
  466. DeleteCurrentSection(
  467. IN HRASFILE h )
  468. // Delete the section containing the current line from phonebook file 'h'.
  469. //
  470. // Returns true if all lines are deleted successfully, false otherwise.
  471. // False is returned if the current line is not in a section. If
  472. // successful, the current line is set to the line following the deleted
  473. // section. There are no promises about the current line in case of
  474. // failure.
  475. //
  476. {
  477. BOOL fLastLine;
  478. // Mark the last line in the section, then reset the current line to the
  479. // first line of the section.
  480. //
  481. if (!RasfileFindLastLine( h, RFL_ANY, RFS_SECTION )
  482. || !RasfilePutLineMark( h, MARK_LastLineToDelete )
  483. || !RasfileFindFirstLine( h, RFL_ANY, RFS_SECTION ))
  484. {
  485. return FALSE;
  486. }
  487. // Delete lines up to and including the last line of the section.
  488. //
  489. do
  490. {
  491. fLastLine = (RasfileGetLineMark( h ) == MARK_LastLineToDelete);
  492. if (!RasfileDeleteLine( h ))
  493. {
  494. return FALSE;
  495. }
  496. }
  497. while (!fLastLine);
  498. return TRUE;
  499. }
  500. // (shaunco) DwAllocateSecurityDescriptorAllowAccessToWorld was added when
  501. // it was seen that the old InitSecurityDescriptor code was leaking memory
  502. // like a sieve.
  503. //
  504. #define SIZE_ALIGNED_FOR_TYPE(_size, _type) \
  505. (((_size) + sizeof(_type)-1) & ~(sizeof(_type)-1))
  506. DWORD
  507. DwAllocateSecurityDescriptorAllowAccessToWorld (
  508. PSECURITY_DESCRIPTOR* ppSd
  509. )
  510. {
  511. PSECURITY_DESCRIPTOR pSd;
  512. PSID pSid;
  513. PACL pDacl;
  514. DWORD dwErr = NOERROR;
  515. DWORD dwAlignSdSize;
  516. DWORD dwAlignDaclSize;
  517. DWORD dwSidSize;
  518. PVOID pvBuffer;
  519. DWORD dwAcls = 0;
  520. // Here is the buffer we are building.
  521. //
  522. // |<- a ->|<- b ->|<- c ->|
  523. // +-------+--------+------+
  524. // | p| p| |
  525. // | SD a| DACL a| SID |
  526. // | d| d| |
  527. // +-------+-------+-------+
  528. // ^ ^ ^
  529. // | | |
  530. // | | +--pSid
  531. // | |
  532. // | +--pDacl
  533. // |
  534. // +--pSd (this is returned via *ppSd)
  535. //
  536. // pad is so that pDacl and pSid are aligned properly.
  537. //
  538. // a = dwAlignSdSize
  539. // b = dwAlignDaclSize
  540. // c = dwSidSize
  541. //
  542. // Initialize output parameter.
  543. //
  544. *ppSd = NULL;
  545. // Compute the size of the SID. The SID is the well-known SID for World
  546. // (S-1-1-0).
  547. //
  548. dwSidSize = GetSidLengthRequired(1);
  549. // Compute the size of the DACL. It has an inherent copy of SID within
  550. // it so add enough room for it. It also must sized properly so that
  551. // a pointer to a SID structure can come after it. Hence, we use
  552. // SIZE_ALIGNED_FOR_TYPE.
  553. //
  554. dwAlignDaclSize = SIZE_ALIGNED_FOR_TYPE(
  555. sizeof(ACCESS_ALLOWED_ACE) + sizeof(ACL) + dwSidSize,
  556. PSID);
  557. // Compute the size of the SD. It must be sized propertly so that a
  558. // pointer to a DACL structure can come after it. Hence, we use
  559. // SIZE_ALIGNED_FOR_TYPE.
  560. //
  561. dwAlignSdSize = SIZE_ALIGNED_FOR_TYPE(
  562. sizeof(SECURITY_DESCRIPTOR),
  563. PACL);
  564. // Allocate the buffer big enough for all.
  565. //
  566. dwErr = ERROR_OUTOFMEMORY;
  567. pvBuffer = Malloc(dwSidSize + dwAlignDaclSize + dwAlignSdSize);
  568. if (pvBuffer)
  569. {
  570. SID_IDENTIFIER_AUTHORITY SidIdentifierWorldAuth
  571. = SECURITY_WORLD_SID_AUTHORITY;
  572. PULONG pSubAuthority;
  573. dwErr = NOERROR;
  574. // Setup the pointers into the buffer.
  575. //
  576. pSd = pvBuffer;
  577. pDacl = (PACL)((PBYTE)pvBuffer + dwAlignSdSize);
  578. pSid = (PSID)((PBYTE)pDacl + dwAlignDaclSize);
  579. // Initialize pSid as S-1-1-0.
  580. //
  581. if (!InitializeSid(
  582. pSid,
  583. &SidIdentifierWorldAuth,
  584. 1)) // 1 sub-authority
  585. {
  586. dwErr = GetLastError();
  587. goto finish;
  588. }
  589. pSubAuthority = GetSidSubAuthority(pSid, 0);
  590. *pSubAuthority = SECURITY_WORLD_RID;
  591. // Initialize pDacl.
  592. //
  593. if (!InitializeAcl(
  594. pDacl,
  595. dwAlignDaclSize,
  596. ACL_REVISION))
  597. {
  598. dwErr = GetLastError();
  599. goto finish;
  600. }
  601. dwAcls = SPECIFIC_RIGHTS_ALL | STANDARD_RIGHTS_ALL;
  602. dwAcls &= ~(WRITE_DAC | WRITE_OWNER);
  603. if(!AddAccessAllowedAce(
  604. pDacl,
  605. ACL_REVISION,
  606. dwAcls,
  607. pSid))
  608. {
  609. dwErr = GetLastError();
  610. goto finish;
  611. }
  612. // Initialize pSd.
  613. //
  614. if (!InitializeSecurityDescriptor(
  615. pSd,
  616. SECURITY_DESCRIPTOR_REVISION))
  617. {
  618. dwErr = GetLastError();
  619. goto finish;
  620. }
  621. // Set pSd to use pDacl.
  622. //
  623. if (!SetSecurityDescriptorDacl(
  624. pSd,
  625. TRUE,
  626. pDacl,
  627. FALSE))
  628. {
  629. dwErr = GetLastError();
  630. goto finish;
  631. }
  632. // Set the owner for pSd.
  633. //
  634. if (!SetSecurityDescriptorOwner(
  635. pSd,
  636. NULL,
  637. TRUE))
  638. {
  639. dwErr = GetLastError();
  640. goto finish;
  641. }
  642. // Set the group for pSd.
  643. //
  644. if (!SetSecurityDescriptorGroup(
  645. pSd,
  646. NULL,
  647. FALSE))
  648. {
  649. dwErr = GetLastError();
  650. goto finish;
  651. }
  652. finish:
  653. if (!dwErr)
  654. {
  655. *ppSd = pSd;
  656. }
  657. else
  658. {
  659. Free(pvBuffer);
  660. }
  661. }
  662. return dwErr;
  663. }
  664. BOOL
  665. GetDefaultPhonebookPath(
  666. IN DWORD dwFlags,
  667. OUT TCHAR** ppszPath )
  668. // Loads caller's 'ppszPath' with the path to the default phonebook
  669. // for the current user, i.e. the phonebook which would be opened
  670. // if 'NULL' were passed as the 'pszPhonebook' argument to any RAS API.
  671. //
  672. // Returns true if successful, or false otherwise.
  673. // It is the caller's responsibility to Free the returned string.
  674. //
  675. {
  676. DWORD dwPhonebookMode;
  677. BOOL f;
  678. PBUSER user;
  679. if (GetUserPreferences( NULL, &user, FALSE ) != 0)
  680. {
  681. return FALSE;
  682. }
  683. f = GetPhonebookPath( &user, dwFlags, ppszPath, &dwPhonebookMode );
  684. DestroyUserPreferences( &user );
  685. return f;
  686. }
  687. #if 0
  688. DWORD
  689. GetPersonalPhonebookFile(
  690. IN TCHAR* pszUser,
  691. IN LONG lNum,
  692. OUT TCHAR* pszFile )
  693. // Loads caller's 'pszFile' buffer with the NUL-terminated filename
  694. // corresponding to unique phonebook file name attempt 'lNum' for current
  695. // user 'pszUser'. Caller's 'pszFile' must be at least 13 characters
  696. // long. Attempts go from -1 to 999.
  697. //
  698. // Returns 0 if successful or a non-0 error code.
  699. //
  700. {
  701. TCHAR szNum[ 3 + 1 ];
  702. if (lNum < 0)
  703. {
  704. lstrcpyn( pszFile, pszUser, 9 );
  705. }
  706. else
  707. {
  708. if (lNum > 999)
  709. {
  710. return ERROR_PATH_NOT_FOUND;
  711. }
  712. lstrcpy( pszFile, TEXT("00000000") );
  713. LToT( lNum, szNum, 10 );
  714. lstrcpy( pszFile + 8 - lstrlen( szNum ), szNum );
  715. CopyMemory( pszFile, pszUser,
  716. (min( lstrlen( pszUser ), 5 )) * sizeof(TCHAR) );
  717. }
  718. lstrcat( pszFile, TEXT(".pbk") );
  719. return 0;
  720. }
  721. #endif
  722. BOOL
  723. GetPhonebookDirectory(
  724. IN DWORD dwPhonebookMode,
  725. OUT TCHAR* pszPathBuf )
  726. // Loads caller's 'pszPathBuf' (should have length MAX_PATH + 1) with the
  727. // path to the directory containing phonebook files for the given mode,
  728. // e.g. c:\nt\system32\ras\" for mode PBM_Router. Note the
  729. // trailing backslash.
  730. //
  731. // Returns true if successful, false otherwise. Caller is guaranteed that
  732. // an 8.3 filename will fit on the end of the directory without exceeding
  733. // MAX_PATH.
  734. //
  735. {
  736. BOOL bSuccess = FALSE;
  737. UINT cch;
  738. // 205217: (shaunco) PBM_System also comees from the profile now.
  739. // We pick it up using the command appdata directory returned from
  740. // SHGetFolderPath.
  741. //
  742. if (dwPhonebookMode == PBM_Personal || dwPhonebookMode == PBM_System)
  743. {
  744. HANDLE hToken = NULL;
  745. if ((OpenThreadToken(
  746. GetCurrentThread(),
  747. TOKEN_QUERY | TOKEN_IMPERSONATE,
  748. TRUE,
  749. &hToken)
  750. || OpenProcessToken(
  751. GetCurrentProcess(),
  752. TOKEN_QUERY | TOKEN_IMPERSONATE,
  753. &hToken)))
  754. {
  755. HRESULT hr;
  756. INT csidl = CSIDL_APPDATA;
  757. if (dwPhonebookMode == PBM_System)
  758. {
  759. csidl = CSIDL_COMMON_APPDATA;
  760. }
  761. hr = SHGetFolderPath(NULL, csidl, hToken, 0, pszPathBuf);
  762. if (SUCCEEDED(hr))
  763. {
  764. if(lstrlen(pszPathBuf) <=
  765. (MAX_PATH -
  766. (lstrlen(TEXT("\\Microsoft\\Network\\Connections\\Pbk\\")))))
  767. {
  768. lstrcat(pszPathBuf, TEXT("\\Microsoft\\Network\\Connections\\Pbk\\"));
  769. bSuccess = TRUE;
  770. }
  771. }
  772. else
  773. {
  774. TRACE1("ShGetFolderPath failed. hr=0x%08x", hr);
  775. }
  776. CloseHandle(hToken);
  777. }
  778. }
  779. else
  780. {
  781. // Note: RASDLG uses this case to determine the scripts directory.
  782. //
  783. cch = GetSystemDirectory(pszPathBuf, MAX_PATH + 1);
  784. if (cch != 0 && cch <= (MAX_PATH - (5 + 8 + 1 + 3)))
  785. {
  786. lstrcat(pszPathBuf, TEXT("\\Ras\\"));
  787. bSuccess = TRUE;
  788. }
  789. }
  790. return bSuccess;
  791. }
  792. BOOL
  793. GetPhonebookPath(
  794. IN PBUSER* pUser,
  795. IN DWORD dwFlags,
  796. OUT TCHAR** ppszPath,
  797. OUT DWORD* pdwPhonebookMode )
  798. // Loads caller's '*ppszPath', with the full path to the user's phonebook
  799. // file. Caller's '*pdwPhonebookMode' is set to the mode, system,
  800. // personal, or alternate. 'PUser' is the current user preferences.
  801. //
  802. // Returns true if successful, false otherwise. It is caller's
  803. // responsibility to Free the returned string.
  804. //
  805. {
  806. TCHAR szPath[ MAX_PATH + 1 ];
  807. *szPath = TEXT('\0');
  808. if (pUser)
  809. {
  810. if (pUser->dwPhonebookMode == PBM_Personal)
  811. {
  812. if (!GetPersonalPhonebookPath( pUser->pszPersonalFile, szPath ))
  813. {
  814. return FALSE;
  815. }
  816. *ppszPath = StrDup( szPath );
  817. if(NULL == *ppszPath)
  818. {
  819. return FALSE;
  820. }
  821. *pdwPhonebookMode = PBM_Personal;
  822. return TRUE;
  823. }
  824. else if (pUser->dwPhonebookMode == PBM_Alternate)
  825. {
  826. *ppszPath = StrDup( pUser->pszAlternatePath );
  827. if(NULL == *ppszPath)
  828. {
  829. return FALSE;
  830. }
  831. *pdwPhonebookMode = PBM_Alternate;
  832. return TRUE;
  833. }
  834. }
  835. // 205217: (shaunco) Admins or power users get to use the public
  836. // phonebook file. Everyone else must use their own phonebook to
  837. // prevent them from adding to/deleting from the public phonebook.
  838. // The exception is the 'no user' case when we are called from winlogon.
  839. // For this case, all edits happen in the public phonebook.
  840. //
  841. if (
  842. (dwFlags & RPBF_NoUser) ||
  843. (dwFlags & RPBF_AllUserPbk) || // XP 346918
  844. (FIsUserAdminOrPowerUser())
  845. )
  846. {
  847. TRACE("User is an admin or power user. (or no user context yet)");
  848. if (!GetPublicPhonebookPath( szPath ))
  849. {
  850. return FALSE;
  851. }
  852. *ppszPath = StrDup( szPath );
  853. if(NULL == *ppszPath)
  854. {
  855. return FALSE;
  856. }
  857. *pdwPhonebookMode = PBM_System;
  858. }
  859. else
  860. {
  861. TRACE("User is NOT an admin or power user.");
  862. if (!GetPersonalPhonebookPath( NULL, szPath ))
  863. {
  864. return FALSE;
  865. }
  866. *ppszPath = StrDup( szPath );
  867. if(NULL == *ppszPath)
  868. {
  869. return FALSE;
  870. }
  871. *pdwPhonebookMode = PBM_Personal;
  872. }
  873. return TRUE;
  874. }
  875. BOOL
  876. GetPersonalPhonebookPath(
  877. IN TCHAR* pszFile,
  878. OUT TCHAR* pszPathBuf )
  879. // Loads caller's 'pszPathBuf' (should have length MAX_PATH + 1) with the
  880. // path to the personal phonebook, (in the user's profile.)
  881. // 'PszFile' is the filename of the personal phonebook.
  882. //
  883. // Returns true if successful, false otherwise.
  884. //
  885. {
  886. if (!GetPhonebookDirectory( PBM_Personal, pszPathBuf ))
  887. {
  888. return FALSE;
  889. }
  890. // No file means use the default name for a phonebook.
  891. //
  892. if (!pszFile)
  893. {
  894. pszFile = TEXT("rasphone.pbk");
  895. }
  896. lstrcat( pszPathBuf, pszFile );
  897. return TRUE;
  898. }
  899. BOOL
  900. GetPublicPhonebookPath(
  901. OUT TCHAR* pszPathBuf )
  902. // Loads caller's 'pszPathBuf' (should have length MAX_PATH + 1) with the
  903. // path to the system phonebook, (in the all-user's profile.)
  904. //
  905. // Returns true if successful, false otherwise.
  906. //
  907. {
  908. if (!GetPhonebookDirectory( PBM_System, pszPathBuf ))
  909. {
  910. return FALSE;
  911. }
  912. lstrcat( pszPathBuf, TEXT("rasphone.pbk") );
  913. return TRUE;
  914. }
  915. DWORD
  916. InitializePbk(
  917. void )
  918. // Initialize the PBK library. This routine must be called before any
  919. // other PBK library calls. See also TerminatePbk.
  920. //
  921. {
  922. DWORD dwErr = NO_ERROR;
  923. if (!g_hmutexPb)
  924. {
  925. SECURITY_ATTRIBUTES sa;
  926. PSECURITY_DESCRIPTOR pSd;
  927. // The mutex must be accessible by everyone, even processes with
  928. // security privilege lower than the creator.
  929. //
  930. dwErr = DwAllocateSecurityDescriptorAllowAccessToWorld(&pSd);
  931. if (dwErr != 0)
  932. {
  933. return dwErr;
  934. }
  935. sa.nLength = sizeof(SECURITY_ATTRIBUTES) ;
  936. sa.lpSecurityDescriptor = pSd;
  937. sa.bInheritHandle = FALSE ;
  938. g_hmutexPb = CreateMutexA( &sa, FALSE, PBMUTEXNAME );
  939. Free(pSd);
  940. if (!g_hmutexPb)
  941. {
  942. dwErr = GetLastError();
  943. if(ERROR_ACCESS_DENIED == dwErr)
  944. {
  945. dwErr = NO_ERROR;
  946. //
  947. // Try to open the mutex for synchronization.
  948. // the mutex must already have been created.
  949. //
  950. g_hmutexPb = OpenMutexA(SYNCHRONIZE, FALSE, PBMUTEXNAME);
  951. if(NULL == g_hmutexPb)
  952. {
  953. return GetLastError();
  954. }
  955. }
  956. }
  957. }
  958. dwErr = PbkPathInfoInit(&g_PbkPathInfo);
  959. if( NO_ERROR != dwErr )
  960. {
  961. return dwErr;
  962. }
  963. #ifdef _PBK_CACHE_
  964. dwErr = PbkCacheInit();
  965. #endif
  966. return dwErr;
  967. }
  968. #if 0
  969. DWORD
  970. InitPersonalPhonebook(
  971. OUT TCHAR** ppszFile )
  972. // Creates a new personal phonebook file and initializes it to the current
  973. // contents of the public phonebook file. Returns the address of the file
  974. // name in caller's '*ppszfile' which is caller's responsibility to Free.
  975. //
  976. // Returns 0 if succesful, otherwise a non-0 error code.
  977. //
  978. {
  979. TCHAR szUser[ UNLEN + 1 ];
  980. DWORD cbUser = UNLEN + 1;
  981. TCHAR szPath[ MAX_PATH + 1 ];
  982. TCHAR* pszDirEnd;
  983. LONG lTry = -1;
  984. // Find a name for the personal phonebook that is derived from the
  985. // username and does not already exist.
  986. //
  987. if (!GetUserName( szUser, &cbUser ))
  988. {
  989. return ERROR_NO_SUCH_USER;
  990. }
  991. if (!GetPhonebookDirectory( PBM_Personal, szPath ))
  992. {
  993. return ERROR_PATH_NOT_FOUND;
  994. }
  995. pszDirEnd = &szPath[ lstrlen( szPath ) ];
  996. do
  997. {
  998. DWORD dwErr;
  999. dwErr = GetPersonalPhonebookFile( szUser, lTry++, pszDirEnd );
  1000. if (dwErr != 0)
  1001. {
  1002. return dwErr;
  1003. }
  1004. }
  1005. while (FFileExists( szPath ));
  1006. // Copy the public phonebook to the new personal phonebook.
  1007. //
  1008. {
  1009. TCHAR szPublicPath[ MAX_PATH + 1 ];
  1010. if (!GetPublicPhonebookPath( szPublicPath ))
  1011. {
  1012. return ERROR_PATH_NOT_FOUND;
  1013. }
  1014. if (!CopyFile( szPublicPath, szPath, TRUE ))
  1015. {
  1016. return GetLastError();
  1017. }
  1018. }
  1019. *ppszFile = StrDup( pszDirEnd );
  1020. if (!*ppszFile)
  1021. {
  1022. return ERROR_NOT_ENOUGH_MEMORY;
  1023. }
  1024. return 0;
  1025. }
  1026. #endif
  1027. DWORD
  1028. InsertBinary(
  1029. IN HRASFILE h,
  1030. IN CHAR* pszKey,
  1031. IN BYTE* pData,
  1032. IN DWORD cbData )
  1033. // Insert key/value line(s) with key 'pszKey' and value hex dump 'cbData'
  1034. // of 'pData' at the current line in file 'h'. The data will be split
  1035. // over multiple same-named keys, if necessary.
  1036. //
  1037. // Returns 0 if successful, otherwise a non-zero error code. The current
  1038. // line is the one added.
  1039. //
  1040. {
  1041. DWORD dwErr;
  1042. BYTE* p;
  1043. DWORD c;
  1044. p = pData;
  1045. c = 0;
  1046. while (cbData)
  1047. {
  1048. if (cbData >= IB_BytesPerLine)
  1049. {
  1050. c = IB_BytesPerLine;
  1051. }
  1052. else
  1053. {
  1054. c = cbData;
  1055. }
  1056. dwErr = InsertBinaryChunk( h, pszKey, p, c );
  1057. if (dwErr != 0)
  1058. {
  1059. return dwErr;
  1060. }
  1061. p += c;
  1062. cbData -= c;
  1063. }
  1064. return 0;
  1065. }
  1066. DWORD
  1067. InsertBinaryChunk(
  1068. IN HRASFILE h,
  1069. IN CHAR* pszKey,
  1070. IN BYTE* pData,
  1071. IN DWORD cbData )
  1072. // Insert key/value line(s) with key 'pszKey' and value hex dump 'cbData'
  1073. // of 'pData' at the current line in file 'h'. The data will be split
  1074. // over multiple same-named keys, if necessary.
  1075. //
  1076. // Returns 0 if successful, otherwise a non-zero error code. The current
  1077. // line is the one added.
  1078. //
  1079. {
  1080. CHAR szBuf[ (IB_BytesPerLine * 2) + 1 ];
  1081. CHAR* pszBuf;
  1082. BOOL fStatus;
  1083. ASSERT( cbData<=IB_BytesPerLine );
  1084. szBuf[ 0 ] = '\0';
  1085. for (pszBuf = szBuf; cbData; ++pData, --cbData)
  1086. {
  1087. *pszBuf++ = HexChar( (BYTE )(*pData / 16) );
  1088. *pszBuf++ = HexChar( (BYTE )(*pData % 16) );
  1089. }
  1090. *pszBuf = '\0';
  1091. return InsertStringA( h, pszKey, szBuf );
  1092. }
  1093. DWORD
  1094. InsertDeviceList(
  1095. IN PBFILE *pFile,
  1096. IN HRASFILE h,
  1097. IN PBENTRY* ppbentry,
  1098. IN PBLINK* ppblink )
  1099. // Inserts the list of devices associated with link 'ppblink' of phone
  1100. // book entry 'ppbentry' at the current line of file 'h'.
  1101. //
  1102. // Returns 0 if successful, otherwise a non-zero error code.
  1103. //
  1104. {
  1105. DWORD dwErr, dwFlags = 0;
  1106. PBDEVICETYPE type;
  1107. type = ppblink->pbport.pbdevicetype;
  1108. dwFlags = ppblink->pbport.dwFlags;
  1109. if (type == PBDT_Isdn)
  1110. {
  1111. // ISDN ports use a single device with the same name as the media.
  1112. //
  1113. if ((dwErr = InsertGroup(
  1114. h, GROUPKEY_Device, TEXT(ISDN_TXT) )) != 0)
  1115. {
  1116. return dwErr;
  1117. }
  1118. if ((dwErr = InsertPhoneList( h, ppblink->pdtllistPhones )) != 0)
  1119. {
  1120. return dwErr;
  1121. }
  1122. if ((dwErr = InsertLong(
  1123. h, KEY_LastSelectedPhone,
  1124. ppblink->iLastSelectedPhone )) != 0)
  1125. {
  1126. return dwErr;
  1127. }
  1128. if ((dwErr = InsertFlag(
  1129. h, KEY_PromoteAlternates,
  1130. ppblink->fPromoteAlternates )) != 0)
  1131. {
  1132. return dwErr;
  1133. }
  1134. if ((dwErr = InsertFlag(
  1135. h, KEY_TryNextAlternateOnFail,
  1136. ppblink->fTryNextAlternateOnFail )) != 0)
  1137. {
  1138. return dwErr;
  1139. }
  1140. if ((dwErr = InsertLong( h, KEY_LineType, ppblink->lLineType )) != 0)
  1141. {
  1142. return dwErr;
  1143. }
  1144. if ((dwErr = InsertFlag( h, KEY_Fallback, ppblink->fFallback )) != 0)
  1145. {
  1146. return dwErr;
  1147. }
  1148. if ((dwErr = InsertFlag(
  1149. h, KEY_Compression, ppblink->fCompression )) != 0)
  1150. {
  1151. return dwErr;
  1152. }
  1153. if ((dwErr = InsertLong(
  1154. h, KEY_Channels, ppblink->lChannels )) != 0)
  1155. {
  1156. return dwErr;
  1157. }
  1158. if ((dwErr = InsertFlag(
  1159. h, KEY_ProprietaryIsdn, ppblink->fProprietaryIsdn )) != 0)
  1160. {
  1161. return dwErr;
  1162. }
  1163. }
  1164. else if (type == PBDT_X25)
  1165. {
  1166. // Native X.25 ports are assumed to use a single device with the same
  1167. // name as the media, i.e. "x25".
  1168. //
  1169. if ((dwErr = InsertGroup( h, GROUPKEY_Device, TEXT(X25_TXT) )) != 0)
  1170. {
  1171. return dwErr;
  1172. }
  1173. if ((dwErr = InsertString(
  1174. h, KEY_X25_Address, ppbentry->pszX25Address )) != 0)
  1175. {
  1176. return dwErr;
  1177. }
  1178. if ((dwErr = InsertString(
  1179. h, KEY_X25_UserData, ppbentry->pszX25UserData )) != 0)
  1180. {
  1181. return dwErr;
  1182. }
  1183. if ((dwErr = InsertString(
  1184. h, KEY_X25_Facilities, ppbentry->pszX25Facilities )) != 0)
  1185. {
  1186. return dwErr;
  1187. }
  1188. }
  1189. else if ( (type == PBDT_Other)
  1190. || (type == PBDT_Irda)
  1191. || (type == PBDT_Vpn)
  1192. || (type == PBDT_Serial)
  1193. || (type == PBDT_Atm)
  1194. || (type == PBDT_Parallel)
  1195. || (type == PBDT_Sonet)
  1196. || (type == PBDT_Sw56)
  1197. || (type == PBDT_FrameRelay)
  1198. || (type == PBDT_PPPoE))
  1199. {
  1200. //
  1201. // If we are looking at a downlevel server (<= win2k) we
  1202. // save the device type as media.
  1203. //
  1204. RAS_RPC *pConnection = (RAS_RPC *) pFile->hConnection;
  1205. TCHAR *pszDevice = NULL;
  1206. BOOL bFreeDev = FALSE;
  1207. if(pFile->hConnection < (HANDLE)VERSION_501)
  1208. {
  1209. pszDevice = pszDeviceTypeFromRdt(RdtFromPbdt(type, dwFlags));
  1210. }
  1211. if(NULL == pszDevice)
  1212. {
  1213. pszDevice = ppblink->pbport.pszMedia;
  1214. }
  1215. else
  1216. {
  1217. bFreeDev = TRUE;
  1218. }
  1219. // "Other" ports use a single device with the same name as the media.
  1220. //
  1221. if ((dwErr = InsertGroup(
  1222. h, GROUPKEY_Device, pszDevice )) != 0)
  1223. {
  1224. if (bFreeDev) Free0(pszDevice);
  1225. return dwErr;
  1226. }
  1227. if ((dwErr = InsertPhoneList( h, ppblink->pdtllistPhones )) != 0)
  1228. {
  1229. if (bFreeDev) Free0(pszDevice);
  1230. return dwErr;
  1231. }
  1232. if ((dwErr = InsertLong(
  1233. h, KEY_LastSelectedPhone,
  1234. ppblink->iLastSelectedPhone )) != 0)
  1235. {
  1236. if (bFreeDev) Free0(pszDevice);
  1237. return dwErr;
  1238. }
  1239. if ((dwErr = InsertFlag(
  1240. h, KEY_PromoteAlternates,
  1241. ppblink->fPromoteAlternates )) != 0)
  1242. {
  1243. if (bFreeDev) Free0(pszDevice);
  1244. return dwErr;
  1245. }
  1246. if ((dwErr = InsertFlag(
  1247. h, KEY_TryNextAlternateOnFail,
  1248. ppblink->fTryNextAlternateOnFail )) != 0)
  1249. {
  1250. if (bFreeDev) Free0(pszDevice);
  1251. return dwErr;
  1252. }
  1253. // For whistler 483290
  1254. //
  1255. if (bFreeDev)
  1256. {
  1257. Free0(pszDevice);
  1258. }
  1259. }
  1260. else
  1261. {
  1262. // Serial ports may involve multiple devices, specifically a modem, an
  1263. // X.25 dialup PAD, and a post-connect switch. Pre-connect script is
  1264. // preserved, though no longer offered by UI.
  1265. //
  1266. if (ppblink->pbport.fScriptBefore
  1267. || ppblink->pbport.fScriptBeforeTerminal)
  1268. {
  1269. if ((dwErr = InsertGroup(
  1270. h, GROUPKEY_Device, TEXT(MXS_SWITCH_TXT) )) != 0)
  1271. {
  1272. return dwErr;
  1273. }
  1274. if (ppblink->pbport.fScriptBefore)
  1275. {
  1276. if ((dwErr = InsertString(
  1277. h, KEY_Name,
  1278. ppblink->pbport.pszScriptBefore )) != 0)
  1279. {
  1280. return dwErr;
  1281. }
  1282. }
  1283. if (ppblink->pbport.fScriptBeforeTerminal)
  1284. {
  1285. if ((dwErr = InsertFlag(
  1286. h, KEY_Terminal,
  1287. ppblink->pbport.fScriptBeforeTerminal )) != 0)
  1288. {
  1289. return dwErr;
  1290. }
  1291. }
  1292. if (ppblink->pbport.fScriptBefore)
  1293. {
  1294. if ((dwErr = InsertFlag(
  1295. h, KEY_Script,
  1296. ppblink->pbport.fScriptBefore )) != 0)
  1297. {
  1298. return dwErr;
  1299. }
  1300. }
  1301. }
  1302. if (((type == PBDT_Null) && !(dwFlags & PBP_F_NullModem)) ||
  1303. (type == PBDT_ComPort)
  1304. )
  1305. {
  1306. if ((dwErr = InsertGroup(
  1307. h, GROUPKEY_Device, TEXT(MXS_NULL_TXT) )) != 0)
  1308. {
  1309. return dwErr;
  1310. }
  1311. }
  1312. // pmay: 245860
  1313. //
  1314. // We must save null modems the same way we save modems in
  1315. // order to export properties such as connect bps.
  1316. //
  1317. if ((type == PBDT_Modem) ||
  1318. (dwFlags & PBP_F_NullModem))
  1319. {
  1320. if ((dwErr = InsertGroup(
  1321. h, GROUPKEY_Device, TEXT(MXS_MODEM_TXT) )) != 0)
  1322. {
  1323. return dwErr;
  1324. }
  1325. if ((dwErr = InsertPhoneList( h, ppblink->pdtllistPhones )) != 0)
  1326. {
  1327. return dwErr;
  1328. }
  1329. if ((dwErr = InsertLong(
  1330. h, KEY_LastSelectedPhone,
  1331. ppblink->iLastSelectedPhone )) != 0)
  1332. {
  1333. return dwErr;
  1334. }
  1335. if ((dwErr = InsertFlag(
  1336. h, KEY_PromoteAlternates,
  1337. ppblink->fPromoteAlternates )) != 0)
  1338. {
  1339. return dwErr;
  1340. }
  1341. if ((dwErr = InsertFlag(
  1342. h, KEY_TryNextAlternateOnFail,
  1343. ppblink->fTryNextAlternateOnFail )) != 0)
  1344. {
  1345. return dwErr;
  1346. }
  1347. if ((dwErr = InsertFlag(
  1348. h, KEY_HwFlow, ppblink->fHwFlow )) != 0)
  1349. {
  1350. return dwErr;
  1351. }
  1352. if ((dwErr = InsertFlag(
  1353. h, KEY_Ec, ppblink->fEc )) != 0)
  1354. {
  1355. return dwErr;
  1356. }
  1357. if ((dwErr = InsertFlag(
  1358. h, KEY_Ecc, ppblink->fEcc )) != 0)
  1359. {
  1360. return dwErr;
  1361. }
  1362. if ((dwErr = InsertFlag(
  1363. h, KEY_Speaker, ppblink->fSpeaker )) != 0)
  1364. {
  1365. return dwErr;
  1366. }
  1367. if ((dwErr = InsertLong(
  1368. h, KEY_MdmProtocol, ppblink->dwModemProtocol )) != 0)
  1369. {
  1370. return dwErr;
  1371. }
  1372. }
  1373. if (type == PBDT_Pad
  1374. || (type == PBDT_Modem && ppbentry->pszX25Network))
  1375. {
  1376. if ((dwErr = InsertGroup(
  1377. h, GROUPKEY_Device, TEXT(MXS_PAD_TXT) )) != 0)
  1378. {
  1379. return dwErr;
  1380. }
  1381. if ((dwErr = InsertString(
  1382. h, KEY_PAD_Type, ppbentry->pszX25Network )) != 0)
  1383. {
  1384. return dwErr;
  1385. }
  1386. if ((dwErr = InsertString(
  1387. h, KEY_PAD_Address, ppbentry->pszX25Address )) != 0)
  1388. {
  1389. return dwErr;
  1390. }
  1391. if ((dwErr = InsertString(
  1392. h, KEY_PAD_UserData, ppbentry->pszX25UserData )) != 0)
  1393. {
  1394. return dwErr;
  1395. }
  1396. if ((dwErr = InsertString(
  1397. h, KEY_PAD_Facilities, ppbentry->pszX25Facilities )) != 0)
  1398. {
  1399. return dwErr;
  1400. }
  1401. }
  1402. if (ppbentry->fScriptAfter
  1403. || ppbentry->fScriptAfterTerminal
  1404. || ppbentry->dwCustomScript)
  1405. {
  1406. if ((dwErr = InsertGroup(
  1407. h, GROUPKEY_Device, TEXT(MXS_SWITCH_TXT) )) != 0)
  1408. {
  1409. return dwErr;
  1410. }
  1411. if (ppbentry->fScriptAfter)
  1412. {
  1413. if ((dwErr = InsertString(
  1414. h, KEY_Name,
  1415. ppbentry->pszScriptAfter )) != 0)
  1416. {
  1417. return dwErr;
  1418. }
  1419. }
  1420. if (ppbentry->fScriptAfterTerminal)
  1421. {
  1422. if ((dwErr = InsertFlag(
  1423. h, KEY_Terminal,
  1424. ppbentry->fScriptAfterTerminal )) != 0)
  1425. {
  1426. return dwErr;
  1427. }
  1428. }
  1429. if (ppbentry->fScriptAfter)
  1430. {
  1431. if ((dwErr = InsertFlag(
  1432. h, KEY_Script,
  1433. ppbentry->fScriptAfter )) != 0)
  1434. {
  1435. return dwErr;
  1436. }
  1437. }
  1438. if(ppbentry->dwCustomScript)
  1439. {
  1440. if((dwErr = InsertLong(
  1441. h, KEY_CustomScript,
  1442. ppbentry->dwCustomScript)) != 0)
  1443. {
  1444. return dwErr;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. return 0;
  1450. }
  1451. DWORD
  1452. InsertFlag(
  1453. IN HRASFILE h,
  1454. IN CHAR* pszKey,
  1455. IN BOOL fValue )
  1456. // Insert a key/value line after the current line in file 'h'. The
  1457. // inserted line has a key of 'pszKey' and a value of "1" if 'fValue' is
  1458. // true or "0" otherwise. If 'pszKey' is NULL a blank line is appended.
  1459. //
  1460. // Returns 0 if successful, otherwise a non-zero error code. The current
  1461. // line is the one added.
  1462. //
  1463. {
  1464. return InsertStringA( h, pszKey, (fValue) ? "1" : "0" );
  1465. }
  1466. DWORD
  1467. InsertGroup(
  1468. IN HRASFILE h,
  1469. IN CHAR* pszGroupKey,
  1470. IN TCHAR* pszValue )
  1471. // Insert a blank line and a group header with group key 'pszGroupKey' and
  1472. // value 'pszValue' after the current line in file 'h'.
  1473. //
  1474. // Returns 0 if successful, otherwise a non-zero error code. The current
  1475. // line is the added group header.
  1476. //
  1477. {
  1478. DWORD dwErr;
  1479. if ((dwErr = InsertString( h, NULL, NULL )) != 0)
  1480. {
  1481. return dwErr;
  1482. }
  1483. if ((dwErr = InsertString( h, pszGroupKey, pszValue )) != 0)
  1484. {
  1485. return dwErr;
  1486. }
  1487. return 0;
  1488. }
  1489. DWORD
  1490. InsertLong(
  1491. IN HRASFILE h,
  1492. IN CHAR* pszKey,
  1493. IN LONG lValue )
  1494. // Insert a key/value line after the current line in file 'h'. The
  1495. // inserted line has a key of 'pszKey' and a value of 'lValue'. If
  1496. // 'pszKey' is NULL a blank line is appended.
  1497. //
  1498. // Returns 0 if successful, otherwise a non-zero error code. The current
  1499. // line is the one added.
  1500. //
  1501. {
  1502. CHAR szNum[ 33 + 1 ];
  1503. _ltoa( lValue, szNum, 10 );
  1504. return InsertStringA( h, pszKey, szNum );
  1505. }
  1506. DWORD
  1507. InsertNetComponents(
  1508. IN HRASFILE h,
  1509. IN DTLLIST* pdtllist )
  1510. // Inserts the NETCOMPONENTS group and adds lines for the list of net
  1511. // component key/value pairs in 'pdtllist' at the current line of file
  1512. // 'h'.
  1513. //
  1514. // Returns 0 if successful, otherwise a non-zero error code.
  1515. //
  1516. {
  1517. DWORD dwErr;
  1518. DTLNODE* pdtlnode;
  1519. // Insert the NETCOMPONENTS group.
  1520. //
  1521. dwErr = InsertGroup( h, GROUPKEY_NetComponents, TEXT("") );
  1522. if (dwErr != 0)
  1523. {
  1524. return dwErr;
  1525. }
  1526. // Insert a key/value pair for each listed net component.
  1527. //
  1528. for (pdtlnode = DtlGetFirstNode( pdtllist );
  1529. pdtlnode;
  1530. pdtlnode = DtlGetNextNode( pdtlnode ))
  1531. {
  1532. KEYVALUE* pKv;
  1533. CHAR* pszKeyA;
  1534. pKv = (KEYVALUE* )DtlGetData( pdtlnode );
  1535. ASSERT( pKv );
  1536. pszKeyA = StrDupAFromT( pKv->pszKey );
  1537. if (!pszKeyA)
  1538. {
  1539. return ERROR_NOT_ENOUGH_MEMORY;
  1540. }
  1541. dwErr = InsertString( h, pszKeyA, pKv->pszValue );
  1542. Free0( pszKeyA );
  1543. if (dwErr != 0)
  1544. {
  1545. return dwErr;
  1546. }
  1547. }
  1548. return 0;
  1549. }
  1550. DWORD
  1551. InsertPhoneList(
  1552. IN HRASFILE h,
  1553. IN DTLLIST* pdtllist )
  1554. // Insert key/value lines for each PBPHONE node in from 'pdtllist' after
  1555. // the current line in file 'h'.
  1556. //
  1557. // Returns 0 if successful, otherwise a non-zero error code. The current
  1558. // line is the last one added.
  1559. //
  1560. {
  1561. DWORD dwErr;
  1562. DTLNODE* pdtlnode;
  1563. for (pdtlnode = DtlGetFirstNode( pdtllist );
  1564. pdtlnode;
  1565. pdtlnode = DtlGetNextNode( pdtlnode ))
  1566. {
  1567. CHAR* pszValueA;
  1568. PBPHONE* pPhone;
  1569. pPhone = (PBPHONE* )DtlGetData( pdtlnode );
  1570. dwErr = InsertString( h, KEY_PhoneNumber, pPhone->pszPhoneNumber );
  1571. if (dwErr)
  1572. {
  1573. return dwErr;
  1574. }
  1575. dwErr = InsertString( h, KEY_AreaCode, pPhone->pszAreaCode );
  1576. if (dwErr)
  1577. {
  1578. return dwErr;
  1579. }
  1580. dwErr = InsertLong( h, KEY_CountryCode, pPhone->dwCountryCode );
  1581. if (dwErr)
  1582. {
  1583. return dwErr;
  1584. }
  1585. dwErr = InsertLong( h, KEY_CountryID, pPhone->dwCountryID );
  1586. if (dwErr)
  1587. {
  1588. return dwErr;
  1589. }
  1590. dwErr = InsertFlag( h, KEY_UseDialingRules, pPhone->fUseDialingRules );
  1591. if (dwErr)
  1592. {
  1593. return dwErr;
  1594. }
  1595. dwErr = InsertString( h, KEY_Comment, pPhone->pszComment );
  1596. if (dwErr)
  1597. {
  1598. return dwErr;
  1599. }
  1600. }
  1601. return 0;
  1602. }
  1603. DWORD
  1604. InsertSection(
  1605. IN HRASFILE h,
  1606. IN TCHAR* pszSectionName )
  1607. // Insert a section header with name 'pszSectionName' and a trailing blank
  1608. // line in file 'h' after the current line.
  1609. //
  1610. // Returns 0 if successful, otherwise a non-zero error code. The current
  1611. // line is the added section header.
  1612. //
  1613. {
  1614. DWORD dwErr;
  1615. CHAR* pszSectionNameA;
  1616. BOOL fStatus;
  1617. ASSERT( pszSectionName );
  1618. if ((dwErr = InsertString( h, NULL, NULL )) != 0)
  1619. {
  1620. return dwErr;
  1621. }
  1622. pszSectionNameA = StrDupAFromT( pszSectionName );
  1623. if (!pszSectionNameA)
  1624. {
  1625. return ERROR_NOT_ENOUGH_MEMORY;
  1626. }
  1627. fStatus = RasfilePutSectionName( h, pszSectionNameA );
  1628. Free( pszSectionNameA );
  1629. if (!fStatus)
  1630. {
  1631. return ERROR_NOT_ENOUGH_MEMORY;
  1632. }
  1633. if ((dwErr = InsertString( h, NULL, NULL )) != 0)
  1634. {
  1635. return dwErr;
  1636. }
  1637. RasfileFindFirstLine( h, RFL_SECTION, RFS_SECTION );
  1638. return 0;
  1639. }
  1640. DWORD
  1641. InsertString(
  1642. IN HRASFILE h,
  1643. IN CHAR* pszKey,
  1644. IN TCHAR* pszValue )
  1645. // Insert a key/value line with key 'pszKey' and value 'pszValue' after
  1646. // the current line in file 'h'. If 'pszKey' is NULL a blank line is
  1647. // appended.
  1648. //
  1649. // Returns 0 if successful, otherwise a non-zero error code. The current
  1650. // line is the one added.
  1651. //
  1652. {
  1653. BOOL fStatus;
  1654. CHAR* pszValueA;
  1655. if (pszValue)
  1656. {
  1657. pszValueA = StrDupAFromT( pszValue );
  1658. if (!pszValueA)
  1659. {
  1660. return ERROR_NOT_ENOUGH_MEMORY;
  1661. }
  1662. }
  1663. else
  1664. {
  1665. pszValueA = NULL;
  1666. }
  1667. fStatus = InsertStringA( h, pszKey, pszValueA );
  1668. Free0( pszValueA );
  1669. return fStatus;
  1670. }
  1671. DWORD
  1672. InsertStringA(
  1673. IN HRASFILE h,
  1674. IN CHAR* pszKey,
  1675. IN CHAR* pszValue )
  1676. // Insert a key/value line with key 'pszKey' and value 'pszValue' after
  1677. // the current line in file 'h'. If 'pszKey' is NULL a blank line is
  1678. // appended.
  1679. //
  1680. // Returns 0 if successful, otherwise a non-zero error code. The current
  1681. // line is the one added.
  1682. //
  1683. {
  1684. if (!RasfileInsertLine( h, "", FALSE ))
  1685. {
  1686. return ERROR_NOT_ENOUGH_MEMORY;
  1687. }
  1688. if (!RasfileFindNextLine( h, RFL_ANY, RFS_FILE ))
  1689. {
  1690. RasfileFindFirstLine( h, RFL_ANY, RFS_FILE );
  1691. }
  1692. if (pszKey)
  1693. {
  1694. CHAR* pszValueA;
  1695. if (!pszValue)
  1696. {
  1697. pszValue = "";
  1698. }
  1699. if (!RasfilePutKeyValueFields( h, pszKey, pszValue ))
  1700. {
  1701. return ERROR_NOT_ENOUGH_MEMORY;
  1702. }
  1703. }
  1704. return 0;
  1705. }
  1706. DWORD
  1707. InsertStringList(
  1708. IN HRASFILE h,
  1709. IN CHAR* pszKey,
  1710. IN DTLLIST* pdtllistValues )
  1711. // Insert key/value lines with key 'pszKey' and values from
  1712. // 'pdtllistValues' after the current line in file 'h'.
  1713. //
  1714. // Returns 0 if successful, otherwise a non-zero error code. The current
  1715. // line is the last one added.
  1716. //
  1717. {
  1718. DTLNODE* pdtlnode;
  1719. for (pdtlnode = DtlGetFirstNode( pdtllistValues );
  1720. pdtlnode;
  1721. pdtlnode = DtlGetNextNode( pdtlnode ))
  1722. {
  1723. CHAR* pszValueA;
  1724. BOOL fStatus;
  1725. if (!RasfileInsertLine( h, "", FALSE ))
  1726. {
  1727. return ERROR_NOT_ENOUGH_MEMORY;
  1728. }
  1729. if (!RasfileFindNextLine( h, RFL_ANY, RFS_FILE ))
  1730. {
  1731. RasfileFindFirstLine( h, RFL_ANY, RFS_FILE );
  1732. }
  1733. pszValueA = StrDupAFromT( (TCHAR* )DtlGetData( pdtlnode ) );
  1734. if (!pszValueA)
  1735. {
  1736. return ERROR_NOT_ENOUGH_MEMORY;
  1737. }
  1738. fStatus = RasfilePutKeyValueFields( h, pszKey, pszValueA );
  1739. Free( pszValueA );
  1740. if (!fStatus)
  1741. {
  1742. return ERROR_NOT_ENOUGH_MEMORY;
  1743. }
  1744. }
  1745. return 0;
  1746. }
  1747. BOOL
  1748. IsDeviceLine(
  1749. IN CHAR* pszText )
  1750. // Returns true if the text of the line, 'pszText', indicates the line is
  1751. // a DEVICE subsection header, false otherwise.
  1752. //
  1753. {
  1754. return
  1755. (StrNCmpA( pszText, GROUPID_Device, sizeof(GROUPID_Device) - 1 ) == 0);
  1756. }
  1757. BOOL
  1758. IsGroup(
  1759. IN CHAR* pszText )
  1760. // Returns true if the text of the line, 'pszText', indicates the line is
  1761. // a valid subsection header, false otherwise. The address of this
  1762. // routine is passed to the RASFILE library on RasFileLoad.
  1763. //
  1764. {
  1765. return
  1766. IsMediaLine( pszText )
  1767. || IsDeviceLine( pszText )
  1768. || IsNetComponentsLine( pszText );
  1769. }
  1770. BOOL
  1771. IsMediaLine(
  1772. IN CHAR* pszText )
  1773. // Returns true if the text of the line, 'pszText', indicates the line is
  1774. // a MEDIA subsection header, false otherwise.
  1775. //
  1776. {
  1777. return
  1778. (StrNCmpA( pszText, GROUPID_Media, sizeof(GROUPID_Media) - 1 ) == 0);
  1779. }
  1780. BOOL
  1781. IsNetComponentsLine(
  1782. IN CHAR* pszText )
  1783. // Returns true if the text of the line, 'pszText', indicates the line is
  1784. // a NETCOMPONENTS subsection header, false otherwise.
  1785. //
  1786. {
  1787. return
  1788. (StrNCmpA(
  1789. pszText,
  1790. GROUPID_NetComponents,
  1791. sizeof(GROUPID_NetComponents) - 1 ) == 0);
  1792. }
  1793. DWORD
  1794. ModifyEntryList(
  1795. IN PBFILE* pFile )
  1796. // Update all dirty entries in phone book file 'pFile'.
  1797. //
  1798. // Returns 0 if successful, otherwise a non-zero error code.
  1799. //
  1800. {
  1801. DWORD dwErr = 0;
  1802. DTLNODE* pdtlnodeEntry;
  1803. DTLNODE* pdtlnodeLink;
  1804. HRASFILE h;
  1805. h = pFile->hrasfile;
  1806. for (pdtlnodeEntry = DtlGetFirstNode( pFile->pdtllistEntries );
  1807. pdtlnodeEntry;
  1808. pdtlnodeEntry = DtlGetNextNode( pdtlnodeEntry ))
  1809. {
  1810. PBENTRY* ppbentry = (PBENTRY* )DtlGetData( pdtlnodeEntry );
  1811. // if (!ppbentry->fDirty || ppbentry->fCustom)
  1812. //for bug 174260
  1813. if (!ppbentry->fDirty )
  1814. {
  1815. continue;
  1816. }
  1817. // Delete the current version of the entry, if any.
  1818. //
  1819. {
  1820. CHAR* pszEntryNameA;
  1821. ASSERT( ppbentry->pszEntryName );
  1822. pszEntryNameA = StrDupAFromT( ppbentry->pszEntryName );
  1823. if (!pszEntryNameA)
  1824. {
  1825. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1826. break;
  1827. }
  1828. if (RasfileFindSectionLine( h, pszEntryNameA, TRUE ))
  1829. {
  1830. DeleteCurrentSection( h );
  1831. }
  1832. Free( pszEntryNameA );
  1833. }
  1834. // Append a blank line followed by a section header and the entry
  1835. // description to the end of the file.
  1836. //
  1837. RasfileFindLastLine( h, RFL_ANY, RFS_FILE );
  1838. if ((dwErr = InsertSection( h, ppbentry->pszEntryName )) != 0)
  1839. {
  1840. break;
  1841. }
  1842. if ((dwErr = InsertLong(
  1843. h, KEY_Encoding,
  1844. (LONG ) EN_Standard )) != 0)
  1845. {
  1846. break;
  1847. }
  1848. if ((dwErr = InsertLong(
  1849. h, KEY_Type,
  1850. (LONG )ppbentry->dwType )) != 0)
  1851. {
  1852. break;
  1853. }
  1854. if ((dwErr = InsertFlag(
  1855. h, KEY_AutoLogon, ppbentry->fAutoLogon )) != 0)
  1856. {
  1857. break;
  1858. }
  1859. if ((dwErr = InsertFlag(
  1860. h, KEY_UseRasCredentials, ppbentry->fUseRasCredentials)) != 0)
  1861. {
  1862. break;
  1863. }
  1864. if ((dwErr = InsertLong(
  1865. h, KEY_UID,
  1866. (LONG )ppbentry->dwDialParamsUID )) != 0)
  1867. {
  1868. break;
  1869. }
  1870. if(ppbentry->pGuid)
  1871. {
  1872. if ((dwErr = InsertBinary(
  1873. h, KEY_Guid,
  1874. (BYTE* )ppbentry->pGuid, sizeof( GUID ) )) != 0)
  1875. {
  1876. return dwErr;
  1877. }
  1878. }
  1879. if ((dwErr = InsertLong(
  1880. h, KEY_BaseProtocol,
  1881. (LONG )ppbentry->dwBaseProtocol )) != 0)
  1882. {
  1883. break;
  1884. }
  1885. if ((dwErr = InsertLong(
  1886. h, KEY_VpnStrategy,
  1887. (LONG )ppbentry->dwVpnStrategy )) != 0)
  1888. {
  1889. break;
  1890. }
  1891. #if AMB
  1892. if ((dwErr = InsertLong(
  1893. h, KEY_Authentication,
  1894. (LONG )ppbentry->dwAuthentication )) != 0)
  1895. {
  1896. break;
  1897. }
  1898. #endif
  1899. if ((dwErr = InsertLong(
  1900. h, KEY_ExcludedProtocols,
  1901. (LONG )ppbentry->dwfExcludedProtocols )) != 0)
  1902. {
  1903. break;
  1904. }
  1905. if ((dwErr = InsertFlag(
  1906. h, KEY_LcpExtensions,
  1907. ppbentry->fLcpExtensions )) != 0)
  1908. {
  1909. break;
  1910. }
  1911. if ((dwErr = InsertLong(
  1912. h, KEY_DataEncryption,
  1913. ppbentry->dwDataEncryption )) != 0)
  1914. {
  1915. break;
  1916. }
  1917. if ((dwErr = InsertFlag(
  1918. h, KEY_SwCompression,
  1919. ppbentry->fSwCompression )) != 0)
  1920. {
  1921. break;
  1922. }
  1923. if ((dwErr = InsertFlag(
  1924. h, KEY_NegotiateMultilinkAlways,
  1925. ppbentry->fNegotiateMultilinkAlways )) != 0)
  1926. {
  1927. break;
  1928. }
  1929. if ((dwErr = InsertFlag(
  1930. h, KEY_SkipNwcWarning,
  1931. ppbentry->fSkipNwcWarning )) != 0)
  1932. {
  1933. break;
  1934. }
  1935. if ((dwErr = InsertFlag(
  1936. h, KEY_SkipDownLevelDialog,
  1937. ppbentry->fSkipDownLevelDialog )) != 0)
  1938. {
  1939. break;
  1940. }
  1941. if ((dwErr = InsertFlag(
  1942. h, KEY_SkipDoubleDialDialog,
  1943. ppbentry->fSkipDoubleDialDialog )) != 0)
  1944. {
  1945. break;
  1946. }
  1947. if ((dwErr = InsertLong(
  1948. h, KEY_DialMode,
  1949. (LONG )ppbentry->dwDialMode )) != 0)
  1950. {
  1951. break;
  1952. }
  1953. if ((dwErr = InsertLong(
  1954. h, KEY_DialPercent,
  1955. (LONG )ppbentry->dwDialPercent )) != 0)
  1956. {
  1957. break;
  1958. }
  1959. if ((dwErr = InsertLong(
  1960. h, KEY_DialSeconds,
  1961. (LONG )ppbentry->dwDialSeconds )) != 0)
  1962. {
  1963. break;
  1964. }
  1965. if ((dwErr = InsertLong(
  1966. h, KEY_HangUpPercent,
  1967. (LONG )ppbentry->dwHangUpPercent )) != 0)
  1968. {
  1969. break;
  1970. }
  1971. if ((dwErr = InsertLong(
  1972. h, KEY_HangUpSeconds,
  1973. (LONG )ppbentry->dwHangUpSeconds )) != 0)
  1974. {
  1975. break;
  1976. }
  1977. if ((dwErr = InsertLong(
  1978. h, KEY_OverridePref,
  1979. ppbentry->dwfOverridePref )) != 0)
  1980. {
  1981. break;
  1982. }
  1983. if ((dwErr = InsertLong(
  1984. h, KEY_RedialAttempts,
  1985. ppbentry->dwRedialAttempts )) != 0)
  1986. {
  1987. break;
  1988. }
  1989. if ((dwErr = InsertLong(
  1990. h, KEY_RedialSeconds,
  1991. ppbentry->dwRedialSeconds )) != 0)
  1992. {
  1993. break;
  1994. }
  1995. if ((dwErr = InsertLong(
  1996. h, KEY_IdleDisconnectSeconds,
  1997. ppbentry->lIdleDisconnectSeconds )) != 0)
  1998. {
  1999. break;
  2000. }
  2001. if ((dwErr = InsertFlag(
  2002. h, KEY_RedialOnLinkFailure,
  2003. ppbentry->fRedialOnLinkFailure )) != 0)
  2004. {
  2005. break;
  2006. }
  2007. if ((dwErr = InsertLong(
  2008. h, KEY_CallbackMode,
  2009. ppbentry->dwCallbackMode )) != 0)
  2010. {
  2011. break;
  2012. }
  2013. if ((dwErr = InsertString(
  2014. h, KEY_CustomDialDll,
  2015. ppbentry->pszCustomDialDll )) != 0)
  2016. {
  2017. return dwErr;
  2018. }
  2019. if ((dwErr = InsertString(
  2020. h, KEY_CustomDialFunc,
  2021. ppbentry->pszCustomDialFunc )) != 0)
  2022. {
  2023. return dwErr;
  2024. }
  2025. if ((dwErr = InsertString(
  2026. h, KEY_CustomDialerName,
  2027. ppbentry->pszCustomDialerName)) != 0)
  2028. {
  2029. return dwErr;
  2030. }
  2031. if ((dwErr = InsertFlag(
  2032. h, KEY_AuthenticateServer,
  2033. ppbentry->fAuthenticateServer )) != 0)
  2034. {
  2035. return dwErr;
  2036. }
  2037. if ((dwErr = InsertFlag(
  2038. h, KEY_ShareMsFilePrint,
  2039. ppbentry->fShareMsFilePrint )) != 0)
  2040. {
  2041. return dwErr;
  2042. }
  2043. if ((dwErr = InsertFlag(
  2044. h, KEY_BindMsNetClient,
  2045. ppbentry->fBindMsNetClient )) != 0)
  2046. {
  2047. return dwErr;
  2048. }
  2049. if ((dwErr = InsertFlag(
  2050. h, KEY_SharedPhoneNumbers,
  2051. ppbentry->fSharedPhoneNumbers )) != 0)
  2052. {
  2053. return dwErr;
  2054. }
  2055. if ((dwErr = InsertFlag(
  2056. h, KEY_GlobalDeviceSettings,
  2057. ppbentry->fGlobalDeviceSettings)) != 0)
  2058. {
  2059. return dwErr;
  2060. }
  2061. if ((dwErr = InsertString(
  2062. h, KEY_PrerequisiteEntry,
  2063. ppbentry->pszPrerequisiteEntry )) != 0)
  2064. {
  2065. return dwErr;
  2066. }
  2067. if ((dwErr = InsertString(
  2068. h, KEY_PrerequisitePbk,
  2069. ppbentry->pszPrerequisitePbk )) != 0)
  2070. {
  2071. return dwErr;
  2072. }
  2073. if ((dwErr = InsertString(
  2074. h, KEY_PreferredPort,
  2075. ppbentry->pszPreferredPort )) != 0)
  2076. {
  2077. return dwErr;
  2078. }
  2079. if ((dwErr = InsertString(
  2080. h, KEY_PreferredDevice,
  2081. ppbentry->pszPreferredDevice )) != 0)
  2082. {
  2083. return dwErr;
  2084. }
  2085. //For .Net 639551
  2086. if ((dwErr = InsertLong(
  2087. h, KEY_PreferredBps,
  2088. ppbentry->dwPreferredBps)) != 0)
  2089. {
  2090. return dwErr;
  2091. }
  2092. if ((dwErr = InsertFlag(
  2093. h, KEY_PreferredHwFlow,
  2094. ppbentry->fPreferredHwFlow)) != 0)
  2095. {
  2096. return dwErr;
  2097. }
  2098. if ((dwErr = InsertFlag(
  2099. h, KEY_PreferredEc,
  2100. ppbentry->fPreferredEc)) != 0)
  2101. {
  2102. return dwErr;
  2103. }
  2104. if ((dwErr = InsertFlag(
  2105. h, KEY_PreferredEcc,
  2106. ppbentry->fPreferredEcc)) != 0)
  2107. {
  2108. return dwErr;
  2109. }
  2110. if ((dwErr = InsertLong(
  2111. h, KEY_PreferredSpeaker,
  2112. ppbentry->fPreferredSpeaker)) != 0)
  2113. {
  2114. return dwErr;
  2115. }
  2116. //For whistler bug 402522
  2117. //
  2118. if ((dwErr = InsertLong(
  2119. h, KEY_PreferredModemProtocol,
  2120. ppbentry->dwPreferredModemProtocol)) != 0)
  2121. {
  2122. return dwErr;
  2123. }
  2124. if ((dwErr = InsertFlag(
  2125. h, KEY_PreviewUserPw,
  2126. ppbentry->fPreviewUserPw )) != 0)
  2127. {
  2128. return dwErr;
  2129. }
  2130. if ((dwErr = InsertFlag(
  2131. h, KEY_PreviewDomain,
  2132. ppbentry->fPreviewDomain )) != 0)
  2133. {
  2134. return dwErr;
  2135. }
  2136. if ((dwErr = InsertFlag(
  2137. h, KEY_PreviewPhoneNumber,
  2138. ppbentry->fPreviewPhoneNumber )) != 0)
  2139. {
  2140. return dwErr;
  2141. }
  2142. if ((dwErr = InsertFlag(
  2143. h, KEY_ShowDialingProgress,
  2144. ppbentry->fShowDialingProgress )) != 0)
  2145. {
  2146. return dwErr;
  2147. }
  2148. if ((dwErr = InsertFlag(
  2149. h, KEY_ShowMonitorIconInTaskBar,
  2150. ppbentry->fShowMonitorIconInTaskBar )) != 0)
  2151. {
  2152. return dwErr;
  2153. }
  2154. if ((dwErr = InsertLong(
  2155. h, KEY_CustomAuthKey,
  2156. ppbentry->dwCustomAuthKey )) != 0)
  2157. {
  2158. return dwErr;
  2159. }
  2160. if(ppbentry->pCustomAuthData)
  2161. {
  2162. if ((dwErr = InsertBinary(
  2163. h, KEY_CustomAuthData,
  2164. ppbentry->pCustomAuthData,
  2165. ppbentry->cbCustomAuthData )) != 0)
  2166. {
  2167. return dwErr;
  2168. }
  2169. }
  2170. // Insert the IP addressing parameters for both PPP/SLIP.
  2171. //
  2172. if ((dwErr = InsertLong(
  2173. h, KEY_AuthRestrictions,
  2174. ppbentry->dwAuthRestrictions )) != 0)
  2175. {
  2176. return dwErr;
  2177. }
  2178. if ((dwErr = InsertLong(
  2179. h, KEY_TypicalAuth,
  2180. ppbentry->dwTypicalAuth )) != 0)
  2181. {
  2182. return dwErr;
  2183. }
  2184. if ((dwErr = InsertFlag(
  2185. h, KEY_IpPrioritizeRemote,
  2186. ppbentry->fIpPrioritizeRemote )) != 0)
  2187. {
  2188. return dwErr;
  2189. }
  2190. if ((dwErr = InsertFlag(
  2191. h, KEY_IpHeaderCompression,
  2192. ppbentry->fIpHeaderCompression )) != 0)
  2193. {
  2194. return dwErr;
  2195. }
  2196. if ((dwErr = InsertString(
  2197. h, KEY_IpAddress,
  2198. (ppbentry->pszIpAddress)
  2199. ? ppbentry->pszIpAddress : TEXT("0.0.0.0") )) != 0)
  2200. {
  2201. return dwErr;
  2202. }
  2203. if ((dwErr = InsertString(
  2204. h, KEY_IpDnsAddress,
  2205. (ppbentry->pszIpDnsAddress)
  2206. ? ppbentry->pszIpDnsAddress : TEXT("0.0.0.0") )) != 0)
  2207. {
  2208. return dwErr;
  2209. }
  2210. if ((dwErr = InsertString(
  2211. h, KEY_IpDns2Address,
  2212. (ppbentry->pszIpDns2Address)
  2213. ? ppbentry->pszIpDns2Address : TEXT("0.0.0.0") )) != 0)
  2214. {
  2215. return dwErr;
  2216. }
  2217. if ((dwErr = InsertString(
  2218. h, KEY_IpWinsAddress,
  2219. (ppbentry->pszIpWinsAddress)
  2220. ? ppbentry->pszIpWinsAddress : TEXT("0.0.0.0") )) != 0)
  2221. {
  2222. return dwErr;
  2223. }
  2224. if ((dwErr = InsertString(
  2225. h, KEY_IpWins2Address,
  2226. (ppbentry->pszIpWins2Address)
  2227. ? ppbentry->pszIpWins2Address : TEXT("0.0.0.0") )) != 0)
  2228. {
  2229. return dwErr;
  2230. }
  2231. // Next two actually used for PPP only.
  2232. //
  2233. if ((dwErr = InsertLong(
  2234. h, KEY_IpAddressSource,
  2235. ppbentry->dwIpAddressSource )) != 0)
  2236. {
  2237. return dwErr;
  2238. }
  2239. if ((dwErr = InsertLong(
  2240. h, KEY_IpNameSource,
  2241. ppbentry->dwIpNameSource )) != 0)
  2242. {
  2243. return dwErr;
  2244. }
  2245. // Next one actually used for SLIP only.
  2246. //
  2247. if ((dwErr = InsertLong(
  2248. h, KEY_IpFrameSize, ppbentry->dwFrameSize )) != 0)
  2249. {
  2250. return dwErr;
  2251. }
  2252. if ((dwErr = InsertLong(
  2253. h, KEY_IpDnsFlags, ppbentry->dwIpDnsFlags )) != 0)
  2254. {
  2255. return dwErr;
  2256. }
  2257. if ((dwErr = InsertLong(
  2258. h, KEY_IpNbtFlags, ppbentry->dwIpNbtFlags )) != 0)
  2259. {
  2260. return dwErr;
  2261. }
  2262. // Whistler bug 300933
  2263. //
  2264. if ((dwErr = InsertLong(
  2265. h, KEY_TcpWindowSize, ppbentry->dwTcpWindowSize )) != 0)
  2266. {
  2267. return dwErr;
  2268. }
  2269. // Add the use flag
  2270. //
  2271. if ((dwErr = InsertLong(
  2272. h, KEY_UseFlags,
  2273. ppbentry->dwUseFlags )) != 0)
  2274. {
  2275. return dwErr;
  2276. }
  2277. // Add IpSec flags for whistler bug 193987 gangz
  2278. //
  2279. if ((dwErr = InsertLong(
  2280. h, KEY_IpSecFlags,
  2281. ppbentry->dwIpSecFlags )) != 0)
  2282. {
  2283. return dwErr;
  2284. }
  2285. if ((dwErr = InsertString(
  2286. h, KEY_IpDnsSuffix,
  2287. ppbentry->pszIpDnsSuffix)) != 0)
  2288. {
  2289. return dwErr;
  2290. }
  2291. // Insert the net components section.
  2292. //
  2293. InsertNetComponents( h, ppbentry->pdtllistNetComponents );
  2294. // Append the MEDIA subsections.
  2295. //
  2296. for (pdtlnodeLink = DtlGetFirstNode( ppbentry->pdtllistLinks );
  2297. pdtlnodeLink;
  2298. pdtlnodeLink = DtlGetNextNode( pdtlnodeLink ))
  2299. {
  2300. PBLINK* ppblink;
  2301. TCHAR* pszMedia;
  2302. ppblink = (PBLINK* )DtlGetData( pdtlnodeLink );
  2303. ASSERT( ppblink );
  2304. pszMedia = ppblink->pbport.pszMedia;
  2305. if ((dwErr = InsertGroup( h, GROUPKEY_Media, pszMedia )) != 0)
  2306. {
  2307. break;
  2308. }
  2309. if ((dwErr = InsertString(
  2310. h, KEY_Port, ppblink->pbport.pszPort )) != 0)
  2311. {
  2312. break;
  2313. }
  2314. if (ppblink->pbport.pszDevice)
  2315. {
  2316. if ((dwErr = InsertString(
  2317. h, KEY_Device, ppblink->pbport.pszDevice )) != 0)
  2318. {
  2319. break;
  2320. }
  2321. }
  2322. if ( (ppblink->pbport.pbdevicetype == PBDT_Modem) ||
  2323. (ppblink->pbport.dwFlags & PBP_F_NullModem)
  2324. )
  2325. {
  2326. if ((dwErr = InsertLong(
  2327. h, KEY_InitBps, ppblink->dwBps )) != 0)
  2328. {
  2329. break;
  2330. }
  2331. }
  2332. // Append the device subsection lines.
  2333. //
  2334. RasfileFindLastLine( h, RFL_ANYACTIVE, RFS_GROUP );
  2335. if ((dwErr = InsertDeviceList( pFile, h, ppbentry, ppblink )) != 0)
  2336. {
  2337. break;
  2338. }
  2339. ppbentry->fDirty = FALSE;
  2340. }
  2341. }
  2342. return dwErr;
  2343. }
  2344. DWORD
  2345. ReadBinary(
  2346. IN HRASFILE h,
  2347. IN RFSCOPE rfscope,
  2348. IN CHAR* pszKey,
  2349. OUT BYTE** ppResult,
  2350. OUT DWORD* pcb )
  2351. // Utility routine to read a string value from the next line in the scope
  2352. // 'rfscope' with key 'pszKey'. The result is placed in the allocated
  2353. // '*ppszResult' buffer. The current line is reset to the start of the
  2354. // scope if the call was successful.
  2355. //
  2356. // Returns 0 if successful, or a non-zero error code. "Not found" is
  2357. // considered successful, in which case '*ppszResult' is not changed.
  2358. // Caller is responsible for freeing the returned '*ppszResult' buffer.
  2359. //
  2360. {
  2361. DWORD cb;
  2362. DWORD cbLine;
  2363. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ] = "\0";
  2364. CHAR* pch = NULL;
  2365. BYTE* pResult = NULL;
  2366. BYTE* pLineResult = NULL;
  2367. BYTE* pTmp = NULL;
  2368. cb = cbLine = 0;
  2369. while (RasfileFindNextKeyLine( h, pszKey, rfscope ))
  2370. {
  2371. if (!RasfileGetKeyValueFields( h, NULL, szValue ))
  2372. {
  2373. Free0( pResult );
  2374. return ERROR_NOT_ENOUGH_MEMORY;
  2375. }
  2376. cbLine = lstrlenA( szValue );
  2377. if (cbLine & 1)
  2378. {
  2379. Free0( pResult );
  2380. return ERROR_CORRUPT_PHONEBOOK;
  2381. }
  2382. cbLine /= 2;
  2383. cb += cbLine;
  2384. if (pResult)
  2385. {
  2386. // For whistler 517007
  2387. //
  2388. pTmp = Realloc( pResult, cb );
  2389. if( pTmp )
  2390. {
  2391. pResult = pTmp;
  2392. }
  2393. else
  2394. {
  2395. Free(pResult);
  2396. pResult = NULL;
  2397. }
  2398. }
  2399. else
  2400. {
  2401. pResult = Malloc( cb );
  2402. }
  2403. if (!pResult)
  2404. {
  2405. return ERROR_NOT_ENOUGH_MEMORY;
  2406. }
  2407. pLineResult = pResult + (cb - cbLine);
  2408. pch = szValue;
  2409. while (*pch != '\0')
  2410. {
  2411. *pLineResult = HexValue( *pch++ ) * 16;
  2412. *pLineResult += HexValue( *pch++ );
  2413. ++pLineResult;
  2414. }
  2415. }
  2416. *ppResult = pResult;
  2417. *pcb = cb;
  2418. return 0;
  2419. }
  2420. DWORD
  2421. ReadDeviceList(
  2422. IN HRASFILE h,
  2423. IN STRDUP_T_FROM_A_FUNC pStrDupTFromA,
  2424. IN OUT PBENTRY* ppbentry,
  2425. IN OUT PBLINK* ppblink,
  2426. IN BOOL fUnconfiguredPort,
  2427. IN BOOL* pfDisableSpeaker )
  2428. // Reads all DEVICE subsections the section from the first subsection
  2429. // following the current position in phonebook file 'h'. Caller's
  2430. // '*ppbentry' and '*ppblink' buffer is loaded with information extracted
  2431. // from the subsections. 'FUnconfiguredPort' is true if the port for the
  2432. // link was unconfigured. In this case, data found/not-found by this
  2433. // routine helps determine whether the link was an MXS modem link.
  2434. // 'pfDisableSpeaker' is the address of the old speaker setting or NULL to
  2435. // read it from the file.
  2436. //
  2437. // Returns 0 if successful, ERROR_CORRUPT_PHONEBOOK if any subsection
  2438. // other than a DEVICE subsection is encountered, or another non-0 error
  2439. // code indicating a fatal error.
  2440. //
  2441. {
  2442. INT i;
  2443. DWORD dwErr;
  2444. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ];
  2445. BOOL fPreconnectFound = FALSE;
  2446. BOOL fModemFound = FALSE;
  2447. BOOL fPadFound = FALSE;
  2448. BOOL fPostconnectFound = FALSE;
  2449. BOOL fDirty = FALSE;
  2450. // For each subsection...
  2451. //
  2452. while (RasfileFindNextLine( h, RFL_GROUP, RFS_SECTION ))
  2453. {
  2454. CHAR* pszLine;
  2455. pszLine = (CHAR* )RasfileGetLine( h );
  2456. if (IsMediaLine( pszLine ))
  2457. {
  2458. RasfileFindPrevLine( h, RFL_ANY, RFS_SECTION );
  2459. break;
  2460. }
  2461. if (!IsDeviceLine( pszLine ))
  2462. {
  2463. return ERROR_CORRUPT_PHONEBOOK;
  2464. }
  2465. RasfileGetKeyValueFields( h, NULL, szValue );
  2466. TRACE1( "Reading device group \"%s\"", szValue );
  2467. // For whistler 524726
  2468. if( CSTR_EQUAL == CompareStringA(
  2469. LOCALE_INVARIANT,
  2470. NORM_IGNORECASE,
  2471. ISDN_TXT,
  2472. -1,
  2473. szValue,
  2474. -1
  2475. )
  2476. )
  2477. {
  2478. // It's an ISDN device.
  2479. //
  2480. ppblink->pbport.pbdevicetype = PBDT_Isdn;
  2481. if ((dwErr = ReadPhoneList( h, RFS_GROUP,
  2482. &ppblink->pdtllistPhones,
  2483. &fDirty )) != 0)
  2484. {
  2485. return dwErr;
  2486. }
  2487. if ((dwErr = ReadLong( h, RFS_GROUP,
  2488. KEY_LastSelectedPhone,
  2489. &ppblink->iLastSelectedPhone )) != 0)
  2490. {
  2491. return dwErr;
  2492. }
  2493. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2494. KEY_PromoteAlternates,
  2495. &ppblink->fPromoteAlternates )) != 0)
  2496. {
  2497. return dwErr;
  2498. }
  2499. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2500. KEY_TryNextAlternateOnFail,
  2501. &ppblink->fTryNextAlternateOnFail )) != 0)
  2502. {
  2503. return dwErr;
  2504. }
  2505. if ((dwErr = ReadLong( h, RFS_GROUP,
  2506. KEY_LineType, &ppblink->lLineType )) != 0)
  2507. {
  2508. return dwErr;
  2509. }
  2510. if (ppblink->lLineType < 0 || ppblink->lLineType > 2)
  2511. ppblink->lLineType = 0;
  2512. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2513. KEY_Fallback, &ppblink->fFallback )) != 0)
  2514. {
  2515. return dwErr;
  2516. }
  2517. // Default is true if not found. Default for new entry is false,
  2518. // so must set this before reading the entry.
  2519. //
  2520. ppblink->fProprietaryIsdn = TRUE;
  2521. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2522. KEY_ProprietaryIsdn, &ppblink->fProprietaryIsdn )) != 0)
  2523. {
  2524. return dwErr;
  2525. }
  2526. // If "Channels" is not found assume it's not proprietary. This
  2527. // covers a case that never shipped outside the NT group.
  2528. //
  2529. {
  2530. LONG lChannels = -1;
  2531. if ((dwErr = ReadLong( h, RFS_GROUP,
  2532. KEY_Channels, &lChannels )) != 0)
  2533. {
  2534. return dwErr;
  2535. }
  2536. if (lChannels == -1)
  2537. {
  2538. ppblink->fProprietaryIsdn = FALSE;
  2539. }
  2540. else
  2541. {
  2542. ppblink->lChannels = lChannels;
  2543. }
  2544. }
  2545. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2546. KEY_Compression, &ppblink->fCompression )) != 0)
  2547. {
  2548. return dwErr;
  2549. }
  2550. }
  2551. else if( CSTR_EQUAL == CompareStringA(
  2552. LOCALE_INVARIANT,
  2553. NORM_IGNORECASE,
  2554. X25_TXT,
  2555. -1,
  2556. szValue,
  2557. -1
  2558. )
  2559. )
  2560. {
  2561. // It's a native X.25 device.
  2562. //
  2563. ppblink->pbport.pbdevicetype = PBDT_X25;
  2564. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2565. KEY_X25_Address, &ppbentry->pszX25Address )) != 0)
  2566. {
  2567. return dwErr;
  2568. }
  2569. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2570. KEY_X25_UserData, &ppbentry->pszX25UserData )) != 0)
  2571. {
  2572. return dwErr;
  2573. }
  2574. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2575. KEY_X25_Facilities, &ppbentry->pszX25Facilities )) != 0)
  2576. {
  2577. return dwErr;
  2578. }
  2579. }
  2580. else if( CSTR_EQUAL == CompareStringA(
  2581. LOCALE_INVARIANT,
  2582. NORM_IGNORECASE,
  2583. MXS_MODEM_TXT,
  2584. -1,
  2585. szValue,
  2586. -1
  2587. )
  2588. )
  2589. {
  2590. // It's a MODEM device.
  2591. //
  2592. ppblink->pbport.pbdevicetype = PBDT_Modem;
  2593. if ((dwErr = ReadPhoneList( h, RFS_GROUP,
  2594. &ppblink->pdtllistPhones,
  2595. &fDirty )) != 0)
  2596. {
  2597. return dwErr;
  2598. }
  2599. if ((dwErr = ReadLong( h, RFS_GROUP,
  2600. KEY_LastSelectedPhone,
  2601. &ppblink->iLastSelectedPhone )) != 0)
  2602. {
  2603. return dwErr;
  2604. }
  2605. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2606. KEY_PromoteAlternates,
  2607. &ppblink->fPromoteAlternates )) != 0)
  2608. {
  2609. return dwErr;
  2610. }
  2611. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2612. KEY_TryNextAlternateOnFail,
  2613. &ppblink->fTryNextAlternateOnFail )) != 0)
  2614. {
  2615. return dwErr;
  2616. }
  2617. {
  2618. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2619. KEY_HwFlow, &ppblink->fHwFlow )) != 0)
  2620. {
  2621. return dwErr;
  2622. }
  2623. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2624. KEY_Ec, &ppblink->fEc )) != 0)
  2625. {
  2626. return dwErr;
  2627. }
  2628. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2629. KEY_Ecc, &ppblink->fEcc )) != 0)
  2630. {
  2631. return dwErr;
  2632. }
  2633. if (pfDisableSpeaker)
  2634. {
  2635. ppblink->fSpeaker = !*pfDisableSpeaker;
  2636. }
  2637. else
  2638. {
  2639. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2640. KEY_Speaker, &ppblink->fSpeaker )) != 0)
  2641. {
  2642. return dwErr;
  2643. }
  2644. }
  2645. if ((dwErr = ReadLong( h, RFS_GROUP,
  2646. KEY_MdmProtocol, &ppblink->dwModemProtocol )) != 0)
  2647. {
  2648. return dwErr;
  2649. }
  2650. }
  2651. fModemFound = TRUE;
  2652. }
  2653. else if( CSTR_EQUAL == CompareStringA(
  2654. LOCALE_INVARIANT,
  2655. NORM_IGNORECASE,
  2656. MXS_SWITCH_TXT,
  2657. -1,
  2658. szValue,
  2659. -1
  2660. )
  2661. )
  2662. {
  2663. // It's a SWITCH device.
  2664. // Read switch type string.
  2665. //
  2666. TCHAR* pszSwitch = NULL;
  2667. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2668. KEY_Type, &pszSwitch )) != 0)
  2669. {
  2670. return dwErr;
  2671. }
  2672. if (pszSwitch)
  2673. {
  2674. // It's a pre-NT5 switch.
  2675. //
  2676. if (!fPreconnectFound && !fModemFound && !fPadFound)
  2677. {
  2678. // It's the preconnect switch.
  2679. //
  2680. if( CSTR_EQUAL == CompareString(
  2681. LOCALE_INVARIANT,
  2682. NORM_IGNORECASE,
  2683. TEXT(SM_TerminalText),
  2684. -1,
  2685. pszSwitch,
  2686. -1
  2687. )
  2688. )
  2689. {
  2690. ppblink->pbport.fScriptBeforeTerminal = TRUE;
  2691. Free( pszSwitch );
  2692. }
  2693. else
  2694. {
  2695. ppblink->pbport.fScriptBefore = TRUE;
  2696. ppblink->pbport.pszScriptBefore = pszSwitch;
  2697. }
  2698. fPreconnectFound = TRUE;
  2699. }
  2700. else if (!fPostconnectFound)
  2701. {
  2702. // It's the postconnect switch, i.e. a login script.
  2703. //
  2704. if( CSTR_EQUAL == CompareString(
  2705. LOCALE_INVARIANT,
  2706. NORM_IGNORECASE,
  2707. TEXT(SM_TerminalText),
  2708. -1,
  2709. pszSwitch,
  2710. -1
  2711. )
  2712. )
  2713. {
  2714. ppbentry->fScriptAfterTerminal = TRUE;
  2715. Free( pszSwitch );
  2716. }
  2717. else
  2718. {
  2719. ppbentry->fScriptAfter = TRUE;
  2720. ppbentry->pszScriptAfter = pszSwitch;
  2721. }
  2722. fPostconnectFound = TRUE;
  2723. }
  2724. else
  2725. {
  2726. // It's a switch, but it's not in the normal pre- or post-
  2727. // connect positions.
  2728. //
  2729. ppbentry->fCustom = TRUE;
  2730. Free( pszSwitch );
  2731. return 0;
  2732. }
  2733. }
  2734. else
  2735. {
  2736. BOOL fTerminal;
  2737. BOOL fScript;
  2738. TCHAR* pszName;
  2739. // It's an NT5+ switch.
  2740. //
  2741. fTerminal = FALSE;
  2742. fScript = FALSE;
  2743. pszName = NULL;
  2744. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2745. KEY_Terminal, &fTerminal )) != 0)
  2746. {
  2747. return dwErr;
  2748. }
  2749. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2750. KEY_Script, &fScript )) != 0)
  2751. {
  2752. return dwErr;
  2753. }
  2754. if ((dwErr = ReadLong(h, RFS_GROUP,
  2755. KEY_CustomScript, &ppbentry->dwCustomScript)))
  2756. {
  2757. return dwErr;
  2758. }
  2759. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2760. KEY_Name, &pszName )) != 0)
  2761. {
  2762. return dwErr;
  2763. }
  2764. if (!fPreconnectFound && !fModemFound && !fPadFound)
  2765. {
  2766. // It's the preconnect switch.
  2767. //
  2768. ppblink->pbport.fScriptBeforeTerminal = fTerminal;
  2769. ppblink->pbport.fScriptBefore = fScript;
  2770. ppblink->pbport.pszScriptBefore = pszName;
  2771. fPreconnectFound = TRUE;
  2772. }
  2773. else if (!fPostconnectFound)
  2774. {
  2775. // It's the postconnect switch, i.e. a login script.
  2776. //
  2777. ppbentry->fScriptAfterTerminal = fTerminal;
  2778. ppbentry->fScriptAfter = fScript;
  2779. ppbentry->pszScriptAfter = pszName;
  2780. fPostconnectFound = TRUE;
  2781. }
  2782. else
  2783. {
  2784. // It's a switch, but it's not in the normal pre- or post-
  2785. // connect positions.
  2786. //
  2787. ppbentry->fCustom = TRUE;
  2788. return 0;
  2789. }
  2790. }
  2791. }
  2792. else if( CSTR_EQUAL == CompareStringA(
  2793. LOCALE_INVARIANT,
  2794. NORM_IGNORECASE,
  2795. MXS_PAD_TXT,
  2796. -1,
  2797. szValue,
  2798. -1
  2799. )
  2800. )
  2801. {
  2802. // It's an X.25 PAD device.
  2803. //
  2804. if (!fModemFound)
  2805. {
  2806. ppblink->pbport.pbdevicetype = PBDT_Pad;
  2807. }
  2808. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2809. KEY_PAD_Type, &ppbentry->pszX25Network )) != 0)
  2810. {
  2811. return dwErr;
  2812. }
  2813. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2814. KEY_PAD_Address, &ppbentry->pszX25Address )) != 0)
  2815. {
  2816. return dwErr;
  2817. }
  2818. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2819. KEY_PAD_UserData, &ppbentry->pszX25UserData )) != 0)
  2820. {
  2821. return dwErr;
  2822. }
  2823. if ((dwErr = ReadString( h, pStrDupTFromA, RFS_GROUP,
  2824. KEY_PAD_Facilities, &ppbentry->pszX25Facilities )) != 0)
  2825. {
  2826. return dwErr;
  2827. }
  2828. fPadFound = TRUE;
  2829. }
  2830. else if( CSTR_EQUAL == CompareStringA(
  2831. LOCALE_INVARIANT,
  2832. NORM_IGNORECASE,
  2833. MXS_NULL_TXT,
  2834. -1,
  2835. szValue,
  2836. -1
  2837. )
  2838. )
  2839. {
  2840. // It's a null device. Currently, there is no specific null
  2841. // information stored.
  2842. //
  2843. ppblink->pbport.pbdevicetype = PBDT_Null;
  2844. }
  2845. else if( (ppblink->pbport.pszDevice[ 0 ] == TEXT('\0')) &&
  2846. ( CSTR_EQUAL == CompareStringA(
  2847. LOCALE_INVARIANT,
  2848. NORM_IGNORECASE,
  2849. S_WIN9XATM,
  2850. -1,
  2851. szValue,
  2852. -1
  2853. ) )
  2854. )
  2855. {
  2856. // Whistler 326015 PBK: if ATM device name is NULL, we should seek
  2857. // out a device name just like w/serial/ISDN
  2858. //
  2859. // This section was added to cover a Win9x migration problem. The
  2860. // ATM device name is NULL'd during the upgrade because we have no
  2861. // way to predict what the name will end up as. We will now use the
  2862. // first ATM device name we get from RASMAN, if any.
  2863. //
  2864. ppblink->pbport.pbdevicetype = PBDT_Atm;
  2865. // Read only the phone number strings and hunt flag.
  2866. //
  2867. if ((dwErr = ReadPhoneList( h, RFS_GROUP,
  2868. &ppblink->pdtllistPhones,
  2869. &fDirty )) != 0)
  2870. {
  2871. return dwErr;
  2872. }
  2873. if ((dwErr = ReadLong( h, RFS_GROUP,
  2874. KEY_LastSelectedPhone,
  2875. &ppblink->iLastSelectedPhone )) != 0)
  2876. {
  2877. return dwErr;
  2878. }
  2879. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2880. KEY_PromoteAlternates,
  2881. &ppblink->fPromoteAlternates )) != 0)
  2882. {
  2883. return dwErr;
  2884. }
  2885. if ((dwErr = ReadFlag( h, RFS_GROUP,
  2886. KEY_TryNextAlternateOnFail,
  2887. &ppblink->fTryNextAlternateOnFail )) != 0)
  2888. {
  2889. return dwErr;
  2890. }
  2891. }
  2892. else
  2893. {
  2894. BOOL fSame;
  2895. CHAR* pszMedia;
  2896. TCHAR *pszValue;
  2897. pszMedia = StrDupAFromT( ppblink->pbport.pszMedia );
  2898. if (!pszMedia)
  2899. {
  2900. return ERROR_NOT_ENOUGH_MEMORY;
  2901. }
  2902. pszValue = pStrDupTFromA(szValue);
  2903. if(!pszValue)
  2904. {
  2905. return ERROR_NOT_ENOUGH_MEMORY;
  2906. }
  2907. fSame = ( CSTR_EQUAL == CompareStringA(
  2908. LOCALE_INVARIANT,
  2909. NORM_IGNORECASE,
  2910. szValue,
  2911. -1,
  2912. pszMedia,
  2913. -1
  2914. ) );
  2915. Free( pszMedia );
  2916. if ( (fSame ) ||
  2917. ( CSTR_EQUAL == CompareString(
  2918. LOCALE_INVARIANT,
  2919. NORM_IGNORECASE,
  2920. TEXT("SERIAL"),
  2921. -1,
  2922. pszValue,
  2923. -1
  2924. ) ) ||
  2925. ( CSTR_EQUAL == CompareString(
  2926. LOCALE_INVARIANT,
  2927. NORM_IGNORECASE,
  2928. RASDT_Vpn,
  2929. -1,
  2930. pszValue,
  2931. -1
  2932. ) ) ||
  2933. ( CSTR_EQUAL == CompareString(
  2934. LOCALE_INVARIANT,
  2935. NORM_IGNORECASE,
  2936. RASDT_Generic,
  2937. -1,
  2938. pszValue,
  2939. -1
  2940. ) ) ||
  2941. ( CSTR_EQUAL == CompareString(
  2942. LOCALE_INVARIANT,
  2943. NORM_IGNORECASE,
  2944. RASDT_FrameRelay,
  2945. -1,
  2946. pszValue,
  2947. -1
  2948. ) ) ||
  2949. ( CSTR_EQUAL == CompareString(
  2950. LOCALE_INVARIANT,
  2951. NORM_IGNORECASE,
  2952. RASDT_Atm,
  2953. -1,
  2954. pszValue,
  2955. -1
  2956. ) ) ||
  2957. ( CSTR_EQUAL == CompareString(
  2958. LOCALE_INVARIANT,
  2959. NORM_IGNORECASE,
  2960. RASDT_Sonet,
  2961. -1,
  2962. pszValue,
  2963. -1
  2964. ) ) ||
  2965. ( CSTR_EQUAL == CompareString(
  2966. LOCALE_INVARIANT,
  2967. NORM_IGNORECASE,
  2968. RASDT_SW56,
  2969. -1,
  2970. pszValue,
  2971. -1
  2972. ) ) ||
  2973. ( CSTR_EQUAL == CompareString(
  2974. LOCALE_INVARIANT,
  2975. NORM_IGNORECASE,
  2976. RASDT_Irda,
  2977. -1,
  2978. pszValue,
  2979. -1
  2980. ) ) ||
  2981. ( CSTR_EQUAL == CompareString(
  2982. LOCALE_INVARIANT,
  2983. NORM_IGNORECASE,
  2984. RASDT_Parallel,
  2985. -1,
  2986. pszValue,
  2987. -1
  2988. ) ) ||
  2989. ( CSTR_EQUAL == CompareString(
  2990. LOCALE_INVARIANT,
  2991. NORM_IGNORECASE,
  2992. RASDT_PPPoE,
  2993. -1,
  2994. pszValue,
  2995. -1
  2996. ) )
  2997. )//end of if()
  2998. {
  2999. Free(pszValue);
  3000. // It's an "other" device.
  3001. //
  3002. if(PBDT_None == ppblink->pbport.pbdevicetype)
  3003. {
  3004. ppblink->pbport.pbdevicetype = PBDT_Other;
  3005. }
  3006. // Read only the phone number strings and hunt flag.
  3007. //
  3008. if ((dwErr = ReadPhoneList( h, RFS_GROUP,
  3009. &ppblink->pdtllistPhones,
  3010. &fDirty )) != 0)
  3011. {
  3012. return dwErr;
  3013. }
  3014. if ((dwErr = ReadLong( h, RFS_GROUP,
  3015. KEY_LastSelectedPhone,
  3016. &ppblink->iLastSelectedPhone )) != 0)
  3017. {
  3018. return dwErr;
  3019. }
  3020. if ((dwErr = ReadFlag( h, RFS_GROUP,
  3021. KEY_PromoteAlternates,
  3022. &ppblink->fPromoteAlternates )) != 0)
  3023. {
  3024. return dwErr;
  3025. }
  3026. if ((dwErr = ReadFlag( h, RFS_GROUP,
  3027. KEY_TryNextAlternateOnFail,
  3028. &ppblink->fTryNextAlternateOnFail )) != 0)
  3029. {
  3030. return dwErr;
  3031. }
  3032. }
  3033. else
  3034. {
  3035. Free(pszValue);
  3036. // Device name doesn't match media so it's a custom type, i.e.
  3037. // it wasn't created by us.
  3038. //
  3039. ppbentry->fCustom = TRUE;
  3040. }
  3041. }
  3042. }
  3043. if (ppblink->pbport.pbdevicetype == PBDT_None)
  3044. {
  3045. TRACE( "No device section" );
  3046. return ERROR_CORRUPT_PHONEBOOK;
  3047. }
  3048. if (fDirty)
  3049. {
  3050. ppbentry->fDirty = TRUE;
  3051. }
  3052. return 0;
  3053. }
  3054. DWORD
  3055. ReadEntryList(
  3056. IN OUT PBFILE* pFile,
  3057. IN DWORD dwFlags,
  3058. IN LPCTSTR pszSection)
  3059. // Creates the entry list 'pFile->pdtllistEntries' from previously loaded
  3060. // phonebook file 'pFile.hrasfile'.' 'FRouter' is true if router ports
  3061. // should be used for comparison/conversion of devices, false otherwise.
  3062. //
  3063. // Returns 0 if successful, otherwise a non-0 error code.
  3064. //
  3065. {
  3066. DWORD dwErr = 0;
  3067. BOOL fDirty = FALSE;
  3068. DTLNODE* pdtlnodeEntry = NULL;
  3069. DTLNODE* pdtlnodeLink = NULL;
  3070. PBENTRY* ppbentry;
  3071. PBLINK* ppblink;
  3072. CHAR* szValue;
  3073. BOOL fStatus;
  3074. BOOL fFoundMedia;
  3075. BOOL fSectionDeleted;
  3076. BOOL fOldPhonebook;
  3077. BOOL fDisableSwCompression;
  3078. BOOL fDisableModemSpeaker;
  3079. BOOL fRouter;
  3080. HRASFILE h;
  3081. DTLLIST* pdtllistPorts = NULL;
  3082. DWORD dwfInstalledProtocols;
  3083. DWORD dwEncoding;
  3084. DWORD dwEntryType;
  3085. STRDUP_T_FROM_A_FUNC pDupTFromA = StrDupTFromA;
  3086. TCHAR* pszCurEntryName;
  3087. BOOL fOldPhoneNumberParts;
  3088. TCHAR* pszOldAreaCode;
  3089. BOOL fOldUseDialingRules;
  3090. DWORD dwOldCountryID;
  3091. DWORD dwOldCountryCode;
  3092. DWORD dwDialUIDOffset;
  3093. fOldPhoneNumberParts = FALSE;
  3094. pszOldAreaCode = NULL;
  3095. szValue = NULL;
  3096. dwOldCountryID = 0;
  3097. dwOldCountryCode = 0;
  3098. dwDialUIDOffset = 0;
  3099. // Make sure our assumption that ISDN phone number keys are equivalent to
  3100. // modem phone number keys is correct.
  3101. //
  3102. ASSERT( ( CSTR_EQUAL == CompareStringA(
  3103. LOCALE_INVARIANT,
  3104. NORM_IGNORECASE,
  3105. ISDN_PHONENUMBER_KEY,
  3106. -1,
  3107. KEY_PhoneNumber,
  3108. -1
  3109. ) ) );
  3110. ASSERT( ( CSTR_EQUAL == CompareStringA(
  3111. LOCALE_INVARIANT,
  3112. NORM_IGNORECASE,
  3113. MXS_PHONENUMBER_KEY,
  3114. -1,
  3115. KEY_PhoneNumber,
  3116. -1
  3117. ) ) );
  3118. h = pFile->hrasfile;
  3119. ASSERT( h != -1 );
  3120. fRouter = !!(dwFlags & RPBF_Router);
  3121. if ( fRouter )
  3122. {
  3123. //
  3124. // if router bit is set, check for protocols to which RasRtr
  3125. // or RasSrv is bound
  3126. //
  3127. dwfInstalledProtocols = GetInstalledProtocolsEx( NULL, TRUE, FALSE, TRUE );
  3128. }
  3129. else
  3130. {
  3131. //
  3132. // get protocols to which Dial Up Client is bound
  3133. //
  3134. dwfInstalledProtocols = GetInstalledProtocolsEx( NULL, FALSE, TRUE, FALSE );
  3135. }
  3136. // Look up a couple flags in the old global section and, if found, apply
  3137. // them to the new per-entry equivalents. This will only find anything on
  3138. // phonebook upgrade, since all ".XXX" sections are deleted later.
  3139. //
  3140. fOldPhonebook = FALSE;
  3141. if (RasfileFindSectionLine( h, GLOBALSECTIONNAME, TRUE ))
  3142. {
  3143. fOldPhonebook = TRUE;
  3144. fDisableModemSpeaker = FALSE;
  3145. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3146. KEY_DisableModemSpeaker, &fDisableModemSpeaker )) != 0)
  3147. {
  3148. return dwErr;
  3149. }
  3150. fDisableSwCompression = FALSE;
  3151. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3152. KEY_DisableSwCompression, &fDisableSwCompression )) != 0)
  3153. {
  3154. return dwErr;
  3155. }
  3156. TRACE2( "Old phonebook: dms=%d,dsc=%d",
  3157. fDisableModemSpeaker, fDisableSwCompression );
  3158. }
  3159. if (!(pFile->pdtllistEntries = DtlCreateList( 0L )))
  3160. {
  3161. return ERROR_NOT_ENOUGH_MEMORY;
  3162. }
  3163. // XP 339346
  3164. //
  3165. if (! (szValue = (CHAR*)Malloc( (RAS_MAXLINEBUFLEN + 1) * sizeof(CHAR))))
  3166. {
  3167. DtlDestroyList(pFile->pdtllistEntries, NULL);
  3168. pFile->pdtllistEntries = NULL;
  3169. return ERROR_NOT_ENOUGH_MEMORY;
  3170. }
  3171. // For each connectoid section in the file...
  3172. //
  3173. fSectionDeleted = FALSE;
  3174. for (fStatus = RasfileFindFirstLine( h, RFL_SECTION, RFS_FILE );
  3175. fStatus;
  3176. fSectionDeleted
  3177. || (fStatus = RasfileFindNextLine( h, RFL_SECTION, RFS_FILE )))
  3178. {
  3179. fSectionDeleted = FALSE;
  3180. // Read the entry name (same as section name), skipping over any
  3181. // sections beginning with dot. These are reserved for special
  3182. // purposes (like the old global section).
  3183. //
  3184. if (!RasfileGetSectionName( h, szValue ))
  3185. {
  3186. // Get here only when the last section in the file is deleted
  3187. // within the loop.
  3188. //
  3189. break;
  3190. }
  3191. TRACE1( "ENTRY: Reading \"%s\"", szValue );
  3192. if (szValue[ 0 ] == '.')
  3193. {
  3194. TRACE1( "Obsolete section %s deleted", szValue );
  3195. DeleteCurrentSection( h );
  3196. fSectionDeleted = TRUE;
  3197. continue;
  3198. }
  3199. // Figure out if this entry was saved with ansi or
  3200. // utf8 encoding
  3201. //
  3202. dwEncoding = EN_Ansi;
  3203. if ((dwErr = ReadLong( h, RFS_SECTION,
  3204. KEY_Encoding, (LONG* )&dwEncoding )) != 0)
  3205. {
  3206. break;
  3207. }
  3208. // Read in the type
  3209. //
  3210. dwEntryType = RASET_Phone;
  3211. if ((dwErr = ReadLong( h, RFS_SECTION,
  3212. KEY_Type, (LONG* )&dwEntryType )) != 0)
  3213. {
  3214. break;
  3215. }
  3216. if (dwEncoding == EN_Ansi)
  3217. {
  3218. // We need to write the entry out in UTF8 for localization
  3219. // reasons, so mark it dirty since it has the wrong encoding.
  3220. //
  3221. pDupTFromA = StrDupTFromAUsingAnsiEncoding;
  3222. }
  3223. else
  3224. {
  3225. pDupTFromA = StrDupTFromA;
  3226. }
  3227. // Get the current entry name
  3228. //
  3229. pszCurEntryName = pDupTFromA( szValue );
  3230. if (pszCurEntryName == NULL)
  3231. {
  3232. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  3233. break;
  3234. }
  3235. // Make sure this is the entry that the user requested
  3236. //
  3237. // for BVT break bug 528488 gangz
  3238. // It's my bad!!!
  3239. if ( pszSection && ( CSTR_EQUAL != CompareString(
  3240. LOCALE_INVARIANT,
  3241. NORM_IGNORECASE,
  3242. pszCurEntryName,
  3243. -1,
  3244. pszSection,
  3245. -1
  3246. ) )
  3247. )
  3248. {
  3249. Free(pszCurEntryName);
  3250. continue;
  3251. }
  3252. // Create the type of node requested in the flags
  3253. //
  3254. if (dwFlags & RPBF_HeadersOnly)
  3255. {
  3256. DtlPutListCode( pFile->pdtllistEntries, RPBF_HeadersOnly );
  3257. pdtlnodeEntry = DtlCreateNode( pszCurEntryName, 0L );
  3258. if (!pdtlnodeEntry )
  3259. {
  3260. Free( pszCurEntryName );
  3261. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  3262. break;
  3263. }
  3264. DtlAddNodeLast( pFile->pdtllistEntries, pdtlnodeEntry );
  3265. continue;
  3266. }
  3267. else if (dwFlags & RPBF_HeaderType)
  3268. {
  3269. RASENTRYHEADER * preh;
  3270. DtlPutListCode( pFile->pdtllistEntries, RPBF_HeaderType );
  3271. pdtlnodeEntry = DtlCreateSizedNode(sizeof(RASENTRYHEADER), 0);
  3272. if (!pdtlnodeEntry )
  3273. {
  3274. Free( pszCurEntryName );
  3275. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  3276. break;
  3277. }
  3278. preh = (RASENTRYHEADER *) DtlGetData(pdtlnodeEntry);
  3279. lstrcpynW(
  3280. preh->szEntryName,
  3281. pszCurEntryName,
  3282. sizeof(preh->szEntryName) / sizeof(WCHAR));
  3283. preh->dwEntryType = dwEntryType;
  3284. Free( pszCurEntryName );
  3285. DtlAddNodeLast( pFile->pdtllistEntries, pdtlnodeEntry );
  3286. continue;
  3287. }
  3288. // If we reach this point, we know that all phonebook
  3289. // info is being requested.
  3290. //
  3291. if (!(pdtlnodeEntry = CreateEntryNode( FALSE )))
  3292. {
  3293. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  3294. break;
  3295. }
  3296. // Initialize the entry, name, and type
  3297. //
  3298. DtlAddNodeLast( pFile->pdtllistEntries, pdtlnodeEntry );
  3299. ppbentry = (PBENTRY* )DtlGetData( pdtlnodeEntry );
  3300. ppbentry->pszEntryName = pszCurEntryName;
  3301. ppbentry->dwType = dwEntryType;
  3302. // Change default on "upgrade" to "show domain field". See bug 281673.
  3303. //
  3304. ppbentry->fPreviewDomain = TRUE;
  3305. if ((fOldPhonebook) || (dwEncoding == EN_Ansi))
  3306. {
  3307. // Mark all entries dirty when upgrading old phonebooks because
  3308. // they all need to have there DialParamUIDs written out.
  3309. //
  3310. fDirty = ppbentry->fDirty = TRUE;
  3311. }
  3312. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3313. KEY_AutoLogon, &ppbentry->fAutoLogon )) != 0)
  3314. {
  3315. break;
  3316. }
  3317. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3318. KEY_UseRasCredentials, &ppbentry->fUseRasCredentials )) != 0)
  3319. {
  3320. break;
  3321. }
  3322. if ((dwErr = ReadLong( h, RFS_SECTION,
  3323. KEY_UID, (LONG* )&ppbentry->dwDialParamsUID )) != 0)
  3324. {
  3325. break;
  3326. }
  3327. {
  3328. GUID* pGuid;
  3329. DWORD cb;
  3330. pGuid = NULL;
  3331. if ((dwErr = ReadBinary( h, RFS_SECTION, KEY_Guid,
  3332. (BYTE** )&pGuid, &cb )) != 0)
  3333. {
  3334. break;
  3335. }
  3336. if (cb == sizeof(UUID))
  3337. {
  3338. Free0( ppbentry->pGuid );
  3339. ppbentry->pGuid = pGuid;
  3340. }
  3341. else
  3342. {
  3343. fDirty = ppbentry->fDirty = TRUE;
  3344. }
  3345. }
  3346. if ((dwErr = ReadLong( h, RFS_SECTION,
  3347. KEY_BaseProtocol,
  3348. (LONG* )&ppbentry->dwBaseProtocol )) != 0)
  3349. {
  3350. break;
  3351. }
  3352. if ((dwErr = ReadLong( h, RFS_SECTION,
  3353. KEY_VpnStrategy,
  3354. (LONG* )&ppbentry->dwVpnStrategy )) != 0)
  3355. {
  3356. break;
  3357. }
  3358. #if AMB
  3359. if ((dwErr = ReadLong( h, RFS_SECTION,
  3360. KEY_Authentication,
  3361. (LONG* )&ppbentry->dwAuthentication )) != 0)
  3362. {
  3363. break;
  3364. }
  3365. #endif
  3366. if ((dwErr = ReadLong( h, RFS_SECTION,
  3367. KEY_ExcludedProtocols,
  3368. (LONG * )&ppbentry->dwfExcludedProtocols )) != 0)
  3369. {
  3370. break;
  3371. }
  3372. #if AMB
  3373. // Automatically mark all installed protocols on AMB-only entries as
  3374. // "excluded for PPP connections".
  3375. //
  3376. if (ppbentry->dwAuthentication == AS_AmbOnly
  3377. || (ppbentry->dwBaseProtocol == BP_Ppp
  3378. && (dwfInstalledProtocols
  3379. & ~(ppbentry->dwfExcludedProtocols)) == 0))
  3380. {
  3381. ppbentry->dwBaseProtocol = BP_Ras;
  3382. ppbentry->dwfExcludedProtocols = 0;
  3383. fDirty = ppbentry->fDirty = TRUE;
  3384. }
  3385. #else
  3386. // AMB support deprecated, see NarenG. If old AMB entry, set framing
  3387. // and authentication strategy back to defaults. If calling a non-PPP
  3388. // (NT 3.1 or WFW server) it still won't work, but at least this fixes
  3389. // someone who accidently chose AMB.
  3390. //
  3391. if (ppbentry->dwBaseProtocol == BP_Ras)
  3392. {
  3393. ppbentry->dwBaseProtocol = BP_Ppp;
  3394. }
  3395. #endif
  3396. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3397. KEY_LcpExtensions,
  3398. &ppbentry->fLcpExtensions )) != 0)
  3399. {
  3400. break;
  3401. }
  3402. if ((dwErr = ReadLong( h, RFS_SECTION,
  3403. KEY_DataEncryption,
  3404. &ppbentry->dwDataEncryption )) != 0)
  3405. {
  3406. break;
  3407. }
  3408. if (fOldPhonebook)
  3409. {
  3410. ppbentry->fSwCompression = !fDisableSwCompression;
  3411. }
  3412. else
  3413. {
  3414. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3415. KEY_SwCompression,
  3416. &ppbentry->fSwCompression )) != 0)
  3417. {
  3418. break;
  3419. }
  3420. }
  3421. fOldUseDialingRules = (BOOL )-1;
  3422. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3423. KEY_UseCountryAndAreaCodes,
  3424. &fOldUseDialingRules )) != 0)
  3425. {
  3426. break;
  3427. }
  3428. if (fOldUseDialingRules != (BOOL )-1)
  3429. {
  3430. fOldPhoneNumberParts = TRUE;
  3431. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3432. KEY_AreaCode,
  3433. &pszOldAreaCode )) != 0)
  3434. {
  3435. break;
  3436. }
  3437. if ((dwErr = ReadLong( h, RFS_SECTION,
  3438. KEY_CountryID,
  3439. &dwOldCountryID )) != 0)
  3440. {
  3441. break;
  3442. }
  3443. if ((dwErr = ReadLong( h, RFS_SECTION,
  3444. KEY_CountryCode,
  3445. &dwOldCountryCode )) != 0)
  3446. {
  3447. break;
  3448. }
  3449. }
  3450. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3451. KEY_NegotiateMultilinkAlways,
  3452. &ppbentry->fNegotiateMultilinkAlways )) != 0)
  3453. {
  3454. break;
  3455. }
  3456. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3457. KEY_SkipNwcWarning,
  3458. &ppbentry->fSkipNwcWarning )) != 0)
  3459. {
  3460. break;
  3461. }
  3462. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3463. KEY_SkipDownLevelDialog,
  3464. &ppbentry->fSkipDownLevelDialog )) != 0)
  3465. {
  3466. break;
  3467. }
  3468. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3469. KEY_SkipDoubleDialDialog,
  3470. &ppbentry->fSkipDoubleDialDialog )) != 0)
  3471. {
  3472. break;
  3473. }
  3474. if ((dwErr = ReadLong( h, RFS_SECTION,
  3475. KEY_DialMode,
  3476. (LONG* )&ppbentry->dwDialMode )) != 0)
  3477. {
  3478. break;
  3479. }
  3480. if ((dwErr = ReadLong( h, RFS_SECTION,
  3481. KEY_DialPercent,
  3482. (LONG* )&ppbentry->dwDialPercent )) != 0)
  3483. {
  3484. break;
  3485. }
  3486. if ((dwErr = ReadLong( h, RFS_SECTION,
  3487. KEY_DialSeconds,
  3488. (LONG* )&ppbentry->dwDialSeconds )) != 0)
  3489. {
  3490. break;
  3491. }
  3492. if ((dwErr = ReadLong( h, RFS_SECTION,
  3493. KEY_HangUpPercent,
  3494. (LONG* )&ppbentry->dwHangUpPercent )) != 0)
  3495. {
  3496. break;
  3497. }
  3498. if ((dwErr = ReadLong( h, RFS_SECTION,
  3499. KEY_HangUpSeconds,
  3500. (LONG* )&ppbentry->dwHangUpSeconds )) != 0)
  3501. {
  3502. break;
  3503. }
  3504. if ((dwErr = ReadLong( h, RFS_SECTION,
  3505. KEY_OverridePref,
  3506. (LONG* )&ppbentry->dwfOverridePref )) != 0)
  3507. {
  3508. break;
  3509. }
  3510. if ((dwErr = ReadLong( h, RFS_SECTION,
  3511. KEY_RedialAttempts,
  3512. (LONG* )&ppbentry->dwRedialAttempts )) != 0)
  3513. {
  3514. break;
  3515. }
  3516. if ((dwErr = ReadLong( h, RFS_SECTION,
  3517. KEY_RedialSeconds,
  3518. (LONG* )&ppbentry->dwRedialSeconds )) != 0)
  3519. {
  3520. break;
  3521. }
  3522. if ((dwErr = ReadLong( h, RFS_SECTION,
  3523. KEY_IdleDisconnectSeconds,
  3524. &ppbentry->lIdleDisconnectSeconds )) != 0)
  3525. {
  3526. break;
  3527. }
  3528. // If this "idle seconds" is non-zero set it's override bit
  3529. // explicitly. This is necessary for this field only, because it
  3530. // existed in entries created before the override bits were
  3531. // implemented.
  3532. //
  3533. if (ppbentry->lIdleDisconnectSeconds != 0)
  3534. {
  3535. ppbentry->dwfOverridePref |= RASOR_IdleDisconnectSeconds;
  3536. }
  3537. if ((dwErr = ReadFlag(
  3538. h, RFS_SECTION, KEY_RedialOnLinkFailure,
  3539. &ppbentry->fRedialOnLinkFailure )) != 0)
  3540. {
  3541. break;
  3542. }
  3543. if ((dwErr = ReadLong( h, RFS_SECTION,
  3544. KEY_CallbackMode,
  3545. (LONG* )&ppbentry->dwCallbackMode )) != 0)
  3546. {
  3547. break;
  3548. }
  3549. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3550. KEY_CustomDialDll,
  3551. &ppbentry->pszCustomDialDll )) != 0)
  3552. {
  3553. break;
  3554. }
  3555. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3556. KEY_CustomDialFunc,
  3557. &ppbentry->pszCustomDialFunc )) != 0)
  3558. {
  3559. break;
  3560. }
  3561. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3562. KEY_CustomDialerName,
  3563. &ppbentry->pszCustomDialerName )) != 0)
  3564. {
  3565. break;
  3566. }
  3567. if ((dwErr = ReadFlag(
  3568. h, RFS_SECTION, KEY_AuthenticateServer,
  3569. &ppbentry->fAuthenticateServer )) != 0)
  3570. {
  3571. break;
  3572. }
  3573. if ((dwErr = ReadFlag(
  3574. h, RFS_SECTION, KEY_ShareMsFilePrint,
  3575. &ppbentry->fShareMsFilePrint )) != 0)
  3576. {
  3577. break;
  3578. }
  3579. if ((dwErr = ReadFlag(
  3580. h, RFS_SECTION, KEY_BindMsNetClient,
  3581. &ppbentry->fBindMsNetClient )) != 0)
  3582. {
  3583. break;
  3584. }
  3585. {
  3586. ppbentry->fSharedPhoneNumbers = (BOOL )-1;
  3587. if ((dwErr = ReadFlag(
  3588. h, RFS_SECTION, KEY_SharedPhoneNumbers,
  3589. &ppbentry->fSharedPhoneNumbers )) != 0)
  3590. {
  3591. break;
  3592. }
  3593. }
  3594. if ((dwErr = ReadFlag(
  3595. h, RFS_SECTION, KEY_GlobalDeviceSettings,
  3596. &ppbentry->fGlobalDeviceSettings)) != 0)
  3597. {
  3598. break;
  3599. }
  3600. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3601. KEY_PrerequisiteEntry,
  3602. &ppbentry->pszPrerequisiteEntry )) != 0)
  3603. {
  3604. break;
  3605. }
  3606. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3607. KEY_PrerequisitePbk,
  3608. &ppbentry->pszPrerequisitePbk )) != 0)
  3609. {
  3610. break;
  3611. }
  3612. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3613. KEY_PreferredPort,
  3614. &ppbentry->pszPreferredPort )) != 0)
  3615. {
  3616. break;
  3617. }
  3618. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3619. KEY_PreferredDevice,
  3620. &ppbentry->pszPreferredDevice )) != 0)
  3621. {
  3622. break;
  3623. }
  3624. //For .Net 639551
  3625. if ((dwErr = ReadLong( h, RFS_SECTION,
  3626. KEY_PreferredBps,
  3627. &ppbentry->dwPreferredBps)) != 0)
  3628. {
  3629. return dwErr;
  3630. }
  3631. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3632. KEY_PreferredHwFlow,
  3633. &ppbentry->fPreferredHwFlow)) != 0)
  3634. {
  3635. return dwErr;
  3636. }
  3637. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3638. KEY_PreferredEc,
  3639. &ppbentry->fPreferredEc)) != 0)
  3640. {
  3641. return dwErr;
  3642. }
  3643. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3644. KEY_PreferredEcc,
  3645. &ppbentry->fPreferredEcc)) != 0)
  3646. {
  3647. return dwErr;
  3648. }
  3649. if ((dwErr = ReadLong( h, RFS_SECTION,
  3650. KEY_PreferredSpeaker,
  3651. &ppbentry->fPreferredSpeaker)) != 0)
  3652. {
  3653. return dwErr;
  3654. }
  3655. //For whistler bug 402522
  3656. //
  3657. if ((dwErr = ReadLong( h, RFS_SECTION,
  3658. KEY_PreferredModemProtocol,
  3659. &ppbentry->dwPreferredModemProtocol)) != 0)
  3660. {
  3661. break;
  3662. }
  3663. if ((dwErr = ReadFlag(
  3664. h, RFS_SECTION, KEY_PreviewUserPw,
  3665. &ppbentry->fPreviewUserPw )) != 0)
  3666. {
  3667. break;
  3668. }
  3669. if ((dwErr = ReadFlag(
  3670. h, RFS_SECTION, KEY_PreviewDomain,
  3671. &ppbentry->fPreviewDomain )) != 0)
  3672. {
  3673. break;
  3674. }
  3675. if ((dwErr = ReadFlag(
  3676. h, RFS_SECTION, KEY_PreviewPhoneNumber,
  3677. &ppbentry->fPreviewPhoneNumber )) != 0)
  3678. {
  3679. break;
  3680. }
  3681. if ((dwErr = ReadFlag(
  3682. h, RFS_SECTION, KEY_ShowDialingProgress,
  3683. &ppbentry->fShowDialingProgress )) != 0)
  3684. {
  3685. break;
  3686. }
  3687. if ((dwErr = ReadFlag(
  3688. h, RFS_SECTION, KEY_ShowMonitorIconInTaskBar,
  3689. &ppbentry->fShowMonitorIconInTaskBar )) != 0)
  3690. {
  3691. break;
  3692. }
  3693. if ((dwErr = ReadLong( h, RFS_SECTION,
  3694. KEY_CustomAuthKey,
  3695. (LONG* )&ppbentry->dwCustomAuthKey )) != 0)
  3696. {
  3697. break;
  3698. }
  3699. if ((dwErr = ReadBinary( h, RFS_SECTION, KEY_CustomAuthData,
  3700. &ppbentry->pCustomAuthData,
  3701. &ppbentry->cbCustomAuthData )) != 0)
  3702. {
  3703. break;
  3704. }
  3705. if (fOldPhonebook)
  3706. {
  3707. // Look for the old PPP keys.
  3708. //
  3709. if (ppbentry->dwBaseProtocol == BP_Ppp)
  3710. {
  3711. if ((dwErr = ReadLong(
  3712. h, RFS_SECTION, KEY_PppTextAuthentication,
  3713. &ppbentry->dwAuthRestrictions )) != 0)
  3714. {
  3715. break;
  3716. }
  3717. if ((dwErr = ReadFlag(
  3718. h, RFS_SECTION, KEY_PppIpPrioritizeRemote,
  3719. &ppbentry->fIpPrioritizeRemote )) != 0)
  3720. {
  3721. break;
  3722. }
  3723. if ((dwErr = ReadFlag(
  3724. h, RFS_SECTION, KEY_PppIpVjCompression,
  3725. &ppbentry->fIpHeaderCompression )) != 0)
  3726. {
  3727. break;
  3728. }
  3729. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3730. KEY_PppIpAddress, &ppbentry->pszIpAddress )) != 0)
  3731. {
  3732. break;
  3733. }
  3734. if ((dwErr = ReadLong( h, RFS_SECTION,
  3735. KEY_PppIpAddressSource,
  3736. &ppbentry->dwIpAddressSource )) != 0)
  3737. {
  3738. break;
  3739. }
  3740. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3741. KEY_PppIpDnsAddress,
  3742. &ppbentry->pszIpDnsAddress )) != 0)
  3743. {
  3744. break;
  3745. }
  3746. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3747. KEY_PppIpDns2Address,
  3748. &ppbentry->pszIpDns2Address )) != 0)
  3749. {
  3750. break;
  3751. }
  3752. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3753. KEY_PppIpWinsAddress,
  3754. &ppbentry->pszIpWinsAddress )) != 0)
  3755. {
  3756. break;
  3757. }
  3758. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3759. KEY_PppIpWins2Address,
  3760. &ppbentry->pszIpWins2Address )) != 0)
  3761. {
  3762. break;
  3763. }
  3764. if ((dwErr = ReadLong( h, RFS_SECTION,
  3765. KEY_PppIpNameSource,
  3766. &ppbentry->dwIpNameSource )) != 0)
  3767. {
  3768. break;
  3769. }
  3770. }
  3771. // Look for the old SLIP keys.
  3772. //
  3773. if (ppbentry->dwBaseProtocol == BP_Slip)
  3774. {
  3775. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3776. KEY_SlipHeaderCompression,
  3777. &ppbentry->fIpHeaderCompression )) != 0)
  3778. {
  3779. break;
  3780. }
  3781. if ((dwErr = ReadFlag( h, RFS_SECTION,
  3782. KEY_SlipPrioritizeRemote,
  3783. &ppbentry->fIpPrioritizeRemote )) != 0)
  3784. {
  3785. break;
  3786. }
  3787. if ((dwErr = ReadLong( h, RFS_SECTION,
  3788. KEY_SlipFrameSize, &ppbentry->dwFrameSize )) != 0)
  3789. {
  3790. break;
  3791. }
  3792. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3793. KEY_SlipIpAddress, &ppbentry->pszIpAddress )) != 0)
  3794. {
  3795. break;
  3796. }
  3797. }
  3798. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3799. KEY_User, &ppbentry->pszOldUser )) != 0)
  3800. {
  3801. break;
  3802. }
  3803. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3804. KEY_Domain, &ppbentry->pszOldDomain )) != 0)
  3805. {
  3806. break;
  3807. }
  3808. }
  3809. else
  3810. {
  3811. // Look for the new IP names.
  3812. //
  3813. if ((dwErr = ReadLong(
  3814. h, RFS_SECTION, KEY_AuthRestrictions,
  3815. &ppbentry->dwAuthRestrictions )) != 0)
  3816. {
  3817. break;
  3818. }
  3819. if ((dwErr = ReadLong(
  3820. h, RFS_SECTION, KEY_TypicalAuth,
  3821. &ppbentry->dwTypicalAuth )) != 0)
  3822. {
  3823. break;
  3824. }
  3825. if ((dwErr = ReadFlag(
  3826. h, RFS_SECTION, KEY_IpPrioritizeRemote,
  3827. &ppbentry->fIpPrioritizeRemote )) != 0)
  3828. {
  3829. break;
  3830. }
  3831. if ((dwErr = ReadFlag(
  3832. h, RFS_SECTION, KEY_IpHeaderCompression,
  3833. &ppbentry->fIpHeaderCompression )) != 0)
  3834. {
  3835. break;
  3836. }
  3837. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3838. KEY_IpAddress, &ppbentry->pszIpAddress )) != 0)
  3839. {
  3840. break;
  3841. }
  3842. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3843. KEY_IpDnsAddress,
  3844. &ppbentry->pszIpDnsAddress )) != 0)
  3845. {
  3846. break;
  3847. }
  3848. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3849. KEY_IpDns2Address,
  3850. &ppbentry->pszIpDns2Address )) != 0)
  3851. {
  3852. break;
  3853. }
  3854. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3855. KEY_IpWinsAddress,
  3856. &ppbentry->pszIpWinsAddress )) != 0)
  3857. {
  3858. break;
  3859. }
  3860. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3861. KEY_IpWins2Address,
  3862. &ppbentry->pszIpWins2Address )) != 0)
  3863. {
  3864. break;
  3865. }
  3866. if ((dwErr = ReadLong( h, RFS_SECTION,
  3867. KEY_IpAddressSource,
  3868. &ppbentry->dwIpAddressSource )) != 0)
  3869. {
  3870. break;
  3871. }
  3872. if ((dwErr = ReadLong( h, RFS_SECTION,
  3873. KEY_IpNameSource,
  3874. &ppbentry->dwIpNameSource )) != 0)
  3875. {
  3876. break;
  3877. }
  3878. if ((dwErr = ReadLong( h, RFS_SECTION,
  3879. KEY_IpFrameSize, &ppbentry->dwFrameSize )) != 0)
  3880. {
  3881. break;
  3882. }
  3883. if ((dwErr = ReadLong( h, RFS_SECTION,
  3884. KEY_IpDnsFlags, &ppbentry->dwIpDnsFlags )) != 0)
  3885. {
  3886. break;
  3887. }
  3888. if ((dwErr = ReadLong( h, RFS_SECTION,
  3889. KEY_IpNbtFlags, &ppbentry->dwIpNbtFlags )) != 0)
  3890. {
  3891. break;
  3892. }
  3893. // Whistler bug 300933
  3894. //
  3895. if ((dwErr = ReadLong( h, RFS_SECTION,
  3896. KEY_TcpWindowSize, &ppbentry->dwTcpWindowSize )) != 0)
  3897. {
  3898. break;
  3899. }
  3900. // Read the use flags
  3901. //
  3902. if ((dwErr = ReadLong( h, RFS_SECTION,
  3903. KEY_UseFlags,
  3904. (LONG* )&ppbentry->dwUseFlags )) != 0)
  3905. {
  3906. break;
  3907. }
  3908. //Add an IPSecFlags for whistler bug 193987 gangz
  3909. //
  3910. if ((dwErr = ReadLong( h, RFS_SECTION,
  3911. KEY_IpSecFlags,
  3912. (LONG* )&ppbentry->dwIpSecFlags )) != 0)
  3913. {
  3914. break;
  3915. }
  3916. if ((dwErr = ReadString( h, pDupTFromA, RFS_SECTION,
  3917. KEY_IpDnsSuffix,
  3918. &ppbentry->pszIpDnsSuffix )) != 0)
  3919. {
  3920. break;
  3921. }
  3922. }
  3923. // Read the NETCOMPONENTS items.
  3924. //
  3925. ReadNetComponents( h, ppbentry->pdtllistNetComponents );
  3926. // MEDIA subsections.
  3927. //
  3928. fFoundMedia = FALSE;
  3929. //Load system ports into pdtllistPorts
  3930. //
  3931. if (!pdtllistPorts)
  3932. {
  3933. dwErr = LoadPortsList2( (fRouter)
  3934. ? (pFile->hConnection)
  3935. : NULL,
  3936. &pdtllistPorts,
  3937. fRouter );
  3938. if (dwErr != 0)
  3939. {
  3940. break;
  3941. }
  3942. }
  3943. //Loop over each media (media + device) section in a connectoid section
  3944. //
  3945. for (;;)
  3946. {
  3947. TCHAR* pszDevice;
  3948. PBPORT* ppbport;
  3949. if (!RasfileFindNextLine( h, RFL_GROUP, RFS_SECTION )
  3950. || !IsMediaLine( (CHAR* )RasfileGetLine( h ) ))
  3951. {
  3952. if (fFoundMedia)
  3953. {
  3954. // Out of media groups, i.e. "links", but found at least
  3955. // one. This is the successful exit case.
  3956. //
  3957. break;
  3958. }
  3959. // First subsection MUST be a MEDIA subsection. Delete
  3960. // non-conforming entries as invalid.
  3961. //
  3962. TRACE( "No media section?" );
  3963. DeleteCurrentSection( h );
  3964. fSectionDeleted = TRUE;
  3965. DtlRemoveNode( pFile->pdtllistEntries, pdtlnodeEntry );
  3966. DestroyEntryNode( pdtlnodeEntry );
  3967. break;
  3968. }
  3969. // Create a default link node and add it to the list.
  3970. //
  3971. if (!(pdtlnodeLink = CreateLinkNode()))
  3972. {
  3973. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  3974. break;
  3975. }
  3976. DtlAddNodeLast( ppbentry->pdtllistLinks, pdtlnodeLink );
  3977. ppblink = (PBLINK* )DtlGetData( pdtlnodeLink );
  3978. RasfileGetKeyValueFields( h, NULL, szValue );
  3979. TRACE1( "Reading media group \"%s\"", szValue );
  3980. if ((dwErr = ReadString( h, pDupTFromA, RFS_GROUP,
  3981. KEY_Port, &ppblink->pbport.pszPort )) != 0)
  3982. {
  3983. break;
  3984. }
  3985. //
  3986. // If this is a Direct Connect Entry default the entry type
  3987. // of the port to some direct connect device. We will default
  3988. // to Parallel port. In the case of a Broadband entry default
  3989. // to PPPoE.
  3990. //
  3991. if(RASET_Direct == ppbentry->dwType)
  3992. {
  3993. ppblink->pbport.pbdevicetype = PBDT_Parallel;
  3994. }
  3995. else if (RASET_Broadband == ppbentry->dwType)
  3996. {
  3997. ppblink->pbport.pbdevicetype = PBDT_PPPoE;
  3998. }
  3999. if (!ppblink->pbport.pszPort)
  4000. {
  4001. // No port. Blow away corrupt section and go on to the next
  4002. // one.
  4003. //
  4004. TRACE( "No port key? (section deleted)" );
  4005. dwErr = 0;
  4006. DeleteCurrentSection( h );
  4007. fSectionDeleted = TRUE;
  4008. DtlRemoveNode( pFile->pdtllistEntries, pdtlnodeEntry );
  4009. DestroyEntryNode( pdtlnodeEntry );
  4010. break;
  4011. }
  4012. {
  4013. pszDevice = NULL;
  4014. if ((dwErr = ReadString(
  4015. h, pDupTFromA, RFS_GROUP, KEY_Device,
  4016. &pszDevice )) != 0)
  4017. {
  4018. break;
  4019. }
  4020. ppblink->pbport.pszDevice = pszDevice;
  4021. TRACE1( "%s link format", (pszDevice) ? "New" : "Old" );
  4022. }
  4023. TRACEW1( "Port=%s", ppblink->pbport.pszPort );
  4024. //
  4025. // pmay: 226594
  4026. //
  4027. // If the device is one of them magic nt4-style null modems,
  4028. // upgrade it to a null modem and update the entry type.
  4029. //
  4030. if ((pszDevice) &&
  4031. (_tcsstr(
  4032. pszDevice,
  4033. TEXT("Dial-Up Networking Serial Cable between 2 PCs")))
  4034. )
  4035. {
  4036. ppbport = PpbportFromNullModem(
  4037. pdtllistPorts,
  4038. ppblink->pbport.pszPort,
  4039. ppblink->pbport.pszDevice );
  4040. if (ppbport != NULL)
  4041. {
  4042. ChangeEntryType( ppbentry, RASET_Direct );
  4043. fDirty = ppbentry->fDirty = TRUE;
  4044. }
  4045. }
  4046. //
  4047. // Otherwise, match the port up with the device name.
  4048. //
  4049. else
  4050. {
  4051. ppbport = PpbportFromPortAndDeviceName(
  4052. pdtllistPorts,
  4053. ppblink->pbport.pszPort,
  4054. ppblink->pbport.pszDevice );
  4055. }
  4056. if ( ( ppbport ) &&
  4057. ( PbportTypeMatchesEntryType(ppbport, ppbentry) ) )
  4058. {
  4059. if (lstrcmp( ppbport->pszPort, ppblink->pbport.pszPort ) != 0)
  4060. {
  4061. // The phonebook had an old-style port name. Mark the
  4062. // entry for update with the new port name format.
  4063. //
  4064. TRACEW1( "Port=>%s", ppblink->pbport.pszPort );
  4065. fDirty = ppbentry->fDirty = TRUE;
  4066. }
  4067. dwErr = CopyToPbport( &ppblink->pbport, ppbport );
  4068. if (dwErr != 0)
  4069. {
  4070. break;
  4071. }
  4072. }
  4073. else
  4074. {
  4075. // If no port is matched, it could be a vpn or isdn from a
  4076. // nt4 upgrade We haven't changed anything else in nt5. Check
  4077. // for these cases and upgrade the port.
  4078. //
  4079. ppbport = PpbportFromNT4PortandDevice(
  4080. pdtllistPorts,
  4081. ppblink->pbport.pszPort,
  4082. ppblink->pbport.pszDevice);
  4083. if( (NULL != ppbport)
  4084. && (PbportTypeMatchesEntryType(ppbport, ppbentry)))
  4085. {
  4086. fDirty = ppbentry->fDirty = TRUE;
  4087. dwErr = CopyToPbport(&ppblink->pbport, ppbport);
  4088. if(dwErr != 0)
  4089. {
  4090. break;
  4091. }
  4092. }
  4093. else
  4094. {
  4095. TRACE( "Port not configured" );
  4096. ppblink->pbport.fConfigured = FALSE;
  4097. // Assign unconfigured port the media we read earlier.
  4098. //
  4099. Free0( ppblink->pbport.pszMedia );
  4100. ppblink->pbport.pszMedia = pDupTFromA( szValue );
  4101. if (!ppblink->pbport.pszMedia)
  4102. {
  4103. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  4104. break;
  4105. }
  4106. }
  4107. }
  4108. if ((!ppbport) ||
  4109. (ppblink->pbport.pbdevicetype == PBDT_Modem) ||
  4110. (ppblink->pbport.dwFlags & PBP_F_NullModem)
  4111. )
  4112. {
  4113. // pmay: 260579. dwBps has to be initialized to zero in order
  4114. // for Rao's fix to 106837 (below) to work.
  4115. DWORD dwBps = 0;
  4116. SetDefaultModemSettings( ppblink );
  4117. if ((dwErr = ReadLong( h, RFS_GROUP,
  4118. KEY_InitBps, &dwBps )) != 0)
  4119. {
  4120. break;
  4121. }
  4122. // If the phonebook returns a 0 value, the case when the entry
  4123. // is created programmatically, then we stick with the default
  4124. // bps. RAID nt5 106837. (RaoS)
  4125. //
  4126. if ( 0 != dwBps )
  4127. {
  4128. ppblink->dwBps = dwBps;
  4129. }
  4130. }
  4131. // DEVICE subsections.
  4132. // At this point ppblink->pbport contains information from the
  4133. // matching port in the configured port list or defaults with
  4134. // pszMedia and pszDevice filled in. ReadDeviceList fills in the
  4135. // pbdevicetype, and if it's an unconfigured port, the unimodem or
  4136. // MXS modem flag.
  4137. //
  4138. dwErr = ReadDeviceList(
  4139. h, pDupTFromA, ppbentry, ppblink, !ppbport,
  4140. (fOldPhonebook) ? &fDisableModemSpeaker : NULL );
  4141. if (dwErr == ERROR_CORRUPT_PHONEBOOK)
  4142. {
  4143. // Blow away corrupt section and go on to the next one.
  4144. //
  4145. dwErr = 0;
  4146. DeleteCurrentSection( h );
  4147. fSectionDeleted = TRUE;
  4148. DtlRemoveNode( pFile->pdtllistEntries, pdtlnodeEntry );
  4149. DestroyEntryNode( pdtlnodeEntry );
  4150. break;
  4151. }
  4152. else if (dwErr != 0)
  4153. {
  4154. break;
  4155. }
  4156. if (fOldPhonebook
  4157. && ppbentry->dwBaseProtocol == BP_Slip)
  4158. {
  4159. // Set an after-dial terminal when upgrading old phonebooks.
  4160. // This was implied in the old format.
  4161. //
  4162. TRACE( "Add SLIP terminal" );
  4163. ppbentry->fScriptAfterTerminal = TRUE;
  4164. }
  4165. if (!ppbport)
  4166. {
  4167. DTLNODE* pdtlnode;
  4168. // This is an old-format link not in the list of installed
  4169. // ports. Change it to the first device of the same device
  4170. // type or to an "unknown" device of that type. Note this is
  4171. // what converts "Any port".
  4172. //
  4173. //Loop over each loaded System Port
  4174. for (pdtlnode = DtlGetFirstNode( pdtllistPorts );
  4175. pdtlnode;
  4176. pdtlnode = DtlGetNextNode( pdtlnode ))
  4177. {
  4178. ppbport = (PBPORT* )DtlGetData( pdtlnode );
  4179. // comments for bug 247189 234154 gangz
  4180. // Look for a system port has a matching pbdevicetype to the
  4181. // phonebook port
  4182. //
  4183. if (ppbport->pbdevicetype == ppblink->pbport.pbdevicetype)
  4184. {
  4185. // Don't convert two links of the entry to use the
  4186. // same port. If there aren't enough similar ports,
  4187. // the overflow will be left "unknown". (bug 63203).
  4188. //
  4189. //Comments for bug 247189 234154 gangz
  4190. // FILTER DUPE#1
  4191. // Look for a system port which is never used by the
  4192. // links read before the current one loaded from phonebook
  4193. //
  4194. DTLNODE* pNodeL;
  4195. for (pNodeL = DtlGetFirstNode( ppbentry->pdtllistLinks );
  4196. pNodeL;
  4197. pNodeL = DtlGetNextNode( pNodeL ))
  4198. {
  4199. PBLINK* pLink = DtlGetData( pNodeL );
  4200. {
  4201. if (
  4202. (pLink->pbport.fConfigured) && // 373745
  4203. (lstrcmp(
  4204. pLink->pbport.pszPort,
  4205. ppbport->pszPort ) == 0)
  4206. )
  4207. {
  4208. break;
  4209. }
  4210. }
  4211. }
  4212. if (!pNodeL)
  4213. {
  4214. //For whistler bug 247189 234254 gangz
  4215. //First we create a DUN on Com1 with no modem installed
  4216. //then create a DCC guest on Com2. A null modem will
  4217. //be installed on Com2, then this DUN is changed to
  4218. //be DCC type and also switches to use Com2's null
  4219. //modem which is only for DCC connections.
  4220. //
  4221. //The basic problem is:
  4222. //We cannot copy a system port just according to its
  4223. //pbdevicetype, we should also check its dwType
  4224. //because (1) NULL modem is not a modem for DUN, it's just for
  4225. // DCC Connection.
  4226. // (2) When creating NULL Modem, its pbdevicetype is
  4227. // assigned to RDT_Modem
  4228. // Then, we need also check if the dwType of the
  4229. // system port matches that of phonebook port
  4230. //
  4231. //Besides: file.c is in pbk.lib which is linked to both rasdlg.dll
  4232. //loaded into explorer and rasapi32.dll hosted by one of the
  4233. //svchost.exe!!!
  4234. if (ppblink->pbport.dwType == ppbport->dwType)
  4235. {
  4236. TRACE( "Port converted" );
  4237. dwErr = CopyToPbport( &ppblink->pbport, ppbport );
  4238. if ((ppblink->pbport.pbdevicetype == PBDT_Modem) ||
  4239. (ppblink->pbport.dwFlags & PBP_F_NullModem)
  4240. )
  4241. {
  4242. SetDefaultModemSettings( ppblink );
  4243. }
  4244. fDirty = ppbentry->fDirty = TRUE;
  4245. break;
  4246. }
  4247. }//end of if (!pNodeL) {}
  4248. }//end of if (ppbport->pbdevicetype == ppblink->pbport.pbdevicetype)
  4249. }//End of //Loop over each loaded System Port
  4250. // pmay: 383038
  4251. //
  4252. // We only want to fall into the following path if the type
  4253. // is Direct. Rao checked in the following path with the
  4254. // intention that a DCC connection not be rolled into a MODEM
  4255. // connection if another DCC device was present on the system.
  4256. //
  4257. if ( (ppbentry->dwType == RASET_Direct)
  4258. || (ppbentry->dwType == RASET_Broadband))
  4259. {
  4260. // If we don't find a port with the same devicetype try to find
  4261. // a port with the same entry type
  4262. //
  4263. for(pdtlnode = DtlGetFirstNode( pdtllistPorts);
  4264. pdtlnode;
  4265. pdtlnode = DtlGetNextNode(pdtlnode))
  4266. {
  4267. DWORD dwType;
  4268. ppbport = (PBPORT *) DtlGetData(pdtlnode);
  4269. dwType = EntryTypeFromPbport( ppbport );
  4270. if(ppbentry->dwType == dwType)
  4271. {
  4272. TRACE("Port with same entry type found");
  4273. dwErr = CopyToPbport(&ppblink->pbport, ppbport);
  4274. fDirty = ppbentry->fDirty = TRUE;
  4275. break;
  4276. }
  4277. }
  4278. }
  4279. if (dwErr != 0)
  4280. {
  4281. break;
  4282. }
  4283. }
  4284. fFoundMedia = TRUE;
  4285. } //end of Loop over each (media+device) section in a connectoid section
  4286. if (dwErr != 0)
  4287. {
  4288. break;
  4289. }
  4290. if (!fSectionDeleted)
  4291. {
  4292. // pmay: 277801
  4293. //
  4294. // At this point, the list of pblinks is read in and ready to go.
  4295. // Apply the "preferred device" logic. (only applies to singlelink)
  4296. //
  4297. if (DtlGetNodes(ppbentry->pdtllistLinks) == 1)
  4298. {
  4299. PBLINK* pLink;
  4300. DTLNODE* pNodeL, *pNodeP;
  4301. pNodeL = DtlGetFirstNode( ppbentry->pdtllistLinks );
  4302. pLink = (PBLINK* )DtlGetData( pNodeL );
  4303. // If the preferred device has been assigned,
  4304. // use it if it exists
  4305. //
  4306. if (ppbentry->pszPreferredDevice && ppbentry->pszPreferredPort)
  4307. {
  4308. // The current device doesn't match the
  4309. // preferred device
  4310. //
  4311. if ((pLink->pbport.pszPort == NULL) ||
  4312. (pLink->pbport.pszDevice == NULL) ||
  4313. (lstrcmpi(
  4314. pLink->pbport.pszPort,
  4315. ppbentry->pszPreferredPort)) ||
  4316. (lstrcmpi(
  4317. pLink->pbport.pszDevice,
  4318. ppbentry->pszPreferredDevice)))
  4319. {
  4320. PBPORT* pPort;
  4321. // See if the preferred device exists on the
  4322. // system
  4323. //
  4324. for (pNodeP = DtlGetFirstNode( pdtllistPorts );
  4325. pNodeP;
  4326. pNodeP = DtlGetNextNode( pNodeP ))
  4327. {
  4328. pPort = (PBPORT*)DtlGetData(pNodeP);
  4329. // The preferred device is found! Use it.
  4330. //
  4331. if ((pPort->pszPort != NULL) &&
  4332. (pPort->pszDevice != NULL) &&
  4333. (lstrcmpi(
  4334. ppbentry->pszPreferredPort,
  4335. pPort->pszPort) == 0) &&
  4336. (lstrcmpi(
  4337. ppbentry->pszPreferredDevice,
  4338. pPort->pszDevice) == 0))
  4339. {
  4340. dwErr = CopyToPbport(&pLink->pbport, pPort);
  4341. // For .Net bug 639551 gangz
  4342. // Add Preferred modem settings
  4343. pLink->dwBps = ppbentry->dwPreferredBps;
  4344. pLink->fHwFlow = ppbentry->fPreferredHwFlow;
  4345. pLink->fEc = ppbentry->fPreferredEc;
  4346. pLink->fEcc = ppbentry->fPreferredEcc;
  4347. pLink->fSpeaker = ppbentry->fPreferredSpeaker;
  4348. //For whistler bug 402522 gangz
  4349. //Add preferred modem protocol
  4350. //
  4351. pLink->dwModemProtocol =
  4352. ppbentry->dwPreferredModemProtocol;
  4353. fDirty = ppbentry->fDirty = TRUE;
  4354. break;
  4355. }
  4356. }
  4357. }
  4358. }
  4359. // pmay: 401398 -- bug postponed so I'm just commenting this out.
  4360. //
  4361. // If this is a DCC connection, then it is valid to have the
  4362. // preferred port set w/o having the prefered device set. This
  4363. // will be the case for NULL modems that we install. If the
  4364. // preferred port is set for such a connection, force the current
  4365. // device to resolve to a null modem on that port.
  4366. //
  4367. //else if (ppbentry->dwType == RASET_Direct)
  4368. //{
  4369. // if ((ppbentry->pszPreferredPort) &&
  4370. // (!ppbentry->pszPreferredDevice) &&
  4371. // (lstrcmpi(
  4372. // pLink->pbport.pszPort,
  4373. // ppbentry->pszPreferredPort))
  4374. // )
  4375. // {
  4376. // PBPORT* pPort;
  4377. //
  4378. // // Attempt to resolve the connection to the
  4379. // // correct preferred device.
  4380. // //
  4381. // for (pNodeP = DtlGetFirstNode( pdtllistPorts );
  4382. // pNodeP;
  4383. // pNodeP = DtlGetNextNode( pNodeP ))
  4384. // {
  4385. // pPort = (PBPORT*)DtlGetData(pNodeP);
  4386. //
  4387. // // The preferred device is found! Use it.
  4388. // //
  4389. // if ((pPort->pszPort != NULL) &&
  4390. // (lstrcmpi(
  4391. // ppbentry->pszPreferredPort,
  4392. // pPort->pszPort) == 0) &&
  4393. // (pPort->dwFlags & PBP_F_NullModem))
  4394. // {
  4395. // dwErr = CopyToPbport(&pLink->pbport, pPort);
  4396. // fDirty = ppbentry->fDirty = TRUE;
  4397. // break;
  4398. // }
  4399. // }
  4400. // }
  4401. //}
  4402. // The preferred device is not configured. This will only be
  4403. // the case for entries that were created before 277801 was
  4404. // resolved or for entries that went multilink->singlelink.
  4405. //
  4406. // Assign the preferred device as the currently selected
  4407. // device.
  4408. //
  4409. else
  4410. {
  4411. if (pLink->pbport.pszPort != NULL)
  4412. {
  4413. ppbentry->pszPreferredPort = StrDup(pLink->pbport.pszPort);
  4414. }
  4415. if (pLink->pbport.pszDevice != NULL)
  4416. {
  4417. ppbentry->pszPreferredDevice =
  4418. StrDup(pLink->pbport.pszDevice);
  4419. }
  4420. // For .Net 639551
  4421. ppbentry->dwPreferredBps = pLink->dwBps;
  4422. ppbentry->fPreferredHwFlow = pLink->fHwFlow;
  4423. ppbentry->fPreferredEc = pLink->fEc;
  4424. ppbentry->fPreferredEcc = pLink->fEcc;
  4425. ppbentry->fPreferredSpeaker = pLink->fSpeaker;
  4426. //For whistler bug 402522
  4427. //
  4428. ppbentry->dwPreferredModemProtocol =
  4429. pLink->dwModemProtocol;
  4430. }
  4431. }
  4432. // Translate old one-per-entry phone number part mapping to the
  4433. // new one-per-phone-number mapping.
  4434. //
  4435. if (fOldPhoneNumberParts)
  4436. {
  4437. DTLNODE* pNodeL;
  4438. DTLNODE* pNodeP;
  4439. PBLINK* pLink;
  4440. PBPHONE* pPhone;
  4441. for (pNodeL = DtlGetFirstNode( ppbentry->pdtllistLinks );
  4442. pNodeL;
  4443. pNodeL = DtlGetNextNode( pNodeL ))
  4444. {
  4445. pLink = (PBLINK* )DtlGetData( pNodeL );
  4446. for (pNodeP = DtlGetFirstNode( pLink->pdtllistPhones );
  4447. pNodeP;
  4448. pNodeP = DtlGetNextNode( pNodeP ))
  4449. {
  4450. pPhone = (PBPHONE* )DtlGetData( pNodeP );
  4451. pPhone->fUseDialingRules = fOldUseDialingRules;
  4452. Free0( pPhone->pszAreaCode );
  4453. pPhone->pszAreaCode = StrDup( pszOldAreaCode );
  4454. pPhone->dwCountryCode = dwOldCountryCode;
  4455. pPhone->dwCountryID = dwOldCountryID;
  4456. fDirty = ppbentry->fDirty = TRUE;
  4457. }
  4458. }
  4459. TRACE( "Phone# parts remapped" );
  4460. }
  4461. // Multiple links only allowed with PPP framing.
  4462. //
  4463. if (ppbentry->dwBaseProtocol != BP_Ppp
  4464. && DtlGetNodes( ppbentry->pdtllistLinks ) > 1)
  4465. {
  4466. TRACE( "Non-PPP multi-link corrected" );
  4467. ppbentry->dwBaseProtocol = BP_Ppp;
  4468. fDirty = ppbentry->fDirty = TRUE;
  4469. }
  4470. // Make sure entry type and dependent settings are appropriate for
  4471. // device list.
  4472. //
  4473. {
  4474. DTLNODE* pdtlnode;
  4475. PBLINK* ppblinkTmp;
  4476. DWORD dwType;
  4477. pdtlnode = DtlGetFirstNode( ppbentry->pdtllistLinks );
  4478. if (pdtlnode)
  4479. {
  4480. ppblinkTmp = (PBLINK* )DtlGetData( pdtlnode );
  4481. ASSERT( ppblinkTmp );
  4482. dwType = EntryTypeFromPbport( &ppblinkTmp->pbport );
  4483. if ( RASET_Internet != ppbentry->dwType
  4484. && dwType != ppbentry->dwType)
  4485. {
  4486. TRACE2("Fix entry type, %d to %d",
  4487. ppbentry->dwType, dwType);
  4488. ChangeEntryType( ppbentry, dwType );
  4489. fDirty = ppbentry->fDirty = TRUE;
  4490. }
  4491. if( (NULL != ppblinkTmp->pbport.pszDevice)
  4492. && ( CSTR_EQUAL == CompareString(
  4493. LOCALE_INVARIANT,
  4494. NORM_IGNORECASE,
  4495. TEXT("RASPPTPM"),
  4496. -1,
  4497. ppblinkTmp->pbport.pszDevice,
  4498. -1
  4499. ) )
  4500. )
  4501. {
  4502. TRACE1("Fix pptp device name. %s to "
  4503. "WAN Miniport (PPTP)",
  4504. ppblinkTmp->pbport.pszDevice);
  4505. Free(ppblinkTmp->pbport.pszDevice);
  4506. ppblinkTmp->pbport.pszDevice =
  4507. StrDup(TEXT("WAN Miniport (PPTP)"));
  4508. ppbentry->dwVpnStrategy = VS_Default;
  4509. fDirty = ppbentry->fDirty = TRUE;
  4510. }
  4511. }
  4512. }
  4513. // If there was no shared phone number setting (i.e. upgrading an
  4514. // NT4.0 or earlier entry), set the flag on when there is a single
  4515. // link and off otherwise.
  4516. //
  4517. if (ppbentry->fSharedPhoneNumbers == (BOOL )-1)
  4518. {
  4519. ppbentry->fSharedPhoneNumbers =
  4520. (DtlGetNodes( ppbentry->pdtllistLinks ) <= 1);
  4521. fDirty = ppbentry->fDirty = TRUE;
  4522. }
  4523. // Upgrade the authorization restrictions You'll know if you need
  4524. // to upgrade the dwAuthRestrictions variable because old phone
  4525. // books have this value set to 0 or have some of the bottom 3
  4526. // bits set.
  4527. //
  4528. if ( (ppbentry->dwAuthRestrictions == 0) ||
  4529. (ppbentry->dwAuthRestrictions & 0x7) )
  4530. {
  4531. switch (ppbentry->dwAuthRestrictions)
  4532. {
  4533. case AR_AuthEncrypted:
  4534. case AR_AuthMsEncrypted:
  4535. {
  4536. ppbentry->dwAuthRestrictions = AR_F_TypicalSecure;
  4537. ppbentry->dwTypicalAuth = TA_Secure;
  4538. break;
  4539. }
  4540. case AR_AuthCustom:
  4541. {
  4542. ppbentry->dwAuthRestrictions = AR_F_TypicalCardOrCert;
  4543. ppbentry->dwTypicalAuth = TA_CardOrCert;
  4544. break;
  4545. }
  4546. case AR_AuthTerminal:
  4547. case AR_AuthAny:
  4548. default:
  4549. {
  4550. ppbentry->dwAuthRestrictions = AR_F_TypicalUnsecure;
  4551. ppbentry->dwTypicalAuth = TA_Unsecure;
  4552. break;
  4553. }
  4554. }
  4555. TRACE1( "Upgraded dwAuthRestrictions to %x",
  4556. ppbentry->dwAuthRestrictions);
  4557. fDirty = ppbentry->fDirty = TRUE;
  4558. }
  4559. if ((ppbentry->dwAuthRestrictions & AR_F_AuthW95MSCHAP)
  4560. && !(ppbentry->dwAuthRestrictions & AR_F_AuthMSCHAP))
  4561. {
  4562. TRACE( "W95CHAP removed from dwAuthRestrictions" );
  4563. ppbentry->dwAuthRestrictions &= ~(AR_F_AuthW95MSCHAP);
  4564. fDirty = ppbentry->fDirty = TRUE;
  4565. }
  4566. // Upgrade old data encryption settings.
  4567. //
  4568. switch (ppbentry->dwDataEncryption)
  4569. {
  4570. case DE_Mppe40bit:
  4571. case DE_IpsecDefault:
  4572. case DE_VpnAlways:
  4573. case DE_PhysAlways:
  4574. {
  4575. ppbentry->dwDataEncryption = DE_Require;
  4576. fDirty = ppbentry->fDirty = TRUE;
  4577. break;
  4578. }
  4579. case DE_Mppe128bit:
  4580. {
  4581. ppbentry->dwDataEncryption = DE_RequireMax;
  4582. fDirty = ppbentry->fDirty = TRUE;
  4583. break;
  4584. }
  4585. }
  4586. //
  4587. // pmay: 233258
  4588. //
  4589. // Based on registry settings, this entry may need to
  4590. // be modified. (upgrade from nt4)
  4591. //
  4592. if ( fOldPhonebook )
  4593. {
  4594. UpgradeRegistryOptions( (fRouter) ?
  4595. pFile->hConnection
  4596. : NULL,
  4597. ppbentry );
  4598. fDirty = ppbentry->fDirty = TRUE;
  4599. }
  4600. // pmay: 422924
  4601. //
  4602. // Make sure that the network components section is in sync
  4603. // with the values written into fBindMsNetClient and
  4604. // fShareMsFilePrint
  4605. //
  4606. {
  4607. // If the component is not listed, then the default
  4608. // is checked (on) for both settings. see rasdlg\penettab.c
  4609. //
  4610. BOOL fClient = TRUE, fServer = TRUE;
  4611. BOOL fEnabled;
  4612. // Sync up the ms client value
  4613. //
  4614. if (FIsNetComponentListed(
  4615. ppbentry,
  4616. TEXT("ms_msclient"),
  4617. &fEnabled,
  4618. NULL))
  4619. {
  4620. fClient = fEnabled;
  4621. }
  4622. if ((!!fClient) != (!!ppbentry->fBindMsNetClient))
  4623. {
  4624. ppbentry->fBindMsNetClient = fClient;
  4625. fDirty = ppbentry->fDirty = TRUE;
  4626. }
  4627. // Sync up the ms server value
  4628. //
  4629. if (FIsNetComponentListed(
  4630. ppbentry,
  4631. TEXT("ms_server"),
  4632. &fEnabled,
  4633. NULL))
  4634. {
  4635. fServer = fEnabled;
  4636. }
  4637. if ((!!fServer) != (!!ppbentry->fShareMsFilePrint))
  4638. {
  4639. ppbentry->fShareMsFilePrint = fServer;
  4640. fDirty = ppbentry->fDirty = TRUE;
  4641. }
  4642. }
  4643. //
  4644. // pmay: 336150
  4645. //
  4646. // If we translated this entry from ANSI to UTF8, then the
  4647. // entry name may have changed. We need to delete the old
  4648. // entry name so that there wont be a duplicate.
  4649. //
  4650. if (dwEncoding == EN_Ansi)
  4651. {
  4652. TRACE( "Ansi Encoding? (section deleted)" );
  4653. DeleteCurrentSection(h);
  4654. fSectionDeleted = TRUE;
  4655. }
  4656. // pmay: 387941
  4657. //
  4658. // Prevent connections from sharing credentials.
  4659. //
  4660. if (ppbentry->dwDialParamsUID == 0)
  4661. {
  4662. ppbentry->dwDialParamsUID = GetTickCount() + dwDialUIDOffset;
  4663. dwDialUIDOffset++;
  4664. fDirty = ppbentry->fDirty = TRUE;
  4665. }
  4666. }
  4667. }//End of reading each connectoid section in a phonebook file
  4668. if (dwErr != 0)
  4669. {
  4670. if (dwFlags & RPBF_HeadersOnly)
  4671. {
  4672. DtlDestroyList( pFile->pdtllistEntries, DestroyPszNode );
  4673. }
  4674. else if (dwFlags & RPBF_HeaderType)
  4675. {
  4676. DtlDestroyList( pFile->pdtllistEntries, DestroyEntryTypeNode );
  4677. }
  4678. else
  4679. {
  4680. DtlDestroyList( pFile->pdtllistEntries, DestroyEntryNode );
  4681. }
  4682. }
  4683. else if(fDirty)
  4684. {
  4685. WritePhonebookFile( pFile, NULL );
  4686. }
  4687. if (pdtllistPorts)
  4688. {
  4689. DtlDestroyList( pdtllistPorts, DestroyPortNode );
  4690. }
  4691. Free0( pszOldAreaCode );
  4692. Free0( szValue );
  4693. return dwErr;
  4694. }
  4695. DWORD
  4696. ReadFlag(
  4697. IN HRASFILE h,
  4698. IN RFSCOPE rfscope,
  4699. IN CHAR* pszKey,
  4700. OUT BOOL* pfResult )
  4701. // Utility routine to read a flag value from the next line in the scope
  4702. // 'rfscope' with key 'pszKey'. The result is placed in caller's
  4703. // '*ppszResult' buffer. The current line is reset to the start of the
  4704. // scope if the call was successful.
  4705. //
  4706. // Returns 0 if successful, or a non-zero error code. "Not found" is
  4707. // considered successful, in which case '*pfResult' is not changed.
  4708. //
  4709. {
  4710. DWORD dwErr;
  4711. LONG lResult = *pfResult;
  4712. dwErr = ReadLong( h, rfscope, pszKey, &lResult );
  4713. if (lResult != (LONG )*pfResult)
  4714. {
  4715. *pfResult = (lResult != 0);
  4716. }
  4717. return dwErr;
  4718. }
  4719. DWORD
  4720. ReadLong(
  4721. IN HRASFILE h,
  4722. IN RFSCOPE rfscope,
  4723. IN CHAR* pszKey,
  4724. OUT LONG* plResult )
  4725. // Utility routine to read a long integer value from the next line in the
  4726. // scope 'rfscope' with key 'pszKey'. The result is placed in caller's
  4727. // '*ppszResult' buffer. The current line is reset to the start of the
  4728. // scope if the call was successful.
  4729. //
  4730. // Returns 0 if successful, or a non-zero error code. "Not found" is
  4731. // considered successful, in which case '*plResult' is not changed.
  4732. //
  4733. {
  4734. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ];
  4735. BOOL fFound;
  4736. fFound = RasfileFindNextKeyLine( h, pszKey, rfscope );
  4737. if (!fFound)
  4738. {
  4739. //DbgPrint( "Pbk Perf: seeking back to top of scope to look for '%s'\n",
  4740. // pszKey );
  4741. RasfileFindFirstLine( h, RFL_ANY, rfscope );
  4742. fFound = RasfileFindNextKeyLine( h, pszKey, rfscope );
  4743. }
  4744. if (fFound)
  4745. {
  4746. if (!RasfileGetKeyValueFields( h, NULL, szValue ))
  4747. {
  4748. return ERROR_NOT_ENOUGH_MEMORY;
  4749. }
  4750. *plResult = atol( szValue );
  4751. }
  4752. return 0;
  4753. }
  4754. VOID
  4755. ReadNetComponents(
  4756. IN HRASFILE h,
  4757. IN DTLLIST* pdtllist )
  4758. // Read the list of networking component key/value pairs from the
  4759. // NETCOMPONENT group into 'pdtllist'. 'H' is the open RAS:FILE handle
  4760. // assumed to be positioned before somewhere before the NETCOMPONENTS
  4761. // group in the entry section. The RASFILE 'CurLine' is left just after
  4762. // the group.
  4763. //
  4764. {
  4765. if (!RasfilePutLineMark( h, MARK_BeginNetComponentsSearch ))
  4766. {
  4767. return;
  4768. }
  4769. if (!RasfileFindNextLine( h, RFL_GROUP, RFS_SECTION )
  4770. || !IsNetComponentsLine( (CHAR* )RasfileGetLine( h ) ))
  4771. {
  4772. // No NetComponents group. Return 'CurLine' to starting position.
  4773. //
  4774. while (RasfileGetLineMark( h ) != MARK_BeginNetComponentsSearch)
  4775. {
  4776. RasfileFindPrevLine( h, RFL_ANY, RFS_SECTION );
  4777. }
  4778. RasfilePutLineMark( h, 0 );
  4779. return;
  4780. }
  4781. // Found the NETCOMPONENTS group header.
  4782. //
  4783. while (RasfileFindNextLine( h, RFL_ANY, RFS_GROUP ))
  4784. {
  4785. DTLNODE* pdtlnode;
  4786. CHAR szKey[ RAS_MAXLINEBUFLEN + 1 ];
  4787. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ];
  4788. TCHAR* pszKey;
  4789. TCHAR* pszValue;
  4790. if (!RasfileGetKeyValueFields( h, szKey, szValue ))
  4791. {
  4792. continue;
  4793. }
  4794. pszKey = StrDupTFromA( szKey );
  4795. pszValue = StrDupTFromA( szValue );
  4796. if (pszKey && pszValue)
  4797. {
  4798. pdtlnode = CreateKvNode( pszKey, pszValue );
  4799. if (pdtlnode)
  4800. {
  4801. DtlAddNodeLast( pdtllist, pdtlnode );
  4802. }
  4803. }
  4804. Free0( pszKey );
  4805. Free0( pszValue );
  4806. }
  4807. }
  4808. DWORD
  4809. CalculatePhonebookPath(
  4810. IN LPCTSTR pszPhonebookPath,
  4811. IN PBUSER* pUser,
  4812. IN DWORD dwFlags,
  4813. OUT DWORD* lpdwMode,
  4814. OUT LPTSTR* ppszFullPath)
  4815. {
  4816. DWORD dwErr = NO_ERROR, dwMode;
  4817. TCHAR szFullPath[MAX_PATH + 1], *pszPath = NULL;
  4818. BOOL f;
  4819. PBUSER user;
  4820. do
  4821. {
  4822. if (pszPhonebookPath)
  4823. {
  4824. pszPath = StrDup( pszPhonebookPath );
  4825. if (!pszPath)
  4826. {
  4827. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  4828. break;
  4829. }
  4830. dwMode = IsPublicPhonebook(pszPath) ? PBM_System : PBM_Alternate;
  4831. }
  4832. else
  4833. {
  4834. if (pUser)
  4835. {
  4836. f = GetPhonebookPath(pUser, dwFlags, &pszPath, &dwMode );
  4837. }
  4838. else
  4839. {
  4840. // Caller didn't provide user preferences but we need them to
  4841. // find the phonebook, so look them up ourselves. Note that
  4842. // "not winlogon mode" is assumed.
  4843. //
  4844. dwErr = GetUserPreferences( NULL, &user, FALSE );
  4845. if (dwErr != 0)
  4846. {
  4847. break;
  4848. }
  4849. f = GetPhonebookPath(&user, dwFlags, &pszPath, &dwMode );
  4850. DestroyUserPreferences( &user );
  4851. }
  4852. if (!f)
  4853. {
  4854. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  4855. break;
  4856. }
  4857. }
  4858. TRACEW1( "path=%s", pszPath );
  4859. if (GetFullPathName(pszPath, MAX_PATH, szFullPath, NULL) > 0)
  4860. {
  4861. TRACEW1( "full path=%s", szFullPath );
  4862. Free(pszPath);
  4863. pszPath = StrDup(szFullPath);
  4864. if(NULL == pszPath)
  4865. {
  4866. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  4867. break;
  4868. }
  4869. }
  4870. // Ok, we've calulated the full path without error. Assign the return
  4871. // values
  4872. //
  4873. *lpdwMode = dwMode;
  4874. *ppszFullPath = pszPath;
  4875. }while (FALSE);
  4876. // Cleanup
  4877. //
  4878. {
  4879. if (dwErr != NO_ERROR)
  4880. {
  4881. Free0( pszPath );
  4882. }
  4883. }
  4884. return dwErr;
  4885. }
  4886. #ifdef _PBK_CACHE_
  4887. //Synchronize pbkcache's read file-last-write-time
  4888. //for bug 559381 and 537369
  4889. DWORD
  4890. GetFileLastWriteTime(
  4891. IN PWCHAR pwszFileName,
  4892. OUT FILETIME* pTime )
  4893. {
  4894. HANDLE hFile = NULL;
  4895. DWORD dwErr = NO_ERROR;
  4896. BOOL fOk = FALSE;
  4897. BY_HANDLE_FILE_INFORMATION Info;
  4898. FILETIME ftTime;
  4899. BOOL fRet = FALSE;
  4900. do
  4901. {
  4902. // Get the file handle
  4903. //
  4904. ASSERT( g_hmutexPb );
  4905. WaitForSingleObject( g_hmutexPb, INFINITE );
  4906. hFile = CreateFileW(
  4907. pwszFileName,
  4908. 0,
  4909. FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
  4910. NULL,
  4911. OPEN_EXISTING,
  4912. FILE_ATTRIBUTE_NORMAL,
  4913. NULL);
  4914. if (hFile == INVALID_HANDLE_VALUE)
  4915. {
  4916. dwErr = GetLastError();
  4917. break;
  4918. }
  4919. fOk = GetFileInformationByHandle( hFile, &Info);
  4920. if (!fOk)
  4921. {
  4922. dwErr = GetLastError();
  4923. break;
  4924. }
  4925. }
  4926. while(FALSE);
  4927. if( INVALID_HANDLE_VALUE != hFile )
  4928. {
  4929. CloseHandle(hFile);
  4930. }
  4931. if( NO_ERROR == dwErr )
  4932. {
  4933. *pTime = Info.ftLastWriteTime;
  4934. }
  4935. ReleaseMutex( g_hmutexPb );
  4936. return dwErr;
  4937. }
  4938. #endif
  4939. DWORD
  4940. ReadPhonebookFile(
  4941. IN LPCTSTR pszPhonebookPath,
  4942. IN PBUSER* pUser,
  4943. IN LPCTSTR pszSection,
  4944. IN DWORD dwFlags,
  4945. OUT PBFILE* pFile )
  4946. {
  4947. return ReadPhonebookFileEx(
  4948. pszPhonebookPath,
  4949. pUser,
  4950. pszSection,
  4951. dwFlags,
  4952. pFile,
  4953. NULL);
  4954. }
  4955. DWORD
  4956. ReadPhonebookFileEx(
  4957. IN LPCTSTR pszPhonebookPath,
  4958. IN PBUSER* pUser,
  4959. IN LPCTSTR pszSection,
  4960. IN DWORD dwFlags,
  4961. OUT PBFILE* pFile,
  4962. OUT OPTIONAL FILETIME* pTime)
  4963. // Reads the phonebook file into a list of PBENTRY.
  4964. //
  4965. // 'PszPhonebookPath' specifies the full path to the RAS phonebook file,
  4966. // or is NULL indicating the default phonebook should be used.
  4967. //
  4968. // 'PUser' is the user preferences used to determine the default phonebook
  4969. // path or NULL if they should be looked up by this routine. If
  4970. // 'pszPhonebookPath' is non-NULL 'pUser' is ignored. Note that caller
  4971. // MUST provide his own 'pUser' in "winlogon" mode.
  4972. //
  4973. // 'PszSection' indicates that only the section named 'pszSection' should
  4974. // be loaded, or is NULL to indicate all sections.
  4975. //
  4976. // 'DwFlags' options: 'RPBF_ReadOnly' causes the file to be opened for
  4977. // reading only. 'RPBF_HeadersOnly' causes only the headers to loaded,
  4978. // and the memory image is parsed into a list of strings, unless the flag
  4979. // 'RPBF_NoList' is specified.
  4980. //
  4981. // 'PFile' is the address of caller's file block. This routine sets
  4982. // 'pFile->hrasfile' to the handle to the open phonebook, 'pFile->pszPath'
  4983. // to the full path to the file mode, 'pFile->dwPhonebookMode' to the mode
  4984. // of the file, and 'pFile->pdtllistEntries' to the parsed chain of entry
  4985. // blocks.
  4986. //
  4987. // Returns 0 if successful, otherwise a non-0 error code. On success,
  4988. // caller should eventually call ClosePhonebookFile on the returned
  4989. // PBFILE*.
  4990. //
  4991. {
  4992. DWORD dwErr = 0;
  4993. BOOL fFileExists;
  4994. TRACE( "ReadPhonebookFile" );
  4995. pFile->hrasfile = -1;
  4996. pFile->pszPath = NULL;
  4997. pFile->dwPhonebookMode = PBM_System;
  4998. pFile->pdtllistEntries = NULL;
  4999. do
  5000. {
  5001. dwErr = CalculatePhonebookPath(
  5002. pszPhonebookPath,
  5003. pUser,
  5004. dwFlags,
  5005. &(pFile->dwPhonebookMode),
  5006. &(pFile->pszPath));
  5007. if (dwErr != NO_ERROR)
  5008. {
  5009. break;
  5010. }
  5011. fFileExists = FFileExists( pFile->pszPath );
  5012. if ((dwFlags & RPBF_NoCreate) && !fFileExists)
  5013. {
  5014. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5015. break;
  5016. }
  5017. if (!fFileExists)
  5018. {
  5019. // The phonebook file does not exist, so we need to create it.
  5020. //
  5021. HANDLE hFile;
  5022. SECURITY_ATTRIBUTES sa;
  5023. PSECURITY_DESCRIPTOR pSd = NULL;
  5024. // If we are creating the public phonebook file, be sure to
  5025. // create it with a security descriptor that allows it to be
  5026. // read by any authenticated user. If we don't it may prevent
  5027. // other users from being able to read it.
  5028. //
  5029. if (pFile->dwPhonebookMode == PBM_System)
  5030. {
  5031. dwErr = DwAllocateSecurityDescriptorAllowAccessToWorld(
  5032. &pSd);
  5033. if (dwErr)
  5034. {
  5035. break;
  5036. }
  5037. }
  5038. // Be sure that any directories on the path to the phonebook file
  5039. // exist. Otherwise, CreatFile will fail.
  5040. //
  5041. CreateDirectoriesOnPath(
  5042. pFile->pszPath,
  5043. NULL);
  5044. sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  5045. sa.lpSecurityDescriptor = pSd;
  5046. sa.bInheritHandle = TRUE;
  5047. hFile =
  5048. CreateFile(
  5049. pFile->pszPath,
  5050. GENERIC_READ | GENERIC_WRITE,
  5051. FILE_SHARE_READ,
  5052. &sa,
  5053. CREATE_ALWAYS,
  5054. FILE_ATTRIBUTE_NORMAL,
  5055. NULL );
  5056. Free0(pSd);
  5057. if (hFile == INVALID_HANDLE_VALUE)
  5058. {
  5059. CloseHandle( hFile );
  5060. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5061. break;
  5062. }
  5063. // for whistler 523647 gangz
  5064. // Have to check if this handle is for disk file
  5065. //
  5066. if( FILE_TYPE_DISK != GetFileType( hFile ) )
  5067. {
  5068. CloseHandle( hFile );
  5069. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5070. break;
  5071. }
  5072. CloseHandle( hFile );
  5073. if (pFile->dwPhonebookMode == PBM_System)
  5074. {
  5075. TRACE( "System phonebook created." );
  5076. }
  5077. else
  5078. {
  5079. TRACE( "User phonebook created." );
  5080. }
  5081. }
  5082. // Load the phonebook file into memory. In "write" mode, comments are
  5083. // loaded so user's custom comments (if any) will be preserved.
  5084. // Normally, there will be none so this costs nothing in the typical
  5085. // case.
  5086. //
  5087. {
  5088. DWORD dwMode;
  5089. CHAR* pszPathA;
  5090. dwMode = 0;
  5091. if (dwFlags & RPBF_ReadOnly)
  5092. {
  5093. dwMode |= RFM_READONLY;
  5094. }
  5095. else
  5096. {
  5097. dwMode |= RFM_CREATE | RFM_LOADCOMMENTS;
  5098. }
  5099. if (dwFlags & RPBF_HeadersOnly)
  5100. {
  5101. dwMode |= RFM_ENUMSECTIONS;
  5102. }
  5103. // Read the disk file into a linked list of lines.
  5104. //
  5105. pszPathA = StrDupAFromTAnsi( pFile->pszPath );
  5106. if (pszPathA)
  5107. {
  5108. ASSERT( g_hmutexPb );
  5109. WaitForSingleObject( g_hmutexPb, INFINITE );
  5110. pFile->hrasfile = RasfileLoadEx(
  5111. pszPathA, dwMode, NULL, IsGroup, pTime);
  5112. ReleaseMutex( g_hmutexPb );
  5113. }
  5114. Free0( pszPathA );
  5115. if (pFile->hrasfile == -1)
  5116. {
  5117. dwErr = ERROR_CANNOT_LOAD_PHONEBOOK;
  5118. break;
  5119. }
  5120. }
  5121. // Parse the linked list of lines
  5122. //
  5123. if (!(dwFlags & RPBF_NoList))
  5124. {
  5125. // Read the phonebook file
  5126. //
  5127. dwErr = ReadEntryList(
  5128. pFile,
  5129. dwFlags,
  5130. pszSection );
  5131. if (dwErr != NO_ERROR)
  5132. {
  5133. break;
  5134. }
  5135. }
  5136. }
  5137. while (FALSE);
  5138. if (dwErr != 0)
  5139. {
  5140. //
  5141. // If we failed to read entry lists, ReadEntry*List above would
  5142. // have cleaned the lists. NULL the lists so that ClosePhonebookFile
  5143. // doesn't attempt to free the already freed memory
  5144. //
  5145. pFile->pdtllistEntries = NULL;
  5146. ClosePhonebookFile( pFile );
  5147. }
  5148. TRACE1( "ReadPhonebookFile=%d", dwErr );
  5149. return dwErr;
  5150. }
  5151. DWORD
  5152. ReadPhoneList(
  5153. IN HRASFILE h,
  5154. IN RFSCOPE rfscope,
  5155. OUT DTLLIST** ppdtllist,
  5156. OUT BOOL* pfDirty )
  5157. // Utility routine to read a list of PBPHONE nodes from next lines in the
  5158. // scope 'rfscope'. The result is placed in the allocated '*ppdtllist'
  5159. // list. The current line is reset to the start of the scope after the
  5160. // call. '*pfDirty' is set true if the entry should be re-written.
  5161. //
  5162. // Returns 0 if successful, or a non-zero error code. "Not found" is
  5163. // considered successful, in which case 'pdtllistResult' is set to an
  5164. // empty list. Caller is responsible for freeing the returned
  5165. // '*ppdtllist' list.
  5166. //
  5167. {
  5168. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ];
  5169. DTLNODE* pdtlnode;
  5170. PBPHONE* pPhone;
  5171. BOOL fOk;
  5172. // Free existing list, if present.
  5173. //
  5174. if (*ppdtllist)
  5175. {
  5176. DtlDestroyList( *ppdtllist, DestroyPhoneNode );
  5177. }
  5178. if (!(*ppdtllist = DtlCreateList( 0 )))
  5179. {
  5180. return ERROR_NOT_ENOUGH_MEMORY;
  5181. }
  5182. while (RasfileFindNextKeyLine( h, KEY_PhoneNumber, rfscope ))
  5183. {
  5184. fOk = FALSE;
  5185. do
  5186. {
  5187. // Allocate and link a node for the new phone number set.
  5188. //
  5189. pdtlnode = CreatePhoneNode();
  5190. if (!pdtlnode)
  5191. {
  5192. break;
  5193. }
  5194. DtlAddNodeLast( *ppdtllist, pdtlnode );
  5195. pPhone = (PBPHONE* )DtlGetData( pdtlnode );
  5196. // Read the individual fields in the set.
  5197. //
  5198. if (!RasfileGetKeyValueFields( h, NULL, szValue )
  5199. || !(pPhone->pszPhoneNumber = StrDupTFromA( szValue )))
  5200. {
  5201. break;
  5202. }
  5203. if (RasfileFindNextKeyLine( h, KEY_AreaCode, rfscope ))
  5204. {
  5205. if (!RasfileGetKeyValueFields( h, NULL, szValue )
  5206. || !(pPhone->pszAreaCode = StrDupTFromA( szValue )))
  5207. {
  5208. break;
  5209. }
  5210. }
  5211. if (RasfileFindNextKeyLine( h, KEY_CountryCode, rfscope ))
  5212. {
  5213. DWORD dwCountryCode;
  5214. if (!RasfileGetKeyValueFields( h, NULL, szValue ))
  5215. {
  5216. break;
  5217. }
  5218. dwCountryCode = atol( szValue );
  5219. if (dwCountryCode > 0)
  5220. {
  5221. pPhone->dwCountryCode = dwCountryCode;
  5222. }
  5223. else
  5224. {
  5225. *pfDirty = TRUE;
  5226. }
  5227. }
  5228. if (RasfileFindNextKeyLine( h, KEY_CountryID, rfscope ))
  5229. {
  5230. DWORD dwCountryID;
  5231. if (!RasfileGetKeyValueFields( h, NULL, szValue ))
  5232. {
  5233. break;
  5234. }
  5235. dwCountryID = atol( szValue );
  5236. if (dwCountryID > 0)
  5237. {
  5238. pPhone->dwCountryID = dwCountryID;
  5239. }
  5240. else
  5241. {
  5242. *pfDirty = TRUE;
  5243. }
  5244. }
  5245. if (RasfileFindNextKeyLine( h, KEY_UseDialingRules, rfscope ))
  5246. {
  5247. if (!RasfileGetKeyValueFields( h, NULL, szValue ))
  5248. {
  5249. break;
  5250. }
  5251. pPhone->fUseDialingRules = !!(atol( szValue ));
  5252. }
  5253. if (RasfileFindNextKeyLine( h, KEY_Comment, rfscope ))
  5254. {
  5255. if (!RasfileGetKeyValueFields( h, NULL, szValue )
  5256. || !(pPhone->pszComment = StrDupTFromA( szValue )))
  5257. {
  5258. break;
  5259. }
  5260. }
  5261. fOk = TRUE;
  5262. }
  5263. while (FALSE);
  5264. if (!fOk)
  5265. {
  5266. // One of the allocations failed. Clean up.
  5267. //
  5268. DtlDestroyList( *ppdtllist, DestroyPhoneNode );
  5269. *ppdtllist = NULL;
  5270. return ERROR_NOT_ENOUGH_MEMORY;
  5271. }
  5272. }
  5273. return 0;
  5274. }
  5275. DWORD
  5276. ReadString(
  5277. IN HRASFILE h,
  5278. IN STRDUP_T_FROM_A_FUNC pStrDupTFromA,
  5279. IN RFSCOPE rfscope,
  5280. IN CHAR* pszKey,
  5281. OUT TCHAR** ppszResult )
  5282. // Utility routine to read a string value from the next line in the scope
  5283. // 'rfscope' with key 'pszKey'. The result is placed in the allocated
  5284. // '*ppszResult' buffer. The current line is reset to the start of the
  5285. // scope if the call was successful.
  5286. //
  5287. // Returns 0 if successful, or a non-zero error code. "Not found" is
  5288. // considered successful, in which case '*ppszResult' is not changed.
  5289. // Caller is responsible for freeing the returned '*ppszResult' buffer.
  5290. //
  5291. {
  5292. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ];
  5293. BOOL fFound;
  5294. fFound = RasfileFindNextKeyLine( h, pszKey, rfscope );
  5295. if (!fFound)
  5296. {
  5297. //DbgPrint( "Pbk Perf: seeking back to top of scope to look for '%s'\n",
  5298. // pszKey );
  5299. RasfileFindFirstLine( h, RFL_ANY, rfscope );
  5300. fFound = RasfileFindNextKeyLine( h, pszKey, rfscope );
  5301. }
  5302. if (fFound)
  5303. {
  5304. if (!RasfileGetKeyValueFields( h, NULL, szValue )
  5305. || !(*ppszResult = pStrDupTFromA( szValue )))
  5306. {
  5307. return ERROR_NOT_ENOUGH_MEMORY;
  5308. }
  5309. }
  5310. return 0;
  5311. }
  5312. DWORD
  5313. ReadStringList(
  5314. IN HRASFILE h,
  5315. IN RFSCOPE rfscope,
  5316. IN CHAR* pszKey,
  5317. OUT DTLLIST** ppdtllistResult )
  5318. // Utility routine to read a list of string values from next lines in the
  5319. // scope 'rfscope' with key 'pszKey'. The result is placed in the
  5320. // allocated '*ppdtllistResult' list. The current line is reset to the
  5321. // start of the scope after the call.
  5322. //
  5323. // Returns 0 if successful, or a non-zero error code. "Not found" is
  5324. // considered successful, in which case 'pdtllistResult' is set to an
  5325. // empty list. Caller is responsible for freeing the returned
  5326. // '*ppdtllistResult' list.
  5327. //
  5328. {
  5329. CHAR szValue[ RAS_MAXLINEBUFLEN + 1 ];
  5330. // Free existing list, if present.
  5331. //
  5332. if (*ppdtllistResult)
  5333. {
  5334. DtlDestroyList( *ppdtllistResult, DestroyPszNode );
  5335. *ppdtllistResult = NULL;
  5336. }
  5337. if (!(*ppdtllistResult = DtlCreateList( 0 )))
  5338. {
  5339. return ERROR_NOT_ENOUGH_MEMORY;
  5340. }
  5341. while (RasfileFindNextKeyLine( h, pszKey, rfscope ))
  5342. {
  5343. TCHAR* psz;
  5344. DTLNODE* pdtlnode;
  5345. if (!RasfileGetKeyValueFields( h, NULL, szValue )
  5346. || !(psz = StrDupTFromA( szValue )))
  5347. {
  5348. DtlDestroyList( *ppdtllistResult, DestroyPszNode );
  5349. *ppdtllistResult = NULL;
  5350. return ERROR_NOT_ENOUGH_MEMORY;
  5351. }
  5352. if (!(pdtlnode = DtlCreateNode( psz, 0 )))
  5353. {
  5354. Free( psz );
  5355. DtlDestroyList( *ppdtllistResult, DestroyPszNode );
  5356. *ppdtllistResult = NULL;
  5357. return ERROR_NOT_ENOUGH_MEMORY;
  5358. }
  5359. DtlAddNodeLast( *ppdtllistResult, pdtlnode );
  5360. }
  5361. return 0;
  5362. }
  5363. VOID
  5364. TerminatePbk(
  5365. void )
  5366. // Terminate the PBK library. This routine should be called after all
  5367. // PBK library access is complete. See also InitializePbk.
  5368. //
  5369. {
  5370. if (g_hmutexPb)
  5371. {
  5372. CloseHandle( g_hmutexPb );
  5373. }
  5374. PbkPathInfoClear(&g_PbkPathInfo);
  5375. #ifdef _PBK_CACHE_
  5376. PbkCacheCleanup();
  5377. #endif
  5378. }
  5379. DWORD
  5380. WritePhonebookFile(
  5381. IN PBFILE* pFile,
  5382. IN LPCTSTR pszSectionToDelete )
  5383. // Write out any dirty globals or entries in 'pFile'. The
  5384. // 'pszSectionToDelete' indicates a section to delete or is NULL.
  5385. //
  5386. // Returns 0 if successful, otherwise a non-zero error code.
  5387. //
  5388. {
  5389. DWORD dwErr;
  5390. HRASFILE h = pFile->hrasfile;
  5391. TRACE( "WritePhonebookFile" );
  5392. if (pszSectionToDelete)
  5393. {
  5394. CHAR* pszSectionToDeleteA;
  5395. pszSectionToDeleteA = StrDupAFromT( pszSectionToDelete );
  5396. if (!pszSectionToDeleteA)
  5397. {
  5398. return ERROR_NOT_ENOUGH_MEMORY;
  5399. }
  5400. if (RasfileFindSectionLine( h, pszSectionToDeleteA, TRUE ))
  5401. {
  5402. DeleteCurrentSection( h );
  5403. }
  5404. Free( pszSectionToDeleteA );
  5405. }
  5406. dwErr = ModifyEntryList( pFile );
  5407. if (dwErr != 0)
  5408. {
  5409. return dwErr;
  5410. }
  5411. {
  5412. BOOL f;
  5413. ASSERT( g_hmutexPb );
  5414. WaitForSingleObject( g_hmutexPb, INFINITE );
  5415. f = RasfileWrite( h, NULL );
  5416. ReleaseMutex( g_hmutexPb );
  5417. if (!f)
  5418. {
  5419. return ERROR_CANNOT_WRITE_PHONEBOOK;
  5420. }
  5421. }
  5422. return 0;
  5423. }
  5424. #ifdef _PBK_CACHE_
  5425. DWORD
  5426. DwReadEntryFromCache(
  5427. IN LPCTSTR pszPhonebook,
  5428. IN LPCTSTR pszEntry,
  5429. IN DWORD dwFlags,
  5430. OUT DTLNODE **ppdtlnode,
  5431. OUT OPTIONAL WCHAR **ppszFullPath)
  5432. {
  5433. DWORD dwErr = NO_ERROR, dwMode = 0;
  5434. TCHAR* pszPath = NULL;
  5435. dwErr = CalculatePhonebookPath(
  5436. pszPhonebook,
  5437. NULL,
  5438. dwFlags,
  5439. &dwMode,
  5440. &pszPath);
  5441. if (dwErr != NO_ERROR)
  5442. {
  5443. return dwErr;
  5444. }
  5445. dwErr = PbkCacheGetEntry((WCHAR*)pszPath, (WCHAR*)pszEntry, ppdtlnode);
  5446. if ((dwErr == NO_ERROR) && (ppszFullPath))
  5447. {
  5448. *ppszFullPath = pszPath;
  5449. }
  5450. else
  5451. {
  5452. Free0(pszPath);
  5453. }
  5454. return dwErr;
  5455. }
  5456. #endif
  5457. // (0 )Reads the entry node from the name and the phoenbook
  5458. // file specified. 'pszPhonebook' can be NULL.
  5459. // (1) ppdtlnode and pFile cannot be NULL at the same time
  5460. // (2) if pFile == NULL, only return entry node to ppdtlnode
  5461. // (3) if pFile != NULL && ppdtlnode != NULL, return PBFILE info to pFile and
  5462. // return the pszEntry node pointer from pFile->pdtllistEntries to ppdtlnode
  5463. //
  5464. DWORD
  5465. DwReadEntryFromSystem(
  5466. IN LPCTSTR pszPhonebook,
  5467. IN LPCTSTR pszEntry,
  5468. IN DWORD dwFlags,
  5469. IN OUT OPTIONAL PBFILE *pFile,
  5470. OUT DTLNODE **ppdtlnode,
  5471. OUT OPTIONAL WCHAR **ppszFullPath)
  5472. {
  5473. DWORD dwErr = NO_ERROR;
  5474. DTLNODE *pdtlnode = NULL, *pCopyNode = NULL;
  5475. PBFILE tmpFile, * pTmpFile = NULL;
  5476. BOOL fFileOpened = FALSE;
  5477. // For .Net bug 559381 (oobe bug) turn off pbkCache
  5478. // If we never find it is necessary in the future,
  5479. // (1) remove all the #ifdef _PBK_CACHE blocks
  5480. // (2) remove PbkCache.cpp/h
  5481. //
  5482. #ifdef _PBK_CACHE_
  5483. if (fReadFromCache)
  5484. {
  5485. return DwReadEntryFromCache(
  5486. pszPhonebook,
  5487. pszEntry,
  5488. dwFlags,
  5489. ppdtlnode,
  5490. ppszFullPath);
  5491. }
  5492. #endif
  5493. if( NULL == ppdtlnode &&
  5494. NULL == pFile )
  5495. {
  5496. return ERROR_INVALID_PARAMETER;
  5497. }
  5498. // Initialize output parameters
  5499. //
  5500. if( ppdtlnode ) *ppdtlnode = NULL;
  5501. if( ppszFullPath ) *ppszFullPath = NULL;
  5502. if( ppszFullPath )
  5503. {
  5504. TCHAR* pszPath = NULL;
  5505. DWORD dwMode = 0;
  5506. dwErr = CalculatePhonebookPath(
  5507. pszPhonebook,
  5508. NULL,
  5509. dwFlags,
  5510. &dwMode,
  5511. &pszPath);
  5512. if (dwErr != NO_ERROR)
  5513. {
  5514. return dwErr;
  5515. }
  5516. if ((dwErr == NO_ERROR) && (ppszFullPath))
  5517. {
  5518. *ppszFullPath = pszPath;
  5519. }
  5520. else
  5521. {
  5522. Free(pszPath);
  5523. }
  5524. }
  5525. // For bug 559381
  5526. // Only output ppdtlnode
  5527. if ( NULL == pFile )
  5528. {
  5529. fFileOpened = FALSE;
  5530. do
  5531. {
  5532. ZeroMemory( &tmpFile, sizeof(tmpFile));
  5533. pTmpFile = &tmpFile;
  5534. pTmpFile->hrasfile = -1;
  5535. dwErr = ReadPhonebookFile(
  5536. pszPhonebook,
  5537. NULL,
  5538. NULL,
  5539. dwFlags,
  5540. pTmpFile);
  5541. if (SUCCESS != dwErr)
  5542. {
  5543. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5544. break;
  5545. }
  5546. fFileOpened = TRUE;
  5547. //
  5548. // Find the specified phonebook entry.
  5549. //
  5550. pdtlnode = EntryNodeFromName(
  5551. pTmpFile->pdtllistEntries,
  5552. pszEntry);
  5553. if( NULL == pdtlnode )
  5554. {
  5555. dwErr = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  5556. break;
  5557. }
  5558. //
  5559. // Copy this entry to output parameter ppdtlnode
  5560. //
  5561. pCopyNode = DuplicateEntryNode( pdtlnode );
  5562. if( NULL == pCopyNode )
  5563. {
  5564. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  5565. break;
  5566. }
  5567. *ppdtlnode = pCopyNode;
  5568. }
  5569. while(FALSE);
  5570. // Free the memory
  5571. if( fFileOpened )
  5572. {
  5573. ClosePhonebookFile(pTmpFile);
  5574. }
  5575. }
  5576. else
  5577. {
  5578. // then pFile is not NULL
  5579. // if ppdtlnode is not NULL either, return the correct node
  5580. // in pFile->pdtllistEntries to ppdtlnode
  5581. //
  5582. fFileOpened = FALSE;
  5583. do
  5584. {
  5585. dwErr = ReadPhonebookFile(
  5586. pszPhonebook,
  5587. NULL,
  5588. NULL,
  5589. dwFlags,
  5590. pFile);
  5591. if ( NO_ERROR != dwErr)
  5592. {
  5593. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5594. break;
  5595. }
  5596. fFileOpened = TRUE;
  5597. //
  5598. // Find the specified phonebook entry.
  5599. //
  5600. pdtlnode = EntryNodeFromName(
  5601. pFile->pdtllistEntries,
  5602. pszEntry);
  5603. if( NULL == pdtlnode )
  5604. {
  5605. dwErr = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  5606. break;
  5607. }
  5608. if( ppdtlnode )
  5609. {
  5610. *ppdtlnode = pdtlnode;
  5611. }
  5612. }
  5613. while(FALSE);
  5614. if( NO_ERROR != dwErr && fFileOpened )
  5615. {
  5616. ClosePhonebookFile( pFile );
  5617. }
  5618. } //end of if..else
  5619. return dwErr;
  5620. }
  5621. DWORD
  5622. DwFindEntryInPersonalPhonebooks(
  5623. IN LPCTSTR pszEntry,
  5624. IN DWORD dwFlags,
  5625. IN BOOL fLegacy,
  5626. OUT OPTIONAL PBFILE *pFile,
  5627. OUT OPTIONAL DTLNODE **ppdtlnode,
  5628. OUT OPTIONAL WCHAR** ppszPbkPath)
  5629. // Tries to find the entry specified by pszEntry in the
  5630. // pbk files located in the users profile if fLegacy is
  5631. // false. Otherwise it looks in pbks in System32\Ras for
  5632. // the entry.
  5633. //
  5634. {
  5635. DWORD dwErr = SUCCESS;
  5636. //
  5637. // consider allocing the paths below.
  5638. // Too much on the stack otherwise.
  5639. //
  5640. TCHAR szFilePath[MAX_PATH + 1];
  5641. TCHAR szFileName[MAX_PATH + 1];
  5642. BOOL fFirstTime = TRUE;
  5643. WIN32_FIND_DATA wfdData;
  5644. HANDLE hFindFile = INVALID_HANDLE_VALUE;
  5645. ZeroMemory((PBYTE) szFilePath, sizeof(szFilePath));
  5646. ZeroMemory((PBYTE) szFileName, sizeof(szFileName));
  5647. #if DBG
  5648. ASSERT(NULL != ppdtlnode);
  5649. #endif
  5650. *ppdtlnode = NULL;
  5651. //
  5652. // Get the personal phonebook directory if its not
  5653. // legacy
  5654. //
  5655. if(fLegacy)
  5656. {
  5657. UINT cch = GetSystemDirectory(szFileName, MAX_PATH + 1);
  5658. if ( (cch == 0)
  5659. || (cch > (MAX_PATH - (5 + 8 + 1 + 3))))
  5660. {
  5661. goto done;
  5662. }
  5663. lstrcat(szFileName, TEXT("\\Ras\\"));
  5664. }
  5665. else if(!GetPhonebookDirectory(PBM_Personal,
  5666. szFileName))
  5667. {
  5668. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5669. goto done;
  5670. }
  5671. if(lstrlen(szFilePath) > (MAX_PATH - lstrlen(TEXT("*.pbk"))))
  5672. {
  5673. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5674. goto done;
  5675. }
  5676. wsprintf(szFilePath,
  5677. TEXT("%s%s"),
  5678. szFileName,
  5679. TEXT("*.pbk"));
  5680. //
  5681. // Look for files with .pbk extension in this
  5682. // directory.
  5683. //
  5684. while(SUCCESS == dwErr)
  5685. {
  5686. if(INVALID_HANDLE_VALUE == hFindFile)
  5687. {
  5688. hFindFile = FindFirstFile(szFilePath,
  5689. &wfdData);
  5690. if(INVALID_HANDLE_VALUE == hFindFile)
  5691. {
  5692. dwErr = GetLastError();
  5693. break;
  5694. }
  5695. }
  5696. else
  5697. {
  5698. if(!FindNextFile(hFindFile,
  5699. &wfdData))
  5700. {
  5701. dwErr = GetLastError();
  5702. break;
  5703. }
  5704. }
  5705. if(FILE_ATTRIBUTE_DIRECTORY & wfdData.dwFileAttributes)
  5706. {
  5707. continue;
  5708. }
  5709. if(lstrlen(wfdData.cFileName) > (MAX_PATH - lstrlen(szFileName)))
  5710. {
  5711. //
  5712. // Modify RAS code to take into account file names
  5713. // larger than MAX_PATH.
  5714. //
  5715. dwErr = ERROR_CANNOT_OPEN_PHONEBOOK;
  5716. goto done;
  5717. }
  5718. //
  5719. // Construct full path name to the pbk file
  5720. //
  5721. wsprintf(szFilePath,
  5722. TEXT("%s\\%s"),
  5723. szFileName,
  5724. wfdData.cFileName);
  5725. //
  5726. // Ignore the phonebook if its router.pbk
  5727. //
  5728. if( (fLegacy)
  5729. && (IsRouterPhonebook(szFilePath)))
  5730. {
  5731. continue;
  5732. }
  5733. dwErr = DwReadEntryFromSystem(
  5734. szFilePath,
  5735. pszEntry,
  5736. dwFlags,
  5737. pFile,
  5738. ppdtlnode,
  5739. ppszPbkPath);
  5740. if( (SUCCESS == dwErr)
  5741. && (NULL != *ppdtlnode))
  5742. {
  5743. break;
  5744. }
  5745. else
  5746. {
  5747. //
  5748. // For some reason we were not able to
  5749. // read the entry - entry not there,
  5750. // failed to open the phonebook. In all
  5751. // error cases try to open the next pbk
  5752. // file.
  5753. //
  5754. dwErr = SUCCESS;
  5755. }
  5756. }
  5757. done:
  5758. if(NULL == *ppdtlnode)
  5759. {
  5760. dwErr = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  5761. }
  5762. if(INVALID_HANDLE_VALUE != hFindFile)
  5763. {
  5764. FindClose(hFindFile);
  5765. }
  5766. return dwErr;
  5767. }
  5768. DWORD
  5769. DwEnumeratePhonebooksFromDirectory(
  5770. TCHAR *pszDir,
  5771. DWORD dwFlags,
  5772. PBKENUMCALLBACK pfnCallback,
  5773. VOID *pvContext
  5774. )
  5775. {
  5776. DWORD dwErr = SUCCESS;
  5777. //
  5778. // consider allocing the paths below.
  5779. // Too much on the stack otherwise.
  5780. //
  5781. TCHAR szFilePath[MAX_PATH + 1];
  5782. BOOL fFirstTime = TRUE;
  5783. PBFILE file;
  5784. WIN32_FIND_DATA wfdData;
  5785. HANDLE hFindFile = INVALID_HANDLE_VALUE;
  5786. if(NULL == pszDir)
  5787. {
  5788. dwErr = E_INVALIDARG;
  5789. goto done;
  5790. }
  5791. ZeroMemory((PBYTE) szFilePath, sizeof(szFilePath));
  5792. wsprintf(szFilePath,
  5793. TEXT("%s%s"),
  5794. pszDir,
  5795. TEXT("*.pbk"));
  5796. //
  5797. // Look for files with .pbk extension in this
  5798. // directory.
  5799. //
  5800. while(SUCCESS == dwErr)
  5801. {
  5802. if(INVALID_HANDLE_VALUE == hFindFile)
  5803. {
  5804. hFindFile = FindFirstFile(szFilePath,
  5805. &wfdData);
  5806. if(INVALID_HANDLE_VALUE == hFindFile)
  5807. {
  5808. dwErr = GetLastError();
  5809. break;
  5810. }
  5811. }
  5812. else
  5813. {
  5814. if(!FindNextFile(hFindFile,
  5815. &wfdData))
  5816. {
  5817. dwErr = GetLastError();
  5818. break;
  5819. }
  5820. }
  5821. if(FILE_ATTRIBUTE_DIRECTORY & wfdData.dwFileAttributes)
  5822. {
  5823. continue;
  5824. }
  5825. wsprintf(szFilePath,
  5826. TEXT("%s%s"),
  5827. pszDir,
  5828. wfdData.cFileName);
  5829. //
  5830. // Ignore the phonebook if its router.pbk
  5831. //
  5832. if(IsRouterPhonebook(szFilePath))
  5833. {
  5834. continue;
  5835. }
  5836. dwErr = ReadPhonebookFile(
  5837. szFilePath,
  5838. NULL,
  5839. NULL,
  5840. dwFlags,
  5841. &file);
  5842. if(SUCCESS == dwErr)
  5843. {
  5844. //
  5845. // Call back
  5846. //
  5847. pfnCallback(&file, pvContext);
  5848. ClosePhonebookFile(&file);
  5849. }
  5850. else
  5851. {
  5852. dwErr = SUCCESS;
  5853. }
  5854. }
  5855. done:
  5856. if( (ERROR_NO_MORE_FILES == dwErr)
  5857. || (ERROR_FILE_NOT_FOUND == dwErr))
  5858. {
  5859. dwErr = ERROR_SUCCESS;
  5860. }
  5861. if(INVALID_HANDLE_VALUE != hFindFile)
  5862. {
  5863. FindClose(hFindFile);
  5864. }
  5865. return dwErr;
  5866. }
  5867. DWORD
  5868. ReadEntryFromSystem(
  5869. IN LPCTSTR pszPhonebook,
  5870. IN LPCTSTR pszEntry,
  5871. IN DWORD dwFlags,
  5872. IN OUT PBFILE *pFile,
  5873. OUT DTLNODE **ppdtlnode,
  5874. OUT WCHAR **ppszPbkPath)
  5875. // Finds the phonebook entrynode given the entryname.
  5876. // The node is returned in 'ppdtlnode'. If 'pszPhonebook'
  5877. // is NULL, All Users phonebook is searched first for the
  5878. // entry and if its not found there, Phonebooks in the per
  5879. // user profile are searched for the entry. 'pFile' on return
  5880. // from this function contains the open phonebook containing
  5881. // the entry specified by pszEntry. Note: if there are
  5882. // mutiple entries with the same name across phonebooks, the
  5883. // entry correspoding the first phonebook enumerated is returned.
  5884. //
  5885. {
  5886. DWORD dwErr = SUCCESS;
  5887. DTLNODE *pdtlnode = NULL;
  5888. TCHAR* szPathBuf = NULL;
  5889. TRACE("GetPbkAndEntryName");
  5890. //
  5891. // Do some parameter validation
  5892. //
  5893. if( (NULL == pszEntry)
  5894. || (NULL == ppdtlnode))
  5895. {
  5896. dwErr = E_INVALIDARG;
  5897. goto done;
  5898. }
  5899. // Phonebook file must be provided if we are not reading from the cache.
  5900. //
  5901. /* //comment it out for .Net 61226, can delete it some time later
  5902. if ( (!fReadFromCache) &&
  5903. (NULL == pFile))
  5904. {
  5905. dwErr = E_INVALIDARG;
  5906. goto done;
  5907. }
  5908. */
  5909. if (! (szPathBuf = (TCHAR*) Malloc((MAX_PATH + 1) * sizeof(TCHAR))))
  5910. {
  5911. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  5912. goto done;
  5913. }
  5914. // XP 426903
  5915. //
  5916. // On consumer platforms, we default to looking at all-user connections
  5917. // even if the current user is not an admin.
  5918. //
  5919. if ((NULL == pszPhonebook) && (IsConsumerPlatform()))
  5920. {
  5921. dwFlags |= RPBF_AllUserPbk;
  5922. }
  5923. //
  5924. // Load the phonebook file.
  5925. //
  5926. dwErr = DwReadEntryFromSystem(
  5927. pszPhonebook,
  5928. pszEntry,
  5929. dwFlags,
  5930. pFile,
  5931. &pdtlnode,
  5932. ppszPbkPath);
  5933. if( (ERROR_SUCCESS == dwErr)
  5934. || (NULL != pszPhonebook))
  5935. {
  5936. if( (ERROR_SUCCESS != dwErr)
  5937. && (NULL != pszPhonebook))
  5938. {
  5939. if(GetPhonebookDirectory(
  5940. PBM_Alternate,
  5941. szPathBuf))
  5942. {
  5943. lstrcat(szPathBuf, TEXT("rasphone.pbk"));
  5944. if(0 == lstrcmpi(szPathBuf, pszPhonebook))
  5945. {
  5946. //
  5947. // some one is passing the legacy
  5948. // phonebook path exclusively, check
  5949. // to see if the entry is in the
  5950. // all-users phonebook. NetScape does
  5951. // the following which requires this
  5952. // workaround: Creates an entry with
  5953. // NULL pbk path so the entry gets
  5954. // created in all-users. Then passes
  5955. // %windir%\system32\ras\rasphone.pbk
  5956. // explicitly to find the entry - and
  5957. // because of the system pbk change in
  5958. // nt5 this doesn't work unless we do
  5959. // the hack below.
  5960. //
  5961. dwErr = DwReadEntryFromSystem(
  5962. NULL,
  5963. pszEntry,
  5964. dwFlags,
  5965. pFile,
  5966. &pdtlnode,
  5967. ppszPbkPath);
  5968. if(ERROR_SUCCESS != dwErr)
  5969. {
  5970. dwErr = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  5971. }
  5972. }
  5973. }
  5974. }
  5975. goto done;
  5976. }
  5977. //
  5978. // Try to find the entry in personal phonebooks.
  5979. //
  5980. dwErr = DwFindEntryInPersonalPhonebooks(
  5981. pszEntry,
  5982. dwFlags,
  5983. FALSE,
  5984. pFile,
  5985. &pdtlnode,
  5986. ppszPbkPath);
  5987. if(ERROR_SUCCESS == dwErr)
  5988. {
  5989. goto done;
  5990. }
  5991. //
  5992. // Try to find the entry in the system32\ras phonebooks.
  5993. //
  5994. dwErr = DwFindEntryInPersonalPhonebooks(
  5995. pszEntry,
  5996. dwFlags,
  5997. TRUE,
  5998. pFile,
  5999. &pdtlnode,
  6000. ppszPbkPath);
  6001. if(ERROR_SUCCESS == dwErr)
  6002. {
  6003. goto done;
  6004. }
  6005. //
  6006. // If the phonebookpath is NULL explicitly try out
  6007. // the public phonebook.
  6008. //
  6009. if(GetPublicPhonebookPath(szPathBuf))
  6010. {
  6011. dwErr = DwReadEntryFromSystem(
  6012. szPathBuf,
  6013. pszEntry,
  6014. dwFlags,
  6015. pFile,
  6016. &pdtlnode,
  6017. ppszPbkPath);
  6018. }
  6019. if(ERROR_SUCCESS != dwErr)
  6020. {
  6021. dwErr = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
  6022. }
  6023. done:
  6024. *ppdtlnode = pdtlnode;
  6025. Free0(szPathBuf);
  6026. TRACE1("GetPbkAndEntryName. rc=0x%x",
  6027. dwErr);
  6028. return dwErr;
  6029. }
  6030. DWORD
  6031. GetPbkAndEntryName(
  6032. IN LPCTSTR pszPhonebook,
  6033. IN LPCTSTR pszEntry,
  6034. IN DWORD dwFlags,
  6035. OUT PBFILE *pFile,
  6036. OUT DTLNODE **ppdtlnode)
  6037. {
  6038. return ReadEntryFromSystem(
  6039. pszPhonebook,
  6040. pszEntry,
  6041. dwFlags,
  6042. pFile,
  6043. ppdtlnode,
  6044. NULL);
  6045. }
  6046. DWORD
  6047. GetFmtServerFromConnection(
  6048. IN HANDLE hConnection,
  6049. IN PWCHAR pszServerFmt)
  6050. {
  6051. PWCHAR pszServer = (PWCHAR) RemoteGetServerName( hConnection );
  6052. if ( pszServer && *pszServer )
  6053. {
  6054. if ( *pszServer == L'\0' )
  6055. {
  6056. wcscpy( pszServerFmt, pszServer );
  6057. }
  6058. else
  6059. {
  6060. pszServerFmt[0] = pszServerFmt[1] = L'\\';
  6061. wcscpy( pszServerFmt + 2, pszServer );
  6062. }
  6063. }
  6064. else
  6065. {
  6066. *pszServerFmt = L'\0';
  6067. }
  6068. return NO_ERROR;
  6069. }
  6070. DWORD
  6071. UpgradeSecureVpnOption(
  6072. IN HKEY hkMachine,
  6073. IN PBENTRY* pEntry )
  6074. // Called to upgrade the "secure vpn" option. If this was set in
  6075. // nt4, it meant that all vpn entries should use strong encryption.
  6076. // If we see this on nt5, then we should for this entry to use
  6077. // mschapv2.
  6078. //
  6079. {
  6080. DWORD dwErr = NO_ERROR;
  6081. HKEY hkValue = NULL;
  6082. DWORD dwType = REG_DWORD, dwSize = sizeof(DWORD), dwValue = 0;
  6083. do
  6084. {
  6085. // Open the registry key that we're looking at
  6086. //
  6087. dwErr = RegOpenKeyEx(
  6088. hkMachine,
  6089. c_pszRegKeySecureVpn,
  6090. 0,
  6091. KEY_READ,
  6092. &hkValue);
  6093. if (dwErr != NO_ERROR)
  6094. {
  6095. break;
  6096. }
  6097. // Read in the value
  6098. //
  6099. dwErr = RegQueryValueEx(
  6100. hkValue,
  6101. c_pszRegValSecureVpn,
  6102. NULL,
  6103. &dwType,
  6104. (LPBYTE)&dwValue,
  6105. &dwSize);
  6106. if (dwErr != NO_ERROR)
  6107. {
  6108. break;
  6109. }
  6110. // Set the entry accordingly
  6111. //
  6112. if (dwValue)
  6113. {
  6114. pEntry->dwAuthRestrictions = AR_F_AuthCustom | AR_F_AuthMSCHAP2;
  6115. }
  6116. // Delete the registry value
  6117. //
  6118. RegDeleteValue( hkValue, c_pszRegValSecureVpn );
  6119. } while (FALSE);
  6120. // Cleanup
  6121. {
  6122. if (hkValue)
  6123. {
  6124. RegCloseKey (hkValue);
  6125. }
  6126. }
  6127. return dwErr;
  6128. }
  6129. DWORD
  6130. UpgradeForceStrongEncrptionOption(
  6131. IN HKEY hkMachine,
  6132. IN PBENTRY* pEntry )
  6133. // Called to upgrade the "force strong encryption" option. If this was
  6134. // set in nt4, it meant that all entries that force strong encryption
  6135. // should now force strong encryption.
  6136. //
  6137. {
  6138. DWORD dwErr = NO_ERROR;
  6139. HKEY hkValue = NULL;
  6140. DWORD dwType = REG_DWORD, dwSize = sizeof(DWORD), dwValue = 0;
  6141. do
  6142. {
  6143. // Open the registry key that we're looking at
  6144. //
  6145. dwErr = RegOpenKeyEx(
  6146. hkMachine,
  6147. c_pszRegKeyForceStrongEncryption,
  6148. 0,
  6149. KEY_READ,
  6150. &hkValue);
  6151. if (dwErr != NO_ERROR)
  6152. {
  6153. break;
  6154. }
  6155. // Read in the value
  6156. //
  6157. dwErr = RegQueryValueEx(
  6158. hkValue,
  6159. c_pszRegValForceStrongEncryption,
  6160. NULL,
  6161. &dwType,
  6162. (LPBYTE)&dwValue,
  6163. &dwSize);
  6164. if (dwErr != NO_ERROR)
  6165. {
  6166. break;
  6167. }
  6168. // Set the entry accordingly
  6169. //
  6170. if (dwValue)
  6171. {
  6172. if ( pEntry->dwDataEncryption == DE_Require )
  6173. {
  6174. pEntry->dwDataEncryption = DE_RequireMax;
  6175. }
  6176. }
  6177. // Delete the registry value
  6178. //
  6179. RegDeleteValue( hkValue, c_pszRegValForceStrongEncryption );
  6180. } while (FALSE);
  6181. // Cleanup
  6182. {
  6183. if (hkValue)
  6184. {
  6185. RegCloseKey (hkValue);
  6186. }
  6187. }
  6188. return dwErr;
  6189. }
  6190. DWORD
  6191. UpgradeRegistryOptions(
  6192. IN HANDLE hConnection,
  6193. IN PBENTRY* pEntry )
  6194. // Called to upgrade any options in this phonebook entry
  6195. // based on registry settings.
  6196. //
  6197. {
  6198. WCHAR pszServer[MAX_COMPUTERNAME_LENGTH + 3];
  6199. HKEY hkMachine = NULL;
  6200. DWORD dwErr = NO_ERROR;
  6201. do
  6202. {
  6203. // Get the formatted server name
  6204. //
  6205. dwErr = GetFmtServerFromConnection(hConnection, pszServer);
  6206. if (dwErr != NO_ERROR)
  6207. {
  6208. break;
  6209. }
  6210. // Connect to the appropriate registry
  6211. //
  6212. dwErr = RegConnectRegistry(
  6213. (*pszServer) ? pszServer : NULL,
  6214. HKEY_LOCAL_MACHINE,
  6215. &hkMachine);
  6216. if (dwErr != NO_ERROR)
  6217. {
  6218. break;
  6219. }
  6220. if (hkMachine == NULL)
  6221. {
  6222. dwErr = ERROR_CAN_NOT_COMPLETE;
  6223. break;
  6224. }
  6225. // Upgrade the various options
  6226. if ( pEntry->dwType == RASET_Vpn )
  6227. {
  6228. UpgradeSecureVpnOption( hkMachine, pEntry );
  6229. }
  6230. UpgradeForceStrongEncrptionOption( hkMachine, pEntry );
  6231. } while (FALSE);
  6232. // Cleanup
  6233. {
  6234. if (hkMachine)
  6235. {
  6236. RegCloseKey (hkMachine);
  6237. }
  6238. }
  6239. return dwErr;
  6240. }