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.

1186 lines
27 KiB

  1. /*
  2. File: routerif.c
  3. Defines callbacks needed to deal with interfaces supported by
  4. the router.
  5. */
  6. #include "precomp.h"
  7. DWORD
  8. RtruiInterfaceShow(
  9. IN PWCHAR pwszIfName,
  10. IN DWORD dwLevel,
  11. IN DWORD dwFormat,
  12. IN PVOID pvData,
  13. IN HANDLE hData
  14. )
  15. /*++
  16. Routine Description:
  17. Prints interface info to display or file
  18. Arguments:
  19. pIfInfo - Info for adding the interface
  20. Return Value:
  21. NO_ERROR
  22. --*/
  23. {
  24. DWORD dwErr, dwSize;
  25. WCHAR rgwcIfDesc[MAX_INTERFACE_NAME_LEN + 1];
  26. PWCHAR pwszEnabled, pwszDisabled, pwszConnected, pwszDisconn;
  27. PWCHAR pwszConnecting, pwszClient, pwszHome, pwszFull;
  28. PWCHAR pwszDedicated, pwszInternal, pwszLoop;
  29. PWCHAR pwszAdminState, pwszState, pwszType;
  30. MPR_INTERFACE_0* pIfInfo = (MPR_INTERFACE_0*)pvData;
  31. BOOL bDump = (hData) && (*((BOOL*)hData));
  32. pwszEnabled = MakeString(g_hModule, STRING_ENABLED);
  33. pwszDisabled = MakeString(g_hModule, STRING_DISABLED);
  34. pwszConnected = MakeString(g_hModule, STRING_CONNECTED);
  35. pwszDisconn = MakeString(g_hModule, STRING_DISCONNECTED);
  36. pwszConnecting = MakeString(g_hModule, STRING_CONNECTING);
  37. pwszClient = MakeString(g_hModule, STRING_CLIENT);
  38. pwszHome = MakeString(g_hModule, STRING_HOME_ROUTER);
  39. pwszFull = MakeString(g_hModule, STRING_FULL_ROUTER);
  40. pwszDedicated = MakeString(g_hModule, STRING_DEDICATED);
  41. pwszInternal = MakeString(g_hModule, STRING_INTERNAL);
  42. pwszLoop = MakeString(g_hModule, STRING_LOOPBACK);
  43. do
  44. {
  45. if(!pwszEnabled or
  46. !pwszDisabled or
  47. !pwszConnected or
  48. !pwszDisconn or
  49. !pwszConnecting or
  50. !pwszClient or
  51. !pwszHome or
  52. !pwszFull or
  53. !pwszDedicated or
  54. !pwszInternal or
  55. !pwszLoop)
  56. {
  57. DisplayError(NULL,
  58. ERROR_NOT_ENOUGH_MEMORY);
  59. break;
  60. }
  61. dwSize = sizeof(rgwcIfDesc);
  62. IfutlGetInterfaceDescription(pIfInfo->wszInterfaceName,
  63. rgwcIfDesc,
  64. &dwSize);
  65. switch(pIfInfo->dwConnectionState)
  66. {
  67. case ROUTER_IF_STATE_DISCONNECTED:
  68. {
  69. pwszState = pwszDisconn;
  70. break;
  71. }
  72. case ROUTER_IF_STATE_CONNECTING:
  73. {
  74. pwszState = pwszConnecting;
  75. break;
  76. }
  77. case ROUTER_IF_STATE_CONNECTED:
  78. {
  79. pwszState = pwszConnected;
  80. break;
  81. }
  82. default:
  83. {
  84. pwszState = L"";
  85. break;
  86. }
  87. }
  88. if (bDump == FALSE)
  89. {
  90. switch(pIfInfo->dwIfType)
  91. {
  92. case ROUTER_IF_TYPE_CLIENT:
  93. pwszType = pwszClient;
  94. break;
  95. case ROUTER_IF_TYPE_HOME_ROUTER:
  96. pwszType = pwszHome;
  97. break;
  98. case ROUTER_IF_TYPE_FULL_ROUTER:
  99. pwszType = pwszFull;
  100. break;
  101. case ROUTER_IF_TYPE_DEDICATED:
  102. pwszType = pwszDedicated;
  103. break;
  104. case ROUTER_IF_TYPE_INTERNAL:
  105. pwszType = pwszInternal;
  106. break;
  107. case ROUTER_IF_TYPE_LOOPBACK:
  108. pwszType = pwszLoop;
  109. break;
  110. default:
  111. pwszType = L"";
  112. break;
  113. }
  114. if(pIfInfo->fEnabled)
  115. {
  116. pwszAdminState = pwszEnabled;
  117. }
  118. else
  119. {
  120. pwszAdminState = pwszDisabled;
  121. }
  122. }
  123. else
  124. {
  125. switch(pIfInfo->dwIfType)
  126. {
  127. case ROUTER_IF_TYPE_FULL_ROUTER:
  128. pwszType = TOKEN_FULL;
  129. break;
  130. default:
  131. pwszType = L"";
  132. break;
  133. }
  134. if(pIfInfo->fEnabled)
  135. {
  136. pwszAdminState = TOKEN_VALUE_ENABLED;
  137. }
  138. else
  139. {
  140. pwszAdminState = TOKEN_VALUE_DISABLED;
  141. }
  142. }
  143. if (bDump)
  144. {
  145. PWCHAR pwszQuoted = NULL;
  146. if (wcscmp(pIfInfo->wszInterfaceName, rgwcIfDesc))
  147. {
  148. pwszQuoted = MakeQuotedString( rgwcIfDesc );
  149. }
  150. else
  151. {
  152. pwszQuoted = MakeQuotedString( pIfInfo->wszInterfaceName );
  153. }
  154. if (pIfInfo->dwIfType == ROUTER_IF_TYPE_FULL_ROUTER)
  155. {
  156. WCHAR pwszUser[256], pwszDomain[256];
  157. PWCHAR pszQuoteUser = NULL, pszQuoteDomain = NULL;
  158. DisplayMessageT( DMP_IF_ADD_IF,
  159. pwszQuoted,
  160. pwszType);
  161. DisplayMessageT( DMP_IF_SET_IF,
  162. pwszQuoted,
  163. pwszAdminState);
  164. dwErr = RtrdbInterfaceReadCredentials(
  165. pIfInfo->wszInterfaceName,
  166. pwszUser,
  167. NULL,
  168. pwszDomain);
  169. if (dwErr == NO_ERROR)
  170. {
  171. pszQuoteUser = MakeQuotedString( pwszUser );
  172. if (pszQuoteUser == NULL)
  173. {
  174. break;
  175. }
  176. if (*pwszDomain == L'\0')
  177. {
  178. DisplayMessageT( DMP_IF_SET_CRED_IF_NOD,
  179. pwszQuoted,
  180. pszQuoteUser);
  181. }
  182. else
  183. {
  184. pszQuoteDomain = MakeQuotedString( pwszDomain );
  185. if (pszQuoteUser == NULL)
  186. {
  187. FreeString(pszQuoteUser);
  188. break;
  189. }
  190. DisplayMessageT( DMP_IF_SET_CRED_IF,
  191. pwszQuoted,
  192. pszQuoteUser,
  193. pszQuoteDomain);
  194. FreeString(pszQuoteDomain);
  195. }
  196. }
  197. DisplayMessageT( DMP_IF_NEWLINE );
  198. }
  199. FreeQuotedString(pwszQuoted);
  200. }
  201. else
  202. {
  203. DisplayMessage(g_hModule,
  204. (dwFormat>0)? MSG_IF_ENTRY_LONG : MSG_IF_ENTRY_SHORT,
  205. pwszAdminState,
  206. pwszState,
  207. pwszType,
  208. rgwcIfDesc );
  209. }
  210. }while(FALSE);
  211. if(pwszEnabled)
  212. {
  213. FreeString(pwszEnabled);
  214. }
  215. if(pwszDisabled)
  216. {
  217. FreeString(pwszDisabled);
  218. }
  219. if(pwszConnected)
  220. {
  221. FreeString(pwszConnected);
  222. }
  223. if(pwszDisconn)
  224. {
  225. FreeString(pwszDisconn);
  226. }
  227. if(pwszConnecting)
  228. {
  229. FreeString(pwszConnecting);
  230. }
  231. if(pwszClient)
  232. {
  233. FreeString(pwszClient);
  234. }
  235. if(pwszHome)
  236. {
  237. FreeString(pwszHome);
  238. }
  239. if(pwszFull)
  240. {
  241. FreeString(pwszFull);
  242. }
  243. if(pwszDedicated)
  244. {
  245. FreeString(pwszDedicated);
  246. }
  247. if(pwszInternal)
  248. {
  249. FreeString(pwszInternal);
  250. }
  251. if(pwszLoop)
  252. {
  253. FreeString(pwszLoop);
  254. }
  255. return NO_ERROR;
  256. }
  257. DWORD
  258. RtrHandleResetAll(
  259. IN PWCHAR *ppwcArguments,
  260. IN DWORD dwCurrentIndex,
  261. IN DWORD dwArgCount,
  262. IN BOOL *pbDone
  263. )
  264. /*++
  265. Routine Description:
  266. Handler for displaying interfaces
  267. Arguments:
  268. ppwcArguments - Argument array
  269. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  270. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  271. Return Value:
  272. NO_ERROR
  273. --*/
  274. {
  275. DWORD dwErr = NO_ERROR, dwSize;
  276. MPR_INTERFACE_0 If0;
  277. WCHAR pszName[MAX_INTERFACE_NAME_LEN];
  278. do
  279. {
  280. // Make sure no arguments were passed in
  281. //
  282. if (dwArgCount - dwCurrentIndex != 0)
  283. {
  284. dwErr = ERROR_INVALID_SYNTAX;
  285. break;
  286. }
  287. dwErr = RtrdbResetAll();
  288. BREAK_ON_DWERR(dwErr);
  289. } while (FALSE);
  290. // Cleanup
  291. {
  292. }
  293. return dwErr;
  294. }
  295. DWORD
  296. RtrHandleAddDel(
  297. IN PWCHAR *ppwcArguments,
  298. IN DWORD dwCurrentIndex,
  299. IN DWORD dwArgCount,
  300. IN BOOL bAdd
  301. )
  302. /*++
  303. Routine Description:
  304. The actual parser for the add and delete commands
  305. Arguments:
  306. ppwcArguments - Argument array
  307. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  308. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  309. bAdd - TRUE to add the interface
  310. Return Value:
  311. NO_ERROR
  312. --*/
  313. {
  314. DWORD i, dwNumArgs, dwRes, dwErr, dwIfType, dwSize;
  315. MPR_INTERFACE_0 IfInfo;
  316. PWCHAR pszIfDesc = NULL;
  317. TOKEN_VALUE rgEnumType[] =
  318. {
  319. {TOKEN_FULL, ROUTER_IF_TYPE_FULL_ROUTER}
  320. };
  321. IFMON_CMD_ARG pArgs[] =
  322. {
  323. {
  324. IFMON_CMD_TYPE_STRING,
  325. {TOKEN_NAME, TRUE, FALSE},
  326. NULL,
  327. 0,
  328. NULL
  329. },
  330. {
  331. IFMON_CMD_TYPE_ENUM,
  332. {TOKEN_TYPE, FALSE, FALSE},
  333. rgEnumType,
  334. sizeof(rgEnumType) / sizeof(*rgEnumType),
  335. NULL
  336. }
  337. };
  338. // Initialize
  339. //
  340. ZeroMemory(&IfInfo, sizeof(IfInfo));
  341. IfInfo.fEnabled = TRUE;
  342. do
  343. {
  344. // Parse out the values
  345. //
  346. dwErr = IfutlParse(
  347. ppwcArguments,
  348. dwCurrentIndex,
  349. dwArgCount,
  350. NULL,
  351. pArgs,
  352. sizeof(pArgs) / sizeof(*pArgs));
  353. if (dwErr isnot NO_ERROR)
  354. {
  355. break;
  356. }
  357. //
  358. // Get the arguments that were specified
  359. //
  360. pszIfDesc = IFMON_CMD_ARG_GetPsz(&pArgs[0]);
  361. IfInfo.dwIfType = IFMON_CMD_ARG_GetDword(&pArgs[1]);
  362. if(bAdd)
  363. {
  364. // Make sure the type was specified
  365. //
  366. if (! pArgs[1].rgTag.bPresent)
  367. {
  368. dwErr = ERROR_INVALID_SYNTAX;
  369. break;
  370. }
  371. wcscpy(
  372. IfInfo.wszInterfaceName,
  373. pszIfDesc
  374. );
  375. dwErr = RtrdbInterfaceAdd(
  376. IfInfo.wszInterfaceName,
  377. 0,
  378. (PVOID)&IfInfo);
  379. }
  380. else
  381. {
  382. WCHAR pszName[MAX_INTERFACE_NAME_LEN + 1];
  383. dwSize = sizeof(pszName);
  384. IfutlGetInterfaceName(
  385. pszIfDesc,
  386. pszName,
  387. &dwSize);
  388. dwErr = RtrdbInterfaceDelete(pszName);
  389. }
  390. } while(FALSE);
  391. // Cleanup
  392. {
  393. IfutlFree(pszIfDesc);
  394. }
  395. return dwErr;
  396. }
  397. DWORD
  398. RtrHandleAdd(
  399. IN PWCHAR *ppwcArguments,
  400. IN DWORD dwCurrentIndex,
  401. IN DWORD dwArgCount,
  402. IN BOOL *pbDone
  403. )
  404. /*++
  405. Routine Description:
  406. Handler for adding an dial interface to the router
  407. Arguments:
  408. ppwcArguments - Argument array
  409. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  410. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  411. Return Value:
  412. NO_ERROR
  413. --*/
  414. {
  415. return RtrHandleAddDel(
  416. ppwcArguments,
  417. dwCurrentIndex,
  418. dwArgCount,
  419. TRUE);
  420. }
  421. DWORD
  422. RtrHandleDel(
  423. IN PWCHAR *ppwcArguments,
  424. IN DWORD dwCurrentIndex,
  425. IN DWORD dwArgCount,
  426. IN BOOL *pbDone
  427. )
  428. /*++
  429. Routine Description:
  430. Handler for deleting a dial interface or from the router
  431. Arguments:
  432. ppwcArguments - Argument array
  433. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  434. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  435. Return Value:
  436. NO_ERROR
  437. --*/
  438. {
  439. return RtrHandleAddDel(
  440. ppwcArguments,
  441. dwCurrentIndex,
  442. dwArgCount,
  443. FALSE);
  444. }
  445. DWORD
  446. RtrHandleSet(
  447. IN PWCHAR *ppwcArguments,
  448. IN DWORD dwCurrentIndex,
  449. IN DWORD dwArgCount,
  450. IN BOOL *pbDone
  451. )
  452. /*++
  453. Routine Description:
  454. Handler for displaying interfaces
  455. Arguments:
  456. ppwcArguments - Argument array
  457. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  458. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  459. Return Value:
  460. NO_ERROR
  461. --*/
  462. {
  463. DWORD dwErr = NO_ERROR, dwSize;
  464. MPR_INTERFACE_0 If0;
  465. TOKEN_VALUE rgEnumAdmin[] =
  466. {
  467. {TOKEN_VALUE_ENABLED, TRUE},
  468. {TOKEN_VALUE_DISABLED, FALSE}
  469. };
  470. TOKEN_VALUE rgEnumConnect[] =
  471. {
  472. {TOKEN_VALUE_CONNECTED, TRUE},
  473. {TOKEN_VALUE_DISCONNECTED, FALSE}
  474. };
  475. IFMON_CMD_ARG pArgs[] =
  476. {
  477. {
  478. IFMON_CMD_TYPE_STRING,
  479. {TOKEN_NAME, TRUE, FALSE},
  480. NULL,
  481. 0,
  482. NULL
  483. },
  484. {
  485. IFMON_CMD_TYPE_ENUM,
  486. {TOKEN_ADMIN, FALSE, FALSE},
  487. rgEnumAdmin,
  488. sizeof(rgEnumAdmin) / sizeof(*rgEnumAdmin),
  489. NULL
  490. },
  491. {
  492. IFMON_CMD_TYPE_ENUM,
  493. {TOKEN_CONNECT, FALSE, FALSE},
  494. rgEnumConnect,
  495. sizeof(rgEnumConnect) / sizeof(*rgEnumConnect),
  496. NULL
  497. },
  498. {
  499. IFMON_CMD_TYPE_STRING,
  500. {TOKEN_NEWNAME, FALSE, FALSE},
  501. NULL,
  502. 0,
  503. NULL
  504. }
  505. };
  506. PWCHAR pszIfName = NULL, pszNewName = NULL;
  507. WCHAR pszName[MAX_INTERFACE_NAME_LEN];
  508. BOOL fEnable = FALSE, fConnect = FALSE;
  509. BOOL fEnablePresent = FALSE, fConnectPresent = FALSE;
  510. do
  511. {
  512. // Parse
  513. //
  514. dwErr = IfutlParse(
  515. ppwcArguments,
  516. dwCurrentIndex,
  517. dwArgCount,
  518. NULL,
  519. pArgs,
  520. sizeof(pArgs)/sizeof(*pArgs));
  521. BREAK_ON_DWERR(dwErr);
  522. // Get the returned values from the parse
  523. //
  524. pszIfName = IFMON_CMD_ARG_GetPsz(&pArgs[0]);
  525. fEnable = IFMON_CMD_ARG_GetDword(&pArgs[1]);
  526. fConnect = IFMON_CMD_ARG_GetDword(&pArgs[2]);
  527. pszNewName = IFMON_CMD_ARG_GetPsz(&pArgs[3]);
  528. fEnablePresent = pArgs[1].rgTag.bPresent;
  529. fConnectPresent = pArgs[2].rgTag.bPresent;
  530. // Get the interface info so that we can
  531. // make sure we have the right type.
  532. //
  533. dwSize = sizeof(pszName);
  534. dwErr = GetIfNameFromFriendlyName(
  535. pszIfName,
  536. pszName,
  537. &dwSize);
  538. BREAK_ON_DWERR(dwErr);
  539. ZeroMemory(&If0, sizeof(If0));
  540. dwErr = RtrdbInterfaceRead(
  541. pszName,
  542. 0,
  543. (PVOID*)&If0);
  544. BREAK_ON_DWERR(dwErr);
  545. // Rename the interface if that is the request
  546. //
  547. if ( If0.dwIfType == ROUTER_IF_TYPE_DEDICATED )
  548. {
  549. if (!pszNewName)
  550. {
  551. DisplayError(
  552. g_hModule,
  553. EMSG_CANT_FIND_EOPT);
  554. dwErr = ERROR_INVALID_SYNTAX;
  555. break;
  556. }
  557. if (g_pwszRouter)
  558. {
  559. DisplayError(
  560. g_hModule,
  561. EMSG_IF_NEWNAME_ONLY_FOR_LOCAL);
  562. dwErr = ERROR_CAN_NOT_COMPLETE;
  563. break;
  564. }
  565. if (fEnablePresent || fConnectPresent)
  566. {
  567. DisplayError(
  568. g_hModule,
  569. EMSG_IF_LAN_ONLY_COMMAND);
  570. dwErr = ERROR_CAN_NOT_COMPLETE;
  571. break;
  572. }
  573. // Rename the interface
  574. //
  575. dwErr = RtrdbInterfaceRename(
  576. pszName,
  577. 0,
  578. (PVOID)&If0,
  579. pszNewName);
  580. break;
  581. }
  582. if (pszNewName)
  583. {
  584. DisplayError(
  585. g_hModule,
  586. EMSG_IF_NEWNAME_ONLY_FOR_LAN);
  587. dwErr = ERROR_CAN_NOT_COMPLETE;
  588. break;
  589. }
  590. // Make sure that at least one option was specified
  591. //
  592. if (!fEnablePresent && !fConnectPresent)
  593. {
  594. dwErr = ERROR_INVALID_SYNTAX;
  595. break;
  596. }
  597. // Validate the interface type
  598. //
  599. //if ( ( If0.dwIfType == ROUTER_IF_TYPE_DEDICATED ) ||
  600. // ( If0.dwIfType == ROUTER_IF_TYPE_INTERNAL )
  601. // )
  602. if ( If0.dwIfType != ROUTER_IF_TYPE_FULL_ROUTER )
  603. {
  604. DisplayError(
  605. g_hModule,
  606. EMSG_IF_WAN_ONLY_COMMAND);
  607. dwErr = ERROR_CAN_NOT_COMPLETE;
  608. break;
  609. }
  610. // Allow the connection request to override
  611. // the admin enabling.
  612. if (fConnectPresent)
  613. {
  614. if (!IfutlIsRouterRunning())
  615. {
  616. DisplayError(
  617. g_hModule,
  618. EMSG_IF_CONNECT_ONLY_WHEN_ROUTER_RUNNING);
  619. dwErr = ERROR_CAN_NOT_COMPLETE;
  620. break;
  621. }
  622. if (fConnect)
  623. {
  624. fEnablePresent = TRUE;
  625. fEnable = TRUE;
  626. }
  627. }
  628. // Enable if requested
  629. //
  630. if (fEnablePresent)
  631. {
  632. // Enable/disable the interface
  633. //
  634. If0.fEnabled = fEnable;
  635. // Commit
  636. //
  637. dwErr = RtrdbInterfaceWrite(
  638. If0.wszInterfaceName,
  639. 0,
  640. (PVOID)&If0);
  641. BREAK_ON_DWERR(dwErr);
  642. }
  643. // Connect if requested
  644. //
  645. if (fConnectPresent)
  646. {
  647. if (fConnect)
  648. {
  649. dwErr = MprAdminInterfaceConnect(
  650. g_hMprAdmin,
  651. If0.hInterface,
  652. NULL,
  653. TRUE);
  654. BREAK_ON_DWERR(dwErr);
  655. }
  656. else
  657. {
  658. dwErr = MprAdminInterfaceDisconnect(
  659. g_hMprAdmin,
  660. If0.hInterface);
  661. BREAK_ON_DWERR(dwErr);
  662. }
  663. }
  664. } while (FALSE);
  665. // Cleanup
  666. {
  667. IfutlFree(pszIfName);
  668. IfutlFree(pszNewName);
  669. }
  670. return dwErr;
  671. }
  672. DWORD
  673. RtrHandleSetCredentials(
  674. IN PWCHAR *ppwcArguments,
  675. IN DWORD dwCurrentIndex,
  676. IN DWORD dwArgCount,
  677. IN BOOL *pbDone
  678. )
  679. /*++
  680. Routine Description:
  681. Handler for displaying interfaces
  682. Arguments:
  683. ppwcArguments - Argument array
  684. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  685. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  686. Return Value:
  687. NO_ERROR
  688. --*/
  689. {
  690. DWORD dwErr = NO_ERROR, dwSize;
  691. MPR_INTERFACE_0 If0;
  692. IFMON_CMD_ARG pArgs[] =
  693. {
  694. {
  695. IFMON_CMD_TYPE_STRING,
  696. {TOKEN_NAME, TRUE, FALSE},
  697. NULL,
  698. 0,
  699. NULL
  700. },
  701. {
  702. IFMON_CMD_TYPE_STRING,
  703. {TOKEN_USER, TRUE, FALSE},
  704. NULL,
  705. 0,
  706. NULL
  707. },
  708. {
  709. IFMON_CMD_TYPE_STRING,
  710. {TOKEN_DOMAIN, FALSE, FALSE},
  711. NULL,
  712. 0,
  713. NULL
  714. },
  715. {
  716. IFMON_CMD_TYPE_STRING,
  717. {TOKEN_PASSWORD, FALSE, FALSE},
  718. NULL,
  719. 0,
  720. NULL
  721. }
  722. };
  723. PWCHAR pszIfName = NULL, pszUser = NULL;
  724. PWCHAR pszPassword = NULL, pszDomain = NULL;
  725. WCHAR pszName[MAX_INTERFACE_NAME_LEN];
  726. do
  727. {
  728. // Parse
  729. //
  730. dwErr = IfutlParse(
  731. ppwcArguments,
  732. dwCurrentIndex,
  733. dwArgCount,
  734. NULL,
  735. pArgs,
  736. sizeof(pArgs)/sizeof(*pArgs));
  737. BREAK_ON_DWERR(dwErr);
  738. // Get the returned values from the parse
  739. //
  740. pszIfName = IFMON_CMD_ARG_GetPsz(&pArgs[0]);
  741. pszUser = IFMON_CMD_ARG_GetPsz(&pArgs[1]);
  742. pszDomain = IFMON_CMD_ARG_GetPsz(&pArgs[2]);
  743. pszPassword = IFMON_CMD_ARG_GetPsz(&pArgs[3]);
  744. // Get the interface info so that we can
  745. // make sure we have the right type.
  746. //
  747. dwSize = sizeof(pszName);
  748. dwErr = GetIfNameFromFriendlyName(
  749. pszIfName,
  750. pszName,
  751. &dwSize);
  752. BREAK_ON_DWERR(dwErr);
  753. dwErr = RtrdbInterfaceWriteCredentials(
  754. pszName,
  755. pszUser,
  756. pszPassword,
  757. pszDomain);
  758. BREAK_ON_DWERR(dwErr);
  759. } while (FALSE);
  760. // Cleanup
  761. {
  762. IfutlFree(pszIfName);
  763. IfutlFree(pszUser);
  764. IfutlFree(pszPassword);
  765. IfutlFree(pszDomain);
  766. }
  767. return dwErr;
  768. }
  769. DWORD
  770. RtrHandleShow(
  771. IN PWCHAR *ppwcArguments,
  772. IN DWORD dwCurrentIndex,
  773. IN DWORD dwArgCount,
  774. IN BOOL *pbDone
  775. )
  776. /*++
  777. Routine Description:
  778. Handler for displaying interfaces
  779. Arguments:
  780. ppwcArguments - Argument array
  781. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  782. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  783. Return Value:
  784. NO_ERROR
  785. --*/
  786. {
  787. DWORD dwErr = NO_ERROR, dwSize;
  788. MPR_INTERFACE_0 If0;
  789. IFMON_CMD_ARG pArgs[] =
  790. {
  791. {
  792. IFMON_CMD_TYPE_STRING,
  793. {TOKEN_NAME, FALSE, FALSE},
  794. NULL,
  795. 0,
  796. NULL
  797. }
  798. };
  799. PWCHAR pszIfName = NULL;
  800. WCHAR pszName[MAX_INTERFACE_NAME_LEN];
  801. do
  802. {
  803. // Parse
  804. //
  805. dwErr = IfutlParse(
  806. ppwcArguments,
  807. dwCurrentIndex,
  808. dwArgCount,
  809. NULL,
  810. pArgs,
  811. sizeof(pArgs)/sizeof(*pArgs));
  812. BREAK_ON_DWERR(dwErr);
  813. // Get the returned values from the parse
  814. //
  815. pszIfName = IFMON_CMD_ARG_GetPsz(&pArgs[0]);
  816. // Handle the no argument case
  817. //
  818. if (pszIfName == NULL)
  819. {
  820. RtrdbInterfaceEnumerate(0, 0, RtruiInterfaceShow, NULL);
  821. dwErr = NO_ERROR;
  822. break;
  823. }
  824. // Map the name
  825. //
  826. dwSize = sizeof(pszName);
  827. GetIfNameFromFriendlyName(
  828. pszIfName,
  829. pszName,
  830. &dwSize);
  831. // Get the info
  832. //
  833. dwErr = RtrdbInterfaceRead(
  834. pszName,
  835. 0,
  836. (PVOID)&If0);
  837. BREAK_ON_DWERR( dwErr );
  838. RtruiInterfaceShow(
  839. If0.wszInterfaceName,
  840. 0,
  841. 1,
  842. (PVOID)&If0,
  843. NULL
  844. );
  845. } while (FALSE);
  846. // Cleanup
  847. //
  848. {
  849. if (pszIfName != NULL)
  850. {
  851. IfutlFree(pszIfName);
  852. }
  853. }
  854. return dwErr;
  855. }
  856. DWORD
  857. RtrHandleShowCredentials(
  858. IN PWCHAR *ppwcArguments,
  859. IN DWORD dwCurrentIndex,
  860. IN DWORD dwArgCount,
  861. IN BOOL *pbDone
  862. )
  863. /*++
  864. Routine Description:
  865. Handler for showing credentials of an interface
  866. Arguments:
  867. ppwcArguments - Argument array
  868. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  869. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  870. Return Value:
  871. NO_ERROR
  872. --*/
  873. {
  874. DWORD dwErr = NO_ERROR, dwSize;
  875. MPR_INTERFACE_0 If0;
  876. IFMON_CMD_ARG pArgs[] =
  877. {
  878. {
  879. IFMON_CMD_TYPE_STRING,
  880. {TOKEN_NAME, TRUE, FALSE},
  881. NULL,
  882. 0,
  883. NULL
  884. },
  885. };
  886. PWCHAR pszIfName = NULL;
  887. WCHAR pszName[MAX_INTERFACE_NAME_LEN];
  888. WCHAR pszUser[256], pszDomain[256], pszPassword[256];
  889. do
  890. {
  891. // Parse
  892. //
  893. dwErr = IfutlParse(
  894. ppwcArguments,
  895. dwCurrentIndex,
  896. dwArgCount,
  897. NULL,
  898. pArgs,
  899. sizeof(pArgs)/sizeof(*pArgs));
  900. BREAK_ON_DWERR(dwErr);
  901. // Get the returned values from the parse
  902. //
  903. pszIfName = IFMON_CMD_ARG_GetPsz(&pArgs[0]);
  904. // Get the interface info so that we can
  905. // make sure we have the right type.
  906. //
  907. dwSize = sizeof(pszName);
  908. dwErr = GetIfNameFromFriendlyName(
  909. pszIfName,
  910. pszName,
  911. &dwSize);
  912. BREAK_ON_DWERR(dwErr);
  913. dwErr = RtrdbInterfaceReadCredentials(
  914. pszName,
  915. pszUser,
  916. pszPassword,
  917. pszDomain);
  918. BREAK_ON_DWERR(dwErr);
  919. DisplayMessage(
  920. g_hModule,
  921. MSG_IF_CREDENTIALS,
  922. pszIfName,
  923. pszUser,
  924. pszDomain,
  925. pszPassword);
  926. } while (FALSE);
  927. // Cleanup
  928. {
  929. IfutlFree(pszIfName);
  930. }
  931. return dwErr;
  932. }
  933. DWORD
  934. RtrHandleDump(
  935. PWCHAR *ppwcArguments,
  936. DWORD dwCurrentIndex,
  937. DWORD dwArgCount,
  938. BOOL *pbDone
  939. )
  940. {
  941. DWORD dwErr, dwCount, dwTotal;
  942. ULONG i;
  943. PMPR_INTERFACE_0 pIfTable;
  944. BOOL bFormat = TRUE;
  945. // Display dump header
  946. //
  947. DisplayMessage(g_hModule, DMP_IF_HEADER_COMMENTS);
  948. DisplayMessageT(DMP_IF_HEADER);
  949. // Display the interfaces
  950. //
  951. RtrdbInterfaceEnumerate(0, 0, RtruiInterfaceShow, &bFormat);
  952. // Display dump footer
  953. //
  954. DisplayMessageT(DMP_IF_FOOTER);
  955. DisplayMessage(g_hModule, DMP_IF_FOOTER_COMMENTS);
  956. return NO_ERROR;
  957. }
  958. DWORD
  959. RtrDump(
  960. IN PWCHAR *ppwcArguments,
  961. IN DWORD dwArgCount
  962. )
  963. {
  964. BOOL bDone;
  965. return RtrHandleDump(ppwcArguments, 1, dwArgCount, &bDone);
  966. }