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.

936 lines
28 KiB

  1. /*********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /*********************************************************************/
  4. //***
  5. //
  6. // Filename: rasapiif.c
  7. //
  8. // Description: Handles all the RASAPI32 calls
  9. //
  10. // History: May 11,1996 NarenG Created original version.
  11. //
  12. #include "ddm.h"
  13. #include "util.h"
  14. #include "objects.h"
  15. #include "rasmanif.h"
  16. #include "rasapiif.h"
  17. #include "handlers.h"
  18. #include "timer.h"
  19. #include <time.h>
  20. #include <mprapi.h>
  21. #include <mprapip.h>
  22. HPORT
  23. RasGetHport(
  24. IN HRASCONN hRasConnSubEntry
  25. );
  26. DWORD
  27. RasPortConnected(
  28. IN HRASCONN hRasConn,
  29. IN HRASCONN hRasConnSubEntry,
  30. IN DEVICE_OBJECT * pDevObj,
  31. IN HANDLE hDIMInterface
  32. )
  33. {
  34. CONNECTION_OBJECT * pConnObj;
  35. DWORD dwRetCode;
  36. ROUTER_INTERFACE_OBJECT * pIfObject;
  37. //
  38. // Set this port to be notified by rasapi32 on disconnect.
  39. //
  40. dwRetCode = RasConnectionNotification(
  41. hRasConnSubEntry,
  42. gblSupervisorEvents[NUM_DDM_EVENTS
  43. + (gblDeviceTable.NumDeviceBuckets*2)
  44. + DeviceObjHashPortToBucket(pDevObj->hPort)],
  45. RASCN_Disconnection );
  46. if ( dwRetCode != NO_ERROR )
  47. {
  48. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  49. "RasConnectionNotification returned %d", dwRetCode );
  50. return( dwRetCode );
  51. }
  52. //
  53. // Get handle to the connection or bundle for this link
  54. //
  55. dwRetCode = RasPortGetBundle(NULL, pDevObj->hPort, &(pDevObj->hConnection));
  56. if ( dwRetCode != NO_ERROR )
  57. {
  58. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  59. "RasPortGetBundle returned %d", dwRetCode );
  60. return( dwRetCode );
  61. }
  62. do
  63. {
  64. pIfObject = IfObjectGetPointer( hDIMInterface );
  65. if ( pIfObject == NULL )
  66. {
  67. RTASSERT( FALSE );
  68. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  69. break;
  70. }
  71. //
  72. // If this interface was disconnected by DDMDisconnectInterface,
  73. // then do not let this device through.
  74. //
  75. if ( pIfObject->fFlags & IFFLAG_DISCONNECT_INITIATED )
  76. {
  77. dwRetCode = ERROR_PORT_DISCONNECTED;
  78. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  79. "RasPortConnected: Admin disconnected port" );
  80. break;
  81. }
  82. //
  83. // Allocate a connection object if it does not exist yet
  84. //
  85. pConnObj = ConnObjGetPointer( pDevObj->hConnection );
  86. if ( pConnObj == (CONNECTION_OBJECT *)NULL )
  87. {
  88. RASPPPIP RasPppIp;
  89. RASPPPIPX RasPppIpx;
  90. DWORD dwSize;
  91. pConnObj = ConnObjAllocateAndInit( hDIMInterface,
  92. pDevObj->hConnection );
  93. if ( pConnObj == (CONNECTION_OBJECT *)NULL )
  94. {
  95. dwRetCode = GetLastError();
  96. break;
  97. }
  98. ConnObjInsertInTable( pConnObj );
  99. //
  100. // First get the projection info, make sure IP or IPX
  101. // were negotiated
  102. //
  103. dwSize = sizeof( RasPppIpx );
  104. RasPppIpx.dwSize = sizeof( RasPppIpx );
  105. dwRetCode = RasGetProjectionInfo(
  106. hRasConn,
  107. RASP_PppIpx,
  108. &RasPppIpx,
  109. &dwSize );
  110. if ( dwRetCode != NO_ERROR )
  111. {
  112. pConnObj->PppProjectionResult.ipx.dwError = dwRetCode;
  113. }
  114. else
  115. {
  116. pConnObj->PppProjectionResult.ipx.dwError = RasPppIpx.dwError;
  117. ConvertStringToIpxAddress(
  118. RasPppIpx.szIpxAddress,
  119. pConnObj->PppProjectionResult.ipx.bLocalAddress);
  120. }
  121. dwSize = sizeof( RasPppIp );
  122. RasPppIp.dwSize = sizeof( RasPppIp );
  123. dwRetCode = RasGetProjectionInfo(
  124. hRasConn,
  125. RASP_PppIp,
  126. &RasPppIp,
  127. &dwSize );
  128. if ( dwRetCode != NO_ERROR )
  129. {
  130. pConnObj->PppProjectionResult.ip.dwError = dwRetCode;
  131. }
  132. else
  133. {
  134. pConnObj->PppProjectionResult.ip.dwError = RasPppIp.dwError;
  135. ConvertStringToIpAddress(
  136. RasPppIp.szIpAddress,
  137. &(pConnObj->PppProjectionResult.ip.dwLocalAddress));
  138. ConvertStringToIpAddress(
  139. RasPppIp.szServerIpAddress,
  140. &(pConnObj->PppProjectionResult.ip.dwRemoteAddress));
  141. }
  142. if ((pConnObj->PppProjectionResult.ipx.dwError!=NO_ERROR )
  143. &&
  144. (pConnObj->PppProjectionResult.ip.dwError!=NO_ERROR ))
  145. {
  146. dwRetCode = ERROR_PPP_NO_PROTOCOLS_CONFIGURED;
  147. break;
  148. }
  149. pConnObj->fFlags = CONN_OBJ_IS_PPP;
  150. pConnObj->hPort = pDevObj->hPort;
  151. }
  152. else
  153. {
  154. //
  155. // Make sure that we are adding a link to a connection for the
  156. // same interface that initiated the connection.
  157. //
  158. if ( hDIMInterface != pConnObj->hDIMInterface )
  159. {
  160. dwRetCode = ERROR_INTERFACE_CONFIGURATION;
  161. break;
  162. }
  163. }
  164. pDevObj->hRasConn = hRasConnSubEntry;
  165. GetSystemTimeAsFileTime( (FILETIME*)&(pDevObj->qwActiveTime) );
  166. //
  167. // Add this link to the connection block.
  168. //
  169. if ((dwRetCode = ConnObjAddLink(pConnObj, pDevObj)) != NO_ERROR)
  170. {
  171. break;
  172. }
  173. //
  174. // Notify router managers that we are connected if we have
  175. // not done so already.
  176. //
  177. if ( !( pConnObj->fFlags & CONN_OBJ_PROJECTIONS_NOTIFIED ) )
  178. {
  179. RASDIALPARAMS RasDialParams;
  180. BOOL fPassword;
  181. dwRetCode = IfObjectConnected(
  182. hDIMInterface,
  183. (HCONN)pDevObj->hConnection,
  184. &(pConnObj->PppProjectionResult) );
  185. if ( dwRetCode != NO_ERROR )
  186. {
  187. break;
  188. }
  189. pConnObj->fFlags |= CONN_OBJ_PROJECTIONS_NOTIFIED;
  190. //
  191. // Get username and domain name
  192. //
  193. ZeroMemory( &RasDialParams, sizeof( RasDialParams ) );
  194. RasDialParams.dwSize = sizeof( RasDialParams );
  195. wcscpy( RasDialParams.szEntryName, pIfObject->lpwsInterfaceName );
  196. dwRetCode = RasGetEntryDialParams( gblpRouterPhoneBook,
  197. &RasDialParams,
  198. &fPassword);
  199. if ( dwRetCode == NO_ERROR )
  200. {
  201. wcscpy( pConnObj->wchUserName, RasDialParams.szUserName );
  202. wcscpy( pConnObj->wchDomainName, RasDialParams.szDomain );
  203. ZeroMemory( &RasDialParams, sizeof( RasDialParams ) );
  204. }
  205. else
  206. {
  207. dwRetCode = NO_ERROR;
  208. }
  209. wcscpy( pConnObj->wchInterfaceName, pIfObject->lpwsInterfaceName );
  210. GetSystemTimeAsFileTime( (FILETIME*)&(pDevObj->qwActiveTime) );
  211. pConnObj->qwActiveTime = pDevObj->qwActiveTime;
  212. pConnObj->InterfaceType = pIfObject->IfType;
  213. pIfObject->dwLastError = NO_ERROR;
  214. //
  215. // If this was initiated by an admin api. Let the caller
  216. // know that we are connected.
  217. //
  218. if (pIfObject->hEventNotifyCaller != INVALID_HANDLE_VALUE)
  219. {
  220. SetEvent( pIfObject->hEventNotifyCaller );
  221. CloseHandle( pIfObject->hEventNotifyCaller );
  222. pIfObject->hEventNotifyCaller = INVALID_HANDLE_VALUE;
  223. }
  224. }
  225. //
  226. // Reduce the media count for this device
  227. //
  228. if ( !(pDevObj->fFlags & DEV_OBJ_MARKED_AS_INUSE) )
  229. {
  230. if ( pDevObj->fFlags & DEV_OBJ_ALLOW_ROUTERS )
  231. {
  232. MediaObjRemoveFromTable( pDevObj->wchDeviceType );
  233. }
  234. pDevObj->fFlags |= DEV_OBJ_MARKED_AS_INUSE;
  235. gblDeviceTable.NumDevicesInUse++;
  236. //
  237. // Possibly need to notify the router managers of
  238. // unreachability
  239. //
  240. IfObjectNotifyAllOfReachabilityChange( FALSE,
  241. INTERFACE_OUT_OF_RESOURCES );
  242. }
  243. RasSetRouterUsage( pDevObj->hPort, TRUE );
  244. }while( FALSE );
  245. if ( dwRetCode != NO_ERROR )
  246. {
  247. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  248. "RasPortConnected: Cleaning up hPort=%d, error %d",
  249. pDevObj->hPort, dwRetCode );
  250. RasApiCleanUpPort( pDevObj );
  251. return( dwRetCode );
  252. }
  253. return( NO_ERROR );
  254. }
  255. //**
  256. //
  257. // Call: RasConnectCallback
  258. //
  259. // Returns: None
  260. //
  261. // Description: Callback function that will be called by RASAPI32 for any
  262. // state change.
  263. //
  264. BOOL
  265. RasConnectCallback(
  266. IN DWORD dwCallbackId,
  267. IN DWORD dwSubEntryId,
  268. IN HRASCONN hRasConn,
  269. IN DWORD dwMsg,
  270. IN RASCONNSTATE RasConnState,
  271. IN DWORD dwError,
  272. IN DWORD dwExtendedError
  273. )
  274. {
  275. DWORD dwIndex;
  276. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  277. DEVICE_OBJECT * pDevObj = NULL;
  278. HANDLE hDIMInterface = (HANDLE)UlongToPtr(dwCallbackId);
  279. HRASCONN hRasConnSubEntry;
  280. DWORD dwRetCode;
  281. HPORT hPort;
  282. LPWSTR lpwsAudit[2];
  283. if ( dwMsg != WM_RASDIALEVENT )
  284. {
  285. RTASSERT( dwMsg == WM_RASDIALEVENT );
  286. return( TRUE );
  287. }
  288. switch( RasConnState )
  289. {
  290. case RASCS_Connected:
  291. case RASCS_SubEntryConnected:
  292. case RASCS_SubEntryDisconnected:
  293. case RASCS_Disconnected:
  294. case RASCS_PortOpened:
  295. break;
  296. default:
  297. if ( dwError != NO_ERROR )
  298. {
  299. break;
  300. }
  301. else
  302. {
  303. //
  304. // Ignore these intermediate events
  305. //
  306. return( TRUE );
  307. }
  308. }
  309. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  310. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  311. do
  312. {
  313. //
  314. // Get pointer to device object and hRasConn of the device
  315. //
  316. dwRetCode = RasGetSubEntryHandle( hRasConn,
  317. dwSubEntryId,
  318. &hRasConnSubEntry );
  319. if ( dwRetCode != NO_ERROR )
  320. {
  321. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  322. "RasGetSubEntryHandle( 0x%x, 0x%x, 0x%x ) = %d",
  323. hRasConn, dwSubEntryId, &hRasConnSubEntry, dwRetCode );
  324. if ( dwError == NO_ERROR )
  325. {
  326. dwError = dwRetCode;
  327. }
  328. }
  329. else
  330. {
  331. hPort = RasGetHport( hRasConnSubEntry );
  332. if ( hPort == (HPORT)INVALID_HANDLE_VALUE )
  333. {
  334. RTASSERT( FALSE );
  335. dwRetCode = ERROR_INVALID_PORT_HANDLE;
  336. if ( dwError == NO_ERROR )
  337. {
  338. dwError = dwRetCode;
  339. }
  340. }
  341. else
  342. {
  343. if ( ( pDevObj = DeviceObjGetPointer( hPort ) ) == NULL )
  344. {
  345. dwRetCode = ERROR_NOT_ROUTER_PORT;
  346. }
  347. else
  348. {
  349. if ( !( pDevObj->fFlags & DEV_OBJ_ALLOW_ROUTERS ) )
  350. {
  351. dwRetCode = ERROR_NOT_ROUTER_PORT;
  352. }
  353. else
  354. {
  355. dwRetCode = NO_ERROR;
  356. }
  357. }
  358. if ( dwError == NO_ERROR )
  359. {
  360. dwError = dwRetCode;
  361. }
  362. }
  363. }
  364. if ( dwError == NO_ERROR )
  365. {
  366. switch( RasConnState )
  367. {
  368. case RASCS_PortOpened:
  369. pDevObj->fFlags |= DEV_OBJ_OPENED_FOR_DIALOUT;
  370. pDevObj->hRasConn = hRasConnSubEntry;
  371. break;
  372. case RASCS_Connected:
  373. case RASCS_SubEntryConnected:
  374. DDM_PRINT(gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  375. "RasConnectCallback:PortConnected,dwSubEntryId=%d,hPort=%d",
  376. dwSubEntryId, hPort );
  377. dwError = RasPortConnected( hRasConn,
  378. hRasConnSubEntry,
  379. pDevObj,
  380. hDIMInterface );
  381. break;
  382. case RASCS_SubEntryDisconnected:
  383. case RASCS_Disconnected:
  384. pDevObj->fFlags &= ~DEV_OBJ_OPENED_FOR_DIALOUT;
  385. pDevObj->hRasConn = (HRASCONN)NULL;
  386. break;
  387. default:
  388. RTASSERT( FALSE );
  389. break;
  390. }
  391. if ( ( RasConnState == RASCS_Connected ) ||
  392. ( RasConnState == RASCS_SubEntryConnected )||
  393. ( RasConnState == RASCS_PortOpened ) )
  394. {
  395. if ( dwError == NO_ERROR )
  396. {
  397. break;
  398. }
  399. }
  400. }
  401. else
  402. {
  403. if ( pDevObj != NULL )
  404. {
  405. pDevObj->fFlags &= ~DEV_OBJ_OPENED_FOR_DIALOUT;
  406. pDevObj->hRasConn = (HRASCONN)NULL;
  407. }
  408. }
  409. DDM_PRINT(gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  410. "RasConnectCallback:Could not connect to SubEntry %d,dwError=%d",
  411. dwSubEntryId, dwError );
  412. //
  413. // Has the bundle failed to connect?
  414. //
  415. pIfObject = IfObjectGetPointer( hDIMInterface );
  416. if ( pIfObject == NULL )
  417. {
  418. RTASSERT( FALSE );
  419. dwError = ERROR_NO_SUCH_INTERFACE;
  420. break;
  421. }
  422. --pIfObject->dwNumSubEntriesCounter;
  423. if ( ( pIfObject->dwNumSubEntriesCounter == 0 ) ||
  424. ( RasConnState == RASCS_Disconnected ) ||
  425. !(pIfObject->fFlags & IFFLAG_DIALMODE_DIALALL))
  426. {
  427. if ( pIfObject->State == RISTATE_CONNECTED )
  428. {
  429. //
  430. // Interface is already connected so it doesn't matter if this
  431. // device failed.
  432. //
  433. break;
  434. }
  435. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  436. "RasConnectCallback:Could not connect to interface %ws",
  437. pIfObject->lpwsInterfaceName );
  438. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  439. "RasConnectCallback: hanging up 0x%x", pIfObject->hRasConn);
  440. RasHangUp( pIfObject->hRasConn );
  441. pIfObject->hRasConn = (HRASCONN)NULL;
  442. //
  443. // If the admin as initiated a disconnect or we are out of
  444. // retries
  445. //
  446. if ( ( pIfObject->fFlags & IFFLAG_DISCONNECT_INITIATED ) ||
  447. ( pIfObject->dwNumOfReConnectAttemptsCounter == 0 ) )
  448. {
  449. //
  450. // Mark as unreachable due to connection failure the admin did
  451. // not disconnect.
  452. //
  453. if ( !( pIfObject->fFlags & IFFLAG_DISCONNECT_INITIATED ) )
  454. {
  455. pIfObject->fFlags |= IFFLAG_CONNECTION_FAILURE;
  456. }
  457. IfObjectDisconnected( pIfObject );
  458. IfObjectNotifyOfReachabilityChange(
  459. pIfObject,
  460. FALSE,
  461. INTERFACE_CONNECTION_FAILURE );
  462. //
  463. // If we were disconnected by the admin then we should
  464. // immediately go to the reachable state.
  465. //
  466. if ( pIfObject->fFlags & IFFLAG_DISCONNECT_INITIATED )
  467. {
  468. IfObjectNotifyOfReachabilityChange(
  469. pIfObject,
  470. TRUE,
  471. INTERFACE_CONNECTION_FAILURE );
  472. }
  473. pIfObject->dwLastError = dwError;
  474. if ( pDevObj != NULL )
  475. {
  476. lpwsAudit[0] = pIfObject->lpwsInterfaceName;
  477. lpwsAudit[1] = pDevObj->wchPortName;
  478. DDMLogErrorString( ROUTERLOG_CONNECTION_ATTEMPT_FAILED,
  479. 2, lpwsAudit, dwError, 2 );
  480. }
  481. //
  482. // If this was initiated by an admin api. Let the caller
  483. // know that we are not connected.
  484. //
  485. if (pIfObject->hEventNotifyCaller != INVALID_HANDLE_VALUE)
  486. {
  487. SetEvent( pIfObject->hEventNotifyCaller );
  488. CloseHandle( pIfObject->hEventNotifyCaller );
  489. pIfObject->hEventNotifyCaller = INVALID_HANDLE_VALUE;
  490. }
  491. }
  492. else
  493. {
  494. //
  495. // Otherwise we try again
  496. //
  497. pIfObject->dwNumOfReConnectAttemptsCounter--;
  498. //
  499. // Stagger the reconnectime randomly between 0 and twice the
  500. // configured reconnect time.
  501. //
  502. srand( (unsigned)time( NULL ) );
  503. TimerQInsert(
  504. pIfObject->hDIMInterface,
  505. rand()%((pIfObject->dwSecondsBetweenReConnectAttempts*2)+1),
  506. ReConnectInterface );
  507. }
  508. }
  509. }
  510. while( FALSE );
  511. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  512. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  513. return( TRUE );
  514. }
  515. //**
  516. //
  517. // Call: RasConnectionInitiate
  518. //
  519. // Returns: NO_ERROR - Success
  520. // Non-zero returns - Failure
  521. //
  522. // Description: Called to initiate a demand-dial connection
  523. //
  524. DWORD
  525. RasConnectionInitiate(
  526. IN ROUTER_INTERFACE_OBJECT * pIfObject,
  527. IN BOOL fRedialAttempt
  528. )
  529. {
  530. RASDIALEXTENSIONS RasDialExtensions;
  531. RASDIALPARAMS RasDialParams;
  532. DWORD dwXportIndex;
  533. DWORD dwRetCode;
  534. RASENTRY re;
  535. DWORD dwSize;
  536. RASEAPUSERIDENTITY* pRasEapUserIdentity = NULL;
  537. //
  538. // Do not try to connect if the interface is disabled or out of resources
  539. // or the service is paused or the interface is marked as unreachable due
  540. // to connection failure.
  541. //
  542. if ( !( pIfObject->fFlags & IFFLAG_ENABLED ) )
  543. {
  544. return( ERROR_INTERFACE_DISABLED );
  545. }
  546. if ( pIfObject->fFlags & IFFLAG_OUT_OF_RESOURCES )
  547. {
  548. return( ERROR_INTERFACE_HAS_NO_DEVICES );
  549. }
  550. if ( gblDDMConfigInfo.pServiceStatus->dwCurrentState == SERVICE_PAUSED )
  551. {
  552. return( ERROR_SERVICE_IS_PAUSED );
  553. }
  554. //
  555. // If this is not a redial attempt then we reset the reconnect attempts
  556. // counter and unset the admin disconnected flag if it was set.
  557. //
  558. if ( !fRedialAttempt )
  559. {
  560. pIfObject->dwNumOfReConnectAttemptsCounter =
  561. pIfObject->dwNumOfReConnectAttempts;
  562. pIfObject->fFlags &= ~IFFLAG_DISCONNECT_INITIATED;
  563. }
  564. else
  565. {
  566. //
  567. // Do not allow the reconnect attempt to go thru if the admin has
  568. // disconnected this interface.
  569. //
  570. if ( pIfObject->fFlags & IFFLAG_DISCONNECT_INITIATED )
  571. {
  572. return( ERROR_INTERFACE_DISCONNECTED );
  573. }
  574. }
  575. //
  576. // Build PppInterfaceInfo structure to pass down to RasDial that will pass
  577. // it on to PPP.
  578. //
  579. for ( dwXportIndex = 0;
  580. dwXportIndex < gblDDMConfigInfo.dwNumRouterManagers;
  581. dwXportIndex++ )
  582. {
  583. switch( gblRouterManagers[dwXportIndex].DdmRouterIf.dwProtocolId )
  584. {
  585. case PID_IPX:
  586. if (pIfObject->Transport[dwXportIndex].fState & RITRANSPORT_ENABLED)
  587. {
  588. pIfObject->PppInterfaceInfo.hIPXInterface =
  589. pIfObject->Transport[dwXportIndex].hInterface;
  590. }
  591. else
  592. {
  593. pIfObject->PppInterfaceInfo.hIPXInterface=INVALID_HANDLE_VALUE;
  594. }
  595. break;
  596. case PID_IP:
  597. if (pIfObject->Transport[dwXportIndex].fState & RITRANSPORT_ENABLED)
  598. {
  599. pIfObject->PppInterfaceInfo.hIPInterface =
  600. pIfObject->Transport[dwXportIndex].hInterface;
  601. }
  602. else
  603. {
  604. pIfObject->PppInterfaceInfo.hIPInterface = INVALID_HANDLE_VALUE;
  605. }
  606. break;
  607. default:
  608. RTASSERT( FALSE );
  609. break;
  610. }
  611. }
  612. pIfObject->PppInterfaceInfo.IfType = pIfObject->IfType;
  613. pIfObject->dwNumSubEntriesCounter = pIfObject->dwNumSubEntries;
  614. //
  615. // Initiate the connection
  616. //
  617. ZeroMemory( &RasDialExtensions, sizeof( RasDialExtensions ) );
  618. RasDialExtensions.dwSize = sizeof( RasDialExtensions );
  619. RasDialExtensions.dwfOptions = RDEOPT_Router;
  620. RasDialExtensions.reserved = (ULONG_PTR)&(pIfObject->PppInterfaceInfo);
  621. ZeroMemory( &RasDialParams, sizeof( RasDialParams ) );
  622. RasDialParams.dwSize = sizeof( RasDialParams );
  623. RasDialParams.dwCallbackId = PtrToUlong(pIfObject->hDIMInterface);
  624. RasDialParams.dwSubEntry = 0;
  625. wcscpy( RasDialParams.szCallbackNumber, TEXT("*") );
  626. wcscpy( RasDialParams.szEntryName, pIfObject->lpwsInterfaceName );
  627. //
  628. // Do we need to call RasEapGetIdentity?
  629. //
  630. dwRetCode = RasGetEapUserIdentity(
  631. gblpRouterPhoneBook,
  632. pIfObject->lpwsInterfaceName,
  633. RASEAPF_NonInteractive,
  634. NULL,
  635. &pRasEapUserIdentity);
  636. if ( ERROR_INVALID_FUNCTION_FOR_ENTRY == dwRetCode )
  637. {
  638. //
  639. // This entry does not require RasEapGetIdentity. Get its credentials.
  640. //
  641. dwRetCode = MprAdminInterfaceGetCredentialsInternal(
  642. NULL,
  643. pIfObject->lpwsInterfaceName,
  644. (LPWSTR)&(RasDialParams.szUserName),
  645. (LPWSTR)&(RasDialParams.szPassword),
  646. (LPWSTR)&(RasDialParams.szDomain) );
  647. if ( dwRetCode != NO_ERROR )
  648. {
  649. return( ERROR_NO_INTERFACE_CREDENTIALS_SET );
  650. }
  651. }
  652. else if ( NO_ERROR != dwRetCode )
  653. {
  654. if ( ERROR_INTERACTIVE_MODE == dwRetCode )
  655. {
  656. dwRetCode = ERROR_NO_INTERFACE_CREDENTIALS_SET;
  657. }
  658. return( dwRetCode );
  659. }
  660. else
  661. {
  662. wcscpy( RasDialParams.szUserName, pRasEapUserIdentity->szUserName );
  663. RasDialExtensions.RasEapInfo.dwSizeofEapInfo =
  664. pRasEapUserIdentity->dwSizeofEapInfo;
  665. RasDialExtensions.RasEapInfo.pbEapInfo =
  666. pRasEapUserIdentity->pbEapInfo;
  667. }
  668. if( (0 != gblDDMConfigInfo.cDigitalIPAddresses)
  669. || (0 != gblDDMConfigInfo.cAnalogIPAddresses))
  670. {
  671. ZeroMemory(&re, sizeof(RASENTRY));
  672. re.dwSize = sizeof(RASENTRY);
  673. dwSize = sizeof(RASENTRY);
  674. if(ERROR_SUCCESS == (dwRetCode = RasGetEntryProperties(
  675. gblpRouterPhoneBook,
  676. pIfObject->lpwsInterfaceName,
  677. &re,
  678. &dwSize,
  679. NULL,
  680. NULL)))
  681. {
  682. if(RASET_Vpn == re.dwType)
  683. {
  684. char *pszMungedPhoneNumber = NULL;
  685. char szPhoneNumber[RAS_MaxPhoneNumber + 1];
  686. WCHAR wszMungedPhoneNumber[RAS_MaxPhoneNumber + 1];
  687. //
  688. // Convert the phonenumber to ansi
  689. //
  690. WideCharToMultiByte(
  691. CP_ACP,
  692. 0,
  693. re.szLocalPhoneNumber,
  694. -1,
  695. szPhoneNumber,
  696. sizeof( szPhoneNumber ),
  697. NULL,
  698. NULL );
  699. //
  700. // Munge the phonenumber
  701. //
  702. dwRetCode = MungePhoneNumber(
  703. szPhoneNumber,
  704. gblDDMConfigInfo.dwIndex,
  705. &dwSize,
  706. &pszMungedPhoneNumber);
  707. if(ERROR_SUCCESS == dwRetCode)
  708. {
  709. //
  710. // Change the munged phonenumber to widechar
  711. //
  712. MultiByteToWideChar( CP_ACP,
  713. 0,
  714. pszMungedPhoneNumber,
  715. -1,
  716. wszMungedPhoneNumber,
  717. RAS_MaxPhoneNumber + 1);
  718. if ( wcslen( wszMungedPhoneNumber ) <= RAS_MaxPhoneNumber)
  719. {
  720. wcscpy( RasDialParams.szPhoneNumber,
  721. wszMungedPhoneNumber );
  722. DDM_PRINT(gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  723. "Munged Phone Number=%ws",
  724. RasDialParams.szPhoneNumber);
  725. //
  726. // Increase the index so that we try the
  727. // next FEP the next time this is dialed.
  728. //
  729. gblDDMConfigInfo.dwIndex += 1;
  730. LocalFree( pszMungedPhoneNumber );
  731. }
  732. }
  733. }
  734. }
  735. }
  736. dwRetCode = RasDial( &RasDialExtensions,
  737. gblpRouterPhoneBook,
  738. &RasDialParams,
  739. 2,
  740. RasConnectCallback,
  741. &(pIfObject->hRasConn) );
  742. //
  743. // Zero out these since they contained sensitive password information
  744. //
  745. ZeroMemory( &RasDialParams, sizeof( RasDialParams ) );
  746. RasFreeEapUserIdentity( pRasEapUserIdentity );
  747. if ( dwRetCode != NO_ERROR )
  748. {
  749. return( dwRetCode );
  750. }
  751. pIfObject->State = RISTATE_CONNECTING;
  752. pIfObject->fFlags |= IFFLAG_LOCALLY_INITIATED;
  753. return( NO_ERROR );
  754. }