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.

635 lines
19 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. if (gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBGetTrapInfo == NULL)
  389. {
  390. return ERROR_CAN_NOT_COMPLETE;
  391. }
  392. //
  393. // First get the size of the required entry
  394. //
  395. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBGetTrapInfo(
  396. dwRoutingPid,
  397. pInfoStruct->dwMibInEntrySize,
  398. pInfoStruct->pMibInEntry,
  399. &dwOutputBufSize,
  400. NULL );
  401. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  402. {
  403. return( dwRetCode );
  404. }
  405. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  406. if ( pOutputBuf == NULL )
  407. {
  408. return( ERROR_NOT_ENOUGH_MEMORY );
  409. }
  410. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBGetTrapInfo(
  411. dwRoutingPid,
  412. pInfoStruct->dwMibInEntrySize,
  413. pInfoStruct->pMibInEntry,
  414. &dwOutputBufSize,
  415. pOutputBuf );
  416. if ( dwRetCode == NO_ERROR )
  417. {
  418. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  419. pInfoStruct->pMibOutEntry = pOutputBuf;
  420. }
  421. else
  422. {
  423. pInfoStruct->dwMibOutEntrySize = 0;
  424. pInfoStruct->pMibOutEntry = NULL;
  425. MIDL_user_free( pOutputBuf );
  426. }
  427. return( dwRetCode );
  428. }
  429. //**
  430. //
  431. // Call: RMIBSetTrapInfo
  432. //
  433. // Returns: NO_ERROR - Success
  434. // ERROR_UNKNOWN_PROTOCOL_ID
  435. // ERROR_NOT_ENOUGH_MEMORY
  436. // non-zero return code from MIBSetTrapInfo
  437. // Failures from OpenProcess
  438. // Failures from DuplicateHandle
  439. //
  440. // Description: Simply called the appropriate router manager to do the real
  441. // work.
  442. //
  443. DWORD
  444. RMIBSetTrapInfo(
  445. IN MIB_SERVER_HANDLE hMibServer,
  446. IN DWORD dwPid,
  447. IN DWORD dwRoutingPid,
  448. IN ULONG_PTR hEvent,
  449. IN DWORD dwClientProcessId,
  450. IN OUT PDIM_MIB_ENTRY_CONTAINER pInfoStruct
  451. )
  452. {
  453. DWORD dwAccessStatus;
  454. LPBYTE pOutputBuf = NULL;
  455. DWORD dwOutputBufSize = 0;
  456. DWORD dwRetCode = NO_ERROR;
  457. HANDLE hDuplicatedEvent;
  458. HANDLE hClientProcess;
  459. DWORD dwTransportIndex = GetTransportIndex( dwPid );
  460. //
  461. // Check if caller has access
  462. //
  463. if ( DimSecObjAccessCheck( DIMSVC_ALL_ACCESS, &dwAccessStatus) != NO_ERROR)
  464. {
  465. return( ERROR_ACCESS_DENIED );
  466. }
  467. if ( dwAccessStatus )
  468. {
  469. return( ERROR_ACCESS_DENIED );
  470. }
  471. if ( dwTransportIndex == (DWORD)-1 )
  472. {
  473. return( ERROR_UNKNOWN_PROTOCOL_ID );
  474. }
  475. if (gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBSetTrapInfo == NULL)
  476. {
  477. return ERROR_CAN_NOT_COMPLETE;
  478. }
  479. //
  480. // Get process handle of the caller of this API
  481. //
  482. hClientProcess = OpenProcess(
  483. STANDARD_RIGHTS_REQUIRED | SPECIFIC_RIGHTS_ALL,
  484. FALSE,
  485. dwClientProcessId);
  486. if ( hClientProcess == NULL )
  487. {
  488. return( GetLastError() );
  489. }
  490. //
  491. // Duplicate the handle to the event
  492. //
  493. if ( !DuplicateHandle( hClientProcess,
  494. (HANDLE)hEvent,
  495. GetCurrentProcess(),
  496. &hDuplicatedEvent,
  497. 0,
  498. FALSE,
  499. DUPLICATE_SAME_ACCESS ) )
  500. {
  501. CloseHandle( hClientProcess );
  502. return( GetLastError() );
  503. }
  504. CloseHandle( hClientProcess );
  505. //
  506. // First get the size of the required entry
  507. //
  508. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBSetTrapInfo(
  509. dwRoutingPid,
  510. hDuplicatedEvent,
  511. pInfoStruct->dwMibInEntrySize,
  512. pInfoStruct->pMibInEntry,
  513. &dwOutputBufSize,
  514. NULL );
  515. if ( dwRetCode != ERROR_INSUFFICIENT_BUFFER )
  516. {
  517. CloseHandle( hDuplicatedEvent );
  518. return( dwRetCode );
  519. }
  520. pOutputBuf = MIDL_user_allocate( dwOutputBufSize );
  521. if ( pOutputBuf == NULL )
  522. {
  523. CloseHandle( hDuplicatedEvent );
  524. return( ERROR_NOT_ENOUGH_MEMORY );
  525. }
  526. dwRetCode = gblRouterManagers[dwTransportIndex].DdmRouterIf.MIBSetTrapInfo(
  527. dwRoutingPid,
  528. hDuplicatedEvent,
  529. pInfoStruct->dwMibInEntrySize,
  530. pInfoStruct->pMibInEntry,
  531. &dwOutputBufSize,
  532. pOutputBuf );
  533. if ( dwRetCode == NO_ERROR )
  534. {
  535. pInfoStruct->dwMibOutEntrySize = dwOutputBufSize;
  536. pInfoStruct->pMibOutEntry = pOutputBuf;
  537. }
  538. else
  539. {
  540. pInfoStruct->dwMibOutEntrySize = 0;
  541. pInfoStruct->pMibOutEntry = NULL;
  542. MIDL_user_free( pOutputBuf );
  543. CloseHandle( hDuplicatedEvent );
  544. }
  545. return( dwRetCode );
  546. }