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.

3334 lines
81 KiB

  1. // Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. //
  3. // pbk.c
  4. // Remote Access phonebook library
  5. // General routines
  6. // Listed alphabetically
  7. //
  8. // 06/20/95 Steve Cobb
  9. #include "pbkp.h"
  10. #include <search.h> // Qsort
  11. #include <tapi.h>
  12. #ifdef UNICODE
  13. #define SZ_PathCanonicalize "PathCanonicalizeW"
  14. #define SZ_PathRemoveFileSpec "PathRemoveFileSpecW"
  15. #else
  16. #define SZ_PathCanonicalize "PathCanonicalizeA"
  17. #define SZ_PathRemoveFileSpec "PathRemoveFileSpecA"
  18. #endif
  19. PbkPathInfo g_PbkPathInfo;
  20. //----------------------------------------------------------------------------
  21. // Local prototypes
  22. //----------------------------------------------------------------------------
  23. DWORD
  24. AppendPbportToList(
  25. IN HANDLE hConnection,
  26. IN DTLLIST* pdtllist,
  27. IN RASMAN_PORT* pPort );
  28. DWORD
  29. AppendStringToList(
  30. IN DTLLIST* pdtllist,
  31. IN TCHAR* psz );
  32. int __cdecl
  33. CompareDevices(
  34. const void* pDevice1,
  35. const void* pDevice2 );
  36. int __cdecl
  37. ComparePorts(
  38. const void* pPort1,
  39. const void* pPort2 );
  40. CHAR*
  41. PbMedia(
  42. IN PBDEVICETYPE pbdt,
  43. IN CHAR* pszMedia );
  44. WCHAR *
  45. GetUnicodeName(HANDLE hPort);
  46. //----------------------------------------------------------------------------
  47. // Routines
  48. //----------------------------------------------------------------------------
  49. DWORD
  50. RdtFromPbdt(PBDEVICETYPE pbdt, DWORD dwFlags)
  51. {
  52. DWORD rdt;
  53. switch(pbdt)
  54. {
  55. case PBDT_Modem:
  56. {
  57. rdt = RDT_Modem;
  58. if(PBP_F_NullModem & dwFlags)
  59. {
  60. rdt |= (RDT_Direct | RDT_Null_Modem);
  61. }
  62. break;
  63. }
  64. case PBDT_X25:
  65. {
  66. rdt = RDT_X25;
  67. break;
  68. }
  69. case PBDT_Isdn:
  70. {
  71. rdt = RDT_Isdn;
  72. break;
  73. }
  74. case PBDT_Serial:
  75. {
  76. rdt = RDT_Serial;
  77. break;
  78. }
  79. case PBDT_FrameRelay:
  80. {
  81. rdt = RDT_FrameRelay;
  82. break;
  83. }
  84. case PBDT_Atm:
  85. {
  86. rdt = RDT_Atm;
  87. break;
  88. }
  89. case PBDT_Vpn:
  90. {
  91. rdt = RDT_Tunnel;
  92. if(PBP_F_L2tpDevice & dwFlags)
  93. {
  94. rdt |= RDT_Tunnel_L2tp;
  95. }
  96. else if(PBP_F_PptpDevice & dwFlags)
  97. {
  98. rdt |= RDT_Tunnel_Pptp;
  99. }
  100. break;
  101. }
  102. case PBDT_Sonet:
  103. {
  104. rdt = RDT_Sonet;
  105. break;
  106. }
  107. case PBDT_Sw56:
  108. {
  109. rdt = RDT_Sw56;
  110. break;
  111. }
  112. case PBDT_Irda:
  113. {
  114. rdt = (RDT_Irda | RDT_Direct);
  115. break;
  116. }
  117. case PBDT_Parallel:
  118. {
  119. rdt = (RDT_Parallel | RDT_Direct);
  120. break;
  121. }
  122. case PBDT_Null:
  123. {
  124. rdt = (RDT_Direct | RDT_Null_Modem);
  125. break;
  126. }
  127. case PBDT_PPPoE:
  128. {
  129. rdt = (RDT_PPPoE | RDT_Broadband);
  130. break;
  131. }
  132. default:
  133. {
  134. rdt = RDT_Other;
  135. break;
  136. }
  137. }
  138. return rdt;
  139. }
  140. PBDEVICETYPE
  141. PbdtFromRdt(
  142. IN DWORD rdt
  143. )
  144. {
  145. PBDEVICETYPE pbdt;
  146. switch(rdt)
  147. {
  148. case RDT_Modem:
  149. {
  150. pbdt = PBDT_Modem;
  151. break;
  152. }
  153. case RDT_X25:
  154. {
  155. pbdt = PBDT_X25;
  156. break;
  157. }
  158. case RDT_Isdn:
  159. {
  160. pbdt = PBDT_Isdn;
  161. break;
  162. }
  163. case RDT_Serial:
  164. {
  165. pbdt = PBDT_Serial;
  166. break;
  167. }
  168. case RDT_FrameRelay:
  169. {
  170. pbdt = PBDT_FrameRelay;
  171. break;
  172. }
  173. case RDT_Atm:
  174. {
  175. pbdt = PBDT_Atm;
  176. break;
  177. }
  178. case RDT_Tunnel_Pptp:
  179. case RDT_Tunnel_L2tp:
  180. {
  181. pbdt = PBDT_Vpn;
  182. break;
  183. }
  184. case RDT_Sonet:
  185. {
  186. pbdt = PBDT_Sonet;
  187. break;
  188. }
  189. case RDT_Sw56:
  190. {
  191. pbdt = PBDT_Sw56;
  192. break;
  193. }
  194. case RDT_Irda:
  195. {
  196. pbdt = PBDT_Irda;
  197. break;
  198. }
  199. case RDT_Parallel:
  200. {
  201. pbdt = PBDT_Parallel;
  202. break;
  203. }
  204. case RDT_PPPoE:
  205. {
  206. pbdt = PBDT_PPPoE;
  207. break;
  208. }
  209. default:
  210. {
  211. pbdt = PBDT_Other;
  212. break;
  213. }
  214. }
  215. return pbdt;
  216. }
  217. TCHAR *
  218. pszDeviceTypeFromRdt(RASDEVICETYPE rdt)
  219. {
  220. TCHAR *pszDeviceType = NULL;
  221. switch(RAS_DEVICE_TYPE(rdt))
  222. {
  223. case RDT_Modem:
  224. {
  225. pszDeviceType = RASDT_Modem;
  226. break;
  227. }
  228. case RDT_X25:
  229. {
  230. pszDeviceType = RASDT_X25;
  231. break;
  232. }
  233. case RDT_Isdn:
  234. {
  235. pszDeviceType = RASDT_Isdn;
  236. break;
  237. }
  238. case RDT_Serial:
  239. {
  240. pszDeviceType = RASDT_Serial;
  241. break;
  242. }
  243. case RDT_FrameRelay:
  244. {
  245. pszDeviceType = RASDT_FrameRelay;
  246. break;
  247. }
  248. case RDT_Atm:
  249. {
  250. pszDeviceType = RASDT_Atm;
  251. break;
  252. }
  253. case RDT_Sonet:
  254. {
  255. pszDeviceType = RASDT_Sonet;
  256. break;
  257. }
  258. case RDT_Sw56:
  259. {
  260. pszDeviceType = RASDT_SW56;
  261. break;
  262. }
  263. case RDT_Tunnel_Pptp:
  264. case RDT_Tunnel_L2tp:
  265. {
  266. pszDeviceType = RASDT_Vpn;
  267. break;
  268. }
  269. case RDT_Irda:
  270. {
  271. pszDeviceType = RASDT_Irda;
  272. break;
  273. }
  274. case RDT_Parallel:
  275. {
  276. pszDeviceType = RASDT_Parallel;
  277. break;
  278. }
  279. case RDT_PPPoE:
  280. {
  281. pszDeviceType = RASDT_PPPoE;
  282. break;
  283. }
  284. default:
  285. {
  286. pszDeviceType = NULL;
  287. break;
  288. }
  289. }
  290. return StrDup(pszDeviceType);
  291. }
  292. DWORD
  293. AppendPbportToList(
  294. IN HANDLE hConnection,
  295. IN DTLLIST* pdtllist,
  296. IN RASMAN_PORT* pPort )
  297. // Append a PBPORT onto the list 'pdtllist' which has the characteristics
  298. // of RAS Manager port 'pPort'.
  299. //
  300. // Returns 0 if successful, otherwise a non-zero error code.
  301. //
  302. {
  303. DWORD dwErr;
  304. DTLNODE* pdtlnode;
  305. PBPORT* ppbport;
  306. DWORD dwType, dwClass;
  307. dwErr = 0;
  308. pdtlnode = CreatePortNode();
  309. if ( !pdtlnode)
  310. {
  311. return ERROR_NOT_ENOUGH_MEMORY;
  312. }
  313. // Get detailed information about the device from
  314. // rasman
  315. dwClass = RAS_DEVICE_CLASS(pPort->P_rdtDeviceType);
  316. dwType = RAS_DEVICE_TYPE(pPort->P_rdtDeviceType);
  317. // Now set the device info
  318. ppbport = (PBPORT* )DtlGetData( pdtlnode );
  319. // ppbport->pszDevice = StrDupTFromAUsingAnsiEncoding( pPort->P_DeviceName );
  320. ppbport->pszDevice = GetUnicodeName(pPort->P_Handle);
  321. if(ppbport->pszDevice == NULL)
  322. {
  323. ppbport->pszDevice = StrDupTFromAUsingAnsiEncoding( pPort->P_DeviceName );
  324. }
  325. ppbport->pszPort = StrDupTFromAUsingAnsiEncoding( pPort->P_PortName );
  326. // Record the flags appropriate to this device
  327. if ( dwType == RDT_Tunnel_Pptp )
  328. {
  329. ppbport->dwFlags |= PBP_F_PptpDevice;
  330. }
  331. else if ( dwType == RDT_Tunnel_L2tp )
  332. {
  333. ppbport->dwFlags |= PBP_F_L2tpDevice;
  334. }
  335. //For whistler 349087 345068 gangz
  336. //
  337. else if ( dwType == RDT_PPPoE )
  338. {
  339. ppbport->dwFlags |= PBP_F_PPPoEDevice;
  340. }
  341. if ( dwClass & RDT_Null_Modem )
  342. {
  343. ppbport->dwFlags |= PBP_F_NullModem;
  344. }
  345. //For whistler 349087 345068 gangz
  346. //
  347. else if ( dwClass & RDT_Broadband )
  348. {
  349. ppbport->dwFlags |= PBP_F_PPPoEDevice;
  350. }
  351. // Compute the phonebook device type
  352. //
  353. ppbport->pbdevicetype = PbdtFromRdt(dwType);
  354. if ( PBDT_Other == ppbport->pbdevicetype )
  355. {
  356. ppbport->pbdevicetype = PbdevicetypeFromPszTypeA( pPort->P_DeviceType);
  357. }
  358. ppbport->pszMedia = StrDupTFromAUsingAnsiEncoding(
  359. PbMedia( ppbport->pbdevicetype, pPort->P_MediaName ) );
  360. if (!ppbport->pszPort || !ppbport->pszDevice || !ppbport->pszMedia)
  361. {
  362. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  363. }
  364. else if ((ppbport->pbdevicetype == PBDT_Modem) ||
  365. (ppbport->dwFlags & PBP_F_NullModem))
  366. {
  367. #ifdef MXSMODEMS
  368. if (pPort->P_LineDeviceId == 0xFFFFFFFF)
  369. {
  370. // MXS modem port.
  371. //
  372. ppbport->fMxsModemPort = TRUE;
  373. GetRasPortMaxBps( pPort->P_Handle,
  374. &ppbport->dwMaxConnectBps, &ppbport->dwMaxCarrierBps );
  375. GetRasPortModemSettings( pPort->P_Handle, &ppbport->fHwFlowDefault,
  376. &ppbport->fEcDefault, &ppbport->fEccDefault );
  377. }
  378. else
  379. #else
  380. ASSERT( pPort->P_LineDeviceId != 0xFFFFFFFF );
  381. #endif
  382. {
  383. // Unimodem port.
  384. //
  385. UNIMODEMINFO info;
  386. ZeroMemory((PBYTE) &info, sizeof(info));
  387. GetRasUnimodemInfo(
  388. hConnection,
  389. pPort->P_Handle,
  390. pPort->P_DeviceType,
  391. &info );
  392. TRACE6( "Port=%s,fHw=%d,fEc=%d,bps=%d,fSp=%d,prot=%x",
  393. pPort->P_PortName, info.fHwFlow, info.fEc,
  394. info.dwBps, info.fSpeaker, info.dwModemProtocol );
  395. ppbport->fHwFlowDefault = info.fHwFlow;
  396. ppbport->fEcDefault = info.fEc;
  397. ppbport->fEccDefault = info.fEcc;
  398. ppbport->dwBpsDefault = info.dwBps;
  399. ppbport->fSpeakerDefault = info.fSpeaker;
  400. // pmay: 228565
  401. // Add the modem protocol information
  402. //
  403. ppbport->dwModemProtDefault = info.dwModemProtocol;
  404. ppbport->pListProtocols = info.pListProtocols;
  405. }
  406. }
  407. if (dwErr == 0)
  408. {
  409. ppbport->dwType = EntryTypeFromPbport( ppbport );
  410. DtlAddNodeLast( pdtllist, pdtlnode );
  411. }
  412. else
  413. {
  414. Free0( ppbport->pszDevice );
  415. Free0( ppbport->pszMedia );
  416. Free0( ppbport->pszPort );
  417. DtlDestroyNode( pdtlnode );
  418. }
  419. return dwErr;
  420. }
  421. DWORD
  422. AppendStringToList(
  423. IN DTLLIST* pdtllist,
  424. IN TCHAR* psz )
  425. // Appends a copy of 'psz' to the end of list 'pdtllist'.
  426. //
  427. // Returns 0 if successful, otherwise a non-zero error code.
  428. // ERROR_NOT_ENOUGH_MEMORY is returned if 'psz' is NULL.
  429. //
  430. {
  431. DTLNODE* pdtlnode;
  432. TCHAR* pszDup;
  433. if (!psz)
  434. {
  435. return ERROR_NOT_ENOUGH_MEMORY;
  436. }
  437. pszDup = StrDup( psz );
  438. if (!pszDup)
  439. {
  440. return ERROR_NOT_ENOUGH_MEMORY;
  441. }
  442. pdtlnode = DtlCreateNode( pszDup, 0L );
  443. if (!pdtlnode )
  444. {
  445. Free( pszDup );
  446. return ERROR_NOT_ENOUGH_MEMORY;
  447. }
  448. DtlAddNodeLast( pdtllist, pdtlnode );
  449. return 0;
  450. }
  451. DTLNODE*
  452. CloneEntryNode(
  453. DTLNODE* pdtlnodeSrc )
  454. // Duplicates entry node 'pdtlnodeSrc' with fields that cannot be cloned
  455. // set to "like new" settings.
  456. //
  457. {
  458. DTLNODE* pdtlnode = NULL;
  459. RPC_STATUS rpcStatus = RPC_S_OK;
  460. PBENTRY* ppbentry = NULL;
  461. HRESULT hr = S_OK;
  462. __try
  463. {
  464. pdtlnode = DuplicateEntryNode( pdtlnodeSrc );
  465. if ( NULL == pdtlnode )
  466. {
  467. hr = E_FAIL;
  468. __leave;
  469. }
  470. ppbentry = (PBENTRY* )DtlGetData( pdtlnode );
  471. ASSERT( ppbentry );
  472. if ( NULL == ppbentry )
  473. {
  474. hr = E_FAIL;
  475. __leave;
  476. }
  477. ppbentry->fSkipDownLevelDialog = FALSE;
  478. ppbentry->fSkipDoubleDialDialog = FALSE;
  479. ppbentry->fSkipNwcWarning = FALSE;
  480. ppbentry->dwDialParamsUID = GetTickCount();
  481. if (ppbentry->dwType != RASET_Phone)
  482. {
  483. ppbentry->fPreviewPhoneNumber = FALSE;
  484. ppbentry->fSharedPhoneNumbers = FALSE;
  485. }
  486. Free0( ppbentry->pGuid );
  487. ppbentry->pGuid = Malloc( sizeof(GUID) );
  488. if ( NULL == ppbentry->pGuid)
  489. {
  490. hr = E_OUTOFMEMORY;
  491. __leave;
  492. }
  493. // For Whistler bug 513885
  494. rpcStatus = UuidCreate( (UUID* )ppbentry->pGuid );
  495. if( !( ( RPC_S_OK == rpcStatus) ||
  496. ( RPC_S_UUID_LOCAL_ONLY == rpcStatus )
  497. )
  498. )
  499. {
  500. hr = E_FAIL;
  501. __leave;
  502. }
  503. ppbentry->fDirty = FALSE;
  504. }
  505. __finally
  506. {
  507. if ( S_OK != hr )
  508. {
  509. if ( pdtlnode )
  510. {
  511. DestroyEntryNode( pdtlnode );
  512. pdtlnode = NULL;
  513. }
  514. }
  515. }
  516. return pdtlnode;
  517. }
  518. int __cdecl
  519. CompareDevices(
  520. const void* pDevice1,
  521. const void* pDevice2 )
  522. // Qsort compare function for RASMAN_DEVICEs.
  523. //
  524. {
  525. return
  526. lstrcmpiA( ((RASMAN_DEVICE* )pDevice1)->D_Name,
  527. ((RASMAN_DEVICE* )pDevice2)->D_Name );
  528. }
  529. int __cdecl
  530. ComparePorts(
  531. const void* pPort1,
  532. const void* pPort2 )
  533. // Qsort compare function for RASMAN_PORTs.
  534. //
  535. {
  536. return
  537. lstrcmpiA( ((RASMAN_PORT* )pPort1)->P_PortName,
  538. ((RASMAN_PORT* )pPort2)->P_PortName );
  539. }
  540. DWORD
  541. CopyToPbport(
  542. IN PBPORT* ppbportDst,
  543. IN PBPORT* ppbportSrc )
  544. // Make a duplicate of 'ppbportSrc' in 'ppbportDst'. If 'ppbportSrc' is
  545. // NULL it sets 'ppbportDst' to defaults.
  546. //
  547. // Returns 0 if successful or an error code.
  548. //
  549. {
  550. DTLNODE *pdtlnode, *pNode;
  551. WCHAR *pwsz;
  552. DTLLIST *pdtllist = NULL;
  553. Free0( ppbportDst->pszDevice );
  554. Free0( ppbportDst->pszMedia );
  555. Free0( ppbportDst->pszPort );
  556. if (!ppbportSrc)
  557. {
  558. ppbportDst->pszPort = NULL;
  559. ppbportDst->fConfigured = TRUE;
  560. ppbportDst->pszDevice = NULL;
  561. ppbportDst->pszMedia = NULL;
  562. ppbportDst->pbdevicetype = PBDT_None;
  563. ppbportDst->dwType = RASET_Phone;
  564. ppbportDst->fHwFlowDefault = FALSE;
  565. ppbportDst->fEcDefault = FALSE;
  566. ppbportDst->fEccDefault = FALSE;
  567. ppbportDst->dwBpsDefault = 0;
  568. ppbportDst->fSpeakerDefault = TRUE;
  569. ppbportDst->fScriptBeforeTerminal = FALSE;
  570. ppbportDst->fScriptBefore = FALSE;
  571. ppbportDst->pszScriptBefore = NULL;
  572. return 0;
  573. }
  574. CopyMemory( ppbportDst, ppbportSrc, sizeof(*ppbportDst) );
  575. ppbportDst->pszDevice = StrDup( ppbportSrc->pszDevice );
  576. ppbportDst->pszMedia = StrDup( ppbportSrc->pszMedia );
  577. ppbportDst->pszPort = StrDup( ppbportSrc->pszPort );
  578. ppbportDst->pszScriptBefore = StrDup( ppbportSrc->pszScriptBefore );
  579. //
  580. // Copy the protocol list.
  581. //
  582. if(ppbportSrc->pListProtocols)
  583. {
  584. for (pdtlnode = DtlGetFirstNode( ppbportSrc->pListProtocols);
  585. pdtlnode;
  586. pdtlnode = DtlGetNextNode( pdtlnode ))
  587. {
  588. if(NULL == pdtllist)
  589. {
  590. pdtllist = DtlCreateList(0);
  591. if(NULL == pdtllist)
  592. {
  593. return ERROR_NOT_ENOUGH_MEMORY;
  594. }
  595. }
  596. pwsz = (WCHAR *) DtlGetData(pdtlnode);
  597. pNode = DtlCreateSizedNode(
  598. (wcslen(pwsz) + 1) * sizeof(WCHAR),
  599. pdtlnode->lNodeId);
  600. if(NULL == pNode)
  601. {
  602. return ERROR_NOT_ENOUGH_MEMORY;
  603. }
  604. wcscpy((WCHAR *) DtlGetData(pNode), pwsz);
  605. DtlAddNodeLast(pdtllist, pNode);
  606. }
  607. }
  608. ppbportDst->pListProtocols = pdtllist;
  609. if ((ppbportSrc->pszDevice && !ppbportDst->pszDevice)
  610. || (ppbportSrc->pszMedia && !ppbportDst->pszMedia)
  611. || (ppbportSrc->pszPort && !ppbportDst->pszPort)
  612. || (ppbportSrc->pszScriptBefore && !ppbportDst->pszScriptBefore))
  613. {
  614. return ERROR_NOT_ENOUGH_MEMORY;
  615. }
  616. return 0;
  617. }
  618. VOID
  619. ChangeEntryType(
  620. PBENTRY* ppbentry,
  621. DWORD dwType )
  622. // Changes the type of 'ppbentry' to 'dwType' and sets defaults
  623. // accordingly.
  624. //
  625. {
  626. ppbentry->dwType = dwType;
  627. if (dwType == RASET_Phone)
  628. {
  629. ppbentry->fPreviewPhoneNumber = TRUE;
  630. // Defaults for Phones changed per bug 230240 and 363809.
  631. //
  632. ppbentry->dwAuthRestrictions = AR_F_TypicalUnsecure;
  633. ppbentry->dwTypicalAuth = TA_Unsecure;
  634. ppbentry->dwDataEncryption = DE_IfPossible;
  635. ppbentry->fIpHeaderCompression = TRUE;
  636. ppbentry->fShareMsFilePrint = FALSE;
  637. // Disable File and Print services by default for phone
  638. //
  639. EnableOrDisableNetComponent( ppbentry, TEXT("ms_server"),
  640. FALSE);
  641. ppbentry->fBindMsNetClient = TRUE;
  642. EnableOrDisableNetComponent( ppbentry, TEXT("ms_msclient"),
  643. TRUE);
  644. }
  645. else if (dwType == RASET_Vpn)
  646. {
  647. // NOTE: If you change this you may need to also make a change in
  648. // CloneEntryNode.
  649. //
  650. ppbentry->fPreviewPhoneNumber = FALSE;
  651. ppbentry->fSharedPhoneNumbers = FALSE;
  652. // Defaults for VPN changed per bug 230240 and 363809.
  653. //
  654. ppbentry->dwAuthRestrictions = AR_F_TypicalSecure;
  655. ppbentry->dwTypicalAuth = TA_Secure;
  656. ppbentry->dwDataEncryption = DE_Require;
  657. ppbentry->fIpHeaderCompression = FALSE;
  658. // We share file and print by default for vpn
  659. //
  660. ppbentry->fShareMsFilePrint = TRUE;
  661. // Enable File and Print services by default
  662. //
  663. EnableOrDisableNetComponent( ppbentry, TEXT("ms_server"),
  664. TRUE);
  665. ppbentry->fBindMsNetClient = TRUE;
  666. EnableOrDisableNetComponent( ppbentry, TEXT("ms_msclient"),
  667. TRUE);
  668. }
  669. else if (dwType == RASET_Broadband)
  670. {
  671. // NOTE: If you change this you may need to also make a change in
  672. // CloneEntryNode.
  673. //
  674. ppbentry->fPreviewPhoneNumber = FALSE;
  675. ppbentry->fSharedPhoneNumbers = FALSE;
  676. // Defaults for broadband connections
  677. //
  678. ppbentry->dwAuthRestrictions = AR_F_TypicalSecure;
  679. ppbentry->dwTypicalAuth = TA_Secure;
  680. ppbentry->dwDataEncryption = DE_IfPossible;
  681. ppbentry->fIpHeaderCompression = FALSE;
  682. // We share file and print by default for vpn
  683. //
  684. ppbentry->fShareMsFilePrint = TRUE;
  685. // Enable File and Print services by default
  686. //
  687. EnableOrDisableNetComponent( ppbentry, TEXT("ms_server"),
  688. FALSE);
  689. ppbentry->fBindMsNetClient = TRUE;
  690. EnableOrDisableNetComponent( ppbentry, TEXT("ms_msclient"),
  691. TRUE);
  692. }
  693. else if (dwType == RASET_Direct)
  694. {
  695. // NOTE: If you change this you may need to also make a change in
  696. // CloneEntryNode.
  697. //
  698. ppbentry->fPreviewPhoneNumber = FALSE;
  699. ppbentry->fSharedPhoneNumbers = FALSE;
  700. // Defaults for DCC (like Phones in this regard) changed per bug
  701. // 230240 and 363809.
  702. //
  703. ppbentry->dwAuthRestrictions = AR_F_TypicalUnsecure;
  704. ppbentry->dwTypicalAuth = TA_Unsecure;
  705. ppbentry->dwDataEncryption = DE_IfPossible;
  706. ppbentry->fIpHeaderCompression = TRUE;
  707. // We share file and print by default for dcc
  708. //
  709. ppbentry->fShareMsFilePrint = TRUE;
  710. // Enable File and Print services by default
  711. //
  712. EnableOrDisableNetComponent( ppbentry, TEXT("ms_server"),
  713. TRUE);
  714. ppbentry->fBindMsNetClient = TRUE;
  715. EnableOrDisableNetComponent( ppbentry, TEXT("ms_msclient"),
  716. TRUE);
  717. }
  718. }
  719. DTLNODE*
  720. CreateEntryNode(
  721. BOOL fCreateLink )
  722. // Allocates a sized phonebook entry node of type RASET_Phone and fills it
  723. // with default values. See ChangeEntryNodeType routine. 'If
  724. // 'fCreateLink' is true a default node is added the list of links.
  725. // Otherwise, the list of links is empty.
  726. //
  727. // Returns the address of the allocated node if successful, NULL
  728. // otherwise.
  729. //
  730. {
  731. DTLNODE* pdtlnode;
  732. PBENTRY* ppbentry;
  733. TRACE( "CreateEntryNode" );
  734. // Allocate the node with built-in PBENTRY.
  735. //
  736. pdtlnode = DtlCreateSizedNode( sizeof(PBENTRY), 0L );
  737. if (!pdtlnode)
  738. {
  739. return NULL;
  740. }
  741. ppbentry = (PBENTRY* )DtlGetData( pdtlnode );
  742. ASSERT( ppbentry );
  743. // Create the list of links with a default link node or no link nodes as
  744. // chosen by caller.
  745. //
  746. ppbentry->pdtllistLinks = DtlCreateList( 0 );
  747. if (!ppbentry->pdtllistLinks)
  748. {
  749. DestroyEntryNode( pdtlnode );
  750. return NULL;
  751. }
  752. if (fCreateLink)
  753. {
  754. DTLNODE* pLinkNode;
  755. pLinkNode = CreateLinkNode();
  756. if (!pLinkNode)
  757. {
  758. DestroyEntryNode( pdtlnode );
  759. return NULL;
  760. }
  761. DtlAddNodeLast( ppbentry->pdtllistLinks, pLinkNode );
  762. }
  763. // Set fields to defaults.
  764. //
  765. ppbentry->pszEntryName = NULL;
  766. ppbentry->dwType = RASET_Phone;
  767. // General page fields.
  768. //
  769. ppbentry->pszPrerequisiteEntry = NULL;
  770. ppbentry->pszPrerequisitePbk = NULL;
  771. ppbentry->fSharedPhoneNumbers = TRUE;
  772. ppbentry->fGlobalDeviceSettings = FALSE;
  773. ppbentry->fShowMonitorIconInTaskBar = TRUE;
  774. ppbentry->pszPreferredDevice = NULL;
  775. ppbentry->pszPreferredPort = NULL;
  776. //For .Net 639551 Add preferred info for Modem settings
  777. ppbentry->dwPreferredBps = 0;
  778. ppbentry->fPreferredHwFlow = 0;
  779. ppbentry->fPreferredEc = 0;
  780. ppbentry->fPreferredEcc = 0;
  781. ppbentry->fPreferredSpeaker = 0;
  782. ppbentry->dwPreferredModemProtocol=0; //For whislter bug 402522
  783. // Options page fields.
  784. //
  785. ppbentry->fShowDialingProgress = TRUE;
  786. ppbentry->fPreviewPhoneNumber = TRUE;
  787. ppbentry->fPreviewUserPw = TRUE;
  788. ppbentry->fPreviewDomain = FALSE; // See bug 281673
  789. ppbentry->dwDialMode = RASEDM_DialAll;
  790. ppbentry->dwDialPercent = 75;
  791. ppbentry->dwDialSeconds = 120;
  792. ppbentry->dwHangUpPercent = 10;
  793. ppbentry->dwHangUpSeconds = 120;
  794. ppbentry->dwfOverridePref =
  795. RASOR_RedialAttempts | RASOR_RedialSeconds
  796. | RASOR_IdleDisconnectSeconds | RASOR_RedialOnLinkFailure;
  797. ppbentry->lIdleDisconnectSeconds = 0;
  798. ppbentry->dwRedialAttempts = 3;
  799. ppbentry->dwRedialSeconds = 60;
  800. ppbentry->fRedialOnLinkFailure = FALSE;
  801. // Security page fields.
  802. //
  803. ppbentry->dwAuthRestrictions = AR_F_TypicalUnsecure;
  804. ppbentry->dwTypicalAuth = TA_Unsecure;
  805. ppbentry->dwDataEncryption = DE_IfPossible;
  806. ppbentry->fAutoLogon = FALSE;
  807. ppbentry->fUseRasCredentials = TRUE;
  808. ppbentry->dwCustomAuthKey = (DWORD )-1;
  809. ppbentry->pCustomAuthData = NULL;
  810. ppbentry->cbCustomAuthData = 0;
  811. ppbentry->fScriptAfterTerminal = FALSE;
  812. ppbentry->fScriptAfter = FALSE;
  813. ppbentry->pszScriptAfter = NULL;
  814. ppbentry->pszX25Network = NULL;
  815. ppbentry->pszX25Address = NULL;
  816. ppbentry->pszX25UserData = NULL;
  817. ppbentry->pszX25Facilities = NULL;
  818. // Use is unknown
  819. //
  820. ppbentry->dwUseFlags = 0;
  821. //IP Security Dialog box
  822. //
  823. ppbentry->dwIpSecFlags = 0;
  824. // Network page fields.
  825. //
  826. ppbentry->dwBaseProtocol = BP_Ppp;
  827. ppbentry->dwVpnStrategy = VS_Default;
  828. ppbentry->dwfExcludedProtocols = 0;
  829. ppbentry->fLcpExtensions = TRUE;
  830. ppbentry->fSkipNwcWarning = FALSE;
  831. ppbentry->fSkipDownLevelDialog = FALSE;
  832. ppbentry->fSkipDoubleDialDialog = FALSE;
  833. ppbentry->fSwCompression = TRUE;
  834. // (shaunco) Gibbs and QOS guys want this on by default.
  835. // for whislter bug 385842 gangz
  836. // we cut this functionality, so set the default to be FALSE
  837. //
  838. ppbentry->fNegotiateMultilinkAlways = FALSE;
  839. // Create the list of links with a default link node or no link nodes as
  840. // chosen by caller.
  841. //
  842. ppbentry->pdtllistNetComponents = DtlCreateList( 0 );
  843. if (!ppbentry->pdtllistNetComponents)
  844. {
  845. DestroyEntryNode( pdtlnode );
  846. return NULL;
  847. }
  848. #ifdef AMB
  849. ppbentry->dwAuthentication = (DWORD )AS_Default;
  850. #endif
  851. ppbentry->fIpPrioritizeRemote = TRUE;
  852. ppbentry->fIpHeaderCompression = TRUE;
  853. ppbentry->pszIpAddress = NULL;
  854. ppbentry->pszIpDnsAddress = NULL;
  855. ppbentry->pszIpDns2Address = NULL;
  856. ppbentry->pszIpWinsAddress = NULL;
  857. ppbentry->pszIpWins2Address = NULL;
  858. ppbentry->dwIpAddressSource = ASRC_ServerAssigned;
  859. ppbentry->dwIpNameSource = ASRC_ServerAssigned;
  860. ppbentry->dwFrameSize = 1006;
  861. //Changed Vivekk - BugId: 105777
  862. if ( !IsServerOS() )
  863. ppbentry->dwIpDnsFlags = 0;
  864. else
  865. ppbentry->dwIpDnsFlags = DNS_RegDefault;
  866. ppbentry->dwIpNbtFlags = PBK_ENTRY_IP_NBT_Enable;
  867. // Whistler bug 300933. 0=default
  868. //
  869. ppbentry->dwTcpWindowSize = 0;
  870. ppbentry->pszIpDnsSuffix = NULL;
  871. // Router page fields.
  872. //
  873. ppbentry->dwCallbackMode = CBM_No;
  874. ppbentry->fAuthenticateServer = FALSE;
  875. // Other fields not shown in UI.
  876. //
  877. ppbentry->pszCustomDialDll = NULL;
  878. ppbentry->pszCustomDialFunc = NULL;
  879. ppbentry->pszCustomDialerName = NULL;
  880. ppbentry->dwDialParamsUID = GetTickCount();
  881. ppbentry->pGuid = Malloc( sizeof(GUID) );
  882. if (ppbentry->pGuid)
  883. {
  884. if(UuidCreate( (UUID* )(ppbentry->pGuid) ))
  885. {
  886. }
  887. }
  888. ppbentry->pszOldUser = NULL;
  889. ppbentry->pszOldDomain = NULL;
  890. // Status flags. 'fDirty' is set when the entry has changed so as to
  891. // differ from the phonebook file on disk. 'fCustom' is set when the
  892. // entry contains at least one MEDIA and DEVICE (so RASAPI is able to read
  893. // it) but was not created by us. When 'fCustom' is set only 'pszEntry'
  894. // is guaranteed valid and the entry cannot be edited.
  895. //
  896. ppbentry->fDirty = FALSE;
  897. ppbentry->fCustom = FALSE;
  898. return pdtlnode;
  899. }
  900. DTLNODE*
  901. CreateLinkNode(
  902. void )
  903. // Allocates a sized phonebook entry link node and fills it with default
  904. // values.
  905. //
  906. // Returns the address of the allocated node if successful, NULL
  907. // otherwise. It's the caller's responsibility to free the block.
  908. //
  909. {
  910. DTLNODE* pdtlnode;
  911. PBLINK* ppblink;
  912. TRACE( "CreateLinkNode" );
  913. pdtlnode = DtlCreateSizedNode( sizeof(PBLINK), 0L );
  914. if (!pdtlnode)
  915. {
  916. return NULL;
  917. }
  918. ppblink = (PBLINK* )DtlGetData( pdtlnode );
  919. ASSERT( ppblink );
  920. CopyToPbport( &ppblink->pbport, NULL );
  921. ppblink->dwBps = 0;
  922. ppblink->fHwFlow = TRUE;
  923. ppblink->fEc = TRUE;
  924. ppblink->fEcc = TRUE;
  925. ppblink->fSpeaker = TRUE;
  926. ppblink->dwModemProtocol = 0;
  927. ppblink->fProprietaryIsdn = FALSE;
  928. ppblink->lLineType = 0;
  929. ppblink->fFallback = TRUE;
  930. ppblink->fCompression = TRUE;
  931. ppblink->lChannels = 1;
  932. ppblink->pTapiBlob = NULL;
  933. ppblink->cbTapiBlob = 0;
  934. ppblink->iLastSelectedPhone = 0;
  935. ppblink->fPromoteAlternates = FALSE;
  936. ppblink->fTryNextAlternateOnFail = TRUE;
  937. ppblink->fEnabled = TRUE;
  938. // The list of phone number blocks is created but left empty.
  939. //
  940. ppblink->pdtllistPhones = DtlCreateList( 0 );
  941. if (!ppblink->pdtllistPhones)
  942. {
  943. Free( ppblink );
  944. return NULL;
  945. }
  946. return pdtlnode;
  947. }
  948. VOID
  949. GetCountryCodeAndID(
  950. IN PBPHONE* pPhone )
  951. // Get TAPI�s country ID for the current location. This is needed because
  952. // it�s needed for lineGetCountry.
  953. //
  954. {
  955. static BOOLEAN fAlreadyQueried = FALSE;
  956. static DWORD dwPreviousCountryCode = 1;
  957. static DWORD dwPreviousCountryID = 1;
  958. LPLINETRANSLATECAPS lpTranslateCaps = NULL;
  959. LPLINELOCATIONENTRY lpLocationList = NULL;
  960. DWORD dwErr = 0;
  961. DWORD dwNeededSize = 0;
  962. DWORD dwLocationIndex = 0;
  963. TRACE("GetCountryCodeAndID");
  964. ASSERT(pPhone != NULL);
  965. // Check to see if we've done this already so we don't have to do it again.
  966. //
  967. if (fAlreadyQueried)
  968. {
  969. pPhone->dwCountryCode = dwPreviousCountryCode;
  970. pPhone->dwCountryID = dwPreviousCountryID;
  971. return;
  972. }
  973. // It's okay to set fAlreadyQueried since the defaults are set up to valid
  974. // values.
  975. //
  976. fAlreadyQueried = TRUE;
  977. // Setup the defaults in case something fails.
  978. //
  979. pPhone->dwCountryCode = 1;
  980. pPhone->dwCountryID = 1;
  981. lpTranslateCaps = Malloc(sizeof(LINETRANSLATECAPS));
  982. if (lpTranslateCaps == NULL)
  983. {
  984. return;
  985. }
  986. // Query lineGetTranslateCaps to find out how big our LINETRANSLATECAPS
  987. // structure needs to be.
  988. //
  989. lpTranslateCaps->dwTotalSize = sizeof(LINETRANSLATECAPS);
  990. dwErr = lineGetTranslateCaps(0, TAPI_CURRENT_VERSION, lpTranslateCaps);
  991. if (dwErr != 0)
  992. {
  993. Free(lpTranslateCaps);
  994. return;
  995. }
  996. // Make our LINETRANSLATECAPS structure big enough.
  997. //
  998. dwNeededSize = lpTranslateCaps->dwNeededSize;
  999. Free(lpTranslateCaps);
  1000. lpTranslateCaps = Malloc(dwNeededSize);
  1001. if (lpTranslateCaps == NULL)
  1002. {
  1003. return;
  1004. }
  1005. // Now we can actually go and get the locations.
  1006. //
  1007. lpTranslateCaps->dwTotalSize = dwNeededSize;
  1008. dwErr = lineGetTranslateCaps(0, TAPI_CURRENT_VERSION, lpTranslateCaps);
  1009. if (dwErr != 0)
  1010. {
  1011. Free(lpTranslateCaps);
  1012. return;
  1013. }
  1014. // Walk through the locations, looking for the current location.
  1015. //
  1016. lpLocationList = (LPLINELOCATIONENTRY) ( ((LPSTR)lpTranslateCaps) + lpTranslateCaps->dwLocationListOffset );
  1017. for ( dwLocationIndex=0; dwLocationIndex < lpTranslateCaps->dwNumLocations; dwLocationIndex++ )
  1018. {
  1019. if (lpLocationList[dwLocationIndex].dwPermanentLocationID == lpTranslateCaps->dwCurrentLocationID)
  1020. {
  1021. break;
  1022. }
  1023. }
  1024. // If we found the current location, we know which country�s ID to use for dialing rules.
  1025. //
  1026. if (dwLocationIndex < lpTranslateCaps->dwNumLocations)
  1027. {
  1028. pPhone->dwCountryCode = lpLocationList[dwLocationIndex].dwCountryCode;
  1029. pPhone->dwCountryID = lpLocationList[dwLocationIndex].dwCountryID;
  1030. // Save the values in case we're called again.
  1031. //
  1032. dwPreviousCountryCode = pPhone->dwCountryCode;
  1033. dwPreviousCountryID = pPhone->dwCountryID;
  1034. }
  1035. Free(lpTranslateCaps);
  1036. }
  1037. DTLNODE*
  1038. CreatePhoneNode(
  1039. void )
  1040. // Allocates a sized phone number node and fills it with default values.
  1041. //
  1042. // Returns the address of the allocated node if successful, NULL
  1043. // otherwise. It's the caller's responsibility to free the block.
  1044. //
  1045. {
  1046. DTLNODE* pNode;
  1047. PBPHONE* pPhone;
  1048. TRACE( "CreatePhoneNode" );
  1049. pNode = DtlCreateSizedNode( sizeof(PBPHONE), 0L );
  1050. if (!pNode)
  1051. {
  1052. return NULL;
  1053. }
  1054. pPhone = (PBPHONE* )DtlGetData( pNode );
  1055. ASSERT( pPhone );
  1056. GetCountryCodeAndID( pPhone );
  1057. pPhone->fUseDialingRules = FALSE;
  1058. return pNode;
  1059. }
  1060. DTLNODE*
  1061. CreatePortNode(
  1062. void )
  1063. // Allocates a sized port node and fills it with default values.
  1064. //
  1065. // Returns the address of the allocated node if successful, NULL
  1066. // otherwise. It's the caller's responsibility to free the block.
  1067. //
  1068. {
  1069. DTLNODE* pdtlnode;
  1070. PBPORT* ppbport;
  1071. TRACE( "CreatePortNode" );
  1072. pdtlnode = DtlCreateSizedNode( sizeof(PBPORT), 0L );
  1073. if (!pdtlnode)
  1074. {
  1075. return NULL;
  1076. }
  1077. ppbport = (PBPORT* )DtlGetData( pdtlnode );
  1078. ASSERT( ppbport );
  1079. CopyToPbport( ppbport, NULL );
  1080. return pdtlnode;
  1081. }
  1082. VOID
  1083. DestroyPort(
  1084. PBPORT* pPort)
  1085. {
  1086. Free0( pPort->pszDevice );
  1087. Free0( pPort->pszMedia );
  1088. Free0( pPort->pszPort );
  1089. Free0( pPort->pszScriptBefore );
  1090. // pmay: 228565
  1091. // Clean up the list of available protocols
  1092. // if any.
  1093. //
  1094. if ( pPort->pListProtocols )
  1095. {
  1096. DtlDestroyList( pPort->pListProtocols, NULL );
  1097. }
  1098. }
  1099. VOID
  1100. DestroyEntryTypeNode(
  1101. IN DTLNODE *pdtlnode)
  1102. {
  1103. DtlDestroyNode(pdtlnode);
  1104. }
  1105. VOID
  1106. DestroyEntryNode(
  1107. IN DTLNODE* pdtlnode )
  1108. // Release all memory associated with phonebook entry node 'pdtlnode'.
  1109. // See DtlDestroyList.
  1110. //
  1111. {
  1112. PBENTRY* ppbentry;
  1113. TRACE( "DestroyEntryNode" );
  1114. ASSERT( pdtlnode );
  1115. ppbentry = (PBENTRY* )DtlGetData( pdtlnode );
  1116. ASSERT( ppbentry );
  1117. Free0( ppbentry->pszEntryName );
  1118. Free0( ppbentry->pszPrerequisiteEntry );
  1119. Free0( ppbentry->pszPrerequisitePbk );
  1120. Free0( ppbentry->pszPreferredPort );
  1121. Free0( ppbentry->pszPreferredDevice );
  1122. Free0( ppbentry->pCustomAuthData );
  1123. Free0( ppbentry->pszScriptAfter );
  1124. Free0( ppbentry->pszX25Network );
  1125. Free0( ppbentry->pszX25Address );
  1126. Free0( ppbentry->pszX25UserData );
  1127. Free0( ppbentry->pszX25Facilities );
  1128. Free0( ppbentry->pszIpAddress );
  1129. Free0( ppbentry->pszIpDnsAddress );
  1130. Free0( ppbentry->pszIpDns2Address );
  1131. Free0( ppbentry->pszIpWinsAddress );
  1132. Free0( ppbentry->pszIpWins2Address );
  1133. Free0( ppbentry->pszIpDnsSuffix );
  1134. Free0( ppbentry->pszCustomDialDll );
  1135. Free0( ppbentry->pszCustomDialFunc );
  1136. Free0( ppbentry->pszCustomDialerName);
  1137. Free0( ppbentry->pszOldUser );
  1138. Free0( ppbentry->pszOldDomain );
  1139. Free0( ppbentry->pGuid );
  1140. DtlDestroyList( ppbentry->pdtllistLinks, DestroyLinkNode );
  1141. DtlDestroyList( ppbentry->pdtllistNetComponents, DestroyKvNode );
  1142. DtlDestroyNode( pdtlnode );
  1143. }
  1144. VOID
  1145. DestroyLinkNode(
  1146. IN DTLNODE* pdtlnode )
  1147. // Release all memory associated with phonebook entry link node
  1148. // 'pdtlnode'. See DtlDestroyList.
  1149. //
  1150. {
  1151. PBLINK* ppblink;
  1152. TRACE( "DestroyLinkNode" );
  1153. ASSERT( pdtlnode );
  1154. ppblink = (PBLINK* )DtlGetData( pdtlnode );
  1155. ASSERT( ppblink );
  1156. DestroyPort(&(ppblink->pbport));
  1157. Free0( ppblink->pTapiBlob );
  1158. DtlDestroyList( ppblink->pdtllistPhones, DestroyPhoneNode );
  1159. DtlDestroyNode( pdtlnode );
  1160. }
  1161. VOID
  1162. DestroyPhoneNode(
  1163. IN DTLNODE* pdtlnode )
  1164. // Release memory associated with PBPHONE node 'pdtlnode'. See
  1165. // DtlDestroyList.
  1166. //
  1167. {
  1168. PBPHONE* pPhone;
  1169. TRACE( "DestroyPhoneNode" );
  1170. ASSERT( pdtlnode );
  1171. pPhone = (PBPHONE* )DtlGetData( pdtlnode );
  1172. ASSERT( pPhone );
  1173. Free0( pPhone->pszAreaCode );
  1174. Free0( pPhone->pszPhoneNumber );
  1175. Free0( pPhone->pszComment );
  1176. DtlDestroyNode( pdtlnode );
  1177. }
  1178. VOID
  1179. DestroyPortNode(
  1180. IN DTLNODE* pdtlnode )
  1181. // Release memory associated with PBPORT node 'pdtlnode'. See
  1182. // DtlDestroyList.
  1183. //
  1184. {
  1185. PBPORT* pPort;
  1186. TRACE( "DestroyPortNode" );
  1187. ASSERT( pdtlnode );
  1188. pPort = (PBPORT* )DtlGetData( pdtlnode );
  1189. ASSERT( pPort );
  1190. DestroyPort(pPort);
  1191. DtlDestroyNode( pdtlnode );
  1192. }
  1193. DTLNODE*
  1194. DuplicateEntryNode(
  1195. DTLNODE* pdtlnodeSrc )
  1196. // Duplicates phonebook entry node 'pdtlnodeSrc'. See CloneEntryNode and
  1197. // DtlDuplicateList.
  1198. //
  1199. // Returns the address of the allocated node if successful, NULL
  1200. // otherwise. It's the caller's responsibility to free the block.
  1201. //
  1202. {
  1203. DTLNODE* pdtlnodeDst;
  1204. PBENTRY* ppbentrySrc;
  1205. PBENTRY* ppbentryDst;
  1206. BOOL fDone;
  1207. TRACE( "DuplicateEntryNode" );
  1208. pdtlnodeDst = DtlCreateSizedNode( sizeof(PBENTRY), 0L );
  1209. if (!pdtlnodeDst)
  1210. {
  1211. return NULL;
  1212. }
  1213. ppbentrySrc = (PBENTRY* )DtlGetData( pdtlnodeSrc );
  1214. ppbentryDst = (PBENTRY* )DtlGetData( pdtlnodeDst );
  1215. fDone = FALSE;
  1216. CopyMemory( ppbentryDst, ppbentrySrc, sizeof(PBENTRY) );
  1217. ppbentryDst->pszEntryName = NULL;
  1218. ppbentryDst->pdtllistLinks = NULL;
  1219. ppbentryDst->pszPrerequisiteEntry = NULL;
  1220. ppbentryDst->pszPrerequisitePbk = NULL;
  1221. ppbentryDst->pszPreferredPort = NULL;
  1222. ppbentryDst->pszPreferredDevice = NULL;
  1223. //For .Net 639551 Add preferred info for Modem settings
  1224. ppbentryDst->dwPreferredBps = 0;
  1225. ppbentryDst->fPreferredHwFlow = 0;
  1226. ppbentryDst->fPreferredEc = 0;
  1227. ppbentryDst->fPreferredEcc = 0;
  1228. ppbentryDst->fPreferredSpeaker = 0;
  1229. ppbentryDst->dwPreferredModemProtocol = 0;
  1230. ppbentryDst->pCustomAuthData = NULL;
  1231. ppbentryDst->pszScriptAfter = NULL;
  1232. ppbentryDst->pszX25Network = NULL;
  1233. ppbentryDst->pszX25Address = NULL;
  1234. ppbentryDst->pszX25UserData = NULL;
  1235. ppbentryDst->pszX25Facilities = NULL;
  1236. ppbentryDst->pdtllistNetComponents = NULL;
  1237. ppbentryDst->pszIpAddress = NULL;
  1238. ppbentryDst->pszIpDnsAddress = NULL;
  1239. ppbentryDst->pszIpDns2Address = NULL;
  1240. ppbentryDst->pszIpWinsAddress = NULL;
  1241. ppbentryDst->pszIpWins2Address = NULL;
  1242. ppbentryDst->pszIpDnsSuffix = NULL;
  1243. ppbentryDst->pszCustomDialDll = NULL;
  1244. ppbentryDst->pszCustomDialFunc = NULL;
  1245. ppbentryDst->pszCustomDialerName = NULL;
  1246. ppbentryDst->pGuid = NULL;
  1247. ppbentryDst->pszOldUser = NULL;
  1248. ppbentryDst->pszOldDomain = NULL;
  1249. do
  1250. {
  1251. // Duplicate strings.
  1252. //
  1253. if (ppbentrySrc->pszEntryName
  1254. && (!(ppbentryDst->pszEntryName =
  1255. StrDup( ppbentrySrc->pszEntryName ))))
  1256. {
  1257. break;
  1258. }
  1259. if (ppbentrySrc->pszPrerequisiteEntry
  1260. && (!(ppbentryDst->pszPrerequisiteEntry =
  1261. StrDup( ppbentrySrc->pszPrerequisiteEntry ))))
  1262. {
  1263. break;
  1264. }
  1265. if (ppbentrySrc->pszPrerequisitePbk
  1266. && (!(ppbentryDst->pszPrerequisitePbk =
  1267. StrDup( ppbentrySrc->pszPrerequisitePbk ))))
  1268. {
  1269. break;
  1270. }
  1271. if (ppbentrySrc->pszPreferredPort
  1272. && (!(ppbentryDst->pszPreferredPort =
  1273. StrDup( ppbentrySrc->pszPreferredPort ))))
  1274. {
  1275. break;
  1276. }
  1277. ppbentryDst->dwPreferredModemProtocol =
  1278. ppbentrySrc->dwPreferredModemProtocol;
  1279. //For .Net 639551 Add preferred info for Modem settings
  1280. ppbentryDst->dwPreferredBps = ppbentrySrc->dwPreferredBps;
  1281. ppbentryDst->fPreferredHwFlow = ppbentrySrc->fPreferredHwFlow;
  1282. ppbentryDst->fPreferredEc = ppbentrySrc->fPreferredEc;
  1283. ppbentryDst->fPreferredEcc = ppbentrySrc->fPreferredEcc ;
  1284. ppbentryDst->fPreferredSpeaker = ppbentrySrc->fPreferredSpeaker;
  1285. if (ppbentrySrc->pszPreferredDevice
  1286. && (!(ppbentryDst->pszPreferredDevice =
  1287. StrDup( ppbentrySrc->pszPreferredDevice ))))
  1288. {
  1289. break;
  1290. }
  1291. if (ppbentrySrc->cbCustomAuthData && ppbentrySrc->pCustomAuthData)
  1292. {
  1293. ppbentryDst->pCustomAuthData = Malloc( ppbentrySrc->cbCustomAuthData );
  1294. if (!ppbentryDst->pCustomAuthData)
  1295. {
  1296. break;
  1297. }
  1298. CopyMemory( ppbentryDst->pCustomAuthData,
  1299. ppbentrySrc->pCustomAuthData,
  1300. ppbentrySrc->cbCustomAuthData);
  1301. ppbentryDst->cbCustomAuthData = ppbentrySrc->cbCustomAuthData;
  1302. }
  1303. if (ppbentrySrc->pszIpAddress
  1304. && (!(ppbentryDst->pszIpAddress =
  1305. StrDup( ppbentrySrc->pszIpAddress ))))
  1306. {
  1307. break;
  1308. }
  1309. if (ppbentrySrc->pszIpDnsAddress
  1310. && (!(ppbentryDst->pszIpDnsAddress =
  1311. StrDup( ppbentrySrc->pszIpDnsAddress ))))
  1312. {
  1313. break;
  1314. }
  1315. if (ppbentrySrc->pszIpDns2Address
  1316. && (!(ppbentryDst->pszIpDns2Address =
  1317. StrDup( ppbentrySrc->pszIpDns2Address ))))
  1318. {
  1319. break;
  1320. }
  1321. if (ppbentrySrc->pszIpWinsAddress
  1322. && (!(ppbentryDst->pszIpWinsAddress =
  1323. StrDup( ppbentrySrc->pszIpWinsAddress ))))
  1324. {
  1325. break;
  1326. }
  1327. if (ppbentrySrc->pszIpWins2Address
  1328. && (!(ppbentryDst->pszIpWins2Address =
  1329. StrDup( ppbentrySrc->pszIpWins2Address ))))
  1330. {
  1331. break;
  1332. }
  1333. if (ppbentrySrc->pszIpDnsSuffix
  1334. && (!(ppbentryDst->pszIpDnsSuffix =
  1335. StrDup( ppbentrySrc->pszIpDnsSuffix ))))
  1336. {
  1337. break;
  1338. }
  1339. if (ppbentrySrc->pszScriptAfter
  1340. && (!(ppbentryDst->pszScriptAfter =
  1341. StrDup( ppbentrySrc->pszScriptAfter ))))
  1342. {
  1343. break;
  1344. }
  1345. if (ppbentrySrc->pszX25Network
  1346. && (!(ppbentryDst->pszX25Network =
  1347. StrDup( ppbentrySrc->pszX25Network ))))
  1348. {
  1349. break;
  1350. }
  1351. if (ppbentrySrc->pszX25Address
  1352. && (!(ppbentryDst->pszX25Address =
  1353. StrDup( ppbentrySrc->pszX25Address ))))
  1354. {
  1355. break;
  1356. }
  1357. if (ppbentrySrc->pszX25UserData
  1358. && (!(ppbentryDst->pszX25UserData =
  1359. StrDup( ppbentrySrc->pszX25UserData ))))
  1360. {
  1361. break;
  1362. }
  1363. if (ppbentrySrc->pszX25Facilities
  1364. && (!(ppbentryDst->pszX25Facilities =
  1365. StrDup( ppbentrySrc->pszX25Facilities ))))
  1366. {
  1367. break;
  1368. }
  1369. if (ppbentrySrc->pszCustomDialDll
  1370. && (!(ppbentryDst->pszCustomDialDll =
  1371. StrDup( ppbentrySrc->pszCustomDialDll ))))
  1372. {
  1373. break;
  1374. }
  1375. if (ppbentrySrc->pszCustomDialFunc
  1376. && (!(ppbentryDst->pszCustomDialFunc =
  1377. StrDup( ppbentrySrc->pszCustomDialFunc ))))
  1378. {
  1379. break;
  1380. }
  1381. if (ppbentrySrc->pszCustomDialerName
  1382. && (!(ppbentryDst->pszCustomDialerName =
  1383. StrDup( ppbentrySrc->pszCustomDialerName))))
  1384. {
  1385. break;
  1386. }
  1387. if (ppbentrySrc->pszOldUser
  1388. && (!(ppbentryDst->pszOldUser =
  1389. StrDup( ppbentrySrc->pszOldUser ))))
  1390. {
  1391. break;
  1392. }
  1393. if (ppbentrySrc->pszOldDomain
  1394. && (!(ppbentryDst->pszOldDomain =
  1395. StrDup( ppbentrySrc->pszOldDomain ))))
  1396. {
  1397. break;
  1398. }
  1399. // Duplicate GUID.
  1400. //
  1401. if (ppbentrySrc->pGuid)
  1402. {
  1403. ppbentryDst->pGuid = Malloc( sizeof( GUID ) );
  1404. if (!ppbentryDst->pGuid)
  1405. {
  1406. break;
  1407. }
  1408. *ppbentryDst->pGuid = *ppbentrySrc->pGuid;
  1409. }
  1410. // Duplicate net component list information.
  1411. //
  1412. if (ppbentrySrc->pdtllistNetComponents
  1413. && (!(ppbentryDst->pdtllistNetComponents =
  1414. DtlDuplicateList(
  1415. ppbentrySrc->pdtllistNetComponents,
  1416. DuplicateKvNode,
  1417. DestroyKvNode ))))
  1418. {
  1419. break;
  1420. }
  1421. // Duplicate list of link information.
  1422. //
  1423. if (ppbentrySrc->pdtllistLinks
  1424. && (!(ppbentryDst->pdtllistLinks =
  1425. DtlDuplicateList(
  1426. ppbentrySrc->pdtllistLinks,
  1427. DuplicateLinkNode,
  1428. DestroyLinkNode ))))
  1429. {
  1430. break;
  1431. }
  1432. fDone = TRUE;
  1433. }
  1434. while (FALSE);
  1435. if (!fDone)
  1436. {
  1437. DestroyEntryNode( pdtlnodeDst );
  1438. return NULL;
  1439. }
  1440. // Since the copy is "new" it is inherently dirty relative to the
  1441. // phonebook file.
  1442. //
  1443. ppbentryDst->fDirty = TRUE;
  1444. return pdtlnodeDst;
  1445. }
  1446. DTLNODE*
  1447. DuplicateLinkNode(
  1448. IN DTLNODE* pdtlnodeSrc )
  1449. // Duplicates phonebook entry link node 'pdtlnodeSrc'. See
  1450. // DtlDuplicateList.
  1451. //
  1452. // Returns the address of the allocated node if successful, NULL
  1453. // otherwise. It's the caller's responsibility to free the block.
  1454. //
  1455. {
  1456. DTLNODE* pdtlnodeDst;
  1457. PBLINK* ppblinkSrc;
  1458. PBLINK* ppblinkDst;
  1459. BOOL fDone;
  1460. TRACE( "DuplicateLinkNode" );
  1461. pdtlnodeDst = DtlCreateSizedNode( sizeof(PBLINK), 0L );
  1462. if (!pdtlnodeDst)
  1463. {
  1464. return NULL;
  1465. }
  1466. ppblinkSrc = (PBLINK* )DtlGetData( pdtlnodeSrc );
  1467. ppblinkDst = (PBLINK* )DtlGetData( pdtlnodeDst );
  1468. fDone = FALSE;
  1469. CopyMemory( ppblinkDst, ppblinkSrc, sizeof(PBLINK) );
  1470. ppblinkDst->pbport.pszDevice = NULL;
  1471. ppblinkDst->pbport.pszMedia = NULL;
  1472. ppblinkDst->pbport.pszPort = NULL;
  1473. ppblinkDst->pbport.pszScriptBefore = NULL;
  1474. ppblinkDst->pbport.pListProtocols = NULL;
  1475. ppblinkDst->pTapiBlob = NULL;
  1476. ppblinkDst->pdtllistPhones = NULL;
  1477. do
  1478. {
  1479. // Duplicate strings.
  1480. //
  1481. if (ppblinkSrc->pbport.pszDevice
  1482. && (!(ppblinkDst->pbport.pszDevice =
  1483. StrDup( ppblinkSrc->pbport.pszDevice ))))
  1484. {
  1485. break;
  1486. }
  1487. if (ppblinkSrc->pbport.pszMedia
  1488. && (!(ppblinkDst->pbport.pszMedia =
  1489. StrDup( ppblinkSrc->pbport.pszMedia ))))
  1490. {
  1491. break;
  1492. }
  1493. if (ppblinkSrc->pbport.pszPort
  1494. && (!(ppblinkDst->pbport.pszPort =
  1495. StrDup( ppblinkSrc->pbport.pszPort ))))
  1496. {
  1497. break;
  1498. }
  1499. if (ppblinkSrc->pbport.pszScriptBefore
  1500. && (!(ppblinkDst->pbport.pszScriptBefore =
  1501. StrDup( ppblinkSrc->pbport.pszScriptBefore ))))
  1502. {
  1503. break;
  1504. }
  1505. // Duplicate TAPI blob.
  1506. //
  1507. if (ppblinkSrc->pTapiBlob)
  1508. {
  1509. VOID* pTapiBlobDst;
  1510. ppblinkDst->pTapiBlob = (VOID* )Malloc( ppblinkSrc->cbTapiBlob );
  1511. if (!ppblinkDst->pTapiBlob)
  1512. break;
  1513. CopyMemory( ppblinkDst->pTapiBlob, ppblinkSrc->pTapiBlob,
  1514. ppblinkSrc->cbTapiBlob );
  1515. }
  1516. // Duplicate list of phone numbers.
  1517. //
  1518. if (ppblinkSrc->pdtllistPhones
  1519. && (!(ppblinkDst->pdtllistPhones =
  1520. DtlDuplicateList(
  1521. ppblinkSrc->pdtllistPhones,
  1522. DuplicatePhoneNode,
  1523. DestroyPhoneNode ))))
  1524. {
  1525. break;
  1526. }
  1527. //For whistler bug 398438 gangz
  1528. //If the pListProtocls is not duplicated, then in EuFree() which calls
  1529. // DestoryEntryNode() to free EINFO->pNode, ClosePhonebookFile() to
  1530. // free EINFO->pFile, both of them will eventually free this
  1531. // pListProtocols, then an AV will occur.
  1532. //
  1533. if (ppblinkSrc->pbport.pListProtocols
  1534. && ( !(ppblinkDst->pbport.pListProtocols =
  1535. DtlDuplicateList(
  1536. ppblinkSrc->pbport.pListProtocols,
  1537. DuplicateProtocolNode,
  1538. DestroyProtocolNode))))
  1539. {
  1540. break;
  1541. }
  1542. fDone = TRUE;
  1543. }
  1544. while (FALSE);
  1545. if (!fDone)
  1546. {
  1547. DestroyLinkNode( pdtlnodeDst );
  1548. return NULL;
  1549. }
  1550. return pdtlnodeDst;
  1551. }
  1552. //For whistler bug 398438 gangz
  1553. //
  1554. DTLNODE*
  1555. DuplicateProtocolNode(
  1556. IN DTLNODE* pdtlnodeSrc )
  1557. {
  1558. DTLNODE* pdtlnodeDst = NULL;
  1559. BOOL fDone = FALSE;
  1560. PVOID pNameSrc = NULL;
  1561. TRACE( "DuplicateProtocolNode" );
  1562. pdtlnodeDst = DtlCreateSizedNode( sizeof(DTLNODE), 0L );
  1563. if ( !pdtlnodeDst )
  1564. {
  1565. return NULL;
  1566. }
  1567. do
  1568. {
  1569. pNameSrc = DtlGetData( pdtlnodeSrc );
  1570. if(pNameSrc
  1571. && ( !(pdtlnodeDst->pData = StrDup(pNameSrc) ))
  1572. )
  1573. {
  1574. break;
  1575. }
  1576. pdtlnodeDst->lNodeId = pdtlnodeSrc->lNodeId;
  1577. fDone = TRUE;
  1578. }
  1579. while(FALSE);
  1580. if (!fDone)
  1581. {
  1582. DestroyProtocolNode(pdtlnodeDst);
  1583. return NULL;
  1584. }
  1585. return pdtlnodeDst;
  1586. }
  1587. VOID
  1588. DestroyProtocolNode(
  1589. IN DTLNODE* pdtlnode )
  1590. // Release memory associated with PBPHONE node 'pdtlnode'. See
  1591. // DtlDestroyList.
  1592. //
  1593. {
  1594. TRACE( "DestroyProtocolNode" );
  1595. DtlDestroyNode( pdtlnode );
  1596. }
  1597. DTLNODE*
  1598. DuplicatePhoneNode(
  1599. IN DTLNODE* pdtlnodeSrc )
  1600. // Duplicates phone number set node 'pdtlnodeSrc'. See DtlDuplicateList.
  1601. //
  1602. // Returns the address of the allocated node if successful, NULL
  1603. // otherwise. It's the caller's responsibility to free the block.
  1604. //
  1605. {
  1606. DTLNODE* pdtlnodeDst;
  1607. PBPHONE* pPhoneSrc;
  1608. PBPHONE* pPhoneDst;
  1609. BOOL fDone;
  1610. TRACE( "DuplicatePhoneNode" );
  1611. pdtlnodeDst = DtlCreateSizedNode( sizeof(PBPHONE), 0L );
  1612. if (!pdtlnodeDst)
  1613. {
  1614. return NULL;
  1615. }
  1616. pPhoneSrc = (PBPHONE* )DtlGetData( pdtlnodeSrc );
  1617. pPhoneDst = (PBPHONE* )DtlGetData( pdtlnodeDst );
  1618. fDone = FALSE;
  1619. CopyMemory( pPhoneDst, pPhoneSrc, sizeof(PBPHONE) );
  1620. pPhoneDst->pszPhoneNumber = NULL;
  1621. pPhoneDst->pszAreaCode = NULL;
  1622. pPhoneDst->pszComment = NULL;
  1623. do
  1624. {
  1625. // Duplicate strings.
  1626. //
  1627. if (pPhoneSrc->pszPhoneNumber
  1628. && (!(pPhoneDst->pszPhoneNumber =
  1629. StrDup( pPhoneSrc->pszPhoneNumber ))))
  1630. {
  1631. break;
  1632. }
  1633. if (pPhoneSrc->pszAreaCode
  1634. && (!(pPhoneDst->pszAreaCode =
  1635. StrDup( pPhoneSrc->pszAreaCode ))))
  1636. {
  1637. break;
  1638. }
  1639. if (pPhoneSrc->pszComment
  1640. && (!(pPhoneDst->pszComment =
  1641. StrDup( pPhoneSrc->pszComment ))))
  1642. {
  1643. break;
  1644. }
  1645. fDone = TRUE;
  1646. }
  1647. while (FALSE);
  1648. if (!fDone)
  1649. {
  1650. DestroyPhoneNode( pdtlnodeDst );
  1651. return NULL;
  1652. }
  1653. return pdtlnodeDst;
  1654. }
  1655. VOID
  1656. EnableOrDisableNetComponent(
  1657. IN PBENTRY* pEntry,
  1658. IN LPCTSTR pszComponent,
  1659. IN BOOL fEnable)
  1660. {
  1661. KEYVALUE* pKv;
  1662. BOOL fIsEnabled;
  1663. static const TCHAR c_pszDisabledValue[] = TEXT("0");
  1664. static const TCHAR c_pszEnabledValue [] = TEXT("1");
  1665. ASSERT (pEntry);
  1666. ASSERT (pszComponent);
  1667. // If the component already exists in the list, update its value.
  1668. //
  1669. if (FIsNetComponentListed (pEntry, pszComponent, &fIsEnabled, &pKv))
  1670. {
  1671. LPCTSTR pszNewValue = NULL;
  1672. // If we need to change the value, do so, otherwise, we don't have
  1673. // any work to do. (Use a logical XOR here instead of == because
  1674. // there are many values of TRUE.
  1675. //
  1676. if (fEnable && !fIsEnabled)
  1677. {
  1678. pszNewValue = c_pszEnabledValue;
  1679. }
  1680. else if (!fEnable && fIsEnabled)
  1681. {
  1682. pszNewValue = c_pszDisabledValue;
  1683. }
  1684. if (pszNewValue)
  1685. {
  1686. Free0 (pKv->pszValue);
  1687. pKv->pszValue = StrDup(pszNewValue);
  1688. }
  1689. }
  1690. // If the component does not exist in the list, we need to add it.
  1691. //
  1692. else
  1693. {
  1694. LPCTSTR pszValue;
  1695. DTLNODE* pdtlnode;
  1696. pszValue = (fEnable) ? c_pszEnabledValue : c_pszDisabledValue;
  1697. pdtlnode = CreateKvNode (pszComponent, pszValue);
  1698. if (pdtlnode)
  1699. {
  1700. ASSERT( DtlGetData(pdtlnode) );
  1701. DtlAddNodeLast (pEntry->pdtllistNetComponents, pdtlnode);
  1702. }
  1703. }
  1704. }
  1705. BOOL
  1706. FIsNetComponentListed(
  1707. IN PBENTRY* pEntry,
  1708. IN LPCTSTR pszComponent,
  1709. OUT BOOL* pfEnabled,
  1710. OUT KEYVALUE** ppKv)
  1711. // Returns TRUE if the pszComponent exists as the key of the NETCOMPONENTs
  1712. // KEYVALUE pairs in pEntry. If TRUE is returned, *pfEnabled is the
  1713. // BOOL form of the value part of the pair. This represents whether the
  1714. // component is 'checked' in the property UI on the networking page.
  1715. // ppKv is an optional output parameter. If ppKv is specfied, and the
  1716. // function returns TRUE, it will point to the KEYVALUE in the DTLLIST
  1717. // of NETCOMPONENTS.
  1718. {
  1719. DTLNODE* pdtlnode;
  1720. BOOL fPresent = FALSE;
  1721. ASSERT (pEntry);
  1722. ASSERT (pEntry->pdtllistNetComponents);
  1723. ASSERT (pszComponent);
  1724. ASSERT (pfEnabled);
  1725. // Initialize the output parameters.
  1726. //
  1727. *pfEnabled = FALSE;
  1728. if (ppKv)
  1729. {
  1730. *ppKv = NULL;
  1731. }
  1732. // Look for pszComponent in the list.
  1733. //
  1734. for (pdtlnode = DtlGetFirstNode (pEntry->pdtllistNetComponents);
  1735. pdtlnode;
  1736. pdtlnode = DtlGetNextNode (pdtlnode))
  1737. {
  1738. KEYVALUE* pKv = (KEYVALUE* )DtlGetData (pdtlnode);
  1739. ASSERT (pKv);
  1740. if (0 == lstrcmp(pszComponent, pKv->pszKey))
  1741. {
  1742. // If we found the component, get its value (as a BOOL)
  1743. // and return the KEYVALUE pointer if requested.
  1744. //
  1745. LONG lValue = _ttol (pKv->pszValue);
  1746. *pfEnabled = !!lValue;
  1747. fPresent = TRUE;
  1748. if (ppKv)
  1749. {
  1750. *ppKv = pKv;
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. return fPresent;
  1756. }
  1757. DTLNODE*
  1758. EntryNodeFromName(
  1759. IN DTLLIST* pdtllistEntries,
  1760. IN LPCTSTR pszName )
  1761. // Returns the address of the node in the global phonebook entries list
  1762. // whose Entry Name matches 'pszName' or NULL if none.
  1763. //
  1764. {
  1765. DTLNODE* pdtlnode;
  1766. for (pdtlnode = DtlGetFirstNode( pdtllistEntries );
  1767. pdtlnode;
  1768. pdtlnode = DtlGetNextNode( pdtlnode ))
  1769. {
  1770. PBENTRY* ppbentry = (PBENTRY* )DtlGetData( pdtlnode );
  1771. if (lstrcmpi( ppbentry->pszEntryName, pszName ) == 0)
  1772. {
  1773. return pdtlnode;
  1774. }
  1775. }
  1776. return NULL;
  1777. }
  1778. DWORD
  1779. EntryTypeFromPbport(
  1780. IN PBPORT* ppbport )
  1781. // Returns the RASET_* entry type associated with the 'ppbport' port type.
  1782. //
  1783. {
  1784. DWORD dwType;
  1785. // Default is phone type
  1786. //
  1787. dwType = RASET_Phone;
  1788. if ((ppbport->pbdevicetype == PBDT_Null) ||
  1789. (ppbport->dwFlags & PBP_F_NullModem) ||
  1790. (ppbport->pbdevicetype == PBDT_Irda) ||
  1791. (ppbport->pbdevicetype == PBDT_Parallel))
  1792. {
  1793. dwType = RASET_Direct;
  1794. }
  1795. else if (ppbport->pbdevicetype == PBDT_Vpn)
  1796. {
  1797. dwType = RASET_Vpn;
  1798. }
  1799. else if (ppbport->pbdevicetype == PBDT_PPPoE)
  1800. {
  1801. dwType = RASET_Broadband;
  1802. }
  1803. else if (ppbport->pszPort)
  1804. {
  1805. TCHAR achPort[ 3 + 1 ];
  1806. lstrcpyn( achPort, ppbport->pszPort, 3 + 1 );
  1807. if (lstrcmp( achPort, TEXT("VPN") ) == 0)
  1808. {
  1809. dwType = RASET_Vpn;
  1810. }
  1811. }
  1812. return dwType;
  1813. }
  1814. DWORD
  1815. GetOverridableParam(
  1816. IN PBUSER* pUser,
  1817. IN PBENTRY* pEntry,
  1818. IN DWORD dwfRasorBit )
  1819. // Return the value of the parameter identified by RASOR_* the single bit
  1820. // in bitmask 'dwfRasorBit', retrieving the value from the 'pUser' or
  1821. // 'pEntry' based on the override mask in 'pEntry'.
  1822. //
  1823. {
  1824. switch (dwfRasorBit)
  1825. {
  1826. case RASOR_RedialAttempts:
  1827. {
  1828. if (pEntry->dwfOverridePref & RASOR_RedialAttempts)
  1829. {
  1830. return pEntry->dwRedialAttempts;
  1831. }
  1832. else
  1833. {
  1834. return pUser->dwRedialAttempts;
  1835. }
  1836. }
  1837. case RASOR_RedialSeconds:
  1838. {
  1839. if (pEntry->dwfOverridePref & RASOR_RedialSeconds)
  1840. {
  1841. return pEntry->dwRedialSeconds;
  1842. }
  1843. else
  1844. {
  1845. return pUser->dwRedialSeconds;
  1846. }
  1847. }
  1848. case RASOR_IdleDisconnectSeconds:
  1849. {
  1850. if (pEntry->dwfOverridePref & RASOR_IdleDisconnectSeconds)
  1851. {
  1852. return (DWORD )pEntry->lIdleDisconnectSeconds;
  1853. }
  1854. else
  1855. {
  1856. return pUser->dwIdleDisconnectSeconds;
  1857. }
  1858. }
  1859. case RASOR_RedialOnLinkFailure:
  1860. {
  1861. if (pEntry->dwfOverridePref & RASOR_RedialOnLinkFailure)
  1862. {
  1863. return pEntry->fRedialOnLinkFailure;
  1864. }
  1865. else
  1866. {
  1867. return pUser->fRedialOnLinkFailure;
  1868. }
  1869. }
  1870. case RASOR_PopupOnTopWhenRedialing:
  1871. {
  1872. if (pEntry->dwfOverridePref & RASOR_PopupOnTopWhenRedialing)
  1873. {
  1874. #if 0
  1875. return pEntry->fPopupOnTopWhenRedialing;
  1876. #else
  1877. return (DWORD )TRUE;
  1878. #endif
  1879. }
  1880. else
  1881. {
  1882. return pUser->fPopupOnTopWhenRedialing;
  1883. }
  1884. }
  1885. case RASOR_CallbackMode:
  1886. {
  1887. if (pEntry->dwfOverridePref & RASOR_CallbackMode)
  1888. {
  1889. return pEntry->dwCallbackMode;
  1890. }
  1891. else
  1892. {
  1893. return pUser->dwCallbackMode;
  1894. }
  1895. }
  1896. }
  1897. return 0;
  1898. }
  1899. DWORD
  1900. PbkPathInfoInit(
  1901. IN PbkPathInfo* pInfo)
  1902. {
  1903. DWORD dwErr = NO_ERROR;
  1904. ZeroMemory(pInfo, sizeof(PbkPathInfo));
  1905. //Add try...except blocck for bug 763057
  1906. __try
  1907. {
  1908. InitializeCriticalSection(&(pInfo->csLock));
  1909. }
  1910. __except(EXCEPTION_EXECUTE_HANDLER)
  1911. {
  1912. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1913. }
  1914. return dwErr;
  1915. }
  1916. DWORD
  1917. PbkPathInfoReset(
  1918. OUT PbkPathInfo* pInfo)
  1919. {
  1920. if (pInfo)
  1921. {
  1922. if (pInfo->hSwapiDll)
  1923. {
  1924. FreeLibrary(pInfo->hSwapiDll);
  1925. }
  1926. Free0(pInfo->pszAllUsers);
  1927. Free0(pInfo->pszSysRas);
  1928. pInfo->fLoaded = FALSE;
  1929. pInfo->hSwapiDll = NULL;
  1930. pInfo->pPathCanonicalize = NULL;
  1931. pInfo->pPathRemoveFileSpec = NULL;
  1932. pInfo->pszAllUsers = NULL;
  1933. pInfo->pszSysRas = NULL;
  1934. }
  1935. return NO_ERROR;
  1936. }
  1937. DWORD
  1938. PbkPathInfoLoad(
  1939. OUT PbkPathInfo* pInfo)
  1940. {
  1941. DWORD dwErr = NO_ERROR;
  1942. BOOL fOk;
  1943. TCHAR* pszTemp = NULL;
  1944. EnterCriticalSection(&pInfo->csLock);
  1945. do
  1946. {
  1947. if (pInfo->fLoaded)
  1948. {
  1949. dwErr = NO_ERROR;
  1950. break;
  1951. }
  1952. pInfo->pszAllUsers = Malloc( (MAX_PATH + 1) * sizeof(TCHAR) );
  1953. pInfo->pszSysRas = Malloc( (MAX_PATH + 1) * sizeof(TCHAR) );
  1954. pszTemp = Malloc( (MAX_PATH + 1) * sizeof(TCHAR) );
  1955. if ((!pInfo->pszAllUsers) || (!pInfo->pszSysRas) || (!pszTemp))
  1956. {
  1957. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1958. break;
  1959. }
  1960. pInfo->hSwapiDll= LoadLibrary(TEXT("shlwapi.dll"));
  1961. if (pInfo->hSwapiDll == NULL)
  1962. {
  1963. dwErr = GetLastError();
  1964. break;
  1965. }
  1966. pInfo->pPathCanonicalize =
  1967. GetProcAddress(pInfo->hSwapiDll, SZ_PathCanonicalize);
  1968. pInfo->pPathRemoveFileSpec =
  1969. GetProcAddress(pInfo->hSwapiDll, SZ_PathRemoveFileSpec);
  1970. fOk = GetPhonebookDirectory(PBM_System, pszTemp);
  1971. if (!fOk)
  1972. {
  1973. dwErr = ERROR_CAN_NOT_COMPLETE;
  1974. break;
  1975. }
  1976. // Canonicalize the path and remove any trailing \
  1977. //
  1978. pInfo->pPathCanonicalize(pInfo->pszAllUsers, pszTemp);
  1979. if(TEXT('\\') == *(pInfo->pszAllUsers + lstrlen(pInfo->pszAllUsers) - 1))
  1980. {
  1981. *(pInfo->pszAllUsers + lstrlen(pInfo->pszAllUsers) - 1) = TEXT('\0');
  1982. }
  1983. fOk = GetSystemWindowsDirectory(
  1984. pInfo->pszSysRas,
  1985. MAX_PATH - S_SYSRASDIR_LENGTH);
  1986. if (!fOk)
  1987. {
  1988. dwErr = ERROR_CAN_NOT_COMPLETE;
  1989. break;
  1990. }
  1991. lstrcat(pInfo->pszSysRas, S_SYSRASDIR);
  1992. pInfo->fLoaded = TRUE;
  1993. } while (FALSE);
  1994. // Cleanup
  1995. //
  1996. {
  1997. if (dwErr != NO_ERROR)
  1998. {
  1999. PbkPathInfoReset(pInfo);
  2000. }
  2001. Free0(pszTemp);
  2002. }
  2003. LeaveCriticalSection(&pInfo->csLock);
  2004. return dwErr;
  2005. }
  2006. DWORD
  2007. PbkPathInfoClear(
  2008. OUT PbkPathInfo* pInfo)
  2009. {
  2010. PbkPathInfoReset(pInfo);
  2011. DeleteCriticalSection(&(pInfo->csLock));
  2012. ZeroMemory(pInfo, sizeof(PbkPathInfo));
  2013. return NO_ERROR;
  2014. }
  2015. BOOL
  2016. IsPublicPhonebook(
  2017. IN LPCTSTR pszPhonebookPath )
  2018. // Returns TRUE if the given phonebook is in the 'All Users' directory
  2019. // and hence is a shared phonebook; returns FALSE otherwise
  2020. //
  2021. {
  2022. BOOL bPublic = FALSE;
  2023. TCHAR* pszPhonebook = NULL;
  2024. DWORD dwErr = NO_ERROR;
  2025. do
  2026. {
  2027. pszPhonebook = Malloc( (MAX_PATH + 1) * sizeof(TCHAR) );
  2028. if ( !pszPhonebook )
  2029. {
  2030. break;
  2031. }
  2032. dwErr = PbkPathInfoLoad(&g_PbkPathInfo);
  2033. if (dwErr != NO_ERROR)
  2034. {
  2035. TRACE1(
  2036. "IsPublicPhonebook: Unable to load pbk path info %x",
  2037. dwErr);
  2038. break;
  2039. }
  2040. g_PbkPathInfo.pPathCanonicalize(pszPhonebook, pszPhonebookPath);
  2041. g_PbkPathInfo.pPathRemoveFileSpec(pszPhonebook);
  2042. if (!lstrcmpi(pszPhonebook, g_PbkPathInfo.pszAllUsers))
  2043. {
  2044. bPublic = TRUE;
  2045. }
  2046. else
  2047. {
  2048. bPublic = (lstrcmpi(pszPhonebook, g_PbkPathInfo.pszSysRas) == 0);
  2049. }
  2050. } while ( FALSE );
  2051. // Clean up
  2052. //
  2053. Free0 ( pszPhonebook );
  2054. TRACE1( "IsPublicPhonebook=%u", bPublic);
  2055. return bPublic;
  2056. }
  2057. DWORD
  2058. LoadPadsList(
  2059. OUT DTLLIST** ppdtllistPads )
  2060. // Build a list of all X.25 PAD devices in '*ppdtllistPads'.
  2061. //
  2062. // Returns 0 if successful, otherwise a non-zero error code. It is
  2063. // caller's responsibility to DtlDestroyList the list when done.
  2064. //
  2065. {
  2066. INT i;
  2067. DWORD dwErr;
  2068. RASMAN_DEVICE* pDevices;
  2069. DWORD dwDevices;
  2070. TRACE( "LoadPadsList" );
  2071. *ppdtllistPads = NULL;
  2072. dwErr = GetRasPads( &pDevices, &dwDevices );
  2073. if (dwErr != 0)
  2074. {
  2075. return dwErr;
  2076. }
  2077. *ppdtllistPads = DtlCreateList( 0L );
  2078. if (!*ppdtllistPads)
  2079. {
  2080. Free( pDevices );
  2081. return ERROR_NOT_ENOUGH_MEMORY;
  2082. }
  2083. qsort( (VOID* )pDevices, (size_t )dwDevices, sizeof(RASMAN_DEVICE),
  2084. CompareDevices );
  2085. for (i = 0; i < (INT )dwDevices; ++i)
  2086. {
  2087. TCHAR* pszDup;
  2088. pszDup = StrDupTFromA( pDevices[ i ].D_Name );
  2089. dwErr = AppendStringToList( *ppdtllistPads, pszDup );
  2090. Free0( pszDup );
  2091. if (dwErr != 0)
  2092. {
  2093. Free( pDevices );
  2094. DtlDestroyList( *ppdtllistPads, NULL );
  2095. *ppdtllistPads = NULL;
  2096. return dwErr;
  2097. }
  2098. }
  2099. Free( pDevices );
  2100. TRACE( "LoadPadsList=0" );
  2101. return 0;
  2102. }
  2103. DWORD
  2104. LoadPortsList(
  2105. OUT DTLLIST** ppdtllistPorts )
  2106. // Build a sorted list of all RAS ports in '*ppdtllistPorts'.
  2107. //
  2108. // Returns 0 if successful, otherwise a non-zero error code. It is
  2109. // caller's responsibility to DtlDestroyList the list when done.
  2110. //
  2111. {
  2112. return LoadPortsList2( NULL, ppdtllistPorts, FALSE );
  2113. }
  2114. DWORD
  2115. LoadPortsList2(
  2116. IN HANDLE hConnection,
  2117. OUT DTLLIST** ppdtllistPorts,
  2118. IN BOOL fRouter)
  2119. // Build a sorted list of all RAS ports in '*ppdtllistPorts'. 'FRouter'
  2120. // indicates only ports with "router" usage should be returned.
  2121. // Otherwise, only dialout ports are returned.
  2122. //
  2123. // Returns 0 if successful, otherwise a non-zero error code. It is
  2124. // caller's responsibility to DtlDestroyList the list when done.
  2125. //
  2126. {
  2127. INT i;
  2128. DWORD dwErr;
  2129. RASMAN_PORT* pPorts;
  2130. RASMAN_PORT* pPort;
  2131. DWORD dwPorts;
  2132. TRACE( "LoadPortsList2" );
  2133. *ppdtllistPorts = NULL;
  2134. dwErr = GetRasPorts( hConnection, &pPorts, &dwPorts );
  2135. if (dwErr != 0)
  2136. {
  2137. return dwErr;
  2138. }
  2139. *ppdtllistPorts = DtlCreateList( 0L );
  2140. if (!*ppdtllistPorts)
  2141. {
  2142. return ERROR_NOT_ENOUGH_MEMORY;
  2143. }
  2144. qsort( (VOID* )pPorts, (size_t )dwPorts, sizeof(RASMAN_PORT),
  2145. ComparePorts );
  2146. for (i = 0, pPort = pPorts; i < (INT )dwPorts; ++i, ++pPort)
  2147. {
  2148. if (fRouter)
  2149. {
  2150. // We're only interested in router ports.
  2151. //
  2152. //Add this CALL_OUTBOUND_ROUTER for bug 349087 345068
  2153. //
  2154. if (!(pPort->P_ConfiguredUsage & CALL_ROUTER) &&
  2155. !(pPort->P_ConfiguredUsage &CALL_OUTBOUND_ROUTER)
  2156. )
  2157. {
  2158. continue;
  2159. }
  2160. }
  2161. else
  2162. {
  2163. // We're only interested in ports you can dial-out on.
  2164. //
  2165. if (!(pPort->P_ConfiguredUsage & CALL_OUT))
  2166. {
  2167. continue;
  2168. }
  2169. }
  2170. dwErr = AppendPbportToList( hConnection, *ppdtllistPorts, pPort );
  2171. if (dwErr != 0)
  2172. {
  2173. Free( pPorts );
  2174. DtlDestroyList( *ppdtllistPorts, NULL );
  2175. *ppdtllistPorts = NULL;
  2176. return dwErr;
  2177. }
  2178. }
  2179. Free( pPorts );
  2180. TRACE( "LoadPortsList=0" );
  2181. return 0;
  2182. }
  2183. DWORD
  2184. LoadScriptsList(
  2185. HANDLE hConnection,
  2186. OUT DTLLIST** ppdtllistScripts )
  2187. // Build a sorted list of all RAS switch devices in '*ppdtllistPorts'.
  2188. //
  2189. // Returns 0 if successful, otherwise a non-zero error code. It is
  2190. // caller's responsibility to DtlDestroyList the list when done.
  2191. //
  2192. {
  2193. INT i;
  2194. DWORD dwErr;
  2195. RASMAN_DEVICE* pDevices;
  2196. DWORD dwDevices;
  2197. TRACE( "LoadScriptsList" );
  2198. *ppdtllistScripts = NULL;
  2199. dwErr = GetRasSwitches( hConnection, &pDevices, &dwDevices );
  2200. if (dwErr != 0)
  2201. {
  2202. return dwErr;
  2203. }
  2204. *ppdtllistScripts = DtlCreateList( 0L );
  2205. if (!*ppdtllistScripts)
  2206. {
  2207. Free( pDevices );
  2208. return ERROR_NOT_ENOUGH_MEMORY;
  2209. }
  2210. qsort( (VOID* )pDevices, (size_t )dwDevices, sizeof(RASMAN_DEVICE),
  2211. CompareDevices );
  2212. for (i = 0; i < (INT )dwDevices; ++i)
  2213. {
  2214. TCHAR* pszDup;
  2215. pszDup = StrDupTFromA( pDevices[ i ].D_Name );
  2216. if(NULL == pszDup)
  2217. {
  2218. return E_OUTOFMEMORY;
  2219. }
  2220. dwErr = AppendStringToList( *ppdtllistScripts, pszDup );
  2221. Free( pszDup );
  2222. if (dwErr != 0)
  2223. {
  2224. Free( pDevices );
  2225. DtlDestroyList( *ppdtllistScripts, NULL );
  2226. *ppdtllistScripts = NULL;
  2227. return dwErr;
  2228. }
  2229. }
  2230. Free( pDevices );
  2231. TRACE( "LoadScriptsList=0" );
  2232. return 0;
  2233. }
  2234. #if 0
  2235. TCHAR*
  2236. NameFromIndex(
  2237. IN DTLLIST* pdtllist,
  2238. IN INT iToFind )
  2239. // Returns the name associated with 0-based index 'iToFind' in the linked
  2240. // list of strings, 'pdtllist', or NULL if not found.
  2241. //
  2242. {
  2243. DTLNODE* pdtlnode;
  2244. if (!pdtllist)
  2245. {
  2246. return NULL;
  2247. }
  2248. pdtlnode = DtlGetFirstNode( pdtllist );
  2249. if (iToFind < 0)
  2250. {
  2251. return NULL;
  2252. }
  2253. while (pdtlnode && iToFind--)
  2254. {
  2255. pdtlnode = DtlGetNextNode( pdtlnode );
  2256. }
  2257. return (pdtlnode) ? (TCHAR* )DtlGetData( pdtlnode ) : NULL;
  2258. }
  2259. #endif
  2260. PBDEVICETYPE
  2261. PbdevicetypeFromPszType(
  2262. IN TCHAR* pszDeviceType )
  2263. // Returns the device type corresponding to the device type string,
  2264. // 'pszDeviceType'.
  2265. //
  2266. {
  2267. CHAR* pszA;
  2268. PBDEVICETYPE pbdt;
  2269. pbdt = PBDT_None;
  2270. pszA = StrDupAFromT( pszDeviceType );
  2271. if (pszA)
  2272. {
  2273. pbdt = PbdevicetypeFromPszTypeA( pszA );
  2274. Free( pszA );
  2275. }
  2276. return pbdt;
  2277. }
  2278. PBDEVICETYPE
  2279. PbdevicetypeFromPszTypeA(
  2280. IN CHAR* pszDeviceTypeA )
  2281. // Returns the device type corresponding to the ANSI device type string,
  2282. // 'pszDeviceType'.
  2283. //
  2284. {
  2285. PBDEVICETYPE pbdt;
  2286. TCHAR *pszDeviceType = StrDupTFromA(pszDeviceTypeA);
  2287. if(NULL == pszDeviceType)
  2288. {
  2289. return PBDT_None;
  2290. }
  2291. if( CSTR_EQUAL == CompareString(
  2292. LOCALE_INVARIANT,
  2293. NORM_IGNORECASE,
  2294. RASDT_Modem,
  2295. -1,
  2296. pszDeviceType,
  2297. -1
  2298. )
  2299. )
  2300. {
  2301. pbdt = PBDT_Modem;
  2302. }
  2303. else if( CSTR_EQUAL == CompareString(
  2304. LOCALE_INVARIANT,
  2305. NORM_IGNORECASE,
  2306. TEXT("null"),
  2307. -1,
  2308. pszDeviceType,
  2309. -1
  2310. )
  2311. )
  2312. {
  2313. pbdt = PBDT_Null;
  2314. }
  2315. else if( CSTR_EQUAL == CompareString(
  2316. LOCALE_INVARIANT,
  2317. NORM_IGNORECASE,
  2318. RASDT_Parallel,
  2319. -1,
  2320. pszDeviceType,
  2321. -1
  2322. )
  2323. )
  2324. {
  2325. pbdt = PBDT_Parallel;
  2326. }
  2327. else if( CSTR_EQUAL == CompareString(
  2328. LOCALE_INVARIANT,
  2329. NORM_IGNORECASE,
  2330. RASDT_Irda,
  2331. -1,
  2332. pszDeviceType,
  2333. -1
  2334. )
  2335. )
  2336. {
  2337. pbdt = PBDT_Irda;
  2338. }
  2339. else if( CSTR_EQUAL == CompareString(
  2340. LOCALE_INVARIANT,
  2341. NORM_IGNORECASE,
  2342. RASDT_Pad,
  2343. -1,
  2344. pszDeviceType,
  2345. -1
  2346. )
  2347. )
  2348. {
  2349. pbdt = PBDT_Pad;
  2350. }
  2351. else if( CSTR_EQUAL == CompareString(
  2352. LOCALE_INVARIANT,
  2353. NORM_IGNORECASE,
  2354. TEXT("switch"),
  2355. -1,
  2356. pszDeviceType,
  2357. -1
  2358. )
  2359. )
  2360. {
  2361. pbdt = PBDT_Switch;
  2362. }
  2363. else if( CSTR_EQUAL == CompareString(
  2364. LOCALE_INVARIANT,
  2365. NORM_IGNORECASE,
  2366. RASDT_Isdn,
  2367. -1,
  2368. pszDeviceType,
  2369. -1
  2370. )
  2371. )
  2372. {
  2373. pbdt = PBDT_Isdn;
  2374. }
  2375. else if( CSTR_EQUAL == CompareString(
  2376. LOCALE_INVARIANT,
  2377. NORM_IGNORECASE,
  2378. RASDT_X25,
  2379. -1,
  2380. pszDeviceType,
  2381. -1
  2382. )
  2383. )
  2384. {
  2385. pbdt = PBDT_X25;
  2386. }
  2387. else if( CSTR_EQUAL == CompareString(
  2388. LOCALE_INVARIANT,
  2389. NORM_IGNORECASE,
  2390. RASDT_Vpn,
  2391. -1,
  2392. pszDeviceType,
  2393. -1
  2394. )
  2395. )
  2396. {
  2397. pbdt = PBDT_Vpn;
  2398. }
  2399. else if( CSTR_EQUAL == CompareString(
  2400. LOCALE_INVARIANT,
  2401. NORM_IGNORECASE,
  2402. RASDT_Atm,
  2403. -1,
  2404. pszDeviceType,
  2405. -1
  2406. )
  2407. )
  2408. {
  2409. pbdt = PBDT_Atm;
  2410. }
  2411. else if( CSTR_EQUAL == CompareString(
  2412. LOCALE_INVARIANT,
  2413. NORM_IGNORECASE,
  2414. RASDT_Serial,
  2415. -1,
  2416. pszDeviceType,
  2417. -1
  2418. )
  2419. )
  2420. {
  2421. pbdt = PBDT_Serial;
  2422. }
  2423. else if( CSTR_EQUAL == CompareString(
  2424. LOCALE_INVARIANT,
  2425. NORM_IGNORECASE,
  2426. RASDT_FrameRelay,
  2427. -1,
  2428. pszDeviceType,
  2429. -1
  2430. )
  2431. )
  2432. {
  2433. pbdt = PBDT_FrameRelay;
  2434. }
  2435. else if( CSTR_EQUAL == CompareString(
  2436. LOCALE_INVARIANT,
  2437. NORM_IGNORECASE,
  2438. RASDT_Sonet,
  2439. -1,
  2440. pszDeviceType,
  2441. -1
  2442. )
  2443. )
  2444. {
  2445. pbdt = PBDT_Sonet;
  2446. }
  2447. else if( CSTR_EQUAL == CompareString(
  2448. LOCALE_INVARIANT,
  2449. NORM_IGNORECASE,
  2450. RASDT_SW56,
  2451. -1,
  2452. pszDeviceType,
  2453. -1
  2454. )
  2455. )
  2456. {
  2457. pbdt = PBDT_Sw56;
  2458. }
  2459. else if( CSTR_EQUAL == CompareString(
  2460. LOCALE_INVARIANT,
  2461. NORM_IGNORECASE,
  2462. RASDT_PPPoE,
  2463. -1,
  2464. pszDeviceType,
  2465. -1
  2466. )
  2467. )
  2468. {
  2469. pbdt = PBDT_PPPoE;
  2470. }
  2471. else
  2472. {
  2473. pbdt = PBDT_Other;
  2474. }
  2475. if(pszDeviceType)
  2476. {
  2477. Free(pszDeviceType);
  2478. }
  2479. return pbdt;
  2480. }
  2481. CHAR*
  2482. PbMedia(
  2483. IN PBDEVICETYPE pbdt,
  2484. IN CHAR* pszMedia )
  2485. // The media names stored in the phonebook are not exactly the same as
  2486. // those returned by RASMAN. This translates a RASMAN media name to
  2487. // equivalent phonebook media names given the device type. The reason for
  2488. // this is historical and obscure.
  2489. //
  2490. {
  2491. if (pbdt == PBDT_Isdn)
  2492. {
  2493. return ISDN_TXT;
  2494. }
  2495. else if (pbdt == PBDT_X25)
  2496. {
  2497. return X25_TXT;
  2498. }
  2499. else if ( pbdt == PBDT_Other
  2500. || pbdt == PBDT_Vpn
  2501. || pbdt == PBDT_Irda
  2502. || pbdt == PBDT_Serial
  2503. || pbdt == PBDT_Atm
  2504. || pbdt == PBDT_Parallel
  2505. || pbdt == PBDT_Sonet
  2506. || pbdt == PBDT_Sw56
  2507. || pbdt == PBDT_FrameRelay
  2508. || pbdt == PBDT_PPPoE)
  2509. {
  2510. return pszMedia;
  2511. }
  2512. else
  2513. {
  2514. return SERIAL_TXT;
  2515. }
  2516. }
  2517. PBPORT*
  2518. PpbportFromPortAndDeviceName(
  2519. IN DTLLIST* pdtllistPorts,
  2520. IN TCHAR* pszPort,
  2521. IN TCHAR* pszDevice )
  2522. // Return port with port name 'pszPort' and device name 'pszDevice' in
  2523. // list of ports 'pdtllistPorts' or NULL if not found. 'PszPort' may be
  2524. // an old-style name such as PcImacISDN1, in which case it will match
  2525. // ISDN1. 'PszDevice' may be NULL in which case any device name is
  2526. // assumed to match.
  2527. //
  2528. {
  2529. DTLNODE* pdtlnode;
  2530. TCHAR szPort[MAX_PORT_NAME+1];
  2531. if (!pszPort)
  2532. {
  2533. return NULL;
  2534. }
  2535. for (pdtlnode = DtlGetFirstNode( pdtllistPorts );
  2536. pdtlnode;
  2537. pdtlnode = DtlGetNextNode( pdtlnode ))
  2538. {
  2539. PBPORT* ppbport = (PBPORT* )DtlGetData( pdtlnode );
  2540. if ((ppbport->pszPort && lstrcmp( ppbport->pszPort, pszPort ) == 0)
  2541. && (!ppbport->pszDevice || !pszDevice
  2542. || lstrcmp( ppbport->pszDevice, pszDevice ) == 0))
  2543. {
  2544. return ppbport;
  2545. }
  2546. }
  2547. // No match. Look for the old port name format.
  2548. //
  2549. for (pdtlnode = DtlGetFirstNode( pdtllistPorts );
  2550. pdtlnode;
  2551. pdtlnode = DtlGetNextNode( pdtlnode ))
  2552. {
  2553. TCHAR szBuf[ MAX_DEVICE_NAME + MAX_DEVICETYPE_NAME + 10 + 1 ];
  2554. PBPORT* ppbport;
  2555. ppbport = (PBPORT* )DtlGetData( pdtlnode );
  2556. // Skip modems (COM ports) and unconfigured ports, since they do not
  2557. // follow the same port name formatting rules as other ports.
  2558. //
  2559. if (!ppbport->pszDevice || ppbport->pbdevicetype == PBDT_Modem)
  2560. {
  2561. continue;
  2562. }
  2563. lstrcpy( szBuf, ppbport->pszDevice );
  2564. lstrcat( szBuf, ppbport->pszPort );
  2565. if (lstrcmp( szBuf, pszPort ) == 0)
  2566. {
  2567. return ppbport;
  2568. }
  2569. }
  2570. return NULL;
  2571. }
  2572. PBPORT*
  2573. PpbportFromNT4PortandDevice(
  2574. IN DTLLIST* pdtllistPorts,
  2575. IN TCHAR* pszPort,
  2576. IN TCHAR* pszDevice )
  2577. // This function is called when we couldn't
  2578. // find a port that matches the one in the
  2579. // phonebook. This will take care of the case
  2580. // where the port is pre-nt5 type of port. Since
  2581. // the portnames have changed in nt5 for isdn
  2582. // and vpn, this routine will try to find a
  2583. // port with the same type.
  2584. {
  2585. PBPORT *ppbport;
  2586. PBPORT *ppbportRet = NULL;
  2587. DTLNODE *pdtlnode;
  2588. TCHAR szPort[MAX_PORT_NAME+1];
  2589. if(NULL == pszPort)
  2590. {
  2591. return NULL;
  2592. }
  2593. ZeroMemory(szPort, sizeof(szPort));
  2594. lstrcpyn(szPort, pszPort, MAX_PORT_NAME);
  2595. szPort[lstrlen(TEXT("VPN"))] = TEXT('\0');
  2596. if(0 == lstrcmp(szPort, TEXT("VPN")))
  2597. {
  2598. for (pdtlnode = DtlGetFirstNode( pdtllistPorts );
  2599. pdtlnode;
  2600. pdtlnode = DtlGetNextNode( pdtlnode ))
  2601. {
  2602. ppbport = (PBPORT *) DtlGetData(pdtlnode);
  2603. if(PBDT_Vpn == ppbport->pbdevicetype)
  2604. {
  2605. ppbportRet = ppbport;
  2606. break;
  2607. }
  2608. }
  2609. return ppbportRet;
  2610. }
  2611. return NULL;
  2612. }
  2613. PBPORT*
  2614. PpbportFromNullModem(
  2615. IN DTLLIST* pdtllistPorts,
  2616. IN TCHAR* pszPort,
  2617. IN TCHAR* pszDevice )
  2618. //
  2619. // pmay: 226594
  2620. //
  2621. // Added this function because sometimes we just need to
  2622. // match a given port to a null modem
  2623. //
  2624. // Will attempt to match the ports, but returns any
  2625. // NULL modem it finds if it can't match ports.
  2626. //
  2627. {
  2628. DTLNODE* pdtlnode;
  2629. PBPORT * pRet = NULL;
  2630. for (pdtlnode = DtlGetFirstNode( pdtllistPorts );
  2631. pdtlnode;
  2632. pdtlnode = DtlGetNextNode( pdtlnode ))
  2633. {
  2634. PBPORT* ppbport = (PBPORT* )DtlGetData( pdtlnode );
  2635. if ((ppbport->dwFlags & PBP_F_NullModem) && (pRet == NULL))
  2636. {
  2637. pRet = ppbport;
  2638. }
  2639. if ((ppbport->pszPort) &&
  2640. (pszPort) &&
  2641. (lstrcmpi( ppbport->pszPort, pszPort ) == 0)
  2642. )
  2643. {
  2644. pRet = ppbport;
  2645. break;
  2646. }
  2647. }
  2648. return pRet;
  2649. }
  2650. BOOL
  2651. PbportTypeMatchesEntryType(
  2652. IN PBPORT * pPort,
  2653. IN PBENTRY* pEntry)
  2654. // Returns whether the given port has a type that's compatible
  2655. // with the type of the given entry.
  2656. {
  2657. if (!pPort || !pEntry)
  2658. {
  2659. return TRUE;
  2660. }
  2661. if ( ( pEntry->dwType == RASET_Phone ) )
  2662. {
  2663. if ( ( pPort->pbdevicetype == PBDT_Null ) ||
  2664. ( pPort->pbdevicetype == PBDT_Parallel ) ||
  2665. ( pPort->pbdevicetype == PBDT_Irda ) ||
  2666. ( pPort->dwFlags & PBP_F_NullModem ) ||
  2667. ( pPort->pbdevicetype == PBDT_Vpn ) ||
  2668. ( pPort->pbdevicetype == PBDT_PPPoE )
  2669. )
  2670. {
  2671. return FALSE;
  2672. }
  2673. }
  2674. return TRUE;
  2675. }
  2676. BOOL
  2677. SetDefaultModemSettings(
  2678. IN PBLINK* pLink )
  2679. // Set the MXS modem settings for link 'pLink' to the defaults.
  2680. //
  2681. // Returns true if something changed, false otherwise.
  2682. //
  2683. {
  2684. BOOL fChange;
  2685. fChange = FALSE;
  2686. if (pLink->fHwFlow != pLink->pbport.fHwFlowDefault)
  2687. {
  2688. fChange = TRUE;
  2689. pLink->fHwFlow = pLink->pbport.fHwFlowDefault;
  2690. }
  2691. if (pLink->fEc != pLink->pbport.fEcDefault)
  2692. {
  2693. fChange = TRUE;
  2694. pLink->fEc = pLink->pbport.fEcDefault;
  2695. }
  2696. if (pLink->fEcc != pLink->pbport.fEccDefault)
  2697. {
  2698. fChange = TRUE;
  2699. pLink->fEcc = pLink->pbport.fEccDefault;
  2700. }
  2701. if (pLink->fSpeaker != pLink->pbport.fSpeakerDefault)
  2702. {
  2703. fChange = TRUE;
  2704. pLink->fSpeaker = pLink->pbport.fSpeakerDefault;
  2705. }
  2706. if (pLink->dwBps != pLink->pbport.dwBpsDefault)
  2707. {
  2708. fChange = TRUE;
  2709. pLink->dwBps = pLink->pbport.dwBpsDefault;
  2710. }
  2711. // For whistler bug 402522 gangz
  2712. // Add preferred modem protocol
  2713. // pmay: 228565
  2714. // Add the default modem protocol
  2715. if (pLink->dwModemProtocol != pLink->pbport.dwModemProtDefault)
  2716. {
  2717. fChange = TRUE;
  2718. pLink->dwModemProtocol = pLink->pbport.dwModemProtDefault;
  2719. }
  2720. TRACE2( "SetDefaultModemSettings(bps=%d)=%d", pLink->dwBps, fChange );
  2721. return fChange;
  2722. }
  2723. BOOL
  2724. ValidateAreaCode(
  2725. IN OUT TCHAR* pszAreaCode )
  2726. // Checks that area code consists of decimal digits only. If the area
  2727. // code is all white characters it is reduced to empty string. Returns
  2728. // true if 'pszAreaCode' is a valid area code, false if not.
  2729. //
  2730. {
  2731. if (IsAllWhite( pszAreaCode ))
  2732. {
  2733. *pszAreaCode = TEXT('\0');
  2734. return TRUE;
  2735. }
  2736. if (lstrlen( pszAreaCode ) > RAS_MaxAreaCode)
  2737. {
  2738. return FALSE;
  2739. }
  2740. while (*pszAreaCode != TEXT('\0'))
  2741. {
  2742. if (*pszAreaCode < TEXT('0') || *pszAreaCode > TEXT('9'))
  2743. {
  2744. return FALSE;
  2745. }
  2746. ++pszAreaCode;
  2747. }
  2748. return TRUE;
  2749. }
  2750. BOOL
  2751. ValidateEntryName(
  2752. IN LPCTSTR pszEntry )
  2753. // Returns true if 'pszEntry' is a valid phonebook entry name, false if
  2754. // not.
  2755. //
  2756. {
  2757. INT nLen = lstrlen( pszEntry );
  2758. if (nLen <= 0
  2759. || nLen > RAS_MaxEntryName
  2760. || IsAllWhite( pszEntry )
  2761. || pszEntry[ 0 ] == TEXT('.'))
  2762. {
  2763. return FALSE;
  2764. }
  2765. return TRUE;
  2766. }