Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

625 lines
18 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: mibapi.c
  7. //
  8. // Description: Contains code to manipulate MIB apis
  9. //
  10. // History: May 11,1995 NarenG Created original version.
  11. //
  12. #include "dimsvcp.h"
  13. #include <dimsvc.h> // Generated by MIDL
  14. //**
  15. //
  16. // Call: RMIBEntryCreate
  17. //
  18. // Returns: NO_ERROR - Success
  19. // ERROR_UNKNOWN_PROTOCOL_ID or non-zero return code from
  20. // MIBEntryCreate
  21. //
  22. // Description: Simply called the appropriate router manager to do the real
  23. // work.
  24. //
  25. DWORD
  26. RMIBEntryCreate(
  27. IN MIB_SERVER_HANDLE hMibServer,
  28. IN DWORD dwPid,
  29. IN DWORD dwRoutingPid,
  30. IN PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  31. )
  32. {
  33. DWORD dwAccessStatus;
  34. DWORD dwRetCode = NO_ERROR;
  35. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  36. //
  37. // Check if caller has access
  38. //
  39. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  40. {
  41. return( ERROR_ACCESS_DENIED );
  42. }
  43. if ( dwAccessStatus )
  44. {
  45. return( ERROR_ACCESS_DENIED );
  46. }
  47. if ( dwTransportIndex == (DWORD)-1 )
  48. {
  49. return( ERROR_UNKNOWN_PROTOCOL_ID );
  50. }
  51. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryCreate(
  52. dwRoutingPid,
  53. pInfoStruct->dwMibInEntrySize,
  54. pInfoStruct->pMibInEntry );
  55. return( dwRetCode );
  56. }
  57. //**
  58. //
  59. // Call: RMIBEntryDelete
  60. //
  61. // Returns: NO_ERROR - Success
  62. // ERROR_UNKNOWN_PROTOCOL_ID or non-zero return code from
  63. // MIBEntryCreate
  64. //
  65. // Description: Simply called the appropriate router manager to do the real
  66. // work.
  67. //
  68. DWORD
  69. RMIBEntryDelete(
  70. IN MIB_SERVER_HANDLE hMibServer,
  71. IN DWORD dwPid,
  72. IN DWORD dwRoutingPid,
  73. IN PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  74. )
  75. {
  76. DWORD dwAccessStatus;
  77. DWORD dwRetCode = NO_ERROR;
  78. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  79. //
  80. // Check if caller has access
  81. //
  82. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  83. {
  84. return( ERROR_ACCESS_DENIED );
  85. }
  86. if ( dwAccessStatus )
  87. {
  88. return( ERROR_ACCESS_DENIED );
  89. }
  90. if ( dwTransportIndex == (DWORD)-1 )
  91. {
  92. return( ERROR_UNKNOWN_PROTOCOL_ID );
  93. }
  94. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryDelete(
  95. dwRoutingPid,
  96. pInfoStruct->dwMibInEntrySize,
  97. pInfoStruct->pMibInEntry );
  98. return( dwRetCode );
  99. }
  100. //**
  101. //
  102. // Call: RMIBEntrySet
  103. //
  104. // Returns: NO_ERROR - Success
  105. // ERROR_UNKNOWN_PROTOCOL_ID or non-zero return code from
  106. // MIBEntryCreate
  107. //
  108. // Description: Simply called the appropriate router manager to do the real
  109. // work.
  110. //
  111. DWORD
  112. RMIBEntrySet(
  113. IN MIB_SERVER_HANDLE hMibServer,
  114. IN DWORD dwPid,
  115. IN DWORD dwRoutingPid,
  116. IN PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  117. )
  118. {
  119. DWORD dwAccessStatus;
  120. DWORD dwRetCode = NO_ERROR;
  121. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  122. //
  123. // Check if caller has access
  124. //
  125. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  126. {
  127. return( ERROR_ACCESS_DENIED );
  128. }
  129. if ( dwAccessStatus )
  130. {
  131. return( ERROR_ACCESS_DENIED );
  132. }
  133. if ( dwTransportIndex == (DWORD)-1 )
  134. {
  135. return( ERROR_UNKNOWN_PROTOCOL_ID );
  136. }
  137. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntrySet(
  138. dwRoutingPid,
  139. pInfoStruct->dwMibInEntrySize,
  140. pInfoStruct->pMibInEntry );
  141. return( dwRetCode );
  142. }
  143. //**
  144. //
  145. // Call: RMIBEntryGet
  146. //
  147. // Returns: NO_ERROR - Success
  148. // ERROR_UNKNOWN_PROTOCOL_ID
  149. // ERROR_NOT_ENOUGH_MEMORY
  150. // non-zero return code from MIBEntryGet
  151. //
  152. // Description: Simply called the appropriate router manager to do the real
  153. // work.
  154. //
  155. //
  156. DWORD
  157. RMIBEntryGet(
  158. IN MIB_SERVER_HANDLE hMibServer,
  159. IN DWORD dwPid,
  160. IN DWORD dwRoutingPid,
  161. IN OUT PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  162. )
  163. {
  164. LPBYTE pOutputBuf = NULL;
  165. DWORD dwOutputBufSize = 0;
  166. DWORD dwRetCode = NO_ERROR;
  167. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  168. //
  169. // We do not do access check for MIB Get apis since these are called
  170. // by iphlpapi.dll which can be run in the user's context. It is assumed
  171. // that the various mibs will take care of their own security.
  172. //
  173. if ( dwTransportIndex == (DWORD)-1 )
  174. {
  175. return( ERROR_UNKNOWN_PROTOCOL_ID );
  176. }
  177. //
  178. // First get the size of the required entry
  179. //
  180. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryGet(
  181. dwRoutingPid,
  182. pInfoStruct->dwMibInEntrySize,
  183. pInfoStruct->pMibInEntry,
  184. &dwOutputBufSize,
  185. NULL );
  186. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  187. {
  188. return( dwRetCode );
  189. }
  190. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  191. if ( pOutputBuf == NULL )
  192. {
  193. return( ERROR_NOT_ENOUGH_MEMORY );
  194. }
  195. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryGet(
  196. dwRoutingPid,
  197. pInfoStruct->dwMibInEntrySize,
  198. pInfoStruct->pMibInEntry,
  199. &dwOutputBufSize,
  200. pOutputBuf );
  201. if ( dwRetCode == NO_ERROR )
  202. {
  203. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  204. pInfoStruct->pMibOutEntry = pOutputBuf;
  205. }
  206. else
  207. {
  208. pInfoStruct->dwMibOutEntrySize = 0;
  209. pInfoStruct->pMibOutEntry = NULL;
  210. MIDL_user_free( pOutputBuf );
  211. }
  212. return( dwRetCode );
  213. }
  214. //**
  215. //
  216. // Call: RMIBEntryGetFirst
  217. //
  218. // Returns: NO_ERROR - Success
  219. // ERROR_UNKNOWN_PROTOCOL_ID
  220. // ERROR_NOT_ENOUGH_MEMORY
  221. // non-zero return code from MIBEntryGetFirst
  222. //
  223. // Description: Simply called the appropriate router manager to do the real
  224. // work.
  225. //
  226. //
  227. DWORD
  228. RMIBEntryGetFirst(
  229. IN MIB_SERVER_HANDLE hMibServer,
  230. IN DWORD dwPid,
  231. IN DWORD dwRoutingPid,
  232. IN OUT PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  233. )
  234. {
  235. LPBYTE pOutputBuf = NULL;
  236. DWORD dwOutputBufSize = 0;
  237. DWORD dwRetCode = NO_ERROR;
  238. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  239. //
  240. // We do not do access check for MIB Get apis since these are called
  241. // by iphlpapi.dll which can be run in the user's context. It is assumed
  242. // that the various mibs will take care of their own security.
  243. //
  244. if ( dwTransportIndex == (DWORD)-1 )
  245. {
  246. return( ERROR_UNKNOWN_PROTOCOL_ID );
  247. }
  248. //
  249. // First get the size of the required entry
  250. //
  251. dwRetCode=gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryGetFirst(
  252. dwRoutingPid,
  253. pInfoStruct->dwMibInEntrySize,
  254. pInfoStruct->pMibInEntry,
  255. &dwOutputBufSize,
  256. NULL );
  257. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  258. {
  259. return( dwRetCode );
  260. }
  261. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  262. if ( pOutputBuf == NULL )
  263. {
  264. return( ERROR_NOT_ENOUGH_MEMORY );
  265. }
  266. dwRetCode=gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryGetFirst(
  267. dwRoutingPid,
  268. pInfoStruct->dwMibInEntrySize,
  269. pInfoStruct->pMibInEntry,
  270. &dwOutputBufSize,
  271. pOutputBuf );
  272. if ( dwRetCode == NO_ERROR )
  273. {
  274. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  275. pInfoStruct->pMibOutEntry = pOutputBuf;
  276. }
  277. else
  278. {
  279. pInfoStruct->dwMibOutEntrySize = 0;
  280. pInfoStruct->pMibOutEntry = NULL;
  281. MIDL_user_free( pOutputBuf );
  282. }
  283. return( dwRetCode );
  284. }
  285. //**
  286. //
  287. // Call: RMIBEntryGetNext
  288. //
  289. // Returns: NO_ERROR - Success
  290. // ERROR_UNKNOWN_PROTOCOL_ID
  291. // ERROR_NOT_ENOUGH_MEMORY
  292. // non-zero return code from MIBEntryGetNext
  293. //
  294. // Description: Simply called the appropriate router manager to do the real
  295. // work.
  296. //
  297. DWORD
  298. RMIBEntryGetNext(
  299. IN MIB_SERVER_HANDLE hMibServer,
  300. IN DWORD dwPid,
  301. IN DWORD dwRoutingPid,
  302. IN OUT PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  303. )
  304. {
  305. LPBYTE pOutputBuf = NULL;
  306. DWORD dwOutputBufSize = 0;
  307. DWORD dwRetCode = NO_ERROR;
  308. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  309. //
  310. // We do not do access check for MIB Get apis since these are called
  311. // by iphlpapi.dll which can be run in the user's context. It is assumed
  312. // that the various mibs will take care of their own security.
  313. //
  314. if ( dwTransportIndex == (DWORD)-1 )
  315. {
  316. return( ERROR_UNKNOWN_PROTOCOL_ID );
  317. }
  318. //
  319. // First get the size of the required entry
  320. //
  321. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryGetNext(
  322. dwRoutingPid,
  323. pInfoStruct->dwMibInEntrySize,
  324. pInfoStruct->pMibInEntry,
  325. &dwOutputBufSize,
  326. NULL );
  327. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  328. {
  329. return( dwRetCode );
  330. }
  331. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  332. if ( pOutputBuf == NULL )
  333. {
  334. return( ERROR_NOT_ENOUGH_MEMORY );
  335. }
  336. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBEntryGetNext(
  337. dwRoutingPid,
  338. pInfoStruct->dwMibInEntrySize,
  339. pInfoStruct->pMibInEntry,
  340. &dwOutputBufSize,
  341. pOutputBuf );
  342. if ( dwRetCode == NO_ERROR )
  343. {
  344. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  345. pInfoStruct->pMibOutEntry = pOutputBuf;
  346. }
  347. else
  348. {
  349. pInfoStruct->dwMibOutEntrySize = 0;
  350. pInfoStruct->pMibOutEntry = NULL;
  351. MIDL_user_free( pOutputBuf );
  352. }
  353. return( dwRetCode );
  354. }
  355. //**
  356. //
  357. // Call: RMIBGetTrapInfo
  358. //
  359. // Returns: NO_ERROR - Success
  360. // ERROR_UNKNOWN_PROTOCOL_ID
  361. // ERROR_NOT_ENOUGH_MEMORY
  362. // non-zero return code from MIBGetTrapInfo
  363. //
  364. // Description: Simply called the appropriate router manager to do the real
  365. // work.
  366. //
  367. DWORD
  368. RMIBGetTrapInfo(
  369. IN MIB_SERVER_HANDLE hMibServer,
  370. IN DWORD dwPid,
  371. IN DWORD dwRoutingPid,
  372. IN OUT PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  373. )
  374. {
  375. LPBYTE pOutputBuf = NULL;
  376. DWORD dwOutputBufSize = 0;
  377. DWORD dwRetCode = NO_ERROR;
  378. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  379. //
  380. // We do not do access check for MIB Get apis since these are called
  381. // by iphlpapi.dll which can be run in the user's context. It is assumed
  382. // that the various mibs will take care of their own security.
  383. //
  384. if ( dwTransportIndex == (DWORD)-1 )
  385. {
  386. return( ERROR_UNKNOWN_PROTOCOL_ID );
  387. }
  388. //
  389. // First get the size of the required entry
  390. //
  391. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBGetTrapInfo(
  392. dwRoutingPid,
  393. pInfoStruct->dwMibInEntrySize,
  394. pInfoStruct->pMibInEntry,
  395. &dwOutputBufSize,
  396. NULL );
  397. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  398. {
  399. return( dwRetCode );
  400. }
  401. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  402. if ( pOutputBuf == NULL )
  403. {
  404. return( ERROR_NOT_ENOUGH_MEMORY );
  405. }
  406. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBGetTrapInfo(
  407. dwRoutingPid,
  408. pInfoStruct->dwMibInEntrySize,
  409. pInfoStruct->pMibInEntry,
  410. &dwOutputBufSize,
  411. pOutputBuf );
  412. if ( dwRetCode == NO_ERROR )
  413. {
  414. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  415. pInfoStruct->pMibOutEntry = pOutputBuf;
  416. }
  417. else
  418. {
  419. pInfoStruct->dwMibOutEntrySize = 0;
  420. pInfoStruct->pMibOutEntry = NULL;
  421. MIDL_user_free( pOutputBuf );
  422. }
  423. return( dwRetCode );
  424. }
  425. //**
  426. //
  427. // Call: RMIBSetTrapInfo
  428. //
  429. // Returns: NO_ERROR - Success
  430. // ERROR_UNKNOWN_PROTOCOL_ID
  431. // ERROR_NOT_ENOUGH_MEMORY
  432. // non-zero return code from MIBSetTrapInfo
  433. // Failures from OpenProcess
  434. // Failures from DuplicateHandle
  435. //
  436. // Description: Simply called the appropriate router manager to do the real
  437. // work.
  438. //
  439. DWORD
  440. RMIBSetTrapInfo(
  441. IN MIB_SERVER_HANDLE hMibServer,
  442. IN DWORD dwPid,
  443. IN DWORD dwRoutingPid,
  444. IN ULONG_PTR hEvent,
  445. IN DWORD dwClientProcessId,
  446. IN OUT PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  447. )
  448. {
  449. DWORD dwAccessStatus;
  450. LPBYTE pOutputBuf = NULL;
  451. DWORD dwOutputBufSize = 0;
  452. DWORD dwRetCode = NO_ERROR;
  453. HANDLE hDuplicatedEvent;
  454. HANDLE hClientProcess;
  455. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  456. //
  457. // Check if caller has access
  458. //
  459. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  460. {
  461. return( ERROR_ACCESS_DENIED );
  462. }
  463. if ( dwAccessStatus )
  464. {
  465. return( ERROR_ACCESS_DENIED );
  466. }
  467. if ( dwTransportIndex == (DWORD)-1 )
  468. {
  469. return( ERROR_UNKNOWN_PROTOCOL_ID );
  470. }
  471. //
  472. // Get process handle of the caller of this API
  473. //
  474. hClientProcess = OpenProcess(
  475. STANDARD_RIGHTS_REQUIRED | SPECIFIC_RIGHTS_ALL,
  476. FALSE,
  477. dwClientProcessId);
  478. if ( hClientProcess == NULL )
  479. {
  480. return( GetLastError() );
  481. }
  482. //
  483. // Duplicate the handle to the event
  484. //
  485. if ( !DuplicateHandle( hClientProcess,
  486. (HANDLE)hEvent,
  487. GetCurrentProcess(),
  488. &hDuplicatedEvent,
  489. 0,
  490. FALSE,
  491. DUPLICATE_SAME_ACCESS ) )
  492. {
  493. CloseHandle( hClientProcess );
  494. return( GetLastError() );
  495. }
  496. CloseHandle( hClientProcess );
  497. //
  498. // First get the size of the required entry
  499. //
  500. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBSetTrapInfo(
  501. dwRoutingPid,
  502. hDuplicatedEvent,
  503. pInfoStruct->dwMibInEntrySize,
  504. pInfoStruct->pMibInEntry,
  505. &dwOutputBufSize,
  506. NULL );
  507. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  508. {
  509. CloseHandle( hDuplicatedEvent );
  510. return( dwRetCode );
  511. }
  512. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  513. if ( pOutputBuf == NULL )
  514. {
  515. CloseHandle( hDuplicatedEvent );
  516. return( ERROR_NOT_ENOUGH_MEMORY );
  517. }
  518. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBSetTrapInfo(
  519. dwRoutingPid,
  520. hDuplicatedEvent,
  521. pInfoStruct->dwMibInEntrySize,
  522. pInfoStruct->pMibInEntry,
  523. &dwOutputBufSize,
  524. pOutputBuf );
  525. if ( dwRetCode == NO_ERROR )
  526. {
  527. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  528. pInfoStruct->pMibOutEntry = pOutputBuf;
  529. }
  530. else
  531. {
  532. pInfoStruct->dwMibOutEntrySize = 0;
  533. pInfoStruct->pMibOutEntry = NULL;
  534. MIDL_user_free( pOutputBuf );
  535. CloseHandle( hDuplicatedEvent );
  536. }
  537. return( dwRetCode );
  538. }