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.

1175 lines
34 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ripflts.c
  5. Abstract:
  6. IPX Router Console Monitoring and Configuration tool.
  7. RIP Filters configuration and monitoring.
  8. Author:
  9. Vadim Eydelman 06/07/1996
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define OPERATION_DEL_RIPFILTER (-1)
  14. #define OPERATION_SET_RIPFILTER 0
  15. #define OPERATION_ADD_RIPFILTER 1
  16. DWORD
  17. AdmSetRipFlt (
  18. int operation,
  19. LPWSTR InterfaceNameW,
  20. ULONG Action,
  21. ULONG Mode,
  22. PRIP_ROUTE_FILTER_INFO RipFilter
  23. );
  24. DWORD
  25. CfgSetRipFlt (
  26. int operation,
  27. LPWSTR InterfaceNameW,
  28. ULONG Action,
  29. ULONG Mode,
  30. PRIP_ROUTE_FILTER_INFO RipFilter
  31. );
  32. DWORD
  33. SetRipFltAction (
  34. LPBYTE pIfBlock,
  35. BOOLEAN Output,
  36. ULONG Action
  37. );
  38. DWORD
  39. APIENTRY
  40. HelpRipFlt (
  41. IN int argc,
  42. IN WCHAR *argv[]
  43. )
  44. {
  45. DisplayMessage (g_hModule, HLP_IPX_RIPFILTER );
  46. return 0;
  47. }
  48. DWORD
  49. APIENTRY
  50. ShowRipFlt (
  51. IN int argc,
  52. IN WCHAR *argv[],
  53. IN HANDLE hFile
  54. )
  55. {
  56. DWORD rc;
  57. if (argc > 0)
  58. {
  59. PWCHAR buffer[2];
  60. LPBYTE pIfBlock;
  61. BOOLEAN fRouter = FALSE, fClient;
  62. ULONG mode = 0;
  63. unsigned count;
  64. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  65. DWORD dwSize = sizeof(IfName);
  66. #define InterfaceNameW argv[0]
  67. count = wcslen (InterfaceNameW);
  68. if ( !_wcsicmp( argv[0], VAL_DIALINCLIENT ) )
  69. {
  70. fClient = TRUE;
  71. }
  72. else if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  73. {
  74. fClient = FALSE;
  75. }
  76. else
  77. {
  78. if ( !hFile ) { DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME); }
  79. rc = ERROR_INVALID_PARAMETER;
  80. goto Exit;
  81. }
  82. if (argc > 1)
  83. {
  84. UINT n;
  85. if ( (argc == 2) &&
  86. !MatchEnumTag(
  87. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  88. FilterModes, &mode
  89. ) )
  90. {
  91. NOTHING;
  92. }
  93. else
  94. {
  95. if ( !hFile ) { DisplayMessage (g_hModule, HLP_IPX_RIPFILTER); }
  96. rc = ERROR_INVALID_PARAMETER;
  97. goto Exit;
  98. }
  99. }
  100. if (g_hMprAdmin)
  101. {
  102. if (fClient)
  103. {
  104. DWORD sz;
  105. rc = MprAdminTransportGetInfo(
  106. g_hMprAdmin, PID_IPX, NULL, NULL, &pIfBlock, &sz
  107. );
  108. if (rc == NO_ERROR)
  109. {
  110. fRouter = TRUE;
  111. }
  112. else
  113. {
  114. if ( !hFile ) { DisplayError( g_hModule, rc); }
  115. goto GetFromCfg;
  116. }
  117. }
  118. else
  119. {
  120. HANDLE hIfAdm;
  121. //======================================
  122. // Translate the Interface Name
  123. //======================================
  124. rc = IpmontrGetIfNameFromFriendlyName(
  125. InterfaceNameW, IfName, &dwSize
  126. );
  127. if ( rc == NO_ERROR )
  128. {
  129. rc = MprAdminInterfaceGetHandle(
  130. g_hMprAdmin, IfName, &hIfAdm, FALSE
  131. );
  132. if (rc == NO_ERROR)
  133. {
  134. DWORD sz;
  135. rc = MprAdminInterfaceTransportGetInfo(
  136. g_hMprAdmin, hIfAdm, PID_IPX, &pIfBlock, &sz
  137. );
  138. }
  139. if (rc == NO_ERROR)
  140. {
  141. fRouter = TRUE;
  142. }
  143. else
  144. {
  145. if ( !hFile ) { DisplayError( g_hModule, rc ); }
  146. goto GetFromCfg;
  147. }
  148. }
  149. }
  150. }
  151. else
  152. {
  153. GetFromCfg:
  154. if (fClient)
  155. {
  156. HANDLE hTrCfg;
  157. rc = MprConfigTransportGetHandle (
  158. g_hMprConfig, PID_IPX, &hTrCfg
  159. );
  160. if (rc == NO_ERROR)
  161. {
  162. DWORD sz;
  163. rc = MprConfigTransportGetInfo (
  164. g_hMprConfig, hTrCfg, NULL, NULL, &pIfBlock, &sz,
  165. NULL
  166. );
  167. }
  168. }
  169. else
  170. {
  171. HANDLE hIfCfg;
  172. //======================================
  173. // Translate the Interface Name
  174. //======================================
  175. rc = IpmontrGetIfNameFromFriendlyName(
  176. InterfaceNameW, IfName, &dwSize
  177. );
  178. if ( rc == NO_ERROR )
  179. {
  180. rc = MprConfigInterfaceGetHandle(
  181. g_hMprConfig, IfName, &hIfCfg
  182. );
  183. if (rc == NO_ERROR)
  184. {
  185. HANDLE hIfTrCfg;
  186. rc = MprConfigInterfaceTransportGetHandle(
  187. g_hMprConfig, hIfCfg, PID_IPX, &hIfTrCfg
  188. );
  189. if (rc == NO_ERROR)
  190. {
  191. DWORD sz;
  192. rc = MprConfigInterfaceTransportGetInfo(
  193. g_hMprConfig, hIfCfg, hIfTrCfg, &pIfBlock, &sz
  194. );
  195. }
  196. }
  197. }
  198. }
  199. }
  200. if (rc == NO_ERROR)
  201. {
  202. PIPX_TOC_ENTRY pRipToc;
  203. pRipToc = GetIPXTocEntry(
  204. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  205. IPX_PROTOCOL_RIP
  206. );
  207. if (pRipToc != NULL)
  208. {
  209. PRIP_IF_CONFIG pRipCfg;
  210. UINT i;
  211. pRipCfg = (PRIP_IF_CONFIG)
  212. (pIfBlock + pRipToc->Offset);
  213. if ( (mode == 0) || (mode == OUTPUT_FILTER) )
  214. {
  215. if (pRipCfg->RipIfFilters.SupplyFilterCount > 0)
  216. {
  217. PRIP_ROUTE_FILTER_INFO pRipFilter =
  218. &pRipCfg->RipIfFilters.RouteFilter[0];
  219. buffer[ 0 ] = VAL_OUTPUT;
  220. buffer[ 1 ] = GetEnumString(
  221. g_hModule,
  222. pRipCfg->RipIfFilters.SupplyFilterAction,
  223. NUM_TOKENS_IN_TABLE( RipFilterActions ),
  224. RipFilterActions
  225. );
  226. if ( buffer[ 0 ] && buffer[ 1 ] )
  227. {
  228. if ( hFile )
  229. {
  230. DisplayMessageT(
  231. DMP_IPX_RIP_SET_FILTER, InterfaceNameW,
  232. buffer[ 0 ], buffer[ 1 ]
  233. );
  234. }
  235. else
  236. {
  237. DisplayIPXMessage(
  238. g_hModule, MSG_RIPFILTER_TABLE_HDR,
  239. buffer[ 0 ], buffer[1]
  240. );
  241. }
  242. for ( i = 0;
  243. i < pRipCfg->RipIfFilters.SupplyFilterCount;
  244. i++, pRipFilter++ )
  245. {
  246. if ( hFile )
  247. {
  248. DisplayMessageT(
  249. DMP_IPX_RIP_ADD_FILTER, InterfaceNameW,
  250. buffer[0],
  251. pRipFilter->Network[0], pRipFilter->Network[1],
  252. pRipFilter->Network[2], pRipFilter->Network[3],
  253. pRipFilter->Mask[0], pRipFilter->Mask[1],
  254. pRipFilter->Mask[2], pRipFilter->Mask[3]
  255. );
  256. }
  257. else
  258. {
  259. DisplayIPXMessage (g_hModule,
  260. MSG_RIPFILTER_TABLE_FMT,
  261. pRipFilter->Network[0], pRipFilter->Network[1],
  262. pRipFilter->Network[2], pRipFilter->Network[3],
  263. pRipFilter->Mask[0], pRipFilter->Mask[1],
  264. pRipFilter->Mask[2], pRipFilter->Mask[3]
  265. );
  266. }
  267. }
  268. }
  269. else
  270. {
  271. rc = ERROR_NOT_ENOUGH_MEMORY;
  272. if ( !hFile ) { DisplayMessage (g_hModule, rc ); }
  273. }
  274. }
  275. else
  276. {
  277. if ( hFile )
  278. {
  279. DisplayMessageT(
  280. DMP_IPX_RIP_SET_FILTER, InterfaceNameW, VAL_OUTPUT,
  281. VAL_DENY
  282. );
  283. }
  284. else
  285. {
  286. DisplayIPXMessage(
  287. g_hModule, MSG_RIPFILTER_TABLE_HDR,
  288. VAL_OUTPUT, VAL_DENY
  289. );
  290. }
  291. }
  292. }
  293. if ((mode == 0) || (mode == INPUT_FILTER))
  294. {
  295. if (pRipCfg->RipIfFilters.ListenFilterCount > 0)
  296. {
  297. PRIP_ROUTE_FILTER_INFO pRipFilter
  298. = &pRipCfg->RipIfFilters.RouteFilter[
  299. pRipCfg->RipIfFilters.SupplyFilterCount
  300. ];
  301. buffer[ 0 ] = VAL_INPUT;
  302. buffer[ 1 ] = GetEnumString(
  303. g_hModule,
  304. pRipCfg->RipIfFilters.ListenFilterAction,
  305. NUM_TOKENS_IN_TABLE( RipFilterActions ),
  306. RipFilterActions
  307. );
  308. if ( buffer[ 0 ] && buffer[ 1 ] )
  309. {
  310. if ( hFile )
  311. {
  312. DisplayMessageT(
  313. DMP_IPX_RIP_SET_FILTER, InterfaceNameW,
  314. buffer[ 0 ], buffer[ 1 ]
  315. );
  316. }
  317. else
  318. {
  319. DisplayIPXMessage(
  320. g_hModule, MSG_RIPFILTER_TABLE_HDR,
  321. buffer[ 0 ], buffer[1]
  322. );
  323. }
  324. for ( i = 0;
  325. i < pRipCfg->RipIfFilters.ListenFilterCount;
  326. i++, pRipFilter++ )
  327. {
  328. if ( hFile )
  329. {
  330. DisplayMessageT(
  331. DMP_IPX_RIP_ADD_FILTER, InterfaceNameW,
  332. buffer[0],
  333. pRipFilter->Network[0], pRipFilter->Network[1],
  334. pRipFilter->Network[2], pRipFilter->Network[3],
  335. pRipFilter->Mask[0], pRipFilter->Mask[1],
  336. pRipFilter->Mask[2], pRipFilter->Mask[3]
  337. );
  338. }
  339. else
  340. {
  341. DisplayIPXMessage (g_hModule,
  342. MSG_RIPFILTER_TABLE_FMT,
  343. pRipFilter->Network[0], pRipFilter->Network[1],
  344. pRipFilter->Network[2], pRipFilter->Network[3],
  345. pRipFilter->Mask[0], pRipFilter->Mask[1],
  346. pRipFilter->Mask[2], pRipFilter->Mask[3]
  347. );
  348. }
  349. }
  350. }
  351. else
  352. {
  353. rc = ERROR_NOT_ENOUGH_MEMORY;
  354. if ( !hFile ) { DisplayMessage (g_hModule, rc ); }
  355. }
  356. }
  357. else
  358. {
  359. if ( hFile )
  360. {
  361. DisplayMessageT(
  362. DMP_IPX_RIP_SET_FILTER, InterfaceNameW, VAL_INPUT,
  363. VAL_DENY
  364. );
  365. }
  366. else
  367. {
  368. DisplayIPXMessage(
  369. g_hModule, MSG_RIPFILTER_TABLE_HDR,
  370. VAL_INPUT, VAL_DENY
  371. );
  372. }
  373. }
  374. }
  375. }
  376. else
  377. {
  378. rc = ERROR_FILE_NOT_FOUND;
  379. if ( !hFile ) { DisplayError( g_hModule, rc); }
  380. }
  381. if (fRouter)
  382. {
  383. MprAdminBufferFree (pIfBlock);
  384. }
  385. else
  386. {
  387. MprConfigBufferFree (pIfBlock);
  388. }
  389. }
  390. else
  391. {
  392. if ( !hFile ) { DisplayError( g_hModule, rc); }
  393. }
  394. }
  395. else
  396. {
  397. if ( !hFile ) { DisplayMessage (g_hModule, HLP_IPX_RIPFILTER); }
  398. rc = ERROR_INVALID_PARAMETER;
  399. }
  400. Exit:
  401. return rc;
  402. #undef InterfaceNameW
  403. }
  404. DWORD
  405. APIENTRY
  406. SetRipFlt(
  407. IN int argc,
  408. IN WCHAR *argv[]
  409. )
  410. {
  411. DWORD rc;
  412. if (argc == 3)
  413. {
  414. PWCHAR buffer;
  415. ULONG mode, action;
  416. UINT n;
  417. RIP_ROUTE_FILTER_INFO RipFilter;
  418. BOOLEAN fClient;
  419. unsigned count;
  420. #define InterfaceNameW argv[0]
  421. count = wcslen (InterfaceNameW);
  422. if ( !_wcsicmp( argv[0], VAL_DIALINCLIENT ) )
  423. {
  424. fClient = TRUE;
  425. }
  426. else if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  427. {
  428. fClient = FALSE;
  429. }
  430. else
  431. {
  432. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME );
  433. rc = ERROR_INVALID_PARAMETER;
  434. goto Exit;
  435. }
  436. if ( !MatchEnumTag(
  437. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  438. FilterModes, &mode
  439. ) &&
  440. !MatchEnumTag(
  441. g_hModule, argv[2], NUM_TOKENS_IN_TABLE( RipFilterActions ),
  442. RipFilterActions, &action
  443. ) )
  444. {
  445. if (g_hMprAdmin)
  446. {
  447. rc = AdmSetRipFlt(
  448. OPERATION_SET_RIPFILTER,
  449. fClient ? NULL : InterfaceNameW,
  450. action,
  451. mode, NULL
  452. );
  453. }
  454. else
  455. {
  456. rc = NO_ERROR;
  457. }
  458. if (rc == NO_ERROR)
  459. {
  460. rc = CfgSetRipFlt(
  461. OPERATION_SET_RIPFILTER,
  462. fClient ? NULL : InterfaceNameW,
  463. action, mode, NULL
  464. );
  465. }
  466. }
  467. else
  468. {
  469. rc = ERROR_INVALID_PARAMETER;
  470. DisplayMessage (g_hModule, HLP_IPX_RIPFILTER);
  471. }
  472. }
  473. else
  474. {
  475. DisplayMessage (g_hModule, HLP_IPX_RIPFILTER);
  476. rc = ERROR_INVALID_PARAMETER;
  477. }
  478. Exit:
  479. return rc;
  480. #undef InterfaceNameW
  481. }
  482. DWORD
  483. APIENTRY
  484. CreateRipFlt(
  485. IN int argc,
  486. IN WCHAR *argv[]
  487. )
  488. {
  489. DWORD rc;
  490. if (argc == 4)
  491. {
  492. PWCHAR buffer = NULL;
  493. ULONG mode;
  494. UINT n;
  495. ULONG val41, val42;
  496. RIP_ROUTE_FILTER_INFO RipFilter;
  497. BOOLEAN fClient;
  498. unsigned count;
  499. #define InterfaceNameW argv[0]
  500. count = wcslen (InterfaceNameW);
  501. if ( !_wcsicmp( argv[0], VAL_DIALINCLIENT ) )
  502. {
  503. fClient = TRUE;
  504. }
  505. else if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  506. {
  507. fClient = FALSE;
  508. }
  509. else
  510. {
  511. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  512. rc = ERROR_INVALID_PARAMETER;
  513. goto Exit;
  514. }
  515. if ( !MatchEnumTag(
  516. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  517. FilterModes, &mode
  518. )
  519. && (swscanf (argv[2], L"%8lx%n", &val41, &n) == 1)
  520. && (n == wcslen (argv[2]))
  521. && (swscanf (argv[3], L"%8lx%n", &val42, &n) == 1)
  522. && (n == wcslen (argv[3]))
  523. && ((val41 & val42) == val41))
  524. {
  525. RipFilter.Network[0] = (BYTE)(val41 >> 24);
  526. RipFilter.Network[1] = (BYTE)(val41 >> 16);
  527. RipFilter.Network[2] = (BYTE)(val41 >> 8);
  528. RipFilter.Network[3] = (BYTE)val41;
  529. RipFilter.Mask[0] = (BYTE)(val42 >> 24);
  530. RipFilter.Mask[1] = (BYTE)(val42 >> 16);
  531. RipFilter.Mask[2] = (BYTE)(val42 >> 8);
  532. RipFilter.Mask[3] = (BYTE)val42;
  533. if (g_hMprAdmin)
  534. {
  535. rc = AdmSetRipFlt(
  536. OPERATION_ADD_RIPFILTER,
  537. fClient ? NULL : InterfaceNameW,
  538. IPX_ROUTE_FILTER_PERMIT,
  539. mode, &RipFilter
  540. );
  541. }
  542. else
  543. {
  544. rc = NO_ERROR;
  545. }
  546. if (rc == NO_ERROR)
  547. {
  548. rc = CfgSetRipFlt(
  549. OPERATION_ADD_RIPFILTER,
  550. fClient ? NULL : InterfaceNameW,
  551. IPX_ROUTE_FILTER_PERMIT,
  552. mode, &RipFilter
  553. );
  554. }
  555. }
  556. else
  557. {
  558. rc = ERROR_INVALID_PARAMETER;
  559. DisplayIPXMessage (g_hModule, HLP_IPX_RIPFILTER);
  560. }
  561. }
  562. else
  563. {
  564. DisplayMessage (g_hModule, HLP_IPX_RIPFILTER);
  565. rc = ERROR_INVALID_PARAMETER;
  566. }
  567. Exit:
  568. return rc;
  569. #undef InterfaceNameW
  570. }
  571. DWORD
  572. APIENTRY
  573. DeleteRipFlt (
  574. IN int argc,
  575. IN WCHAR *argv[]
  576. )
  577. {
  578. DWORD rc;
  579. if (argc == 4)
  580. {
  581. PWCHAR buffer = NULL;
  582. ULONG mode;
  583. UINT n;
  584. ULONG val41, val42;
  585. RIP_ROUTE_FILTER_INFO RipFilter;
  586. BOOLEAN fClient;
  587. unsigned count;
  588. #define InterfaceNameW argv[0]
  589. count = wcslen (InterfaceNameW);
  590. if ( !_wcsicmp( argv[0], VAL_DIALINCLIENT ) )
  591. {
  592. fClient = TRUE;
  593. }
  594. else if ((count > 0) && (count <= MAX_INTERFACE_NAME_LEN))
  595. {
  596. fClient = FALSE;
  597. }
  598. else
  599. {
  600. DisplayIPXMessage (g_hModule, MSG_INVALID_INTERFACE_NAME);
  601. rc = ERROR_INVALID_PARAMETER;
  602. goto Exit;
  603. }
  604. if ( !MatchEnumTag(
  605. g_hModule, argv[1], NUM_TOKENS_IN_TABLE( FilterModes ),
  606. FilterModes, &mode
  607. )
  608. && (swscanf (argv[2], L"%8lx%n", &val41, &n) == 1)
  609. && (n == wcslen (argv[2]))
  610. && (swscanf (argv[3], L"%8lx%n", &val42, &n) == 1)
  611. && (n == wcslen (argv[3]))
  612. && ((val41 & val42) == val41))
  613. {
  614. RipFilter.Network[0] = (BYTE)(val41 >> 24);
  615. RipFilter.Network[1] = (BYTE)(val41 >> 16);
  616. RipFilter.Network[2] = (BYTE)(val41 >> 8);
  617. RipFilter.Network[3] = (BYTE)val41;
  618. RipFilter.Mask[0] = (BYTE)(val42 >> 24);
  619. RipFilter.Mask[1] = (BYTE)(val42 >> 16);
  620. RipFilter.Mask[2] = (BYTE)(val42 >> 8);
  621. RipFilter.Mask[3] = (BYTE)val42;
  622. if (g_hMprAdmin)
  623. {
  624. rc = AdmSetRipFlt(
  625. OPERATION_DEL_RIPFILTER,
  626. fClient ? NULL : InterfaceNameW,
  627. IPX_ROUTE_FILTER_PERMIT,
  628. mode, &RipFilter
  629. );
  630. }
  631. else
  632. {
  633. rc = NO_ERROR;
  634. }
  635. if (rc == NO_ERROR)
  636. {
  637. rc = CfgSetRipFlt(
  638. OPERATION_DEL_RIPFILTER,
  639. fClient ? NULL : InterfaceNameW,
  640. IPX_ROUTE_FILTER_PERMIT,
  641. mode, &RipFilter
  642. );
  643. }
  644. }
  645. else
  646. {
  647. rc = ERROR_INVALID_PARAMETER;
  648. DisplayMessage (g_hModule, HLP_IPX_RIPFILTER);
  649. }
  650. }
  651. else
  652. {
  653. DisplayMessage (g_hModule, HLP_IPX_RIPFILTER);
  654. rc = ERROR_INVALID_PARAMETER;
  655. }
  656. Exit:
  657. return rc;
  658. #undef InterfaceNameW
  659. }
  660. DWORD
  661. AdmSetRipFlt(
  662. int operation,
  663. LPWSTR InterfaceNameW,
  664. ULONG Action,
  665. ULONG Mode,
  666. PRIP_ROUTE_FILTER_INFO RipFilter
  667. )
  668. {
  669. DWORD rc;
  670. HANDLE hIfAdm;
  671. LPBYTE pIfBlock;
  672. DWORD sz;
  673. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  674. DWORD dwSize = sizeof(IfName);
  675. if (InterfaceNameW != NULL)
  676. {
  677. //======================================
  678. // Translate the Interface Name
  679. //======================================
  680. rc = IpmontrGetIfNameFromFriendlyName(
  681. InterfaceNameW, IfName, &dwSize
  682. );
  683. if ( rc == NO_ERROR )
  684. {
  685. rc = MprAdminInterfaceGetHandle(
  686. g_hMprAdmin, IfName, &hIfAdm,FALSE
  687. );
  688. if (rc == NO_ERROR)
  689. {
  690. rc = MprAdminInterfaceTransportGetInfo(
  691. g_hMprAdmin, hIfAdm, PID_IPX, &pIfBlock, &sz
  692. );
  693. }
  694. }
  695. }
  696. else
  697. {
  698. rc = MprAdminTransportGetInfo (
  699. g_hMprAdmin, PID_IPX, NULL, NULL, &pIfBlock, &sz
  700. );
  701. }
  702. if (rc == NO_ERROR)
  703. {
  704. UINT msg;
  705. LPBYTE pNewBlock;
  706. switch (operation)
  707. {
  708. case OPERATION_ADD_RIPFILTER:
  709. rc = UpdateRipFilter (
  710. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  711. (BOOLEAN)(Mode == OUTPUT_FILTER),
  712. NULL, RipFilter,
  713. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  714. );
  715. if (InterfaceNameW != NULL)
  716. {
  717. msg = MSG_RIPFILTER_CREATED_ADM;
  718. }
  719. else
  720. {
  721. msg = MSG_CLIENT_RIPFILTER_CREATED_ADM;
  722. }
  723. break;
  724. case OPERATION_SET_RIPFILTER:
  725. rc = SetRipFltAction(
  726. pIfBlock, (BOOLEAN)(Mode == OUTPUT_FILTER), Action
  727. );
  728. if (InterfaceNameW != NULL)
  729. {
  730. msg = MSG_RIPFILTER_SET_ADM;
  731. }
  732. else
  733. {
  734. msg = MSG_CLIENT_RIPFILTER_SET_ADM;
  735. }
  736. pNewBlock = pIfBlock;
  737. break;
  738. case OPERATION_DEL_RIPFILTER:
  739. rc = UpdateRipFilter (
  740. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  741. (BOOLEAN)(Mode == OUTPUT_FILTER),
  742. RipFilter, NULL, (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  743. );
  744. if (InterfaceNameW != NULL)
  745. {
  746. msg = MSG_RIPFILTER_SET_ADM;
  747. }
  748. else
  749. {
  750. msg = MSG_CLIENT_RIPFILTER_SET_ADM;
  751. }
  752. break;
  753. }
  754. if (rc == NO_ERROR)
  755. {
  756. if (InterfaceNameW != NULL)
  757. {
  758. rc = MprAdminInterfaceTransportSetInfo (
  759. g_hMprAdmin, hIfAdm, PID_IPX, pNewBlock,
  760. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  761. );
  762. }
  763. else
  764. {
  765. rc = MprAdminTransportSetInfo (
  766. g_hMprAdmin, PID_IPX, NULL, 0, pNewBlock,
  767. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  768. );
  769. }
  770. if (pNewBlock != pIfBlock)
  771. {
  772. GlobalFree (pNewBlock);
  773. }
  774. if (rc == NO_ERROR)
  775. {
  776. DisplayIPXMessage (g_hModule, msg, InterfaceNameW);
  777. }
  778. else
  779. {
  780. DisplayError( g_hModule, rc);
  781. }
  782. }
  783. else
  784. {
  785. DisplayError( g_hModule, rc);
  786. }
  787. MprAdminBufferFree (pIfBlock);
  788. }
  789. else
  790. {
  791. DisplayError( g_hModule, rc);
  792. }
  793. return rc;
  794. }
  795. DWORD
  796. CfgSetRipFlt(
  797. int operation,
  798. LPWSTR InterfaceNameW,
  799. ULONG Action,
  800. ULONG Mode,
  801. PRIP_ROUTE_FILTER_INFO RipFilter
  802. )
  803. {
  804. DWORD rc;
  805. HANDLE hIfCfg;
  806. HANDLE hIfTrCfg;
  807. HANDLE hTrCfg;
  808. LPBYTE pIfBlock;
  809. DWORD sz;
  810. WCHAR IfName[ MAX_INTERFACE_NAME_LEN + 1 ];
  811. DWORD dwSize = sizeof(IfName);
  812. if (InterfaceNameW != NULL)
  813. {
  814. //======================================
  815. // Translate the Interface Name
  816. //======================================
  817. rc = IpmontrGetIfNameFromFriendlyName(
  818. InterfaceNameW, IfName, &dwSize
  819. );
  820. if ( rc == NO_ERROR )
  821. {
  822. rc = MprConfigInterfaceGetHandle(
  823. g_hMprConfig, IfName, &hIfCfg
  824. );
  825. if ( rc == NO_ERROR )
  826. {
  827. rc = MprConfigInterfaceTransportGetHandle(
  828. g_hMprConfig, hIfCfg, PID_IPX, &hIfTrCfg
  829. );
  830. if (rc == NO_ERROR)
  831. {
  832. rc = MprConfigInterfaceTransportGetInfo(
  833. g_hMprConfig, hIfCfg, hIfTrCfg, &pIfBlock, &sz
  834. );
  835. }
  836. }
  837. }
  838. }
  839. else
  840. {
  841. rc = MprConfigTransportGetHandle(
  842. g_hMprConfig, PID_IPX, &hTrCfg
  843. );
  844. if (rc == NO_ERROR)
  845. {
  846. rc = MprConfigTransportGetInfo (
  847. g_hMprConfig, hTrCfg, NULL, NULL, &pIfBlock, &sz, NULL
  848. );
  849. }
  850. }
  851. if (rc == NO_ERROR)
  852. {
  853. UINT msg;
  854. LPBYTE pNewBlock;
  855. switch (operation)
  856. {
  857. case OPERATION_ADD_RIPFILTER:
  858. rc = UpdateRipFilter(
  859. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  860. (BOOLEAN)(Mode == OUTPUT_FILTER),
  861. NULL,
  862. RipFilter,
  863. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  864. );
  865. if (InterfaceNameW != NULL)
  866. {
  867. msg = MSG_RIPFILTER_CREATED_ADM;
  868. }
  869. else
  870. {
  871. msg = MSG_CLIENT_RIPFILTER_CREATED_ADM;
  872. }
  873. break;
  874. case OPERATION_SET_RIPFILTER:
  875. rc = SetRipFltAction(
  876. pIfBlock,
  877. (BOOLEAN)(Mode == OUTPUT_FILTER),
  878. Action
  879. );
  880. if (InterfaceNameW != NULL)
  881. {
  882. msg = MSG_RIPFILTER_SET_ADM;
  883. }
  884. else
  885. {
  886. msg = MSG_CLIENT_RIPFILTER_SET_ADM;
  887. }
  888. pNewBlock = pIfBlock;
  889. break;
  890. case OPERATION_DEL_RIPFILTER:
  891. rc = UpdateRipFilter(
  892. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  893. (BOOLEAN)(Mode == OUTPUT_FILTER),
  894. RipFilter, NULL,
  895. (PIPX_INFO_BLOCK_HEADER * ) & pNewBlock
  896. );
  897. if (InterfaceNameW != NULL)
  898. {
  899. msg = MSG_RIPFILTER_DELETED_ADM;
  900. }
  901. else
  902. {
  903. msg = MSG_CLIENT_RIPFILTER_DELETED_ADM;
  904. }
  905. break;
  906. }
  907. if (rc == NO_ERROR)
  908. {
  909. if (InterfaceNameW != NULL)
  910. {
  911. rc = MprConfigInterfaceTransportSetInfo (
  912. g_hMprConfig, hIfCfg, hIfTrCfg, pNewBlock,
  913. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size
  914. );
  915. }
  916. else
  917. {
  918. rc = MprConfigTransportSetInfo (
  919. g_hMprConfig, hTrCfg, NULL, 0, pNewBlock,
  920. ((PIPX_INFO_BLOCK_HEADER)pNewBlock)->Size,
  921. NULL
  922. );
  923. }
  924. if (pNewBlock != pIfBlock)
  925. {
  926. GlobalFree (pNewBlock);
  927. }
  928. if (rc == NO_ERROR)
  929. {
  930. DisplayIPXMessage (g_hModule, msg, InterfaceNameW);
  931. }
  932. else
  933. {
  934. DisplayError( g_hModule, rc);
  935. }
  936. }
  937. else
  938. {
  939. DisplayError( g_hModule, rc);
  940. }
  941. MprConfigBufferFree (pIfBlock);
  942. }
  943. else
  944. {
  945. DisplayError( g_hModule, rc);
  946. }
  947. return rc;
  948. }
  949. DWORD
  950. SetRipFltAction(
  951. LPBYTE pIfBlock,
  952. BOOLEAN Output,
  953. ULONG Action
  954. )
  955. {
  956. DWORD rc;
  957. PIPX_TOC_ENTRY pRipToc;
  958. pRipToc = GetIPXTocEntry (
  959. (PIPX_INFO_BLOCK_HEADER)pIfBlock,
  960. IPX_PROTOCOL_RIP
  961. );
  962. if (pRipToc != NULL)
  963. {
  964. PRIP_IF_CONFIG pRipCfg;
  965. pRipCfg = (PRIP_IF_CONFIG)
  966. (pIfBlock + pRipToc->Offset);
  967. if (Output)
  968. {
  969. pRipCfg->RipIfFilters.SupplyFilterAction = Action;
  970. }
  971. else
  972. {
  973. pRipCfg->RipIfFilters.ListenFilterAction = Action;
  974. }
  975. rc = NO_ERROR;
  976. }
  977. else
  978. {
  979. rc = ERROR_INVALID_DATA;
  980. }
  981. return rc;
  982. }