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.

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