Source code of Windows XP (NT5)
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.

3518 lines
95 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: ifapi.c
  7. //
  8. // Description: Contains code to process interface admin api requests
  9. //
  10. // History: May 11,1995 NarenG Created original version.
  11. //
  12. #include "dimsvcp.h"
  13. #include <ras.h>
  14. #include <dimsvc.h> // Generated by MIDL
  15. #include "rpbk.h"
  16. #include <mprapip.h>
  17. #define MAX_GET_INFO_RETRIES 3
  18. //
  19. // DoStartRouter API interface
  20. //
  21. typedef struct _START_ROUTER_DATA
  22. {
  23. DWORD dwTransportId;
  24. DWORD dwInterfaceInfoSize;
  25. LPBYTE pInterfaceInfo;
  26. DWORD dwGlobalInfoSize;
  27. LPBYTE pGlobalInfo;
  28. } START_ROUTER_DATA, *PSTART_ROUTER_DATA;
  29. DWORD
  30. RRouterDeviceEnum(
  31. IN MPR_SERVER_HANDLE hMprServer,
  32. IN DWORD dwLevel,
  33. IN OUT PDIM_INFORMATION_CONTAINER pInfoStruct,
  34. OUT LPDWORD lpdwTotalEntries
  35. )
  36. {
  37. DWORD dwAccessStatus;
  38. DWORD dwRetCode = NO_ERROR;
  39. LPRASDEVINFO lpRasDevInfo = NULL;
  40. DWORD dwSize = 0, dwRetSize = 0;
  41. DWORD dwcDevices = 0;
  42. DWORD i = 0;
  43. MPR_DEVICE_0* pDev0 = NULL;
  44. //
  45. // Check if caller has access
  46. //
  47. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  48. {
  49. return( ERROR_ACCESS_DENIED );
  50. }
  51. if ( dwAccessStatus )
  52. {
  53. return( ERROR_ACCESS_DENIED );
  54. }
  55. if ( dwLevel != 0 )
  56. {
  57. return( ERROR_NOT_SUPPORTED );
  58. }
  59. do
  60. {
  61. *lpdwTotalEntries = 0;
  62. // Find out how much memory to allocate
  63. //
  64. dwRetCode = RasEnumDevices(
  65. NULL,
  66. &dwSize,
  67. &dwcDevices);
  68. if ( ( dwRetCode != NO_ERROR ) &&
  69. ( dwRetCode != ERROR_BUFFER_TOO_SMALL )
  70. )
  71. {
  72. break;
  73. }
  74. if ( dwSize == 0 )
  75. {
  76. dwRetCode = NO_ERROR;
  77. break;
  78. }
  79. // Allocate the ras device info
  80. //
  81. lpRasDevInfo = LOCAL_ALLOC ( LPTR, dwSize );
  82. if ( lpRasDevInfo == NULL )
  83. {
  84. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  85. break;
  86. }
  87. ZeroMemory(lpRasDevInfo, dwSize );
  88. // Allocate the return value
  89. //
  90. dwRetSize = dwcDevices * sizeof(MPR_DEVICE_0);
  91. pInfoStruct->pBuffer = MIDL_user_allocate( dwRetSize );
  92. if ( pInfoStruct->pBuffer == NULL )
  93. {
  94. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  95. break;
  96. }
  97. ZeroMemory(pInfoStruct->pBuffer, dwRetSize );
  98. pDev0 = (MPR_DEVICE_0*) pInfoStruct->pBuffer;
  99. // Read in the device info
  100. lpRasDevInfo->dwSize = sizeof(RASDEVINFO);
  101. dwRetCode = RasEnumDevices(
  102. lpRasDevInfo,
  103. &dwSize,
  104. &dwcDevices);
  105. if ( dwRetCode == ERROR_BUFFER_TOO_SMALL )
  106. {
  107. dwRetCode = NO_ERROR;
  108. }
  109. if ( dwRetCode != NO_ERROR )
  110. {
  111. break;
  112. }
  113. // Copy the device info over
  114. for ( i = 0; i < dwcDevices; i++ )
  115. {
  116. wcscpy(pDev0[i].szDeviceType, lpRasDevInfo[i].szDeviceType);
  117. wcscpy(pDev0[i].szDeviceName, lpRasDevInfo[i].szDeviceName);
  118. }
  119. // Everything's ok, go ahead and set the return values
  120. //
  121. *lpdwTotalEntries = dwcDevices;
  122. pInfoStruct->dwBufferSize = dwRetSize;
  123. } while( FALSE );
  124. // Cleanup
  125. {
  126. if ( lpRasDevInfo )
  127. {
  128. LOCAL_FREE( lpRasDevInfo );
  129. }
  130. if ( dwRetCode != NO_ERROR )
  131. {
  132. if ( pInfoStruct->pBuffer )
  133. {
  134. MIDL_user_free ( pInfoStruct->pBuffer );
  135. pInfoStruct->pBuffer = NULL;
  136. }
  137. }
  138. }
  139. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  140. "DeviceEnum returned %d", dwRetCode );
  141. return( dwRetCode );
  142. }
  143. //**
  144. //
  145. // Call: DoStartRouter
  146. //
  147. // Returns: NO_ERROR - Success
  148. // Non-zero returns - Failure
  149. //
  150. // Description:
  151. //
  152. VOID
  153. DoStartRouter(
  154. IN PVOID pParameter
  155. )
  156. {
  157. DWORD dwRetCode = NO_ERROR;
  158. DWORD dwIndex = gblDIMConfigInfo.dwNumRouterManagers;
  159. ROUTER_INTERFACE_OBJECT * pIfObject;
  160. START_ROUTER_DATA * pStartRouterData = (START_ROUTER_DATA *)pParameter;
  161. DWORD (*StartRouter)(
  162. IN OUT DIM_ROUTER_INTERFACE * pDimRouterIf,
  163. IN BOOL fLANModeOnly,
  164. IN LPVOID pGlobalInfo );
  165. //
  166. // Wait for setup to finsh
  167. //
  168. Sleep( 15000 );
  169. //
  170. // Load the StartRouter
  171. //
  172. StartRouter = (PVOID)GetProcAddress( gblRouterManagers[dwIndex].hModule,
  173. "StartRouter" );
  174. if ( StartRouter == NULL )
  175. {
  176. if ( pStartRouterData->pInterfaceInfo != NULL )
  177. {
  178. LOCAL_FREE( pStartRouterData->pInterfaceInfo );
  179. }
  180. if ( pStartRouterData->pGlobalInfo != NULL )
  181. {
  182. LOCAL_FREE( pStartRouterData->pGlobalInfo );
  183. }
  184. LOCAL_FREE( pStartRouterData );
  185. return;
  186. }
  187. gblRouterManagers[dwIndex].DdmRouterIf.ConnectInterface
  188. = DIMConnectInterface;
  189. gblRouterManagers[dwIndex].DdmRouterIf.DisconnectInterface
  190. = DIMDisconnectInterface;
  191. gblRouterManagers[dwIndex].DdmRouterIf.SaveInterfaceInfo
  192. = DIMSaveInterfaceInfo;
  193. gblRouterManagers[dwIndex].DdmRouterIf.RestoreInterfaceInfo
  194. = DIMRestoreInterfaceInfo;
  195. gblRouterManagers[dwIndex].DdmRouterIf.SaveGlobalInfo
  196. = DIMSaveGlobalInfo;
  197. gblRouterManagers[dwIndex].DdmRouterIf.RouterStopped
  198. = DIMRouterStopped;
  199. gblRouterManagers[dwIndex].DdmRouterIf.InterfaceEnabled
  200. = DIMInterfaceEnabled;
  201. dwRetCode = (*StartRouter)(
  202. &(gblRouterManagers[dwIndex].DdmRouterIf),
  203. gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN,
  204. pStartRouterData->pGlobalInfo );
  205. if ( dwRetCode != NO_ERROR )
  206. {
  207. DIMTRACE1( "Start Router failed with %d", dwRetCode );
  208. if ( pStartRouterData->pInterfaceInfo != NULL )
  209. {
  210. LOCAL_FREE( pStartRouterData->pInterfaceInfo );
  211. }
  212. if ( pStartRouterData->pGlobalInfo != NULL )
  213. {
  214. LOCAL_FREE( pStartRouterData->pGlobalInfo );
  215. }
  216. LOCAL_FREE( pStartRouterData );
  217. return;
  218. }
  219. //
  220. // Save the global client info
  221. //
  222. if ( pStartRouterData->pInterfaceInfo == NULL )
  223. {
  224. gblRouterManagers[dwIndex].pDefaultClientInterface = NULL;
  225. gblRouterManagers[dwIndex].dwDefaultClientInterfaceSize = 0;
  226. }
  227. else
  228. {
  229. LPBYTE lpData = LOCAL_ALLOC(LPTR,pStartRouterData->dwInterfaceInfoSize);
  230. if ( lpData == NULL )
  231. {
  232. if ( pStartRouterData->pInterfaceInfo != NULL )
  233. {
  234. LOCAL_FREE( pStartRouterData->pInterfaceInfo );
  235. }
  236. if ( pStartRouterData->pGlobalInfo != NULL )
  237. {
  238. LOCAL_FREE( pStartRouterData->pGlobalInfo );
  239. }
  240. LOCAL_FREE( pStartRouterData );
  241. return;
  242. }
  243. CopyMemory( lpData,
  244. pStartRouterData->pInterfaceInfo,
  245. pStartRouterData->dwInterfaceInfoSize );
  246. gblRouterManagers[dwIndex].pDefaultClientInterface = lpData;
  247. gblRouterManagers[dwIndex].dwDefaultClientInterfaceSize
  248. = pStartRouterData->dwInterfaceInfoSize;
  249. }
  250. gblRouterManagers[dwIndex].fIsRunning = TRUE;
  251. gblDIMConfigInfo.dwNumRouterManagers++;
  252. //
  253. // Register all interfaces with the router manager
  254. //
  255. AddInterfacesToRouterManager( NULL, pStartRouterData->dwTransportId );
  256. //
  257. // Notify router manager that all interfaces have been added to the
  258. // router
  259. //
  260. gblRouterManagers[dwIndex].DdmRouterIf.RouterBootComplete();
  261. if ( gblDIMConfigInfo.dwRouterRole != ROUTER_ROLE_LAN )
  262. {
  263. DWORD (*DDMTransportCreate)( DWORD ) =
  264. (DWORD(*)( DWORD ))GetDDMEntryPoint("DDMTransportCreate");
  265. if(NULL == DDMTransportCreate)
  266. {
  267. return ;
  268. }
  269. DDMTransportCreate( pStartRouterData->dwTransportId );
  270. }
  271. //
  272. // We can only make this call while not holding the interface table
  273. // lock
  274. //
  275. DIMTRACE( "Setting router attributes in the identity object" );
  276. RouterIdentityObjectUpdateAttributes( FALSE, FALSE );
  277. if ( pStartRouterData->pInterfaceInfo != NULL )
  278. {
  279. LOCAL_FREE( pStartRouterData->pInterfaceInfo );
  280. }
  281. if ( pStartRouterData->pGlobalInfo != NULL )
  282. {
  283. LOCAL_FREE( pStartRouterData->pGlobalInfo );
  284. }
  285. LOCAL_FREE( pStartRouterData );
  286. }
  287. //**
  288. //
  289. // Call: RRouterInterfaceTransportCreate
  290. //
  291. // Returns: NO_ERROR - Success
  292. // Non-zero returns - Failure
  293. //
  294. // Description:
  295. //
  296. DWORD
  297. RRouterInterfaceTransportCreate(
  298. IN MPR_SERVER_HANDLE hMprServer,
  299. IN DWORD dwTransportId,
  300. IN LPWSTR lpwsTransportName,
  301. IN PDIM_INTERFACE_CONTAINER pInfoStruct,
  302. IN LPWSTR lpwsDLLPath
  303. )
  304. {
  305. DWORD dwAccessStatus = 0;
  306. DWORD dwRetCode = NO_ERROR;
  307. DWORD dwIndex = gblDIMConfigInfo.dwNumRouterManagers;
  308. START_ROUTER_DATA * pStartRouterData = NULL;
  309. //
  310. // Check if caller has access
  311. //
  312. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  313. {
  314. return( ERROR_ACCESS_DENIED );
  315. }
  316. if ( dwAccessStatus )
  317. {
  318. return( ERROR_ACCESS_DENIED );
  319. }
  320. if ( GetTransportIndex( dwTransportId ) != (DWORD) -1 )
  321. {
  322. return( ERROR_PROTOCOL_ALREADY_INSTALLED );
  323. }
  324. if ( ( dwTransportId == PID_IP ) || ( dwTransportId == PID_IPX ) )
  325. {
  326. DWORD cbSize = 0;
  327. WCHAR * pDllExpandedPath = NULL;
  328. //
  329. // Replace the %SystemRoot% with the actual path.
  330. //
  331. cbSize = ExpandEnvironmentStrings( lpwsDLLPath, NULL, 0 );
  332. if ( cbSize == 0 )
  333. {
  334. return( GetLastError() );
  335. }
  336. else
  337. {
  338. cbSize *= sizeof( WCHAR );
  339. }
  340. pDllExpandedPath = (LPWSTR)LOCAL_ALLOC( LPTR, cbSize*sizeof(WCHAR) );
  341. if ( pDllExpandedPath == (LPWSTR)NULL )
  342. {
  343. return( GetLastError() );
  344. }
  345. cbSize = ExpandEnvironmentStrings( lpwsDLLPath,
  346. pDllExpandedPath,
  347. cbSize );
  348. if ( cbSize == 0 )
  349. {
  350. LOCAL_FREE( pDllExpandedPath );
  351. return( GetLastError() );
  352. }
  353. //
  354. // Load the DLL
  355. //
  356. gblRouterManagers[dwIndex].hModule = LoadLibrary( pDllExpandedPath );
  357. LOCAL_FREE( pDllExpandedPath );
  358. if ( gblRouterManagers[dwIndex].hModule == NULL )
  359. {
  360. return( GetLastError() );
  361. }
  362. pStartRouterData = LOCAL_ALLOC( LPTR, sizeof( START_ROUTER_DATA ) );
  363. if ( pStartRouterData == NULL )
  364. {
  365. return( GetLastError() );
  366. }
  367. pStartRouterData->dwTransportId = dwTransportId;
  368. pStartRouterData->dwInterfaceInfoSize = pInfoStruct->dwInterfaceInfoSize;
  369. if ( pStartRouterData->dwInterfaceInfoSize != 0 )
  370. {
  371. pStartRouterData->pInterfaceInfo = LOCAL_ALLOC( LPTR,
  372. pStartRouterData->dwInterfaceInfoSize );
  373. if ( pStartRouterData->pInterfaceInfo == NULL )
  374. {
  375. LOCAL_FREE( pStartRouterData );
  376. return( GetLastError() );
  377. }
  378. else
  379. {
  380. CopyMemory( pStartRouterData->pInterfaceInfo,
  381. pInfoStruct->pInterfaceInfo,
  382. pInfoStruct->dwInterfaceInfoSize );
  383. }
  384. }
  385. pStartRouterData->dwGlobalInfoSize = pInfoStruct->dwGlobalInfoSize;
  386. if ( pStartRouterData->dwGlobalInfoSize != 0 )
  387. {
  388. pStartRouterData->pGlobalInfo = LOCAL_ALLOC( LPTR,
  389. pStartRouterData->dwGlobalInfoSize );
  390. if ( pStartRouterData->pGlobalInfo == NULL )
  391. {
  392. if ( pStartRouterData->pInterfaceInfo != NULL )
  393. {
  394. LOCAL_FREE( pStartRouterData->pInterfaceInfo );
  395. }
  396. LOCAL_FREE( pStartRouterData );
  397. return( GetLastError() );
  398. }
  399. else
  400. {
  401. CopyMemory( pStartRouterData->pGlobalInfo,
  402. pInfoStruct->pGlobalInfo,
  403. pInfoStruct->dwGlobalInfoSize );
  404. }
  405. }
  406. //
  407. // Schedule this for 15 seconds after returning from this call since setup
  408. // may have a ways to go to complete doing all its installation.
  409. // This is a low risk fix to
  410. //
  411. RtlQueueWorkItem( DoStartRouter, pStartRouterData, WT_EXECUTEDEFAULT );
  412. }
  413. return( NO_ERROR );
  414. }
  415. //**
  416. //
  417. // Call: RRouterInterfaceTransportSetGlobalInfo
  418. //
  419. // Returns: NO_ERROR - Success
  420. // ERROR_ACCESS_DENIED
  421. // ERROR_UNKNOWN_PROTOCOL_ID
  422. // non-zero returns from SetGlobalInfo
  423. //
  424. // Description: Simply called the appropriate router manager to do the real
  425. // work.
  426. //
  427. DWORD
  428. RRouterInterfaceTransportSetGlobalInfo(
  429. IN MPR_SERVER_HANDLE hMprServer,
  430. IN DWORD dwTransportId,
  431. IN PDIM_INTERFACE_CONTAINER pInfoStruct
  432. )
  433. {
  434. LPBYTE lpData;
  435. DWORD dwAccessStatus = 0;
  436. DWORD dwRetCode = NO_ERROR;
  437. DWORD dwTransportIndex = GetTransportIndex( dwTransportId );
  438. BOOL fGlobalDataUpdated = FALSE;
  439. //
  440. // Check if caller has access
  441. //
  442. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  443. {
  444. return( ERROR_ACCESS_DENIED );
  445. }
  446. if ( dwAccessStatus )
  447. {
  448. return( ERROR_ACCESS_DENIED );
  449. }
  450. if ( dwTransportIndex == (DWORD)-1 )
  451. {
  452. return( ERROR_UNKNOWN_PROTOCOL_ID );
  453. }
  454. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  455. do
  456. {
  457. if ( pInfoStruct->pGlobalInfo != NULL )
  458. {
  459. dwRetCode =
  460. gblRouterManagers[dwTransportIndex].DdmRouterIf.SetGlobalInfo(
  461. pInfoStruct->pGlobalInfo );
  462. if ( dwRetCode != NO_ERROR )
  463. {
  464. break;
  465. }
  466. //
  467. // Update router identity object since we may be adding or
  468. // removing a routing protocol
  469. //
  470. fGlobalDataUpdated = TRUE;
  471. }
  472. if ( pInfoStruct->pInterfaceInfo != NULL )
  473. {
  474. lpData=gblRouterManagers[dwTransportIndex].pDefaultClientInterface;
  475. if ( lpData != NULL )
  476. {
  477. LOCAL_FREE( lpData );
  478. }
  479. lpData = LOCAL_ALLOC( LPTR, pInfoStruct->dwInterfaceInfoSize );
  480. if ( lpData == NULL )
  481. {
  482. dwRetCode = GetLastError();
  483. break;
  484. }
  485. CopyMemory( lpData,
  486. pInfoStruct->pInterfaceInfo,
  487. pInfoStruct->dwInterfaceInfoSize );
  488. gblRouterManagers[dwTransportIndex].pDefaultClientInterface=lpData;
  489. gblRouterManagers[dwTransportIndex].dwDefaultClientInterfaceSize
  490. = pInfoStruct->dwInterfaceInfoSize;
  491. }
  492. }while( FALSE );
  493. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  494. if ( ( dwRetCode == NO_ERROR ) && ( fGlobalDataUpdated ) )
  495. {
  496. //
  497. // We can only make this call while not holding the interface table
  498. // lock
  499. //
  500. RouterIdentityObjectUpdateAttributes( FALSE, FALSE );
  501. }
  502. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  503. "SetGlobalInfo returned %d", dwRetCode );
  504. return( dwRetCode );
  505. }
  506. //**
  507. //
  508. // Call: RRouterInterfaceTransportGetGlobalInfo
  509. //
  510. // Returns: NO_ERROR - Success
  511. // ERROR_ACCESS_DENIED
  512. // ERROR_UNKNOWN_PROTOCOL_ID
  513. // non-zero returns from GetGlobalInfo
  514. //
  515. // Description: Simply called the appropriate router manager to do the real
  516. // work.
  517. //
  518. DWORD
  519. RRouterInterfaceTransportGetGlobalInfo(
  520. IN MPR_SERVER_HANDLE hMprServer,
  521. IN DWORD dwTransportId,
  522. IN PDIM_INTERFACE_CONTAINER pInfoStruct
  523. )
  524. {
  525. DWORD dwAccessStatus = 0;
  526. DWORD dwRetCode = NO_ERROR;
  527. DWORD dwTransportIndex = GetTransportIndex( dwTransportId );
  528. ULONG ulNumAttempts;
  529. //
  530. // Check if caller has access
  531. //
  532. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  533. {
  534. return( ERROR_ACCESS_DENIED );
  535. }
  536. if ( dwAccessStatus )
  537. {
  538. return( ERROR_ACCESS_DENIED );
  539. }
  540. if ( dwTransportIndex == (DWORD)-1 )
  541. {
  542. return( ERROR_UNKNOWN_PROTOCOL_ID );
  543. }
  544. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  545. do
  546. {
  547. if ( pInfoStruct->fGetGlobalInfo )
  548. {
  549. ulNumAttempts = 0;
  550. pInfoStruct->pGlobalInfo = NULL;
  551. do
  552. {
  553. //
  554. // The first iteration should get the size
  555. // The second iteration should get the info.
  556. // iteration 3 is only required if the
  557. // size of the info. changes between first and
  558. // second iteration.
  559. // of course the size can change between iteration
  560. // 2 and 3 and so on. So we try MAX_GET_INFO_RETRIES
  561. // many times and quit if we still have not
  562. // successfully retrieved the info.
  563. //
  564. dwRetCode =
  565. gblRouterManagers[dwTransportIndex].DdmRouterIf.GetGlobalInfo(
  566. pInfoStruct->pGlobalInfo,
  567. &(pInfoStruct->dwGlobalInfoSize) );
  568. TracePrintfExA(
  569. gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  570. "GetGlobalInfo: Transport %d requires size %d, result %d",
  571. dwTransportIndex, pInfoStruct->dwGlobalInfoSize,
  572. dwRetCode
  573. );
  574. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  575. {
  576. break;
  577. }
  578. //
  579. // release previous allocation
  580. //
  581. if ( ulNumAttempts )
  582. {
  583. MIDL_user_free( pInfoStruct->pGlobalInfo );
  584. pInfoStruct-> pGlobalInfo = NULL;
  585. }
  586. if ( pInfoStruct->dwGlobalInfoSize > 0 )
  587. {
  588. pInfoStruct->pGlobalInfo =
  589. MIDL_user_allocate( pInfoStruct->dwGlobalInfoSize );
  590. if ( pInfoStruct->pGlobalInfo == NULL )
  591. {
  592. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  593. break;
  594. }
  595. }
  596. else
  597. {
  598. break;
  599. }
  600. ulNumAttempts++;
  601. } while ( (dwRetCode == ERROR_INSUFFICIENT_BUFFER) &&
  602. (ulNumAttempts < MAX_GET_INFO_RETRIES) );
  603. }
  604. if ( dwRetCode != NO_ERROR )
  605. {
  606. break;
  607. }
  608. if ((gblRouterManagers[dwTransportIndex].dwDefaultClientInterfaceSize>0)
  609. && ( pInfoStruct->fGetInterfaceInfo ) )
  610. {
  611. pInfoStruct->dwInterfaceInfoSize =
  612. gblRouterManagers[dwTransportIndex].dwDefaultClientInterfaceSize;
  613. pInfoStruct->pInterfaceInfo =
  614. MIDL_user_allocate(pInfoStruct->dwInterfaceInfoSize);
  615. if ( pInfoStruct->pInterfaceInfo == NULL )
  616. {
  617. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  618. break;
  619. }
  620. CopyMemory(
  621. pInfoStruct->pInterfaceInfo,
  622. gblRouterManagers[dwTransportIndex].pDefaultClientInterface,
  623. pInfoStruct->dwInterfaceInfoSize );
  624. }
  625. }while( FALSE );
  626. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  627. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  628. "GetGlobalInfo returned %d", dwRetCode );
  629. return( dwRetCode );
  630. }
  631. //**
  632. //
  633. // Call: InterfaceAjustVLSPointers
  634. //
  635. // Returns: none
  636. //
  637. // Description: Adjusts pointers in variable length structures
  638. // dealing with interface info
  639. //
  640. DWORD
  641. InterfaceAjustVLSPointers (
  642. DWORD dwLevel,
  643. LPBYTE lpbBuffer)
  644. {
  645. if ( dwLevel == 1 )
  646. {
  647. MPRI_INTERFACE_1 * pIf1 = (MPRI_INTERFACE_1*)lpbBuffer;
  648. if ( pIf1->dwDialoutHoursRestrictionOffset )
  649. {
  650. pIf1->dwDialoutHoursRestrictionOffset = sizeof(MPRI_INTERFACE_1);
  651. }
  652. }
  653. else if ( dwLevel == 2 )
  654. {
  655. MPRI_INTERFACE_2 * pIf2 = (MPRI_INTERFACE_2*)lpbBuffer;
  656. DWORD dwOffset = 0;
  657. // Adjust the custom auth data pointer
  658. //
  659. dwOffset += sizeof(MPRI_INTERFACE_2);
  660. if ( pIf2->dwCustomAuthDataSize )
  661. {
  662. pIf2->dwCustomAuthDataOffset = dwOffset;
  663. }
  664. // Adjust the alternates list pointer
  665. //
  666. dwOffset += pIf2->dwCustomAuthDataSize;
  667. if ( pIf2->dwAlternatesOffset )
  668. {
  669. pIf2->dwAlternatesOffset = dwOffset;
  670. }
  671. }
  672. return NO_ERROR;
  673. }
  674. //**
  675. //
  676. // Call: GetMprInterface0Data
  677. //
  678. // Returns: none
  679. //
  680. // Description: Given a pointer to an interface object will fill an
  681. // MPR_INTERFACE_0 structure appropriately.
  682. //
  683. VOID
  684. GetMprInterface0Data(
  685. IN ROUTER_INTERFACE_OBJECT * pIfObject,
  686. OUT MPRI_INTERFACE_0 * pMprIf0
  687. )
  688. {
  689. wcscpy( pMprIf0->wszInterfaceName, pIfObject->lpwsInterfaceName );
  690. pMprIf0->dwIfType = pIfObject->IfType;
  691. pMprIf0->dwInterface = PtrToUlong(pIfObject->hDIMInterface);
  692. pMprIf0->dwLastError = pIfObject->dwLastError;
  693. pMprIf0->fEnabled = ( pIfObject->fFlags & IFFLAG_ENABLED );
  694. pMprIf0->fUnReachabilityReasons =
  695. ( pIfObject->fFlags & IFFLAG_OUT_OF_RESOURCES )
  696. ? MPR_INTERFACE_OUT_OF_RESOURCES : 0;
  697. if ( !( pIfObject->fFlags & IFFLAG_ENABLED ) )
  698. {
  699. pMprIf0->fUnReachabilityReasons |= MPR_INTERFACE_ADMIN_DISABLED;
  700. }
  701. if ( gblDIMConfigInfo.ServiceStatus.dwCurrentState == SERVICE_PAUSED )
  702. {
  703. pMprIf0->fUnReachabilityReasons |= MPR_INTERFACE_SERVICE_PAUSED;
  704. }
  705. if ( pIfObject->fFlags & IFFLAG_CONNECTION_FAILURE )
  706. {
  707. pMprIf0->fUnReachabilityReasons |= MPR_INTERFACE_CONNECTION_FAILURE;
  708. }
  709. if ( pIfObject->fFlags & IFFLAG_DIALOUT_HOURS_RESTRICTION )
  710. {
  711. pMprIf0->fUnReachabilityReasons |=
  712. MPR_INTERFACE_DIALOUT_HOURS_RESTRICTION;
  713. }
  714. if ( pIfObject->fFlags & IFFLAG_NO_MEDIA_SENSE )
  715. {
  716. pMprIf0->fUnReachabilityReasons |= MPR_INTERFACE_NO_MEDIA_SENSE;
  717. }
  718. switch( pIfObject->State )
  719. {
  720. case RISTATE_CONNECTED:
  721. pMprIf0->dwConnectionState = ROUTER_IF_STATE_CONNECTED;
  722. break;
  723. case RISTATE_DISCONNECTED:
  724. if ( pMprIf0->fUnReachabilityReasons != 0 )
  725. {
  726. pMprIf0->dwConnectionState = ROUTER_IF_STATE_UNREACHABLE;
  727. }
  728. else
  729. {
  730. pMprIf0->dwConnectionState = ROUTER_IF_STATE_DISCONNECTED;
  731. }
  732. break;
  733. case RISTATE_CONNECTING:
  734. pMprIf0->dwConnectionState = ROUTER_IF_STATE_CONNECTING;
  735. break;
  736. }
  737. }
  738. //**
  739. //
  740. // Call: GetMprInterfaceData
  741. //
  742. // Returns: none
  743. //
  744. // Description: Given a pointer to an interface object will fill an
  745. // MPRI_INTERFACE_* structure appropriately.
  746. //
  747. LPBYTE
  748. GetMprInterfaceData(
  749. IN ROUTER_INTERFACE_OBJECT * pIfObject,
  750. IN DWORD dwLevel,
  751. OUT LPDWORD lpdwcbSizeOfData
  752. )
  753. {
  754. DWORD cbDialoutHoursRestriction = 0;
  755. DWORD dwErr;
  756. MPRI_INTERFACE_0 * pMprIf0 = NULL;
  757. MPRI_INTERFACE_1 * pIf1 = NULL;
  758. LPBYTE pInterfaceData = NULL;
  759. HANDLE hEntry = NULL;
  760. switch ( dwLevel )
  761. {
  762. // Basic
  763. //
  764. case 0:
  765. *lpdwcbSizeOfData = sizeof( MPRI_INTERFACE_0 );
  766. dwErr = NO_ERROR;
  767. break;
  768. // Basic plus dialout hours restriction
  769. //
  770. case 1:
  771. *lpdwcbSizeOfData = sizeof( MPRI_INTERFACE_1 );
  772. if ( pIfObject->lpwsDialoutHoursRestriction != NULL )
  773. {
  774. cbDialoutHoursRestriction =
  775. GetSizeOfDialoutHoursRestriction(
  776. pIfObject->lpwsDialoutHoursRestriction);
  777. *lpdwcbSizeOfData += cbDialoutHoursRestriction;
  778. }
  779. dwErr = NO_ERROR;
  780. break;
  781. // Basic plus router phonebook entry info
  782. //
  783. case 2:
  784. dwErr = RpbkOpenEntry(pIfObject, &hEntry);
  785. if (dwErr == NO_ERROR)
  786. {
  787. dwErr = RpbkEntryToIfDataSize(
  788. hEntry,
  789. dwLevel,
  790. lpdwcbSizeOfData);
  791. }
  792. break;
  793. }
  794. if (dwErr != NO_ERROR)
  795. {
  796. return( NULL );
  797. }
  798. do
  799. {
  800. // Allocate the return value
  801. pInterfaceData = MIDL_user_allocate( *lpdwcbSizeOfData );
  802. if ( pInterfaceData == NULL )
  803. {
  804. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  805. break;
  806. }
  807. //
  808. // Add any appropriate information
  809. //
  810. switch ( dwLevel )
  811. {
  812. case 0:
  813. GetMprInterface0Data( pIfObject, (MPRI_INTERFACE_0 *)pInterfaceData );
  814. break;
  815. case 1:
  816. GetMprInterface0Data( pIfObject, (MPRI_INTERFACE_0 *)pInterfaceData );
  817. pIf1 = (MPRI_INTERFACE_1*)pInterfaceData;
  818. if ( pIfObject->lpwsDialoutHoursRestriction != NULL )
  819. {
  820. CopyMemory( pIf1 + 1,
  821. pIfObject->lpwsDialoutHoursRestriction,
  822. cbDialoutHoursRestriction );
  823. pIf1->dwDialoutHoursRestrictionOffset = TRUE;
  824. }
  825. else
  826. {
  827. pIf1->dwDialoutHoursRestrictionOffset = 0;
  828. }
  829. break;
  830. case 2:
  831. GetMprInterface0Data( pIfObject, (MPRI_INTERFACE_0 *)pInterfaceData );
  832. dwErr = RpbkEntryToIfData(
  833. hEntry,
  834. dwLevel,
  835. pInterfaceData );
  836. break;
  837. }
  838. } while (FALSE);
  839. // Cleanup
  840. {
  841. if ( dwErr != NO_ERROR )
  842. {
  843. if ( pInterfaceData )
  844. {
  845. MIDL_user_free( pInterfaceData );
  846. }
  847. }
  848. if ( hEntry )
  849. {
  850. RpbkCloseEntry( hEntry );
  851. }
  852. }
  853. return( pInterfaceData );
  854. }
  855. //**
  856. //
  857. // Call: GetMprInterfaceData
  858. //
  859. // Returns: none
  860. //
  861. // Description: Given a pointer to an interface object will fill an
  862. // MPR_INTERFACE_* structure appropriately.
  863. //
  864. DWORD
  865. GetMprInterfaceDeviceData(
  866. IN ROUTER_INTERFACE_OBJECT * pIfObject,
  867. IN DWORD dwIndex,
  868. IN DWORD dwLevel,
  869. OUT LPDWORD lpdwcbSizeOfData,
  870. OUT LPBYTE* lplpbReturn
  871. )
  872. {
  873. DWORD dwErr = NO_ERROR;
  874. LPBYTE pDevData = NULL;
  875. HANDLE hSubEntry = NULL;
  876. *lplpbReturn = NULL;
  877. switch ( dwLevel )
  878. {
  879. // Basic
  880. //
  881. case 0:
  882. *lpdwcbSizeOfData = sizeof( MPR_DEVICE_0 );
  883. dwErr = NO_ERROR;
  884. break;
  885. // Basic plus phone numbers
  886. //
  887. case 1:
  888. dwErr = RpbkOpenSubEntry(pIfObject, dwIndex, &hSubEntry);
  889. if (dwErr == NO_ERROR)
  890. {
  891. dwErr = RpbkSubEntryToDevDataSize(
  892. hSubEntry,
  893. dwLevel,
  894. lpdwcbSizeOfData);
  895. }
  896. break;
  897. }
  898. if (dwErr != NO_ERROR)
  899. {
  900. return( dwErr );
  901. }
  902. do
  903. {
  904. // Allocate the return value
  905. //
  906. pDevData = MIDL_user_allocate( *lpdwcbSizeOfData );
  907. if ( pDevData == NULL )
  908. {
  909. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  910. break;
  911. }
  912. //
  913. // Add any appropriate information
  914. //
  915. switch ( dwLevel )
  916. {
  917. case 0:
  918. case 1:
  919. dwErr = RpbkSubEntryToDevData(
  920. hSubEntry,
  921. dwLevel,
  922. pDevData );
  923. break;
  924. }
  925. } while (FALSE);
  926. // Cleanup
  927. {
  928. if ( hSubEntry )
  929. {
  930. RpbkCloseSubEntry( hSubEntry );
  931. }
  932. if ( dwErr != NO_ERROR )
  933. {
  934. if ( pDevData )
  935. {
  936. MIDL_user_free( pDevData );
  937. }
  938. }
  939. else
  940. {
  941. *lplpbReturn = pDevData;
  942. }
  943. }
  944. return( dwErr );
  945. }
  946. //**
  947. //
  948. // Call: RRouterInterfaceCreate
  949. //
  950. // Returns: NO_ERROR - Success
  951. // ERROR_ACCESS_DENIED
  952. // ERROR_NOT_SUPPORTED
  953. //
  954. // Description: Creates an interface with DIM.
  955. //
  956. DWORD
  957. RRouterInterfaceCreate(
  958. IN MPR_SERVER_HANDLE hMprServer,
  959. IN DWORD dwLevel,
  960. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  961. IN LPDWORD phInterface
  962. )
  963. {
  964. DWORD dwAccessStatus;
  965. ROUTER_INTERFACE_OBJECT * pIfObject;
  966. DWORD IfState;
  967. DWORD dwRetCode = NO_ERROR;
  968. LPWSTR lpwsDialoutHoursRestriction = NULL;
  969. BOOL fLANInterfaceAdded = FALSE;
  970. MPRI_INTERFACE_0 * pMprIf0 =
  971. (MPRI_INTERFACE_0*)pInfoStruct->pBuffer;
  972. MPRI_INTERFACE_1 * pMprIf1 =
  973. (MPRI_INTERFACE_1*)pInfoStruct->pBuffer;
  974. MPRI_INTERFACE_2 * pMprIf2 =
  975. (MPRI_INTERFACE_2*)pInfoStruct->pBuffer;
  976. //
  977. // Check if caller has access
  978. //
  979. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  980. {
  981. return( ERROR_ACCESS_DENIED );
  982. }
  983. if ( dwAccessStatus )
  984. {
  985. return( ERROR_ACCESS_DENIED );
  986. }
  987. if ( ( (int) dwLevel < 0 ) || ( dwLevel > 2 ) )
  988. {
  989. return( ERROR_NOT_SUPPORTED );
  990. }
  991. if ( pMprIf0->dwIfType == ROUTER_IF_TYPE_TUNNEL1)
  992. {
  993. return( ERROR_NOT_SUPPORTED );
  994. }
  995. //
  996. // Adjust the given buffer for any pointers to
  997. // variable length data.
  998. //
  999. InterfaceAjustVLSPointers ( dwLevel, pInfoStruct->pBuffer );
  1000. if ( ( pMprIf0->dwIfType == ROUTER_IF_TYPE_DEDICATED ) ||
  1001. ( pMprIf0->dwIfType == ROUTER_IF_TYPE_INTERNAL ) ||
  1002. ( pMprIf0->dwIfType == ROUTER_IF_TYPE_LOOPBACK ) ||
  1003. ( pMprIf0->dwIfType == ROUTER_IF_TYPE_TUNNEL1 ) )
  1004. {
  1005. IfState = RISTATE_CONNECTED;
  1006. if ( !pMprIf0->fEnabled )
  1007. {
  1008. return( ERROR_INVALID_PARAMETER );
  1009. }
  1010. //
  1011. // Update router identity object since we are adding a LAN interface
  1012. //
  1013. fLANInterfaceAdded = TRUE;
  1014. }
  1015. else if ( ( pMprIf0->dwIfType == ROUTER_IF_TYPE_CLIENT ) ||
  1016. ( pMprIf0->dwIfType == ROUTER_IF_TYPE_HOME_ROUTER ) ||
  1017. ( pMprIf0->dwIfType == ROUTER_IF_TYPE_FULL_ROUTER ) )
  1018. {
  1019. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  1020. {
  1021. return( ERROR_DDM_NOT_RUNNING );
  1022. }
  1023. else
  1024. {
  1025. IfState = RISTATE_DISCONNECTED;
  1026. }
  1027. }
  1028. else
  1029. {
  1030. return( ERROR_INVALID_PARAMETER );
  1031. }
  1032. if ( dwLevel == 1 )
  1033. {
  1034. if ( pMprIf1->dwDialoutHoursRestrictionOffset != 0 )
  1035. {
  1036. DWORD cbDialoutHoursRestriction;
  1037. cbDialoutHoursRestriction =
  1038. GetSizeOfDialoutHoursRestriction((LPWSTR)(pMprIf1 + 1));
  1039. DIMTRACE1(
  1040. "Creating l1 interface with %d bytes of dohr",
  1041. cbDialoutHoursRestriction);
  1042. lpwsDialoutHoursRestriction =
  1043. LOCAL_ALLOC( LPTR, cbDialoutHoursRestriction );
  1044. if ( lpwsDialoutHoursRestriction == NULL )
  1045. {
  1046. return( GetLastError() );
  1047. }
  1048. }
  1049. }
  1050. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1051. do
  1052. {
  1053. if ( pMprIf0->dwIfType != ROUTER_IF_TYPE_CLIENT )
  1054. {
  1055. //
  1056. // Check for duplicates if we are not adding a client interface
  1057. //
  1058. pIfObject = IfObjectGetPointerByName( pMprIf0->wszInterfaceName,
  1059. FALSE );
  1060. if ( pIfObject != NULL )
  1061. {
  1062. dwRetCode = ERROR_INTERFACE_ALREADY_EXISTS;
  1063. break;
  1064. }
  1065. }
  1066. //
  1067. // If phonebook information is being specified, set it
  1068. // before continuing
  1069. //
  1070. if (dwLevel == 2)
  1071. {
  1072. dwRetCode = RpbkSetEntry(dwLevel, (LPBYTE)pMprIf2);
  1073. if (dwRetCode != NO_ERROR)
  1074. {
  1075. break;
  1076. }
  1077. }
  1078. pIfObject = IfObjectAllocateAndInit(
  1079. pMprIf0->wszInterfaceName,
  1080. IfState,
  1081. pMprIf0->dwIfType,
  1082. (HCONN)0,
  1083. pMprIf0->fEnabled,
  1084. 600,
  1085. 21600,
  1086. lpwsDialoutHoursRestriction );
  1087. if ( pIfObject == NULL )
  1088. {
  1089. dwRetCode = GetLastError();
  1090. break;
  1091. }
  1092. if ( ( dwRetCode = IfObjectInsertInTable( pIfObject ) ) != NO_ERROR )
  1093. {
  1094. LOCAL_FREE( pIfObject );
  1095. break;
  1096. }
  1097. *phInterface = PtrToUlong(pIfObject->hDIMInterface);
  1098. if ( lpwsDialoutHoursRestriction != NULL )
  1099. {
  1100. VOID (*IfObjectSetDialoutHoursRestriction)(
  1101. ROUTER_INTERFACE_OBJECT * ) =
  1102. (VOID(*)( ROUTER_INTERFACE_OBJECT *))
  1103. GetDDMEntryPoint("IfObjectSetDialoutHoursRestriction");
  1104. //
  1105. // Set dialout hours restriction if there was one
  1106. //
  1107. IfObjectSetDialoutHoursRestriction( pIfObject );
  1108. }
  1109. }while( FALSE );
  1110. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1111. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1112. "InterfaceCreate returned %d", dwRetCode );
  1113. if ( dwRetCode != NO_ERROR )
  1114. {
  1115. if ( lpwsDialoutHoursRestriction != NULL )
  1116. {
  1117. //
  1118. // If there was some error then free this memory
  1119. //
  1120. LOCAL_FREE( lpwsDialoutHoursRestriction );
  1121. }
  1122. }
  1123. else
  1124. {
  1125. if ( fLANInterfaceAdded )
  1126. {
  1127. //
  1128. // Can only call this API while not holding the interface lock
  1129. //
  1130. RouterIdentityObjectUpdateAttributes( FALSE, FALSE );
  1131. }
  1132. }
  1133. return( dwRetCode );
  1134. }
  1135. //**
  1136. //
  1137. // Call: RRouterInterfaceGetInfo
  1138. //
  1139. // Returns: NO_ERROR - Success
  1140. // ERROR_ACCESS_DENIED
  1141. // ERROR_NOT_SUPPORTED
  1142. //
  1143. // Description: Gets information about a DIM interface.
  1144. //
  1145. DWORD
  1146. RRouterInterfaceGetInfo(
  1147. IN MPR_SERVER_HANDLE hMprServer,
  1148. IN DWORD dwLevel,
  1149. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  1150. IN DWORD hInterface
  1151. )
  1152. {
  1153. DWORD dwAccessStatus;
  1154. ROUTER_INTERFACE_OBJECT * pIfObject;
  1155. DWORD dwRetCode = NO_ERROR;
  1156. //
  1157. // Check if caller has access
  1158. //
  1159. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1160. {
  1161. return( ERROR_ACCESS_DENIED );
  1162. }
  1163. if ( dwAccessStatus )
  1164. {
  1165. return( ERROR_ACCESS_DENIED );
  1166. }
  1167. if ( ( (int) dwLevel < 0 ) || ( dwLevel > 2 ) )
  1168. {
  1169. return( ERROR_NOT_SUPPORTED );
  1170. }
  1171. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1172. do
  1173. {
  1174. if ( ( pIfObject = IfObjectGetPointer(
  1175. DimIndexToHandle(hInterface)) ) == NULL )
  1176. {
  1177. dwRetCode = ERROR_INVALID_HANDLE;
  1178. break;
  1179. }
  1180. // pmay: 274487
  1181. //
  1182. // Validate the type of the interface against the level
  1183. //
  1184. if ( ( dwLevel == 2 ) &&
  1185. ( pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER ) )
  1186. {
  1187. dwRetCode = ERROR_INVALID_LEVEL;
  1188. break;
  1189. }
  1190. pInfoStruct->pBuffer = GetMprInterfaceData(
  1191. pIfObject,
  1192. dwLevel,
  1193. &(pInfoStruct->dwBufferSize) );
  1194. if ( pInfoStruct->pBuffer == NULL )
  1195. {
  1196. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1197. break;
  1198. }
  1199. }while( FALSE );
  1200. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1201. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1202. "InterfaceGetInfo returned %d", dwRetCode );
  1203. return( dwRetCode );
  1204. }
  1205. //**
  1206. //
  1207. // Call: RRouterInterfaceSetInfo
  1208. //
  1209. // Returns: NO_ERROR - Success
  1210. // ERROR_ACCESS_DENIED
  1211. // ERROR_NOT_SUPPORTED
  1212. //
  1213. // Description: Sets interface configuration information
  1214. //
  1215. DWORD
  1216. RRouterInterfaceSetInfo(
  1217. IN MPR_SERVER_HANDLE hMprServer,
  1218. IN DWORD dwLevel,
  1219. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  1220. IN DWORD hInterface
  1221. )
  1222. {
  1223. DWORD dwAccessStatus;
  1224. ROUTER_INTERFACE_OBJECT * pIfObject;
  1225. DWORD IfState;
  1226. DWORD dwRetCode = NO_ERROR;
  1227. BOOL fNotify = FALSE;
  1228. DWORD dwIndex;
  1229. MPRI_INTERFACE_0 * pMprIf0 =
  1230. (MPRI_INTERFACE_0*)pInfoStruct->pBuffer;
  1231. MPRI_INTERFACE_1 * pMprIf1 =
  1232. (MPRI_INTERFACE_1*)pInfoStruct->pBuffer;
  1233. MPRI_INTERFACE_2 * pMprIf2 =
  1234. (MPRI_INTERFACE_2*)pInfoStruct->pBuffer;
  1235. //
  1236. // Check if caller has access
  1237. //
  1238. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1239. {
  1240. return( ERROR_ACCESS_DENIED );
  1241. }
  1242. if ( dwAccessStatus )
  1243. {
  1244. return( ERROR_ACCESS_DENIED );
  1245. }
  1246. if ( ( (int) dwLevel < 0 ) || ( dwLevel > 2 ) )
  1247. {
  1248. return( ERROR_NOT_SUPPORTED );
  1249. }
  1250. //
  1251. // Adjust the given buffer for any pointers to
  1252. // variable length data.
  1253. //
  1254. InterfaceAjustVLSPointers ( dwLevel, pInfoStruct->pBuffer );
  1255. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1256. do
  1257. {
  1258. if ( ( pIfObject = IfObjectGetPointer(
  1259. DimIndexToHandle(hInterface)) ) == NULL )
  1260. {
  1261. dwRetCode = ERROR_INVALID_HANDLE;
  1262. break;
  1263. }
  1264. if ( ( pIfObject->IfType == ROUTER_IF_TYPE_DEDICATED ) ||
  1265. ( pIfObject->IfType == ROUTER_IF_TYPE_TUNNEL1 ) ||
  1266. ( pIfObject->IfType == ROUTER_IF_TYPE_INTERNAL ) )
  1267. {
  1268. if ( !pMprIf0->fEnabled )
  1269. {
  1270. dwRetCode = ERROR_INVALID_PARAMETER;
  1271. }
  1272. //
  1273. // Nothing can be set for these interfaces
  1274. //
  1275. break;
  1276. }
  1277. if ( pMprIf0->fEnabled )
  1278. {
  1279. if ( !( pIfObject->fFlags & IFFLAG_ENABLED ) )
  1280. {
  1281. pIfObject->fFlags |= IFFLAG_ENABLED;
  1282. fNotify = TRUE;
  1283. }
  1284. }
  1285. else
  1286. {
  1287. if ( pIfObject->fFlags & IFFLAG_ENABLED )
  1288. {
  1289. pIfObject->fFlags &= ~IFFLAG_ENABLED;
  1290. fNotify = TRUE;
  1291. }
  1292. if ( pIfObject->State != RISTATE_DISCONNECTED )
  1293. {
  1294. fNotify = FALSE;
  1295. }
  1296. }
  1297. if ( fNotify )
  1298. {
  1299. VOID (*IfObjectNotifyOfReachabilityChange)(
  1300. ROUTER_INTERFACE_OBJECT *,
  1301. BOOL,
  1302. UNREACHABILITY_REASON ) =
  1303. (VOID(*)( ROUTER_INTERFACE_OBJECT *,
  1304. BOOL,
  1305. UNREACHABILITY_REASON ))
  1306. GetDDMEntryPoint("IfObjectNotifyOfReachabilityChange");
  1307. if(NULL != IfObjectNotifyOfReachabilityChange)
  1308. {
  1309. IfObjectNotifyOfReachabilityChange( pIfObject,
  1310. pMprIf0->fEnabled,
  1311. INTERFACE_DISABLED );
  1312. }
  1313. }
  1314. //
  1315. // Check level 1 values
  1316. //
  1317. if ( dwLevel == 1 )
  1318. {
  1319. VOID (*IfObjectSetDialoutHoursRestriction)(
  1320. ROUTER_INTERFACE_OBJECT * ) =
  1321. (VOID(*)( ROUTER_INTERFACE_OBJECT *))
  1322. GetDDMEntryPoint("IfObjectSetDialoutHoursRestriction");
  1323. if ( pMprIf1->dwDialoutHoursRestrictionOffset == 0 )
  1324. {
  1325. if ( pIfObject->lpwsDialoutHoursRestriction != NULL )
  1326. {
  1327. LOCAL_FREE( pIfObject->lpwsDialoutHoursRestriction );
  1328. pIfObject->lpwsDialoutHoursRestriction = NULL;
  1329. IfObjectSetDialoutHoursRestriction( pIfObject );
  1330. }
  1331. }
  1332. else
  1333. {
  1334. DWORD cbDialoutHoursRestriction =
  1335. GetSizeOfDialoutHoursRestriction(
  1336. (LPWSTR)(pMprIf1 + 1) );
  1337. if ( pIfObject->lpwsDialoutHoursRestriction != NULL )
  1338. {
  1339. //
  1340. // Free currently allocated memory for dialout hours
  1341. //
  1342. LOCAL_FREE( pIfObject->lpwsDialoutHoursRestriction );
  1343. pIfObject->lpwsDialoutHoursRestriction = NULL;
  1344. }
  1345. DIMTRACE1(
  1346. "Setting info on l1 interface. %d bytes dohr",
  1347. cbDialoutHoursRestriction);
  1348. pIfObject->lpwsDialoutHoursRestriction =
  1349. LOCAL_ALLOC( LPTR, cbDialoutHoursRestriction );
  1350. if ( pIfObject->lpwsDialoutHoursRestriction == NULL )
  1351. {
  1352. dwRetCode = GetLastError();
  1353. break;
  1354. }
  1355. CopyMemory( pIfObject->lpwsDialoutHoursRestriction,
  1356. (LPBYTE)(pMprIf1 + 1),
  1357. cbDialoutHoursRestriction );
  1358. IfObjectSetDialoutHoursRestriction( pIfObject );
  1359. }
  1360. }
  1361. //
  1362. // Check level 2 values
  1363. //
  1364. else if ( dwLevel == 2 )
  1365. {
  1366. if (pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER)
  1367. {
  1368. dwRetCode = ERROR_INVALID_PARAMETER;
  1369. }
  1370. else
  1371. {
  1372. dwRetCode = RpbkSetEntry(dwLevel, (LPBYTE)pMprIf2);
  1373. }
  1374. }
  1375. }while( FALSE );
  1376. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1377. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1378. "InterfaceSetInfo returned %d", dwRetCode );
  1379. return( dwRetCode );
  1380. }
  1381. DWORD
  1382. RRouterInterfaceDeviceGetInfo(
  1383. IN MPR_SERVER_HANDLE hMprServer,
  1384. IN DWORD dwLevel,
  1385. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  1386. IN DWORD dwIndex,
  1387. IN DWORD hInterface
  1388. )
  1389. {
  1390. DWORD dwAccessStatus;
  1391. ROUTER_INTERFACE_OBJECT * pIfObject;
  1392. DWORD dwRetCode = NO_ERROR;
  1393. //
  1394. // Check if caller has access
  1395. //
  1396. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1397. {
  1398. return( ERROR_ACCESS_DENIED );
  1399. }
  1400. if ( dwAccessStatus )
  1401. {
  1402. return( ERROR_ACCESS_DENIED );
  1403. }
  1404. if ( ( (int) dwLevel < 0 ) || ( dwLevel > 1 ) )
  1405. {
  1406. return( ERROR_NOT_SUPPORTED );
  1407. }
  1408. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1409. do
  1410. {
  1411. if ( ( pIfObject = IfObjectGetPointer(
  1412. DimIndexToHandle(hInterface)) ) == NULL )
  1413. {
  1414. dwRetCode = ERROR_INVALID_HANDLE;
  1415. break;
  1416. }
  1417. dwRetCode = GetMprInterfaceDeviceData(
  1418. pIfObject,
  1419. dwIndex,
  1420. dwLevel,
  1421. &(pInfoStruct->dwBufferSize),
  1422. &(pInfoStruct->pBuffer));
  1423. if ( dwRetCode != NO_ERROR )
  1424. {
  1425. if ( dwRetCode == ERROR_CANNOT_FIND_PHONEBOOK_ENTRY )
  1426. {
  1427. dwRetCode = ERROR_DEV_NOT_EXIST;
  1428. }
  1429. break;
  1430. }
  1431. }while( FALSE );
  1432. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1433. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1434. "InterfaceDeviceGetInfo returned %d", dwRetCode );
  1435. return( dwRetCode );
  1436. }
  1437. DWORD
  1438. RRouterInterfaceDeviceSetInfo(
  1439. IN MPR_SERVER_HANDLE hMprServer,
  1440. IN DWORD dwLevel,
  1441. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  1442. IN DWORD dwIndex,
  1443. IN DWORD hInterface
  1444. )
  1445. {
  1446. DWORD dwAccessStatus;
  1447. ROUTER_INTERFACE_OBJECT * pIfObject;
  1448. DWORD dwRetCode = NO_ERROR;
  1449. MPR_DEVICE_0 * pDev0 =
  1450. (MPR_DEVICE_0*)pInfoStruct->pBuffer;
  1451. MPR_DEVICE_1 * pDev1 =
  1452. (MPR_DEVICE_1*)pInfoStruct->pBuffer;
  1453. //
  1454. // Check if caller has access
  1455. //
  1456. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1457. {
  1458. return( ERROR_ACCESS_DENIED );
  1459. }
  1460. if ( dwAccessStatus )
  1461. {
  1462. return( ERROR_ACCESS_DENIED );
  1463. }
  1464. if ( ( (int) dwLevel < 0 ) || ( dwLevel > 1 ) )
  1465. {
  1466. return( ERROR_NOT_SUPPORTED );
  1467. }
  1468. // Adjust the variable-length structure pointers
  1469. //
  1470. if ( dwLevel == 1 )
  1471. {
  1472. if ( pDev1->szAlternates )
  1473. {
  1474. pDev1->szAlternates = (PWCHAR)(pDev1 + 1);
  1475. }
  1476. }
  1477. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1478. do
  1479. {
  1480. if ( ( pIfObject = IfObjectGetPointer(
  1481. DimIndexToHandle(hInterface)) ) == NULL )
  1482. {
  1483. dwRetCode = ERROR_INVALID_HANDLE;
  1484. break;
  1485. }
  1486. //
  1487. // Set the subentry
  1488. //
  1489. if (pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER)
  1490. {
  1491. dwRetCode = ERROR_INVALID_PARAMETER;
  1492. }
  1493. else
  1494. {
  1495. dwRetCode = RpbkSetSubEntry(
  1496. pIfObject->lpwsInterfaceName,
  1497. dwIndex,
  1498. dwLevel,
  1499. pInfoStruct->pBuffer);
  1500. }
  1501. }while( FALSE );
  1502. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1503. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1504. "InterfaceDeviceSetInfo returned %d", dwRetCode );
  1505. return( dwRetCode );
  1506. }
  1507. //**
  1508. //
  1509. // Call: RRouterInterfaceGetHandle
  1510. //
  1511. // Returns: NO_ERROR - Success
  1512. // ERROR_ACCESS_DENIED
  1513. //
  1514. // Description:
  1515. //
  1516. DWORD
  1517. RRouterInterfaceGetHandle(
  1518. IN MPR_SERVER_HANDLE hMprServer,
  1519. IN LPWSTR lpwsInterfaceName,
  1520. IN LPDWORD phInterface,
  1521. IN DWORD fIncludeClientInterfaces
  1522. )
  1523. {
  1524. DWORD dwAccessStatus;
  1525. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  1526. DWORD dwRetCode = NO_ERROR;
  1527. //
  1528. // Check if caller has access
  1529. //
  1530. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1531. {
  1532. return( ERROR_ACCESS_DENIED );
  1533. }
  1534. if ( dwAccessStatus )
  1535. {
  1536. return( ERROR_ACCESS_DENIED );
  1537. }
  1538. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1539. do
  1540. {
  1541. pIfObject = IfObjectGetPointerByName( lpwsInterfaceName,
  1542. fIncludeClientInterfaces );
  1543. if ( pIfObject == NULL )
  1544. {
  1545. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  1546. break;
  1547. }
  1548. *phInterface = PtrToUlong(pIfObject->hDIMInterface);
  1549. }while( FALSE );
  1550. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1551. return( dwRetCode );
  1552. }
  1553. //**
  1554. //
  1555. // Call: RRouterInterfaceDelete
  1556. //
  1557. // Returns: NO_ERROR - Success
  1558. // ERROR_ACCESS_DENIED
  1559. //
  1560. // Description: Deletes and interface from the DIM database.
  1561. // work.
  1562. //
  1563. DWORD
  1564. RRouterInterfaceDelete(
  1565. IN MPR_SERVER_HANDLE hMprServer,
  1566. IN DWORD hInterface
  1567. )
  1568. {
  1569. DWORD dwAccessStatus;
  1570. DWORD dwTransportIndex;
  1571. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  1572. DWORD dwRetCode = NO_ERROR;
  1573. BOOL fLANInterfaceRemoved = FALSE;
  1574. BOOL fDeletePbkEntry = FALSE;
  1575. //
  1576. // Check if caller has access
  1577. //
  1578. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1579. {
  1580. return( ERROR_ACCESS_DENIED );
  1581. }
  1582. if ( dwAccessStatus )
  1583. {
  1584. return( ERROR_ACCESS_DENIED );
  1585. }
  1586. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1587. do
  1588. {
  1589. if ( ( pIfObject = IfObjectGetPointer(
  1590. DimIndexToHandle(hInterface)) ) == NULL )
  1591. {
  1592. dwRetCode = ERROR_INVALID_HANDLE;
  1593. break;
  1594. }
  1595. //
  1596. // If this is a demand dial dynamic interface then we cannot delete
  1597. // it if it is connected.
  1598. //
  1599. if ( ( pIfObject->IfType == ROUTER_IF_TYPE_CLIENT ) ||
  1600. ( pIfObject->IfType == ROUTER_IF_TYPE_HOME_ROUTER ) ||
  1601. ( pIfObject->IfType == ROUTER_IF_TYPE_FULL_ROUTER ) )
  1602. {
  1603. if ( pIfObject->State != RISTATE_DISCONNECTED )
  1604. {
  1605. dwRetCode = ERROR_INTERFACE_CONNECTED;
  1606. break;
  1607. }
  1608. fDeletePbkEntry = TRUE;
  1609. //
  1610. // Remove credentials for this interface if they were set.
  1611. //
  1612. MprAdminInterfaceSetCredentials( NULL,
  1613. pIfObject->lpwsInterfaceName,
  1614. NULL,
  1615. NULL,
  1616. NULL );
  1617. }
  1618. else
  1619. {
  1620. //
  1621. // Update router identity object since we are removing a LAN
  1622. // interface
  1623. //
  1624. fLANInterfaceRemoved = TRUE;
  1625. }
  1626. //
  1627. // Delete any transport interfaces that might still be around
  1628. //
  1629. for ( dwTransportIndex = 0;
  1630. dwTransportIndex < gblDIMConfigInfo.dwNumRouterManagers;
  1631. dwTransportIndex++ )
  1632. {
  1633. if ( pIfObject->Transport[dwTransportIndex].hInterface !=
  1634. INVALID_HANDLE_VALUE )
  1635. {
  1636. dwRetCode =
  1637. gblRouterManagers[dwTransportIndex].DdmRouterIf.DeleteInterface(
  1638. pIfObject->Transport[dwTransportIndex].hInterface );
  1639. if ( dwRetCode != NO_ERROR )
  1640. {
  1641. break;
  1642. }
  1643. pIfObject->Transport[dwTransportIndex].hInterface
  1644. = INVALID_HANDLE_VALUE;
  1645. pIfObject->Transport[dwTransportIndex].fState = 0;
  1646. }
  1647. }
  1648. if ( fDeletePbkEntry )
  1649. {
  1650. RpbkDeleteEntry( pIfObject->lpwsInterfaceName );
  1651. }
  1652. IfObjectRemove( (HANDLE)UlongToPtr(hInterface) );
  1653. } while ( FALSE );
  1654. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1655. if ( ( dwRetCode == NO_ERROR ) && ( fLANInterfaceRemoved ) )
  1656. {
  1657. //
  1658. // Can only call this API while not holding the interface lock
  1659. //
  1660. RouterIdentityObjectUpdateAttributes( FALSE, FALSE );
  1661. }
  1662. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1663. "DeleteInterface returned %d", dwRetCode );
  1664. return( dwRetCode );
  1665. }
  1666. //**
  1667. //
  1668. // Call: RRouterInterfaceTransportRemove
  1669. //
  1670. // Returns: NO_ERROR - Success
  1671. // ERROR_ACCESS_DENIED
  1672. //
  1673. // Description: Simply called the appropriate router manager to do the real
  1674. // work.
  1675. //
  1676. DWORD
  1677. RRouterInterfaceTransportRemove(
  1678. IN MPR_SERVER_HANDLE hMprServer,
  1679. IN DWORD hInterface,
  1680. IN DWORD dwTransportId
  1681. )
  1682. {
  1683. DWORD dwAccessStatus;
  1684. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  1685. DWORD dwRetCode = NO_ERROR;
  1686. DWORD dwTransportIndex
  1687. = GetTransportIndex( dwTransportId );
  1688. //
  1689. // Check if caller has access
  1690. //
  1691. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1692. {
  1693. return( ERROR_ACCESS_DENIED );
  1694. }
  1695. if ( dwAccessStatus )
  1696. {
  1697. return( ERROR_ACCESS_DENIED );
  1698. }
  1699. if ( dwTransportIndex == (DWORD)-1 )
  1700. {
  1701. return( ERROR_UNKNOWN_PROTOCOL_ID );
  1702. }
  1703. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1704. do
  1705. {
  1706. if ( ( pIfObject = IfObjectGetPointer(
  1707. DimIndexToHandle(hInterface)) ) == NULL )
  1708. {
  1709. dwRetCode = ERROR_INVALID_HANDLE;
  1710. break;
  1711. }
  1712. //
  1713. // If this is a demand dial dynamic interface then we cannot delete
  1714. // it if it is connected.
  1715. //
  1716. if ( ( pIfObject->IfType == ROUTER_IF_TYPE_CLIENT ) ||
  1717. ( pIfObject->IfType == ROUTER_IF_TYPE_HOME_ROUTER ) ||
  1718. ( pIfObject->IfType == ROUTER_IF_TYPE_FULL_ROUTER ) )
  1719. {
  1720. if ( pIfObject->State == RISTATE_CONNECTED )
  1721. {
  1722. dwRetCode = ERROR_INTERFACE_CONNECTED;
  1723. break;
  1724. }
  1725. }
  1726. //
  1727. // Remove the transport interface.
  1728. //
  1729. if ( pIfObject->Transport[dwTransportIndex].hInterface
  1730. != INVALID_HANDLE_VALUE )
  1731. {
  1732. dwRetCode =
  1733. gblRouterManagers[dwTransportIndex].DdmRouterIf.DeleteInterface(
  1734. pIfObject->Transport[dwTransportIndex].hInterface );
  1735. if ( dwRetCode == NO_ERROR )
  1736. {
  1737. pIfObject->Transport[dwTransportIndex].hInterface
  1738. = INVALID_HANDLE_VALUE;
  1739. }
  1740. }
  1741. else
  1742. {
  1743. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  1744. }
  1745. }while( FALSE );
  1746. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1747. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1748. "RemoveInterface returned %d", dwRetCode );
  1749. return( dwRetCode );
  1750. }
  1751. //**
  1752. //
  1753. // Call: RRouterInterfaceTransportGetInfo
  1754. //
  1755. // Returns: NO_ERROR - Success
  1756. // ERROR_ACCESS_DENIED
  1757. // ERROR_UNKNOWN_PROTOCOL_ID
  1758. // ERROR_INVALID_HANDLE
  1759. // non-zero returns from GetInterfaceInfo
  1760. //
  1761. // Description: Simply called the appropriate router manager to do the real
  1762. // work.
  1763. //
  1764. DWORD
  1765. RRouterInterfaceTransportGetInfo(
  1766. IN MPR_SERVER_HANDLE hMprServer,
  1767. IN DWORD hInterface,
  1768. IN DWORD dwTransportId,
  1769. IN DIM_INTERFACE_CONTAINER * pInfoStruct
  1770. )
  1771. {
  1772. DWORD dwAccessStatus = 0;
  1773. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  1774. DWORD dwRetCode = NO_ERROR;
  1775. DWORD dwTransportIndex = GetTransportIndex( dwTransportId );
  1776. ULONG ulNumAttempts;
  1777. //
  1778. // Check if caller has access
  1779. //
  1780. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1781. {
  1782. return( ERROR_ACCESS_DENIED );
  1783. }
  1784. if ( dwAccessStatus )
  1785. {
  1786. return( ERROR_ACCESS_DENIED );
  1787. }
  1788. if ( dwTransportIndex == (DWORD)-1 )
  1789. {
  1790. return( ERROR_UNKNOWN_PROTOCOL_ID );
  1791. }
  1792. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1793. do
  1794. {
  1795. if ( ( pIfObject = IfObjectGetPointer(
  1796. (HANDLE) UlongToPtr(hInterface ))) == NULL )
  1797. {
  1798. dwRetCode = ERROR_INVALID_HANDLE;
  1799. break;
  1800. }
  1801. //
  1802. // If the interface has not been added for this protocol
  1803. //
  1804. if ( pIfObject->Transport[dwTransportIndex].hInterface
  1805. == INVALID_HANDLE_VALUE )
  1806. {
  1807. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  1808. break;
  1809. }
  1810. if ( pInfoStruct->fGetInterfaceInfo )
  1811. {
  1812. ulNumAttempts = 0;
  1813. pInfoStruct->pInterfaceInfo = NULL;
  1814. do
  1815. {
  1816. dwRetCode =
  1817. gblRouterManagers[dwTransportIndex].DdmRouterIf.GetInterfaceInfo(
  1818. pIfObject->Transport[dwTransportIndex].hInterface,
  1819. pInfoStruct->pInterfaceInfo,
  1820. &(pInfoStruct->dwInterfaceInfoSize) );
  1821. TracePrintfExA(
  1822. gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1823. "GetInterfaceInfo: Transport %d requires size %d, result %d",
  1824. dwTransportIndex, pInfoStruct->dwInterfaceInfoSize,
  1825. dwRetCode
  1826. );
  1827. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  1828. {
  1829. break;
  1830. }
  1831. //
  1832. // Release previous allocation
  1833. //
  1834. if ( ulNumAttempts )
  1835. {
  1836. MIDL_user_free( pInfoStruct->pInterfaceInfo );
  1837. pInfoStruct->pInterfaceInfo = NULL;
  1838. }
  1839. if ( pInfoStruct->dwInterfaceInfoSize > 0 )
  1840. {
  1841. pInfoStruct->pInterfaceInfo = MIDL_user_allocate(
  1842. pInfoStruct->dwInterfaceInfoSize);
  1843. if ( pInfoStruct->pInterfaceInfo == NULL )
  1844. {
  1845. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  1846. break;
  1847. }
  1848. }
  1849. else
  1850. {
  1851. break;
  1852. }
  1853. ulNumAttempts++;
  1854. } while ( (dwRetCode == ERROR_INSUFFICIENT_BUFFER) &&
  1855. (ulNumAttempts < MAX_GET_INFO_RETRIES) );
  1856. }
  1857. } while( FALSE );
  1858. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1859. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1860. "InterfaceGetInfo returned %d", dwRetCode );
  1861. if ( !pInfoStruct->fGetInterfaceInfo )
  1862. {
  1863. pInfoStruct->dwInterfaceInfoSize = 0;
  1864. }
  1865. if ( dwRetCode != NO_ERROR )
  1866. {
  1867. pInfoStruct->dwInterfaceInfoSize = 0;
  1868. }
  1869. return( dwRetCode );
  1870. }
  1871. //**
  1872. //
  1873. // Call: RRouterInterfaceTransportAdd
  1874. //
  1875. // Returns: NO_ERROR - Success
  1876. // ERROR_ACCESS_DENIED
  1877. // ERROR_UNKNOWN_PROTOCOL_ID
  1878. // ERROR_INVALID_HANDLE
  1879. // non-zero returns from AddInterface
  1880. //
  1881. // Description: Simply called the appropriate router manager to do the real
  1882. // work.
  1883. //
  1884. DWORD
  1885. RRouterInterfaceTransportAdd(
  1886. IN MPR_SERVER_HANDLE hMprServer,
  1887. IN DWORD hInterface,
  1888. IN DWORD dwTransportId,
  1889. IN DIM_INTERFACE_CONTAINER * pInfoStruct
  1890. )
  1891. {
  1892. DWORD dwAccessStatus = 0;
  1893. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  1894. DWORD dwRetCode = NO_ERROR;
  1895. DWORD dwIndex = GetTransportIndex( dwTransportId );
  1896. //
  1897. // Check if caller has access
  1898. //
  1899. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  1900. {
  1901. return( ERROR_ACCESS_DENIED );
  1902. }
  1903. if ( dwAccessStatus )
  1904. {
  1905. return( ERROR_ACCESS_DENIED );
  1906. }
  1907. if ( dwIndex == (DWORD)-1 )
  1908. {
  1909. return( ERROR_UNKNOWN_PROTOCOL_ID );
  1910. }
  1911. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1912. do
  1913. {
  1914. if ( ( pIfObject = IfObjectGetPointer(
  1915. DimIndexToHandle(hInterface) )) == NULL )
  1916. {
  1917. dwRetCode = ERROR_INVALID_HANDLE;
  1918. break;
  1919. }
  1920. //
  1921. // If the handle to the interface is NULL, then we have to add the
  1922. // interface
  1923. //
  1924. if ( pIfObject->Transport[dwIndex].hInterface == INVALID_HANDLE_VALUE )
  1925. {
  1926. if (IsInterfaceRoleAcceptable(pIfObject, dwTransportId))
  1927. {
  1928. dwRetCode =
  1929. gblRouterManagers[dwIndex].DdmRouterIf.AddInterface(
  1930. pIfObject->lpwsInterfaceName,
  1931. pInfoStruct->pInterfaceInfo,
  1932. pIfObject->IfType,
  1933. pIfObject->hDIMInterface,
  1934. &pIfObject->Transport[dwIndex].hInterface);
  1935. if ( dwRetCode != NO_ERROR )
  1936. {
  1937. pIfObject->Transport[dwIndex].hInterface =
  1938. INVALID_HANDLE_VALUE;
  1939. }
  1940. else
  1941. {
  1942. if ( !( pIfObject->fFlags & IFFLAG_ENABLED ) ||
  1943. ( pIfObject->fFlags & IFFLAG_OUT_OF_RESOURCES ) ||
  1944. ( gblDIMConfigInfo.ServiceStatus.dwCurrentState ==
  1945. SERVICE_PAUSED))
  1946. {
  1947. TracePrintfExA(
  1948. gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1949. "InterfaceTransportAdd: Set if to unreachable");
  1950. gblRouterManagers[dwIndex].DdmRouterIf.InterfaceNotReachable(
  1951. pIfObject->Transport[dwIndex].hInterface,
  1952. INTERFACE_DISABLED );
  1953. }
  1954. }
  1955. }
  1956. else
  1957. {
  1958. pIfObject->Transport[dwIndex].hInterface = INVALID_HANDLE_VALUE;
  1959. }
  1960. }
  1961. else
  1962. {
  1963. dwRetCode = ERROR_INTERFACE_ALREADY_EXISTS;
  1964. }
  1965. }while( FALSE );
  1966. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  1967. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  1968. "InterfaceTransportAdd returned %d", dwRetCode );
  1969. return( dwRetCode );
  1970. }
  1971. //**
  1972. //
  1973. // Call: RRouterInterfaceTransportSetInfo
  1974. //
  1975. // Returns: NO_ERROR - Success
  1976. // ERROR_ACCESS_DENIED
  1977. // ERROR_UNKNOWN_PROTOCOL_ID
  1978. // ERROR_INVALID_HANDLE
  1979. // non-zero returns from AddInterface or SetInterfaceInfo
  1980. //
  1981. // Description: Simply called the appropriate router manager to do the real
  1982. // work.
  1983. //
  1984. DWORD
  1985. RRouterInterfaceTransportSetInfo(
  1986. IN MPR_SERVER_HANDLE hMprServer,
  1987. IN DWORD hInterface,
  1988. IN DWORD dwTransportId,
  1989. IN DIM_INTERFACE_CONTAINER * pInfoStruct
  1990. )
  1991. {
  1992. DWORD dwAccessStatus = 0;
  1993. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  1994. DWORD dwRetCode = NO_ERROR;
  1995. DWORD dwTransportIndex = GetTransportIndex( dwTransportId );
  1996. //
  1997. // Check if caller has access
  1998. //
  1999. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  2000. {
  2001. return( ERROR_ACCESS_DENIED );
  2002. }
  2003. if ( dwAccessStatus )
  2004. {
  2005. return( ERROR_ACCESS_DENIED );
  2006. }
  2007. if ( dwTransportIndex == (DWORD)-1 )
  2008. {
  2009. return( ERROR_UNKNOWN_PROTOCOL_ID );
  2010. }
  2011. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2012. do
  2013. {
  2014. if ( ( pIfObject = IfObjectGetPointer(
  2015. DimIndexToHandle(hInterface))) == NULL )
  2016. {
  2017. dwRetCode = ERROR_INVALID_HANDLE;
  2018. break;
  2019. }
  2020. //
  2021. // If the handle to the interface is NULL, then we have to add the
  2022. // interface
  2023. //
  2024. if ( pIfObject->Transport[dwTransportIndex].hInterface
  2025. == INVALID_HANDLE_VALUE )
  2026. {
  2027. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  2028. }
  2029. else
  2030. {
  2031. dwRetCode =
  2032. gblRouterManagers[dwTransportIndex].DdmRouterIf.SetInterfaceInfo(
  2033. pIfObject->Transport[dwTransportIndex].hInterface,
  2034. pInfoStruct->pInterfaceInfo );
  2035. }
  2036. }while( FALSE );
  2037. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2038. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  2039. "InterfaceSetInfo returned %d", dwRetCode );
  2040. return( dwRetCode );
  2041. }
  2042. //**
  2043. //
  2044. // Call: RRouterInterfaceEnum
  2045. //
  2046. // Returns: NO_ERROR - Success
  2047. // ERROR_ACCESS_DENIED
  2048. // ERROR_NOT_SUPPORTED
  2049. //
  2050. // Description: Simply called the appropriate router manager to do the real
  2051. // work.
  2052. //
  2053. DWORD
  2054. RRouterInterfaceEnum(
  2055. IN MPR_SERVER_HANDLE hMprServer,
  2056. IN DWORD dwLevel,
  2057. IN OUT PDIM_INFORMATION_CONTAINER pInfoStruct,
  2058. IN DWORD dwPreferedMaximumLength,
  2059. OUT LPDWORD lpdwEntriesRead,
  2060. OUT LPDWORD lpdwTotalEntries,
  2061. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  2062. )
  2063. {
  2064. DWORD dwAccessStatus;
  2065. PMPRI_INTERFACE_0 pInterface0 = NULL;
  2066. DWORD dwIfIndex = 0;
  2067. DWORD dwBucketIndex= 0;
  2068. PROUTER_INTERFACE_OBJECT pIfObject = NULL;
  2069. DWORD dwStartIndex = ( lpdwResumeHandle == NULL )
  2070. ? 0 : *lpdwResumeHandle;
  2071. //
  2072. // Check if caller has access
  2073. //
  2074. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  2075. {
  2076. return( ERROR_ACCESS_DENIED );
  2077. }
  2078. if ( dwAccessStatus )
  2079. {
  2080. return( ERROR_ACCESS_DENIED );
  2081. }
  2082. if ( dwLevel != 0 )
  2083. {
  2084. return( ERROR_NOT_SUPPORTED );
  2085. }
  2086. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2087. if ( gblInterfaceTable.dwNumTotalInterfaces < dwStartIndex )
  2088. {
  2089. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2090. return( ERROR_NO_MORE_ITEMS );
  2091. }
  2092. *lpdwTotalEntries = gblInterfaceTable.dwNumTotalInterfaces - dwStartIndex;
  2093. if ( dwPreferedMaximumLength != -1 )
  2094. {
  2095. *lpdwEntriesRead = dwPreferedMaximumLength /
  2096. sizeof( MPR_INTERFACE_0 );
  2097. if ( *lpdwEntriesRead > *lpdwTotalEntries )
  2098. {
  2099. *lpdwEntriesRead = *lpdwTotalEntries;
  2100. }
  2101. }
  2102. else
  2103. {
  2104. *lpdwEntriesRead = *lpdwTotalEntries;
  2105. }
  2106. pInfoStruct->dwBufferSize = *lpdwEntriesRead * sizeof( MPR_INTERFACE_0 );
  2107. pInfoStruct->pBuffer = MIDL_user_allocate( pInfoStruct->dwBufferSize );
  2108. if ( pInfoStruct->pBuffer == NULL )
  2109. {
  2110. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2111. pInfoStruct->dwBufferSize = 0;
  2112. return( ERROR_NOT_ENOUGH_MEMORY );
  2113. }
  2114. pInterface0 = (PMPRI_INTERFACE_0)pInfoStruct->pBuffer;
  2115. for ( dwBucketIndex = 0; dwBucketIndex < NUM_IF_BUCKETS; dwBucketIndex++ )
  2116. {
  2117. for( pIfObject = gblInterfaceTable.IfBucket[dwBucketIndex];
  2118. pIfObject != (ROUTER_INTERFACE_OBJECT *)NULL;
  2119. pIfObject = pIfObject->pNext )
  2120. {
  2121. //
  2122. // Check if this interface is within the range we need to copy
  2123. // from.
  2124. //
  2125. if ( ( dwIfIndex >= dwStartIndex ) &&
  2126. ( dwIfIndex < ( dwStartIndex + *lpdwEntriesRead ) ) )
  2127. {
  2128. //
  2129. // Copy the info
  2130. //
  2131. GetMprInterface0Data( pIfObject, pInterface0 );
  2132. pInterface0++;
  2133. }
  2134. else if ( dwIfIndex >= (dwStartIndex+*lpdwEntriesRead) )
  2135. {
  2136. //
  2137. // Beyond the range so exit
  2138. //
  2139. if ( lpdwResumeHandle != NULL )
  2140. {
  2141. *lpdwResumeHandle = dwIfIndex;
  2142. }
  2143. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2144. return( ERROR_MORE_DATA );
  2145. }
  2146. dwIfIndex++;
  2147. }
  2148. }
  2149. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2150. return( NO_ERROR );
  2151. }
  2152. //**
  2153. //
  2154. // Call: RRouterInterfaceUpdateRoutes
  2155. //
  2156. // Returns: NO_ERROR - Success
  2157. // ERROR_ACCESS_DENIED
  2158. //
  2159. // Description: Simply called the appropriate router manager to do the real
  2160. // work.
  2161. //
  2162. DWORD
  2163. RRouterInterfaceUpdateRoutes(
  2164. IN MPR_SERVER_HANDLE hMprServer,
  2165. IN DWORD hDimInterface,
  2166. IN DWORD dwPid,
  2167. IN ULONG_PTR hEvent,
  2168. IN DWORD dwCallersProcessId
  2169. )
  2170. {
  2171. DWORD dwAccessStatus;
  2172. PROUTER_INTERFACE_OBJECT pIfObject = NULL;
  2173. HANDLE hEventDuplicated;
  2174. HANDLE hEventToBeDuplicated;
  2175. HANDLE hClientProcess;
  2176. DWORD dwRetCode = NO_ERROR;
  2177. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  2178. //
  2179. // Check if caller has access
  2180. //
  2181. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  2182. {
  2183. return( ERROR_ACCESS_DENIED );
  2184. }
  2185. if ( dwAccessStatus )
  2186. {
  2187. return( ERROR_ACCESS_DENIED );
  2188. }
  2189. if ( dwTransportIndex == (DWORD)-1 )
  2190. {
  2191. return( ERROR_UNKNOWN_PROTOCOL_ID );
  2192. }
  2193. if ( hEvent == PtrToUlong(NULL) )
  2194. {
  2195. //
  2196. // This call is to be synchrnonous, create an event and block on
  2197. // it.
  2198. //
  2199. hEventToBeDuplicated = CreateEvent( NULL, FALSE, FALSE, NULL );
  2200. if ( hEventToBeDuplicated == NULL )
  2201. {
  2202. return( GetLastError() );
  2203. }
  2204. dwCallersProcessId = GetCurrentProcessId();
  2205. }
  2206. else
  2207. {
  2208. hEventToBeDuplicated = (HANDLE)hEvent;
  2209. }
  2210. //
  2211. // Get process handle of the caller of this API
  2212. //
  2213. hClientProcess = OpenProcess(
  2214. STANDARD_RIGHTS_REQUIRED | SPECIFIC_RIGHTS_ALL,
  2215. FALSE,
  2216. dwCallersProcessId);
  2217. if ( hClientProcess == NULL )
  2218. {
  2219. return( GetLastError() );
  2220. }
  2221. //
  2222. // Duplicate the handle to the event
  2223. //
  2224. if ( !DuplicateHandle( hClientProcess,
  2225. (HANDLE)hEventToBeDuplicated,
  2226. GetCurrentProcess(),
  2227. &hEventDuplicated,
  2228. 0,
  2229. FALSE,
  2230. DUPLICATE_SAME_ACCESS ) )
  2231. {
  2232. CloseHandle( hClientProcess );
  2233. return( GetLastError() );
  2234. }
  2235. CloseHandle( hClientProcess );
  2236. //
  2237. // Validate the interface handle and check to see if it is connected
  2238. //
  2239. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2240. do
  2241. {
  2242. if ( ( pIfObject = IfObjectGetPointer(
  2243. DimIndexToHandle(hDimInterface))) == NULL )
  2244. {
  2245. dwRetCode = ERROR_INVALID_HANDLE;
  2246. break;
  2247. }
  2248. if ( pIfObject->State != RISTATE_CONNECTED )
  2249. {
  2250. dwRetCode = ERROR_INTERFACE_NOT_CONNECTED;
  2251. break;
  2252. }
  2253. //
  2254. // Make sure the handle to the interface is NULL, then the interface
  2255. // has not yet been added to the transport.
  2256. //
  2257. if ( pIfObject->Transport[dwTransportIndex].hInterface
  2258. == INVALID_HANDLE_VALUE )
  2259. {
  2260. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  2261. break;
  2262. }
  2263. dwRetCode =
  2264. gblRouterManagers[dwTransportIndex].DdmRouterIf.UpdateRoutes(
  2265. pIfObject->Transport[dwTransportIndex].hInterface,
  2266. (HANDLE)hEventDuplicated );
  2267. } while( FALSE );
  2268. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2269. if ( ( dwRetCode != NO_ERROR ) && ( dwRetCode != PENDING ) )
  2270. {
  2271. CloseHandle( hEventDuplicated );
  2272. }
  2273. if ( hEvent == PtrToUlong(NULL) )
  2274. {
  2275. if ( ( dwRetCode == NO_ERROR ) || ( dwRetCode == PENDING ) )
  2276. {
  2277. //
  2278. // Wait for this event to be signalled
  2279. //
  2280. if ( WaitForSingleObject( hEventToBeDuplicated, INFINITE ) ==
  2281. WAIT_FAILED )
  2282. {
  2283. dwRetCode = GetLastError();
  2284. }
  2285. }
  2286. CloseHandle( hEventToBeDuplicated );
  2287. if ( dwRetCode == PENDING )
  2288. {
  2289. dwRetCode = NO_ERROR;
  2290. }
  2291. }
  2292. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  2293. "InterfaceUpdateRoutes returned %d", dwRetCode );
  2294. return( dwRetCode );
  2295. }
  2296. //**
  2297. //
  2298. // Call: RRouterInterfaceQueryUpdateResult
  2299. //
  2300. // Returns: NO_ERROR - Success
  2301. // ERROR_ACCESS_DENIED - FAILURE
  2302. //
  2303. //
  2304. // Description: Simply called the appropriate router manager to do the real
  2305. // work.
  2306. //
  2307. DWORD
  2308. RRouterInterfaceQueryUpdateResult(
  2309. IN MPR_SERVER_HANDLE hMprServer,
  2310. IN DWORD hDimInterface,
  2311. IN DWORD dwPid,
  2312. IN LPDWORD pUpdateResult
  2313. )
  2314. {
  2315. DWORD dwAccessStatus;
  2316. DWORD dwRetCode = NO_ERROR;
  2317. PROUTER_INTERFACE_OBJECT pIfObject = NULL;
  2318. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  2319. //
  2320. // Check if caller has access
  2321. //
  2322. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  2323. {
  2324. return( ERROR_ACCESS_DENIED );
  2325. }
  2326. if ( dwAccessStatus )
  2327. {
  2328. return( ERROR_ACCESS_DENIED );
  2329. }
  2330. if ( dwTransportIndex == (DWORD)-1 )
  2331. {
  2332. return( ERROR_UNKNOWN_PROTOCOL_ID );
  2333. }
  2334. //
  2335. // Validate the interface handle and check to see if it is connected
  2336. //
  2337. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2338. do
  2339. {
  2340. if ( ( pIfObject = IfObjectGetPointer(
  2341. DimIndexToHandle(hDimInterface))) == NULL )
  2342. {
  2343. dwRetCode = ERROR_INVALID_HANDLE;
  2344. break;
  2345. }
  2346. if ( pIfObject->State != RISTATE_CONNECTED )
  2347. {
  2348. dwRetCode = ERROR_INTERFACE_NOT_CONNECTED;
  2349. break;
  2350. }
  2351. //
  2352. // Make sure the handle to the interface is NULL, then the interface
  2353. // has not yet been added to the transport.
  2354. //
  2355. if ( pIfObject->Transport[dwTransportIndex].hInterface
  2356. == INVALID_HANDLE_VALUE )
  2357. {
  2358. dwRetCode = ERROR_NO_SUCH_INTERFACE;
  2359. break;
  2360. }
  2361. dwRetCode =
  2362. gblRouterManagers[dwTransportIndex].DdmRouterIf.GetUpdateRoutesResult(
  2363. pIfObject->Transport[dwTransportIndex].hInterface,
  2364. pUpdateResult );
  2365. }while( FALSE );
  2366. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2367. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  2368. "QueryUpdateResult returned %d", dwRetCode );
  2369. return( dwRetCode );
  2370. }
  2371. //**
  2372. //
  2373. // Call: RRouterInterfaceConnect
  2374. //
  2375. // Returns: ERROR_ACCESS_DENIED - The caller does not have sufficient priv.
  2376. // ERROR_DDM_NOT_RUNNING - This call cannot be made because DDM is
  2377. // not loaded
  2378. // non-zero returns from DDMAdminInterfaceConnect
  2379. //
  2380. // Description: Simply calles into DDM to do the work.
  2381. //
  2382. DWORD
  2383. RRouterInterfaceConnect(
  2384. IN MPR_SERVER_HANDLE hMprServer,
  2385. IN DWORD hDimInterface,
  2386. IN ULONG_PTR hEvent,
  2387. IN DWORD fBlocking,
  2388. IN DWORD dwCallersProcessId
  2389. )
  2390. {
  2391. DWORD dwAccessStatus;
  2392. //
  2393. // Check if caller has access
  2394. //
  2395. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR )
  2396. {
  2397. return( ERROR_ACCESS_DENIED );
  2398. }
  2399. if ( dwAccessStatus )
  2400. {
  2401. return( ERROR_ACCESS_DENIED );
  2402. }
  2403. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  2404. {
  2405. return( ERROR_DDM_NOT_RUNNING );
  2406. }
  2407. else
  2408. {
  2409. DWORD (*DDMAdminInterfaceConnect)( HANDLE, HANDLE, BOOL, DWORD ) =
  2410. (DWORD(*)( HANDLE, HANDLE, BOOL, DWORD ) )
  2411. GetDDMEntryPoint("DDMAdminInterfaceConnect");
  2412. if(NULL == DDMAdminInterfaceConnect)
  2413. {
  2414. return ERROR_PROC_NOT_FOUND;
  2415. }
  2416. return( DDMAdminInterfaceConnect( DimIndexToHandle(hDimInterface),
  2417. (HANDLE)hEvent,
  2418. (BOOL)fBlocking,
  2419. (DWORD)dwCallersProcessId ) );
  2420. }
  2421. }
  2422. //**
  2423. //
  2424. // Call: RRouterInterfaceDisconnect
  2425. //
  2426. // Returns: ERROR_ACCESS_DENIED - The caller does not have sufficient priv.
  2427. // ERROR_DDM_NOT_RUNNING - This call cannot be made because DDM is
  2428. // not loaded
  2429. // non-zero returns from DDMAdminInterfaceDisconnect
  2430. //
  2431. // Description: Simply calles into DDM to do the work.
  2432. //
  2433. DWORD
  2434. RRouterInterfaceDisconnect(
  2435. IN MPR_SERVER_HANDLE hMprServer,
  2436. IN DWORD hDimInterface
  2437. )
  2438. {
  2439. DWORD dwAccessStatus;
  2440. //
  2441. // Check if caller has access
  2442. //
  2443. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR )
  2444. {
  2445. return( ERROR_ACCESS_DENIED );
  2446. }
  2447. if ( dwAccessStatus )
  2448. {
  2449. return( ERROR_ACCESS_DENIED );
  2450. }
  2451. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  2452. {
  2453. return( ERROR_DDM_NOT_RUNNING );
  2454. }
  2455. else
  2456. {
  2457. DWORD
  2458. (*DDMAdminInterfaceDisconnect)( HANDLE ) =
  2459. (DWORD(*)( HANDLE ) )GetDDMEntryPoint("DDMAdminInterfaceDisconnect");
  2460. if(NULL == DDMAdminInterfaceDisconnect)
  2461. {
  2462. return ERROR_PROC_NOT_FOUND;
  2463. }
  2464. return( DDMAdminInterfaceDisconnect( DimIndexToHandle(hDimInterface) ) );
  2465. }
  2466. }
  2467. //**
  2468. //
  2469. // Call: RRouterInterfaceUpdatePhonebookInfo
  2470. //
  2471. // Returns: NO_ERROR - Success
  2472. /// ERROR_ACCESS_DENIED - The caller does not have sufficient priv.
  2473. // non-zero returns
  2474. //
  2475. // Description: Will update the phonebook information for a given interface
  2476. //
  2477. DWORD
  2478. RRouterInterfaceUpdatePhonebookInfo(
  2479. IN MPR_SERVER_HANDLE hMprServer,
  2480. IN DWORD hDimInterface
  2481. )
  2482. {
  2483. DWORD dwAccessStatus;
  2484. DWORD dwRetCode;
  2485. PROUTER_INTERFACE_OBJECT pIfObject = NULL;
  2486. //
  2487. // Check if caller has access
  2488. //
  2489. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR )
  2490. {
  2491. return( ERROR_ACCESS_DENIED );
  2492. }
  2493. if ( dwAccessStatus )
  2494. {
  2495. return( ERROR_ACCESS_DENIED );
  2496. }
  2497. if ( gblDIMConfigInfo.dwRouterRole == ROUTER_ROLE_LAN )
  2498. {
  2499. return( ERROR_DDM_NOT_RUNNING );
  2500. }
  2501. //
  2502. // Validate the interface handle and check to see if it is connected
  2503. //
  2504. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2505. do
  2506. {
  2507. DWORD (*IfObjectLoadPhonebookInfo)( ROUTER_INTERFACE_OBJECT * ) =
  2508. (DWORD(*)( ROUTER_INTERFACE_OBJECT * ))
  2509. GetDDMEntryPoint("IfObjectLoadPhonebookInfo");
  2510. if(NULL == IfObjectLoadPhonebookInfo)
  2511. {
  2512. dwRetCode = ERROR_PROC_NOT_FOUND;
  2513. break;
  2514. }
  2515. if ( ( pIfObject = IfObjectGetPointer(
  2516. DimIndexToHandle(hDimInterface))) == NULL )
  2517. {
  2518. dwRetCode = ERROR_INVALID_HANDLE;
  2519. break;
  2520. }
  2521. //
  2522. // Load phonebook information for this interface
  2523. //
  2524. dwRetCode = IfObjectLoadPhonebookInfo( pIfObject );
  2525. } while( FALSE );
  2526. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2527. return( dwRetCode );
  2528. }
  2529. DWORD
  2530. RRouterInterfaceSetCredentialsEx(
  2531. IN MPR_SERVER_HANDLE hMprServer,
  2532. IN DWORD dwLevel,
  2533. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  2534. IN DWORD hInterface
  2535. )
  2536. {
  2537. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  2538. PWCHAR pszPath = NULL;
  2539. DWORD dwAccessStatus;
  2540. DWORD dwRetCode = NO_ERROR;
  2541. MPR_CREDENTIALSEX_0 * pCredsEx0 = NULL;
  2542. MPR_CREDENTIALSEX_1 * pCredsEx1 = NULL;
  2543. MPR_CREDENTIALSEXI * pCredsI = (MPR_CREDENTIALSEXI *)
  2544. pInfoStruct->pBuffer;
  2545. //
  2546. // Check if caller has access
  2547. //
  2548. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  2549. {
  2550. return( ERROR_ACCESS_DENIED );
  2551. }
  2552. if ( dwAccessStatus )
  2553. {
  2554. return( ERROR_ACCESS_DENIED );
  2555. }
  2556. if ( (dwLevel != 0 ) &&
  2557. (dwLevel != 1 ) &&
  2558. (dwLevel != 2 ))
  2559. {
  2560. return( ERROR_NOT_SUPPORTED );
  2561. }
  2562. //
  2563. // Adjust the given buffer for any pointers to
  2564. // variable length data.
  2565. //
  2566. if ( dwLevel == 0 )
  2567. {
  2568. //
  2569. // Thunk the credentials structure
  2570. //
  2571. pCredsEx0 = LOCAL_ALLOC(LPTR,
  2572. pCredsI->dwSize + sizeof(MPR_CREDENTIALSEX_0));
  2573. if(pCredsEx0 == NULL)
  2574. {
  2575. return GetLastError();
  2576. }
  2577. pCredsEx0->dwSize = pCredsI->dwSize;
  2578. pCredsEx0->lpbCredentialsInfo = (PBYTE) (pCredsEx0 + 1);
  2579. CopyMemory(pCredsEx0->lpbCredentialsInfo,
  2580. ((PBYTE) pCredsI) + pCredsI->dwOffset,
  2581. pCredsI->dwSize);
  2582. }
  2583. if( ( dwLevel == 1 )
  2584. || ( dwLevel == 2 ))
  2585. {
  2586. //
  2587. // Thunk the credentials structure
  2588. //
  2589. pCredsEx1 = LOCAL_ALLOC(LPTR,
  2590. pCredsI->dwSize + sizeof(MPR_CREDENTIALSEX_1));
  2591. if(pCredsEx1 == NULL)
  2592. {
  2593. return GetLastError();
  2594. }
  2595. pCredsEx1->dwSize = pCredsI->dwSize;
  2596. pCredsEx1->lpbCredentialsInfo = (PBYTE) (pCredsEx1 + 1);
  2597. CopyMemory(pCredsEx1->lpbCredentialsInfo,
  2598. ((PBYTE) pCredsI) + pCredsI->dwOffset,
  2599. pCredsI->dwSize);
  2600. }
  2601. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2602. do
  2603. {
  2604. if (( 2 != dwLevel ) &&
  2605. ( pIfObject = IfObjectGetPointer(DimIndexToHandle(hInterface))) == NULL )
  2606. {
  2607. dwRetCode = ERROR_INVALID_HANDLE;
  2608. break;
  2609. }
  2610. //
  2611. // Process Level 0
  2612. //
  2613. if ( dwLevel == 0 )
  2614. {
  2615. if (pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER)
  2616. {
  2617. dwRetCode = ERROR_INVALID_PARAMETER;
  2618. break;
  2619. }
  2620. dwRetCode = RpbkGetPhonebookPath( &pszPath );
  2621. if ( dwRetCode != NO_ERROR)
  2622. {
  2623. break;
  2624. }
  2625. dwRetCode = RasSetEapUserDataW(
  2626. NULL,
  2627. pszPath,
  2628. pIfObject->lpwsInterfaceName,
  2629. pCredsEx0->lpbCredentialsInfo,
  2630. pCredsEx0->dwSize);
  2631. }
  2632. //
  2633. // Process Levels 1 and 2
  2634. //
  2635. if (( dwLevel == 1 ) ||
  2636. ( dwLevel == 2 ))
  2637. {
  2638. HANDLE hEntry = NULL;
  2639. if( ((NULL != pIfObject) &&
  2640. (pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER)) ||
  2641. (pCredsEx1->dwSize > (PWLEN+1) * sizeof(WCHAR)))
  2642. {
  2643. dwRetCode = ERROR_INVALID_PARAMETER;
  2644. break;
  2645. }
  2646. dwRetCode = RpbkGetPhonebookPath (&pszPath);
  2647. if( dwRetCode != NO_ERROR )
  2648. {
  2649. break;
  2650. }
  2651. {
  2652. RASCREDENTIALS rasCredentials;
  2653. ZeroMemory(&rasCredentials, sizeof(RASCREDENTIALS));
  2654. rasCredentials.dwSize = sizeof(RASCREDENTIALS);
  2655. if(dwLevel == 1)
  2656. {
  2657. rasCredentials.dwMask = RASCM_DDMPreSharedKey;
  2658. }
  2659. else if(dwLevel == 2)
  2660. {
  2661. rasCredentials.dwMask = RASCM_ServerPreSharedKey;
  2662. }
  2663. memcpy((PBYTE) &rasCredentials.szPassword,
  2664. pCredsEx1->lpbCredentialsInfo,
  2665. pCredsEx1->dwSize);
  2666. //
  2667. // Call Ras api to set the credentials.
  2668. //
  2669. dwRetCode = RasSetCredentials(
  2670. pszPath,
  2671. (NULL != pIfObject)
  2672. ? pIfObject->lpwsInterfaceName
  2673. : NULL,
  2674. &rasCredentials,
  2675. (pCredsEx1->dwSize == 0)
  2676. ? TRUE
  2677. : FALSE);
  2678. //
  2679. // If these are server credentials, the set might fail
  2680. // because of no listens being posted on l2tp ports.
  2681. // Attempt to post listens on l2tp ports now that we
  2682. // have a preshared key.
  2683. //
  2684. if( (ERROR_IPSEC_MM_AUTH_NOT_FOUND == dwRetCode)
  2685. && (pCredsEx1->dwSize > 0)
  2686. && (dwLevel == 2))
  2687. {
  2688. VOID (*DDMServicePostListens)(VOID *);
  2689. DDMServicePostListens = (VOID(*)(VOID *))
  2690. GetDDMEntryPoint("DDMServicePostListens");
  2691. if(DDMServicePostListens != NULL)
  2692. {
  2693. DWORD rdt = RDT_Tunnel_L2tp;
  2694. DDMServicePostListens((VOID *) &rdt);
  2695. dwRetCode = ERROR_SUCCESS;
  2696. }
  2697. }
  2698. }
  2699. }
  2700. } while( FALSE );
  2701. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2702. // Cleanup
  2703. {
  2704. if ( pszPath )
  2705. {
  2706. RpbkFreePhonebookPath( pszPath );
  2707. }
  2708. if(pCredsEx0)
  2709. {
  2710. LOCAL_FREE(pCredsEx0);
  2711. }
  2712. if(pCredsEx1)
  2713. {
  2714. LOCAL_FREE(pCredsEx1);
  2715. }
  2716. }
  2717. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  2718. "InterfaceSetCredEx returned %d", dwRetCode );
  2719. return( dwRetCode );
  2720. }
  2721. DWORD
  2722. RRouterInterfaceGetCredentialsEx(
  2723. IN MPR_SERVER_HANDLE hMprServer,
  2724. IN DWORD dwLevel,
  2725. IN PDIM_INFORMATION_CONTAINER pInfoStruct,
  2726. IN DWORD hInterface
  2727. )
  2728. {
  2729. ROUTER_INTERFACE_OBJECT * pIfObject = NULL;
  2730. PWCHAR pszPath = NULL;
  2731. DWORD dwAccessStatus;
  2732. DWORD dwRetCode = NO_ERROR, dwSize = 0;
  2733. MPR_CREDENTIALSEXI * pCredsI = NULL;
  2734. //
  2735. // Check if caller has access
  2736. //
  2737. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  2738. {
  2739. return( ERROR_ACCESS_DENIED );
  2740. }
  2741. if ( dwAccessStatus )
  2742. {
  2743. return( ERROR_ACCESS_DENIED );
  2744. }
  2745. if ( (dwLevel != 0 )
  2746. && (dwLevel != 1 )
  2747. && (dwLevel != 2 ))
  2748. {
  2749. return( ERROR_NOT_SUPPORTED );
  2750. }
  2751. EnterCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2752. do
  2753. {
  2754. if ( (dwLevel != 2)
  2755. && (( pIfObject = IfObjectGetPointer(
  2756. DimIndexToHandle(hInterface))) == NULL ))
  2757. {
  2758. dwRetCode = ERROR_INVALID_HANDLE;
  2759. break;
  2760. }
  2761. //
  2762. // Process Level 0
  2763. //
  2764. if ( dwLevel == 0 )
  2765. {
  2766. if (pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER)
  2767. {
  2768. dwRetCode = ERROR_INVALID_PARAMETER;
  2769. break;
  2770. }
  2771. dwRetCode = RpbkGetPhonebookPath( &pszPath );
  2772. if ( dwRetCode != NO_ERROR)
  2773. {
  2774. break;
  2775. }
  2776. // Find out how big the data is
  2777. //
  2778. dwSize = 0;
  2779. dwRetCode = RasGetEapUserDataW(
  2780. NULL,
  2781. pszPath,
  2782. pIfObject->lpwsInterfaceName,
  2783. NULL,
  2784. &dwSize);
  2785. if ( (dwRetCode != NO_ERROR) &&
  2786. (dwRetCode != ERROR_BUFFER_TOO_SMALL)
  2787. )
  2788. {
  2789. break;
  2790. }
  2791. // Allocate the return value
  2792. //
  2793. pCredsI = (MPR_CREDENTIALSEXI *)
  2794. MIDL_user_allocate(dwSize + sizeof(MPR_CREDENTIALSEXI));
  2795. if ( pCredsI == NULL )
  2796. {
  2797. dwRetCode = ERROR_NOT_ENOUGH_MEMORY;
  2798. break;
  2799. }
  2800. // Initialize
  2801. ZeroMemory(pCredsI, dwSize + sizeof(MPR_CREDENTIALSEXI));
  2802. pCredsI->dwSize = dwSize;
  2803. pCredsI->dwOffset = FIELD_OFFSET(MPR_CREDENTIALSEXI, bData);
  2804. if ( pCredsI->dwSize == 0)
  2805. {
  2806. dwRetCode = NO_ERROR;
  2807. break;
  2808. }
  2809. // Read in the credentials info
  2810. //
  2811. // pCredsEx0->lpbCredentialsInfo = (BYTE*) (pCredsEx0 + 1);
  2812. dwRetCode = RasGetEapUserDataW(
  2813. NULL,
  2814. pszPath,
  2815. pIfObject->lpwsInterfaceName,
  2816. pCredsI->bData,
  2817. &dwSize);
  2818. if ( dwRetCode != NO_ERROR )
  2819. {
  2820. break;
  2821. }
  2822. }
  2823. else if( (dwLevel == 1 ) || (dwLevel == 2))
  2824. {
  2825. RASCREDENTIALS rasCredentials;
  2826. if ( (dwLevel != 2)
  2827. && (pIfObject->IfType != ROUTER_IF_TYPE_FULL_ROUTER))
  2828. {
  2829. dwRetCode = ERROR_INVALID_PARAMETER;
  2830. break;
  2831. }
  2832. dwRetCode = RpbkGetPhonebookPath( &pszPath );
  2833. if ( dwRetCode != NO_ERROR)
  2834. {
  2835. break;
  2836. }
  2837. ZeroMemory(&rasCredentials, sizeof(RASCREDENTIALS));
  2838. rasCredentials.dwSize = sizeof(RASCREDENTIALS);
  2839. if(dwLevel == 1)
  2840. {
  2841. rasCredentials.dwMask = RASCM_DDMPreSharedKey;
  2842. }
  2843. else if(dwLevel == 2)
  2844. {
  2845. rasCredentials.dwMask = RASCM_ServerPreSharedKey;
  2846. }
  2847. dwRetCode = RasGetCredentials(
  2848. pszPath,
  2849. (NULL != pIfObject)
  2850. ? pIfObject->lpwsInterfaceName
  2851. : NULL,
  2852. &rasCredentials);
  2853. if(dwRetCode != NO_ERROR)
  2854. {
  2855. break;
  2856. }
  2857. dwSize = (1 + wcslen(rasCredentials.szPassword)) * sizeof(WCHAR);
  2858. //
  2859. // allocate for pCredsEx1
  2860. //
  2861. pCredsI = (MPR_CREDENTIALSEXI *)
  2862. MIDL_user_allocate(dwSize + sizeof(MPR_CREDENTIALSEXI));
  2863. if(NULL == pCredsI)
  2864. {
  2865. break;
  2866. }
  2867. ZeroMemory(pCredsI, dwSize + sizeof(MPR_CREDENTIALSEXI));
  2868. pCredsI->dwSize = dwSize;
  2869. pCredsI->dwOffset = FIELD_OFFSET(MPR_CREDENTIALSEXI, bData);
  2870. CopyMemory((pCredsI->bData),
  2871. (PBYTE) rasCredentials.szPassword,
  2872. dwSize);
  2873. }
  2874. } while( FALSE );
  2875. LeaveCriticalSection( &(gblInterfaceTable.CriticalSection) );
  2876. // Assign the return value
  2877. //
  2878. if ( dwRetCode == NO_ERROR )
  2879. {
  2880. pInfoStruct->pBuffer = (BYTE*)pCredsI;
  2881. pInfoStruct->dwBufferSize =
  2882. sizeof(MPR_CREDENTIALSEXI) + pCredsI->dwSize;
  2883. }
  2884. // Cleanup
  2885. {
  2886. if ( pszPath )
  2887. {
  2888. RpbkFreePhonebookPath( pszPath );
  2889. }
  2890. }
  2891. TracePrintfExA( gblDIMConfigInfo.dwTraceId, DIM_TRACE_FLAGS,
  2892. "InterfaceSetCredEx returned %d", dwRetCode );
  2893. return( dwRetCode );
  2894. }