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.

1226 lines
35 KiB

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