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.

1142 lines
29 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: adminapi.c
  7. //
  8. // Description: Contains code to respond to DDM admin. requests.
  9. //
  10. // History: May 11,1995 NarenG Created original version.
  11. //
  12. #include "ddm.h"
  13. #include <lmmsg.h>
  14. #include "objects.h"
  15. #include "handlers.h"
  16. #include "rasapiif.h"
  17. #include "routerif.h"
  18. #include "util.h"
  19. #include <dimsvc.h> // Generated by MIDL
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include <mprapip.h>
  23. //**
  24. //
  25. // Call: DDMAdminInterfaceConnect
  26. //
  27. // Returns: NO_ERROR - Success
  28. //
  29. // Description:
  30. //
  31. DWORD
  32. DDMAdminInterfaceConnect(
  33. IN HANDLE hDimInterface,
  34. IN HANDLE hEvent,
  35. IN BOOL fBlocking,
  36. IN DWORD dwCallersProcessId
  37. )
  38. {
  39. HANDLE hClientProcess = NULL;
  40. DWORD dwRetCode = NO_ERROR;
  41. ROUTER_INTERFACE_OBJECT* pIfObject = NULL;
  42. HANDLE hEventToBeDuplicated = NULL;
  43. DWORD fReturn = FALSE;
  44. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  45. do
  46. {
  47. if ( ( pIfObject = IfObjectGetPointer((HANDLE)hDimInterface) ) == NULL )
  48. {
  49. dwRetCode = ERROR_INVALID_HANDLE;
  50. break;
  51. }
  52. if ( pIfObject->State == RISTATE_CONNECTED )
  53. {
  54. dwRetCode = NO_ERROR;
  55. fReturn = TRUE;
  56. break;
  57. }
  58. if ( pIfObject->State == RISTATE_CONNECTING )
  59. {
  60. dwRetCode = ERROR_ALREADY_CONNECTING;
  61. fReturn = TRUE;
  62. break;
  63. }
  64. if ( ( hEvent == NULL ) && ( fBlocking ) )
  65. {
  66. //
  67. // This call is to be synchrnonous, create an event and block on
  68. // it.
  69. //
  70. hEventToBeDuplicated = CreateEvent( NULL, FALSE, FALSE, NULL );
  71. if ( hEventToBeDuplicated == NULL )
  72. {
  73. dwRetCode = GetLastError();
  74. break;
  75. }
  76. dwCallersProcessId = GetCurrentProcessId();
  77. }
  78. else
  79. {
  80. hEventToBeDuplicated = hEvent;
  81. }
  82. if ( hEventToBeDuplicated != NULL )
  83. {
  84. //
  85. //
  86. // Get process handle of the caller of this API
  87. //
  88. hClientProcess = OpenProcess(
  89. STANDARD_RIGHTS_REQUIRED | SPECIFIC_RIGHTS_ALL,
  90. FALSE,
  91. dwCallersProcessId);
  92. if ( hClientProcess == NULL )
  93. {
  94. dwRetCode = GetLastError();
  95. break;
  96. }
  97. //
  98. // Duplicate the handle to the event
  99. //
  100. if ( !DuplicateHandle(
  101. hClientProcess,
  102. hEventToBeDuplicated,
  103. GetCurrentProcess(),
  104. &(pIfObject->hEventNotifyCaller),
  105. 0,
  106. FALSE,
  107. DUPLICATE_SAME_ACCESS ) )
  108. {
  109. CloseHandle( hClientProcess );
  110. dwRetCode = GetLastError();
  111. break;
  112. }
  113. CloseHandle( hClientProcess );
  114. }
  115. else
  116. {
  117. pIfObject->hEventNotifyCaller = INVALID_HANDLE_VALUE;
  118. }
  119. //
  120. // Initiate a connection
  121. //
  122. dwRetCode = RasConnectionInitiate( pIfObject, FALSE );
  123. if ( dwRetCode != NO_ERROR )
  124. {
  125. CloseHandle( pIfObject->hEventNotifyCaller );
  126. pIfObject->hEventNotifyCaller = INVALID_HANDLE_VALUE;
  127. }
  128. else
  129. {
  130. dwRetCode = PENDING;
  131. }
  132. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  133. "RasConnectionInitiate: To %ws dwRetCode=%d",
  134. pIfObject->lpwsInterfaceName, dwRetCode );
  135. }
  136. while( FALSE );
  137. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  138. //
  139. // If we are or already connecting or connected then simply return
  140. //
  141. if ( fReturn )
  142. {
  143. return( dwRetCode );
  144. }
  145. //
  146. // This is a synchronous call, we need to wait till compeletion
  147. //
  148. if ( ( hEvent == NULL ) && ( fBlocking ) )
  149. {
  150. if ( dwRetCode == PENDING )
  151. {
  152. if ( WaitForSingleObject( hEventToBeDuplicated, INFINITE )
  153. == WAIT_FAILED )
  154. {
  155. CloseHandle( hEventToBeDuplicated );
  156. return( GetLastError() );
  157. }
  158. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  159. if ( ( pIfObject = IfObjectGetPointer((HANDLE)hDimInterface) )
  160. == NULL )
  161. {
  162. dwRetCode = ERROR_INVALID_HANDLE;
  163. }
  164. else
  165. {
  166. dwRetCode = pIfObject->dwLastError;
  167. }
  168. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  169. }
  170. if ( hEventToBeDuplicated != NULL )
  171. {
  172. CloseHandle( hEventToBeDuplicated );
  173. }
  174. }
  175. return( dwRetCode );
  176. }
  177. //**
  178. //
  179. // Call: DDMAdminInterfaceDisconnect
  180. //
  181. // Returns: NO_ERROR - Success
  182. //
  183. // Description:
  184. //
  185. DWORD
  186. DDMAdminInterfaceDisconnect(
  187. IN HANDLE hDimInterface
  188. )
  189. {
  190. DWORD dwRetCode = NO_ERROR;
  191. DWORD dwTransportIndex = -1;
  192. if ( gblDDMConfigInfo.dwNumRouterManagers > 0 )
  193. {
  194. for ( dwTransportIndex = 0;
  195. dwTransportIndex < gblDDMConfigInfo.dwNumRouterManagers;
  196. dwTransportIndex++ )
  197. {
  198. dwRetCode =
  199. DDMDisconnectInterface(
  200. hDimInterface,
  201. gblRouterManagers[dwTransportIndex].DdmRouterIf.dwProtocolId );
  202. if ( dwRetCode != NO_ERROR )
  203. {
  204. return( dwRetCode );
  205. }
  206. }
  207. }
  208. else
  209. {
  210. //
  211. // [old comment] If no router managers are installed then we are a AMB
  212. // or NBF only client connection, simply call disconnect interface
  213. //
  214. // [new comment]
  215. //
  216. // AMB and NBF have been removed from the project but this path is
  217. // being kept since logically, you should be able to disconnect an
  218. // interface regardless of whether any router managers exist.
  219. //
  220. // This philosphy is in spirit with the work we'll do
  221. // to merge rasman, dim, and ddm. Then it will be possible for
  222. // code paths like this to execute without any router managers being
  223. // loaded.
  224. //
  225. dwRetCode = DDMDisconnectInterface( hDimInterface, -1 );
  226. }
  227. return( dwRetCode );
  228. }
  229. //**
  230. //
  231. // Call: DDMAdminServerGetInfo
  232. //
  233. // Returns: NO_ERROR - Success
  234. //
  235. // Description:
  236. //
  237. DWORD
  238. DDMAdminServerGetInfo(
  239. IN OUT PVOID pServerInfo,
  240. IN DWORD dwLevel
  241. )
  242. {
  243. MPR_SERVER_0* pServerInfo0;
  244. if ( dwLevel == 0 )
  245. {
  246. pServerInfo0 = (MPR_SERVER_0*)pServerInfo;
  247. pServerInfo0->fLanOnlyMode = FALSE;
  248. }
  249. else
  250. {
  251. return( ERROR_NOT_SUPPORTED );
  252. }
  253. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  254. //
  255. // Copy server info
  256. //
  257. pServerInfo0->dwTotalPorts = gblDeviceTable.NumDeviceNodes;
  258. pServerInfo0->dwPortsInUse = gblDeviceTable.NumDevicesInUse;
  259. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  260. return( NO_ERROR );
  261. }
  262. //**
  263. //
  264. // Call: DDMAdminConnectionEnum
  265. //
  266. // Returns: NO_ERROR - Success
  267. //
  268. // Description:
  269. //
  270. DWORD
  271. DDMAdminConnectionEnum(
  272. IN OUT PDIM_INFORMATION_CONTAINER pInfoStruct,
  273. IN DWORD dwLevel,
  274. IN DWORD dwPreferedMaximumLength,
  275. IN LPDWORD lpdwEntriesRead,
  276. IN LPDWORD lpdwTotalEntries,
  277. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  278. )
  279. {
  280. PRASI_CONNECTION_0 pRasConnection0 = NULL;
  281. PRASI_CONNECTION_1 pRasConnection1 = NULL;
  282. PRASI_CONNECTION_2 pRasConnection2 = NULL;
  283. PCONNECTION_OBJECT pConnObj = NULL;
  284. DWORD dwBucketIndex = 0;
  285. DWORD dwConnObjIndex = 0;
  286. DWORD dwConnInfoSize = 0;
  287. DWORD dwStartIndex = ( lpdwResumeHandle == NULL )
  288. ? 0
  289. : *lpdwResumeHandle;
  290. // Calculate the connection info size
  291. switch (dwLevel) {
  292. case 0:
  293. dwConnInfoSize = sizeof( RASI_CONNECTION_0 );
  294. break;
  295. case 1:
  296. dwConnInfoSize = sizeof( RASI_CONNECTION_1 );
  297. break;
  298. case 2:
  299. dwConnInfoSize = sizeof( RASI_CONNECTION_2 );
  300. break;
  301. default:
  302. return ERROR_NOT_SUPPORTED;
  303. }
  304. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  305. if ( gblDeviceTable.NumConnectionNodes < dwStartIndex )
  306. {
  307. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  308. return( ERROR_NO_MORE_ITEMS );
  309. }
  310. *lpdwTotalEntries = gblDeviceTable.NumConnectionNodes - dwStartIndex;
  311. if ( dwPreferedMaximumLength != -1 )
  312. {
  313. *lpdwEntriesRead = dwPreferedMaximumLength / dwConnInfoSize;
  314. if ( *lpdwEntriesRead > *lpdwTotalEntries )
  315. {
  316. *lpdwEntriesRead = *lpdwTotalEntries;
  317. }
  318. }
  319. else
  320. {
  321. *lpdwEntriesRead = *lpdwTotalEntries;
  322. }
  323. pInfoStruct->dwBufferSize = *lpdwEntriesRead * dwConnInfoSize;
  324. pInfoStruct->pBuffer = MIDL_user_allocate( pInfoStruct->dwBufferSize );
  325. if ( pInfoStruct->pBuffer == NULL )
  326. {
  327. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  328. pInfoStruct->dwBufferSize = 0;
  329. return( ERROR_NOT_ENOUGH_MEMORY );
  330. }
  331. if (dwLevel == 0)
  332. pRasConnection0 = (PRASI_CONNECTION_0)pInfoStruct->pBuffer;
  333. else if (dwLevel == 1)
  334. pRasConnection1 = (PRASI_CONNECTION_1)pInfoStruct->pBuffer;
  335. else
  336. pRasConnection2 = (PRASI_CONNECTION_2)pInfoStruct->pBuffer;
  337. for ( dwBucketIndex = 0;
  338. dwBucketIndex < gblDeviceTable.NumDeviceBuckets;
  339. dwBucketIndex++ )
  340. {
  341. for( pConnObj = gblDeviceTable.ConnectionBucket[dwBucketIndex];
  342. pConnObj != (CONNECTION_OBJECT *)NULL;
  343. pConnObj = pConnObj->pNext )
  344. {
  345. //
  346. // Check if this connection object is within the range we need to
  347. // copy from.
  348. //
  349. if ( ( dwConnObjIndex >= dwStartIndex ) &&
  350. ( dwConnObjIndex < (dwStartIndex+*lpdwEntriesRead)))
  351. {
  352. //
  353. // Copy the info
  354. //
  355. if (dwLevel == 0) {
  356. GetRasiConnection0Data( pConnObj, pRasConnection0 );
  357. pRasConnection0++;
  358. }
  359. else if (dwLevel == 1) {
  360. GetRasiConnection1Data( pConnObj, pRasConnection1 );
  361. pRasConnection1++;
  362. }
  363. else {
  364. GetRasiConnection2Data( pConnObj, pRasConnection2 );
  365. pRasConnection2++;
  366. }
  367. }
  368. else if (dwConnObjIndex>=(dwStartIndex+*lpdwEntriesRead))
  369. {
  370. //
  371. // Beyond the range so exit
  372. //
  373. if ( lpdwResumeHandle != NULL )
  374. {
  375. *lpdwResumeHandle = dwConnObjIndex;
  376. }
  377. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  378. return( ERROR_MORE_DATA );
  379. }
  380. dwConnObjIndex++;
  381. }
  382. }
  383. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  384. return( NO_ERROR );
  385. }
  386. //**
  387. //
  388. // Call: DDMAdminConnectionGetInfo
  389. //
  390. // Returns: NO_ERROR - Success
  391. //
  392. // Description:
  393. //
  394. DWORD
  395. DDMAdminConnectionGetInfo(
  396. IN HANDLE hConnection,
  397. IN OUT PDIM_INFORMATION_CONTAINER pInfoStruct,
  398. IN DWORD dwLevel
  399. )
  400. {
  401. DWORD dwRetCode = NO_ERROR;
  402. ROUTER_INTERFACE_OBJECT * pIfObject;
  403. CONNECTION_OBJECT * pConnObj;
  404. if ( dwLevel > 2 )
  405. {
  406. return( ERROR_NOT_SUPPORTED );
  407. }
  408. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  409. switch( dwLevel )
  410. {
  411. case 0:
  412. pInfoStruct->dwBufferSize = sizeof( RASI_CONNECTION_0 );
  413. break;
  414. case 1:
  415. pInfoStruct->dwBufferSize = sizeof( RASI_CONNECTION_1 );
  416. break;
  417. case 2:
  418. pInfoStruct->dwBufferSize = sizeof( RASI_CONNECTION_2 );
  419. break;
  420. }
  421. pInfoStruct->pBuffer = MIDL_user_allocate( pInfoStruct->dwBufferSize );
  422. if ( pInfoStruct->pBuffer == NULL )
  423. {
  424. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  425. return( ERROR_NOT_ENOUGH_MEMORY );
  426. }
  427. //
  428. // Copy Connection info
  429. //
  430. do
  431. {
  432. pConnObj = ConnObjGetPointer( (HCONN)hConnection );
  433. if ( pConnObj == (CONNECTION_OBJECT *)NULL )
  434. {
  435. dwRetCode = ERROR_INTERFACE_NOT_CONNECTED;
  436. break;
  437. }
  438. switch( dwLevel )
  439. {
  440. case 0:
  441. dwRetCode = GetRasiConnection0Data(
  442. pConnObj,
  443. (PRASI_CONNECTION_0)pInfoStruct->pBuffer );
  444. break;
  445. case 1:
  446. dwRetCode = GetRasiConnection1Data(
  447. pConnObj,
  448. (PRASI_CONNECTION_1)pInfoStruct->pBuffer );
  449. break;
  450. case 2:
  451. dwRetCode = GetRasiConnection2Data(
  452. pConnObj,
  453. (PRASI_CONNECTION_2)pInfoStruct->pBuffer );
  454. break;
  455. }
  456. }while( FALSE );
  457. if ( dwRetCode != NO_ERROR )
  458. {
  459. MIDL_user_free( pInfoStruct->pBuffer );
  460. pInfoStruct->pBuffer = NULL;
  461. pInfoStruct->dwBufferSize = 0;
  462. }
  463. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  464. return( dwRetCode );
  465. }
  466. //**
  467. //
  468. // Call: DDMAdminConnectionClearStats
  469. //
  470. // Returns: NO_ERROR - Success
  471. //
  472. // Description:
  473. //
  474. DWORD
  475. DDMAdminConnectionClearStats(
  476. IN HANDLE hConnection
  477. )
  478. {
  479. return( RasBundleClearStatisticsEx(NULL, (HCONN)hConnection ) );
  480. }
  481. //**
  482. //
  483. // Call: DDMAdminPortEnum
  484. //
  485. // Returns: NO_ERROR - Success
  486. //
  487. // Description:
  488. //
  489. DWORD
  490. DDMAdminPortEnum(
  491. IN OUT PDIM_INFORMATION_CONTAINER pInfoStruct,
  492. IN HANDLE hConnection,
  493. IN DWORD dwLevel,
  494. IN DWORD dwPreferedMaximumLength,
  495. IN LPDWORD lpdwEntriesRead,
  496. IN LPDWORD lpdwTotalEntries,
  497. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  498. )
  499. {
  500. PRASI_PORT_0 pRasPort0 = NULL;
  501. PDEVICE_OBJECT pDevObj = NULL;
  502. PCONNECTION_OBJECT pConnObj = NULL;
  503. DWORD dwIndex = 0;
  504. DWORD dwBucketIndex = 0;
  505. DWORD dwDevObjIndex = 0;
  506. DWORD dwStartIndex = ( lpdwResumeHandle == NULL )
  507. ? 0
  508. : *lpdwResumeHandle;
  509. if ( dwLevel != 0 )
  510. {
  511. return( ERROR_NOT_SUPPORTED );
  512. }
  513. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  514. if ( hConnection != INVALID_HANDLE_VALUE )
  515. {
  516. if ( ( pConnObj = ConnObjGetPointer( (HCONN)hConnection ) ) == NULL )
  517. {
  518. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  519. return( ERROR_INVALID_HANDLE );
  520. }
  521. if ( pConnObj->cActiveDevices < dwStartIndex )
  522. {
  523. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  524. return( ERROR_NO_MORE_ITEMS );
  525. }
  526. *lpdwTotalEntries = pConnObj->cActiveDevices - dwStartIndex;
  527. }
  528. else
  529. {
  530. if ( gblDeviceTable.NumDeviceNodes < dwStartIndex )
  531. {
  532. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  533. return( ERROR_NO_MORE_ITEMS );
  534. }
  535. *lpdwTotalEntries = gblDeviceTable.NumDeviceNodes - dwStartIndex;
  536. }
  537. if ( dwPreferedMaximumLength != -1 )
  538. {
  539. *lpdwEntriesRead = dwPreferedMaximumLength / sizeof( RAS_PORT_0 );
  540. if ( *lpdwEntriesRead > *lpdwTotalEntries )
  541. {
  542. *lpdwEntriesRead = *lpdwTotalEntries;
  543. }
  544. }
  545. else
  546. {
  547. *lpdwEntriesRead = *lpdwTotalEntries;
  548. }
  549. pInfoStruct->dwBufferSize = *lpdwEntriesRead * sizeof( RASI_PORT_0 );
  550. pInfoStruct->pBuffer = MIDL_user_allocate( pInfoStruct->dwBufferSize );
  551. if ( pInfoStruct->pBuffer == NULL )
  552. {
  553. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  554. pInfoStruct->dwBufferSize = 0;
  555. return( ERROR_NOT_ENOUGH_MEMORY );
  556. }
  557. pRasPort0 = (PRASI_PORT_0)pInfoStruct->pBuffer;
  558. if ( hConnection == INVALID_HANDLE_VALUE )
  559. {
  560. for ( dwBucketIndex = 0;
  561. dwBucketIndex < gblDeviceTable.NumDeviceBuckets;
  562. dwBucketIndex++ )
  563. {
  564. for( pDevObj = gblDeviceTable.DeviceBucket[dwBucketIndex];
  565. pDevObj != (DEVICE_OBJECT *)NULL;
  566. pDevObj = pDevObj->pNext )
  567. {
  568. //
  569. // Check if this port is within the range we need to copy
  570. // from.
  571. //
  572. if ( ( dwDevObjIndex >= dwStartIndex ) &&
  573. ( dwDevObjIndex < (dwStartIndex+*lpdwEntriesRead)))
  574. {
  575. //
  576. // Copy the info
  577. //
  578. GetRasiPort0Data( pDevObj, pRasPort0 );
  579. pRasPort0++;
  580. }
  581. else if (dwDevObjIndex>=(dwStartIndex+*lpdwEntriesRead))
  582. {
  583. //
  584. // Beyond the range so exit
  585. //
  586. if ( lpdwResumeHandle != NULL )
  587. {
  588. *lpdwResumeHandle = dwDevObjIndex;
  589. }
  590. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  591. return( ERROR_MORE_DATA );
  592. }
  593. dwDevObjIndex++;
  594. }
  595. }
  596. }
  597. else
  598. {
  599. for ( dwIndex = 0; dwIndex < pConnObj->cDeviceListSize; dwIndex++ )
  600. {
  601. if ( pConnObj->pDeviceList[dwIndex] != NULL )
  602. {
  603. //
  604. // Check if this port is within the range we need to copy
  605. // from.
  606. //
  607. if ( ( dwDevObjIndex >= dwStartIndex ) &&
  608. ( dwDevObjIndex < (dwStartIndex+*lpdwEntriesRead)))
  609. {
  610. //
  611. // Copy the info
  612. //
  613. GetRasiPort0Data(pConnObj->pDeviceList[dwIndex], pRasPort0);
  614. pRasPort0++;
  615. }
  616. else if (dwDevObjIndex>=(dwStartIndex+*lpdwEntriesRead))
  617. {
  618. //
  619. // Beyond the range so exit
  620. //
  621. if ( lpdwResumeHandle != NULL )
  622. {
  623. *lpdwResumeHandle = dwDevObjIndex;
  624. }
  625. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  626. return( NO_ERROR );
  627. }
  628. dwDevObjIndex++;
  629. }
  630. }
  631. }
  632. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  633. return( NO_ERROR );
  634. }
  635. //**
  636. //
  637. // Call: DDMAdminPortGetInfo
  638. //
  639. // Returns: NO_ERROR - Success
  640. //
  641. // Description:
  642. //
  643. DWORD
  644. DDMAdminPortGetInfo(
  645. IN HANDLE hPort,
  646. IN OUT PDIM_INFORMATION_CONTAINER pInfoStruct,
  647. IN DWORD dwLevel
  648. )
  649. {
  650. DEVICE_OBJECT * pDevObj;
  651. DWORD dwRetCode;
  652. if ( dwLevel > 1 )
  653. {
  654. return( ERROR_NOT_SUPPORTED );
  655. }
  656. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  657. pInfoStruct->dwBufferSize = ( dwLevel == 0 )
  658. ? sizeof( RAS_PORT_0 )
  659. : sizeof( RAS_PORT_1 );
  660. pInfoStruct->pBuffer = MIDL_user_allocate( pInfoStruct->dwBufferSize );
  661. if ( pInfoStruct->pBuffer == NULL )
  662. {
  663. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  664. return( ERROR_NOT_ENOUGH_MEMORY );
  665. }
  666. //
  667. // Copy port info
  668. //
  669. do
  670. {
  671. pDevObj = DeviceObjGetPointer( (HPORT)hPort );
  672. if ( pDevObj == (HPORT)NULL )
  673. {
  674. dwRetCode = ERROR_INVALID_PORT_HANDLE;
  675. break;
  676. }
  677. if ( dwLevel == 0 )
  678. {
  679. dwRetCode = GetRasiPort0Data( pDevObj,
  680. (PRASI_PORT_0)pInfoStruct->pBuffer );
  681. }
  682. else
  683. {
  684. dwRetCode = GetRasiPort1Data( pDevObj,
  685. (PRASI_PORT_1)pInfoStruct->pBuffer );
  686. }
  687. }
  688. while( FALSE );
  689. if ( dwRetCode != NO_ERROR )
  690. {
  691. MIDL_user_free( pInfoStruct->pBuffer );
  692. pInfoStruct->pBuffer = NULL;
  693. pInfoStruct->dwBufferSize = 0;
  694. }
  695. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  696. return( dwRetCode );
  697. }
  698. //**
  699. //
  700. // Call: DDMAdminPortClearStats
  701. //
  702. // Returns: NO_ERROR - Success
  703. //
  704. // Description:
  705. //
  706. DWORD
  707. DDMAdminPortClearStats(
  708. IN HANDLE hPort
  709. )
  710. {
  711. PDEVICE_OBJECT pDevObj = NULL;
  712. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  713. if ( ( pDevObj = DeviceObjGetPointer( (HPORT)hPort ) ) == NULL )
  714. {
  715. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  716. return( ERROR_INVALID_HANDLE );
  717. }
  718. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  719. return( RasPortClearStatistics(NULL, (HPORT)hPort ) );
  720. }
  721. //**
  722. //
  723. // Call: DDMAdminPortReset
  724. //
  725. // Returns: NO_ERROR - Success
  726. //
  727. // Description:
  728. //
  729. DWORD
  730. DDMAdminPortReset(
  731. IN HANDLE hPort
  732. )
  733. {
  734. return( NO_ERROR );
  735. }
  736. //**
  737. //
  738. // Call: DDMAdminPortDisconnect
  739. //
  740. // Returns: NO_ERROR - Success
  741. //
  742. // Description: Disconnect the client port.
  743. //
  744. DWORD
  745. DDMAdminPortDisconnect(
  746. IN HANDLE hPort
  747. )
  748. {
  749. DEVICE_OBJECT * pDevObj;
  750. DWORD dwRetCode = NO_ERROR;
  751. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  752. do
  753. {
  754. if ( ( pDevObj = DeviceObjGetPointer( (HPORT)hPort ) ) == NULL )
  755. {
  756. dwRetCode = ERROR_INVALID_HANDLE;
  757. break;
  758. }
  759. if ( pDevObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  760. {
  761. RasApiCleanUpPort( pDevObj );
  762. }
  763. else
  764. {
  765. if ( pDevObj->fFlags & DEV_OBJ_PPP_IS_ACTIVE )
  766. {
  767. PppDdmStop( (HPORT)pDevObj->hPort, NO_ERROR );
  768. }
  769. else
  770. {
  771. DevStartClosing( pDevObj );
  772. }
  773. }
  774. }
  775. while( FALSE );
  776. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  777. return( dwRetCode );
  778. }
  779. //**
  780. //
  781. // Call: DDMRegisterConnectionNotification
  782. //
  783. // Returns: NO_ERROR - Success
  784. // Non-zero returns - Failure
  785. //
  786. // Description: Will insert or remove and event from the notification list
  787. //
  788. DWORD
  789. DDMRegisterConnectionNotification(
  790. IN BOOL fRegister,
  791. IN HANDLE hEventClient,
  792. IN HANDLE hEventRouter
  793. )
  794. {
  795. DWORD dwRetCode = NO_ERROR;
  796. NOTIFICATION_EVENT * pNotificationEvent = NULL;
  797. EnterCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  798. if ( fRegister )
  799. {
  800. //
  801. // Insert event in notification list
  802. //
  803. pNotificationEvent = (NOTIFICATION_EVENT *)
  804. LOCAL_ALLOC(
  805. LPTR,
  806. sizeof(NOTIFICATION_EVENT) );
  807. if ( pNotificationEvent == NULL )
  808. {
  809. dwRetCode = GetLastError();
  810. }
  811. else
  812. {
  813. pNotificationEvent->hEventClient = hEventClient;
  814. pNotificationEvent->hEventRouter = hEventRouter;
  815. InsertHeadList(
  816. (LIST_ENTRY *)&(gblDDMConfigInfo.NotificationEventListHead),
  817. (LIST_ENTRY*)pNotificationEvent );
  818. }
  819. }
  820. else
  821. {
  822. //
  823. // Remove event from notification list
  824. //
  825. for( pNotificationEvent = (NOTIFICATION_EVENT *)
  826. (gblDDMConfigInfo.NotificationEventListHead.Flink);
  827. pNotificationEvent != (NOTIFICATION_EVENT *)
  828. &(gblDDMConfigInfo.NotificationEventListHead);
  829. pNotificationEvent = (NOTIFICATION_EVENT *)
  830. (pNotificationEvent->ListEntry.Flink) )
  831. {
  832. if ( pNotificationEvent->hEventClient == hEventClient )
  833. {
  834. RemoveEntryList( (LIST_ENTRY *)pNotificationEvent );
  835. CloseHandle( pNotificationEvent->hEventClient );
  836. CloseHandle( pNotificationEvent->hEventRouter );
  837. LOCAL_FREE( pNotificationEvent );
  838. break;
  839. }
  840. }
  841. }
  842. LeaveCriticalSection( &(gblpInterfaceTable->CriticalSection) );
  843. return( dwRetCode );
  844. }
  845. //**
  846. //
  847. // Call: DDMSendUserMessage
  848. //
  849. // Returns: NO_ERROR - Success
  850. //
  851. // Description:
  852. //
  853. DWORD
  854. DDMSendUserMessage(
  855. IN HANDLE hConnection,
  856. IN LPWSTR lpwszMessage
  857. )
  858. {
  859. PCONNECTION_OBJECT pConnObj = NULL;
  860. DWORD dwRetCode = NO_ERROR;
  861. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  862. do
  863. {
  864. pConnObj = ConnObjGetPointer( (HCONN)hConnection );
  865. if ( pConnObj == (CONNECTION_OBJECT *)NULL )
  866. {
  867. dwRetCode = ERROR_INTERFACE_NOT_CONNECTED;
  868. break;
  869. }
  870. if ( pConnObj->fFlags & CONN_OBJ_MESSENGER_PRESENT )
  871. {
  872. WCHAR wszRemoteComputer[CNLEN+1];
  873. MultiByteToWideChar( CP_ACP,
  874. 0,
  875. pConnObj->bComputerName,
  876. -1,
  877. wszRemoteComputer,
  878. CNLEN+1 );
  879. dwRetCode = NetMessageBufferSend(
  880. NULL,
  881. wszRemoteComputer,
  882. NULL,
  883. (BYTE*)lpwszMessage,
  884. (wcslen(lpwszMessage)+1) * sizeof(WCHAR));
  885. }
  886. } while( FALSE );
  887. LeaveCriticalSection( &(gblDeviceTable.CriticalSection) );
  888. return(dwRetCode);
  889. }
  890. DWORD
  891. DDMAdminRemoveQuarantine(
  892. IN HANDLE hConnection,
  893. IN BOOL fIsIpAddress)
  894. {
  895. DWORD dwBucketIndex;
  896. CONNECTION_OBJECT *pConnObj = NULL;
  897. DWORD dwErr = ERROR_SUCCESS;
  898. BOOL fFound = FALSE;
  899. EnterCriticalSection(&gblDeviceTable.CriticalSection);
  900. if(fIsIpAddress)
  901. {
  902. for ( dwBucketIndex = 0;
  903. dwBucketIndex < gblDeviceTable.NumDeviceBuckets;
  904. dwBucketIndex++ )
  905. {
  906. for( pConnObj = gblDeviceTable.ConnectionBucket[dwBucketIndex];
  907. pConnObj != (CONNECTION_OBJECT *)NULL;
  908. pConnObj = pConnObj->pNext )
  909. {
  910. if(pConnObj->PppProjectionResult.ip.dwRemoteAddress ==
  911. HandleToUlong(hConnection))
  912. {
  913. fFound = TRUE;
  914. break;
  915. }
  916. }
  917. if(fFound)
  918. {
  919. break;
  920. }
  921. }
  922. }
  923. else
  924. {
  925. pConnObj = ConnObjGetPointer((HCONN) hConnection);
  926. }
  927. if(NULL != pConnObj)
  928. {
  929. //
  930. // If we have a valid connection object, Remove quarantine
  931. // on the connection object.
  932. //
  933. dwErr = RemoveQuarantineOnConnection(pConnObj);
  934. }
  935. else
  936. {
  937. dwErr = ERROR_INTERFACE_NOT_CONNECTED;
  938. }
  939. LeaveCriticalSection(&gblDeviceTable.CriticalSection);
  940. return dwErr;
  941. }