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.

1196 lines
37 KiB

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