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.

1092 lines
33 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 2000
  5. //
  6. // File: N E T R A S . C P P
  7. //
  8. // Contents: Routines supporting RAS interoperability
  9. //
  10. // Notes:
  11. //
  12. // Author: billi 07 03 2001
  13. //
  14. // History:
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "Util.h"
  19. #include "TheApp.h"
  20. #include <lmjoin.h>
  21. #include <devguid.h>
  22. #include <tapi.h>
  23. #include <rasdlg.h>
  24. #include "NetUtil.h"
  25. #include "NetRas.h"
  26. #include "NetIp.h"
  27. // PPPoE driver returns the MAC addresses appended to call info from lineGetCallInfo
  28. // for caller and called station id's
  29. // we set their size as 6 ( a MAC address occupies 6 bytes )
  30. #define TAPI_STATION_ID_SIZE ( 6 * sizeof( CHAR ) )
  31. // PPPoE driver returns address string appended to address caps from lineGetAddressCaps
  32. #define PPPOE_LINE_ADDR_STRING L"PPPoE VPN"
  33. #define PPTP_LINE_ADDR_STRING L"PPTP VPN"
  34. HRESULT HrRasGetEntryProperties(
  35. INetRasConnection* pRas,
  36. LPRASENTRY* lplpRasEntry,
  37. LPDWORD lpdwEntryInfoSize )
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Function: HrRasGetEntryProperties
  41. //
  42. // Purpose:
  43. //
  44. // Arguments: INetConnection* pRas
  45. // LPRASENTRY lpRasEntry,
  46. // LPDWORD lpdwEntryInfoSize
  47. //
  48. // Returns: HRESULT
  49. //
  50. // Author: billi 07/02/01
  51. //
  52. // Notes:
  53. //
  54. {
  55. ASSERT( pRas );
  56. ASSERT( lplpRasEntry );
  57. ASSERT( lpdwEntryInfoSize );
  58. HRESULT hr;
  59. RASCON_INFO rcInfo;
  60. *lplpRasEntry = NULL;
  61. *lpdwEntryInfoSize = 0L;
  62. hr = pRas->GetRasConnectionInfo( &rcInfo );
  63. if ( SUCCEEDED(hr) )
  64. {
  65. DWORD dwSize = sizeof(RASENTRY);
  66. hr = E_FAIL;
  67. for ( DWORD i=0; i<2; i++ )
  68. {
  69. LPRASENTRY lpEntry = (LPRASENTRY) new BYTE[ dwSize ];
  70. if ( NULL != lpEntry )
  71. {
  72. lpEntry->dwSize = dwSize;
  73. DWORD dwErr = RasGetEntryProperties( rcInfo.pszwPbkFile,
  74. rcInfo.pszwEntryName,
  75. lpEntry,
  76. &dwSize,
  77. NULL,
  78. 0 );
  79. if ( ERROR_SUCCESS == dwErr )
  80. {
  81. #if (WINVER >= 0x500)
  82. ASSERT( RASET_Vpn == (*lplpRasEntry)->dwType );
  83. ASSERT( rcInfo.guidId == (*lplpRasEntry)->guidId );
  84. #endif
  85. *lplpRasEntry = lpEntry;
  86. *lpdwEntryInfoSize = dwSize;
  87. hr = S_OK;
  88. break;
  89. }
  90. else
  91. {
  92. TraceMsg(TF_ERROR, "\tRasGetEntryProperties Failed = %lx Size = %ul", dwErr, *lpdwEntryInfoSize );
  93. delete [] (PBYTE)(lpEntry);
  94. }
  95. }
  96. else
  97. {
  98. hr = E_OUTOFMEMORY;
  99. TraceMsg(TF_ERROR, "\tnew Failed!" );
  100. break;
  101. }
  102. }
  103. CoTaskMemFree( rcInfo.pszwPbkFile );
  104. CoTaskMemFree( rcInfo.pszwEntryName );
  105. }
  106. else
  107. {
  108. TraceMsg(TF_ERROR, "\tGetRasConnectionInfo Failed!" );
  109. }
  110. TraceMsg(TF_ALWAYS, "HrRasGetEntryProperties = %lx", hr);
  111. return hr;
  112. }
  113. HRESULT HrCheckVPNForRoute(
  114. INetConnection* pPrivate,
  115. INetRasConnection* pShared,
  116. NETCON_PROPERTIES* pProps,
  117. BOOL* pfAssociated )
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Function: HrCheckVPNForRoute
  121. //
  122. // Purpose:
  123. //
  124. // Arguments: INetConnection* pPrivate
  125. // INetConnection* pShared
  126. // NETCON_PROPERTIES* pProps
  127. // BOOL* pfAssociated
  128. //
  129. // Returns: HRESULT
  130. //
  131. // Author: billi 26/01/01
  132. //
  133. // Notes:
  134. //
  135. {
  136. HRESULT hr;
  137. LPRASENTRY lpRasEntry = NULL;
  138. DWORD dwEntryInfoSize = 0;
  139. ASSERT( pPrivate );
  140. ASSERT( pShared );
  141. ASSERT( pProps );
  142. ASSERT( pfAssociated );
  143. *pfAssociated = FALSE;
  144. hr = HrRasGetEntryProperties( pShared, &lpRasEntry, &dwEntryInfoSize );
  145. if ( SUCCEEDED(hr) )
  146. {
  147. int WsaErr = ERROR_SUCCESS;
  148. WSADATA WsaData;
  149. WsaErr = WSAStartup( MAKEWORD(2, 0), &WsaData );
  150. if ( ERROR_SUCCESS == WsaErr )
  151. {
  152. PHOSTENT pHostEnt = NULL;
  153. IPAddr IpAddress = INADDR_NONE;
  154. #ifdef DBG // checked build
  155. if ( NCS_DISCONNECTED == pProps->Status )
  156. {
  157. TraceMsg(TF_ALWAYS, "VPN = DISCONNECTED");
  158. }
  159. else if ( NCS_CONNECTED == pProps->Status )
  160. {
  161. TraceMsg(TF_ALWAYS, "VPN = CONNECTED");
  162. }
  163. #endif
  164. hr = HrGetHostIpList( (char*)lpRasEntry->szLocalPhoneNumber, &IpAddress, &pHostEnt );
  165. if ( SUCCEEDED(hr) )
  166. {
  167. hr = HrCheckListForMatch( pPrivate, IpAddress, pHostEnt, pfAssociated );
  168. }
  169. WSACleanup();
  170. }
  171. else
  172. {
  173. TraceMsg(TF_ERROR, "WSAStartup Failed = %lu", WsaErr );
  174. hr = E_FAIL;
  175. }
  176. delete lpRasEntry;
  177. }
  178. TraceMsg(TF_ALWAYS, "HrCheckVPNForRoute = %lx", hr);
  179. return hr;
  180. }
  181. HRESULT HrRasDialDlg( INetRasConnection* pRas )
  182. //+---------------------------------------------------------------------------
  183. //
  184. // Function: HrRasDialDlg
  185. //
  186. // Purpose:
  187. //
  188. // Arguments: INetConnection* pRas
  189. //
  190. // Returns: HRESULT
  191. //
  192. // Author: billi 26/01/01
  193. //
  194. // Notes:
  195. //
  196. {
  197. ASSERT( pRas );
  198. HRESULT hr;
  199. RASCON_INFO rcInfo;
  200. hr = pRas->GetRasConnectionInfo( &rcInfo );
  201. if ( SUCCEEDED(hr) )
  202. {
  203. RASDIALDLG Info;
  204. ZeroMemory( &Info, sizeof(Info) );
  205. Info.dwSize = sizeof (RASDIALDLG);
  206. //billi 3/19/01 we don't set this flag as per #342832 by SethH
  207. // Info.dwFlags |= RASDDFLAG_LinkFailure; // "reconnect pending" countdown
  208. TraceMsg(TF_ALWAYS, "Pbk : %s", rcInfo.pszwPbkFile);
  209. TraceMsg(TF_ALWAYS, "Entry: %s", rcInfo.pszwEntryName);
  210. SetLastError( ERROR_SUCCESS );
  211. if ( RasDialDlg( rcInfo.pszwPbkFile,
  212. rcInfo.pszwEntryName,
  213. NULL,
  214. &Info ) )
  215. {
  216. hr = S_OK;
  217. }
  218. else
  219. {
  220. hr = HrFromLastWin32Error();
  221. if ( ERROR_SUCCESS == Info.dwError )
  222. {
  223. TraceMsg(TF_ALWAYS, "RasDialDlg Cancelled by User!");
  224. hr = E_FAIL;
  225. }
  226. else
  227. {
  228. TraceMsg(TF_ERROR, "RasDialDlg Failed! = %lx", Info.dwError );
  229. }
  230. }
  231. CoTaskMemFree( rcInfo.pszwPbkFile );
  232. CoTaskMemFree( rcInfo.pszwEntryName );
  233. }
  234. TraceMsg(TF_ALWAYS, "HrRasDialDlg = %lx", hr);
  235. return hr;
  236. }
  237. VOID CALLBACK
  238. RasTapiCallback(
  239. DWORD hDevice,
  240. DWORD dwMessage,
  241. DWORD_PTR dwInstance,
  242. DWORD_PTR dwParam1,
  243. DWORD_PTR dwParam2,
  244. DWORD_PTR dwParam3 )
  245. //+---------------------------------------------------------------------------
  246. //
  247. // Function: RasTapiCallback
  248. //
  249. // Purpose: a callback function that is invoked to determine status and events on
  250. // the line device, addresses, or calls, when the application is using
  251. // the "hidden window" method of event notification
  252. //
  253. // Arguments: hDevice A handle to either a line device or a call associated
  254. // with the callback. The nature of this handle (line
  255. // handle or call handle) can be determined by the context
  256. // provided by dwMsg. Applications must use the DWORD type
  257. // for this parameter because using the HANDLE type may
  258. // generate an error.
  259. // dwMessage A line or call device message.
  260. // dwCallbackInstance Callback instance data passed back to the application
  261. // in the callback. This DWORD is not interpreted by TAPI.
  262. // dwParam1 A parameter for the message.
  263. // dwParam2 A parameter for the message.
  264. // dwParam3 A parameter for the message.
  265. //
  266. // Returns: VOID
  267. //
  268. // Author: billi 15/02/01
  269. //
  270. // Notes:
  271. //
  272. {
  273. TraceMsg(TF_ALWAYS, "RasTapiCallback");
  274. TraceMsg(TF_ALWAYS, "\t%lx, %lx, %lx, %lx, %lx, %lx", hDevice, dwMessage, dwInstance, dwParam1, dwParam2, dwParam3);
  275. return;
  276. }
  277. //+---------------------------------------------------------------------------
  278. //
  279. // Function: HrLineInitialize
  280. //
  281. // Purpose:
  282. //
  283. // Arguments: HLINEAPP* phRasLine
  284. // DWORD* pdwLines
  285. //
  286. // Returns: HRESULT
  287. //
  288. // Author: billi 22/02/01
  289. //
  290. // Notes:
  291. //
  292. HRESULT HrLineInitialize(
  293. HLINEAPP* phRasLine,
  294. DWORD* pdwLines
  295. )
  296. {
  297. HRESULT hr = E_FAIL;
  298. DWORD dwVersion = HIGH_VERSION;
  299. LONG lError;
  300. LINEINITIALIZEEXPARAMS param;
  301. ASSERT( phRasLine );
  302. ASSERT( pdwLines );
  303. *phRasLine = 0;
  304. *pdwLines = 0;
  305. memset( &param, 0, sizeof (LINEINITIALIZEEXPARAMS) ) ;
  306. param.dwOptions = LINEINITIALIZEEXOPTION_USEHIDDENWINDOW ;
  307. param.dwTotalSize = sizeof(param) ;
  308. // lineInitialize
  309. //TODO: Place application name in resource (for localization ) and make
  310. // sure application name string is used throughout!
  311. lError = lineInitializeEx( phRasLine,
  312. g_hinst,
  313. (LINECALLBACK) RasTapiCallback,
  314. WIZARDNAME,
  315. pdwLines,
  316. &dwVersion,
  317. &param );
  318. TraceMsg(TF_GENERAL, "lineInitializeEx( %lx,", phRasLine );
  319. TraceMsg(TF_GENERAL, " %lx,", g_hinst );
  320. TraceMsg(TF_GENERAL, " %lx,", RasTapiCallback );
  321. TraceMsg(TF_GENERAL, " %s,", WIZARDNAME );
  322. TraceMsg(TF_GENERAL, " %lx = %lx,", pdwLines, *pdwLines );
  323. TraceMsg(TF_GENERAL, " %lx = %lx,", &dwVersion, dwVersion );
  324. TraceMsg(TF_GENERAL, " %lx", &param );
  325. TraceMsg(TF_GENERAL, " ) = %lx", lError );
  326. if ( ERROR_SUCCESS == lError )
  327. {
  328. hr = S_OK;
  329. }
  330. TraceMsg(TF_ALWAYS, "HrLineInitialize = %lx", hr);
  331. return hr;
  332. }
  333. HRESULT HrLineOpen(
  334. HLINEAPP hRasLine,
  335. DWORD dwLine,
  336. HLINE* phLine,
  337. DWORD* pdwApiVersion,
  338. DWORD* pdwExtVersion,
  339. LPWSTR* ppszwLineAddress
  340. )
  341. //+---------------------------------------------------------------------------
  342. //
  343. // Function: HrLineOpen
  344. //
  345. // Purpose:
  346. //
  347. // Arguments: HLINEAPP hRasLine
  348. // DWORD dwLine
  349. // HLINE* phLine
  350. // DWORD* pdwApiVersion
  351. // DWORD* pdwExtVersion
  352. // LPWSTR* ppszwLineAddress
  353. //
  354. // Returns: HRESULT
  355. //
  356. // Author: billi 22/02/01
  357. //
  358. // Notes:
  359. //
  360. {
  361. HRESULT hr;
  362. LONG lError;
  363. LINEEXTENSIONID extensionid;
  364. ASSERT(phLine);
  365. ASSERT(pdwApiVersion);
  366. ASSERT(pdwExtVersion);
  367. ASSERT(ppszwLineAddress);
  368. hr = E_FAIL;
  369. *phLine = 0;
  370. *pdwApiVersion = 0;
  371. *pdwExtVersion = 0;
  372. *ppszwLineAddress = NULL;
  373. lError = lineNegotiateAPIVersion( hRasLine,
  374. dwLine,
  375. LOW_VERSION,
  376. HIGH_VERSION,
  377. pdwApiVersion,
  378. &extensionid );
  379. TraceMsg(TF_GENERAL, "lineNegotiateAPIVersion( %lx,", hRasLine);
  380. TraceMsg(TF_GENERAL, " %lx,", dwLine);
  381. TraceMsg(TF_GENERAL, " %lx,", LOW_VERSION);
  382. TraceMsg(TF_GENERAL, " %lx,", HIGH_VERSION);
  383. TraceMsg(TF_GENERAL, " %lx = %lx,", pdwApiVersion, *pdwApiVersion);
  384. TraceMsg(TF_GENERAL, " %lx = %lx", &extensionid, extensionid);
  385. TraceMsg(TF_GENERAL, " ) = %lx", lError);
  386. if ( ERROR_SUCCESS == lError )
  387. {
  388. LINECALLPARAMS lineparams;
  389. lError = lineOpen( hRasLine, dwLine, phLine,
  390. *pdwApiVersion,
  391. *pdwExtVersion, 0,
  392. LINECALLPRIVILEGE_NONE,
  393. LINEMEDIAMODE_DIGITALDATA,
  394. &lineparams );
  395. TraceMsg(TF_GENERAL, "lineOpen( %lx,", hRasLine);
  396. TraceMsg(TF_GENERAL, " %lx,", dwLine);
  397. TraceMsg(TF_GENERAL, " %lx = %lx,", phLine, *phLine);
  398. TraceMsg(TF_GENERAL, " %lx,", *pdwApiVersion);
  399. TraceMsg(TF_GENERAL, " %lx,", *pdwExtVersion);
  400. TraceMsg(TF_GENERAL, " %lx,", 0);
  401. TraceMsg(TF_GENERAL, " %lx,", LINECALLPRIVILEGE_NONE);
  402. TraceMsg(TF_GENERAL, " %lx,", LINEMEDIAMODE_DIGITALDATA);
  403. TraceMsg(TF_GENERAL, " %lx", &lineparams);
  404. TraceMsg(TF_GENERAL, " ) = %lx", lError);
  405. if ( ERROR_SUCCESS == lError )
  406. {
  407. DWORD dwSize = 1024;
  408. for ( int i=0; (i<2)&&(E_FAIL==hr); i++ )
  409. {
  410. BYTE* Buffer = new BYTE[ dwSize ];
  411. if ( NULL != Buffer )
  412. {
  413. LPLINEADDRESSCAPS lpCaps = (LPLINEADDRESSCAPS)Buffer;
  414. lpCaps->dwTotalSize = dwSize * sizeof(BYTE);
  415. lError = lineGetAddressCaps( hRasLine, dwLine, 0,
  416. *pdwApiVersion,
  417. *pdwExtVersion,
  418. lpCaps );
  419. if ( ERROR_SUCCESS == lError )
  420. {
  421. TraceMsg(TF_GENERAL, "\tdwTotalSize = %lx", lpCaps->dwTotalSize);
  422. TraceMsg(TF_GENERAL, "\tdwNeededSize = %lx", lpCaps->dwNeededSize);
  423. TraceMsg(TF_GENERAL, "\tdwUsedSize = %lx", lpCaps->dwUsedSize);
  424. TraceMsg(TF_GENERAL, "\tdwAddressSize = %lx", lpCaps->dwAddressSize);
  425. TraceMsg(TF_GENERAL, "\tdwAddressOffset = %lx", lpCaps->dwAddressOffset);
  426. if ( ( 0 < lpCaps->dwAddressOffset ) &&
  427. ( 0 < lpCaps->dwAddressSize ) )
  428. {
  429. LPWSTR lpsz = (LPWSTR)((CHAR*)lpCaps + lpCaps->dwAddressOffset);
  430. if ( lpsz )
  431. {
  432. LPWSTR lpBuf = new WCHAR[ lpCaps->dwAddressSize / sizeof(WCHAR) + 1 ];
  433. if ( NULL != lpBuf )
  434. {
  435. memcpy( lpBuf, lpsz, lpCaps->dwAddressSize );
  436. lpBuf[ lpCaps->dwAddressSize / sizeof(WCHAR) ] = 0;
  437. *ppszwLineAddress = lpBuf;
  438. TraceMsg(TF_ALWAYS, "\tdwAddress = %s", lpBuf);
  439. }
  440. }
  441. }
  442. hr = S_OK;
  443. }
  444. else if ( LINEERR_STRUCTURETOOSMALL == lError )
  445. {
  446. dwSize = lpCaps->dwNeededSize;
  447. }
  448. else
  449. {
  450. i = 2; // drop out of for loop
  451. }
  452. delete [] Buffer;
  453. }
  454. else
  455. {
  456. hr = E_OUTOFMEMORY;
  457. }
  458. } // for ( int i=0; i<2; i++ )
  459. if ( FAILED(hr) )
  460. {
  461. lineClose( *phLine );
  462. *phLine = 0;
  463. }
  464. } // if ( ERROR_SUCCESS == lError )
  465. } // if ( ERROR_SUCCESS == lError )
  466. TraceMsg(TF_ALWAYS, "HrLineOpen = %lx", hr);
  467. return hr;
  468. }
  469. HRESULT HrGetCallList(
  470. HLINE hLine,
  471. DWORD* pdwNumber,
  472. HCALL** ppList
  473. )
  474. //+---------------------------------------------------------------------------
  475. //
  476. // Function: HrGetCallList
  477. //
  478. // Purpose:
  479. //
  480. // Arguments: HLINE hLine
  481. // DWORD* pdwNumber
  482. // HCALL** ppList
  483. //
  484. // Returns: HRESULT
  485. //
  486. // Author: billi 22/02/01
  487. //
  488. // Notes:
  489. //
  490. {
  491. HRESULT hr = E_FAIL;
  492. DWORD dwSize = 1024;
  493. ASSERT( ppList );
  494. ASSERT( pdwNumber );
  495. *ppList = NULL;
  496. *pdwNumber = 0;
  497. for ( int i=0; (i<2)&&(E_FAIL==hr); i++ )
  498. {
  499. BYTE* Buffer = new BYTE[ dwSize ];
  500. if ( NULL != Buffer )
  501. {
  502. LONG lError;
  503. LPLINECALLLIST lpList = (LPLINECALLLIST)Buffer;
  504. ZeroMemory( lpList, dwSize*sizeof(BYTE) );
  505. lpList->dwTotalSize = dwSize * sizeof(BYTE);
  506. lError = lineGetNewCalls( hLine, 0, LINECALLSELECT_LINE, lpList );
  507. TraceMsg(TF_GENERAL, "lineGetNewCalls( %lx,", hLine);
  508. TraceMsg(TF_GENERAL, " %lx,", 0);
  509. TraceMsg(TF_GENERAL, " %lx,", LINECALLSELECT_LINE);
  510. TraceMsg(TF_GENERAL, " %lx,", lpList);
  511. TraceMsg(TF_GENERAL, " ) = %lx", lError);
  512. if ( ERROR_SUCCESS == lError )
  513. {
  514. DWORD dwNumber;
  515. TraceMsg(TF_GENERAL, "\tdwTotalSize = %lx", lpList->dwTotalSize);
  516. TraceMsg(TF_GENERAL, "\tdwNeededSize = %lx", lpList->dwNeededSize);
  517. TraceMsg(TF_GENERAL, "\tdwUsedSize = %lx", lpList->dwUsedSize);
  518. TraceMsg(TF_GENERAL, "\tdwCallsNumEntries = %lx", lpList->dwCallsNumEntries);
  519. TraceMsg(TF_GENERAL, "\tdwCallsSize = %lx", lpList->dwCallsSize);
  520. TraceMsg(TF_GENERAL, "\tdwCallsOffset = %lx", lpList->dwCallsOffset);
  521. dwNumber = lpList->dwCallsNumEntries;
  522. ASSERT(dwNumber);
  523. if ( 0 < dwNumber )
  524. {
  525. HCALL *pCalls = new HCALL[ dwNumber ];
  526. if ( NULL != pCalls )
  527. {
  528. memcpy( pCalls, (Buffer + lpList->dwCallsOffset), dwNumber*sizeof(HCALL) );
  529. *pdwNumber = dwNumber;
  530. *ppList = pCalls;
  531. hr = S_OK;
  532. }
  533. else
  534. {
  535. hr = E_OUTOFMEMORY;
  536. }
  537. }
  538. else
  539. {
  540. hr = E_UNEXPECTED;
  541. }
  542. }
  543. else if ( LINEERR_STRUCTURETOOSMALL == lError )
  544. {
  545. dwSize = lpList->dwNeededSize;
  546. }
  547. else
  548. {
  549. i = 2; // break out of for loop
  550. }
  551. delete [] Buffer;
  552. } // if ( NULL != Buffer )
  553. else
  554. {
  555. hr = E_OUTOFMEMORY;
  556. break;
  557. }
  558. } // for ( int i=0; i<2; i++ )
  559. TraceMsg(TF_ALWAYS, "HrGetCallList = %lx", hr);
  560. return hr;
  561. }
  562. HRESULT HrGetSourceMacAddr( HCALL hCall, BYTE** ppMacAddress )
  563. //+---------------------------------------------------------------------------
  564. //
  565. // Function: HrGetSourceMacAddr
  566. //
  567. // Purpose:
  568. //
  569. // Arguments: HCALL hCall
  570. //
  571. // Returns: HRESULT
  572. //
  573. // Author: billi 22/02/01
  574. //
  575. // Notes:
  576. //
  577. {
  578. HRESULT hr = E_FAIL;
  579. DWORD dwSize = sizeof(LINECALLINFO) + 3*TAPI_STATION_ID_SIZE;
  580. ASSERT( ppMacAddress );
  581. *ppMacAddress = NULL;
  582. for ( int i=0; (i<2)&&(E_FAIL==hr); i++ )
  583. {
  584. BYTE* Buffer = new BYTE[ dwSize ];
  585. if ( NULL != Buffer )
  586. {
  587. LONG lError;
  588. LPLINECALLINFO lpInfo = (LPLINECALLINFO)Buffer;
  589. ZeroMemory( lpInfo, dwSize*sizeof(BYTE) );
  590. lpInfo->dwTotalSize = dwSize * sizeof(BYTE);
  591. lError = lineGetCallInfo( hCall, lpInfo );
  592. TraceMsg(TF_ALWAYS, "lineGetCallInfo( %lx, %lx ) = %lx", hCall, lpInfo, lError);
  593. if ( ERROR_SUCCESS == lError )
  594. {
  595. TraceMsg(TF_ALWAYS, "\tdwTotalSize = %lx", lpInfo->dwTotalSize);
  596. TraceMsg(TF_ALWAYS, "\tdwNeededSize = %lx", lpInfo->dwNeededSize);
  597. TraceMsg(TF_ALWAYS, "\tdwUsedSize = %lx", lpInfo->dwUsedSize);
  598. TraceMsg(TF_ALWAYS, "\tdwCallerIDFlags = %lx", lpInfo->dwCallerIDFlags);
  599. TraceMsg(TF_ALWAYS, "\tdwCallerIDSize = %lx", lpInfo->dwCallerIDSize);
  600. TraceMsg(TF_ALWAYS, "\tdwCallerIDOffset = %lx", lpInfo->dwCallerIDOffset);
  601. TraceMsg(TF_ALWAYS, "\tdwCalledIDFlags = %lx", lpInfo->dwCalledIDFlags);
  602. TraceMsg(TF_ALWAYS, "\tdwCalledIDSize = %lx", lpInfo->dwCalledIDSize);
  603. TraceMsg(TF_ALWAYS, "\tdwCalledIDOffset = %lx", lpInfo->dwCalledIDOffset);
  604. if ( ( 0 < lpInfo->dwCalledIDOffset ) &&
  605. ( 0 < lpInfo->dwCalledIDSize ) )
  606. {
  607. PBYTE lpAddr;
  608. lpAddr = ( (PBYTE) lpInfo ) + lpInfo->dwCallerIDOffset;
  609. if ( lpAddr )
  610. {
  611. TraceMsg(TF_ALWAYS, "\t%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  612. lpAddr[0], lpAddr[1], lpAddr[2], lpAddr[3], lpAddr[4], lpAddr[5],
  613. lpAddr[6], lpAddr[7], lpAddr[8], lpAddr[9], lpAddr[10], lpAddr[11] );
  614. }
  615. // The local address from the ndis binding is in dwCalledIDOffset
  616. // The server address is in dwCallerIDOffset
  617. lpAddr = ( (PBYTE) lpInfo ) + lpInfo->dwCalledIDOffset;
  618. if ( lpAddr )
  619. {
  620. DWORD dwSize = lpInfo->dwCalledIDSize;
  621. PBYTE lpBuf = new BYTE[ dwSize ];
  622. TraceMsg(TF_ALWAYS, "\t%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  623. lpAddr[0], lpAddr[1], lpAddr[2], lpAddr[3], lpAddr[4], lpAddr[5],
  624. lpAddr[6], lpAddr[7], lpAddr[8], lpAddr[9], lpAddr[10], lpAddr[11] );
  625. if ( NULL != lpBuf )
  626. {
  627. memset( lpBuf, NULL, sizeof(lpBuf) );
  628. for ( DWORD j=0; j<dwSize/2; j++ )
  629. {
  630. lpBuf[j] = lpAddr[2*j];
  631. }
  632. *ppMacAddress = lpBuf;
  633. hr = S_OK;
  634. }
  635. }
  636. }
  637. else if ( lpInfo->dwNeededSize > lpInfo->dwTotalSize )
  638. {
  639. dwSize = lpInfo->dwNeededSize + 1;
  640. }
  641. }
  642. else if ( LINEERR_STRUCTURETOOSMALL == lError )
  643. {
  644. dwSize = lpInfo->dwNeededSize + 1;
  645. }
  646. else
  647. {
  648. i = 2; // break out of for loop
  649. }
  650. delete [] Buffer;
  651. } // if ( NULL != Buffer )
  652. else
  653. {
  654. hr = E_OUTOFMEMORY;
  655. break;
  656. }
  657. } // for ( int i=0; i<2; i++ )
  658. TraceMsg(TF_ALWAYS, "HrGetSourceMacAddr = %lx", hr);
  659. return hr;
  660. }
  661. HRESULT HrCompareMacAddresses(
  662. INetConnection* pConnection,
  663. HLINE hLine,
  664. BOOL* pfAssociated
  665. )
  666. //+---------------------------------------------------------------------------
  667. //
  668. // Function: HrCompareMacAddresses
  669. //
  670. // Purpose:
  671. //
  672. // Arguments: INetConnection* pConnection
  673. // HLINE hLine
  674. // BOOL* pfAssociated
  675. //
  676. // Returns: HRESULT
  677. //
  678. // Author: billi 22/02/01
  679. //
  680. // Notes:
  681. //
  682. {
  683. HRESULT hr;
  684. HCALL* pList = NULL;
  685. DWORD dwNumber = 0;
  686. ASSERT( pConnection );
  687. ASSERT( pfAssociated );
  688. *pfAssociated = FALSE;
  689. hr = HrGetCallList( hLine, &dwNumber, &pList );
  690. if ( SUCCEEDED(hr) )
  691. {
  692. PIP_ADAPTER_INFO pInfo;
  693. hr = HrGetAdapterInfo( pConnection, &pInfo );
  694. if ( SUCCEEDED(hr) )
  695. {
  696. for ( DWORD i=0; i<dwNumber; i++ )
  697. {
  698. PBYTE pMacAddress;
  699. hr = HrGetSourceMacAddr( pList[i], &pMacAddress );
  700. if ( SUCCEEDED(hr) )
  701. {
  702. TraceMsg(TF_ALWAYS,
  703. "memcmp( %lx, %lx, %lx, %lx )",
  704. pMacAddress, pInfo->Address, pInfo->AddressLength, TAPI_STATION_ID_SIZE);
  705. TraceMsg(TF_ALWAYS, "\t%02x %02x %02x %02x %02x %02x",
  706. pMacAddress[0], pMacAddress[1], pMacAddress[2],
  707. pMacAddress[3], pMacAddress[4], pMacAddress[5] );
  708. TraceMsg(TF_ALWAYS, "\t%02x %02x %02x %02x %02x %02x",
  709. pInfo->Address[0], pInfo->Address[1], pInfo->Address[2],
  710. pInfo->Address[3], pInfo->Address[4], pInfo->Address[5] );
  711. if ( !memcmp( pMacAddress, pInfo->Address, TAPI_STATION_ID_SIZE ) )
  712. {
  713. TraceMsg(TF_ALWAYS, "\tFound It!");
  714. *pfAssociated = TRUE;
  715. i = dwNumber; // break out of for loop
  716. }
  717. delete pMacAddress;
  718. }
  719. } // for ( DWORD i=0; i<dwNumber; i++ )
  720. delete pInfo;
  721. }
  722. delete pList;
  723. }
  724. TraceMsg(TF_ALWAYS, "HrCompareMacAddresses = %lx", hr);
  725. return hr;
  726. }
  727. HRESULT HrCheckMacAddress(
  728. INetConnection* pConnection,
  729. NETCON_MEDIATYPE MediaType,
  730. BOOL* pfAssociated
  731. )
  732. //+---------------------------------------------------------------------------
  733. //
  734. // Function: HrCheckMacAddress
  735. //
  736. // Purpose:
  737. //
  738. // Arguments: INetConnection* pConnection
  739. // NETCON_MEDIATYPE MediaType
  740. // BOOL* pfAssociated
  741. //
  742. // Returns: HRESULT
  743. //
  744. // Author: billi 22/02/01
  745. //
  746. // Notes:
  747. //
  748. {
  749. HRESULT hr;
  750. HLINEAPP hRasLine = 0;
  751. DWORD dwLines = 0;
  752. ASSERT( pConnection );
  753. ASSERT( pfAssociated );
  754. *pfAssociated = FALSE;
  755. hr = HrLineInitialize( &hRasLine, &dwLines );
  756. if ( SUCCEEDED(hr) )
  757. {
  758. for ( DWORD i=0; i<dwLines; i++ )
  759. {
  760. DWORD dwApiVersion = 0;
  761. DWORD dwExtVersion = 0;
  762. HLINE hLine = 0;
  763. LPWSTR pszwLineAddress = NULL;
  764. hr = HrLineOpen( hRasLine, i, &hLine, &dwApiVersion, &dwExtVersion, &pszwLineAddress );
  765. if ( SUCCEEDED(hr) && pszwLineAddress )
  766. {
  767. if ( (NCM_TUNNEL == MediaType) &&
  768. !wcscmp(pszwLineAddress, PPTP_LINE_ADDR_STRING) )
  769. {
  770. TraceMsg(TF_ALWAYS, "MediaType match %s!", PPTP_LINE_ADDR_STRING);
  771. hr = S_OK;
  772. }
  773. else if ( (NCM_PPPOE == MediaType) &&
  774. !wcscmp(pszwLineAddress, PPPOE_LINE_ADDR_STRING) )
  775. {
  776. TraceMsg(TF_ALWAYS, "MediaType match %s!", PPPOE_LINE_ADDR_STRING);
  777. hr = S_OK;
  778. }
  779. /*
  780. else if ( (NCM_PHONE == MediaType) &&
  781. !wcscmp(pszwLineAddress, PPPOE_LINE_ADDR_STRING) )
  782. {
  783. TraceMsg(TF_ALWAYS, "MediaType match %s!", PPPOE_LINE_ADDR_STRING);
  784. hr = S_OK;
  785. }
  786. */
  787. else
  788. {
  789. TraceMsg(TF_ALWAYS, "MediaType mismatch");
  790. hr = E_FAIL;
  791. }
  792. if ( SUCCEEDED(hr) )
  793. {
  794. hr = HrCompareMacAddresses( pConnection, hLine, pfAssociated );
  795. if ( SUCCEEDED(hr) && *pfAssociated )
  796. {
  797. i = dwLines; // break out of for loop
  798. }
  799. }
  800. if ( NULL != pszwLineAddress )
  801. {
  802. delete [] pszwLineAddress;
  803. }
  804. lineClose( hLine );
  805. }
  806. } // for ( DWORD i=0; i<dwLines; i++ )
  807. lineShutdown( hRasLine ) ;
  808. }
  809. TraceMsg(TF_ALWAYS, "HrCheckMacAddress = %lx", hr);
  810. return hr;
  811. }
  812. HRESULT HrConnectionAssociatedWithSharedConnection(
  813. INetConnection* pPrivate,
  814. INetConnection* pShared,
  815. BOOL* pfAssociated
  816. )
  817. //+---------------------------------------------------------------------------
  818. //
  819. // Function: HrConnectionAssociatedWithSharedConnection
  820. //
  821. // Purpose:
  822. //
  823. // Arguments: INetConnection* pPrivate
  824. // INetConnection* pShared
  825. //
  826. // Returns: HRESULT
  827. //
  828. // Author: billi 26/01/01
  829. //
  830. // Notes:
  831. //
  832. {
  833. HRESULT hr = S_OK;
  834. ASSERT( pPrivate );
  835. ASSERT( pfAssociated );
  836. // False by default
  837. *pfAssociated = FALSE;
  838. if ( NULL != pShared )
  839. {
  840. NETCON_PROPERTIES* pProps = NULL;
  841. hr = pShared->GetProperties( &pProps );
  842. if ( SUCCEEDED(hr) )
  843. {
  844. INetRasConnection* pRasShared = NULL;
  845. TraceMsg(TF_ALWAYS, "MediaType = %lx", pProps->MediaType);
  846. switch ( pProps->MediaType )
  847. {
  848. case NCM_TUNNEL:
  849. hr = pShared->QueryInterface( IID_PPV_ARG(INetRasConnection, &pRasShared) );
  850. if ( SUCCEEDED(hr) )
  851. {
  852. hr = HrCheckVPNForRoute( pPrivate, pRasShared, pProps, pfAssociated );
  853. pRasShared->Release();
  854. }
  855. break;
  856. case NCM_PPPOE:
  857. if ( pProps->Status == NCS_DISCONNECTED )
  858. {
  859. hr = pShared->QueryInterface( IID_PPV_ARG(INetRasConnection, &pRasShared) );
  860. if ( SUCCEEDED(hr) )
  861. {
  862. // We are in a bad fix if the connection is in an
  863. // intermediate state or a failure state
  864. hr = HrRasDialDlg( pRasShared );
  865. pRasShared->Release();
  866. }
  867. }
  868. if ( SUCCEEDED(hr) )
  869. {
  870. hr = HrCheckMacAddress( pPrivate, pProps->MediaType, pfAssociated );
  871. }
  872. break;
  873. default:
  874. // leave hr as succeeded
  875. // leave pfAssociated = FALSE
  876. break;
  877. }
  878. NcFreeNetconProperties( pProps );
  879. if ( FAILED(hr) )
  880. {
  881. // We want this call to succeed. If there were problems then
  882. // we simply report that the connections weren't associated
  883. *pfAssociated = FALSE;
  884. // Whether it succeeds or not we need to return S_OK
  885. // The wizard should not fail because we can't determine the
  886. // correct adapter.
  887. hr = S_OK;
  888. }
  889. }
  890. }
  891. TraceMsg(TF_ALWAYS, "HrConnectionAssociatedWithSharedConnection = %lx fAssociated = %lx", hr, *pfAssociated );
  892. return S_OK;
  893. }